pi-stereo-view 0.1.21 → 0.1.23

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,27 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.1.23 - 2026-11-21
6
+
7
+ ### Fixed
8
+
9
+ - Pi-Bolt no longer closes with "Pi's assistant content layout is not supported" after a reply. Pi-Bolt 1.1.6 and later free the parts of finished replies they have drawn; split view now asks Pi-Bolt to restore them before showing the reply. Thanks to [@Unk-now](https://github.com/Unk-now) for the detailed report ([#99](https://github.com/alexshpunt/pi-stereo-view/issues/99)).
10
+ - An error in split view no longer closes Pi. Split view turns off, and Pi shows its own history until the next reload.
11
+
12
+ ### Added
13
+
14
+ - When split view turns off after an error, or cannot start in a Pi version it does not support, a panel above the editor names the problem. **Open issue** opens a GitHub issue form with the error, its stack and the versions filled in; nothing is sent until you submit it. **Copy report** copies the same text, and **Close** hides the panel.
15
+
16
+ ### Changed
17
+
18
+ - Combined history no longer reads the split's content index on every frame.
19
+
20
+ ## 0.1.22 - 2026-11-21
21
+
22
+ ### Fixed
23
+
24
+ - Ctrl+G no longer crashes Pi when opening an external editor from split view. Pi returns to the same layout with the edited draft when the editor closes. Thanks to [@okuuva](https://github.com/okuuva) for the fix ([#120](https://github.com/alexshpunt/pi-stereo-view/pull/120)).
25
+
5
26
  ## 0.1.21 - 2026-11-19
6
27
 
7
28
  ### Added
package/README.md CHANGED
@@ -198,7 +198,8 @@ Your layout, panel order, sizes, compact Activity choice, timestamp and copy-but
198
198
  - Tested with Pi 1.1.0. Requires Node.js 22.19 or newer.
199
199
  - Regular mode shows one combined history.
200
200
  - If the terminal is too small, history temporarily combines without forgetting your split.
201
- - If your Pi version cannot display the split, normal history stays visible and a warning explains the problem.
201
+ - If your Pi version cannot display the split, or the split hits an error, Pi keeps working with its normal history. A panel above the editor names the problem and offers a prefilled GitHub issue (**Open issue**) or the same report as text (**Copy report**). Nothing is sent until you submit the issue yourself.
202
+ - Also tested with [Pi-Bolt](https://github.com/opensec-git/Pi-Bolt) 1.1.7.
202
203
 
203
204
  ## License
204
205
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-stereo-view",
3
- "version": "0.1.21",
3
+ "version": "0.1.23",
4
4
  "type": "module",
5
5
  "description": "Keep Pi conversation separate from tool output and agent activity.",
6
6
  "license": "MIT",
package/src/content.ts CHANGED
@@ -30,6 +30,8 @@ interface NativeAssistant extends Container {
30
30
  lastMessage?: { content: { type: string; text?: string; thinking?: string }[] };
31
31
  contentIsStale?: boolean;
32
32
  buildContent?(message: NonNullable<NativeAssistant["lastMessage"]>): void;
33
+ isCompacted?(): boolean;
34
+ thaw?(): void;
33
35
  setHideThinkingBlock(hidden: boolean): void;
34
36
  }
35
37
 
@@ -83,6 +85,12 @@ function assistant(component: Component): NativeAssistant | undefined {
83
85
  (native.lastMessage !== undefined && !Array.isArray(native.lastMessage.content))) {
84
86
  throw new Error("Pi's assistant content metadata is not supported");
85
87
  }
88
+ // Pi-Bolt releases the children of settled messages it drew itself and keeps only their lines.
89
+ // Restore them through the owner, as Pi-Bolt does before it draws such a message again.
90
+ if (typeof native.isCompacted === "function" && native.isCompacted()) {
91
+ if (typeof native.thaw !== "function") throw new Error("Pi's compacted assistant content is not supported");
92
+ native.thaw();
93
+ }
86
94
  // Pi-Bolt builds streamed children lazily. Synchronize the real owner before
87
95
  // indexing or cloning it, so a pane cannot rebuild both content kinds itself.
88
96
  if (native.contentIsStale === true) {
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@ import { defaults, loadPreferences, savePreferences, type Preferences } from "./
7
7
  import { beforeFirstFrame } from "./startup.ts";
8
8
  import { observeNativeEditor } from "./native-editor.ts";
9
9
  import { NestedCalls } from "./nested-calls.ts";
10
+ import { ProblemReporter } from "./report.ts";
10
11
 
11
12
  const DELAYS = [1, 2, 3, 5, 10, 30];
12
13
 
@@ -146,6 +147,7 @@ export default async function transcript(pi: ExtensionAPI): Promise<void> {
146
147
  host = tui;
147
148
  timestamps = new TranscriptTimestamps(session);
148
149
  nested.restore(session.getBranch());
150
+ const problems = new ProblemReporter(ui, copyToClipboard);
149
151
  layout = new TranscriptLayout(preferences, () => ui.theme,
150
152
  message => ui.notify(message, "warning"), () => persist(ui), timestamps,
151
153
  () => { void openSettings(ui).catch(error => ui.notify(String(error), "error")); }, text => {
@@ -159,7 +161,7 @@ export default async function transcript(pi: ExtensionAPI): Promise<void> {
159
161
  }
160
162
  void copyToClipboard(text).then(() => ui.notify("Block sent to clipboard.", "info"),
161
163
  error => ui.notify("Could not copy block: " + String(error), "error"));
162
- }, () => pi.getAllTools(), nested, () => nativeEditor.get(tui));
164
+ }, () => pi.getAllTools(), nested, () => nativeEditor.get(tui), problem => problems.show(problem));
163
165
  try { ensureLayout(); }
164
166
  catch (error) {
165
167
  layout.dispose();
package/src/layout.ts CHANGED
@@ -12,6 +12,7 @@ import type { TranscriptTimestamps } from "./timestamps.ts";
12
12
  import { PANEL_SEARCH_ROWS, PanelSearch, PanelSearchShortcut, type SearchHit } from "./search.ts";
13
13
  import { SplitSurface } from "./surface.ts";
14
14
  import { sameValues } from "./render-cache.ts";
15
+ import type { Problem } from "./report.ts";
15
16
 
16
17
  type NativeTui = TUI & {
17
18
  layoutRoot?: Container;
@@ -250,8 +251,32 @@ export class TranscriptLayout {
250
251
  private readonly getTools: () => readonly ToolInfo[] = () => [],
251
252
  private readonly nested = new NestedCalls(),
252
253
  private readonly getEditor: () => Component | undefined = () => undefined,
254
+ /** Show a problem that stops the split, with a way to report it. */
255
+ private readonly report: (problem: Problem) => void = problem => this.warn("pi-stereo-view " + problem.summary +
256
+ (problem.error === undefined ? "" : ": " + (problem.error instanceof Error ? problem.error.message : String(problem.error)))),
253
257
  ) {}
254
258
 
259
+ /** Refuse a Pi layout the split cannot use; Pi keeps its own history view. */
260
+ private refuse(reason: string): void {
261
+ this.report({ summary: "split is unavailable: " + reason });
262
+ }
263
+
264
+ /**
265
+ * Stop the split after an unexpected error instead of letting it reach Pi's render loop, which would end Pi.
266
+ * The next layout pass shows Pi's own history and dock.
267
+ */
268
+ private fail(error: unknown): void {
269
+ if (this.failed) return;
270
+ this.failed = true;
271
+ this.searchShortcut.dispose();
272
+ this.disposeDocuments?.();
273
+ queueMicrotask(() => {
274
+ this.closeSearch(false);
275
+ this.report({ summary: "split disabled after an error", error });
276
+ this.host?.requestRender();
277
+ });
278
+ }
279
+
255
280
  private button(label: () => string, action: () => void, enabled = (): boolean => true, background?: () => Color): Component {
256
281
  const button = new MouseRegion(memoized(width => [width, this.theme(), this.preferences.buttonStyle, label(), enabled(), background?.()],
257
282
  width => new Text(this.theme().style((this.preferences.buttonStyle === "icons" ? "[ " + label() + " ]" : "[" + label() + "]").padEnd(width), {
@@ -276,7 +301,7 @@ export class TranscriptLayout {
276
301
  }
277
302
  const host = tui as unknown as NativeTui;
278
303
  if (typeof host.getFocusedComponent !== "function") {
279
- this.warn("pi-stereo-view split is unavailable: Pi's focus API is not supported.");
304
+ this.refuse("Pi's focus API is not supported.");
280
305
  return;
281
306
  }
282
307
  if (host.layoutRoot === this.mounted && this.host) {
@@ -286,7 +311,7 @@ export class TranscriptLayout {
286
311
  mounted.preserveForeignChildren(original as VStack);
287
312
  this.dispose();
288
313
  this.rejectedRoots.add(original);
289
- this.warn("pi-stereo-view split is unavailable: Pi's fullscreen layout is not supported.");
314
+ this.refuse("Pi's fullscreen layout is not supported.");
290
315
  return;
291
316
  }
292
317
  const root = host.layoutRoot;
@@ -294,7 +319,7 @@ export class TranscriptLayout {
294
319
  if (root && this.rejectedRoots.has(root)) return;
295
320
  if (!root || root.constructor.name !== "VStack" || root.children.length !== 2) {
296
321
  if (root) this.rejectedRoots.add(root);
297
- this.warn("pi-stereo-view split is unavailable: Pi's fullscreen layout is not supported.");
322
+ this.refuse("Pi's fullscreen layout is not supported.");
298
323
  return;
299
324
  }
300
325
  const [transcript, dock] = root.children;
@@ -305,7 +330,7 @@ export class TranscriptLayout {
305
330
  document?.constructor.name !== "Container" || owner.child !== document || document.children.length !== 3 ||
306
331
  !Array.isArray((document.children[2] as Container)?.children)) {
307
332
  this.rejectedRoots.add(root);
308
- this.warn("pi-stereo-view split is unavailable: Pi's history document is not supported.");
333
+ this.refuse("Pi's history document is not supported.");
309
334
  return;
310
335
  }
311
336
  // Route only the known native dock shape. Keep the original untouched for fallback.
@@ -386,6 +411,8 @@ export class TranscriptLayout {
386
411
  return pass.shown;
387
412
  };
388
413
  const evaluate = ({ width, height }: { width: number; height: number }): boolean => {
414
+ // Width-only stack rendering during external-editor handoff has no viewport height bound.
415
+ height = Math.min(height, Math.max(1, host.terminal.rows));
389
416
  const previousHeight = historyHeight;
390
417
  const candidate = !!projectedDock && (widgetsPresent() || dialogPresent()) && dockUnchanged() && !this.failed &&
391
418
  this.preferences.mode === "split" && this.preferences.zoom !== "chat";
@@ -441,10 +468,7 @@ export class TranscriptLayout {
441
468
  return true;
442
469
  } catch (error) {
443
470
  projectSurface = false;
444
- this.failed = true;
445
- this.searchShortcut.dispose();
446
- this.disposeDocuments?.();
447
- queueMicrotask(() => this.warn("pi-stereo-view split disabled: " + (error as Error).message));
471
+ this.fail(error);
448
472
  return false;
449
473
  }
450
474
  };
@@ -603,6 +627,7 @@ export class TranscriptLayout {
603
627
  const pane = this.searchPane();
604
628
  return pane === "chat" ? this.chat : pane === "activity" ? this.activity : undefined;
605
629
  },
630
+ failed: error => this.fail(error),
606
631
  });
607
632
  surface.setModels([columns, rows, activityPane, chatPane]);
608
633
  this.surface = surface;
@@ -610,10 +635,19 @@ export class TranscriptLayout {
610
635
  { component: toolbar, basis: "auto", shrink: 0, visible: () => {
611
636
  // Root visibility is evaluated once at the start of each native layout pass.
612
637
  pass = undefined;
613
- this.timestamps.beginFrame();
614
- index.beginFrame();
615
- activityDocument.beginFrame(true);
616
- chatDocument.beginFrame(true);
638
+ // An error here would reach Pi's render loop and end Pi; stop the split instead.
639
+ try {
640
+ this.timestamps.beginFrame();
641
+ // Combined history draws Pi's own document, so the shared index waits until the split is shown again.
642
+ // Pi-Bolt can then keep releasing the settled messages it draws itself.
643
+ if (this.preferences.mode === "split" && !this.failed) {
644
+ index.beginFrame();
645
+ activityDocument.beginFrame(true);
646
+ chatDocument.beginFrame(true);
647
+ }
648
+ } catch (error) {
649
+ this.fail(error);
650
+ }
617
651
  return true;
618
652
  } },
619
653
  { component: {
package/src/report.ts ADDED
@@ -0,0 +1,183 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { VERSION, type Theme } from "@earendil-works/pi-coding-agent";
4
+ import { truncateToWidth, visibleWidth, wrapTextWithAnsi, type Component, type TUI, type TuiMouseEvent } from "@earendil-works/pi-tui";
5
+
6
+ export const ISSUES_URL = "https://github.com/alexshpunt/pi-stereo-view/issues";
7
+ /** GitHub rejects longer new-issue links; long stacks lose their last frames first. */
8
+ const MAX_URL_LENGTH = 7000;
9
+ const MAX_STACK_LINES = 15;
10
+ const WIDGET = "pi-stereo-view-problem";
11
+
12
+ /** Something that stopped the split: an unexpected error, or a Pi layout the extension cannot use. */
13
+ export interface Problem {
14
+ /** What happened, in a few words, for the user. */
15
+ summary: string;
16
+ error?: unknown;
17
+ }
18
+
19
+ export interface ProblemReport {
20
+ title: string;
21
+ /** Issue body with the error, its stack and versions. */
22
+ body: string;
23
+ /** New-issue link with the title and body filled in. */
24
+ url: string;
25
+ }
26
+
27
+ function extensionVersion(): string {
28
+ try {
29
+ const value: unknown = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
30
+ const version = (value as { version?: unknown }).version;
31
+ return typeof version === "string" ? version : "unknown";
32
+ } catch {
33
+ return "unknown";
34
+ }
35
+ }
36
+
37
+ /** Pi's version, whether it is the Pi-Bolt build, the runtime and the platform. */
38
+ function hostDescription(): string {
39
+ const bolt = /pi-bolt/i.test(process.execPath) ? " (Pi-Bolt)" : "";
40
+ const runtime = process.versions.bun ? `Bun ${process.versions.bun}` : `Node.js ${process.versions.node}`;
41
+ return `Pi ${VERSION}${bolt}, ${runtime}, ${process.platform}-${process.arch}`;
42
+ }
43
+
44
+ const errorMessage = (error: unknown): string => error instanceof Error ? error.message : error === undefined ? "" : String(error);
45
+
46
+ /** Stack frames without the user's home folder, which appears in every installed extension path. */
47
+ function stackFrames(error: unknown): string[] {
48
+ if (!(error instanceof Error) || !error.stack) return [];
49
+ const home = homedir();
50
+ return error.stack.split("\n").slice(1).map(line => line.trim()).filter(Boolean)
51
+ .map(line => home ? line.replaceAll(home, "~") : line).slice(0, MAX_STACK_LINES);
52
+ }
53
+
54
+ /** Build the issue a user can review and submit; nothing is sent automatically. */
55
+ export function problemReport(problem: Problem): ProblemReport {
56
+ const message = errorMessage(problem.error);
57
+ const title = truncateToWidth(message || problem.summary, 100, "…");
58
+ const frames = stackFrames(problem.error);
59
+ const body = (lines: string[]): string => [
60
+ "### What happened",
61
+ problem.summary,
62
+ "",
63
+ ...(message ? ["### Error", "```text", message, ...lines, "```", ""] : []),
64
+ "### Environment",
65
+ `- pi-stereo-view ${extensionVersion()}`,
66
+ `- ${hostDescription()}`,
67
+ "",
68
+ "### What I was doing",
69
+ "<!-- For example: streaming a reply, switching to Combined, resizing the terminal. -->",
70
+ "",
71
+ ].join("\n");
72
+ const link = (text: string): string =>
73
+ `${ISSUES_URL}/new?title=${encodeURIComponent(title)}&body=${encodeURIComponent(text)}`;
74
+ let shown = frames;
75
+ while (shown.length && link(body(shown)).length > MAX_URL_LENGTH) shown = shown.slice(0, -1);
76
+ return { title, body: body(frames), url: link(body(shown)) };
77
+ }
78
+
79
+ const hyperlink = (url: string, text: string): string => `\x1b]8;;${url}\x1b\\${text}\x1b]8;;\x1b\\`;
80
+
81
+ type Action = "open" | "copy" | "close";
82
+ const ACTIONS: { action: Action; label: string }[] = [
83
+ { action: "open", label: "[Open issue]" },
84
+ { action: "copy", label: "[Copy report]" },
85
+ { action: "close", label: "[Close]" },
86
+ ];
87
+
88
+ /**
89
+ * Widget above the editor that names the problem and offers a prefilled GitHub issue. It stays until closed,
90
+ * because a short notification is easy to miss while the split silently falls back to combined history.
91
+ */
92
+ export class ProblemPanel implements Component {
93
+ private actionsRow = -1;
94
+ private readonly spans: { action: Action; start: number; end: number }[] = [];
95
+
96
+ constructor(
97
+ private readonly problem: Problem,
98
+ private readonly report: ProblemReport,
99
+ private readonly theme: Theme,
100
+ private readonly act: (action: Action) => void,
101
+ ) {}
102
+
103
+ render(width: number): string[] {
104
+ const theme = this.theme;
105
+ const message = errorMessage(this.problem.error);
106
+ const inner = Math.max(1, width - 3);
107
+ const wrap = (text: string): string[] => wrapTextWithAnsi(text, inner).map(line => " " + line);
108
+ const lines = [
109
+ truncateToWidth(" " + theme.fg("warning", "⚠ ") + theme.bold("pi-stereo-view " + this.problem.summary), width),
110
+ ...(message ? wrap(theme.fg("muted", message)) : []),
111
+ ...wrap(theme.fg("dim", "Pi keeps working with its own history view. Please report this so it can be fixed:")),
112
+ truncateToWidth(" " + hyperlink(ISSUES_URL, theme.fg("accent", ISSUES_URL)), width),
113
+ ];
114
+ this.spans.length = 0;
115
+ let column = 3;
116
+ let row = " ";
117
+ for (const { action, label } of ACTIONS) {
118
+ const text = action === "open" ? hyperlink(this.report.url, theme.fg("accent", label)) : theme.fg("accent", label);
119
+ this.spans.push({ action, start: column, end: column + visibleWidth(label) });
120
+ row += text + " ";
121
+ column += visibleWidth(label) + 1;
122
+ }
123
+ this.actionsRow = lines.length;
124
+ lines.push(truncateToWidth(row, width));
125
+ return lines;
126
+ }
127
+
128
+ handleMouse(event: TuiMouseEvent): { handled: true; render?: boolean } | { capture: true } | undefined {
129
+ if (event.button !== "left" || event.y !== this.actionsRow) return undefined;
130
+ const span = this.spans.find(candidate => event.x >= candidate.start && event.x < candidate.end);
131
+ if (!span) return undefined;
132
+ // Like Pi's own buttons: capture the press, act on the click that follows its release.
133
+ if (event.type === "press") return { capture: true };
134
+ if (event.type === "click") {
135
+ this.act(span.action);
136
+ return { handled: true, render: true };
137
+ }
138
+ return { handled: true };
139
+ }
140
+
141
+ invalidate(): void {}
142
+ }
143
+
144
+ /** Show one problem at a time and never reopen a problem the user closed in this session. */
145
+ export class ProblemReporter {
146
+ private readonly closed = new Set<string>();
147
+ private current?: string;
148
+
149
+ constructor(private readonly ui: {
150
+ setWidget(key: string, content: ((tui: TUI, theme: Theme) => Component) | undefined): void;
151
+ notify(message: string, type?: "info" | "warning" | "error"): void;
152
+ }, private readonly copy: (text: string) => Promise<void>) {}
153
+
154
+ show(problem: Problem): void {
155
+ const key = problem.summary + "\n" + errorMessage(problem.error);
156
+ if (this.closed.has(key) || this.current === key) return;
157
+ this.current = key;
158
+ const report = problemReport(problem);
159
+ this.ui.setWidget(WIDGET, (tui, theme) => new ProblemPanel(problem, report, theme, action => {
160
+ if (action === "close") {
161
+ this.closed.add(key);
162
+ this.clear();
163
+ return;
164
+ }
165
+ if (action === "open") {
166
+ const open = Reflect.get(tui, "openUrl") as ((url: string) => void) | undefined;
167
+ if (typeof open === "function") {
168
+ try { open.call(tui, report.url); return; } catch { /* Fall back to copying the link. */ }
169
+ }
170
+ void this.copy(report.url).then(() => this.ui.notify("Issue link copied to the clipboard.", "info"),
171
+ error => this.ui.notify("Could not copy the issue link: " + String(error), "error"));
172
+ return;
173
+ }
174
+ void this.copy(report.body).then(() => this.ui.notify("Problem report copied to the clipboard.", "info"),
175
+ error => this.ui.notify("Could not copy the problem report: " + String(error), "error"));
176
+ }));
177
+ }
178
+
179
+ clear(): void {
180
+ this.current = undefined;
181
+ this.ui.setWidget(WIDGET, undefined);
182
+ }
183
+ }
package/src/surface.ts CHANGED
@@ -277,6 +277,8 @@ export interface SplitSurfaceOptions {
277
277
  height(): number;
278
278
  /** Panel receiving keyboard scrolling and the follow-end indicator. */
279
279
  active(): ScrollView | undefined;
280
+ /** An error while painting or dispatching the panels; it must not reach Pi's render loop, which would end Pi. */
281
+ failed?(error: unknown): void;
280
282
  }
281
283
 
282
284
  type SelectionApi = Record<"hasActiveSelection" | "copyActiveSelectionToClipboard" | "resetTextSelection", (...args: never[]) => unknown>;
@@ -322,6 +324,17 @@ export class SplitSurface extends Container {
322
324
  }
323
325
 
324
326
  override render(width: number): string[] {
327
+ try {
328
+ return this.layoutFrame(width);
329
+ } catch (error) {
330
+ if (!this.options.failed) throw error;
331
+ this.frame = undefined;
332
+ this.options.failed(error);
333
+ return [];
334
+ }
335
+ }
336
+
337
+ private layoutFrame(width: number): string[] {
325
338
  const model = this.options.model();
326
339
  this.syncHostSelection();
327
340
  if (!model) {
@@ -523,7 +536,15 @@ export class SplitSurface extends Container {
523
536
 
524
537
  override handleMouse(event: TuiMouseEvent): Dispatched | undefined {
525
538
  this.lastEvent = event;
526
- const result = this.mouse(event) as (TuiMouseEventResult & Partial<Dispatched>) | undefined;
539
+ let result: (TuiMouseEventResult & Partial<Dispatched>) | undefined;
540
+ try {
541
+ result = this.mouse(event) as typeof result;
542
+ } catch (error) {
543
+ if (!this.options.failed) throw error;
544
+ this.frame = undefined;
545
+ this.options.failed(error);
546
+ return undefined;
547
+ }
527
548
  if (!result || result.target) return result as Dispatched | undefined;
528
549
  if (!result.handled && !result.capture && !result.focus) return undefined;
529
550
  return { ...result, handled: true, target: { component: this, originX: event.screenX - event.x, originY: event.screenY - event.y,