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): When running /compact, pressing Esc, the process cannot be interrupted

jingjinduod557c976c128
diff --git a/jiuwenswarm/channels/tui/frontend/src/app-state.ts b/jiuwenswarm/channels/tui/frontend/src/app-state.ts
index 750dd24c12..d18315978b 100644
--- a/jiuwenswarm/channels/tui/frontend/src/app-state.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/app-state.ts
@@ -131,6 +131,8 @@ export interface AppSnapshot {
threshold: number;
message: string;
}[];
+ /** 当前正在执行的命令名称,用于追踪不可中断命令。 */
+ runningCommand: string | null;
}
function formatElapsed(ms: number): string {
@@ -270,6 +272,8 @@ export class CliPiAppState {
private interruptRequested = false;
/** 当前正在执行的斜杠命令 WS 请求 ID,用于 Ctrl+C 时立即取消。 */
private activeCommandRequestId: string | null = null;
+ /** 当前正在执行的命令名称,用于追踪不可中断命令。 */
+ private runningCommand: string | null = null;
private lastVisibleUserRequest: VisibleUserRequest | null = null;
/** 保存 askQuestions 之前的 streamingState,用于在对话框关闭后恢复。 */
private streamingStateBeforeQuestion: StreamingState | null = null;
@@ -688,6 +692,7 @@ export class CliPiAppState {
sessionTitle: this.sessionTitle,
statusLineText: this.statusLineText,
memoryWarnings: [...this.memoryWarnings],
+ runningCommand: this.runningCommand,
};
}
@@ -718,6 +723,12 @@ export class CliPiAppState {
this.interruptRequested = false;
}
+ /** Set the currently running command name (for tracking uninterruptible commands) */
+ setRunningCommand(name: string | null): void {
+ this.runningCommand = name;
+ this.emitChange();
+ }
+
/** Check if there's a server task running (for deciding whether to send chat.interrupt) */
hasServerTask(): boolean {
const snapshot = this.getSnapshot();
@@ -792,6 +803,7 @@ export class CliPiAppState {
// Use cancellableWork which covers all stages: processing, running tools, subtasks, team working
return snapshot.cancellableWork;
},
+ setRunningCommand: (name: string | null) => this.setRunningCommand(name),
};
}
diff --git a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/compact.ts b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/compact.ts
index 4249b74f42..828d9bd215 100644
--- a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/compact.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/compact.ts
@@ -20,6 +20,7 @@ export function createCompactCommand(): SlashCommand {
kind: CommandKind.BUILT_IN,
takesArgs: false,
action: async (ctx) => {
+ ctx.setRunningCommand?.("compact"); // 标记当前命令开始
try {
const payload = await ctx.request<CompactResponse>(
"command.compact",
@@ -66,6 +67,8 @@ export function createCompactCommand(): SlashCommand {
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
ctx.addItem(addError(ctx.sessionId, `compact failed: ${message}`));
+ } finally {
+ ctx.setRunningCommand?.(null); // 清除标记(finally 确保无论成功/失败/异常都会清除)
}
},
};
diff --git a/jiuwenswarm/channels/tui/frontend/src/core/commands/types.ts b/jiuwenswarm/channels/tui/frontend/src/core/commands/types.ts
index 0ca230b7a1..1dafc902a3 100644
--- a/jiuwenswarm/channels/tui/frontend/src/core/commands/types.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/core/commands/types.ts
@@ -60,6 +60,8 @@ export interface CommandContext {
isInterruptRequested: () => boolean;
/** Clear local interrupt flag (for long-running commands to reset after handling interrupt) */
clearInterruptRequested: () => void;
+ /** Set the currently running command name (for tracking uninterruptible commands) */
+ setRunningCommand?: (name: string | null) => void;
connectionStatus: ConnectionStatus;
mode: ClientMode;
setMode: (mode: ClientMode) => void;
diff --git a/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts b/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
index c2138dac36..ee3bdc77f3 100644
--- a/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
@@ -78,6 +78,8 @@ const ENABLE_MOUSE_TRACKING = "\x1b[?1000h\x1b[?1006h";
const DISABLE_MOUSE_TRACKING = "\x1b[?1000l\x1b[?1006l";
const TRANSCRIPT_WHEEL_SCROLL_LINES = 3;
const SWARM_WORKFLOW_AGENT_PREVIEW_LIMIT = 8;
+// 不可中断的命令列表(ESC 按下时显示提示)
+const UNINTERRUPTIBLE_COMMANDS = ["compact"];
const PERMISSION_TOOL_RE = /工具\s+`([^`]+)`\s+需要授权/;
const CONFIRM_TOOL_RE = /(?:Tool|工具)\s*:\s*`([^`]+)`/i;
const CONFIRM_ACTION_RE = /\*\*(?:Agent wants to|Tool `[^`]+` requires your approval)([^*]*)\*\*/i;
@@ -1052,6 +1054,21 @@ export class AppScreen implements Component, Focusable {
return;
}
+ // 检查不可中断命令列表(ESC 显示提示)
+ if (!pendingQuestion && snapshot.runningCommand && UNINTERRUPTIBLE_COMMANDS.includes(snapshot.runningCommand) && matchesKey(data, "escape") && !hasOverlay) {
+ this.transientNotice = `${snapshot.runningCommand} 命令执行中,无法中断`;
+ if (this.transientNoticeTimer) {
+ clearTimeout(this.transientNoticeTimer);
+ }
+ this.transientNoticeTimer = setTimeout(() => {
+ this.transientNotice = null;
+ this.transientNoticeTimer = null;
+ this.tui.requestRender();
+ }, 3500);
+ this.tui.requestRender();
+ return;
+ }
+
if (this.startupPromptList !== null && matchesKey(data, "ctrl+c")) {
this.startupPromptList.handleInput(data);
this.tui.requestRender();