pi-stereo-view 0.1.14 → 0.1.16

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,32 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.1.16 - 2026-11-08
6
+
7
+ ### Changed
8
+
9
+ - Use descriptive labels for text controls and wrap controls onto additional lines in narrow panels.
10
+ - Separate the toolbar from history with a full-width line in combined view.
11
+
12
+ ### Fixed
13
+
14
+ - Close Stereo View settings when clicking outside the menu.
15
+ - Keep the panel header background continuous between controls and across wrapped rows.
16
+
17
+ ## 0.1.15 - 2026-11-08
18
+
19
+ ### Added
20
+
21
+ - Choose icons or text for toolbar, panel, search and copy controls in Stereo View settings. The choice survives restart.
22
+
23
+ ### Changed
24
+
25
+ - Use consistent spacing between adjacent buttons. In narrow search panels, hide the match counter when needed to keep the query editable.
26
+
27
+ ### Fixed
28
+
29
+ - Keep timestamps and copy controls on user messages when an extension replaces a message after it is displayed.
30
+
5
31
  ## 0.1.14 - 2026-11-07
6
32
 
7
33
  ### Fixed
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
+ | `[ ▣ ]` / `[ ◫ ]` | `[Combine]` / `[Split]` | Turn split history off / on. |
82
+ | `[ ▤ ]` / `[ ▥ ]` | `[Rows]` / `[Columns]` | Switch between rows and columns. |
83
+ | `[ ↕ ]` / `[ ↔ ]` | `[Swap]` | Swap the panels. |
84
+ | `[ ↗ ]` / `[ ↙ ]` | `[Maximize]` / `[Restore]` | Zoom a panel / restore the split. |
85
+ | `[ ≡ ]` | `[Menu]` | Open display and Conversation height settings. |
86
+ | `[ ⌕ ]` | `[Find]` | Search this panel. |
87
+ | `[ ⊟ ]` / `[ ⊞ ]` | `[Compact tools]` / `[Full tools]` | 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 `[Compact tools]` beside Find 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 `[Full tools]` 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.14",
3
+ "version": "0.1.16",
4
4
  "type": "module",
5
5
  "description": "Keep Pi conversation separate from tool output and agent activity.",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import path from "node:path";
2
2
  import { copyToClipboard, getAgentDir, getSettingsListTheme, type ExtensionAPI, type ExtensionContext } from "@earendil-works/pi-coding-agent";
3
- import { Box, Container, isKeyRelease, matchesKey, SettingsList, Text, type TUI } from "@earendil-works/pi-tui";
3
+ import { Box, Container, isKeyRelease, matchesKey, SettingsList, Text, type OverlayHandle, type TUI, type TuiMouseEvent } from "@earendil-works/pi-tui";
4
4
  import { TranscriptLayout } from "./layout.js";
5
5
  import { TOOL_START_ENTRY, TranscriptTimestamps } from "./timestamps.js";
6
6
  import { defaults, loadPreferences, savePreferences, type Preferences } from "./preferences.js";
