pi-subagent-manager 0.14.0 → 0.16.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 +3 -2
- package/docs/custom-agents.md +3 -0
- package/docs/settings.md +8 -1
- package/docs/tools-and-ui.md +4 -3
- package/package.json +1 -1
- package/src/index.ts +40 -9
- package/src/orch/manager.ts +65 -4
- package/src/prefs/settings.ts +12 -1
- package/src/types.ts +5 -0
- package/src/ui/agent-loader.ts +63 -0
- package/src/ui/live-agent-view.ts +117 -48
- package/src/ui/settings-ui.ts +32 -2
- package/src/ui/status-ui.ts +14 -8
- package/src/ui/thread-tree.ts +37 -11
- package/src/ui/tool-picker.ts +308 -0
- package/src/ui/ui.ts +77 -156
package/README.md
CHANGED
|
@@ -68,13 +68,14 @@ They inherit your current model until you set preferences. Details: [docs/defaul
|
|
|
68
68
|
| ---------------- | ------------------------------------------------------ |
|
|
69
69
|
| `/agents` | Settings (mode, limits, model picking, tool filtering) |
|
|
70
70
|
| `/agents types` | Agent-type browser and editor |
|
|
71
|
-
| `/agents tree` | Fullscreen tree and live viewer with manual steering
|
|
71
|
+
| `/agents tree` | Fullscreen tree and live viewer with manual steering |
|
|
72
72
|
| `/agents import` | Import agents from other subagent extensions |
|
|
73
73
|
| `/agents reload` | Reload definitions and settings |
|
|
74
|
+
| `/agents reap` | Confirm the eligible count, then forget completed agents and free retained-thread slots (cannot be resumed); preserves active parents and ancestors of retained threads. Session files remain on disk. |
|
|
74
75
|
|
|
75
76
|
A live **Agents** widget sits above the input box. Choose **Full** (the existing tree) or **Minimal** (colored status counts and running-agent token totals, plus the browser hint) under **Status Widget** in `/agents` settings. In the fullscreen tree, **Enter** opens an agent's live view. Type in the bottom **Steer** input and press **Enter** to send it a steering message, including nested agents. **Tab** switches between input and transcript controls, **Escape** returns, and **i** in the tree opens existing thread actions. A status strip below the previews shows how many agents are running and **Press ← to open subagent browser**. Once the main turn ends and all subagents are idle, the preview collapses to a single status-count line. A fresh prompt hides previously settled agents from the widget; they reappear only when resumed, and `/agents tree` always keeps them available. While subagents are starting or running, press **Left** at the start of the main draft to open it; otherwise Left stays native. Press **Right** at the end of the draft (or in an empty input) to collapse the widget to one line for this session only, without changing saved settings. `/agents tree` remains available regardless of agent activity. See [live navigation](docs/tools-and-ui.md#live-agent-navigation) for controls and compatibility.
|
|
76
77
|
|
|
77
|
-
Experimental features are marked **[labs]** in settings. Enable **[labs] Nerd Font icons** in `/agents` to show role-specific icons beside agent names,
|
|
78
|
+
Experimental features are marked **[labs]** in settings. Enable **[labs] Nerd Font icons** in `/agents` to show role-specific icons beside agent names (off by default; requires a Nerd Font in your terminal). Loaders appear **before**, never instead of, the role icon. Choose Circle, Braille, or Hourglass under **[labs] Loader style**, with previews of every animation frame and each family's completed, paused, failed, and stopped icons. Custom agent types can set an optional `icon` or use **[labs] Icon** in `/agents types`. See [icon setup](docs/settings.md#labs-nerd-font-icons-nerdfonticons).
|
|
78
79
|
|
|
79
80
|
Enable **[labs] Final Recap** in `/agents` to automatically ask the idle main agent to summarize detached-agent results, keeping the final response in the main thread. It is off by default and suppressed by Subagent Mode Off. **Enabling it may cause extra model turns and uses more tokens and context.** See [Final Recap](docs/settings.md#labs-final-recap-finalrecap).
|
|
80
81
|
|
package/docs/custom-agents.md
CHANGED
|
@@ -46,6 +46,9 @@ In `/agents types`, editing a bundled agent asks you to pick one mode first,
|
|
|
46
46
|
and settings stay locked until you choose. Overrides cannot rename the agent
|
|
47
47
|
or edit the system prompt — fork it instead.
|
|
48
48
|
|
|
49
|
+
To undo a fork or override, choose **Reset to bundled** (after Save) in the editor.
|
|
50
|
+
It deletes the `.md`/`.yml` file after confirmation and the shipped agent applies again.
|
|
51
|
+
|
|
49
52
|
These are the only locations read. Other packages' `~/.pi/agent/agents` or `.pi/agents` are ignored — use [`/agents import`](importing-agents.md) for those.
|
|
50
53
|
|
|
51
54
|
## 2. Write the file
|
package/docs/settings.md
CHANGED
|
@@ -16,6 +16,7 @@ All keys are optional. Defaults:
|
|
|
16
16
|
"subagentMode": "opportunistic",
|
|
17
17
|
"widgetMode": "full",
|
|
18
18
|
"nerdFontIcons": false,
|
|
19
|
+
"loaderStyle": "circle",
|
|
19
20
|
"finalRecap": false,
|
|
20
21
|
"modelSelection": "pick-first-scoped",
|
|
21
22
|
"toolFiltering": "allowed",
|
|
@@ -59,10 +60,16 @@ Minimal mode groups starting agents with running agents and excludes the main co
|
|
|
59
60
|
|
|
60
61
|
Experimental features are tagged **[labs]** in settings. **[labs] Nerd Font icons** is an on/off toggle, **off by default**. Enable it in `/agents` and save with **Ctrl+S**, or set `"nerdFontIcons": true` in your settings file. Configure a [Nerd Font](https://www.nerdfonts.com/) in your terminal first; unsupported fonts may show boxes or incorrect glyphs. The extension does not install or detect fonts.
|
|
61
62
|
|
|
62
|
-
When enabled, an agent type’s optional `icon` appears before its readable name in the full widget, thread browsers, live watcher header, and type picker. Starting/running agents
|
|
63
|
+
When enabled, an agent type’s optional `icon` appears before its readable name in the full widget, thread browsers, live watcher header, and type picker. Starting/running agents show the selected loader **before the original role icon**, never replacing it. Completed, paused, failed, and stopped agents show that loader family's corresponding static state icon before the role icon. Agents without a configured role icon still show their loader/state indicator. The one-line minimal widget uses the same family's indicators for aggregate status counts. Turning the setting off restores text-only labels without removing configured icons; RPC output keeps state indicators static. Saved settings apply immediately to newly rendered widgets and dialogs.
|
|
63
64
|
|
|
64
65
|
All six bundled agents have [role-specific icons](default-agents.md#nerd-font-icons). Add or change an icon with **[labs] Icon** in `/agents types`, or the optional `icon` frontmatter field in [your own agent](custom-agents.md#icons-labs). Retained threads keep the icon from their saved agent definition.
|
|
65
66
|
|
|
67
|
+
## [labs] Loader style (`loaderStyle`)
|
|
68
|
+
|
|
69
|
+
Choose **Circle** (default), **Braille**, or **Hourglass** in `/agents` settings and save with **Ctrl+S**, or set `"loaderStyle": "circle"`, `"braille"`, or `"hourglass"` in your settings file. Loaders are displayed when **[labs] Nerd Font icons** is enabled.
|
|
70
|
+
|
|
71
|
+
The Labs preview shows every family's running animation frames and completed, paused, failed, and stopped icons, so you can compare all states before choosing. Starting uses the running animation. State indicators always precede the unchanged role icon; the selected family also applies to the minimal widget's counts. In non-animated output, active agents use the family's first frame.
|
|
72
|
+
|
|
66
73
|
## [labs] Final Recap (`finalRecap`)
|
|
67
74
|
|
|
68
75
|
**[labs] Final Recap** is an experimental on/off toggle, **off by default**. Enable it in `/agents` and save with **Ctrl+S**, or set `"finalRecap": true` in your settings file.
|
package/docs/tools-and-ui.md
CHANGED
|
@@ -45,9 +45,10 @@ Child progress and completion notifications are retained in the main agent's con
|
|
|
45
45
|
| ----------------------------- | ---------------------------------------------------------------------------------- |
|
|
46
46
|
| `/agents`, `/agents settings` | [Settings](settings.md) dialog. **Agent definitions** jumps to the type editor. |
|
|
47
47
|
| `/agents types` | Type browser and editor — see [custom agents](custom-agents.md#editing-in-the-tui) |
|
|
48
|
-
| `/agents tree [path]` | Live full tree; optional path preselects.
|
|
48
|
+
| `/agents tree [path]` | Live full tree; optional path preselects. |
|
|
49
49
|
| `/agents import` | [Import picker](importing-agents.md) |
|
|
50
50
|
| `/agents reload` | Reload definitions and settings; show diagnostics |
|
|
51
|
+
| `/agents reap` | Show the eligible count and a Confirm/Cancel dialog, then forget completed agents and free retained-thread slots. Active parents and ancestors of retained threads are preserved; reaped agents cannot be resumed. Session files are not deleted. |
|
|
51
52
|
|
|
52
53
|
### `/agents tree` keys
|
|
53
54
|
|
|
@@ -98,10 +99,10 @@ In full mode:
|
|
|
98
99
|
|
|
99
100
|
- One row per agent: colored type pill, path, state, task, active time, input `↑` / output `↓` tokens.
|
|
100
101
|
- Activity and lifecycle messages (such as `Completed; session retained`) are omitted to save space; detailed status remains available in `/agents tree` and `agent_status`.
|
|
101
|
-
-
|
|
102
|
+
- Agents are ordered newest-started first (spawn or resume); a branch ranks by its most recently started agent. The most recently started agents are preferred when previews overflow. Overflow is counted, not listed.
|
|
102
103
|
- Time freezes while paused and resumes on continue.
|
|
103
104
|
- A small status strip below the previews shows the running count (including starting agents) and **Press ← to open subagent browser**, including when agents overflow. The full footer also shows **→ collapse**. Minimal mode keeps **← browser** inline so it stays one line. Browser hints appear only while subagents are starting or running; RPC output omits keyboard hints.
|
|
104
|
-
- With **[labs] Nerd Font icons** enabled,
|
|
105
|
+
- With **[labs] Nerd Font icons** enabled, the selected Circle, Braille, or Hourglass loader appears before the preserved role icon in the widget and fullscreen tree/live-view headers. Each family provides completed, paused, failed, and stopped state icons. The minimal summary uses the same indicators for its status counts. Preview all families and states under **[labs] Loader style**. Animation timers stop on settlement or disposal; RPC output stays static.
|
|
105
106
|
|
|
106
107
|
### Interrupts and stopping agents
|
|
107
108
|
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -7,13 +7,14 @@ import { IMPORT_REQUEST_PREFIX, markImportOffered, offerAgentImport } from "./pr
|
|
|
7
7
|
import { ThreadManager } from "./orch/manager.ts";
|
|
8
8
|
import { loadManagerSettings } from "./prefs/settings.ts";
|
|
9
9
|
import { configureAgents } from "./ui/settings-ui.ts";
|
|
10
|
-
import { AgentNavigationController
|
|
10
|
+
import { AgentNavigationController } from "./ui/status-ui.ts";
|
|
11
11
|
import { AgentNavigationEditor } from "./ui/agent-navigation-editor.ts";
|
|
12
12
|
import { createDriverFactory } from "./orch/runtime.ts";
|
|
13
13
|
import { createInheritedToolSource } from "./orch/inherited-tools.ts";
|
|
14
14
|
import { subagentPrompt } from "./orch/prompt.ts";
|
|
15
15
|
import { agentTools } from "./orch/tools.ts";
|
|
16
16
|
import { editAgentTypes, updateWidget } from "./ui/ui.ts";
|
|
17
|
+
import { canOpenDialog, dialogMenu } from "./ui/dialog.ts";
|
|
17
18
|
import type { SavedThread, ThreadEvent } from "./types.ts";
|
|
18
19
|
|
|
19
20
|
const REGISTRY_ENTRY = "pi-subagent:registry:v1";
|
|
@@ -96,7 +97,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
96
97
|
manager.list().some((thread) => thread.path !== "/root" &&
|
|
97
98
|
(thread.state === "starting" || thread.state === "running")),
|
|
98
99
|
openTree: () => manager && context
|
|
99
|
-
? navigation.open(context, manager.scope("/root"), undefined, limits.nerdFontIcons) : undefined,
|
|
100
|
+
? navigation.open(context, manager.scope("/root"), undefined, limits.nerdFontIcons, limits.loaderStyle) : undefined,
|
|
100
101
|
canCollapse: () => manager !== undefined && context?.mode === "tui" &&
|
|
101
102
|
limits.subagentMode !== "off" && !navigation.isOpen && !widgetCollapsed &&
|
|
102
103
|
limits.widgetMode === "full" && widgetThreads().some((thread) => thread.path !== "/root"),
|
|
@@ -335,7 +336,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
335
336
|
if (limits.subagentMode === "off") {
|
|
336
337
|
if (ctx.hasUI) ctx.ui.setWidget("pi-subagent", undefined);
|
|
337
338
|
} else updateWidget(ctx, widgetThreads(), widgetCollapsed ? "minimal" : limits.widgetMode,
|
|
338
|
-
limits.nerdFontIcons, rootTurnEnded);
|
|
339
|
+
limits.nerdFontIcons, rootTurnEnded, limits.loaderStyle);
|
|
339
340
|
};
|
|
340
341
|
pi.on("agent_start", async (_event, ctx) => {
|
|
341
342
|
// A new task must not resurrect the previous task's settled agents. Automatic
|
|
@@ -402,6 +403,10 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
402
403
|
rootSnapshot: () => buildSessionContext(requireContext().sessionManager.getBranch()).messages,
|
|
403
404
|
getType: (name) => store.get(name),
|
|
404
405
|
toolsFor,
|
|
406
|
+
onEventError: (error, event) => {
|
|
407
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
408
|
+
context?.ui.notify(`Subagent ${event.kind} notification failed: ${message}`, "warning");
|
|
409
|
+
},
|
|
405
410
|
onEvent: (event) => {
|
|
406
411
|
if (token !== generation) return;
|
|
407
412
|
refreshWidget(requireContext());
|
|
@@ -473,7 +478,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
473
478
|
manager = undefined;
|
|
474
479
|
context = undefined;
|
|
475
480
|
});
|
|
476
|
-
const agentSubcommands = ["tree", "
|
|
481
|
+
const agentSubcommands = ["tree", "settings", "types", "import", "reload", "reap"] as const;
|
|
477
482
|
pi.registerCommand("agents", {
|
|
478
483
|
description: "Configure agent settings, import/edit definitions, or show the live tree",
|
|
479
484
|
getArgumentCompletions: (argumentText) => {
|
|
@@ -500,7 +505,10 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
500
505
|
if (command === "import") {
|
|
501
506
|
await importAgents(ctx, false);
|
|
502
507
|
} else if (command === "types") {
|
|
503
|
-
await editAgentTypes(ctx, store, limits.nerdFontIcons
|
|
508
|
+
await editAgentTypes(ctx, store, limits.nerdFontIcons, {
|
|
509
|
+
getAllTools: () => pi.getAllTools(),
|
|
510
|
+
toolFiltering: limits.toolFiltering,
|
|
511
|
+
});
|
|
504
512
|
store.reload();
|
|
505
513
|
} else if (command === "reload") {
|
|
506
514
|
store.reload();
|
|
@@ -520,6 +528,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
520
528
|
store,
|
|
521
529
|
settings: limits,
|
|
522
530
|
agentDir: getAgentDir(),
|
|
531
|
+
getAllTools: () => pi.getAllTools(),
|
|
523
532
|
apply: () => {
|
|
524
533
|
const diagnostics = loadLimits(ctx);
|
|
525
534
|
requireManager().setLimits(limits);
|
|
@@ -529,13 +538,35 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
529
538
|
if (diagnostics.length) ctx.ui.notify(diagnostics.join("\n"), "warning");
|
|
530
539
|
},
|
|
531
540
|
});
|
|
532
|
-
} else if (command === "
|
|
533
|
-
|
|
541
|
+
} else if (command === "reap") {
|
|
542
|
+
const current = requireManager();
|
|
543
|
+
const candidates = current.reapCandidates();
|
|
544
|
+
if (!candidates.length) {
|
|
545
|
+
ctx.ui.notify("No completed agents eligible for reaping.", "info");
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
if (!canOpenDialog(ctx)) return;
|
|
549
|
+
closeNavigation();
|
|
550
|
+
const warning = `${candidates.length} completed agent${candidates.length === 1 ? "" : "s"} will be reaped.\nYou will not be able to resume them anymore.`;
|
|
551
|
+
const choice = await dialogMenu(ctx, "Reap completed agents?", [
|
|
552
|
+
{ id: "confirm", label: "Confirm", help: warning },
|
|
553
|
+
{ id: "cancel", label: "Cancel", help: warning },
|
|
554
|
+
], { selectedId: "cancel" });
|
|
555
|
+
if (choice !== "confirm" || manager !== current) return;
|
|
556
|
+
const reaped = current.reap(candidates);
|
|
557
|
+
persist();
|
|
558
|
+
refreshWidget(ctx);
|
|
559
|
+
ctx.ui.notify(
|
|
560
|
+
reaped.length
|
|
561
|
+
? `Reaped ${reaped.length} completed agent(s); their sessions can no longer be resumed.`
|
|
562
|
+
: "No completed agents eligible for reaping.",
|
|
563
|
+
"info",
|
|
564
|
+
);
|
|
534
565
|
} else if (command === "tree") {
|
|
535
|
-
await navigation.open(ctx, requireManager().scope("/root"), rest.join(" ") || undefined, limits.nerdFontIcons);
|
|
566
|
+
await navigation.open(ctx, requireManager().scope("/root"), rest.join(" ") || undefined, limits.nerdFontIcons, limits.loaderStyle);
|
|
536
567
|
} else
|
|
537
568
|
ctx.ui.notify(
|
|
538
|
-
"Usage: /agents [tree [path] |
|
|
569
|
+
"Usage: /agents [tree [path] | settings | types | import | reload | reap]",
|
|
539
570
|
"warning",
|
|
540
571
|
);
|
|
541
572
|
},
|
package/src/orch/manager.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
SavedThread,
|
|
8
8
|
SavedThreadView,
|
|
9
9
|
ThreadService,
|
|
10
|
+
ThreadEvent,
|
|
10
11
|
ThreadView,
|
|
11
12
|
TranscriptListener,
|
|
12
13
|
TranscriptObservation,
|
|
@@ -83,6 +84,50 @@ export class ThreadManager {
|
|
|
83
84
|
return [...this.records.values()].map((record) => this.view(record));
|
|
84
85
|
}
|
|
85
86
|
|
|
87
|
+
/** Preview eligible completed sessions without changing retained records. */
|
|
88
|
+
reapCandidates(only?: readonly string[]): string[] {
|
|
89
|
+
this.assertLive();
|
|
90
|
+
const records = [...this.records.values()];
|
|
91
|
+
const eligible = new Set(
|
|
92
|
+
records
|
|
93
|
+
.filter((record) => !only || only.includes(record.view.path))
|
|
94
|
+
.filter((record) => record.view.state === "completed" && (!record.initializing || record.driver))
|
|
95
|
+
.filter((record) =>
|
|
96
|
+
!records.some(
|
|
97
|
+
(other) => active(other.view) && isDescendant(record.view.path, other.view.path),
|
|
98
|
+
),
|
|
99
|
+
)
|
|
100
|
+
.map((record) => record.view.path),
|
|
101
|
+
);
|
|
102
|
+
// Any retained descendant still needs its lexical ancestors.
|
|
103
|
+
for (const record of records) {
|
|
104
|
+
if (eligible.has(record.view.path)) continue;
|
|
105
|
+
let parent = record.view.parent;
|
|
106
|
+
while (parent && parent !== "/root") {
|
|
107
|
+
eligible.delete(parent);
|
|
108
|
+
parent = this.records.get(parent)?.view.parent ?? null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return records
|
|
112
|
+
.filter((record) => eligible.has(record.view.path))
|
|
113
|
+
.sort((a, b) => a.view.createdAt - b.view.createdAt)
|
|
114
|
+
.map((record) => record.view.path);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Revalidate an optional confirmed snapshot before forgetting sessions. */
|
|
118
|
+
reap(only?: readonly string[]): string[] {
|
|
119
|
+
const reaped: string[] = [];
|
|
120
|
+
for (const path of this.reapCandidates(only)) {
|
|
121
|
+
const record = this.records.get(path)!;
|
|
122
|
+
record.detachTranscript?.();
|
|
123
|
+
record.transcriptListeners?.clear();
|
|
124
|
+
record.driver?.dispose();
|
|
125
|
+
this.records.delete(record.view.path);
|
|
126
|
+
reaped.push(record.view.path);
|
|
127
|
+
}
|
|
128
|
+
return reaped;
|
|
129
|
+
}
|
|
130
|
+
|
|
86
131
|
/** Bind authority once; models and the user UI share this small composable service. */
|
|
87
132
|
scope(caller: string): ThreadService {
|
|
88
133
|
caller = canonicalPath(caller);
|
|
@@ -143,6 +188,7 @@ export class ThreadManager {
|
|
|
143
188
|
output: current.output,
|
|
144
189
|
error: current.error,
|
|
145
190
|
createdAt: current.createdAt,
|
|
191
|
+
...(current.lastStartedAt !== undefined ? { lastStartedAt: current.lastStartedAt } : {}),
|
|
146
192
|
sessionFile: current.sessionFile,
|
|
147
193
|
// Settled totals only. startedAt and partial usage must not churn persistence.
|
|
148
194
|
elapsedMs: record.view.elapsedMs ?? 0,
|
|
@@ -357,7 +403,7 @@ export class ThreadManager {
|
|
|
357
403
|
throw new Error("Progress message must contain 1–8000 characters");
|
|
358
404
|
record.view.status = message;
|
|
359
405
|
this.touch(record);
|
|
360
|
-
this.
|
|
406
|
+
this.emit({
|
|
361
407
|
kind: "update",
|
|
362
408
|
thread: this.view(record),
|
|
363
409
|
message,
|
|
@@ -475,6 +521,7 @@ export class ThreadManager {
|
|
|
475
521
|
record.view.state = "starting";
|
|
476
522
|
record.view.status = "Starting";
|
|
477
523
|
record.view.startedAt = Date.now();
|
|
524
|
+
record.view.lastStartedAt = record.view.startedAt;
|
|
478
525
|
delete record.view.output;
|
|
479
526
|
delete record.view.error;
|
|
480
527
|
const epoch = this.epoch;
|
|
@@ -519,7 +566,7 @@ export class ThreadManager {
|
|
|
519
566
|
markStarted(); // Failed/cancelled initialization must also release callers waiting to steer.
|
|
520
567
|
this.touch(record);
|
|
521
568
|
if (!this.disposed && epoch === this.epoch)
|
|
522
|
-
this.
|
|
569
|
+
this.emit({
|
|
523
570
|
kind: "settled",
|
|
524
571
|
thread: this.view(record),
|
|
525
572
|
recipient: record.view.parent ?? record.view.owner,
|
|
@@ -639,10 +686,24 @@ export class ThreadManager {
|
|
|
639
686
|
}
|
|
640
687
|
}
|
|
641
688
|
}
|
|
689
|
+
private emit(event: ThreadEvent): void {
|
|
690
|
+
try {
|
|
691
|
+
this.options.onEvent?.(event);
|
|
692
|
+
} catch (error) {
|
|
693
|
+
// Widgets/persistence/delivery run on the runner's event path. An exception
|
|
694
|
+
// here must not orphan a prompt promise or reject detached settlement.
|
|
695
|
+
try {
|
|
696
|
+
if (this.options.onEventError) this.options.onEventError(error, event);
|
|
697
|
+
else console.warn(`Subagent ${event.kind} notification failed: ${errorText(error)}`);
|
|
698
|
+
} catch {
|
|
699
|
+
/* A failing diagnostic sink must not turn a notification into a crash. */
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
}
|
|
642
703
|
private touch(record: Record): void {
|
|
643
704
|
record.view.updatedAt = Date.now();
|
|
644
705
|
this.publishTranscript(record);
|
|
645
|
-
if (!this.disposed) this.
|
|
706
|
+
if (!this.disposed) this.emit({ kind: "change", thread: this.view(record) });
|
|
646
707
|
}
|
|
647
708
|
/** Fold driver-cumulative usage into persisted totals. Partials only refresh the live view. */
|
|
648
709
|
private applyUsage(
|
|
@@ -656,7 +717,7 @@ export class ThreadManager {
|
|
|
656
717
|
if (input === record.liveInputTokens && output === record.liveOutputTokens) return;
|
|
657
718
|
record.liveInputTokens = input;
|
|
658
719
|
record.liveOutputTokens = output;
|
|
659
|
-
if (!this.disposed) this.
|
|
720
|
+
if (!this.disposed) this.emit({ kind: "metrics", thread: this.view(record) });
|
|
660
721
|
return;
|
|
661
722
|
}
|
|
662
723
|
record.view.inputTokens =
|
package/src/prefs/settings.ts
CHANGED
|
@@ -19,6 +19,9 @@ export type SubagentMode = (typeof SUBAGENT_MODES)[number];
|
|
|
19
19
|
export const WIDGET_MODES = ["full", "minimal"] as const;
|
|
20
20
|
export type WidgetMode = (typeof WIDGET_MODES)[number];
|
|
21
21
|
|
|
22
|
+
export const LOADER_STYLES = ["circle", "braille", "hourglass"] as const;
|
|
23
|
+
export type LoaderStyle = (typeof LOADER_STYLES)[number];
|
|
24
|
+
|
|
22
25
|
export const TOOL_FILTERING_MODES = ["allowed", "all-except-blocked", "all"] as const;
|
|
23
26
|
export type ToolFilteringMode = (typeof TOOL_FILTERING_MODES)[number];
|
|
24
27
|
|
|
@@ -34,6 +37,7 @@ export interface ManagerSettings {
|
|
|
34
37
|
toolFiltering: ToolFilteringMode;
|
|
35
38
|
widgetMode: WidgetMode;
|
|
36
39
|
nerdFontIcons: boolean;
|
|
40
|
+
loaderStyle: LoaderStyle;
|
|
37
41
|
finalRecap: boolean;
|
|
38
42
|
maxLevels: number;
|
|
39
43
|
maxConcurrent: number;
|
|
@@ -50,11 +54,12 @@ export const DEFAULT_MANAGER_SETTINGS: ManagerSettings = {
|
|
|
50
54
|
toolFiltering: "allowed",
|
|
51
55
|
widgetMode: "full",
|
|
52
56
|
nerdFontIcons: false,
|
|
57
|
+
loaderStyle: "circle",
|
|
53
58
|
finalRecap: false,
|
|
54
59
|
};
|
|
55
60
|
|
|
56
61
|
const KEYS = [
|
|
57
|
-
"maxLevels", "maxConcurrent", "maxThreads", "modelSelection", "subagentMode", "toolFiltering", "widgetMode", "nerdFontIcons", "finalRecap",
|
|
62
|
+
"maxLevels", "maxConcurrent", "maxThreads", "modelSelection", "subagentMode", "toolFiltering", "widgetMode", "nerdFontIcons", "loaderStyle", "finalRecap",
|
|
58
63
|
] as const;
|
|
59
64
|
const MAX_LEVELS = 32;
|
|
60
65
|
|
|
@@ -95,6 +100,7 @@ function requirement(key: (typeof KEYS)[number]): string {
|
|
|
95
100
|
if (key === "nerdFontIcons" || key === "finalRecap") return `${key} must be a boolean`;
|
|
96
101
|
if (key === "subagentMode") return "subagentMode must be off, opportunistic or orchestration";
|
|
97
102
|
if (key === "widgetMode") return "widgetMode must be full or minimal";
|
|
103
|
+
if (key === "loaderStyle") return "loaderStyle must be circle, braille or hourglass";
|
|
98
104
|
if (key === "toolFiltering") return "toolFiltering must be allowed, all-except-blocked or all";
|
|
99
105
|
if (key === "modelSelection")
|
|
100
106
|
return "modelSelection must be pick-first-available, pick-first-scoped or use-current";
|
|
@@ -148,6 +154,11 @@ function parseSettings(content: string): Partial<ManagerSettings> {
|
|
|
148
154
|
layer.widgetMode = value as WidgetMode;
|
|
149
155
|
continue;
|
|
150
156
|
}
|
|
157
|
+
if (key === "loaderStyle") {
|
|
158
|
+
if (!LOADER_STYLES.includes(value as LoaderStyle)) throw new Error(requirement(key));
|
|
159
|
+
layer.loaderStyle = value as LoaderStyle;
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
151
162
|
if (key === "modelSelection") {
|
|
152
163
|
if (!MODEL_SELECTION_MODES.includes(value as ModelSelectionMode))
|
|
153
164
|
throw new Error(requirement(key));
|
package/src/types.ts
CHANGED
|
@@ -61,6 +61,8 @@ export interface ThreadView {
|
|
|
61
61
|
elapsedMs?: number;
|
|
62
62
|
/** Current run start. Live only; omitted from saved views so reloads do not count offline time. */
|
|
63
63
|
startedAt?: number;
|
|
64
|
+
/** Most recent run start (spawn or resume). Persisted; orders the agent tree newest-first. */
|
|
65
|
+
lastStartedAt?: number;
|
|
64
66
|
/** Cumulative input tokens, including cache read/write. Live views include the in-progress message. */
|
|
65
67
|
inputTokens?: number;
|
|
66
68
|
/** Cumulative output tokens. Live views include the in-progress message. */
|
|
@@ -152,6 +154,7 @@ export interface SavedThreadView {
|
|
|
152
154
|
sessionLeafId?: string | null;
|
|
153
155
|
/** Frozen cumulative active time. `startedAt` is intentionally not persisted. */
|
|
154
156
|
elapsedMs?: number;
|
|
157
|
+
lastStartedAt?: number;
|
|
155
158
|
inputTokens?: number;
|
|
156
159
|
outputTokens?: number;
|
|
157
160
|
}
|
|
@@ -190,6 +193,8 @@ export interface ManagerOptions {
|
|
|
190
193
|
getType(name: string): AgentType;
|
|
191
194
|
toolsFor(path: string): ToolDefinition[];
|
|
192
195
|
onEvent?(event: ThreadEvent): void;
|
|
196
|
+
/** Notification failures are diagnostic only; they must never interrupt a runner. */
|
|
197
|
+
onEventError?(error: unknown, event: ThreadEvent): void;
|
|
193
198
|
/** Maximum levels including the main conversation as L1; defaults to 3. */
|
|
194
199
|
maxLevels?: number;
|
|
195
200
|
/** @deprecated Internal legacy path-depth override; prefer maxLevels. */
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { LoaderStyle } from "../prefs/settings.ts";
|
|
2
|
+
import type { ThreadView } from "../types.ts";
|
|
3
|
+
|
|
4
|
+
export const AGENT_PROGRESS_INTERVAL = 180;
|
|
5
|
+
|
|
6
|
+
type SettledState = Exclude<ThreadView["state"], "starting" | "running">;
|
|
7
|
+
|
|
8
|
+
/** Built-in glyphs only; role icons are validated separately and never replaced. */
|
|
9
|
+
export const AGENT_LOADERS: Record<
|
|
10
|
+
LoaderStyle,
|
|
11
|
+
{
|
|
12
|
+
label: string;
|
|
13
|
+
frames: readonly string[];
|
|
14
|
+
states: Record<SettledState, string>;
|
|
15
|
+
}
|
|
16
|
+
> = {
|
|
17
|
+
circle: {
|
|
18
|
+
label: "Circle",
|
|
19
|
+
// Nerd Fonts md-circle-slice-1..8, check-circle, pause-circle, close-circle, stop-circle.
|
|
20
|
+
frames: Array.from({ length: 8 }, (_, index) => String.fromCodePoint(0xf0a9e + index)),
|
|
21
|
+
states: {
|
|
22
|
+
completed: "\u{f05e0}",
|
|
23
|
+
paused: "\u{f03e5}",
|
|
24
|
+
failed: "\u{f0159}",
|
|
25
|
+
stopped: "\u{f0666}",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
braille: {
|
|
29
|
+
label: "Braille",
|
|
30
|
+
frames: Array.from("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"),
|
|
31
|
+
states: { completed: "✓", paused: "Ⅱ", failed: "×", stopped: "■" },
|
|
32
|
+
},
|
|
33
|
+
hourglass: {
|
|
34
|
+
label: "Hourglass",
|
|
35
|
+
// Nerd Fonts fa-hourglass-start/half/end, check-square, pause, times-circle, stop.
|
|
36
|
+
frames: ["\uf251", "\uf252", "\uf253"],
|
|
37
|
+
states: { completed: "\uf14a", paused: "\uf04c", failed: "\uf057", stopped: "\uf04d" },
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** RPC/non-animated hosts use the first running frame and all settled indicators. */
|
|
42
|
+
export function agentProgressIcon(
|
|
43
|
+
thread: Pick<ThreadView, "state">,
|
|
44
|
+
nerdFontIcons: boolean,
|
|
45
|
+
now = Date.now(),
|
|
46
|
+
animate = true,
|
|
47
|
+
loaderStyle: LoaderStyle = "circle",
|
|
48
|
+
): string | undefined {
|
|
49
|
+
if (!nerdFontIcons) return undefined;
|
|
50
|
+
const loader = AGENT_LOADERS[loaderStyle];
|
|
51
|
+
if (thread.state === "starting" || thread.state === "running") {
|
|
52
|
+
const index = animate ? Math.floor(Math.max(0, now) / AGENT_PROGRESS_INTERVAL) : 0;
|
|
53
|
+
return loader.frames[index % loader.frames.length];
|
|
54
|
+
}
|
|
55
|
+
return loader.states[thread.state];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Restrict the separate label prefix to trusted, single built-in loader glyphs. */
|
|
59
|
+
export function isAgentLoaderGlyph(glyph: string): boolean {
|
|
60
|
+
return Object.values(AGENT_LOADERS).some(
|
|
61
|
+
(loader) => loader.frames.includes(glyph) || Object.values(loader.states).includes(glyph),
|
|
62
|
+
);
|
|
63
|
+
}
|