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-frontend): preserve btw history navigation
ldstyle85d110ef95069
diff --git a/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts b/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.tsindex a36cb562f0..1d48345966 100644--- a/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts+++ b/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts@@ -3603,16 +3603,21 @@ export class AppScreen implements Component, Focusable {return true;}- // Enter / Space / ctrl+c 关闭 btw 浮层(对齐 Esc:关闭 overlay + 取消进行中的 btw 请求)- if (- matchesKey(data, "enter") ||- matchesKey(data, "return") ||- matchesKey(data, "space") ||- matchesKey(data, "ctrl+c")- ) {+ // 输入框为空时,Enter / Space 关闭 btw 浮层;输入框有内容时保留原有 composer 行为。+ // ctrl+c 始终优先关闭浮层,但只在确有 btw 请求进行中时发送中断。+ const dismissWithCtrlC = matchesKey(data, "ctrl+c");+ const dismissWithEnterOrSpace =+ this.editor.getText().length === 0 &&+ (matchesKey(data, "enter") ||+ matchesKey(data, "return") ||+ matchesKey(data, "space"));+ if (dismissWithCtrlC || dismissWithEnterOrSpace) {+ const hasPendingBtwRequest = this.state.getSnapshot().btwPendingQuestion !== null;this.state.clearBtwOverlay();this.btwOverlayScrollOffset = 0;- this.state.requestLocalInterrupt();+ if (hasPendingBtwRequest) {+ this.state.requestLocalInterrupt();+ }this.state.setBtwActive(false);this.tui.requestRender();return true;diff --git a/jiuwenswarm/channels/tui/frontend/tests/run-tests.mjs b/jiuwenswarm/channels/tui/frontend/tests/run-tests.mjsindex 246f4be79a..aefdfbbc90 100644--- a/jiuwenswarm/channels/tui/frontend/tests/run-tests.mjs+++ b/jiuwenswarm/channels/tui/frontend/tests/run-tests.mjs@@ -301,6 +301,68 @@ assert.equal(assert.equal(stripAnsi(btwPulseDim.join("\n")), stripAnsi(btwPulseBright.join("\n")));assert.notEqual(btwPulseDim.join("\n"), btwPulseBright.join("\n"));+function handleBtwOverlayKey(data, { composerText = "", pendingQuestion = null } = {}) {+ let clears = 0;+ let interrupts = 0;+ let deletes = 0;+ const navigations = [];+ const screen = Object.create(AppScreen.prototype);+ Object.assign(screen, {+ btwOverlayScrollOffset: 0,+ editor: { getText: () => composerText },+ state: {+ getSnapshot: () => ({ btwPendingQuestion: pendingQuestion }),+ clearBtwOverlay: () => {+ clears += 1;+ },+ requestLocalInterrupt: () => {+ interrupts += 1;+ },+ navigateBtw: (direction) => {+ navigations.push(direction);+ },+ deleteCurrentBtwEntry: () => {+ deletes += 1;+ },+ setBtwActive: () => undefined,+ },+ tui: {+ terminal: { rows: 40 },+ requestRender: () => undefined,+ },+ });++ return {+ handled: screen.handleBtwOverlayScrollInput(data),+ clears,+ interrupts,+ navigations,+ deletes,+ };+}++// Enter/Space retain composer behavior when it has text; the new dismiss and+// paging keys must coexist with existing history navigation and deletion.+const btwKeyCases = [+ ["space with input", " ", { composerText: "/btw" }, { handled: false, clears: 0 }],+ ["enter with input", "\r", { composerText: "/btw next" }, { handled: false, clears: 0 }],+ ["enter dismiss", "\r", {}, { handled: true, clears: 1, interrupts: 0 }],+ ["space dismiss", " ", {}, { handled: true, clears: 1 }],+ ["ctrl+c completed", "\x03", {}, { handled: true, interrupts: 0 }],+ ["ctrl+c pending", "\x03", { pendingQuestion: "next" }, { handled: true, interrupts: 1 }],+ ["history left", "\x1b[D", { composerText: "draft" }, { navigations: [-1], clears: 0 }],+ ["history right", "\x1b[C", { composerText: "draft" }, { navigations: [1], clears: 0 }],+ ["delete", "x", { composerText: "draft" }, { deletes: 1, clears: 0 }],+ ["page up", "\x10", { composerText: "draft" }, { handled: true, clears: 0 }],+ ["page down", "\x0e", { composerText: "draft" }, { handled: true, clears: 0 }],+];+for (const [name, data, options, expected] of btwKeyCases) {+ const result = handleBtwOverlayKey(data, options);+ for (const [key, value] of Object.entries(expected)) {+ assert.deepEqual(result[key], value, `${name}: ${key}`);+ }+}+const slashCommands = AppScreen.prototype.buildSlashCommands.call({commands: {getAll: () => [