pi-stereo-view 0.1.13 → 0.1.15

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,26 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.1.15 - 2026-11-08
6
+
7
+ ### Added
8
+
9
+ - Choose icons or text for toolbar, panel, search and copy controls in Stereo View settings. The choice survives restart.
10
+
11
+ ### Changed
12
+
13
+ - Use consistent spacing between adjacent buttons. In narrow search panels, hide the match counter when needed to keep the query editable.
14
+
15
+ ### Fixed
16
+
17
+ - Keep timestamps and copy controls on user messages when an extension replaces a message after it is displayed.
18
+
19
+ ## 0.1.14 - 2026-11-07
20
+
21
+ ### Fixed
22
+
23
+ - Keep split view responsive while an agent streams in long sessions. Frames no longer rebuild call headers, timestamps and every earlier answer for the whole history.
24
+
5
25
  ## 0.1.13 - 2026-11-06
6
26
 
7
27
  ### Changed
package/README.md CHANGED
@@ -74,23 +74,23 @@ pi --tui-mode fullscreen
74
74
 
75
75
  ## Use it
76
76
 
77
- Click the toolbar and the buttons in each panel's header:
78
-
79
- | Button | Action |
80
- | --- | --- |
81
- | `[ ▣ ]` / `[ ◫ ]` | Turn split history off / on. |
82
- | `[ ▤ ]` / `[ ▥ ]` | Switch between rows and columns. |
83
- | `[ ↕ ]` / `[ ↔ ]` | Swap the panels. |
84
- | `[ ↗ ]` / `[ ↙ ]` | Zoom a panel / restore the split. |
85
- | `[ ≡ ]` | Open display and Conversation height settings. |
86
- | `[ ⌕ ]` | Search this panel. |
87
- | `[ ⊟ ]` / `[ ⊞ ]` | Compact Activity tools / restore full tools. |
77
+ Click the toolbar and the buttons in each panel's header. Buttons use icons by default. To use text instead, open **Stereo View settings** with `[ ≡ ]` or `/stereo-view settings`, then set **Button style** to `text`. The choice survives restart.
78
+
79
+ | Icons | Text | Action |
80
+ | --- | --- | --- |
81
+ | `[ ▣ ]` / `[ ◫ ]` | `[Join]` / `[Open]` | Turn split history off / on. |
82
+ | `[ ▤ ]` / `[ ▥ ]` | `[Rows]` / `[Cols]` | Switch between rows and columns. |
83
+ | `[ ↕ ]` / `[ ↔ ]` | `[Swap]` | Swap the panels. |
84
+ | `[ ↗ ]` / `[ ↙ ]` | `[Max]` / `[Out]` | Zoom a panel / restore the split. |
85
+ | `[ ≡ ]` | `[Menu]` | Open display and Conversation height settings. |
86
+ | `[ ⌕ ]` | `[Find]` | Search this panel. |
87
+ | `[ ⊟ ]` / `[ ⊞ ]` | `[Few]` / `[All]` | Compact Activity tools / restore full tools. |
88
88
 
89
89
  **Resize:** drag the double line between the panels — `═` in rows, `║` in columns.
90
90
 
91
91
  New installs start in Columns: Conversation gets 20% of the width on the left, and Activity gets 80% on the right. Drag the divider or use the size shortcuts to change this.
92
92
 
93
- In Rows, Conversation grows with its messages up to half the available history area, then scrolls. Dragging the divider or setting a height changes that limit. Choose **Conversation height: auto** in `≡`, or run `/stereo-view height auto`, to restore automatic sizing.
93
+ In Rows, Conversation grows with its messages up to half the available history area, then scrolls. Dragging the divider or setting a height changes that limit. Choose **Conversation height: auto** in settings, or run `/stereo-view height auto`, to restore automatic sizing.
94
94
 
95
95
  Panels fit short content and scroll when history fills up. Each panel has its own scrolling, text selection and copy.
96
96
 
@@ -98,17 +98,17 @@ Swap the panels whenever you want. Zoom a panel to give it the whole history are
98
98
 
99
99
  ## Compact Activity
100
100
 
101
- Click `⊟` beside Search and Maximize in the Activity header to show compact tool calls. Adjacent calls to the same tool in the same state share a header with a count; every failed call stays separate, even beside another failure. Click that header to show the individual compact rows, then click a row to open its original full card and linked output. Left guides mark each level: members sit inside their group, and an open card and its linked output sit inside their call. Collapse a call or its group independently; reopening the group keeps your expanded calls. Thinking, Conversation content and different tools end a group.
101
+ Click `[ ⊟ ]` or `[Few]` beside Search and Maximize in the Activity header to show compact tool calls. Adjacent calls to the same tool in the same state share a header with a count; every failed call stays separate, even beside another failure. Click that header to show the individual compact rows, then click a row to open its original full card and linked output. Left guides mark each level: members sit inside their group, and an open card and its linked output sit inside their call. Collapse a call or its group independently; reopening the group keeps your expanded calls. Thinking, Conversation content and different tools end a group.
102
102
 
103
103
  Group and call headers show `▸` when collapsed and `▾` when expanded. Each call row has a one-cell left gutter, a colored status dot, its tool name and a short argument description. A group shows its shared running or successful state. Failed calls expose their own status and argument preview without opening a group. Long descriptions are truncated, not the saved calls. Verified local MCP forwarding aliases use their native tool's name; foreign, ambiguous and unknown tools keep their original identity.
104
104
 
105
- Search and `/stereo-view copy` still include full saved results and linked output. A search match opens its group and call temporarily; clearing the search restores your previous expansion. You can also click `⊞` in the Activity header to restore full tools. Conversation and combined history keep their normal display.
105
+ Search and `/stereo-view copy` still include full saved results and linked output. A search match opens its group and call temporarily; clearing the search restores your previous expansion. You can also click `[ ⊞ ]` or `[All]` in the Activity header to restore full tools. Conversation and combined history keep their normal display.
106
106
 
107
107
  Compact tools work in columns, rows and zoomed Activity. The choice survives restart and defaults to off. For keyboard access, run `/stereo-view settings` and change **Compact Activity tools**.
108
108
 
109
109
  ## Search history
110
110
 
111
- Press **Ctrl+F** to search the last clicked or scrolled panel. A dot in the header marks the active panel; Conversation is active initially. The `⌕` button always searches its own panel.
111
+ Press **Ctrl+F** to search the last clicked or scrolled panel. The active panel's header is highlighted and, when space permits, marked with a dot; Conversation is active initially. The `[ ⌕ ]` / `[Find]` button always searches its own panel.
112
112
 
113
113
  Type a word or phrase to find it without case sensitivity. Combine terms with `AND`, `OR`, `NOT` and parentheses. Put phrases in quotes to keep them together, or start with `regex:` for a regular expression.
114
114
 
