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: remove /theme (system¤t) and double ctrl+c to exit
huanggawa81973c61efff
diff --git a/jiuwenclaw/cli/src/app-state.ts b/jiuwenclaw/cli/src/app-state.tsindex 910abf33de..fdc5736ca1 100644--- a/jiuwenclaw/cli/src/app-state.ts+++ b/jiuwenclaw/cli/src/app-state.ts@@ -132,6 +132,8 @@ export class CliPiAppState {version: "",};private workspaceDir: string = loadTuiWorkspaceDir();+ /** 当 closeUi 中 cancelBeforeExit 调 cancel({showNotice:false}) 时置 true,抑制 chat.interrupt_result 的 UI 通知。 */+ private suppressInterruptResult = false;private readonly eventDelegate: AppEventDelegate = {getConnectionStatus: () => this.connectionStatus,getSessionId: () => this.sessionId,@@ -203,6 +205,10 @@ export class CliPiAppState {safeFetchSessionTitle: (sessionId) => {this.safeFetchSessionTitle(sessionId);},+ getSuppressInterruptResult: () => this.suppressInterruptResult,+ clearSuppressInterruptResult: () => {+ this.suppressInterruptResult = false;+ },reportHistoryPageMeta: ({ totalPages }) => {if (typeof totalPages === "number" && Number.isFinite(totalPages) && totalPages > 0) {this.historyTotalPages = totalPages;@@ -631,7 +637,7 @@ readonly request = async <T = Record<string, unknown>>(return requestId;}- /** 向服务端请求中断当前 session 的任务;成功发送前不宣称“已中断”。 */+ /** 向服务端请求中断当前 session 的任务;成功发送前不宣称"已中断"。 */cancel(options?: { showNotice?: boolean }): boolean {if (this.connectionStatus !== "connected") {if (options?.showNotice !== false) {@@ -639,6 +645,9 @@ readonly request = async <T = Record<string, unknown>>(}return false;}+ if (options?.showNotice === false) {+ this.suppressInterruptResult = true;+ }const hadLocalWork = this.getSnapshot().cancellableWork;this.sendEventOnly("chat.interrupt", { intent: "cancel" });if (options?.showNotice !== false && hadLocalWork) {diff --git a/jiuwenclaw/cli/src/core/commands/builtins/theme.ts b/jiuwenclaw/cli/src/core/commands/builtins/theme.tsindex 082957fb85..b8a47f1dfd 100644--- a/jiuwenclaw/cli/src/core/commands/builtins/theme.ts+++ b/jiuwenclaw/cli/src/core/commands/builtins/theme.ts@@ -1,18 +1,18 @@import { addError, addInfo } from "../helpers.js";import { CommandKind, type SlashCommand } from "../types.js";-import { getThemeOptions } from "../../../ui/theme.js";+import type { ThemeName } from "../../../ui/theme.js";-const THEME_OPTIONS = getThemeOptions();+const DISPLAY_OPTIONS: readonly ["dark", "light"] = ["dark", "light"];export function createThemeCommand(): SlashCommand {return {name: "theme",description: "Change the theme",- usage: "/theme [system|dark|light]",+ usage: "/theme [dark|light]",example: "/theme dark",kind: CommandKind.BUILT_IN,takesArgs: true,- completion: async () => [...THEME_OPTIONS],+ completion: async () => [...DISPLAY_OPTIONS],action: (ctx, args) => {const value = args.trim().toLowerCase();if (!value) {@@ -20,26 +20,26 @@ export function createThemeCommand(): SlashCommand {addInfo(ctx.sessionId, `Current theme: ${ctx.themeName}`, "t", {view: "list",title: "Theme",- items: THEME_OPTIONS.map((option) => ({- label: option,- description: option === ctx.themeName ? "current" : undefined,+ items: DISPLAY_OPTIONS.map((option) => ({+ label:+ option === ctx.themeName ? `${option} (current)` : option,})),}),);return;}- if (!THEME_OPTIONS.includes(value as (typeof THEME_OPTIONS)[number])) {+ if (!DISPLAY_OPTIONS.includes(value as "dark" | "light")) {ctx.addItem(addError(ctx.sessionId,- `invalid theme "${value}". available: ${THEME_OPTIONS.join(", ")}`,+ `invalid theme "${value}". available: ${DISPLAY_OPTIONS.join(", ")}`,),);return;}- ctx.setThemeName(value as (typeof THEME_OPTIONS)[number]);+ ctx.setThemeName(value as ThemeName);ctx.addItem(addInfo(ctx.sessionId, `Theme set to ${value}`, "t"));},};diff --git a/jiuwenclaw/cli/src/core/event-handlers.ts b/jiuwenclaw/cli/src/core/event-handlers.tsindex a38c043a70..1a78043c68 100644--- a/jiuwenclaw/cli/src/core/event-handlers.ts+++ b/jiuwenclaw/cli/src/core/event-handlers.ts@@ -85,6 +85,9 @@ export interface AppEventDelegate {clearToolExecutionState(): void;/** 用户中断:将 running 的工具标为已结束,避免 TUI 继续转圈 */markRunningToolsInterrupted(): void;+ /** 退出前 cancel({showNotice:false}) 置 true,抑制 interrupt_result UI 通知。 */+ getSuppressInterruptResult(): boolean;+ clearSuppressInterruptResult(): void;pushHistoryEntry(entry: HistoryItem): void;scheduleHistoryFlush(): void;safeRestoreHistory(sessionId: string): void;@@ -616,6 +619,11 @@ export function handleIncomingFrame(delegate: AppEventDelegate, frame: EventFramcase "chat.interrupt_result": {const intent = typeof payload.intent === "string" ? payload.intent : "cancel";if (intent === "cancel") {+ const suppressed = delegate.getSuppressInterruptResult();+ if (suppressed) {+ delegate.clearSuppressInterruptResult();+ return true;+ }const success = payload.success !== false;const message =typeof payload.message === "string" && payload.message.trim()diff --git a/jiuwenclaw/cli/src/index.ts b/jiuwenclaw/cli/src/index.tsindex 4d284bdbfe..3d2a809e3b 100644--- a/jiuwenclaw/cli/src/index.ts+++ b/jiuwenclaw/cli/src/index.ts@@ -104,8 +104,15 @@ tui.setFocus(screen);process.on("SIGTERM", () => {void closeUi(0);});-// 与 TUI 内 Ctrl+C 一致:SIGINT 始终尝试中断当前 session 的任务,不退出进程(退出用 /exit、SIGTERM 等)。+// 双击 Ctrl+C 退出:第一次中断当前任务,1 秒内再按一次退出进程。+let lastInterruptTime = 0;process.on("SIGINT", () => {+ const now = Date.now();+ if (now - lastInterruptTime < 1000) {+ void closeUi(0);+ return;+ }+ lastInterruptTime = now;screen?.interruptTask();});process.on("uncaughtException", (error) => {diff --git a/jiuwenclaw/cli/src/ui/app-screen.ts b/jiuwenclaw/cli/src/ui/app-screen.tsindex 7b2a7d4230..4a5cecd0c4 100644--- a/jiuwenclaw/cli/src/ui/app-screen.ts+++ b/jiuwenclaw/cli/src/ui/app-screen.ts@@ -427,6 +427,7 @@ export class AppScreen implements Component, Focusable {const handled = handleAppScreenKeyInput(data, {interruptTask: () => this.interruptTask(),+ exitApp: () => this.exit(),toggleTodos: () => {this.showTodos = !this.showTodos;this.tui.requestRender();diff --git a/jiuwenclaw/cli/src/ui/keymap.ts b/jiuwenclaw/cli/src/ui/keymap.tsindex 88482d5db9..730bfc2951 100644--- a/jiuwenclaw/cli/src/ui/keymap.ts+++ b/jiuwenclaw/cli/src/ui/keymap.ts@@ -2,12 +2,15 @@ import { matchesKey } from "@mariozechner/pi-tui";/*** 快捷键约定(Ctrl+C):- * 用户在 CLI/TUI 按下 Ctrl+C 时,始终尝试向服务端发送 `chat.interrupt`,- * 强制结束当前 session 正在运行的任务;不退出 CLI/TUI。+ * 第一次按下尝试向服务端发送 `chat.interrupt`,中断当前任务;+ * 1 秒内再次按下则退出 CLI/TUI。*/+let lastInterruptTime = 0;+export interface AppScreenKeymapDelegate {interruptTask(): void;+ exitApp(): void;toggleTodos(): void;toggleTeamPanel(): void;toggleTranscript(): void;@@ -25,8 +28,14 @@ export const APP_SCREEN_KEY_BINDINGS: readonly KeyBinding[] = [{key: "ctrl+c",label: "ctrl+c",- description: "请求强制结束当前任务(不退出 CLI)",+ description: "中断任务;连按两次退出",run: (delegate) => {+ const now = Date.now();+ if (now - lastInterruptTime < 1000) {+ delegate.exitApp();+ return;+ }+ lastInterruptTime = now;delegate.interruptTask();},},