@narumitw/pi-btw 0.63.2 → 0.63.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,6 +14,46 @@ The [retained shared matrix and verification record](https://github.com/narumiru
14
14
 
15
15
  Pi's official [TUI guidance](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/docs/tui.md) advises against a second terminal renderer. BTW intentionally deviates: a second TUI instance exists, but only one renderer actively owns the shared terminal. Extracting the physical lifecycle into Kit does not make that deviation officially supported or remove private layout access from BTW.
16
16
 
17
+ ## Command and workspace lifetimes
18
+
19
+ A split workspace releases Pi's command wait after its first non-overlay root mounts, receives focus, and requests rendering.
20
+ This lets Pi's idle loop consume main-pane submissions without closing BTW; the streaming path keeps Pi's normal steering behavior.
21
+ The initial manager and fullscreen-only workspaces remain modal.
22
+
23
+ Command completion does not end resource ownership.
24
+ `BtwSessionLifetime` still tracks the complete UI task and drains retained thread work and settings writes during shutdown.
25
+ The active-command guard lasts through cleanup, so another invocation cannot overlap a manager, startup, live workspace, or restoration.
26
+ Startup failures propagate through Pi's command handler; failures after split readiness produce sanitized notifications only while the owning session remains active.
27
+ Cancellation or a late factory cannot publish readiness for a disposed workspace.
28
+
29
+ ```mermaid
30
+ sequenceDiagram
31
+ participant Pi as Pi idle input loop
32
+ participant Command as BTW command
33
+ participant View as BTW split workspace
34
+ participant Lifetime as BTW session lifetime
35
+ Pi->>Command: Await command handler
36
+ Command->>Lifetime: Track complete workspace task
37
+ Command->>View: Mount and focus split
38
+ View-->>Command: onSplitReady, once
39
+ Command-->>Pi: Command wait completes
40
+ Pi->>Pi: Consume main submissions normally
41
+ Note over View,Lifetime: Workspace task stays session-owned
42
+ alt Normal close
43
+ View->>View: Restore terminal owner
44
+ View-->>Lifetime: Complete workspace task
45
+ else Session shutdown
46
+ Lifetime->>View: Abort and drain owned work
47
+ View->>View: Restore only when permitted
48
+ View-->>Lifetime: Cleanup completes
49
+ end
50
+ ```
51
+
52
+ `btw-lifecycle.test.ts` verifies the separate completion boundaries, startup overlap, error visibility, stale readiness, and shutdown draining.
53
+ `fullscreen-ui.test.ts` verifies readiness ordering, one-time publication, failed mounting/focus, and late factories.
54
+ The local-provider `fullscreen-handoff-smoke.py` routes verify main-provider completion before BTW closes and use `agent_settled` for the final-idle barrier.
55
+ These checks retain the private-layout and shared-terminal limits below; readiness is not a physical-terminal visual acceptance signal.
56
+
17
57
  ## Evidence boundary
18
58
 
19
59
  The alignment review uses Pi core source at commit `1402973a9` and the installed public runtime.
package/docs/workflows.md CHANGED
@@ -74,6 +74,9 @@ Pi's search and keyboard viewport controls apply to the active pane.
74
74
  The mouse wheel scrolls the pane under the pointer without moving keyboard focus, and a narrow terminal returns focus to the visible side thread.
75
75
  A branch selected through **Start from main thread tree…** supplies side-model context but does not replace the active main thread shown in the other pane.
76
76
  The main agent may keep running, and the main pane redraws its progress while either pane is active.
77
+ With **Main focus**, submissions start or steer main work without closing BTW, whether BTW opened while the main agent was idle or responding.
78
+ The initial manager and fullscreen-only workspaces remain modal; a split releases the command wait only after its first view mounts and receives focus.
79
+ Another `/btw` invocation warns instead of opening an overlapping manager or workspace, including during startup and cleanup.
77
80
  Submit each question with Pi's effective editor submission binding, Enter by default; successful prior questions and answers remain available to the side model.
78
81
 
79
82
  Drag the primary mouse button across the transcript to select text.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narumitw/pi-btw",
3
- "version": "0.63.2",
3
+ "version": "0.63.3",
4
4
  "description": "Pi extension that adds a /btw side-question command.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/btw.ts CHANGED
@@ -216,6 +216,7 @@ export default function btw(pi: ExtensionAPI, dependencies: BtwExtensionDependen
216
216
  const subscribeMainThreadUpdates = registerBtwMainThreadUpdates(pi);
217
217
  const getLifetime = registerBtwSessionLifetimes(pi);
218
218
  const sessionThreads = new WeakMap<BtwSessionLifetime, Map<string, BtwThreadState>>();
219
+ const activeCommands = new WeakSet<BtwSessionLifetime>();
219
220
  let nextThreadNumber = 1;
220
221
  const listResumeThreads = (resumableThreads: Map<string, BtwThreadState>): BtwResumeThreadSummary[] =>
221
222
  [...resumableThreads.values()]
@@ -234,15 +235,39 @@ export default function btw(pi: ExtensionAPI, dependencies: BtwExtensionDependen
234
235
  if (lifetime.signal.aborted) return Promise.resolve();
235
236
  const commandCtx = Object.create(ctx) as ExtensionCommandContext;
236
237
  Object.defineProperty(commandCtx, "signal", { value: lifetime.signal, configurable: true });
237
- return lifetime.track(
238
- handleCommand(args, commandCtx, lifetime).catch((error: unknown) => {
239
- if (!lifetime.signal.aborted) throw error;
240
- }),
238
+ if (activeCommands.has(lifetime)) {
239
+ notifySafely(commandCtx, "A /btw workspace is already open; close it before opening another.", "warning");
240
+ return Promise.resolve();
241
+ }
242
+ activeCommands.add(lifetime);
243
+ const ready = Promise.withResolvers<void>();
244
+ let released = false;
245
+ const task = lifetime.track(
246
+ handleCommand(args, commandCtx, lifetime, () => {
247
+ if (lifetime.signal.aborted) return;
248
+ released = true;
249
+ ready.resolve();
250
+ })
251
+ .catch((error: unknown) => {
252
+ if (lifetime.signal.aborted) return;
253
+ if (!released) throw error;
254
+ // Pi no longer awaits this task after the split releases its command.
255
+ notifySafely(commandCtx, `Pi BTW: ${formatError(error)}`, "error");
256
+ })
257
+ .finally(() => activeCommands.delete(lifetime)),
241
258
  );
259
+ // Pi's idle input loop awaits command completion. Keep the full UI task
260
+ // session-owned, but release that wait only after a split is mounted.
261
+ return Promise.race([task, ready.promise]);
242
262
  },
243
263
  });
244
264
 
245
- async function handleCommand(args: string, ctx: ExtensionCommandContext, lifetime: BtwSessionLifetime) {
265
+ async function handleCommand(
266
+ args: string,
267
+ ctx: ExtensionCommandContext,
268
+ lifetime: BtwSessionLifetime,
269
+ releaseMainInput: () => void,
270
+ ) {
246
271
  let resumableThreads = sessionThreads.get(lifetime);
247
272
  if (!resumableThreads) {
248
273
  resumableThreads = new Map();
@@ -338,6 +363,7 @@ export default function btw(pi: ExtensionAPI, dependencies: BtwExtensionDependen
338
363
  canRestoreParent: lifetime.canRestoreParent,
339
364
  copyOnSelect: effectiveFullscreenCopyOnSelect(settings),
340
365
  layout: effectiveBtwLayout(settings),
366
+ ...(effectiveBtwLayout(settings) !== "fullscreen" ? { onSplitReady: releaseMainInput } : {}),
341
367
  sidePaneRatio: effectiveBtwSidePaneRatio(settings),
342
368
  persistSidePaneRatio: (ratio, signal) =>
343
369
  updateBtwSettings({ sidePaneRatio: ratio }, { signal }).then(() => undefined),
@@ -40,6 +40,8 @@ type FocusInspectableTui = TUI & {
40
40
 
41
41
  export interface BtwFullscreenOptions {
42
42
  signal?: AbortSignal;
43
+ /** The first split root is mounted and focused; its command can release Pi's input loop. */
44
+ onSplitReady?(): void;
43
45
  canRestoreParent?(): boolean;
44
46
  keybindings?: BtwKeybindingOverrides;
45
47
  copyOnSelect?: boolean;
@@ -154,6 +156,7 @@ class BtwFullscreenHost<T> implements Component {
154
156
  private removeHardCancelListener: (() => void) | undefined;
155
157
  private removeUpstreamAbortListener: (() => void) | undefined;
156
158
  private started = false;
159
+ private splitReady = false;
157
160
  private disposed = false;
158
161
  private finished = false;
159
162
  private parentRestorePromise: Promise<void> | undefined;
@@ -652,6 +655,16 @@ class BtwFullscreenHost<T> implements Component {
652
655
  }
653
656
  fullscreen.setFocus(component);
654
657
  fullscreen.requestRender();
658
+ if (
659
+ splitPane &&
660
+ !this.splitReady &&
661
+ !this.disposed &&
662
+ !this.finished &&
663
+ !this.lifetimeController.signal.aborted
664
+ ) {
665
+ this.splitReady = true;
666
+ this.options.onSplitReady?.();
667
+ }
655
668
  }
656
669
  })
657
670
  .catch(fail);