feat(desktop): typo auto-correct and context-aware sentence prediction
Some checks failed
ci / 정본·보안·린트·타입·테스트 (push) Has been cancelled
deploy-site / deploy (push) Has been cancelled
ci / 워크스페이스 빌드 검증 (push) Has been cancelled
ci / 모바일 린트·타입·Jest (push) Has been cancelled
ci / Supabase Edge Functions + Cloudflare Worker (push) Has been cancelled
ci / .NET API 서버 테스트 (push) Has been cancelled

Typo auto-correct (INPUT-19)
- TypoCorrectionService + core typo-correction: 2-set Korean layout
  mistypes both ways, always-wrong spellings, near-misses of the user's
  frequent words, optional model check re-validated in core; applied by
  backspace N + paste and cancelled on new keys or window change.

Prediction quality (INPUT-20/21)
- gemma models are sent raw with the user's unfinished sentence pre-filled
  into the model turn, so the model truly continues the text (mid-word
  joins and spacing exact). Other models keep the instruction prompt.
- Context: text before the caret (opening lines and a fact list of names,
  dates, amounts outside the 400-char window), messages just sent in the
  same chat window (memory only, 30 min), personal-graph follow-ups and
  IDF-ranked related sentences with Korean stemming.
- Guards: first sentence only, restated-prefix stripping (also fixes the
  instruction path), repeat drop, no invented dates/names/numbers
  (one retry), plain -다 register, no emoji unless the user uses them,
  search-box keywords. Fill loop mixes instruction prompts for variety.
- Opt-in real-model probe: tests/integration/suggestion-quality.ollama.test.ts

Suggestions now actually show up
- Terminal (Claude Code): caret trust from the input line, not the whole
  screen (status line below the box blocked every keystroke); Korean
  composition counts as typing at the end; a grey placeholder filling the
  empty box at once is not user text.
- Chrome: UIA focus flicker while typing no longer resets "edited".
- KakaoTalk/RichEdit: trailing paragraph mark ignored for edit position
  and stripped so accepted text keeps its separating space.
- While the overlay is visible the suggestion shortcuts are captured so
  Ctrl+Alt+Enter no longer also types a newline; released when hidden.
- nut-js preloaded after boot (first accept waited 4.8 s).
This commit is contained in:
Yun Chan 2026-10-03 21:48:28 +09:00
parent 5ca3709b32
commit 3cac14f668
56 changed files with 4700 additions and 258 deletions

View file

