pi-stereo-view 0.1.9 → 0.1.11
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 +13 -0
- package/README.md +3 -1
- package/package.json +1 -1
- package/src/compact-tools.ts +2 -2
- package/src/content.ts +54 -5
- package/src/index.ts +27 -7
- package/src/layout.ts +4 -2
- package/src/native.ts +7 -6
- package/src/nested-activity.ts +110 -0
- package/src/startup.ts +28 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.11 - 2026-10-29
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Show nested tool calls in Activity with their arguments, status and native result views. Recorded calls remain visible after reopening a session.
|
|
8
|
+
|
|
9
|
+
## 0.1.10 - 2026-10-26
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- Add a one-cell left inset before panel header content while keeping the colored background full width.
|
|
14
|
+
- Use `▸` and `▾` for collapsed and expanded compact tool groups and calls. The Activity header keeps its existing `⊟` / `⊞` controls.
|
|
15
|
+
|
|
3
16
|
## 0.1.9 - 2026-10-26
|
|
4
17
|
|
|
5
18
|
### Added
|
package/README.md
CHANGED
|
@@ -27,6 +27,8 @@ Unrecognized content stays in Conversation unless its metadata links it to a kno
|
|
|
27
27
|
|
|
28
28
|
Late output linked to a tool call appears directly below that call in Activity, even if other work has happened since. Combined history keeps its original order.
|
|
29
29
|
|
|
30
|
+
Calls made inside Codemode and other tools appear beneath their parent in Activity. While running, their arguments, status and available results are shown; compact mode gives each nested call its own expandable row. After reopening a session, Pi restores recorded call metadata and any saved error excerpt. Pi Agent IDE may also restore its saved native result panels; full results are not always available. Activity marks incomplete records and omitted arguments. Older sessions without nested records remain unchanged.
|
|
31
|
+
|
|
30
32
|
Messages and tools keep their familiar appearance. The input stays full width below both panels.
|
|
31
33
|
|
|
32
34
|
## Features
|
|
@@ -96,7 +98,7 @@ Swap the panels whenever you want. Zoom a panel to give it the whole history are
|
|
|
96
98
|
|
|
97
99
|
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
100
|
|
|
99
|
-
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.
|
|
101
|
+
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
102
|
|
|
101
103
|
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
104
|
|
package/package.json
CHANGED
package/src/compact-tools.ts
CHANGED
|
@@ -39,10 +39,10 @@ export class CompactTool implements Component {
|
|
|
39
39
|
width = Math.max(0, width - (this.options.gutter?.() ?? 0));
|
|
40
40
|
const { name, args, status } = this.summary();
|
|
41
41
|
const theme = this.theme();
|
|
42
|
-
const dot = theme.fg(status === "running" ? "warning" : status, "●");
|
|
42
|
+
const dot = theme.fg(status === "running" ? "warning" : status === "unknown" ? "dim" : status, "●");
|
|
43
43
|
const count = this.options.count?.();
|
|
44
44
|
const description = count ? "" : toolDescription(args);
|
|
45
|
-
const control = this.options.toggle ? theme.fg("muted", this.options.expanded?.() ? "
|
|
45
|
+
const control = this.options.toggle ? theme.fg("muted", this.options.expanded?.() ? "▾" : "▸") + " " : "";
|
|
46
46
|
const text = `${dot} ${control}${singleLine(name)}${count ? ` ×${count}` : ""}${description ? " " + theme.fg("muted", description) : ""}`;
|
|
47
47
|
const label = this.options.clock?.() ?? "";
|
|
48
48
|
const clock = label && width >= visibleWidth(label) + 8 ? label : "";
|
package/src/content.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Container, Markdown, Text, stripTerminalSequences, type Component } from "@earendil-works/pi-tui";
|
|
1
|
+
import { Container, Markdown, Text, stripTerminalSequences, type Component, type TuiMouseEvent } from "@earendil-works/pi-tui";
|
|
2
2
|
import { searchText, type SearchEntry } from "./search.js";
|
|
3
|
+
import type { NestedActivity } from "./nested-activity.js";
|
|
3
4
|
|
|
4
5
|
export type Pane = "activity" | "chat";
|
|
5
6
|
export type ContentKind = "dialogue" | "system" | "thinking" | "tool" | "shell";
|
|
@@ -11,7 +12,7 @@ const panes: Record<ContentKind, Pane> = {
|
|
|
11
12
|
interface NativeContent extends Component {
|
|
12
13
|
text?: string;
|
|
13
14
|
message?: { content?: unknown; summary?: string; details?: { parentToolCallId?: unknown } };
|
|
14
|
-
entry?: { data?: { parentToolCallId?: unknown } };
|
|
15
|
+
entry?: { customType?: string; data?: { parentToolCallId?: unknown; calls?: { id?: unknown }[] } };
|
|
15
16
|
toolCallId?: string;
|
|
16
17
|
toolName?: string;
|
|
17
18
|
args?: unknown;
|
|
@@ -34,7 +35,7 @@ interface NativeAssistant extends Container {
|
|
|
34
35
|
export interface ToolSummary {
|
|
35
36
|
name: string;
|
|
36
37
|
args: unknown;
|
|
37
|
-
status: "running" | "success" | "error";
|
|
38
|
+
status: "running" | "success" | "error" | "unknown";
|
|
38
39
|
}
|
|
39
40
|
/** One native owner and its pane projection; spacing and search retain that same owner. */
|
|
40
41
|
export interface ContentEntry {
|
|
@@ -44,6 +45,7 @@ export interface ContentEntry {
|
|
|
44
45
|
kind: ContentKind;
|
|
45
46
|
spacing: Component[];
|
|
46
47
|
compact: boolean;
|
|
48
|
+
nested?: boolean;
|
|
47
49
|
search(width: number): Omit<SearchEntry, "source">;
|
|
48
50
|
/** Live execution metadata exists only on calls, never on linked output. */
|
|
49
51
|
tool?(): ToolSummary;
|
|
@@ -87,13 +89,33 @@ const nativeKinds: Record<string, { kind: ContentKind; accepts(content: NativeCo
|
|
|
87
89
|
},
|
|
88
90
|
};
|
|
89
91
|
|
|
92
|
+
/** Show the IDE-owned native child when its saved panel contains this call. */
|
|
93
|
+
class SavedNativePanel implements Component {
|
|
94
|
+
constructor(private readonly fallback: Component, private readonly group: NativeContent, private readonly id: string) {}
|
|
95
|
+
private native(): Component | undefined {
|
|
96
|
+
this.group.setExpanded?.(true);
|
|
97
|
+
const find = (component: Component | undefined): Component | undefined => {
|
|
98
|
+
if (!component) return undefined;
|
|
99
|
+
const node = component as NativeContent & { children?: Component[] };
|
|
100
|
+
if (nameOf(component) === "ToolExecutionComponent" && node.toolCallId === this.id) return component;
|
|
101
|
+
for (const child of node.children ?? []) { const found = find(child); if (found) return found; }
|
|
102
|
+
return undefined;
|
|
103
|
+
};
|
|
104
|
+
return find(this.group.customComponent);
|
|
105
|
+
}
|
|
106
|
+
render(width: number): string[] { return (this.native() ?? this.fallback).render(width); }
|
|
107
|
+
invalidate(): void { this.fallback.invalidate(); this.group.invalidate(); }
|
|
108
|
+
handleMouse(event: TuiMouseEvent): ReturnType<NonNullable<Component["handleMouse"]>> { return (this.native() ?? this.fallback).handleMouse?.(event); }
|
|
109
|
+
}
|
|
110
|
+
|
|
90
111
|
/** Shared semantic index for painting and search, independent of wording, severity and lifecycle. */
|
|
91
112
|
export class NativeContentIndex {
|
|
92
113
|
private signature: unknown[] = [];
|
|
93
114
|
private content: ContentEntry[] = [];
|
|
94
115
|
private readonly views = new WeakMap<NativeAssistant, Partial<Record<Pane, Container>>>();
|
|
116
|
+
private readonly savedPanels = new WeakMap<Component, { group: NativeContent; panel: Component }>();
|
|
95
117
|
|
|
96
|
-
constructor(private readonly source: Container) {}
|
|
118
|
+
constructor(private readonly source: Container, private readonly nested?: NestedActivity) {}
|
|
97
119
|
|
|
98
120
|
/** Return the same classification until native ownership or assistant content changes. */
|
|
99
121
|
entries(pane?: Pane): ContentEntry[] {
|
|
@@ -121,7 +143,7 @@ export class NativeContentIndex {
|
|
|
121
143
|
private refresh(): void {
|
|
122
144
|
const history = this.source.children[2] as Container;
|
|
123
145
|
if (!Array.isArray(history?.children)) throw new Error("Pi's history document is not supported");
|
|
124
|
-
const signature: unknown[] = [...this.source.children, ...history.children];
|
|
146
|
+
const signature: unknown[] = [this.nested?.revision, ...this.source.children, ...history.children];
|
|
125
147
|
for (const component of history.children) {
|
|
126
148
|
const metadata = component as NativeContent;
|
|
127
149
|
signature.push(metadata.toolCallId, metadata.entry?.data?.parentToolCallId, metadata.message?.details?.parentToolCallId);
|
|
@@ -130,6 +152,12 @@ export class NativeContentIndex {
|
|
|
130
152
|
}
|
|
131
153
|
if (signature.length === this.signature.length && signature.every((value, index) => value === this.signature[index])) return;
|
|
132
154
|
const owners = new Map<string, NativeContent>();
|
|
155
|
+
const panels = new Map<string, NativeContent>();
|
|
156
|
+
for (const component of history.children) {
|
|
157
|
+
const entry = (component as NativeContent).entry;
|
|
158
|
+
if (entry?.customType !== "ide-nested-results" || !Array.isArray(entry.data?.calls)) continue;
|
|
159
|
+
for (const call of entry.data.calls) if (typeof call.id === "string") panels.set(call.id, component as NativeContent);
|
|
160
|
+
}
|
|
133
161
|
for (const component of history.children) {
|
|
134
162
|
const adapter = nativeKinds[nameOf(component)];
|
|
135
163
|
const native = component as NativeContent;
|
|
@@ -153,6 +181,27 @@ export class NativeContentIndex {
|
|
|
153
181
|
const parentId = native.entry?.data?.parentToolCallId ?? native.message?.details?.parentToolCallId;
|
|
154
182
|
const owner = kind === "system" && typeof parentId === "string" ? owners.get(parentId) : undefined;
|
|
155
183
|
entries.push(this.entry(component, kind, spacing, true, owner));
|
|
184
|
+
if (kind === "tool" && typeof native.toolCallId === "string") {
|
|
185
|
+
for (const child of this.nested?.entries(native.toolCallId) ?? []) {
|
|
186
|
+
const entry = this.entry(child, "system", [], true, native);
|
|
187
|
+
entry.nested = true;
|
|
188
|
+
if (this.nested?.summary(child)) {
|
|
189
|
+
const id = this.nested.id(child);
|
|
190
|
+
const group = id && this.nested.isSaved(child) ? panels.get(id) : undefined;
|
|
191
|
+
if (group && id && group.entry?.data?.parentToolCallId === native.toolCallId) {
|
|
192
|
+
let cached = this.savedPanels.get(child);
|
|
193
|
+
if (!cached || cached.group !== group) {
|
|
194
|
+
cached = { group, panel: new SavedNativePanel(child, group, id) };
|
|
195
|
+
this.savedPanels.set(child, cached);
|
|
196
|
+
}
|
|
197
|
+
entry.component = cached.panel;
|
|
198
|
+
}
|
|
199
|
+
entry.tool = () => this.nested!.summary(child)!;
|
|
200
|
+
entry.search = () => ({ label: this.nested!.summary(child)!.name, text: this.nested!.search(child) });
|
|
201
|
+
}
|
|
202
|
+
entries.push(entry);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
156
205
|
}
|
|
157
206
|
spacing = [];
|
|
158
207
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,15 +2,19 @@ import path from "node:path";
|
|
|
2
2
|
import { copyToClipboard, getAgentDir, getSettingsListTheme, type ExtensionAPI, type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import { Box, Container, isKeyRelease, matchesKey, SettingsList, Text, type TUI } from "@earendil-works/pi-tui";
|
|
4
4
|
import { TranscriptLayout } from "./layout.js";
|
|
5
|
+
import { NestedActivity } from "./nested-activity.js";
|
|
5
6
|
import { TOOL_START_ENTRY, TranscriptTimestamps } from "./timestamps.js";
|
|
6
7
|
import { defaults, loadPreferences, savePreferences, type Preferences } from "./preferences.js";
|
|
7
|
-
import { beforeFirstFrame } from "./startup.js";
|
|
8
|
+
import { beforeFirstFrame, captureToolRenderers } from "./startup.js";
|
|
8
9
|
|
|
9
10
|
/** Split native fullscreen history without changing message content or the input dock. */
|
|
10
11
|
export default async function transcript(pi: ExtensionAPI): Promise<void> {
|
|
11
12
|
let layout: TranscriptLayout | undefined;
|
|
12
13
|
let host: TUI | undefined;
|
|
13
14
|
let timestamps: TranscriptTimestamps | undefined;
|
|
15
|
+
let nested: NestedActivity | undefined;
|
|
16
|
+
const renderers = captureToolRenderers();
|
|
17
|
+
renderers.install();
|
|
14
18
|
let unsubscribeInput: (() => void) | undefined;
|
|
15
19
|
let writes = Promise.resolve();
|
|
16
20
|
let preferences: Preferences = { ...defaults };
|
|
@@ -94,6 +98,8 @@ export default async function transcript(pi: ExtensionAPI): Promise<void> {
|
|
|
94
98
|
const createLayout = (tui: TUI, ui: ExtensionContext["ui"], session: ExtensionContext["sessionManager"]): void => {
|
|
95
99
|
host = tui;
|
|
96
100
|
timestamps = new TranscriptTimestamps(session);
|
|
101
|
+
nested = new NestedActivity(tui, session.getCwd(), renderers.resolve);
|
|
102
|
+
nested.restore(session.getBranch());
|
|
97
103
|
layout = new TranscriptLayout(preferences, () => ui.theme,
|
|
98
104
|
message => ui.notify(message, "warning"), () => persist(ui), timestamps,
|
|
99
105
|
() => { void openSettings(ui).catch(error => ui.notify(String(error), "error")); }, text => {
|
|
@@ -107,7 +113,7 @@ export default async function transcript(pi: ExtensionAPI): Promise<void> {
|
|
|
107
113
|
}
|
|
108
114
|
void copyToClipboard(text).then(() => ui.notify("Block sent to clipboard.", "info"),
|
|
109
115
|
error => ui.notify("Could not copy block: " + String(error), "error"));
|
|
110
|
-
}, () => pi.getAllTools());
|
|
116
|
+
}, () => pi.getAllTools(), nested);
|
|
111
117
|
try { ensureLayout(); }
|
|
112
118
|
catch (error) {
|
|
113
119
|
layout.dispose();
|
|
@@ -126,6 +132,7 @@ export default async function transcript(pi: ExtensionAPI): Promise<void> {
|
|
|
126
132
|
});
|
|
127
133
|
|
|
128
134
|
pi.on("session_start", async (event, ctx) => {
|
|
135
|
+
renderers.install();
|
|
129
136
|
releaseStartup();
|
|
130
137
|
if (ctx.mode !== "tui") return;
|
|
131
138
|
const early = event.reason === "startup" && earlySession === ctx.sessionManager.getSessionId() && layout !== undefined;
|
|
@@ -163,6 +170,7 @@ export default async function transcript(pi: ExtensionAPI): Promise<void> {
|
|
|
163
170
|
});
|
|
164
171
|
pi.on("message_start", event => {
|
|
165
172
|
timestamps?.observe(event.message);
|
|
173
|
+
if (event.message.role === "toolResult") nested?.absorb(event.message);
|
|
166
174
|
layout?.refreshSearch();
|
|
167
175
|
});
|
|
168
176
|
pi.on("message_update", event => {
|
|
@@ -174,16 +182,27 @@ export default async function transcript(pi: ExtensionAPI): Promise<void> {
|
|
|
174
182
|
timestamps?.observe(event.message, true);
|
|
175
183
|
layout?.refreshSearch();
|
|
176
184
|
});
|
|
177
|
-
pi.on("tool_execution_update",
|
|
178
|
-
|
|
185
|
+
pi.on("tool_execution_update", event => {
|
|
186
|
+
if (event.parentToolCallId) { nested?.update(event); host?.requestRender(); }
|
|
187
|
+
layout?.refreshSearch();
|
|
188
|
+
});
|
|
189
|
+
pi.on("tool_execution_end", event => {
|
|
190
|
+
if (event.parentToolCallId) { nested?.end({ ...event, parentToolCallId: event.parentToolCallId }); host?.requestRender(); }
|
|
191
|
+
layout?.refreshSearch();
|
|
192
|
+
});
|
|
179
193
|
pi.on("tool_execution_start", event => {
|
|
180
|
-
if (
|
|
194
|
+
if (event.parentToolCallId) {
|
|
195
|
+
nested?.start({ ...event, parentToolCallId: event.parentToolCallId });
|
|
196
|
+
layout?.refreshSearch(); host?.requestRender(); return;
|
|
197
|
+
}
|
|
198
|
+
if (!timestamps) return;
|
|
181
199
|
pi.appendEntry(TOOL_START_ENTRY, { toolCallId: event.toolCallId, time: Date.now() });
|
|
182
200
|
host?.requestRender();
|
|
183
201
|
});
|
|
184
|
-
pi.on("session_tree", () => { closeSearch(); timestamps?.reset(); });
|
|
185
|
-
pi.on("session_compact", () => { closeSearch(); timestamps?.reset(); });
|
|
202
|
+
pi.on("session_tree", (_event, ctx) => { closeSearch(); timestamps?.reset(); nested?.restore(ctx.sessionManager.getBranch()); host?.requestRender(); });
|
|
203
|
+
pi.on("session_compact", (_event, ctx) => { closeSearch(); timestamps?.reset(); nested?.restore(ctx.sessionManager.getBranch()); host?.requestRender(); });
|
|
186
204
|
pi.on("session_shutdown", async () => {
|
|
205
|
+
renderers.dispose();
|
|
187
206
|
releaseStartup();
|
|
188
207
|
closeSearch();
|
|
189
208
|
unsubscribeInput?.();
|
|
@@ -191,6 +210,7 @@ export default async function transcript(pi: ExtensionAPI): Promise<void> {
|
|
|
191
210
|
layout?.dispose();
|
|
192
211
|
layout = undefined;
|
|
193
212
|
timestamps = undefined;
|
|
213
|
+
nested = undefined;
|
|
194
214
|
host = undefined;
|
|
195
215
|
await writes;
|
|
196
216
|
});
|
package/src/layout.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
} from "@earendil-works/pi-tui";
|
|
7
7
|
import { NativeDocument, type Pane } from "./native.js";
|
|
8
8
|
import { NativeContentIndex } from "./content.js";
|
|
9
|
+
import type { NestedActivity } from "./nested-activity.js";
|
|
9
10
|
import type { Preferences } from "./preferences.js";
|
|
10
11
|
import type { TranscriptTimestamps } from "./timestamps.js";
|
|
11
12
|
import { PANEL_SEARCH_ROWS, PanelSearch, PanelSearchShortcut, type SearchHit } from "./search.js";
|
|
@@ -136,6 +137,7 @@ export class TranscriptLayout {
|
|
|
136
137
|
private readonly openSettings: () => void,
|
|
137
138
|
private readonly copy?: (text: string | undefined) => void,
|
|
138
139
|
private readonly getTools: () => readonly ToolInfo[] = () => [],
|
|
140
|
+
private readonly nested?: NestedActivity,
|
|
139
141
|
) {}
|
|
140
142
|
|
|
141
143
|
private button(icon: () => string, action: () => void, enabled = (): boolean => true, background?: () => Color): Component {
|
|
@@ -202,7 +204,7 @@ export class TranscriptLayout {
|
|
|
202
204
|
const timestampGutter = (): number => scroll.scrollbar === "auto" ? 1 : 0;
|
|
203
205
|
const showTimestamps = (): boolean => this.preferences.showTimestamps;
|
|
204
206
|
const showCopyButtons = (): boolean => this.preferences.showCopyButtons;
|
|
205
|
-
const index = new NativeContentIndex(document);
|
|
207
|
+
const index = new NativeContentIndex(document, this.nested);
|
|
206
208
|
const activityDocument = new NativeDocument(document, "activity", this.timestamps, this.theme, timestampGutter, showTimestamps,
|
|
207
209
|
() => this.activate("activity"), false, index, this.copy, showCopyButtons, () => this.preferences.compactTools, this.getTools,
|
|
208
210
|
() => { if (this.activity) this.activity.scrollTo(this.activity.scrollTop, { disableFollow: true }); });
|
|
@@ -296,7 +298,7 @@ export class TranscriptLayout {
|
|
|
296
298
|
};
|
|
297
299
|
const label = new HStack([
|
|
298
300
|
{ component: new MouseRegion({
|
|
299
|
-
render: width => new Text(this.theme().style(truncateToWidth((this.searchPane() === target ? "● " : " ") + title, width, "").padEnd(width), {
|
|
301
|
+
render: width => new Text(this.theme().style(truncateToWidth(" " + (this.searchPane() === target ? "● " : " ") + title, width, "").padEnd(width), {
|
|
300
302
|
fg: this.searchPane() === target ? "accent" : palette().text, bg: palette().fill,
|
|
301
303
|
}), 0, 0).render(width),
|
|
302
304
|
invalidate() {},
|
package/src/native.ts
CHANGED
|
@@ -118,7 +118,7 @@ export class NativeDocument extends Container {
|
|
|
118
118
|
this.frameActive = true;
|
|
119
119
|
this.frameWidth = undefined;
|
|
120
120
|
if (this.compactBlocks.size) {
|
|
121
|
-
const present = new Set((this.
|
|
121
|
+
const present = new Set(this.index.entries(this.pane).map(entry => entry.source));
|
|
122
122
|
for (const [component, block] of this.compactBlocks) if (!present.has(component)) {
|
|
123
123
|
block.dispose();
|
|
124
124
|
this.compactBlocks.delete(component);
|
|
@@ -316,7 +316,8 @@ export class NativeDocument extends Container {
|
|
|
316
316
|
}
|
|
317
317
|
for (const source of opening) this.openGroups.add(source);
|
|
318
318
|
this.groups = groups;
|
|
319
|
-
|
|
319
|
+
const searched = this.searchAnchor ? this.index.entries(this.pane).find(entry => entry.source === this.searchAnchor!.entry.source) : undefined;
|
|
320
|
+
this.searchTool = searched?.nested ? searched.source : searched?.owner;
|
|
320
321
|
for (const entry of this.index.entries(this.pane)) {
|
|
321
322
|
const component = entry.source;
|
|
322
323
|
const routed = entry.component;
|
|
@@ -328,18 +329,18 @@ export class NativeDocument extends Container {
|
|
|
328
329
|
let bodyDepth = 0;
|
|
329
330
|
const compactTool = compactTools && entry.kind === "tool";
|
|
330
331
|
if (compactTool) {
|
|
331
|
-
const group = this.groups.get(entry.owner);
|
|
332
|
+
const group = entry.nested ? undefined : this.groups.get(entry.owner);
|
|
332
333
|
const grouped = group !== undefined && group.calls.length > 1;
|
|
333
|
-
bodyDepth = grouped ? 2 : 1;
|
|
334
|
+
bodyDepth = entry.nested || grouped ? 2 : 1;
|
|
334
335
|
const members = !grouped || this.groupOpen(group);
|
|
335
336
|
if (entry.tool) {
|
|
336
337
|
if (visibleBlock && !toolRun) result.push(new Spacer(1));
|
|
337
338
|
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
|
+
if (members) result.push(this.indent(this.compactRow(entry), entry.nested || grouped ? 1 : 0));
|
|
339
340
|
toolRun = true;
|
|
340
341
|
visibleBlock = true;
|
|
341
342
|
}
|
|
342
|
-
nativeBody = members && this.toolOpen(entry.owner);
|
|
343
|
+
nativeBody = entry.nested && !entry.tool ? true : members && this.toolOpen(entry.nested ? component : entry.owner);
|
|
343
344
|
}
|
|
344
345
|
const contentStart = result.length;
|
|
345
346
|
const bodyWidth = Math.max(0, width - (bodyDepth ? bodyDepth * 2 + 1 : 0));
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { ToolExecutionComponent, type ToolRenderers } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { Text, stripTerminalSequences, type Component, type TUI } from "@earendil-works/pi-tui";
|
|
3
|
+
|
|
4
|
+
type Start = { parentToolCallId: string; toolCallId: string; toolName: string; args: unknown };
|
|
5
|
+
type End = { parentToolCallId: string; toolCallId: string; toolName: string; result: { content?: unknown }; isError: boolean; durationMs?: number };
|
|
6
|
+
type RecordCall = { id: string; name: string; status: "ok" | "error" | "unfinished"; arguments?: unknown; argumentsBytes?: number; error?: string };
|
|
7
|
+
type SavedMessage = { role: string; toolCallId?: string; nestedCalls?: { complete: boolean; calls: RecordCall[] } };
|
|
8
|
+
type Call = { root: string; id: string; name: string; args: unknown; status: string; result?: string; saved?: boolean; bytes?: number; parallel?: boolean; view: Component };
|
|
9
|
+
|
|
10
|
+
const clean = (value: string): string => stripTerminalSequences(value).replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g, "");
|
|
11
|
+
const resultText = (content: unknown): string => Array.isArray(content) ? content.map(block =>
|
|
12
|
+
block?.type === "text" && typeof block.text === "string" ? clean(block.text.replace(/^<system-result\b[^>]*><uuid>[a-f\d-]{36}<\/uuid><\/system-result>\n/iu, "")) : block?.type === "image" ? "[image]" : "").filter(Boolean).join("\n") : "";
|
|
13
|
+
|
|
14
|
+
/** Display-only nested call state. Saved records never imply that a result was saved. */
|
|
15
|
+
export class NestedActivity {
|
|
16
|
+
private calls = new Map<string, Call>();
|
|
17
|
+
private roots = new Map<string, Component[]>();
|
|
18
|
+
private byView = new WeakMap<Component, Call>();
|
|
19
|
+
private notices = new Map<string, Text>();
|
|
20
|
+
revision = 0;
|
|
21
|
+
|
|
22
|
+
constructor(private readonly tui?: TUI, private readonly cwd = "", private readonly renderer?: (name: string) => ToolRenderers | undefined) {}
|
|
23
|
+
|
|
24
|
+
entries(parent: string): readonly Component[] { return this.roots.get(parent) ?? []; }
|
|
25
|
+
|
|
26
|
+
summary(view: Component): { name: string; args: unknown; status: "running" | "success" | "error" | "unknown" } | undefined {
|
|
27
|
+
const call = this.byView.get(view);
|
|
28
|
+
return call ? { name: call.name, args: call.args, status: call.status === "error" ? "error" : call.status === "ok" ? "success" : call.status === "running" ? "running" : "unknown" } : undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
id(view: Component): string | undefined { return this.byView.get(view)?.id; }
|
|
32
|
+
isSaved(view: Component): boolean { return this.byView.get(view)?.saved === true; }
|
|
33
|
+
search(view: Component): string {
|
|
34
|
+
const call = this.byView.get(view);
|
|
35
|
+
return call ? [call.name, JSON.stringify(call.args, null, 2), call.result].filter(Boolean).join("\n") : "";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private paint(call: Call): void {
|
|
39
|
+
const depth = Math.max(1, call.id.slice(call.root.length).split("/").length - 1);
|
|
40
|
+
const prefix = " ".repeat(Math.min(depth, 8));
|
|
41
|
+
const args = call.args === undefined ? (call.bytes === undefined ? "" : `Arguments omitted (${call.bytes} bytes)`) : JSON.stringify(call.args, null, 2);
|
|
42
|
+
const details = [args, call.result, call.saved ? "Result not saved" : ""].filter(Boolean).join("\n");
|
|
43
|
+
if (!(call.view instanceof Text)) return;
|
|
44
|
+
call.view.setText(`${prefix}↳ ${clean(call.name)} [${call.status}${call.parallel ? ", overlapping" : ""}]\n${details.split("\n").map(line => prefix + clean(line)).join("\n")}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
start(event: Start): void {
|
|
48
|
+
const root = this.calls.get(event.parentToolCallId)?.root ?? event.parentToolCallId;
|
|
49
|
+
const running = [...this.calls.values()].filter(call => call.root === root && call.status === "running" && !event.parentToolCallId.startsWith(call.id + "/") && event.parentToolCallId !== call.id);
|
|
50
|
+
const native = this.tui ? new ToolExecutionComponent(event.toolName, event.toolCallId, event.args, { showImages: true }, this.renderer?.(event.toolName), this.tui, this.cwd) : undefined;
|
|
51
|
+
native?.markExecutionStarted();
|
|
52
|
+
native?.setArgsComplete();
|
|
53
|
+
native?.setExpanded(true);
|
|
54
|
+
const call: Call = { root, id: event.toolCallId, name: event.toolName, args: event.args, status: "running", parallel: running.length > 0, view: native ?? new Text("", 0, 0) };
|
|
55
|
+
for (const other of running) { other.parallel = true; this.paint(other); }
|
|
56
|
+
this.calls.set(call.id, call);
|
|
57
|
+
this.byView.set(call.view, call);
|
|
58
|
+
const entries = this.roots.get(root) ?? [];
|
|
59
|
+
entries.push(call.view);
|
|
60
|
+
this.roots.set(root, entries);
|
|
61
|
+
this.paint(call);
|
|
62
|
+
this.revision++;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
update(event: { toolCallId: string; partialResult: { content?: unknown } }): void {
|
|
66
|
+
const call = this.calls.get(event.toolCallId);
|
|
67
|
+
if (!call) return;
|
|
68
|
+
call.result = resultText(event.partialResult.content);
|
|
69
|
+
if (call.view instanceof ToolExecutionComponent) call.view.updateResult({ ...event.partialResult, content: Array.isArray(event.partialResult.content) ? event.partialResult.content : [], isError: false }, true);
|
|
70
|
+
this.paint(call);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
end(event: End): void {
|
|
74
|
+
const call = this.calls.get(event.toolCallId);
|
|
75
|
+
if (!call) return;
|
|
76
|
+
call.status = event.isError ? "error" : "ok";
|
|
77
|
+
call.result = resultText(event.result.content);
|
|
78
|
+
if (call.view instanceof ToolExecutionComponent) call.view.updateResult({ ...event.result, content: Array.isArray(event.result.content) ? event.result.content : [], isError: event.isError, durationMs: event.durationMs });
|
|
79
|
+
this.paint(call);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
absorb(message: SavedMessage): void {
|
|
83
|
+
const root = message.toolCallId;
|
|
84
|
+
const nested = message.nestedCalls;
|
|
85
|
+
if (message.role !== "toolResult" || !root || !nested || !Array.isArray(nested.calls)) return;
|
|
86
|
+
let entries = this.roots.get(root);
|
|
87
|
+
if (!entries) { entries = []; this.roots.set(root, entries); }
|
|
88
|
+
for (const record of nested.calls) {
|
|
89
|
+
if (this.calls.has(record.id)) continue;
|
|
90
|
+
const call: Call = { root, id: record.id, name: record.name, args: record.arguments, status: record.status,
|
|
91
|
+
bytes: record.argumentsBytes, result: record.error, saved: true, view: new Text("", 0, 0) };
|
|
92
|
+
this.calls.set(record.id, call);
|
|
93
|
+
this.byView.set(call.view, call);
|
|
94
|
+
entries.push(call.view);
|
|
95
|
+
this.paint(call);
|
|
96
|
+
this.revision++;
|
|
97
|
+
}
|
|
98
|
+
if (!nested.complete && !this.notices.has(root)) {
|
|
99
|
+
const notice = new Text(" Nested call record incomplete", 0, 0);
|
|
100
|
+
this.notices.set(root, notice);
|
|
101
|
+
entries.push(notice);
|
|
102
|
+
this.revision++;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
restore(branch: readonly { type: string; message?: unknown }[]): void {
|
|
107
|
+
this.calls.clear(); this.roots.clear(); this.notices.clear(); this.revision++;
|
|
108
|
+
for (const entry of branch) if (entry.type === "message" && entry.message && typeof entry.message === "object") this.absorb(entry.message as SavedMessage);
|
|
109
|
+
}
|
|
110
|
+
}
|
package/src/startup.ts
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
|
-
import { InteractiveMode, type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
1
|
+
import { InteractiveMode, type ExtensionContext, type ToolRenderers } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { isViewportTUI, type TUI } from "@earendil-works/pi-tui";
|
|
3
3
|
|
|
4
|
+
/** Resolve nested tools through the same interactive host that renders ordinary calls. */
|
|
5
|
+
export function captureToolRenderers(): { install(): void; resolve(name: string): ToolRenderers | undefined; dispose(): void } {
|
|
6
|
+
const prototype = InteractiveMode.prototype as unknown as Record<string, unknown>;
|
|
7
|
+
let owner: unknown;
|
|
8
|
+
let original: ((this: unknown, name: string) => ToolRenderers | undefined) | undefined;
|
|
9
|
+
let wrapper: ((this: unknown, name: string) => ToolRenderers | undefined) | undefined;
|
|
10
|
+
let stop = (): void => {};
|
|
11
|
+
return {
|
|
12
|
+
install() {
|
|
13
|
+
if (wrapper) return;
|
|
14
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, "getRegisteredToolDefinition");
|
|
15
|
+
if (!descriptor?.writable || typeof descriptor.value !== "function") return;
|
|
16
|
+
const previous = descriptor.value as (this: unknown, name: string) => ToolRenderers | undefined;
|
|
17
|
+
original = previous;
|
|
18
|
+
let active = true;
|
|
19
|
+
stop = () => { active = false; };
|
|
20
|
+
wrapper = function (this: unknown, name: string) { if (active) owner = this; return previous.call(this, name); };
|
|
21
|
+
prototype.getRegisteredToolDefinition = wrapper;
|
|
22
|
+
},
|
|
23
|
+
resolve(name) { return owner && original ? original.call(owner, name) : undefined; },
|
|
24
|
+
dispose() {
|
|
25
|
+
stop();
|
|
26
|
+
if (wrapper && prototype.getRegisteredToolDefinition === wrapper) prototype.getRegisteredToolDefinition = original;
|
|
27
|
+
owner = undefined; wrapper = undefined; original = undefined;
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
4
31
|
type Ui = ExtensionContext["ui"];
|
|
5
32
|
type Session = ExtensionContext["sessionManager"];
|
|
6
33
|
type StartupHost = {
|