@@ -119,7 +119,7 @@ Type a word or phrase to find it without case sensitivity. Combine terms with `A
119
119
  | `(worker OR server) AND "ready now"` | Lines containing either term and the phrase “ready now”. |
120
120
  | `regex:worker_[0-9]+` | Names such as `worker_12`. |
121
121
 
122
- Press **Enter** or `[↓]` for the next match, and **Shift+Enter** for the previous one. The counter shows your position and the total matches. Ctrl+F returns to the search field without clearing your query.
122
+ Press **Enter**, `[ ↓ ]` or `[Go]` for the next match, and **Shift+Enter** for the previous one. The counter shows your position and the total matches when space permits. Ctrl+F returns to the search field without clearing your query.
123
123
 
124
124
  Search covers the whole current conversation branch, including off-screen messages, hidden thinking and collapsed tool output. It does not search other branches, sessions, attachments or files. Russian and English queries work.
125
125
 
@@ -127,11 +127,11 @@ A match is revealed in its own panel without moving the other one. If matching t
127
127
 
128
128
  **Regex search requires ripgrep (`rg`) to be installed.** Invalid queries and search errors appear in the search field instead of showing incomplete results.
129
129
 
130
- Press **Escape** or `[×]` to close search and restore your previous scroll position. Your message draft stays unchanged. Close other dialogs before searching. Search is available in split fullscreen history; combined history and regular mode keep Pi's usual keyboard behaviour.
130
+ Press **Escape**, `[ × ]` or `[Exit]` to close search and restore your previous scroll position. Your message draft stays unchanged. Close other dialogs before searching. Search is available in split fullscreen history; combined history and regular mode keep Pi's usual keyboard behaviour.
131
131
 
132
132
  ## Copy a block
133
133
 
134
- Click the dim `⧉` icon below the right corner of a message, thinking, tool or other history block to copy its text. Blocks without a known time have no copy button. Copy buttons work in split and zoomed panels, even with timestamps hidden.
134
+ Click `[ ⧉ ]` or `[Copy]` below the right corner of a message, thinking, tool or other history block to copy its text. Blocks without a known time have no copy button. Copy buttons work in split and zoomed panels, even with timestamps hidden.
135
135
 
136
136
  Messages and thinking keep their original text/Markdown, without terminal colours, clocks or copy buttons. Copying a tool includes its name, arguments, saved result and linked late output. A late-output block also has its own button to copy just that block. Collapsed and off-screen text is included.
137
137
 
@@ -139,17 +139,17 @@ During streaming, each click copies the content available at that moment. Copy u
139
139
 
140
140
  For keyboard access, run `/stereo-view copy` and choose a numbered block from the active panel. It copies the same text as that block's button.
141
141
 
142
- Use **Show copy buttons** in `≡` or `/stereo-view settings` to hide the icons and their rows. This choice survives restart. Keyboard copying stays available when the icons are hidden.
142
+ Use **Show copy buttons** in Stereo View settings to hide the buttons and their rows. This choice survives restart. Keyboard copying stays available when the buttons are hidden.
143
143
 
144
144
  ## Timestamps
145
145
 
146
- Conversation and Activity can show a dim local `HH:mm:ss` clock above each block on the left, with a small inset. The copy icon sits below the block on the right, so neither control takes width away from the text. New tool calls show their start time.
146
+ Conversation and Activity can show a dim local `HH:mm:ss` clock above each block on the left, with a small inset. The copy button sits below the block on the right, so neither control takes width away from the text. New tool calls show their start time.
147
147
 
148
148
  In compact Activity, clocks sit at the start of the same line on the left, before the status and tool name, when space permits. A group shows its first call's original time; expanded member rows show their own. Opening a full card does not repeat its clock.
149
149
 
150
150
  Older tool calls may show `~HH:mm:ss` for an approximate time. Blocks without a known time show neither a clock nor a copy button; their content stays visible.
151
151
 
152
- Use `≡` or `/stereo-view settings` to hide or show clocks. This setting survives restart. Clocks appear in split and zoomed panels, not in combined history. They are display-only and are not added to the conversation sent to the model.
152
+ Use Stereo View settings to hide or show clocks. This setting survives restart. Clocks appear in split and zoomed panels, not in combined history. They are display-only and are not added to the conversation sent to the model.
153
153
 
154
154
  ## Commands and shortcuts
155
155
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-stereo-view",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "type": "module",
5
5
  "description": "Keep Pi conversation separate from tool output and agent activity.",
6
6
  "license": "MIT",
@@ -31,21 +31,38 @@ interface CompactToolOptions {
31
31
  toggle?(): void;
32
32
  }
33
33
 
34
+ interface HeaderInputs {
35
+ width: number; name: string; args: unknown; status: ToolSummary["status"]; count?: number; expanded?: boolean;
36
+ label: string; theme: Theme;
37
+ }
38
+ const sameInputs = (a: HeaderInputs, b: HeaderInputs): boolean => a.width === b.width && a.name === b.name &&
39
+ a.args === b.args && a.status === b.status && a.count === b.count && a.expanded === b.expanded && a.label === b.label && a.theme === b.theme;
40
+
34
41
  /** A display-only call or group header; the original renderer owns the body. */
35
42
  export class CompactTool implements Component {
43
+ // Headers are rebuilt every frame for the whole history. Completed calls keep their
44
+ // argument object, so reuse the row until a displayed input changes.
45
+ private cached?: { inputs: HeaderInputs; lines: string[] };
46
+
36
47
  constructor(private readonly summary: () => ToolSummary, private readonly theme: () => Theme,
37
48
  private readonly options: CompactToolOptions = {}) {}
38
49
 
39
50
  render(width: number): string[] {
40
51
  width = Math.max(0, width - (this.options.gutter?.() ?? 0));
41
52
  const { name, args, status } = this.summary();
42
- const theme = this.theme();
53
+ const inputs: HeaderInputs = { width, name, args, status, count: this.options.count?.(),
54
+ expanded: this.options.toggle ? this.options.expanded?.() : undefined, label: this.options.clock?.() ?? "", theme: this.theme() };
55
+ // Streamed arguments may be updated in place, so running calls always rebuild.
56
+ if (this.cached && status !== "running" && sameInputs(this.cached.inputs, inputs)) return this.cached.lines;
57
+ const lines = this.header(inputs);
58
+ this.cached = { inputs, lines };
59
+ return lines;
60
+ }
61
+ private header({ width, name, args, status, count, expanded, label, theme }: HeaderInputs): string[] {
43
62
  const dot = theme.fg(status === "running" ? "warning" : status === "unknown" ? "dim" : status, "●");
44
- const count = this.options.count?.();
45
63
  const description = count ? "" : toolDescription(args);
46
- const control = this.options.toggle ? theme.fg("muted", this.options.expanded?.() ? "▾" : "▸") + " " : this.options.alignControl ? " " : "";
64
+ const control = this.options.toggle ? theme.fg("muted", expanded ? "▾" : "▸") + " " : this.options.alignControl ? " " : "";
47
65
  const text = `${dot} ${control}${singleLine(name)}${count ? ` ×${count}` : ""}${description ? " " + theme.fg("muted", description) : ""}`;
48
- const label = this.options.clock?.() ?? "";
49
66
  const clock = label && width >= visibleWidth(label) + 8 ? label : "";
50
67
  const available = Math.max(0, width - 1 - (clock ? visibleWidth(clock) + 1 : 0));
51
68
  const body = truncateToWidth(text, available, "…");
@@ -60,5 +77,5 @@ export class CompactTool implements Component {
60
77
  }
61
78
  return { handled: true };
62
79
  }
63
- invalidate(): void {}
80
+ invalidate(): void { this.cached = undefined; }
64
81
  }
package/src/content.ts CHANGED
@@ -79,6 +79,20 @@ function assistant(component: Component): NativeAssistant | undefined {
79
79
  return native;
80
80
  }
81
81
 
82
+ /** Native rendering creates one child per visible text block or consecutive thinking run. */
83
+ function forEachRun(source: NativeAssistant, visit: (kind: ContentKind) => void): void {
84
+ let thinking = false;
85
+ for (const block of source.lastMessage?.content ?? []) {
86
+ if (block.type === "thinking") {
87
+ if (!thinking && block.thinking?.trim()) { visit("thinking"); thinking = true; }
88
+ } else {
89
+ thinking = false;
90
+ if (block.type === "text" && block.text?.trim()) visit("dialogue");
91
+ }
92
+ }
93
+ }
94
+ const runsEnd = Symbol("runs");
95
+
82
96
  /** Read supported native execution identities; unrecognized content is system information. */
83
97
  const nativeKinds: Record<string, { kind: ContentKind; accepts(content: NativeContent): boolean }> = {
84
98
  UserMessageComponent: { kind: "dialogue", accepts: content => typeof content.text === "string" },
@@ -127,15 +141,31 @@ function nativePanelParts(source: NativeContent): Component[] | undefined {
127
141
  export class NativeContentIndex {
128
142
  private signature: unknown[] = [];
129
143
  private content: ContentEntry[] = [];
144
+ private panes: Partial<Record<Pane, ContentEntry[]>> = {};
130
145
  private readonly expandedPanels = new WeakMap<Component, Component>();
131
146
  private readonly views = new WeakMap<NativeAssistant, Partial<Record<Pane, Container>>>();
132
147
 
148
+ private pass?: { active: boolean; verified?: { children: Component[]; length: number; last?: Component; parts: number; revision: number } };
149
+
133
150
  constructor(private readonly source: Container, readonly nested = new NestedCalls()) {}
134
151
 
152
+ /**
153
+ * Native history cannot change while Pi lays out one frame, so the panes of a pass
154
+ * share one verification. The pass ends in the next microtask; structural changes
155
+ * and nested-call updates inside it still verify again.
156
+ */
157
+ beginFrame(): void {
158
+ if (this.pass?.active) { this.pass.verified = undefined; return; }
159
+ const pass: NonNullable<typeof this.pass> = { active: true };
160
+ this.pass = pass;
161
+ queueMicrotask(() => { pass.active = false; if (this.pass === pass) this.pass = undefined; });
162
+ }
163
+
135
164
  /** Return the same classification until native ownership or assistant content changes. */
136
165
  entries(pane?: Pane): ContentEntry[] {
137
166
  this.refresh();
138
- return pane === undefined ? this.content : this.content.filter(entry => panes[entry.kind] === pane);
167
+ if (pane === undefined) return this.content;
168
+ return this.panes[pane] ??= this.content.filter(entry => panes[entry.kind] === pane);
139
169
  }
140
170
 
141
171
  /** A rebuilt history cannot retain search hits belonging to removed native owners. */
@@ -155,23 +185,51 @@ export class NativeContentIndex {
155
185
  return group.map(candidate => stripTerminalSequences(candidate.search(width).text)).filter(Boolean).join("\n\n");
156
186
  }
157
187
 
188
+ /** Visit every native identity that classification depends on, in a fixed order. */
189
+ private visitSignature(history: Container, visit: (value: unknown) => boolean): boolean {
190
+ if (!visit(this.nested.revision)) return false;
191
+ for (const component of this.source.children) if (!visit(component)) return false;
192
+ for (const component of history.children) if (!visit(component)) return false;
193
+ for (const component of history.children) {
194
+ const metadata = component as NativeContent;
195
+ if (!visit(metadata.toolCallId) || !visit(metadata.entry?.data?.parentToolCallId) ||
196
+ !visit(metadata.message?.details?.parentToolCallId) || !visit(metadata.customComponent)) return false;
197
+ if (metadata.entry?.data?.parentToolCallId || metadata.message?.details?.parentToolCallId)
198
+ for (const part of nativePanelParts(metadata) ?? []) if (!visit(part)) return false;
199
+ const native = assistant(component);
200
+ if (native) {
201
+ // Streaming replaces the message on every delta; only its block layout affects routing.
202
+ let changed = false;
203
+ forEachRun(native, kind => { if (!changed && !visit(kind)) changed = true; });
204
+ if (changed || !visit(runsEnd)) return false;
205
+ for (const child of native.contentContainer.children) if (!visit(child)) return false;
206
+ }
207
+ }
208
+ return true;
209
+ }
210
+
158
211
  private refresh(): void {
159
212
  const history = this.source.children[2] as Container;
160
213
  if (!Array.isArray(history?.children)) throw new Error("Pi's history document is not supported");
214
+ const pass = this.pass?.active ? this.pass : undefined;
215
+ const children = history.children;
216
+ const verified = pass?.verified;
217
+ if (verified && verified.children === children && verified.length === children.length && verified.last === children.at(-1) &&
218
+ verified.parts === this.source.children.length && verified.revision === this.nested.revision) return;
219
+ this.verify(history);
220
+ if (pass) pass.verified = { children, length: children.length, last: children.at(-1), parts: this.source.children.length, revision: this.nested.revision };
221
+ }
222
+
223
+ private verify(history: Container): void {
161
224
  const makeSignature = (): unknown[] => {
162
- const values: unknown[] = [this.nested.revision, ...this.source.children, ...history.children];
163
- for (const component of history.children) {
164
- const metadata = component as NativeContent;
165
- values.push(metadata.toolCallId, metadata.entry?.data?.parentToolCallId, metadata.message?.details?.parentToolCallId, metadata.customComponent);
166
- if (metadata.entry?.data?.parentToolCallId || metadata.message?.details?.parentToolCallId)
167
- values.push(...(nativePanelParts(metadata) ?? []));
168
- const native = assistant(component);
169
- if (native) values.push(native.lastMessage, ...native.contentContainer.children);
170
- }
225
+ const values: unknown[] = [];
226
+ this.visitSignature(history, value => { values.push(value); return true; });
171
227
  return values;
172
228
  };
173
- const signature = makeSignature();
174
- if (signature.length === this.signature.length && signature.every((value, index) => value === this.signature[index])) return;
229
+ // Compare in place: this runs several times per frame over the whole history.
230
+ let position = 0;
231
+ const previous = this.signature;
232
+ if (this.visitSignature(history, value => value === previous[position++]) && position === previous.length) return;
175
233
  const owners = new Map<string, NativeContent>();
176
234
  for (const component of history.children) {
177
235
  const adapter = nativeKinds[nameOf(component)];
@@ -219,6 +277,7 @@ export class NativeContentIndex {
219
277
  this.content = entries.flatMap(entry => entry.owner === entry.source
220
278
  ? [entry, ...(linked.get(entry.source) ?? [])] : []);
221
279
  this.signature = makeSignature();
280
+ this.panes = {};
222
281
  }
223
282
 
224
283
  private entry(source: Component, kind: ContentKind, spacing: Component[], compact: boolean, owner?: NativeContent): ContentEntry {
@@ -268,15 +327,7 @@ export class NativeContentIndex {
268
327
  // Native rendering creates one child per visible text block or consecutive thinking run.
269
328
  // Match those children to semantic content before projecting; a Text diagnostic is not thinking.
270
329
  const runs: ContentKind[] = [];
271
- let thinking = false;
272
- for (const block of source.lastMessage?.content ?? []) {
273
- if (block.type === "thinking") {
274
- if (block.thinking?.trim() && !thinking) { runs.push("thinking"); thinking = true; }
275
- } else {
276
- thinking = false;
277
- if (block.type === "text" && block.text?.trim()) runs.push("dialogue");
278
- }
279
- }
330
+ forEachRun(source, kind => runs.push(kind));
280
331
  const groups: Record<Pane, Component[]> = { chat: [], activity: [] };
281
332
  const diagnostics: Component[] = [];
282
333
  let slot = 0;
@@ -310,7 +361,8 @@ export class NativeContentIndex {
310
361
  views[pane] = view;
311
362
  }
312
363
  const content = view.children[0] as Container;
313
- content.children = parts;
364
+ // Keep the array of unchanged views: their native render caches compare child identity.
365
+ if (content.children.length !== parts.length || content.children.some((child, index) => child !== parts[index])) content.children = parts;
314
366
  result.push({
315
367
  source, owner: source, component: view, kind: pane === "activity" ? "thinking" : runs.includes("dialogue") ? "dialogue" : "system", spacing, compact: true,
316
368
  search: width => {
package/src/index.ts CHANGED
@@ -44,8 +44,12 @@ export default async function transcript(pi: ExtensionAPI): Promise<void> {
44
44
  currentValue: preferences.showTimestamps ? "on" : "off", values: ["on", "off"],
45
45
  }, {
46
46
  id: "copyButtons", label: "Show copy buttons",
47
- description: "Hide copy icons and their rows; keyboard copying stays available.",
47
+ description: "Hide copy buttons and their rows; keyboard copying stays available.",
48
48
  currentValue: preferences.showCopyButtons ? "on" : "off", values: ["on", "off"],
49
+ }, {
50
+ id: "buttonStyle", label: "Button style",
51
+ description: "Choose icons or text for toolbar, panel and copy controls.",
52
+ currentValue: preferences.buttonStyle, values: ["icons", "text"],
49
53
  }, {
50
54
  id: "compactTools", label: "Compact Activity tools",
51
55
  description: "Group adjacent tools and expand individual calls inline. Full text stays searchable and copyable.",
@@ -54,9 +58,10 @@ export default async function transcript(pi: ExtensionAPI): Promise<void> {
54
58
  id: "height", label: "Conversation height",
55
59
  description: "Auto grows to half the history area. Drag sets a manual maximum.",
56
60
  currentValue: preferences.chatHeight === null ? "auto" : "manual", values: ["auto", "manual"],
57
- }], 4, getSettingsListTheme(), (id, value) => {
61
+ }], 5, getSettingsListTheme(), (id, value) => {
58
62
  if (id === "timestamps") layout?.setTimestamps(value === "on");
59
63
  else if (id === "copyButtons") layout?.setCopyButtons(value === "on");
64
+ else if (id === "buttonStyle") layout?.setButtonStyle(value === "text" ? "text" : "icons");
60
65
  else if (id === "compactTools") layout?.setCompactTools(value === "on");
61
66
  else if (id === "height") layout?.setAutomaticHeight(value === "auto");
62
67
  tui.requestRender();
@@ -238,7 +243,7 @@ export default async function transcript(pi: ExtensionAPI): Promise<void> {
238
243
  const choice = await ctx.ui.select("Copy a block from the active panel", blocks.map(block => block.label));
239
244
  blocks.find(block => block.label === choice)?.copy();
240
245
  } else if (action === "help") {
241
- ctx.ui.notify("pi-stereo-view icons: ▣ combined, ◫ split, ▤ rows, ▥ columns, ↕/↔ swap, ↗ expand, ↙ restore, ⌕ search, ⊟ compact tools, ⊞ full tools, ≡ settings, ⧉ copy block. /stereo-view copy chooses a block with the keyboard. Ctrl+F searches and PgUp/PgDn scroll the active panel; Ctrl+Alt+Up/Down switches it. Drag the ═ or ║ divider to resize.", "info");
246
+ ctx.ui.notify("pi-stereo-view: choose icon or text buttons in /stereo-view settings. Buttons: ▣/Join combines history, ◫/Open splits it, ▤/Rows and ▥/Cols change layout, ↕/↔/Swap exchanges panels, ↗/Max and ↙/Out zoom and restore, ⌕/Find searches, ⊟/Few and ⊞/All toggle compact tools, ≡/Menu opens settings, ⧉/Copy copies a block. /stereo-view copy chooses a block with the keyboard. Ctrl+F searches and PgUp/PgDn scroll the active panel; Ctrl+Alt+Up/Down switches it. Drag the ═ or ║ divider to resize.", "info");
242
247
  } else if (action === "swap") layout.swap();
243
248
  else if (action === "width" && /^\d+$/.test(target ?? "")) layout.setWidth(Number(target));
244
249
  else if (action === "height" && target === "auto") layout.setHeight(null);
package/src/layout.ts CHANGED
@@ -19,7 +19,7 @@ type NativeTui = TUI & {
19
19
  const MIN_CHAT = 24;
20
20
  const MIN_ACTIVITY = 40;
21
21
  const MIN_ROWS = 4;
22
- const BUTTON_WIDTH = 5;
22
+ const TOOLBAR_BUTTON_WIDTH = 6;
23
23
 
24
24
  class PanelScrollView extends ScrollView {
25
25
  constructor(component: Component, options: ScrollViewOptions, private readonly interact: () => void, active: () => boolean) {
@@ -44,6 +44,22 @@ class NativeSurfaceScrollView extends ScrollView {
44
44
  }
45
45
  }
46
46
 
47
+ class ButtonStack extends HStack {
48
+ constructor(children: StackChild[], private readonly controls: { index: number; icon: number; text: number; min: number }[],
49
+ private readonly titleLength?: number) {
50
+ super(children);
51
+ }
52
+
53
+ setStyle(style: "icons" | "text"): void {
54
+ if (this.titleLength !== undefined) this.entries[0].minSize = style === "icons" ? 1 : this.titleLength;
55
+ for (const { index, icon, text, min } of this.controls) {
56
+ const entry = this.entries[index];
57
+ entry.basis = style === "icons" ? icon : text;
58
+ entry.minSize = style === "icons" ? icon : min;
59
+ entry.shrink = style === "icons" ? 0 : 1;
60
+ }
61
+ }
62
+ }
47
63
  class TranscriptColumns extends HStack {
48
64
  /** Reserve a fixed width for Conversation, independent of its content. */
49
65
  sizeConversation(component: Component, width: number): void {
@@ -154,9 +170,9 @@ export class TranscriptLayout {
154
170
  private readonly getEditor: () => Component | undefined = () => undefined,
155
171
  ) {}
156
172
 
157
- private button(icon: () => string, action: () => void, enabled = (): boolean => true, background?: () => Color): Component {
173
+ private button(label: () => string, action: () => void, enabled = (): boolean => true, background?: () => Color): Component {
158
174
  return new MouseRegion({
159
- render: width => new Text(this.theme().style("[ " + icon() + " ]", {
175
+ render: width => new Text(this.theme().style((this.preferences.buttonStyle === "icons" ? "[ " + label() + " ]" : "[" + label() + "]").padEnd(width), {
160
176
  fg: enabled() ? "accent" : "dim", bg: background?.(),
161
177
  }), 0, 0).render(width),
162
178
  invalidate() {},
@@ -249,9 +265,9 @@ export class TranscriptLayout {
249
265
  const index = new NativeContentIndex(document, this.nested);
250
266
  const activityDocument = new NativeDocument(document, "activity", this.timestamps, this.theme, timestampGutter, showTimestamps,
251
267
  () => this.activate("activity"), false, index, this.copy, showCopyButtons, () => this.preferences.compactTools, this.getTools,
252
- () => { if (this.activity) this.activity.scrollTo(this.activity.scrollTop, { disableFollow: true }); });
268
+ () => { if (this.activity) this.activity.scrollTo(this.activity.scrollTop, { disableFollow: true }); }, () => this.preferences.buttonStyle);
253
269
  const chatDocument = new NativeDocument(document, "chat", this.timestamps, this.theme, timestampGutter, showTimestamps,
254
- () => this.activate("chat"), false, index, this.copy, showCopyButtons);
270
+ () => this.activate("chat"), false, index, this.copy, showCopyButtons, undefined, undefined, undefined, () => this.preferences.buttonStyle);
255
271
  this.documents = { activity: activityDocument, chat: chatDocument };
256
272
  this.disposeDocuments = () => {
257
273
  activityDocument.dispose();
@@ -270,7 +286,14 @@ export class TranscriptLayout {
270
286
  this.chat = new PanelScrollView(chatDocument, scrollOptions, () => this.activate("chat"), () => this.searchPane() === "chat");
271
287
  let historyHeight = 0;
272
288
  let projectSurface = false;
273
- const shown = ({ width, height }: { width: number; height: number }): boolean => {
289
+ // Every root entry asks in turn during one visibility pass; evaluate the projection once.
290
+ let pass: { width: number; height: number; shown: boolean } | undefined;
291
+ const shown = (viewport: { width: number; height: number }): boolean => {
292
+ if (pass?.width === viewport.width && pass.height === viewport.height) return pass.shown;
293
+ pass = { ...viewport, shown: evaluate(viewport) };
294
+ return pass.shown;
295
+ };
296
+ const evaluate = ({ width, height }: { width: number; height: number }): boolean => {
274
297
  const previousHeight = historyHeight;
275
298
  const candidate = !!projectedDock && (widgetsPresent() || dialogPresent()) && dockUnchanged() && !this.failed &&
276
299
  this.preferences.mode === "split" && this.preferences.zoom !== "chat";
@@ -337,21 +360,22 @@ export class TranscriptLayout {
337
360
  return false;
338
361
  }
339
362
  };
340
- const toolbar = new HStack([
363
+ const headers: ButtonStack[] = [];
364
+ const toolbar = new ButtonStack([
341
365
  { component: this.button(
342
- () => this.preferences.mode === "combined" || this.fallback || this.failed ? "◫" : "▣",
366
+ () => this.preferences.mode === "combined" || this.fallback || this.failed ? (this.preferences.buttonStyle === "icons" ? "◫" : "Open") : (this.preferences.buttonStyle === "icons" ? "▣" : "Join"),
343
367
  () => this.toggle(), () => !this.fallback && !this.failed,
344
- ), basis: BUTTON_WIDTH, shrink: 0 },
368
+ ), basis: TOOLBAR_BUTTON_WIDTH + 1, minSize: TOOLBAR_BUTTON_WIDTH, shrink: 1 },
345
369
  { component: this.button(
346
- () => this.preferences.layout === "columns" ? "▤" : "▥",
370
+ () => this.preferences.layout === "columns" ? (this.preferences.buttonStyle === "icons" ? "▤" : "Rows") : (this.preferences.buttonStyle === "icons" ? "▥" : "Cols"),
347
371
  () => this.setLayout(this.preferences.layout === "columns" ? "rows" : "columns"), () => !this.failed,
348
- ), basis: BUTTON_WIDTH, shrink: 0 },
372
+ ), basis: TOOLBAR_BUTTON_WIDTH + 1, minSize: TOOLBAR_BUTTON_WIDTH, shrink: 1 },
349
373
  { component: this.button(
350
- () => this.preferences.layout === "columns" ? "↔" : "↕", () => this.swap(),
374
+ () => this.preferences.buttonStyle === "icons" ? (this.preferences.layout === "columns" ? "↔" : "↕") : "Swap", () => this.swap(),
351
375
  () => this.preferences.mode === "split" && !this.preferences.zoom && !this.fallback && !this.failed,
352
- ), basis: BUTTON_WIDTH, shrink: 0 },
353
- { component: this.button(() => "≡", this.openSettings), basis: BUTTON_WIDTH, shrink: 0 },
354
- ], { gap: 1 });
376
+ ), basis: TOOLBAR_BUTTON_WIDTH + 1, minSize: TOOLBAR_BUTTON_WIDTH, shrink: 1 },
377
+ { component: this.button(() => this.preferences.buttonStyle === "icons" ? "≡" : "Menu", this.openSettings), basis: TOOLBAR_BUTTON_WIDTH, shrink: 0 },
378
+ ], [0, 1, 2, 3].map(index => ({ index, icon: index === 3 ? 5 : 6, text: index === 3 ? 6 : 7, min: 6 })));
355
379
  const pane = (title: string, target: Pane, view: ScrollView): Component => {
356
380
  const hue = target === "chat" ? rgbColor(104, 158, 115) : rgbColor(107, 152, 190);
357
381
  const palette = () => {
@@ -366,9 +390,9 @@ export class TranscriptLayout {
366
390
  render: width => [this.theme().style("─".repeat(width), { fg: palette().border })],
367
391
  invalidate() {},
368
392
  };
369
- const label = new HStack([
393
+ const label = new ButtonStack([
370
394
  { component: new MouseRegion({
371
- render: width => new Text(this.theme().style(truncateToWidth(" " + (this.searchPane() === target ? "● " : " ") + title, width, "").padEnd(width), {
395
+ render: width => new Text(this.theme().style(truncateToWidth(width < title.length + 3 ? title : " " + (this.searchPane() === target ? "● " : " ") + title, width, "").padEnd(width), {
372
396
  fg: this.searchPane() === target ? "accent" : palette().text, bg: palette().fill,
373
397
  }), 0, 0).render(width),
374
398
  invalidate() {},
@@ -378,23 +402,31 @@ export class TranscriptLayout {
378
402
  return { handled: true, render: true };
379
403
  }
380
404
  return undefined;
381
- }), basis: 0, grow: 1, minSize: 1 },
405
+ }), basis: 0, grow: 1, minSize: title.length },
382
406
  ...(target === "activity" ? [{ component: this.button(
383
- () => this.preferences.compactTools ? "⊞" : "⊟",
407
+ () => this.preferences.compactTools ? (this.preferences.buttonStyle === "icons" ? "⊞" : "All") : (this.preferences.buttonStyle === "icons" ? "⊟" : "Few"),
384
408
  () => {
385
409
  this.activate("activity");
386
410
  this.setCompactTools(!this.preferences.compactTools);
387
411
  }, () => true, () => palette().fill,
388
- ), basis: BUTTON_WIDTH, shrink: 0 }] : []),
389
- { component: this.button(() => "⌕", () => {
412
+ ), basis: 6, minSize: 5, shrink: 1 }] : []),
413
+ { component: this.button(() => this.preferences.buttonStyle === "icons" ? "⌕" : "Find", () => {
390
414
  this.activate(target);
391
415
  this.openSearch(target);
392
- }, () => true, () => palette().fill), basis: BUTTON_WIDTH, shrink: 0 },
416
+ }, () => true, () => palette().fill), basis: TOOLBAR_BUTTON_WIDTH + 1, minSize: TOOLBAR_BUTTON_WIDTH, shrink: 1 },
393
417
  { component: this.button(
394
- () => this.preferences.zoom === target ? "↙" : "↗",
418
+ () => this.preferences.zoom === target ? (this.preferences.buttonStyle === "icons" ? "↙" : "Out") : (this.preferences.buttonStyle === "icons" ? "↗" : "Max"),
395
419
  () => this.maximize(target), () => true, () => palette().fill,
396
- ), basis: BUTTON_WIDTH, shrink: 0 },
397
- ]);
420
+ ), basis: 5, shrink: 0 },
421
+ ], target === "activity" ? [
422
+ { index: 1, icon: 6, text: 6, min: 5 },
423
+ { index: 2, icon: 6, text: 7, min: 6 },
424
+ { index: 3, icon: 5, text: 5, min: 5 },
425
+ ] : [
426
+ { index: 1, icon: 6, text: 7, min: 6 },
427
+ { index: 2, icon: 5, text: 5, min: 5 },
428
+ ], title.length);
429
+ headers.push(label);
398
430
  const header = new VStack([
399
431
  { component: line, basis: 1, shrink: 0, visible: () =>
400
432
  this.preferences.zoom !== null || this.preferences.layout === "columns" ||
@@ -444,6 +476,8 @@ export class TranscriptLayout {
444
476
  const columns = new TranscriptColumns();
445
477
  const rows = new TranscriptRows();
446
478
  this.rebuild = (): void => {
479
+ toolbar.setStyle(this.preferences.buttonStyle);
480
+ for (const header of headers) header.setStyle(this.preferences.buttonStyle);
447
481
  for (const [stack, axis] of [[columns, "columns"], [rows, "rows"]] as const) {
448
482
  stack.clear();
449
483
  const minimum = axis === "columns" ? MIN_CHAT : MIN_ROWS;
@@ -467,6 +501,7 @@ export class TranscriptLayout {
467
501
  const mounted = new TranscriptRoot([
468
502
  { component: toolbar, basis: 1, shrink: 0, visible: () => {
469
503
  // Root visibility is evaluated once at the start of each native layout pass.
504
+ pass = undefined;
470
505
  this.timestamps.beginFrame();
471
506
  activityDocument.beginFrame();
472
507
  chatDocument.beginFrame();
@@ -548,7 +583,7 @@ export class TranscriptLayout {
548
583
  }
549
584
  void this.jumpToSearch(pane, hit, query, () => this.search?.bar === bar && this.searchVersion === version)
550
585
  .catch(error => this.warn("Could not navigate search: " + String(error)));
551
- }, () => this.closeSearch());
586
+ }, () => this.closeSearch(), this.preferences.buttonStyle);
552
587
  this.search = { pane, bar, document, view, top: view.scrollTop, following: view.isFollowingEnd,
553
588
  focus: host.getFocusedComponent() };
554
589
  this.searchRows[pane].addChild(bar);
@@ -633,6 +668,12 @@ export class TranscriptLayout {
633
668
  this.changed();
634
669
  }
635
670
 
671
+ /** Change the presentation of toolbar, header and copy controls. */
672
+ setButtonStyle(style: "icons" | "text"): void {
673
+ this.preferences.buttonStyle = style;
674
+ this.changed();
675
+ }
676
+
636
677
  /** Project tool calls as dense rows while retaining their full search and copy text. */
637
678
  setCompactTools(compact: boolean): void {
638
679
  this.preferences.compactTools = compact;
package/src/native.ts CHANGED
@@ -73,6 +73,7 @@ export class NativeDocument extends Container {
73
73
  private frameWidth?: number;
74
74
  private frameLines?: string[];
75
75
  private checked = false;
76
+ private releasedFor?: readonly ContentEntry[];
76
77
  private disposed = false;
77
78
 
78
79
  constructor(
@@ -90,6 +91,7 @@ export class NativeDocument extends Container {
90
91
  private readonly compactTools: () => boolean = () => false,
91
92
  private readonly getTools: () => readonly ToolInfo[] = () => [],
92
93
  private readonly beforeExpand: () => void = () => {},
94
+ private readonly buttonStyle: () => "icons" | "text" = () => "text",
93
95
  ) {
94
96
  super();
95
97
  }
@@ -98,8 +100,12 @@ export class NativeDocument extends Container {
98
100
  beginFrame(): void {
99
101
  this.frameActive = true;
100
102
  this.frameWidth = undefined;
101
- if (this.compactBlocks.size) {
102
- const present = new Set(this.index.entries(this.pane).map(entry => entry.source));
103
+ this.index.beginFrame();
104
+ // Blocks are only added from the current entries, so an unchanged index has nothing to release.
105
+ const entries = this.index.entries(this.pane);
106
+ if (this.compactBlocks.size && entries !== this.releasedFor) {
107
+ this.releasedFor = entries;
108
+ const present = new Set(entries.map(entry => entry.source));
103
109
  for (const [component, block] of this.compactBlocks) if (!present.has(component)) {
104
110
  block.dispose();
105
111
  this.compactBlocks.delete(component);
@@ -272,7 +278,7 @@ export class NativeDocument extends Container {
272
278
  if (!stamped) {
273
279
  stamped = new CompactMessage(routed, () => this.timestamps.label(this.clockOwners.get(component) ?? component),
274
280
  this.theme, this.timestampGutter, () => this.showTimestamps() && !(this.pane === "activity" && this.compactTools() && entry.kind === "tool"),
275
- this.copy ? () => this.copyBlock(component) : undefined, this.showCopy);
281
+ this.copy ? () => this.copyBlock(component) : undefined, this.showCopy, this.buttonStyle);
276
282
  this.stamped.set(routed, stamped);
277
283
  }
278
284
  this.compactBlocks.set(component, stamped);
@@ -16,10 +16,11 @@ export interface Preferences {
16
16
  showTimestamps: boolean;
17
17
  showCopyButtons: boolean;
18
18
  compactTools: boolean;
19
+ buttonStyle: "icons" | "text";
19
20
  }
20
21
 
21
22
  export const defaults: Preferences = {
22
- mode: "split", side: "left", chatWidth: null, layout: "columns", chatHeight: null, zoom: null, showTimestamps: true, showCopyButtons: true, compactTools: false,
23
+ mode: "split", side: "left", chatWidth: null, layout: "columns", chatHeight: null, zoom: null, showTimestamps: true, showCopyButtons: true, compactTools: false, buttonStyle: "icons",
23
24
  };
24
25
 
25
26
  /** Read display preferences, retaining the first version's saved arrangement. */
@@ -39,16 +40,18 @@ export async function loadPreferences(file: string): Promise<Preferences> {
39
40
  const showTimestamps = record.showTimestamps === undefined ? defaults.showTimestamps : record.showTimestamps;
40
41
  const showCopyButtons = record.showCopyButtons === undefined ? defaults.showCopyButtons : record.showCopyButtons;
41
42
  const compactTools = record.compactTools === undefined ? defaults.compactTools : record.compactTools;
43
+ const buttonStyle = record.buttonStyle === undefined ? defaults.buttonStyle : record.buttonStyle;
42
44
  if ((record.side !== "left" && record.side !== "right") ||
43
45
  (record.chatWidth !== null && (typeof record.chatWidth !== "number" || !Number.isInteger(record.chatWidth) ||
44
46
  record.chatWidth < 24 || record.chatWidth > 240)) ||
45
47
  (layout !== "columns" && layout !== "rows") ||
46
48
  (chatHeight !== null && (typeof chatHeight !== "number" || !Number.isInteger(chatHeight) || chatHeight < 4 || chatHeight > 240)) ||
47
- typeof showTimestamps !== "boolean" || typeof showCopyButtons !== "boolean" || typeof compactTools !== "boolean") {
49
+ typeof showTimestamps !== "boolean" || typeof showCopyButtons !== "boolean" || typeof compactTools !== "boolean" ||
50
+ (buttonStyle !== "icons" && buttonStyle !== "text")) {
48
51
  throw new Error("Invalid pi-stereo-view preferences");
49
52
  }
50
53
  // Legacy files may contain mode/zoom. Every session starts with both panels visible.
51
- return { mode: "split", side: record.side, chatWidth: record.chatWidth, layout, chatHeight, zoom: null, showTimestamps, showCopyButtons, compactTools };
54
+ return { mode: "split", side: record.side, chatWidth: record.chatWidth, layout, chatHeight, zoom: null, showTimestamps, showCopyButtons, compactTools, buttonStyle };
52
55
  }
53
56
 
54
57
  /** Atomically save only the display settings, never session messages. */
@@ -56,8 +59,8 @@ export async function savePreferences(file: string, preferences: Preferences): P
56
59
  await mkdir(path.dirname(file), { recursive: true });
57
60
  const temporary = file + "." + randomUUID() + ".tmp";
58
61
  try {
59
- const { side, chatWidth, layout, chatHeight, showTimestamps, showCopyButtons, compactTools } = preferences;
60
- const saved = { side, chatWidth, layout, chatHeight, showTimestamps, showCopyButtons, compactTools };
62
+ const { side, chatWidth, layout, chatHeight, showTimestamps, showCopyButtons, compactTools, buttonStyle } = preferences;
63
+ const saved = { side, chatWidth, layout, chatHeight, showTimestamps, showCopyButtons, compactTools, buttonStyle };
61
64
  await writeFile(temporary, JSON.stringify(saved, null, 2) + "\n", { mode: 0o600 });
62
65
  await rename(temporary, file);
63
66
  } finally {
package/src/search.ts CHANGED
@@ -95,11 +95,11 @@ class SearchInput extends Input {
95
95
  }
96
96
 
97
97
  class SearchControls extends HStack {
98
- constructor(private readonly count: () => string) { super([], { gap: 1 }); }
98
+ constructor(private readonly count: () => string) { super([]); }
99
99
  override render(width: number): string[] {
100
- // Keep query space usable even in the smallest panel.
101
- this.entries[1].basis = Math.min(this.count().length,
102
- Math.max(3, width - 19));
100
+ // Keep room for at least one query character and the cursor.
101
+ this.entries[1].basis = Math.min(this.count().length + 2, Math.max(2, width - 22));
102
+ this.entries[1].visible = () => width >= 25;
103
103
  return super.render(width);
104
104
  }
105
105
  }
@@ -131,6 +131,7 @@ export class PanelSearch extends VStack {
131
131
  private readonly theme: () => Theme,
132
132
  private readonly match: (hit: SearchHit | undefined, query: string) => void,
133
133
  private readonly close: () => void,
134
+ buttonStyle: "icons" | "text" = "icons",
134
135
  ) {
135
136
  super();
136
137
  this.input = new SearchInput(() => this.refresh(true), () => this.step(-1));
@@ -148,14 +149,16 @@ export class PanelSearch extends VStack {
148
149
  }
149
150
  return { handled: true };
150
151
  });
151
- this.controls.addChild(this.input, { basis: 0, grow: 1, minSize: 10 });
152
+ this.controls.addChild(this.input, { basis: 0, grow: 1, minSize: 11 });
152
153
  this.controls.addChild({
153
154
  render: width => new Text(this.theme().fg(this.hits.length ? "accent" : "dim",
154
- truncateToWidth(this.count(), width, "…")), 0, 0).render(width),
155
+ truncateToWidth(" " + this.count() + " ", width, "…")), 0, 0).render(width),
155
156
  invalidate() {},
156
157
  }, { basis: 7, shrink: 0 });
157
- this.controls.addChild(button("[↓]", () => { this.step(1); this.focus(); }), { basis: 3, shrink: 0 });
158
- this.controls.addChild(button("[×]", close), { basis: 3, shrink: 0 });
158
+ this.controls.addChild(button(buttonStyle === "icons" ? "[ ↓ ]" : "[Go]", () => { this.step(1); this.focus(); }),
159
+ { basis: buttonStyle === "icons" ? 6 : 5, shrink: 0 });
160
+ this.controls.addChild(button(buttonStyle === "icons" ? "[ × ]" : "[Exit]", close),
161
+ { basis: buttonStyle === "icons" ? 5 : 6, shrink: 0 });
159
162
  const border = (render: (width: number) => string): Component => ({
160
163
  render: width => [this.theme().fg("border", render(width))], invalidate() {},
161
164
  });
package/src/timestamps.ts CHANGED
@@ -8,6 +8,10 @@ import { NativeRenderCache } from "./render-cache.js";
8
8
  type Message = ReturnType<typeof sessionEntryToContextMessages>[number];
9
9
  type TimedSource = { message: Message; time: unknown };
10
10
  type UserSlot = { kind: string; text?: string; time: unknown };
11
+ interface BranchTimes {
12
+ messageTimes: WeakMap<object, unknown>; users: TimedSource[]; bash: TimedSource[];
13
+ starts: Map<string, number>; owners: Map<string, unknown>;
14
+ }
11
15
 
12
16
  // Identical native padding is common across cold blocks. Keep only a few short blank rows.
13
17
  const blankRows = new Set<string>();
@@ -33,10 +37,17 @@ const validTime = (value: unknown): number | undefined => {
33
37
  export function timestampLabel(value: unknown): string {
34
38
  const time = validTime(value);
35
39
  if (time === undefined) return "";
40
+ // Every visible block asks for its clock on every frame.
41
+ let label = labels.get(time);
42
+ if (label !== undefined) return label;
36
43
  const date = new Date(time);
37
- return [date.getHours(), date.getMinutes(), date.getSeconds()]
44
+ label = [date.getHours(), date.getMinutes(), date.getSeconds()]
38
45
  .map(part => String(part).padStart(2, "0")).join(":");
46
+ if (labels.size >= 8192) labels.clear();
47
+ labels.set(time, label);
48
+ return label;
39
49
  }
50
+ const labels = new Map<number, string>();
40
51
 
41
52
  const userSlots = ({ message, time }: TimedSource): UserSlot[] => {
42
53
  if (message.role !== "user") return [];
@@ -59,16 +70,52 @@ export class TranscriptTimestamps {
59
70
  private owners = new Map<string, unknown>();
60
71
  private readonly liveCalls = new Set<string>();
61
72
  private pendingUser?: { source: TimedSource; before: number; ended: boolean };
73
+ private readonly liveUsers = new Map<number, TimedSource>();
62
74
  private frameActive = false;
63
75
  private preparedComponents?: Component[];
64
76
 
65
77
  constructor(private readonly session: ExtensionContext["sessionManager"]) {}
66
78
 
79
+ private branch?: { leaf: object; sources: TimedSource[]; derived?: BranchTimes };
80
+
81
+ /** Session entries are append-only, so one leaf entry identifies the whole active branch. */
82
+ private leaf(): object | undefined {
83
+ const leaf = typeof this.session.getLeafEntry === "function" ? this.session.getLeafEntry() : undefined;
84
+ return leaf && typeof leaf === "object" ? leaf : undefined;
85
+ }
67
86
  private sources(): TimedSource[] {
68
- return this.session.buildContextEntries().flatMap(entry =>
87
+ const leaf = this.leaf();
88
+ if (leaf && this.branch?.leaf === leaf) return this.branch.sources;
89
+ const sources = this.session.buildContextEntries().flatMap(entry =>
69
90
  sessionEntryToContextMessages(entry).map(message => ({
70
91
  message, time: validTime("timestamp" in message ? message.timestamp : undefined) ?? entry.timestamp,
71
92
  })));
93
+ this.branch = leaf ? { leaf, sources } : undefined;
94
+ return sources;
95
+ }
96
+ /** Branch-derived lookups are rebuilt only when the active branch changes. */
97
+ private times(): BranchTimes {
98
+ const sources = this.sources();
99
+ if (this.branch?.sources === sources && this.branch.derived) return this.branch.derived;
100
+ const users = sources.filter(source => source.message.role === "user");
101
+ const starts = new Map<string, number>();
102
+ for (const entry of this.session.getBranch()) {
103
+ if (entry.type !== "custom" || entry.customType !== TOOL_START_ENTRY || !entry.data || typeof entry.data !== "object") continue;
104
+ const data = entry.data as { toolCallId?: unknown; time?: unknown };
105
+ const time = validTime(data.time);
106
+ if (typeof data.toolCallId === "string" && time !== undefined) starts.set(data.toolCallId, time);
107
+ }
108
+ const owners = new Map<string, unknown>();
109
+ for (const { message, time } of sources) {
110
+ if (message.role !== "assistant") continue;
111
+ for (const block of message.content) if (block.type === "toolCall") owners.set(block.id, time);
112
+ }
113
+ const derived = {
114
+ messageTimes: new WeakMap(sources.map(source => [source.message, source.time])), users,
115
+ bash: sources.filter(source => source.message.role === "bashExecution"), starts, owners,
116
+ };
117
+ if (this.branch?.sources === sources) this.branch.derived = derived;
118
+ return derived;
72
119
  }
73
120
 
74
121
  /** Include the current unpersisted user and streamed tool IDs before UI delivery. */
@@ -77,10 +124,11 @@ export class TranscriptTimestamps {
77
124
  if (message.role === "user") {
78
125
  if (!ended) {
79
126
  this.pendingUser = {
80
- source: { message, time: message.timestamp },
127
+ source: { message: { ...message, content: typeof message.content === "string" ? message.content : message.content.map(block => ({ ...block })) }, time: message.timestamp },
81
128
  before: this.sources().filter(source => source.message.role === "user").length,
82
129
  ended: false,
83
130
  };
131
+ this.liveUsers.set(this.pendingUser.before, this.pendingUser.source);
84
132
  } else if (this.pendingUser) {
85
133
  this.pendingUser.ended = true;
86
134
  }
@@ -97,10 +145,12 @@ export class TranscriptTimestamps {
97
145
  this.preparedComponents = undefined;
98
146
  this.pendingUser = undefined;
99
147
  this.liveCalls.clear();
148
+ this.liveUsers.clear();
100
149
  this.orderedLabels = new WeakMap();
101
150
  this.messageTimes = new WeakMap();
102
- this.starts.clear();
103
- this.owners.clear();
151
+ this.branch = undefined;
152
+ this.starts = new Map();
153
+ this.owners = new Map();
104
154
  }
105
155
 
106
156
  /** Share one history correlation across the panels measured in a native frame. */
@@ -112,42 +162,44 @@ export class TranscriptTimestamps {
112
162
  prepare(components: Component[]): void {
113
163
  if (this.frameActive && this.preparedComponents === components) return;
114
164
  this.preparedComponents = components;
115
- const sources = this.sources();
116
- this.messageTimes = new WeakMap(sources.map(source => [source.message, source.time]));
117
- const users = sources.filter(source => source.message.role === "user");
165
+ const { messageTimes, users, bash, starts, owners } = this.times();
166
+ this.messageTimes = messageTimes;
118
167
  if (this.pendingUser?.ended && users.length > this.pendingUser.before) this.pendingUser = undefined;
119
- const slots = users.flatMap(userSlots);
120
168
  const nativeUsers = components.filter(component =>
121
169
  component.constructor.name === "UserMessageComponent" || component.constructor.name === "SkillInvocationMessageComponent");
122
- if (nativeUsers.length !== slots.length && this.pendingUser) slots.push(...userSlots(this.pendingUser.source));
123
- this.orderedLabels = new WeakMap();
124
- if (nativeUsers.length === slots.length) {
125
- // Text is a compatibility check after ordinal association, never an identity key.
126
- const matches = nativeUsers.every((component, index) => {
127
- const slot = slots[index];
128
- return component.constructor.name === slot.kind &&
170
+ const sources = users.slice();
171
+ if (this.pendingUser && users.length === this.pendingUser.before) sources.push(this.pendingUser.source);
172
+ const associations: Array<{ component: Component; time: unknown }> = [];
173
+ let position = 0;
174
+ let matched = true;
175
+ for (const [index, source] of sources.entries()) {
176
+ const live = this.liveUsers.get(index);
177
+ // An extension may replace a message after Pi rendered it. Use the observed
178
+ // version only for the same timestamp and only if it matches native text.
179
+ const candidates = [userSlots(source)];
180
+ if (live && validTime(live.time) !== undefined && validTime(live.time) === validTime(source.time)) {
181
+ candidates.push(userSlots(live));
182
+ }
183
+ const slots = candidates.find(candidate => candidate.every((slot, offset) => {
184
+ const component = nativeUsers[position + offset];
185
+ return component?.constructor.name === slot.kind &&
129
186
  (slot.text === undefined || (component as Component & { text?: unknown }).text === slot.text);
130
- });
131
- if (matches) nativeUsers.forEach((component, index) => this.orderedLabels.set(component, timestampLabel(slots[index].time)));
187
+ }));
188
+ if (!slots) { matched = false; break; }
189
+ slots.forEach((slot, offset) => associations.push({ component: nativeUsers[position + offset], time: slot.time }));
190
+ position += slots.length;
191
+ }
192
+ this.orderedLabels = new WeakMap();
193
+ if (matched && position === nativeUsers.length) {
194
+ for (const { component, time } of associations) this.orderedLabels.set(component, timestampLabel(time));
132
195
  }
133
- const bash = sources.filter(source => source.message.role === "bashExecution");
134
196
  const nativeBash = components.filter(component => component.constructor.name === "BashExecutionComponent");
135
197
  if (nativeBash.length === bash.length && nativeBash.every((component, index) =>
136
198
  (component as Component & { command?: unknown }).command === (bash[index].message as { command: string }).command)) {
137
199
  nativeBash.forEach((component, index) => this.orderedLabels.set(component, timestampLabel(bash[index].time)));
138
200
  }
139
- this.starts.clear();
140
- for (const entry of this.session.getBranch()) {
141
- if (entry.type !== "custom" || entry.customType !== TOOL_START_ENTRY || !entry.data || typeof entry.data !== "object") continue;
142
- const data = entry.data as { toolCallId?: unknown; time?: unknown };
143
- const time = validTime(data.time);
144
- if (typeof data.toolCallId === "string" && time !== undefined) this.starts.set(data.toolCallId, time);
145
- }
146
- this.owners.clear();
147
- for (const { message, time } of sources) {
148
- if (message.role !== "assistant") continue;
149
- for (const block of message.content) if (block.type === "toolCall") this.owners.set(block.id, time);
150
- }
201
+ this.starts = starts;
202
+ this.owners = owners;
151
203
  }
152
204
 
153
205
  /** Reject changed private metadata before relying on it for a label. */
@@ -191,10 +243,9 @@ export class TranscriptTimestamps {
191
243
  }
192
244
  }
193
245
 
194
- // CGJ avoids xterm's single-codepoint rescaling without changing the visible glyph.
195
- // The trailing blank reserves its overhang and keeps the control two cells wide.
196
- const COPY_CONTROL = "⧉\u034f ";
197
- const COPY_CONTROL_WIDTH = visibleWidth(COPY_CONTROL);
246
+ const TEXT_COPY_CONTROL = "[Copy]";
247
+ // CGJ avoids xterm's single-codepoint rescaling; the space reserves glyph overhang.
248
+ const ICON_COPY_CONTROL = "[ ⧉\u034f ]";
198
249
  /** Keep message text full-width, with a clock above and copy action below. */
199
250
  export class CompactMessage extends Container {
200
251
  private top = 0;
@@ -205,6 +256,7 @@ export class CompactMessage extends Container {
205
256
  private bodyRows = 0;
206
257
  private copyRow?: number;
207
258
  private copyColumn?: number;
259
+ private copyWidth = 0;
208
260
  private copyPressed = false;
209
261
  private leadingRows = 0;
210
262
  private prepared?: { width: number; content: string[]; lines: string[] };
@@ -214,7 +266,8 @@ export class CompactMessage extends Container {
214
266
  constructor(private readonly component: Component, private readonly label: () => string,
215
267
  private readonly theme: () => Theme, private readonly gutter: () => number,
216
268
  private readonly show: () => boolean, private readonly copy?: () => void,
217
- private readonly showCopy: () => boolean = () => true) {
269
+ private readonly showCopy: () => boolean = () => true,
270
+ private readonly buttonStyle: () => "icons" | "text" = () => "text") {
218
271
  super();
219
272
  this.addChild(component);
220
273
  this.nativeCache = new NativeRenderCache(component);
@@ -252,7 +305,9 @@ export class CompactMessage extends Container {
252
305
  // Only the scrollbar needs a side gutter; controls have their own rows.
253
306
  this.contentWidth = Math.max(1, width - gutter);
254
307
  const time = label && this.show() && visibleWidth(label) + 1 <= this.contentWidth ? " " + label : "";
255
- const copy = label && this.copy && this.showCopy() && this.contentWidth >= COPY_CONTROL_WIDTH ? COPY_CONTROL : "";
308
+ const control = this.buttonStyle() === "icons" ? ICON_COPY_CONTROL : TEXT_COPY_CONTROL;
309
+ const controlWidth = visibleWidth(control);
310
+ const copy = label && this.copy && this.showCopy() && this.contentWidth >= controlWidth ? control : "";
256
311
  const content = this.nativeCache.render(this.contentWidth, theme);
257
312
  this.contentHeight = content.length;
258
313
  const cached = this.formatted;
@@ -288,8 +343,9 @@ export class CompactMessage extends Container {
288
343
  const lines = time ? [theme.fg("dim", time), ...body] : body;
289
344
  if (copy) {
290
345
  this.copyRow = lines.length;
291
- this.copyColumn = this.contentWidth - COPY_CONTROL_WIDTH;
292
- lines.push(" ".repeat(this.copyColumn) + theme.style(copy, { fg: "dim", dim: true }));
346
+ this.copyWidth = controlWidth;
347
+ this.copyColumn = this.contentWidth - controlWidth;
348
+ lines.push(" ".repeat(this.copyColumn) + theme.style(copy, { fg: "dim", dim: this.buttonStyle() === "icons" }));
293
349
  }
294
350
  this.formatted = { width, time, copy, gutter, theme, version: this.nativeCache.version, top: this.top, lines };
295
351
  return lines;
@@ -300,7 +356,7 @@ export class CompactMessage extends Container {
300
356
  width: event.width, height: event.height };
301
357
  const onCopy = this.copyColumn !== undefined && this.copyRow !== undefined &&
302
358
  event.y === this.leadingRows + this.copyRow && event.x >= this.copyColumn &&
303
- event.x < this.copyColumn + COPY_CONTROL_WIDTH && event.button === "left";
359
+ event.x < this.copyColumn + this.copyWidth && event.button === "left";
304
360
  if (onCopy && event.type === "press") {
305
361
  this.copyPressed = true;
306
362
  return { handled: true, capture: true, target };
@@ -8,10 +8,22 @@ export class ToolIndent extends Container {
8
8
  super(); this.addChild(component);
9
9
  this.prefix = " ".repeat(gutter) + " │".repeat(depth) + (body ? " " : "");
10
10
  }
11
+ // Expanded runs are re-indented on every frame; reuse rows while the native rows are unchanged.
12
+ private cached?: { width: number; prefix: string; source: string[]; lines: string[] };
11
13
  override render(width: number): string[] {
12
14
  const inset = Math.min(width, this.prefix.length);
13
15
  const prefix = this.theme().fg("dim", this.prefix.slice(0, inset));
14
- return super.render(Math.max(0, width - inset)).map(line => truncateToWidth(prefix + line, width, ""));
16
+ const source = super.render(Math.max(0, width - inset));
17
+ const cached = this.cached;
18
+ if (cached && cached.width === width && cached.prefix === prefix && cached.source.length === source.length &&
19
+ cached.source.every((line, index) => line === source[index])) return cached.lines;
20
+ const lines = source.map(line => truncateToWidth(prefix + line, width, ""));
21
+ this.cached = { width, prefix, source, lines };
22
+ return lines;
23
+ }
24
+ override invalidate(): void {
25
+ this.cached = undefined;
26
+ super.invalidate();
15
27
  }
16
28
  override handleMouse(event: TuiMouseEvent): ReturnType<Container["handleMouse"]> {
17
29
  const inset = Math.min(event.width, this.prefix.length);