pi-subagent-manager 1.10.0 → 1.11.0
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/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +836 -0
- package/dist/index.js.map +1 -0
- package/dist/orch/checklist-integration.d.ts +48 -0
- package/dist/orch/checklist-integration.d.ts.map +1 -0
- package/dist/orch/checklist-integration.js +204 -0
- package/dist/orch/checklist-integration.js.map +1 -0
- package/dist/orch/context-entries.d.ts +8 -0
- package/dist/orch/context-entries.d.ts.map +1 -0
- package/dist/orch/context-entries.js +8 -0
- package/dist/orch/context-entries.js.map +1 -0
- package/dist/orch/cost-ledger.d.ts +16 -0
- package/dist/orch/cost-ledger.d.ts.map +1 -0
- package/dist/orch/cost-ledger.js +43 -0
- package/dist/orch/cost-ledger.js.map +1 -0
- package/dist/orch/diagnostics.d.ts +13 -0
- package/dist/orch/diagnostics.d.ts.map +1 -0
- package/dist/orch/diagnostics.js +95 -0
- package/dist/orch/diagnostics.js.map +1 -0
- package/dist/orch/extensions.d.ts +15 -0
- package/dist/orch/extensions.d.ts.map +1 -0
- package/dist/orch/extensions.js +80 -0
- package/dist/orch/extensions.js.map +1 -0
- package/dist/orch/housekeeping-usage.d.ts +14 -0
- package/dist/orch/housekeeping-usage.d.ts.map +1 -0
- package/dist/orch/housekeeping-usage.js +27 -0
- package/dist/orch/housekeeping-usage.js.map +1 -0
- package/dist/orch/housekeeping.d.ts +89 -0
- package/dist/orch/housekeeping.d.ts.map +1 -0
- package/dist/orch/housekeeping.js +281 -0
- package/dist/orch/housekeeping.js.map +1 -0
- package/dist/orch/inherited-tools.d.ts +18 -0
- package/dist/orch/inherited-tools.d.ts.map +1 -0
- package/dist/orch/inherited-tools.js +71 -0
- package/dist/orch/inherited-tools.js.map +1 -0
- package/dist/orch/mailbox.d.ts +59 -0
- package/dist/orch/mailbox.d.ts.map +1 -0
- package/dist/orch/mailbox.js +196 -0
- package/dist/orch/mailbox.js.map +1 -0
- package/dist/orch/manager.d.ts +82 -0
- package/dist/orch/manager.d.ts.map +1 -0
- package/dist/orch/manager.js +1010 -0
- package/dist/orch/manager.js.map +1 -0
- package/dist/orch/paths.d.ts +7 -0
- package/dist/orch/paths.d.ts.map +1 -0
- package/dist/orch/paths.js +73 -0
- package/dist/orch/paths.js.map +1 -0
- package/dist/orch/prompt.d.ts +7 -0
- package/dist/orch/prompt.d.ts.map +1 -0
- package/dist/orch/prompt.js +34 -0
- package/dist/orch/prompt.js.map +1 -0
- package/dist/orch/registry.d.ts +49 -0
- package/dist/orch/registry.d.ts.map +1 -0
- package/dist/orch/registry.js +134 -0
- package/dist/orch/registry.js.map +1 -0
- package/dist/orch/runtime.d.ts +11 -0
- package/dist/orch/runtime.d.ts.map +1 -0
- package/dist/orch/runtime.js +882 -0
- package/dist/orch/runtime.js.map +1 -0
- package/dist/orch/tools.d.ts +6 -0
- package/dist/orch/tools.d.ts.map +1 -0
- package/dist/orch/tools.js +114 -0
- package/dist/orch/tools.js.map +1 -0
- package/dist/orch/transcript.d.ts +28 -0
- package/dist/orch/transcript.d.ts.map +1 -0
- package/dist/orch/transcript.js +176 -0
- package/dist/orch/transcript.js.map +1 -0
- package/dist/prefs/agent-import.d.ts +37 -0
- package/dist/prefs/agent-import.d.ts.map +1 -0
- package/dist/prefs/agent-import.js +196 -0
- package/dist/prefs/agent-import.js.map +1 -0
- package/dist/prefs/config.d.ts +108 -0
- package/dist/prefs/config.d.ts.map +1 -0
- package/dist/prefs/config.js +926 -0
- package/dist/prefs/config.js.map +1 -0
- package/dist/prefs/import-discovery.d.ts +28 -0
- package/dist/prefs/import-discovery.d.ts.map +1 -0
- package/dist/prefs/import-discovery.js +562 -0
- package/dist/prefs/import-discovery.js.map +1 -0
- package/dist/prefs/import-instructions.d.ts +3 -0
- package/dist/prefs/import-instructions.d.ts.map +1 -0
- package/{src/prefs/import-instructions.ts → dist/prefs/import-instructions.js} +1 -0
- package/dist/prefs/import-instructions.js.map +1 -0
- package/dist/prefs/models.d.ts +24 -0
- package/dist/prefs/models.d.ts.map +1 -0
- package/dist/prefs/models.js +57 -0
- package/dist/prefs/models.js.map +1 -0
- package/dist/prefs/settings.d.ts +89 -0
- package/dist/prefs/settings.d.ts.map +1 -0
- package/dist/prefs/settings.js +505 -0
- package/dist/prefs/settings.js.map +1 -0
- package/dist/types.d.ts +293 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/ui/agent-loader.d.ts +21 -0
- package/dist/ui/agent-loader.d.ts.map +1 -0
- package/dist/ui/agent-loader.js +73 -0
- package/dist/ui/agent-loader.js.map +1 -0
- package/dist/ui/agent-navigation-editor.d.ts +46 -0
- package/dist/ui/agent-navigation-editor.d.ts.map +1 -0
- package/dist/ui/agent-navigation-editor.js +189 -0
- package/dist/ui/agent-navigation-editor.js.map +1 -0
- package/dist/ui/cost-footer.d.ts +37 -0
- package/dist/ui/cost-footer.d.ts.map +1 -0
- package/dist/ui/cost-footer.js +215 -0
- package/dist/ui/cost-footer.js.map +1 -0
- package/dist/ui/dialog.d.ts +135 -0
- package/dist/ui/dialog.d.ts.map +1 -0
- package/dist/ui/dialog.js +533 -0
- package/dist/ui/dialog.js.map +1 -0
- package/dist/ui/import-picker.d.ts +38 -0
- package/dist/ui/import-picker.d.ts.map +1 -0
- package/dist/ui/import-picker.js +211 -0
- package/dist/ui/import-picker.js.map +1 -0
- package/dist/ui/live-agent-view.d.ts +82 -0
- package/dist/ui/live-agent-view.d.ts.map +1 -0
- package/dist/ui/live-agent-view.js +546 -0
- package/dist/ui/live-agent-view.js.map +1 -0
- package/dist/ui/model-picker.d.ts +109 -0
- package/dist/ui/model-picker.d.ts.map +1 -0
- package/dist/ui/model-picker.js +549 -0
- package/dist/ui/model-picker.js.map +1 -0
- package/dist/ui/settings-ui.d.ts +17 -0
- package/dist/ui/settings-ui.d.ts.map +1 -0
- package/dist/ui/settings-ui.js +679 -0
- package/dist/ui/settings-ui.js.map +1 -0
- package/dist/ui/status-ui.d.ts +67 -0
- package/dist/ui/status-ui.d.ts.map +1 -0
- package/dist/ui/status-ui.js +487 -0
- package/dist/ui/status-ui.js.map +1 -0
- package/dist/ui/thread-tree.d.ts +22 -0
- package/dist/ui/thread-tree.d.ts.map +1 -0
- package/dist/ui/thread-tree.js +153 -0
- package/dist/ui/thread-tree.js.map +1 -0
- package/dist/ui/tool-picker.d.ts +46 -0
- package/dist/ui/tool-picker.d.ts.map +1 -0
- package/dist/ui/tool-picker.js +334 -0
- package/dist/ui/tool-picker.js.map +1 -0
- package/dist/ui/transcript-tool.d.ts +2 -0
- package/dist/ui/transcript-tool.d.ts.map +1 -0
- package/dist/ui/transcript-tool.js +100 -0
- package/dist/ui/transcript-tool.js.map +1 -0
- package/dist/ui/ui.d.ts +41 -0
- package/dist/ui/ui.d.ts.map +1 -0
- package/dist/ui/ui.js +1047 -0
- package/dist/ui/ui.js.map +1 -0
- package/docs/development.md +2 -1
- package/package.json +16 -4
- package/src/index.ts +0 -920
- package/src/orch/checklist-integration.ts +0 -230
- package/src/orch/context-entries.ts +0 -15
- package/src/orch/cost-ledger.ts +0 -56
- package/src/orch/diagnostics.ts +0 -95
- package/src/orch/extensions.ts +0 -83
- package/src/orch/housekeeping-usage.ts +0 -47
- package/src/orch/housekeeping.ts +0 -348
- package/src/orch/inherited-tools.ts +0 -84
- package/src/orch/mailbox.ts +0 -261
- package/src/orch/manager.ts +0 -1084
- package/src/orch/paths.ts +0 -73
- package/src/orch/prompt.ts +0 -39
- package/src/orch/registry.ts +0 -168
- package/src/orch/runtime.ts +0 -1041
- package/src/orch/tools.ts +0 -190
- package/src/orch/transcript.ts +0 -186
- package/src/prefs/agent-import.ts +0 -245
- package/src/prefs/config.ts +0 -1017
- package/src/prefs/import-discovery.ts +0 -643
- package/src/prefs/models.ts +0 -74
- package/src/prefs/settings.ts +0 -614
- package/src/types.ts +0 -271
- package/src/ui/agent-loader.ts +0 -98
- package/src/ui/agent-navigation-editor.ts +0 -233
- package/src/ui/cost-footer.ts +0 -230
- package/src/ui/dialog.ts +0 -678
- package/src/ui/import-picker.ts +0 -231
- package/src/ui/live-agent-view.ts +0 -600
- package/src/ui/model-picker.ts +0 -701
- package/src/ui/settings-ui.ts +0 -830
- package/src/ui/status-ui.ts +0 -628
- package/src/ui/thread-tree.ts +0 -173
- package/src/ui/tool-picker.ts +0 -398
- package/src/ui/transcript-tool.ts +0 -142
- package/src/ui/ui.ts +0 -1407
|
@@ -1,600 +0,0 @@
|
|
|
1
|
-
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
|
2
|
-
import { getMarkdownTheme, type Theme } from "@earendil-works/pi-coding-agent";
|
|
3
|
-
import {
|
|
4
|
-
Input,
|
|
5
|
-
Key,
|
|
6
|
-
Markdown,
|
|
7
|
-
matchesKey,
|
|
8
|
-
ScrollView,
|
|
9
|
-
stripTerminalSequences,
|
|
10
|
-
truncateToWidth,
|
|
11
|
-
type TuiMouseEvent,
|
|
12
|
-
type TuiMouseEventResult,
|
|
13
|
-
visibleWidth,
|
|
14
|
-
wrapTextWithAnsi,
|
|
15
|
-
} from "@earendil-works/pi-tui";
|
|
16
|
-
import type { ThreadService, TranscriptSnapshot, TranscriptToolState } from "../types.ts";
|
|
17
|
-
import { dialogText, type DialogHost } from "./dialog.ts";
|
|
18
|
-
import { AGENT_PROGRESS_INTERVAL, agentProgressIcon, agentTypeLabel } from "./ui.ts";
|
|
19
|
-
import type { LoaderStyle } from "../prefs/settings.ts";
|
|
20
|
-
import { renderTranscriptTool } from "./transcript-tool.ts";
|
|
21
|
-
|
|
22
|
-
/** Transcript detail level cycled by Ctrl+O: full → preview → compact. */
|
|
23
|
-
export type TranscriptDetail = "full" | "preview" | "compact";
|
|
24
|
-
const DETAIL_CYCLE: TranscriptDetail[] = ["full", "preview", "compact"];
|
|
25
|
-
|
|
26
|
-
export interface AgentViewportState {
|
|
27
|
-
scrollTop: number;
|
|
28
|
-
follow: boolean;
|
|
29
|
-
showInherited?: boolean;
|
|
30
|
-
detail?: TranscriptDetail;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** Fully cover main, including at very small sizes; only trusted renderers emit terminal sequences. */
|
|
34
|
-
export function fillViewport(lines: string[], width: number, height: number): string[] {
|
|
35
|
-
width = Math.max(0, Math.floor(width));
|
|
36
|
-
height = Math.max(1, Math.floor(height));
|
|
37
|
-
const result = lines.slice(0, height).map((line) => {
|
|
38
|
-
const clipped = truncateToWidth(line, width, "", true);
|
|
39
|
-
return clipped + " ".repeat(Math.max(0, width - visibleWidth(clipped)));
|
|
40
|
-
});
|
|
41
|
-
while (result.length < height) result.push(" ".repeat(width));
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function text(value: string): string {
|
|
46
|
-
return stripTerminalSequences(value)
|
|
47
|
-
.replace(/\r\n?/g, "\n")
|
|
48
|
-
.replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g, "");
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function object(value: unknown): Record<string, unknown> | undefined {
|
|
52
|
-
return value && typeof value === "object" ? (value as Record<string, unknown>) : undefined;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function json(value: unknown): string {
|
|
56
|
-
try {
|
|
57
|
-
return JSON.stringify(value, null, 2) ?? "";
|
|
58
|
-
} catch {
|
|
59
|
-
return "[unrenderable data]";
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** Live transcript and manual steering. Reuse trusted pi built-ins; strip untrusted controls. */
|
|
64
|
-
export class LiveAgentView {
|
|
65
|
-
private snapshot: TranscriptSnapshot | undefined;
|
|
66
|
-
private error: string | undefined;
|
|
67
|
-
private disposed = false;
|
|
68
|
-
private attachment = 0;
|
|
69
|
-
private unsubscribe: (() => void) | undefined;
|
|
70
|
-
private renderTimer: ReturnType<typeof setTimeout> | undefined;
|
|
71
|
-
private progressTimer: ReturnType<typeof setInterval> | undefined;
|
|
72
|
-
private cache = new WeakMap<
|
|
73
|
-
object,
|
|
74
|
-
{ width: number; detail: TranscriptDetail; lines: string[] }
|
|
75
|
-
>();
|
|
76
|
-
private scroll: ScrollView;
|
|
77
|
-
private content: string[] = [];
|
|
78
|
-
private restoreViewport = true;
|
|
79
|
-
private input = new Input({ prompt: "Steer > " });
|
|
80
|
-
private editing = true;
|
|
81
|
-
private focusedState = true;
|
|
82
|
-
private pasting = false;
|
|
83
|
-
private pasteTail = "";
|
|
84
|
-
private sending = false;
|
|
85
|
-
private steerStatus: string | undefined;
|
|
86
|
-
private steerFailed = false;
|
|
87
|
-
|
|
88
|
-
private results = new Map<string, AgentMessage>();
|
|
89
|
-
private tools = new Map<string, TranscriptToolState>();
|
|
90
|
-
private renderedTools = new Set<string>();
|
|
91
|
-
private toolCache = new Map<
|
|
92
|
-
string,
|
|
93
|
-
{
|
|
94
|
-
args: unknown;
|
|
95
|
-
result: unknown;
|
|
96
|
-
running: boolean;
|
|
97
|
-
isError: boolean;
|
|
98
|
-
name: string;
|
|
99
|
-
width: number;
|
|
100
|
-
detail: TranscriptDetail;
|
|
101
|
-
lines: string[];
|
|
102
|
-
}
|
|
103
|
-
>();
|
|
104
|
-
constructor(
|
|
105
|
-
private host: DialogHost,
|
|
106
|
-
private theme: Theme,
|
|
107
|
-
private service: ThreadService,
|
|
108
|
-
readonly path: string,
|
|
109
|
-
private viewport: AgentViewportState,
|
|
110
|
-
private done: (result: "back" | "main") => void,
|
|
111
|
-
private nerdFontIcons = false,
|
|
112
|
-
private loaderStyle: LoaderStyle = "circle",
|
|
113
|
-
) {
|
|
114
|
-
this.scroll = new ScrollView(
|
|
115
|
-
{ render: () => this.content, invalidate() {} },
|
|
116
|
-
{ follow: "end", overscroll: "contain", scrollbar: "hidden" },
|
|
117
|
-
);
|
|
118
|
-
this.input.focused = true;
|
|
119
|
-
this.input.onSubmit = (value) => void this.steer(value);
|
|
120
|
-
void this.attach();
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
get focused(): boolean {
|
|
124
|
-
return this.focusedState;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
set focused(value: boolean) {
|
|
128
|
-
this.focusedState = value;
|
|
129
|
-
this.input.focused = value && this.editing;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
private async steer(value: string): Promise<void> {
|
|
133
|
-
const message = dialogText(value);
|
|
134
|
-
if (this.disposed || this.sending || !message.trim()) return;
|
|
135
|
-
this.sending = true;
|
|
136
|
-
this.steerFailed = false;
|
|
137
|
-
this.steerStatus = "Sending steering…";
|
|
138
|
-
this.host.requestRender();
|
|
139
|
-
try {
|
|
140
|
-
// Same root-scoped service as the Actions menu: queues a running turn or resumes a settled one.
|
|
141
|
-
await this.service.steer(this.path, message);
|
|
142
|
-
if (this.disposed) return;
|
|
143
|
-
if (this.input.getValue() === message) this.input.setValue("");
|
|
144
|
-
this.steerStatus = "Steering sent";
|
|
145
|
-
} catch (error) {
|
|
146
|
-
if (this.disposed) return;
|
|
147
|
-
this.steerFailed = true;
|
|
148
|
-
this.steerStatus = `Steering failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
149
|
-
} finally {
|
|
150
|
-
this.sending = false;
|
|
151
|
-
if (!this.disposed) this.host.requestRender();
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
private editInput(data: string): void {
|
|
156
|
-
// Keep paste chunks (including embedded Esc, Tab and Enter) out of navigation shortcuts.
|
|
157
|
-
const pasteData = this.pasteTail + data;
|
|
158
|
-
if (pasteData.includes("\x1b[200~")) this.pasting = true;
|
|
159
|
-
if (pasteData.includes("\x1b[201~")) this.pasting = false;
|
|
160
|
-
this.pasteTail = this.pasting ? pasteData.slice(-5) : "";
|
|
161
|
-
const before = this.input.getValue();
|
|
162
|
-
this.input.handleInput(data);
|
|
163
|
-
const safe = dialogText(this.input.getValue());
|
|
164
|
-
if (safe !== this.input.getValue()) this.input.setValue(safe);
|
|
165
|
-
if (safe !== before && !this.sending) this.steerStatus = undefined;
|
|
166
|
-
this.host.requestRender();
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
private async attach(): Promise<void> {
|
|
170
|
-
const attachment = ++this.attachment;
|
|
171
|
-
this.unsubscribe?.();
|
|
172
|
-
this.unsubscribe = undefined;
|
|
173
|
-
this.error = undefined;
|
|
174
|
-
this.scheduleRender();
|
|
175
|
-
try {
|
|
176
|
-
if (!this.service.observeTranscript)
|
|
177
|
-
throw new Error("Live observation is unavailable for this service.");
|
|
178
|
-
let latest: TranscriptSnapshot | undefined;
|
|
179
|
-
const observation = await this.service.observeTranscript(this.path, (snapshot) => {
|
|
180
|
-
latest = snapshot;
|
|
181
|
-
if (this.disposed || attachment !== this.attachment) return;
|
|
182
|
-
this.accept(snapshot);
|
|
183
|
-
});
|
|
184
|
-
if (this.disposed || attachment !== this.attachment) {
|
|
185
|
-
observation.unsubscribe();
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
this.unsubscribe = observation.unsubscribe;
|
|
189
|
-
this.accept(latest ?? observation.snapshot);
|
|
190
|
-
} catch (error) {
|
|
191
|
-
if (this.disposed || attachment !== this.attachment) return;
|
|
192
|
-
this.error = error instanceof Error ? error.message : String(error);
|
|
193
|
-
this.syncProgress();
|
|
194
|
-
this.scheduleRender();
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
private accept(snapshot: TranscriptSnapshot): void {
|
|
199
|
-
if (
|
|
200
|
-
this.snapshot &&
|
|
201
|
-
(snapshot.generation < this.snapshot.generation ||
|
|
202
|
-
(snapshot.generation === this.snapshot.generation &&
|
|
203
|
-
snapshot.revision < this.snapshot.revision))
|
|
204
|
-
)
|
|
205
|
-
return;
|
|
206
|
-
if (snapshot.generation !== this.snapshot?.generation) this.toolCache.clear();
|
|
207
|
-
this.snapshot = snapshot;
|
|
208
|
-
this.error = snapshot.error;
|
|
209
|
-
this.syncProgress();
|
|
210
|
-
this.scheduleRender();
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
private syncProgress(): void {
|
|
214
|
-
const state = this.snapshot?.thread?.state;
|
|
215
|
-
const active = !this.disposed && !this.error && (state === "starting" || state === "running");
|
|
216
|
-
if (!active) {
|
|
217
|
-
if (this.progressTimer !== undefined) clearInterval(this.progressTimer);
|
|
218
|
-
this.progressTimer = undefined;
|
|
219
|
-
} else if (this.progressTimer === undefined) {
|
|
220
|
-
this.progressTimer = setInterval(() => this.scheduleRender(), AGENT_PROGRESS_INTERVAL);
|
|
221
|
-
this.progressTimer.unref?.();
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
private scheduleRender(): void {
|
|
226
|
-
if (this.disposed || this.renderTimer) return;
|
|
227
|
-
this.renderTimer = setTimeout(() => {
|
|
228
|
-
this.renderTimer = undefined;
|
|
229
|
-
if (!this.disposed) this.host.requestRender();
|
|
230
|
-
}, 16);
|
|
231
|
-
this.renderTimer.unref?.();
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
invalidate(): void {
|
|
235
|
-
this.cache = new WeakMap();
|
|
236
|
-
this.toolCache.clear();
|
|
237
|
-
this.input.invalidate();
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
dispose(): void {
|
|
241
|
-
if (this.disposed) return;
|
|
242
|
-
this.disposed = true;
|
|
243
|
-
++this.attachment;
|
|
244
|
-
this.unsubscribe?.();
|
|
245
|
-
this.unsubscribe = undefined;
|
|
246
|
-
if (this.renderTimer) clearTimeout(this.renderTimer);
|
|
247
|
-
this.renderTimer = undefined;
|
|
248
|
-
this.syncProgress();
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
handleInput(data: string): void {
|
|
252
|
-
if (this.disposed) return;
|
|
253
|
-
if (this.pasting || (this.editing && data.includes("\x1b[200~"))) {
|
|
254
|
-
this.editInput(data);
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
if (matchesKey(data, Key.escape)) return this.done("back");
|
|
258
|
-
if (matchesKey(data, Key.ctrl("q")) || matchesKey(data, Key.ctrl("c")))
|
|
259
|
-
return this.done("main");
|
|
260
|
-
if (matchesKey(data, Key.ctrl("o"))) {
|
|
261
|
-
this.viewport.detail =
|
|
262
|
-
DETAIL_CYCLE[(DETAIL_CYCLE.indexOf(this.detail) + 1) % DETAIL_CYCLE.length];
|
|
263
|
-
this.invalidate();
|
|
264
|
-
this.host.requestRender();
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
if (matchesKey(data, Key.tab)) {
|
|
268
|
-
this.editing = !this.editing;
|
|
269
|
-
this.input.focused = this.focused && this.editing;
|
|
270
|
-
this.host.requestRender();
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
if (this.error && (matchesKey(data, Key.ctrl("r")) || (!this.editing && data === "r"))) {
|
|
274
|
-
void this.attach();
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
// Transcript scrolling remains available while composing; Home/End edit the input.
|
|
278
|
-
if (matchesKey(data, Key.up)) this.scroll.scrollBy(-1);
|
|
279
|
-
else if (matchesKey(data, Key.down)) this.scroll.scrollBy(1);
|
|
280
|
-
else if (matchesKey(data, Key.pageUp))
|
|
281
|
-
this.scroll.scrollBy(-Math.max(1, this.scroll.viewportHeight));
|
|
282
|
-
else if (matchesKey(data, Key.pageDown))
|
|
283
|
-
this.scroll.scrollBy(Math.max(1, this.scroll.viewportHeight));
|
|
284
|
-
else if (this.editing) {
|
|
285
|
-
this.editInput(data);
|
|
286
|
-
return;
|
|
287
|
-
} else if (data === "c") {
|
|
288
|
-
this.viewport.showInherited = !this.viewport.showInherited;
|
|
289
|
-
this.invalidate();
|
|
290
|
-
} else if (matchesKey(data, Key.home)) this.scroll.scrollTo(0, { disableFollow: true });
|
|
291
|
-
else if (matchesKey(data, Key.end) || data === "l") this.scroll.scrollToEnd();
|
|
292
|
-
else return;
|
|
293
|
-
this.saveViewport();
|
|
294
|
-
this.host.requestRender();
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/** Fullscreen wheel events scroll the transcript like Up/Down, even while composing. */
|
|
298
|
-
handleMouse(event: TuiMouseEvent): TuiMouseEventResult | undefined {
|
|
299
|
-
if (this.disposed || event.type !== "wheel") return undefined;
|
|
300
|
-
const lines = Math.trunc(event.wheelDelta ?? 0);
|
|
301
|
-
if (!Number.isFinite(lines) || lines === 0) return undefined;
|
|
302
|
-
this.scroll.scrollBy(lines);
|
|
303
|
-
this.saveViewport();
|
|
304
|
-
return { handled: true, render: true };
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
private saveViewport(): void {
|
|
308
|
-
this.viewport.scrollTop = this.scroll.scrollTop;
|
|
309
|
-
this.viewport.follow = this.scroll.isFollowingEnd;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
private get detail(): TranscriptDetail {
|
|
313
|
-
return this.viewport.detail ?? "preview";
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/** One column of horizontal padding on each side of the transcript. */
|
|
317
|
-
private pad(lines: string[]): string[] {
|
|
318
|
-
return lines.map((line) => ` ${line}`);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
private wrap(value: string, width: number): string[] {
|
|
322
|
-
return text(value)
|
|
323
|
-
.split("\n")
|
|
324
|
-
.flatMap((line) => wrapTextWithAnsi(line, Math.max(1, width)));
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/** Use the same themed Markdown (including code highlighting) as pi's main transcript. */
|
|
328
|
-
private markdown(value: string, width: number, thinking = false): string[] {
|
|
329
|
-
return new Markdown(
|
|
330
|
-
text(value),
|
|
331
|
-
0,
|
|
332
|
-
0,
|
|
333
|
-
getMarkdownTheme(),
|
|
334
|
-
thinking
|
|
335
|
-
? { color: (value) => this.theme.fg("thinkingText", value), italic: true }
|
|
336
|
-
: undefined,
|
|
337
|
-
).render(Math.max(1, width));
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
/** Collapsed content is bounded by rendered rows, not just source newlines. */
|
|
341
|
-
private preview(content: unknown, width: number, markdown = false): string[] {
|
|
342
|
-
const values = Array.isArray(content) ? content : [content];
|
|
343
|
-
const lines: string[] = [];
|
|
344
|
-
const more = this.theme.fg("dim", markdown ? "... (Ctrl+O to expand)" : "...");
|
|
345
|
-
for (const value of values) {
|
|
346
|
-
const block = object(value);
|
|
347
|
-
const valueText =
|
|
348
|
-
typeof value === "string"
|
|
349
|
-
? value
|
|
350
|
-
: block?.type === "text"
|
|
351
|
-
? String(block.text ?? "")
|
|
352
|
-
: block?.type === "image"
|
|
353
|
-
? "[Image — text-only observer]"
|
|
354
|
-
: json(value);
|
|
355
|
-
// Bound source work before rendering a collapsed preview.
|
|
356
|
-
const safe = text(valueText);
|
|
357
|
-
const bounded = safe.slice(0, 32768);
|
|
358
|
-
const rendered = markdown ? this.markdown(bounded, width) : bounded.split("\n");
|
|
359
|
-
for (const line of rendered) {
|
|
360
|
-
lines.push(...(markdown ? [line] : wrapTextWithAnsi(line, Math.max(1, width))));
|
|
361
|
-
if (lines.length > 3) return [...lines.slice(0, 3), more];
|
|
362
|
-
}
|
|
363
|
-
if (safe.length > bounded.length) return [...lines.slice(0, 3), more];
|
|
364
|
-
}
|
|
365
|
-
return lines;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
/** Renders padded rows: `width` is the full transcript width. Tool calls get a themed band. */
|
|
369
|
-
private blocks(content: unknown, width: number): string[] {
|
|
370
|
-
const inner = Math.max(1, width - 2);
|
|
371
|
-
if (!Array.isArray(content)) return this.pad(this.blockLines(content, inner));
|
|
372
|
-
return content.flatMap((value) => {
|
|
373
|
-
const block = object(value);
|
|
374
|
-
if (block?.type === "toolCall")
|
|
375
|
-
return this.tool(String(block.id), String(block.name), block.arguments, width);
|
|
376
|
-
return this.pad(this.blockLines(value, inner));
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
private blockLines(value: unknown, width: number): string[] {
|
|
381
|
-
if (typeof value === "string") return this.markdown(value, width);
|
|
382
|
-
const block = object(value);
|
|
383
|
-
if (!block) return this.wrap(json(value), width);
|
|
384
|
-
if (block.type === "text") return this.markdown(String(block.text ?? ""), width);
|
|
385
|
-
if (block.type === "image") return ["[Image — text-only observer]"];
|
|
386
|
-
if (block.type === "thinking") {
|
|
387
|
-
if (this.detail === "compact")
|
|
388
|
-
return [this.theme.fg("dim", "[Thinking hidden · Ctrl+O cycles view]")];
|
|
389
|
-
// Thinking is model-authored Markdown; preview truncates the rendered lines, not the source.
|
|
390
|
-
const rendered = this.markdown(String(block.thinking ?? "[redacted thinking]"), width, true);
|
|
391
|
-
if (this.detail === "full" || rendered.length <= 3) return rendered;
|
|
392
|
-
return [...rendered.slice(0, 3), this.theme.fg("dim", "...")];
|
|
393
|
-
}
|
|
394
|
-
return this.preview(json(block), width);
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
/** Extension messages follow the tool detail cycle without running extension renderers. */
|
|
398
|
-
private customBlocks(content: unknown, width: number): string[] {
|
|
399
|
-
if (this.detail === "compact") return [];
|
|
400
|
-
if (this.detail === "full") return this.blocks(content, width);
|
|
401
|
-
return this.pad(this.preview(content, Math.max(1, width - 2), true));
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
private message(message: AgentMessage, width: number): string[] {
|
|
405
|
-
if (message.role === "toolResult") {
|
|
406
|
-
const result = message as unknown as Record<string, unknown>;
|
|
407
|
-
return this.tool(String(result.toolCallId), String(result.toolName), {}, width);
|
|
408
|
-
}
|
|
409
|
-
const data = message as unknown as Record<string, unknown>;
|
|
410
|
-
const hasTools =
|
|
411
|
-
Array.isArray(data.content) &&
|
|
412
|
-
data.content.some((block: unknown) => object(block)?.type === "toolCall");
|
|
413
|
-
const cached = !hasTools && this.cache.get(message);
|
|
414
|
-
if (cached && cached.width === width && cached.detail === this.detail) return cached.lines;
|
|
415
|
-
const label = message.role;
|
|
416
|
-
const collapsed = !["user", "assistant", "custom"].includes(message.role);
|
|
417
|
-
const content = data.content ?? data.summary ?? data.output ?? data;
|
|
418
|
-
const inner = Math.max(1, width - 2);
|
|
419
|
-
const heading = this.theme.fg(data.isError ? "error" : "accent", dialogText(label));
|
|
420
|
-
const errors = data.errorMessage
|
|
421
|
-
? (collapsed
|
|
422
|
-
? this.preview(String(data.errorMessage), inner)
|
|
423
|
-
: this.wrap(String(data.errorMessage), inner)
|
|
424
|
-
).map((line) => this.theme.fg("error", line))
|
|
425
|
-
: [];
|
|
426
|
-
const lines = [
|
|
427
|
-
...this.pad([heading]),
|
|
428
|
-
...(message.role === "custom"
|
|
429
|
-
? this.customBlocks(content, width)
|
|
430
|
-
: collapsed
|
|
431
|
-
? this.pad(this.preview(content, inner))
|
|
432
|
-
: this.blocks(content, width)),
|
|
433
|
-
...this.pad(errors),
|
|
434
|
-
"",
|
|
435
|
-
];
|
|
436
|
-
if (!hasTools) this.cache.set(message, { width, detail: this.detail, lines });
|
|
437
|
-
return lines;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
/** Pair a call with its committed result or live partial, then render nested executions in place. */
|
|
441
|
-
private tool(id: string, name: string, args: unknown, width: number): string[] {
|
|
442
|
-
if (this.renderedTools.has(id)) return [];
|
|
443
|
-
this.renderedTools.add(id);
|
|
444
|
-
const state = this.tools.get(id);
|
|
445
|
-
const result = this.results.get(id) ?? state?.result;
|
|
446
|
-
const running =
|
|
447
|
-
!this.results.has(id) && (state ? state.state === "running" : result === undefined);
|
|
448
|
-
const isError = Boolean(object(result)?.isError ?? state?.isError);
|
|
449
|
-
// Committed call arguments are authoritative; orphan results use retained live args if available.
|
|
450
|
-
if (state && !Object.keys(object(args) ?? {}).length) args = state.args;
|
|
451
|
-
const cached = this.toolCache.get(id);
|
|
452
|
-
let lines: string[];
|
|
453
|
-
if (
|
|
454
|
-
cached &&
|
|
455
|
-
cached.args === args &&
|
|
456
|
-
cached.result === result &&
|
|
457
|
-
cached.running === running &&
|
|
458
|
-
cached.isError === isError &&
|
|
459
|
-
cached.name === name &&
|
|
460
|
-
cached.width === width &&
|
|
461
|
-
cached.detail === this.detail
|
|
462
|
-
) {
|
|
463
|
-
lines = cached.lines;
|
|
464
|
-
} else {
|
|
465
|
-
lines = renderTranscriptTool(name, id, args, result, isError, running, this.detail, width);
|
|
466
|
-
this.toolCache.set(id, {
|
|
467
|
-
args,
|
|
468
|
-
result,
|
|
469
|
-
running,
|
|
470
|
-
isError,
|
|
471
|
-
name,
|
|
472
|
-
width,
|
|
473
|
-
detail: this.detail,
|
|
474
|
-
lines,
|
|
475
|
-
});
|
|
476
|
-
}
|
|
477
|
-
const nested: string[] = [];
|
|
478
|
-
for (const child of this.tools.values()) {
|
|
479
|
-
if (child.parentToolCallId !== id || this.renderedTools.has(child.toolCallId)) continue;
|
|
480
|
-
nested.push(
|
|
481
|
-
` ${this.theme.fg("dim", "↳ nested tool")}`,
|
|
482
|
-
...this.tool(child.toolCallId, child.toolName, child.args, Math.max(3, width - 2)).map(
|
|
483
|
-
(line) => ` ${line}`,
|
|
484
|
-
),
|
|
485
|
-
);
|
|
486
|
-
}
|
|
487
|
-
return [...lines, ...nested];
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
render(width: number): string[] {
|
|
491
|
-
const height = Math.max(1, this.host.terminal?.rows ?? 24);
|
|
492
|
-
const columns = Math.max(1, width);
|
|
493
|
-
const snapshot = this.snapshot;
|
|
494
|
-
const thread = snapshot?.thread;
|
|
495
|
-
const inner = Math.max(1, columns - 2);
|
|
496
|
-
const header = this.theme.fg(
|
|
497
|
-
"accent",
|
|
498
|
-
dialogText(
|
|
499
|
-
`${this.path} · ${agentTypeLabel(thread?.type ?? "agent", thread?.icon, this.nerdFontIcons, thread ? agentProgressIcon(thread, this.nerdFontIcons, Date.now(), true, this.loaderStyle) : undefined)} · ${thread?.state ?? "attaching"} — Watching — main continues`,
|
|
500
|
-
),
|
|
501
|
-
);
|
|
502
|
-
this.results = new Map(
|
|
503
|
-
(snapshot?.messages ?? [])
|
|
504
|
-
.filter((message) => message.role === "toolResult")
|
|
505
|
-
.map((message) => [
|
|
506
|
-
String((message as unknown as Record<string, unknown>).toolCallId),
|
|
507
|
-
message,
|
|
508
|
-
]),
|
|
509
|
-
);
|
|
510
|
-
this.tools = new Map((snapshot?.tools ?? []).map((tool) => [tool.toolCallId, tool]));
|
|
511
|
-
this.renderedTools.clear();
|
|
512
|
-
const body: string[] = [];
|
|
513
|
-
if (this.error)
|
|
514
|
-
body.push(
|
|
515
|
-
` ${this.theme.fg("error", dialogText(`Attachment error: ${this.error}`))}`,
|
|
516
|
-
" Ctrl+R Retry · Esc Back · Ctrl+Q Back to main",
|
|
517
|
-
);
|
|
518
|
-
if (!snapshot) {
|
|
519
|
-
if (!this.error) body.push(" Attaching to retained live session…");
|
|
520
|
-
} else {
|
|
521
|
-
if (snapshot.inheritedCount)
|
|
522
|
-
body.push(
|
|
523
|
-
" " +
|
|
524
|
-
this.theme.fg(
|
|
525
|
-
"dim",
|
|
526
|
-
`${snapshot.inheritedCount} inherited messages ${this.viewport.showInherited ? "shown" : "collapsed"} · c toggle`,
|
|
527
|
-
),
|
|
528
|
-
);
|
|
529
|
-
const start = this.viewport.showInherited ? 0 : snapshot.inheritedCount;
|
|
530
|
-
for (const message of snapshot.messages.slice(start))
|
|
531
|
-
body.push(...this.message(message, columns));
|
|
532
|
-
if (snapshot.assistant)
|
|
533
|
-
body.push(
|
|
534
|
-
` ${this.theme.fg("warning", "Assistant streaming…")}`,
|
|
535
|
-
...this.message(snapshot.assistant, columns),
|
|
536
|
-
);
|
|
537
|
-
// Parents first even when nested notifications arrive before the outer call.
|
|
538
|
-
for (const tool of snapshot.tools)
|
|
539
|
-
if (!tool.parentToolCallId && !this.results.has(tool.toolCallId))
|
|
540
|
-
body.push(...this.tool(tool.toolCallId, tool.toolName, tool.args, columns));
|
|
541
|
-
// An orphan nested execution still needs to be visible if its parent is unavailable.
|
|
542
|
-
for (const tool of snapshot.tools)
|
|
543
|
-
if (!this.renderedTools.has(tool.toolCallId) && !this.results.has(tool.toolCallId))
|
|
544
|
-
body.push(...this.tool(tool.toolCallId, tool.toolName, tool.args, columns));
|
|
545
|
-
for (const id of this.toolCache.keys())
|
|
546
|
-
if (!this.renderedTools.has(id)) this.toolCache.delete(id);
|
|
547
|
-
if (!body.length)
|
|
548
|
-
body.push(
|
|
549
|
-
thread?.state === "starting"
|
|
550
|
-
? " Starting — waiting for transcript attachment…"
|
|
551
|
-
: " No retained messages yet.",
|
|
552
|
-
);
|
|
553
|
-
}
|
|
554
|
-
this.content = body;
|
|
555
|
-
const bodyHeight = Math.max(0, height - 4);
|
|
556
|
-
this.scroll.updateLayout(body.length, bodyHeight, () => this.scheduleRender());
|
|
557
|
-
if (this.restoreViewport) {
|
|
558
|
-
if (this.viewport.follow) this.scroll.scrollToEnd();
|
|
559
|
-
else this.scroll.scrollTo(this.viewport.scrollTop, { disableFollow: true });
|
|
560
|
-
this.restoreViewport = false;
|
|
561
|
-
}
|
|
562
|
-
const visible = this.scroll
|
|
563
|
-
.render(columns)
|
|
564
|
-
.slice(this.scroll.scrollTop, this.scroll.scrollTop + bodyHeight);
|
|
565
|
-
while (visible.length < bodyHeight) visible.push("");
|
|
566
|
-
this.saveViewport();
|
|
567
|
-
const footer = this.error
|
|
568
|
-
? "Ctrl+R Retry · Tab input/transcript · Esc tree · Ctrl+Q main"
|
|
569
|
-
: `${this.editing ? "Enter steer · Tab browse" : "Tab steer · Home/End scroll · c context"} · Ctrl+O view:${this.detail} · Esc tree · Ctrl+Q main · ↑↓/PgUp/PgDn scroll · ${this.viewport.follow ? "following" : "scrolled"}`;
|
|
570
|
-
const input = ` ${this.input.render(inner)[0]!}`;
|
|
571
|
-
const status = this.theme.fg(
|
|
572
|
-
this.steerStatus ? (this.steerFailed ? "error" : "muted") : this.error ? "error" : "muted",
|
|
573
|
-
dialogText(
|
|
574
|
-
this.steerStatus ??
|
|
575
|
-
(this.error
|
|
576
|
-
? `Attachment error: ${this.error}`
|
|
577
|
-
: thread
|
|
578
|
-
? `${thread.task} · ${thread.status}`
|
|
579
|
-
: "Live transcript · Enter to steer"),
|
|
580
|
-
),
|
|
581
|
-
);
|
|
582
|
-
// Chrome rows share the transcript's one-column side padding; `visible` is already padded.
|
|
583
|
-
const chrome = (line: string) => ` ${truncateToWidth(line, inner, "")}`;
|
|
584
|
-
const lines =
|
|
585
|
-
height === 1
|
|
586
|
-
? [input]
|
|
587
|
-
: height === 2
|
|
588
|
-
? [chrome(header), input]
|
|
589
|
-
: height === 3
|
|
590
|
-
? [chrome(header), chrome(this.theme.fg("dim", footer)), input]
|
|
591
|
-
: [
|
|
592
|
-
chrome(header),
|
|
593
|
-
chrome(status),
|
|
594
|
-
...visible,
|
|
595
|
-
chrome(this.theme.fg("dim", footer)),
|
|
596
|
-
input,
|
|
597
|
-
];
|
|
598
|
-
return fillViewport(lines, width, height);
|
|
599
|
-
}
|
|
600
|
-
}
|