pi-stereo-view 0.1.17 → 0.1.18
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 +12 -0
- package/README.md +9 -3
- package/package.json +1 -1
- package/src/index.ts +14 -2
- package/src/layout.ts +19 -3
- package/src/native.ts +15 -4
- package/src/preferences.ts +11 -4
- package/src/tool-groups.ts +5 -3
- package/src/tool-streaming.ts +60 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.1.18 - 2026-11-09
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Stream latest tools: with Compact Activity tools on, new tool calls show in full, then collapse into the compact history after a configurable delay.
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- The `[Menu]` button is now `[Settings]`.
|
|
14
|
+
- New installs start side by side with Conversation on the left and Activity on the right, text buttons, Compact Activity tools and Stream latest tools on. Saved settings are kept.
|
|
15
|
+
- Keep the last text button in a panel header one cell away from the right edge.
|
|
16
|
+
|
|
5
17
|
## 0.1.17 - 2026-11-09
|
|
6
18
|
|
|
7
19
|
### Changed
|
package/README.md
CHANGED
|
@@ -74,7 +74,7 @@ pi --tui-mode fullscreen
|
|
|
74
74
|
|
|
75
75
|
## Use it
|
|
76
76
|
|
|
77
|
-
Click the toolbar and the buttons in each panel's header. Buttons use
|
|
77
|
+
Click the toolbar and the buttons in each panel's header. Buttons use text labels by default. To use icons instead, open **Stereo View settings** with `[Settings]` or `/stereo-view settings`, then set **Button style** to `icons`. The choice survives restart.
|
|
78
78
|
|
|
79
79
|
| Icons | Text | Action |
|
|
80
80
|
| --- | --- | --- |
|
|
@@ -82,7 +82,7 @@ Click the toolbar and the buttons in each panel's header. Buttons use icons by d
|
|
|
82
82
|
| `[ ▤ ]` / `[ ▥ ]` | `[Rows]` / `[Columns]` | Switch between rows and columns. |
|
|
83
83
|
| `[ ↕ ]` / `[ ↔ ]` | `[Swap]` | Swap the panels. |
|
|
84
84
|
| `[ ↗ ]` / `[ ↙ ]` | `[Maximize]` / `[Restore]` | Zoom a panel / restore the split. |
|
|
85
|
-
| `[ ≡ ]` | `[
|
|
85
|
+
| `[ ≡ ]` | `[Settings]` | Open display and Conversation height settings. |
|
|
86
86
|
| `[ ⌕ ]` | `[Find]` | Search this panel. |
|
|
87
87
|
| `[ ⊟ ]` / `[ ⊞ ]` | `[Compact tools]` / `[Full tools]` | Compact Activity tools / restore full tools. |
|
|
88
88
|
|
|
@@ -104,7 +104,13 @@ Group and call headers show `▸` when collapsed and `▾` when expanded. Each c
|
|
|
104
104
|
|
|
105
105
|
Search and `/stereo-view copy` still include full saved results and linked output. A search match opens its group and call temporarily; clearing the search restores your previous expansion. You can also click `[ ⊞ ]` or `[Full tools]` in the Activity header to restore full tools. Conversation and combined history keep their normal display.
|
|
106
106
|
|
|
107
|
-
Compact tools work in columns, rows and zoomed Activity. The choice survives restart and defaults to
|
|
107
|
+
Compact tools work in columns, rows and zoomed Activity. The choice survives restart and defaults to on. For keyboard access, run `/stereo-view settings` and change **Compact Activity tools**.
|
|
108
|
+
|
|
109
|
+
### Stream latest tools
|
|
110
|
+
|
|
111
|
+
**Stream latest tools** (on by default, in Settings) lets you watch the current work while keeping history short. With Compact Activity tools on, a new tool call appears as its full card and updates live. When it finishes, it stays fully visible for the **Collapse delay** (1, 2, 3, 5, 10 or 30 seconds; default 5), then collapses in place into a compact row and joins the adjacent identical collapsed calls (`read ×3`).
|
|
112
|
+
|
|
113
|
+
Calls that are still running or waiting to collapse are never grouped. Thinking, answers and other content between calls appear as usual and end a group. Several calls running together collapse separately, each after its own delay. A call you opened yourself stays open. Scroll position is not changed when a call collapses; if you are at the end of Activity, you stay there. A reopened session shows all its calls collapsed. Both options survive restart; streaming defaults to on.
|
|
108
114
|
|
|
109
115
|
## Search history
|
|
110
116
|
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -8,6 +8,8 @@ import { beforeFirstFrame } from "./startup.ts";
|
|
|
8
8
|
import { observeNativeEditor } from "./native-editor.ts";
|
|
9
9
|
import { NestedCalls } from "./nested-calls.ts";
|
|
10
10
|
|
|
11
|
+
const DELAYS = [1, 2, 3, 5, 10, 30];
|
|
12
|
+
|
|
11
13
|
/** Split native fullscreen history without changing message content or the input dock. */
|
|
12
14
|
export default async function transcript(pi: ExtensionAPI): Promise<void> {
|
|
13
15
|
let layout: TranscriptLayout | undefined;
|
|
@@ -68,15 +70,25 @@ export default async function transcript(pi: ExtensionAPI): Promise<void> {
|
|
|
68
70
|
id: "compactTools", label: "Compact Activity tools",
|
|
69
71
|
description: "Group adjacent tools and expand individual calls inline. Full text stays searchable and copyable.",
|
|
70
72
|
currentValue: preferences.compactTools ? "on" : "off", values: ["on", "off"],
|
|
73
|
+
}, {
|
|
74
|
+
id: "streamTools", label: "Stream latest tools",
|
|
75
|
+
description: "In compact Activity, show new tool calls in full and collapse them after the delay.",
|
|
76
|
+
currentValue: preferences.streamTools ? "on" : "off", values: ["on", "off"],
|
|
77
|
+
}, {
|
|
78
|
+
id: "streamDelay", label: "Collapse delay",
|
|
79
|
+
description: "How long a finished streamed tool call stays fully visible before it collapses.",
|
|
80
|
+
currentValue: `${preferences.streamDelay}s`, values: [...new Set([...DELAYS, preferences.streamDelay])].sort((a, b) => a - b).map(seconds => `${seconds}s`),
|
|
71
81
|
}, {
|
|
72
82
|
id: "height", label: "Conversation height",
|
|
73
83
|
description: "Auto grows to half the history area. Drag sets a manual maximum.",
|
|
74
84
|
currentValue: preferences.chatHeight === null ? "auto" : "manual", values: ["auto", "manual"],
|
|
75
|
-
}],
|
|
85
|
+
}], 7, getSettingsListTheme(), (id, value) => {
|
|
76
86
|
if (id === "timestamps") layout?.setTimestamps(value === "on");
|
|
77
87
|
else if (id === "copyButtons") layout?.setCopyButtons(value === "on");
|
|
78
88
|
else if (id === "buttonStyle") layout?.setButtonStyle(value === "text" ? "text" : "icons");
|
|
79
89
|
else if (id === "compactTools") layout?.setCompactTools(value === "on");
|
|
90
|
+
else if (id === "streamTools") layout?.setStreamTools(value === "on");
|
|
91
|
+
else if (id === "streamDelay") layout?.setStreamDelay(Number.parseInt(value, 10));
|
|
80
92
|
else if (id === "height") layout?.setAutomaticHeight(value === "auto");
|
|
81
93
|
tui.requestRender();
|
|
82
94
|
}, () => done());
|
|
@@ -263,7 +275,7 @@ export default async function transcript(pi: ExtensionAPI): Promise<void> {
|
|
|
263
275
|
const choice = await ctx.ui.select("Copy a block from the active panel", blocks.map(block => block.label));
|
|
264
276
|
blocks.find(block => block.label === choice)?.copy();
|
|
265
277
|
} else if (action === "help") {
|
|
266
|
-
ctx.ui.notify("pi-stereo-view: choose icon or text buttons in /stereo-view settings. Buttons: ▣/Combine combines history, ◫/Split separates it, ▤/Rows and ▥/Columns change layout, ↕/↔/Swap exchanges panels, ↗/Maximize and ↙/Restore change panel size, ⌕/Find searches, ⊟/Compact tools and ⊞/Full tools toggle compact tools, ≡/
|
|
278
|
+
ctx.ui.notify("pi-stereo-view: choose icon or text buttons in /stereo-view settings. Buttons: ▣/Combine combines history, ◫/Split separates it, ▤/Rows and ▥/Columns change layout, ↕/↔/Swap exchanges panels, ↗/Maximize and ↙/Restore change panel size, ⌕/Find searches, ⊟/Compact tools and ⊞/Full tools toggle compact tools, ≡/Settings opens settings, ⧉/Copy copies a block. /stereo-view copy chooses a block with the keyboard. Ctrl+F searches and PgUp/PgDn scroll the active panel; Ctrl+Alt+Up/Down switches it. Drag the ═ or ║ divider to resize.", "info");
|
|
267
279
|
} else if (action === "swap") layout.swap();
|
|
268
280
|
else if (action === "width" && /^\d+$/.test(target ?? "")) layout.setWidth(Number(target));
|
|
269
281
|
else if (action === "height" && target === "auto") layout.setHeight(null);
|
package/src/layout.ts
CHANGED
|
@@ -95,6 +95,8 @@ class ButtonStack extends VStack {
|
|
|
95
95
|
return entry;
|
|
96
96
|
});
|
|
97
97
|
if (this.fill && !row.includes(entries[0])) spaced.push({ component: this.fill, basis: 0, grow: 1 });
|
|
98
|
+
// Keep the last label off the panel's right edge, where the scrollbar sits.
|
|
99
|
+
if (this.fill) spaced.push({ component: this.fill, basis: 1, shrink: 0 });
|
|
98
100
|
this.addChild(new HStack(spaced), { basis: 1, shrink: 0 });
|
|
99
101
|
}
|
|
100
102
|
row = []; occupied = 0;
|
|
@@ -102,7 +104,7 @@ class ButtonStack extends VStack {
|
|
|
102
104
|
for (const [index, entry] of entries.entries()) {
|
|
103
105
|
const control = this.controls.find(candidate => candidate.index === index);
|
|
104
106
|
const size = control ? textWidth(index) : this.titleLength ?? 0;
|
|
105
|
-
if (row.length && occupied + 1 + size > width) flush();
|
|
107
|
+
if (row.length && occupied + 1 + size > width - (this.fill ? 1 : 0)) flush();
|
|
106
108
|
occupied += (row.length ? 1 : 0) + size;
|
|
107
109
|
row.push(entry);
|
|
108
110
|
}
|
|
@@ -318,7 +320,10 @@ export class TranscriptLayout {
|
|
|
318
320
|
const index = new NativeContentIndex(document, this.nested);
|
|
319
321
|
const activityDocument = new NativeDocument(document, "activity", this.timestamps, this.theme, timestampGutter, showTimestamps,
|
|
320
322
|
() => this.activate("activity"), false, index, this.copy, showCopyButtons, () => this.preferences.compactTools, this.getTools,
|
|
321
|
-
() => { if (this.activity) this.activity.scrollTo(this.activity.scrollTop, { disableFollow: true }); }, () => this.preferences.buttonStyle
|
|
323
|
+
() => { if (this.activity) this.activity.scrollTo(this.activity.scrollTop, { disableFollow: true }); }, () => this.preferences.buttonStyle, {
|
|
324
|
+
enabled: () => this.preferences.streamTools, delay: () => this.preferences.streamDelay * 1000,
|
|
325
|
+
changed: () => this.host?.requestRender(),
|
|
326
|
+
});
|
|
322
327
|
const chatDocument = new NativeDocument(document, "chat", this.timestamps, this.theme, timestampGutter, showTimestamps,
|
|
323
328
|
() => this.activate("chat"), false, index, this.copy, showCopyButtons, undefined, undefined, undefined, () => this.preferences.buttonStyle);
|
|
324
329
|
this.documents = { activity: activityDocument, chat: chatDocument };
|
|
@@ -425,7 +430,7 @@ export class TranscriptLayout {
|
|
|
425
430
|
() => this.preferences.buttonStyle === "icons" ? (this.preferences.layout === "columns" ? "↔" : "↕") : "Swap", () => this.swap(),
|
|
426
431
|
() => this.preferences.mode === "split" && !this.preferences.zoom && !this.fallback && !this.failed,
|
|
427
432
|
), basis: TOOLBAR_BUTTON_WIDTH + 1, minSize: TOOLBAR_BUTTON_WIDTH, shrink: 1 },
|
|
428
|
-
{ component: this.button(() => this.preferences.buttonStyle === "icons" ? "≡" : "
|
|
433
|
+
{ component: this.button(() => this.preferences.buttonStyle === "icons" ? "≡" : "Settings", this.openSettings), basis: TOOLBAR_BUTTON_WIDTH, shrink: 0 },
|
|
429
434
|
], [
|
|
430
435
|
{ index: 0, icon: 6 },
|
|
431
436
|
{ index: 1, icon: 6 },
|
|
@@ -744,6 +749,17 @@ export class TranscriptLayout {
|
|
|
744
749
|
this.preferences.compactTools = compact;
|
|
745
750
|
this.changed();
|
|
746
751
|
}
|
|
752
|
+
/** Show the latest compact tool calls in full until they have been finished for the delay. */
|
|
753
|
+
setStreamTools(stream: boolean): void {
|
|
754
|
+
this.preferences.streamTools = stream;
|
|
755
|
+
this.changed();
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
/** Seconds a finished streamed call stays in full before collapsing. */
|
|
759
|
+
setStreamDelay(seconds: number): void {
|
|
760
|
+
this.preferences.streamDelay = Math.max(1, Math.min(300, Math.trunc(seconds)));
|
|
761
|
+
this.changed();
|
|
762
|
+
}
|
|
747
763
|
private defaultWidth(width: number): number {
|
|
748
764
|
return Math.max(MIN_CHAT, Math.floor((width - 1) * 0.2));
|
|
749
765
|
}
|
package/src/native.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { CompactMessage, type TranscriptTimestamps } from "./timestamps.ts";
|
|
|
6
6
|
import { NativeContentIndex, type ContentEntry, type Pane } from "./content.ts";
|
|
7
7
|
import { CompactTool } from "./compact-tools.ts";
|
|
8
8
|
import { toolPresentations, type ToolPresentation } from "./tool-presentation.ts";
|
|
9
|
+
import { ToolStreaming } from "./tool-streaming.ts";
|
|
9
10
|
import { toolGroups, groupSummary, type ToolGroup } from "./tool-groups.ts";
|
|
10
11
|
import { ToolIndent } from "./tool-indent.ts";
|
|
11
12
|
import { NestedTree, type NativeTreeBody } from "./nested-tree.ts";
|
|
@@ -92,9 +93,15 @@ export class NativeDocument extends Container {
|
|
|
92
93
|
private readonly getTools: () => readonly ToolInfo[] = () => [],
|
|
93
94
|
private readonly beforeExpand: () => void = () => {},
|
|
94
95
|
private readonly buttonStyle: () => "icons" | "text" = () => "text",
|
|
96
|
+
private readonly streaming?: { enabled(): boolean; delay(): number; changed(): void },
|
|
95
97
|
) {
|
|
96
98
|
super();
|
|
99
|
+
if (streaming) this.streamer = new ToolStreaming(() => streaming.delay(), () => streaming.changed());
|
|
97
100
|
}
|
|
101
|
+
private readonly streamer?: ToolStreaming;
|
|
102
|
+
/** Calls Compact Activity still shows as full native cards. */
|
|
103
|
+
private live(source: Component): boolean { return this.compactActive && this.streamer?.isLive(source) === true; }
|
|
104
|
+
private compactActive = false;
|
|
98
105
|
|
|
99
106
|
/** Start a native frame; only repeated measurements within that frame may reuse routing. */
|
|
100
107
|
beginFrame(): void {
|
|
@@ -204,6 +211,7 @@ export class NativeDocument extends Container {
|
|
|
204
211
|
/** Stop native observers when the layout is detached or falls back. */
|
|
205
212
|
dispose(): void {
|
|
206
213
|
this.disposed = true;
|
|
214
|
+
this.streamer?.dispose();
|
|
207
215
|
for (const block of this.compactBlocks.values()) block.dispose();
|
|
208
216
|
this.compactBlocks.clear();
|
|
209
217
|
this.frameWidth = undefined;
|
|
@@ -277,7 +285,7 @@ export class NativeDocument extends Container {
|
|
|
277
285
|
let stamped = this.stamped.get(routed);
|
|
278
286
|
if (!stamped) {
|
|
279
287
|
stamped = new CompactMessage(routed, () => this.timestamps.label(this.clockOwners.get(component) ?? component),
|
|
280
|
-
this.theme, this.timestampGutter, () => this.showTimestamps() && !(this.pane === "activity" && this.compactTools() && entry.kind === "tool"),
|
|
288
|
+
this.theme, this.timestampGutter, () => this.showTimestamps() && !(this.pane === "activity" && this.compactTools() && entry.kind === "tool" && !this.live(entry.owner)),
|
|
281
289
|
this.copy ? () => this.copyBlock(component) : undefined, this.showCopy, this.buttonStyle);
|
|
282
290
|
this.stamped.set(routed, stamped);
|
|
283
291
|
}
|
|
@@ -308,7 +316,10 @@ export class NativeDocument extends Container {
|
|
|
308
316
|
let toolRun = false;
|
|
309
317
|
const compactTools = this.pane === "activity" && this.compactTools();
|
|
310
318
|
this.present = toolPresentations(compactTools ? this.getTools() : []);
|
|
311
|
-
|
|
319
|
+
this.compactActive = compactTools && this.streaming?.enabled() === true;
|
|
320
|
+
if (this.compactActive) this.streamer!.observe(this.index.entries());
|
|
321
|
+
else this.streamer?.clear();
|
|
322
|
+
const groups = compactTools ? toolGroups(this.index.entries(), this.present, source => this.live(source)) : new Map<Component, ToolGroup>();
|
|
312
323
|
// Carry visible expansion through state-driven splits and merges, without
|
|
313
324
|
// reopening explicitly collapsed runs. Read the old state before adding heads.
|
|
314
325
|
const opening: Component[] = [];
|
|
@@ -336,7 +347,7 @@ export class NativeDocument extends Container {
|
|
|
336
347
|
if (!id || (!this.index.nested.entries(id).length && !this.index.nested.isIncomplete(id))) continue;
|
|
337
348
|
let tree = this.nestedTrees.get(entry.source);
|
|
338
349
|
if (!tree) {
|
|
339
|
-
tree = new NestedTree(id, this.index.nested, this.theme, name => this.present(name), this.compactTools, () => {
|
|
350
|
+
tree = new NestedTree(id, this.index.nested, this.theme, name => this.present(name), () => this.compactTools() && !this.live(entry.source), () => {
|
|
340
351
|
this.beforeExpand(); if (this.searchAnchor) this.clearSearch(); this.frameWidth = undefined;
|
|
341
352
|
}, () => {
|
|
342
353
|
const clock = this.showTimestamps() && this.compactTools() ? this.timestamps.label(entry.source) : "";
|
|
@@ -356,7 +367,7 @@ export class NativeDocument extends Container {
|
|
|
356
367
|
let clock: SearchClock | undefined;
|
|
357
368
|
let nativeBody = true;
|
|
358
369
|
let bodyDepth = 0;
|
|
359
|
-
const compactTool = compactTools && entry.kind === "tool";
|
|
370
|
+
const compactTool = compactTools && entry.kind === "tool" && !this.live(entry.owner);
|
|
360
371
|
if (compactTool) {
|
|
361
372
|
const group = this.groups.get(entry.owner);
|
|
362
373
|
const grouped = group !== undefined && group.calls.length > 1;
|
package/src/preferences.ts
CHANGED
|
@@ -16,11 +16,15 @@ export interface Preferences {
|
|
|
16
16
|
showTimestamps: boolean;
|
|
17
17
|
showCopyButtons: boolean;
|
|
18
18
|
compactTools: boolean;
|
|
19
|
+
/** Show the latest tool calls in full inside compact Activity, then collapse them. */
|
|
20
|
+
streamTools: boolean;
|
|
21
|
+
/** Seconds a finished streamed call stays in full before it collapses. */
|
|
22
|
+
streamDelay: number;
|
|
19
23
|
buttonStyle: "icons" | "text";
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
export const defaults: Preferences = {
|
|
23
|
-
mode: "split", side: "left", chatWidth: null, layout: "columns", chatHeight: null, zoom: null, showTimestamps: true, showCopyButtons: true, compactTools:
|
|
27
|
+
mode: "split", side: "left", chatWidth: null, layout: "columns", chatHeight: null, zoom: null, showTimestamps: true, showCopyButtons: true, compactTools: true, streamTools: true, streamDelay: 5, buttonStyle: "text",
|
|
24
28
|
};
|
|
25
29
|
|
|
26
30
|
/** Read display preferences, retaining the first version's saved arrangement. */
|
|
@@ -40,6 +44,8 @@ export async function loadPreferences(file: string): Promise<Preferences> {
|
|
|
40
44
|
const showTimestamps = record.showTimestamps === undefined ? defaults.showTimestamps : record.showTimestamps;
|
|
41
45
|
const showCopyButtons = record.showCopyButtons === undefined ? defaults.showCopyButtons : record.showCopyButtons;
|
|
42
46
|
const compactTools = record.compactTools === undefined ? defaults.compactTools : record.compactTools;
|
|
47
|
+
const streamTools = record.streamTools === undefined ? defaults.streamTools : record.streamTools;
|
|
48
|
+
const streamDelay = record.streamDelay === undefined ? defaults.streamDelay : record.streamDelay;
|
|
43
49
|
const buttonStyle = record.buttonStyle === undefined ? defaults.buttonStyle : record.buttonStyle;
|
|
44
50
|
if ((record.side !== "left" && record.side !== "right") ||
|
|
45
51
|
(record.chatWidth !== null && (typeof record.chatWidth !== "number" || !Number.isInteger(record.chatWidth) ||
|
|
@@ -47,11 +53,12 @@ export async function loadPreferences(file: string): Promise<Preferences> {
|
|
|
47
53
|
(layout !== "columns" && layout !== "rows") ||
|
|
48
54
|
(chatHeight !== null && (typeof chatHeight !== "number" || !Number.isInteger(chatHeight) || chatHeight < 4 || chatHeight > 240)) ||
|
|
49
55
|
typeof showTimestamps !== "boolean" || typeof showCopyButtons !== "boolean" || typeof compactTools !== "boolean" ||
|
|
56
|
+
typeof streamTools !== "boolean" || typeof streamDelay !== "number" || !Number.isInteger(streamDelay) || streamDelay < 1 || streamDelay > 300 ||
|
|
50
57
|
(buttonStyle !== "icons" && buttonStyle !== "text")) {
|
|
51
58
|
throw new Error("Invalid pi-stereo-view preferences");
|
|
52
59
|
}
|
|
53
60
|
// Legacy files may contain mode/zoom. Every session starts with both panels visible.
|
|
54
|
-
return { mode: "split", side: record.side, chatWidth: record.chatWidth, layout, chatHeight, zoom: null, showTimestamps, showCopyButtons, compactTools, buttonStyle };
|
|
61
|
+
return { mode: "split", side: record.side, chatWidth: record.chatWidth, layout, chatHeight, zoom: null, showTimestamps, showCopyButtons, compactTools, streamTools, streamDelay, buttonStyle };
|
|
55
62
|
}
|
|
56
63
|
|
|
57
64
|
/** Atomically save only the display settings, never session messages. */
|
|
@@ -59,8 +66,8 @@ export async function savePreferences(file: string, preferences: Preferences): P
|
|
|
59
66
|
await mkdir(path.dirname(file), { recursive: true });
|
|
60
67
|
const temporary = file + "." + randomUUID() + ".tmp";
|
|
61
68
|
try {
|
|
62
|
-
const { side, chatWidth, layout, chatHeight, showTimestamps, showCopyButtons, compactTools, buttonStyle } = preferences;
|
|
63
|
-
const saved = { side, chatWidth, layout, chatHeight, showTimestamps, showCopyButtons, compactTools, buttonStyle };
|
|
69
|
+
const { side, chatWidth, layout, chatHeight, showTimestamps, showCopyButtons, compactTools, streamTools, streamDelay, buttonStyle } = preferences;
|
|
70
|
+
const saved = { side, chatWidth, layout, chatHeight, showTimestamps, showCopyButtons, compactTools, streamTools, streamDelay, buttonStyle };
|
|
64
71
|
await writeFile(temporary, JSON.stringify(saved, null, 2) + "\n", { mode: 0o600 });
|
|
65
72
|
await rename(temporary, file);
|
|
66
73
|
} finally {
|
package/src/tool-groups.ts
CHANGED
|
@@ -3,13 +3,15 @@ import type { ContentEntry, ToolSummary } from "./content.ts";
|
|
|
3
3
|
|
|
4
4
|
export interface ToolGroup { calls: ContentEntry[]; key: string; name: string; status: ToolSummary["status"] }
|
|
5
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 }
|
|
6
|
+
/** Adjacency is measured before pane filtering; live calls break runs. Linked output belongs to its call. */
|
|
7
|
+
export function toolGroups(entries: readonly ContentEntry[], present: (name: string) => { name: string; key: string },
|
|
8
|
+
live: (source: Component) => boolean = () => false): Map<Component, ToolGroup> {
|
|
8
9
|
const groups = new Map<Component, ToolGroup>();
|
|
9
10
|
let run: ToolGroup | undefined;
|
|
10
11
|
for (const entry of entries) {
|
|
11
12
|
if (entry.owner !== entry.source) continue;
|
|
12
|
-
|
|
13
|
+
// A call still shown in full neither joins nor continues a group.
|
|
14
|
+
if (!entry.tool || live(entry.source)) { run = undefined; continue; }
|
|
13
15
|
const { name, status } = entry.tool();
|
|
14
16
|
const identity = present(name);
|
|
15
17
|
if (!run || run.key !== identity.key || run.status !== status || status === "error") run = { calls: [], ...identity, status };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Component } from "@earendil-works/pi-tui";
|
|
2
|
+
import type { ContentEntry } from "./content.ts";
|
|
3
|
+
|
|
4
|
+
interface Live { finishedAt?: number; timer?: ReturnType<typeof setTimeout> }
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Tracks which tool calls Compact Activity still shows in full. A call is live from the moment it is first seen
|
|
8
|
+
* running until its delay has passed after it finished. Calls first seen already finished, such as a restored
|
|
9
|
+
* session, were never live.
|
|
10
|
+
*/
|
|
11
|
+
export class ToolStreaming {
|
|
12
|
+
private readonly live = new Map<Component, Live>();
|
|
13
|
+
private readonly released = new WeakSet<Component>();
|
|
14
|
+
|
|
15
|
+
constructor(private readonly delay: () => number, private readonly changed: () => void, private readonly now: () => number = Date.now) {}
|
|
16
|
+
|
|
17
|
+
/** Advance every call's lifecycle from the current entries; call once per frame. */
|
|
18
|
+
observe(entries: readonly ContentEntry[]): void {
|
|
19
|
+
const present = new Set<Component>();
|
|
20
|
+
for (const entry of entries) {
|
|
21
|
+
if (!entry.tool || entry.owner !== entry.source) continue;
|
|
22
|
+
const source = entry.source;
|
|
23
|
+
present.add(source);
|
|
24
|
+
if (this.released.has(source)) continue;
|
|
25
|
+
const running = entry.tool().status === "running";
|
|
26
|
+
let state = this.live.get(source);
|
|
27
|
+
if (!state) {
|
|
28
|
+
// Anything that is not running on first sight is history.
|
|
29
|
+
if (!running) { this.released.add(source); continue; }
|
|
30
|
+
state = {};
|
|
31
|
+
this.live.set(source, state);
|
|
32
|
+
}
|
|
33
|
+
if (running) {
|
|
34
|
+
if (state.timer) clearTimeout(state.timer);
|
|
35
|
+
state.finishedAt = undefined; state.timer = undefined;
|
|
36
|
+
} else if (state.finishedAt === undefined) {
|
|
37
|
+
state.finishedAt = this.now();
|
|
38
|
+
state.timer = setTimeout(this.changed, this.delay() + 20);
|
|
39
|
+
} else if (this.now() - state.finishedAt >= this.delay()) this.release(source);
|
|
40
|
+
}
|
|
41
|
+
for (const source of [...this.live.keys()]) if (!present.has(source)) this.release(source);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
isLive(source: Component): boolean { return this.live.has(source); }
|
|
45
|
+
|
|
46
|
+
/** Collapse one call now, for example because the user closed it. */
|
|
47
|
+
release(source: Component): void {
|
|
48
|
+
const state = this.live.get(source);
|
|
49
|
+
if (state?.timer) clearTimeout(state.timer);
|
|
50
|
+
this.live.delete(source);
|
|
51
|
+
this.released.add(source);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Stop streaming: everything collapses. */
|
|
55
|
+
clear(): void {
|
|
56
|
+
for (const source of [...this.live.keys()]) this.release(source);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
dispose(): void { this.clear(); }
|
|
60
|
+
}
|