pi-subagent-manager 0.18.0 → 0.19.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 -3
- package/docs/settings.md +13 -0
- package/package.json +1 -1
- package/src/index.ts +5 -2
- package/src/orch/prompt.ts +1 -1
- package/src/orch/tools.ts +15 -3
- package/src/prefs/settings.ts +12 -1
- package/src/ui/cost-footer.ts +32 -6
- package/src/ui/settings-ui.ts +31 -0
package/README.md
CHANGED
|
@@ -77,9 +77,9 @@ A live **Agents** widget sits above the input box. Choose **Full** (the existing
|
|
|
77
77
|
|
|
78
78
|
**Cost accounting:** Agent rows show estimated USD cost (including cache reads/writes) when reported. Completed, paused, stopped, and failed agents roll up only newly incurred cost. Accounting survives resume, reload, branch navigation, and reaping; nested agents' own costs are counted once. Running-agent costs remain in their rows until settlement. This changes the footer display, not Pi's native session statistics.
|
|
79
79
|
|
|
80
|
-
- **
|
|
81
|
-
- **`npm:pi-footer`:**
|
|
82
|
-
-
|
|
80
|
+
- Choose **[labs] Cost display** in `/agents settings`: **pi-footer status key** (default), **pi-footer event**, or **Pi status only**. The stable ID/key is **`subagent_cost`**.
|
|
81
|
+
- **`npm:pi-footer`:** with the default status-key mode, add **Extension Status** through `/footer` and select **`subagent_cost`**. Event mode instead requires a **Pi Event Value** widget with **Widget ID** entered manually and **Raw value only** enabled; event IDs are not listed in the status selector.
|
|
82
|
+
- Values publish at session start and immediately on subagent startup, including `$0.0000`, then after settlement/settings changes. Status modes leave your footer untouched; event mode retains the combined-cost fallback when no extension provides `/footer`. See [Cost display settings](docs/settings.md#labs-cost-display-costdisplay).
|
|
83
83
|
|
|
84
84
|
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).
|
|
85
85
|
|
package/docs/settings.md
CHANGED
|
@@ -17,6 +17,7 @@ All keys are optional. Defaults:
|
|
|
17
17
|
"widgetMode": "full",
|
|
18
18
|
"nerdFontIcons": false,
|
|
19
19
|
"loaderStyle": "circle",
|
|
20
|
+
"costDisplay": "pi-footer-status",
|
|
20
21
|
"finalRecap": false,
|
|
21
22
|
"modelSelection": "pick-first-scoped",
|
|
22
23
|
"toolFiltering": "allowed",
|
|
@@ -70,6 +71,18 @@ Choose **Circle** (default), **Braille**, or **Hourglass** in `/agents` settings
|
|
|
70
71
|
|
|
71
72
|
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
73
|
|
|
74
|
+
## [labs] Cost display (`costDisplay`)
|
|
75
|
+
|
|
76
|
+
Choose the cost output in `/agents settings` and save. The stable ID/key is **`subagent_cost`**.
|
|
77
|
+
|
|
78
|
+
| Value | Output |
|
|
79
|
+
| --- | --- |
|
|
80
|
+
| `pi-footer-status` (default) | Publishes `$0.0000` via Pi’s `setStatus` API. In `/footer`, add **Extension Status** and pick **`subagent_cost`** from the status-key selector. |
|
|
81
|
+
| `pi-footer-event` | Emits `pi-footer:update-widget` with `widgetId: "subagent_cost"`. Add **Pi Event Value**, enter **Widget ID** manually, and enable **Raw value only**. Event IDs do not appear in the status selector. Without an extension providing `/footer`, preserves the combined-cost fallback footer. |
|
|
82
|
+
| `pi-status` | Sets Pi’s status to `Total: $0.0000` — main session + all settled subagents; no pi-footer events or custom footer. |
|
|
83
|
+
|
|
84
|
+
Both status modes use the same public Pi status API: third-party footers may also display Pi status-only output. These modes never replace your footer. The pi-footer modes show the **settled subagent-only** USD subtotal; Pi status shows **main session + all settled subagents**. In all modes, running costs settle on completion, pause, stop, or failure. It publishes on session start/reload, immediately when a subagent starts (even at zero), and after settlement/settings changes. Switching modes clears the previous output; shutdown clears the published value. Nerd Font icons apply when enabled.
|
|
85
|
+
|
|
73
86
|
## [labs] Final Recap (`finalRecap`)
|
|
74
87
|
|
|
75
88
|
**[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/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -50,6 +50,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
50
50
|
pi,
|
|
51
51
|
() => costLedger.totalUsd,
|
|
52
52
|
() => limits.nerdFontIcons,
|
|
53
|
+
() => limits.costDisplay,
|
|
53
54
|
);
|
|
54
55
|
const refreshCostFooter = (ctx: ExtensionContext) => costFooter.refresh(ctx);
|
|
55
56
|
const rollupCost = (thread: ThreadView) => {
|
|
@@ -272,7 +273,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
272
273
|
customType: ROOT_WAKE_MESSAGE,
|
|
273
274
|
content:
|
|
274
275
|
"Asynchronous subagent event(s) arrived (see the preceding subagent notifications). " +
|
|
275
|
-
"React: collect results with agent_output, and for a timeout event decide to wait, steer, stop or re-arm with agent_steer timeoutMs.",
|
|
276
|
+
"React: collect results with agent_output, and for a timeout event decide to wait, steer, stop or re-arm with agent_steer using path and timeoutMs only (omit message; resets the reporting timer from now without interrupting the running agent).",
|
|
276
277
|
display: false,
|
|
277
278
|
details: {},
|
|
278
279
|
},
|
|
@@ -506,6 +507,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
506
507
|
pi.on("agent_end", async (_event, ctx) => {
|
|
507
508
|
rootTurnEnded = true;
|
|
508
509
|
if (manager) refreshWidget(ctx);
|
|
510
|
+
refreshCostFooter(ctx);
|
|
509
511
|
// A migration can span clarification turns. Reload after each root turn, without converting files.
|
|
510
512
|
if (limits.subagentMode === "off" || !migrationRequested) return;
|
|
511
513
|
store.reload();
|
|
@@ -572,6 +574,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
572
574
|
refreshWidget(requireContext());
|
|
573
575
|
if (event.kind !== "metrics") persist();
|
|
574
576
|
if (event.kind === "settled") rollupCost(event.thread);
|
|
577
|
+
else refreshCostFooter(requireContext());
|
|
575
578
|
delivery(event);
|
|
576
579
|
},
|
|
577
580
|
});
|
|
@@ -633,10 +636,10 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
633
636
|
pi.on("session_before_fork", stopWorkingThreads);
|
|
634
637
|
pi.on("session_shutdown", async () => {
|
|
635
638
|
cancelSummary();
|
|
636
|
-
costFooter.clear();
|
|
637
639
|
generation++;
|
|
638
640
|
closeNavigation(true);
|
|
639
641
|
await manager?.shutdown();
|
|
642
|
+
costFooter.clear();
|
|
640
643
|
persist();
|
|
641
644
|
if (context?.hasUI) context.ui.setWidget("pi-subagent", undefined);
|
|
642
645
|
manager = undefined;
|
package/src/orch/prompt.ts
CHANGED
|
@@ -17,7 +17,7 @@ export function subagentPrompt(settings: ManagerSettings): string | undefined {
|
|
|
17
17
|
policy,
|
|
18
18
|
"Call agent_types before choosing a type. Use task-based kebab-case paths, not type names. Choose context via agent_spawn path: /root/task forks the lexical parent's conversation; /task starts fresh with no inherited history. Use fresh agents for adversarial review or clean-slate research; give them a self-contained task without the current thread's conclusions.",
|
|
19
19
|
waitingPolicy,
|
|
20
|
-
|
|
20
|
+
'Use agent_status to inspect and agent_output for full results. Completion, failure or stop of a wait:false agent is delivered to you as a message event that starts a new turn when you are idle (with Final Recap on, once after all outstanding async agents have finished). Pass timeoutMs to agent_spawn to get a status event if a child runs long; the child is not killed. Valid range 30000–300000 ms; omit for no timeout. To extend a running background agent\'s reporting timer, before or after a timeout event, call agent_steer({path: "/root/task", timeoutMs: 120000}) with message omitted entirely. This resets the timer from now (replacing any pending timer), without sending input, interrupting or resuming the agent; it requires the agent to still be running. After re-arming, end your turn to remain available while it works. For other timeout responses, follow the waiting policy above, send steering input or stop the agent.',
|
|
21
21
|
"Use agent_steer to send input or resume retained sessions. Paused agents have no final answer; completed agents hand back results. Both retain their session.",
|
|
22
22
|
`Maximum depth: ${settings.maxLevels} levels including L1. Shared concurrency: ${settings.maxConcurrent} active threads; waiting parents count.`,
|
|
23
23
|
].join("\n");
|
package/src/orch/tools.ts
CHANGED
|
@@ -113,11 +113,23 @@ export function agentTools(
|
|
|
113
113
|
),
|
|
114
114
|
make(
|
|
115
115
|
"agent_steer",
|
|
116
|
-
|
|
116
|
+
'Send input to a descendant and/or re-arm its report-only timeout. With message: working threads receive queued steering; completed, stopped and paused threads resume the SAME session with its previous context. With timeoutMs (30000–300000): the timeout fires that many ms from now, replacing any pending timer. To extend a running background agent\'s reporting timer without sending input, call agent_steer({path: "/root/task", timeoutMs: 120000}) and omit message entirely. This resets the timer to 120000 ms from now, not an addition to the old deadline. timeoutMs WITHOUT message only re-arms the timeout of a running child (error if not running) and does not steer, interrupt or resume it; with both, steer and re-arm. At least one is required. Returns immediately; use agent_wait for the result.',
|
|
117
117
|
Type.Object({
|
|
118
118
|
path,
|
|
119
|
-
message: Type.Optional(
|
|
120
|
-
|
|
119
|
+
message: Type.Optional(
|
|
120
|
+
Type.String({
|
|
121
|
+
minLength: 1,
|
|
122
|
+
description: "Input to send or resume with. Omit entirely for a timer-only re-arm.",
|
|
123
|
+
}),
|
|
124
|
+
),
|
|
125
|
+
timeoutMs: Type.Optional(
|
|
126
|
+
Type.Integer({
|
|
127
|
+
minimum: 30000,
|
|
128
|
+
maximum: 300000,
|
|
129
|
+
description:
|
|
130
|
+
"Reset the report-only timer to this many ms from now, replacing any pending timer. With no message, only re-arms a running agent; does not send input, interrupt or resume it.",
|
|
131
|
+
}),
|
|
132
|
+
),
|
|
121
133
|
}),
|
|
122
134
|
async (params) =>
|
|
123
135
|
result(compact(await threads().steer(params.path, params.message, params.timeoutMs))),
|
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 COST_DISPLAY_MODES = ["pi-footer-event", "pi-footer-status", "pi-status"] as const;
|
|
23
|
+
export type CostDisplayMode = (typeof COST_DISPLAY_MODES)[number];
|
|
24
|
+
|
|
22
25
|
export const LOADER_STYLES = ["circle", "braille", "hourglass"] as const;
|
|
23
26
|
export type LoaderStyle = (typeof LOADER_STYLES)[number];
|
|
24
27
|
|
|
@@ -36,6 +39,7 @@ export interface ManagerSettings {
|
|
|
36
39
|
subagentMode: SubagentMode;
|
|
37
40
|
toolFiltering: ToolFilteringMode;
|
|
38
41
|
widgetMode: WidgetMode;
|
|
42
|
+
costDisplay: CostDisplayMode;
|
|
39
43
|
nerdFontIcons: boolean;
|
|
40
44
|
loaderStyle: LoaderStyle;
|
|
41
45
|
finalRecap: boolean;
|
|
@@ -53,13 +57,14 @@ export const DEFAULT_MANAGER_SETTINGS: ManagerSettings = {
|
|
|
53
57
|
subagentMode: "opportunistic",
|
|
54
58
|
toolFiltering: "allowed",
|
|
55
59
|
widgetMode: "full",
|
|
60
|
+
costDisplay: "pi-footer-status",
|
|
56
61
|
nerdFontIcons: false,
|
|
57
62
|
loaderStyle: "circle",
|
|
58
63
|
finalRecap: false,
|
|
59
64
|
};
|
|
60
65
|
|
|
61
66
|
const KEYS = [
|
|
62
|
-
"maxLevels", "maxConcurrent", "maxThreads", "modelSelection", "subagentMode", "toolFiltering", "widgetMode", "nerdFontIcons", "loaderStyle", "finalRecap",
|
|
67
|
+
"maxLevels", "maxConcurrent", "maxThreads", "modelSelection", "subagentMode", "toolFiltering", "widgetMode", "costDisplay", "nerdFontIcons", "loaderStyle", "finalRecap",
|
|
63
68
|
] as const;
|
|
64
69
|
const MAX_LEVELS = 32;
|
|
65
70
|
|
|
@@ -100,6 +105,7 @@ function requirement(key: (typeof KEYS)[number]): string {
|
|
|
100
105
|
if (key === "nerdFontIcons" || key === "finalRecap") return `${key} must be a boolean`;
|
|
101
106
|
if (key === "subagentMode") return "subagentMode must be off, opportunistic or orchestration";
|
|
102
107
|
if (key === "widgetMode") return "widgetMode must be full or minimal";
|
|
108
|
+
if (key === "costDisplay") return "costDisplay must be pi-footer-event, pi-footer-status or pi-status";
|
|
103
109
|
if (key === "loaderStyle") return "loaderStyle must be circle, braille or hourglass";
|
|
104
110
|
if (key === "toolFiltering") return "toolFiltering must be allowed, all-except-blocked or all";
|
|
105
111
|
if (key === "modelSelection")
|
|
@@ -154,6 +160,11 @@ function parseSettings(content: string): Partial<ManagerSettings> {
|
|
|
154
160
|
layer.widgetMode = value as WidgetMode;
|
|
155
161
|
continue;
|
|
156
162
|
}
|
|
163
|
+
if (key === "costDisplay") {
|
|
164
|
+
if (!COST_DISPLAY_MODES.includes(value as CostDisplayMode)) throw new Error(requirement(key));
|
|
165
|
+
layer.costDisplay = value as CostDisplayMode;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
157
168
|
if (key === "loaderStyle") {
|
|
158
169
|
if (!LOADER_STYLES.includes(value as LoaderStyle)) throw new Error(requirement(key));
|
|
159
170
|
layer.loaderStyle = value as LoaderStyle;
|
package/src/ui/cost-footer.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { homedir } from "node:os";
|
|
|
2
2
|
import type { Usage } from "@earendil-works/pi-ai";
|
|
3
3
|
import type { ExtensionAPI, ExtensionContext, SessionEntry } from "@earendil-works/pi-coding-agent";
|
|
4
4
|
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
5
|
+
import type { CostDisplayMode } from "../prefs/settings.ts";
|
|
5
6
|
|
|
6
7
|
export function footerUsage(entries: readonly SessionEntry[]) {
|
|
7
8
|
const totals = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0 };
|
|
@@ -46,18 +47,39 @@ export class CostFooterController {
|
|
|
46
47
|
private installed = false;
|
|
47
48
|
private requestRender: (() => void) | undefined;
|
|
48
49
|
|
|
50
|
+
private publishedMode: CostDisplayMode | undefined;
|
|
51
|
+
private statusContext: ExtensionContext | undefined;
|
|
49
52
|
constructor(
|
|
50
53
|
private readonly pi: Pick<ExtensionAPI, "getCommands" | "events">,
|
|
51
54
|
private readonly subagentCost: () => number,
|
|
52
55
|
private readonly nerdFontIcons: () => boolean,
|
|
56
|
+
private readonly displayMode: () => CostDisplayMode = () => "pi-footer-status",
|
|
53
57
|
) {}
|
|
54
58
|
|
|
55
59
|
refresh(ctx: ExtensionContext): void {
|
|
56
|
-
|
|
57
|
-
this.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
const mode = this.displayMode();
|
|
61
|
+
const value = formatSubagentCost(this.subagentCost(), this.nerdFontIcons());
|
|
62
|
+
if (this.publishedMode !== undefined && this.publishedMode !== mode) {
|
|
63
|
+
this.clear();
|
|
64
|
+
this.reset(ctx);
|
|
65
|
+
}
|
|
66
|
+
this.publishedMode = mode;
|
|
67
|
+
if (mode !== "pi-footer-event") {
|
|
68
|
+
if (ctx.hasUI) {
|
|
69
|
+
this.statusContext = ctx;
|
|
70
|
+
const statusValue =
|
|
71
|
+
mode === "pi-status"
|
|
72
|
+
? `Total: ${formatSubagentCost(
|
|
73
|
+
footerUsage(ctx.sessionManager.getEntries()).cost + this.subagentCost(),
|
|
74
|
+
this.nerdFontIcons(),
|
|
75
|
+
)}`
|
|
76
|
+
: value;
|
|
77
|
+
ctx.ui.setStatus(COST_WIDGET_ID, statusValue);
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
// Event mode also works in headless sessions; status modes need a UI consumer.
|
|
82
|
+
this.pi.events.emit(COST_WIDGET_EVENT, { widgetId: COST_WIDGET_ID, value });
|
|
61
83
|
if (hasExternalFooter(this.pi)) {
|
|
62
84
|
// Do not clear setFooter here: it could already belong to pi-footer.
|
|
63
85
|
this.installed = false;
|
|
@@ -80,7 +102,11 @@ export class CostFooterController {
|
|
|
80
102
|
}
|
|
81
103
|
|
|
82
104
|
clear(): void {
|
|
83
|
-
this.
|
|
105
|
+
if (this.publishedMode === "pi-footer-event")
|
|
106
|
+
this.pi.events.emit(COST_WIDGET_EVENT, { widgetId: COST_WIDGET_ID, value: null });
|
|
107
|
+
this.statusContext?.ui.setStatus(COST_WIDGET_ID, undefined);
|
|
108
|
+
this.statusContext = undefined;
|
|
109
|
+
this.publishedMode = undefined;
|
|
84
110
|
}
|
|
85
111
|
}
|
|
86
112
|
|
package/src/ui/settings-ui.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from "./dialog.ts";
|
|
9
9
|
import {
|
|
10
10
|
DEFAULT_MANAGER_SETTINGS,
|
|
11
|
+
type CostDisplayMode,
|
|
11
12
|
LOADER_STYLES,
|
|
12
13
|
type LoaderStyle,
|
|
13
14
|
loadManagerSaveScope,
|
|
@@ -117,6 +118,24 @@ const WIDGET_MODE_OPTIONS = [
|
|
|
117
118
|
const WIDGET_MODE_HELP =
|
|
118
119
|
"Full: detailed agent status rows above the input box.\nMinimal: one-line status counts and cumulative input/output tokens for active (starting/running) agents.\nSave and apply to update the widget immediately.";
|
|
119
120
|
|
|
121
|
+
const COST_DISPLAY_OPTIONS = [
|
|
122
|
+
{
|
|
123
|
+
id: "pi-footer-event",
|
|
124
|
+
label: "pi-footer event",
|
|
125
|
+
help: "Publish settled subagent-only USD via pi-footer:update-widget with Widget ID subagent_cost. Add a Pi Event Value widget manually and enable Raw value only. Without an external /footer, retain the combined-cost fallback.",
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
id: "pi-footer-status",
|
|
129
|
+
label: "pi-footer status key",
|
|
130
|
+
help: "Publish settled subagent-only USD under status key subagent_cost for pi-footer’s Extension Status selector, including $0.0000 before any cost settles. Does not replace your footer.",
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
id: "pi-status",
|
|
134
|
+
label: "Pi status only",
|
|
135
|
+
help: "Only update Pi’s status with total USD cost: main session + all settled subagents. pi-footer modes show subagent-only cost. No pi-footer events or custom footer. Third-party footers may also consume this status key.",
|
|
136
|
+
},
|
|
137
|
+
] as const;
|
|
138
|
+
|
|
120
139
|
const MODEL_SELECTION_OPTIONS = [
|
|
121
140
|
{
|
|
122
141
|
id: "pick-first-available",
|
|
@@ -207,6 +226,12 @@ async function configureAgentsDialog(
|
|
|
207
226
|
value: WIDGET_MODE_OPTIONS.find((mode) => mode.id === draft.widgetMode)!.label,
|
|
208
227
|
help: WIDGET_MODE_HELP,
|
|
209
228
|
},
|
|
229
|
+
{
|
|
230
|
+
id: "costDisplay",
|
|
231
|
+
label: "[labs] Cost display",
|
|
232
|
+
value: COST_DISPLAY_OPTIONS.find((mode) => mode.id === draft.costDisplay)!.label,
|
|
233
|
+
help: "Choose pi-footer event, pi-footer status key (default), or Pi status only. ID: subagent_cost. pi-footer modes: settled subagent-only USD. Pi status: main session + all settled subagents; publishes on session start and as soon as a subagent starts. Save to apply immediately.",
|
|
234
|
+
},
|
|
210
235
|
{
|
|
211
236
|
id: "nerdFontIcons",
|
|
212
237
|
label: "[labs] Nerd Font icons",
|
|
@@ -306,6 +331,12 @@ async function configureAgentsDialog(
|
|
|
306
331
|
});
|
|
307
332
|
if (WIDGET_MODE_OPTIONS.some((option) => option.id === mode))
|
|
308
333
|
draft.widgetMode = mode as WidgetMode;
|
|
334
|
+
} else if (action === "costDisplay") {
|
|
335
|
+
const mode = await dialogMenu(ctx, "[labs] Cost display", [...COST_DISPLAY_OPTIONS], {
|
|
336
|
+
selectedId: draft.costDisplay,
|
|
337
|
+
});
|
|
338
|
+
if (COST_DISPLAY_OPTIONS.some((option) => option.id === mode))
|
|
339
|
+
draft.costDisplay = mode as CostDisplayMode;
|
|
309
340
|
} else if (action === "nerdFontIcons") {
|
|
310
341
|
draft.nerdFontIcons = !draft.nerdFontIcons;
|
|
311
342
|
} else if (action === "loaderStyle") {
|