pi-stereo-view 0.1.8 → 0.1.10
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 +26 -0
- package/README.md +16 -2
- package/package.json +1 -1
- package/src/compact-tools.ts +63 -0
- package/src/content.ts +19 -4
- package/src/index.ts +8 -3
- package/src/layout.ts +18 -3
- package/src/native.ts +156 -12
- package/src/preferences.ts +7 -5
- package/src/tool-groups.ts +25 -0
- package/src/tool-presentation.ts +28 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.10 - 2026-10-26
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- Add a one-cell left inset before panel header content while keeping the colored background full width.
|
|
8
|
+
- Use `▸` and `▾` for collapsed and expanded compact tool groups and calls. The Activity header keeps its existing `⊟` / `⊞` controls.
|
|
9
|
+
|
|
10
|
+
## 0.1.9 - 2026-10-26
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Optional **Compact tools** mode shows tool calls as single-line status, name and argument previews. Full arguments and results remain searchable and copyable.
|
|
15
|
+
- Adjacent calls with the same verified tool identity and execution state form a group. Every failed call stays separate.
|
|
16
|
+
- Expand groups into individual calls, then open each original tool card independently. Left guides show both nesting levels, and linked output stays with its tool.
|
|
17
|
+
- Verified MCP forwarding calls show their original tool names. Unverified and custom tool names remain unchanged.
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- Show original tool timestamps inline-left, before the status and tool name. Expanded members retain their own start times.
|
|
22
|
+
- Inset compact Activity rows by one cell from the panel border.
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- Preserve opened cards and explicit group collapse when streaming calls form, split or merge groups.
|
|
27
|
+
- Keep native card wrapping, mouse actions and search positions aligned inside nested guides.
|
|
28
|
+
|
|
3
29
|
## 0.1.8 - 2026-10-25
|
|
4
30
|
|
|
5
31
|
### Fixed
|
package/README.md
CHANGED
|
@@ -32,6 +32,7 @@ Messages and tools keep their familiar appearance. The input stays full width be
|
|
|
32
32
|
## Features
|
|
33
33
|
|
|
34
34
|
- Arrange Conversation and Activity in columns or rows, swap or resize the panels, and zoom either one while keeping the input full width.
|
|
35
|
+
- Group consecutive Activity tools and expand individual calls inline while keeping thinking visible.
|
|
35
36
|
- Copy an individual user message, assistant reply or thinking block with its own copy icon.
|
|
36
37
|
- Copy a complete tool call with its arguments, saved result and linked late output, including collapsed and off-screen text.
|
|
37
38
|
- Search panel history with literal text, Boolean expressions or regular expressions, then jump between matches.
|
|
@@ -77,8 +78,9 @@ Click the toolbar and the buttons in each panel's header:
|
|
|
77
78
|
| `[ ▤ ]` / `[ ▥ ]` | Switch between rows and columns. |
|
|
78
79
|
| `[ ↕ ]` / `[ ↔ ]` | Swap the panels. |
|
|
79
80
|
| `[ ↗ ]` / `[ ↙ ]` | Zoom a panel / restore the split. |
|
|
80
|
-
| `[ ≡ ]` | Open
|
|
81
|
+
| `[ ≡ ]` | Open display and Conversation height settings. |
|
|
81
82
|
| `[ ⌕ ]` | Search this panel. |
|
|
83
|
+
| `[ ⊟ ]` / `[ ⊞ ]` | Compact Activity tools / restore full tools. |
|
|
82
84
|
|
|
83
85
|
**Resize:** drag the double line between the panels — `═` in rows, `║` in columns.
|
|
84
86
|
|
|
@@ -90,6 +92,16 @@ Panels fit short content and scroll when history fills up. Each panel has its ow
|
|
|
90
92
|
|
|
91
93
|
Swap the panels whenever you want. Zoom a panel to give it the whole history area; the input stays visible. Restore it to return to your split. Turning split off returns to one combined history; the toolbar stays available to turn it back on.
|
|
92
94
|
|
|
95
|
+
## Compact Activity
|
|
96
|
+
|
|
97
|
+
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.
|
|
98
|
+
|
|
99
|
+
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.
|
|
100
|
+
|
|
101
|
+
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.
|
|
102
|
+
|
|
103
|
+
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**.
|
|
104
|
+
|
|
93
105
|
## Search history
|
|
94
106
|
|
|
95
107
|
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.
|
|
@@ -129,6 +141,8 @@ Use **Show copy buttons** in `≡` or `/stereo-view settings` to hide the icons
|
|
|
129
141
|
|
|
130
142
|
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.
|
|
131
143
|
|
|
144
|
+
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.
|
|
145
|
+
|
|
132
146
|
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.
|
|
133
147
|
|
|
134
148
|
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.
|
|
@@ -157,7 +171,7 @@ Keyboard scrolling (`PgUp`/`PgDn` and Pi's other scroll keys) moves the active p
|
|
|
157
171
|
|
|
158
172
|
## Settings and limits
|
|
159
173
|
|
|
160
|
-
Your layout, panel order, sizes, timestamp and copy-button settings are saved automatically. Each new session opens both panels in that arrangement. Zooming one panel or turning split off is temporary and does not carry over to another session.
|
|
174
|
+
Your layout, panel order, sizes, compact Activity choice, timestamp and copy-button settings are saved automatically. Each new session opens both panels in that arrangement. Zooming one panel or turning split off is temporary and does not carry over to another session.
|
|
161
175
|
|
|
162
176
|
- Tested with Pi 1.1.0. Requires Node.js 22.19 or newer.
|
|
163
177
|
- Regular mode shows one combined history.
|
package/package.json
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { stripTerminalSequences, truncateToWidth, visibleWidth, type Component, type TuiMouseEvent } from "@earendil-works/pi-tui";
|
|
3
|
+
import type { ToolSummary } from "./content.js";
|
|
4
|
+
|
|
5
|
+
const singleLine = (text: string): string => stripTerminalSequences(text).replace(/[\x00-\x1f\x7f-\x9f]/g, " ").replace(/\s+/g, " ").trim();
|
|
6
|
+
|
|
7
|
+
/** Prefer the useful argument, falling back to a bounded preview of custom input. */
|
|
8
|
+
export function toolDescription(args: unknown): string {
|
|
9
|
+
if (typeof args === "string") return singleLine(args);
|
|
10
|
+
if (!args || typeof args !== "object") return args == null ? "" : String(args);
|
|
11
|
+
const record = args as Record<string, unknown>;
|
|
12
|
+
const values = ["command", "query", "pattern", "url", "path", "file_path", "file", "description", "code"];
|
|
13
|
+
for (const key of values) {
|
|
14
|
+
const value = record[key];
|
|
15
|
+
if (typeof value === "string" && value.trim()) return singleLine(value);
|
|
16
|
+
}
|
|
17
|
+
// Streamed args are JSON values; don't stringify a large file body just to label a call.
|
|
18
|
+
return Object.entries(record).slice(0, 3).map(([key, value]) => {
|
|
19
|
+
const preview = typeof value === "string" ? value.slice(0, 160) :
|
|
20
|
+
value === null || typeof value !== "object" ? String(value) : Array.isArray(value) ? "[…]" : "{…}";
|
|
21
|
+
return `${singleLine(key)}: ${singleLine(preview)}`;
|
|
22
|
+
}).join(" ");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface CompactToolOptions {
|
|
26
|
+
clock?(): string;
|
|
27
|
+
gutter?(): number;
|
|
28
|
+
count?(): number;
|
|
29
|
+
expanded?(): boolean;
|
|
30
|
+
toggle?(): void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** A display-only call or group header; the original renderer owns the body. */
|
|
34
|
+
export class CompactTool implements Component {
|
|
35
|
+
constructor(private readonly summary: () => ToolSummary, private readonly theme: () => Theme,
|
|
36
|
+
private readonly options: CompactToolOptions = {}) {}
|
|
37
|
+
|
|
38
|
+
render(width: number): string[] {
|
|
39
|
+
width = Math.max(0, width - (this.options.gutter?.() ?? 0));
|
|
40
|
+
const { name, args, status } = this.summary();
|
|
41
|
+
const theme = this.theme();
|
|
42
|
+
const dot = theme.fg(status === "running" ? "warning" : status, "●");
|
|
43
|
+
const count = this.options.count?.();
|
|
44
|
+
const description = count ? "" : toolDescription(args);
|
|
45
|
+
const control = this.options.toggle ? theme.fg("muted", this.options.expanded?.() ? "▾" : "▸") + " " : "";
|
|
46
|
+
const text = `${dot} ${control}${singleLine(name)}${count ? ` ×${count}` : ""}${description ? " " + theme.fg("muted", description) : ""}`;
|
|
47
|
+
const label = this.options.clock?.() ?? "";
|
|
48
|
+
const clock = label && width >= visibleWidth(label) + 8 ? label : "";
|
|
49
|
+
const available = Math.max(0, width - 1 - (clock ? visibleWidth(clock) + 1 : 0));
|
|
50
|
+
const body = truncateToWidth(text, available, "…");
|
|
51
|
+
return [(width > 0 ? " " : "") + (clock ? theme.fg("dim", clock) + " " : "") + body];
|
|
52
|
+
}
|
|
53
|
+
handleMouse(event: TuiMouseEvent): ReturnType<NonNullable<Component["handleMouse"]>> {
|
|
54
|
+
if (!this.options.toggle || event.button !== "left") return undefined;
|
|
55
|
+
if (event.type === "press") return { capture: true };
|
|
56
|
+
if (event.type === "click" && event.x >= 0 && event.x < event.width && event.y === 0) {
|
|
57
|
+
this.options.toggle();
|
|
58
|
+
return { handled: true, render: true };
|
|
59
|
+
}
|
|
60
|
+
return { handled: true };
|
|
61
|
+
}
|
|
62
|
+
invalidate(): void {}
|
|
63
|
+
}
|
package/src/content.ts
CHANGED
|
@@ -15,7 +15,8 @@ interface NativeContent extends Component {
|
|
|
15
15
|
toolCallId?: string;
|
|
16
16
|
toolName?: string;
|
|
17
17
|
args?: unknown;
|
|
18
|
-
result?: { content?: unknown };
|
|
18
|
+
result?: { content?: unknown; isError?: boolean };
|
|
19
|
+
isPartial?: boolean;
|
|
19
20
|
command?: string;
|
|
20
21
|
outputLines?: string[];
|
|
21
22
|
customComponent?: Component;
|
|
@@ -30,6 +31,11 @@ interface NativeAssistant extends Container {
|
|
|
30
31
|
setHideThinkingBlock(hidden: boolean): void;
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
export interface ToolSummary {
|
|
35
|
+
name: string;
|
|
36
|
+
args: unknown;
|
|
37
|
+
status: "running" | "success" | "error";
|
|
38
|
+
}
|
|
33
39
|
/** One native owner and its pane projection; spacing and search retain that same owner. */
|
|
34
40
|
export interface ContentEntry {
|
|
35
41
|
source: Component;
|
|
@@ -39,6 +45,8 @@ export interface ContentEntry {
|
|
|
39
45
|
spacing: Component[];
|
|
40
46
|
compact: boolean;
|
|
41
47
|
search(width: number): Omit<SearchEntry, "source">;
|
|
48
|
+
/** Live execution metadata exists only on calls, never on linked output. */
|
|
49
|
+
tool?(): ToolSummary;
|
|
42
50
|
}
|
|
43
51
|
|
|
44
52
|
const nameOf = (component: Component): string => component.constructor.name;
|
|
@@ -88,9 +96,9 @@ export class NativeContentIndex {
|
|
|
88
96
|
constructor(private readonly source: Container) {}
|
|
89
97
|
|
|
90
98
|
/** Return the same classification until native ownership or assistant content changes. */
|
|
91
|
-
entries(pane
|
|
99
|
+
entries(pane?: Pane): ContentEntry[] {
|
|
92
100
|
this.refresh();
|
|
93
|
-
return this.content.filter(entry => panes[entry.kind] === pane);
|
|
101
|
+
return pane === undefined ? this.content : this.content.filter(entry => panes[entry.kind] === pane);
|
|
94
102
|
}
|
|
95
103
|
|
|
96
104
|
/** A rebuilt history cannot retain search hits belonging to removed native owners. */
|
|
@@ -162,7 +170,14 @@ export class NativeContentIndex {
|
|
|
162
170
|
}
|
|
163
171
|
|
|
164
172
|
private entry(source: Component, kind: ContentKind, spacing: Component[], compact: boolean, owner?: NativeContent): ContentEntry {
|
|
165
|
-
|
|
173
|
+
const tool = kind === "tool" ? (): ToolSummary => {
|
|
174
|
+
const native = source as NativeContent;
|
|
175
|
+
return {
|
|
176
|
+
name: native.toolName!, args: native.args,
|
|
177
|
+
status: !native.result || native.isPartial !== false ? "running" : native.result.isError ? "error" : "success",
|
|
178
|
+
};
|
|
179
|
+
} : undefined;
|
|
180
|
+
return { source, owner: owner ?? source, component: source, kind: owner ? "tool" : kind, spacing, compact, tool, search: width => {
|
|
166
181
|
const native = source as NativeContent;
|
|
167
182
|
if (kind === "tool") {
|
|
168
183
|
if (typeof native.toolName !== "string") throw new Error("Pi's tool metadata is not supported");
|
package/src/index.ts
CHANGED
|
@@ -42,13 +42,18 @@ export default async function transcript(pi: ExtensionAPI): Promise<void> {
|
|
|
42
42
|
id: "copyButtons", label: "Show copy buttons",
|
|
43
43
|
description: "Hide copy icons and their rows; keyboard copying stays available.",
|
|
44
44
|
currentValue: preferences.showCopyButtons ? "on" : "off", values: ["on", "off"],
|
|
45
|
+
}, {
|
|
46
|
+
id: "compactTools", label: "Compact Activity tools",
|
|
47
|
+
description: "Group adjacent tools and expand individual calls inline. Full text stays searchable and copyable.",
|
|
48
|
+
currentValue: preferences.compactTools ? "on" : "off", values: ["on", "off"],
|
|
45
49
|
}, {
|
|
46
50
|
id: "height", label: "Conversation height",
|
|
47
51
|
description: "Auto grows to half the history area. Drag sets a manual maximum.",
|
|
48
52
|
currentValue: preferences.chatHeight === null ? "auto" : "manual", values: ["auto", "manual"],
|
|
49
|
-
}],
|
|
53
|
+
}], 4, getSettingsListTheme(), (id, value) => {
|
|
50
54
|
if (id === "timestamps") layout?.setTimestamps(value === "on");
|
|
51
55
|
else if (id === "copyButtons") layout?.setCopyButtons(value === "on");
|
|
56
|
+
else if (id === "compactTools") layout?.setCompactTools(value === "on");
|
|
52
57
|
else if (id === "height") layout?.setAutomaticHeight(value === "auto");
|
|
53
58
|
tui.requestRender();
|
|
54
59
|
}, () => done());
|
|
@@ -102,7 +107,7 @@ export default async function transcript(pi: ExtensionAPI): Promise<void> {
|
|
|
102
107
|
}
|
|
103
108
|
void copyToClipboard(text).then(() => ui.notify("Block sent to clipboard.", "info"),
|
|
104
109
|
error => ui.notify("Could not copy block: " + String(error), "error"));
|
|
105
|
-
});
|
|
110
|
+
}, () => pi.getAllTools());
|
|
106
111
|
try { ensureLayout(); }
|
|
107
112
|
catch (error) {
|
|
108
113
|
layout.dispose();
|
|
@@ -214,7 +219,7 @@ export default async function transcript(pi: ExtensionAPI): Promise<void> {
|
|
|
214
219
|
const choice = await ctx.ui.select("Copy a block from the active panel", blocks.map(block => block.label));
|
|
215
220
|
blocks.find(block => block.label === choice)?.copy();
|
|
216
221
|
} else if (action === "help") {
|
|
217
|
-
ctx.ui.notify("pi-stereo-view icons: ▣ combined, ◫ split, ▤ rows, ▥ columns, ↕/↔ swap, ↗ expand, ↙ restore, ⌕ search, ≡ 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");
|
|
222
|
+
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");
|
|
218
223
|
} else if (action === "swap") layout.swap();
|
|
219
224
|
else if (action === "width" && /^\d+$/.test(target ?? "")) layout.setWidth(Number(target));
|
|
220
225
|
else if (action === "height" && target === "auto") layout.setHeight(null);
|
package/src/layout.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { setImmediate } from "node:timers/promises";
|
|
2
|
-
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { Theme, ToolInfo } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import {
|
|
4
4
|
Container, HStack, isViewportTUI, mixColors, MouseRegion, rgbColor, ScrollView, Text, truncateToWidth, VStack,
|
|
5
5
|
type Color, type Component, type ScrollViewOptions, type StackChild, type TUI, type TuiMouseEvent,
|
|
@@ -135,6 +135,7 @@ export class TranscriptLayout {
|
|
|
135
135
|
private readonly timestamps: TranscriptTimestamps,
|
|
136
136
|
private readonly openSettings: () => void,
|
|
137
137
|
private readonly copy?: (text: string | undefined) => void,
|
|
138
|
+
private readonly getTools: () => readonly ToolInfo[] = () => [],
|
|
138
139
|
) {}
|
|
139
140
|
|
|
140
141
|
private button(icon: () => string, action: () => void, enabled = (): boolean => true, background?: () => Color): Component {
|
|
@@ -203,7 +204,8 @@ export class TranscriptLayout {
|
|
|
203
204
|
const showCopyButtons = (): boolean => this.preferences.showCopyButtons;
|
|
204
205
|
const index = new NativeContentIndex(document);
|
|
205
206
|
const activityDocument = new NativeDocument(document, "activity", this.timestamps, this.theme, timestampGutter, showTimestamps,
|
|
206
|
-
() => this.activate("activity"), false, index, this.copy, showCopyButtons)
|
|
207
|
+
() => this.activate("activity"), false, index, this.copy, showCopyButtons, () => this.preferences.compactTools, this.getTools,
|
|
208
|
+
() => { if (this.activity) this.activity.scrollTo(this.activity.scrollTop, { disableFollow: true }); });
|
|
207
209
|
const chatDocument = new NativeDocument(document, "chat", this.timestamps, this.theme, timestampGutter, showTimestamps,
|
|
208
210
|
() => this.activate("chat"), false, index, this.copy, showCopyButtons);
|
|
209
211
|
this.documents = { activity: activityDocument, chat: chatDocument };
|
|
@@ -294,7 +296,7 @@ export class TranscriptLayout {
|
|
|
294
296
|
};
|
|
295
297
|
const label = new HStack([
|
|
296
298
|
{ component: new MouseRegion({
|
|
297
|
-
render: width => new Text(this.theme().style(truncateToWidth((this.searchPane() === target ? "● " : " ") + title, width, "").padEnd(width), {
|
|
299
|
+
render: width => new Text(this.theme().style(truncateToWidth(" " + (this.searchPane() === target ? "● " : " ") + title, width, "").padEnd(width), {
|
|
298
300
|
fg: this.searchPane() === target ? "accent" : palette().text, bg: palette().fill,
|
|
299
301
|
}), 0, 0).render(width),
|
|
300
302
|
invalidate() {},
|
|
@@ -305,6 +307,13 @@ export class TranscriptLayout {
|
|
|
305
307
|
}
|
|
306
308
|
return undefined;
|
|
307
309
|
}), basis: 0, grow: 1, minSize: 1 },
|
|
310
|
+
...(target === "activity" ? [{ component: this.button(
|
|
311
|
+
() => this.preferences.compactTools ? "⊞" : "⊟",
|
|
312
|
+
() => {
|
|
313
|
+
this.activate("activity");
|
|
314
|
+
this.setCompactTools(!this.preferences.compactTools);
|
|
315
|
+
}, () => true, () => palette().fill,
|
|
316
|
+
), basis: BUTTON_WIDTH, shrink: 0 }] : []),
|
|
308
317
|
{ component: this.button(() => "⌕", () => {
|
|
309
318
|
this.activate(target);
|
|
310
319
|
this.openSearch(target);
|
|
@@ -546,6 +555,12 @@ export class TranscriptLayout {
|
|
|
546
555
|
this.preferences.showCopyButtons = show;
|
|
547
556
|
this.changed();
|
|
548
557
|
}
|
|
558
|
+
|
|
559
|
+
/** Project tool calls as dense rows while retaining their full search and copy text. */
|
|
560
|
+
setCompactTools(compact: boolean): void {
|
|
561
|
+
this.preferences.compactTools = compact;
|
|
562
|
+
this.changed();
|
|
563
|
+
}
|
|
549
564
|
private defaultWidth(width: number): number {
|
|
550
565
|
return Math.max(MIN_CHAT, Math.floor((width - 1) * 0.2));
|
|
551
566
|
}
|
package/src/native.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { Container, Spacer, Text, type Component, type TuiMouseEvent } from "@earendil-works/pi-tui";
|
|
1
|
+
import type { Theme, ToolInfo } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { Container, Spacer, Text, truncateToWidth, type Component, type TuiMouseEvent } from "@earendil-works/pi-tui";
|
|
3
3
|
import { searchText, type SearchEntry, type SearchHit } from "./search.js";
|
|
4
4
|
import { highlightSearchRows, searchHitRow, type SearchClock } from "./search-highlight.js";
|
|
5
5
|
import { CompactMessage, type TranscriptTimestamps } from "./timestamps.js";
|
|
6
|
-
import { NativeContentIndex, type Pane } from "./content.js";
|
|
6
|
+
import { NativeContentIndex, type ContentEntry, type Pane } from "./content.js";
|
|
7
|
+
import { CompactTool } from "./compact-tools.js";
|
|
8
|
+
import { toolPresentations, type ToolPresentation } from "./tool-presentation.js";
|
|
9
|
+
import { toolGroups, groupSummary, type ToolGroup } from "./tool-groups.js";
|
|
7
10
|
export type { Pane } from "./content.js";
|
|
8
11
|
|
|
9
12
|
/** Decorate one selected block without changing native text or mouse coordinates. */
|
|
@@ -38,6 +41,28 @@ class SearchHighlight implements Component {
|
|
|
38
41
|
}
|
|
39
42
|
}
|
|
40
43
|
|
|
44
|
+
/** Keep hierarchy guides outside native rendering, search and pointer coordinates. */
|
|
45
|
+
class ToolIndent extends Container {
|
|
46
|
+
private readonly prefix: string;
|
|
47
|
+
|
|
48
|
+
constructor(component: Component, depth: number, body: boolean, private readonly theme: () => Theme) {
|
|
49
|
+
super();
|
|
50
|
+
this.addChild(component);
|
|
51
|
+
this.prefix = " │".repeat(depth) + (body ? " " : "");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
override render(width: number): string[] {
|
|
55
|
+
const inset = Math.min(width, this.prefix.length);
|
|
56
|
+
const prefix = this.theme().fg("dim", this.prefix.slice(0, inset));
|
|
57
|
+
return super.render(Math.max(0, width - inset)).map(line => truncateToWidth(prefix + line, width, ""));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
override handleMouse(event: TuiMouseEvent): ReturnType<Container["handleMouse"]> {
|
|
61
|
+
const inset = Math.min(event.width, this.prefix.length);
|
|
62
|
+
if (event.x < inset) return undefined;
|
|
63
|
+
return super.handleMouse({ ...event, x: event.x - inset, width: Math.max(0, event.width - inset) });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
41
66
|
/**
|
|
42
67
|
* Project the live native component tree, not messages or renderer strings.
|
|
43
68
|
* Assistant shells keep the native render method and original content components.
|
|
@@ -46,6 +71,14 @@ class SearchHighlight implements Component {
|
|
|
46
71
|
*/
|
|
47
72
|
export class NativeDocument extends Container {
|
|
48
73
|
private readonly stamped = new WeakMap<Component, CompactMessage>();
|
|
74
|
+
private readonly toolRows = new WeakMap<Component, CompactTool>();
|
|
75
|
+
private readonly groupRows = new WeakMap<Component, CompactTool>();
|
|
76
|
+
private readonly indented = new WeakMap<Component, ToolIndent[]>();
|
|
77
|
+
private readonly openGroups = new WeakSet<Component>();
|
|
78
|
+
private readonly openTools = new WeakSet<Component>();
|
|
79
|
+
private groups = new Map<Component, ToolGroup>();
|
|
80
|
+
private present: (name: string) => ToolPresentation = name => ({ name, key: name });
|
|
81
|
+
private searchTool?: Component;
|
|
49
82
|
private readonly clockOwners = new WeakMap<Component, Component>();
|
|
50
83
|
private readonly compactBlocks = new Map<Component, CompactMessage>();
|
|
51
84
|
private readonly positions = new Map<Component, { row: number; lines: string[]; clock?: SearchClock; excerptRow?: number }>();
|
|
@@ -73,6 +106,9 @@ export class NativeDocument extends Container {
|
|
|
73
106
|
private readonly index = new NativeContentIndex(source),
|
|
74
107
|
private readonly copy?: (text: string | undefined) => void,
|
|
75
108
|
private readonly showCopy: () => boolean = () => true,
|
|
109
|
+
private readonly compactTools: () => boolean = () => false,
|
|
110
|
+
private readonly getTools: () => readonly ToolInfo[] = () => [],
|
|
111
|
+
private readonly beforeExpand: () => void = () => {},
|
|
76
112
|
) {
|
|
77
113
|
super();
|
|
78
114
|
}
|
|
@@ -140,6 +176,7 @@ export class NativeDocument extends Container {
|
|
|
140
176
|
|
|
141
177
|
/** Clear search-only fragments, measurements and highlighting without invalidating native blocks. */
|
|
142
178
|
clearSearch(): void {
|
|
179
|
+
this.searchTool = undefined;
|
|
143
180
|
this.searchAnchor = undefined;
|
|
144
181
|
this.excerpt = undefined;
|
|
145
182
|
this.searchQuery = "";
|
|
@@ -189,6 +226,63 @@ export class NativeDocument extends Container {
|
|
|
189
226
|
if (event.type === "wheel" || (event.type === "press" && event.button === "left")) this.interact();
|
|
190
227
|
return super.handleMouse(event);
|
|
191
228
|
}
|
|
229
|
+
private toolOpen(source: Component): boolean {
|
|
230
|
+
return this.openTools.has(source) || this.searchTool === source;
|
|
231
|
+
}
|
|
232
|
+
private groupOpen(group: ToolGroup): boolean {
|
|
233
|
+
return this.openGroups.has(group.calls[0].source) || (this.searchTool !== undefined && this.groups.get(this.searchTool) === group);
|
|
234
|
+
}
|
|
235
|
+
private compactRow(entry: ContentEntry): CompactTool {
|
|
236
|
+
let row = this.toolRows.get(entry.source);
|
|
237
|
+
if (!row) {
|
|
238
|
+
row = new CompactTool(() => {
|
|
239
|
+
const summary = entry.tool!();
|
|
240
|
+
return { ...summary, name: this.present(summary.name).name };
|
|
241
|
+
}, this.theme, {
|
|
242
|
+
clock: () => this.showTimestamps() ? this.timestamps.label(entry.source) : "",
|
|
243
|
+
gutter: this.timestampGutter,
|
|
244
|
+
expanded: () => this.toolOpen(entry.source),
|
|
245
|
+
toggle: () => {
|
|
246
|
+
if (!this.index.contains(entry.source, this.pane)) return;
|
|
247
|
+
this.beforeExpand();
|
|
248
|
+
if (this.toolOpen(entry.source)) { this.openTools.delete(entry.source); if (this.searchTool === entry.source) this.clearSearch(); }
|
|
249
|
+
else { this.openTools.add(entry.source); entry.search(this.lastWidth).reveal?.(); }
|
|
250
|
+
this.frameWidth = undefined;
|
|
251
|
+
},
|
|
252
|
+
});
|
|
253
|
+
this.toolRows.set(entry.source, row);
|
|
254
|
+
}
|
|
255
|
+
return row;
|
|
256
|
+
}
|
|
257
|
+
private indent(component: Component, depth: number, body = false): Component {
|
|
258
|
+
if (!depth) return component;
|
|
259
|
+
let levels = this.indented.get(component);
|
|
260
|
+
if (!levels) { levels = []; this.indented.set(component, levels); }
|
|
261
|
+
const inset = depth * 2 + (body ? 1 : 0);
|
|
262
|
+
return levels[inset] ??= new ToolIndent(component, depth, body, this.theme);
|
|
263
|
+
}
|
|
264
|
+
private groupRow(group: ToolGroup): CompactTool {
|
|
265
|
+
const source = group.calls[0].source;
|
|
266
|
+
let row = this.groupRows.get(source);
|
|
267
|
+
if (!row) {
|
|
268
|
+
row = new CompactTool(() => groupSummary(this.groups.get(source)!), this.theme, {
|
|
269
|
+
count: () => this.groups.get(source)!.calls.length,
|
|
270
|
+
clock: () => this.showTimestamps() ? this.timestamps.label(source) : "",
|
|
271
|
+
gutter: this.timestampGutter,
|
|
272
|
+
expanded: () => this.groupOpen(this.groups.get(source)!),
|
|
273
|
+
toggle: () => {
|
|
274
|
+
const current = this.groups.get(source);
|
|
275
|
+
if (!current || !this.index.contains(source, this.pane)) return;
|
|
276
|
+
this.beforeExpand();
|
|
277
|
+
if (this.groupOpen(current)) { this.openGroups.delete(source); if (current.calls.some(call => call.source === this.searchTool)) this.clearSearch(); }
|
|
278
|
+
else this.openGroups.add(source);
|
|
279
|
+
this.frameWidth = undefined;
|
|
280
|
+
},
|
|
281
|
+
});
|
|
282
|
+
this.groupRows.set(source, row);
|
|
283
|
+
}
|
|
284
|
+
return row;
|
|
285
|
+
}
|
|
192
286
|
override render(width: number): string[] {
|
|
193
287
|
if (this.frameActive && this.frameWidth === width && this.frameLines) return this.frameLines;
|
|
194
288
|
const chat = this.source.children[2] as Container;
|
|
@@ -201,31 +295,78 @@ export class NativeDocument extends Container {
|
|
|
201
295
|
const locateMatch = this.searchAnchor !== undefined || this.excerpt !== undefined;
|
|
202
296
|
let row = 0;
|
|
203
297
|
let visibleBlock = false;
|
|
298
|
+
let toolRun = false;
|
|
299
|
+
const compactTools = this.pane === "activity" && this.compactTools();
|
|
300
|
+
this.present = toolPresentations(compactTools ? this.getTools() : []);
|
|
301
|
+
const groups = compactTools ? toolGroups(this.index.entries(), this.present) : new Map<Component, ToolGroup>();
|
|
302
|
+
// Carry visible expansion through state-driven splits and merges, without
|
|
303
|
+
// reopening explicitly collapsed runs. Read the old state before adding heads.
|
|
304
|
+
const opening: Component[] = [];
|
|
305
|
+
for (const [source, group] of groups) {
|
|
306
|
+
if (group.calls[0].source !== source || group.calls.length < 2 || this.openGroups.has(source)) continue;
|
|
307
|
+
if (group.calls.some(call => {
|
|
308
|
+
const previous = this.groups.get(call.source);
|
|
309
|
+
return previous && (previous.calls.length > 1 ? this.openGroups.has(previous.calls[0].source) : this.openTools.has(call.source));
|
|
310
|
+
})) opening.push(source);
|
|
311
|
+
}
|
|
312
|
+
if (compactTools) for (const [source, previous] of this.groups) {
|
|
313
|
+
const current = groups.get(source);
|
|
314
|
+
if (previous.calls[0].source === source && previous.calls.length > 1 &&
|
|
315
|
+
(!current || current.calls.length < 2 || current.calls[0].source !== source)) this.openGroups.delete(source);
|
|
316
|
+
}
|
|
317
|
+
for (const source of opening) this.openGroups.add(source);
|
|
318
|
+
this.groups = groups;
|
|
319
|
+
this.searchTool = this.searchAnchor ? this.index.entries(this.pane).find(entry => entry.source === this.searchAnchor!.entry.source)?.owner : undefined;
|
|
204
320
|
for (const entry of this.index.entries(this.pane)) {
|
|
205
321
|
const component = entry.source;
|
|
206
322
|
const routed = entry.component;
|
|
207
323
|
this.clockOwners.set(component, entry.owner);
|
|
208
324
|
const start = result.length;
|
|
209
325
|
const wasVisible = visibleBlock;
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
326
|
+
let clock: SearchClock | undefined;
|
|
327
|
+
let nativeBody = true;
|
|
328
|
+
let bodyDepth = 0;
|
|
329
|
+
const compactTool = compactTools && entry.kind === "tool";
|
|
330
|
+
if (compactTool) {
|
|
331
|
+
const group = this.groups.get(entry.owner);
|
|
332
|
+
const grouped = group !== undefined && group.calls.length > 1;
|
|
333
|
+
bodyDepth = grouped ? 2 : 1;
|
|
334
|
+
const members = !grouped || this.groupOpen(group);
|
|
335
|
+
if (entry.tool) {
|
|
336
|
+
if (visibleBlock && !toolRun) result.push(new Spacer(1));
|
|
337
|
+
if (grouped && group.calls[0].source === component) result.push(this.groupRow(group));
|
|
338
|
+
if (members) result.push(this.indent(this.compactRow(entry), grouped ? 1 : 0));
|
|
339
|
+
toolRun = true;
|
|
340
|
+
visibleBlock = true;
|
|
341
|
+
}
|
|
342
|
+
nativeBody = members && this.toolOpen(entry.owner);
|
|
343
|
+
}
|
|
344
|
+
const contentStart = result.length;
|
|
345
|
+
const bodyWidth = Math.max(0, width - (bodyDepth ? bodyDepth * 2 + 1 : 0));
|
|
346
|
+
if (nativeBody && !entry.compact) {
|
|
347
|
+
toolRun = false;
|
|
348
|
+
result.push(...entry.spacing, routed);
|
|
349
|
+
} else if (nativeBody) {
|
|
350
|
+
if (!compactTool) toolRun = false;
|
|
213
351
|
let stamped = this.stamped.get(routed);
|
|
214
352
|
if (!stamped) {
|
|
215
353
|
stamped = new CompactMessage(routed, () => this.timestamps.label(this.clockOwners.get(component) ?? component),
|
|
216
|
-
this.theme, this.timestampGutter, this.showTimestamps
|
|
354
|
+
this.theme, this.timestampGutter, () => this.showTimestamps() && !(this.pane === "activity" && this.compactTools() && entry.kind === "tool"),
|
|
355
|
+
this.copy ? () => this.copyBlock(component) : undefined, this.showCopy);
|
|
217
356
|
this.stamped.set(routed, stamped);
|
|
218
357
|
}
|
|
219
358
|
this.compactBlocks.set(component, stamped);
|
|
220
|
-
visibleBlock = stamped.prepare(
|
|
359
|
+
visibleBlock = stamped.prepare(bodyWidth, compactTool ? false : visibleBlock) || visibleBlock;
|
|
221
360
|
result.push(stamped);
|
|
361
|
+
clock = stamped.searchClock();
|
|
222
362
|
}
|
|
223
|
-
if (this.searchAnchor?.entry.source === component && !this.excerpt) {
|
|
363
|
+
if (this.searchAnchor?.entry.source === component && !this.excerpt && result.length > start) {
|
|
224
364
|
const last = result.length - 1;
|
|
225
365
|
result[last] = this.highlighted(result[last]);
|
|
226
366
|
}
|
|
227
367
|
if (locateMatch) {
|
|
228
|
-
const
|
|
368
|
+
const prefix = result.slice(start, contentStart).flatMap(child => child.render(width));
|
|
369
|
+
const lines = [...prefix, ...result.slice(contentStart).flatMap(child => child.render(bodyWidth))];
|
|
229
370
|
let excerptRow: number | undefined;
|
|
230
371
|
if (this.excerpt?.entry.source === component) {
|
|
231
372
|
const fragment = new Text(this.theme().fg("accent", "Search match: ") + searchText(this.excerpt.text), 1, 0);
|
|
@@ -236,12 +377,15 @@ export class NativeDocument extends Container {
|
|
|
236
377
|
excerptRow = row + lines.length;
|
|
237
378
|
const decorated = this.highlighted(fragment, true);
|
|
238
379
|
result.push(decorated);
|
|
239
|
-
lines.push(...decorated.render(
|
|
380
|
+
lines.push(...decorated.render(bodyWidth));
|
|
240
381
|
visibleBlock = true;
|
|
241
382
|
}
|
|
242
|
-
|
|
383
|
+
// Compact controls/clocks are not saved text. Search the original body only.
|
|
384
|
+
const prefixRows = prefix.length;
|
|
385
|
+
this.positions.set(component, { row: row + prefixRows, lines: lines.slice(prefixRows), clock, excerptRow });
|
|
243
386
|
row += lines.length;
|
|
244
387
|
}
|
|
388
|
+
for (let child = contentStart; child < result.length; child++) result[child] = this.indent(result[child], bodyDepth, true);
|
|
245
389
|
}
|
|
246
390
|
// Native follow-end guidance overlays the bottom row. Keep the selected last line above it.
|
|
247
391
|
if (this.searchAnchor) result.push(new Spacer(1));
|
package/src/preferences.ts
CHANGED
|
@@ -15,10 +15,11 @@ export interface Preferences {
|
|
|
15
15
|
zoom: "activity" | "chat" | null;
|
|
16
16
|
showTimestamps: boolean;
|
|
17
17
|
showCopyButtons: boolean;
|
|
18
|
+
compactTools: boolean;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
export const defaults: Preferences = {
|
|
21
|
-
mode: "split", side: "left", chatWidth: null, layout: "columns", chatHeight: null, zoom: null, showTimestamps: true, showCopyButtons: true,
|
|
22
|
+
mode: "split", side: "left", chatWidth: null, layout: "columns", chatHeight: null, zoom: null, showTimestamps: true, showCopyButtons: true, compactTools: false,
|
|
22
23
|
};
|
|
23
24
|
|
|
24
25
|
/** Read display preferences, retaining the first version's saved arrangement. */
|
|
@@ -37,16 +38,17 @@ export async function loadPreferences(file: string): Promise<Preferences> {
|
|
|
37
38
|
const chatHeight = record.chatHeight === undefined ? defaults.chatHeight : record.chatHeight;
|
|
38
39
|
const showTimestamps = record.showTimestamps === undefined ? defaults.showTimestamps : record.showTimestamps;
|
|
39
40
|
const showCopyButtons = record.showCopyButtons === undefined ? defaults.showCopyButtons : record.showCopyButtons;
|
|
41
|
+
const compactTools = record.compactTools === undefined ? defaults.compactTools : record.compactTools;
|
|
40
42
|
if ((record.side !== "left" && record.side !== "right") ||
|
|
41
43
|
(record.chatWidth !== null && (typeof record.chatWidth !== "number" || !Number.isInteger(record.chatWidth) ||
|
|
42
44
|
record.chatWidth < 24 || record.chatWidth > 240)) ||
|
|
43
45
|
(layout !== "columns" && layout !== "rows") ||
|
|
44
46
|
(chatHeight !== null && (typeof chatHeight !== "number" || !Number.isInteger(chatHeight) || chatHeight < 4 || chatHeight > 240)) ||
|
|
45
|
-
typeof showTimestamps !== "boolean" || typeof showCopyButtons !== "boolean") {
|
|
47
|
+
typeof showTimestamps !== "boolean" || typeof showCopyButtons !== "boolean" || typeof compactTools !== "boolean") {
|
|
46
48
|
throw new Error("Invalid pi-stereo-view preferences");
|
|
47
49
|
}
|
|
48
50
|
// Legacy files may contain mode/zoom. Every session starts with both panels visible.
|
|
49
|
-
return { mode: "split", side: record.side, chatWidth: record.chatWidth, layout, chatHeight, zoom: null, showTimestamps, showCopyButtons };
|
|
51
|
+
return { mode: "split", side: record.side, chatWidth: record.chatWidth, layout, chatHeight, zoom: null, showTimestamps, showCopyButtons, compactTools };
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
/** Atomically save only the display settings, never session messages. */
|
|
@@ -54,8 +56,8 @@ export async function savePreferences(file: string, preferences: Preferences): P
|
|
|
54
56
|
await mkdir(path.dirname(file), { recursive: true });
|
|
55
57
|
const temporary = file + "." + randomUUID() + ".tmp";
|
|
56
58
|
try {
|
|
57
|
-
const { side, chatWidth, layout, chatHeight, showTimestamps, showCopyButtons } = preferences;
|
|
58
|
-
const saved = { side, chatWidth, layout, chatHeight, showTimestamps, showCopyButtons };
|
|
59
|
+
const { side, chatWidth, layout, chatHeight, showTimestamps, showCopyButtons, compactTools } = preferences;
|
|
60
|
+
const saved = { side, chatWidth, layout, chatHeight, showTimestamps, showCopyButtons, compactTools };
|
|
59
61
|
await writeFile(temporary, JSON.stringify(saved, null, 2) + "\n", { mode: 0o600 });
|
|
60
62
|
await rename(temporary, file);
|
|
61
63
|
} finally {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Component } from "@earendil-works/pi-tui";
|
|
2
|
+
import type { ContentEntry, ToolSummary } from "./content.js";
|
|
3
|
+
|
|
4
|
+
export interface ToolGroup { calls: ContentEntry[]; key: string; name: string; status: ToolSummary["status"] }
|
|
5
|
+
|
|
6
|
+
/** Adjacency is measured before pane filtering. Linked output belongs to its call. */
|
|
7
|
+
export function toolGroups(entries: readonly ContentEntry[], present: (name: string) => { name: string; key: string }): Map<Component, ToolGroup> {
|
|
8
|
+
const groups = new Map<Component, ToolGroup>();
|
|
9
|
+
let run: ToolGroup | undefined;
|
|
10
|
+
for (const entry of entries) {
|
|
11
|
+
if (entry.owner !== entry.source) continue;
|
|
12
|
+
if (!entry.tool) { run = undefined; continue; }
|
|
13
|
+
const { name, status } = entry.tool();
|
|
14
|
+
const identity = present(name);
|
|
15
|
+
if (!run || run.key !== identity.key || run.status !== status || status === "error") run = { calls: [], ...identity, status };
|
|
16
|
+
run.calls.push(entry);
|
|
17
|
+
groups.set(entry.source, run);
|
|
18
|
+
}
|
|
19
|
+
return groups;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Every group has one state; failed calls always remain individual rows. */
|
|
23
|
+
export function groupSummary(group: ToolGroup): ToolSummary {
|
|
24
|
+
return { name: group.name, args: undefined, status: group.status };
|
|
25
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from "node:util";
|
|
2
|
+
import type { ToolInfo } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
|
|
4
|
+
export interface ToolPresentation { name: string; key: string }
|
|
5
|
+
|
|
6
|
+
/** Resolve presentation only; native execution and renderer ownership stay unchanged. */
|
|
7
|
+
export function toolPresentations(tools: readonly ToolInfo[]): (name: string) => ToolPresentation {
|
|
8
|
+
const catalogue = new Map(tools.map(tool => [tool.name, tool]));
|
|
9
|
+
const sources = tools.filter(tool => tool.exposure !== "hidden" && (
|
|
10
|
+
tool.namespace?.name.startsWith("ide_") === true ||
|
|
11
|
+
(tool.name === "codemode" && tool.sourceInfo.source === "builtin" && tool.sourceInfo.path === "builtin:codemode")
|
|
12
|
+
));
|
|
13
|
+
const cache = new Map<string, ToolPresentation>();
|
|
14
|
+
return name => {
|
|
15
|
+
const cached = cache.get(name);
|
|
16
|
+
if (cached) return cached;
|
|
17
|
+
let canonical = name;
|
|
18
|
+
const alias = catalogue.get(name);
|
|
19
|
+
// Local forwarding aliases opt into IDE's description/schema contract.
|
|
20
|
+
if (name.startsWith("mcp__") && alias && !alias.namespace && alias.exposure !== "hidden") {
|
|
21
|
+
const matches = sources.filter(tool => tool.description === alias.description && isDeepStrictEqual(tool.parameters, alias.parameters));
|
|
22
|
+
if (matches.length === 1) canonical = matches[0].name;
|
|
23
|
+
}
|
|
24
|
+
const presentation = { name: canonical, key: canonical };
|
|
25
|
+
cache.set(name, presentation);
|
|
26
|
+
return presentation;
|
|
27
|
+
};
|
|
28
|
+
}
|