pi-subagent-manager 0.14.0 → 0.15.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 +1 -1
- package/docs/custom-agents.md +3 -0
- package/docs/settings.md +8 -1
- package/docs/tools-and-ui.md +2 -2
- package/package.json +1 -1
- package/src/index.ts +8 -4
- package/src/orch/manager.ts +21 -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 +25 -1
- package/src/ui/status-ui.ts +14 -8
- package/src/ui/thread-tree.ts +37 -11
- package/src/ui/ui.ts +65 -119
package/README.md
CHANGED
|
@@ -74,7 +74,7 @@ They inherit your current model until you set preferences. Details: [docs/defaul
|
|
|
74
74
|
|
|
75
75
|
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
76
|
|
|
77
|
-
Experimental features are marked **[labs]** in settings. Enable **[labs] Nerd Font icons** in `/agents` to show role-specific icons beside agent names,
|
|
77
|
+
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
78
|
|
|
79
79
|
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
80
|
|
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
|
@@ -98,10 +98,10 @@ In full mode:
|
|
|
98
98
|
|
|
99
99
|
- One row per agent: colored type pill, path, state, task, active time, input `↑` / output `↓` tokens.
|
|
100
100
|
- 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
|
-
-
|
|
101
|
+
- 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
102
|
- Time freezes while paused and resumes on continue.
|
|
103
103
|
- 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,
|
|
104
|
+
- 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
105
|
|
|
106
106
|
### Interrupts and stopping agents
|
|
107
107
|
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -96,7 +96,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
96
96
|
manager.list().some((thread) => thread.path !== "/root" &&
|
|
97
97
|
(thread.state === "starting" || thread.state === "running")),
|
|
98
98
|
openTree: () => manager && context
|
|
99
|
-
? navigation.open(context, manager.scope("/root"), undefined, limits.nerdFontIcons) : undefined,
|
|
99
|
+
? navigation.open(context, manager.scope("/root"), undefined, limits.nerdFontIcons, limits.loaderStyle) : undefined,
|
|
100
100
|
canCollapse: () => manager !== undefined && context?.mode === "tui" &&
|
|
101
101
|
limits.subagentMode !== "off" && !navigation.isOpen && !widgetCollapsed &&
|
|
102
102
|
limits.widgetMode === "full" && widgetThreads().some((thread) => thread.path !== "/root"),
|
|
@@ -335,7 +335,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
335
335
|
if (limits.subagentMode === "off") {
|
|
336
336
|
if (ctx.hasUI) ctx.ui.setWidget("pi-subagent", undefined);
|
|
337
337
|
} else updateWidget(ctx, widgetThreads(), widgetCollapsed ? "minimal" : limits.widgetMode,
|
|
338
|
-
limits.nerdFontIcons, rootTurnEnded);
|
|
338
|
+
limits.nerdFontIcons, rootTurnEnded, limits.loaderStyle);
|
|
339
339
|
};
|
|
340
340
|
pi.on("agent_start", async (_event, ctx) => {
|
|
341
341
|
// A new task must not resurrect the previous task's settled agents. Automatic
|
|
@@ -402,6 +402,10 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
402
402
|
rootSnapshot: () => buildSessionContext(requireContext().sessionManager.getBranch()).messages,
|
|
403
403
|
getType: (name) => store.get(name),
|
|
404
404
|
toolsFor,
|
|
405
|
+
onEventError: (error, event) => {
|
|
406
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
407
|
+
context?.ui.notify(`Subagent ${event.kind} notification failed: ${message}`, "warning");
|
|
408
|
+
},
|
|
405
409
|
onEvent: (event) => {
|
|
406
410
|
if (token !== generation) return;
|
|
407
411
|
refreshWidget(requireContext());
|
|
@@ -530,9 +534,9 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
530
534
|
},
|
|
531
535
|
});
|
|
532
536
|
} else if (command === "status") {
|
|
533
|
-
await showAgentStatus(ctx, requireManager().scope("/root"), undefined, limits.nerdFontIcons);
|
|
537
|
+
await showAgentStatus(ctx, requireManager().scope("/root"), undefined, limits.nerdFontIcons, limits.loaderStyle);
|
|
534
538
|
} else if (command === "tree") {
|
|
535
|
-
await navigation.open(ctx, requireManager().scope("/root"), rest.join(" ") || undefined, limits.nerdFontIcons);
|
|
539
|
+
await navigation.open(ctx, requireManager().scope("/root"), rest.join(" ") || undefined, limits.nerdFontIcons, limits.loaderStyle);
|
|
536
540
|
} else
|
|
537
541
|
ctx.ui.notify(
|
|
538
542
|
"Usage: /agents [tree [path] | status | settings | types | import | reload]",
|
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,
|
|
@@ -143,6 +144,7 @@ export class ThreadManager {
|
|
|
143
144
|
output: current.output,
|
|
144
145
|
error: current.error,
|
|
145
146
|
createdAt: current.createdAt,
|
|
147
|
+
...(current.lastStartedAt !== undefined ? { lastStartedAt: current.lastStartedAt } : {}),
|
|
146
148
|
sessionFile: current.sessionFile,
|
|
147
149
|
// Settled totals only. startedAt and partial usage must not churn persistence.
|
|
148
150
|
elapsedMs: record.view.elapsedMs ?? 0,
|
|
@@ -357,7 +359,7 @@ export class ThreadManager {
|
|
|
357
359
|
throw new Error("Progress message must contain 1–8000 characters");
|
|
358
360
|
record.view.status = message;
|
|
359
361
|
this.touch(record);
|
|
360
|
-
this.
|
|
362
|
+
this.emit({
|
|
361
363
|
kind: "update",
|
|
362
364
|
thread: this.view(record),
|
|
363
365
|
message,
|
|
@@ -475,6 +477,7 @@ export class ThreadManager {
|
|
|
475
477
|
record.view.state = "starting";
|
|
476
478
|
record.view.status = "Starting";
|
|
477
479
|
record.view.startedAt = Date.now();
|
|
480
|
+
record.view.lastStartedAt = record.view.startedAt;
|
|
478
481
|
delete record.view.output;
|
|
479
482
|
delete record.view.error;
|
|
480
483
|
const epoch = this.epoch;
|
|
@@ -519,7 +522,7 @@ export class ThreadManager {
|
|
|
519
522
|
markStarted(); // Failed/cancelled initialization must also release callers waiting to steer.
|
|
520
523
|
this.touch(record);
|
|
521
524
|
if (!this.disposed && epoch === this.epoch)
|
|
522
|
-
this.
|
|
525
|
+
this.emit({
|
|
523
526
|
kind: "settled",
|
|
524
527
|
thread: this.view(record),
|
|
525
528
|
recipient: record.view.parent ?? record.view.owner,
|
|
@@ -639,10 +642,24 @@ export class ThreadManager {
|
|
|
639
642
|
}
|
|
640
643
|
}
|
|
641
644
|
}
|
|
645
|
+
private emit(event: ThreadEvent): void {
|
|
646
|
+
try {
|
|
647
|
+
this.options.onEvent?.(event);
|
|
648
|
+
} catch (error) {
|
|
649
|
+
// Widgets/persistence/delivery run on the runner's event path. An exception
|
|
650
|
+
// here must not orphan a prompt promise or reject detached settlement.
|
|
651
|
+
try {
|
|
652
|
+
if (this.options.onEventError) this.options.onEventError(error, event);
|
|
653
|
+
else console.warn(`Subagent ${event.kind} notification failed: ${errorText(error)}`);
|
|
654
|
+
} catch {
|
|
655
|
+
/* A failing diagnostic sink must not turn a notification into a crash. */
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
642
659
|
private touch(record: Record): void {
|
|
643
660
|
record.view.updatedAt = Date.now();
|
|
644
661
|
this.publishTranscript(record);
|
|
645
|
-
if (!this.disposed) this.
|
|
662
|
+
if (!this.disposed) this.emit({ kind: "change", thread: this.view(record) });
|
|
646
663
|
}
|
|
647
664
|
/** Fold driver-cumulative usage into persisted totals. Partials only refresh the live view. */
|
|
648
665
|
private applyUsage(
|
|
@@ -656,7 +673,7 @@ export class ThreadManager {
|
|
|
656
673
|
if (input === record.liveInputTokens && output === record.liveOutputTokens) return;
|
|
657
674
|
record.liveInputTokens = input;
|
|
658
675
|
record.liveOutputTokens = output;
|
|
659
|
-
if (!this.disposed) this.
|
|
676
|
+
if (!this.disposed) this.emit({ kind: "metrics", thread: this.view(record) });
|
|
660
677
|
return;
|
|
661
678
|
}
|
|
662
679
|
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, pause, times-circle, stop.
|
|
36
|
+
frames: ["\uf251", "\uf252", "\uf253"],
|
|
37
|
+
states: { completed: "\uf253", 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
|
+
}
|
|
@@ -14,6 +14,9 @@ import {
|
|
|
14
14
|
import type { ThreadService, TranscriptSnapshot } from "../types.ts";
|
|
15
15
|
import { dialogText, type DialogHost } from "./dialog.ts";
|
|
16
16
|
import { AGENT_PROGRESS_INTERVAL, agentProgressIcon, agentTypeLabel } from "./ui.ts";
|
|
17
|
+
import type { LoaderStyle } from "../prefs/settings.ts";
|
|
18
|
+
|
|
19
|
+
type ThemeBg = Parameters<Theme["bg"]>[0];
|
|
17
20
|
|
|
18
21
|
/** Transcript detail level cycled by the t key: full → preview → compact. */
|
|
19
22
|
export type TranscriptDetail = "full" | "preview" | "compact";
|
|
@@ -65,7 +68,10 @@ export class LiveAgentView {
|
|
|
65
68
|
private unsubscribe: (() => void) | undefined;
|
|
66
69
|
private renderTimer: ReturnType<typeof setTimeout> | undefined;
|
|
67
70
|
private progressTimer: ReturnType<typeof setInterval> | undefined;
|
|
68
|
-
private cache = new WeakMap<
|
|
71
|
+
private cache = new WeakMap<
|
|
72
|
+
object,
|
|
73
|
+
{ width: number; detail: TranscriptDetail; lines: string[] }
|
|
74
|
+
>();
|
|
69
75
|
private scroll: ScrollView;
|
|
70
76
|
private content: string[] = [];
|
|
71
77
|
private restoreViewport = true;
|
|
@@ -86,6 +92,7 @@ export class LiveAgentView {
|
|
|
86
92
|
private viewport: AgentViewportState,
|
|
87
93
|
private done: (result: "back" | "main") => void,
|
|
88
94
|
private nerdFontIcons = false,
|
|
95
|
+
private loaderStyle: LoaderStyle = "circle",
|
|
89
96
|
) {
|
|
90
97
|
this.scroll = new ScrollView(
|
|
91
98
|
{ render: () => this.content, invalidate() {} },
|
|
@@ -187,7 +194,10 @@ export class LiveAgentView {
|
|
|
187
194
|
|
|
188
195
|
private syncProgress(): void {
|
|
189
196
|
const state = this.snapshot?.thread?.state;
|
|
190
|
-
const active =
|
|
197
|
+
const active =
|
|
198
|
+
this.nerdFontIcons &&
|
|
199
|
+
!this.disposed &&
|
|
200
|
+
!this.error &&
|
|
191
201
|
(state === "starting" || state === "running");
|
|
192
202
|
if (!active) {
|
|
193
203
|
if (this.progressTimer !== undefined) clearInterval(this.progressTimer);
|
|
@@ -275,6 +285,23 @@ export class LiveAgentView {
|
|
|
275
285
|
return this.viewport.detail ?? "preview";
|
|
276
286
|
}
|
|
277
287
|
|
|
288
|
+
/** One column of horizontal padding on each side of the transcript. */
|
|
289
|
+
private pad(lines: string[]): string[] {
|
|
290
|
+
return lines.map((line) => ` ${line}`);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** Full-width themed band with one column of padding, like pi's tool boxes. */
|
|
294
|
+
private band(lines: string[], token: ThemeBg, width: number): string[] {
|
|
295
|
+
const inner = Math.max(1, width - 2);
|
|
296
|
+
return lines.map((line) => {
|
|
297
|
+
const clipped = truncateToWidth(line, inner, "", true);
|
|
298
|
+
return this.theme.bg(
|
|
299
|
+
token,
|
|
300
|
+
` ${clipped}${" ".repeat(Math.max(0, inner - visibleWidth(clipped)))} `,
|
|
301
|
+
);
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
|
|
278
305
|
private wrap(value: string, width: number): string[] {
|
|
279
306
|
return text(value)
|
|
280
307
|
.split("\n")
|
|
@@ -320,28 +347,39 @@ export class LiveAgentView {
|
|
|
320
347
|
return lines;
|
|
321
348
|
}
|
|
322
349
|
|
|
350
|
+
/** Renders padded rows: `width` is the full transcript width. Tool calls get a themed band. */
|
|
323
351
|
private blocks(content: unknown, width: number): string[] {
|
|
324
|
-
|
|
325
|
-
if (!Array.isArray(content)) return this.
|
|
352
|
+
const inner = Math.max(1, width - 2);
|
|
353
|
+
if (!Array.isArray(content)) return this.pad(this.blockLines(content, inner));
|
|
326
354
|
return content.flatMap((value) => {
|
|
327
355
|
const block = object(value);
|
|
328
|
-
if (
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
const rendered = this.markdown(String(block.thinking ?? "[redacted thinking]"), width, true);
|
|
336
|
-
if (this.detail === "full" || rendered.length <= 3) return rendered;
|
|
337
|
-
return [...rendered.slice(0, 3), this.theme.fg("dim", "...")];
|
|
338
|
-
}
|
|
339
|
-
if (block.type === "toolCall")
|
|
340
|
-
return this.toolCall(String(block.name), block.arguments, width);
|
|
341
|
-
return this.preview(json(block), width);
|
|
356
|
+
if (block?.type === "toolCall")
|
|
357
|
+
return this.band(
|
|
358
|
+
this.toolCall(String(block.name), block.arguments, inner),
|
|
359
|
+
"toolSuccessBg",
|
|
360
|
+
width,
|
|
361
|
+
);
|
|
362
|
+
return this.pad(this.blockLines(value, inner));
|
|
342
363
|
});
|
|
343
364
|
}
|
|
344
365
|
|
|
366
|
+
private blockLines(value: unknown, width: number): string[] {
|
|
367
|
+
if (typeof value === "string") return this.markdown(value, width);
|
|
368
|
+
const block = object(value);
|
|
369
|
+
if (!block) return this.wrap(json(value), width);
|
|
370
|
+
if (block.type === "text") return this.markdown(String(block.text ?? ""), width);
|
|
371
|
+
if (block.type === "image") return ["[Image — text-only observer]"];
|
|
372
|
+
if (block.type === "thinking") {
|
|
373
|
+
if (this.detail === "compact")
|
|
374
|
+
return [this.theme.fg("dim", "[Thinking hidden · t cycles view]")];
|
|
375
|
+
// Thinking is model-authored Markdown; preview truncates the rendered lines, not the source.
|
|
376
|
+
const rendered = this.markdown(String(block.thinking ?? "[redacted thinking]"), width, true);
|
|
377
|
+
if (this.detail === "full" || rendered.length <= 3) return rendered;
|
|
378
|
+
return [...rendered.slice(0, 3), this.theme.fg("dim", "...")];
|
|
379
|
+
}
|
|
380
|
+
return this.preview(json(block), width);
|
|
381
|
+
}
|
|
382
|
+
|
|
345
383
|
private message(message: AgentMessage, width: number): string[] {
|
|
346
384
|
const cached = this.cache.get(message);
|
|
347
385
|
if (cached && cached.width === width && cached.detail === this.detail) return cached.lines;
|
|
@@ -352,17 +390,30 @@ export class LiveAgentView {
|
|
|
352
390
|
: message.role;
|
|
353
391
|
const collapsed = !["user", "assistant", "custom"].includes(message.role);
|
|
354
392
|
const content = data.content ?? data.summary ?? data.output ?? data;
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
""
|
|
365
|
-
|
|
393
|
+
const inner = Math.max(1, width - 2);
|
|
394
|
+
const heading = this.theme.fg(data.isError ? "error" : "accent", dialogText(label));
|
|
395
|
+
const errors = data.errorMessage
|
|
396
|
+
? (collapsed
|
|
397
|
+
? this.preview(String(data.errorMessage), inner)
|
|
398
|
+
: this.wrap(String(data.errorMessage), inner)
|
|
399
|
+
).map((line) => this.theme.fg("error", line))
|
|
400
|
+
: [];
|
|
401
|
+
const lines =
|
|
402
|
+
message.role === "toolResult"
|
|
403
|
+
? [
|
|
404
|
+
...this.band(
|
|
405
|
+
[heading, ...this.preview(content, inner), ...errors],
|
|
406
|
+
data.isError ? "toolErrorBg" : "customMessageBg",
|
|
407
|
+
width,
|
|
408
|
+
),
|
|
409
|
+
"",
|
|
410
|
+
]
|
|
411
|
+
: [
|
|
412
|
+
...this.pad([heading]),
|
|
413
|
+
...(collapsed ? this.pad(this.preview(content, inner)) : this.blocks(content, width)),
|
|
414
|
+
...this.pad(errors),
|
|
415
|
+
"",
|
|
416
|
+
];
|
|
366
417
|
this.cache.set(message, { width, detail: this.detail, lines });
|
|
367
418
|
return lines;
|
|
368
419
|
}
|
|
@@ -448,7 +499,9 @@ export class LiveAgentView {
|
|
|
448
499
|
}
|
|
449
500
|
case "ls": {
|
|
450
501
|
const limit = num("limit");
|
|
451
|
-
lines = [
|
|
502
|
+
lines = [
|
|
503
|
+
`${title("ls")} ${path ?? "."}${limit != null ? detail(` (limit ${limit})`) : ""}`,
|
|
504
|
+
];
|
|
452
505
|
break;
|
|
453
506
|
}
|
|
454
507
|
default:
|
|
@@ -474,34 +527,36 @@ export class LiveAgentView {
|
|
|
474
527
|
const columns = Math.max(1, width);
|
|
475
528
|
const snapshot = this.snapshot;
|
|
476
529
|
const thread = snapshot?.thread;
|
|
530
|
+
const inner = Math.max(1, columns - 2);
|
|
477
531
|
const header = this.theme.fg(
|
|
478
532
|
"accent",
|
|
479
533
|
dialogText(
|
|
480
|
-
`${this.path} · ${agentTypeLabel(thread?.type ?? "agent", thread ? agentProgressIcon(thread, this.nerdFontIcons)
|
|
534
|
+
`${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`,
|
|
481
535
|
),
|
|
482
536
|
);
|
|
483
537
|
const body: string[] = [];
|
|
484
538
|
if (this.error)
|
|
485
539
|
body.push(
|
|
486
|
-
this.theme.fg("error", dialogText(`Attachment error: ${this.error}`))
|
|
487
|
-
"Ctrl+R Retry · Esc Back · Ctrl+Q Back to main",
|
|
540
|
+
` ${this.theme.fg("error", dialogText(`Attachment error: ${this.error}`))}`,
|
|
541
|
+
" Ctrl+R Retry · Esc Back · Ctrl+Q Back to main",
|
|
488
542
|
);
|
|
489
543
|
if (!snapshot) {
|
|
490
|
-
if (!this.error) body.push("Attaching to retained live session…");
|
|
544
|
+
if (!this.error) body.push(" Attaching to retained live session…");
|
|
491
545
|
} else {
|
|
492
546
|
if (snapshot.inheritedCount)
|
|
493
547
|
body.push(
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
548
|
+
" " +
|
|
549
|
+
this.theme.fg(
|
|
550
|
+
"dim",
|
|
551
|
+
`${snapshot.inheritedCount} inherited messages ${this.viewport.showInherited ? "shown" : "collapsed"} · c toggle`,
|
|
552
|
+
),
|
|
498
553
|
);
|
|
499
554
|
const start = this.viewport.showInherited ? 0 : snapshot.inheritedCount;
|
|
500
555
|
for (const message of snapshot.messages.slice(start))
|
|
501
556
|
body.push(...this.message(message, columns));
|
|
502
557
|
if (snapshot.assistant)
|
|
503
558
|
body.push(
|
|
504
|
-
this.theme.fg("warning", "Assistant streaming…")
|
|
559
|
+
` ${this.theme.fg("warning", "Assistant streaming…")}`,
|
|
505
560
|
...this.message(snapshot.assistant, columns),
|
|
506
561
|
);
|
|
507
562
|
const committedResults = new Set(
|
|
@@ -511,23 +566,29 @@ export class LiveAgentView {
|
|
|
511
566
|
);
|
|
512
567
|
for (const tool of snapshot.tools) {
|
|
513
568
|
if (committedResults.has(tool.toolCallId)) continue;
|
|
514
|
-
const call = this.toolCall(tool.toolName, tool.args,
|
|
569
|
+
const call = this.toolCall(tool.toolName, tool.args, inner);
|
|
515
570
|
call[0] = `${call[0]} ${this.theme.fg(
|
|
516
571
|
tool.isError ? "error" : "warning",
|
|
517
572
|
dialogText(
|
|
518
573
|
`— ${tool.state}${tool.isError ? " (error)" : ""}${tool.parentToolCallId ? " (nested)" : ""}`,
|
|
519
574
|
),
|
|
520
575
|
)}`;
|
|
521
|
-
body.push(...call);
|
|
576
|
+
body.push(...this.band(call, "toolSuccessBg", columns));
|
|
522
577
|
if (tool.result !== undefined && this.detail !== "compact")
|
|
523
|
-
body.push(
|
|
578
|
+
body.push(
|
|
579
|
+
...this.band(
|
|
580
|
+
this.preview(object(tool.result)?.content ?? tool.result, inner),
|
|
581
|
+
tool.isError ? "toolErrorBg" : "customMessageBg",
|
|
582
|
+
columns,
|
|
583
|
+
),
|
|
584
|
+
);
|
|
524
585
|
body.push("");
|
|
525
586
|
}
|
|
526
587
|
if (!body.length)
|
|
527
588
|
body.push(
|
|
528
589
|
thread?.state === "starting"
|
|
529
|
-
? "Starting — waiting for transcript attachment…"
|
|
530
|
-
: "No retained messages yet.",
|
|
590
|
+
? " Starting — waiting for transcript attachment…"
|
|
591
|
+
: " No retained messages yet.",
|
|
531
592
|
);
|
|
532
593
|
}
|
|
533
594
|
this.content = body;
|
|
@@ -546,7 +607,7 @@ export class LiveAgentView {
|
|
|
546
607
|
const footer = this.error
|
|
547
608
|
? "Ctrl+R Retry · Tab input/transcript · Esc tree · Ctrl+Q main"
|
|
548
609
|
: `${this.editing ? "Enter steer · Tab browse" : `Tab steer · Home/End scroll · c context · t view:${this.detail}`} · Esc tree · Ctrl+Q main · ↑↓/PgUp/PgDn scroll · ${this.viewport.follow ? "following" : "scrolled"}`;
|
|
549
|
-
const input = this.input.render(
|
|
610
|
+
const input = ` ${this.input.render(inner)[0]!}`;
|
|
550
611
|
const status = this.theme.fg(
|
|
551
612
|
this.steerStatus ? (this.steerFailed ? "error" : "muted") : this.error ? "error" : "muted",
|
|
552
613
|
dialogText(
|
|
@@ -558,14 +619,22 @@ export class LiveAgentView {
|
|
|
558
619
|
: "Live transcript · Enter to steer"),
|
|
559
620
|
),
|
|
560
621
|
);
|
|
622
|
+
// Chrome rows share the transcript's one-column side padding; `visible` is already padded.
|
|
623
|
+
const chrome = (line: string) => ` ${truncateToWidth(line, inner, "")}`;
|
|
561
624
|
const lines =
|
|
562
625
|
height === 1
|
|
563
626
|
? [input]
|
|
564
627
|
: height === 2
|
|
565
|
-
? [header, input]
|
|
628
|
+
? [chrome(header), input]
|
|
566
629
|
: height === 3
|
|
567
|
-
? [header, this.theme.fg("dim", footer), input]
|
|
568
|
-
: [
|
|
630
|
+
? [chrome(header), chrome(this.theme.fg("dim", footer)), input]
|
|
631
|
+
: [
|
|
632
|
+
chrome(header),
|
|
633
|
+
chrome(status),
|
|
634
|
+
...visible,
|
|
635
|
+
chrome(this.theme.fg("dim", footer)),
|
|
636
|
+
input,
|
|
637
|
+
];
|
|
569
638
|
return fillViewport(lines, width, height);
|
|
570
639
|
}
|
|
571
640
|
}
|
package/src/ui/settings-ui.ts
CHANGED
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
} from "./dialog.ts";
|
|
9
9
|
import {
|
|
10
10
|
DEFAULT_MANAGER_SETTINGS,
|
|
11
|
+
LOADER_STYLES,
|
|
12
|
+
type LoaderStyle,
|
|
11
13
|
loadManagerSaveScope,
|
|
12
14
|
saveManagerSaveScope,
|
|
13
15
|
saveManagerSettings,
|
|
@@ -18,6 +20,17 @@ import {
|
|
|
18
20
|
type WidgetMode,
|
|
19
21
|
} from "../prefs/settings.ts";
|
|
20
22
|
import { editAgentTypes } from "./ui.ts";
|
|
23
|
+
import { AGENT_LOADERS } from "./agent-loader.ts";
|
|
24
|
+
|
|
25
|
+
const LOADER_OPTIONS = LOADER_STYLES.map((id) => {
|
|
26
|
+
const loader = AGENT_LOADERS[id];
|
|
27
|
+
return {
|
|
28
|
+
id,
|
|
29
|
+
label: loader.label,
|
|
30
|
+
value: `${loader.frames.join(" ")} · ${Object.values(loader.states).join(" ")}`,
|
|
31
|
+
help: `Each row: all starting/running frames · completed, paused, failed, stopped.\nStarting/running: ${loader.frames.join(" ")}\nCompleted: ${loader.states.completed} · Paused: ${loader.states.paused}\nFailed: ${loader.states.failed} · Stopped: ${loader.states.stopped}\nRequires [labs] Nerd Font icons On. The loader appears before the unchanged role icon.`,
|
|
32
|
+
};
|
|
33
|
+
});
|
|
21
34
|
|
|
22
35
|
const FIELDS = [
|
|
23
36
|
{
|
|
@@ -195,7 +208,13 @@ async function configureAgentsDialog(
|
|
|
195
208
|
id: "nerdFontIcons",
|
|
196
209
|
label: "[labs] Nerd Font icons",
|
|
197
210
|
value: draft.nerdFontIcons ? "On" : "Off",
|
|
198
|
-
help: "Experimental: display each agent type’s optional icon.\nRequires a Nerd Font configured in your terminal; otherwise glyphs may appear as boxes.\nOff by default. Save and apply to update the widget immediately.",
|
|
211
|
+
help: "Experimental: display each agent type’s optional icon, preceded by its loader/state indicator.\nRequires a Nerd Font configured in your terminal; otherwise glyphs may appear as boxes.\nOff by default. Save and apply to update the widget immediately.",
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
id: "loaderStyle",
|
|
215
|
+
label: "[labs] Loader style",
|
|
216
|
+
value: AGENT_LOADERS[draft.loaderStyle].label,
|
|
217
|
+
help: "Choose Circle, Braille or Hourglass. Preview every animation frame and settled state for all families.\nRequires [labs] Nerd Font icons On. Circle is the default.\nSave and apply to update the widget immediately.",
|
|
199
218
|
},
|
|
200
219
|
{
|
|
201
220
|
id: "finalRecap",
|
|
@@ -286,6 +305,11 @@ async function configureAgentsDialog(
|
|
|
286
305
|
draft.widgetMode = mode as WidgetMode;
|
|
287
306
|
} else if (action === "nerdFontIcons") {
|
|
288
307
|
draft.nerdFontIcons = !draft.nerdFontIcons;
|
|
308
|
+
} else if (action === "loaderStyle") {
|
|
309
|
+
const style = await dialogMenu(ctx, "[labs] Loader style", LOADER_OPTIONS, {
|
|
310
|
+
selectedId: draft.loaderStyle,
|
|
311
|
+
});
|
|
312
|
+
if (LOADER_STYLES.includes(style as LoaderStyle)) draft.loaderStyle = style as LoaderStyle;
|
|
289
313
|
} else if (action === "finalRecap") {
|
|
290
314
|
draft.finalRecap = !draft.finalRecap;
|
|
291
315
|
} else if (action === "scope") {
|
package/src/ui/status-ui.ts
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
frameDialog,
|
|
25
25
|
} from "./dialog.ts";
|
|
26
26
|
import type { ThreadService } from "../types.ts";
|
|
27
|
+
import type { LoaderStyle } from "../prefs/settings.ts";
|
|
27
28
|
import { buildStatusTree, type StatusRow } from "./thread-tree.ts";
|
|
28
29
|
import {
|
|
29
30
|
AGENT_PROGRESS_INTERVAL, agentProgressIcon, agentTypeBadge, agentTypeLabel, showThreads, threadMetrics,
|
|
@@ -109,6 +110,7 @@ export class StatusDialog {
|
|
|
109
110
|
fullscreen?: boolean;
|
|
110
111
|
},
|
|
111
112
|
private nerdFontIcons = false,
|
|
113
|
+
private loaderStyle: LoaderStyle = "circle",
|
|
112
114
|
) {
|
|
113
115
|
this.state = navigation?.state ?? { selectedPath: selected || ROOT, collapsed: new Set() };
|
|
114
116
|
}
|
|
@@ -260,7 +262,7 @@ export class StatusDialog {
|
|
|
260
262
|
const status = dialogText(thread.status);
|
|
261
263
|
return [
|
|
262
264
|
this.theme.fg(selected ? "accent" : base, head),
|
|
263
|
-
this.theme.fg(base, `${agentTypeLabel(thread.type, thread.icon, this.nerdFontIcons)} ${path} `),
|
|
265
|
+
this.theme.fg(base, `${agentTypeLabel(thread.type, thread.icon, this.nerdFontIcons, agentProgressIcon(thread, this.nerdFontIcons, Date.now(), true, this.loaderStyle))} ${path} `),
|
|
264
266
|
this.theme.fg(hint, state),
|
|
265
267
|
this.theme.fg(base, ` ${status}`),
|
|
266
268
|
].join("");
|
|
@@ -268,8 +270,8 @@ export class StatusDialog {
|
|
|
268
270
|
const rest = [thread.path, thread.state, thread.status]
|
|
269
271
|
.map((part) => dialogText(part))
|
|
270
272
|
.join(" ");
|
|
271
|
-
const badge = agentTypeBadge(thread.type, thread.color, this.theme,
|
|
272
|
-
agentProgressIcon(thread, this.nerdFontIcons), this.
|
|
273
|
+
const badge = agentTypeBadge(thread.type, thread.color, this.theme, thread.icon, this.nerdFontIcons,
|
|
274
|
+
agentProgressIcon(thread, this.nerdFontIcons, Date.now(), true, this.loaderStyle));
|
|
273
275
|
if (selected)
|
|
274
276
|
return `${this.theme.fg("accent", head)}${badge} ${this.theme.fg("accent", rest)}`;
|
|
275
277
|
return `${head}${badge} ${rest}`;
|
|
@@ -337,6 +339,7 @@ async function showAgentDialog(
|
|
|
337
339
|
selected?: string;
|
|
338
340
|
inspect?: (path: string) => Promise<void>;
|
|
339
341
|
nerdFontIcons?: boolean;
|
|
342
|
+
loaderStyle?: LoaderStyle;
|
|
340
343
|
} = {},
|
|
341
344
|
): Promise<void> {
|
|
342
345
|
const open = options.inspect ?? ((path: string) => showThreads(ctx, service, path));
|
|
@@ -347,7 +350,7 @@ async function showAgentDialog(
|
|
|
347
350
|
let dialog: StatusDialog | undefined;
|
|
348
351
|
try {
|
|
349
352
|
const chosen = await ctx.ui.custom<string | undefined>((host, theme, _keys, done) => {
|
|
350
|
-
dialog = new StatusDialog(host, theme, service, done, selected, options.title, undefined, options.nerdFontIcons);
|
|
353
|
+
dialog = new StatusDialog(host, theme, service, done, selected, options.title, undefined, options.nerdFontIcons, options.loaderStyle);
|
|
351
354
|
dialog.startRefresh();
|
|
352
355
|
return dialog;
|
|
353
356
|
}, DIALOG_OPTIONS);
|
|
@@ -367,9 +370,10 @@ export async function showAgentStatus(
|
|
|
367
370
|
service: ThreadService,
|
|
368
371
|
inspect?: (path: string) => Promise<void>,
|
|
369
372
|
nerdFontIcons = false,
|
|
373
|
+
loaderStyle: LoaderStyle = "circle",
|
|
370
374
|
): Promise<void> {
|
|
371
375
|
if (!canOpenDialog(ctx)) return;
|
|
372
|
-
await showAgentDialog(ctx, service, { inspect, nerdFontIcons });
|
|
376
|
+
await showAgentDialog(ctx, service, { inspect, nerdFontIcons, loaderStyle });
|
|
373
377
|
}
|
|
374
378
|
|
|
375
379
|
/** Root-owned navigation state. Opening and closing never changes the executing session. */
|
|
@@ -390,7 +394,7 @@ export class AgentNavigationController {
|
|
|
390
394
|
this.session = undefined;
|
|
391
395
|
}
|
|
392
396
|
|
|
393
|
-
open(ctx: ExtensionContext, service: ThreadService, selectedPath?: string, nerdFontIcons = false): Promise<void> {
|
|
397
|
+
open(ctx: ExtensionContext, service: ThreadService, selectedPath?: string, nerdFontIcons = false, loaderStyle: LoaderStyle = "circle"): Promise<void> {
|
|
394
398
|
if (this.opening) return this.opening;
|
|
395
399
|
if (!canOpenDialog(ctx)) return Promise.resolve();
|
|
396
400
|
if (selectedPath) this.tree.selectedPath = selectedPath;
|
|
@@ -471,6 +475,7 @@ export class AgentNavigationController {
|
|
|
471
475
|
actions: (path) => finish({ kind: "actions", path }),
|
|
472
476
|
},
|
|
473
477
|
nerdFontIcons,
|
|
478
|
+
loaderStyle,
|
|
474
479
|
);
|
|
475
480
|
treeDialog.startRefresh();
|
|
476
481
|
return treeDialog;
|
|
@@ -488,7 +493,7 @@ export class AgentNavigationController {
|
|
|
488
493
|
}
|
|
489
494
|
const result = await session.mount<"back" | "main">(
|
|
490
495
|
(tui, activeTheme, _keys, finish) =>
|
|
491
|
-
new LiveAgentView(tui, activeTheme, service, chosen.path, viewport!, finish, nerdFontIcons),
|
|
496
|
+
new LiveAgentView(tui, activeTheme, service, chosen.path, viewport!, finish, nerdFontIcons, loaderStyle),
|
|
492
497
|
);
|
|
493
498
|
if (result !== "back") break;
|
|
494
499
|
}
|
|
@@ -534,11 +539,12 @@ export async function showAgentTree(
|
|
|
534
539
|
service: ThreadService,
|
|
535
540
|
selectedPath?: string,
|
|
536
541
|
nerdFontIcons = false,
|
|
542
|
+
loaderStyle: LoaderStyle = "circle",
|
|
537
543
|
): Promise<void> {
|
|
538
544
|
let navigation = navigationByService.get(service);
|
|
539
545
|
if (!navigation) {
|
|
540
546
|
navigation = new AgentNavigationController();
|
|
541
547
|
navigationByService.set(service, navigation);
|
|
542
548
|
}
|
|
543
|
-
await navigation.open(ctx, service, selectedPath, nerdFontIcons);
|
|
549
|
+
await navigation.open(ctx, service, selectedPath, nerdFontIcons, loaderStyle);
|
|
544
550
|
}
|
package/src/ui/thread-tree.ts
CHANGED
|
@@ -24,11 +24,7 @@ function comparePath(a: string, b: string): number {
|
|
|
24
24
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
function chainHas(
|
|
28
|
-
parentOf: Map<string, string | null>,
|
|
29
|
-
start: string,
|
|
30
|
-
target: string,
|
|
31
|
-
): boolean {
|
|
27
|
+
function chainHas(parentOf: Map<string, string | null>, start: string, target: string): boolean {
|
|
32
28
|
const seen = new Set<string>();
|
|
33
29
|
let current: string | null = start;
|
|
34
30
|
while (current) {
|
|
@@ -39,18 +35,49 @@ function chainHas(
|
|
|
39
35
|
return false;
|
|
40
36
|
}
|
|
41
37
|
|
|
38
|
+
/** When an agent last (re)started; older saves fall back to creation time. */
|
|
39
|
+
export function lastStarted(thread: ThreadView | undefined): number {
|
|
40
|
+
const value = thread?.lastStartedAt ?? thread?.createdAt;
|
|
41
|
+
return typeof value === "number" && Number.isFinite(value) ? value : 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Newest branch first: a branch ranks by its most recently started agent. Cycles are guarded. */
|
|
45
|
+
export function recencyComparator(threads: ThreadView[]): (a: string, b: string) => number {
|
|
46
|
+
const byPath = new Map<string, ThreadView>();
|
|
47
|
+
for (const thread of threads) {
|
|
48
|
+
if (thread?.path && !byPath.has(thread.path)) byPath.set(thread.path, thread);
|
|
49
|
+
}
|
|
50
|
+
const latest = new Map<string, number>();
|
|
51
|
+
for (const thread of byPath.values()) {
|
|
52
|
+
const time = lastStarted(thread);
|
|
53
|
+
const seen = new Set<string>();
|
|
54
|
+
let current: string | null = thread.path;
|
|
55
|
+
while (current && !seen.has(current)) {
|
|
56
|
+
seen.add(current);
|
|
57
|
+
latest.set(current, Math.max(latest.get(current) ?? 0, time));
|
|
58
|
+
const view = byPath.get(current);
|
|
59
|
+
current = view
|
|
60
|
+
? view.parent && view.parent !== current
|
|
61
|
+
? view.parent
|
|
62
|
+
: null
|
|
63
|
+
: lexicalParent(current);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return (a, b) => (latest.get(b) ?? 0) - (latest.get(a) ?? 0) || comparePath(a, b);
|
|
67
|
+
}
|
|
68
|
+
|
|
42
69
|
/** Flatten retained agents. Parent links win over path shape; /root is always present.
|
|
43
|
-
* `comparePaths` orders siblings and roots only
|
|
70
|
+
* `comparePaths` orders siblings and roots only (default: most recently started branch first).
|
|
71
|
+
* Cycle repair stays lexical.
|
|
44
72
|
*/
|
|
45
73
|
export function buildStatusTree(
|
|
46
74
|
threads: ThreadView[],
|
|
47
75
|
collapsed: Set<string>,
|
|
48
|
-
comparePaths: (a: string, b: string) => number =
|
|
76
|
+
comparePaths: (a: string, b: string) => number = recencyComparator(threads),
|
|
49
77
|
): StatusRow[] {
|
|
50
78
|
const threadsByPath = new Map<string, ThreadView>();
|
|
51
79
|
for (const thread of threads) {
|
|
52
|
-
if (thread?.path && !threadsByPath.has(thread.path))
|
|
53
|
-
threadsByPath.set(thread.path, thread);
|
|
80
|
+
if (thread?.path && !threadsByPath.has(thread.path)) threadsByPath.set(thread.path, thread);
|
|
54
81
|
}
|
|
55
82
|
const nodes = new Map<string, StatusNode>();
|
|
56
83
|
const parentOf = new Map<string, string | null>();
|
|
@@ -65,8 +92,7 @@ export function buildStatusTree(
|
|
|
65
92
|
const declaredParent = (path: string): string | null => {
|
|
66
93
|
if (path === ROOT) return null;
|
|
67
94
|
const thread = threadsByPath.get(path);
|
|
68
|
-
if (thread)
|
|
69
|
-
return thread.parent && thread.parent !== path ? thread.parent : null;
|
|
95
|
+
if (thread) return thread.parent && thread.parent !== path ? thread.parent : null;
|
|
70
96
|
return lexicalParent(path);
|
|
71
97
|
};
|
|
72
98
|
const ensure = (path: string, seen = new Set<string>()): void => {
|
package/src/ui/ui.ts
CHANGED
|
@@ -39,8 +39,10 @@ import {
|
|
|
39
39
|
withDialogSession,
|
|
40
40
|
} from "./dialog.ts";
|
|
41
41
|
import { getModelPreferences } from "../prefs/models.ts";
|
|
42
|
-
import type { WidgetMode } from "../prefs/settings.ts";
|
|
43
|
-
import {
|
|
42
|
+
import type { LoaderStyle, WidgetMode } from "../prefs/settings.ts";
|
|
43
|
+
import { AGENT_PROGRESS_INTERVAL, agentProgressIcon, isAgentLoaderGlyph } from "./agent-loader.ts";
|
|
44
|
+
export { AGENT_PROGRESS_INTERVAL, agentProgressIcon } from "./agent-loader.ts";
|
|
45
|
+
import { buildStatusTree, lastStarted, type StatusRow } from "./thread-tree.ts";
|
|
44
46
|
import {
|
|
45
47
|
THINKING_LEVELS,
|
|
46
48
|
type AgentType,
|
|
@@ -91,33 +93,11 @@ function contrastPill(
|
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
/** Invalid/untrusted saved icons never reach the terminal. Names remain readable. */
|
|
94
|
-
export function agentTypeLabel(type: string, icon?: string, nerdFontIcons = false): string {
|
|
95
|
-
const
|
|
96
|
+
export function agentTypeLabel(type: string, icon?: string, nerdFontIcons = false, loaderIcon?: string): string {
|
|
97
|
+
const role = nerdFontIcons && typeof icon === "string" && /^\p{Co}$/u.test(icon)
|
|
96
98
|
? `${icon} ` : "";
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/** Nerd Fonts md-circle-slice-1..8: an equal-width, shape-changing progress cycle.
|
|
101
|
-
* Verified against https://raw.githubusercontent.com/ryanoasis/nerd-fonts/master/glyphnames.json.
|
|
102
|
-
*/
|
|
103
|
-
export const AGENT_PROGRESS_INTERVAL = 180;
|
|
104
|
-
const AGENT_PROGRESS_FRAMES = Array.from({ length: 8 }, (_, index) =>
|
|
105
|
-
String.fromCodePoint(0xf0a9e + index),
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
/** Keep the configured role icon for settled threads and non-animated/RPC output. */
|
|
109
|
-
export function agentProgressIcon(
|
|
110
|
-
thread: Pick<ThreadView, "state" | "icon">,
|
|
111
|
-
nerdFontIcons: boolean,
|
|
112
|
-
now = Date.now(),
|
|
113
|
-
animate = true,
|
|
114
|
-
): string | undefined {
|
|
115
|
-
if (!nerdFontIcons) return undefined;
|
|
116
|
-
if (animate && (thread.state === "starting" || thread.state === "running")) {
|
|
117
|
-
const frame = Math.floor(Math.max(0, now) / AGENT_PROGRESS_INTERVAL) % AGENT_PROGRESS_FRAMES.length;
|
|
118
|
-
return AGENT_PROGRESS_FRAMES[frame];
|
|
119
|
-
}
|
|
120
|
-
return thread.icon;
|
|
99
|
+
const progress = nerdFontIcons && loaderIcon && isAgentLoaderGlyph(loaderIcon) ? `${loaderIcon} ` : "";
|
|
100
|
+
return `${progress}${role}${sanitizeText(type)}`;
|
|
121
101
|
}
|
|
122
102
|
|
|
123
103
|
export function agentTypeBadge(
|
|
@@ -126,8 +106,9 @@ export function agentTypeBadge(
|
|
|
126
106
|
theme: AgentBadgeTheme,
|
|
127
107
|
icon?: string,
|
|
128
108
|
nerdFontIcons = false,
|
|
109
|
+
loaderIcon?: string,
|
|
129
110
|
): string {
|
|
130
|
-
return contrastPill(agentTypeLabel(type, icon, nerdFontIcons), color, theme);
|
|
111
|
+
return contrastPill(agentTypeLabel(type, icon, nerdFontIcons, loaderIcon), color, theme);
|
|
131
112
|
}
|
|
132
113
|
|
|
133
114
|
function agentPath(
|
|
@@ -204,6 +185,7 @@ export function renderThreads(
|
|
|
204
185
|
width: number,
|
|
205
186
|
theme: AgentBadgeTheme,
|
|
206
187
|
nerdFontIcons = false,
|
|
188
|
+
loaderStyle: LoaderStyle = "circle",
|
|
207
189
|
): string[] {
|
|
208
190
|
const priority = (thread: ThreadView) =>
|
|
209
191
|
thread.state === "starting" || thread.state === "running"
|
|
@@ -228,7 +210,8 @@ export function renderThreads(
|
|
|
228
210
|
? "warning"
|
|
229
211
|
: "accent";
|
|
230
212
|
const badge = agentTypeBadge(
|
|
231
|
-
thread.type, thread.color, theme,
|
|
213
|
+
thread.type, thread.color, theme, thread.icon, nerdFontIcons,
|
|
214
|
+
agentProgressIcon(thread, nerdFontIcons, Date.now(), true, loaderStyle),
|
|
232
215
|
);
|
|
233
216
|
const path = agentPath(thread.path, thread.color, theme);
|
|
234
217
|
const state = theme.fg(stateColor, `[${sanitizeText(thread.state)}]`);
|
|
@@ -262,7 +245,8 @@ interface AgentWidgetRenderOptions {
|
|
|
262
245
|
/** RPC widgets cannot open a terminal browser. */
|
|
263
246
|
showBrowserHint?: boolean;
|
|
264
247
|
nerdFontIcons?: boolean;
|
|
265
|
-
|
|
248
|
+
loaderStyle?: LoaderStyle;
|
|
249
|
+
/** RPC snapshots use a static running frame and never start an animation. */
|
|
266
250
|
animate?: boolean;
|
|
267
251
|
}
|
|
268
252
|
|
|
@@ -292,76 +276,6 @@ function statePriority(state: ThreadView["state"] | undefined): number {
|
|
|
292
276
|
return 2;
|
|
293
277
|
}
|
|
294
278
|
|
|
295
|
-
function explicitParent(
|
|
296
|
-
path: string,
|
|
297
|
-
threadsByPath: Map<string, ThreadView>,
|
|
298
|
-
): string | null {
|
|
299
|
-
if (path === WIDGET_ROOT) return null;
|
|
300
|
-
const thread = threadsByPath.get(path);
|
|
301
|
-
if (thread)
|
|
302
|
-
return thread.parent && thread.parent !== path ? thread.parent : null;
|
|
303
|
-
const index = path.lastIndexOf("/");
|
|
304
|
-
return index > 0 ? path.slice(0, index) : null;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/** Lowest state in the branch. Parent links define ancestry; cycles are guarded. */
|
|
308
|
-
function branchPriorityComparator(
|
|
309
|
-
threads: ThreadView[],
|
|
310
|
-
): (a: string, b: string) => number {
|
|
311
|
-
const threadsByPath = new Map<string, ThreadView>();
|
|
312
|
-
for (const thread of threads) {
|
|
313
|
-
if (thread?.path && !threadsByPath.has(thread.path))
|
|
314
|
-
threadsByPath.set(thread.path, thread);
|
|
315
|
-
}
|
|
316
|
-
const children = new Map<string, string[]>();
|
|
317
|
-
const link = (path: string, seen: Set<string>) => {
|
|
318
|
-
if (!path || seen.has(path)) return;
|
|
319
|
-
seen.add(path);
|
|
320
|
-
const parent = explicitParent(path, threadsByPath);
|
|
321
|
-
if (!parent || parent === path) return;
|
|
322
|
-
const list = children.get(parent) ?? [];
|
|
323
|
-
if (!list.includes(path)) list.push(path);
|
|
324
|
-
children.set(parent, list);
|
|
325
|
-
link(parent, seen);
|
|
326
|
-
};
|
|
327
|
-
link(WIDGET_ROOT, new Set());
|
|
328
|
-
for (const path of threadsByPath.keys()) link(path, new Set());
|
|
329
|
-
|
|
330
|
-
const subtree = new Map<string, number>();
|
|
331
|
-
const ancestors = new Map<string, number>();
|
|
332
|
-
const subtreeOf = (path: string, stack: Set<string>): number => {
|
|
333
|
-
const cached = subtree.get(path);
|
|
334
|
-
if (cached !== undefined) return cached;
|
|
335
|
-
const own = statePriority(threadsByPath.get(path)?.state);
|
|
336
|
-
if (stack.has(path)) return own;
|
|
337
|
-
stack.add(path);
|
|
338
|
-
let best = own;
|
|
339
|
-
for (const child of children.get(path) ?? [])
|
|
340
|
-
best = Math.min(best, subtreeOf(child, stack));
|
|
341
|
-
stack.delete(path);
|
|
342
|
-
subtree.set(path, best);
|
|
343
|
-
return best;
|
|
344
|
-
};
|
|
345
|
-
const ancestorOf = (path: string): number => {
|
|
346
|
-
const cached = ancestors.get(path);
|
|
347
|
-
if (cached !== undefined) return cached;
|
|
348
|
-
let best = 2;
|
|
349
|
-
const seen = new Set<string>();
|
|
350
|
-
let current: string | null = path;
|
|
351
|
-
while (current && !seen.has(current)) {
|
|
352
|
-
seen.add(current);
|
|
353
|
-
best = Math.min(best, statePriority(threadsByPath.get(current)?.state));
|
|
354
|
-
current = explicitParent(current, threadsByPath);
|
|
355
|
-
}
|
|
356
|
-
ancestors.set(path, best);
|
|
357
|
-
return best;
|
|
358
|
-
};
|
|
359
|
-
return (a, b) =>
|
|
360
|
-
subtreeOf(a, new Set()) - subtreeOf(b, new Set()) ||
|
|
361
|
-
ancestorOf(a) - ancestorOf(b) ||
|
|
362
|
-
(a < b ? -1 : a > b ? 1 : 0);
|
|
363
|
-
}
|
|
364
|
-
|
|
365
279
|
function agentStateColor(
|
|
366
280
|
state: ThreadView["state"],
|
|
367
281
|
): "error" | "warning" | "accent" {
|
|
@@ -378,11 +292,12 @@ function agentLine(
|
|
|
378
292
|
theme: AgentBadgeTheme,
|
|
379
293
|
nerdFontIcons: boolean,
|
|
380
294
|
animate: boolean,
|
|
295
|
+
loaderStyle: LoaderStyle,
|
|
381
296
|
): string {
|
|
382
297
|
const thread = row.thread!;
|
|
383
298
|
const badge = agentTypeBadge(
|
|
384
|
-
thread.type, thread.color, theme,
|
|
385
|
-
agentProgressIcon(thread, nerdFontIcons, Date.now(), animate
|
|
299
|
+
thread.type, thread.color, theme, thread.icon, nerdFontIcons,
|
|
300
|
+
agentProgressIcon(thread, nerdFontIcons, Date.now(), animate, loaderStyle),
|
|
386
301
|
);
|
|
387
302
|
const left = `${row.prefix}${badge} ${agentPath(thread.path, thread.color, theme)} ${theme.fg(agentStateColor(thread.state), `[${sanitizeText(thread.state)}]`)} ${sanitizeText(thread.task)}`;
|
|
388
303
|
return fitLine(left, theme.fg("muted", threadMetrics(thread)), width);
|
|
@@ -421,7 +336,7 @@ function takeWidgetRows(rows: StatusRow[], budget: number): StatusRow[] {
|
|
|
421
336
|
(a, b) =>
|
|
422
337
|
statePriority(a.row.thread!.state) -
|
|
423
338
|
statePriority(b.row.thread!.state) ||
|
|
424
|
-
b.row.thread
|
|
339
|
+
lastStarted(b.row.thread) - lastStarted(a.row.thread) || a.index - b.index,
|
|
425
340
|
);
|
|
426
341
|
const chosen = new Set<number>();
|
|
427
342
|
let used = 0;
|
|
@@ -456,14 +371,10 @@ export function renderAgentTree(
|
|
|
456
371
|
threads: ThreadView[],
|
|
457
372
|
width: number,
|
|
458
373
|
theme: AgentBadgeTheme,
|
|
459
|
-
{ showBrowserHint = true, nerdFontIcons = false, animate = true }: AgentWidgetRenderOptions = {},
|
|
374
|
+
{ showBrowserHint = true, nerdFontIcons = false, animate = true, loaderStyle = "circle" }: AgentWidgetRenderOptions = {},
|
|
460
375
|
): string[] {
|
|
461
376
|
const columns = Math.max(0, width);
|
|
462
|
-
const rows = buildStatusTree(
|
|
463
|
-
threads,
|
|
464
|
-
new Set(),
|
|
465
|
-
branchPriorityComparator(threads),
|
|
466
|
-
);
|
|
377
|
+
const rows = buildStatusTree(threads, new Set());
|
|
467
378
|
const agents = rows.filter((row) => row.thread && row.path !== WIDGET_ROOT);
|
|
468
379
|
if (!agents.length) return [];
|
|
469
380
|
const live = agents.filter(
|
|
@@ -485,7 +396,7 @@ export function renderAgentTree(
|
|
|
485
396
|
lines.push(placeholderLine(row, columns, theme));
|
|
486
397
|
continue;
|
|
487
398
|
}
|
|
488
|
-
lines.push(agentLine(row, columns, theme, nerdFontIcons, animate));
|
|
399
|
+
lines.push(agentLine(row, columns, theme, nerdFontIcons, animate, loaderStyle));
|
|
489
400
|
}
|
|
490
401
|
lines.push(agentWidgetStatus(live, omitted, columns, theme, showBrowserHint));
|
|
491
402
|
return lines;
|
|
@@ -496,7 +407,7 @@ export function renderAgentSummary(
|
|
|
496
407
|
threads: ThreadView[],
|
|
497
408
|
width: number,
|
|
498
409
|
theme: Pick<Theme, "fg">,
|
|
499
|
-
{ showBrowserHint = true, nerdFontIcons = false, animate = true }: AgentWidgetRenderOptions = {},
|
|
410
|
+
{ showBrowserHint = true, nerdFontIcons = false, animate = true, loaderStyle = "circle" }: AgentWidgetRenderOptions = {},
|
|
500
411
|
): string[] {
|
|
501
412
|
const agents = new Map<string, ThreadView>();
|
|
502
413
|
for (const thread of threads) {
|
|
@@ -528,13 +439,14 @@ export function renderAgentSummary(
|
|
|
528
439
|
["paused", "warning"],
|
|
529
440
|
["completed", "success"],
|
|
530
441
|
];
|
|
531
|
-
const progress = counts.running > 0
|
|
532
|
-
? agentProgressIcon({ state: "running" }, nerdFontIcons, Date.now(), animate)
|
|
533
|
-
: undefined;
|
|
534
442
|
const left = statuses
|
|
535
443
|
.filter(([state]) => state === "running" || counts[state] > 0)
|
|
536
|
-
.map(([state, color]) =>
|
|
537
|
-
|
|
444
|
+
.map(([state, color]) => {
|
|
445
|
+
const progress = counts[state] > 0
|
|
446
|
+
? agentProgressIcon({ state }, nerdFontIcons, Date.now(), animate, loaderStyle)
|
|
447
|
+
: undefined;
|
|
448
|
+
return theme.fg(color, `${progress ? `${progress} ` : ""}${counts[state]} ${state}`);
|
|
449
|
+
})
|
|
538
450
|
.join(theme.fg("muted", ", ")) +
|
|
539
451
|
(showBrowserHint && counts.running > 0 ? theme.fg("muted", " · ← browser") : "");
|
|
540
452
|
const right = theme.fg("muted", `↑${formatCount(input)} ↓${formatCount(output)}`);
|
|
@@ -547,6 +459,7 @@ export function updateWidget(
|
|
|
547
459
|
mode: WidgetMode = "full",
|
|
548
460
|
nerdFontIcons = false,
|
|
549
461
|
rootTurnEnded = false,
|
|
462
|
+
loaderStyle: LoaderStyle = "circle",
|
|
550
463
|
): void {
|
|
551
464
|
if (!ctx.hasUI) return;
|
|
552
465
|
if (!threads.some((thread) => thread.path !== "/root")) {
|
|
@@ -560,7 +473,7 @@ export function updateWidget(
|
|
|
560
473
|
if (ctx.mode === "rpc") {
|
|
561
474
|
ctx.ui.setWidget(
|
|
562
475
|
"pi-subagent",
|
|
563
|
-
render(threads, 80, ctx.ui.theme, { showBrowserHint: false, nerdFontIcons, animate: false }),
|
|
476
|
+
render(threads, 80, ctx.ui.theme, { showBrowserHint: false, nerdFontIcons, loaderStyle, animate: false }),
|
|
564
477
|
AGENT_WIDGET_PLACEMENT,
|
|
565
478
|
);
|
|
566
479
|
return;
|
|
@@ -578,6 +491,7 @@ export function updateWidget(
|
|
|
578
491
|
render: (width) => render(snapshot, width, ctx.ui.theme, {
|
|
579
492
|
showBrowserHint: !settled,
|
|
580
493
|
nerdFontIcons,
|
|
494
|
+
loaderStyle,
|
|
581
495
|
}),
|
|
582
496
|
invalidate: () => {},
|
|
583
497
|
dispose: () => {
|
|
@@ -1042,6 +956,7 @@ const EDIT_MENU_ACTIONS = [
|
|
|
1042
956
|
"Edit frontmatter YAML",
|
|
1043
957
|
"External editor (entire Markdown)",
|
|
1044
958
|
"Save",
|
|
959
|
+
"Reset to bundled",
|
|
1045
960
|
"Cancel",
|
|
1046
961
|
] as const;
|
|
1047
962
|
|
|
@@ -1066,6 +981,7 @@ const EDIT_FIELD_LABELS: Record<EditMenuAction, string> = {
|
|
|
1066
981
|
"Edit frontmatter YAML": "Frontmatter YAML",
|
|
1067
982
|
"External editor (entire Markdown)": "External editor",
|
|
1068
983
|
Save: "Save",
|
|
984
|
+
"Reset to bundled": "Reset to bundled",
|
|
1069
985
|
Cancel: "Cancel",
|
|
1070
986
|
};
|
|
1071
987
|
|
|
@@ -1093,6 +1009,8 @@ const EDIT_FIELD_HELP: Record<EditMenuAction, string> = {
|
|
|
1093
1009
|
"External editor (entire Markdown)":
|
|
1094
1010
|
"Edit the complete definition using $VISUAL / $EDITOR.",
|
|
1095
1011
|
Save: "Validate and save. Existing sessions keep their original configuration.",
|
|
1012
|
+
"Reset to bundled":
|
|
1013
|
+
"Delete this fork/override file and go back to the definition shipped with the extension. Unsaved edits are discarded.",
|
|
1096
1014
|
Cancel: "Close without saving any edits.",
|
|
1097
1015
|
};
|
|
1098
1016
|
|
|
@@ -1266,7 +1184,11 @@ async function editAgentTypesDialog(
|
|
|
1266
1184
|
const field = await dialogMenu(
|
|
1267
1185
|
ctx,
|
|
1268
1186
|
`Edit ${sanitizeText(draft.name)} (unsaved)`,
|
|
1269
|
-
EDIT_MENU_ACTIONS.
|
|
1187
|
+
EDIT_MENU_ACTIONS.filter(
|
|
1188
|
+
(action) =>
|
|
1189
|
+
action !== "Reset to bundled" ||
|
|
1190
|
+
(!isNew && !!original?.customization && !!original.baseSource),
|
|
1191
|
+
).map((action) => {
|
|
1270
1192
|
const decorated = editMenuLabel(action, draft);
|
|
1271
1193
|
const separator = decorated.indexOf(": ");
|
|
1272
1194
|
return {
|
|
@@ -1384,6 +1306,30 @@ async function editAgentTypesDialog(
|
|
|
1384
1306
|
);
|
|
1385
1307
|
break;
|
|
1386
1308
|
}
|
|
1309
|
+
if (field === "Reset to bundled") {
|
|
1310
|
+
if (!original?.customization || !original.baseSource) continue;
|
|
1311
|
+
const { scope, filePath } = original.customization;
|
|
1312
|
+
const confirmed = await dialogMenu(
|
|
1313
|
+
ctx,
|
|
1314
|
+
`Reset ${sanitizeText(original.name)}?`,
|
|
1315
|
+
[
|
|
1316
|
+
{
|
|
1317
|
+
id: "reset",
|
|
1318
|
+
label: "Reset",
|
|
1319
|
+
help: `Deletes ${filePath} and restores the ${original.baseSource ?? "bundled"} definition.`,
|
|
1320
|
+
},
|
|
1321
|
+
{ id: "keep", label: "Keep" },
|
|
1322
|
+
],
|
|
1323
|
+
{ selectedId: "keep" },
|
|
1324
|
+
);
|
|
1325
|
+
if (confirmed !== "reset") continue;
|
|
1326
|
+
store.removeCustomization(original.name, scope);
|
|
1327
|
+
ctx.ui.notify(
|
|
1328
|
+
`Reset ${sanitizeText(original.name)}: deleted ${sanitizeText(filePath)}; using the ${original.baseSource ?? "bundled"} definition.`,
|
|
1329
|
+
"info",
|
|
1330
|
+
);
|
|
1331
|
+
break;
|
|
1332
|
+
}
|
|
1387
1333
|
if (field === "Save scope") {
|
|
1388
1334
|
const scope = await chooseSaveScope(ctx, store, saveScope);
|
|
1389
1335
|
if (scope) saveScope = scope;
|