@@ -37,15 +37,33 @@ export default async function transcript(pi: ExtensionAPI): Promise<void> {
37
37
  settingsOpen = true;
38
38
  closeSearch();
39
39
  try {
40
+ let overlay: OverlayHandle | undefined;
40
41
  await ui.custom<void>((tui, _theme, _keys, done) => {
42
+ // Pi dispatches outside clicks to the underlying layout, not the overlay.
43
+ const viewport = tui as unknown as { dispatchMouseToOverlay?: (event: TuiMouseEvent) => { hit: boolean } };
44
+ const dispatch = viewport.dispatchMouseToOverlay;
45
+ const ownDispatch = Object.hasOwn(viewport, "dispatchMouseToOverlay");
46
+ const dismissOutside = dispatch && function (event: TuiMouseEvent): { hit: boolean } {
47
+ const result = dispatch.call(viewport, event);
48
+ if (!result.hit && event.type === "press" && event.button === "left" && overlay?.isFocused()) {
49
+ done();
50
+ return { hit: true };
51
+ }
52
+ return result;
53
+ };
54
+ if (dismissOutside) viewport.dispatchMouseToOverlay = dismissOutside;
41
55
  const list = new SettingsList([{
42
56
  id: "timestamps", label: "Show timestamps",
43
57
  description: "Hide clock rows without changing messages or recorded tool starts.",
44
58
  currentValue: preferences.showTimestamps ? "on" : "off", values: ["on", "off"],
45
59
  }, {
46
60
  id: "copyButtons", label: "Show copy buttons",
47
- description: "Hide copy icons and their rows; keyboard copying stays available.",
61
+ description: "Hide copy buttons and their rows; keyboard copying stays available.",
48
62
  currentValue: preferences.showCopyButtons ? "on" : "off", values: ["on", "off"],
63
+ }, {
64
+ id: "buttonStyle", label: "Button style",
65
+ description: "Choose icons or text for toolbar, panel and copy controls.",
66
+ currentValue: preferences.buttonStyle, values: ["icons", "text"],
49
67
  }, {
50
68
  id: "compactTools", label: "Compact Activity tools",
51
69
  description: "Group adjacent tools and expand individual calls inline. Full text stays searchable and copyable.",
@@ -54,9 +72,10 @@ export default async function transcript(pi: ExtensionAPI): Promise<void> {
54
72
  id: "height", label: "Conversation height",
55
73
  description: "Auto grows to half the history area. Drag sets a manual maximum.",
56
74
  currentValue: preferences.chatHeight === null ? "auto" : "manual", values: ["auto", "manual"],
57
- }], 4, getSettingsListTheme(), (id, value) => {
75
+ }], 5, getSettingsListTheme(), (id, value) => {
58
76
  if (id === "timestamps") layout?.setTimestamps(value === "on");
59
77
  else if (id === "copyButtons") layout?.setCopyButtons(value === "on");
78
+ else if (id === "buttonStyle") layout?.setButtonStyle(value === "text" ? "text" : "icons");
60
79
  else if (id === "compactTools") layout?.setCompactTools(value === "on");
61
80
  else if (id === "height") layout?.setAutomaticHeight(value === "auto");
62
81
  tui.requestRender();
@@ -73,12 +92,18 @@ export default async function transcript(pi: ExtensionAPI): Promise<void> {
73
92
  render: (width: number) => box.render(width),
74
93
  invalidate: () => box.invalidate(),
75
94
  handleMouse: (event) => box.handleMouse(event),
95
+ dispose: () => {
96
+ if (viewport.dispatchMouseToOverlay === dismissOutside) {
97
+ if (ownDispatch) viewport.dispatchMouseToOverlay = dispatch;
98
+ else delete viewport.dispatchMouseToOverlay;
99
+ }
100
+ },
76
101
  handleInput: (data: string) => {
77
102
  list.handleInput(data);
78
103
  tui.requestRender();
79
104
  },
80
105
  };
81
- }, { overlay: true, overlayOptions: { width: 60, margin: 1 } });
106
+ }, { overlay: true, overlayOptions: { width: 60, margin: 1 }, onHandle: handle => { overlay = handle; } });
82
107
  } finally {
83
108
  settingsOpen = false;
84
109
  }
@@ -238,7 +263,7 @@ export default async function transcript(pi: ExtensionAPI): Promise<void> {
238
263
  const choice = await ctx.ui.select("Copy a block from the active panel", blocks.map(block => block.label));
239
264
  blocks.find(block => block.label === choice)?.copy();
240
265
  } 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");
266
+ ctx.ui.notify("pi-stereo-view: choose icon or text buttons in /stereo-view settings. Buttons: ▣/Combine combines history, ◫/Split separates it, ▤/Rows and ▥/Columns change layout, ↕/↔/Swap exchanges panels, ↗/Maximize and ↙/Restore change panel size, ⌕/Find searches, ⊟/Compact tools and ⊞/Full tools 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
267
  } else if (action === "swap") layout.swap();
243
268
  else if (action === "width" && /^\d+$/.test(target ?? "")) layout.setWidth(Number(target));
244
269
  else if (action === "height" && target === "auto") layout.setHeight(null);
package/src/layout.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { setImmediate } from "node:timers/promises";
2
2
  import type { Theme, ToolInfo } from "@earendil-works/pi-coding-agent";
3
3
  import {
4
- Container, HStack, isViewportTUI, mixColors, MouseRegion, rgbColor, ScrollView, Text, truncateToWidth, VStack,
4
+ Container, HStack, isViewportTUI, mixColors, MouseRegion, rgbColor, ScrollView, Text, truncateToWidth, visibleWidth, VStack,
5
5
  type Color, type Component, type ScrollViewOptions, type StackChild, type TUI, type TuiMouseEvent,
6
6
  } from "@earendil-works/pi-tui";
7
7
  import { NativeDocument, type Pane } from "./native.js";
@@ -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,74 @@ class NativeSurfaceScrollView extends ScrollView {
44
44
  }
45
45
  }
46
46
 
