From f358b7effc17203245851acdc87caff9df8f196f Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 30 Apr 2026 13:42:07 -0700 Subject: [PATCH 1/2] Fix Ctrl-C behavior in BTW composer --- extensions/btw.ts | 11 +++++++++ tests/btw.runtime.test.ts | 51 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/extensions/btw.ts b/extensions/btw.ts index f25db6b..4ca7e61 100644 --- a/extensions/btw.ts +++ b/extensions/btw.ts @@ -1083,6 +1083,17 @@ class BtwOverlayComponent extends Container implements Focusable { const originalHandleInput = this.input.handleInput.bind(this.input); this.input.handleInput = (data: string) => { + if (keybindings.matches(data, "app.clear")) { + if (this.input.getValue().length > 0) { + this.input.setValue(""); + this.tui.requestRender(); + return; + } + + this.onDismissCallback(); + return; + } + if (keybindings.matches(data, "tui.select.cancel")) { this.onDismissCallback(); return; diff --git a/tests/btw.runtime.test.ts b/tests/btw.runtime.test.ts index acd8599..04ce4b5 100644 --- a/tests/btw.runtime.test.ts +++ b/tests/btw.runtime.test.ts @@ -453,6 +453,7 @@ function createHarness( italic: (text: string) => string; bold: (text: string) => string; }; + keybindingMatches?: (data: string, id: string) => boolean; } = {}, ) { const commands = new Map(); @@ -473,7 +474,7 @@ function createHarness( bold: (text: string) => text, }; const keybindings = { - matches: (_data: string, _id: string) => false, + matches: options.keybindingMatches ?? ((_data: string, _id: string) => false), }; const sessionManager = { @@ -975,6 +976,54 @@ describe("btw runtime behavior", () => { expect(record.session.prompt).not.toHaveBeenCalled(); }); + it("clears a non-empty BTW composer on app.clear without dismissing the overlay", async () => { + const harness = createHarness([], { + keybindingMatches: (_data, id) => id === "app.clear" || id === "tui.select.cancel", + }); + + await harness.runSessionStart(); + await harness.command("btw", ""); + + const overlay = harness.latestOverlayComponent(); + overlay.input.setValue("draft follow-up"); + overlay.input.handleInput("\x03"); + + expect(overlay.input.getValue()).toBe(""); + expect(harness.overlayHandles.at(-1)?.hideCalls).toBe(0); + }); + + it("dismisses the BTW overlay on app.clear when the composer is empty", async () => { + const harness = createHarness([], { + keybindingMatches: (_data, id) => id === "app.clear" || id === "tui.select.cancel", + }); + + await harness.runSessionStart(); + await harness.command("btw", ""); + + const overlay = harness.latestOverlayComponent(); + overlay.input.setValue(""); + overlay.input.handleInput("\x03"); + await flushAsyncWork(); + + expect(harness.overlayHandles.at(-1)?.hideCalls).toBe(1); + }); + + it("still dismisses the BTW overlay on select cancel", async () => { + const harness = createHarness([], { + keybindingMatches: (_data, id) => id === "tui.select.cancel", + }); + + await harness.runSessionStart(); + await harness.command("btw", ""); + + const overlay = harness.latestOverlayComponent(); + overlay.input.setValue("draft follow-up"); + overlay.input.handleInput("\x1b"); + await flushAsyncWork(); + + expect(harness.overlayHandles.at(-1)?.hideCalls).toBe(1); + }); + it("aborts, disposes, and unsubscribes the active BTW sub-session when Escape dismisses mid-stream", async () => { const harness = createHarness(); const blocking = createBlockingToolStream(); From b5137470bb027a575be284fbd1a159aa79baade5 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 30 Apr 2026 13:56:17 -0700 Subject: [PATCH 2/2] Bump version to 0.3.8 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7c61507..3579bd7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pi-btw", - "version": "0.3.7", + "version": "0.3.8", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pi-btw", - "version": "0.3.7", + "version": "0.3.8", "license": "MIT", "devDependencies": { "typescript": "^6.0.2", diff --git a/package.json b/package.json index 6ff2711..94ee137 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pi-btw", - "version": "0.3.7", + "version": "0.3.8", "description": "A pi extension for parallel side conversations with /btw", "type": "module", "license": "MIT",