Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-ctrl-s-steer-input-history.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch
---

修复 Ctrl-S steer 直接发送的消息不写入输入历史的问题,避免按 ↑ 无法召回。
14 changes: 13 additions & 1 deletion apps/kimi-code/src/tui/controllers/editor-keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ export interface EditorKeyboardHost {
harness?: KimiHarness | undefined;

handleUserInput(text: string): void;
/**
* Append one submitted input to the persistent input history (↑ recall).
* `handleUserInput` writes history itself; paths that dispatch editor text
* directly (Ctrl-S steering the draft) must call this explicitly.
*/
persistInputHistory(text: string): void;
readonly btwPanelController: BtwPanelController;
readonly skillCommandMap: Map<string, string>;
steerMessage(session: Session, input: readonly SteerInputItem[]): void;
Expand Down Expand Up @@ -401,7 +407,13 @@ export class EditorKeyboardController {
host.state.queuedMessages = queued.filter(
(m, index) => m.mode === 'bash' || (firstBundle !== -1 && index >= firstBundle),
);
if (!editorIsBash && !editorHasInlineSkills && firstBundle === -1) editor.setText('');
if (!editorIsBash && !editorHasInlineSkills && firstBundle === -1) {
// A steered editor draft bypasses handleUserInput (and its input-
// history write) — persist it here, or ↑ recall loses Ctrl-S-sent
// input. Queued items were already persisted at submit time.
if (text.length > 0) host.persistInputHistory(text);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Persist expanded paste contents instead of the marker

When the Ctrl-S draft contains a large terminal paste, editor.getText() returns a collapsed value such as [paste #1 +20 lines], while getExpandedText() contains the actual pasted input. This call therefore saves only the temporary marker, and the following editor.setText('') clears the paste registry; recalling the new history entry later produces an unresolvable literal marker instead of the steered draft. Persist the expanded editor text, matching the normal Enter submission path.

Useful? React with 👍 / 👎.

editor.setText('');
}
for (const run of runs) {
if (run.kind === 'text') {
host.steerMessage(session, run.items);
Expand Down
2 changes: 1 addition & 1 deletion apps/kimi-code/src/tui/kimi-tui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,7 @@ export class KimiTUI {
}
}

private async persistInputHistory(text: string): Promise<void> {
async persistInputHistory(text: string): Promise<void> {
const trimmed = text.trim();
if (trimmed.length === 0) return;
if (trimmed === this.lastHistoryContent) return;
Expand Down
64 changes: 62 additions & 2 deletions apps/kimi-code/test/tui/controllers/editor-keyboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,11 @@ describe('EditorKeyboardController Ctrl-S steering', () => {
queued: Array<Record<string, unknown>>;
engineV2?: boolean;
skillCommandMap?: Map<string, string>;
model?: string;
}) {
const steerMessage = vi.fn();
const steerSkillActivation = vi.fn();
const persistInputHistory = vi.fn();
const updateQueueDisplay = vi.fn();
const setText = vi.fn();
const editor: Record<string, ((...args: never[]) => unknown) | undefined> = {
Expand All @@ -493,7 +495,7 @@ describe('EditorKeyboardController Ctrl-S steering', () => {
editor,
activeDialog: null,
queuedMessages: options.queued,
appState: { streamingPhase: 'waiting', isCompacting: false, model: 'k2' },
appState: { streamingPhase: 'waiting', isCompacting: false, model: options.model ?? 'k2' },
footer: { setTransientHint: vi.fn() },
ui: { requestRender: vi.fn() },
},
Expand All @@ -502,8 +504,10 @@ describe('EditorKeyboardController Ctrl-S steering', () => {
skillCommandMap: options.skillCommandMap ?? new Map(),
steerMessage,
steerSkillActivation,
persistInputHistory,
updateQueueDisplay,
validateMediaCapabilities: vi.fn(() => true),
releaseStagingMedia: vi.fn(),
showError: vi.fn(),
track: vi.fn(),
btwPanelController: {
Expand All @@ -513,7 +517,7 @@ describe('EditorKeyboardController Ctrl-S steering', () => {
} as unknown as EditorKeyboardHost;
const controller = new EditorKeyboardController(
host,
undefined as unknown as ImageAttachmentStore,
{ get: vi.fn(() => undefined), retainFileIds: vi.fn() } as unknown as ImageAttachmentStore,
);
controller.install();
const onCtrlS = editor['onCtrlS'];
Expand All @@ -524,11 +528,67 @@ describe('EditorKeyboardController Ctrl-S steering', () => {
setText,
steerMessage,
steerSkillActivation,
persistInputHistory,
updateQueueDisplay,
onCtrlS: onCtrlS as () => void,
};
}

it('persists a steered editor draft into input history', () => {
const { host, setText, steerMessage, persistInputHistory, onCtrlS } = createCtrlSHarness({
editorText: 'fresh steer',
queued: [],
});

onCtrlS();

expect(steerMessage).toHaveBeenCalledWith(host.session, [
{ text: 'fresh steer', parts: undefined, imageAttachmentIds: undefined, stagingPaths: [] },
]);
expect(persistInputHistory).toHaveBeenCalledWith('fresh steer');
expect(setText).toHaveBeenCalledWith('');
});

it('does not re-persist queued items — they were persisted at submit time', () => {
const { steerMessage, persistInputHistory, onCtrlS } = createCtrlSHarness({
editorText: '',
queued: [{ text: 'queued text', agentId: 'main' }],
});

onCtrlS();

expect(steerMessage).toHaveBeenCalled();
expect(persistInputHistory).not.toHaveBeenCalled();
});

it('does not persist the draft when steering is rejected and the draft stays', () => {
const { setText, steerMessage, persistInputHistory, onCtrlS } = createCtrlSHarness({
editorText: 'fresh steer',
queued: [],
model: '',
});

onCtrlS();

expect(steerMessage).not.toHaveBeenCalled();
expect(persistInputHistory).not.toHaveBeenCalled();
expect(setText).not.toHaveBeenCalled();
});

it('does not persist an inline-skill draft left in the editor for the grouped path', () => {
const { setText, persistInputHistory, onCtrlS } = createCtrlSHarness({
editorText: 'check /skill:review',
queued: [],
engineV2: true,
skillCommandMap: new Map([['skill:review', 'review']]),
});

onCtrlS();

expect(persistInputHistory).not.toHaveBeenCalled();
expect(setText).not.toHaveBeenCalled();
});

it('steers text as a message, skill items as activations, and keeps bash queued', () => {
const { host, steerMessage, steerSkillActivation, updateQueueDisplay, onCtrlS } =
createCtrlSHarness({
Expand Down
Loading