pi-subagent-manager 1.10.0 → 1.12.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/README.md +9 -9
- package/dist/index.d.ts +2 -0
- package/dist/index.js +790 -0
- package/dist/orch/checklist-integration.js +176 -0
- package/dist/orch/context-entries.js +6 -0
- package/dist/orch/cost-ledger.js +38 -0
- package/dist/orch/diagnostics.js +86 -0
- package/dist/orch/extensions.js +66 -0
- package/dist/orch/housekeeping-usage.js +22 -0
- package/dist/orch/housekeeping.js +248 -0
- package/dist/orch/inherited-tools.js +57 -0
- package/dist/orch/mailbox.js +195 -0
- package/dist/orch/manager.js +970 -0
- package/dist/orch/paths.js +69 -0
- package/dist/orch/prompt.js +30 -0
- package/dist/orch/registry.js +115 -0
- package/dist/orch/runtime.js +835 -0
- package/dist/orch/tools.js +112 -0
- package/dist/orch/transcript.js +165 -0
- package/dist/prefs/agent-import.js +188 -0
- package/dist/prefs/config.js +878 -0
- package/dist/prefs/import-discovery.js +547 -0
- package/{src/prefs/import-instructions.ts → dist/prefs/import-instructions.js} +0 -1
- package/dist/prefs/models.js +56 -0
- package/dist/prefs/settings.js +491 -0
- package/dist/types.js +1 -0
- package/dist/ui/agent-loader.js +63 -0
- package/dist/ui/agent-navigation-editor.js +168 -0
- package/dist/ui/cost-footer.js +209 -0
- package/dist/ui/dialog.js +505 -0
- package/dist/ui/import-picker.js +191 -0
- package/dist/ui/live-agent-view.js +527 -0
- package/dist/ui/model-picker.js +529 -0
- package/dist/ui/settings-ui.js +671 -0
- package/dist/ui/status-ui.js +470 -0
- package/dist/ui/thread-tree.js +142 -0
- package/dist/ui/tool-picker.js +331 -0
- package/dist/ui/transcript-tool.js +91 -0
- package/dist/ui/ui.js +1019 -0
- package/package.json +17 -5
- package/docs/assets/subagent-manager-demo.gif +0 -0
- package/docs/async-lifecycle.md +0 -153
- package/docs/custom-agents.md +0 -154
- package/docs/default-agents.md +0 -95
- package/docs/demo.md +0 -63
- package/docs/development.md +0 -74
- package/docs/importing-agents.md +0 -41
- package/docs/pi-footer.md +0 -128
- package/docs/research-claude.md +0 -258
- package/docs/research-codex.md +0 -143
- package/docs/research-default-agent-models.md +0 -121
- package/docs/research-model-audit-2026-10.md +0 -154
- package/docs/research-model-roles-coding.md +0 -99
- package/docs/research-model-roles-writing.md +0 -78
- package/docs/research-researcher-workflow.md +0 -97
- package/docs/settings.md +0 -293
- package/docs/subagent-extension-limitations.md +0 -98
- package/docs/threads.md +0 -73
- package/docs/tools-and-ui.md +0 -129
- 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
package/src/ui/status-ui.ts
DELETED
|
@@ -1,628 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ExtensionCommandContext,
|
|
3
|
-
ExtensionContext,
|
|
4
|
-
ExtensionUIContext,
|
|
5
|
-
Theme,
|
|
6
|
-
} from "@earendil-works/pi-coding-agent";
|
|
7
|
-
import {
|
|
8
|
-
getKeybindings,
|
|
9
|
-
setKeybindings,
|
|
10
|
-
Key,
|
|
11
|
-
matchesKey,
|
|
12
|
-
type Keybinding,
|
|
13
|
-
} from "@earendil-works/pi-tui";
|
|
14
|
-
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
15
|
-
import {
|
|
16
|
-
canOpenDialog,
|
|
17
|
-
DIALOG_OPTIONS,
|
|
18
|
-
type DialogHost,
|
|
19
|
-
DialogSession,
|
|
20
|
-
scopeDialogContext,
|
|
21
|
-
dialogMenu,
|
|
22
|
-
dialogEditor,
|
|
23
|
-
dialogHeight,
|
|
24
|
-
dialogText,
|
|
25
|
-
frameDialog,
|
|
26
|
-
} from "./dialog.ts";
|
|
27
|
-
import type { ThreadService } from "../types.ts";
|
|
28
|
-
import type { LoaderStyle } from "../prefs/settings.ts";
|
|
29
|
-
import { buildStatusTree, threadActivity, type StatusRow } from "./thread-tree.ts";
|
|
30
|
-
import {
|
|
31
|
-
AGENT_PROGRESS_INTERVAL,
|
|
32
|
-
agentProgressIcon,
|
|
33
|
-
agentTypeBadge,
|
|
34
|
-
agentTypeLabel,
|
|
35
|
-
showThreads,
|
|
36
|
-
threadMetrics,
|
|
37
|
-
} from "./ui.ts";
|
|
38
|
-
import { LiveAgentView, fillViewport, type AgentViewportState } from "./live-agent-view.ts";
|
|
39
|
-
|
|
40
|
-
export { buildStatusTree, type StatusRow };
|
|
41
|
-
|
|
42
|
-
const ROOT = "/root";
|
|
43
|
-
const INACTIVE_STATES = new Set(["paused", "stopped", "failed", "completed"]);
|
|
44
|
-
const TITLE = "Agents status";
|
|
45
|
-
const TREE_TITLE = "Agents tree";
|
|
46
|
-
const FOOTER =
|
|
47
|
-
"Esc close · ↑↓ select · ←→ fold · PgUp/PgDn · Enter inspect · r refresh · Ctrl+C stop all";
|
|
48
|
-
|
|
49
|
-
function agentCount(threads: readonly { path?: string }[]): number {
|
|
50
|
-
const paths = new Set<string>();
|
|
51
|
-
for (const thread of threads) {
|
|
52
|
-
if (thread?.path && thread.path !== ROOT) paths.add(thread.path);
|
|
53
|
-
}
|
|
54
|
-
return paths.size;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function lexicalParent(path: string): string | null {
|
|
58
|
-
const index = path.lastIndexOf("/");
|
|
59
|
-
return index > 0 ? path.slice(0, index) : null;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function treeParent(rows: StatusRow[], index: number): StatusRow | undefined {
|
|
63
|
-
const depth = rows[index]?.prefix.length ?? 0;
|
|
64
|
-
for (let cursor = index - 1; cursor >= 0; cursor--) {
|
|
65
|
-
if (rows[cursor]!.prefix.length < depth) return rows[cursor];
|
|
66
|
-
}
|
|
67
|
-
return undefined;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function firstChild(rows: StatusRow[], index: number): StatusRow | undefined {
|
|
71
|
-
const next = rows[index + 1];
|
|
72
|
-
return next && next.prefix.length > (rows[index]?.prefix.length ?? 0) ? next : undefined;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function label(row: StatusRow): string {
|
|
76
|
-
if (!row.thread)
|
|
77
|
-
return row.path === ROOT
|
|
78
|
-
? `${dialogText(row.path)} main running main`
|
|
79
|
-
: `${dialogText(row.path)} missing parent`;
|
|
80
|
-
return [row.path, row.thread.type, row.thread.state, row.thread.status]
|
|
81
|
-
.map((part) => dialogText(part))
|
|
82
|
-
.join(" ");
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export interface AgentTreeState {
|
|
86
|
-
selectedPath: string;
|
|
87
|
-
collapsed: Set<string>;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export class StatusDialog {
|
|
91
|
-
private state: AgentTreeState;
|
|
92
|
-
private get selectedPath(): string {
|
|
93
|
-
return this.state.selectedPath;
|
|
94
|
-
}
|
|
95
|
-
private set selectedPath(value: string) {
|
|
96
|
-
this.state.selectedPath = value;
|
|
97
|
-
}
|
|
98
|
-
private get collapsed(): Set<string> {
|
|
99
|
-
return this.state.collapsed;
|
|
100
|
-
}
|
|
101
|
-
private viewport = 1;
|
|
102
|
-
private timer: ReturnType<typeof setInterval> | undefined;
|
|
103
|
-
private refreshDelay = 0;
|
|
104
|
-
private refreshing = false;
|
|
105
|
-
|
|
106
|
-
constructor(
|
|
107
|
-
private host: DialogHost,
|
|
108
|
-
private theme: Theme,
|
|
109
|
-
private service: ThreadService,
|
|
110
|
-
private done: (path: string | undefined) => void,
|
|
111
|
-
selected?: string,
|
|
112
|
-
private title = TITLE,
|
|
113
|
-
private navigation?: {
|
|
114
|
-
state: AgentTreeState;
|
|
115
|
-
actions(path: string): void;
|
|
116
|
-
fullscreen?: boolean;
|
|
117
|
-
/** Right on a leaf steps tree → widget; called just before the tree closes. */
|
|
118
|
-
returnToWidget?(): void;
|
|
119
|
-
},
|
|
120
|
-
private nerdFontIcons = false,
|
|
121
|
-
private loaderStyle: LoaderStyle = "circle",
|
|
122
|
-
) {
|
|
123
|
-
this.state = navigation?.state ?? { selectedPath: selected || ROOT, collapsed: new Set() };
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
invalidate(): void {}
|
|
127
|
-
|
|
128
|
-
/** Poll retained status, accelerating the existing timer only for animated live agents. */
|
|
129
|
-
startRefresh(): void {
|
|
130
|
-
this.stopRefresh();
|
|
131
|
-
this.refreshing = true;
|
|
132
|
-
this.syncRefresh();
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/** Stop the refresh. Safe to call more than once, including from dispose(). */
|
|
136
|
-
dispose(): void {
|
|
137
|
-
this.refreshing = false;
|
|
138
|
-
this.stopRefresh();
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
private syncRefresh(): void {
|
|
142
|
-
if (!this.refreshing) return;
|
|
143
|
-
const delay = this.service
|
|
144
|
-
.list()
|
|
145
|
-
.some(
|
|
146
|
-
(thread) =>
|
|
147
|
-
thread.path !== ROOT && (thread.state === "starting" || thread.state === "running"),
|
|
148
|
-
)
|
|
149
|
-
? AGENT_PROGRESS_INTERVAL
|
|
150
|
-
: 1000;
|
|
151
|
-
if (this.timer !== undefined && this.refreshDelay === delay) return;
|
|
152
|
-
this.stopRefresh();
|
|
153
|
-
this.refreshDelay = delay;
|
|
154
|
-
this.timer = setInterval(() => {
|
|
155
|
-
this.syncRefresh();
|
|
156
|
-
this.host.requestRender();
|
|
157
|
-
}, delay);
|
|
158
|
-
if (typeof this.timer.unref === "function") this.timer.unref();
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
private stopRefresh(): void {
|
|
162
|
-
if (this.timer === undefined) return;
|
|
163
|
-
clearInterval(this.timer);
|
|
164
|
-
this.timer = undefined;
|
|
165
|
-
this.refreshDelay = 0;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/** Stop every live agent. Stopping a subtree covers its descendants, so only top-most live paths are sent. */
|
|
169
|
-
private stopAll(): void {
|
|
170
|
-
const live = this.service
|
|
171
|
-
.list()
|
|
172
|
-
.filter(
|
|
173
|
-
(thread) =>
|
|
174
|
-
thread.path !== ROOT && (thread.state === "starting" || thread.state === "running"),
|
|
175
|
-
)
|
|
176
|
-
.map((thread) => thread.path);
|
|
177
|
-
const tops = live.filter((path) => !live.some((other) => path.startsWith(`${other}/`)));
|
|
178
|
-
for (const path of tops) {
|
|
179
|
-
void this.service
|
|
180
|
-
.stop(path)
|
|
181
|
-
.catch(() => {})
|
|
182
|
-
.finally(() => this.host.requestRender());
|
|
183
|
-
}
|
|
184
|
-
this.host.requestRender();
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
private rows(): StatusRow[] {
|
|
188
|
-
return buildStatusTree(this.service.list(), this.collapsed);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
private locate(rows: StatusRow[]): number {
|
|
192
|
-
const exact = rows.findIndex((row) => row.path === this.selectedPath);
|
|
193
|
-
if (exact >= 0) return exact;
|
|
194
|
-
let parent = lexicalParent(this.selectedPath);
|
|
195
|
-
while (parent) {
|
|
196
|
-
const index = rows.findIndex((row) => row.path === parent);
|
|
197
|
-
if (index >= 0) return index;
|
|
198
|
-
parent = lexicalParent(parent);
|
|
199
|
-
}
|
|
200
|
-
const root = rows.findIndex((row) => row.path === ROOT);
|
|
201
|
-
return root >= 0 ? root : 0;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
handleInput(data: string): void {
|
|
205
|
-
const keys = getKeybindings();
|
|
206
|
-
if (matchesKey(data, Key.ctrl("c"))) {
|
|
207
|
-
this.stopAll();
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
if (keys.matches(data, "tui.select.cancel")) {
|
|
211
|
-
this.done(undefined);
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
const rows = this.rows();
|
|
215
|
-
const index = this.locate(rows);
|
|
216
|
-
const row = rows[index];
|
|
217
|
-
if (row) this.selectedPath = row.path;
|
|
218
|
-
if (keys.matches(data, "tui.select.confirm")) {
|
|
219
|
-
if (this.navigation && row?.path === ROOT) this.done(undefined);
|
|
220
|
-
else if (row?.thread && row.path !== ROOT) this.done(row.path);
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
if (data === "i" && this.navigation) {
|
|
224
|
-
if (row?.thread && row.path !== ROOT) this.navigation.actions(row.path);
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
if (matchesKey(data, Key.ctrl("q")) && this.navigation) {
|
|
228
|
-
this.done(undefined);
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
if (data === "r") {
|
|
232
|
-
this.host.requestRender();
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
if (matchesKey(data, Key.left)) {
|
|
236
|
-
if (row?.hasChildren && !this.collapsed.has(row.path)) this.collapsed.add(row.path);
|
|
237
|
-
else if (row) {
|
|
238
|
-
const parent = treeParent(rows, index);
|
|
239
|
-
if (parent) this.selectedPath = parent.path;
|
|
240
|
-
}
|
|
241
|
-
} else if (matchesKey(data, Key.right)) {
|
|
242
|
-
if (row?.hasChildren && this.collapsed.has(row.path)) this.collapsed.delete(row.path);
|
|
243
|
-
else {
|
|
244
|
-
const child = row?.hasChildren ? firstChild(rows, index) : undefined;
|
|
245
|
-
if (child) this.selectedPath = child.path;
|
|
246
|
-
else if (this.navigation?.fullscreen) {
|
|
247
|
-
// Nothing left to fold or descend into: the next step right is the widget.
|
|
248
|
-
this.navigation.returnToWidget?.();
|
|
249
|
-
this.done(undefined);
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
} else {
|
|
254
|
-
let next = index;
|
|
255
|
-
if (keys.matches(data, "tui.select.up")) next -= 1;
|
|
256
|
-
else if (keys.matches(data, "tui.select.down")) next += 1;
|
|
257
|
-
else if (matchesKey(data, Key.pageUp)) next -= this.viewport;
|
|
258
|
-
else if (matchesKey(data, Key.pageDown)) next += this.viewport;
|
|
259
|
-
else if (matchesKey(data, Key.home)) next = 0;
|
|
260
|
-
else if (matchesKey(data, Key.end)) next = Math.max(0, rows.length - 1);
|
|
261
|
-
else return;
|
|
262
|
-
this.selectedPath =
|
|
263
|
-
rows[Math.max(0, Math.min(rows.length - 1, next))]?.path ?? this.selectedPath;
|
|
264
|
-
}
|
|
265
|
-
this.host.requestRender();
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
private line(row: StatusRow, selected: boolean, width: number): string[] {
|
|
269
|
-
const marker = row.hasChildren ? (this.collapsed.has(row.path) ? "▸ " : "▾ ") : "";
|
|
270
|
-
const head = ` ${row.prefix}${selected ? "›" : " "} ${marker}`;
|
|
271
|
-
const thread = row.thread;
|
|
272
|
-
if (!thread) {
|
|
273
|
-
const text = `${head}${label(row)}`;
|
|
274
|
-
return [selected ? this.theme.fg("accent", text) : text, ""];
|
|
275
|
-
}
|
|
276
|
-
const inactive = INACTIVE_STATES.has(thread.state);
|
|
277
|
-
const base = thread.state === "completed" ? "dim" : "muted";
|
|
278
|
-
const hint =
|
|
279
|
-
thread.state === "completed" ? "success" : thread.state === "failed" ? "error" : base;
|
|
280
|
-
const progress = agentProgressIcon(
|
|
281
|
-
thread,
|
|
282
|
-
this.nerdFontIcons,
|
|
283
|
-
Date.now(),
|
|
284
|
-
true,
|
|
285
|
-
this.loaderStyle,
|
|
286
|
-
);
|
|
287
|
-
const badge = inactive
|
|
288
|
-
? this.theme.fg(base, agentTypeLabel(thread.type, thread.icon, this.nerdFontIcons, progress))
|
|
289
|
-
: agentTypeBadge(
|
|
290
|
-
thread.type,
|
|
291
|
-
thread.color,
|
|
292
|
-
this.theme,
|
|
293
|
-
thread.icon,
|
|
294
|
-
this.nerdFontIcons,
|
|
295
|
-
progress,
|
|
296
|
-
);
|
|
297
|
-
const identity = [
|
|
298
|
-
thread.path,
|
|
299
|
-
`${thread.model ?? "model pending"}${thread.thinkingLevel ? `:${thread.thinkingLevel}` : ""}`,
|
|
300
|
-
]
|
|
301
|
-
.map((part) => dialogText(part))
|
|
302
|
-
.join(" ");
|
|
303
|
-
const identityLine = [
|
|
304
|
-
selected ? this.theme.fg("accent", head) : head,
|
|
305
|
-
badge,
|
|
306
|
-
this.theme.fg(inactive ? base : selected ? "accent" : "text", ` ${identity} `),
|
|
307
|
-
this.theme.fg(inactive ? hint : "muted", dialogText(thread.state)),
|
|
308
|
-
].join("");
|
|
309
|
-
// Continue the tree's vertical guides without repeating the branch or selection marker.
|
|
310
|
-
const stem = row.prefix.replace("├ ", "│ ").replace("└ ", " ");
|
|
311
|
-
const activity = ` ${stem} ${dialogText(threadActivity(thread))}`;
|
|
312
|
-
const metrics = this.theme.fg(base, threadMetrics(thread));
|
|
313
|
-
const metricWidth = visibleWidth(metrics);
|
|
314
|
-
const first =
|
|
315
|
-
metricWidth >= width
|
|
316
|
-
? truncateToWidth(metrics, width, "")
|
|
317
|
-
: (() => {
|
|
318
|
-
const left = truncateToWidth(identityLine, width - metricWidth - 1);
|
|
319
|
-
return (
|
|
320
|
-
left + " ".repeat(Math.max(1, width - visibleWidth(left) - metricWidth)) + metrics
|
|
321
|
-
);
|
|
322
|
-
})();
|
|
323
|
-
const second = truncateToWidth(
|
|
324
|
-
this.theme.fg(inactive ? base : selected ? "accent" : "muted", activity),
|
|
325
|
-
width,
|
|
326
|
-
);
|
|
327
|
-
return [first, second];
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
private detail(row: StatusRow | undefined): string[] {
|
|
331
|
-
if (!row?.thread) {
|
|
332
|
-
return [
|
|
333
|
-
` ${row?.path === ROOT ? (agentCount(this.service.list()) ? "Main Pi session" : "Main Pi session — No agents yet") : "Missing parent"}`,
|
|
334
|
-
"",
|
|
335
|
-
];
|
|
336
|
-
}
|
|
337
|
-
return [` task ${dialogText(row.thread.task)}`, ` ${threadMetrics(row.thread)}`];
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
render(width: number): string[] {
|
|
341
|
-
this.syncRefresh();
|
|
342
|
-
const rows = this.rows();
|
|
343
|
-
const height = this.navigation?.fullscreen
|
|
344
|
-
? Math.max(1, this.host.terminal?.rows ?? 24)
|
|
345
|
-
: dialogHeight(this.host);
|
|
346
|
-
const index = this.locate(rows);
|
|
347
|
-
if (rows[index]) this.selectedPath = rows[index].path;
|
|
348
|
-
const budget = Math.max(0, height - 4);
|
|
349
|
-
const detail = budget > 2 ? this.detail(rows[index]) : [];
|
|
350
|
-
const treeCount = Math.max(0, Math.floor((budget - detail.length) / 2));
|
|
351
|
-
this.viewport = Math.max(1, treeCount);
|
|
352
|
-
const start = treeCount
|
|
353
|
-
? Math.max(0, Math.min(index - treeCount + 1, Math.max(0, rows.length - treeCount)))
|
|
354
|
-
: 0;
|
|
355
|
-
const body = [
|
|
356
|
-
...rows
|
|
357
|
-
.slice(start, start + treeCount)
|
|
358
|
-
.flatMap((row) => this.line(row, row.path === this.selectedPath, Math.max(0, width - 2))),
|
|
359
|
-
...detail,
|
|
360
|
-
];
|
|
361
|
-
return frameDialog(
|
|
362
|
-
this.theme,
|
|
363
|
-
width,
|
|
364
|
-
height,
|
|
365
|
-
this.heading(rows, start, treeCount),
|
|
366
|
-
body,
|
|
367
|
-
this.navigation
|
|
368
|
-
? "Esc main · ↑↓ select · ←→ fold · → widget · i Actions · Ctrl+C stop all"
|
|
369
|
-
: FOOTER,
|
|
370
|
-
);
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
private heading(rows: StatusRow[], start: number, treeCount: number): string {
|
|
374
|
-
if (this.title !== TREE_TITLE) return this.title;
|
|
375
|
-
const agents = agentCount(this.service.list());
|
|
376
|
-
const noun = agents === 1 ? "agent" : "agents";
|
|
377
|
-
const total = rows.length;
|
|
378
|
-
const shown = Math.max(0, Math.min(treeCount, total - start));
|
|
379
|
-
if (shown <= 0) return `${TREE_TITLE} ${agents} ${noun}`;
|
|
380
|
-
return `${TREE_TITLE} ${agents} ${noun} ${start + 1}-${start + shown}/${total}`;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
async function showAgentDialog(
|
|
385
|
-
ctx: ExtensionCommandContext,
|
|
386
|
-
service: ThreadService,
|
|
387
|
-
options: {
|
|
388
|
-
title?: string;
|
|
389
|
-
selected?: string;
|
|
390
|
-
inspect?: (path: string) => Promise<void>;
|
|
391
|
-
nerdFontIcons?: boolean;
|
|
392
|
-
loaderStyle?: LoaderStyle;
|
|
393
|
-
} = {},
|
|
394
|
-
): Promise<void> {
|
|
395
|
-
const open = options.inspect ?? ((path: string) => showThreads(ctx, service, path));
|
|
396
|
-
let selected = options.selected;
|
|
397
|
-
for (;;) {
|
|
398
|
-
// Cleared on close and from dispose(): DialogSession host disposal can
|
|
399
|
-
// leave this promise pending, so finally alone may not run immediately.
|
|
400
|
-
let dialog: StatusDialog | undefined;
|
|
401
|
-
try {
|
|
402
|
-
const chosen = await ctx.ui.custom<string | undefined>((host, theme, _keys, done) => {
|
|
403
|
-
dialog = new StatusDialog(
|
|
404
|
-
host,
|
|
405
|
-
theme,
|
|
406
|
-
service,
|
|
407
|
-
done,
|
|
408
|
-
selected,
|
|
409
|
-
options.title,
|
|
410
|
-
undefined,
|
|
411
|
-
options.nerdFontIcons,
|
|
412
|
-
options.loaderStyle,
|
|
413
|
-
);
|
|
414
|
-
dialog.startRefresh();
|
|
415
|
-
return dialog;
|
|
416
|
-
}, DIALOG_OPTIONS);
|
|
417
|
-
dialog?.dispose();
|
|
418
|
-
dialog = undefined;
|
|
419
|
-
if (!chosen) return;
|
|
420
|
-
selected = chosen;
|
|
421
|
-
await open(chosen);
|
|
422
|
-
} finally {
|
|
423
|
-
dialog?.dispose();
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
export async function showAgentStatus(
|
|
429
|
-
ctx: ExtensionCommandContext,
|
|
430
|
-
service: ThreadService,
|
|
431
|
-
inspect?: (path: string) => Promise<void>,
|
|
432
|
-
nerdFontIcons = false,
|
|
433
|
-
loaderStyle: LoaderStyle = "circle",
|
|
434
|
-
): Promise<void> {
|
|
435
|
-
if (!canOpenDialog(ctx)) return;
|
|
436
|
-
await showAgentDialog(ctx, service, { inspect, nerdFontIcons, loaderStyle });
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
/** Root-owned navigation state. Opening and closing never changes the executing session. */
|
|
440
|
-
export class AgentNavigationController {
|
|
441
|
-
private tree: AgentTreeState = { selectedPath: ROOT, collapsed: new Set() };
|
|
442
|
-
private viewports = new Map<string, AgentViewportState>();
|
|
443
|
-
private session: DialogSession | undefined;
|
|
444
|
-
private opening: Promise<void> | undefined;
|
|
445
|
-
private generation = 0;
|
|
446
|
-
|
|
447
|
-
constructor(private returnToWidget?: () => void) {}
|
|
448
|
-
|
|
449
|
-
get isOpen(): boolean {
|
|
450
|
-
return this.opening !== undefined;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
close(): void {
|
|
454
|
-
++this.generation;
|
|
455
|
-
this.session?.close();
|
|
456
|
-
this.session = undefined;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
open(
|
|
460
|
-
ctx: ExtensionContext,
|
|
461
|
-
service: ThreadService,
|
|
462
|
-
selectedPath?: string,
|
|
463
|
-
nerdFontIcons = false,
|
|
464
|
-
loaderStyle: LoaderStyle = "circle",
|
|
465
|
-
): Promise<void> {
|
|
466
|
-
if (this.opening) return this.opening;
|
|
467
|
-
if (!canOpenDialog(ctx)) return Promise.resolve();
|
|
468
|
-
if (selectedPath) this.tree.selectedPath = selectedPath;
|
|
469
|
-
const generation = ++this.generation;
|
|
470
|
-
let failure: unknown;
|
|
471
|
-
let failed = false;
|
|
472
|
-
let ownedSession: DialogSession | undefined;
|
|
473
|
-
const task = ctx.ui.custom<void>(
|
|
474
|
-
(host, theme, keys, done) => {
|
|
475
|
-
const session = new DialogSession(host, theme, keys, done);
|
|
476
|
-
ownedSession = session;
|
|
477
|
-
if (generation !== this.generation) {
|
|
478
|
-
void Promise.resolve().then(() => session.close());
|
|
479
|
-
return session;
|
|
480
|
-
}
|
|
481
|
-
this.session = session;
|
|
482
|
-
// The alt-screen renderer's listener runs before extension listeners. Temporarily
|
|
483
|
-
// remove only its search action from the public keybinding lookup, before dispatch.
|
|
484
|
-
const previousKeybindings = getKeybindings();
|
|
485
|
-
const watchingKeybindings = new Proxy(previousKeybindings, {
|
|
486
|
-
get(target, property) {
|
|
487
|
-
if (property === "matches")
|
|
488
|
-
return (data: string, action: Keybinding) =>
|
|
489
|
-
action === "tui.altScreen.search" ? false : target.matches(data, action);
|
|
490
|
-
// Preserve all other public manager methods and their original receiver.
|
|
491
|
-
const value = Reflect.get(target, property, target);
|
|
492
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
493
|
-
},
|
|
494
|
-
});
|
|
495
|
-
setKeybindings(watchingKeybindings);
|
|
496
|
-
const dispose = session.dispose.bind(session);
|
|
497
|
-
session.dispose = () => {
|
|
498
|
-
// Do not overwrite a newer keybinding owner installed by another extension.
|
|
499
|
-
if (getKeybindings() === watchingKeybindings) setKeybindings(previousKeybindings);
|
|
500
|
-
dispose();
|
|
501
|
-
};
|
|
502
|
-
// One fullscreen surface also covers shorter Actions dialogs without exposing main.
|
|
503
|
-
const render = session.render.bind(session);
|
|
504
|
-
session.render = (width) => fillViewport(render(width), width, host.terminal.rows);
|
|
505
|
-
const scoped = scopeDialogContext(ctx, session);
|
|
506
|
-
// Built-in UI dialogs otherwise stack independently. Mount these actions in our child slot.
|
|
507
|
-
const ui = scoped.ui as ExtensionUIContext;
|
|
508
|
-
ui.select = (title, options) =>
|
|
509
|
-
dialogMenu(
|
|
510
|
-
scoped,
|
|
511
|
-
title,
|
|
512
|
-
options.map((label) => ({ id: label, label })),
|
|
513
|
-
);
|
|
514
|
-
ui.confirm = async (title, message) =>
|
|
515
|
-
(await dialogMenu(
|
|
516
|
-
scoped,
|
|
517
|
-
title,
|
|
518
|
-
[
|
|
519
|
-
{ id: "Yes", label: "Yes", help: message },
|
|
520
|
-
{ id: "No", label: "No", help: message },
|
|
521
|
-
],
|
|
522
|
-
{ selectedId: "No" },
|
|
523
|
-
)) === "Yes";
|
|
524
|
-
ui.editor = (title, prefill) => dialogEditor(scoped, title, prefill ?? "");
|
|
525
|
-
// Defer until Pi has installed/focused the overlay.
|
|
526
|
-
void Promise.resolve()
|
|
527
|
-
.then(async () => {
|
|
528
|
-
while (generation === this.generation) {
|
|
529
|
-
let treeDialog: StatusDialog | undefined;
|
|
530
|
-
const chosen = await session.mount<
|
|
531
|
-
{ kind: "watch" | "actions"; path: string } | undefined
|
|
532
|
-
>((tui, activeTheme, _keys, finish) => {
|
|
533
|
-
treeDialog = new StatusDialog(
|
|
534
|
-
tui,
|
|
535
|
-
activeTheme,
|
|
536
|
-
service,
|
|
537
|
-
(path) => finish(path ? { kind: "watch", path } : undefined),
|
|
538
|
-
undefined,
|
|
539
|
-
TREE_TITLE,
|
|
540
|
-
{
|
|
541
|
-
state: this.tree,
|
|
542
|
-
fullscreen: true,
|
|
543
|
-
returnToWidget: this.returnToWidget,
|
|
544
|
-
actions: (path) => finish({ kind: "actions", path }),
|
|
545
|
-
},
|
|
546
|
-
nerdFontIcons,
|
|
547
|
-
loaderStyle,
|
|
548
|
-
);
|
|
549
|
-
treeDialog.startRefresh();
|
|
550
|
-
return treeDialog;
|
|
551
|
-
});
|
|
552
|
-
treeDialog?.dispose();
|
|
553
|
-
if (!chosen || generation !== this.generation) break;
|
|
554
|
-
if (chosen.kind === "actions") {
|
|
555
|
-
await showThreads(scoped, service, chosen.path);
|
|
556
|
-
continue;
|
|
557
|
-
}
|
|
558
|
-
let viewport = this.viewports.get(chosen.path);
|
|
559
|
-
if (!viewport) {
|
|
560
|
-
viewport = { scrollTop: 0, follow: true };
|
|
561
|
-
this.viewports.set(chosen.path, viewport);
|
|
562
|
-
}
|
|
563
|
-
const result = await session.mount<"back" | "main">(
|
|
564
|
-
(tui, activeTheme, _keys, finish) =>
|
|
565
|
-
new LiveAgentView(
|
|
566
|
-
tui,
|
|
567
|
-
activeTheme,
|
|
568
|
-
service,
|
|
569
|
-
chosen.path,
|
|
570
|
-
viewport!,
|
|
571
|
-
finish,
|
|
572
|
-
nerdFontIcons,
|
|
573
|
-
loaderStyle,
|
|
574
|
-
),
|
|
575
|
-
);
|
|
576
|
-
if (result !== "back") break;
|
|
577
|
-
}
|
|
578
|
-
})
|
|
579
|
-
.then(
|
|
580
|
-
() => session.close(),
|
|
581
|
-
(error: unknown) => {
|
|
582
|
-
failed = true;
|
|
583
|
-
failure = error;
|
|
584
|
-
ctx.ui.notify(
|
|
585
|
-
dialogText(error instanceof Error ? error.message : String(error)),
|
|
586
|
-
"error",
|
|
587
|
-
);
|
|
588
|
-
session.close();
|
|
589
|
-
},
|
|
590
|
-
);
|
|
591
|
-
return session;
|
|
592
|
-
},
|
|
593
|
-
{
|
|
594
|
-
overlay: true,
|
|
595
|
-
overlayOptions: { width: "100%", maxHeight: "100%", row: 0, col: 0, margin: 0 },
|
|
596
|
-
},
|
|
597
|
-
);
|
|
598
|
-
this.opening = task
|
|
599
|
-
.then(() => {
|
|
600
|
-
if (failed) throw failure;
|
|
601
|
-
})
|
|
602
|
-
.finally(() => {
|
|
603
|
-
// Also clean up if the host rejects mounting after our factory returned.
|
|
604
|
-
ownedSession?.dispose();
|
|
605
|
-
if (this.opening === result) this.opening = undefined;
|
|
606
|
-
if (generation === this.generation) this.session = undefined;
|
|
607
|
-
});
|
|
608
|
-
const result = this.opening;
|
|
609
|
-
return result;
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
const navigationByService = new WeakMap<ThreadService, AgentNavigationController>();
|
|
614
|
-
|
|
615
|
-
export async function showAgentTree(
|
|
616
|
-
ctx: ExtensionContext,
|
|
617
|
-
service: ThreadService,
|
|
618
|
-
selectedPath?: string,
|
|
619
|
-
nerdFontIcons = false,
|
|
620
|
-
loaderStyle: LoaderStyle = "circle",
|
|
621
|
-
): Promise<void> {
|
|
622
|
-
let navigation = navigationByService.get(service);
|
|
623
|
-
if (!navigation) {
|
|
624
|
-
navigation = new AgentNavigationController();
|
|
625
|
-
navigationByService.set(service, navigation);
|
|
626
|
-
}
|
|
627
|
-
await navigation.open(ctx, service, selectedPath, nerdFontIcons, loaderStyle);
|
|
628
|
-
}
|