fix(desktop): prevent modifier key buffer resets, clipboard race on terminal accept, and redundant UIA settle snapshots

This commit is contained in:
Yun Chan 2026-10-31 04:19:53 +09:00
parent 6d909dd0e5
commit 41901c1ec5
10 changed files with 198 additions and 23 deletions

View file

@ -40,6 +40,7 @@ import {
isTerminalApp,
manhattanDistance,
mergeActivityBucket,
normalizeRequestPrefix,
rankFlowWindows,
recommendAppExclusion,
summarizeActivity,
@ -532,8 +533,6 @@ class InputTelemetryService extends EventEmitter {
// ── 이벤트 수집 ────────────────────────────────────────
private _handleKeyDown(event: UiohookKeyboardEvent): void {
// 합성 키도 화면을 바꾼다. 통계 제외 여부와 무관하게 이전 UIA 응답은 무효다.
this._inputRevision += 1
this._syncModifiers(event)
// Win32 SendInput(KEYEVENTF_UNICODE) 가 보내는 합성 유니코드 키는 uiohook 에서 keycode=0 으로 들어온다.
// 사용자 키스트로크나 IME 입력으로 처리하면 버퍼와 타이머를 교란하므로 즉시 무시한다.
@ -553,6 +552,7 @@ class InputTelemetryService extends EventEmitter {
vk === 0xa2 ||
vk === 0xa3
if (isExpectedProgrammaticKey) {
this._inputRevision += 1
this._programmaticKeys -= 1
if (this._programmaticKeys === 0) {
this._scheduleTextSnapshot()
@ -560,6 +560,24 @@ class InputTelemetryService extends EventEmitter {
return
}
}
// 순수 수정자 키(Ctrl/Alt/Shift/Win) 단독 눌림·키 반복은 화면 텍스트를 바꾸지 않는다.
// 여기서 _inputRevision·_lastKeyAt·스냅샷 타이머를 건드리면 수정자 키를 쥐고 있는 동안
// 진행 중 UIA 스냅샷이 버려지고 유휴 시간(idleMs)과 터미널 버퍼가 리셋된다.
if (vk !== null && classifyKeyStroke(vk, this._modifiers) === 'modifier') {
return
}
// D3RO Voice 전역 제안 탐색/수락 단축키(Ctrl+Alt+방향키/Enter/Space/Backspace)는
// OS globalShortcut 이 가로채므로 대상 앱 텍스트를 바꾸지 않는다.
const isSuggestionChord =
this._modifiers.ctrl &&
this._modifiers.alt &&
!this._modifiers.meta &&
(vk === 0x0d || vk === 0x20 || vk === 0x08 || (vk !== null && vk >= 0x25 && vk <= 0x28))
if (isSuggestionChord) {
return
}
// 실제 키 입력은 화면을 바꾼다 — 이전 UIA 응답은 무효다.
this._inputRevision += 1
this._registerInput(true)
const bucket = this._bucket()
// 한글·일본어 IME 가 켜져 있으면 Windows 는 글자 키를 VK_PROCESSKEY 로 넘기고, uiohook 은 그것을
@ -836,22 +854,27 @@ class InputTelemetryService extends EventEmitter {
}, INPUT_TELEMETRY_DEFAULTS.textSnapshotDebounceMs)
this._textTimer.unref?.()
// 제안 트리거 지연(기본 1000ms)이 스냅샷 디바운스(700ms)보다 크다. 스냅샷이
// 제안 트리거 지연(기본 600ms)이 스냅샷 디바운스(380ms)보다 크다. 스냅샷이
// 디바운스에만 돌면 "타이핑을 멈춘 뒤 N ms" 조건이 결코 충족되지 않아
// 제안이 영원히 요청되지 않는다(실측: debounce 로그만 반복). 그래서
// 트리거 지연을 넘긴 시점에 한 번 더 스냅샷을 돌려 게이트를 연다.
if (this._settleTimer) clearTimeout(this._settleTimer)
// 조합 중(한글은 멈출 때 거의 늘 조합 중이다)에 필요한 유휴 시간을 막 넘긴 순간에 찍는다 — 예전엔
// 지연+400ms(=1초)라 멈춘 뒤 제안이 그만큼 늦게 시작됐다(실측 2026-10-17: "빠릿하지 않다").
const settleDelay = Math.max(
INPUT_TELEMETRY_DEFAULTS.textSnapshotDebounceMs + 50,
Math.ceil((configGet('suggestionTriggerDelayMs') || SUGGESTION_DEFAULTS.triggerDelayMs) * COMPOSING_IDLE_MULTIPLIER) + 60
)
this._settleTimer = setTimeout(() => {
// 실제 글자/편집 입력이 있었고 제안이 켜져 있을 때만 트리거 지연을 넘긴 시점에 한 번 더 스냅샷을 돌린다.
if (this._settleTimer) {
clearTimeout(this._settleTimer)
this._settleTimer = null
void this._captureTextSnapshot()
}, settleDelay)
this._settleTimer.unref?.()
}
if ((!keyClass || TYPING_KEY_CLASSES.has(keyClass)) && configGet('suggestionEnabled') === true) {
// 조합 중(한글은 멈출 때 거의 늘 조합 중이다)에 필요한 유휴 시간을 막 넘긴 순간에 찍는다 — 예전엔
// 지연+400ms(=1초)라 멈춘 뒤 제안이 그만큼 늦게 시작됐다(실측 2026-10-17: "빠릿하지 않다").
const settleDelay = Math.max(
INPUT_TELEMETRY_DEFAULTS.textSnapshotDebounceMs + 50,
Math.ceil((configGet('suggestionTriggerDelayMs') || SUGGESTION_DEFAULTS.triggerDelayMs) * COMPOSING_IDLE_MULTIPLIER) + 60
)
this._settleTimer = setTimeout(() => {
this._settleTimer = null
void this._captureTextSnapshot()
}, settleDelay)
this._settleTimer.unref?.()
}
}
/**
@ -1141,6 +1164,21 @@ class InputTelemetryService extends EventEmitter {
}
this._lastContext = context
if (this._settleTimer) {
const minPrefixChars = configGet('suggestionMinPrefixChars') || SUGGESTION_DEFAULTS.minPrefixChars
const canTriggerSuggestion =
configGet('suggestionEnabled') === true &&
context.available &&
context.isEditable &&
!context.isPassword &&
context.editedSinceFocus &&
context.typedRecently &&
normalizeRequestPrefix(context.prefix).length + (context.isComposing ? 1 : 0) >= minPrefixChars
if (!canTriggerSuggestion) {
clearTimeout(this._settleTimer)
this._settleTimer = null
}
}
this.emit('typed-context', context)
// 진단 줄이 즉시 갱신되도록 상태 변경을 알린다 (키 입력마다가 아니라 스냅샷마다).
this._emitState()