pi-stereo-view 0.1.12 → 0.1.14
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 +15 -0
- package/README.md +3 -1
- package/package.json +1 -1
- package/src/compact-tools.ts +22 -5
- package/src/content.ts +74 -22
- package/src/index.ts +4 -1
- package/src/layout.ts +45 -21
- package/src/native-editor.ts +41 -0
- package/src/native.ts +7 -2
- package/src/timestamps.ts +56 -21
- package/src/tool-indent.ts +13 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
## 0.1.14 - 2026-11-07
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- Keep split view responsive while an agent streams in long sessions. Frames no longer rebuild call headers, timestamps and every earlier answer for the whole history.
|
|
10
|
+
|
|
11
|
+
## 0.1.13 - 2026-11-06
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- Show native inline extension dialogs below Activity history alongside widgets. Keep message editors full width, explicit overlays unchanged and native placement available when the surface does not fit.
|
|
16
|
+
- Preserve an inline dialog's keyboard focus when pressing the panel search shortcut.
|
|
17
|
+
|
|
3
18
|
## 0.1.12 - 2026-11-04
|
|
4
19
|
|
|
5
20
|
### Changed
|
package/README.md
CHANGED
|
@@ -29,7 +29,9 @@ Late output linked to a tool call appears directly below that call in Activity,
|
|
|
29
29
|
|
|
30
30
|
Expand a parent tool such as Codemode to browse its nested call tree. Adjacent calls of the same tool form a group with individual call headers. Each independent native result opens under its call. A combined result covering several calls stays whole inside their group. Panels without child execution identities remain available inside the parent's output disclosure. Session restoration uses Pi's saved nested-call metadata and the original saved panels.
|
|
31
31
|
|
|
32
|
-
Messages and tools keep their familiar appearance. Extension widgets appear at the bottom of Activity
|
|
32
|
+
Messages and tools keep their familiar appearance. Extension widgets and inline dialogs appear at the bottom of Activity, below its independently scrolling history. Standard select, confirm, input and editor dialogs and non-overlay custom components keep Pi's native input, focus and completion behavior. The message editor, including extension-provided replacements, stays full width whenever Pi displays it. Explicit overlays keep their native placement.
|
|
33
|
+
|
|
34
|
+
If the Activity surface cannot fit without clipping, the view temporarily returns to combined history and Pi's normal placement. Combined history, zoomed Conversation and unsupported native layouts also leave dialogs and widgets in Pi's dock. Open forms stay live as layouts change and disappear when their producer closes them; they are not added to history.
|
|
33
35
|
|
|
34
36
|
## Features
|
|
35
37
|
|
package/package.json
CHANGED
package/src/compact-tools.ts
CHANGED
|
@@ -31,21 +31,38 @@ interface CompactToolOptions {
|
|
|
31
31
|
toggle?(): void;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
interface HeaderInputs {
|
|
35
|
+
width: number; name: string; args: unknown; status: ToolSummary["status"]; count?: number; expanded?: boolean;
|
|
36
|
+
label: string; theme: Theme;
|
|
37
|
+
}
|
|
38
|
+
const sameInputs = (a: HeaderInputs, b: HeaderInputs): boolean => a.width === b.width && a.name === b.name &&
|
|
39
|
+
a.args === b.args && a.status === b.status && a.count === b.count && a.expanded === b.expanded && a.label === b.label && a.theme === b.theme;
|
|
40
|
+
|
|
34
41
|
/** A display-only call or group header; the original renderer owns the body. */
|
|
35
42
|
export class CompactTool implements Component {
|
|
43
|
+
// Headers are rebuilt every frame for the whole history. Completed calls keep their
|
|
44
|
+
// argument object, so reuse the row until a displayed input changes.
|
|
45
|
+
private cached?: { inputs: HeaderInputs; lines: string[] };
|
|
46
|
+
|
|
36
47
|
constructor(private readonly summary: () => ToolSummary, private readonly theme: () => Theme,
|
|
37
48
|
private readonly options: CompactToolOptions = {}) {}
|
|
38
49
|
|
|
39
50
|
render(width: number): string[] {
|
|
40
51
|
width = Math.max(0, width - (this.options.gutter?.() ?? 0));
|
|
41
52
|
const { name, args, status } = this.summary();
|
|
42
|
-
const
|
|
53
|
+
const inputs: HeaderInputs = { width, name, args, status, count: this.options.count?.(),
|
|
54
|
+
expanded: this.options.toggle ? this.options.expanded?.() : undefined, label: this.options.clock?.() ?? "", theme: this.theme() };
|
|
55
|
+
// Streamed arguments may be updated in place, so running calls always rebuild.
|
|
56
|
+
if (this.cached && status !== "running" && sameInputs(this.cached.inputs, inputs)) return this.cached.lines;
|
|
57
|
+
const lines = this.header(inputs);
|
|
58
|
+
this.cached = { inputs, lines };
|
|
59
|
+
return lines;
|
|
60
|
+
}
|
|
61
|
+
private header({ width, name, args, status, count, expanded, label, theme }: HeaderInputs): string[] {
|
|
43
62
|
const dot = theme.fg(status === "running" ? "warning" : status === "unknown" ? "dim" : status, "●");
|
|
44
|
-
const count = this.options.count?.();
|
|
45
63
|
const description = count ? "" : toolDescription(args);
|
|
46
|
-
const control = this.options.toggle ? theme.fg("muted",
|
|
64
|
+
const control = this.options.toggle ? theme.fg("muted", expanded ? "▾" : "▸") + " " : this.options.alignControl ? " " : "";
|
|
47
65
|
const text = `${dot} ${control}${singleLine(name)}${count ? ` ×${count}` : ""}${description ? " " + theme.fg("muted", description) : ""}`;
|
|
48
|
-
const label = this.options.clock?.() ?? "";
|
|
49
66
|
const clock = label && width >= visibleWidth(label) + 8 ? label : "";
|
|
50
67
|
const available = Math.max(0, width - 1 - (clock ? visibleWidth(clock) + 1 : 0));
|
|
51
68
|
const body = truncateToWidth(text, available, "…");
|
|
@@ -60,5 +77,5 @@ export class CompactTool implements Component {
|
|
|
60
77
|
}
|
|
61
78
|
return { handled: true };
|
|
62
79
|
}
|
|
63
|
-
invalidate(): void {}
|
|
80
|
+
invalidate(): void { this.cached = undefined; }
|
|
64
81
|
}
|
package/src/content.ts
CHANGED
|
@@ -79,6 +79,20 @@ function assistant(component: Component): NativeAssistant | undefined {
|
|
|
79
79
|
return native;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
/** Native rendering creates one child per visible text block or consecutive thinking run. */
|
|
83
|
+
function forEachRun(source: NativeAssistant, visit: (kind: ContentKind) => void): void {
|
|
84
|
+
let thinking = false;
|
|
85
|
+
for (const block of source.lastMessage?.content ?? []) {
|
|
86
|
+
if (block.type === "thinking") {
|
|
87
|
+
if (!thinking && block.thinking?.trim()) { visit("thinking"); thinking = true; }
|
|
88
|
+
} else {
|
|
89
|
+
thinking = false;
|
|
90
|
+
if (block.type === "text" && block.text?.trim()) visit("dialogue");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const runsEnd = Symbol("runs");
|
|
95
|
+
|
|
82
96
|
/** Read supported native execution identities; unrecognized content is system information. */
|
|
83
97
|
const nativeKinds: Record<string, { kind: ContentKind; accepts(content: NativeContent): boolean }> = {
|
|
84
98
|
UserMessageComponent: { kind: "dialogue", accepts: content => typeof content.text === "string" },
|
|
@@ -127,15 +141,31 @@ function nativePanelParts(source: NativeContent): Component[] | undefined {
|
|
|
127
141
|
export class NativeContentIndex {
|
|
128
142
|
private signature: unknown[] = [];
|
|
129
143
|
private content: ContentEntry[] = [];
|
|
144
|
+
private panes: Partial<Record<Pane, ContentEntry[]>> = {};
|
|
130
145
|
private readonly expandedPanels = new WeakMap<Component, Component>();
|
|
131
146
|
private readonly views = new WeakMap<NativeAssistant, Partial<Record<Pane, Container>>>();
|
|
132
147
|
|
|
148
|
+
private pass?: { active: boolean; verified?: { children: Component[]; length: number; last?: Component; parts: number; revision: number } };
|
|
149
|
+
|
|
133
150
|
constructor(private readonly source: Container, readonly nested = new NestedCalls()) {}
|
|
134
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Native history cannot change while Pi lays out one frame, so the panes of a pass
|
|
154
|
+
* share one verification. The pass ends in the next microtask; structural changes
|
|
155
|
+
* and nested-call updates inside it still verify again.
|
|
156
|
+
*/
|
|
157
|
+
beginFrame(): void {
|
|
158
|
+
if (this.pass?.active) { this.pass.verified = undefined; return; }
|
|
159
|
+
const pass: NonNullable<typeof this.pass> = { active: true };
|
|
160
|
+
this.pass = pass;
|
|
161
|
+
queueMicrotask(() => { pass.active = false; if (this.pass === pass) this.pass = undefined; });
|
|
162
|
+
}
|
|
163
|
+
|
|
135
164
|
/** Return the same classification until native ownership or assistant content changes. */
|
|
136
165
|
entries(pane?: Pane): ContentEntry[] {
|
|
137
166
|
this.refresh();
|
|
138
|
-
|
|
167
|
+
if (pane === undefined) return this.content;
|
|
168
|
+
return this.panes[pane] ??= this.content.filter(entry => panes[entry.kind] === pane);
|
|
139
169
|
}
|
|
140
170
|
|
|
141
171
|
/** A rebuilt history cannot retain search hits belonging to removed native owners. */
|
|
@@ -155,23 +185,51 @@ export class NativeContentIndex {
|
|
|
155
185
|
return group.map(candidate => stripTerminalSequences(candidate.search(width).text)).filter(Boolean).join("\n\n");
|
|
156
186
|
}
|
|
157
187
|
|
|
188
|
+
/** Visit every native identity that classification depends on, in a fixed order. */
|
|
189
|
+
private visitSignature(history: Container, visit: (value: unknown) => boolean): boolean {
|
|
190
|
+
if (!visit(this.nested.revision)) return false;
|
|
191
|
+
for (const component of this.source.children) if (!visit(component)) return false;
|
|
192
|
+
for (const component of history.children) if (!visit(component)) return false;
|
|
193
|
+
for (const component of history.children) {
|
|
194
|
+
const metadata = component as NativeContent;
|
|
195
|
+
if (!visit(metadata.toolCallId) || !visit(metadata.entry?.data?.parentToolCallId) ||
|
|
196
|
+
!visit(metadata.message?.details?.parentToolCallId) || !visit(metadata.customComponent)) return false;
|
|
197
|
+
if (metadata.entry?.data?.parentToolCallId || metadata.message?.details?.parentToolCallId)
|
|
198
|
+
for (const part of nativePanelParts(metadata) ?? []) if (!visit(part)) return false;
|
|
199
|
+
const native = assistant(component);
|
|
200
|
+
if (native) {
|
|
201
|
+
// Streaming replaces the message on every delta; only its block layout affects routing.
|
|
202
|
+
let changed = false;
|
|
203
|
+
forEachRun(native, kind => { if (!changed && !visit(kind)) changed = true; });
|
|
204
|
+
if (changed || !visit(runsEnd)) return false;
|
|
205
|
+
for (const child of native.contentContainer.children) if (!visit(child)) return false;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
|
|
158
211
|
private refresh(): void {
|
|
159
212
|
const history = this.source.children[2] as Container;
|
|
160
213
|
if (!Array.isArray(history?.children)) throw new Error("Pi's history document is not supported");
|
|
214
|
+
const pass = this.pass?.active ? this.pass : undefined;
|
|
215
|
+
const children = history.children;
|
|
216
|
+
const verified = pass?.verified;
|
|
217
|
+
if (verified && verified.children === children && verified.length === children.length && verified.last === children.at(-1) &&
|
|
218
|
+
verified.parts === this.source.children.length && verified.revision === this.nested.revision) return;
|
|
219
|
+
this.verify(history);
|
|
220
|
+
if (pass) pass.verified = { children, length: children.length, last: children.at(-1), parts: this.source.children.length, revision: this.nested.revision };
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
private verify(history: Container): void {
|
|
161
224
|
const makeSignature = (): unknown[] => {
|
|
162
|
-
const values: unknown[] = [
|
|
163
|
-
|
|
164
|
-
const metadata = component as NativeContent;
|
|
165
|
-
values.push(metadata.toolCallId, metadata.entry?.data?.parentToolCallId, metadata.message?.details?.parentToolCallId, metadata.customComponent);
|
|
166
|
-
if (metadata.entry?.data?.parentToolCallId || metadata.message?.details?.parentToolCallId)
|
|
167
|
-
values.push(...(nativePanelParts(metadata) ?? []));
|
|
168
|
-
const native = assistant(component);
|
|
169
|
-
if (native) values.push(native.lastMessage, ...native.contentContainer.children);
|
|
170
|
-
}
|
|
225
|
+
const values: unknown[] = [];
|
|
226
|
+
this.visitSignature(history, value => { values.push(value); return true; });
|
|
171
227
|
return values;
|
|
172
228
|
};
|
|
173
|
-
|
|
174
|
-
|
|
229
|
+
// Compare in place: this runs several times per frame over the whole history.
|
|
230
|
+
let position = 0;
|
|
231
|
+
const previous = this.signature;
|
|
232
|
+
if (this.visitSignature(history, value => value === previous[position++]) && position === previous.length) return;
|
|
175
233
|
const owners = new Map<string, NativeContent>();
|
|
176
234
|
for (const component of history.children) {
|
|
177
235
|
const adapter = nativeKinds[nameOf(component)];
|
|
@@ -219,6 +277,7 @@ export class NativeContentIndex {
|
|
|
219
277
|
this.content = entries.flatMap(entry => entry.owner === entry.source
|
|
220
278
|
? [entry, ...(linked.get(entry.source) ?? [])] : []);
|
|
221
279
|
this.signature = makeSignature();
|
|
280
|
+
this.panes = {};
|
|
222
281
|
}
|
|
223
282
|
|
|
224
283
|
private entry(source: Component, kind: ContentKind, spacing: Component[], compact: boolean, owner?: NativeContent): ContentEntry {
|
|
@@ -268,15 +327,7 @@ export class NativeContentIndex {
|
|
|
268
327
|
// Native rendering creates one child per visible text block or consecutive thinking run.
|
|
269
328
|
// Match those children to semantic content before projecting; a Text diagnostic is not thinking.
|
|
270
329
|
const runs: ContentKind[] = [];
|
|
271
|
-
|
|
272
|
-
for (const block of source.lastMessage?.content ?? []) {
|
|
273
|
-
if (block.type === "thinking") {
|
|
274
|
-
if (block.thinking?.trim() && !thinking) { runs.push("thinking"); thinking = true; }
|
|
275
|
-
} else {
|
|
276
|
-
thinking = false;
|
|
277
|
-
if (block.type === "text" && block.text?.trim()) runs.push("dialogue");
|
|
278
|
-
}
|
|
279
|
-
}
|
|
330
|
+
forEachRun(source, kind => runs.push(kind));
|
|
280
331
|
const groups: Record<Pane, Component[]> = { chat: [], activity: [] };
|
|
281
332
|
const diagnostics: Component[] = [];
|
|
282
333
|
let slot = 0;
|
|
@@ -310,7 +361,8 @@ export class NativeContentIndex {
|
|
|
310
361
|
views[pane] = view;
|
|
311
362
|
}
|
|
312
363
|
const content = view.children[0] as Container;
|
|
313
|
-
|
|
364
|
+
// Keep the array of unchanged views: their native render caches compare child identity.
|
|
365
|
+
if (content.children.length !== parts.length || content.children.some((child, index) => child !== parts[index])) content.children = parts;
|
|
314
366
|
result.push({
|
|
315
367
|
source, owner: source, component: view, kind: pane === "activity" ? "thinking" : runs.includes("dialogue") ? "dialogue" : "system", spacing, compact: true,
|
|
316
368
|
search: width => {
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ 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";
|
|
7
7
|
import { beforeFirstFrame } from "./startup.js";
|
|
8
|
+
import { observeNativeEditor } from "./native-editor.js";
|
|
8
9
|
import { NestedCalls } from "./nested-calls.js";
|
|
9
10
|
|
|
10
11
|
/** Split native fullscreen history without changing message content or the input dock. */
|
|
@@ -13,6 +14,7 @@ export default async function transcript(pi: ExtensionAPI): Promise<void> {
|
|
|
13
14
|
let host: TUI | undefined;
|
|
14
15
|
let timestamps: TranscriptTimestamps | undefined;
|
|
15
16
|
const nested = new NestedCalls();
|
|
17
|
+
const nativeEditor = observeNativeEditor();
|
|
16
18
|
let unsubscribeInput: (() => void) | undefined;
|
|
17
19
|
let writes = Promise.resolve();
|
|
18
20
|
let preferences: Preferences = { ...defaults };
|
|
@@ -110,7 +112,7 @@ export default async function transcript(pi: ExtensionAPI): Promise<void> {
|
|
|
110
112
|
}
|
|
111
113
|
void copyToClipboard(text).then(() => ui.notify("Block sent to clipboard.", "info"),
|
|
112
114
|
error => ui.notify("Could not copy block: " + String(error), "error"));
|
|
113
|
-
}, () => pi.getAllTools(), nested);
|
|
115
|
+
}, () => pi.getAllTools(), nested, () => nativeEditor.get(tui));
|
|
114
116
|
try { ensureLayout(); }
|
|
115
117
|
catch (error) {
|
|
116
118
|
layout.dispose();
|
|
@@ -201,6 +203,7 @@ export default async function transcript(pi: ExtensionAPI): Promise<void> {
|
|
|
201
203
|
pi.on("session_compact", (_event, ctx) => { closeSearch(); nested.restore(ctx.sessionManager.getBranch()); timestamps?.reset(); host?.requestRender(); });
|
|
202
204
|
pi.on("session_shutdown", async () => {
|
|
203
205
|
releaseStartup();
|
|
206
|
+
nativeEditor.dispose();
|
|
204
207
|
closeSearch();
|
|
205
208
|
unsubscribeInput?.();
|
|
206
209
|
unsubscribeInput = undefined;
|
package/src/layout.ts
CHANGED
|
@@ -35,7 +35,7 @@ class PanelScrollView extends ScrollView {
|
|
|
35
35
|
return undefined;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
class
|
|
38
|
+
class NativeSurfaceScrollView extends ScrollView {
|
|
39
39
|
override handleMouse(event: TuiMouseEvent): ReturnType<Container["handleMouse"]> {
|
|
40
40
|
if (event.type !== "wheel" || !event.wheelDelta) return undefined;
|
|
41
41
|
this.scrollBy(event.wheelDelta);
|
|
@@ -116,7 +116,7 @@ class TranscriptPane extends VStack {
|
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
/**
|
|
119
|
+
/** Project native fullscreen history and transient surfaces without taking ownership of their lifecycle. */
|
|
120
120
|
export class TranscriptLayout {
|
|
121
121
|
private host?: NativeTui;
|
|
122
122
|
private original?: Container;
|
|
@@ -151,6 +151,7 @@ export class TranscriptLayout {
|
|
|
151
151
|
private readonly copy?: (text: string | undefined) => void,
|
|
152
152
|
private readonly getTools: () => readonly ToolInfo[] = () => [],
|
|
153
153
|
private readonly nested = new NestedCalls(),
|
|
154
|
+
private readonly getEditor: () => Component | undefined = () => undefined,
|
|
154
155
|
) {}
|
|
155
156
|
|
|
156
157
|
private button(icon: () => string, action: () => void, enabled = (): boolean => true, background?: () => Color): Component {
|
|
@@ -213,16 +214,28 @@ export class TranscriptLayout {
|
|
|
213
214
|
// Route only the known native dock shape. Keep the original untouched for fallback.
|
|
214
215
|
const nativeDock = dock as unknown as { entries: Array<Exclude<StackChild, Component>>; children: Component[] };
|
|
215
216
|
const entries = Array.isArray(nativeDock.entries) ? nativeDock.entries.map(entry => ({ ...entry })) : [];
|
|
216
|
-
const
|
|
217
|
+
const supportedDock = entries.length === 6 && entries.every((entry, i) => entry.component === nativeDock.children[i]) &&
|
|
217
218
|
[2, 4].every(i => entries[i].component.constructor.name === "Container") &&
|
|
218
219
|
entries[3].minSize === 3;
|
|
219
|
-
const above =
|
|
220
|
-
const below =
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
|
|
220
|
+
const above = supportedDock ? entries[2].component as Container : undefined;
|
|
221
|
+
const below = supportedDock ? entries[4].component as Container : undefined;
|
|
222
|
+
const editorSlot = supportedDock && entries[3].component.constructor.name === "Container"
|
|
223
|
+
? entries[3].component as Container : undefined;
|
|
224
|
+
let projectDialog = false;
|
|
225
|
+
const dialogPresent = (): boolean => {
|
|
226
|
+
const editor = this.getEditor();
|
|
227
|
+
return !!editor && !!editorSlot && editorSlot.children.length === 1 && editorSlot.children[0] !== editor;
|
|
228
|
+
};
|
|
229
|
+
const projectedDock = supportedDock ? new VStack(entries.filter((_, i) => i !== 2 && i !== 4).map(entry =>
|
|
230
|
+
entry.component === editorSlot ? { ...entry, visible: () => !projectDialog } : entry)) : undefined;
|
|
231
|
+
// Preserve the original containers and Pi's above/editor/below order. Pi still owns their lifecycle.
|
|
232
|
+
const surfaceTree = above && below ? new VStack([
|
|
233
|
+
above, ...(editorSlot ? [{ component: editorSlot, visible: () => projectDialog }] : []), below,
|
|
234
|
+
]) : undefined;
|
|
235
|
+
const surfaceView = surfaceTree ? new NativeSurfaceScrollView(surfaceTree, { overscroll: "contain" }) : undefined;
|
|
224
236
|
const widgetsPresent = (): boolean => !!above && !!below && (above.children.length > 1 || below.children.length > 0);
|
|
225
|
-
const
|
|
237
|
+
const surfacePresent = (): boolean => widgetsPresent() || projectDialog;
|
|
238
|
+
const dockUnchanged = (): boolean => supportedDock && nativeDock.entries.length === 6 &&
|
|
226
239
|
nativeDock.entries.every((entry, i) => entry.component === nativeDock.children[i] &&
|
|
227
240
|
Object.keys({ ...entry, ...entries[i] }).every(key =>
|
|
228
241
|
entry[key as keyof typeof entry] === entries[i][key as keyof typeof entry]));
|
|
@@ -256,11 +269,19 @@ export class TranscriptLayout {
|
|
|
256
269
|
() => this.searchPane() === "activity");
|
|
257
270
|
this.chat = new PanelScrollView(chatDocument, scrollOptions, () => this.activate("chat"), () => this.searchPane() === "chat");
|
|
258
271
|
let historyHeight = 0;
|
|
259
|
-
let
|
|
260
|
-
|
|
272
|
+
let projectSurface = false;
|
|
273
|
+
// Every root entry asks in turn during one visibility pass; evaluate the projection once.
|
|
274
|
+
let pass: { width: number; height: number; shown: boolean } | undefined;
|
|
275
|
+
const shown = (viewport: { width: number; height: number }): boolean => {
|
|
276
|
+
if (pass?.width === viewport.width && pass.height === viewport.height) return pass.shown;
|
|
277
|
+
pass = { ...viewport, shown: evaluate(viewport) };
|
|
278
|
+
return pass.shown;
|
|
279
|
+
};
|
|
280
|
+
const evaluate = ({ width, height }: { width: number; height: number }): boolean => {
|
|
261
281
|
const previousHeight = historyHeight;
|
|
262
|
-
const candidate = !!projectedDock && widgetsPresent() && dockUnchanged() && !this.failed &&
|
|
282
|
+
const candidate = !!projectedDock && (widgetsPresent() || dialogPresent()) && dockUnchanged() && !this.failed &&
|
|
263
283
|
this.preferences.mode === "split" && this.preferences.zoom !== "chat";
|
|
284
|
+
projectDialog = candidate && dialogPresent();
|
|
264
285
|
historyHeight = Math.max(0, height - (candidate ? projectedDock : dock).render(width).length - 1);
|
|
265
286
|
const search = this.search;
|
|
266
287
|
if (search && previousHeight !== historyHeight) queueMicrotask(() => {
|
|
@@ -272,7 +293,7 @@ export class TranscriptLayout {
|
|
|
272
293
|
this.preferences.layout === "columns" ? width >= MIN_CHAT + MIN_ACTIVITY + 1 && historyHeight >= MIN_ROWS + searchRows :
|
|
273
294
|
width >= MIN_CHAT && historyHeight >= MIN_ROWS * 2 + 1 + searchRows;
|
|
274
295
|
this.fallback = this.preferences.mode === "split" && !fits;
|
|
275
|
-
|
|
296
|
+
projectSurface = candidate && fits;
|
|
276
297
|
if (this.search && (this.fallback || this.failed || this.preferences.mode !== "split" ||
|
|
277
298
|
(this.preferences.zoom && this.preferences.zoom !== this.search.pane))) this.closeSearch(false);
|
|
278
299
|
this.searchShortcut.sync(!this.failed && this.preferences.mode === "split" && fits);
|
|
@@ -281,7 +302,7 @@ export class TranscriptLayout {
|
|
|
281
302
|
if (this.preferences.mode !== "split" || !fits) return false;
|
|
282
303
|
// Both panels project the same native history and supported content kinds.
|
|
283
304
|
activityDocument.check();
|
|
284
|
-
if (
|
|
305
|
+
if (projectSurface && surfaceTree && surfacePresent()) {
|
|
285
306
|
const chatWidth = Math.min(width - MIN_ACTIVITY - 1,
|
|
286
307
|
Math.max(MIN_CHAT, this.preferences.chatWidth ?? this.defaultWidth(width)));
|
|
287
308
|
const widgetWidth = this.preferences.zoom === "activity" || this.preferences.layout === "rows"
|
|
@@ -294,11 +315,11 @@ export class TranscriptLayout {
|
|
|
294
315
|
historyHeight - activityMin - 1));
|
|
295
316
|
const activityHeight = this.preferences.zoom || this.preferences.layout === "columns" ? historyHeight :
|
|
296
317
|
historyHeight - 1 - Math.min(chatLimit, Math.max(chatMin, chatPane.render(width).length));
|
|
297
|
-
// Do not clip opaque interactive
|
|
318
|
+
// Do not clip opaque interactive surfaces: their own wheel handlers may consume scrolling.
|
|
298
319
|
// If the entire surface cannot fit, leave Pi's original dock available instead.
|
|
299
320
|
const budget = Math.max(0, activityHeight - 3 - activitySearch);
|
|
300
|
-
if (
|
|
301
|
-
|
|
321
|
+
if (surfaceTree.render(widgetWidth).length > budget) {
|
|
322
|
+
projectSurface = false;
|
|
302
323
|
this.fallback = true;
|
|
303
324
|
return false;
|
|
304
325
|
}
|
|
@@ -315,7 +336,7 @@ export class TranscriptLayout {
|
|
|
315
336
|
historyHeight - activityMinimum - 1)), chatMinimum, activityMinimum);
|
|
316
337
|
return true;
|
|
317
338
|
} catch (error) {
|
|
318
|
-
|
|
339
|
+
projectSurface = false;
|
|
319
340
|
this.failed = true;
|
|
320
341
|
this.searchShortcut.dispose();
|
|
321
342
|
this.disposeDocuments?.();
|
|
@@ -391,7 +412,7 @@ export class TranscriptLayout {
|
|
|
391
412
|
visible: () => this.search?.pane === target },
|
|
392
413
|
]);
|
|
393
414
|
return new TranscriptPane(header, view, () => historyHeight,
|
|
394
|
-
target === "activity" ?
|
|
415
|
+
target === "activity" ? surfaceView : undefined, () => projectSurface && surfacePresent());
|
|
395
416
|
};
|
|
396
417
|
const activityPane = pane("Activity", "activity", this.activity);
|
|
397
418
|
const chatPane = pane("Conversation", "chat", this.chat);
|
|
@@ -453,6 +474,7 @@ export class TranscriptLayout {
|
|
|
453
474
|
const mounted = new TranscriptRoot([
|
|
454
475
|
{ component: toolbar, basis: 1, shrink: 0, visible: () => {
|
|
455
476
|
// Root visibility is evaluated once at the start of each native layout pass.
|
|
477
|
+
pass = undefined;
|
|
456
478
|
this.timestamps.beginFrame();
|
|
457
479
|
activityDocument.beginFrame();
|
|
458
480
|
chatDocument.beginFrame();
|
|
@@ -468,8 +490,8 @@ export class TranscriptLayout {
|
|
|
468
490
|
visible: viewport => shown(viewport) && this.preferences.zoom === "chat" },
|
|
469
491
|
{ component: transcript, basis: 0, grow: 1, minSize: 1, visible: viewport => !shown(viewport) },
|
|
470
492
|
...(projectedDock ? [{ component: projectedDock, basis: "auto" as const, shrink: 0, minSize: 1,
|
|
471
|
-
visible: () =>
|
|
472
|
-
{ component: dock, basis: "auto", shrink: 0, minSize: 1, visible: () => !
|
|
493
|
+
visible: () => projectSurface }] : []),
|
|
494
|
+
{ component: dock, basis: "auto", shrink: 0, minSize: 1, visible: () => !projectSurface },
|
|
473
495
|
]);
|
|
474
496
|
this.mounted = mounted;
|
|
475
497
|
host.setLayoutRoot(mounted);
|
|
@@ -497,6 +519,8 @@ export class TranscriptLayout {
|
|
|
497
519
|
private canFocusSearch(): boolean {
|
|
498
520
|
const focused = this.host?.getFocusedComponent();
|
|
499
521
|
if (!focused || focused === this.search?.bar.input) return true;
|
|
522
|
+
const editor = this.getEditor();
|
|
523
|
+
if (editor) return focused === editor;
|
|
500
524
|
const dock = this.original?.children[1];
|
|
501
525
|
const pending = dock ? [dock] : [];
|
|
502
526
|
const visited = new Set<Component>();
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { InteractiveMode } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { Component, TUI } from "@earendil-works/pi-tui";
|
|
3
|
+
|
|
4
|
+
type Host = { ui?: unknown; renderer?: unknown; editor?: Component };
|
|
5
|
+
type Boundary = "createExtensionUIContext" | "rebuildChatFromMessages";
|
|
6
|
+
type Prototype = Partial<Record<Boundary, (this: Host, ...args: unknown[]) => unknown>>;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Observe the native editor identity at UI binding or reload's history rebuild.
|
|
10
|
+
* No dialog APIs, factories, components or focus are wrapped. Unknown hosts stay native.
|
|
11
|
+
*/
|
|
12
|
+
export function observeNativeEditor(): { get(tui: TUI): Component | undefined; dispose(): void } {
|
|
13
|
+
const prototype = InteractiveMode.prototype as unknown as Prototype;
|
|
14
|
+
const restorers: Array<() => void> = [];
|
|
15
|
+
let owner: Host | undefined;
|
|
16
|
+
let active = true;
|
|
17
|
+
const restore = (): void => { for (const release of restorers) release(); };
|
|
18
|
+
for (const name of ["createExtensionUIContext", "rebuildChatFromMessages"] as const) {
|
|
19
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, name);
|
|
20
|
+
const original = prototype[name];
|
|
21
|
+
if (typeof original !== "function" || !descriptor?.writable) continue;
|
|
22
|
+
function observe(this: Host, ...args: unknown[]): unknown {
|
|
23
|
+
const result = original!.apply(this, args);
|
|
24
|
+
// A later wrapper can retain this trampoline after cancellation.
|
|
25
|
+
if (active && this.editor && typeof this.editor.render === "function" &&
|
|
26
|
+
typeof this.editor.invalidate === "function" && (this.ui || this.renderer)) {
|
|
27
|
+
owner = this;
|
|
28
|
+
restore();
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
restorers.push(() => {
|
|
33
|
+
if (prototype[name] === observe) Object.defineProperty(prototype, name, descriptor);
|
|
34
|
+
});
|
|
35
|
+
prototype[name] = observe;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
get: tui => active && owner && (owner.ui === tui || owner.renderer === tui) ? owner.editor : undefined,
|
|
39
|
+
dispose: () => { active = false; owner = undefined; restore(); },
|
|
40
|
+
};
|
|
41
|
+
}
|
package/src/native.ts
CHANGED
|
@@ -73,6 +73,7 @@ export class NativeDocument extends Container {
|
|
|
73
73
|
private frameWidth?: number;
|
|
74
74
|
private frameLines?: string[];
|
|
75
75
|
private checked = false;
|
|
76
|
+
private releasedFor?: readonly ContentEntry[];
|
|
76
77
|
private disposed = false;
|
|
77
78
|
|
|
78
79
|
constructor(
|
|
@@ -98,8 +99,12 @@ export class NativeDocument extends Container {
|
|
|
98
99
|
beginFrame(): void {
|
|
99
100
|
this.frameActive = true;
|
|
100
101
|
this.frameWidth = undefined;
|
|
101
|
-
|
|
102
|
-
|
|
102
|
+
this.index.beginFrame();
|
|
103
|
+
// Blocks are only added from the current entries, so an unchanged index has nothing to release.
|
|
104
|
+
const entries = this.index.entries(this.pane);
|
|
105
|
+
if (this.compactBlocks.size && entries !== this.releasedFor) {
|
|
106
|
+
this.releasedFor = entries;
|
|
107
|
+
const present = new Set(entries.map(entry => entry.source));
|
|
103
108
|
for (const [component, block] of this.compactBlocks) if (!present.has(component)) {
|
|
104
109
|
block.dispose();
|
|
105
110
|
this.compactBlocks.delete(component);
|
package/src/timestamps.ts
CHANGED
|
@@ -8,6 +8,10 @@ import { NativeRenderCache } from "./render-cache.js";
|
|
|
8
8
|
type Message = ReturnType<typeof sessionEntryToContextMessages>[number];
|
|
9
9
|
type TimedSource = { message: Message; time: unknown };
|
|
10
10
|
type UserSlot = { kind: string; text?: string; time: unknown };
|
|
11
|
+
interface BranchTimes {
|
|
12
|
+
messageTimes: WeakMap<object, unknown>; users: TimedSource[]; slots: UserSlot[]; bash: TimedSource[];
|
|
13
|
+
starts: Map<string, number>; owners: Map<string, unknown>;
|
|
14
|
+
}
|
|
11
15
|
|
|
12
16
|
// Identical native padding is common across cold blocks. Keep only a few short blank rows.
|
|
13
17
|
const blankRows = new Set<string>();
|
|
@@ -33,10 +37,17 @@ const validTime = (value: unknown): number | undefined => {
|
|
|
33
37
|
export function timestampLabel(value: unknown): string {
|
|
34
38
|
const time = validTime(value);
|
|
35
39
|
if (time === undefined) return "";
|
|
40
|
+
// Every visible block asks for its clock on every frame.
|
|
41
|
+
let label = labels.get(time);
|
|
42
|
+
if (label !== undefined) return label;
|
|
36
43
|
const date = new Date(time);
|
|
37
|
-
|
|
44
|
+
label = [date.getHours(), date.getMinutes(), date.getSeconds()]
|
|
38
45
|
.map(part => String(part).padStart(2, "0")).join(":");
|
|
46
|
+
if (labels.size >= 8192) labels.clear();
|
|
47
|
+
labels.set(time, label);
|
|
48
|
+
return label;
|
|
39
49
|
}
|
|
50
|
+
const labels = new Map<number, string>();
|
|
40
51
|
|
|
41
52
|
const userSlots = ({ message, time }: TimedSource): UserSlot[] => {
|
|
42
53
|
if (message.role !== "user") return [];
|
|
@@ -64,11 +75,46 @@ export class TranscriptTimestamps {
|
|
|
64
75
|
|
|
65
76
|
constructor(private readonly session: ExtensionContext["sessionManager"]) {}
|
|
66
77
|
|
|
78
|
+
private branch?: { leaf: object; sources: TimedSource[]; derived?: BranchTimes };
|
|
79
|
+
|
|
80
|
+
/** Session entries are append-only, so one leaf entry identifies the whole active branch. */
|
|
81
|
+
private leaf(): object | undefined {
|
|
82
|
+
const leaf = typeof this.session.getLeafEntry === "function" ? this.session.getLeafEntry() : undefined;
|
|
83
|
+
return leaf && typeof leaf === "object" ? leaf : undefined;
|
|
84
|
+
}
|
|
67
85
|
private sources(): TimedSource[] {
|
|
68
|
-
|
|
86
|
+
const leaf = this.leaf();
|
|
87
|
+
if (leaf && this.branch?.leaf === leaf) return this.branch.sources;
|
|
88
|
+
const sources = this.session.buildContextEntries().flatMap(entry =>
|
|
69
89
|
sessionEntryToContextMessages(entry).map(message => ({
|
|
70
90
|
message, time: validTime("timestamp" in message ? message.timestamp : undefined) ?? entry.timestamp,
|
|
71
91
|
})));
|
|
92
|
+
this.branch = leaf ? { leaf, sources } : undefined;
|
|
93
|
+
return sources;
|
|
94
|
+
}
|
|
95
|
+
/** Branch-derived lookups are rebuilt only when the active branch changes. */
|
|
96
|
+
private times(): BranchTimes {
|
|
97
|
+
const sources = this.sources();
|
|
98
|
+
if (this.branch?.sources === sources && this.branch.derived) return this.branch.derived;
|
|
99
|
+
const users = sources.filter(source => source.message.role === "user");
|
|
100
|
+
const starts = new Map<string, number>();
|
|
101
|
+
for (const entry of this.session.getBranch()) {
|
|
102
|
+
if (entry.type !== "custom" || entry.customType !== TOOL_START_ENTRY || !entry.data || typeof entry.data !== "object") continue;
|
|
103
|
+
const data = entry.data as { toolCallId?: unknown; time?: unknown };
|
|
104
|
+
const time = validTime(data.time);
|
|
105
|
+
if (typeof data.toolCallId === "string" && time !== undefined) starts.set(data.toolCallId, time);
|
|
106
|
+
}
|
|
107
|
+
const owners = new Map<string, unknown>();
|
|
108
|
+
for (const { message, time } of sources) {
|
|
109
|
+
if (message.role !== "assistant") continue;
|
|
110
|
+
for (const block of message.content) if (block.type === "toolCall") owners.set(block.id, time);
|
|
111
|
+
}
|
|
112
|
+
const derived = {
|
|
113
|
+
messageTimes: new WeakMap(sources.map(source => [source.message, source.time])), users, slots: users.flatMap(userSlots),
|
|
114
|
+
bash: sources.filter(source => source.message.role === "bashExecution"), starts, owners,
|
|
115
|
+
};
|
|
116
|
+
if (this.branch?.sources === sources) this.branch.derived = derived;
|
|
117
|
+
return derived;
|
|
72
118
|
}
|
|
73
119
|
|
|
74
120
|
/** Include the current unpersisted user and streamed tool IDs before UI delivery. */
|
|
@@ -99,8 +145,9 @@ export class TranscriptTimestamps {
|
|
|
99
145
|
this.liveCalls.clear();
|
|
100
146
|
this.orderedLabels = new WeakMap();
|
|
101
147
|
this.messageTimes = new WeakMap();
|
|
102
|
-
this.
|
|
103
|
-
this.
|
|
148
|
+
this.branch = undefined;
|
|
149
|
+
this.starts = new Map();
|
|
150
|
+
this.owners = new Map();
|
|
104
151
|
}
|
|
105
152
|
|
|
106
153
|
/** Share one history correlation across the panels measured in a native frame. */
|
|
@@ -112,11 +159,10 @@ export class TranscriptTimestamps {
|
|
|
112
159
|
prepare(components: Component[]): void {
|
|
113
160
|
if (this.frameActive && this.preparedComponents === components) return;
|
|
114
161
|
this.preparedComponents = components;
|
|
115
|
-
const
|
|
116
|
-
this.messageTimes =
|
|
117
|
-
const users = sources.filter(source => source.message.role === "user");
|
|
162
|
+
const { messageTimes, users, slots: saved, bash, starts, owners } = this.times();
|
|
163
|
+
this.messageTimes = messageTimes;
|
|
118
164
|
if (this.pendingUser?.ended && users.length > this.pendingUser.before) this.pendingUser = undefined;
|
|
119
|
-
const slots =
|
|
165
|
+
const slots = saved.slice();
|
|
120
166
|
const nativeUsers = components.filter(component =>
|
|
121
167
|
component.constructor.name === "UserMessageComponent" || component.constructor.name === "SkillInvocationMessageComponent");
|
|
122
168
|
if (nativeUsers.length !== slots.length && this.pendingUser) slots.push(...userSlots(this.pendingUser.source));
|
|
@@ -130,24 +176,13 @@ export class TranscriptTimestamps {
|
|
|
130
176
|
});
|
|
131
177
|
if (matches) nativeUsers.forEach((component, index) => this.orderedLabels.set(component, timestampLabel(slots[index].time)));
|
|
132
178
|
}
|
|
133
|
-
const bash = sources.filter(source => source.message.role === "bashExecution");
|
|
134
179
|
const nativeBash = components.filter(component => component.constructor.name === "BashExecutionComponent");
|
|
135
180
|
if (nativeBash.length === bash.length && nativeBash.every((component, index) =>
|
|
136
181
|
(component as Component & { command?: unknown }).command === (bash[index].message as { command: string }).command)) {
|
|
137
182
|
nativeBash.forEach((component, index) => this.orderedLabels.set(component, timestampLabel(bash[index].time)));
|
|
138
183
|
}
|
|
139
|
-
this.starts
|
|
140
|
-
|
|
141
|
-
if (entry.type !== "custom" || entry.customType !== TOOL_START_ENTRY || !entry.data || typeof entry.data !== "object") continue;
|
|
142
|
-
const data = entry.data as { toolCallId?: unknown; time?: unknown };
|
|
143
|
-
const time = validTime(data.time);
|
|
144
|
-
if (typeof data.toolCallId === "string" && time !== undefined) this.starts.set(data.toolCallId, time);
|
|
145
|
-
}
|
|
146
|
-
this.owners.clear();
|
|
147
|
-
for (const { message, time } of sources) {
|
|
148
|
-
if (message.role !== "assistant") continue;
|
|
149
|
-
for (const block of message.content) if (block.type === "toolCall") this.owners.set(block.id, time);
|
|
150
|
-
}
|
|
184
|
+
this.starts = starts;
|
|
185
|
+
this.owners = owners;
|
|
151
186
|
}
|
|
152
187
|
|
|
153
188
|
/** Reject changed private metadata before relying on it for a label. */
|
package/src/tool-indent.ts
CHANGED
|
@@ -8,10 +8,22 @@ export class ToolIndent extends Container {
|
|
|
8
8
|
super(); this.addChild(component);
|
|
9
9
|
this.prefix = " ".repeat(gutter) + " │".repeat(depth) + (body ? " " : "");
|
|
10
10
|
}
|
|
11
|
+
// Expanded runs are re-indented on every frame; reuse rows while the native rows are unchanged.
|
|
12
|
+
private cached?: { width: number; prefix: string; source: string[]; lines: string[] };
|
|
11
13
|
override render(width: number): string[] {
|
|
12
14
|
const inset = Math.min(width, this.prefix.length);
|
|
13
15
|
const prefix = this.theme().fg("dim", this.prefix.slice(0, inset));
|
|
14
|
-
|
|
16
|
+
const source = super.render(Math.max(0, width - inset));
|
|
17
|
+
const cached = this.cached;
|
|
18
|
+
if (cached && cached.width === width && cached.prefix === prefix && cached.source.length === source.length &&
|
|
19
|
+
cached.source.every((line, index) => line === source[index])) return cached.lines;
|
|
20
|
+
const lines = source.map(line => truncateToWidth(prefix + line, width, ""));
|
|
21
|
+
this.cached = { width, prefix, source, lines };
|
|
22
|
+
return lines;
|
|
23
|
+
}
|
|
24
|
+
override invalidate(): void {
|
|
25
|
+
this.cached = undefined;
|
|
26
|
+
super.invalidate();
|
|
15
27
|
}
|
|
16
28
|
override handleMouse(event: TuiMouseEvent): ReturnType<Container["handleMouse"]> {
|
|
17
29
|
const inset = Math.min(event.width, this.prefix.length);
|