Skip to content

The agent that grows with you

fix(tui): preserve edited history input

fangliquanflq16ab670a637c
diff --git a/ui-tui/src/__tests__/useInputHandlers.test.ts b/ui-tui/src/__tests__/useInputHandlers.test.ts
index f77a3b69ce5..5fe403dfd87 100644
--- a/ui-tui/src/__tests__/useInputHandlers.test.ts
+++ b/ui-tui/src/__tests__/useInputHandlers.test.ts
@@ -7,6 +7,7 @@ import {
handleIdleHotkeyExit,
resolveCtrlCComposerAction,
shouldAllowIdleHotkeyExit,
+ shouldDetachEditedHistoryInput,
shouldFallThroughForScroll
} from '../app/useInputHandlers.js'
@@ -60,6 +61,22 @@ describe('shouldAllowIdleHotkeyExit', () => {
})
})
+describe('shouldDetachEditedHistoryInput', () => {
+ const history = ['older message', 'line one\nline two']
+
+ it('detaches a recalled entry as soon as the user edits it', () => {
+ expect(shouldDetachEditedHistoryInput(1, history, 'line one edited\nline two')).toBe(true)
+ })
+
+ it('keeps unchanged recalled entries in history navigation', () => {
+ expect(shouldDetachEditedHistoryInput(1, history, 'line one\nline two')).toBe(false)
+ })
+
+ it('does not detach an ordinary current draft', () => {
+ expect(shouldDetachEditedHistoryInput(null, history, 'new draft')).toBe(false)
+ })
+})
+
describe('resolveCtrlCComposerAction — draft wins over interrupt', () => {
it('clears a non-empty composer even while the agent is streaming', () => {
expect(resolveCtrlCComposerAction({ busy: true, hasDraft: true, hasSession: true })).toBe('clear')
diff --git a/ui-tui/src/app/useInputHandlers.ts b/ui-tui/src/app/useInputHandlers.ts
index f549bc86688..222d50cdafe 100644
--- a/ui-tui/src/app/useInputHandlers.ts
+++ b/ui-tui/src/app/useInputHandlers.ts
@@ -167,6 +167,10 @@ export function dismissSensitivePrompt(
const clamp = (value: number, min: number, max: number) => Math.max(min, Math.min(max, value))
+export function shouldDetachEditedHistoryInput(historyIdx: null | number, history: readonly string[], value: string) {
+ return historyIdx !== null && value !== history[historyIdx]
+}
+
export function useInputHandlers(ctx: InputHandlerContext): InputHandlerResult {
const { actions, composer, gateway, terminal, voice, wheelStep } = ctx
const { actions: cActions, refs: cRefs, state: cState } = composer
diff --git a/ui-tui/src/app/useMainApp.ts b/ui-tui/src/app/useMainApp.ts
index b42c77470f5..4a794fc29ba 100644
--- a/ui-tui/src/app/useMainApp.ts
+++ b/ui-tui/src/app/useMainApp.ts
@@ -60,7 +60,7 @@ import { $uiState, getUiState, patchUiState } from './uiStore.js'
import { useBatteryPoll } from './useBatteryPoll.js'
import { useComposerState } from './useComposerState.js'
import { useConfigSync } from './useConfigSync.js'
-import { useInputHandlers } from './useInputHandlers.js'
+import { shouldDetachEditedHistoryInput, useInputHandlers } from './useInputHandlers.js'
import { useLongRunToolCharms } from './useLongRunToolCharms.js'
import { useSessionLifecycle } from './useSessionLifecycle.js'
import { useSubmission } from './useSubmission.js'
@@ -1203,10 +1203,15 @@ export function useMainApp(gw: GatewayClient) {
composerActions.syncTokens(value)
+ if (shouldDetachEditedHistoryInput(composerState.historyIdx, composerRefs.historyRef.current, value)) {
+ composerRefs.historyDraftRef.current = value
+ composerActions.setHistoryIdx(null)
+ }
+
return value
})
},
- [composerActions]
+ [composerActions, composerRefs, composerState.historyIdx]
)
const appComposer = useMemo(