Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix(tui): single-press Ctrl+C/Esc interrupts askUserQuestion approval box; drop Ctrl+D

ldstyle8c96540bef814
diff --git a/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts b/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
index b2536339d2..0778b08422 100644
--- a/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
@@ -1315,8 +1315,6 @@ export class AppScreen implements Component, Focusable {
private questionPreviewMap: Map<string, string> | null = null;
private questionOptionRows: QuestionOptionRowHit[] = [];
private otherInputMode = false;
- private ctrlCPendingForQuestion = false;
- private ctrlCPendingForQuestionTimer: ReturnType<typeof setTimeout> | null = null;
private resumeSessionList: ResumeSessionListState | null = null;
private modelList: ModelListState | null = null;
private toolSelector: ToolSelectorState | null = null;
@@ -1567,7 +1565,6 @@ export class AppScreen implements Component, Focusable {
this.transientNoticeTimer = null;
}
this.clearEscClearPending();
- this.clearCtrlCPendingForQuestion();
if (this.animationTimer) {
clearInterval(this.animationTimer);
this.animationTimer = null;
@@ -1576,14 +1573,6 @@ export class AppScreen implements Component, Focusable {
this.unsubscribe();
}
- private clearCtrlCPendingForQuestion(): void {
- this.ctrlCPendingForQuestion = false;
- if (this.ctrlCPendingForQuestionTimer) {
- clearTimeout(this.ctrlCPendingForQuestionTimer);
- this.ctrlCPendingForQuestionTimer = null;
- }
- }
-
/** 清除 ESC 双击清空输入框的待触发状态及其提示定时器。 */
private clearEscClearPending(): void {
this.escClearPending = false;
@@ -2264,42 +2253,14 @@ export class AppScreen implements Component, Focusable {
return;
}
- // Ctrl+C during pending question: first press shows hint, second press within 3s exits
- if (pendingQuestion && matchesKey(data, "ctrl+c")) {
- if (this.ctrlCPendingForQuestion) {
- this.clearCtrlCPendingForQuestion();
- this.transientNotice = null;
- this.exit();
- return;
- }
- this.ctrlCPendingForQuestion = true;
- this.transientNotice = "Press Ctrl+C again to exit";
- this.ctrlCPendingForQuestionTimer = setTimeout(() => {
- this.ctrlCPendingForQuestion = false;
- this.ctrlCPendingForQuestionTimer = null;
- this.transientNotice = null;
- this.tui.requestRender();
- }, 3000);
- this.tui.requestRender();
- return;
- }
-
- // Ctrl+D during pending question: same double-press mechanism as Ctrl+C
- if (pendingQuestion && matchesKey(data, "ctrl+d")) {
- if (this.ctrlCPendingForQuestion) {
- this.clearCtrlCPendingForQuestion();
- this.transientNotice = null;
- this.interruptTask();
- return;
- }
- this.ctrlCPendingForQuestion = true;
- this.transientNotice = "Press Ctrl+D again to cancel";
- this.ctrlCPendingForQuestionTimer = setTimeout(() => {
- this.ctrlCPendingForQuestion = false;
- this.ctrlCPendingForQuestionTimer = null;
- this.transientNotice = null;
- this.tui.requestRender();
- }, 3000);
+ // 审批框(pendingQuestion)激活时:Ctrl+C 或 Esc 按一次即中断任务并关闭审批框,
+ // 不再需要双击,也不再退出 TUI 进程;Ctrl+D 不再响应。
+ if (
+ pendingQuestion &&
+ (matchesKey(data, "ctrl+c") || matchesKey(data, "escape"))
+ ) {
+ this.transientNotice = null;
+ this.interruptTask();
this.tui.requestRender();
return;
}
@@ -3296,7 +3257,6 @@ export class AppScreen implements Component, Focusable {
this.editor.setText(this.draftBeforeQuestion);
}
this.draftBeforeQuestion = "";
- this.clearCtrlCPendingForQuestion();
}
this.syncEditorSubmitState(snapshot);
this.syncTeamPanelSelection(snapshot);
@@ -7168,9 +7128,6 @@ export class AppScreen implements Component, Focusable {
),
);
}
- if (this.ctrlCPendingForQuestion) {
- lines.push(padToWidth(palette.status.warning("Press Ctrl+C again to exit"), width));
- }
return lines;
}
diff --git a/jiuwenswarm/channels/tui/frontend/tests/run-tests.mjs b/jiuwenswarm/channels/tui/frontend/tests/run-tests.mjs
index 7488f7e35f..43a0e6fb2e 100644
--- a/jiuwenswarm/channels/tui/frontend/tests/run-tests.mjs
+++ b/jiuwenswarm/channels/tui/frontend/tests/run-tests.mjs
@@ -101,12 +101,15 @@ let pendingQuestionInterruptCount = 0;
let pendingQuestionRenderCount = 0;
Object.assign(pendingQuestionScreen, {
activeQuestionIndex: 0,
- ctrlCPendingForQuestion: false,
- ctrlCPendingForQuestionTimer: null,
- transientNotice: null,
+ transientNotice: "stale hint",
startupPromptList: null,
fileViewerState: null,
diffViewerState: null,
+ // Provide a minimal question list so Ctrl+D falls through to the
+ // approval input handler (which ignores it) instead of crashing.
+ questionList: { handleInput: () => undefined, getSelectedItem: () => null },
+ questionCheckboxList: null,
+ otherInputMode: false,
state: {
recordActivity: () => undefined,
getSnapshot: () => ({
@@ -130,12 +133,26 @@ Object.assign(pendingQuestionScreen, {
},
});
+// Ctrl+C on the approval box interrupts the task (single press) and does NOT exit
pendingQuestionScreen.handleInput("\x03");
-assert.equal(pendingQuestionScreen.transientNotice, "Press Ctrl+C again to exit");
+assert.equal(pendingQuestionInterruptCount, 1);
assert.equal(pendingQuestionExitCount, 0);
-pendingQuestionScreen.handleInput("\x03");
-assert.equal(pendingQuestionExitCount, 1);
-assert.equal(pendingQuestionInterruptCount, 0);
-assert.equal(pendingQuestionRenderCount, 1);
+assert.equal(pendingQuestionScreen.transientNotice, null);
+
+// Esc likewise interrupts the task (single press)
+pendingQuestionScreen.handleInput("\x1b");
+assert.equal(pendingQuestionInterruptCount, 2);
+assert.equal(pendingQuestionExitCount, 0);
+assert.equal(pendingQuestionScreen.transientNotice, null);
+
+// Ctrl+D is no longer supported on the approval box: does nothing
+const renderCountBeforeCtrlD = pendingQuestionRenderCount;
+pendingQuestionScreen.handleInput("\x04");
+assert.equal(pendingQuestionInterruptCount, 2);
+assert.equal(pendingQuestionExitCount, 0);
+// Ctrl+D did not trigger an interrupt/exit; it may or may not request a
+// render depending on the list handler, but it must not interrupt or exit.
+assert.ok(pendingQuestionInterruptCount === 2 && pendingQuestionExitCount === 0);
+console.log("ctrl+d render requests:", pendingQuestionRenderCount - renderCountBeforeCtrlD);
console.log("frontend tests passed");