47
+ class ButtonStack extends VStack {
48
+ private style: "icons" | "text" = "icons";
49
+ private lastLayout = "";
50
+
51
+ constructor(private readonly items: StackChild[], private readonly controls: { index: number; icon: number }[],
52
+ private readonly titleLength?: number, private readonly fill?: Component) {
53
+ super();
54
+ }
55
+
56
+ setStyle(style: "icons" | "text"): void {
57
+ if (this.style !== style) { this.style = style; this.lastLayout = ""; }
58
+ }
59
+
60
+ override render(width: number): string[] {
61
+ const textWidth = (index: number): number => {
62
+ const item = this.items[index];
63
+ const component = "component" in item ? item.component : item;
64
+ return (component as Component & { textWidth(): number }).textWidth();
65
+ };
66
+ const layout = `${this.style}:${width}:${this.style === "text" ? this.controls.map(control => textWidth(control.index)).join(",") : ""}`;
67
+ if (layout !== this.lastLayout) {
68
+ this.lastLayout = layout;
69
+ this.clear();
70
+ const entries = this.items.map((item, index) => {
71
+ const entry = "component" in item ? { ...item } : { component: item };
72
+ const control = this.controls.find(candidate => candidate.index === index);
73
+ if (control) {
74
+ entry.basis = this.style === "icons" ? control.icon : textWidth(index);
75
+ entry.minSize = entry.basis;
76
+ entry.shrink = 0;
77
+ } else if (this.titleLength !== undefined) {
78
+ entry.minSize = this.style === "icons" ? 1 : this.titleLength;
79
+ }
80
+ return entry;
81
+ });
82
+ if (this.style === "icons") {
83
+ this.addChild(new HStack(entries), { basis: 1, shrink: 0 });
84
+ } else {
85
+ let row: StackChild[] = [];
86
+ let occupied = 0;
87
+ const flush = (): void => {
88
+ if (row.length) {
89
+ const spaced = row.map((item, index) => {
90
+ const entry = "component" in item ? { ...item } : { component: item };
91
+ if (index < row.length - 1) {
92
+ if (typeof entry.basis === "number" && !entry.grow) entry.basis++;
93
+ entry.minSize = (entry.minSize ?? 0) + 1;
94
+ }
95
+ return entry;
96
+ });
97
+ if (this.fill && !row.includes(entries[0])) spaced.push({ component: this.fill, basis: 0, grow: 1 });
98
+ this.addChild(new HStack(spaced), { basis: 1, shrink: 0 });
99
+ }
100
+ row = []; occupied = 0;
101
+ };
102
+ for (const [index, entry] of entries.entries()) {
103
+ const control = this.controls.find(candidate => candidate.index === index);
104
+ const size = control ? textWidth(index) : this.titleLength ?? 0;
105
+ if (row.length && occupied + 1 + size > width) flush();
106
+ occupied += (row.length ? 1 : 0) + size;
107
+ row.push(entry);
108
+ }
109
+ flush();
110
+ }
111
+ }
112
+ return super.render(width);
113
+ }
114
+ }
47
115
  class TranscriptColumns extends HStack {
48
116
  /** Reserve a fixed width for Conversation, independent of its content. */
49
117
  sizeConversation(component: Component, width: number): void {
@@ -154,9 +222,9 @@ export class TranscriptLayout {
154
222
  private readonly getEditor: () => Component | undefined = () => undefined,
155
223
  ) {}
156
224
 
157
- private button(icon: () => string, action: () => void, enabled = (): boolean => true, background?: () => Color): Component {
158
- return new MouseRegion({
159
- render: width => new Text(this.theme().style("[ " + icon() + " ]", {
225
+ private button(label: () => string, action: () => void, enabled = (): boolean => true, background?: () => Color): Component {
226
+ const button = new MouseRegion({
227
+ render: width => new Text(this.theme().style((this.preferences.buttonStyle === "icons" ? "[ " + label() + " ]" : "[" + label() + "]").padEnd(width), {
160
228
  fg: enabled() ? "accent" : "dim", bg: background?.(),
161
229
  }), 0, 0).render(width),
162
230
  invalidate() {},
@@ -169,6 +237,7 @@ export class TranscriptLayout {
169
237
  }
170
238
  return { handled: true };
171
239
  });
240
+ return Object.assign(button, { textWidth: () => visibleWidth(label()) + 2 });
172
241
  }
173
242
 
174
243
  /** Mount controls only on a compatible native fullscreen history tree. */
@@ -249,9 +318,9 @@ export class TranscriptLayout {
249
318
  const index = new NativeContentIndex(document, this.nested);
250
319
  const activityDocument = new NativeDocument(document, "activity", this.timestamps, this.theme, timestampGutter, showTimestamps,
251
320
  () => 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 }); });
321
+ () => { if (this.activity) this.activity.scrollTo(this.activity.scrollTop, { disableFollow: true }); }, () => this.preferences.buttonStyle);
253
322
  const chatDocument = new NativeDocument(document, "chat", this.timestamps, this.theme, timestampGutter, showTimestamps,
254
- () => this.activate("chat"), false, index, this.copy, showCopyButtons);
323
+ () => this.activate("chat"), false, index, this.copy, showCopyButtons, undefined, undefined, undefined, () => this.preferences.buttonStyle);
255
324
  this.documents = { activity: activityDocument, chat: chatDocument };
256
325
  this.disposeDocuments = () => {
257
326
  activityDocument.dispose();
@@ -269,6 +338,8 @@ export class TranscriptLayout {
269
338
  () => this.searchPane() === "activity");
270
339
  this.chat = new PanelScrollView(chatDocument, scrollOptions, () => this.activate("chat"), () => this.searchPane() === "chat");
271
340
  let historyHeight = 0;
341
+ let chatHeader: Component;
342
+ let activityHeader: Component;
272
343
  let projectSurface = false;
273
344
  // Every root entry asks in turn during one visibility pass; evaluate the projection once.
274
345
  let pass: { width: number; height: number; shown: boolean } | undefined;
@@ -282,16 +353,22 @@ export class TranscriptLayout {
282
353
  const candidate = !!projectedDock && (widgetsPresent() || dialogPresent()) && dockUnchanged() && !this.failed &&
283
354
  this.preferences.mode === "split" && this.preferences.zoom !== "chat";
284
355
  projectDialog = candidate && dialogPresent();
285
- historyHeight = Math.max(0, height - (candidate ? projectedDock : dock).render(width).length - 1);
356
+ historyHeight = Math.max(0, height - (candidate ? projectedDock : dock).render(width).length - toolbar.render(width).length);
286
357
  const search = this.search;
287
358
  if (search && previousHeight !== historyHeight) queueMicrotask(() => {
288
359
  if (this.search === search) search.bar.reposition();
289
360
  });
290
361
  this.automaticHeight = Math.max(MIN_ROWS, Math.floor(historyHeight / 2));
291
- const searchRows = this.search ? PANEL_SEARCH_ROWS : 0;
292
- const fits = this.preferences.zoom ? width >= MIN_CHAT && historyHeight >= MIN_ROWS + searchRows :
293
- this.preferences.layout === "columns" ? width >= MIN_CHAT + MIN_ACTIVITY + 1 && historyHeight >= MIN_ROWS + searchRows :
294
- width >= MIN_CHAT && historyHeight >= MIN_ROWS * 2 + 1 + searchRows;
362
+ const chatWidth = this.preferences.zoom || this.preferences.layout === "rows" ? width : Math.min(width - MIN_ACTIVITY - 1,
363
+ Math.max(MIN_CHAT, this.preferences.chatWidth ?? this.defaultWidth(width)));
364
+ const activityWidth = this.preferences.zoom || this.preferences.layout === "rows" ? width : width - chatWidth - 1;
365
+ const chatSearch = this.search?.pane === "chat" ? PANEL_SEARCH_ROWS : 0;
366
+ const activitySearch = this.search?.pane === "activity" ? PANEL_SEARCH_ROWS : 0;
367
+ const chatMin = Math.max(MIN_ROWS + chatSearch, chatHeader.render(Math.max(1, chatWidth)).length + 1);
368
+ const activityMin = Math.max(MIN_ROWS + activitySearch, activityHeader.render(Math.max(1, activityWidth)).length + 1);
369
+ const fits = this.preferences.zoom ? width >= MIN_CHAT && historyHeight >= (this.preferences.zoom === "chat" ? chatMin : activityMin) :
370
+ this.preferences.layout === "columns" ? width >= MIN_CHAT + MIN_ACTIVITY + 1 && historyHeight >= Math.max(chatMin, activityMin) :
371
+ width >= MIN_CHAT && historyHeight >= chatMin + activityMin + 1;
295
372
  this.fallback = this.preferences.mode === "split" && !fits;
296
373
  projectSurface = candidate && fits;
297
374
  if (this.search && (this.fallback || this.failed || this.preferences.mode !== "split" ||
@@ -303,21 +380,14 @@ export class TranscriptLayout {
303
380
  // Both panels project the same native history and supported content kinds.
304
381
  activityDocument.check();
305
382
  if (projectSurface && surfaceTree && surfacePresent()) {
306
- const chatWidth = Math.min(width - MIN_ACTIVITY - 1,
307
- Math.max(MIN_CHAT, this.preferences.chatWidth ?? this.defaultWidth(width)));
308
- const widgetWidth = this.preferences.zoom === "activity" || this.preferences.layout === "rows"
309
- ? width : width - chatWidth - 1;
310
- const chatSearch = this.search?.pane === "chat" ? PANEL_SEARCH_ROWS : 0;
311
- const activitySearch = this.search?.pane === "activity" ? PANEL_SEARCH_ROWS : 0;
312
- const chatMin = MIN_ROWS + chatSearch;
313
- const activityMin = MIN_ROWS + activitySearch;
383
+ const widgetWidth = activityWidth;
314
384
  const chatLimit = Math.max(chatMin, Math.min((this.preferences.chatHeight ?? this.automaticHeight) + chatSearch,
315
385
  historyHeight - activityMin - 1));
316
386
  const activityHeight = this.preferences.zoom || this.preferences.layout === "columns" ? historyHeight :
317
387
  historyHeight - 1 - Math.min(chatLimit, Math.max(chatMin, chatPane.render(width).length));
318
388
  // Do not clip opaque interactive surfaces: their own wheel handlers may consume scrolling.
319
389
  // If the entire surface cannot fit, leave Pi's original dock available instead.
320
- const budget = Math.max(0, activityHeight - 3 - activitySearch);
390
+ const budget = Math.max(0, activityHeight - activityHeader.render(widgetWidth).length);
321
391
  if (surfaceTree.render(widgetWidth).length > budget) {
322
392
  projectSurface = false;
323
393
  this.fallback = true;
@@ -328,12 +398,9 @@ export class TranscriptLayout {
328
398
  this.chat?.setScrollbar(scroll.scrollbar);
329
399
  columns.sizeConversation(chatPane, this.preferences.chatWidth ?? this.defaultWidth(width));
330
400
  // Keep short Conversation intact; shrink Activity first when history fills up.
331
- const chatSearchRow = this.search?.pane === "chat" ? PANEL_SEARCH_ROWS : 0;
332
- const chatMinimum = MIN_ROWS + chatSearchRow;
333
- const activityMinimum = MIN_ROWS + (this.search?.pane === "activity" ? PANEL_SEARCH_ROWS : 0);
334
- rows.limitConversation(chatPane, Math.max(chatMinimum,
335
- Math.min((this.preferences.chatHeight ?? this.automaticHeight) + chatSearchRow,
336
- historyHeight - activityMinimum - 1)), chatMinimum, activityMinimum);
401
+ rows.limitConversation(chatPane, Math.max(chatMin,
402
+ Math.min((this.preferences.chatHeight ?? this.automaticHeight) + chatSearch,
403
+ historyHeight - activityMin - 1)), chatMin, activityMin);
337
404
  return true;
338
405
  } catch (error) {
339
406
  projectSurface = false;
@@ -344,21 +411,27 @@ export class TranscriptLayout {
344
411
  return false;
345
412
  }
346
413
  };
347
- const toolbar = new HStack([
414
+ const headers: ButtonStack[] = [];
415
+ const toolbar = new ButtonStack([
348
416
  { component: this.button(
349
- () => this.preferences.mode === "combined" || this.fallback || this.failed ? "◫" : "▣",
417
+ () => this.preferences.mode === "combined" || this.fallback || this.failed ? (this.preferences.buttonStyle === "icons" ? "◫" : "Split") : (this.preferences.buttonStyle === "icons" ? "▣" : "Combine"),
350
418
  () => this.toggle(), () => !this.fallback && !this.failed,
351
- ), basis: BUTTON_WIDTH, shrink: 0 },
419
+ ), basis: TOOLBAR_BUTTON_WIDTH + 1, minSize: TOOLBAR_BUTTON_WIDTH, shrink: 1 },
352
420
  { component: this.button(
353
- () => this.preferences.layout === "columns" ? "▤" : "▥",
421
+ () => this.preferences.layout === "columns" ? (this.preferences.buttonStyle === "icons" ? "▤" : "Rows") : (this.preferences.buttonStyle === "icons" ? "▥" : "Columns"),
354
422
  () => this.setLayout(this.preferences.layout === "columns" ? "rows" : "columns"), () => !this.failed,
355
- ), basis: BUTTON_WIDTH, shrink: 0 },
423
+ ), basis: TOOLBAR_BUTTON_WIDTH + 1, minSize: TOOLBAR_BUTTON_WIDTH, shrink: 1 },
356
424
  { component: this.button(
357
- () => this.preferences.layout === "columns" ? "↔" : "↕", () => this.swap(),
425
+ () => this.preferences.buttonStyle === "icons" ? (this.preferences.layout === "columns" ? "↔" : "↕") : "Swap", () => this.swap(),
358
426
  () => this.preferences.mode === "split" && !this.preferences.zoom && !this.fallback && !this.failed,
359
- ), basis: BUTTON_WIDTH, shrink: 0 },
360
- { component: this.button(() => "≡", this.openSettings), basis: BUTTON_WIDTH, shrink: 0 },
361
- ], { gap: 1 });
427
+ ), basis: TOOLBAR_BUTTON_WIDTH + 1, minSize: TOOLBAR_BUTTON_WIDTH, shrink: 1 },
428
+ { component: this.button(() => this.preferences.buttonStyle === "icons" ? "≡" : "Menu", this.openSettings), basis: TOOLBAR_BUTTON_WIDTH, shrink: 0 },
429
+ ], [
430
+ { index: 0, icon: 6 },
431
+ { index: 1, icon: 6 },
432
+ { index: 2, icon: 6 },
433
+ { index: 3, icon: 5 },
434
+ ]);
362
435
  const pane = (title: string, target: Pane, view: ScrollView): Component => {
363
436
  const hue = target === "chat" ? rgbColor(104, 158, 115) : rgbColor(107, 152, 190);
364
437
  const palette = () => {
@@ -373,9 +446,9 @@ export class TranscriptLayout {
373
446
  render: width => [this.theme().style("─".repeat(width), { fg: palette().border })],
374
447
  invalidate() {},
375
448
  };
376
- const label = new HStack([
449
+ const label = new ButtonStack([
377
450
  { component: new MouseRegion({
378
- render: width => new Text(this.theme().style(truncateToWidth(" " + (this.searchPane() === target ? "● " : " ") + title, width, "").padEnd(width), {
451
+ render: width => new Text(this.theme().style(truncateToWidth(width < title.length + 3 ? title : " " + (this.searchPane() === target ? "● " : " ") + title, width, "").padEnd(width), {
379
452
  fg: this.searchPane() === target ? "accent" : palette().text, bg: palette().fill,
380
453
  }), 0, 0).render(width),
381
454
  invalidate() {},
@@ -385,32 +458,45 @@ export class TranscriptLayout {
385
458
  return { handled: true, render: true };
386
459
  }
387
460
  return undefined;
388
- }), basis: 0, grow: 1, minSize: 1 },
461
+ }), basis: 0, grow: 1, minSize: title.length },
389
462
  ...(target === "activity" ? [{ component: this.button(
390
- () => this.preferences.compactTools ? "⊞" : "⊟",
463
+ () => this.preferences.compactTools ? (this.preferences.buttonStyle === "icons" ? "⊞" : "Full tools") : (this.preferences.buttonStyle === "icons" ? "⊟" : "Compact tools"),
391
464
  () => {
392
465
  this.activate("activity");
393
466
  this.setCompactTools(!this.preferences.compactTools);
394
467
  }, () => true, () => palette().fill,
395
- ), basis: BUTTON_WIDTH, shrink: 0 }] : []),
396
- { component: this.button(() => "⌕", () => {
468
+ ), basis: 6, minSize: 5, shrink: 1 }] : []),
469
+ { component: this.button(() => this.preferences.buttonStyle === "icons" ? "⌕" : "Find", () => {
397
470
  this.activate(target);
398
471
  this.openSearch(target);
399
- }, () => true, () => palette().fill), basis: BUTTON_WIDTH, shrink: 0 },
472
+ }, () => true, () => palette().fill), basis: TOOLBAR_BUTTON_WIDTH + 1, minSize: TOOLBAR_BUTTON_WIDTH, shrink: 1 },
400
473
  { component: this.button(
401
- () => this.preferences.zoom === target ? "↙" : "↗",
474
+ () => this.preferences.zoom === target ? (this.preferences.buttonStyle === "icons" ? "↙" : "Restore") : (this.preferences.buttonStyle === "icons" ? "↗" : "Maximize"),
402
475
  () => this.maximize(target), () => true, () => palette().fill,
403
- ), basis: BUTTON_WIDTH, shrink: 0 },
404
- ]);
476
+ ), basis: 5, shrink: 0 },
477
+ ], target === "activity" ? [
478
+ { index: 1, icon: 6 },
479
+ { index: 2, icon: 6 },
480
+ { index: 3, icon: 5 },
481
+ ] : [
482
+ { index: 1, icon: 6 },
483
+ { index: 2, icon: 5 },
484
+ ], title.length, {
485
+ render: width => [this.theme().style(" ".repeat(width), { bg: palette().fill })],
486
+ invalidate() {},
487
+ });
488
+ headers.push(label);
405
489
  const header = new VStack([
406
490
  { component: line, basis: 1, shrink: 0, visible: () =>
407
491
  this.preferences.zoom !== null || this.preferences.layout === "columns" ||
408
492
  (this.preferences.side === "left" ? target === "chat" : target === "activity") },
409
- { component: label, basis: 1, shrink: 0 },
493
+ { component: label, basis: "auto", shrink: 0 },
410
494
  { component: line, basis: 1, shrink: 0 },
411
495
  { component: this.searchRows[target], basis: "auto", shrink: 0,
412
496
  visible: () => this.search?.pane === target },
413
497
  ]);
498
+ if (target === "chat") chatHeader = header;
499
+ else activityHeader = header;
414
500
  return new TranscriptPane(header, view, () => historyHeight,
415
501
  target === "activity" ? surfaceView : undefined, () => projectSurface && surfacePresent());
416
502
  };
