The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(tui): double-Esc interrupts the active turn
Brooklyn Nicholsone49e3598234e
diff --git a/ui-tui/src/__tests__/useInputHandlers.test.ts b/ui-tui/src/__tests__/useInputHandlers.test.tsindex d06ae23c26e..ac1417aa77a 100644--- a/ui-tui/src/__tests__/useInputHandlers.test.ts+++ b/ui-tui/src/__tests__/useInputHandlers.test.ts@@ -8,6 +8,7 @@ import {dismissSensitivePrompt,handleIdleHotkeyExit,resolveCtrlCComposerAction,+ resolveDoubleEscAction,shouldDetachEditedHistoryInput,shouldFallThroughForScroll} from '../app/useInputHandlers.js'@@ -99,6 +100,28 @@ describe('resolveCtrlCComposerAction — draft wins over interrupt', () => {})})+describe('resolveDoubleEscAction — double-Esc interrupts only a busy, draft-free turn (#62478)', () => {+ it('interrupts the running turn when the composer is empty', () => {+ expect(resolveDoubleEscAction({ busy: true, hasDraft: false, hasSession: true })).toBe('interrupt')+ })++ it('clears a draft instead of interrupting, even mid-stream', () => {+ expect(resolveDoubleEscAction({ busy: true, hasDraft: true, hasSession: true })).toBe('clear')+ })++ it('does nothing while idle with an empty composer (single-Esc conventions unchanged)', () => {+ expect(resolveDoubleEscAction({ busy: false, hasDraft: false, hasSession: true })).toBe('none')+ })++ it('does not interrupt a busy session that has no sid yet', () => {+ expect(resolveDoubleEscAction({ busy: true, hasDraft: false, hasSession: false })).toBe('none')+ })++ it('keeps clearing an idle draft (existing discard convention)', () => {+ expect(resolveDoubleEscAction({ busy: false, hasDraft: true, hasSession: true })).toBe('clear')+ })+})+describe('handleIdleHotkeyExit', () => {it('exits in normal terminals', () => {const actions = { die: vi.fn(), sys: vi.fn() }diff --git a/ui-tui/src/app/useInputHandlers.ts b/ui-tui/src/app/useInputHandlers.tsindex 95fde3d48db..13edfae92ee 100644--- a/ui-tui/src/app/useInputHandlers.ts+++ b/ui-tui/src/app/useInputHandlers.ts@@ -85,6 +85,30 @@ export function resolveCtrlCComposerAction(opts: {return 'exit'}+export type DoubleEscAction = 'clear' | 'interrupt' | 'none'++/**+ * Double-Esc (#62478): while a turn runs with no draft in the composer, the+ * second Esc interrupts it — the same path Ctrl+C and /stop use. A single Esc+ * never cancels work, and the idle composer keeps the existing discard-only+ * behaviour, so a draft always clears instead of interrupting.+ */+export function resolveDoubleEscAction(opts: {+ busy: boolean+ hasDraft: boolean+ hasSession: boolean+}): DoubleEscAction {+ if (opts.hasDraft) {+ return 'clear'+ }++ if (opts.busy && opts.hasSession) {+ return 'interrupt'+ }++ return 'none'+}+/*** Approval / clarify / confirm overlays mount their own `useInput` handlers* for the in-prompt keys (arrows, numbers, Enter, sometimes Esc). The global@@ -402,19 +426,46 @@ export function useInputHandlers(ctx: InputHandlerContext): InputHandlerResult {const live = getUiState()if (key.escape) {- const now = Date.now()- const isDouble = now - lastEscRef.current <= DOUBLE_ESC_MS+ // Escape-configured voice bindings (ctrl/alt/super+escape PTT) must win+ // over the double-Esc interrupt, exactly as they win over the generic+ // Esc handlers below — two quick PTT presses are a stop/start pair,+ // not an interrupt.+ if (isVoiceToggleKey(key, ch, voice.recordKey)) {+ lastEscRef.current = 0+ } else {+ const now = Date.now()+ const isDouble = now - lastEscRef.current <= DOUBLE_ESC_MS++ lastEscRef.current = isDouble ? 0 : now++ if (isDouble) {+ const escAction = resolveDoubleEscAction({+ busy: live.busy,+ hasDraft: Boolean(cState.input || cState.inputBuf.length),+ hasSession: Boolean(live.sid)+ })- lastEscRef.current = isDouble ? 0 : now+ // Draft discard keeps its above-isBlocked placement (#116443): the+ // prompt overlays must not swallow discarding an unsent draft. The+ // interrupt does NOT — an approval/clarify overlay owns Esc/Ctrl+C+ // until answered, so it only fires with no overlay up.+ if (escAction === 'interrupt' && live.sid && !isBlocked) {+ return turnController.interruptTurn({+ appendMessage: actions.appendMessage,+ gw: gateway.gw,+ sid: live.sid,+ sys: actions.sys+ })+ }++ if (escAction === 'clear') {+ if (cState.input.trim()) {+ cActions.pushHistory(cState.input)+ }- if (isDouble && (cState.input || cState.inputBuf.length)) {- if (cState.input.trim()) {- cActions.pushHistory(cState.input)+ return cActions.clearIn()+ }}-- cActions.clearIn()-- return}}