@ -27,7 +27,7 @@ import {
SUGGESTION_SYSTEM_PROMPT,
FREE_PROMPT_SYSTEM_PROMPT,
} from '../../../src/main/services/llm-prompts'
import { buildCaptionRefinePrompt } from '../../../src/main/services/llm-prompts'
import { buildCaptionRefinePrompt, buildTypoCheckPrompt } from '../../../src/main/services/llm-prompts'
beforeEach(() => {
vi.clearAllMocks()
@ -249,6 +249,52 @@ describe('buildSuggestionPrompt', () => {
const { text } = buildSuggestionPrompt({ prefix: 'abc' })
expect(text).not.toContain('이미 제안한 문장')
})
it('접두를 직전 문장과 지금 쓰는 문장으로 나누고 마저 쓰기·언어·말투를 지시한다', () => {
const { text } = buildSuggestionPrompt({
prefix: '어제 배포는 잘 끝났습니다. 오늘은 모니터링 결과를'
})
expect(text).toContain('[직전 문장]\n어제 배포는 잘 끝났습니다.')
expect(text).toContain('[지금 쓰는 문장 — 아직 끝나지 않음]\n오늘은 모니터링 결과를')
expect(text).toContain('나머지 부분만')
expect(text).toContain('언어: 한국어')
expect(text).toContain('말투: 격식체')
})
it('문장이 끝났으면 다음 문장을 지시한다', () => {
const { text } = buildSuggestionPrompt({ prefix: 'Thanks for the update. ' })
expect(text).toContain('새 문장 하나')
expect(text).toContain('언어: 영어')
expect(text).not.toContain('말투:')
})
it('그래프 근거(직전 문장 뒤 이어 쓴 문장)와 커서 뒤 텍스트를 데이터로 넣는다', () => {
const { systemPrompt, text } = buildSuggestionPrompt({
prefix: '회의록 정리했습니다.',
suffix: '감사합니다.',
followUpHints: ['검토 후 의견 주세요']
})
expect(text).toContain('[사용자가 평소 직전 문장 같은 말 뒤에 이어 쓴 문장]\n- 검토 후 의견 주세요')
expect(text).toContain('[커서 뒤에 이미 있는 텍스트 — 이것과 겹치지 않게]\n감사합니다.')
expect(systemPrompt).not.toContain('검토 후 의견 주세요')
})
it('프롬프트에 깨진 글자(빈 자리)가 없다', () => {
const { systemPrompt, text } = buildSuggestionPrompt({ prefix: '안녕하세요. 오늘' })
expect(systemPrompt).toContain('사용자가 쓴 언어와 같은 언어')
expect(systemPrompt).toContain('머리말')
expect(systemPrompt).not.toMatch(/ {2}[가-힣]/u)
expect(text).not.toMatch(/\[[^\]]* {2}[^\]]*\]/u)
})
})
describe('buildTypoCheckPrompt', () => {
it('지시문은 시스템 프롬프트에, 검사할 문장과 앞 문맥만 본문에', () => {
const { systemPrompt, text } = buildTypoCheckPrompt({ sentence: '회으 자료 공유', previous: '오늘 회의 끝났습니다.' })
expect(systemPrompt).toContain('=>')
expect(systemPrompt).toContain('없음')
expect(text).toBe('[앞 문맥]\n오늘 회의 끝났습니다.\n\n[검사할 문장]\n회으 자료 공유')
})
})
describe('buildCaptionRefinePrompt', () => {
@ -268,3 +314,58 @@ describe('buildCaptionRefinePrompt', () => {
expect(buildCaptionRefinePrompt({ text: '안녕', previous: [] }).text).toBe(['[다듬을 자막]', '안녕'].join('\n'))
})
})
describe('buildSuggestionPrompt — prefill 이어 쓰기', () => {
it('마저 쓰기: 지금 문장을 모델 차례에 넣고(끝 공백 제외) 단어를 끝냈는지 알려 준다', () => {
const prompt = buildSuggestionPrompt({ prefix: '안녕하세요. 첨부 파일 검토해 보시고 ', prefill: true })
expect(prompt.assistantPrefix).toBe('첨부 파일 검토해 보시고')
expect(prompt.wordFinished).toBe(true)
expect(prompt.writing.mode).toBe('complete-sentence')
expect(prompt.systemPrompt).toContain('당신의 차례에는 사용자가 쓰던 글의 끝부분')
expect(prompt.systemPrompt).not.toContain(SUGGESTION_NO_THINK_PREFIX)
})
it('다음 문장: 직전 문장을 넣고, 새 줄에서 멈췄으면 줄바꿈을 남긴다', () => {
expect(buildSuggestionPrompt({ prefix: '자료 공유드립니다.', prefill: true }).assistantPrefix).toBe('자료 공유드립니다.')
expect(buildSuggestionPrompt({ prefix: '- 일정: 10월 7일\n', prefill: true }).assistantPrefix).toBe('- 일정: 10월 7일\n')
})
it('400자 창 밖의 첫머리와 사실을 문서 원문에서 뽑아 보여 준다', () => {
const documentText = `팀장님 안녕하세요. 출시일은 11월 15일로 확정됐습니다.\n${'세부 내용입니다. '.repeat(150)}정리하면 출시는 `
const prompt = buildSuggestionPrompt({ prefix: documentText.slice(-400), documentText, prefill: true })
expect(prompt.text).toContain('[글의 첫머리]\n팀장님 안녕하세요. 출시일은 11월 15일로 확정됐습니다.')
expect(prompt.text).toMatch(/\[글에 나온 사실\]\n.*11월 15일/u)
expect(prompt.factSource).toContain('11월 15일')
})
it('이 창에서 조금 전에 쓴 글을 오래된 것부터 보여 주고 사실 검사 원문에도 넣는다', () => {
const prompt = buildSuggestionPrompt({
prefix: 'ㅇㅋ 그럼 나도 ',
recentWrites: [
{ text: '야 내일 몇 시에 보기로 했지?', ageMs: 240_000 },
{ text: '나 3시쯤 강남역 도착할 듯', ageMs: 30_000 }
],
prefill: true
})
expect(prompt.text).toContain('[이 창에서 조금 전에 쓴 글 — 오래된 것부터]\n- (4분 전) 야 내일 몇 시에 보기로 했지?\n- (방금) 나 3시쯤 강남역 도착할 듯')
expect(prompt.factSource).toContain('3시쯤 강남역')
})
it('검색 페이지의 짧은 입력은 검색어로 잇게 한다', () => {
const prompt = buildSuggestionPrompt({ prefix: '서울 강남 파스타 ', appName: 'Chrome', windowTitle: 'Google', prefill: true })
expect(prompt.text).toContain('입력: 검색어입니다.')
expect(buildSuggestionPrompt({ prefix: '서울 강남 파스타 ', appName: 'Slack', windowTitle: '#food' }).text).not.toContain(
'입력: 검색어'
)
})
it('일기체(-다)는 반말과 구분된 평서체로 지시한다', () => {
const prompt = buildSuggestionPrompt({ prefix: '오늘은 진짜 피곤했다. 점심도 ', prefill: true })
expect(prompt.text).toContain('말투: 평서체')
})
it('이모지는 사용자가 쓸 때만 허용한다', () => {
expect(buildSuggestionPrompt({ prefix: '좋아요 👍 내일 ', prefill: true }).allowEmoji).toBe(true)
expect(buildSuggestionPrompt({ prefix: '좋아요 내일 ', prefill: true }).allowEmoji).toBe(false)
})
})