@@ -451,6 +537,8 @@ export class TranscriptLayout {
451
537
  const columns = new TranscriptColumns();
452
538
  const rows = new TranscriptRows();
453
539
  this.rebuild = (): void => {
540
+ toolbar.setStyle(this.preferences.buttonStyle);
541
+ for (const header of headers) header.setStyle(this.preferences.buttonStyle);
454
542
  for (const [stack, axis] of [[columns, "columns"], [rows, "rows"]] as const) {
455
543
  stack.clear();
456
544
  const minimum = axis === "columns" ? MIN_CHAT : MIN_ROWS;
@@ -472,7 +560,7 @@ export class TranscriptLayout {
472
560
  };
473
561
  this.rebuild();
474
562
  const mounted = new TranscriptRoot([
475
- { component: toolbar, basis: 1, shrink: 0, visible: () => {
563
+ { component: toolbar, basis: "auto", shrink: 0, visible: () => {
476
564
  // Root visibility is evaluated once at the start of each native layout pass.
477
565
  pass = undefined;
478
566
  this.timestamps.beginFrame();
@@ -480,6 +568,10 @@ export class TranscriptLayout {
480
568
  chatDocument.beginFrame();
481
569
  return true;
482
570
  } },
571
+ { component: {
572
+ render: width => [this.theme().style("─".repeat(width), { fg: this.theme().colors.border })],
573
+ invalidate() {},
574
+ }, basis: 1, shrink: 0, visible: viewport => !shown(viewport) },
483
575
  { component: columns, basis: 0, grow: 1, minSize: 1,
484
576
  visible: viewport => shown(viewport) && !this.preferences.zoom && this.preferences.layout === "columns" },
485
577
  { component: rows, basis: "auto", minSize: 1,
@@ -556,7 +648,7 @@ export class TranscriptLayout {
556
648
  }
557
649
  void this.jumpToSearch(pane, hit, query, () => this.search?.bar === bar && this.searchVersion === version)
558
650
  .catch(error => this.warn("Could not navigate search: " + String(error)));
559
- }, () => this.closeSearch());
651
+ }, () => this.closeSearch(), this.preferences.buttonStyle);
560
652
  this.search = { pane, bar, document, view, top: view.scrollTop, following: view.isFollowingEnd,
561
653
  focus: host.getFocusedComponent() };
562
654
  this.searchRows[pane].addChild(bar);
@@ -641,6 +733,12 @@ export class TranscriptLayout {
641
733
  this.changed();
642
734
  }
643
735
 
736
+ /** Change the presentation of toolbar, header and copy controls. */
737
+ setButtonStyle(style: "icons" | "text"): void {
738
+ this.preferences.buttonStyle = style;
739
+ this.changed();
740
+ }
741
+
644
742
  /** Project tool calls as dense rows while retaining their full search and copy text. */
645
743
  setCompactTools(compact: boolean): void {
646
744
  this.preferences.compactTools = compact;
package/src/native.ts CHANGED
@@ -91,6 +91,7 @@ export class NativeDocument extends Container {
91
91
  private readonly compactTools: () => boolean = () => false,
92
92
  private readonly getTools: () => readonly ToolInfo[] = () => [],
93
93
  private readonly beforeExpand: () => void = () => {},
94
+ private readonly buttonStyle: () => "icons" | "text" = () => "text",
94
95
  ) {
95
96
  super();
96
97
  }
@@ -277,7 +278,7 @@ export class NativeDocument extends Container {
277
278
  if (!stamped) {
278
279
  stamped = new CompactMessage(routed, () => this.timestamps.label(this.clockOwners.get(component) ?? component),
279
280
  this.theme, this.timestampGutter, () => this.showTimestamps() && !(this.pane === "activity" && this.compactTools() && entry.kind === "tool"),
280
- this.copy ? () => this.copyBlock(component) : undefined, this.showCopy);
281
+ this.copy ? () => this.copyBlock(component) : undefined, this.showCopy, this.buttonStyle);
281
282
  this.stamped.set(routed, stamped);
282
283
  }
283
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
@@ -9,7 +9,7 @@ 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
11
  interface BranchTimes {
12
- messageTimes: WeakMap<object, unknown>; users: TimedSource[]; slots: UserSlot[]; bash: TimedSource[];
12
+ messageTimes: WeakMap<object, unknown>; users: TimedSource[]; bash: TimedSource[];
13
13
  starts: Map<string, number>; owners: Map<string, unknown>;
14
14
  }
15
15
 
@@ -70,6 +70,7 @@ export class TranscriptTimestamps {
70
70
  private owners = new Map<string, unknown>();
71
71
  private readonly liveCalls = new Set<string>();
72
72
  private pendingUser?: { source: TimedSource; before: number; ended: boolean };
73
+ private readonly liveUsers = new Map<number, TimedSource>();
73
74
  private frameActive = false;
74
75
  private preparedComponents?: Component[];
75
76
 
@@ -110,7 +111,7 @@ export class TranscriptTimestamps {
110
111
  for (const block of message.content) if (block.type === "toolCall") owners.set(block.id, time);
111
112
  }
112
113
  const derived = {
113
- messageTimes: new WeakMap(sources.map(source => [source.message, source.time])), users, slots: users.flatMap(userSlots),
114
+ messageTimes: new WeakMap(sources.map(source => [source.message, source.time])), users,
114
115
  bash: sources.filter(source => source.message.role === "bashExecution"), starts, owners,
115
116
  };
116
117
  if (this.branch?.sources === sources) this.branch.derived = derived;
@@ -123,10 +124,11 @@ export class TranscriptTimestamps {
123
124
  if (message.role === "user") {
124
125
  if (!ended) {
125
126
  this.pendingUser = {
126
- source: { message, time: message.timestamp },
127
+ source: { message: { ...message, content: typeof message.content === "string" ? message.content : message.content.map(block => ({ ...block })) }, time: message.timestamp },
127
128
  before: this.sources().filter(source => source.message.role === "user").length,
128
129
  ended: false,
129
130
  };
131
+ this.liveUsers.set(this.pendingUser.before, this.pendingUser.source);
130
132
  } else if (this.pendingUser) {
131
133
  this.pendingUser.ended = true;
132
134
  }
@@ -143,6 +145,7 @@ export class TranscriptTimestamps {
143
145
  this.preparedComponents = undefined;
144
146
  this.pendingUser = undefined;
145
147
  this.liveCalls.clear();
148
+ this.liveUsers.clear();
146
149
  this.orderedLabels = new WeakMap();
147
150
  this.messageTimes = new WeakMap();
148
151
  this.branch = undefined;
@@ -159,22 +162,36 @@ export class TranscriptTimestamps {
159
162
  prepare(components: Component[]): void {
160
163
  if (this.frameActive && this.preparedComponents === components) return;
161
164
  this.preparedComponents = components;
162
- const { messageTimes, users, slots: saved, bash, starts, owners } = this.times();
165
+ const { messageTimes, users, bash, starts, owners } = this.times();
163
166
  this.messageTimes = messageTimes;
164
167
  if (this.pendingUser?.ended && users.length > this.pendingUser.before) this.pendingUser = undefined;
165
- const slots = saved.slice();
166
168
  const nativeUsers = components.filter(component =>
167
169
  component.constructor.name === "UserMessageComponent" || component.constructor.name === "SkillInvocationMessageComponent");
168
- if (nativeUsers.length !== slots.length && this.pendingUser) slots.push(...userSlots(this.pendingUser.source));
169
- this.orderedLabels = new WeakMap();
170
- if (nativeUsers.length === slots.length) {
171
- // Text is a compatibility check after ordinal association, never an identity key.
172
- const matches = nativeUsers.every((component, index) => {
173
- const slot = slots[index];
174
- 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 &&
175
186
  (slot.text === undefined || (component as Component & { text?: unknown }).text === slot.text);
176
- });
177
- 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));
178
195
  }
179
196
  const nativeBash = components.filter(component => component.constructor.name === "BashExecutionComponent");
180
197
  if (nativeBash.length === bash.length && nativeBash.every((component, index) =>
@@ -226,10 +243,9 @@ export class TranscriptTimestamps {
226
243
  }
227
244
  }
228
245
 
229
- // CGJ avoids xterm's single-codepoint rescaling without changing the visible glyph.
230
- // The trailing blank reserves its overhang and keeps the control two cells wide.
231
- const COPY_CONTROL = "⧉\u034f ";
232
- 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 ]";
233
249
  /** Keep message text full-width, with a clock above and copy action below. */
234
250
  export class CompactMessage extends Container {
235
251
  private top = 0;
@@ -240,6 +256,7 @@ export class CompactMessage extends Container {
240
256
  private bodyRows = 0;
241
257
  private copyRow?: number;
242
258
  private copyColumn?: number;
259
+ private copyWidth = 0;
243
260
  private copyPressed = false;
244
261
  private leadingRows = 0;
245
262
  private prepared?: { width: number; content: string[]; lines: string[] };
@@ -249,7 +266,8 @@ export class CompactMessage extends Container {
249
266
  constructor(private readonly component: Component, private readonly label: () => string,
250
267
  private readonly theme: () => Theme, private readonly gutter: () => number,
251
268
  private readonly show: () => boolean, private readonly copy?: () => void,
252
- private readonly showCopy: () => boolean = () => true) {
269
+ private readonly showCopy: () => boolean = () => true,
270
+ private readonly buttonStyle: () => "icons" | "text" = () => "text") {
253
271
  super();
254
272
  this.addChild(component);
255
273
  this.nativeCache = new NativeRenderCache(component);
@@ -287,7 +305,9 @@ export class CompactMessage extends Container {
287
305
  // Only the scrollbar needs a side gutter; controls have their own rows.
288
306
  this.contentWidth = Math.max(1, width - gutter);
289
307
  const time = label && this.show() && visibleWidth(label) + 1 <= this.contentWidth ? " " + label : "";
290
- 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 : "";
291
311
  const content = this.nativeCache.render(this.contentWidth, theme);
292
312
  this.contentHeight = content.length;
293
313
  const cached = this.formatted;
@@ -323,8 +343,9 @@ export class CompactMessage extends Container {
323
343
  const lines = time ? [theme.fg("dim", time), ...body] : body;
324
344
  if (copy) {
325
345
  this.copyRow = lines.length;
326
- this.copyColumn = this.contentWidth - COPY_CONTROL_WIDTH;
327
- 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" }));
328
349
  }
329
350
  this.formatted = { width, time, copy, gutter, theme, version: this.nativeCache.version, top: this.top, lines };
330
351
  return lines;
@@ -335,7 +356,7 @@ export class CompactMessage extends Container {
335
356
  width: event.width, height: event.height };
336
357
  const onCopy = this.copyColumn !== undefined && this.copyRow !== undefined &&
337
358
  event.y === this.leadingRows + this.copyRow && event.x >= this.copyColumn &&
338
- event.x < this.copyColumn + COPY_CONTROL_WIDTH && event.button === "left";
359
+ event.x < this.copyColumn + this.copyWidth && event.button === "left";
339
360
  if (onCopy && event.type === "press") {
340
361
  this.copyPressed = true;
341
362
  return { handled: true, capture: true, target };