Compare commits

...

2 commits

Author SHA1 Message Date
Yun Chan
f18cebaa24 chore(release): v1.15.0
Some checks failed
ci / 정본·보안·린트·타입·테스트 (push) Failing after 21s
ci / 모바일 린트·타입·Jest (push) Successful in 40s
ci / Supabase Edge Functions + Cloudflare Worker (push) Successful in 33s
ci / .NET API 서버 테스트 (push) Successful in 12s
ci / 워크스페이스 빌드 검증 (push) Has been skipped
deploy-site / deploy (push) Successful in 33s
release / release-windows (push) Failing after 14m1s
portable-unsigned / portable-windows (push) Failing after 14m6s
2026-10-31 02:55:55 +09:00
Yun Chan
10af20a0ad feat(commands): multi-select ordered command pipeline with step reordering and single-pass composition (AI-05, AI-07) 2026-10-31 02:54:54 +09:00
178 changed files with 29502 additions and 958 deletions

View file

@ -62,11 +62,27 @@ jobs:
FORGEJO_TOKEN: "${{ secrets.FORGEJO_TOKEN }}" FORGEJO_TOKEN: "${{ secrets.FORGEJO_TOKEN }}"
run: node scripts/ci/publish-portable-release.mjs run: node scripts/ci/publish-portable-release.mjs
- name: 아티팩트 업로드 - name: 게시 요약 출력
uses: actions/upload-artifact@v4 # Forgejo Actions 러너는 actions/upload-artifact@v4 의 GHES 스토리지 프로토콜을 지원하지 않으므로(GAP-REL-11),
with: # 실제 배포 산출물은 앞 단계에서 Forgejo Generic Package Registry 에 이미 게시됐고 여기서는 해시 요약을 남긴다.
name: d3ro-voice-portable-${{ github.ref_name }} run: |
path: | $version = node -p "require('./release/product-version.json').version"
apps/desktop/release/*/*-portable.7z.00* $manifestPath = "apps/desktop/release/$version/portable.json"
apps/desktop/release/*/portable.json if (-not (Test-Path $manifestPath)) {
bucket/d3ro-voice.json throw "portable.json 이 없습니다: $manifestPath"
}
$manifest = Get-Content $manifestPath -Raw | ConvertFrom-Json
$summaryLines = @(
"### Portable Release ($($manifest.version))",
"- Volumes: $($manifest.volumeCount)",
"- Total Size: $([math]::Round($manifest.totalSize / 1MB, 1)) MiB",
"- Feed: https://git.chanpaca.net/api/packages/yunchan/generic/d3ro-voice/portable-$($manifest.version)/portable.json"
)
foreach ($vol in $manifest.volumes) {
$summaryLines += " - ``$($vol.name)``: ``$($vol.sha256)``"
}
$summaryText = $summaryLines -join "`n"
Write-Host $summaryText
if ($env:GITHUB_STEP_SUMMARY) {
Add-Content -Path $env:GITHUB_STEP_SUMMARY -Value $summaryText -Encoding utf8
}

View file

@ -40,7 +40,30 @@ jobs:
run: | run: |
$releaseVersion = node -p "require('./release/product-version.json').version" $releaseVersion = node -p "require('./release/product-version.json').version"
$url = "https://git.chanpaca.net/api/packages/yunchan/generic/d3ro-voice/$releaseVersion/latest.yml" $url = "https://git.chanpaca.net/api/packages/yunchan/generic/d3ro-voice/$releaseVersion/latest.yml"
try { Invoke-WebRequest -Uri $url -Method Get -UseBasicParsing | Out-Null; $published = 'true' } catch { $published = 'false' } $filesApiUrl = "https://git.chanpaca.net/api/v1/packages/yunchan/generic/d3ro-voice/$releaseVersion/files"
$published = 'false'
# 로컬 `npm run release` 는 annotated 태그를 먼저 푸시한 직후 설치본과 latest.yml 을 게시한다(GAP-REL-14).
# 이미 올라왔거나 업로드 진행 중이면 완료될 때까지 대기해 CI 가 중복 빌드/충돌하지 않게 한다.
for ($attempt = 0; $attempt -lt 10; $attempt++) {
try {
Invoke-WebRequest -Uri $url -Method Get -UseBasicParsing | Out-Null
$published = 'true'
break
} catch {}
if ($attempt -lt 9) {
$inProgress = $false
try {
$files = Invoke-RestMethod -Uri $filesApiUrl -Method Get
if ($files -and $files.Count -gt 0) { $inProgress = $true }
} catch {}
if ($attempt -lt 3 -or $inProgress) {
Write-Host "로컬 릴리스 게시 확인 대기 중... ($($attempt + 1)/10)"
Start-Sleep -Seconds 10
continue
}
}
break
}
"published=$published" >> $env:GITHUB_OUTPUT "published=$published" >> $env:GITHUB_OUTPUT
if ($published -eq 'true') { Write-Host "$releaseVersion 는 이미 피드에 있습니다 — 건너뜁니다." } if ($published -eq 'true') { Write-Host "$releaseVersion 는 이미 피드에 있습니다 — 건너뜁니다." }
@ -61,4 +84,12 @@ jobs:
FORGEJO_TOKEN: "${{ secrets.FORGEJO_TOKEN }}" FORGEJO_TOKEN: "${{ secrets.FORGEJO_TOKEN }}"
D3RO_UPDATE_SIGNING_KEY: "${{ secrets.D3RO_UPDATE_SIGNING_KEY }}" D3RO_UPDATE_SIGNING_KEY: "${{ secrets.D3RO_UPDATE_SIGNING_KEY }}"
FORGEJO_REPO: "${{ github.server_url }}/${{ github.repository }}" FORGEJO_REPO: "${{ github.server_url }}/${{ github.repository }}"
run: node scripts/ci/publish-forgejo-release.mjs run: |
$releaseVersion = node -p "require('./release/product-version.json').version"
$url = "https://git.chanpaca.net/api/packages/yunchan/generic/d3ro-voice/$releaseVersion/latest.yml"
try {
Invoke-WebRequest -Uri $url -Method Get -UseBasicParsing | Out-Null
Write-Host "$releaseVersion 는 빌드 도중 로컬 릴리스에서 이미 게시됐습니다 — 게시 단계를 건너뜁니다."
exit 0
} catch {}
node scripts/ci/publish-forgejo-release.mjs

View file

@ -501,8 +501,7 @@ publish-release:
- if: '$CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+.*$/' - if: '$CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+.*$/'
# ──────────────────────────────────────────────────────────────────── # ────────────────────────────────────────────────────────────────────
# Admin NAS deployment remains disabled until an immutable image, authenticated # Admin/Web/API NAS deployment uses the canonical runbook in
# remote target, health check, and rollback path are configured. Do not revive # docs/deployment/nas-deploy-runbook.md against docker-compose.nas.yml.
# the former DinD job: it only changed an ephemeral CI daemon and referenced a # Do not revive the former DinD job: it only changed an ephemeral CI daemon.
# non-existent compose file, so it never deployed the NAS.
# ──────────────────────────────────────────────────────────────────── # ────────────────────────────────────────────────────────────────────

View file

@ -12,6 +12,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Additional Whisper model management UI - Additional Whisper model management UI
- Plugin system for custom pipelines - Plugin system for custom pipelines
## [1.15.0] - 2026-10-31
> Published from an annotated tag. Installer and update metadata are served by the
> canonical Forgejo feed; no binaries are committed to this repository.
### Added
- **Multi-command ordered pipeline selection & reordering in Commands (`CommandsPage.tsx`, `@d3ro/core/instruction-template`, `VoiceModeService`).**
- Replaces single-select radio buttons in the Commands screen with an ordered multi-select pipeline: check multiple commands in sequence (e.g., **`1단계: 구어·추임새·중복 정리` → `2단계: 격식체 변환`** or **`1단계: 구어·추임새·중복 정리` → `2단계: 텍스트 요약` → `3단계: 번역`**) and reorder steps anytime with `↑` / `↓` controls.
- Synthesizes selected pipeline steps into a single ordered pipeline prompt (`composeInstructionPipelinePrompt`) where later steps determine the final output tone/format/language without adding multi-roundtrip LLM latency, and supports testing the full multi-step pipeline directly in the Commands test runner.
## [1.14.0] - 2026-10-29 ## [1.14.0] - 2026-10-29
> Published from an annotated tag. Installer and update metadata are served by the > Published from an annotated tag. Installer and update metadata are served by the

View file

@ -1,79 +1,84 @@
# D3RO-VOICE — 로컬 AI 음성 어시스턴트 # D3RO-VOICE — 멀티플랫폼 AI 음성 어시스턴트 모노레포
Speakly RE 기반 완전 로컬 음성 어시스턴트. Ollama + Whisper + TTS. 로컬 우선(Desktop) + 클라우드 동기화(Web · Mobile · Supabase · .NET API · Admin)를 아우르는 멀티플랫폼 AI 음성 어시스턴트.
> **에이전트 진입점**: 작업 전 `AGENTS.md`를 읽고, 기능/인프라 현황은 `docs/map/`를 > **에이전트 진입점**: 작업 전 [`AGENTS.md`](./AGENTS.md)와 정본 인프라/기능 지도인 [`docs/map/00-index.md`](./docs/map/00-index.md)를 먼저 읽는다.
> 참조한다. 기능 추가·삭제·변경·백로그 이관 시 `docs/map/10-feature-catalog.md`와 > 기능 추가·삭제·변경·백로그 이관 시 `docs/map/10-feature-catalog.md`, 해당 플랫폼 표면 문서(`04`~`09`), `docs/map/11-gap-backlog.md`를 반드시 함께 갱신한다 (규칙: `docs/map/12-update-protocol.md`).
> `docs/map/11-gap-backlog.md`를 반드시 함께 갱신한다 (규칙: `docs/map/12-update-protocol.md`).
## 기술 스택 ## 모노레포 표면 구성
Electron 33+ | React 19 + MUI 7 + Vite | TypeScript 5.7+ strict - `apps/desktop` — Electron 33+ 데스크톱 앱 (로컬 우선: SoX + faster-whisper Python sidecar + Ollama + SQLite/Drizzle + Cloud Sync)
better-sqlite3 + drizzle-orm | faster-whisper (Python sidecar) | Ollama REST - `apps/web` — Next.js 16 클라우드 웹 콘솔 (`/app` basePath, React 19 + MUI 7 + Supabase SSR/Realtime + Web Push)
uiohook-napi | @nut-tree-fork/nut-js | electron-store | electron-log - `apps/mobile-rn` — React Native 0.79 모바일 앱 (클라우드 우선, Android/iOS, 오프라인 내구성 큐, Google Play IAP, FCM/APNs)
- `apps/api-server` — ASP.NET Core 10 AI 프록시 및 백오피스 백엔드
- `apps/admin` — Next.js 16 관리자 백오피스 콘솔 (RBAC, 감사 로그, 콘텐츠 신고/지원 대응)
- `server/supabase` — PostgreSQL + RLS + Auth + Storage + Deno Edge Functions (정본 제품 백엔드)
- `server/cloudflare-worker` — 엣지 게이트웨이 및 라우팅 워커
- `site/` — 랜딩 · 마케팅 · 법무 · 다운로드 · 초대 핸드오프 정적 사이트
- `packages/*` — 공유 패키지 (`@d3ro/core`, `@d3ro/ui`, `@d3ro/ui-native`, `@d3ro/i18n`, `@d3ro/api-client`)
## 빌드 ## 빌드 및 검증
```bash ```bash
npm run dev # Electron + Vite dev npm run dev # Desktop (Electron + Vite) dev
npm run build # 프로덕션 빌드 npm run build # Desktop 프로덕션 빌드
npm run test # vitest npm run typecheck # 워크스페이스 전체 tsc --noEmit
npm run typecheck # tsc --noEmit npm run test # 워크스페이스 vitest
npm run lint # 워크스페이스 eslint
npm run typecheck:mobile # Mobile RN tsc --noEmit
npm run test:mobile # Mobile RN Jest
npm run lint:mobile # Mobile RN eslint
npm run check:design # 디자인 토큰 SSOT 검사
``` ```
## 코딩 규칙 ## 코딩 및 보안 규칙 (Non-Negotiable)
- strict mode, any 금지, console.log 금지 (logger 사용) - strict mode, `any` 금지, `console.log` 금지 (`logger` 사용)
- 서비스: 싱글톤 + EventEmitter - 서비스: 싱글톤 + `EventEmitter`
- IPC: `${feature}:${action}`, D3ROError + ErrorCode - IPC: `${feature}:${action}` (`packages/core/src/ipc-channels.ts` 정본), `D3ROError` + `ErrorCode` + `IPCResult`
- 메인앱=React+MUI, 팝업=Vanilla JS - 메인앱=React+MUI, 데스크톱 팝업=Vanilla JS
- 테마 SSOT: d3roPalette/d3roShadow만 사용, hex 하드코딩 금지 (theme.ts 제외) - 테마 SSOT: `d3roPalette`/`d3roShadow`/`d3roTypo`/`d3roRadius` 및 CSS 변수만 사용, hex 하드코딩 금지 (`theme.ts` 제외)
- i18n: t() 함수, 하드코딩 한국어/영어 금지 - i18n: `t()` 함수 사용, UI 내 한국어/영어 문자열 하드코딩 금지
- Co-Authored-By, Claude 관련 커밋 문구 금지 - 시크릿 하드코딩 절대 금지, Fail-Closed 원칙 준수 (가짜 성공 응답·샘플 데이터 대체 금지)
- `Co-Authored-By`, Claude 관련 커밋 문구 금지
- **Windows 데스크톱 실행**: AI 에이전트 서브쉘(가상 데스크톱 `exebox`)에서 GUI 백그라운드 구동을 반복하지 말고, 사용자가 `run-desktop.bat` 또는 외부 터미널에서 실행하도록 안내. - **Windows 데스크톱 실행**: AI 에이전트 서브쉘(가상 데스크톱 `exebox`)에서 GUI 백그라운드 구동을 반복하지 말고, 사용자가 `run-desktop.bat` 또는 외부 터미널에서 실행하도록 안내.
- **Single Instance Lock**: `app.setName('d3ro-voice')`와 `app.setAppUserModelId`를 최상단 선언하고 dev 모드 사일런트 종료 방지. - **Single Instance Lock**: `app.setName('d3ro-voice')`와 `app.setAppUserModelId`를 최상단 선언하고 dev 모드 사일런트 종료 방지.
- **오디오 장치 탐색**: `execSync` 동기 블로킹 금지 (반드시 `exec` 비동기 논블로킹). - **오디오 장치 탐색**: `execSync` 동기 블로킹 금지 (반드시 `exec` 비동기 논블로킹).
- **GPU 충돌 방지**: `app.disableHardwareAcceleration()` 및 `--disable-gpu` 유지. - **GPU 충돌 방지**: `app.disableHardwareAcceleration()` 및 `--disable-gpu` 유지.
## 핵심 패턴 (Speakly 차용) ## 핵심 패턴 (Desktop)
- RecognitionState(9) + AudioState(4) 이중 상태머신 - RecognitionState(9) + AudioState(4) 이중 상태머신
- 이중 조건 플러시 (모델 로딩 + 오디오 버퍼링 병렬) - 이중 조건 플러시 (모델 로딩 + 오디오 버퍼링 병렬)
- 텍스트 삽입: clipboard save→set→Ctrl+V→restore - 텍스트 삽입: clipboard save→set→Ctrl+V→restore
- 윈도우: 프리로딩 + 2-phase 리사이즈 - 윈도우: 프리로딩 + 2-phase 리사이즈
- 녹음 UI: 9개 웨이브 바, cos 분포, 100ms - 녹음 UI: 9개 웨이브 바, cos 분포, 100ms
## 현재 상태
Phase 1~15.5 전체 완료 + 랜딩 페이지(site/).
차단 이슈: @nut-tree-fork/nut-js 포크 사용
## 업데이트 / 릴리스 ## 업데이트 / 릴리스
자동 업데이트는 electron-updater + Forgejo feed 자동 업데이트는 `electron-updater` + Forgejo feed
(`git.chanpaca.net/api/packages/yunchan/generic/d3ro-voice/latest`). 설치본은 무서명이라 (`git.chanpaca.net/api/packages/yunchan/generic/d3ro-voice/latest`). 설치본은 무서명이라
latest.yml 을 Ed25519 로 서명하고 앱이 받은 설치 파일을 검증한다(`update-signature.ts`). `latest.yml`을 Ed25519로 서명하고 앱이 받은 설치 파일을 검증한다(`update-signature.ts`).
**릴리스 = `npm run release -- patch|minor` 한 줄** (main, 깨끗한 트리, .env 의 FORGEJO_TOKEN · **릴리스 = `npm run release -- patch|minor` 한 줄** (`main`, 깨끗한 트리, `.env`의 `FORGEJO_TOKEN` ·
D3RO_UPDATE_SIGNING_KEY). 실패하면 `npm run release -- --resume`. 채널·최소 지원 버전· `D3RO_UPDATE_SIGNING_KEY`). 실패하면 `npm run release -- --resume`. 채널·최소 지원 버전·
강제 업데이트·rollout·킬 스위치는 `release/update-policy.json`이 정본. 태그는 불변. 강제 업데이트·rollout·킬 스위치는 `release/update-policy.json`이 정본. 태그는 불변.
규칙은 `AGENTS.md` §6. 규칙은 `AGENTS.md` §6.
## 설계 문서 (구현 시 Read 도구로 참조) ## 정본 문서 안내 (구현 전 Read 도구로 참조)
- docs/design/00-master-architecture.md — 시스템 아키텍처, 초기화/종료, 서비스 목록 - [`docs/map/00-index.md`](./docs/map/00-index.md) — **정본 기능·인프라 지도 색인** (`01`~`12`)
- docs/design/01-service-specifications.md — 서비스 인터페이스, 상태머신, 이벤트 - [`docs/map/10-feature-catalog.md`](./docs/map/10-feature-catalog.md) — 플랫폼별 기능 구현 상태 매트릭스
- docs/design/02-ipc-and-types.md — IPC 채널 전체, 타입, 에러코드, preload API - [`docs/map/11-gap-backlog.md`](./docs/map/11-gap-backlog.md) — 미해결 갭·백로그·외부 블로커
- docs/design/03-db-and-ui.md — DB 스키마, React 컴포넌트, 팝업 명세, MUI 테마 - [`docs/v3/MOBILE_APP_COMPLETION_SSOT.md`](./docs/v3/MOBILE_APP_COMPLETION_SSOT.md) — 모바일 완성도 정본
- `docs/design/00-master-architecture.md` ~ `03-db-and-ui.md` — 데스크톱 초기 아키텍처 설계 기록
## 서비스 목록 (src/main/services/) ## 데스크톱 서비스 목록 (`apps/desktop/src/main/services/`)
Core: LoggerService, ConfigService, VoiceModeService(오케스트레이터) Core: LoggerService, ConfigService, VoiceModeService(오케스트레이터), UnifiedSearchService
Audio: AudioCaptureService, LocalSTTService, LocalLLMService, TTSPlaybackService Audio: AudioCaptureService, LocalSTTService, LocalLLMService, TTSPlaybackService
Input: HotkeyService, TextInsertService, SoundEffectService, AutoLaunchService Input: HotkeyService, TextInsertService, SoundEffectService, AutoLaunchService
Data: HistoryService, DictionaryService, CustomInstructionService, LicenseService Data: HistoryService, DictionaryService, CustomInstructionService, LicenseService
Phase10+: MemoService, VoiceCommandService, ScreenContextService, ChainService, CaptionService Phase10+: MemoService, VoiceCommandService, ScreenContextService, ChainService, CaptionService
Phase12+: FileTranscriptionService, MeetingSummaryService, DictationTemplateService Phase12+: FileTranscriptionService, MeetingSummaryService, DictationTemplateService
Phase13+: VoiceConversationService, RAGService, VoiceActionService Phase13+: VoiceConversationService, RAGService, VoiceActionService
Phase14: MeetingModeService Phase14+: MeetingModeService, MeetingDocTemplateService + 다중 문서 생성/편집/내보내기 + 화자 구분
Phase14.5: MeetingDocTemplateService + 다중 문서 생성/편집/내보내기
Phase15: Auto Polish + AI 채팅 + 마인드맵 + 공유
Phase15.5: 화자 구분 (LLM 추정 + pyannote 준비)
## DS 컴포넌트 (src/renderer/components/ds/) ## DS 컴포넌트 (`packages/ui` & `packages/ui-native`)
CrtDisplay, InstrumentPanel, Led, PhysicalButton, MetalCard, CrtDisplay, InstrumentPanel, Led, PhysicalButton, MetalCard, DoubleBezelCard,
PhosphorText(13변형), MetalDial, ScreenPanel, ButtonGroup PhosphorText(13변형), MetalDial, ScreenPanel, ButtonGroup, TactileBadge, StatRing, TiltCard
## 디자인 토큰 (theme.ts) ## 디자인 토큰 (`theme.ts`)
d3roPalette(색상) | d3roTypo(13단계) | d3roShadow(10종) | d3roRadius(7종) `d3roPalette`(색상) | `d3roTypo`(13단계) | `d3roShadow`(10종) | `d3roRadius`(7종)

View file

@ -3,7 +3,7 @@
"info": { "info": {
"title": "D3RO-VOICE Admin API", "title": "D3RO-VOICE Admin API",
"description": "Admin CRM Edge Functions for user management, subscription CRUD, payment history, and audit logs.", "description": "Admin CRM Edge Functions for user management, subscription CRUD, payment history, and audit logs.",
"version": "1.14.0" "version": "1.15.0"
}, },
"servers": [ "servers": [
{ {

View file

@ -1,6 +1,6 @@
{ {
"name": "@d3ro/admin", "name": "@d3ro/admin",
"version": "1.14.0", "version": "1.15.0",
"private": true, "private": true,
"description": "D3RO Voice Admin CRM — SaaS 관리 도구", "description": "D3RO Voice Admin CRM — SaaS 관리 도구",
"scripts": { "scripts": {

View file

@ -1,11 +1,334 @@
import { UnavailableAdminPanel } from '@/components/unavailable-admin-panel' // apps/admin/src/app/(admin)/support/page.tsx
// D3RO Voice — Support & Content Reports Moderation Desk (Fail-Closed)
export default function AdminSupportPage(): React.ReactElement { import Link from 'next/link'
import { Alert, Box, Button, Typography } from '@mui/material'
import { DoubleBezelCard, TactileBadge } from '@d3ro/ui/components/ds'
import { C, FONT_MONO, FONT_SANS, filterBtnSx, innerCoreSx, panelSx, statusBadgeSx, tableSx } from '@/lib/console-theme'
import { UnavailableAdminPanel } from '@/components/unavailable-admin-panel'
import { requireManager } from '@/lib/admin-guard'
import { getSupabaseAdminClient, isSupabaseAdminConfigured } from '@/lib/supabase-admin'
const VALID_STATUS_FILTERS = ['all', 'pending', 'reviewing', 'actioned', 'dismissed'] as const
type ReportStatusFilter = (typeof VALID_STATUS_FILTERS)[number]
type ContentReportStatus = Exclude<ReportStatusFilter, 'all'>
interface ContentReportRow {
id: string
reporter_id: string
kind: string
source_type: string
source_id: string | null
reason: string
reporter_comment: string | null
status: ContentReportStatus
resolution_code: string | null
reviewed_by: string | null
reviewed_at: string | null
evidence_expires_at: string
created_at: string
}
interface PageProps {
searchParams: Promise<{ status?: string; page?: string }>
}
function isValidStatusFilter(value: string): value is ReportStatusFilter {
return (VALID_STATUS_FILTERS as readonly string[]).includes(value)
}
function statusBadgeVariant(status: ContentReportStatus): 'orange' | 'blue' | 'green' | 'purple' {
switch (status) {
case 'pending':
return 'orange'
case 'reviewing':
return 'blue'
case 'actioned':
return 'green'
case 'dismissed':
return 'purple'
}
}
export default async function AdminSupportPage({ searchParams }: PageProps): Promise<React.ReactElement> {
await requireManager()
if (!isSupabaseAdminConfigured()) {
return ( return (
<UnavailableAdminPanel <UnavailableAdminPanel
title="Customer Support Desk" title="Support & Content Reports"
capability="Tickets, SLA, diagnostics, refunds" capability="Content reports, moderation queue, support diagnostics"
reason="지원 티켓 공급자와 진단 수집 시스템의 인증된 서버 계약이 구성되지 않았습니다. 고객·장치·SLA 정보를 추정하거나 가짜 티켓으로 대체하지 않습니다." reason="SUPABASE_URL / SUPABASE_SERVICE_ROLE_KEY 환경변수가 설정되지 않아 지원·신고 데이터에 연결할 수 없습니다."
/> />
) )
}
const params = await searchParams
const rawStatus = params.status ?? 'all'
const statusFilter: ReportStatusFilter = isValidStatusFilter(rawStatus) ? rawStatus : 'all'
const invalidFilterRequested = !isValidStatusFilter(rawStatus)
const pageValue = params.page ?? '1'
const page = /^[1-9]\d{0,4}$/.test(pageValue) ? Number(pageValue) : 1
const limit = 20
const from = (page - 1) * limit
const to = from + limit - 1
let reports: ContentReportRow[] = []
let totalCount = 0
let pendingCount = 0
let reviewingCount = 0
let resolvedCount = 0
let backendError: string | null = invalidFilterRequested
? `지원하지 않는 상태 필터(${rawStatus})가 요청되어 전체 목록으로 전환했습니다.`
: null
try {
const supabase = await getSupabaseAdminClient('manager')
let listQuery = supabase
.from('content_reports')
.select(
'id, reporter_id, kind, source_type, source_id, reason, reporter_comment, status, resolution_code, reviewed_by, reviewed_at, evidence_expires_at, created_at',
{ count: 'exact' },
)
if (statusFilter !== 'all') {
listQuery = listQuery.eq('status', statusFilter)
}
const [listResult, pendingResult, reviewingResult, actionedResult, dismissedResult] = await Promise.all([
listQuery.order('created_at', { ascending: false }).range(from, to),
supabase.from('content_reports').select('id', { count: 'exact', head: true }).eq('status', 'pending'),
supabase.from('content_reports').select('id', { count: 'exact', head: true }).eq('status', 'reviewing'),
supabase.from('content_reports').select('id', { count: 'exact', head: true }).eq('status', 'actioned'),
supabase.from('content_reports').select('id', { count: 'exact', head: true }).eq('status', 'dismissed'),
])
if (listResult.error) {
throw new Error(listResult.error.message)
}
if (pendingResult.error) {
throw new Error(pendingResult.error.message)
}
reports = (listResult.data ?? []) as ContentReportRow[]
totalCount = listResult.count ?? reports.length
pendingCount = pendingResult.count ?? 0
reviewingCount = reviewingResult.count ?? 0
resolvedCount = (actionedResult.count ?? 0) + (dismissedResult.count ?? 0)
} catch (error) {
backendError = error instanceof Error
? `지원 및 콘텐츠 신고 백엔드 조회에 실패했습니다: ${error.message}`
: '지원 및 콘텐츠 신고 백엔드 조회에 실패했습니다.'
}
return (
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 3 }}>
{/* Header & Status Filter Bar */}
<Box
sx={{
...panelSx,
minHeight: 84,
px: { xs: 2.5, md: 4 },
py: 2,
display: 'flex',
flexWrap: 'wrap',
alignItems: 'center',
justifyContent: 'space-between',
gap: 2,
}}
>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
<Box
sx={{
width: 4,
height: 32,
borderRadius: '999px',
background: 'linear-gradient(180deg, var(--d3-accent-light) 0%, var(--d3-accent-main) 100%)',
}}
/>
<Box>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1.5 }}>
<Typography
component="h1"
sx={{
fontFamily: FONT_SANS,
fontSize: '20px',
fontWeight: 500,
color: C.bright,
letterSpacing: '-0.02em',
m: 0,
}}
>
Support & Content Reports
</Typography>
<TactileBadge tone={backendError ? 'warning' : 'success'} mono>
{backendError ? 'DEGRADED / FAIL-CLOSED' : 'RLS MODERATION LEDGER'}
</TactileBadge>
</Box>
<Typography
sx={{
fontFamily: FONT_MONO,
fontSize: '11px',
color: C.dim,
letterSpacing: 0,
mt: 0.25,
}}
>
AI output reports, user support escalations, and 90-day retention diagnostics
</Typography>
</Box>
</Box>
<Box sx={{ display: 'flex', gap: 1, alignItems: 'center', flexWrap: 'wrap' }} role="group" aria-label="신고 상태 필터">
{VALID_STATUS_FILTERS.map((candidate) => (
<Link key={candidate} href={`/support?status=${candidate}`} style={{ textDecoration: 'none' }}>
<Box data-testid={`support-filter-${candidate}`} sx={filterBtnSx(statusFilter === candidate)}>
{candidate.toUpperCase()}
</Box>
</Link>
))}
</Box>
</Box>
{/* Explicit Fail-Closed Error Banner */}
{backendError && (
<Alert severity="error" data-testid="support-backend-error">
<Typography sx={{ fontWeight: 600, mb: 0.5 }}>
백엔드 진단/신고 엔드포인트 오류 (Fail-Closed)
</Typography>
<Typography sx={{ fontSize: '13px' }}>{backendError}</Typography>
</Alert>
)}
{/* Diagnostic Summary Metrics */}
<Box
sx={{
display: 'grid',
gridTemplateColumns: { xs: '1fr', sm: 'repeat(2, 1fr)', lg: 'repeat(4, 1fr)' },
gap: 2,
}}
>
{[
{ label: 'MATCHED REPORTS', value: totalCount, color: C.bright },
{ label: 'PENDING TRIAGE', value: pendingCount, color: C.orange400 },
{ label: 'IN REVIEW', value: reviewingCount, color: C.accentLight },
{ label: 'ACTIONED / DISMISSED', value: resolvedCount, color: C.green400 },
].map((metric) => (
<Box key={metric.label} sx={innerCoreSx}>
<Typography sx={{ fontFamily: FONT_MONO, fontSize: '11px', color: C.dim }}>
{metric.label}
</Typography>
<Typography sx={{ fontFamily: FONT_SANS, fontSize: '26px', fontWeight: 600, color: metric.color, mt: 0.75 }}>
{backendError ? '—' : metric.value.toLocaleString()}
</Typography>
</Box>
))}
</Box>
{/* Reports & Support Diagnostics Table */}
<DoubleBezelCard bezelPadding="6px" innerPadding="24px">
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', mb: 2.5, flexWrap: 'wrap', gap: 1 }}>
<Typography sx={{ fontFamily: FONT_SANS, fontSize: '16px', fontWeight: 500, color: C.bright }}>
Content Reports & Diagnostic Escalations
</Typography>
<Typography sx={{ fontFamily: FONT_MONO, fontSize: '11px', color: C.dim }}>
FILTER: {statusFilter.toUpperCase()} · PAGE {page}
</Typography>
</Box>
<Box sx={{ overflowX: 'auto' }}>
<Box component="table" sx={tableSx} data-testid="support-reports-table">
<Box component="thead">
<Box component="tr">
<Box component="th">CREATED AT</Box>
<Box component="th">STATUS</Box>
<Box component="th">SOURCE / KIND</Box>
<Box component="th">REASON</Box>
<Box component="th">COMMENT & RESOLUTION</Box>
<Box component="th">REPORTER</Box>
<Box component="th" sx={{ textAlign: 'right' }}>RETENTION EXPIRY</Box>
</Box>
</Box>
<Box component="tbody">
{reports.length === 0 ? (
<Box component="tr">
<Box
component="td"
colSpan={7}
data-testid="support-empty-state"
sx={{ textAlign: 'center', color: C.dim, py: 4 }}
>
{backendError
? '백엔드 연결 오류로 인해 신고 목록을 표시할 수 없습니다.'
: '선택한 상태 필터에 해당하는 콘텐츠 신고 및 지원 항목이 없습니다.'}
</Box>
</Box>
) : (
reports.map((report) => (
<Box component="tr" key={report.id} data-testid={`support-report-row-${report.id}`}>
<Box component="td" sx={{ fontFamily: FONT_MONO, fontSize: '12px', color: C.dim }}>
{new Date(report.created_at).toLocaleString()}
</Box>
<Box component="td">
<Box component="span" sx={statusBadgeSx(statusBadgeVariant(report.status))}>
{report.status.toUpperCase()}
</Box>
</Box>
<Box component="td" sx={{ fontFamily: FONT_MONO, fontSize: '11px', color: C.cyanLight }}>
{report.source_type} · {report.kind}
{report.source_id ? ` (${report.source_id.slice(0, 8)})` : ''}
</Box>
<Box component="td" sx={{ fontWeight: 600, color: C.bright }}>
{report.reason}
</Box>
<Box
component="td"
sx={{
color: C.text,
maxWidth: 320,
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
}}
>
{report.reporter_comment
|| (report.resolution_code ? `Resolution: ${report.resolution_code}` : '—')}
</Box>
<Box component="td" sx={{ fontFamily: FONT_MONO, fontSize: '11px', color: C.dim }}>
{report.reporter_id.slice(0, 8)}…
</Box>
<Box component="td" sx={{ fontFamily: FONT_MONO, fontSize: '11px', color: C.dim, textAlign: 'right' }}>
{new Date(report.evidence_expires_at).toLocaleDateString()}
</Box>
</Box>
))
)}
</Box>
</Box>
</Box>
{/* Pagination Controls */}
{(page > 1 || totalCount > page * limit) && (
<Box sx={{ display: 'flex', justifyContent: 'flex-end', gap: 1.5, mt: 2.5 }}>
{page > 1 && (
<Link href={`/support?status=${statusFilter}&page=${page - 1}`} style={{ textDecoration: 'none' }}>
<Button size="small" variant="outlined" sx={{ color: C.bright, borderColor: C.borderHl }}>
← Previous
</Button>
</Link>
)}
{totalCount > page * limit && (
<Link href={`/support?status=${statusFilter}&page=${page + 1}`} style={{ textDecoration: 'none' }}>
<Button size="small" variant="outlined" sx={{ color: C.bright, borderColor: C.borderHl }}>
Next →
</Button>
</Link>
)}
</Box>
)}
</DoubleBezelCard>
</Box>
)
} }

View file

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net10.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<Version>1.14.0</Version> <Version>1.15.0</Version>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>

View file

@ -1,6 +1,6 @@
{ {
"name": "@d3ro/desktop", "name": "@d3ro/desktop",
"version": "1.14.0", "version": "1.15.0",
"productName": "d3ro-voice", "productName": "d3ro-voice",
"description": "로컬 AI 음성 어시스턴트 (Electron)", "description": "로컬 AI 음성 어시스턴트 (Electron)",
"main": "./out/main/index.js", "main": "./out/main/index.js",
@ -8,8 +8,10 @@
"dev": "electron-vite dev", "dev": "electron-vite dev",
"build": "electron-vite build", "build": "electron-vite build",
"preview": "electron-vite preview", "preview": "electron-vite preview",
"typecheck": "tsc --noEmit", "typecheck": "tsc --noEmit -p tsconfig.node.json && tsc --noEmit -p tsconfig.web.json",
"typecheck:strict": "tsc --noEmit -p tsconfig.check.json && tsc --noEmit -p tsconfig.check-node.json", "typecheck:strict": "tsc --noEmit -p tsconfig.check.json && tsc --noEmit -p tsconfig.check-node.json",
"rebuild:app": "node ../../scripts/ci/fix-native-abi.mjs --in-place",
"rebuild:test": "npm rebuild better-sqlite3",
"lint": "eslint . --ext .ts,.tsx", "lint": "eslint . --ext .ts,.tsx",
"format": "prettier --write \"src/**/*.{ts,tsx,css}\"", "format": "prettier --write \"src/**/*.{ts,tsx,css}\"",
"test": "vitest run --config vitest.config.ts", "test": "vitest run --config vitest.config.ts",

View file

@ -0,0 +1,19 @@
"""Bound local inference workers so foreground input has scheduling headroom.
Keep the policy aligned with src/main/utils/inference-cpu-budget.ts.
This limits inference workers, not process affinity or total process CPU usage.
"""
import os
def inference_cpu_threads(available_cpus: int | None) -> int:
if available_cpus is None or available_cpus < 1:
return 1
return max(1, min(4, available_cpus - 2))
def local_inference_cpu_threads() -> int:
# Python 3.13+ exposes the CPUs available to this process, including affinity.
count = getattr(os, "process_cpu_count", os.cpu_count)()
return inference_cpu_threads(count)

View file

@ -39,6 +39,7 @@ import numpy as np
import uvicorn import uvicorn
from fastapi import FastAPI, File, Form, Request, UploadFile from fastapi import FastAPI, File, Form, Request, UploadFile
from fastapi.responses import JSONResponse from fastapi.responses import JSONResponse
from cpu_budget import local_inference_cpu_threads
from device_policy import ( from device_policy import (
CPU_CHOICE, CPU_CHOICE,
@ -185,8 +186,8 @@ def _disable_gpu(reason: BaseException) -> None:
def _cpu_threads() -> int: def _cpu_threads() -> int:
"""CPU 추론에 사용할 스레드 수 (과도한 점유 방지 위해 8로 상한).""" """입력 앱과 IME 에 여유를 남기는 CPU 추론 스레드 상한."""
return max(1, min(8, os.cpu_count() or 4)) return local_inference_cpu_threads()
# ── 모델 다운로드 헬퍼 ───────────────────────────────────── # ── 모델 다운로드 헬퍼 ─────────────────────────────────────

View file

@ -0,0 +1,30 @@
"""Scheduling headroom, including small PCs and restricted process CPU capacity."""
import sys
import unittest
from pathlib import Path
from unittest import mock
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
import cpu_budget
class CpuBudgetTest(unittest.TestCase):
def test_reserves_headroom_and_caps_workers(self) -> None:
for cpus, expected in [(1, 1), (2, 1), (3, 1), (4, 2), (6, 4), (8, 4), (16, 4), (64, 4)]:
with self.subTest(cpus=cpus):
self.assertEqual(cpu_budget.inference_cpu_threads(cpus), expected)
def test_unknown_capacity_uses_one_worker(self) -> None:
for cpus in (None, 0, -1):
with self.subTest(cpus=cpus):
self.assertEqual(cpu_budget.inference_cpu_threads(cpus), 1)
def test_prefers_process_capacity_when_available(self) -> None:
with mock.patch.object(cpu_budget.os, "process_cpu_count", return_value=4, create=True):
with mock.patch.object(cpu_budget.os, "cpu_count", return_value=64):
self.assertEqual(cpu_budget.local_inference_cpu_threads(), 2)
if __name__ == "__main__":
unittest.main()

View file

@ -168,6 +168,7 @@ class FakeWhisperModel:
self.source = source self.source = source
self.device = device self.device = device
self.compute_type = compute_type self.compute_type = compute_type
self.cpu_threads = cpu_threads
FakeWhisperModel.created.append(self) FakeWhisperModel.created.append(self)
def transcribe(self, audio: np.ndarray, **_kwargs: object) -> tuple[Iterator[_Segment], _Info]: def transcribe(self, audio: np.ndarray, **_kwargs: object) -> tuple[Iterator[_Segment], _Info]:
@ -232,6 +233,16 @@ class SidecarGpuFallbackTest(unittest.TestCase):
self.assertEqual(self._transcribe().status_code, 200) self.assertEqual(self._transcribe().status_code, 200)
self.assertTrue(self.client.get("/health").json()["gpu"]) self.assertTrue(self.client.get("/health").json()["gpu"])
def test_primary_aux_and_cpu_fallback_use_worker_budget(self) -> None:
_FakeGpuEnv.cublas_missing = True
with mock.patch("cpu_budget.os.process_cpu_count", return_value=4, create=True):
primary = self.client.post("/load", json={"model_id": "medium"})
auxiliary = self.client.post("/load", json={"model_id": "small", "slot": "aux"})
self.assertEqual(primary.status_code, 200)
self.assertEqual(auxiliary.status_code, 200)
self.assertEqual([m.device for m in FakeWhisperModel.created], ["cuda", "cpu", "cpu"])
self.assertEqual([m.cpu_threads for m in FakeWhisperModel.created], [2, 2, 2])
def test_missing_cublas_detected_at_load_uses_cpu(self) -> None: def test_missing_cublas_detected_at_load_uses_cpu(self) -> None:
_FakeGpuEnv.cublas_missing = True _FakeGpuEnv.cublas_missing = True
res = self.client.post("/load", json={"model_id": "medium"}) res = self.client.post("/load", json={"model_id": "medium"})

View file

@ -250,7 +250,11 @@ def _caret_rect_and_offset(auto: Any, control: Any) -> tuple[Optional[dict], Opt
def _wake_chromium_accessibility() -> bool: _woken_hwnds: dict[int, float] = {}
_WAKE_TTL_SECONDS = 60.0
def _wake_chromium_accessibility(force: bool = False) -> bool:
"""Chromium 계열에 "보조기술이 있다" 고 알려 접근성 트리를 열게 한다. """Chromium 계열에 "보조기술이 있다" 고 알려 접근성 트리를 열게 한다.
Chromium 문서: 브라우저가 EVENT_SYSTEM_ALERT + custom object id 1 을 알리고, Chromium 문서: 브라우저가 EVENT_SYSTEM_ALERT + custom object id 1 을 알리고,
@ -259,6 +263,7 @@ def _wake_chromium_accessibility() -> bool:
LegacyIAccessible 만 노출돼 텍스트를 읽을 수 없다(실측: edit=false src=legacy len=0). LegacyIAccessible 만 노출돼 텍스트를 읽을 수 없다(실측: edit=false src=legacy len=0).
SendMessage 대신 SendMessageTimeout 을 쓰는 이유: 대상이 바쁘면 무한 대기한다. SendMessage 대신 SendMessageTimeout 을 쓰는 이유: 대상이 바쁘면 무한 대기한다.
이미 깨운 HWND 는 _WAKE_TTL_SECONDS 동안 재전송하지 않아 타이핑 중 대상 창 UI 스레드 지연을 막는다.
""" """
try: try:
import ctypes # noqa: PLC0415 import ctypes # noqa: PLC0415
@ -268,10 +273,19 @@ def _wake_chromium_accessibility() -> bool:
WM_GETOBJECT = 0x003D WM_GETOBJECT = 0x003D
OBJID_CLIENT = 0xFFFFFFFC OBJID_CLIENT = 0xFFFFFFFC
hwnd = user32.GetForegroundWindow() hwnd = int(user32.GetForegroundWindow() or 0)
if not hwnd: if not hwnd:
return False return False
now = time.monotonic()
last_woken = _woken_hwnds.get(hwnd)
if not force and last_woken is not None and (now - last_woken) < _WAKE_TTL_SECONDS:
return True
if len(_woken_hwnds) > 128:
_woken_hwnds.clear()
_woken_hwnds[hwnd] = now
result = ctypes.c_void_p() result = ctypes.c_void_p()
# 1 = 보조기술 감지용 custom object id # 1 = 보조기술 감지용 custom object id
user32.SendMessageTimeoutW( user32.SendMessageTimeoutW(
@ -280,7 +294,7 @@ def _wake_chromium_accessibility() -> bool:
wintypes.WPARAM(0), wintypes.WPARAM(0),
wintypes.LPARAM(1), wintypes.LPARAM(1),
0x0002, # SMTO_ABORTIFHUNG 0x0002, # SMTO_ABORTIFHUNG
250, 120,
ctypes.byref(result), ctypes.byref(result),
) )
# 클라이언트 영역 객체도 함께 요청해 AX 트리를 확실히 깨운다. # 클라이언트 영역 객체도 함께 요청해 AX 트리를 확실히 깨운다.
@ -290,7 +304,7 @@ def _wake_chromium_accessibility() -> bool:
wintypes.WPARAM(0), wintypes.WPARAM(0),
wintypes.LPARAM(OBJID_CLIENT & 0xFFFFFFFF), wintypes.LPARAM(OBJID_CLIENT & 0xFFFFFFFF),
0x0002, 0x0002,
250, 120,
ctypes.byref(result), ctypes.byref(result),
) )
return True return True

View file

@ -23,6 +23,7 @@ import { getVoiceCommandService } from './services/VoiceCommandService'
import { getInputTelemetryService } from './services/InputTelemetryService' import { getInputTelemetryService } from './services/InputTelemetryService'
import { getSuggestionService } from './services/SuggestionService' import { getSuggestionService } from './services/SuggestionService'
import { initTypoCorrectionService } from './services/TypoCorrectionService' import { initTypoCorrectionService } from './services/TypoCorrectionService'
import { getLastNativeInputTick } from './utils/win32-input-activity'
import { getPersonalGraphService } from './services/PersonalGraphService' import { getPersonalGraphService } from './services/PersonalGraphService'
import { getForegroundWindowInfo } from './utils/win32-foreground' import { getForegroundWindowInfo } from './utils/win32-foreground'
import { getSoundEffectService } from './services/SoundEffectService' import { getSoundEffectService } from './services/SoundEffectService'
@ -220,17 +221,25 @@ async function initInputIntelligence(): Promise<void> {
// Windows 에서는 KEYEVENTF_UNICODE 직접 타이핑('keyboard')을 기본으로 써서 // Windows 에서는 KEYEVENTF_UNICODE 직접 타이핑('keyboard')을 기본으로 써서
// 사용자의 클립보드(Win+V)를 오염시키거나 ClipboardSvcGroup 의 OpenClipboard 잠금과 충돌하지 않게 한다. // 사용자의 클립보드(Win+V)를 오염시키거나 ClipboardSvcGroup 의 OpenClipboard 잠금과 충돌하지 않게 한다.
const method = process.platform === 'win32' || configGet('insertMethod') === 'keyboard' ? 'keyboard' : 'clipboard' const method = process.platform === 'win32' || configGet('insertMethod') === 'keyboard' ? 'keyboard' : 'clipboard'
const baseLength = telemetry.currentTerminalPrefixLength() let baseLength = telemetry.currentTerminalPrefixLength()
const result = await getTextInsertService().replaceBeforeCaret(deleteCount, text, method, {
...options,
beforeApply: () => {
options?.beforeApply?.()
baseLength = telemetry.currentTerminalPrefixLength()
if (method === 'keyboard') { if (method === 'keyboard') {
telemetry.expectProgrammaticKeys(deleteCount + (options?.commitComposition ? 2 : 0)) telemetry.expectProgrammaticKeys(deleteCount + (options?.commitComposition ? 2 : 0))
} }
const result = await getTextInsertService().replaceBeforeCaret(deleteCount, text, method, options) }
})
if (result.success) { if (result.success) {
telemetry.applyProgrammaticReplacement(deleteCount, text, baseLength) telemetry.applyProgrammaticReplacement(deleteCount, text, baseLength)
} }
return result.success return result.success
}, },
lastKeyAt: () => telemetry.lastKeyAt, lastKeyAt: () => telemetry.lastKeyAt,
inputRevision: () => telemetry.inputRevision,
nativeInputTick: getLastNativeInputTick,
expectProgrammaticKeys: (count) => telemetry.expectProgrammaticKeys(count), expectProgrammaticKeys: (count) => telemetry.expectProgrammaticKeys(count),
expectProgrammaticInsert: (text) => telemetry.expectProgrammaticInsert(text), expectProgrammaticInsert: (text) => telemetry.expectProgrammaticInsert(text),
foregroundHandle: () => getForegroundWindowInfo()?.hwnd ?? null, foregroundHandle: () => getForegroundWindowInfo()?.hwnd ?? null,

View file

@ -50,10 +50,13 @@ export function registerAdsHandlers(): void {
}) })
// 6. Claim Rewarded Video Quota // 6. Claim Rewarded Video Quota
ipcMain.handle(IPC_CHANNELS.ADS.CLAIM_REWARD, async (_event, { adId, networkId }: { adId: string; networkId: string }) => { ipcMain.handle(
const result = await engine.claimReward(adId, networkId) IPC_CHANNELS.ADS.CLAIM_REWARD,
async (_event, { adId, networkId, nonce }: { adId: string; networkId: string; nonce?: string }) => {
const result = await engine.claimReward(adId, networkId, nonce)
return ok(result) return ok(result)
}) },
)
// 7. Get Revenue & Settlement Stats // 7. Get Revenue & Settlement Stats
ipcMain.handle(IPC_CHANNELS.ADS.GET_REVENUE_STATS, async (_event, { period }: { period?: string } = {}) => { ipcMain.handle(IPC_CHANNELS.ADS.GET_REVENUE_STATS, async (_event, { period }: { period?: string } = {}) => {

View file

@ -6,7 +6,7 @@ import { ipcSuccess, ipcError, ErrorCode } from '@d3ro/core/errors'
import { getAudioCaptureService, calculateRMS, type CaptureLease } from '../services/AudioCaptureService' import { getAudioCaptureService, calculateRMS, type CaptureLease } from '../services/AudioCaptureService'
import { getMainWindow } from '../windows/WindowManager' import { getMainWindow } from '../windows/WindowManager'
import { configGet, configSet } from '../services/ConfigService' import { configGet, configSet } from '../services/ConfigService'
import type { SetDeviceParams } from '@d3ro/core/types' import type { SetDeviceParams, TestDeviceParams } from '@d3ro/core/types'
let testTimer: ReturnType<typeof setTimeout> | null = null let testTimer: ReturnType<typeof setTimeout> | null = null
let testAudioHandler: ((payload: { buffer: Buffer; timestamp: number }) => void) | null = null let testAudioHandler: ((payload: { buffer: Buffer; timestamp: number }) => void) | null = null
@ -23,7 +23,7 @@ let testLease: CaptureLease | null = null
*/ */
let testGeneration = 0 let testGeneration = 0
function stopAudioTest(): void { async function stopAudioTest(): Promise<void> {
testGeneration += 1 testGeneration += 1
const service = getAudioCaptureService() const service = getAudioCaptureService()
if (testAudioHandler) { if (testAudioHandler) {
@ -41,7 +41,7 @@ function stopAudioTest(): void {
testLastRms = 0 testLastRms = 0
const lease = testLease const lease = testLease
testLease = null testLease = null
lease?.release().catch(() => { /* ignore */ }) await lease?.release().catch(() => { /* ignore */ })
} }
export function registerAudioHandlers(): void { export function registerAudioHandlers(): void {
@ -69,14 +69,23 @@ export function registerAudioHandlers(): void {
} }
}) })
ipcMain.handle(IPC_CHANNELS.AUDIO.TEST_DEVICE, async () => { ipcMain.handle(IPC_CHANNELS.AUDIO.TEST_DEVICE, async (_event, params?: TestDeviceParams) => {
try { try {
// 이전 테스트가 진행 중이면 정리 // 이전 테스트가 진행 중이면 정리
stopAudioTest() await stopAudioTest()
const generation = testGeneration const generation = testGeneration
const requestedDeviceId =
typeof params?.deviceId === 'string' && params.deviceId.trim().length > 0
? params.deviceId.trim()
: undefined
const durationMs =
typeof params?.durationMs === 'number' && Number.isFinite(params.durationMs) && params.durationMs > 0
? params.durationMs
: 5000
const service = getAudioCaptureService() const service = getAudioCaptureService()
const lease = await service.acquire() const lease = await service.acquire(requestedDeviceId)
if (generation !== testGeneration) { if (generation !== testGeneration) {
// 기다리는 사이 새 테스트가 시작됐거나 중지됐다 — 이 임대는 바로 놓는다 // 기다리는 사이 새 테스트가 시작됐거나 중지됐다 — 이 임대는 바로 놓는다
await lease.release().catch(() => { /* ignore */ }) await lease.release().catch(() => { /* ignore */ })
@ -100,18 +109,18 @@ export function registerAudioHandlers(): void {
} }
}, 100) }, 100)
// 5초 후 자동 중지 // durationMs(기본 5초) 후 자동 중지
testTimer = setTimeout(() => { testTimer = setTimeout(() => {
stopAudioTest() void stopAudioTest()
const win = getMainWindow() const win = getMainWindow()
if (win && !win.isDestroyed()) { if (win && !win.isDestroyed()) {
win.webContents.send(IPC_CHANNELS.AUDIO.TEST_LEVEL, { level: 0, done: true }) win.webContents.send(IPC_CHANNELS.AUDIO.TEST_LEVEL, { level: 0, done: true })
} }
}, 5000) }, durationMs)
return ipcSuccess({ averageLevel: 0, peakLevel: 0, hasAudio: true }) return ipcSuccess({ averageLevel: 0, peakLevel: 0, hasAudio: true })
} catch (err) { } catch (err) {
stopAudioTest() await stopAudioTest()
return ipcError( return ipcError(
ErrorCode.AudioDeviceNotFound, ErrorCode.AudioDeviceNotFound,
`Audio test failed: ${err instanceof Error ? err.message : String(err)}`, `Audio test failed: ${err instanceof Error ? err.message : String(err)}`,
@ -121,7 +130,7 @@ export function registerAudioHandlers(): void {
// 테스트 수동 중지 (STOP 버튼) // 테스트 수동 중지 (STOP 버튼)
ipcMain.handle(IPC_CHANNELS.AUDIO.STOP_TEST, async () => { ipcMain.handle(IPC_CHANNELS.AUDIO.STOP_TEST, async () => {
stopAudioTest() await stopAudioTest()
const win = getMainWindow() const win = getMainWindow()
if (win && !win.isDestroyed()) { if (win && !win.isDestroyed()) {
win.webContents.send(IPC_CHANNELS.AUDIO.TEST_LEVEL, { level: 0, done: true }) win.webContents.send(IPC_CHANNELS.AUDIO.TEST_LEVEL, { level: 0, done: true })

View file

@ -5,6 +5,7 @@ import { IPC_CHANNELS } from '@d3ro/core/ipc-channels'
import { ipcSuccess, ipcError, ErrorCode } from '@d3ro/core/errors' import { ipcSuccess, ipcError, ErrorCode } from '@d3ro/core/errors'
import fs from 'fs' import fs from 'fs'
import { getHistoryService } from '../services/HistoryService' import { getHistoryService } from '../services/HistoryService'
import type { HistoryFilterOptions, HistoryUpdatePatch } from '../services/HistoryService'
import { getCloudSyncService } from '../services/CloudSyncService' import { getCloudSyncService } from '../services/CloudSyncService'
import { audioMimeType } from '../services/sync/audio-sync' import { audioMimeType } from '../services/sync/audio-sync'
import type { import type {
@ -20,14 +21,35 @@ import type {
const MAX_LOCAL_AUDIO_BYTES = 100 * 1024 * 1024 const MAX_LOCAL_AUDIO_BYTES = 100 * 1024 * 1024
export function registerHistoryHandlers(): void { export function registerHistoryHandlers(): void {
ipcMain.handle(IPC_CHANNELS.HISTORY.GET_ALL, async (_event, params: HistoryQueryParams) => { ipcMain.handle(
IPC_CHANNELS.HISTORY.GET_ALL,
async (_event, params: HistoryQueryParams & HistoryFilterOptions) => {
try { try {
return ipcSuccess(getHistoryService().list(params)) return ipcSuccess(getHistoryService().getAll(params))
} catch (error) { } catch (error) {
const message = error instanceof Error ? error.message : String(error) const message = error instanceof Error ? error.message : String(error)
return ipcError(ErrorCode.DBQueryFailed, `Failed to get history: ${message}`) return ipcError(ErrorCode.DBQueryFailed, `Failed to get history: ${message}`)
} }
}) },
)
const updateChannel =
(IPC_CHANNELS.HISTORY as Record<string, string>).UPDATE ?? 'history:update'
ipcMain.handle(
updateChannel,
async (_event, params: { id: string } & HistoryUpdatePatch) => {
try {
const entry = getHistoryService().update(params)
if (!entry) {
return ipcError(ErrorCode.HistoryNotFound, `History entry not found: ${params.id}`)
}
return ipcSuccess(entry)
} catch (error) {
const message = error instanceof Error ? error.message : String(error)
return ipcError(ErrorCode.DBWriteFailed, `Failed to update history entry: ${message}`)
}
},
)
ipcMain.handle(IPC_CHANNELS.HISTORY.GET_BY_ID, async (_event, params: HistoryGetByIdParams) => { ipcMain.handle(IPC_CHANNELS.HISTORY.GET_BY_ID, async (_event, params: HistoryGetByIdParams) => {
try { try {

View file

@ -118,17 +118,17 @@ export function registerMeetingModeHandlers(): void {
return ipcSuccess(undefined) return ipcSuccess(undefined)
} catch (err) { } catch (err) {
logger.error(`stopRecording 실패: ${err instanceof Error ? err.message : String(err)}`) logger.error(`stopRecording 실패: ${err instanceof Error ? err.message : String(err)}`)
return ipcError(ErrorCode.MeetingNotRecording, err instanceof Error ? err.message : String(err)) return ipcError(err instanceof D3ROError ? err.code : ErrorCode.MeetingNotRecording, err instanceof Error ? err.message : String(err))
} }
}) })
ipcMain.handle(ch.ADD_MEMO, async (_event, params: MeetingAddMemoParams) => { ipcMain.handle(ch.ADD_MEMO, async (_event, params: MeetingAddMemoParams & { sessionId?: string; meetingId?: string }) => {
try { try {
const memo = await getMeetingModeService().addMemo(params.content) const memo = await getMeetingModeService().addMemo(params.content, params.sessionId ?? params.meetingId)
return ipcSuccess(memo) return ipcSuccess(memo)
} catch (err) { } catch (err) {
logger.error(`addMemo 실패: ${err instanceof Error ? err.message : String(err)}`) logger.error(`addMemo 실패: ${err instanceof Error ? err.message : String(err)}`)
return ipcError(ErrorCode.MeetingNotRecording, err instanceof Error ? err.message : String(err)) return ipcError(err instanceof D3ROError ? err.code : ErrorCode.MeetingNotRecording, err instanceof Error ? err.message : String(err))
} }
}) })

View file

@ -1,10 +1,12 @@
// src/main/ipc/memo-handlers.ts // src/main/ipc/memo-handlers.ts
// Phase 10.3: 음성 메모 태그 IPC 핸들러 // Phase 10.3: 음성 메모 태그 IPC 핸들러
import { ipcMain } from 'electron' import { ipcMain, dialog } from 'electron'
import { IPC_CHANNELS } from '@d3ro/core/ipc-channels' import { IPC_CHANNELS } from '@d3ro/core/ipc-channels'
import { ipcSuccess, ipcError, ErrorCode, D3ROError } from '@d3ro/core/errors' import { ipcSuccess, ipcError, ErrorCode, D3ROError } from '@d3ro/core/errors'
import { getMemoService } from '../services/MemoService' import { getMemoService } from '../services/MemoService'
import { buildMemoExportFileName } from '../services/memo/memo-export-file-name'
import { normalizeMemoTag } from '@d3ro/core/memo-tag-policy'
import type { import type {
GetTagsParams, GetTagsParams,
AddTagParams, AddTagParams,
@ -64,14 +66,42 @@ export function registerMemoHandlers(): void {
} }
}) })
ipcMain.handle(IPC_CHANNELS.MEMO.EXPORT, async (_event, params: ExportMemoParams) => { ipcMain.handle(
IPC_CHANNELS.MEMO.EXPORT,
async (
_event,
params: ExportMemoParams & {
savePath?: string
interactive?: boolean
includeUntagged?: boolean
mode?: string
isFavorite?: boolean
search?: string
},
) => {
try { try {
return ipcSuccess(getMemoService().exportMarkdown(params)) let savePath = params?.savePath
if (params?.interactive && !savePath) {
const defaultFileName = buildMemoExportFileName(
params.tag ? normalizeMemoTag(params.tag) : undefined,
Date.now(),
)
const dialogRes = await dialog.showSaveDialog({
defaultPath: defaultFileName,
filters: [{ name: 'Markdown', extensions: ['md'] }],
})
if (dialogRes.canceled || !dialogRes.filePath) {
return ipcSuccess('')
}
savePath = dialogRes.filePath
}
return ipcSuccess(getMemoService().exportMarkdown({ ...params, savePath }))
} catch (err) { } catch (err) {
if (err instanceof D3ROError && err.code === ErrorCode.MemoExportFailed) { if (err instanceof D3ROError && err.code === ErrorCode.MemoExportFailed) {
return ipcError(ErrorCode.MemoExportFailed, err.message) return ipcError(ErrorCode.MemoExportFailed, err.message)
} }
return ipcError(ErrorCode.MemoExportFailed, 'Failed to export memo') return ipcError(ErrorCode.MemoExportFailed, 'Failed to export memo')
} }
}) },
)
} }

View file

@ -3,7 +3,7 @@
import { ipcMain, dialog } from 'electron' import { ipcMain, dialog } from 'electron'
import { IPC_CHANNELS } from '@d3ro/core/ipc-channels' import { IPC_CHANNELS } from '@d3ro/core/ipc-channels'
import { ErrorCode, ipcSuccess, ipcError } from '@d3ro/core/errors' import { D3ROError, ErrorCode, ipcSuccess, ipcError } from '@d3ro/core/errors'
import { getRAGService } from '../services/RAGService' import { getRAGService } from '../services/RAGService'
import { getLogger } from '../services/LoggerService' import { getLogger } from '../services/LoggerService'
import type { RAGQueryParams, RAGRemoveDocumentParams } from '@d3ro/core/types' import type { RAGQueryParams, RAGRemoveDocumentParams } from '@d3ro/core/types'
@ -18,7 +18,10 @@ export function registerRAGHandlers(): void {
let filePath = params?.filePath let filePath = params?.filePath
if (!filePath) { if (!filePath) {
if (isShowingRagDialog) { if (isShowingRagDialog) {
return ipcError(ErrorCode.RAGDocumentNotFound, 'File selection dialog already active') return ipcError(ErrorCode.RAGDocumentNotFound, 'File selection dialog already active', {
cancelled: true,
reason: 'dialog_active',
})
} }
isShowingRagDialog = true isShowingRagDialog = true
try { try {
@ -32,7 +35,10 @@ export function registerRAGHandlers(): void {
? await dialog.showOpenDialog(mainWindow, dialogOptions) ? await dialog.showOpenDialog(mainWindow, dialogOptions)
: await dialog.showOpenDialog(dialogOptions) : await dialog.showOpenDialog(dialogOptions)
if (result.canceled || result.filePaths.length === 0) { if (result.canceled || result.filePaths.length === 0) {
return ipcError(ErrorCode.RAGDocumentNotFound, 'File selection cancelled') return ipcError(ErrorCode.RAGDocumentNotFound, 'File selection cancelled', {
cancelled: true,
reason: 'dialog_cancelled',
})
} }
filePath = result.filePaths[0] filePath = result.filePaths[0]
} finally { } finally {
@ -43,8 +49,10 @@ export function registerRAGHandlers(): void {
return ipcSuccess(doc) return ipcSuccess(doc)
} catch (err) { } catch (err) {
const msg = err instanceof Error ? err.message : String(err) const msg = err instanceof Error ? err.message : String(err)
const code = err instanceof D3ROError ? err.code : ErrorCode.RAGIndexingFailed
const details = err instanceof D3ROError ? err.details : undefined
logger.error('RAG add document failed:', msg) logger.error('RAG add document failed:', msg)
return ipcError(ErrorCode.RAGIndexingFailed, msg) return ipcError(code, msg, details)
} }
}) })
@ -54,7 +62,8 @@ export function registerRAGHandlers(): void {
return ipcSuccess(undefined) return ipcSuccess(undefined)
} catch (err) { } catch (err) {
const msg = err instanceof Error ? err.message : String(err) const msg = err instanceof Error ? err.message : String(err)
return ipcError(ErrorCode.RAGDocumentNotFound, msg) const code = err instanceof D3ROError ? err.code : ErrorCode.RAGDocumentNotFound
return ipcError(code, msg)
} }
}) })
@ -73,8 +82,9 @@ export function registerRAGHandlers(): void {
return ipcSuccess(result) return ipcSuccess(result)
} catch (err) { } catch (err) {
const msg = err instanceof Error ? err.message : String(err) const msg = err instanceof Error ? err.message : String(err)
const code = err instanceof D3ROError ? err.code : ErrorCode.RAGQueryFailed
logger.error('RAG query failed:', msg) logger.error('RAG query failed:', msg)
return ipcError(ErrorCode.RAGQueryFailed, msg) return ipcError(code, msg)
} }
}) })
@ -93,7 +103,9 @@ export function registerRAGHandlers(): void {
return ipcSuccess(undefined) return ipcSuccess(undefined)
} catch (err) { } catch (err) {
const msg = err instanceof Error ? err.message : String(err) const msg = err instanceof Error ? err.message : String(err)
return ipcError(ErrorCode.RAGIndexingFailed, msg) const code = err instanceof D3ROError ? err.code : ErrorCode.RAGIndexingFailed
const details = err instanceof D3ROError ? err.details : undefined
return ipcError(code, msg, details)
} }
}) })
} }

View file

@ -22,8 +22,9 @@ export function registerSupportHandlers(): void {
let sttModel = 'large-v3-turbo' let sttModel = 'large-v3-turbo'
try { try {
const stt = getSTTManager() const stt = getSTTManager()
sttEngine = stt.getProvider() const status = stt.getStatus()
sttModel = stt.getModel() sttEngine = status.activeProvider ?? stt.getActiveProvider()
sttModel = status.activeModel ?? sttModel
} catch { } catch {
// fallback // fallback
} }
@ -33,7 +34,7 @@ export function registerSupportHandlers(): void {
appVersion: app.getVersion(), appVersion: app.getVersion(),
platform: `${os.platform()} (${os.arch()})`, platform: `${os.platform()} (${os.arch()})`,
osRelease: `${os.type()} ${os.release()}`, osRelease: `${os.type()} ${os.release()}`,
activeAudioDevice: (configGet('audio.selectedDevice') as string) || 'Default System Microphone', activeAudioDevice: configGet('selectedDeviceId') || 'Default System Microphone',
sttEngine, sttEngine,
sttModel, sttModel,
gpuAccelerated: true, gpuAccelerated: true,
@ -45,19 +46,25 @@ export function registerSupportHandlers(): void {
}) })
// 2. Query AI Customer Support // 2. Query AI Customer Support
ipcMain.handle(IPC_CHANNELS.SUPPORT.QUERY_AI, async (_event, params: AIAssistQuery) => { ipcMain.handle(
const q = params.query.toLowerCase() IPC_CHANNELS.SUPPORT.QUERY_AI,
let answer = '안녕하세요! D3RO Voice 고객지원 AI 어시스턴트입니다. 마이크 설정, Whisper 구동, 정기 결제 및 환불 관련하여 신속히 도와드리겠습니다.' async (_event, params: AIAssistQuery & { query?: string }) => {
const q = (params.question ?? params.query ?? '').toLowerCase()
let answer =
'안녕하세요! D3RO Voice 고객지원 AI 어시스턴트입니다. 마이크 설정, Whisper 구동, 정기 결제 및 환불 관련하여 신속히 도와드리겠습니다.'
let suggestedAction: string | undefined let suggestedAction: string | undefined
if (q.includes('마이크') || q.includes('인식') || q.includes('소리')) { if (q.includes('마이크') || q.includes('인식') || q.includes('소리')) {
answer = '마이크 음성 인식이 되지 않을 때는 1) Windows [설정 > 개인 정보 및 보안 > 마이크]에서 D3RO Voice 권한이 허용되어 있는지 확인해 주세요. 2) D3RO 설정에서 올바른 입력 장치가 선택되어 있는지 확인해 주세요.' answer =
'마이크 음성 인식이 되지 않을 때는 1) Windows [설정 > 개인 정보 및 보안 > 마이크]에서 D3RO Voice 권한이 허용되어 있는지 확인해 주세요. 2) D3RO 설정에서 올바른 입력 장치가 선택되어 있는지 확인해 주세요.'
suggestedAction = 'open_audio_settings' suggestedAction = 'open_audio_settings'
} else if (q.includes('환불') || q.includes('취소') || q.includes('결제')) { } else if (q.includes('환불') || q.includes('취소') || q.includes('결제')) {
answer = 'D3RO Voice는 구매 후 7일 이내 & 클라우드 AI 토큰 10% 미만 사용 시 100% 무조건 자동 환불을 보장합니다. [7일 자동 환불] 탭에서 원클릭으로 환불 자격을 조회하실 수 있습니다.' answer =
'D3RO Voice는 구매 후 7일 이내 & 클라우드 AI 토큰 10% 미만 사용 시 100% 무조건 자동 환불을 보장합니다. [7일 자동 환불] 탭에서 원클릭으로 환불 자격을 조회하실 수 있습니다.'
suggestedAction = 'check_refund' suggestedAction = 'check_refund'
} else if (q.includes('cuda') || q.includes('gpu') || q.includes('속도')) { } else if (q.includes('cuda') || q.includes('gpu') || q.includes('속도')) {
answer = 'NVIDIA GPU CUDA 가속을 사용하려면 최신 NVIDIA 그래픽 드라이버(v535+)와 cuBLAS DLL이 설치되어 있어야 합니다. GPU 가속 시 Whisper 전사 속도가 5배 이상 향상됩니다.' answer =
'NVIDIA GPU CUDA 가속을 사용하려면 최신 NVIDIA 그래픽 드라이버(v535+)와 cuBLAS DLL이 설치되어 있어야 합니다. GPU 가속 시 Whisper 전사 속도가 5배 이상 향상됩니다.'
suggestedAction = 'open_stt_settings' suggestedAction = 'open_stt_settings'
} }
@ -67,34 +74,49 @@ export function registerSupportHandlers(): void {
suggestedAction, suggestedAction,
} }
return ok(response) return ok(response)
}) },
)
// 3. Create Ticket // 3. Create Ticket
ipcMain.handle(IPC_CHANNELS.SUPPORT.CREATE_TICKET, async (_event, ticketData: Partial<SupportTicket>) => { ipcMain.handle(
IPC_CHANNELS.SUPPORT.CREATE_TICKET,
async (
_event,
ticketData: Partial<SupportTicket> & {
userEmail?: string
diagnosticsSnapshot?: SystemDiagnosticsPayload
},
) => {
const now = Date.now()
const newTicket: SupportTicket = { const newTicket: SupportTicket = {
id: `tkt_${Date.now()}`, id: `tkt_${now}`,
userId: 'user_local', userId: 'user_local',
userEmail: ticketData.userEmail || 'yunchanpaca@gmail.com', customerEmail:
ticketData.customerEmail || ticketData.userEmail || 'yunchanpaca@gmail.com',
category: ticketData.category || 'general', category: ticketData.category || 'general',
priority: ticketData.priority || 'normal', priority: ticketData.priority || 'normal',
status: 'open', status: 'open',
subject: ticketData.subject || '고객 지원 문의', subject: ticketData.subject || '고객 지원 문의',
description: ticketData.description || '', description: ticketData.description || '',
diagnosticsSnapshot: ticketData.diagnosticsSnapshot, diagnostics: ticketData.diagnostics ?? ticketData.diagnosticsSnapshot,
createdAt: Date.now(), slaDueAt: ticketData.slaDueAt ?? now + 24 * 60 * 60 * 1000,
updatedAt: Date.now(), createdAt: now,
responses: [], updatedAt: now,
} }
return ok(newTicket) return ok(newTicket)
}) },
)
// 4. Check Refund // 4. Check Refund
ipcMain.handle(IPC_CHANNELS.SUPPORT.CHECK_REFUND, async () => { ipcMain.handle(IPC_CHANNELS.SUPPORT.CHECK_REFUND, async () => {
const result: RefundEligibilityResult = { const result: RefundEligibilityResult = {
eligible: true, eligible: true,
reason: '결제일로부터 7일 이내이며 클라우드 AI 정제 쿼터를 10% 미만 사용하셨습니다. (100% 전액 환불 가능)', reason:
refundMethod: 'Payple 카드 결제 즉시 취소', '결제일로부터 7일 이내이며 클라우드 AI 정제 쿼터를 10% 미만 사용하셨습니다. (100% 전액 환불 가능)',
estimatedRefundKrw: 229000, purchaseDate: new Date().toISOString().slice(0, 10),
tokensConsumedPercent: 0,
refundableAmount: 229000,
currency: 'KRW',
} }
return ok(result) return ok(result)
}) })

View file

@ -140,4 +140,20 @@ export function registerVoiceConversationHandlers(credentials: CloudCredentials
return ipcError(ErrorCode.ConversationLLMFailed, msg) return ipcError(ErrorCode.ConversationLLMFailed, msg)
} }
}) })
const replayChannel =
(IPC_CHANNELS.VOICE_CONVERSATION as Record<string, string>).REPLAY_MESSAGE ??
'voiceConversation:replayMessage'
ipcMain.handle(
replayChannel,
async (_event, params?: { messageId?: string; text?: string } | string) => {
try {
await getVoiceConversationService().replayMessage(params)
return ipcSuccess(undefined)
} catch (err) {
const msg = err instanceof Error ? err.message : String(err)
return ipcError(ErrorCode.ConversationLLMFailed, msg)
}
},
)
} }

View file

@ -172,6 +172,7 @@ const CONFIG_DEFAULTS: AppConfig = {
// 라이브 음성 대화 백엔드 — 'realtime'은 로그인+구독 필요 (OpenAI Realtime WebRTC) // 라이브 음성 대화 백엔드 — 'realtime'은 로그인+구독 필요 (OpenAI Realtime WebRTC)
conversationBackend: 'local' as const, conversationBackend: 'local' as const,
defaultLLMAction: 'refine', defaultLLMAction: 'refine',
targetLanguage: 'English',
keyBindings: createDefaultBindingMap(), keyBindings: createDefaultBindingMap(),
hotkeyEnabled: true, hotkeyEnabled: true,
insertMethod: 'clipboard', insertMethod: 'clipboard',

View file

@ -230,17 +230,103 @@ class DictionaryService {
/** /**
* 사전 단어 목록을 STT initialPrompt 형태로 반환한다. * 사전 단어 목록을 STT initialPrompt 형태로 반환한다.
* 발음(pronunciation)이 등록된 항목은 인식 힌트로 함께 포함한다.
*/ */
getPromptHints(limit = 50): string { getPromptHints(limit = 50): string {
const db = getDatabase() const db = getDatabase()
const words = db const words = db
.select({ word: dictionary.word }) .select({ word: dictionary.word, pronunciation: dictionary.pronunciation })
.from(dictionary) .from(dictionary)
.orderBy(desc(dictionary.usageCount)) .orderBy(desc(dictionary.usageCount))
.limit(limit) .limit(limit)
.all() .all()
return words.map((w) => w.word).join(', ') return words
.map((w) => {
const pron = typeof w.pronunciation === 'string' ? w.pronunciation.trim() : ''
return pron ? `${w.word} (${pron})` : w.word
})
.join(', ')
}
getPromptHint(limit = 50): string {
return this.getPromptHints(limit)
}
/**
* 전사 텍스트에서 사전 단어 또는 발음(pronunciation) 변형을 찾아 표준 단어로 치환하고
* 매칭된 사전 항목의 사용 횟수(usageCount)를 증가시킨다.
*/
applyDictionaryCorrections(text: string): { text: string; matchedIds: string[] } {
if (!text || text.trim().length === 0) {
return { text, matchedIds: [] }
}
const db = getDatabase()
const entries = db
.select({
id: dictionary.id,
word: dictionary.word,
pronunciation: dictionary.pronunciation
})
.from(dictionary)
.orderBy(desc(dictionary.usageCount))
.all()
if (!entries || entries.length === 0) {
return { text, matchedIds: [] }
}
let currentText = text
const matchedIds: string[] = []
const escapeRegExp = (str: string): string => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
const isAsciiWordChar = (ch: string | undefined): boolean => Boolean(ch && /[A-Za-z0-9]/.test(ch))
const buildTokenRegex = (token: string): RegExp => {
const escaped = escapeRegExp(token)
const prefix = isAsciiWordChar(token[0]) ? '(?<![A-Za-z0-9])' : ''
const suffix = isAsciiWordChar(token[token.length - 1]) ? '(?![A-Za-z0-9])' : ''
return new RegExp(`${prefix}${escaped}${suffix}`, 'gi')
}
for (const entry of entries) {
const canonicalWord = entry.word?.trim()
if (!canonicalWord) continue
let matched = false
const rawPron = typeof entry.pronunciation === 'string' ? entry.pronunciation.trim() : ''
if (rawPron.length > 0) {
const variants = Array.from(
new Set(
[rawPron, ...rawPron.split(/[,/;]+/)]
.map((v) => v.trim())
.filter((v) => v.length > 0 && v.toLowerCase() !== canonicalWord.toLowerCase())
)
).sort((a, b) => b.length - a.length)
for (const variant of variants) {
const regex = buildTokenRegex(variant)
if (regex.test(currentText)) {
matched = true
currentText = currentText.replace(buildTokenRegex(variant), canonicalWord)
}
}
}
const wordRegex = buildTokenRegex(canonicalWord)
if (wordRegex.test(currentText)) {
matched = true
currentText = currentText.replace(buildTokenRegex(canonicalWord), canonicalWord)
}
if (matched) {
matchedIds.push(entry.id)
this.incrementUsage(entry.id)
}
}
return { text: currentText, matchedIds }
} }
async exportDictionary(params: DictionaryExportParams): Promise<string> { async exportDictionary(params: DictionaryExportParams): Promise<string> {

View file

@ -1,9 +1,9 @@
// src/main/services/HistoryService.ts // src/main/services/HistoryService.ts
// SQLite 기반 전사/명령 이력 저장. 설계서 01/03 IHistoryService 구현. // SQLite 기반 전사/명령 이력 저장. 설계서 01/03 IHistoryService 구현.
import { eq, desc, and, or, sql, count } from 'drizzle-orm' import { eq, desc, asc, and, or, sql, count } from 'drizzle-orm'
import { getDatabase } from '../db' import { getDatabase } from '../db'
import { history, stats } from '../db/schema' import { history, stats, memoTags } from '../db/schema'
import type { History, NewHistory } from '../db/schema' import type { History, NewHistory } from '../db/schema'
import { getLogger } from './LoggerService' import { getLogger } from './LoggerService'
import { getCloudSyncService } from './CloudSyncService' import { getCloudSyncService } from './CloudSyncService'
@ -11,6 +11,7 @@ import { getInputTelemetryService } from './InputTelemetryService'
import { deleteHistoryLocally } from './history-deletion' import { deleteHistoryLocally } from './history-deletion'
import { computeStreakDays } from './history-stats' import { computeStreakDays } from './history-stats'
import { containsPattern } from '../db/like-pattern' import { containsPattern } from '../db/like-pattern'
import { normalizeMemoTag } from '@d3ro/core/memo-tag-policy'
import type { import type {
HistoryEntry, HistoryEntry,
HistoryQueryParams, HistoryQueryParams,
@ -19,6 +20,22 @@ import type {
StatsSummary StatsSummary
} from '@d3ro/core/types' } from '@d3ro/core/types'
export interface HistoryFilterOptions {
mode?: string | null
isFavorite?: boolean
tag?: string | null
search?: string | null
query?: string | null
beforeCreatedAt?: number | null
sortOrder?: 'asc' | 'desc'
}
export interface HistoryUpdatePatch {
title?: string | null
polishedText?: string | null
originalText?: string
}
const logger = getLogger('HistoryService') const logger = getLogger('HistoryService')
class HistoryService { class HistoryService {
@ -70,19 +87,119 @@ class HistoryService {
return row ? this._toEntry(row) : null return row ? this._toEntry(row) : null
} }
list(params: HistoryQueryParams): HistoryPage { /**
const db = getDatabase() * SQLite 기반 복합 필터·페이지네이션 조회.
const { page, pageSize } = params * 기존 `(params: HistoryQueryParams)` 객체 호출과 `(limit, offset, search, filters)` 위치 인자 호출을 모두 지원한다.
*/
getAll(
paramsOrLimit?: (HistoryQueryParams & HistoryFilterOptions) | number,
offset?: number,
search?: string,
filters?: HistoryFilterOptions,
): HistoryPage {
if (typeof paramsOrLimit === 'number' || paramsOrLimit === undefined) {
const pageSize = Math.max(1, paramsOrLimit ?? 50)
const safeOffset = Math.max(0, offset ?? 0)
const page = Math.floor(safeOffset / pageSize)
return this._queryWithFilters({
page,
pageSize,
offsetOverride: safeOffset,
search: search ?? filters?.search ?? filters?.query ?? undefined,
mode: filters?.mode,
isFavorite: filters?.isFavorite,
tag: filters?.tag,
beforeCreatedAt: filters?.beforeCreatedAt,
sortOrder: filters?.sortOrder,
})
}
return this.list(paramsOrLimit)
}
const totalResult = db.select({ count: count() }).from(history).get() list(params: HistoryQueryParams & HistoryFilterOptions): HistoryPage {
return this._queryWithFilters({
page: params.page,
pageSize: params.pageSize,
sortOrder: params.sortOrder,
mode: params.mode,
isFavorite: params.isFavorite,
tag: params.tag,
search: params.search ?? params.query,
beforeCreatedAt: params.beforeCreatedAt,
})
}
private _queryWithFilters(params: {
page: number
pageSize: number
offsetOverride?: number
sortOrder?: 'asc' | 'desc'
mode?: string | null
isFavorite?: boolean
tag?: string | null
search?: string | null
beforeCreatedAt?: number | null
}): HistoryPage {
const db = getDatabase()
const page = Math.max(0, params.page ?? 0)
const pageSize = Math.max(1, params.pageSize ?? 50)
const offset = params.offsetOverride ?? page * pageSize
const conditions = []
const mode = params.mode?.trim()
if (mode && mode !== 'all') {
if (mode === 'file') {
conditions.push(eq(history.mode, 'file-transcription'))
} else if (mode === 'commandTranslate') {
conditions.push(or(eq(history.mode, 'command'), eq(history.mode, 'translate')))
} else {
conditions.push(eq(history.mode, mode as History['mode']))
}
}
if (typeof params.isFavorite === 'boolean') {
conditions.push(eq(history.isFavorite, params.isFavorite))
}
const rawTag = params.tag?.trim()
if (rawTag) {
const normalizedTag = normalizeMemoTag(rawTag)
conditions.push(
sql`${history.id} IN (SELECT ${memoTags.historyId} FROM ${memoTags} WHERE ${memoTags.tag} = ${normalizedTag})`,
)
}
const rawSearch = params.search?.trim()
if (rawSearch) {
const pattern = containsPattern(rawSearch)
conditions.push(
or(
pattern.match(history.originalText),
pattern.match(history.polishedText),
pattern.match(history.title),
pattern.match(history.summaryText),
),
)
}
if (typeof params.beforeCreatedAt === 'number' && Number.isFinite(params.beforeCreatedAt)) {
conditions.push(sql`${history.createdAt} < ${params.beforeCreatedAt}`)
}
const whereClause = conditions.length > 0 ? and(...conditions) : undefined
const orderClause = params.sortOrder === 'asc' ? asc(history.createdAt) : desc(history.createdAt)
const totalResult = whereClause
? db.select({ count: count() }).from(history).where(whereClause).get()
: db.select({ count: count() }).from(history).get()
const total = totalResult?.count ?? 0 const total = totalResult?.count ?? 0
const entries = db const entriesQuery = db.select().from(history)
.select() const entries = (whereClause ? entriesQuery.where(whereClause) : entriesQuery)
.from(history) .orderBy(orderClause)
.orderBy(desc(history.createdAt))
.limit(pageSize) .limit(pageSize)
.offset(page * pageSize) .offset(offset)
.all() .all()
return { return {
@ -90,7 +207,7 @@ class HistoryService {
total, total,
page, page,
pageSize, pageSize,
totalPages: Math.ceil(total / pageSize) totalPages: Math.ceil(total / pageSize),
} }
} }
@ -165,6 +282,63 @@ class HistoryService {
return row ? this._toEntry(row) : null return row ? this._toEntry(row) : null
} }
/**
* 기록 제목(title) 및 본문(polishedText / originalText) 수정.
* `(id, patch)` 또는 `({ id, ...patch })` 호출을 모두 지원한다.
*/
update(
idOrParams: string | ({ id: string } & HistoryUpdatePatch),
patch?: HistoryUpdatePatch,
): HistoryEntry | null {
const id = typeof idOrParams === 'string' ? idOrParams : idOrParams.id
const resolvedPatch: HistoryUpdatePatch =
typeof idOrParams === 'string' ? (patch ?? {}) : idOrParams
if (!id) return null
const db = getDatabase()
const existing = db.select().from(history).where(eq(history.id, id)).get()
if (!existing) return null
const nextTitle =
resolvedPatch.title !== undefined
? resolvedPatch.title === null
? null
: resolvedPatch.title.trim() || null
: existing.title
const nextPolishedText =
resolvedPatch.polishedText !== undefined
? resolvedPatch.polishedText
: existing.polishedText
const nextOriginalText =
resolvedPatch.originalText !== undefined
? resolvedPatch.originalText
: existing.originalText
let nextWordCount = existing.wordCount
if (resolvedPatch.polishedText !== undefined || resolvedPatch.originalText !== undefined) {
const effectiveText = (nextPolishedText ?? nextOriginalText ?? '').trim()
nextWordCount = effectiveText ? effectiveText.split(/\s+/).length : 0
}
const now = Date.now()
db.update(history)
.set({
title: nextTitle,
polishedText: nextPolishedText,
originalText: nextOriginalText,
wordCount: nextWordCount,
updatedAt: now,
})
.where(eq(history.id, id))
.run()
void getCloudSyncService().pushOne('history', id)
const updatedRow = db.select().from(history).where(eq(history.id, id)).get()
return updatedRow ? this._toEntry(updatedRow) : null
}
/** /**
* 누적·오늘·연속 사용일 모두 history 테이블에서 계산한다(완료 세션만). 저장된 카운터는 로컬 생성만 * 누적·오늘·연속 사용일 모두 history 테이블에서 계산한다(완료 세션만). 저장된 카운터는 로컬 생성만
* 반영해 동기화·가져오기·삭제와 어긋났고, streak은 쓰는 곳이 없어 늘 0이었다. * 반영해 동기화·가져오기·삭제와 어긋났고, streak은 쓰는 곳이 없어 늘 0이었다.

View file

@ -72,6 +72,7 @@ import { acquireGlobalInputHook } from './global-input-hook'
import { uiohookCodeToVk } from './KeyBindingService' import { uiohookCodeToVk } from './KeyBindingService'
import { getUiaContextService } from './UiaContextService' import { getUiaContextService } from './UiaContextService'
import { getForegroundWindowInfo, isForegroundKoreanIme } from '../utils/win32-foreground' import { getForegroundWindowInfo, isForegroundKoreanIme } from '../utils/win32-foreground'
import { getLastNativeInputTick } from '../utils/win32-input-activity'
import { getPersonalGraphService } from './PersonalGraphService' import { getPersonalGraphService } from './PersonalGraphService'
import { getPersonalNgramIndex } from './suggestion/PersonalNgramIndex' import { getPersonalNgramIndex } from './suggestion/PersonalNgramIndex'
@ -104,6 +105,10 @@ export interface TypingContext {
windowHandle?: number | null windowHandle?: number | null
idleMs: number idleMs: number
capturedAt: number capturedAt: number
/** 스냅샷을 읽는 동안 입력/포커스가 바뀌지 않았는지 확인한 단조 증가 번호. */
inputRevision?: number
/** Windows 세션의 마지막 입력 tick. null이면 네이티브 입력 상태 확인 실패, 다른 OS는 생략. */
nativeInputTick?: number | null
/** 포커스가 바뀐 뒤 이 필드에서 실제로 편집이 있었는가 (마우스로 들어오기만 한 경우 false) */ /** 포커스가 바뀐 뒤 이 필드에서 실제로 편집이 있었는가 (마우스로 들어오기만 한 경우 false) */
editedSinceFocus: boolean editedSinceFocus: boolean
/** 최근에 실제로 타이핑했는가 (recentTypingWindowMs 이내) */ /** 최근에 실제로 타이핑했는가 (recentTypingWindowMs 이내) */
@ -193,6 +198,10 @@ class InputTelemetryService extends EventEmitter {
private _sampleTimer: NodeJS.Timeout | null = null private _sampleTimer: NodeJS.Timeout | null = null
/** 주기 샘플 스냅샷 진행 중 (중복 방지) */ /** 주기 샘플 스냅샷 진행 중 (중복 방지) */
private _sampling = false private _sampling = false
/** 모든 스냅샷 트리거를 합쳐 같은 UIA 응답을 중복 적용하지 않는다. */
private _snapshotRequest: Promise<TypingContext | null> | null = null
/** 같은 밀리초에 들어온 키·클릭도 서로 다른 편집으로 구분한다. */
private _inputRevision = 0
/** 제안 오버레이가 표시 중일 때만 포커스 이탈/선택을 계속 확인한다. */ /** 제안 오버레이가 표시 중일 때만 포커스 이탈/선택을 계속 확인한다. */
private _suggestionPresentationActive = false private _suggestionPresentationActive = false
private _presentationValidationTimer: NodeJS.Timeout | null = null private _presentationValidationTimer: NodeJS.Timeout | null = null
@ -227,6 +236,8 @@ class InputTelemetryService extends EventEmitter {
private _typedIntoFocus = false private _typedIntoFocus = false
/** 현재 포커스/클릭 이후 실제로 글자 키를 쳤는가 (첫 스냅샷 전 빠른 입력 보존) */ /** 현재 포커스/클릭 이후 실제로 글자 키를 쳤는가 (첫 스냅샷 전 빠른 입력 보존) */
private _typedInCurrentFocus = false private _typedInCurrentFocus = false
/** Chromium/Electron 등 UIA GetActiveComposition 미지원 앱을 위한 키스트로크 기반 한글 조합 추정 */
private _imeComposing = false
private _lastTypedHwnd: number | null = null private _lastTypedHwnd: number | null = null
/** 직전 스냅샷이 편집 가능한 칸이었는가 / 어느 창이었는가 (포커스 깜빡임 판정) */ /** 직전 스냅샷이 편집 가능한 칸이었는가 / 어느 창이었는가 (포커스 깜빡임 판정) */
private _prevSnapshotEditable = false private _prevSnapshotEditable = false
@ -314,6 +325,10 @@ class InputTelemetryService extends EventEmitter {
return this._lastKeyAt return this._lastKeyAt
} }
get inputRevision(): number {
return this._inputRevision
}
/** /**
* 곧 프로그램이 키 count 개를 보낸다 — 그 키들은 입력 통계에 넣지 않는다. * 곧 프로그램이 키 count 개를 보낸다 — 그 키들은 입력 통계에 넣지 않는다.
* 남은 예고는 ttlMs 뒤 무효다(보내지 못한 키가 사용자 키를 삼키지 않게). * 남은 예고는 ttlMs 뒤 무효다(보내지 못한 키가 사용자 키를 삼키지 않게).
@ -321,6 +336,7 @@ class InputTelemetryService extends EventEmitter {
expectProgrammaticKeys(count: number, ttlMs = 3000): void { expectProgrammaticKeys(count: number, ttlMs = 3000): void {
this._programmaticKeys = Math.max(0, count) this._programmaticKeys = Math.max(0, count)
this._programmaticKeysUntil = Date.now() + ttlMs this._programmaticKeysUntil = Date.now() + ttlMs
if (count > 0) this._imeComposing = false
} }
/** /**
@ -334,6 +350,8 @@ class InputTelemetryService extends EventEmitter {
* 프로그램(오타 교정)이 커서 앞 deleteCount 글자를 지우고 insertText 를 넣었을 때 터미널 키 버퍼도 동기화한다. * 프로그램(오타 교정)이 커서 앞 deleteCount 글자를 지우고 insertText 를 넣었을 때 터미널 키 버퍼도 동기화한다.
*/ */
applyProgrammaticReplacement(deleteCount: number, insertText: string, baseLength?: number): void { applyProgrammaticReplacement(deleteCount: number, insertText: string, baseLength?: number): void {
this._inputRevision += 1
this._imeComposing = false
this._terminalTracker.applyReplacement(deleteCount, insertText, baseLength) this._terminalTracker.applyReplacement(deleteCount, insertText, baseLength)
} }
@ -372,6 +390,7 @@ class InputTelemetryService extends EventEmitter {
this._releaseHook = acquireGlobalInputHook() this._releaseHook = acquireGlobalInputHook()
this._running = true this._running = true
this._inputRevision += 1
this._flushTimer = setInterval( this._flushTimer = setInterval(
() => this._flush(), () => this._flush(),
INPUT_TELEMETRY_DEFAULTS.flushIntervalMs INPUT_TELEMETRY_DEFAULTS.flushIntervalMs
@ -408,6 +427,7 @@ class InputTelemetryService extends EventEmitter {
} }
stop(): void { stop(): void {
this._inputRevision += 1
// 입력 관찰을 끄면 메모리에 잡아 둔 "조금 전에 쓴 글" 도 버린다. // 입력 관찰을 끄면 메모리에 잡아 둔 "조금 전에 쓴 글" 도 버린다.
this._recentWrites.clear() this._recentWrites.clear()
if (!this._running) { if (!this._running) {
@ -511,6 +531,8 @@ class InputTelemetryService extends EventEmitter {
// ── 이벤트 수집 ──────────────────────────────────────── // ── 이벤트 수집 ────────────────────────────────────────
private _handleKeyDown(event: UiohookKeyboardEvent): void { private _handleKeyDown(event: UiohookKeyboardEvent): void {
// 합성 키도 화면을 바꾼다. 통계 제외 여부와 무관하게 이전 UIA 응답은 무효다.
this._inputRevision += 1
this._syncModifiers(event) this._syncModifiers(event)
// Win32 SendInput(KEYEVENTF_UNICODE) 가 보내는 합성 유니코드 키는 uiohook 에서 keycode=0 으로 들어온다. // Win32 SendInput(KEYEVENTF_UNICODE) 가 보내는 합성 유니코드 키는 uiohook 에서 keycode=0 으로 들어온다.
// 사용자 키스트로크나 IME 입력으로 처리하면 버퍼와 타이머를 교란하므로 즉시 무시한다. // 사용자 키스트로크나 IME 입력으로 처리하면 버퍼와 타이머를 교란하므로 즉시 무시한다.
@ -563,6 +585,13 @@ class InputTelemetryService extends EventEmitter {
} else if (keyClass === 'shortcut') { } else if (keyClass === 'shortcut') {
this._typedInCurrentFocus = false this._typedInCurrentFocus = false
} }
if (event.keycode === 112 || vk === 0x15) {
this._imeComposing = false
} else if (keyClass === 'ime' || keyClass === 'letter') {
this._imeComposing = true
} else if (keyClass !== 'modifier') {
this._imeComposing = false
}
// 진단: 키 값이 아니라 종류·수정자만 남긴다 (typed 판정이 왜 틀리는지 로그로 보이게) // 진단: 키 값이 아니라 종류·수정자만 남긴다 (typed 판정이 왜 틀리는지 로그로 보이게)
this._lastKeyDiag = `${keyClass}${vk === null ? `?${event.keycode}` : ''}${this._modifiers.ctrl ? '+C' : ''}${this._modifiers.alt ? '+A' : ''}${this._modifiers.meta ? '+M' : ''}` this._lastKeyDiag = `${keyClass}${vk === null ? `?${event.keycode}` : ''}${this._modifiers.ctrl ? '+C' : ''}${this._modifiers.alt ? '+A' : ''}${this._modifiers.meta ? '+M' : ''}`
@ -594,6 +623,7 @@ class InputTelemetryService extends EventEmitter {
} }
private _handleMouseDown(event: UiohookMouseEvent): void { private _handleMouseDown(event: UiohookMouseEvent): void {
this._inputRevision += 1
this._registerInput(false) this._registerInput(false)
const now = Date.now() const now = Date.now()
@ -615,10 +645,12 @@ class InputTelemetryService extends EventEmitter {
// 클릭은 다른 칸으로 옮겨 갔을 수 있다 — 다음 스냅샷의 텍스트를 새 기준으로 삼는다. // 클릭은 다른 칸으로 옮겨 갔을 수 있다 — 다음 스냅샷의 텍스트를 새 기준으로 삼는다.
this._rebaseFocusText = true this._rebaseFocusText = true
this._typedInCurrentFocus = false this._typedInCurrentFocus = false
this._imeComposing = false
this._terminalTracker.onPointerOrFocusChange(this._foreground.hwnd) this._terminalTracker.onPointerOrFocusChange(this._foreground.hwnd)
} }
private _handleMouseUp(event: UiohookMouseEvent): void { private _handleMouseUp(event: UiohookMouseEvent): void {
this._inputRevision += 1
this._lastMouse = { x: event.x, y: event.y } this._lastMouse = { x: event.x, y: event.y }
if (!this._suggestionPresentationActive) return if (!this._suggestionPresentationActive) return
if (this._presentationValidationTimer) clearTimeout(this._presentationValidationTimer) if (this._presentationValidationTimer) clearTimeout(this._presentationValidationTimer)
@ -643,6 +675,7 @@ class InputTelemetryService extends EventEmitter {
} }
private _handleWheel(event: UiohookWheelEvent): void { private _handleWheel(event: UiohookWheelEvent): void {
this._inputRevision += 1
const bucket = this._bucket() const bucket = this._bucket()
bucket.scrollTicks += Math.max(1, Math.abs(Number(event.rotation) || 1)) bucket.scrollTicks += Math.max(1, Math.abs(Number(event.rotation) || 1))
this._registerInput(false) this._registerInput(false)
@ -698,7 +731,9 @@ class InputTelemetryService extends EventEmitter {
const info = getForegroundWindowInfo() const info = getForegroundWindowInfo()
if (info) { if (info) {
if (info.hwnd !== this._foreground.hwnd) { if (info.hwnd !== this._foreground.hwnd) {
this._inputRevision += 1
this._typedInCurrentFocus = false this._typedInCurrentFocus = false
this._imeComposing = false
} }
this._foreground = { this._foreground = {
appName: info.appName || null, appName: info.appName || null,
@ -733,9 +768,13 @@ class InputTelemetryService extends EventEmitter {
*/ */
private async _sampleWhileTyping(): Promise<void> { private async _sampleWhileTyping(): Promise<void> {
if (!this._running || this._sampling) return if (!this._running || this._sampling) return
const now = Date.now()
if (!this._suggestionPresentationActive && this._lastKeyAt > 0 && now - this._lastKeyAt < 350) {
return
}
const hasRecentKeyboardInput = const hasRecentKeyboardInput =
this._lastKeyAt > 0 && this._lastKeyAt > 0 &&
Date.now() - this._lastKeyAt <= INPUT_TELEMETRY_DEFAULTS.sampleActiveWindowMs now - this._lastKeyAt <= INPUT_TELEMETRY_DEFAULTS.sampleActiveWindowMs
if (!hasRecentKeyboardInput && !this._suggestionPresentationActive) return if (!hasRecentKeyboardInput && !this._suggestionPresentationActive) return
this._sampling = true this._sampling = true
@ -799,9 +838,38 @@ class InputTelemetryService extends EventEmitter {
*/ */
private async _captureTextSnapshot(): Promise<TypingContext | null> { private async _captureTextSnapshot(): Promise<TypingContext | null> {
if (!this._running) return null if (!this._running) return null
if (this._snapshotRequest) return this._snapshotRequest
const request = this._readTextSnapshot()
this._snapshotRequest = request
try {
return await request
} finally {
if (this._snapshotRequest === request) this._snapshotRequest = null
}
}
private async _readTextSnapshot(): Promise<TypingContext | null> {
this._sampleForeground(Date.now(), true)
const inputRevision = this._inputRevision
const foregroundHwnd = this._foreground.hwnd
const nativeInputTick = getLastNativeInputTick()
const uia = getUiaContextService() const uia = getUiaContextService()
const snapshot = withoutPlaceholderText(await uia.getSnapshot()) const snapshot = withoutPlaceholderText(await uia.getSnapshot())
if (!this._running) return null
this._sampleForeground(Date.now(), true)
// CPU 부하/모델 로딩 중 UIA 응답이 늦어질 수 있다. 예전 텍스트를 최신 키 시각과
// 섞으면 자동 교정이 방금 친 글자를 지운다. 기준선·학습·제안 모두 갱신 전에 버린다.
if (
inputRevision !== this._inputRevision ||
foregroundHwnd !== this._foreground.hwnd ||
nativeInputTick !== getLastNativeInputTick() ||
(snapshot.available && snapshot.capturedAt < Math.max(this._lastKeyAt, this._lastClickAt))
) {
logger.debug('입력 스냅샷 버림: UIA 조회 중 입력 또는 포커스 변경')
return null
}
const now = Date.now() const now = Date.now()
// 유휴 시간은 키보드 기준이다 (마우스 이동/클릭으로는 제안하지 않는다). // 유휴 시간은 키보드 기준이다 (마우스 이동/클릭으로는 제안하지 않는다).
const idleMs = this._lastKeyAt > 0 ? now - this._lastKeyAt : Number.MAX_SAFE_INTEGER const idleMs = this._lastKeyAt > 0 ? now - this._lastKeyAt : Number.MAX_SAFE_INTEGER
@ -824,6 +892,8 @@ class InputTelemetryService extends EventEmitter {
windowHandle: this._foreground.hwnd, windowHandle: this._foreground.hwnd,
idleMs, idleMs,
capturedAt: snapshot.capturedAt, capturedAt: snapshot.capturedAt,
inputRevision,
nativeInputTick: process.platform === 'win32' ? nativeInputTick : undefined,
editedSinceFocus: false, editedSinceFocus: false,
typedRecently typedRecently
} }
@ -920,10 +990,21 @@ class InputTelemetryService extends EventEmitter {
if (clearedByEnter) { if (clearedByEnter) {
this._lastTypedAt = 0 this._lastTypedAt = 0
this._typedInCurrentFocus = false this._typedInCurrentFocus = false
this._imeComposing = false
context.typedRecently = false context.typedRecently = false
} }
} }
context.editedSinceFocus = textForFocus !== this._textAtFocus || this._typedIntoFocus context.editedSinceFocus = textForFocus !== this._textAtFocus || this._typedIntoFocus
if (
!context.isComposing &&
this._imeComposing &&
context.editedSinceFocus &&
/[가-힣ㄱ-ㅎㅏ-ㅣ]$/u.test(context.prefix)
) {
context.isComposing = true
} else if (context.isComposing && !/[가-힣ㄱ-ㅎㅏ-ㅣ]$/u.test(context.prefix)) {
context.isComposing = false
}
// 보내면 비워지는 칸(채팅)의 직전 내용을 "이 창에서 조금 전에 쓴 글" 로 잠시 기억한다. // 보내면 비워지는 칸(채팅)의 직전 내용을 "이 창에서 조금 전에 쓴 글" 로 잠시 기억한다.
// 비밀번호·편집 불가 칸과 터미널(명령 기록)은 보지 않는다. 조합 중인 칸도 본다 — 한글은 보내기 직전 // 비밀번호·편집 불가 칸과 터미널(명령 기록)은 보지 않는다. 조합 중인 칸도 본다 — 한글은 보내기 직전
@ -942,7 +1023,7 @@ class InputTelemetryService extends EventEmitter {
// 단, 방금 프로그램(오타 교정·제안 수락)이 커서 앞 텍스트를 바꾼 경우에는 끝 편집으로 본다. // 단, 방금 프로그램(오타 교정·제안 수락)이 커서 앞 텍스트를 바꾼 경우에는 끝 편집으로 본다.
this._pruneExpectedInserts(now) this._pruneExpectedInserts(now)
const programmaticEdit = const programmaticEdit =
this._programmaticKeyBudget > 0 || this._programmaticKeys > 0 ||
this._expectedInserts.some((entry) => textForFocus.includes(entry.text)) this._expectedInserts.some((entry) => textForFocus.includes(entry.text))
if (this._editProbe === null || this._editProbe.key !== focusKey || programmaticEdit) { if (this._editProbe === null || this._editProbe.key !== focusKey || programmaticEdit) {
this._lastEditAtEnd = true this._lastEditAtEnd = true

View file

@ -555,10 +555,11 @@ class KeyBindingService extends EventEmitter {
this._altGr.reset() this._altGr.reset()
forgetHeldModifiers() forgetHeldModifiers()
} }
const events = ['lock-screen', 'suspend'] as const powerMonitor.on('lock-screen', releaseHeld)
for (const event of events) powerMonitor.on(event, releaseHeld) powerMonitor.on('suspend', releaseHeld)
this._offSessionLock = () => { this._offSessionLock = () => {
for (const event of events) powerMonitor.removeListener(event, releaseHeld) powerMonitor.removeListener('lock-screen', releaseHeld)
powerMonitor.removeListener('suspend', releaseHeld)
} }
} }

View file

@ -117,6 +117,9 @@ export class LicenseService extends EventEmitter {
private _keyVerifiedAt: number | null = null private _keyVerifiedAt: number | null = null
private _cloudTier: LicenseTier = 'free' private _cloudTier: LicenseTier = 'free'
private _cloudVerifiedAt: number | null = null private _cloudVerifiedAt: number | null = null
private _rewardBonusDate = ''
private _rewardBonusAmount = 0
private _claimedRewardNonces = new Set<string>()
constructor( constructor(
private readonly _store: LicenseStore = new FileLicenseStore(), private readonly _store: LicenseStore = new FileLicenseStore(),
@ -180,6 +183,27 @@ export class LicenseService extends EventEmitter {
this._persistSummary() this._persistSummary()
} }
// 3. 보상형 광고 보너스 쿼터 & 리플레이 방지 논스 복원
const today = getTodayDate()
const storedBonusDate = this._store.read<string>('licenseRewardBonusDate')
const storedBonusAmount = this._store.read<number>('licenseRewardBonusAmount')
const storedNonces = this._store.read<string[]>('licenseRewardClaimedNonces')
if (
storedBonusDate === today &&
typeof storedBonusAmount === 'number' &&
Number.isFinite(storedBonusAmount) &&
storedBonusAmount > 0
) {
this._rewardBonusDate = today
this._rewardBonusAmount = Math.floor(storedBonusAmount)
} else {
this._rewardBonusDate = today
this._rewardBonusAmount = 0
}
this._claimedRewardNonces = new Set(
Array.isArray(storedNonces) ? storedNonces.filter((n): n is string => typeof n === 'string') : [],
)
logger.info( logger.info(
`LicenseService initialized: tier=${this.tier}, key=${this._key?.tier ?? 'none'}, cloud=${this._cloudTier}, trial=${this._key?.isTrial ?? false}, machineId=${this._machineId.substring(0, 8)}...`, `LicenseService initialized: tier=${this.tier}, key=${this._key?.tier ?? 'none'}, cloud=${this._cloudTier}, trial=${this._key?.isTrial ?? false}, machineId=${this._machineId.substring(0, 8)}...`,
) )
@ -338,10 +362,10 @@ export class LicenseService extends EventEmitter {
/** 일일 사용량 조회 */ /** 일일 사용량 조회 */
getUsage(feature: Feature): UsageQuota { getUsage(feature: Feature): UsageQuota {
const limit = quotaLimitFor(this.tier, feature) const baseLimit = quotaLimitFor(this.tier, feature)
// 쿼터 없는 기능 (무제한) // 쿼터 없는 기능 (무제한)
if (limit === undefined) { if (baseLimit === undefined) {
return { return {
feature, feature,
used: 0, used: 0,
@ -351,6 +375,8 @@ export class LicenseService extends EventEmitter {
} }
} }
const bonus = feature === Feature.PREMIUM_LLM ? this.getRewardBonusQuota() : 0
const limit = baseLimit + bonus
const used = this._usage.getCount(getTodayDate(), feature) const used = this._usage.getCount(getTodayDate(), feature)
return { return {
@ -362,6 +388,104 @@ export class LicenseService extends EventEmitter {
} }
} }
/** 당일 보상형 광고 보너스 쿼터 조회 */
getRewardBonusQuota(): number {
const today = getTodayDate()
if (this._rewardBonusDate !== today) {
const storedBonusDate = this._store.read<string>('licenseRewardBonusDate')
const storedBonusAmount = this._store.read<number>('licenseRewardBonusAmount')
if (
storedBonusDate === today &&
typeof storedBonusAmount === 'number' &&
Number.isFinite(storedBonusAmount) &&
storedBonusAmount > 0
) {
this._rewardBonusDate = today
this._rewardBonusAmount = Math.floor(storedBonusAmount)
} else {
this._rewardBonusDate = today
this._rewardBonusAmount = 0
}
}
return this._rewardBonusAmount
}
/**
* 보상형 광고 완료 검증 후 보너스 쿼터 부여 (리플레이/논스 중복 차감 방지).
*/
grantRewardQuota(
amount: number = 50,
nonce?: string,
): {
granted: boolean
tokensAdded: number
bonusQuota: number
newTotalQuota: number
rewardId: string
} {
const currentQuota = this.getUsage(Feature.PREMIUM_LLM)
if (!Number.isFinite(amount) || amount <= 0) {
return {
granted: false,
tokensAdded: 0,
bonusQuota: this.getRewardBonusQuota(),
newTotalQuota: currentQuota.limit,
rewardId: '',
}
}
const trimmedNonce = nonce?.trim()
if (trimmedNonce) {
const storedNonces = this._store.read<string[]>('licenseRewardClaimedNonces')
if (Array.isArray(storedNonces)) {
for (const n of storedNonces) {
if (typeof n === 'string') this._claimedRewardNonces.add(n)
}
}
if (this._claimedRewardNonces.has(trimmedNonce)) {
return {
granted: false,
tokensAdded: 0,
bonusQuota: this.getRewardBonusQuota(),
newTotalQuota: currentQuota.limit,
rewardId: '',
}
}
this._claimedRewardNonces.add(trimmedNonce)
if (this._claimedRewardNonces.size > 512) {
const oldest = this._claimedRewardNonces.values().next().value
if (oldest !== undefined) {
this._claimedRewardNonces.delete(oldest)
}
}
}
const today = getTodayDate()
const normalizedAmount = Math.floor(amount)
const currentBonus = this.getRewardBonusQuota()
this._rewardBonusDate = today
this._rewardBonusAmount = currentBonus + normalizedAmount
this._store.writeAll({
licenseRewardBonusDate: this._rewardBonusDate,
licenseRewardBonusAmount: this._rewardBonusAmount,
licenseRewardClaimedNonces: Array.from(this._claimedRewardNonces),
})
const updatedQuota = this.getUsage(Feature.PREMIUM_LLM)
const rewardId = `reward_${Date.now()}_${trimmedNonce ?? Math.random().toString(36).slice(2, 8)}`
this.emit('quota-updated', updatedQuota)
logger.info(
`Reward quota granted: +${normalizedAmount} tokens (bonus=${this._rewardBonusAmount}, newLimit=${updatedQuota.limit})`,
)
return {
granted: true,
tokensAdded: normalizedAmount,
bonusQuota: this._rewardBonusAmount,
newTotalQuota: updatedQuota.limit,
rewardId,
}
}
/** 전체 쿼터 기능 사용량 조회 */ /** 전체 쿼터 기능 사용량 조회 */
getAllUsage(): UsageQuota[] { getAllUsage(): UsageQuota[] {
const quotaFeatures = [Feature.DICTATION, Feature.LLM_PROCESS] const quotaFeatures = [Feature.DICTATION, Feature.LLM_PROCESS]

View file

@ -13,6 +13,7 @@ import type { LLMStatus, LLMModel, LLMAction, LLMConnectionState } from '@d3ro/c
import { resolveSystemPrompt } from './llm-prompts' import { resolveSystemPrompt } from './llm-prompts'
import { getBundledOllamaPath } from '../utils/paths' import { getBundledOllamaPath } from '../utils/paths'
import { normalizeLoopbackUrl } from '../utils/loopback' import { normalizeLoopbackUrl } from '../utils/loopback'
import { localInferenceCpuOptions } from '../utils/inference-cpu-budget'
import { readNdjsonLines } from '../utils/ndjson-reader' import { readNdjsonLines } from '../utils/ndjson-reader'
import { import {
LOCAL_LLM_KEEP_ALIVE, LOCAL_LLM_KEEP_ALIVE,
@ -449,6 +450,7 @@ class LocalLLMService extends EventEmitter {
// gemma4/llama3.2 등 non-reasoning 모델에서는 무시됨. // gemma4/llama3.2 등 non-reasoning 모델에서는 무시됨.
think: false, think: false,
options: { options: {
...localInferenceCpuOptions(serverUrl),
temperature: options?.temperature ?? 0.3, temperature: options?.temperature ?? 0.3,
num_predict: maxTokens num_predict: maxTokens
} }
@ -514,6 +516,7 @@ class LocalLLMService extends EventEmitter {
keep_alive: options?.keepAlive ?? LOCAL_LLM_KEEP_ALIVE, keep_alive: options?.keepAlive ?? LOCAL_LLM_KEEP_ALIVE,
think: false, think: false,
options: { options: {
...localInferenceCpuOptions(serverUrl),
temperature: options?.temperature ?? 0.3, temperature: options?.temperature ?? 0.3,
num_predict: maxTokens, num_predict: maxTokens,
...(options?.stop && options.stop.length > 0 ? { stop: options.stop } : {}) ...(options?.stop && options.stop.length > 0 ? { stop: options.stop } : {})
@ -889,6 +892,7 @@ class LocalLLMService extends EventEmitter {
keep_alive: options?.keepAlive ?? LOCAL_LLM_KEEP_ALIVE, keep_alive: options?.keepAlive ?? LOCAL_LLM_KEEP_ALIVE,
think: false, think: false,
options: { options: {
...localInferenceCpuOptions(serverUrl),
temperature: options?.temperature ?? 0.7, temperature: options?.temperature ?? 0.7,
num_predict: maxTokens, num_predict: maxTokens,
}, },

View file

@ -379,11 +379,14 @@ class MeetingModeService extends EventEmitter {
// ── 메모 추가 ── // ── 메모 추가 ──
async addMemo(content: string): Promise<MeetingMemo> { async addMemo(content: string, meetingId?: string): Promise<MeetingMemo> {
const session = this._current const trimmed = content.trim()
if (this._state !== 'recording' || !session) { if (!trimmed) {
throw new D3ROError(ErrorCode.MeetingNotRecording, '녹음 중이 아닙니다') throw new D3ROError(ErrorCode.MeetingNotRecording, '메모 내용이 비어 있습니다')
} }
const session = this._current
if (this._state === 'recording' && session && (!meetingId || meetingId === session.id)) {
const memo = session.addMemo(crypto.randomUUID(), content) const memo = session.addMemo(crypto.randomUUID(), content)
if (!memo) { if (!memo) {
throw new D3ROError(ErrorCode.MeetingNotRecording, '녹음 중이 아닙니다') throw new D3ROError(ErrorCode.MeetingNotRecording, '녹음 중이 아닙니다')
@ -408,6 +411,57 @@ class MeetingModeService extends EventEmitter {
return memo return memo
} }
// 종료된 회의(또는 특정 meetingId)에 사후 메모 추가
const targetSessionId = meetingId?.trim() || this._finalizedSessionId
if (!targetSessionId) {
throw new D3ROError(ErrorCode.MeetingNotRecording, '녹음 중이 아닙니다')
}
const db = getDatabase()
const sessionRow = db
.select()
.from(meetingSessions)
.where(eq(meetingSessions.id, targetSessionId))
.get()
if (!sessionRow) {
throw new D3ROError(
meetingId ? ErrorCode.MeetingSessionNotFound : ErrorCode.MeetingNotRecording,
meetingId ? `회의 세션을 찾을 수 없습니다: ${targetSessionId}` : '녹음 중이 아닙니다',
)
}
const now = Date.now()
const timestampMs =
sessionRow.durationMs ??
(sessionRow.endedAt ? Math.max(0, sessionRow.endedAt - sessionRow.startedAt) : 0)
const memo: MeetingMemo = {
id: crypto.randomUUID(),
sessionId: targetSessionId,
content: trimmed,
timestampMs,
createdAt: now,
}
db.insert(meetingMemos)
.values({
id: memo.id,
sessionId: memo.sessionId,
content: memo.content,
timestampMs: memo.timestampMs,
createdAt: memo.createdAt,
})
.run()
this.emit('memo-added', memo)
logger.debug(`사후 회의 메모 추가: sessionId=${targetSessionId}, [${formatTime(memo.timestampMs)}] ${trimmed}`)
// Phase 3.3: 자동 push (fire-and-forget)
getCloudSyncService().pushOne('meeting_memos', memo.id)
return memo
}
// ── 녹음 종료 ── // ── 녹음 종료 ──
/** /**

View file

@ -24,19 +24,51 @@ const logger = getLogger('MeetingSummaryService')
let isShowingSummarySaveDialog = false let isShowingSummarySaveDialog = false
const MEETING_SUMMARY_PROMPT = `다음은 회의 전사록입니다. 아래 형식으로 정리해주세요: export interface TranscriptCitation {
label: string
timestampMs: number
}
export function parseCitationTimestampMs(token: string): number | null {
const match = /^\[?(?:(\d{1,2}):)?(\d{1,3}):(\d{2})\]?$/.exec(token.trim())
if (!match) return null
const hours = match[1] ? parseInt(match[1], 10) : 0
const minutes = parseInt(match[2], 10)
const seconds = parseInt(match[3], 10)
if (seconds >= 60) return null
return (hours * 3600 + minutes * 60 + seconds) * 1000
}
export function extractTranscriptCitations(text: string): TranscriptCitation[] {
const regex = /\[(?:\d{1,2}:)?\d{1,3}:\d{2}\]/g
const seen = new Set<string>()
const results: TranscriptCitation[] = []
let match: RegExpExecArray | null
while ((match = regex.exec(text)) !== null) {
const label = match[0]
const ts = parseCitationTimestampMs(label)
if (ts !== null && !seen.has(label)) {
seen.add(label)
results.push({ label, timestampMs: ts })
}
}
return results
}
export const MEETING_SUMMARY_PROMPT = `다음은 회의 전사록입니다. 아래 형식으로 정리해주세요:
## 요약 ## 요약
(3줄 이내 핵심 요약) (3줄 이내 핵심 요약. 전사록에 [MM:SS] 시각이 있으면 관련 문장 끝에 [MM:SS] 인용 표기를 남기세요)
## 핵심 결정사항 ## 핵심 결정사항
- (결정 1) - (결정 1) [MM:SS]
- (결정 2) - (결정 2) [MM:SS]
## 할 일 목록 ## 할 일 목록
- [ ] (할 일 1) - [ ] (할 일 1) [MM:SS]
- [ ] (할 일 2) - [ ] (할 일 2) [MM:SS]
전사록에 [MM:SS] 타임스탬프가 포함되어 있다면 각 핵심 요약·결정사항·할 일 항목 끝에 근거가 되는 [MM:SS] 시각 인용을 함께 표기하세요.
전사록 외의 내용을 추가하지 마세요. 전사록이 비어 있거나 내용이 부족하면 "요약할 내용이 충분하지 않습니다"라고만 출력하세요.` 전사록 외의 내용을 추가하지 마세요. 전사록이 비어 있거나 내용이 부족하면 "요약할 내용이 충분하지 않습니다"라고만 출력하세요.`
class MeetingSummaryService extends EventEmitter { class MeetingSummaryService extends EventEmitter {

View file

@ -1,13 +1,14 @@
// src/main/services/MemoService.ts // src/main/services/MemoService.ts
// Phase 10.3: 음성 메모 태그 시스템. 히스토리 항목에 태그를 부착하고 태그별 검색/내보내기를 지원한다. // Phase 10.3: 음성 메모 태그 시스템. 히스토리 항목에 태그를 부착하고 태그별 검색/내보내기를 지원한다.
import { eq, and, desc, count, sql } from 'drizzle-orm' import { eq, and, or, desc, count, sql } from 'drizzle-orm'
import { app } from 'electron' import { app } from 'electron'
import path from 'path' import path from 'path'
import fs from 'fs' import fs from 'fs'
import { getDatabase } from '../db' import { getDatabase } from '../db'
import { memoTags, history } from '../db/schema' import { memoTags, history } from '../db/schema'
import type { MemoTagRow } from '../db/schema' import type { MemoTagRow } from '../db/schema'
import { containsPattern } from '../db/like-pattern'
import { getLogger } from './LoggerService' import { getLogger } from './LoggerService'
import { getCloudSyncService } from './CloudSyncService' import { getCloudSyncService } from './CloudSyncService'
import { MEMO_TAG_MAX_LENGTH, memoTagKey, normalizeMemoTag, validateMemoTag } from '@d3ro/core/memo-tag-policy' import { MEMO_TAG_MAX_LENGTH, memoTagKey, normalizeMemoTag, validateMemoTag } from '@d3ro/core/memo-tag-policy'
@ -24,6 +25,14 @@ import type {
const logger = getLogger('MemoService') const logger = getLogger('MemoService')
export interface ExtendedExportMemoParams extends ExportMemoParams {
savePath?: string
includeUntagged?: boolean
mode?: string
isFavorite?: boolean
search?: string
}
class MemoService { class MemoService {
/** /**
* 특정 히스토리 항목에 부착된 태그 목록을 조회한다. * 특정 히스토리 항목에 부착된 태그 목록을 조회한다.
@ -205,47 +214,126 @@ class MemoService {
/** /**
* 태그+날짜 기준으로 그룹핑된 마크다운 파일을 생성하고 파일 경로를 반환한다. * 태그+날짜 기준으로 그룹핑된 마크다운 파일을 생성하고 파일 경로를 반환한다.
* 태그가 지정되지 않은 경우 태그가 없는 히스토리 항목도 함께 내보낼 수 있으며,
* `savePath`가 전달되면 지정 경로에 저장한다.
*/ */
exportMarkdown(params: ExportMemoParams): string { exportMarkdown(params: ExtendedExportMemoParams): string {
const db = getDatabase() const db = getDatabase()
// 태그별 히스토리 조회 const filterConditions = []
const tagFilter = params.tag
? eq(memoTags.tag, normalizeMemoTag(params.tag))
: undefined
const dateConditions: ReturnType<typeof sql>[] = []
if (params.from) { if (params.from) {
const fromMs = new Date(params.from).getTime() const fromMs = new Date(params.from).getTime()
dateConditions.push(sql`${history.createdAt} >= ${fromMs}`) filterConditions.push(sql`${history.createdAt} >= ${fromMs}`)
} }
if (params.to) { if (params.to) {
const toMs = new Date(params.to).getTime() const toMs = new Date(params.to).getTime()
dateConditions.push(sql`${history.createdAt} <= ${toMs}`) filterConditions.push(sql`${history.createdAt} <= ${toMs}`)
}
if (params.mode && params.mode !== 'all') {
if (params.mode === 'file') {
filterConditions.push(eq(history.mode, 'file-transcription'))
} else if (params.mode === 'commandTranslate') {
filterConditions.push(or(eq(history.mode, 'command'), eq(history.mode, 'translate')))
} else {
filterConditions.push(eq(history.mode, params.mode as HistoryEntry['mode']))
}
}
if (typeof params.isFavorite === 'boolean') {
filterConditions.push(eq(history.isFavorite, params.isFavorite))
}
if (params.search?.trim()) {
const pattern = containsPattern(params.search.trim())
filterConditions.push(
or(
pattern.match(history.originalText),
pattern.match(history.polishedText),
pattern.match(history.title),
pattern.match(history.summaryText),
),
)
} }
const conditions = [tagFilter, ...dateConditions].filter( type ExportRow = {
(c): c is NonNullable<typeof c> => c !== undefined tag: string
) title: string | null
originalText: string
polishedText: string | null
createdAt: number
duration: number
}
let rows: ExportRow[] = []
if (params.tag) {
const normalizedTag = normalizeMemoTag(params.tag)
const conditions = [eq(memoTags.tag, normalizedTag), ...filterConditions].filter(
(c): c is NonNullable<typeof c> => c !== undefined,
)
const whereClause = conditions.length > 0 ? and(...conditions) : undefined const whereClause = conditions.length > 0 ? and(...conditions) : undefined
const rows = db rows = db
.select({ .select({
tag: memoTags.tag, tag: memoTags.tag,
title: history.title,
originalText: history.originalText, originalText: history.originalText,
polishedText: history.polishedText, polishedText: history.polishedText,
createdAt: history.createdAt, createdAt: history.createdAt,
duration: history.duration duration: history.duration,
}) })
.from(memoTags) .from(memoTags)
.innerJoin(history, eq(memoTags.historyId, history.id)) .innerJoin(history, eq(memoTags.historyId, history.id))
.where(whereClause) .where(whereClause)
.orderBy(memoTags.tag, desc(history.createdAt)) .orderBy(memoTags.tag, desc(history.createdAt))
.all() .all()
} else if (params.includeUntagged === false) {
const conditions = filterConditions.filter((c): c is NonNullable<typeof c> => c !== undefined)
const whereClause = conditions.length > 0 ? and(...conditions) : undefined
rows = db
.select({
tag: memoTags.tag,
title: history.title,
originalText: history.originalText,
polishedText: history.polishedText,
createdAt: history.createdAt,
duration: history.duration,
})
.from(memoTags)
.innerJoin(history, eq(memoTags.historyId, history.id))
.where(whereClause)
.orderBy(memoTags.tag, desc(history.createdAt))
.all()
} else {
const conditions = filterConditions.filter((c): c is NonNullable<typeof c> => c !== undefined)
const whereClause = conditions.length > 0 ? and(...conditions) : undefined
const rawRows = db
.select({
tag: memoTags.tag,
title: history.title,
originalText: history.originalText,
polishedText: history.polishedText,
createdAt: history.createdAt,
duration: history.duration,
})
.from(history)
.leftJoin(memoTags, eq(memoTags.historyId, history.id))
.where(whereClause)
.orderBy(desc(history.createdAt))
.all()
rows = rawRows.map((r) => ({
tag: r.tag ?? 'untagged',
title: r.title,
originalText: r.originalText,
polishedText: r.polishedText,
createdAt: r.createdAt,
duration: r.duration,
}))
}
// 태그별 → 날짜별 그룹핑 // 태그별 → 날짜별 그룹핑
const grouped = new Map<string, Map<string, typeof rows>>() const grouped = new Map<string, Map<string, ExportRow[]>>()
for (const row of rows) { for (const row of rows) {
const dateKey = localDateKey(new Date(row.createdAt)) const dateKey = localDateKey(new Date(row.createdAt))
if (!grouped.has(row.tag)) { if (!grouped.has(row.tag)) {
@ -269,7 +357,7 @@ class MemoService {
} }
for (const [tag, dateMap] of grouped) { for (const [tag, dateMap] of grouped) {
lines.push(`## #${tag}`) lines.push(tag === 'untagged' ? '## Untagged' : `## #${tag}`)
lines.push('') lines.push('')
for (const [date, entries] of dateMap) { for (const [date, entries] of dateMap) {
@ -282,14 +370,22 @@ class MemoService {
minute: '2-digit' minute: '2-digit'
}) })
const text = entry.polishedText ?? entry.originalText const text = entry.polishedText ?? entry.originalText
const titlePrefix = entry.title?.trim() ? `[${entry.title.trim()}] ` : ''
const durationSec = Math.round(entry.duration) const durationSec = Math.round(entry.duration)
lines.push(`- **${time}** (${durationSec}s): ${text}`) lines.push(`- **${time}** (${durationSec}s): ${titlePrefix}${text}`)
} }
lines.push('') lines.push('')
} }
} }
// 파일 저장 let filePath: string
if (params.savePath?.trim()) {
filePath = path.resolve(params.savePath.trim())
const targetDir = path.dirname(filePath)
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir, { recursive: true })
}
} else {
const exportDir = path.join(app.getPath('userData'), 'exports') const exportDir = path.join(app.getPath('userData'), 'exports')
if (!fs.existsSync(exportDir)) { if (!fs.existsSync(exportDir)) {
fs.mkdirSync(exportDir, { recursive: true }) fs.mkdirSync(exportDir, { recursive: true })
@ -299,10 +395,11 @@ class MemoService {
params.tag ? normalizeMemoTag(params.tag) : undefined, params.tag ? normalizeMemoTag(params.tag) : undefined,
Date.now() Date.now()
) )
const filePath = path.join(exportDir, fileName) filePath = path.join(exportDir, fileName)
if (path.dirname(path.resolve(filePath)) !== path.resolve(exportDir)) { if (path.dirname(path.resolve(filePath)) !== path.resolve(exportDir)) {
throw new D3ROError(ErrorCode.MemoExportFailed, 'Memo export path escapes the exports folder') throw new D3ROError(ErrorCode.MemoExportFailed, 'Memo export path escapes the exports folder')
} }
}
try { try {
fs.writeFileSync(filePath, lines.join('\n'), 'utf-8') fs.writeFileSync(filePath, lines.join('\n'), 'utf-8')

View file

@ -23,7 +23,8 @@ import {
type GraphContext, type GraphContext,
type PersonalGraphQuery, type PersonalGraphQuery,
type PersonalGraphStats, type PersonalGraphStats,
type PhraseSource type PhraseSource,
type TwoHopGraphEdge
} from '@d3ro/core/personal-graph' } from '@d3ro/core/personal-graph'
import { SUGGESTION_MEMORY_TAIL_CHARS, isLearnablePhrase, prefixTail } from '@d3ro/core/input-intelligence' import { SUGGESTION_MEMORY_TAIL_CHARS, isLearnablePhrase, prefixTail } from '@d3ro/core/input-intelligence'
import { analyzeWritingContext } from '@d3ro/core/writing-context' import { analyzeWritingContext } from '@d3ro/core/writing-context'
@ -254,16 +255,16 @@ class PersonalGraphService {
const directFollowHops = firstHopEdges.filter( const directFollowHops = firstHopEdges.filter(
(edge) => edge.kind === 'follows' && anchors.includes(edge.fromPhrase) (edge) => edge.kind === 'follows' && anchors.includes(edge.fromPhrase)
) )
const normalizedFirstHop = firstHopEdges.flatMap((edge) => { const normalizedFirstHop = firstHopEdges.flatMap<TwoHopGraphEdge>((edge) => {
if (edge.kind === 'follows' && anchors.includes(edge.fromPhrase)) { if (edge.kind === 'follows' && anchors.includes(edge.fromPhrase)) {
return [{ from: edge.fromPhrase, to: edge.toPhrase, kind: 'follows' as const, weight: edge.weight }] return [{ from: edge.fromPhrase, to: edge.toPhrase, kind: 'follows', weight: edge.weight }]
} }
if (edge.kind === 'shares_terms') { if (edge.kind === 'shares_terms') {
if (anchors.includes(edge.fromPhrase)) { if (anchors.includes(edge.fromPhrase)) {
return [{ from: edge.fromPhrase, to: edge.toPhrase, kind: 'shares_terms' as const, weight: edge.weight }] return [{ from: edge.fromPhrase, to: edge.toPhrase, kind: 'shares_terms', weight: edge.weight }]
} }
if (anchors.includes(edge.toPhrase)) { if (anchors.includes(edge.toPhrase)) {
return [{ from: edge.toPhrase, to: edge.fromPhrase, kind: 'shares_terms' as const, weight: edge.weight }] return [{ from: edge.toPhrase, to: edge.fromPhrase, kind: 'shares_terms', weight: edge.weight }]
} }
} }
return [] return []

View file

@ -2145,7 +2145,7 @@ export class SuggestionService extends EventEmitter {
const anchor = this._anchor const anchor = this._anchor
const anchorKind = this._anchorKind const anchorKind = this._anchorKind
const provenance = this._provenance const provenance = this._provenance
const composing = this._lastContext?.isComposing === true const composing = this._lastContext?.isComposing === true && /[가-힣]$/u.test(acceptPrefix)
const appName = this._appName const appName = this._appName
const windowTitle = this._windowTitle const windowTitle = this._windowTitle
const targetWindow = this._windowHandle const targetWindow = this._windowHandle
@ -2251,7 +2251,9 @@ export class SuggestionService extends EventEmitter {
try { try {
if (deleteCount > 0) { if (deleteCount > 0) {
// 확정용 Space(+1)·백스페이스·붙여넣기(Ctrl, V) 키는 사용자 입력 통계에서 뺀다. // 확정용 Space(+1)·백스페이스·붙여넣기(Ctrl, V) 키는 사용자 입력 통계에서 뺀다.
this._learning.expectProgrammaticKeys?.(deleteCount + (composing ? 2 : 0) + 2) this._learning.expectProgrammaticKeys?.(
deleteCount + (composing ? 2 : 0) + (insertMethod === 'keyboard' ? 0 : 2)
)
} }
const result = const result =
deleteCount > 0 deleteCount > 0

View file

@ -25,6 +25,16 @@ const logger = getLogger('TextInsertService')
type InsertMethod = 'clipboard' | 'keyboard' type InsertMethod = 'clipboard' | 'keyboard'
export interface ReplacementOptions {
commitComposition?: boolean
/** Revalidate after queue/module waits, immediately before sending destructive keys. */
canApply?: () => boolean
/** Register synthetic input only when the replacement is about to run. */
beforeApply?: () => void
/** Automatic Windows corrections must not fall back to separate delete/type operations. */
requireAtomic?: boolean
}
interface InsertResult { interface InsertResult {
success: boolean success: boolean
/** 실제로 쓴 방식 — 클립보드를 되돌릴 수 없으면 'clipboard' 요청도 'keyboard' 가 된다 */ /** 실제로 쓴 방식 — 클립보드를 되돌릴 수 없으면 'clipboard' 요청도 'keyboard' 가 된다 */
@ -101,11 +111,14 @@ export class TextInsertService extends EventEmitter {
deleteCount: number, deleteCount: number,
text: string, text: string,
method: InsertMethod = 'clipboard', method: InsertMethod = 'clipboard',
options: { commitComposition?: boolean } = {} options: ReplacementOptions = {}
): Promise<InsertResult> { ): Promise<InsertResult> {
const run = this._tail.then(async () => { const run = this._tail.then(async () => {
const skipped = (): InsertResult => ({ success: false, method, textLength: 0, durationMs: 0 })
if (options.canApply && !options.canApply()) return skipped()
if (method === 'keyboard' && this._keyboard.replaceBeforeCaret) { if (method === 'keyboard' && this._keyboard.replaceBeforeCaret) {
const start = performance.now() const start = performance.now()
options.beforeApply?.()
const handled = await this._keyboard.replaceBeforeCaret(deleteCount, text, options) const handled = await this._keyboard.replaceBeforeCaret(deleteCount, text, options)
if (handled) { if (handled) {
this.emit('insert-started', { text, method: 'keyboard' }) this.emit('insert-started', { text, method: 'keyboard' })
@ -122,7 +135,12 @@ export class TextInsertService extends EventEmitter {
return result return result
} }
} }
if (options.requireAtomic) return skipped()
try { try {
// Loading the fallback adapter can take seconds. A check before this await is insufficient.
await this._keyboard.preload?.()
if (options.canApply && !options.canApply()) return skipped()
options.beforeApply?.()
let count = deleteCount let count = deleteCount
// 커서 앞 글자가 IME 조합 중이면 먼저 확정한다 (Space → 남은 공백까지 지운다). // 커서 앞 글자가 IME 조합 중이면 먼저 확정한다 (Space → 남은 공백까지 지운다).
if (options.commitComposition && this._keyboard.commitComposition) { if (options.commitComposition && this._keyboard.commitComposition) {

View file

@ -45,6 +45,7 @@ import { configGet, configSet } from './ConfigService'
import { getLogger } from './LoggerService' import { getLogger } from './LoggerService'
import { buildTypoCheckPrompt } from './llm-prompts' import { buildTypoCheckPrompt } from './llm-prompts'
import type { TypingContext } from './InputTelemetryService' import type { TypingContext } from './InputTelemetryService'
import type { ReplacementOptions } from './TextInsertService'
const logger = getLogger('TypoCorrectionService') const logger = getLogger('TypoCorrectionService')
@ -78,9 +79,13 @@ export type TypoVerdict = 'pass' | 'correcting' | 'checking'
export interface TypoCorrectionDeps { export interface TypoCorrectionDeps {
/** 커서 앞 deleteCount 글자를 지우고 text 를 넣는다. 성공 여부. */ /** 커서 앞 deleteCount 글자를 지우고 text 를 넣는다. 성공 여부. */
replaceBeforeCaret(deleteCount: number, text: string, options?: { commitComposition?: boolean }): Promise<boolean> replaceBeforeCaret(deleteCount: number, text: string, options?: ReplacementOptions): Promise<boolean>
/** 마지막 키보드 입력 시각 */ /** 마지막 키보드 입력 시각 */
lastKeyAt(): number lastKeyAt(): number
/** Monotonic revision including clicks/focus changes and same-millisecond key events. */
inputRevision(): number
/** OS-side activity also catches physical keys still waiting in the JS hook queue. */
nativeInputTick(): number | null
/** 곧 보낼 프로그램 키 수 (입력 통계 제외) */ /** 곧 보낼 프로그램 키 수 (입력 통계 제외) */
expectProgrammaticKeys(count: number): void expectProgrammaticKeys(count: number): void
/** 곧 삽입할 텍스트 (학습 제외). 취소 함수를 돌려준다. */ /** 곧 삽입할 텍스트 (학습 제외). 취소 함수를 돌려준다. */
@ -297,8 +302,12 @@ export class TypoCorrectionService extends EventEmitter {
const worthModel = this._worthModelCheck(region) const worthModel = this._worthModelCheck(region)
const model = configGet('typoAutoCorrectUseModel') !== false ? this._deps.warmModel() : null const model = configGet('typoAutoCorrectUseModel') !== false ? this._deps.warmModel() : null
if (!model || !worthModel) { if (!model || !worthModel) {
// 아직 공백·문장부호로 끝나지 않은 커서 끝 토큰(c.end === prefix.length)은 사용자가 다음 음절을
// 조합하는 도중일 수 있으므로 인플레이스 자동 백스페이스 삭제 대상에서 제외한다(제안 팝업 propose 에서만 제시).
const tailJamo = detectJamoNoise(prefix, { ignoredWords }).filter( const tailJamo = detectJamoNoise(prefix, { ignoredWords }).filter(
(c) => prefix.length - c.start <= MAX_MODEL_DELETE_CHARS (c) =>
(c.to !== '' ? c.end < prefix.length : /[ \t]$/u.test(c.from)) &&
prefix.length - c.start <= MAX_MODEL_DELETE_CHARS
) )
const jamoPlan = planTypoReplacement(prefix, tailJamo) const jamoPlan = planTypoReplacement(prefix, tailJamo)
if (jamoPlan && jamoPlan.deleteCount <= MAX_MODEL_DELETE_CHARS) { if (jamoPlan && jamoPlan.deleteCount <= MAX_MODEL_DELETE_CHARS) {
@ -453,7 +462,11 @@ export class TypoCorrectionService extends EventEmitter {
if (abort.signal.aborted || this._check?.abort !== abort) return if (abort.signal.aborted || this._check?.abort !== abort) return
// 인플레이스 모델 교정은 커서 바로 앞 어절(MAX_MODEL_DELETE_CHARS 이내)만 고친다. // 인플레이스 모델 교정은 커서 바로 앞 어절(MAX_MODEL_DELETE_CHARS 이내)만 고친다.
// 문장 앞쪽 단어를 고치려고 50~70자를 통째로 백스페이스하면 사용자의 다음 타이핑과 정면 충돌한다. // 문장 앞쪽 단어를 고치려고 50~70자를 통째로 백스페이스하면 사용자의 다음 타이핑과 정면 충돌한다.
const tailCorrections = mergeTypoCorrections(fromModel, detectJamoNoise(prefix, { ignoredWords })).filter( // 또한 커서 바로 끝(c.end === prefix.length)의 미완성 낱자 삭제는 자동 인플레이스 교정에서 제외한다.
const safeJamoNoise = detectJamoNoise(prefix, { ignoredWords }).filter((c) =>
c.to !== '' ? c.end < prefix.length : /[ \t]$/u.test(c.from)
)
const tailCorrections = mergeTypoCorrections(fromModel, safeJamoNoise).filter(
(c) => prefix.length - c.start <= MAX_MODEL_DELETE_CHARS (c) => prefix.length - c.start <= MAX_MODEL_DELETE_CHARS
) )
const basePlan = planTypoReplacement(prefix, tailCorrections) const basePlan = planTypoReplacement(prefix, tailCorrections)
@ -534,19 +547,19 @@ export class TypoCorrectionService extends EventEmitter {
private async _apply(plan: TypoReplacementPlan, context: TypingContext, keyAtDecision: number): Promise<boolean> { private async _apply(plan: TypoReplacementPlan, context: TypingContext, keyAtDecision: number): Promise<boolean> {
const preRegion = context.prefix.slice(typoRegionStart(context.prefix)) const preRegion = context.prefix.slice(typoRegionStart(context.prefix))
if (this._deps.lastKeyAt() !== keyAtDecision) { const revision = context.inputRevision ?? this._deps.inputRevision()
const canApply = (): boolean =>
this.isEnabled() &&
this._deps.lastKeyAt() === keyAtDecision &&
this._deps.inputRevision() === revision &&
(context.windowHandle == null || this._deps.foregroundHandle() === context.windowHandle) &&
(context.nativeInputTick === undefined ||
(context.nativeInputTick !== null && this._deps.nativeInputTick() === context.nativeInputTick))
if (!canApply()) {
this._unmarkRegionChecked(preRegion) this._unmarkRegionChecked(preRegion)
logger.debug('오타 교정 취소: 판단 뒤 키 입력이 있었다') logger.debug('오타 교정 취소: 입력 또는 포커스가 변경됐다')
return false return false
} }
if (context.windowHandle != null) {
const current = this._deps.foregroundHandle()
if (current !== null && current !== context.windowHandle) {
this._unmarkRegionChecked(preRegion)
logger.debug('오타 교정 취소: 포커스가 다른 창으로 옮겨 갔다')
return false
}
}
this._applying = true this._applying = true
// 커서 바로 앞 글자가 완성형 한글 음절([가-힣])이고 조합 중일 때만 Space 로 조합을 확정한 뒤 지운다. // 커서 바로 앞 글자가 완성형 한글 음절([가-힣])이고 조합 중일 때만 Space 로 조합을 확정한 뒤 지운다.
@ -554,14 +567,21 @@ export class TypoCorrectionService extends EventEmitter {
// 불필요한 Space 를 보내 앞의 글자까지 지우거나 유령 공백을 남기지 않는다. // 불필요한 Space 를 보내 앞의 글자까지 지우거나 유령 공백을 남기지 않는다.
const commitComposition = context.isComposing === true && /[가-힣]$/u.test(context.prefix) const commitComposition = context.isComposing === true && /[가-힣]$/u.test(context.prefix)
// 확정용 Space(+2)·백스페이스 + 붙여넣기(Ctrl, V) 키는 사용자 입력 통계에서 뺀다. // 확정용 Space(+2)·백스페이스 + 붙여넣기(Ctrl, V) 키는 사용자 입력 통계에서 뺀다.
this._deps.expectProgrammaticKeys(plan.deleteCount + (commitComposition ? 2 : 0) + 2) let cancelInsert = (): void => undefined
const cancelInsert = this._deps.expectProgrammaticInsert(plan.insertText)
try { try {
const ok = commitComposition const ok = await this._deps.replaceBeforeCaret(plan.deleteCount, plan.insertText, {
? await this._deps.replaceBeforeCaret(plan.deleteCount, plan.insertText, { commitComposition: true }) commitComposition,
: await this._deps.replaceBeforeCaret(plan.deleteCount, plan.insertText) canApply,
requireAtomic: process.platform === 'win32',
beforeApply: () => {
cancelInsert()
this._deps.expectProgrammaticKeys(plan.deleteCount + (commitComposition ? 2 : 0) + 2)
cancelInsert = this._deps.expectProgrammaticInsert(plan.insertText)
}
})
if (!ok) { if (!ok) {
cancelInsert() cancelInsert()
this._deps.expectProgrammaticKeys(0)
this._unmarkRegionChecked(preRegion) this._unmarkRegionChecked(preRegion)
logger.warn('오타 교정 삽입 실패') logger.warn('오타 교정 삽입 실패')
return false return false
@ -587,6 +607,7 @@ export class TypoCorrectionService extends EventEmitter {
return true return true
} catch (error) { } catch (error) {
cancelInsert() cancelInsert()
this._deps.expectProgrammaticKeys(0)
this._lastCheckedRegion = '' this._lastCheckedRegion = ''
logger.warn(`오타 교정 예외: ${error instanceof Error ? error.message : String(error)}`) logger.warn(`오타 교정 예외: ${error instanceof Error ? error.message : String(error)}`)
return false return false

View file

@ -1,7 +1,8 @@
// 기록과 회의를 스키마 변경 없이 함께 찾는 로컬 통합 검색. // 기록과 회의를 스키마 변경 없이 함께 찾는 로컬 통합 검색.
import { EventEmitter } from 'events' import { EventEmitter } from 'events'
import { count, desc, or } from 'drizzle-orm' import { count, desc, inArray, or } from 'drizzle-orm'
import { formatTranscriptTimestamp, parseTranscriptLines } from '@d3ro/core/meeting-transcript'
import { D3ROError, ErrorCode } from '@d3ro/core/errors' import { D3ROError, ErrorCode } from '@d3ro/core/errors'
import type { import type {
UnifiedSearchParams, UnifiedSearchParams,
@ -10,7 +11,14 @@ import type {
} from '@d3ro/core/types' } from '@d3ro/core/types'
import { getDatabase } from '../db' import { getDatabase } from '../db'
import { containsPattern } from '../db/like-pattern' import { containsPattern } from '../db/like-pattern'
import { history, meetingSessions, type History, type MeetingSessionRow } from '../db/schema' import {
history,
meetingMemos,
meetingSessions,
type History,
type MeetingMemoRow,
type MeetingSessionRow,
} from '../db/schema'
import { getLogger } from './LoggerService' import { getLogger } from './LoggerService'
const logger = getLogger('UnifiedSearchService') const logger = getLogger('UnifiedSearchService')
@ -86,18 +94,59 @@ function recordResult(row: History, query: string): UnifiedSearchResult {
} }
} }
function meetingResult(row: MeetingSessionRow, query: string): UnifiedSearchResult { function findMatchingTranscriptSegmentSnippet(
transcript: string | null | undefined,
query: string,
): string | null {
const lines = parseTranscriptLines(transcript)
for (const line of lines) {
if (includesQuery(line.text, query) || includesQuery(line.speaker, query)) {
if (!line.timed) return line.text
const speakerPrefix = line.speaker ? `[${line.speaker}] ` : ''
return `[${formatTranscriptTimestamp(line.timestampMs)}] ${speakerPrefix}${line.text}`
}
}
return null
}
function formatMemoSnippet(memo: MeetingMemoRow): string {
return `[${formatTranscriptTimestamp(memo.timestampMs)}] ${memo.content}`
}
function meetingResult(
row: MeetingSessionRow,
query: string,
memoMatch?: MeetingMemoRow,
): UnifiedSearchResult {
const titleMatched = includesQuery(row.title, query) const titleMatched = includesQuery(row.title, query)
const matchingTranscript = [row.editedTranscript, row.rawTranscript] const matchingTranscript = [row.editedTranscript, row.rawTranscript]
.find((value) => includesQuery(value, query)) .find((value) => includesQuery(value, query))
const displayContent = matchingTranscript ?? row.editedTranscript ?? row.rawTranscript ?? row.title const segmentSnippet = findMatchingTranscriptSegmentSnippet(
matchingTranscript ?? row.editedTranscript ?? row.rawTranscript,
query,
)
const memoSnippet = memoMatch ? formatMemoSnippet(memoMatch) : null
const displayContent = segmentSnippet
?? matchingTranscript
?? memoSnippet
?? row.editedTranscript
?? row.rawTranscript
?? row.title
const matchedField = titleMatched && !matchingTranscript && !memoSnippet
? 'title'
: matchingTranscript || segmentSnippet
? 'transcript'
: memoSnippet
? 'content'
: 'transcript'
return { return {
source: 'meeting', source: 'meeting',
id: row.id, id: row.id,
title: row.title, title: row.title,
excerpt: createUnifiedSearchExcerpt(displayContent, query), excerpt: createUnifiedSearchExcerpt(displayContent, query),
matchedField: titleMatched ? 'title' : 'transcript', matchedField,
occurredAt: row.startedAt, occurredAt: row.startedAt,
} }
} }
@ -147,16 +196,49 @@ class UnifiedSearchService extends EventEmitter {
.select() .select()
.from(meetingSessions) .from(meetingSessions)
.where(meetingConditions) .where(meetingConditions)
.orderBy(desc(meetingSessions.startedAt)) .orderBy(desc(meetingSessions.createdAt))
.limit(limit)
.all()
const memoRows = db
.select()
.from(meetingMemos)
.where(pattern.match(meetingMemos.content))
.orderBy(desc(meetingMemos.timestampMs))
.limit(limit) .limit(limit)
.all() .all()
const memoBySessionId = new Map<string, MeetingMemoRow>()
for (const memo of memoRows) {
if (!memoBySessionId.has(memo.sessionId)) {
memoBySessionId.set(memo.sessionId, memo)
}
}
const directMeetingIds = new Set(meetingRows.map((row) => row.id))
const missingSessionIds = [...memoBySessionId.keys()].filter(
(sessionId) => !directMeetingIds.has(sessionId),
)
const memoMatchedMeetings = missingSessionIds.length > 0
? db
.select()
.from(meetingSessions)
.where(inArray(meetingSessions.id, missingSessionIds))
.orderBy(desc(meetingSessions.createdAt))
.limit(limit)
.all()
: []
const combinedMeetingRows = [...meetingRows, ...memoMatchedMeetings]
const results = mergeUnifiedSearchResults( const results = mergeUnifiedSearchResults(
recordRows.map((row) => recordResult(row, query)), recordRows.map((row) => recordResult(row, query)),
meetingRows.map((row) => meetingResult(row, query)), combinedMeetingRows.map((row) => meetingResult(row, query, memoBySessionId.get(row.id))),
limit, limit,
) )
return { query, results, total: recordTotal + meetingTotal } return {
query,
results,
total: recordTotal + meetingTotal + memoMatchedMeetings.length,
}
} catch (error) { } catch (error) {
const message = error instanceof Error ? error.message : String(error) const message = error instanceof Error ? error.message : String(error)
logger.error(`Unified search failed: ${message}`) logger.error(`Unified search failed: ${message}`)

View file

@ -162,6 +162,86 @@ class VoiceConversationService extends EventEmitter {
this._sendToRenderer(IPC_CHANNELS.VOICE_CONVERSATION.STATE_CHANGED, this.getSessionInfo()) this._sendToRenderer(IPC_CHANNELS.VOICE_CONVERSATION.STATE_CHANGED, this.getSessionInfo())
} }
/**
* 이전 대화 메시지(또는 지정한 텍스트)를 TTS로 다시 읽어준다.
* 활성 세션 중이면 마이크 캡처를 일시 중지하고 speaking 상태로 재생한 뒤 다시 listening으로 복귀한다.
*/
async replayMessage(
target?: string | { messageId?: string; text?: string },
): Promise<void> {
let textToSpeak = ''
if (typeof target === 'string') {
const found = this._messages.find((m) => m.id === target)
if (found) {
textToSpeak = found.content
} else if (this._messages.length === 0 && target.trim().length > 0) {
textToSpeak = target
} else {
throw new D3ROError(ErrorCode.ConversationLLMFailed, `Conversation message not found: ${target}`)
}
} else if (target && typeof target === 'object') {
if (target.messageId) {
const found = this._messages.find((m) => m.id === target.messageId)
if (found) {
textToSpeak = found.content
} else if (typeof target.text === 'string' && target.text.trim().length > 0) {
textToSpeak = target.text
} else {
throw new D3ROError(
ErrorCode.ConversationLLMFailed,
`Conversation message not found: ${target.messageId}`,
)
}
} else if (typeof target.text === 'string') {
textToSpeak = target.text
}
} else {
for (let i = this._messages.length - 1; i >= 0; i--) {
if (this._messages[i].role === 'assistant') {
textToSpeak = this._messages[i].content
break
}
}
}
const trimmed = textToSpeak.trim()
if (!trimmed) {
throw new D3ROError(ErrorCode.ConversationLLMFailed, 'No conversation message to replay')
}
const sentences = trimmed
.split(/(?<=[.!?。!?])\s+/)
.map((s) => s.trim())
.filter((s) => s.length > 0)
const ttsSentences = sentences.length > 0 ? sentences : [trimmed]
const wasActive = this._isActive
const turn = this._turn
if (wasActive) {
this._stopListening()
this._setState('speaking')
}
this._sendToRenderer(IPC_CHANNELS.VOICE_CONVERSATION.TTS_STARTED, {})
try {
await getTTSPlaybackService().speakSentences(ttsSentences)
} finally {
if (!wasActive || (this._isActive && this._turn === turn)) {
this._sendToRenderer(IPC_CHANNELS.VOICE_CONVERSATION.TTS_FINISHED, {})
}
if (wasActive && this._isActive && this._turn === turn) {
this._resumeListening()
}
}
}
async speakMessage(
target?: string | { messageId?: string; text?: string },
): Promise<void> {
return this.replayMessage(target)
}
// ── 내부 로직 ── // ── 내부 로직 ──
private _setState(state: ConversationState): void { private _setState(state: ConversationState): void {

View file

@ -30,6 +30,7 @@ import { getLlmGateway } from './llm/LlmGateway'
import { buildInstructionInvocation, resolveTargetLanguage } from './llm-prompts' import { buildInstructionInvocation, resolveTargetLanguage } from './llm-prompts'
import { D3ROError, ErrorCode } from '@d3ro/core/errors' import { D3ROError, ErrorCode } from '@d3ro/core/errors'
import { cleanDictatedText } from '@d3ro/core/dictation-cleaner' import { cleanDictatedText } from '@d3ro/core/dictation-cleaner'
import { composeInstructionPipelinePrompt, parseActiveInstructionIds } from '@d3ro/core/instruction-template'
import { TIMING } from '@d3ro/core/constants' import { TIMING } from '@d3ro/core/constants'
import { RecognitionState, AudioState } from '@d3ro/core/types' import { RecognitionState, AudioState } from '@d3ro/core/types'
import type { KeyBindingActionId, VoiceMode, VoiceState, LLMAction } from '@d3ro/core/types' import type { KeyBindingActionId, VoiceMode, VoiceState, LLMAction } from '@d3ro/core/types'
@ -132,6 +133,8 @@ class SessionRun {
audioStarted = false audioStarted = false
/** 사용자가 이미 정지를 요청했다 — 두 번째 release/토글은 무시한다 */ /** 사용자가 이미 정지를 요청했다 — 두 번째 release/토글은 무시한다 */
stopRequested = false stopRequested = false
/** 이 세션을 시작한 키바인딩 액션 */
actionId: KeyBindingActionId = 'dictation'
sttReady = false sttReady = false
transcribing = false transcribing = false
audioBuffer: Buffer[] = [] audioBuffer: Buffer[] = []
@ -266,11 +269,23 @@ class VoiceModeService extends EventEmitter {
*/ */
connectKeyBindings(): void { connectKeyBindings(): void {
this._keyBindingHandler = (payload) => { this._keyBindingHandler = (payload) => {
this.handleShortcutTrigger(payload)
}
getKeyBindingService().on('triggered', this._keyBindingHandler)
logger.info('Key binding events connected')
}
/**
* 키바인딩 트리거 이벤트를 받아 세션 액션 큐에 넣는다.
*/
handleShortcutTrigger(payload: KeyBindingTriggerPayload): void {
switch (payload.actionId) { switch (payload.actionId) {
case 'caption': case 'caption':
// Phase 10.1: caption은 VoiceModeService가 아닌 CaptionService로 라우팅. // Phase 10.1: caption은 VoiceModeService가 아닌 CaptionService로 라우팅.
// 토글이므로 press만 처리하고 release는 버린다. // 토글이므로 press만 처리하고 release는 버린다.
if (payload.type === 'pressed') this._toggleCaption() if (payload.type === 'pressed') void this._toggleCaption()
return return
case 'dictation': case 'dictation':
case 'hands-free': case 'hands-free':
@ -282,7 +297,7 @@ class VoiceModeService extends EventEmitter {
return return
} }
const holdMode = resolveGestureHoldMode(payload.actionId, payload.holdMode) const holdMode = this._resolveHoldMode(payload.actionId, payload.holdMode)
const action: VoiceAction = { const action: VoiceAction = {
type: payload.type === 'pressed' ? 'press' : 'release', type: payload.type === 'pressed' ? 'press' : 'release',
timestamp: payload.timestamp, timestamp: payload.timestamp,
@ -293,14 +308,16 @@ class VoiceModeService extends EventEmitter {
this._enqueueAction(action) this._enqueueAction(action)
} }
getKeyBindingService().on('triggered', this._keyBindingHandler) _resolveHoldMode(actionId: KeyBindingActionId, specHoldMode = false): boolean {
return resolveGestureHoldMode(actionId, specHoldMode)
logger.info('Key binding events connected')
} }
// ── 세션 제어 ────────────────────────────────────────── // ── 세션 제어 ──────────────────────────────────────────
async startSession(mode: VoiceMode): Promise<void> { async startSession(
mode: VoiceMode,
options?: { actionId?: KeyBindingActionId },
): Promise<void> {
if (this._disposed) return if (this._disposed) return
if (this._session && !this._isInTerminalState()) { if (this._session && !this._isInTerminalState()) {
logger.warn('Session already active, ignoring startSession') logger.warn('Session already active, ignoring startSession')
@ -380,6 +397,7 @@ class VoiceModeService extends EventEmitter {
// 세션 생성 // 세션 생성
const run = new SessionRun(randomUUID()) const run = new SessionRun(randomUUID())
run.actionId = options?.actionId ?? (mode === 'hands-free' ? 'hands-free' : 'dictation')
run.captureSelection = windowContext !== null run.captureSelection = windowContext !== null
run.windowContext = windowContext run.windowContext = windowContext
this._run = run this._run = run
@ -469,7 +487,7 @@ class VoiceModeService extends EventEmitter {
// 핫키를 뗀 뒤라 복사 단축키가 안전하다 — LLM 이 쓸 것이 확실하면 전사와 병렬로 선택 텍스트를 // 핫키를 뗀 뒤라 복사 단축키가 안전하다 — LLM 이 쓸 것이 확실하면 전사와 병렬로 선택 텍스트를
// 캡처한다. 원문 삽입 경로(none·LLM 불가)에선 보내지 않는다: 쓰지도 않을 Ctrl+C 가 터미널에선 // 캡처한다. 원문 삽입 경로(none·LLM 불가)에선 보내지 않는다: 쓰지도 않을 Ctrl+C 가 터미널에선
// 프로세스를 중단시킨다. 음성 단축키로 LLM 경로가 될 수도 있으면 LLM 단계에서 늦게 캡처한다. // 프로세스를 중단시킨다. 음성 단축키로 LLM 경로가 될 수도 있으면 LLM 단계에서 늦게 캡처한다.
if (routeUsesLlm(this._resolveLlmRoute(null))) this._startSelectionCapture(run) if (routeUsesLlm(this._resolveLlmRoute(null, run.actionId))) this._startSelectionCapture(run)
// 버퍼가 있으면 STT에 전달 // 버퍼가 있으면 STT에 전달
if (run.audioBuffer.length > 0 && run.sttReady) { if (run.audioBuffer.length > 0 && run.sttReady) {
@ -924,20 +942,30 @@ class VoiceModeService extends EventEmitter {
return return
} }
if (this._session) { let rawText = result.text
this._session.transcription = result.text try {
const { getDictionaryService } = await import('./DictionaryService')
const corrected = getDictionaryService().applyDictionaryCorrections(rawText)
rawText = corrected.text
} catch {
// DictionaryService 미초기화 시 무시
} }
this.emit('transcription-update', { text: result.text, isFinal: true }) if (this._session) {
this._session.transcription = rawText
}
this.emit('transcription-update', { text: rawText, isFinal: true })
// Phase 10.5: 음성 단축키 — 키워드 매칭으로 LLM 명령어 자동 선택 // Phase 10.5: 음성 단축키 — 키워드 매칭으로 LLM 명령어 자동 선택
let effectiveText = result.text // 'command' 핫키로 진입한 세션은 voiceCommandsEnabled 설정과 무관하게 음성 명령 매칭을 항상 수행한다.
let effectiveText = rawText
let overrideInstructionId: string | null = null let overrideInstructionId: string | null = null
try { try {
const { getVoiceCommandService } = await import('./VoiceCommandService') const { getVoiceCommandService } = await import('./VoiceCommandService')
const vcSvc = getVoiceCommandService() const vcSvc = getVoiceCommandService()
if (vcSvc.isEnabled()) { if (run.actionId === 'command' || vcSvc.isEnabled()) {
const match = vcSvc.match(result.text) const match = vcSvc.match(rawText)
if (match.matched && match.instructionId) { if (match.matched && match.instructionId) {
effectiveText = match.cleanedText effectiveText = match.cleanedText
overrideInstructionId = match.instructionId overrideInstructionId = match.instructionId
@ -952,7 +980,7 @@ class VoiceModeService extends EventEmitter {
// 결정적 구어 군더더기·추임새·말바꾸기·중복·동음이의어 1차 정리 (LLM 유무와 무관하게 0ms 즉시 적용) // 결정적 구어 군더더기·추임새·말바꾸기·중복·동음이의어 1차 정리 (LLM 유무와 무관하게 0ms 즉시 적용)
effectiveText = cleanDictatedText(effectiveText) effectiveText = cleanDictatedText(effectiveText)
const route = this._resolveLlmRoute(overrideInstructionId) const route = this._resolveLlmRoute(overrideInstructionId, run.actionId)
if (route.kind === 'insert-raw') { if (route.kind === 'insert-raw') {
if (route.reason === 'llm-unavailable') { if (route.reason === 'llm-unavailable') {
this.emit('error', { this.emit('error', {
@ -999,10 +1027,16 @@ class VoiceModeService extends EventEmitter {
} }
/** 현재 설정으로 LLM 후처리 경로를 결정한다 (정책은 @d3ro/core/voice-llm-route 가 소유) */ /** 현재 설정으로 LLM 후처리 경로를 결정한다 (정책은 @d3ro/core/voice-llm-route 가 소유) */
private _resolveLlmRoute(overrideInstructionId: string | null): VoiceLlmRoute { private _resolveLlmRoute(
overrideInstructionId: string | null,
actionId: KeyBindingActionId | undefined = this._run?.actionId,
): VoiceLlmRoute {
const backend = configGet('llmBackend') const backend = configGet('llmBackend')
const configuredAction = configGet('defaultLLMAction')
const defaultAction =
actionId === 'command' && configuredAction === 'none' ? 'refine' : configuredAction
return resolveVoiceLlmRoute({ return resolveVoiceLlmRoute({
defaultAction: configGet('defaultLLMAction'), defaultAction,
overrideInstructionId, overrideInstructionId,
activeChainId: configGet('activeChainId') ?? null, activeChainId: configGet('activeChainId') ?? null,
activeInstructionId: configGet('activeInstructionId') ?? null, activeInstructionId: configGet('activeInstructionId') ?? null,
@ -1073,19 +1107,33 @@ class VoiceModeService extends EventEmitter {
} }
} }
/** 지시문(음성 단축키 또는 활성 지시문)으로 처리한다. 지시문이 없으면 지시문 없이 custom 처리 */ /** 지시문(음성 단축키 또는 활성 지시문·파이프라인)으로 처리한다. 지시문이 없으면 지시문 없이 custom 처리 */
private async _processWithInstruction(userText: string, instructionId: string | null): Promise<string> { private async _processWithInstruction(userText: string, instructionId: string | null): Promise<string> {
let invocationText = userText let invocationText = userText
let instructionPrompt: string | undefined let instructionPrompt: string | undefined
if (instructionId) { if (instructionId) {
const { getCustomInstructionService } = await import('./CustomInstructionService') const { getCustomInstructionService } = await import('./CustomInstructionService')
const instruction = getCustomInstructionService().getById(instructionId) const svc = getCustomInstructionService()
if (instruction) { const ids = parseActiveInstructionIds(instructionId)
const matched = ids
.map((id) => svc.getById(id))
.filter((item): item is NonNullable<typeof item> => item !== null)
if (matched.length === 1) {
const instruction = matched[0]
const invocation = buildInstructionInvocation(instruction.prompt, userText, resolveTargetLanguage()) const invocation = buildInstructionInvocation(instruction.prompt, userText, resolveTargetLanguage())
invocationText = invocation.text invocationText = invocation.text
instructionPrompt = invocation.systemPrompt instructionPrompt = invocation.systemPrompt
logger.info(`Using custom instruction: "${instruction.name}"`) logger.info(`Using custom instruction: "${instruction.name}"`)
} else if (matched.length >= 2) {
const composedPrompt = composeInstructionPipelinePrompt(matched)
const invocation = buildInstructionInvocation(composedPrompt, userText, resolveTargetLanguage())
invocationText = invocation.text
instructionPrompt = invocation.systemPrompt
logger.info(
`Using custom instruction pipeline (${matched.length} steps): ${matched.map((i) => i.name).join(' → ')}`,
)
} else { } else {
logger.warn(`Custom instruction not found: ${instructionId} — processing without an instruction`) logger.warn(`Custom instruction not found: ${instructionId} — processing without an instruction`)
} }
@ -1275,7 +1323,7 @@ class VoiceModeService extends EventEmitter {
) )
switch (intent.kind) { switch (intent.kind) {
case 'start': case 'start':
await this.startSession(intent.mode) await this.startSession(intent.mode, { actionId: action.actionId })
break break
case 'stop': case 'stop':
// Speakly 패턴: 딜레이 없이 즉시 stop (딜레이가 race condition 유발) // Speakly 패턴: 딜레이 없이 즉시 stop (딜레이가 race condition 유발)

View file

@ -22,6 +22,7 @@ import { PubMaticAdapter } from './PubMaticAdapter'
import { MintegralAdapter } from './MintegralAdapter' import { MintegralAdapter } from './MintegralAdapter'
import { DirectHouseSponsorAdapter } from './DirectHouseSponsorAdapter' import { DirectHouseSponsorAdapter } from './DirectHouseSponsorAdapter'
import { getAdSettlementService } from './AdSettlementService' import { getAdSettlementService } from './AdSettlementService'
import { getLicenseService } from '../LicenseService'
export class AdMediationEngine { export class AdMediationEngine {
private static instance: AdMediationEngine | null = null private static instance: AdMediationEngine | null = null
@ -30,6 +31,8 @@ export class AdMediationEngine {
private impressionHistory: AdImpressionEvent[] = [] private impressionHistory: AdImpressionEvent[] = []
private deliveredCreatives = new Map<string, AdCreativePayload>() private deliveredCreatives = new Map<string, AdCreativePayload>()
private clickedCreatives = new Set<string>() private clickedCreatives = new Set<string>()
private claimedRewards = new Set<string>()
private lastRewardClaimedAt = 0
private constructor() { private constructor() {
// Provider shells stay registered for explicit configuration diagnostics, // Provider shells stay registered for explicit configuration diagnostics,
@ -280,12 +283,21 @@ export class AdMediationEngine {
getAdSettlementService().recordClick(networkId) getAdSettlementService().recordClick(networkId)
} }
public async claimReward(adId: string, networkId: string): Promise<AdRewardResult> { public async reportRewardCompletion(
// Desktop mediation has no server-verified completion/nonce ledger. A adId: string,
// timer, renderer-supplied ID, or adapter callback is not entitlement networkId: string,
// proof, so rewards remain unavailable until that boundary exists. nonce?: string,
void adId ): Promise<AdRewardResult> {
void networkId return this.claimReward(adId, networkId, nonce)
}
public async claimReward(
adId: string,
networkId: string,
nonce?: string,
): Promise<AdRewardResult> {
const trimmedAdId = adId?.trim()
if (!trimmedAdId || !networkId) {
return { return {
success: false, success: false,
tokensAdded: 0, tokensAdded: 0,
@ -293,6 +305,97 @@ export class AdMediationEngine {
} }
} }
const delivered = this.deliveredCreatives.get(trimmedAdId)
const impression = this.impressionHistory.find((candidate) => candidate.adId === trimmedAdId)
if (
delivered === undefined ||
delivered.networkId !== networkId ||
impression === undefined
) {
return {
success: false,
tokensAdded: 0,
newTotalQuota: 0,
}
}
const claimKey = nonce?.trim() ? `${trimmedAdId}:${nonce.trim()}` : trimmedAdId
if (this.claimedRewards.has(trimmedAdId) || this.claimedRewards.has(claimKey)) {
return {
success: false,
tokensAdded: 0,
newTotalQuota: 0,
}
}
const now = Date.now()
const cooldownMs = Math.max(0, this.config.rewardCooldownSeconds * 1000)
if (this.lastRewardClaimedAt > 0 && now - this.lastRewardClaimedAt < cooldownMs) {
return {
success: false,
tokensAdded: 0,
newTotalQuota: 0,
nextAvailableAt: this.lastRewardClaimedAt + cooldownMs,
}
}
const adapter = this.adapters.get(networkId)
if (!adapter?.reportRewardCompletion) {
return {
success: false,
tokensAdded: 0,
newTotalQuota: 0,
}
}
const completion = await adapter
.reportRewardCompletion(trimmedAdId)
.catch(() => ({ success: false, tokenReward: 0 }))
if (!completion.success) {
return {
success: false,
tokensAdded: 0,
newTotalQuota: 0,
}
}
const rawTokens =
completion.tokenReward > 0
? completion.tokenReward
: (delivered.rewardTokens ?? this.config.rewardTokensAmount)
const tokensToGrant = rawTokens > 0 ? rawTokens : this.config.rewardTokensAmount
if (tokensToGrant <= 0) {
return {
success: false,
tokensAdded: 0,
newTotalQuota: 0,
}
}
const grantResult = getLicenseService().grantRewardQuota(tokensToGrant, claimKey)
if (!grantResult.granted) {
return {
success: false,
tokensAdded: 0,
newTotalQuota: 0,
}
}
this.claimedRewards.add(trimmedAdId)
this.claimedRewards.add(claimKey)
this.lastRewardClaimedAt = now
impression.completed = true
getAdSettlementService().recordCompletion(networkId)
return {
success: true,
tokensAdded: grantResult.tokensAdded,
newTotalQuota: grantResult.newTotalQuota,
nextAvailableAt: now + cooldownMs,
rewardId: grantResult.rewardId,
}
}
public getRevenueStats(period = new Date().toISOString().slice(0, 7)): AdRevenueStats { public getRevenueStats(period = new Date().toISOString().slice(0, 7)): AdRevenueStats {
return getAdSettlementService().getRevenueStats(period) return getAdSettlementService().getRevenueStats(period)
} }

View file

@ -25,6 +25,10 @@ export type LicenseStoreField =
// cloud entitlement // cloud entitlement
| 'licenseCloudTier' | 'licenseCloudTier'
| 'licenseCloudVerifiedAt' | 'licenseCloudVerifiedAt'
// rewarded ad bonus quota (daily + replay nonces)
| 'licenseRewardBonusDate'
| 'licenseRewardBonusAmount'
| 'licenseRewardClaimedNonces'
// combined view (kept for older app versions that read the same file) // combined view (kept for older app versions that read the same file)
| 'licenseTier' | 'licenseTier'
| 'licenseLastVerifiedAt' | 'licenseLastVerifiedAt'

View file

@ -2,6 +2,7 @@
// LLM 시스템 프롬프트 SSOT — PremiumLLMService 공용. // LLM 시스템 프롬프트 SSOT — PremiumLLMService 공용.
import { getLogger } from './LoggerService' import { getLogger } from './LoggerService'
import * as ConfigServiceModule from './ConfigService'
import type { LLMAction } from '@d3ro/core/types' import type { LLMAction } from '@d3ro/core/types'
import { import {
fillInstructionPlaceholders, fillInstructionPlaceholders,
@ -52,23 +53,49 @@ const BASE_SYSTEM_PROMPTS: Record<string, string> = {
/** /**
* 번역 대상 언어 기본값. * 번역 대상 언어 기본값.
* `AppConfig`에는 번역 대상 언어 키가 없다 (`language`는 UI 로케일,
* `sttLanguage`는 입력 언어라 둘 다 대상 언어가 아니다).
*/ */
export const DEFAULT_TARGET_LANGUAGE = 'English' export const DEFAULT_TARGET_LANGUAGE = 'English'
/**
* 설정 UI에서 고를 수 있는 번역 대상 언어 목록.
* 프롬프트(`{{targetLanguage}}로 번역해주세요`)에 자연스럽게 들어가도록 명확한 언어 이름을 쓴다.
*/
export const SUPPORTED_TARGET_LANGUAGES = [
'English',
'Korean',
'Japanese',
'Chinese (Simplified)',
'Chinese (Traditional)',
'Spanish',
'French',
'German',
'Portuguese',
'Vietnamese',
'Indonesian',
'Arabic',
] as const
export type SupportedTargetLanguage = (typeof SUPPORTED_TARGET_LANGUAGES)[number]
/** /**
* 번역 대상 언어를 해석한다. LLM을 호출하는 모든 경로가 이 함수를 쓴다. * 번역 대상 언어를 해석한다. LLM을 호출하는 모든 경로가 이 함수를 쓴다.
* *
* `AppConfig`에는 번역 대상 언어 키가 없다 — `language`는 UI 로케일이고 * 명시 인자가 있으면 우선하고, 없으면 `AppConfig.targetLanguage` 설정값을 읽는다.
* `sttLanguage`는 입력(원문) 언어라 어느 쪽도 대상 언어로 쓸 수 없다. * 설정 서비스가 초기화되지 않았거나 값이 비어 있으면 {@link DEFAULT_TARGET_LANGUAGE}로 폴백한다.
* (입력 언어로 번역하면 원문 그대로가 되고, UI 로케일은 `'ko'` 같은 코드라
* 프롬프트에 그대로 넣으면 문장이 깨진다.)
*
* 따라서 현재는 {@link DEFAULT_TARGET_LANGUAGE} 고정이다. 사용자가 대상 언어를
* 고를 수 있으려면 설정 키가 필요하다.
*/ */
export function resolveTargetLanguage(): string { export function resolveTargetLanguage(explicit?: string | null): string {
if (typeof explicit === 'string' && explicit.trim().length > 0) {
return explicit.trim()
}
if (Object.keys(ConfigServiceModule).includes('getConfigService')) {
const store = ConfigServiceModule.getConfigService()
if (store) {
const configured = store.get('targetLanguage')
if (typeof configured === 'string' && configured.trim().length > 0) {
return configured.trim()
}
}
}
return DEFAULT_TARGET_LANGUAGE return DEFAULT_TARGET_LANGUAGE
} }
@ -105,7 +132,7 @@ function warnUnresolved(unresolved: readonly string[]): void {
function renderWithDefaults(prompt: string, vars: InstructionVars): RenderedInstruction { function renderWithDefaults(prompt: string, vars: InstructionVars): RenderedInstruction {
const rendered = renderInstruction(prompt, { const rendered = renderInstruction(prompt, {
text: vars.text, text: vars.text,
targetLanguage: vars.targetLanguage ?? DEFAULT_TARGET_LANGUAGE, targetLanguage: resolveTargetLanguage(vars.targetLanguage),
}) })
// 조용히 새어나간 플레이스홀더가 LLM에 그대로 전달되는 사고가 있었다. // 조용히 새어나간 플레이스홀더가 LLM에 그대로 전달되는 사고가 있었다.
warnUnresolved(rendered.unresolved) warnUnresolved(rendered.unresolved)
@ -120,7 +147,7 @@ export function renderInstructionPrompt(prompt: string, vars: InstructionVars):
warnUnresolved(findUnresolvedPlaceholders(prompt)) warnUnresolved(findUnresolvedPlaceholders(prompt))
return fillInstructionPlaceholders(prompt, { return fillInstructionPlaceholders(prompt, {
text: vars.text, text: vars.text,
targetLanguage: vars.targetLanguage ?? DEFAULT_TARGET_LANGUAGE, targetLanguage: resolveTargetLanguage(vars.targetLanguage),
}) })
} }
@ -176,7 +203,7 @@ export function resolveSystemPrompt(
if (action === 'translate') { if (action === 'translate') {
return BASE_SYSTEM_PROMPTS.translate.replace( return BASE_SYSTEM_PROMPTS.translate.replace(
'{{targetLanguage}}', '{{targetLanguage}}',
targetLanguage ?? DEFAULT_TARGET_LANGUAGE, resolveTargetLanguage(targetLanguage),
) )
} }
return BASE_SYSTEM_PROMPTS[action] ?? BASE_SYSTEM_PROMPTS[CUSTOM_FALLBACK_ACTION] return BASE_SYSTEM_PROMPTS[action] ?? BASE_SYSTEM_PROMPTS[CUSTOM_FALLBACK_ACTION]

View file

@ -49,8 +49,8 @@ export const STT_PROVIDERS_META: STTProviderInfo[] = [
{ {
id: 'local', id: 'local',
name: 'Local Whisper', name: 'Local Whisper',
description: '100% 완전 오프라인, 무료, 프라이버시 보호', description: 'Local faster-whisper inference on device',
badge: 'Offline · Free', badge: 'Local · On-Device',
requiresApiKey: false, requiresApiKey: false,
defaultModel: 'large-v3-turbo', defaultModel: 'large-v3-turbo',
models: ['tiny', 'base', 'small', 'medium', 'large-v3', 'large-v3-turbo'], models: ['tiny', 'base', 'small', 'medium', 'large-v3', 'large-v3-turbo'],
@ -59,8 +59,8 @@ export const STT_PROVIDERS_META: STTProviderInfo[] = [
{ {
id: 'd3ro-cloud', id: 'd3ro-cloud',
name: 'D3RO Cloud STT (Managed)', name: 'D3RO Cloud STT (Managed)',
description: 'D3RO 클라우드 매니지드 전사 서비스 (키 설정 불필요)', description: 'Managed cloud speech-to-text gateway',
badge: 'Cloud · Zero Config', badge: 'Cloud · Managed',
requiresApiKey: false, requiresApiKey: false,
defaultModel: 'default', defaultModel: 'default',
defaultBaseUrl: 'http://127.0.0.1:5000', defaultBaseUrl: 'http://127.0.0.1:5000',
@ -70,8 +70,8 @@ export const STT_PROVIDERS_META: STTProviderInfo[] = [
{ {
id: 'openai', id: 'openai',
name: 'OpenAI Whisper', name: 'OpenAI Whisper',
description: '공식 OpenAI 고품질 다국어 음성 인식', description: 'OpenAI Audio Transcriptions API',
badge: 'Standard · High Accuracy', badge: 'Cloud · OpenAI API',
requiresApiKey: true, requiresApiKey: true,
defaultModel: 'whisper-1', defaultModel: 'whisper-1',
defaultBaseUrl: 'https://api.openai.com/v1', defaultBaseUrl: 'https://api.openai.com/v1',
@ -81,8 +81,8 @@ export const STT_PROVIDERS_META: STTProviderInfo[] = [
{ {
id: 'groq', id: 'groq',
name: 'Groq Whisper LPU', name: 'Groq Whisper LPU',
description: 'LPU 가속 기반 초저지연(~200ms) 초고속 인식', description: 'Groq LPU-hosted Whisper API',
badge: 'Ultra Fast (~200ms)', badge: 'Cloud · Groq LPU',
requiresApiKey: true, requiresApiKey: true,
defaultModel: 'whisper-large-v3-turbo', defaultModel: 'whisper-large-v3-turbo',
defaultBaseUrl: 'https://api.groq.com/openai/v1', defaultBaseUrl: 'https://api.groq.com/openai/v1',
@ -92,8 +92,8 @@ export const STT_PROVIDERS_META: STTProviderInfo[] = [
{ {
id: 'deepgram', id: 'deepgram',
name: 'Deepgram Nova-3', name: 'Deepgram Nova-3',
description: '업계 최고 인식률, 스마트 문장 부호 및 포맷팅', description: 'Deepgram Nova speech recognition API',
badge: 'Industry Benchmark', badge: 'Cloud · Deepgram API',
requiresApiKey: true, requiresApiKey: true,
defaultModel: 'nova-3', defaultModel: 'nova-3',
defaultBaseUrl: 'https://api.deepgram.com', defaultBaseUrl: 'https://api.deepgram.com',
@ -103,8 +103,8 @@ export const STT_PROVIDERS_META: STTProviderInfo[] = [
{ {
id: 'assemblyai', id: 'assemblyai',
name: 'AssemblyAI Universal-2', name: 'AssemblyAI Universal-2',
description: '고도화된 음향 모델 및 문맥 인식 STT', description: 'AssemblyAI asynchronous speech-to-text API',
badge: 'Advanced Acoustic', badge: 'Cloud · AssemblyAI API',
requiresApiKey: true, requiresApiKey: true,
defaultModel: 'best', defaultModel: 'best',
defaultBaseUrl: 'https://api.assemblyai.com/v2', defaultBaseUrl: 'https://api.assemblyai.com/v2',
@ -114,8 +114,8 @@ export const STT_PROVIDERS_META: STTProviderInfo[] = [
{ {
id: 'google', id: 'google',
name: 'Google Gemini 2.0 Flash / Cloud STT', name: 'Google Gemini 2.0 Flash / Cloud STT',
description: 'Gemini 2.0 Flash 기반 한국어/다국어 인식', description: 'Google Generative Language multimodal audio API',
badge: 'Multilingual · Asian Languages', badge: 'Cloud · Gemini Audio',
requiresApiKey: true, requiresApiKey: true,
defaultModel: 'gemini-2.0-flash', defaultModel: 'gemini-2.0-flash',
defaultBaseUrl: 'https://generativelanguage.googleapis.com/v1beta', defaultBaseUrl: 'https://generativelanguage.googleapis.com/v1beta',
@ -124,9 +124,9 @@ export const STT_PROVIDERS_META: STTProviderInfo[] = [
}, },
{ {
id: 'custom', id: 'custom',
name: 'Custom (OpenAI 호환)', name: 'Custom (OpenAI Compatible)',
description: 'vLLM, 사내 프라이빗 서버, Together 등 커스텀 엔드포인트', description: 'Custom OpenAI-compatible audio transcriptions endpoint',
badge: 'Self-Hosted / Proxy', badge: 'Self-Hosted · Proxy',
requiresApiKey: false, requiresApiKey: false,
defaultModel: 'whisper-1', defaultModel: 'whisper-1',
defaultBaseUrl: 'http://127.0.0.1:8000/v1', defaultBaseUrl: 'http://127.0.0.1:8000/v1',

View file

@ -62,7 +62,7 @@ export interface NutKeyboardModule {
hasKeyboard(): boolean hasKeyboard(): boolean
getKeyboard(): NutNativeKeyboard getKeyboard(): NutNativeKeyboard
} }
Key: Pick<typeof NutKey, 'LeftControl' | 'LeftSuper' | 'V' | 'Backspace'> Key: Pick<typeof NutKey, 'LeftControl' | 'LeftSuper' | 'V' | 'Backspace' | 'Space'>
} }
export type NutModuleLoader = () => Promise<NutKeyboardModule> export type NutModuleLoader = () => Promise<NutKeyboardModule>

View file

@ -59,6 +59,9 @@ export function resolveVoiceIntent(gesture: VoiceGesture, phase: VoiceIntentPhas
if (gesture.type === 'press') { if (gesture.type === 'press') {
if (gesture.mode === 'dictation') { if (gesture.mode === 'dictation') {
if (!gesture.holdMode) {
return phase === 'idle' ? { kind: 'start', mode: 'dictation' } : STOP
}
return phase === 'idle' ? { kind: 'start', mode: 'dictation' } : IGNORE return phase === 'idle' ? { kind: 'start', mode: 'dictation' } : IGNORE
} }
return phase === 'idle' ? { kind: 'start', mode: 'hands-free' } : STOP return phase === 'idle' ? { kind: 'start', mode: 'hands-free' } : STOP
@ -75,11 +78,9 @@ export function resolveGestureMode(actionId: KeyBindingActionId, isDoublePress:
} }
/** /**
* 'command' 액션에는 아직 전용 핸들러가 없다. * 키바인딩 스펙의 holdMode 설정을 그대로 존중한다.
* 현행 동작대로 dictation 파이프라인으로 fallback 하며, 그 경로는 hold-to-talk 이므로 * 'command' 액션도 스펙/설정에 따라 토글(holdMode=false) 또는 홀드(holdMode=true)로 동작한다.
* KEYBINDING_ACTIONS 의 holdMode(false)가 아니라 dictation 과 같은 값을 쓴다.
*/ */
export function resolveGestureHoldMode(actionId: KeyBindingActionId, specHoldMode: boolean): boolean { export function resolveGestureHoldMode(_actionId: KeyBindingActionId, specHoldMode: boolean): boolean {
if (actionId === 'command') return true
return specHoldMode return specHoldMode
} }

View file

@ -0,0 +1,21 @@
import { availableParallelism } from 'node:os'
/** Leave scheduling headroom for the foreground app and IME; this is a worker cap, not CPU affinity. */
export function inferenceCpuThreads(availableCpus: number): number {
if (!Number.isFinite(availableCpus) || availableCpus < 1) return 1
return Math.max(1, Math.min(4, Math.floor(availableCpus) - 2))
}
/** A remote Ollama host has a different CPU budget; only constrain the local engine. */
export function localInferenceCpuOptions(serverUrl: string): { num_thread?: number } {
try {
const hostname = new URL(serverUrl).hostname.toLowerCase()
if (
hostname !== 'localhost' && hostname !== 'localhost.' && hostname !== '[::1]' &&
!/^127\.\d+\.\d+\.\d+$/.test(hostname)
) return {}
return { num_thread: inferenceCpuThreads(availableParallelism()) }
} catch {
return {}
}
}

View file

@ -79,9 +79,17 @@ const IME_CMODE_NATIVE = 0x0001
const SMTO_ABORTIFHUNG = 0x0002 const SMTO_ABORTIFHUNG = 0x0002
const TITLE_BUFFER_CHARS = 512 const TITLE_BUFFER_CHARS = 512
const PATH_BUFFER_CHARS = 1024 const PATH_BUFFER_CHARS = 1024
const PROCESS_PATH_CACHE_MAX = 256
const IME_MODE_CACHE_TTL_MS = 400
let api: Win32Api | null = null let api: Win32Api | null = null
let loadFailed = false let loadFailed = false
const processPathCache = new Map<number, string | null>()
let imeModeCache: { hwnd: number; korean: boolean | null; at: number } | null = null
export function invalidateKoreanImeCache(): void {
imeModeCache = null
}
function loadApi(): Win32Api | null { function loadApi(): Win32Api | null {
if (api) return api if (api) return api
@ -188,6 +196,9 @@ export function getForegroundWindowInfo(): ForegroundWindowInfo | null {
: null : null
let appPath: string | null = null let appPath: string | null = null
if (processId > 0 && processPathCache.has(processId)) {
appPath = processPathCache.get(processId) ?? null
} else if (processId > 0) {
const processHandle = a.OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, false, processId) as const processHandle = a.OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, false, processId) as
| bigint | bigint
| number | number
@ -211,6 +222,14 @@ export function getForegroundWindowInfo(): ForegroundWindowInfo | null {
a.CloseHandle(processHandle) a.CloseHandle(processHandle)
} }
} }
if (appPath) {
if (processPathCache.size >= PROCESS_PATH_CACHE_MAX) {
const firstKey = processPathCache.keys().next().value
if (firstKey !== undefined) processPathCache.delete(firstKey)
}
processPathCache.set(processId, appPath)
}
}
const appName = appPath ? (appPath.split(/[\\/]/u).pop() ?? '') : '' const appName = appPath ? (appPath.split(/[\\/]/u).pop() ?? '') : ''
@ -241,6 +260,11 @@ export function isForegroundKoreanIme(foregroundHwnd?: number | null): boolean |
const fg = Number(rawFg ?? 0) const fg = Number(rawFg ?? 0)
if (!Number.isFinite(fg) || fg <= 0) return null if (!Number.isFinite(fg) || fg <= 0) return null
const now = Date.now()
if (imeModeCache && imeModeCache.hwnd === fg && now - imeModeCache.at < IME_MODE_CACHE_TTL_MS) {
return imeModeCache.korean
}
const pidBuffer = Buffer.alloc(4) const pidBuffer = Buffer.alloc(4)
const tid = Number(a.GetWindowThreadProcessId(fg, pidBuffer) ?? 0) const tid = Number(a.GetWindowThreadProcessId(fg, pidBuffer) ?? 0)
let targetHwnd = fg let targetHwnd = fg
@ -268,7 +292,10 @@ export function isForegroundKoreanIme(foregroundHwnd?: number | null): boolean |
} }
const imeWnd = Number((a.ImmGetDefaultIMEWnd(targetHwnd) as bigint | number | null) ?? 0) const imeWnd = Number((a.ImmGetDefaultIMEWnd(targetHwnd) as bigint | number | null) ?? 0)
if (!Number.isFinite(imeWnd) || imeWnd <= 0) return null if (!Number.isFinite(imeWnd) || imeWnd <= 0) {
imeModeCache = { hwnd: fg, korean: null, at: now }
return null
}
const convOut = [0] const convOut = [0]
const convRes = a.SendMessageTimeoutW( const convRes = a.SendMessageTimeoutW(
@ -277,13 +304,18 @@ export function isForegroundKoreanIme(foregroundHwnd?: number | null): boolean |
IMC_GETCONVERSIONMODE, IMC_GETCONVERSIONMODE,
0, 0,
SMTO_ABORTIFHUNG, SMTO_ABORTIFHUNG,
30, 8,
convOut convOut
) )
if (Number(convRes) === 0) return null if (Number(convRes) === 0) {
imeModeCache = { hwnd: fg, korean: null, at: now }
return null
}
// Windows 한국어 IME(TSF/Chromium 포함)는 한/영('가'/'A') 상태를 IMC_GETOPENSTATUS 가 아니라 // Windows 한국어 IME(TSF/Chromium 포함)는 한/영('가'/'A') 상태를 IMC_GETOPENSTATUS 가 아니라
// IMC_GETCONVERSIONMODE 의 IME_CMODE_NATIVE(0x0001) 비트로 나타낸다. // IMC_GETCONVERSIONMODE 의 IME_CMODE_NATIVE(0x0001) 비트로 나타낸다.
return (Number(convOut[0]) & IME_CMODE_NATIVE) !== 0 const korean = (Number(convOut[0]) & IME_CMODE_NATIVE) !== 0
imeModeCache = { hwnd: fg, korean, at: now }
return korean
} catch { } catch {
return null return null
} }
@ -293,4 +325,6 @@ export function isForegroundKoreanIme(foregroundHwnd?: number | null): boolean |
export function resetWin32ForegroundForTests(): void { export function resetWin32ForegroundForTests(): void {
api = null api = null
loadFailed = false loadFailed = false
processPathCache.clear()
imeModeCache = null
} }

View file

@ -0,0 +1,36 @@
import { getLogger } from '../services/LoggerService'
const logger = getLogger('win32-input-activity')
// LASTINPUTINFO is two DWORDs on both 32-bit and 64-bit Windows.
const LAST_INPUT_INFO_SIZE = 8
type GetLastInputInfoFn = (info: Buffer) => boolean
let getLastInputInfo: GetLastInputInfoFn | null = null
let loadFailed = false
/**
* Session input token read directly from Windows, independent of queued JS hook callbacks.
* dwTime is a system tick, not an epoch timestamp or monotonic sequence: compare equality only.
* Unsupported platforms or unavailable native state return null; callers must not infer idle.
*/
export function getLastNativeInputTick(): number | null {
if (process.platform !== 'win32' || loadFailed) return null
try {
if (!getLastInputInfo) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const koffi = require('koffi') as {
load: (library: string) => { func: (signature: string) => GetLastInputInfoFn }
}
getLastInputInfo = koffi.load('user32.dll').func('bool GetLastInputInfo(_Inout_ void *plii)')
}
const info = Buffer.alloc(LAST_INPUT_INFO_SIZE)
info.writeUInt32LE(LAST_INPUT_INFO_SIZE, 0)
if (!getLastInputInfo(info)) return null
return info.readUInt32LE(4)
} catch (error) {
loadFailed = true
logger.warn(`Windows 입력 시각 조회 실패: ${error instanceof Error ? error.message : String(error)}`)
return null
}
}

View file

@ -12,6 +12,7 @@
// IME 상태를 타지 않고 클립보드도 전혀 건드리지 않는다. // IME 상태를 타지 않고 클립보드도 전혀 건드리지 않는다.
import { getLogger } from '../services/LoggerService' import { getLogger } from '../services/LoggerService'
import { D3ROError, ErrorCode } from '@d3ro/core/errors'
const logger = getLogger('win32-unicode-input') const logger = getLogger('win32-unicode-input')
@ -110,9 +111,30 @@ function writeUnicodeKeyPair(buffer: Buffer, pairIndex: number, codeUnit: number
buffer.writeUInt32LE(KEYEVENTF_UNICODE | KEYEVENTF_KEYUP, upBase + unionOffset + 4) buffer.writeUInt32LE(KEYEVENTF_UNICODE | KEYEVENTF_KEYUP, upBase + unionOffset + 4)
} }
/** Only zero inserted events are safe to retry through another input backend. */
function sendInputBatch(sendInput: SendInputFn, totalEvents: number, buffer: Buffer): boolean {
let sent: number
try {
sent = sendInput(totalEvents, buffer, inputStructSize)
} catch (error) {
// A native-call exception does not prove that the input stream was untouched.
throw new D3ROError(
ErrorCode.TextInsertKeySimulationFailed,
`SendInput failed with an unknown insertion result; retry blocked: ${error instanceof Error ? error.message : String(error)}`
)
}
if (sent === totalEvents) return true
if (sent === 0) return false
// Replaying a partially applied batch can delete the user's next word or duplicate text.
throw new D3ROError(
ErrorCode.TextInsertKeySimulationFailed,
`SendInput inserted ${sent}/${totalEvents} events; retry blocked to preserve existing input`
)
}
/** /**
* UTF-16 문자열을 Windows SendInput(KEYEVENTF_UNICODE) 호출 한 번으로 입력 큐에 넣는다. * UTF-16 문자열을 Windows SendInput(KEYEVENTF_UNICODE) 호출 한 번으로 입력 큐에 넣는다.
* 성공 시 true, 지원하지 않거나 실패 시 false 를 반환한다. * 성공 시 true, 미지원 또는 입력 0건이면 false. 일부 입력/결과 불명은 재시도하지 않도록 예외를 던진다.
*/ */
export function sendWin32UnicodeText(text: string): boolean { export function sendWin32UnicodeText(text: string): boolean {
if (!text) return true if (!text) return true
@ -128,9 +150,9 @@ export function sendWin32UnicodeText(text: string): boolean {
writeUnicodeKeyPair(buffer, i, text.charCodeAt(i)) writeUnicodeKeyPair(buffer, i, text.charCodeAt(i))
} }
const sent = sendInput(totalEvents, buffer, inputStructSize) return sendInputBatch(sendInput, totalEvents, buffer)
return sent === totalEvents
} catch (error) { } catch (error) {
if (error instanceof D3ROError) throw error
logger.warn(`SendInput(KEYEVENTF_UNICODE) 실행 실패: ${error instanceof Error ? error.message : String(error)}`) logger.warn(`SendInput(KEYEVENTF_UNICODE) 실행 실패: ${error instanceof Error ? error.message : String(error)}`)
return false return false
} }
@ -138,10 +160,11 @@ export function sendWin32UnicodeText(text: string): boolean {
/** /**
* (선택적 IME 조합 확정 Space) + 커서 앞 백스페이스 N번 + UTF-16 문자열 입력을 * (선택적 IME 조합 확정 Space) + 커서 앞 백스페이스 N번 + UTF-16 문자열 입력을
* 단 한 번의 Windows SendInput 호출로 원자적(atomic)으로 주입한다. * 단 한 번의 Windows SendInput 호출로 입력 큐에 연속해서 주입한다.
* *
* Win32 SendInput 규약상 단일 호출 안의 INPUT 배열 사이에 사용자의 물리 키 입력이 끼어들 수 없으므로, * Win32 SendInput 규약상 단일 호출 안의 INPUT 배열 사이에 사용자의 물리 키 입력이 끼어들 수 없으므로,
* 빠른 타이핑 도중에도 지우기와 다시 쓰기가 경쟁하지 않고 < 0.5ms 안에 끝난다. * 배치 내부의 순서만 보장한다. 이전 스냅샷 이후 바뀐 커서/텍스트, 대상 앱의 처리 시간,
* IME 상태까지 보장하지 않는다. 일부 입력만 성공하면 삭제/입력 배치를 재실행하지 않는다.
*/ */
export function sendWin32UnicodeReplacement( export function sendWin32UnicodeReplacement(
deleteCount: number, deleteCount: number,
@ -177,9 +200,9 @@ export function sendWin32UnicodeReplacement(
pairCursor += 1 pairCursor += 1
} }
const sent = sendInput(totalEvents, buffer, inputStructSize) return sendInputBatch(sendInput, totalEvents, buffer)
return sent === totalEvents
} catch (error) { } catch (error) {
if (error instanceof D3ROError) throw error
logger.warn( logger.warn(
`SendInput(atomic replacement) 실행 실패: ${error instanceof Error ? error.message : String(error)}` `SendInput(atomic replacement) 실행 실패: ${error instanceof Error ? error.message : String(error)}`
) )

View file

@ -80,6 +80,7 @@ import type {
DictionaryImportParams, DictionaryImportParams,
DictionaryImportResult, DictionaryImportResult,
DictionaryExportParams, DictionaryExportParams,
CustomInstruction,
StatsSummary, StatsSummary,
PermissionStatus, PermissionStatus,
// Phase 10 // Phase 10
@ -411,10 +412,24 @@ const electronAPI = {
// ── History ──────────────────────────────────────────── // ── History ────────────────────────────────────────────
history: { history: {
getAll: (params: HistoryQueryParams) => getAll: (
invoke<HistoryPage>(IPC_CHANNELS.HISTORY.GET_ALL, params), params: HistoryQueryParams & {
mode?: string | null
isFavorite?: boolean
tag?: string | null
search?: string | null
query?: string | null
beforeCreatedAt?: number | null
},
) => invoke<HistoryPage>(IPC_CHANNELS.HISTORY.GET_ALL, params),
getById: (params: HistoryGetByIdParams) => getById: (params: HistoryGetByIdParams) =>
invoke<HistoryEntry | null>(IPC_CHANNELS.HISTORY.GET_BY_ID, params), invoke<HistoryEntry | null>(IPC_CHANNELS.HISTORY.GET_BY_ID, params),
update: (params: {
id: string
title?: string | null
polishedText?: string | null
originalText?: string
}) => invoke<HistoryEntry>('history:update', params),
delete: (params: HistoryDeleteParams) => delete: (params: HistoryDeleteParams) =>
invoke<void>(IPC_CHANNELS.HISTORY.DELETE, params), invoke<void>(IPC_CHANNELS.HISTORY.DELETE, params),
deleteAll: () => invoke<void>(IPC_CHANNELS.HISTORY.DELETE_ALL), deleteAll: () => invoke<void>(IPC_CHANNELS.HISTORY.DELETE_ALL),
@ -477,14 +492,14 @@ const electronAPI = {
// ── Instruction (커스텀 명령어) ──────────────────────── // ── Instruction (커스텀 명령어) ────────────────────────
instruction: { instruction: {
getAll: () => invoke<unknown[]>('instruction:getAll'), getAll: () => invoke<CustomInstruction[]>(IPC_CHANNELS.INSTRUCTION.GET_ALL),
getById: (params: { id: string }) => invoke<unknown>('instruction:getById', params), getById: (params: { id: string }) => invoke<CustomInstruction | null>(IPC_CHANNELS.INSTRUCTION.GET_BY_ID, params),
create: (params: { name: string; description: string; prompt: string }) => create: (params: { name: string; description: string; prompt: string }) =>
invoke<unknown>('instruction:create', params), invoke<CustomInstruction>(IPC_CHANNELS.INSTRUCTION.CREATE, params),
update: (params: { id: string; name?: string; description?: string; prompt?: string }) => update: (params: { id: string; name?: string; description?: string; prompt?: string }) =>
invoke<unknown>('instruction:update', params), invoke<CustomInstruction>(IPC_CHANNELS.INSTRUCTION.UPDATE, params),
delete: (params: { id: string }) => invoke<void>('instruction:delete', params), delete: (params: { id: string }) => invoke<void>(IPC_CHANNELS.INSTRUCTION.DELETE, params),
reorder: (params: { ids: string[] }) => invoke<void>('instruction:reorder', params), reorder: (params: { ids: string[] }) => invoke<void>(IPC_CHANNELS.INSTRUCTION.REORDER, params),
}, },
// ── App 이벤트 (실시간 UI 갱신) ──────────────────────── // ── App 이벤트 (실시간 UI 갱신) ────────────────────────
@ -505,7 +520,16 @@ const electronAPI = {
removeTag: (params: RemoveTagParams) => invoke<void>(IPC_CHANNELS.MEMO.REMOVE_TAG, params), removeTag: (params: RemoveTagParams) => invoke<void>(IPC_CHANNELS.MEMO.REMOVE_TAG, params),
getAllTags: () => invoke<TagCount[]>(IPC_CHANNELS.MEMO.GET_ALL_TAGS), getAllTags: () => invoke<TagCount[]>(IPC_CHANNELS.MEMO.GET_ALL_TAGS),
searchByTag: (params: SearchByTagParams) => invoke<HistoryPage>(IPC_CHANNELS.MEMO.SEARCH_BY_TAG, params), searchByTag: (params: SearchByTagParams) => invoke<HistoryPage>(IPC_CHANNELS.MEMO.SEARCH_BY_TAG, params),
export: (params: ExportMemoParams) => invoke<string>(IPC_CHANNELS.MEMO.EXPORT, params), export: (
params: ExportMemoParams & {
savePath?: string
interactive?: boolean
includeUntagged?: boolean
mode?: string
isFavorite?: boolean
search?: string
},
) => invoke<string>(IPC_CHANNELS.MEMO.EXPORT, params),
}, },
// ── Phase 10: Voice Commands ──────────────────────────── // ── Phase 10: Voice Commands ────────────────────────────
@ -711,6 +735,12 @@ const electronAPI = {
), ),
finishListening: () => finishListening: () =>
invoke<void>('voiceConversation:finishListening'), invoke<void>('voiceConversation:finishListening'),
replayMessage: (params?: { messageId?: string; text?: string } | string) =>
invoke<void>(
(IPC_CHANNELS.VOICE_CONVERSATION as Record<string, string>).REPLAY_MESSAGE ??
'voiceConversation:replayMessage',
params,
),
onStateChanged: (cb: (data: ConversationSessionInfo) => void): Unsubscribe => onStateChanged: (cb: (data: ConversationSessionInfo) => void): Unsubscribe =>
on(IPC_CHANNELS.VOICE_CONVERSATION.STATE_CHANGED, cb), on(IPC_CHANNELS.VOICE_CONVERSATION.STATE_CHANGED, cb),
onUserMessage: (cb: (data: ConversationMessage) => void): Unsubscribe => onUserMessage: (cb: (data: ConversationMessage) => void): Unsubscribe =>
@ -737,7 +767,7 @@ const electronAPI = {
invoke<void>('meetingMode:forceReset'), invoke<void>('meetingMode:forceReset'),
stopRecording: () => stopRecording: () =>
invoke<void>(IPC_CHANNELS.MEETING_MODE.STOP_RECORDING), invoke<void>(IPC_CHANNELS.MEETING_MODE.STOP_RECORDING),
addMemo: (params: MeetingAddMemoParams) => addMemo: (params: MeetingAddMemoParams & { sessionId?: string; meetingId?: string }) =>
invoke<MeetingMemo>(IPC_CHANNELS.MEETING_MODE.ADD_MEMO, params), invoke<MeetingMemo>(IPC_CHANNELS.MEETING_MODE.ADD_MEMO, params),
getState: () => getState: () =>
invoke<MeetingModeStateInfo>(IPC_CHANNELS.MEETING_MODE.GET_STATE), invoke<MeetingModeStateInfo>(IPC_CHANNELS.MEETING_MODE.GET_STATE),

View file

@ -94,6 +94,9 @@ function Shell(): React.ReactElement {
const handleOpenLicenseModal = (): void => setLicenseModalOpen(true) const handleOpenLicenseModal = (): void => setLicenseModalOpen(true)
window.addEventListener('d3ro:open-license-modal', handleOpenLicenseModal) window.addEventListener('d3ro:open-license-modal', handleOpenLicenseModal)
const handleOpenRewardedModal = (): void => setRewardedModalOpen(true)
window.addEventListener('d3ro:open-rewarded-modal', handleOpenRewardedModal)
// detail.tab 은 타입 없는 DOM 경계라 검증한다 — 모르는 값이면 기본 탭(빈 설정 화면 방지) // detail.tab 은 타입 없는 DOM 경계라 검증한다 — 모르는 값이면 기본 탭(빈 설정 화면 방지)
const handleOpenSettings = (e: Event): void => { const handleOpenSettings = (e: Event): void => {
const tab = readOpenSettingsTab(e) const tab = readOpenSettingsTab(e)
@ -128,6 +131,7 @@ function Shell(): React.ReactElement {
unsubUpgradeReq() unsubUpgradeReq()
unsubVoiceError() unsubVoiceError()
window.removeEventListener('d3ro:open-license-modal', handleOpenLicenseModal) window.removeEventListener('d3ro:open-license-modal', handleOpenLicenseModal)
window.removeEventListener('d3ro:open-rewarded-modal', handleOpenRewardedModal)
window.removeEventListener(OPEN_SETTINGS_EVENT, handleOpenSettings) window.removeEventListener(OPEN_SETTINGS_EVENT, handleOpenSettings)
window.removeEventListener('d3ro:open-ollama-guide', handleOpenGuide) window.removeEventListener('d3ro:open-ollama-guide', handleOpenGuide)
} }

View file

@ -41,7 +41,7 @@ interface RecommendedModel {
} }
const RECOMMENDED_MODELS: readonly RecommendedModel[] = [ const RECOMMENDED_MODELS: readonly RecommendedModel[] = [
{ id: 'gemma4:e4b', name: 'Gemma 4 (E4B)', size: '4 GB', descriptionKey: 'ollamaGuide.model.gemma4e4b', recommended: true }, { id: 'gemma4:e4b', name: 'Gemma 4 (E4B)', size: '4.0 GB', descriptionKey: 'ollamaGuide.model.gemma4e4b', recommended: true },
{ id: 'llama3.2:3b', name: 'Llama 3.2 (3B)', size: '2.0 GB', descriptionKey: 'ollamaGuide.model.llama32' }, { id: 'llama3.2:3b', name: 'Llama 3.2 (3B)', size: '2.0 GB', descriptionKey: 'ollamaGuide.model.llama32' },
{ id: 'qwen2.5:3b', name: 'Qwen 2.5 (3B)', size: '1.9 GB', descriptionKey: 'ollamaGuide.model.qwen25' }, { id: 'qwen2.5:3b', name: 'Qwen 2.5 (3B)', size: '1.9 GB', descriptionKey: 'ollamaGuide.model.qwen25' },
{ id: 'phi4', name: 'Phi 4', size: '9.1 GB', descriptionKey: 'ollamaGuide.model.phi4' }, { id: 'phi4', name: 'Phi 4', size: '9.1 GB', descriptionKey: 'ollamaGuide.model.phi4' },

View file

@ -823,6 +823,33 @@ export function SettingsModal({ open, initialTab = DEFAULT_SETTINGS_TAB, onClose
</FormControl> </FormControl>
} }
/> />
<SettingRow
labelId="settings-target-language"
label={t('settings.targetLanguage')}
description={t('settings.targetLanguage.desc')}
control={
<FormControl size="small" sx={controlSx}>
<Select
labelId="settings-target-language"
value={config.targetLanguage ?? 'English'}
onChange={(e) => updateConfig('targetLanguage', e.target.value)}
>
<MenuItem value="English">{t('settings.targetLanguage.en')}</MenuItem>
<MenuItem value="Korean">{t('settings.targetLanguage.ko')}</MenuItem>
<MenuItem value="Japanese">{t('settings.targetLanguage.ja')}</MenuItem>
<MenuItem value="Chinese (Simplified)">{t('settings.targetLanguage.zhCN')}</MenuItem>
<MenuItem value="Chinese (Traditional)">{t('settings.targetLanguage.zhTW')}</MenuItem>
<MenuItem value="Spanish">{t('settings.targetLanguage.es')}</MenuItem>
<MenuItem value="French">{t('settings.targetLanguage.fr')}</MenuItem>
<MenuItem value="German">{t('settings.targetLanguage.de')}</MenuItem>
<MenuItem value="Portuguese">{t('settings.targetLanguage.pt')}</MenuItem>
<MenuItem value="Vietnamese">{t('settings.targetLanguage.vi')}</MenuItem>
<MenuItem value="Indonesian">{t('settings.targetLanguage.id')}</MenuItem>
<MenuItem value="Arabic">{t('settings.targetLanguage.ar')}</MenuItem>
</Select>
</FormControl>
}
/>
<SettingRow <SettingRow
labelId="settings-voice-commands" labelId="settings-voice-commands"
label={t('settings.voiceCommands')} label={t('settings.voiceCommands')}

View file

@ -31,6 +31,7 @@ interface EditableSegmentProps {
onEdit: (segmentId: string, newText: string) => void onEdit: (segmentId: string, newText: string) => void
readOnly?: boolean readOnly?: boolean
speaker?: string speaker?: string
highlighted?: boolean
} }
function formatTimestamp(ms: number): string { function formatTimestamp(ms: number): string {
@ -48,6 +49,7 @@ export function EditableSegment({
onEdit, onEdit,
readOnly = false, readOnly = false,
speaker, speaker,
highlighted = false,
}: EditableSegmentProps): React.ReactElement { }: EditableSegmentProps): React.ReactElement {
const { t } = useI18n() const { t } = useI18n()
const [editing, setEditing] = useState(false) const [editing, setEditing] = useState(false)
@ -168,13 +170,21 @@ export function EditableSegment({
return ( return (
<Box <Box
data-segment-id={segmentId}
data-timestamp-ms={timestamp}
sx={{ sx={{
display: 'flex', display: 'flex',
alignItems: 'flex-start', alignItems: 'flex-start',
gap: 1, gap: 1,
mb: 0.5, mb: 0.5,
borderLeft: speakerColor ? `4px solid ${speakerColor}` : undefined, borderLeft: speakerColor
pl: speakerColor ? 0.75 : 0, ? `4px solid ${speakerColor}`
: highlighted
? `2px solid ${d3roPalette.accent.main}`
: undefined,
pl: speakerColor || highlighted ? 0.75 : 0,
bgcolor: highlighted ? d3roPalette.surface.overlaySoft : undefined,
borderRadius: highlighted ? d3roRadius.xs : undefined,
}} }}
> >
<Box <Box

View file

@ -1,14 +1,109 @@
// src/renderer/components/meeting/MarkdownRenderer.tsx // src/renderer/components/meeting/MarkdownRenderer.tsx
// Phase 14.5: react-markdown + remark-gfm 래퍼 — d3roPalette 기반 스타일 // Phase 14.5: react-markdown + remark-gfm 래퍼 — d3roPalette 기반 스타일
import React from 'react'
import ReactMarkdown from 'react-markdown' import ReactMarkdown from 'react-markdown'
import remarkGfm from 'remark-gfm' import remarkGfm from 'remark-gfm'
import { Box } from '@mui/material' import { Box } from '@mui/material'
import { d3roPalette, d3roFontMono, d3roTypo, d3roRadius } from '@d3ro/ui/theme' import { d3roPalette, d3roFontMono, d3roTypo, d3roRadius, d3roFocusRing } from '@d3ro/ui/theme'
import type { Components } from 'react-markdown' import type { Components } from 'react-markdown'
interface MarkdownRendererProps { interface MarkdownRendererProps {
content: string content: string
onCitationClick?: (timestampMs: number, label: string) => void
}
export type CitationSegmentPart =
| { type: 'text'; value: string }
| { type: 'citation'; label: string; timestampMs: number }
export function parseCitationTimestampMs(token: string): number | null {
const match = /^\[?(?:(\d{1,2}):)?(\d{1,3}):(\d{2})\]?$/.exec(token.trim())
if (!match) return null
const hours = match[1] ? parseInt(match[1], 10) : 0
const minutes = parseInt(match[2], 10)
const seconds = parseInt(match[3], 10)
if (seconds >= 60) return null
return (hours * 3600 + minutes * 60 + seconds) * 1000
}
export function splitTextWithCitations(text: string): CitationSegmentPart[] {
const regex = /\[(?:\d{1,2}:)?\d{1,3}:\d{2}\]/g
const parts: CitationSegmentPart[] = []
let lastIndex = 0
let match: RegExpExecArray | null
while ((match = regex.exec(text)) !== null) {
const label = match[0]
const timestampMs = parseCitationTimestampMs(label)
if (timestampMs === null) continue
if (match.index > lastIndex) {
parts.push({ type: 'text', value: text.slice(lastIndex, match.index) })
}
parts.push({ type: 'citation', label, timestampMs })
lastIndex = match.index + label.length
}
if (lastIndex < text.length) {
parts.push({ type: 'text', value: text.slice(lastIndex) })
}
return parts.length > 0 ? parts : [{ type: 'text', value: text }]
}
export function renderChildrenWithCitations(
children: React.ReactNode,
onCitationClick?: (timestampMs: number, label: string) => void,
): React.ReactNode {
return React.Children.map(children, (child, index) => {
if (typeof child !== 'string') return child
const parts = splitTextWithCitations(child)
if (parts.length === 1 && parts[0].type === 'text') return child
return (
<React.Fragment key={index}>
{parts.map((part, partIdx) => {
if (part.type === 'text') return part.value
return (
<Box
key={`${index}-${partIdx}-${part.label}`}
component="button"
type="button"
data-citation-ms={part.timestampMs}
onClick={(e: React.MouseEvent<HTMLButtonElement>) => {
e.stopPropagation()
onCitationClick?.(part.timestampMs, part.label)
}}
sx={{
display: 'inline-flex',
alignItems: 'center',
fontFamily: d3roFontMono,
fontSize: d3roTypo.small.size,
color: d3roPalette.accent.light,
bgcolor: d3roPalette.surface.overlaySoft,
border: `1px solid ${d3roPalette.border.default}`,
borderRadius: d3roRadius.xs,
px: 0.6,
py: 0.1,
mx: 0.25,
cursor: onCitationClick ? 'pointer' : 'default',
fontVariantNumeric: 'tabular-nums',
verticalAlign: 'baseline',
'&:hover': onCitationClick
? {
bgcolor: d3roPalette.surface.overlayStrong,
borderColor: d3roPalette.accent.main,
}
: {},
'&:focus-visible': d3roFocusRing,
}}
>
{part.label}
</Box>
)
})}
</React.Fragment>
)
})
} }
/** /**
@ -208,10 +303,44 @@ const components: Components = {
), ),
} }
export function MarkdownRenderer({ content }: MarkdownRendererProps): React.ReactElement { export function MarkdownRenderer({ content, onCitationClick }: MarkdownRendererProps): React.ReactElement {
const customComponents = React.useMemo<Components>(
() => ({
...components,
p: ({ children }) => (
<Box
component="p"
sx={{
fontSize: d3roTypo.body.size,
color: d3roPalette.text.primary,
lineHeight: 1.7,
mb: 0.75,
mt: 0,
}}
>
{renderChildrenWithCitations(children, onCitationClick)}
</Box>
),
li: ({ children }) => (
<Box
component="li"
sx={{
fontSize: d3roTypo.body.size,
color: d3roPalette.text.primary,
lineHeight: 1.7,
mb: 0.25,
}}
>
{renderChildrenWithCitations(children, onCitationClick)}
</Box>
),
}),
[onCitationClick],
)
return ( return (
<Box sx={{ color: d3roPalette.text.primary, fontSize: d3roTypo.body.size }}> <Box sx={{ color: d3roPalette.text.primary, fontSize: d3roTypo.body.size }}>
<ReactMarkdown remarkPlugins={[remarkGfm]} components={components}> <ReactMarkdown remarkPlugins={[remarkGfm]} components={customComponents}>
{content} {content}
</ReactMarkdown> </ReactMarkdown>
</Box> </Box>

View file

@ -109,6 +109,11 @@ export function MeetingDetailTabs({
const [templates, setTemplates] = useState<MeetingDocTemplate[]>([]) const [templates, setTemplates] = useState<MeetingDocTemplate[]>([])
const [tab, setTab] = useState<MeetingDetailTab>('summary') const [tab, setTab] = useState<MeetingDetailTab>('summary')
const [highlightedTimestampMs, setHighlightedTimestampMs] = useState<number | null>(null)
const handleJumpToTimestamp = useCallback((timestampMs: number) => {
setHighlightedTimestampMs(timestampMs)
setTab('transcript')
}, [])
// 문서 탭에서 고른 문서 — 사라지면 렌더링 시점에 첫 문서로 맞춘다. // 문서 탭에서 고른 문서 — 사라지면 렌더링 시점에 첫 문서로 맞춘다.
const [pickedDocId, setPickedDocId] = useState<string | null>(null) const [pickedDocId, setPickedDocId] = useState<string | null>(null)
const selectedDocId = resolveSelectedDocumentId(pickedDocId, documents) const selectedDocId = resolveSelectedDocumentId(pickedDocId, documents)
@ -686,6 +691,7 @@ export function MeetingDetailTabs({
setPickedDocId(docId) setPickedDocId(docId)
setTab('documents') setTab('documents')
}} }}
onJumpToTimestamp={handleJumpToTimestamp}
/> />
)} )}
@ -701,6 +707,7 @@ export function MeetingDetailTabs({
polishing={transcript.polishing} polishing={transcript.polishing}
onDiarize={() => void handleDiarize()} onDiarize={() => void handleDiarize()}
diarizing={transcript.diarizing} diarizing={transcript.diarizing}
highlightedTimestampMs={highlightedTimestampMs}
/> />
)} )}
@ -769,6 +776,13 @@ export function MeetingDetailTabs({
recordedMemos={detail.memos ?? []} recordedMemos={detail.memos ?? []}
enhancing={enhancingNotes} enhancing={enhancingNotes}
onEnhance={(notes) => void handleEnhanceNotes(notes)} onEnhance={(notes) => void handleEnhanceNotes(notes)}
onMemoAdded={(memo) =>
setDetail((prev) => ({
...prev,
memos: [...(prev.memos ?? []), memo],
memoCount: (prev.memos?.length ?? 0) + 1,
}))
}
/> />
)} )}
</Box> </Box>

View file

@ -3,14 +3,14 @@
// 자유 노트는 입력마다 이 기기에 저장한다(meeting-notepad-storage). 예전 "Granola Notepad" 는 // 자유 노트는 입력마다 이 기기에 저장한다(meeting-notepad-storage). 예전 "Granola Notepad" 는
// React 상태에만 있어 회의를 닫으면 적은 글이 사라졌다. // React 상태에만 있어 회의를 닫으면 적은 글이 사라졌다.
import { useState } from 'react' import { useState, useRef } from 'react'
import { Box, TextField, Typography } from '@mui/material' import { Box, TextField, Typography } from '@mui/material'
import { Sparkles } from 'lucide-react' import { Sparkles } from 'lucide-react'
import { PhysicalButton } from '@d3ro/ui/components/ds' import { PhysicalButton } from '@d3ro/ui/components/ds'
import { d3roFontMono, d3roFontSans, d3roPalette, d3roRadius, typoSx } from '@d3ro/ui/theme' import { d3roFontMono, d3roFontSans, d3roPalette, d3roRadius, typoSx } from '@d3ro/ui/theme'
import { useI18n } from '@d3ro/i18n' import { useI18n } from '@d3ro/i18n'
import type { MeetingMemo } from '@d3ro/core/types' import type { MeetingMemo } from '@d3ro/core/types'
import { defaultNotepadStorage, loadNotepad, saveNotepad } from './meeting-notepad-storage' import { defaultNotepadStorage, loadNotepad, saveNotepad, syncNotepadMemo } from './meeting-notepad-storage'
import { formatElapsed } from './meeting-format' import { formatElapsed } from './meeting-format'
interface MeetingNotesTabProps { interface MeetingNotesTabProps {
@ -18,6 +18,7 @@ interface MeetingNotesTabProps {
recordedMemos: readonly MeetingMemo[] recordedMemos: readonly MeetingMemo[]
enhancing: boolean enhancing: boolean
onEnhance: (notes: string) => void onEnhance: (notes: string) => void
onMemoAdded?: (memo: MeetingMemo) => void
} }
export function MeetingNotesTab({ export function MeetingNotesTab({
@ -25,17 +26,29 @@ export function MeetingNotesTab({
recordedMemos, recordedMemos,
enhancing, enhancing,
onEnhance, onEnhance,
onMemoAdded,
}: MeetingNotesTabProps): React.ReactElement { }: MeetingNotesTabProps): React.ReactElement {
const { t } = useI18n() const { t } = useI18n()
const [storage] = useState(defaultNotepadStorage) const [storage] = useState(defaultNotepadStorage)
const [notes, setNotes] = useState(() => loadNotepad(storage, sessionId)) const [notes, setNotes] = useState(() => loadNotepad(storage, sessionId))
const [saveFailed, setSaveFailed] = useState(false) const [saveFailed, setSaveFailed] = useState(false)
const lastSyncedRef = useRef<string>('')
const handleChange = (value: string): void => { const handleChange = (value: string): void => {
setNotes(value) setNotes(value)
setSaveFailed(!saveNotepad(storage, sessionId, value)) setSaveFailed(!saveNotepad(storage, sessionId, value))
} }
const handleBlurSync = async (): Promise<void> => {
const trimmed = notes.trim()
if (!trimmed || trimmed === lastSyncedRef.current) return
lastSyncedRef.current = trimmed
const added = await syncNotepadMemo(storage, sessionId, trimmed)
if (added) {
onMemoAdded?.(added)
}
}
return ( return (
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 4 }}> <Box sx={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
{recordedMemos.length > 0 && ( {recordedMemos.length > 0 && (
@ -117,6 +130,7 @@ export function MeetingNotesTab({
minRows={10} minRows={10}
value={notes} value={notes}
onChange={(e) => handleChange(e.target.value)} onChange={(e) => handleChange(e.target.value)}
onBlur={() => void handleBlurSync()}
placeholder={t('meetings.notes.placeholder')} placeholder={t('meetings.notes.placeholder')}
fullWidth fullWidth
slotProps={{ htmlInput: { 'aria-label': t('meetings.notes.padTitle') } }} slotProps={{ htmlInput: { 'aria-label': t('meetings.notes.padTitle') } }}

View file

@ -8,7 +8,7 @@ import { PhysicalButton } from '@d3ro/ui/components/ds'
import { d3roPalette, typoSx } from '@d3ro/ui/theme' import { d3roPalette, typoSx } from '@d3ro/ui/theme'
import { useI18n } from '@d3ro/i18n' import { useI18n } from '@d3ro/i18n'
import { EmptyStateCard } from '../shared' import { EmptyStateCard } from '../shared'
import { MarkdownRenderer } from './MarkdownRenderer' import { MarkdownRenderer, renderChildrenWithCitations } from './MarkdownRenderer'
import { withoutChecklistLines, type ActionItem } from './meeting-documents-model' import { withoutChecklistLines, type ActionItem } from './meeting-documents-model'
import type { SummarySource } from './meeting-summary-model' import type { SummarySource } from './meeting-summary-model'
@ -24,6 +24,7 @@ interface MeetingSummaryTabProps {
onCreateSummary: () => void onCreateSummary: () => void
onChooseTemplate: () => void onChooseTemplate: () => void
onEditDocument: (documentId: string) => void onEditDocument: (documentId: string) => void
onJumpToTimestamp?: (timestampMs: number, label: string) => void
} }
function SectionTitle({ children, action }: { children: React.ReactNode; action?: React.ReactNode }): React.ReactElement { function SectionTitle({ children, action }: { children: React.ReactNode; action?: React.ReactNode }): React.ReactElement {
@ -47,6 +48,7 @@ export function MeetingSummaryTab({
onCreateSummary, onCreateSummary,
onChooseTemplate, onChooseTemplate,
onEditDocument, onEditDocument,
onJumpToTimestamp,
}: MeetingSummaryTabProps): React.ReactElement { }: MeetingSummaryTabProps): React.ReactElement {
const { t } = useI18n() const { t } = useI18n()
@ -88,7 +90,7 @@ export function MeetingSummaryTab({
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 3 }}> <Box sx={{ display: 'flex', flexDirection: 'column', gap: 3 }}>
{minutes.summary.trim() && ( {minutes.summary.trim() && (
<Typography sx={{ ...typoSx('body'), color: d3roPalette.text.primary, whiteSpace: 'pre-wrap' }}> <Typography sx={{ ...typoSx('body'), color: d3roPalette.text.primary, whiteSpace: 'pre-wrap' }}>
{minutes.summary} {renderChildrenWithCitations(minutes.summary, onJumpToTimestamp)}
</Typography> </Typography>
)} )}
{minutes.decisions.length > 0 && ( {minutes.decisions.length > 0 && (
@ -96,7 +98,7 @@ export function MeetingSummaryTab({
<SectionTitle>{t('meetings.summary.decisions')}</SectionTitle> <SectionTitle>{t('meetings.summary.decisions')}</SectionTitle>
<Box component="ul" sx={{ m: 0, pl: 2.5, ...typoSx('body'), color: d3roPalette.text.primary }}> <Box component="ul" sx={{ m: 0, pl: 2.5, ...typoSx('body'), color: d3roPalette.text.primary }}>
{minutes.decisions.map((d, i) => ( {minutes.decisions.map((d, i) => (
<li key={`${i}-${d}`}>{d}</li> <li key={`${i}-${d}`}>{renderChildrenWithCitations(d, onJumpToTimestamp)}</li>
))} ))}
</Box> </Box>
</Box> </Box>
@ -107,7 +109,7 @@ export function MeetingSummaryTab({
<Box component="ul" sx={{ m: 0, pl: 2.5, ...typoSx('body'), color: d3roPalette.text.primary }}> <Box component="ul" sx={{ m: 0, pl: 2.5, ...typoSx('body'), color: d3roPalette.text.primary }}>
{minutes.actionItems.map((a, i) => ( {minutes.actionItems.map((a, i) => (
<li key={`${i}-${a.task}`}> <li key={`${i}-${a.task}`}>
{a.task} {renderChildrenWithCitations(a.task, onJumpToTimestamp)}
{(a.assignee || a.deadline) && ( {(a.assignee || a.deadline) && (
<Box component="span" sx={{ color: d3roPalette.text.tertiary }}> <Box component="span" sx={{ color: d3roPalette.text.tertiary }}>
{` · ${[a.assignee, a.deadline].filter(Boolean).join(' · ')}`} {` · ${[a.assignee, a.deadline].filter(Boolean).join(' · ')}`}
@ -123,7 +125,7 @@ export function MeetingSummaryTab({
} }
if (source.kind === 'markdown') { if (source.kind === 'markdown') {
return <MarkdownRenderer content={source.markdown} /> return <MarkdownRenderer content={source.markdown} onCitationClick={onJumpToTimestamp} />
} }
// 1순위 문서 — 할 일은 체크 목록으로 위에, 본문에서는 같은 줄을 뺀다 // 1순위 문서 — 할 일은 체크 목록으로 위에, 본문에서는 같은 줄을 뺀다
@ -187,7 +189,7 @@ export function MeetingSummaryTab({
pt: '3px', pt: '3px',
}} }}
> >
{item.text} {renderChildrenWithCitations(item.text, onJumpToTimestamp)}
</Typography> </Typography>
</Box> </Box>
))} ))}
@ -196,7 +198,7 @@ export function MeetingSummaryTab({
)} )}
<Box component="article"> <Box component="article">
<MarkdownRenderer content={body} /> <MarkdownRenderer content={body} onCitationClick={onJumpToTimestamp} />
</Box> </Box>
</Box> </Box>
) )

View file

@ -2,6 +2,7 @@
// Phase 14.5: 전사 편집 탭 (상세 페이지용) — 요약의 근거. // Phase 14.5: 전사 편집 탭 (상세 페이지용) — 요약의 근거.
// 복사·내보내기는 상세 머리의 행동 줄 한 곳에 있다(예전 "전사 다운로드" 버튼은 거기로 옮겼다). // 복사·내보내기는 상세 머리의 행동 줄 한 곳에 있다(예전 "전사 다운로드" 버튼은 거기로 옮겼다).
import { useEffect, useMemo } from 'react'
import { Box, Switch, FormControlLabel, LinearProgress, Typography } from '@mui/material' import { Box, Switch, FormControlLabel, LinearProgress, Typography } from '@mui/material'
import { EditableSegment } from './EditableSegment' import { EditableSegment } from './EditableSegment'
import { PhysicalButton } from '@d3ro/ui/components/ds' import { PhysicalButton } from '@d3ro/ui/components/ds'
@ -25,6 +26,7 @@ interface TranscriptTabProps {
polishing: boolean polishing: boolean
onDiarize?: () => void onDiarize?: () => void
diarizing?: boolean diarizing?: boolean
highlightedTimestampMs?: number | null
} }
type TimelineItem = type TimelineItem =
@ -42,6 +44,7 @@ export function TranscriptTab({
polishing, polishing,
onDiarize, onDiarize,
diarizing = false, diarizing = false,
highlightedTimestampMs = null,
}: TranscriptTabProps): React.ReactElement { }: TranscriptTabProps): React.ReactElement {
const { t } = useI18n() const { t } = useI18n()
const showEdited = view === 'edited' const showEdited = view === 'edited'
@ -64,6 +67,26 @@ export function TranscriptTab({
})), })),
].sort((a, b) => a.timestamp - b.timestamp) ].sort((a, b) => a.timestamp - b.timestamp)
const highlightedId = useMemo(() => {
if (highlightedTimestampMs === null || timeline.length === 0) return null
let best = timeline[0]
let bestDiff = Math.abs(best.timestamp - highlightedTimestampMs)
for (const item of timeline) {
const diff = Math.abs(item.timestamp - highlightedTimestampMs)
if (diff < bestDiff) {
best = item
bestDiff = diff
}
}
return best.id
}, [highlightedTimestampMs, timeline])
useEffect(() => {
if (!highlightedId || typeof document === 'undefined') return
const el = document.querySelector<HTMLElement>(`[data-segment-id="${highlightedId}"]`)
el?.scrollIntoView?.({ behavior: 'smooth', block: 'center' })
}, [highlightedId, highlightedTimestampMs])
return ( return (
<Box sx={{ display: 'flex', flexDirection: 'column' }}> <Box sx={{ display: 'flex', flexDirection: 'column' }}>
{/* 상단 컨트롤 */} {/* 상단 컨트롤 */}
@ -135,6 +158,7 @@ export function TranscriptTab({
onEdit={onEditSegment} onEdit={onEditSegment}
readOnly={!editable} readOnly={!editable}
speaker={item.speaker} speaker={item.speaker}
highlighted={item.id === highlightedId}
/> />
) )
} }
@ -142,6 +166,8 @@ export function TranscriptTab({
return ( return (
<Box <Box
key={item.id} key={item.id}
data-segment-id={item.id}
data-timestamp-ms={item.timestamp}
sx={{ sx={{
display: 'flex', display: 'flex',
alignItems: 'baseline', alignItems: 'baseline',

View file

@ -55,3 +55,37 @@ export function clearNotepad(storage: NotepadStorage | null, sessionId: string):
/* 지우지 못해도 다른 회의에 영향은 없다 */ /* 지우지 못해도 다른 회의에 영향은 없다 */
} }
} }
export interface NotepadSyncApi {
addMemo: (params: { content: string; sessionId?: string; meetingId?: string }) => Promise<{
success: boolean
data?: import('@d3ro/core/types').MeetingMemo
}>
}
/**
* 로컬 초안 저장소(localStorage)에 즉시 보관하고, 비어 있지 않은 노트는 `meetingMode.addMemo` IPC를 통해
* SQLite `meeting_memos` 및 클라우드 동기화 아웃박스에 반영한다.
*/
export async function syncNotepadMemo(
storage: NotepadStorage | null,
sessionId: string,
text: string,
api?: NotepadSyncApi | null,
): Promise<import('@d3ro/core/types').MeetingMemo | null> {
saveNotepad(storage, sessionId, text)
const trimmed = text.trim()
if (!trimmed) return null
const resolvedApi =
api ?? (typeof window !== 'undefined' ? window.electronAPI?.meetingMode : undefined)
if (!resolvedApi?.addMemo) return null
try {
const res = await resolvedApi.addMemo({ content: trimmed, sessionId, meetingId: sessionId })
if (res.success && res.data) {
return res.data
}
} catch {
/* IPC 실패 시에도 localStorage 초안은 유지 */
}
return null
}

View file

@ -5,8 +5,8 @@
// 2026-09-28: 2열 카드(글래스·LED·배지 무더기·떠오르는 hover)를 목록 한 줄로 바꿨다. // 2026-09-28: 2열 카드(글래스·LED·배지 무더기·떠오르는 hover)를 목록 한 줄로 바꿨다.
import React, { useCallback, useEffect, useId, useRef, useState } from 'react' import React, { useCallback, useEffect, useId, useRef, useState } from 'react'
import { Box, ButtonBase, Chip, Collapse, IconButton, InputBase, Tooltip, Typography } from '@mui/material' import { Box, ButtonBase, Chip, Collapse, IconButton, InputBase, TextField, Tooltip, Typography } from '@mui/material'
import { Check, ChevronDown, Copy, Play, Square, Star, Tag, Trash2, X } from 'lucide-react' import { Check, ChevronDown, Copy, Pencil, Play, Square, Star, Tag, Trash2, X } from 'lucide-react'
import { PhysicalButton, TactileBadge } from '@d3ro/ui/components/ds' import { PhysicalButton, TactileBadge } from '@d3ro/ui/components/ds'
import { d3roPalette, d3roFocusRing, d3roRadius, d3roTransition, typoSx } from '@d3ro/ui/theme' import { d3roPalette, d3roFocusRing, d3roRadius, d3roTransition, typoSx } from '@d3ro/ui/theme'
import { useI18n } from '@d3ro/i18n' import { useI18n } from '@d3ro/i18n'
@ -66,6 +66,11 @@ export interface HistoryEntryCardProps {
activeTag?: string | null activeTag?: string | null
/** 태그를 붙이거나 뗐을 때 (화면의 태그 목록 갱신) */ /** 태그를 붙이거나 뗐을 때 (화면의 태그 목록 갱신) */
onTagsChanged?: () => void onTagsChanged?: () => void
/** 제목·본문 수정 저장 콜백 */
onUpdate?: (
entry: HistoryEntry,
patch: { title?: string | null; polishedText?: string | null; originalText?: string },
) => Promise<boolean> | void
} }
export function HistoryEntryCard({ export function HistoryEntryCard({
@ -79,6 +84,7 @@ export function HistoryEntryCard({
onTagClick, onTagClick,
activeTag = null, activeTag = null,
onTagsChanged, onTagsChanged,
onUpdate,
}: HistoryEntryCardProps): React.ReactElement { }: HistoryEntryCardProps): React.ReactElement {
const { t } = useI18n() const { t } = useI18n()
const panelId = useId() const panelId = useId()
@ -197,6 +203,7 @@ export function HistoryEntryCard({
onTagClick={onTagClick} onTagClick={onTagClick}
activeTag={activeTag} activeTag={activeTag}
onTagsChanged={onTagsChanged} onTagsChanged={onTagsChanged}
onUpdate={onUpdate}
/> />
</Collapse> </Collapse>
</Box> </Box>
@ -216,6 +223,10 @@ interface RecordDetailProps {
onTagClick?: (tag: string) => void onTagClick?: (tag: string) => void
activeTag: string | null activeTag: string | null
onTagsChanged?: () => void onTagsChanged?: () => void
onUpdate?: (
entry: HistoryEntry,
patch: { title?: string | null; polishedText?: string | null; originalText?: string },
) => Promise<boolean> | void
} }
function SectionLabel({ children }: { children: React.ReactNode }): React.ReactElement { function SectionLabel({ children }: { children: React.ReactNode }): React.ReactElement {
@ -248,6 +259,7 @@ function RecordDetail({
onTagClick, onTagClick,
activeTag, activeTag,
onTagsChanged, onTagsChanged,
onUpdate,
}: RecordDetailProps): React.ReactElement { }: RecordDetailProps): React.ReactElement {
const { t } = useI18n() const { t } = useI18n()
const [tags, setTags] = useState<MemoTag[]>([]) const [tags, setTags] = useState<MemoTag[]>([])
@ -257,9 +269,36 @@ function RecordDetail({
const [showOriginal, setShowOriginal] = useState(false) const [showOriginal, setShowOriginal] = useState(false)
const [copied, setCopied] = useState<CopiedKind>(null) const [copied, setCopied] = useState<CopiedKind>(null)
const [audioState, setAudioState] = useState<HistoryAudioState>('idle') const [audioState, setAudioState] = useState<HistoryAudioState>('idle')
const [editing, setEditing] = useState(false)
const [draftTitle, setDraftTitle] = useState(entry.title ?? '')
const [draftText, setDraftText] = useState(primaryText)
const [savingEdit, setSavingEdit] = useState(false)
const playerRef = useRef<HistoryAudioPlayer | null>(null) const playerRef = useRef<HistoryAudioPlayer | null>(null)
const copiedTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null) const copiedTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
const handleStartEdit = useCallback(() => {
setDraftTitle(entry.title ?? '')
setDraftText(primaryText)
setEditing(true)
}, [entry.title, primaryText])
const handleSaveEdit = useCallback(async () => {
if (!onUpdate || savingEdit) return
setSavingEdit(true)
try {
const hasPolished = Boolean(entry.polishedText?.trim())
const patch = hasPolished
? { title: draftTitle.trim() || null, polishedText: draftText }
: { title: draftTitle.trim() || null, originalText: draftText }
const ok = await onUpdate(entry, patch)
if (ok !== false) {
setEditing(false)
}
} finally {
setSavingEdit(false)
}
}, [onUpdate, savingEdit, entry, draftTitle, draftText])
const getPlayer = useCallback((): HistoryAudioPlayer => { const getPlayer = useCallback((): HistoryAudioPlayer => {
if (!playerRef.current) playerRef.current = new HistoryAudioPlayer(browserHistoryAudioPort, setAudioState) if (!playerRef.current) playerRef.current = new HistoryAudioPlayer(browserHistoryAudioPort, setAudioState)
return playerRef.current return playerRef.current
@ -405,6 +444,40 @@ function RecordDetail({
<Box component="section"> <Box component="section">
{labelled && <SectionLabel>{originalText ? t('records.section.polished') : t('records.section.original')}</SectionLabel>} {labelled && <SectionLabel>{originalText ? t('records.section.polished') : t('records.section.original')}</SectionLabel>}
{editing ? (
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>
<TextField
size="small"
value={draftTitle}
onChange={(e) => setDraftTitle(e.target.value)}
placeholder={t('meetings.renameDialog.label')}
fullWidth
sx={{ '& .MuiOutlinedInput-root': { bgcolor: d3roPalette.bg.input } }}
/>
<TextField
size="small"
multiline
minRows={3}
value={draftText}
onChange={(e) => setDraftText(e.target.value)}
fullWidth
sx={{ '& .MuiOutlinedInput-root': { bgcolor: d3roPalette.bg.input } }}
/>
<Box sx={{ display: 'flex', gap: 1, justifyContent: 'flex-end' }}>
<PhysicalButton size="small" tone="ghost" onClick={() => setEditing(false)} disabled={savingEdit}>
{t('common.cancel')}
</PhysicalButton>
<PhysicalButton
size="small"
tone="glass"
onClick={() => void handleSaveEdit()}
disabled={savingEdit || !draftText.trim()}
>
{t('common.save')}
</PhysicalButton>
</Box>
</Box>
) : (
<Typography <Typography
sx={{ sx={{
...typoSx('body'), ...typoSx('body'),
@ -416,6 +489,7 @@ function RecordDetail({
> >
{primaryText} {primaryText}
</Typography> </Typography>
)}
</Box> </Box>
{originalText && ( {originalText && (
@ -591,6 +665,18 @@ function RecordDetail({
<Tag size={15} aria-hidden /> <Tag size={15} aria-hidden />
</IconButton> </IconButton>
</Tooltip> </Tooltip>
{onUpdate && (
<Tooltip title={t('common.edit')}>
<IconButton
size="small"
aria-label={t('common.edit')}
onClick={handleStartEdit}
sx={iconButtonSx}
>
<Pencil size={15} aria-hidden />
</IconButton>
</Tooltip>
)}
<Tooltip title={t('common.delete')}> <Tooltip title={t('common.delete')}>
<IconButton <IconButton
size="small" size="small"

View file

@ -8,23 +8,27 @@
import React, { useState, useEffect, useCallback, useRef } from 'react' import React, { useState, useEffect, useCallback, useRef } from 'react'
import { import {
Box, Box,
Checkbox,
Dialog, Dialog,
DialogTitle, DialogTitle,
DialogContent, DialogContent,
DialogActions, DialogActions,
FormControlLabel, FormControlLabel,
IconButton, IconButton,
Radio,
RadioGroup,
TextField, TextField,
Tooltip, Tooltip,
Typography, Typography,
} from '@mui/material' } from '@mui/material'
import { Plus, Trash2, Pencil, Play } from 'lucide-react' import { Plus, Trash2, Pencil, Play, ArrowUp, ArrowDown } from 'lucide-react'
import { PhysicalButton, TactileBadge } from '@d3ro/ui/components/ds' import { PhysicalButton, TactileBadge } from '@d3ro/ui/components/ds'
import { PageHeader, EmptyStateCard, useNotify } from '../components/shared' import { PageHeader, EmptyStateCard, useNotify } from '../components/shared'
import { d3roPalette, d3roRadius, typoSx } from '@d3ro/ui/theme' import { d3roPalette, d3roRadius, typoSx } from '@d3ro/ui/theme'
import { INSTRUCTION_LIMITS } from '@d3ro/core/instruction-policy' import { INSTRUCTION_LIMITS } from '@d3ro/core/instruction-policy'
import {
moveInstructionInPipeline,
serializeActiveInstructionIds,
toggleInstructionInPipeline,
} from '@d3ro/core/instruction-template'
import type { CustomInstruction, LLMActionSelection } from '@d3ro/core/types' import type { CustomInstruction, LLMActionSelection } from '@d3ro/core/types'
import { commandSaveError } from './commands/command-form' import { commandSaveError } from './commands/command-form'
import { useI18n } from '@d3ro/i18n' import { useI18n } from '@d3ro/i18n'
@ -34,9 +38,11 @@ import { useDeferredDelete } from './tools/useDeferredDelete'
import { import {
COMMAND_NONE, COMMAND_NONE,
commandSelection, commandSelection,
commandSelections,
commandTestRequest, commandTestRequest,
isInstructionInUse, isInstructionInUse,
llmActionLabelKey, llmActionLabelKey,
removeInstructionFromActiveIds,
resolveCommandPipeline, resolveCommandPipeline,
withoutHidden, withoutHidden,
type CommandPipeline, type CommandPipeline,
@ -105,15 +111,17 @@ export function CommandsPage(): React.ReactElement {
const visible = withoutHidden(instructions, hidden) const visible = withoutHidden(instructions, hidden)
const pipeline: CommandPipeline<CustomInstruction> | null = config ? resolveCommandPipeline(config, visible) : null const pipeline: CommandPipeline<CustomInstruction> | null = config ? resolveCommandPipeline(config, visible) : null
const selection = pipeline ? commandSelection(pipeline) : '' const selection = pipeline ? commandSelection(pipeline) : ''
const selectedIds = pipeline ? commandSelections(pipeline) : []
/** 라디오 선택 — 설정 두 개를 함께 바꾼다. 실패하면 되돌리고 알린다 */ /** 파이프라인 ID 목록 적용 — 0개면 none, 1개 이상이면 순서대로 직렬화해 custom 으로 저장한다 */
const handleSelect = async (value: string): Promise<void> => { const applyPipelineIds = async (nextIds: readonly string[]): Promise<void> => {
if (!config) return if (!config) return
const previous = config const previous = config
const serialized = serializeActiveInstructionIds(nextIds)
const next: PipelineConfig = const next: PipelineConfig =
value === COMMAND_NONE serialized.length === 0
? { defaultLLMAction: 'none', activeInstructionId: null } ? { defaultLLMAction: 'none', activeInstructionId: null }
: { defaultLLMAction: 'custom', activeInstructionId: value } : { defaultLLMAction: 'custom', activeInstructionId: serialized }
setConfig(next) setConfig(next)
try { try {
const results = await Promise.all([ const results = await Promise.all([
@ -127,6 +135,14 @@ export function CommandsPage(): React.ReactElement {
} }
} }
const handleToggleInstruction = (id: string): void => {
void applyPipelineIds(toggleInstructionInPipeline(selectedIds, id))
}
const handleMoveInstruction = (id: string, direction: 'up' | 'down'): void => {
void applyPipelineIds(moveInstructionInPipeline(selectedIds, id, direction))
}
const openAdd = () => { const openAdd = () => {
if (dialogOpen) return if (dialogOpen) return
setEditId(null) setEditId(null)
@ -187,10 +203,19 @@ export function CommandsPage(): React.ReactElement {
commit: async () => { commit: async () => {
const res = await window.electronAPI.instruction.delete({ id: inst.id }) const res = await window.electronAPI.instruction.delete({ id: inst.id })
if (!res.success) return false if (!res.success) return false
// 지금도 쓰이는 명령을 지웠으면 원문 그대로 넣기로 돌린다 — 확정 시점의 설정으로 판단한다 // 지금도 쓰이는 명령을 지웠으면 파이프라인에서 빼고, 남은 명령이 없을 때만 원문 그대로 넣기로 돌린다
const latest = await window.electronAPI.config.getAll() const latest = await window.electronAPI.config.getAll()
if (latest.success && isInstructionInUse(latest.data, inst.id)) { if (latest.success && isInstructionInUse(latest.data, inst.id)) {
const remaining = removeInstructionFromActiveIds(latest.data.activeInstructionId, inst.id)
if (remaining.length === 0) {
await window.electronAPI.config.set({ key: 'activeInstructionId', value: '' })
await window.electronAPI.config.set({ key: 'defaultLLMAction', value: 'none' }) await window.electronAPI.config.set({ key: 'defaultLLMAction', value: 'none' })
} else {
await window.electronAPI.config.set({
key: 'activeInstructionId',
value: serializeActiveInstructionIds(remaining),
})
}
} }
return true return true
}, },
@ -247,16 +272,13 @@ export function CommandsPage(): React.ReactElement {
{loading && instructions.length === 0 ? ( {loading && instructions.length === 0 ? (
<ToolLoading /> <ToolLoading />
) : ( ) : (
<RadioGroup <Box role="group" aria-label={t('tools.commands.listTitle')}>
value={selection}
onChange={(_e, value) => void handleSelect(value)}
aria-label={t('tools.commands.listTitle')}
>
<ToolRow selected={selection === COMMAND_NONE}> <ToolRow selected={selection === COMMAND_NONE}>
<FormControlLabel <FormControlLabel
value={COMMAND_NONE} checked={selection === COMMAND_NONE}
onChange={() => void applyPipelineIds([])}
disabled={!config} disabled={!config}
control={<Radio size="small" />} control={<Checkbox size="small" />}
sx={{ flex: 1, minWidth: 0, m: 0, gap: 0.5 }} sx={{ flex: 1, minWidth: 0, m: 0, gap: 0.5 }}
label={ label={
<Box sx={{ minWidth: 0 }}> <Box sx={{ minWidth: 0 }}>
@ -269,26 +291,63 @@ export function CommandsPage(): React.ReactElement {
/> />
</ToolRow> </ToolRow>
{visible.map((inst) => { {visible.map((inst) => {
const isActive = inst.id === selection const stepIndex = selectedIds.indexOf(inst.id)
const isActive = stepIndex >= 0
const stepNumber = stepIndex + 1
return ( return (
<ToolRow key={inst.id} selected={isActive}> <ToolRow key={inst.id} selected={isActive}>
<FormControlLabel <FormControlLabel
value={inst.id} checked={isActive}
onChange={() => handleToggleInstruction(inst.id)}
disabled={!config} disabled={!config}
control={<Radio size="small" />} control={<Checkbox size="small" />}
sx={{ flex: 1, minWidth: 0, m: 0, gap: 0.5 }} sx={{ flex: 1, minWidth: 0, m: 0, gap: 0.5 }}
label={ label={
<Box sx={{ minWidth: 0 }}> <Box sx={{ minWidth: 0 }}>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1, flexWrap: 'wrap' }}> <Box sx={{ display: 'flex', alignItems: 'center', gap: 1, flexWrap: 'wrap' }}>
<Typography sx={{ ...typoSx('body'), color: d3roPalette.text.primary }}>{inst.name}</Typography> <Typography sx={{ ...typoSx('body'), color: d3roPalette.text.primary }}>{inst.name}</Typography>
{isActive && <TactileBadge tone="accent">{t('tools.commands.inUse')}</TactileBadge>} {isActive && (
<TactileBadge tone="accent">
{selectedIds.length > 1
? t('tools.commands.stepBadge', { step: stepNumber })
: t('tools.commands.inUse')}
</TactileBadge>
)}
{inst.isBuiltin && <Typography sx={TOOL_TEXT_SX.meta}>{t('tools.builtin')}</Typography>} {inst.isBuiltin && <Typography sx={TOOL_TEXT_SX.meta}>{t('tools.builtin')}</Typography>}
</Box> </Box>
{inst.description && <Typography sx={TOOL_TEXT_SX.meta}>{inst.description}</Typography>} {inst.description && <Typography sx={TOOL_TEXT_SX.meta}>{inst.description}</Typography>}
</Box> </Box>
} }
/> />
<Box sx={{ display: 'flex', gap: 0.5, flexShrink: 0 }}> <Box sx={{ display: 'flex', gap: 0.5, flexShrink: 0, alignItems: 'center' }}>
{isActive && selectedIds.length > 1 && (
<>
<Tooltip title={t('tools.commands.moveUp', { name: inst.name })}>
<span>
<IconButton
size="small"
disabled={stepIndex === 0}
aria-label={t('tools.commands.moveUp', { name: inst.name })}
onClick={() => handleMoveInstruction(inst.id, 'up')}
>
<ArrowUp size={15} />
</IconButton>
</span>
</Tooltip>
<Tooltip title={t('tools.commands.moveDown', { name: inst.name })}>
<span>
<IconButton
size="small"
disabled={stepIndex === selectedIds.length - 1}
aria-label={t('tools.commands.moveDown', { name: inst.name })}
onClick={() => handleMoveInstruction(inst.id, 'down')}
>
<ArrowDown size={15} />
</IconButton>
</span>
</Tooltip>
</>
)}
<Tooltip title={t('common.edit')}> <Tooltip title={t('common.edit')}>
<IconButton <IconButton
size="small" size="small"
@ -313,7 +372,7 @@ export function CommandsPage(): React.ReactElement {
</ToolRow> </ToolRow>
) )
})} })}
</RadioGroup> </Box>
)} )}
{!loading && !loadError && visible.length === 0 && ( {!loading && !loadError && visible.length === 0 && (
<Box sx={{ mt: 2 }}> <Box sx={{ mt: 2 }}>
@ -431,7 +490,7 @@ export function CommandsPage(): React.ReactElement {
) )
} }
/** 지금 받아쓰기가 거치는 단계 — 조용한 요약 패널 하나 */ /** 지금 받아쓰기가 거치는 단계 — 조용한 요약 패널 하나 (단일 명령 및 다단계 파이프라인 모두 표시) */
function PipelineSummary({ pipeline }: { pipeline: CommandPipeline<CustomInstruction> }): React.ReactElement { function PipelineSummary({ pipeline }: { pipeline: CommandPipeline<CustomInstruction> }): React.ReactElement {
const { t } = useI18n() const { t } = useI18n()
const current = const current =
@ -439,18 +498,26 @@ function PipelineSummary({ pipeline }: { pipeline: CommandPipeline<CustomInstruc
? t('tools.commands.none') ? t('tools.commands.none')
: pipeline.kind === 'instruction' : pipeline.kind === 'instruction'
? pipeline.instruction.name ? pipeline.instruction.name
: pipeline.kind === 'instructions'
? pipeline.instructions.map((inst, idx) => `${idx + 1}. ${inst.name}`).join(' → ')
: pipeline.kind === 'instruction-missing' : pipeline.kind === 'instruction-missing'
? t('tools.commands.pipeline.missing') ? t('tools.commands.pipeline.missing')
: t(llmActionLabelKey(pipeline.action)) : t(llmActionLabelKey(pipeline.action))
const llmStep =
const llmSteps: string[] =
pipeline.kind === 'raw' pipeline.kind === 'raw'
? t('tools.commands.pipeline.stepRaw') ? [t('tools.commands.pipeline.stepRaw')]
: pipeline.kind === 'instruction' : pipeline.kind === 'instruction'
? t('tools.commands.pipeline.stepInstruction', { name: pipeline.instruction.name }) ? [t('tools.commands.pipeline.stepInstruction', { name: pipeline.instruction.name })]
: pipeline.kind === 'instructions'
? pipeline.instructions.map((inst, idx) =>
t('tools.commands.pipeline.stepPipelineItem', { step: idx + 1, name: inst.name }),
)
: pipeline.kind === 'instruction-missing' : pipeline.kind === 'instruction-missing'
? t('tools.commands.pipeline.stepMissing') ? [t('tools.commands.pipeline.stepMissing')]
: t('tools.commands.pipeline.stepAction', { action: t(llmActionLabelKey(pipeline.action)) }) : [t('tools.commands.pipeline.stepAction', { action: t(llmActionLabelKey(pipeline.action)) })]
const steps = [t('tools.commands.pipeline.stepStt'), llmStep, t('tools.commands.pipeline.stepInsert')]
const steps = [t('tools.commands.pipeline.stepStt'), ...llmSteps, t('tools.commands.pipeline.stepInsert')]
return ( return (
<Box <Box

View file

@ -253,6 +253,24 @@ export function HistoryPage(): React.ReactElement {
setTag((prev) => (prev === next ? null : next)) setTag((prev) => (prev === next ? null : next))
}, []) }, [])
const handleUpdate = useCallback(
async (
entry: HistoryEntry,
nextPatch: { title?: string | null; polishedText?: string | null; originalText?: string },
): Promise<boolean> => {
const result = await window.electronAPI.history
.update({ id: entry.id, ...nextPatch })
.catch(() => null)
if (result?.success && result.data) {
patch(entry.id, result.data)
return true
}
notify({ message: t('records.status.error'), severity: 'error' })
return false
},
[patch, notify, t],
)
const exportingRef = useRef(false) const exportingRef = useRef(false)
const [exporting, setExporting] = useState(false) const [exporting, setExporting] = useState(false)
const handleExport = useCallback(async () => { const handleExport = useCallback(async () => {
@ -261,15 +279,27 @@ export function HistoryPage(): React.ReactElement {
setExporting(true) setExporting(true)
try { try {
const result = await window.electronAPI.memo const result = await window.electronAPI.memo
.export({ format: 'markdown', tag: tag ?? undefined }) .export({
format: 'markdown',
tag: tag ?? undefined,
mode: mode !== 'all' ? mode : undefined,
isFavorite: favoritesOnly ? true : undefined,
search: query.trim() || undefined,
includeUntagged: !tag,
})
.catch(() => null) .catch(() => null)
if (result?.success) notify({ message: t('records.exportDone', { path: result.data }), severity: 'success' }) if (result?.success && result.data) {
else notify({ message: t('records.exportFailed'), severity: 'error' }) notify({ message: t('records.exportDone', { path: result.data }), severity: 'success' })
} else if (result?.success && result.data === '') {
// 대화상자 취소 시 무시
} else {
notify({ message: t('records.exportFailed'), severity: 'error' })
}
} finally { } finally {
exportingRef.current = false exportingRef.current = false
setExporting(false) setExporting(false)
} }
}, [tag, notify, t]) }, [tag, mode, favoritesOnly, query, notify, t])
// 전체 삭제는 필터와 무관하고 동기화로 다른 기기에도 전파되므로 반드시 확인 단계를 거친다 // 전체 삭제는 필터와 무관하고 동기화로 다른 기기에도 전파되므로 반드시 확인 단계를 거친다
const clearAll = useClearAllHistory((deleted) => { const clearAll = useClearAllHistory((deleted) => {
@ -477,6 +507,7 @@ export function HistoryPage(): React.ReactElement {
onTagClick={handleTagToggle} onTagClick={handleTagToggle}
activeTag={tag} activeTag={tag}
onTagsChanged={() => void loadMeta()} onTagsChanged={() => void loadMeta()}
onUpdate={handleUpdate}
/> />
))} ))}
</Box> </Box>

View file

@ -14,13 +14,30 @@ import { isImeComposingEvent } from '../utils/keyboard'
import { d3roPalette, d3roRadius, typoSx } from '@d3ro/ui/theme' import { d3roPalette, d3roRadius, typoSx } from '@d3ro/ui/theme'
import { useI18n } from '@d3ro/i18n' import { useI18n } from '@d3ro/i18n'
import type { RAGDocument, RAGQueryResult, RAGIndexProgress } from '@d3ro/core/types' import type { RAGDocument, RAGQueryResult, RAGIndexProgress } from '@d3ro/core/types'
import { ErrorCode } from '@d3ro/core/errors' import { ErrorCode, type IPCResult } from '@d3ro/core/errors'
import { ToolLoadError, ToolLoading, ToolRow, ToolSection, TOOL_PAGE_SX, TOOL_TABS_SX, TOOL_TEXT_SX } from './tools/ToolSection' import { ToolLoadError, ToolLoading, ToolRow, ToolSection, TOOL_PAGE_SX, TOOL_TABS_SX, TOOL_TEXT_SX } from './tools/ToolSection'
import { useDeferredDelete } from './tools/useDeferredDelete' import { useDeferredDelete } from './tools/useDeferredDelete'
import { documentIndexLabelKey, KNOWLEDGE_EXAMPLE_KEYS, withoutHidden } from './tools/tools-model' import { documentIndexLabelKey, KNOWLEDGE_EXAMPLE_KEYS, withoutHidden } from './tools/tools-model'
type KnowledgeView = 'kb' | 'insights' type KnowledgeView = 'kb' | 'insights'
/**
* 지식 문서 추가 응답에서 사용자에게 표시할 오류 메시지를 결정한다.
* 파일 선택 취소나 대화상자 중복 활성 상태는 구조화된 details.cancelled 및 ErrorCode로 판별한다.
*/
export function resolveRagAddError(resp: IPCResult<RAGDocument>): string | null {
if (resp.success) return null
const details = resp.error.details as { cancelled?: boolean; reason?: string } | undefined
if (details?.cancelled === true) return null
if (
resp.error.code === ErrorCode.RAGDocumentNotFound &&
(details?.reason === 'dialog_cancelled' || details?.reason === 'dialog_active')
) {
return null
}
return resp.error.message
}
export function KnowledgeBasePage(): React.ReactElement { export function KnowledgeBasePage(): React.ReactElement {
// 이 화면은 두 축을 가진다: 수집된 지식 문서(RAG)와 자동 수집된 입력 데이터 통계. // 이 화면은 두 축을 가진다: 수집된 지식 문서(RAG)와 자동 수집된 입력 데이터 통계.
const [view, setView] = useState<KnowledgeView>('kb') const [view, setView] = useState<KnowledgeView>('kb')
@ -88,8 +105,9 @@ export function KnowledgeBasePage(): React.ReactElement {
const resp = await window.electronAPI.rag.addDocument() const resp = await window.electronAPI.rag.addDocument()
if (resp.success) { if (resp.success) {
void loadDocuments() void loadDocuments()
} else if (!resp.error.message.includes('cancelled') && !resp.error.message.includes('already active')) { } else {
setAddError(resp.error.message) const errMessage = resolveRagAddError(resp)
if (errMessage) setAddError(errMessage)
} }
} finally { } finally {
setAdding(false) setAdding(false)

View file

@ -7,7 +7,7 @@
import React, { useState, useEffect, useCallback, useRef } from 'react' import React, { useState, useEffect, useCallback, useRef } from 'react'
import { Box, IconButton, TextField, Tooltip, Typography } from '@mui/material' import { Box, IconButton, TextField, Tooltip, Typography } from '@mui/material'
import { Mic, Square, Send, Trash2, XCircle, Bot } from 'lucide-react' import { Mic, Square, Send, Trash2, XCircle, Bot, Volume2 } from 'lucide-react'
import { PhysicalButton, TactileBadge } from '@d3ro/ui/components/ds' import { PhysicalButton, TactileBadge } from '@d3ro/ui/components/ds'
import { ConfirmDialog, PageHeader, useNotify } from '../components/shared' import { ConfirmDialog, PageHeader, useNotify } from '../components/shared'
import { VoiceRecordingPanel } from '../components/voice-conversation/VoiceRecordingPanel' import { VoiceRecordingPanel } from '../components/voice-conversation/VoiceRecordingPanel'
@ -246,6 +246,13 @@ export function VoiceConversationPage(): React.ReactElement {
await window.electronAPI.voiceConversation.cancelResponse() await window.electronAPI.voiceConversation.cancelResponse()
}, [isRealtime, realtime]) }, [isRealtime, realtime])
const handleReplayMessage = useCallback(async (msg: ConversationMessage) => {
await window.electronAPI.voiceConversation.replayMessage({
messageId: msg.id,
text: msg.content,
})
}, [])
const handleTextKeyDown = useCallback( const handleTextKeyDown = useCallback(
(e: React.KeyboardEvent) => { (e: React.KeyboardEvent) => {
if (isImeComposingEvent(e)) return if (isImeComposingEvent(e)) return
@ -351,9 +358,23 @@ export function VoiceConversationPage(): React.ReactElement {
borderRadius: isUser ? BUBBLE_RADIUS.user : BUBBLE_RADIUS.assistant, borderRadius: isUser ? BUBBLE_RADIUS.user : BUBBLE_RADIUS.assistant,
bgcolor: isUser ? d3roPalette.bg.inset : d3roPalette.bg.card, bgcolor: isUser ? d3roPalette.bg.inset : d3roPalette.bg.card,
border: `1px solid ${isUser ? d3roPalette.border.subtle : d3roPalette.border.default}`, border: `1px solid ${isUser ? d3roPalette.border.subtle : d3roPalette.border.default}`,
display: 'flex',
alignItems: 'flex-start',
gap: 1,
}} }}
> >
<Typography sx={{ ...BUBBLE_TEXT_SX, color: d3roPalette.text.primary }}>{msg.content}</Typography> <Typography sx={{ ...BUBBLE_TEXT_SX, color: d3roPalette.text.primary, flex: 1 }}>{msg.content}</Typography>
{!isUser && (
<IconButton
size="small"
aria-label={t('conversation.error.phase.tts')}
onClick={() => void handleReplayMessage(msg)}
disabled={busy}
sx={{ p: 0.5, mt: -0.25, mr: -0.5, color: d3roPalette.text.tertiary }}
>
<Volume2 size={14} />
</IconButton>
)}
</Box> </Box>
</Box> </Box>
) )

View file

@ -3,6 +3,11 @@
// 화면이 말하는 상태는 여기서 한 번만 정한다: 조회한 설정에서 나온 사실만 쓰고, 추측을 '정상'으로 쓰지 않는다. // 화면이 말하는 상태는 여기서 한 번만 정한다: 조회한 설정에서 나온 사실만 쓰고, 추측을 '정상'으로 쓰지 않는다.
import type { TranslationKey } from '@d3ro/i18n' import type { TranslationKey } from '@d3ro/i18n'
import {
composeInstructionPipelinePrompt,
parseActiveInstructionIds,
serializeActiveInstructionIds,
} from '@d3ro/core/instruction-template'
import type { ConversationState, LLMAction, LLMActionSelection, LLMProcessParams } from '@d3ro/core/types' import type { ConversationState, LLMAction, LLMActionSelection, LLMProcessParams } from '@d3ro/core/types'
/** 지연 삭제 중인 항목을 목록에서 뺀다 */ /** 지연 삭제 중인 항목을 목록에서 뺀다 */
@ -25,10 +30,12 @@ interface InstructionLike {
/** /**
* 지금 받아쓰기에 실제로 적용되는 후처리 — main 의 resolveVoiceLlmRoute 와 같은 규칙: * 지금 받아쓰기에 실제로 적용되는 후처리 — main 의 resolveVoiceLlmRoute 와 같은 규칙:
* 지시문은 기본 액션이 'custom' 일 때만 쓰인다(활성 지시문이 있어도 refine 등을 덮지 않는다). * 지시문은 기본 액션이 'custom' 일 때만 쓰인다(활성 지시문이 있어도 refine 등을 덮지 않는다).
* 여러 명령을 순서대로 고르면 `instructions`(2개 이상) 파이프라인으로 합성 실행된다.
*/ */
export type CommandPipeline<T extends InstructionLike> = export type CommandPipeline<T extends InstructionLike> =
| { kind: 'raw' } | { kind: 'raw' }
| { kind: 'instruction'; instruction: T } | { kind: 'instruction'; instruction: T }
| { kind: 'instructions'; instructions: readonly T[] }
/** 'custom' 인데 활성 지시문이 없거나 지워졌다 */ /** 'custom' 인데 활성 지시문이 없거나 지워졌다 */
| { kind: 'instruction-missing' } | { kind: 'instruction-missing' }
| { kind: 'action'; action: Exclude<LLMAction, 'custom'> } | { kind: 'action'; action: Exclude<LLMAction, 'custom'> }
@ -40,21 +47,32 @@ export function resolveCommandPipeline<T extends InstructionLike>(
const action = config.defaultLLMAction const action = config.defaultLLMAction
if (action === 'none') return { kind: 'raw' } if (action === 'none') return { kind: 'raw' }
if (action === 'custom') { if (action === 'custom') {
const instruction = config.activeInstructionId const ids = parseActiveInstructionIds(config.activeInstructionId)
? instructions.find((item) => item.id === config.activeInstructionId) const matched = ids
: undefined .map((id) => instructions.find((item) => item.id === id))
return instruction ? { kind: 'instruction', instruction } : { kind: 'instruction-missing' } .filter((item): item is T => item !== undefined)
if (matched.length === 0) return { kind: 'instruction-missing' }
if (matched.length === 1) return { kind: 'instruction', instruction: matched[0] }
return { kind: 'instructions', instructions: matched }
} }
return { kind: 'action', action } return { kind: 'action', action }
} }
/** 목록 라디오의 선택 값 — 일반 액션(다듬기 등)이 기본이면 아무것도 고르지 않은 상태다 */ /** 목록 선택 직렬화 값 — 일반 액션(다듬기 등)이 기본이면 아무것도 고르지 않은 상태다 */
export function commandSelection<T extends InstructionLike>(pipeline: CommandPipeline<T>): string { export function commandSelection<T extends InstructionLike>(pipeline: CommandPipeline<T>): string {
if (pipeline.kind === 'raw') return COMMAND_NONE if (pipeline.kind === 'raw') return COMMAND_NONE
if (pipeline.kind === 'instruction') return pipeline.instruction.id if (pipeline.kind === 'instruction') return pipeline.instruction.id
if (pipeline.kind === 'instructions') return serializeActiveInstructionIds(pipeline.instructions.map((i) => i.id))
return '' return ''
} }
/** 현재 파이프라인에서 선택된 명령 ID 배열 (순서 보존) */
export function commandSelections<T extends InstructionLike>(pipeline: CommandPipeline<T>): string[] {
if (pipeline.kind === 'instruction') return [pipeline.instruction.id]
if (pipeline.kind === 'instructions') return pipeline.instructions.map((i) => i.id)
return []
}
/** /**
* 지운 명령이 지금도 받아쓰기에 쓰이는가 — 삭제 확정(되돌리기 알림이 닫힐 때) 시점의 설정으로 판단한다. * 지운 명령이 지금도 받아쓰기에 쓰이는가 — 삭제 확정(되돌리기 알림이 닫힐 때) 시점의 설정으로 판단한다.
* 삭제를 누른 순간 값으로 판단하면, 그사이 사용자가 고른 다른 명령을 '원문 그대로'로 덮었다. * 삭제를 누른 순간 값으로 판단하면, 그사이 사용자가 고른 다른 명령을 '원문 그대로'로 덮었다.
@ -63,7 +81,13 @@ export function isInstructionInUse(
config: { defaultLLMAction?: unknown; activeInstructionId?: unknown } | null | undefined, config: { defaultLLMAction?: unknown; activeInstructionId?: unknown } | null | undefined,
instructionId: string, instructionId: string,
): boolean { ): boolean {
return config?.defaultLLMAction === 'custom' && config.activeInstructionId === instructionId if (config?.defaultLLMAction !== 'custom') return false
return parseActiveInstructionIds(config.activeInstructionId).includes(instructionId)
}
/** 삭제 확정된 명령 ID를 활성 파이프라인에서 제거한 나머지 ID 배열을 반환한다. */
export function removeInstructionFromActiveIds(activeInstructionId: unknown, removedId: string): string[] {
return parseActiveInstructionIds(activeInstructionId).filter((id) => id !== removedId)
} }
/** 일반 후처리 액션 이름 */ /** 일반 후처리 액션 이름 */
@ -101,6 +125,15 @@ export function commandTestRequest<T extends InstructionLike>(
return { ok: false, reason: 'missing' } return { ok: false, reason: 'missing' }
case 'instruction': case 'instruction':
return { ok: true, params: { text: trimmed, action: 'custom', customPrompt: pipeline.instruction.prompt } } return { ok: true, params: { text: trimmed, action: 'custom', customPrompt: pipeline.instruction.prompt } }
case 'instructions':
return {
ok: true,
params: {
text: trimmed,
action: 'custom',
customPrompt: composeInstructionPipelinePrompt(pipeline.instructions),
},
}
case 'action': case 'action':
// 체인은 여러 단계를 main 의 ChainService 가 실행한다 — 한 번의 LLM 호출로 흉내 내지 않는다 // 체인은 여러 단계를 main 의 ChainService 가 실행한다 — 한 번의 LLM 호출로 흉내 내지 않는다
if (pipeline.action === 'chain') return { ok: false, reason: 'chain' } if (pipeline.action === 'chain') return { ok: false, reason: 'chain' }

View file

@ -62,8 +62,14 @@
currentCommands = commands currentCommands = commands
itemsContainer.innerHTML = '' itemsContainer.innerHTML = ''
items = [] items = []
var activeIds = String(activeId || '')
.split(',')
.map(function (s) {
return s.trim()
})
.filter(Boolean)
var none = makeRow(0, '0', tr('commandNone'), '', !activeId, true) var none = makeRow(0, '0', tr('commandNone'), '', activeIds.length === 0, true)
itemsContainer.appendChild(none) itemsContainer.appendChild(none)
items.push(none) items.push(none)
@ -75,7 +81,7 @@
} else { } else {
commands.forEach(function (cmd, i) { commands.forEach(function (cmd, i) {
var index = i + 1 var index = i + 1
var row = makeRow(index, index <= 9 ? String(index) : '', cmd.name, cmd.description || '', cmd.id === activeId, false) var row = makeRow(index, index <= 9 ? String(index) : '', cmd.name, cmd.description || '', activeIds.indexOf(cmd.id) !== -1, false)
itemsContainer.appendChild(row) itemsContainer.appendChild(row)
items.push(row) items.push(row)
}) })

View file

@ -0,0 +1,511 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { globalShortcut, ipcMain, powerMonitor } from 'electron'
import { uIOhook, UiohookKey } from 'uiohook-napi'
import type { UiohookKeyboardEvent, UiohookMouseEvent } from 'uiohook-napi'
import { IPC_CHANNELS } from '@d3ro/core/ipc-channels'
import {
MouseButton,
VK,
createDefaultBindingMap,
kb,
validateBinding,
} from '@d3ro/core/keybinding'
import type { KeyBinding, MouseButtonCode } from '@d3ro/core/types'
import {
configSet,
initInMemoryConfig,
resetInMemoryConfig,
saveKeyBindings,
} from '../../../src/main/services/ConfigService'
import {
getKeyBindingService,
uiohookCodeToVk,
type KeyBindingTriggerPayload,
} from '../../../src/main/services/KeyBindingService'
import { registerKeyBindingHandlers } from '../../../src/main/ipc/keybinding-handlers'
import { resetGlobalInputHookForTests } from '../../../src/main/services/global-input-hook'
type HookHandler<T> = (event: T) => void
function createHookHarness(): {
keydown: (event: Partial<UiohookKeyboardEvent> & { keycode: number }) => void
keyup: (event: Partial<UiohookKeyboardEvent> & { keycode: number }) => void
mousedown: (event: Partial<UiohookMouseEvent> & { button: unknown }) => void
mouseup: (event: Partial<UiohookMouseEvent> & { button: unknown }) => void
} {
const findListener = <T>(eventName: string): HookHandler<T> => {
const calls = vi.mocked(uIOhook.on).mock.calls
for (let i = calls.length - 1; i >= 0; i -= 1) {
const [registeredEvent, listener] = calls[i]
if (registeredEvent === eventName && typeof listener === 'function') {
return listener as unknown as HookHandler<T>
}
}
throw new Error(`No uIOhook listener registered for "${eventName}"`)
}
return {
keydown: (event) => {
findListener<UiohookKeyboardEvent>('keydown')({
type: 4,
time: Date.now(),
altKey: false,
ctrlKey: false,
metaKey: false,
shiftKey: false,
...event,
} as UiohookKeyboardEvent)
},
keyup: (event) => {
findListener<UiohookKeyboardEvent>('keyup')({
type: 5,
time: Date.now(),
altKey: false,
ctrlKey: false,
metaKey: false,
shiftKey: false,
...event,
} as UiohookKeyboardEvent)
},
mousedown: (event) => {
findListener<UiohookMouseEvent>('mousedown')({
type: 7,
time: Date.now(),
altKey: false,
ctrlKey: false,
metaKey: false,
shiftKey: false,
x: 0,
y: 0,
clicks: 1,
...event,
} as UiohookMouseEvent)
},
mouseup: (event) => {
findListener<UiohookMouseEvent>('mouseup')({
type: 8,
time: Date.now(),
altKey: false,
ctrlKey: false,
metaKey: false,
shiftKey: false,
x: 0,
y: 0,
clicks: 1,
...event,
} as UiohookMouseEvent)
},
}
}
function mb(
code: MouseButtonCode,
mods: Partial<Pick<KeyBinding, 'ctrl' | 'alt' | 'shift' | 'meta'>> = {},
): KeyBinding {
return {
device: 'mouse',
code,
ctrl: mods.ctrl ?? false,
alt: mods.alt ?? false,
shift: mods.shift ?? false,
meta: mods.meta ?? false,
}
}
const VK_F8 = VK.F1 + 7
const VK_F9 = VK.F1 + 8
describe('KeyBindingService', () => {
const hook = createHookHarness()
beforeEach(() => {
vi.clearAllMocks()
resetGlobalInputHookForTests()
initInMemoryConfig({
hotkeyEnabled: true,
suggestionEnabled: true,
})
const service = getKeyBindingService()
service.dispose()
})
afterEach(() => {
getKeyBindingService().dispose()
resetGlobalInputHookForTests()
resetInMemoryConfig()
})
describe('keyboard & mouse event handling and lifecycle', () => {
it('maps uiohook keycodes to canonical Windows VK codes and returns null for unknown codes', () => {
expect(uiohookCodeToVk(UiohookKey.F8)).toBe(VK_F8)
expect(uiohookCodeToVk(UiohookKey.AltRight)).toBe(VK.AltRight)
expect(uiohookCodeToVk(UiohookKey.A)).toBe(VK.A)
expect(uiohookCodeToVk(UiohookKey.Enter)).toBe(VK.Enter)
expect(uiohookCodeToVk(999_999)).toBeNull()
})
it('attaches uIOhook listeners on start, triggers keyboard actions, and cleans up on stop', () => {
const map = createDefaultBindingMap()
map.command = [kb(VK_F9, { ctrl: true })]
saveKeyBindings(map)
const service = getKeyBindingService()
const triggered: KeyBindingTriggerPayload[] = []
service.on('triggered', (payload) => triggered.push(payload))
service.loadFromConfig()
service.start()
expect(service.isRunning).toBe(true)
expect(service.registeredBindingCount).toBeGreaterThan(0)
hook.keydown({ keycode: UiohookKey.F9, ctrlKey: true })
hook.keyup({ keycode: UiohookKey.F9, ctrlKey: true })
expect(triggered).toEqual([
expect.objectContaining({
actionId: 'command',
type: 'pressed',
isDoublePress: false,
}),
expect.objectContaining({
actionId: 'command',
type: 'released',
isDoublePress: false,
}),
])
service.stop()
expect(service.isRunning).toBe(false)
expect(uIOhook.removeListener).toHaveBeenCalledWith('keydown', expect.any(Function))
expect(uIOhook.removeListener).toHaveBeenCalledWith('keyup', expect.any(Function))
expect(uIOhook.removeListener).toHaveBeenCalledWith('mousedown', expect.any(Function))
expect(uIOhook.removeListener).toHaveBeenCalledWith('mouseup', expect.any(Function))
})
it('skips keyboard bindings whose VK has no uiohook mapping (e.g., VK.Pause)', () => {
const map = createDefaultBindingMap()
for (const key of Object.keys(map) as Array<keyof typeof map>) {
map[key] = []
}
map.command = [kb(VK.Pause)]
saveKeyBindings(map)
const service = getKeyBindingService()
service.loadFromConfig()
expect(service.registeredBindingCount).toBe(0)
})
it('releases held bindings when powerMonitor emits lock-screen or suspend', () => {
const map = createDefaultBindingMap()
map.dictation = [kb(VK_F8)]
map['hands-free'] = []
saveKeyBindings(map)
const service = getKeyBindingService()
const triggered: KeyBindingTriggerPayload[] = []
service.on('triggered', (payload) => triggered.push(payload))
service.loadFromConfig()
service.start()
hook.keydown({ keycode: UiohookKey.F8 })
expect(triggered).toHaveLength(1)
expect(triggered[0]).toMatchObject({ actionId: 'dictation', type: 'pressed' })
const lockCall = vi
.mocked(powerMonitor.on)
.mock.calls.find(([event]) => (event as string) === 'lock-screen')
expect(lockCall).toBeDefined()
const lockHandler = lockCall?.[1] as (() => void) | undefined
lockHandler?.()
expect(triggered).toHaveLength(2)
expect(triggered[1]).toMatchObject({ actionId: 'dictation', type: 'released' })
})
})
describe('mouse button binding rules (MB1 rejection, MB2/MB3 modifier requirement, MB4/MB5 free binding)', () => {
it('rejects MB1 (Left click) both with and without modifiers in validation and IPC setBindings', async () => {
expect(validateBinding(mb(MouseButton.Left))).toEqual({
valid: false,
reason: 'device-disabled',
reasonKey: 'keybinding.disabled.mouseLeft',
warningKey: null,
})
expect(validateBinding(mb(MouseButton.Left, { ctrl: true, alt: true }))).toEqual({
valid: false,
reason: 'device-disabled',
reasonKey: 'keybinding.disabled.mouseLeft',
warningKey: null,
})
const handlers = new Map<string, (...args: unknown[]) => unknown>()
vi.mocked(ipcMain.handle).mockImplementation((channel, listener) => {
handlers.set(channel, listener as (...args: unknown[]) => unknown)
})
registerKeyBindingHandlers()
const setBindings = handlers.get(IPC_CHANNELS.KEYBINDING.SET_BINDINGS)!
const res = (await setBindings({}, {
actionId: 'dictation',
bindings: [mb(MouseButton.Left, { ctrl: true })],
})) as { success: boolean; error?: { details?: { reason?: string } } }
expect(res.success).toBe(false)
expect(res.error?.details?.reason).toBe('device-disabled')
})
it('requires a modifier for MB2 (Right) and MB3 (Middle), and triggers only when modifier is held', () => {
expect(validateBinding(mb(MouseButton.Right))).toMatchObject({
valid: false,
reason: 'modifier-required',
reasonKey: 'keybinding.reject.modifierRequired',
})
expect(validateBinding(mb(MouseButton.Middle))).toMatchObject({
valid: false,
reason: 'modifier-required',
reasonKey: 'keybinding.reject.modifierRequired',
})
expect(validateBinding(mb(MouseButton.Right, { ctrl: true }))).toMatchObject({
valid: true,
reason: null,
warningKey: 'keybinding.warning.mousePassthrough',
})
expect(validateBinding(mb(MouseButton.Middle, { alt: true }))).toMatchObject({
valid: true,
reason: null,
warningKey: 'keybinding.warning.mousePassthrough',
})
const map = createDefaultBindingMap()
map.command = [mb(MouseButton.Right, { ctrl: true })]
map.caption = [mb(MouseButton.Middle, { alt: true })]
saveKeyBindings(map)
const service = getKeyBindingService()
const triggered: KeyBindingTriggerPayload[] = []
service.on('triggered', (payload) => triggered.push(payload))
service.loadFromConfig()
service.start()
// Unmodified MB2 / MB3 must not trigger
hook.mousedown({ button: MouseButton.Right })
hook.mouseup({ button: MouseButton.Right })
hook.mousedown({ button: MouseButton.Middle })
hook.mouseup({ button: MouseButton.Middle })
expect(triggered).toHaveLength(0)
// Ctrl+MB2 and Alt+MB3 trigger their respective actions
hook.mousedown({ button: MouseButton.Right, ctrlKey: true })
hook.mouseup({ button: MouseButton.Right, ctrlKey: true })
hook.mousedown({ button: MouseButton.Middle, altKey: true })
hook.mouseup({ button: MouseButton.Middle, altKey: true })
expect(
triggered.filter((t) => t.type === 'pressed').map((t) => t.actionId),
).toEqual(['command', 'caption'])
})
it('allows free (unmodified) binding for MB4 (Back) and MB5 (Forward) and handles constituent mouseup release', () => {
expect(validateBinding(mb(MouseButton.Back))).toMatchObject({
valid: true,
reason: null,
warningKey: 'keybinding.warning.mousePassthrough',
})
expect(validateBinding(mb(MouseButton.Forward))).toMatchObject({
valid: true,
reason: null,
warningKey: 'keybinding.warning.mousePassthrough',
})
const map = createDefaultBindingMap()
map.dictation = [mb(MouseButton.Back)]
map['hands-free'] = []
map.command = [mb(MouseButton.Forward)]
saveKeyBindings(map)
const service = getKeyBindingService()
const triggered: KeyBindingTriggerPayload[] = []
service.on('triggered', (payload) => triggered.push(payload))
service.loadFromConfig()
service.start()
// Press MB4 unmodified -> hold starts; release MB4 while Alt is held -> constituent button still releases hold!
hook.mousedown({ button: MouseButton.Back })
hook.mouseup({ button: MouseButton.Back, altKey: true })
// Press MB5 unmodified -> triggers command
hook.mousedown({ button: MouseButton.Forward })
hook.mouseup({ button: MouseButton.Forward })
expect(triggered).toEqual([
expect.objectContaining({ actionId: 'dictation', type: 'pressed', isDoublePress: false }),
expect.objectContaining({ actionId: 'dictation', type: 'released', isDoublePress: false }),
expect.objectContaining({ actionId: 'command', type: 'pressed', isDoublePress: false }),
expect.objectContaining({ actionId: 'command', type: 'released', isDoublePress: false }),
])
})
})
describe('hold-to-talk vs double-press hands-free on shared binding', () => {
it('distinguishes single hold (dictation) from rapid double-press (hands-free) on the same key', () => {
const sharedBinding = kb(VK_F8)
const map = createDefaultBindingMap()
map.dictation = [sharedBinding]
map['hands-free'] = [sharedBinding]
saveKeyBindings(map)
const service = getKeyBindingService()
const triggered: KeyBindingTriggerPayload[] = []
service.on('triggered', (payload) => triggered.push(payload))
service.loadFromConfig()
service.start()
let now = 1_000
const nowSpy = vi.spyOn(Date, 'now').mockImplementation(() => now)
try {
// 1. Single press & hold (>400ms gap afterwards)
hook.keydown({ keycode: UiohookKey.F8, time: now })
now += 600
hook.keyup({ keycode: UiohookKey.F8, time: now })
expect(triggered).toEqual([
expect.objectContaining({ actionId: 'dictation', type: 'pressed', isDoublePress: false }),
expect.objectContaining({ actionId: 'dictation', type: 'released', isDoublePress: false }),
])
triggered.length = 0
// 2. Wait past double-press window, then double-press within 150ms
now += 1_000
hook.keydown({ keycode: UiohookKey.F8, time: now })
now += 80
hook.keyup({ keycode: UiohookKey.F8, time: now })
now += 100
hook.keydown({ keycode: UiohookKey.F8, time: now })
now += 80
hook.keyup({ keycode: UiohookKey.F8, time: now })
expect(triggered).toEqual([
expect.objectContaining({ actionId: 'dictation', type: 'pressed', isDoublePress: false }),
expect.objectContaining({ actionId: 'dictation', type: 'released', isDoublePress: false }),
expect.objectContaining({ actionId: 'hands-free', type: 'pressed', isDoublePress: true }),
expect.objectContaining({ actionId: 'hands-free', type: 'released', isDoublePress: true }),
])
} finally {
nowSpy.mockRestore()
}
})
})
describe('multiple bindings per action', () => {
it('triggers the same action from multiple distinct keyboard and mouse bindings independently', () => {
const map = createDefaultBindingMap()
map.dictation = [kb(VK_F8), mb(MouseButton.Back)]
map['hands-free'] = []
saveKeyBindings(map)
const service = getKeyBindingService()
const triggered: KeyBindingTriggerPayload[] = []
service.on('triggered', (payload) => triggered.push(payload))
service.loadFromConfig()
service.start()
hook.keydown({ keycode: UiohookKey.F8 })
hook.keyup({ keycode: UiohookKey.F8 })
hook.mousedown({ button: MouseButton.Back })
hook.mouseup({ button: MouseButton.Back })
expect(triggered).toEqual([
expect.objectContaining({
actionId: 'dictation',
type: 'pressed',
binding: expect.objectContaining({ device: 'keyboard', code: VK_F8 }),
}),
expect.objectContaining({
actionId: 'dictation',
type: 'released',
binding: expect.objectContaining({ device: 'keyboard', code: VK_F8 }),
}),
expect.objectContaining({
actionId: 'dictation',
type: 'pressed',
binding: expect.objectContaining({ device: 'mouse', code: MouseButton.Back }),
}),
expect.objectContaining({
actionId: 'dictation',
type: 'released',
binding: expect.objectContaining({ device: 'mouse', code: MouseButton.Back }),
}),
])
})
})
describe('suggestion capture accelerator registration & unregistration', () => {
it('registers suggestion accelerators only while suggestion capture is active and suggestionEnabled is true', () => {
const service = getKeyBindingService()
service.loadFromConfig()
service.start()
// On Windows/Linux, no globalShortcut is registered when suggestion overlay is inactive
vi.mocked(globalShortcut.register).mockClear()
vi.mocked(globalShortcut.unregister).mockClear()
service.setSuggestionCaptureActive(true)
const registeredWhenActive = vi
.mocked(globalShortcut.register)
.mock.calls.map(([accelerator]) => accelerator)
expect(registeredWhenActive).toEqual(
expect.arrayContaining([
'Control+Alt+Return',
'Control+Alt+Space',
'Control+Alt+Down',
'Control+Alt+Up',
'Control+Alt+Backspace',
]),
)
// Deactivating suggestion capture unregisters all captured accelerators
service.setSuggestionCaptureActive(false)
const unregisteredWhenInactive = vi
.mocked(globalShortcut.unregister)
.mock.calls.map(([accelerator]) => accelerator)
expect(unregisteredWhenInactive).toEqual(
expect.arrayContaining([
'Control+Alt+Return',
'Control+Alt+Space',
'Control+Alt+Down',
'Control+Alt+Up',
'Control+Alt+Backspace',
]),
)
})
it('releases captured accelerators when suggestionEnabled is turned off and re-registers when turned back on', () => {
const service = getKeyBindingService()
service.loadFromConfig()
service.start()
service.setSuggestionCaptureActive(true)
vi.mocked(globalShortcut.register).mockClear()
vi.mocked(globalShortcut.unregister).mockClear()
// Turning off suggestionEnabled releases captured shortcuts immediately
configSet('suggestionEnabled', false)
expect(vi.mocked(globalShortcut.unregister)).toHaveBeenCalledWith('Control+Alt+Return')
vi.mocked(globalShortcut.register).mockClear()
// Turning suggestionEnabled back on while capture is still wanted re-registers them
configSet('suggestionEnabled', true)
expect(vi.mocked(globalShortcut.register)).toHaveBeenCalledWith(
'Control+Alt+Return',
expect.any(Function),
)
})
})
})

View file

@ -48,11 +48,19 @@ function typingContext(overrides: Partial<TypingContext> = {}): TypingContext {
} }
function deps(overrides: Partial<TypoCorrectionDeps> = {}) { function deps(overrides: Partial<TypoCorrectionDeps> = {}) {
const state = { lastKeyAt: 1000 } const state = { lastKeyAt: 1000, inputRevision: 1 }
const replaceBeforeCaret = vi.fn(async () => true) const replaceBeforeCaret = vi.fn(async (_count: number, _text: string, _options?: { commitComposition?: boolean }) => true)
const base: TypoCorrectionDeps = { const base: TypoCorrectionDeps = {
replaceBeforeCaret, replaceBeforeCaret: async (count, text, options) => {
if (options?.canApply && !options.canApply()) return false
options?.beforeApply?.()
return options?.commitComposition
? replaceBeforeCaret(count, text, { commitComposition: true })
: replaceBeforeCaret(count, text)
},
lastKeyAt: () => state.lastKeyAt, lastKeyAt: () => state.lastKeyAt,
inputRevision: () => state.inputRevision,
nativeInputTick: () => 10,
expectProgrammaticKeys: vi.fn(), expectProgrammaticKeys: vi.fn(),
expectProgrammaticInsert: vi.fn(() => () => undefined), expectProgrammaticInsert: vi.fn(() => () => undefined),
foregroundHandle: () => 7, foregroundHandle: () => 7,
@ -216,6 +224,48 @@ describe('TypoCorrectionService', () => {
expect(fake.replaceBeforeCaret).not.toHaveBeenCalled() expect(fake.replaceBeforeCaret).not.toHaveBeenCalled()
}) })
it('같은 밀리초의 입력/클릭도 대기한 교정의 삭제 직전에 취소한다', async () => {
let ready!: () => void
const fake = deps({
replaceBeforeCaret: async (_count, _text, options) => {
await new Promise<void>((resolve) => { ready = resolve })
if (options?.canApply && !options.canApply()) return false
options?.beforeApply?.()
return true
}
})
const service = new TypoCorrectionService(fake.deps)
const corrected = vi.fn()
service.on('corrected', corrected)
expect(service.handleTypingContext(typingContext({ inputRevision: 1 }))).toBe('correcting')
expect(fake.deps.expectProgrammaticKeys).not.toHaveBeenCalled()
expect(fake.deps.expectProgrammaticInsert).not.toHaveBeenCalled()
fake.state.inputRevision += 1 // lastKeyAt is intentionally unchanged
ready()
await flush()
expect(corrected).not.toHaveBeenCalled()
expect(fake.deps.expectProgrammaticInsert).not.toHaveBeenCalled()
expect(fake.deps.expectProgrammaticKeys).toHaveBeenLastCalledWith(0)
})
it('JS 훅 도착 전 OS 입력이 바뀌었거나 조회가 불가능하면 자동 교정을 취소한다', async () => {
for (const tick of [11, null]) {
const fake = deps({ nativeInputTick: () => tick })
const service = new TypoCorrectionService(fake.deps)
service.handleTypingContext(typingContext({ nativeInputTick: 10 }))
await flush()
expect(fake.replaceBeforeCaret).not.toHaveBeenCalled()
}
})
it('포그라운드 창 확인이 실패해도 이전 창에 있다고 가정하지 않는다', async () => {
const fake = deps({ foregroundHandle: () => null })
const service = new TypoCorrectionService(fake.deps)
service.handleTypingContext(typingContext())
await flush()
expect(fake.replaceBeforeCaret).not.toHaveBeenCalled()
})
it('같은 구간은 두 번 검사하지 않는다', async () => { it('같은 구간은 두 번 검사하지 않는다', async () => {
const fake = deps({ warmModel: () => 'gemma' }) const fake = deps({ warmModel: () => 'gemma' })
const service = new TypoCorrectionService(fake.deps) const service = new TypoCorrectionService(fake.deps)
@ -262,6 +312,41 @@ describe('TypoCorrectionService', () => {
expect(fake.deps.generate).not.toHaveBeenCalled() expect(fake.deps.generate).not.toHaveBeenCalled()
}) })
it('콜드 모델이거나 유휴 스냅샷이 와도 커서 끝에서 조합 중인 한글 초성(안ㄴ·안녕ㅎ·오늘 ㅇ)을 지워 글자를 삼키지 않는다', async () => {
const fake = deps({ warmModel: () => null })
const service = new TypoCorrectionService(fake.deps)
for (const prefix of ['안ㄴ', '안녕ㅎ', '안녕하ㅅ', '한ㄱ', '글ㅈ', '오늘 ㅇ', '아직 ㄴ']) {
expect(
service.handleTypingContext(
typingContext({
prefix,
isComposing: false,
idleMs: 800,
appName: 'chrome.exe'
})
),
prefix
).toBe('pass')
}
await flush()
expect(fake.replaceBeforeCaret).not.toHaveBeenCalled()
// 반면 어절이 공백으로 끝난 뒤 남은 내부 낱자 잡음("그ㅓ런건 ")은 콜드 모델에서도 즉시 정리한다
expect(
service.handleTypingContext(
typingContext({
prefix: '그ㅓ런건 ',
isComposing: false,
idleMs: 800,
appName: 'chrome.exe'
})
)
).toBe('correcting')
await flush()
expect(fake.replaceBeforeCaret).toHaveBeenCalledWith('그ㅓ런건 '.length, '그런건 ')
})
it('검사 중 접두가 바뀌면 검사를 버리고 새 문맥은 그대로 넘긴다', async () => { it('검사 중 접두가 바뀌면 검사를 버리고 새 문맥은 그대로 넘긴다', async () => {
let release: (() => void) | null = null let release: (() => void) | null = null
const fake = deps({ const fake = deps({

View file

@ -1,6 +1,6 @@
import { beforeEach, describe, expect, it, vi } from 'vitest' import { beforeEach, describe, expect, it, vi } from 'vitest'
import { ErrorCode } from '@d3ro/core/errors' import { ErrorCode } from '@d3ro/core/errors'
import type { History, MeetingSessionRow } from '../../../src/main/db/schema' import type { History, MeetingMemoRow, MeetingSessionRow } from '../../../src/main/db/schema'
interface MockBuilderOptions { interface MockBuilderOptions {
get?: unknown get?: unknown
@ -182,4 +182,48 @@ describe('UnifiedSearchService', () => {
expect.objectContaining({ code: ErrorCode.DBQueryFailed }), expect.objectContaining({ code: ErrorCode.DBQueryFailed }),
) )
}) })
it('includes meeting_memos and timed transcript segments in meeting search results', async () => {
const memoOnlyMeeting: MeetingSessionRow = {
...meeting,
id: 'meeting-memo-1',
title: '설계 검토 회의',
startedAt: 400,
createdAt: 400,
rawTranscript: '[00:10] 아키텍처 개요 설명',
}
const memoRow: MeetingMemoRow = {
id: 'memo-1',
sessionId: 'meeting-memo-1',
content: '마이그레이션 체크리스트 확인 필요',
timestampMs: 75_000,
createdAt: 410,
updatedAt: 410,
}
selectQueue.push(
createMockBuilder({ get: { count: 0 } }),
createMockBuilder({ all: [] }),
createMockBuilder({ get: { count: 0 } }),
createMockBuilder({ all: [] }),
createMockBuilder({ all: [memoRow] }),
createMockBuilder({ all: [memoOnlyMeeting] }),
)
const { getUnifiedSearchService, resetUnifiedSearchServiceForTests } = await import(
'../../../src/main/services/UnifiedSearchService'
)
resetUnifiedSearchServiceForTests()
const response = getUnifiedSearchService().search({ query: '체크리스트', limit: 10 })
expect(response.total).toBe(1)
expect(response.results).toEqual([
expect.objectContaining({
source: 'meeting',
id: 'meeting-memo-1',
title: '설계 검토 회의',
matchedField: 'content',
excerpt: '[01:15] 마이그레이션 체크리스트 확인 필요',
}),
])
})
}) })

View file

@ -380,6 +380,29 @@ describe('VoiceModeService', () => {
expect(action).toBe('custom') expect(action).toBe('custom')
expect(systemPrompt).toBeUndefined() expect(systemPrompt).toBeUndefined()
}) })
it('복수 지시문 파이프라인(정리 → 격식체 변환)이 설정되면 단계별로 합성된 시스템 프롬프트를 전달한다', async () => {
registerInstruction({
id: 'builtin-clean-speech',
name: '구어·추임새·중복 정리',
prompt: '추임새와 말바꾸기, 중복을 제거하세요.',
})
registerInstruction({
id: 'builtin-formal',
name: '격식체 변환',
prompt: '정중한 비즈니스 존댓말(-습니다/-합니다)로 변환하세요.',
})
config.values.defaultLLMAction = 'custom'
config.values.activeInstructionId = 'builtin-clean-speech,builtin-formal'
await runSession()
const [text, action, , systemPrompt] = mockLLM.processText.mock.calls[0]
expect(text).toBe(TRANSCRIPT)
expect(action).toBe('custom')
expect(systemPrompt).toContain('[1단계: 구어·추임새·중복 정리]')
expect(systemPrompt).toContain('[2단계: 격식체 변환]')
})
}) })
// ── 두 번째 진입점: 음성 단축키 ──────────────────────── // ── 두 번째 진입점: 음성 단축키 ────────────────────────

View file

@ -0,0 +1,61 @@
// tests/main/services/i18n-locale-parity.test.ts
// GAP-I18N-01 / GAP-UX-07 / GAP-LLM-01 회귀 방지 테스트:
// 12개 지원 로케일 파일의 키 집합이 마스터(ko.json)와 100% 일치하는지 검증한다.
import fs from 'node:fs'
import path from 'node:path'
import { describe, it, expect } from 'vitest'
import { LOCALE_META } from '@d3ro/i18n'
const LOCALES_DIR = path.resolve(__dirname, '../../../../../packages/i18n/src/locales')
describe('i18n 12개 로케일 키 정합성 (GAP-I18N-01 / GAP-UX-07 / GAP-LLM-01)', () => {
const ko = JSON.parse(fs.readFileSync(path.join(LOCALES_DIR, 'ko.json'), 'utf8')) as Record<string, string>
const en = JSON.parse(fs.readFileSync(path.join(LOCALES_DIR, 'en.json'), 'utf8')) as Record<string, string>
const masterKeys = Object.keys(ko)
it('마스터(ko.json)와 영어(en.json)의 키 집합이 정확히 일치한다', () => {
const missingInEn = masterKeys.filter((k) => !(k in en))
const extraInEn = Object.keys(en).filter((k) => !(k in ko))
expect(missingInEn).toEqual([])
expect(extraInEn).toEqual([])
})
it.each(LOCALE_META.map((m) => m.code))(
"로케일 '%s'가 마스터(ko.json)의 모든 키를 빠짐없이 포함한다",
(localeCode) => {
const filePath = path.join(LOCALES_DIR, `${localeCode}.json`)
const data = JSON.parse(fs.readFileSync(filePath, 'utf8')) as Record<string, string>
const missing = masterKeys.filter((k) => !(k in data) || typeof data[k] !== 'string' || data[k].length === 0)
expect(missing).toEqual([])
},
)
it('온보딩 LLM 모델 크기 안내가 기본 모델(gemma4:e4b, 4.0GB)과 일치한다 (GAP-UX-07)', () => {
expect(ko['onboarding.llmModelSize']).toContain('4.0GB')
expect(en['onboarding.llmModelSize']).toContain('4.0GB')
})
it('번역 대상 언어 설정 키가 정의되어 있다 (GAP-LLM-01)', () => {
const requiredKeys = [
'settings.targetLanguage',
'settings.targetLanguage.desc',
'settings.targetLanguage.en',
'settings.targetLanguage.ko',
'settings.targetLanguage.ja',
'settings.targetLanguage.zhCN',
'settings.targetLanguage.zhTW',
'settings.targetLanguage.es',
'settings.targetLanguage.fr',
'settings.targetLanguage.de',
'settings.targetLanguage.pt',
'settings.targetLanguage.vi',
'settings.targetLanguage.id',
'settings.targetLanguage.ar',
]
for (const key of requiredKeys) {
expect(ko[key]).toBeTruthy()
expect(en[key]).toBeTruthy()
}
})
})

View file

@ -126,12 +126,13 @@ describe('classifyKeyStroke', () => {
}) })
describe('텍스트 지표', () => { describe('텍스트 지표', () => {
it('단어 수 — 공백 분리 토큰 중 문자/숫자가 있는 것만', () => { it('단어 수 — 공백 분리 토큰 중 문자/숫자가 있는 것만 세며, 비공백 CJK 문장도 분할 집계한다', () => {
expect(countWords('')).toBe(0) expect(countWords('')).toBe(0)
expect(countWords('hello world')).toBe(2) expect(countWords('hello world')).toBe(2)
expect(countWords('안녕하세요 오늘 날씨')).toBe(3) expect(countWords('안녕하세요 오늘 날씨')).toBe(3)
expect(countWords(' , . ! ')).toBe(0) expect(countWords(' , . ! ')).toBe(0)
expect(countWords('v1.2 배포 준비')).toBe(3) expect(countWords('v1.2 배포 준비')).toBe(3)
expect(countWords('今天开会讨论了三件事')).toBeGreaterThanOrEqual(4)
}) })
it('문장 수 — 종결 부호와 개행', () => { it('문장 수 — 종결 부호와 개행', () => {

View file

@ -27,6 +27,7 @@ vi.mock('../../../src/main/services/UiaContextService', () => ({
}) })
})) }))
vi.mock('../../../src/main/utils/win32-foreground', () => ({ getForegroundWindowInfo: () => null })) vi.mock('../../../src/main/utils/win32-foreground', () => ({ getForegroundWindowInfo: () => null }))
vi.mock('../../../src/main/utils/win32-input-activity', () => ({ getLastNativeInputTick: () => 123 }))
import { import {
getInputTelemetryService, getInputTelemetryService,

View file

@ -10,12 +10,13 @@ vi.mock('../../../src/main/services/LoggerService', () => ({
getLogger: () => ({ debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() }) getLogger: () => ({ debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() })
})) }))
vi.mock('../../../src/main/services/global-input-hook', () => ({ acquireGlobalInputHook: () => () => undefined })) vi.mock('../../../src/main/services/global-input-hook', () => ({ acquireGlobalInputHook: () => () => undefined }))
// 매핑 없는 키코드(0) = IME 처리 키 // 0은 합성 유니코드 키다. IME는 별도의 변환표에 없는 코드를 쓴다.
vi.mock('../../../src/main/services/KeyBindingService', () => ({ vi.mock('../../../src/main/services/KeyBindingService', () => ({
uiohookCodeToVk: (code: number) => (code === 0 ? null : 0x41) uiohookCodeToVk: (code: number) => (code === 0xffff ? null : 0x41)
})) }))
vi.mock('../../../src/main/services/UiaContextService', () => ({ getUiaContextService: () => ({}) })) vi.mock('../../../src/main/services/UiaContextService', () => ({ getUiaContextService: () => ({}) }))
vi.mock('../../../src/main/utils/win32-foreground', () => ({ getForegroundWindowInfo: () => null })) vi.mock('../../../src/main/utils/win32-foreground', () => ({ getForegroundWindowInfo: () => null }))
vi.mock('../../../src/main/utils/win32-input-activity', () => ({ getLastNativeInputTick: () => 123 }))
import { import {
getInputTelemetryService, getInputTelemetryService,
@ -37,13 +38,19 @@ describe('IME 글자 키', () => {
it('변환표에 없는 키(IME 처리 키)를 수정자 없이 누르면 타이핑으로 본다', () => { it('변환표에 없는 키(IME 처리 키)를 수정자 없이 누르면 타이핑으로 본다', () => {
const service = getInputTelemetryService() as unknown as Internal const service = getInputTelemetryService() as unknown as Internal
expect(service._lastTypedAt).toBe(0) expect(service._lastTypedAt).toBe(0)
service._handleKeyDown(key(0)) service._handleKeyDown(key(0xffff))
expect(service._lastTypedAt).toBeGreaterThan(0) expect(service._lastTypedAt).toBeGreaterThan(0)
}) })
it('Ctrl/Alt 와 함께면 단축키다 — 타이핑이 아니다', () => { it('Ctrl/Alt 와 함께면 단축키다 — 타이핑이 아니다', () => {
const service = getInputTelemetryService() as unknown as Internal const service = getInputTelemetryService() as unknown as Internal
service._handleKeyDown(key(0, { ctrlKey: true })) service._handleKeyDown(key(0xffff, { ctrlKey: true }))
expect(service._lastTypedAt).toBe(0)
})
it('합성 유니코드 패킷은 사용자 타이핑으로 집계하지 않는다', () => {
const service = getInputTelemetryService() as unknown as Internal
service._handleKeyDown(key(0))
expect(service._lastTypedAt).toBe(0) expect(service._lastTypedAt).toBe(0)
}) })
}) })

View file

@ -0,0 +1,216 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import type { FocusSnapshot } from '@d3ro/core/input-intelligence'
import type { ForegroundWindowInfo } from '../../../src/main/utils/win32-foreground'
const mocks = vi.hoisted(() => ({
snapshot: vi.fn<() => Promise<FocusSnapshot>>(),
foreground: vi.fn<() => ForegroundWindowInfo | null>(),
nativeInputTick: vi.fn<() => number | null>()
}))
vi.mock('electron', () => ({ screen: { getPrimaryDisplay: () => ({ scaleFactor: 1 }) } }))
vi.mock('uiohook-napi', () => ({ uIOhook: { on: vi.fn(), removeListener: vi.fn() } }))
vi.mock('../../../src/main/db', () => ({ getDatabase: vi.fn() }))
vi.mock('../../../src/main/services/ConfigService', () => ({
configGet: (key: string) => (key === 'inputExcludedApps' ? [] : undefined),
configSet: vi.fn()
}))
vi.mock('../../../src/main/services/LoggerService', () => ({
getLogger: () => ({ debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() })
}))
vi.mock('../../../src/main/services/global-input-hook', () => ({ acquireGlobalInputHook: () => () => undefined }))
vi.mock('../../../src/main/services/KeyBindingService', () => ({ uiohookCodeToVk: (code: number) => code }))
vi.mock('../../../src/main/services/UiaContextService', () => ({
getUiaContextService: () => ({
getSnapshot: mocks.snapshot,
isAvailable: () => true,
lastReason: null,
lastSuccessAt: 0
})
}))
vi.mock('../../../src/main/utils/win32-foreground', () => ({
getForegroundWindowInfo: mocks.foreground,
isForegroundKoreanIme: () => false
}))
vi.mock('../../../src/main/utils/win32-input-activity', () => ({ getLastNativeInputTick: mocks.nativeInputTick }))
import {
getInputTelemetryService,
resetInputTelemetryServiceForTests,
type TypingContext
} from '../../../src/main/services/InputTelemetryService'
interface Internal {
_running: boolean
_lastKeyAt: number
_lastTypedAt: number
_lastFocusKey: string
_textAtFocus: string
_lastContext: TypingContext | null
_foreground: { appName: string | null; windowTitle: string | null; hwnd: number | null }
_captureTextSnapshot(): Promise<TypingContext | null>
_handleKeyDown(event: { keycode: number }): void
_handleMouseDown(event: { x: number; y: number; button: number }): void
_handleMouseUp(event: { x: number; y: number }): void
_handleWheel(event: { rotation: number }): void
}
function snapshot(overrides: Partial<FocusSnapshot> = {}): FocusSnapshot {
return {
available: true,
isPassword: false,
isEditable: true,
isComposing: false,
hasSelection: false,
controlType: 'Edit',
controlName: '메시지',
textSource: 'value',
text: '안녕하세요',
caretOffset: 5,
caretRect: null,
elementRect: null,
windowTitle: '채팅',
appName: 'chrome.exe',
processId: 1,
capturedAt: Date.now(),
...overrides
}
}
describe('입력 중 늦게 도착하는 UIA 스냅샷', () => {
let service: ReturnType<typeof getInputTelemetryService>
let internal: Internal
let publish: ReturnType<typeof vi.fn>
beforeEach(() => {
resetInputTelemetryServiceForTests()
vi.useFakeTimers()
vi.setSystemTime(10_000)
mocks.foreground.mockReset().mockReturnValue(null)
mocks.nativeInputTick.mockReset().mockReturnValue(123)
mocks.snapshot.mockReset()
service = getInputTelemetryService()
internal = service as unknown as Internal
internal._running = true
internal._foreground = { appName: 'chrome.exe', windowTitle: '채팅', hwnd: 42 }
internal._lastKeyAt = Date.now()
internal._lastTypedAt = Date.now()
internal._textAtFocus = '기존 기준선'
publish = vi.fn()
service.on('typed-context', publish)
})
afterEach(() => {
service.dispose()
vi.restoreAllMocks()
vi.useRealTimers()
})
function pending() {
let resolve!: (value: FocusSnapshot) => void
mocks.snapshot.mockImplementationOnce(() => new Promise((done) => { resolve = done }))
const request = internal._captureTextSnapshot()
return { request, resolve }
}
it('같은 밀리초에 친 새 글자도 감지해 오래된 텍스트를 발행하거나 기준선으로 저장하지 않는다', async () => {
const delayed = pending()
const at = internal._lastKeyAt
internal._handleKeyDown({ keycode: 0x41 })
expect(internal._lastKeyAt).toBe(at)
delayed.resolve(snapshot())
expect(await delayed.request).toBeNull()
expect(publish).not.toHaveBeenCalled()
expect(internal._lastContext).toBeNull()
expect(internal._textAtFocus).toBe('기존 기준선')
mocks.snapshot.mockResolvedValueOnce(snapshot({ text: '안녕하세요 추가', caretOffset: 8 }))
expect((await internal._captureTextSnapshot())?.prefix).toBe('안녕하세요 추가')
expect(publish).toHaveBeenCalledTimes(1)
})
it.each([
['마우스 클릭', (value: Internal) => value._handleMouseDown({ x: 2, y: 3, button: 1 })],
['선택 드래그 끝', (value: Internal) => value._handleMouseUp({ x: 2, y: 3 })],
['스크롤', (value: Internal) => value._handleWheel({ rotation: 1 })],
['합성 유니코드 키', (value: Internal) => value._handleKeyDown({ keycode: 0 })]
] as const)('%s 중 도착한 응답은 버린다', async (_name, change) => {
const delayed = pending()
change(internal)
delayed.resolve(snapshot())
expect(await delayed.request).toBeNull()
expect(publish).not.toHaveBeenCalled()
})
it('통계에서 제외한 프로그램 백스페이스도 스냅샷을 무효화한다', async () => {
service.expectProgrammaticKeys(1)
const delayed = pending()
internal._handleKeyDown({ keycode: 0x08 })
delayed.resolve(snapshot())
expect(await delayed.request).toBeNull()
expect(publish).not.toHaveBeenCalled()
})
it('키 이벤트 없이 포그라운드 창이 바뀌어도 이전 창의 텍스트를 발행하지 않는다', async () => {
const delayed = pending()
mocks.foreground.mockReturnValue({
hwnd: 99, title: '다른 창', appName: 'notes.exe', processId: 2, appPath: null, bounds: null
})
delayed.resolve(snapshot())
expect(await delayed.request).toBeNull()
expect(publish).not.toHaveBeenCalled()
})
it('중지 후 재시작해도 이전 세션의 응답을 적용하지 않는다', async () => {
const delayed = pending()
service.stop()
service.start()
delayed.resolve(snapshot())
expect(await delayed.request).toBeNull()
expect(publish).not.toHaveBeenCalled()
})
it('마지막 키보다 먼저 캡처된 응답은 버린다', async () => {
mocks.snapshot.mockResolvedValueOnce(snapshot({ capturedAt: Date.now() - 1 }))
expect(await internal._captureTextSnapshot()).toBeNull()
expect(publish).not.toHaveBeenCalled()
})
it('메인 스레드에 키 콜백이 아직 도착하지 않아도 네이티브 입력 변화로 취소한다', async () => {
const revision = service.inputRevision
const delayed = pending()
mocks.nativeInputTick.mockReturnValue(124)
delayed.resolve(snapshot())
expect(service.inputRevision).toBe(revision)
expect(await delayed.request).toBeNull()
expect(publish).not.toHaveBeenCalled()
})
it('네이티브 tick이 감소하거나 래핑되어도 변화로 처리한다', async () => {
mocks.nativeInputTick.mockReturnValue(0xffffffff)
const delayed = pending()
mocks.nativeInputTick.mockReturnValue(0)
delayed.resolve(snapshot())
expect(await delayed.request).toBeNull()
expect(publish).not.toHaveBeenCalled()
})
it('Windows에서 네이티브 상태를 못 읽으면 문맥에 null을 명시해 자동 교정이 거절할 수 있게 한다', async () => {
vi.spyOn(process, 'platform', 'get').mockReturnValue('win32')
mocks.nativeInputTick.mockReturnValue(null)
mocks.snapshot.mockResolvedValueOnce(snapshot())
expect((await internal._captureTextSnapshot())?.nativeInputTick).toBeNull()
})
it('겹친 타이머들은 UIA 조회와 문맥 발행을 한 번만 한다', async () => {
const delayed = pending()
const duplicate = internal._captureTextSnapshot()
delayed.resolve(snapshot())
const [first, second] = await Promise.all([delayed.request, duplicate])
expect(first).toBe(second)
expect(first?.inputRevision).toBe(service.inputRevision)
expect(mocks.snapshot).toHaveBeenCalledTimes(1)
expect(publish).toHaveBeenCalledTimes(1)
})
})

View file

@ -20,6 +20,8 @@ import {
renderInstructionPrompt, renderInstructionPrompt,
buildInstructionInvocation, buildInstructionInvocation,
resolveSystemPrompt, resolveSystemPrompt,
resolveTargetLanguage,
SUPPORTED_TARGET_LANGUAGES,
buildSuggestionPrompt, buildSuggestionPrompt,
DEFAULT_TARGET_LANGUAGE, DEFAULT_TARGET_LANGUAGE,
BASE_SYSTEM_PROMPTS, BASE_SYSTEM_PROMPTS,
@ -28,6 +30,7 @@ import {
FREE_PROMPT_SYSTEM_PROMPT, FREE_PROMPT_SYSTEM_PROMPT,
} from '../../../src/main/services/llm-prompts' } from '../../../src/main/services/llm-prompts'
import { buildCaptionRefinePrompt, buildTypoCheckPrompt } from '../../../src/main/services/llm-prompts' import { buildCaptionRefinePrompt, buildTypoCheckPrompt } from '../../../src/main/services/llm-prompts'
import * as ConfigServiceModule from '../../../src/main/services/ConfigService'
beforeEach(() => { beforeEach(() => {
vi.clearAllMocks() vi.clearAllMocks()
@ -153,6 +156,23 @@ describe('resolveSystemPrompt', () => {
expect(resolveSystemPrompt('translate')).toContain(`${DEFAULT_TARGET_LANGUAGE}로 번역`) expect(resolveSystemPrompt('translate')).toContain(`${DEFAULT_TARGET_LANGUAGE}로 번역`)
}) })
it('ConfigService에 targetLanguage가 설정되어 있으면 명시 인자 생략 시 설정값을 사용한다', () => {
const spy = vi.spyOn(ConfigServiceModule, 'getConfigService').mockReturnValue({
get: (key: string) => (key === 'targetLanguage' ? 'Japanese' : undefined),
} as never)
try {
expect(resolveTargetLanguage()).toBe('Japanese')
expect(resolveTargetLanguage('Spanish')).toBe('Spanish')
expect(resolveSystemPrompt('translate')).toContain('Japanese로 번역')
expect(
renderInstructionPrompt('{{targetLanguage}}로 번역해줘', { text: '안녕' }),
).toBe('Japanese로 번역해줘')
expect(SUPPORTED_TARGET_LANGUAGES).toContain('Japanese')
} finally {
spy.mockRestore()
}
})
// 수정 대상이 아닌 일반 액션들이 각자의 프롬프트로 해석되는지 잠근다. // 수정 대상이 아닌 일반 액션들이 각자의 프롬프트로 해석되는지 잠근다.
// 이들이 refine으로 조용히 폴백하면 커스텀 경로와 같은 사고가 난다. // 이들이 refine으로 조용히 폴백하면 커스텀 경로와 같은 사고가 난다.
it.each(['refine', 'summarize', 'grammar', 'expand'] as const)( it.each(['refine', 'summarize', 'grammar', 'expand'] as const)(

View file

@ -1,6 +1,8 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { ErrorCode } from '@d3ro/core/errors' import { ErrorCode } from '@d3ro/core/errors'
import { initInMemoryConfig, resetInMemoryConfig } from '../../../src/main/services/ConfigService' import { configSet, initInMemoryConfig, resetInMemoryConfig } from '../../../src/main/services/ConfigService'
import { availableParallelism } from 'node:os'
import { inferenceCpuThreads } from '../../../src/main/utils/inference-cpu-budget'
import { import {
getLocalLLMService, getLocalLLMService,
resetLocalLLMServiceForTests, resetLocalLLMServiceForTests,
@ -44,6 +46,36 @@ describe('LocalLLMService request lifecycle', () => {
vi.useRealTimers() vi.useRealTimers()
}) })
it.each(['http://127.0.0.1:11434', 'http://192.168.1.2:11434'])(
'applies CPU headroom across generate, warm-up streaming and chat only for loopback (%s)', async (serverUrl) => {
configSet('ollamaServerUrl', serverUrl)
const bodies: Array<{ options: { num_thread?: number }; stream: boolean }> = []
vi.stubGlobal('fetch', vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
const body = JSON.parse(String(init?.body)) as (typeof bodies)[number]
bodies.push(body)
if (!body.stream) return completedGenerateResponse()
const frame = String(input).endsWith('/api/chat')
? { message: { content: 'ok' }, done: true }
: { model: 'gemma4:e4b', response: 'ok', done: true }
return new Response(completedStream([JSON.stringify(frame)]), { status: 200 })
}))
const service = getLocalLLMService()
await service.generate('hello')
for await (const token of service.streamGenerate('hi', { maxTokens: 1 })) void token
for await (const token of service.chatStream([{ role: 'user', content: 'hello' }])) void token
expect(bodies).toHaveLength(3)
for (const body of bodies) {
if (serverUrl.includes('127.0.0.1')) {
expect(body.options.num_thread).toBe(inferenceCpuThreads(availableParallelism()))
} else {
expect(body.options).not.toHaveProperty('num_thread')
}
}
}
)
it('sends the bounded default num_predict to chat requests', async () => { it('sends the bounded default num_predict to chat requests', async () => {
const cancel = vi.fn() const cancel = vi.fn()
const fetchMock = vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => { const fetchMock = vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {

View file

@ -0,0 +1,87 @@
import { describe, expect, it, vi } from 'vitest'
import { TextInsertService } from '../../../src/main/services/TextInsertService'
vi.mock('../../../src/main/services/text-insert/electron-clipboard-port', () => ({ electronClipboardPort: {} }))
vi.mock('../../../src/main/services/LoggerService', () => ({
getLogger: () => ({ info: vi.fn(), warn: vi.fn(), error: vi.fn() })
}))
function deferred() {
let resolve!: () => void
const promise = new Promise<void>((done) => { resolve = done })
return { promise, resolve }
}
describe('replacement under delayed input processing', () => {
it('does not delete new typing after waiting behind another insertion', async () => {
const pending = deferred()
const keyboard = {
type: vi.fn(() => pending.promise), paste: vi.fn(), backspace: vi.fn(),
replaceBeforeCaret: vi.fn(async () => true)
}
const service = new TextInsertService({ keyboard })
let revision = 1
const beforeApply = vi.fn()
const first = service.insertText('prior insertion', 'keyboard')
const correction = service.replaceBeforeCaret(3, 'fixed', 'keyboard', {
canApply: () => revision === 1, beforeApply, requireAtomic: true
})
await Promise.resolve()
revision += 1 // physical input or a click while the first insertion is pending
pending.resolve()
await first
expect((await correction).success).toBe(false)
expect(keyboard.replaceBeforeCaret).not.toHaveBeenCalled()
expect(keyboard.backspace).not.toHaveBeenCalled()
expect(beforeApply).not.toHaveBeenCalled()
})
it('revalidates after a slow fallback module load before sending any keys', async () => {
const loading = deferred()
const started = deferred()
const keyboard = {
type: vi.fn(), paste: vi.fn(), backspace: vi.fn(),
preload: vi.fn(() => { started.resolve(); return loading.promise })
}
const service = new TextInsertService({ keyboard })
let current = true
const correction = service.replaceBeforeCaret(3, 'fixed', 'keyboard', { canApply: () => current })
await started.promise
current = false
loading.resolve()
expect((await correction).success).toBe(false)
expect(keyboard.backspace).not.toHaveBeenCalled()
expect(keyboard.type).not.toHaveBeenCalled()
})
it('does not use separate backspaces when automatic atomic replacement is unavailable', async () => {
const keyboard = {
type: vi.fn(), paste: vi.fn(), backspace: vi.fn(),
replaceBeforeCaret: vi.fn(async () => false)
}
const service = new TextInsertService({ keyboard })
expect((await service.replaceBeforeCaret(3, 'fixed', 'keyboard', { requireAtomic: true })).success).toBe(false)
expect(keyboard.backspace).not.toHaveBeenCalled()
expect(keyboard.type).not.toHaveBeenCalled()
})
it('registers synthetic keys only when the valid queued replacement actually runs', async () => {
const pending = deferred()
const order: string[] = []
const keyboard = {
type: vi.fn(() => pending.promise), paste: vi.fn(), backspace: vi.fn(),
replaceBeforeCaret: vi.fn(async () => { order.push('replace'); return true })
}
const service = new TextInsertService({ keyboard })
const first = service.insertText('prior', 'keyboard')
const correction = service.replaceBeforeCaret(3, 'fixed', 'keyboard', {
canApply: () => true, beforeApply: () => { order.push('register') }, requireAtomic: true
})
await Promise.resolve()
expect(order).toEqual([])
pending.resolve()
await first
expect((await correction).success).toBe(true)
expect(order).toEqual(['register', 'replace'])
})
})

View file

@ -0,0 +1,96 @@
import { describe, expect, it, vi } from 'vitest'
import { TextInsertService } from '../../../src/main/services/TextInsertService'
import { TypoCorrectionService } from '../../../src/main/services/TypoCorrectionService'
import type { TypingContext } from '../../../src/main/services/InputTelemetryService'
vi.mock('../../../src/main/services/text-insert/electron-clipboard-port', () => ({ electronClipboardPort: {} }))
vi.mock('../../../src/main/services/ConfigService', () => ({
configGet: (key: string) => key === 'typoAutoCorrectEnabled' ? true :
key === 'typoAutoCorrectUseModel' ? false : [],
configSet: vi.fn()
}))
vi.mock('../../../src/main/services/LoggerService', () => ({
getLogger: () => ({ info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() })
}))
function deferred() {
let resolve!: () => void
const promise = new Promise<void>((done) => { resolve = done })
return { promise, resolve }
}
function fixture() {
const state = { text: '오늘 잘 됬어요 ', lastKeyAt: 1_000, revision: 1, nativeTick: 5, hwnd: 7 }
const prior = deferred()
const replacementDone = deferred()
const keyboard = {
type: async () => prior.promise,
paste: vi.fn(async () => undefined),
backspace: vi.fn(async (count: number) => { state.text = state.text.slice(0, -count) }),
replaceBeforeCaret: vi.fn(async (count: number, text: string) => {
state.text = state.text.slice(0, -count) + text
return true
})
}
const insert = new TextInsertService({ keyboard })
const typo = new TypoCorrectionService({
replaceBeforeCaret: async (count, text, options) => {
try { return (await insert.replaceBeforeCaret(count, text, 'keyboard', options)).success }
finally { replacementDone.resolve() }
},
lastKeyAt: () => state.lastKeyAt,
inputRevision: () => state.revision,
nativeInputTick: () => state.nativeTick,
foregroundHandle: () => state.hwnd,
expectProgrammaticKeys: vi.fn(),
expectProgrammaticInsert: () => () => undefined,
recentTexts: () => [],
warmModel: () => null,
generate: async function* () { yield '없음' }
})
const context: TypingContext = {
prefix: state.text, fullText: state.text, caretOffset: state.text.length,
anchor: null, anchorKind: null, isPassword: false, isEditable: true,
isComposing: false, hasSelection: false, available: true,
appName: 'notepad.exe', windowTitle: 'Fixture', windowHandle: 7,
idleMs: 800, capturedAt: 1_800, inputRevision: 1, nativeInputTick: 5,
editedSinceFocus: true, typedRecently: true, caretReliable: true
}
return { state, prior, replacementDone, keyboard, insert, typo, context }
}
describe('real correction services preserve a text sink across delayed queue interleavings', () => {
it.each(['delivered-key', 'same-millisecond-key', 'native-event-before-js'] as const)(
'preserves the whole next Hangul word when %s arrives while correction waits', async (event) => {
const f = fixture()
const priorInsertion = f.insert.insertText('', 'keyboard')
expect(f.typo.handleTypingContext(f.context)).toBe('correcting')
await Promise.resolve()
const expected = f.state.text + '안녕하세요 '
f.state.text = expected
// Isolate each guard: identical millisecond/native ticks must not hide the
// revision case, and a native event may precede both JS-side counters.
if (event === 'delivered-key') f.state.lastKeyAt += 100
if (event === 'same-millisecond-key') f.state.revision += 1
if (event === 'native-event-before-js') f.state.nativeTick += 1
f.prior.resolve()
await priorInsertion
await f.replacementDone.promise
expect(f.state.text).toBe(expected)
expect(f.keyboard.replaceBeforeCaret).not.toHaveBeenCalled()
f.typo.dispose()
}
)
it('still replaces the intended typo if nothing changed during the same queue wait', async () => {
const f = fixture()
const priorInsertion = f.insert.insertText('', 'keyboard')
expect(f.typo.handleTypingContext(f.context)).toBe('correcting')
f.prior.resolve()
await priorInsertion
await f.replacementDone.promise
expect(f.state.text).toBe('오늘 잘 됐어요 ')
expect(f.keyboard.replaceBeforeCaret).toHaveBeenCalledOnce()
f.typo.dispose()
})
})

View file

@ -76,9 +76,19 @@ describe('제스처 입력 정규화', () => {
expect(resolveGestureMode('command', false)).toBe('dictation') expect(resolveGestureMode('command', false)).toBe('dictation')
}) })
it("'command' 는 dictation 파이프라인 fallback 이라 hold-to-talk 이다", () => { it("'command' 는 바인딩의 holdMode(토글 또는 홀드)를 그대로 따른다", () => {
expect(resolveGestureHoldMode('command', false)).toBe(true) expect(resolveGestureHoldMode('command', false)).toBe(false)
expect(resolveGestureHoldMode('command', true)).toBe(true)
expect(resolveGestureHoldMode('dictation', true)).toBe(true) expect(resolveGestureHoldMode('dictation', true)).toBe(true)
expect(resolveGestureHoldMode('hands-free', false)).toBe(false) expect(resolveGestureHoldMode('hands-free', false)).toBe(false)
}) })
it("holdMode=false 인 'command' 토글은 첫 press 로 시작하고 녹음 중 다음 press 로 정지한다", () => {
const commandTogglePress: VoiceGesture = { type: 'press', mode: 'dictation', holdMode: false }
const commandToggleRelease: VoiceGesture = { type: 'release', mode: 'dictation', holdMode: false }
expect(resolveVoiceIntent(commandTogglePress, 'idle')).toEqual(START_DICTATION)
expect(resolveVoiceIntent(commandToggleRelease, 'recording')).toEqual(IGNORE)
expect(resolveVoiceIntent(commandTogglePress, 'recording')).toEqual(STOP)
expect(resolveVoiceIntent(commandTogglePress, 'processing')).toEqual(IGNORE)
})
}) })

View file

@ -0,0 +1,77 @@
import { createRequire } from 'node:module'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
const nodeRequire = createRequire(import.meta.url)
const koffiPath = nodeRequire.resolve('koffi')
const originalKoffi = nodeRequire.cache[koffiPath]
const nativeRead = vi.fn<(info: Buffer) => boolean>()
const load = vi.fn()
let input: typeof import('../../../src/main/utils/win32-input-activity')
vi.mock('../../../src/main/services/LoggerService', () => ({
getLogger: () => ({ warn: vi.fn() })
}))
beforeEach(async () => {
vi.resetModules()
vi.spyOn(process, 'platform', 'get').mockReturnValue('win32')
nativeRead.mockReset().mockImplementation((info) => {
expect(info.length).toBe(8)
expect(info.readUInt32LE(0)).toBe(8)
info.writeUInt32LE(0xfedcba98, 4)
return true
})
load.mockReset().mockReturnValue({ func: vi.fn(() => nativeRead) })
nodeRequire.cache[koffiPath] = {
id: koffiPath, filename: koffiPath, loaded: true, exports: { load }
} as unknown as NodeModule
input = await import('../../../src/main/utils/win32-input-activity')
})
afterEach(() => {
if (originalKoffi) nodeRequire.cache[koffiPath] = originalKoffi
else delete nodeRequire.cache[koffiPath]
vi.restoreAllMocks()
})
describe('native input activity token', () => {
it('initializes LASTINPUTINFO.cbSize and reads an unsigned DWORD without epoch conversion', () => {
expect(input.getLastNativeInputTick()).toBe(0xfedcba98)
expect(input.getLastNativeInputTick()).toBe(0xfedcba98)
expect(nativeRead).toHaveBeenCalledTimes(2)
expect(load).toHaveBeenCalledTimes(1)
expect(load).toHaveBeenCalledWith('user32.dll')
})
it('preserves zero after tick wraparound as a valid token', () => {
nativeRead.mockImplementation((info) => {
info.writeUInt32LE(0, 4)
return true
})
expect(input.getLastNativeInputTick()).toBe(0)
})
it('returns null on native failure instead of treating zeroed memory as an idle token', () => {
nativeRead.mockReturnValueOnce(false)
expect(input.getLastNativeInputTick()).toBeNull()
expect(input.getLastNativeInputTick()).toBe(0xfedcba98)
})
it('does not load a Windows DLL on other platforms', () => {
vi.spyOn(process, 'platform', 'get').mockReturnValue('linux')
expect(input.getLastNativeInputTick()).toBeNull()
expect(load).not.toHaveBeenCalled()
})
it('fails closed and avoids repeated native loads when koffi is unavailable', () => {
load.mockImplementation(() => { throw new Error('unavailable') })
expect(input.getLastNativeInputTick()).toBeNull()
expect(input.getLastNativeInputTick()).toBeNull()
expect(load).toHaveBeenCalledTimes(1)
})
it('returns null when native invocation throws', () => {
nativeRead.mockImplementation(() => { throw new Error('native failure') })
expect(input.getLastNativeInputTick()).toBeNull()
})
})

View file

@ -0,0 +1,124 @@
import { createRequire } from 'node:module'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { ErrorCode } from '@d3ro/core/errors'
const nodeRequire = createRequire(import.meta.url)
const koffiPath = nodeRequire.resolve('koffi')
const originalKoffi = nodeRequire.cache[koffiPath]
const sendInput = vi.fn<(count: number, buffer: Buffer, size: number) => number>()
let input: typeof import('../../../src/main/utils/win32-unicode-input')
beforeEach(async () => {
vi.resetModules()
vi.spyOn(process, 'platform', 'get').mockReturnValue('win32')
sendInput.mockReset().mockImplementation((count) => count)
// Production loads koffi with CommonJS require; vi.mock cannot intercept it.
// Replace its cache entry before importing so no native library can receive keys.
nodeRequire.cache[koffiPath] = {
id: koffiPath,
filename: koffiPath,
loaded: true,
exports: {
struct: vi.fn((name: string) => name),
union: vi.fn((name: string) => name),
sizeof: vi.fn(() => 40),
offsetof: vi.fn(() => 8),
load: vi.fn(() => ({ func: vi.fn(() => sendInput) }))
}
} as unknown as NodeModule
input = await import('../../../src/main/utils/win32-unicode-input')
})
afterEach(() => {
if (originalKoffi) nodeRequire.cache[koffiPath] = originalKoffi
else delete nodeRequire.cache[koffiPath]
vi.restoreAllMocks()
})
function events(): Array<{ vk: number; scan: number; flags: number }> {
const [count, buffer, size] = sendInput.mock.calls[0]
expect(size).toBe(40)
expect(buffer.length).toBe(count * size)
return Array.from({ length: count }, (_, index) => {
const base = index * size
expect(buffer.readUInt32LE(base)).toBe(1)
return {
vk: buffer.readUInt16LE(base + 8),
scan: buffer.readUInt16LE(base + 10),
flags: buffer.readUInt32LE(base + 12)
}
})
}
describe('Win32 input batches', () => {
it('encodes Hangul and both UTF-16 surrogate units as Unicode down/up pairs', () => {
expect(input.sendWin32UnicodeText('안😀')).toBe(true)
expect(sendInput).toHaveBeenCalledTimes(1)
expect(events()).toEqual([
{ vk: 0, scan: 0xc548, flags: 4 }, { vk: 0, scan: 0xc548, flags: 6 },
{ vk: 0, scan: 0xd83d, flags: 4 }, { vk: 0, scan: 0xd83d, flags: 6 },
{ vk: 0, scan: 0xde00, flags: 4 }, { vk: 0, scan: 0xde00, flags: 6 }
])
})
it('puts composition commit, requested deletion plus commit space, and replacement in one batch', () => {
expect(input.sendWin32UnicodeReplacement(2, '안', { commitComposition: true })).toBe(true)
expect(sendInput).toHaveBeenCalledTimes(1)
expect(events()).toEqual([
{ vk: 0x20, scan: 0, flags: 0 }, { vk: 0x20, scan: 0, flags: 2 },
{ vk: 8, scan: 0, flags: 0 }, { vk: 8, scan: 0, flags: 2 },
{ vk: 8, scan: 0, flags: 0 }, { vk: 8, scan: 0, flags: 2 },
{ vk: 8, scan: 0, flags: 0 }, { vk: 8, scan: 0, flags: 2 },
{ vk: 0, scan: 0xc548, flags: 4 }, { vk: 0, scan: 0xc548, flags: 6 }
])
})
it('permits fallback only when the native call reports no inserted events', () => {
sendInput.mockReturnValue(0)
expect(input.sendWin32UnicodeText('hello')).toBe(false)
expect(input.sendWin32UnicodeReplacement(2, '안')).toBe(false)
})
it.each([1, 2, 4, 5])('rejects a replacement after %i of 6 events instead of replaying deletions', (sent) => {
sendInput.mockReturnValue(sent)
expect(() => input.sendWin32UnicodeReplacement(2, '안')).toThrow(`${sent}/6 events; retry blocked`)
expect(sendInput).toHaveBeenCalledTimes(1)
})
it('rejects partially inserted ordinary text instead of duplicating it', () => {
sendInput.mockReturnValue(2)
expect(() => input.sendWin32UnicodeText('안녕')).toThrow('2/4 events; retry blocked')
expect(sendInput).toHaveBeenCalledTimes(1)
})
it('blocks retry when the native result is unknown', () => {
sendInput.mockImplementation(() => { throw new Error('native failure') })
expect(() => input.sendWin32UnicodeReplacement(2, '안')).toThrow('unknown insertion result')
expect(() => input.sendWin32UnicodeText('안')).toThrow('unknown insertion result')
expect(sendInput).toHaveBeenCalledTimes(2)
})
it('propagates partial insertion through the actual keyboard adapter and service without fallback', async () => {
const { NutKeyboardPort } = await import('../../../src/main/services/text-insert/nut-keyboard-port')
const { TextInsertService } = await import('../../../src/main/services/TextInsertService')
const keyboard = new NutKeyboardPort('win32')
const backspace = vi.spyOn(keyboard, 'backspace')
const type = vi.spyOn(keyboard, 'type')
const service = new TextInsertService({ keyboard, platform: 'win32' })
const completed = vi.fn()
service.on('insert-completed', completed)
sendInput.mockReturnValue(2)
await expect(service.replaceBeforeCaret(2, '안', 'keyboard')).rejects.toMatchObject({
code: ErrorCode.TextInsertKeySimulationFailed
})
expect(sendInput).toHaveBeenCalledTimes(1)
expect(backspace).not.toHaveBeenCalled()
expect(type).not.toHaveBeenCalled()
expect(completed).not.toHaveBeenCalled()
sendInput.mockImplementation((count) => count)
await expect(service.replaceBeforeCaret(2, '안', 'keyboard')).resolves.toMatchObject({ success: true })
expect(completed).toHaveBeenCalledTimes(1)
})
})

View file

@ -0,0 +1,27 @@
import { describe, expect, it } from 'vitest'
import { inferenceCpuThreads, localInferenceCpuOptions } from '../../../src/main/utils/inference-cpu-budget'
describe('local inference scheduling budget', () => {
it.each([[1, 1], [2, 1], [3, 1], [4, 2], [6, 4], [8, 4], [16, 4], [64, 4]])(
'leaves foreground headroom on %i available CPUs (%i workers)', (cpus, expected) => {
expect(inferenceCpuThreads(cpus)).toBe(expected)
}
)
it.each([0, -1, Number.NaN, Number.POSITIVE_INFINITY])('uses one worker for invalid capacity %s', (cpus) => {
expect(inferenceCpuThreads(cpus)).toBe(1)
})
it.each(['http://localhost:11434', 'http://localhost.:11434', 'http://127.0.0.1:11434', 'http://127.0.0.2:11434', 'http://[::1]:11434'])(
'bounds the local engine at %s', (url) => {
expect(localInferenceCpuOptions(url).num_thread).toBeGreaterThanOrEqual(1)
expect(localInferenceCpuOptions(url).num_thread).toBeLessThanOrEqual(4)
}
)
it.each(['https://llm.example.com', 'http://192.168.1.2:11434', 'http://localhost.example.com', 'invalid'])(
'does not infer a remote engine budget from this PC: %s', (url) => {
expect(localInferenceCpuOptions(url)).toEqual({})
}
)
})

View file

@ -32,8 +32,11 @@ import { resetCloudSyncServiceForTests } from '../../src/main/services/CloudSync
import { resetTTSPlaybackServiceForTests } from '../../src/main/services/TTSPlaybackService' import { resetTTSPlaybackServiceForTests } from '../../src/main/services/TTSPlaybackService'
import { resetMeetingSummaryServiceForTests } from '../../src/main/services/MeetingSummaryService' import { resetMeetingSummaryServiceForTests } from '../../src/main/services/MeetingSummaryService'
import { resetLocalLLMServiceForTests } from '../../src/main/services/LocalLLMService' import { resetLocalLLMServiceForTests } from '../../src/main/services/LocalLLMService'
import { resetLocalSTTServiceForTests } from '../../src/main/services/LocalSTTService' import {
import type { IPCResult } from '@d3ro/core/errors' LocalSTTService,
resetLocalSTTServiceForTests,
} from '../../src/main/services/LocalSTTService'
import { D3ROError, ErrorCode, type IPCResult } from '@d3ro/core/errors'
import type { NewHistory } from '../../src/main/db/schema' import type { NewHistory } from '../../src/main/db/schema'
const ipcHandlers = new Map<string, (...args: unknown[]) => unknown>() const ipcHandlers = new Map<string, (...args: unknown[]) => unknown>()
@ -103,6 +106,8 @@ export function resetAllSingletons(): void {
export function useRedHarness(): void { export function useRedHarness(): void {
let testdb: ReturnType<typeof createTestDb> | null = null let testdb: ReturnType<typeof createTestDb> | null = null
let initSpy: ReturnType<typeof vi.spyOn> | null = null
let ensureSidecarSpy: ReturnType<typeof vi.spyOn> | null = null
beforeEach(() => { beforeEach(() => {
testdb = createTestDb() testdb = createTestDb()
@ -110,9 +115,28 @@ export function useRedHarness(): void {
initInMemoryConfig() initInMemoryConfig()
resetAllSingletons() resetAllSingletons()
resetIpcHandlers() resetIpcHandlers()
vi.stubGlobal(
'fetch',
vi.fn(async () => {
throw new TypeError('fetch failed (red harness offline default)')
}),
)
const sidecarDisabledError = (): Promise<never> =>
Promise.reject(
new D3ROError(
ErrorCode.STTSidecarSpawnFailed,
'red harness: real Python sidecar spawn is disabled in usecase tests',
),
)
initSpy = vi.spyOn(LocalSTTService.prototype, 'initialize').mockImplementation(sidecarDisabledError)
ensureSidecarSpy = vi.spyOn(LocalSTTService.prototype, 'ensureSidecar').mockImplementation(sidecarDisabledError)
}) })
afterEach(() => { afterEach(() => {
initSpy?.mockRestore()
ensureSidecarSpy?.mockRestore()
initSpy = null
ensureSidecarSpy = null
resetAllSingletons() resetAllSingletons()
unbindTestDatabase() unbindTestDatabase()
testdb?.close() testdb?.close()

View file

@ -1,7 +1,8 @@
import { beforeEach, describe, expect, it, vi } from 'vitest' import { beforeEach, describe, expect, it, vi } from 'vitest'
import type { AdMediationConfig } from '@d3ro/core/types' import { Feature, type AdMediationConfig } from '@d3ro/core/types'
import { getAdMediationEngine } from '../../src/main/services/ads/AdMediationEngine' import { getAdMediationEngine } from '../../src/main/services/ads/AdMediationEngine'
import { getAdSettlementService } from '../../src/main/services/ads/AdSettlementService' import { getAdSettlementService } from '../../src/main/services/ads/AdSettlementService'
import { getLicenseService } from '../../src/main/services/LicenseService'
import { EthicalAdsAdapter } from '../../src/main/services/ads/EthicalAdsAdapter' import { EthicalAdsAdapter } from '../../src/main/services/ads/EthicalAdsAdapter'
import { CarbonAdsAdapter } from '../../src/main/services/ads/CarbonAdsAdapter' import { CarbonAdsAdapter } from '../../src/main/services/ads/CarbonAdsAdapter'
import { PlaywireAdapter } from '../../src/main/services/ads/PlaywireAdapter' import { PlaywireAdapter } from '../../src/main/services/ads/PlaywireAdapter'
@ -275,3 +276,88 @@ describe('AdSettlementService fail-closed ledger', () => {
expect(settlement.getRevenueStats('2026-08')).toEqual(before) expect(settlement.getRevenueStats('2026-08')).toEqual(before)
}) })
}) })
describe('GAP-ADS-02 rewarded quota integration', () => {
const engine = getAdMediationEngine()
const knownNetworks = engine.getConfig().networks
it('grants LicenseService bonus quota on verified rewarded ad completion and blocks replay', async () => {
const license = getLicenseService()
const baseQuota = license.getUsage(Feature.PREMIUM_LLM)
engine.setConfig({
rewardTokensAmount: 50,
rewardCooldownSeconds: 0,
networks: knownNetworks.map((n) =>
n.id === 'direct_sponsor'
? {
...n,
enabled: true,
endpointUrl: 'https://ads.example.com',
apiSecret: 'secret',
}
: { ...n, enabled: false },
),
})
const fetchMock = vi
.fn()
.mockResolvedValueOnce(
new Response(
JSON.stringify({
bidEcpm: 15,
creative: {
id: 'rewarded-ad-1',
title: 'Rewarded Video',
advertiserName: 'D3RO Partner',
clickUrl: 'https://example.com/reward',
format: 'rewarded_video',
rewardTokens: 50,
durationSeconds: 15,
},
}),
{ status: 200 },
),
)
.mockResolvedValueOnce(new Response(JSON.stringify({ ok: true }), { status: 200 }))
.mockResolvedValueOnce(
new Response(JSON.stringify({ success: true, tokenReward: 50 }), { status: 200 }),
)
vi.stubGlobal('fetch', fetchMock)
try {
const auction = await engine.runAuction({
placement: 'rewarded_video_quota',
format: 'rewarded_video',
floorEcpm: 4,
})
expect(auction.winner?.id).toBe('rewarded-ad-1')
engine.recordImpression({
adId: 'rewarded-ad-1',
format: 'rewarded_video',
network: 'direct_sponsor',
earnedEcpm: auction.winningBidEcpm,
})
const claim = await engine.claimReward('rewarded-ad-1', 'direct_sponsor', 'nonce-1')
expect(claim.success).toBe(true)
expect(claim.tokensAdded).toBe(50)
expect(claim.newTotalQuota).toBe(baseQuota.limit + 50)
expect(license.getUsage(Feature.PREMIUM_LLM).limit).toBe(baseQuota.limit + 50)
// Replay with same adId or nonce is rejected
const replay = await engine.claimReward('rewarded-ad-1', 'direct_sponsor', 'nonce-1')
expect(replay).toEqual({
success: false,
tokensAdded: 0,
newTotalQuota: 0,
})
} finally {
vi.unstubAllGlobals()
engine.setConfig({
networks: knownNetworks.map((n) => ({ ...n, enabled: false })),
})
}
})
})

View file

@ -0,0 +1,368 @@
// apps/desktop/tests/unit/desktop-ux-gaps.test.ts
// Unit tests for Desktop UX & Main backlog items:
// GAP-UX-06, GAP-KEY-03, GAP-ADS-02, GAP-UX-01, GAP-UX-02, GAP-UX-03
import fs from 'fs'
import path from 'path'
import os from 'os'
import { describe, it, expect, vi } from 'vitest'
import { EventEmitter } from 'events'
import { IPC_CHANNELS } from '@d3ro/core/ipc-channels'
import { ErrorCode, ipcError, ipcSuccess } from '@d3ro/core/errors'
import { Feature } from '@d3ro/core/types'
import { STT_PROVIDERS_META } from '../../src/main/services/stt/STTManager'
import { registerAudioHandlers } from '../../src/main/ipc/audio-handlers'
import { getAudioCaptureService } from '../../src/main/services/AudioCaptureService'
import { getDictionaryService } from '../../src/main/services/DictionaryService'
import { getVoiceConversationService } from '../../src/main/services/VoiceConversationService'
import { getTTSPlaybackService } from '../../src/main/services/TTSPlaybackService'
import { registerVoiceConversationHandlers } from '../../src/main/ipc/voice-conversation-handlers'
import { resolveRagAddError } from '../../src/renderer/pages/KnowledgeBasePage'
import { getVoiceModeService } from '../../src/main/services/VoiceModeService'
import { getLicenseService } from '../../src/main/services/LicenseService'
import { getMeetingModeService } from '../../src/main/services/MeetingModeService'
import { registerMeetingModeHandlers } from '../../src/main/ipc/meeting-mode-handlers'
import { syncNotepadMemo, loadNotepad } from '../../src/renderer/components/meeting/meeting-notepad-storage'
import { getHistoryService } from '../../src/main/services/HistoryService'
import { registerHistoryHandlers } from '../../src/main/ipc/history-handlers'
import { getMemoService } from '../../src/main/services/MemoService'
import {
MEETING_SUMMARY_PROMPT,
extractTranscriptCitations,
parseCitationTimestampMs,
} from '../../src/main/services/MeetingSummaryService'
import { splitTextWithCitations } from '../../src/renderer/components/meeting/MarkdownRenderer'
import { getDatabase } from '../../src/main/db'
import { meetingSessions } from '../../src/main/db/schema'
import { historyInput, invokeIpc, useRedHarness } from '../red/harness'
useRedHarness()
describe('GAP-UX-06: Desktop Main Cleanup (sub-items a–f)', () => {
it('(a) STT_PROVIDERS_META uses neutral technical descriptions without marketing strings', () => {
const bannedTerms = ['100% 완전 오프라인', 'Industry Benchmark', 'Ultra Fast', 'Enterprise Ready', 'K-Language Best']
for (const meta of STT_PROVIDERS_META) {
for (const banned of bannedTerms) {
expect(meta.description).not.toContain(banned)
expect(meta.badge ?? '').not.toContain(banned)
}
expect(meta.description.length).toBeGreaterThan(5)
}
})
it('(b) AUDIO.TEST_DEVICE forwards the requested deviceId to AudioCaptureService.acquire', async () => {
registerAudioHandlers()
const audioService = getAudioCaptureService()
const fakeStream = new EventEmitter()
const releaseMock = vi.fn().mockResolvedValue(undefined)
const acquireSpy = vi.spyOn(audioService, 'acquire').mockResolvedValue({
stream: fakeStream,
sampleRate: 16000,
channels: 1,
release: releaseMock,
})
try {
const res = await invokeIpc<{ success: boolean }>(IPC_CHANNELS.AUDIO.TEST_DEVICE, {
deviceId: 'usb-mic-device-42',
durationMs: 50,
})
expect(res.success).toBe(true)
expect(acquireSpy).toHaveBeenCalledWith('usb-mic-device-42')
await invokeIpc(IPC_CHANNELS.AUDIO.STOP_TEST)
} finally {
acquireSpy.mockRestore()
}
})
it('(c) DictionaryService includes pronunciation in getPromptHints and applyDictionaryCorrections replaces & increments usageCount', () => {
const dict = getDictionaryService()
const added = dict.add({
word: 'D3ROVoice',
pronunciation: '디쓰리로보이스, 디쓰리로',
category: 'general',
})
const hints = dict.getPromptHints()
expect(hints).toContain('D3ROVoice (디쓰리로보이스, 디쓰리로)')
const corrected = dict.applyDictionaryCorrections('오늘 디쓰리로보이스 테스트를 진행합니다')
expect(corrected.text).toBe('오늘 D3ROVoice 테스트를 진행합니다')
expect(corrected.matchedIds).toEqual([added.id])
const page = dict.list({ page: 0, pageSize: 10 })
const entry = page.entries.find((e) => e.id === added.id)
expect(entry?.usageCount).toBe(1)
})
it('(d) VoiceConversationService.replayMessage speaks assistant message via TTSPlaybackService and is exposed via IPC', async () => {
registerVoiceConversationHandlers()
const tts = getTTSPlaybackService()
const speakSpy = vi.spyOn(tts, 'speakSentences').mockResolvedValue(undefined)
try {
const res = await invokeIpc(IPC_CHANNELS.VOICE_CONVERSATION.REPLAY_MESSAGE ?? 'voiceConversation:replayMessage', {
text: '다시 읽어줄 응답입니다.',
})
expect(res.success).toBe(true)
expect(speakSpy).toHaveBeenCalledWith(['다시 읽어줄 응답입니다.'])
await getVoiceConversationService().replayMessage('직접 호출 테스트')
expect(speakSpy).toHaveBeenCalledWith(['직접 호출 테스트'])
} finally {
speakSpy.mockRestore()
}
})
it('(e) preload instruction.getAll is typed as CustomInstruction[]', () => {
const preloadSrc = fs.readFileSync(
path.resolve(__dirname, '../../src/preload/index.ts'),
'utf-8',
)
expect(preloadSrc).toContain('invoke<CustomInstruction[]>(IPC_CHANNELS.INSTRUCTION.GET_ALL)')
})
it('(f) resolveRagAddError checks structured details.cancelled / error code instead of fragile string matching', () => {
const cancelledResp = ipcError(ErrorCode.RAGIndexingFailed, 'File selection cancelled', {
cancelled: true,
reason: 'dialog_cancelled',
})
expect(resolveRagAddError(cancelledResp)).toBeNull()
const realErrorResp = ipcError(ErrorCode.RAGIndexingFailed, 'Failed to parse PDF', {
cancelled: false,
})
expect(resolveRagAddError(realErrorResp)).toBe('Failed to parse PDF')
const okResp = ipcSuccess({
id: 'doc-1',
title: 'Test',
filePath: '/tmp/test.txt',
chunkCount: 2,
createdAt: Date.now(),
})
expect(resolveRagAddError(okResp)).toBeNull()
})
})
describe('GAP-KEY-03: command Keybinding Action Dedicated Behavior', () => {
it('_resolveHoldMode honors specHoldMode for command action and _resolveLlmRoute upgrades none to refine', async () => {
const { configSet } = await import('../../src/main/services/ConfigService')
configSet('llmBackend', 'online')
configSet('defaultLLMAction', 'none')
const vm = getVoiceModeService()
expect(vm._resolveHoldMode('command', false)).toBe(false)
expect(vm._resolveHoldMode('command', true)).toBe(true)
const resolveRoute = (
vm as unknown as {
_resolveLlmRoute: (
overrideId: string | null,
actionId?: 'dictation' | 'command' | 'hands-free',
) => { kind: string; action?: string; reason?: string }
}
)._resolveLlmRoute.bind(vm)
expect(resolveRoute(null, 'dictation')).toEqual({ kind: 'insert-raw', reason: 'none' })
expect(resolveRoute(null, 'command')).toEqual({ kind: 'action', action: 'refine' })
})
})
describe('GAP-ADS-02: LicenseService.grantRewardQuota', () => {
it('increments bonus quota for PREMIUM_LLM and deduplicates nonces', () => {
const license = getLicenseService()
const before = license.getUsage(Feature.PREMIUM_LLM)
const first = license.grantRewardQuota(50, 'nonce-abc')
expect(first.granted).toBe(true)
expect(first.tokensAdded).toBe(50)
expect(first.bonusQuota).toBe(50)
expect(first.newTotalQuota).toBe(before.limit + 50)
const duplicate = license.grantRewardQuota(50, 'nonce-abc')
expect(duplicate.granted).toBe(false)
expect(duplicate.tokensAdded).toBe(0)
expect(license.getUsage(Feature.PREMIUM_LLM).limit).toBe(before.limit + 50)
})
})
describe('GAP-UX-01: Meeting Post-Meeting addMemo & Notepad Sync', () => {
it('allows adding a memo to an ended meeting session by meetingId and syncs via syncNotepadMemo', async () => {
registerMeetingModeHandlers()
const now = Date.now()
getDatabase()
.insert(meetingSessions)
.values({
id: 'ended-session-1',
title: '종료된 회의',
status: 'completed',
startedAt: now - 60_000,
endedAt: now,
durationMs: 60_000,
rawTranscript: '[00:10] 안녕하세요',
createdAt: now - 60_000,
updatedAt: now,
})
.run()
const memo = await getMeetingModeService().addMemo('회의 종료 후 추가한 메모', 'ended-session-1')
expect(memo.sessionId).toBe('ended-session-1')
expect(memo.content).toBe('회의 종료 후 추가한 메모')
expect(memo.timestampMs).toBe(60_000)
const detail = getMeetingModeService().getSession('ended-session-1')
expect(detail.memos).toHaveLength(1)
expect(detail.memos[0].content).toBe('회의 종료 후 추가한 메모')
// Test notepad storage + IPC sync helper
const fakeStorageMap = new Map<string, string>()
const fakeStorage = {
getItem: (k: string) => fakeStorageMap.get(k) ?? null,
setItem: (k: string, v: string) => {
fakeStorageMap.set(k, v)
},
removeItem: (k: string) => {
fakeStorageMap.delete(k)
},
}
const synced = await syncNotepadMemo(
fakeStorage,
'ended-session-1',
'노트패드에서 동기화된 메모',
{
addMemo: (params) =>
invokeIpc(IPC_CHANNELS.MEETING_MODE.ADD_MEMO, params),
},
)
expect(loadNotepad(fakeStorage, 'ended-session-1')).toBe('노트패드에서 동기화된 메모')
expect(synced?.content).toBe('노트패드에서 동기화된 메모')
expect(getMeetingModeService().getSession('ended-session-1').memos).toHaveLength(2)
})
})
describe('GAP-UX-02: History SQLite Multi-Filter, Update, and Markdown Export', () => {
it('filters HistoryService.getAll in SQLite by mode, isFavorite, tag, search, and beforeCreatedAt', () => {
const historySvc = getHistoryService()
const memoSvc = getMemoService()
const e1 = historySvc.create(
historyInput({
originalText: '알파 프로젝트 일정 논의',
mode: 'dictation',
isFavorite: true,
}),
)
const e2 = historySvc.create(
historyInput({
originalText: '알파 프로젝트 번역 테스트',
mode: 'translate',
isFavorite: true,
}),
)
historySvc.create(
historyInput({
originalText: '베타 프로젝트 일반 메모',
mode: 'dictation',
isFavorite: false,
}),
)
memoSvc.addTag(e1.id, 'alpha')
memoSvc.addTag(e2.id, 'alpha')
// Object caller with combined filters
const filtered = historySvc.getAll({
page: 0,
pageSize: 10,
mode: 'dictation',
isFavorite: true,
tag: 'alpha',
search: '일정',
})
expect(filtered.total).toBe(1)
expect(filtered.entries[0].id).toBe(e1.id)
// Backward-compatible positional caller (limit, offset, search)
const positional = historySvc.getAll(10, 0, '알파')
expect(positional.total).toBe(2)
})
it('updates history entry title and text via HistoryService.update and history:update IPC', async () => {
registerHistoryHandlers()
const historySvc = getHistoryService()
const created = historySvc.create(
historyInput({
originalText: '초기 원문 텍스트',
polishedText: '초기 다듬은 텍스트',
}),
)
const res = await invokeIpc<{ id: string; title: string | null; polishedText: string | null }>(
'history:update',
{
id: created.id,
title: '수정된 제목',
polishedText: '수정된 본문 내용입니다',
},
)
expect(res.success).toBe(true)
if (res.success) {
expect(res.data.title).toBe('수정된 제목')
expect(res.data.polishedText).toBe('수정된 본문 내용입니다')
}
const reloaded = historySvc.getById(created.id)
expect(reloaded?.title).toBe('수정된 제목')
expect(reloaded?.polishedText).toBe('수정된 본문 내용입니다')
expect(reloaded?.wordCount).toBe(3)
})
it('exports untagged history records and supports custom savePath in MemoService.exportMarkdown', () => {
const historySvc = getHistoryService()
historySvc.create(
historyInput({
title: '태그 없는 메모',
originalText: '태그가 없어도 내보내기에 포함됩니다',
}),
)
const customPath = path.join(os.tmpdir(), `d3ro-memo-export-test-${Date.now()}.md`)
try {
const outPath = getMemoService().exportMarkdown({
format: 'markdown',
savePath: customPath,
})
expect(outPath).toBe(path.resolve(customPath))
const content = fs.readFileSync(outPath, 'utf-8')
expect(content).toContain('## Untagged')
expect(content).toContain('태그가 없어도 내보내기에 포함됩니다')
} finally {
if (fs.existsSync(customPath)) fs.unlinkSync(customPath)
}
})
})
describe('GAP-UX-03: Meeting Summary Transcript Citations', () => {
it('parses [MM:SS] and [HH:MM:SS] citations and splits summary text into clickable citation parts', () => {
expect(MEETING_SUMMARY_PROMPT).toContain('[MM:SS]')
expect(parseCitationTimestampMs('[01:25]')).toBe(85_000)
expect(parseCitationTimestampMs('[01:02:03]')).toBe(3_723_000)
expect(parseCitationTimestampMs('[invalid]')).toBeNull()
const sampleMarkdown = `## 요약\n출시 일정을 확정했습니다 [02:15].\n\n## 핵심 결정사항\n- 11월 정식 배포 [05:40]`
const citations = extractTranscriptCitations(sampleMarkdown)
expect(citations).toEqual([
{ label: '[02:15]', timestampMs: 135_000 },
{ label: '[05:40]', timestampMs: 340_000 },
])
const parts = splitTextWithCitations('출시 일정을 확정했습니다 [02:15].')
expect(parts).toEqual([
{ type: 'text', value: '출시 일정을 확정했습니다 ' },
{ type: 'citation', label: '[02:15]', timestampMs: 135_000 },
{ type: 'text', value: '.' },
])
})
})

View file

@ -9,10 +9,12 @@ import { describe, expect, it } from 'vitest'
import { import {
COMMAND_NONE, COMMAND_NONE,
commandSelection, commandSelection,
commandSelections,
commandTestRequest, commandTestRequest,
conversationBadge, conversationBadge,
documentIndexLabelKey, documentIndexLabelKey,
llmActionLabelKey, llmActionLabelKey,
removeInstructionFromActiveIds,
resolveCommandPipeline, resolveCommandPipeline,
withoutHidden, withoutHidden,
isInstructionInUse, isInstructionInUse,
@ -32,6 +34,21 @@ describe('resolveCommandPipeline', () => {
const p = resolveCommandPipeline({ defaultLLMAction: 'custom', activeInstructionId: 'i1' }, list) const p = resolveCommandPipeline({ defaultLLMAction: 'custom', activeInstructionId: 'i1' }, list)
expect(p).toEqual({ kind: 'instruction', instruction: polish }) expect(p).toEqual({ kind: 'instruction', instruction: polish })
expect(commandSelection(p)).toBe('i1') expect(commandSelection(p)).toBe('i1')
expect(commandSelections(p)).toEqual(['i1'])
})
it("'custom' + 복수 지시문('i2,i1')이면 선택한 순서대로 다단계 파이프라인을 구성한다", () => {
const p = resolveCommandPipeline({ defaultLLMAction: 'custom', activeInstructionId: 'i2,i1' }, list)
expect(p).toEqual({ kind: 'instructions', instructions: [list[1], polish] })
expect(commandSelection(p)).toBe('i2,i1')
expect(commandSelections(p)).toEqual(['i2', 'i1'])
const testReq = commandTestRequest(p, ' 어 오늘 회의 내용 정리 ')
expect(testReq.ok).toBe(true)
if (testReq.ok) {
expect(testReq.params.action).toBe('custom')
expect(testReq.params.customPrompt).toContain('[1단계: 요약]')
expect(testReq.params.customPrompt).toContain('[2단계: 정중하게]')
}
}) })
it("'custom' 인데 지시문이 지워졌으면 '선택 안 됨'으로 정직하게", () => { it("'custom' 인데 지시문이 지워졌으면 '선택 안 됨'으로 정직하게", () => {
@ -98,8 +115,10 @@ describe('withoutHidden / documentIndexLabelKey', () => {
}) })
describe('isInstructionInUse — 명령 삭제 확정 시점의 설정으로 판단', () => { describe('isInstructionInUse — 명령 삭제 확정 시점의 설정으로 판단', () => {
it('지운 명령이 아직 선택돼 있을 때만 true', () => { it('지운 명령이 아직 선택돼 있을 때만 true (단일 및 복수 파이프라인 포함)', () => {
expect(isInstructionInUse({ defaultLLMAction: 'custom', activeInstructionId: 'x' }, 'x')).toBe(true) expect(isInstructionInUse({ defaultLLMAction: 'custom', activeInstructionId: 'x' }, 'x')).toBe(true)
expect(isInstructionInUse({ defaultLLMAction: 'custom', activeInstructionId: 'y,x' }, 'x')).toBe(true)
expect(removeInstructionFromActiveIds('y,x', 'x')).toEqual(['y'])
// 되돌리기 알림 동안 다른 명령을 골랐다 — 덮으면 안 된다 // 되돌리기 알림 동안 다른 명령을 골랐다 — 덮으면 안 된다
expect(isInstructionInUse({ defaultLLMAction: 'custom', activeInstructionId: 'y' }, 'x')).toBe(false) expect(isInstructionInUse({ defaultLLMAction: 'custom', activeInstructionId: 'y' }, 'x')).toBe(false)
expect(isInstructionInUse({ defaultLLMAction: 'refine', activeInstructionId: 'x' }, 'x')).toBe(false) expect(isInstructionInUse({ defaultLLMAction: 'refine', activeInstructionId: 'x' }, 'x')).toBe(false)

View file

@ -1,8 +1,13 @@
{ {
"extends": "@electron-toolkit/tsconfig/tsconfig.node.json", "extends": "@electron-toolkit/tsconfig/tsconfig.node.json",
"compilerOptions": { "compilerOptions": {
"composite": true, "composite": false,
"incremental": false,
"noEmit": true,
"declaration": false,
"declarationMap": false,
"outDir": "./out", "outDir": "./out",
"rootDir": "../..",
"baseUrl": ".", "baseUrl": ".",
"paths": { "paths": {
"@d3ro/core": ["../../packages/core/src/index.ts"], "@d3ro/core": ["../../packages/core/src/index.ts"],

View file

@ -1,8 +1,13 @@
{ {
"extends": "@electron-toolkit/tsconfig/tsconfig.web.json", "extends": "@electron-toolkit/tsconfig/tsconfig.web.json",
"compilerOptions": { "compilerOptions": {
"composite": true, "composite": false,
"incremental": false,
"noEmit": true,
"declaration": false,
"declarationMap": false,
"outDir": "./out", "outDir": "./out",
"rootDir": "../..",
"baseUrl": ".", "baseUrl": ".",
"paths": { "paths": {
"@d3ro/core": ["../../packages/core/src/index.ts"], "@d3ro/core": ["../../packages/core/src/index.ts"],
@ -22,6 +27,7 @@
"skipLibCheck": true "skipLibCheck": true
}, },
"include": [ "include": [
"src/renderer/**/*" "src/renderer/**/*",
"src/preload/**/*"
] ]
} }

View file

@ -1,4 +1,6 @@
import { Feature } from '@d3ro/core/types'
import { normalizeEntitlement } from '../src/lib/entitlement-context' import { normalizeEntitlement } from '../src/lib/entitlement-context'
import { resolveWebEntitlement } from '../../web/src/lib/entitlement'
describe('normalizeEntitlement', () => { describe('normalizeEntitlement', () => {
const now = new Date('2026-08-21T00:00:00Z') const now = new Date('2026-08-21T00:00:00Z')
@ -16,6 +18,7 @@ describe('normalizeEntitlement', () => {
expect(snapshot.adFree).toBe(false) expect(snapshot.adFree).toBe(false)
expect(snapshot.overageCredits).toBe(50) expect(snapshot.overageCredits).toBe(50)
expect(snapshot.usageToday.stt_transcribe).toBe(3) expect(snapshot.usageToday.stt_transcribe).toBe(3)
expect(snapshot.features).not.toContain(Feature.TEAM_WORKSPACE)
}) })
it('서버가 확인한 유효 paid period만 광고 제거 권한을 준다', () => { it('서버가 확인한 유효 paid period만 광고 제거 권한을 준다', () => {
@ -34,7 +37,10 @@ describe('normalizeEntitlement', () => {
current_period_end: '2026-08-20T00:00:00Z', current_period_end: '2026-08-20T00:00:00Z',
}, [], [], now) }, [], [], now)
expect(active.tier).toBe('pro')
expect(active.adFree).toBe(true) expect(active.adFree).toBe(true)
expect(active.features).toContain(Feature.TEAM_WORKSPACE)
expect(expired.tier).toBe('free')
expect(expired.adFree).toBe(false) expect(expired.adFree).toBe(false)
}) })
@ -61,11 +67,41 @@ describe('normalizeEntitlement', () => {
product_id: 'unknown', product_id: 'unknown',
purchase_state: 'purchased', purchase_state: 'purchased',
verified_at: 'invalid', verified_at: 'invalid',
}], now) }], now, 'manager')
expect(snapshot.tier).toBe('pro_plus')
expect(snapshot.adFree).toBe(true) expect(snapshot.adFree).toBe(true)
expect(snapshot.adminRole).toBe('manager')
expect(snapshot.autoRenewing).toBe(false) expect(snapshot.autoRenewing).toBe(false)
expect(snapshot.purchases).toHaveLength(1) expect(snapshot.purchases).toHaveLength(1)
expect(snapshot.purchases[0].productId).toBe('d3ro_voice_pro_plus_monthly') expect(snapshot.purchases[0].productId).toBe('d3ro_voice_pro_plus_monthly')
}) })
it('웹 구독과 역할도 @d3ro/core resolveEntitlement 기준으로 정규화한다', () => {
const activeWeb = resolveWebEntitlement({
tier: 'pro_plus',
status: 'active',
provider: 'none',
payment_provider: 'payple',
current_period_end: '2026-09-21T00:00:00Z',
overage_credits: 120,
}, { supabaseRole: 'admin', now })
expect(activeWeb.tier).toBe('pro_plus')
expect(activeWeb.provider).toBe('payple')
expect(activeWeb.adFree).toBe(true)
expect(activeWeb.adminRole).toBe('admin')
expect(activeWeb.adminCapabilities.canAdmin).toBe(true)
const expiredWeb = resolveWebEntitlement({
tier: 'pro',
status: 'active',
provider: 'payple',
current_period_end: '2026-08-01T00:00:00Z',
}, { now })
expect(expiredWeb.tier).toBe('free')
expect(expiredWeb.rawTier).toBe('pro')
expect(expiredWeb.adFree).toBe(false)
})
}) })

View file

@ -40,6 +40,7 @@ import {
computeMemoTimestamp, computeMemoTimestamp,
createMeetingCreationIdempotencyKey, createMeetingCreationIdempotencyKey,
createMeetingWorkspaceWithMetadata, createMeetingWorkspaceWithMetadata,
findActiveTranscriptSegmentId,
getMeetingRecordingLanguage, getMeetingRecordingLanguage,
MeetingServiceError, MeetingServiceError,
normalizeDocumentDraft, normalizeDocumentDraft,
@ -48,11 +49,17 @@ import {
normalizeMeetingLanguage, normalizeMeetingLanguage,
normalizeMeetingTitle, normalizeMeetingTitle,
normalizeMemoContent, normalizeMemoContent,
parseTimestampTokenToMs,
parseTranscriptSeekSegments,
sanitizeMeetingSearch, sanitizeMeetingSearch,
subscribeToMeetingDetail, subscribeToMeetingDetail,
updateMeetingMemoConflictSafe, updateMeetingMemoConflictSafe,
updateMeetingTitleRevisionSafe, updateMeetingTitleRevisionSafe,
} from '../src/features/meetings/meetings-service' } from '../src/features/meetings/meetings-service'
import {
findActiveWebTranscriptSegmentId,
parseFallbackTranscriptRows,
} from '../../web/src/components/meetings/live-transcript-list'
const USER_ID = '11111111-1111-4111-8111-111111111111' const USER_ID = '11111111-1111-4111-8111-111111111111'
const MEETING_ID = '22222222-2222-4222-8222-222222222222' const MEETING_ID = '22222222-2222-4222-8222-222222222222'
@ -307,6 +314,53 @@ describe('meeting transcript selection', () => {
expect(buildMeetingTranscriptView(meeting(), [])) expect(buildMeetingTranscriptView(meeting(), []))
.toEqual({ source: 'empty', text: '' }) .toEqual({ source: 'empty', text: '' })
}) })
test('parses [MM:SS] timestamps and resolves active segment for audio seek sync', () => {
expect(parseTimestampTokenToMs('[01:25]')).toBe(85_000)
expect(parseTimestampTokenToMs('02:05')).toBe(125_000)
expect(parseTimestampTokenToMs('[01:02:03]')).toBe(3_723_000)
expect(parseTimestampTokenToMs('invalid')).toBeNull()
const fromRows = parseTranscriptSeekSegments(meeting(), [
transcript('seg-2', 2, '두 번째 발언', '화자 2'),
transcript('seg-1', 1, '첫 번째 발언', '화자 1'),
])
expect(fromRows.map((item) => ({ id: item.id, timestampMs: item.timestampMs }))).toEqual([
{ id: 'seg-1', timestampMs: 1_000 },
{ id: 'seg-2', timestampMs: 2_000 },
])
expect(findActiveTranscriptSegmentId(fromRows, 500)).toBeNull()
expect(findActiveTranscriptSegmentId(fromRows, 1_500)).toBe('seg-1')
expect(findActiveTranscriptSegmentId(fromRows, 2_500)).toBe('seg-2')
const fromFallback = parseTranscriptSeekSegments(
meeting({ raw_transcript: '[00:05] [화자 A] 안건 소개\n[00:20] 일정 논의' }),
[],
)
expect(fromFallback).toEqual([
expect.objectContaining({
id: 'line-0',
timestampMs: 5_000,
speaker: '화자 A',
text: '안건 소개',
timed: true,
}),
expect.objectContaining({
id: 'line-1',
timestampMs: 20_000,
speaker: null,
text: '일정 논의',
timed: true,
}),
])
expect(findActiveTranscriptSegmentId(fromFallback, 12_000)).toBe('line-0')
expect(findActiveTranscriptSegmentId(fromFallback, 25_000)).toBe('line-1')
const webRows = parseFallbackTranscriptRows('[00:10] [윤찬] 첫 구간\n[00:40] 둘째 구간')
expect(webRows).toHaveLength(2)
expect(findActiveWebTranscriptSegmentId(webRows, 15_000)).toBe('fallback-line-0')
expect(findActiveWebTranscriptSegmentId(webRows, 45_000)).toBe('fallback-line-1')
})
}) })
describe('meeting mutation safety', () => { describe('meeting mutation safety', () => {

View file

@ -26,8 +26,13 @@ import {
import { import {
detachPushRegistrationForLogout, detachPushRegistrationForLogout,
registerPushRegistration, registerPushRegistration,
resolveDevicePushProvider,
synchronizePushRegistration, synchronizePushRegistration,
} from '../src/features/notifications/notification-service' } from '../src/features/notifications/notification-service'
import {
subscribeWebPush,
urlBase64ToUint8Array,
} from '../../web/src/lib/web-push'
const USER_ID = '11111111-1111-4111-8111-111111111111' const USER_ID = '11111111-1111-4111-8111-111111111111'
const DEVICE_ID = '22222222-2222-4222-8222-222222222222' const DEVICE_ID = '22222222-2222-4222-8222-222222222222'
@ -270,4 +275,56 @@ describe('device-bound push registration', () => {
expect(mockedSupabase.rpc).not.toHaveBeenCalled() expect(mockedSupabase.rpc).not.toHaveBeenCalled()
expect(mockedNative.deleteNativePushRegistration).toHaveBeenCalledTimes(1) expect(mockedNative.deleteNativePushRegistration).toHaveBeenCalledTimes(1)
}) })
test('registers iOS devices with provider apns while Android uses fcm', async () => {
const iosDevice: RegisteredDevice = {
...device,
platform: 'ios',
deviceName: 'iPhone 16 Pro',
osVersion: 'iOS 18.1',
}
const apnsToken = `apns_${'b'.repeat(64)}`
expect(resolveDevicePushProvider(device)).toBe('fcm')
expect(resolveDevicePushProvider(iosDevice)).toBe('apns')
mockedNative.getNativeNotificationStatus.mockResolvedValue({
configured: true,
provider: 'apns',
reason: 'configured',
permission: 'granted',
registrationId: apnsToken,
fullSyncRequired: false,
})
mockedSupabase.rpc.mockResolvedValue({
data: {
device_id: DEVICE_ID,
provider: 'apns',
registered_at: '2026-08-21T00:05:00.000Z',
},
error: null,
})
await expect(synchronizePushRegistration(USER_ID, iosDevice)).resolves.toMatchObject({
status: 'registered',
registeredAt: '2026-08-21T00:05:00.000Z',
})
expect(mockedSupabase.rpc).toHaveBeenCalledWith('register_push_registration', {
push_device_id: DEVICE_ID,
push_provider: 'apns',
registration_id: apnsToken,
})
})
test('converts VAPID public key and fails closed when VAPID key is absent in web push', async () => {
const bytes = urlBase64ToUint8Array('SGVsbG8td29ybGQ')
expect(bytes).toBeInstanceOf(Uint8Array)
expect(bytes.length).toBeGreaterThan(0)
await expect(
subscribeWebPush({
userId: USER_ID,
vapidPublicKey: '',
}),
).rejects.toMatchObject({ code: 'vapid-key-missing' })
})
}) })

View file

@ -6,6 +6,7 @@ import {
createMobileSearchExcerpt, createMobileSearchExcerpt,
createPostgrestLikePattern, createPostgrestLikePattern,
createSupabaseUnifiedSearchSource, createSupabaseUnifiedSearchSource,
isUnifiedSearchAbortedError,
sanitizeUnifiedSearchQuery, sanitizeUnifiedSearchQuery,
searchUnifiedContent, searchUnifiedContent,
type MobileUnifiedSearchOptions, type MobileUnifiedSearchOptions,
@ -212,4 +213,110 @@ describe('mobile unified search service', () => {
expect(normalizeUnifiedSearchInitialQuery(123)).toBe('') expect(normalizeUnifiedSearchInitialQuery(123)).toBe('')
expect(normalizeUnifiedSearchInitialQuery('가'.repeat(120))).toHaveLength(100) expect(normalizeUnifiedSearchInitialQuery('가'.repeat(120))).toHaveLength(100)
}) })
test('includes transcript segment matches with segment snippet and parent meeting ID', async () => {
const segmentOnlyMeetingId = '44444444-4444-4444-8444-444444444444'
const source: UnifiedSearchSourcePort = {
searchRecords: jest.fn(async () => ({ rows: [], total: 0 })),
searchMeetings: jest.fn(async () => ({ rows: [], total: 0 })),
searchTranscriptSegments: jest.fn(async () => ({
rows: [{
id: '55555555-5555-4555-8555-555555555555',
meeting_id: segmentOnlyMeetingId,
text: '보안 감사 일정을 금요일로 확정했습니다.',
speaker: '김팀장',
timestamp_ms: 125_000,
created_at: '2026-09-29T00:00:00.000Z',
}],
total: 1,
})),
loadMeetingsByIds: jest.fn(async () => [{
id: segmentOnlyMeetingId,
title: '보안 점검 회의',
started_at: '2026-09-29T00:00:00.000Z',
}]),
}
const response = await searchUnifiedContent({
userId: USER_ID,
query: '보안 감사',
limit: 10,
}, source)
expect(source.searchTranscriptSegments).toHaveBeenCalledWith('보안 감사', 10)
expect(source.loadMeetingsByIds).toHaveBeenCalledWith([segmentOnlyMeetingId])
expect(response.total).toBe(1)
expect(response.results).toEqual([
expect.objectContaining({
source: 'meeting',
id: segmentOnlyMeetingId,
title: '보안 점검 회의',
matchedField: 'transcript',
excerpt: '[02:05] [김팀장] 보안 감사 일정을 금요일로 확정했습니다.',
}),
])
})
test('cancels in-flight search when AbortSignal is aborted', async () => {
const controller = new AbortController()
controller.abort()
const source: UnifiedSearchSourcePort = {
searchRecords: jest.fn(),
searchMeetings: jest.fn(),
}
let caughtError: unknown = null
try {
await searchUnifiedContent({
userId: USER_ID,
query: '로드맵',
signal: controller.signal,
}, source)
} catch (error) {
caughtError = error
}
expect(isUnifiedSearchAbortedError(caughtError)).toBe(true)
expect(source.searchRecords).not.toHaveBeenCalled()
expect(source.searchMeetings).not.toHaveBeenCalled()
})
test('bounds oversized text payloads in Supabase source adapter', async () => {
const hugeText = `${'가'.repeat(500)} 핵심키워드 ${'나'.repeat(500)}`
const transcriptBuilder = {
select: jest.fn(),
or: jest.fn(),
order: jest.fn(),
abortSignal: jest.fn(),
limit: jest.fn(),
}
transcriptBuilder.select.mockReturnValue(transcriptBuilder)
transcriptBuilder.or.mockReturnValue(transcriptBuilder)
transcriptBuilder.order.mockReturnValue(transcriptBuilder)
transcriptBuilder.abortSignal.mockReturnValue(transcriptBuilder)
transcriptBuilder.limit.mockResolvedValue({
data: [{
id: 'seg-1',
meeting_id: meeting.id,
text: hugeText,
speaker: '화자 1',
timestamp_ms: 15_000,
created_at: '2026-09-28T00:00:00.000Z',
}],
error: null,
count: 1,
})
const from = jest.fn(() => transcriptBuilder)
const source = createSupabaseUnifiedSearchSource({ from } as unknown as D3roSupabaseClient)
const controller = new AbortController()
const page = await source.searchTranscriptSegments!('핵심키워드', 10, controller.signal)
expect(transcriptBuilder.select).toHaveBeenCalledWith(
'id,meeting_id,text,speaker,timestamp_ms,created_at',
{ count: 'exact' },
)
expect(transcriptBuilder.abortSignal).toHaveBeenCalledWith(controller.signal)
expect(page.rows[0].text.length).toBeLessThanOrEqual(602)
expect(page.rows[0].text).toContain('핵심키워드')
})
}) })

View file

@ -151,8 +151,8 @@ def versionSettingsValid = configuredVersionName != null &&
configuredVersionName ==~ strictSemver && configuredVersionName ==~ strictSemver &&
configuredVersionCodeValue != null && configuredVersionCodeValue != null &&
configuredVersionCodeValue <= 2100000000L configuredVersionCodeValue <= 2100000000L
def resolvedVersionName = versionSettingsValid ? configuredVersionName : "1.14.0" def resolvedVersionName = versionSettingsValid ? configuredVersionName : "1.15.0"
def resolvedVersionCode = versionSettingsValid ? configuredVersionCodeValue.toInteger() : 1140000 def resolvedVersionCode = versionSettingsValid ? configuredVersionCodeValue.toInteger() : 1150000
def requiredReleaseSettings = [ def requiredReleaseSettings = [
D3RO_RELEASE_STORE_FILE: releaseStoreFilePath, D3RO_RELEASE_STORE_FILE: releaseStoreFilePath,

View file

@ -257,7 +257,7 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1140000; CURRENT_PROJECT_VERSION = 1150000;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
INFOPLIST_FILE = D3ROVoice/Info.plist; INFOPLIST_FILE = D3ROVoice/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.1; IPHONEOS_DEPLOYMENT_TARGET = 15.1;
@ -265,7 +265,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.14.0; MARKETING_VERSION = 1.15.0;
OTHER_LDFLAGS = ( OTHER_LDFLAGS = (
"$(inherited)", "$(inherited)",
"-ObjC", "-ObjC",
@ -287,14 +287,14 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1140000; CURRENT_PROJECT_VERSION = 1150000;
INFOPLIST_FILE = D3ROVoice/Info.plist; INFOPLIST_FILE = D3ROVoice/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.1; IPHONEOS_DEPLOYMENT_TARGET = 15.1;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.14.0; MARKETING_VERSION = 1.15.0;
OTHER_LDFLAGS = ( OTHER_LDFLAGS = (
"$(inherited)", "$(inherited)",
"-ObjC", "-ObjC",

View file

@ -0,0 +1 @@
Stability and performance improvements.

View file

@ -0,0 +1 @@
안정성과 성능을 개선했습니다.

Some files were not shown because too many files have changed in this diff Show more