pi-subagent-manager 0.29.0 β 0.29.3
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 +28 -82
- package/docs/settings.md +5 -3
- package/docs/tools-and-ui.md +17 -9
- package/package.json +1 -1
- package/src/index.ts +6 -1
- package/src/orch/housekeeping-usage.ts +47 -0
- package/src/orch/housekeeping.ts +13 -0
- package/src/orch/manager.ts +3 -1
- package/src/ui/thread-tree.ts +7 -4
- package/src/ui/ui.ts +3 -3
package/README.md
CHANGED
|
@@ -6,111 +6,57 @@
|
|
|
6
6
|
[](https://github.com/championswimmer/pi-subagent-manager/actions/workflows/tests.yml)
|
|
7
7
|
[](https://codecov.io/gh/championswimmer/pi-subagent-manager)
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
π [Changelog](CHANGELOG.md)
|
|
9
|
+
Let pi hand work to helper agents in parallel. Watch what they're doing, give them more direction, or pick up a finished agent's conversation.
|
|
12
10
|
|
|
13
11
|
## Install
|
|
14
12
|
|
|
15
|
-
Requires pi **0.99.2+**.
|
|
13
|
+
Requires pi **0.99.2+**.
|
|
16
14
|
|
|
17
15
|
```sh
|
|
18
16
|
pi install npm:pi-subagent-manager
|
|
19
17
|
```
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
```sh
|
|
24
|
-
pi install /absolute/path/to/pi-subagent
|
|
25
|
-
# Or try it without installing:
|
|
26
|
-
pi -e ./src/index.ts
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## How it works
|
|
19
|
+
## Start using it
|
|
30
20
|
|
|
31
|
-
|
|
21
|
+
Ask pi to delegate in plain language:
|
|
32
22
|
|
|
33
|
-
|
|
34
|
-
- **Like Codex:** every running agent has a **path**, such as `/root/fix-auth/review`. The path says _where it sits_ in the tree.
|
|
23
|
+
> Have a reviewer check my last commit while a researcher looks up how this repo handles retries.
|
|
35
24
|
|
|
36
|
-
|
|
25
|
+
Or start an agent yourself:
|
|
37
26
|
|
|
38
27
|
```text
|
|
39
|
-
/
|
|
40
|
-
/root/fix-auth β child: starts with a snapshot of /root
|
|
41
|
-
/root/fix-auth/review β grandchild: snapshot of /root/fix-auth
|
|
42
|
-
/k β independent root: no /root history
|
|
28
|
+
/agents fork:coder fix the failing auth test
|
|
43
29
|
```
|
|
44
30
|
|
|
45
|
-
|
|
31
|
+
`fork:` includes your current conversation. Use `fresh:` instead for a task that needs no conversation history.
|
|
46
32
|
|
|
47
|
-
|
|
48
|
-
- **Pause** β hands back without an answer; resume it later.
|
|
49
|
-
- **Report progress** β sends updates while it keeps working.
|
|
50
|
-
- **Be steered** β the parent can send it more input, or resume it after it finishes.
|
|
51
|
-
- **Survive restarts** β threads are saved with the main session and come back on `/reload` or `pi --resume`.
|
|
33
|
+
The **Agents** widget above the input shows what's running. Open `/agents tree`, select an agent, and press **Enter** to watch it. Type in the **Steer** input to give it more direction or resume it after it finishes. Results also return to the main agent.
|
|
52
34
|
|
|
53
35
|
## Bundled agents
|
|
54
36
|
|
|
55
|
-
|
|
|
56
|
-
| ------------ |
|
|
57
|
-
| `architect` | Plans, tradeoffs, coordinating
|
|
58
|
-
| `coder` | Implementation
|
|
59
|
-
| `researcher` |
|
|
60
|
-
| `reviewer` | Finding
|
|
61
|
-
| `tasker` | Small
|
|
62
|
-
| `writer` |
|
|
63
|
-
|
|
64
|
-
They inherit your current model until you set preferences. Details: [docs/default-agents.md](docs/default-agents.md).
|
|
65
|
-
|
|
66
|
-
## Commands
|
|
67
|
-
|
|
68
|
-
| Command | Opens |
|
|
69
|
-
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
70
|
-
| `/agents` | Settings (mode, limits, model picking, tool filtering) |
|
|
71
|
-
| `/agents types` | Agent-type browser and editor |
|
|
72
|
-
| `/agents tree` | Fullscreen tree and live viewer with manual steering |
|
|
73
|
-
| `/agents import` | Import agents from other subagent extensions |
|
|
74
|
-
| `/agents fork:<agent> <task>` | Start a detached agent that inherits your current conversation (autocompletes every available agent) |
|
|
75
|
-
| `/agents fresh:<agent> <task>` | Start a detached agent with no inherited context (autocompletes every available agent) |
|
|
76
|
-
| `/agents reload` | Reload definitions and settings |
|
|
77
|
-
| `/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. |
|
|
78
|
-
|
|
79
|
-
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. Arrow keys walk **tree β full β minimal**: 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, and **Left** at the start of the draft to step back to full and then, while subagents are starting or running, into the tree (otherwise Left stays native). With the Minimal setting the walk is just **tree β minimal**. In the tree, **Right** on a leaf returns to the widget. `/agents tree` remains available regardless of agent activity. See [live navigation](docs/tools-and-ui.md#live-agent-navigation) for controls and compatibility.
|
|
80
|
-
|
|
81
|
-
**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.
|
|
82
|
-
|
|
83
|
-
- Open **[labs] Footer display** in `/agents settings` to choose a location (**Replace Pi status**, **pi-footer status widget**, or **pi-footer event**), a value (**Only subagent cost** or **Total cost**), and a money icon. Defaults: status widget, settled subagent-only cost, and π΅. The stable ID/key is **`subagent_cost`**.
|
|
84
|
-
- **`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.
|
|
85
|
-
- Values publish at session start and immediately on subagent startup, including `π΅ $0.0000`, then after settlement/settings changes. Total cost includes the main session plus settled subagents. The icon picker offers three Nerd Font choices when the labs toggle is on, otherwise three emoji choices. Status modes leave your footer untouched; event mode retains a fallback showing the selected value/icon when no extension provides `/footer`. See [Cost display settings](docs/settings.md#labs-cost-display-costdisplay) and the [pi-footer setup guide with exact snippets](docs/pi-footer.md).
|
|
86
|
-
|
|
87
|
-
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 Braille, ASCII (`| / - \`), ASCII Star (`+ x *`), or ASCII Pulse (`= * -`) with Nerd Fonts off; enabling Nerd Fonts also unlocks Circle and 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).
|
|
88
|
-
|
|
89
|
-
Enable **[labs] Enable subagent extensions** in `/agents settings` to reload configured user and trusted-project extension hooks in each subagentβs separate session. It is off by default and experimental: hooks that assume main-session state can cause bugs or unintended consequences. This is configured-file discovery, **not exact main-session inheritance**; CLI-only, inline, and built-in extensions are not reloaded. See [subagent extension settings](docs/settings.md#labs-enable-subagent-extensions-subagentextensions) and read the [limitations](docs/subagent-extension-limitations.md) before enabling.
|
|
90
|
-
|
|
91
|
-
Enable **[labs] Final Recap** in `/agents` to automatically ask the idle main agent to collect detached-agent results and continue unfinished work, or recap when the overall task is complete, 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).
|
|
92
|
-
|
|
93
|
-
**[labs] Checklist integration** is always listed in `/agents settings` but can only be turned on while a loaded, active [pi-checklist](https://github.com/championswimmer/pi-checklist) β₯3.0.0 has task meta enabled (`/checklist settings meta`). When on and eligible, the main agent's prompt explains tagging tasks with `meta.agent`; in Orchestration mode the main agent must use the checklist. See [Checklist integration](docs/settings.md#labs-checklist-integration-checklistintegration).
|
|
37
|
+
| Agent | Use it for |
|
|
38
|
+
| ------------ | --------------------------------------- |
|
|
39
|
+
| `architect` | Plans, tradeoffs, coordinating helpers |
|
|
40
|
+
| `coder` | Implementation and debugging |
|
|
41
|
+
| `researcher` | Codebase and web research |
|
|
42
|
+
| `reviewer` | Finding correctness and security issues |
|
|
43
|
+
| `tasker` | Small jobs and quick lookups |
|
|
44
|
+
| `writer` | Drafting and editing prose |
|
|
94
45
|
|
|
95
|
-
|
|
46
|
+
They use your current model until you configure preferences. Open `/agents types` to change a role's model, tools, or instructions, or [add your own agent](docs/custom-agents.md).
|
|
96
47
|
|
|
97
|
-
##
|
|
48
|
+
## Settings and safety
|
|
98
49
|
|
|
99
|
-
|
|
100
|
-
- [Settings](docs/settings.md) β every setting and option, and when to use each
|
|
101
|
-
- [Threads and lifecycle](docs/threads.md) β paths, context, pause/resume, persistence
|
|
102
|
-
- [Asynchronous lifecycle](docs/async-lifecycle.md) β flow and timing diagrams for completion, wakes, and continuation
|
|
103
|
-
- [Tools and UI](docs/tools-and-ui.md) β model-facing tools, parallel work, dialogs
|
|
104
|
-
- [Importing agents](docs/importing-agents.md) β migrate from other pi subagent packages
|
|
105
|
-
- [Bundled agents](docs/default-agents.md) β routing, tool boundaries, model suggestions
|
|
106
|
-
- [Development](docs/development.md) β tests, code layout, releases
|
|
50
|
+
Open `/agents` to change delegation mode, limits, and display settings; save with **Ctrl+S**. Experimental options are marked **[labs]** in their help.
|
|
107
51
|
|
|
108
|
-
|
|
52
|
+
Agents share your working directory and OS permissions: **tool policies are not a sandbox**. Don't run multiple subagent extensions together β they clash on `/agents`.
|
|
109
53
|
|
|
110
|
-
|
|
111
|
-
- Children can use your registered extension, MCP and web tools when [Tool Filtering](docs/settings.md#tool-filtering-toolfiltering) permits them. Skills are not automatically loaded; external tools share main-session resources/context.
|
|
112
|
-
- Don't run multiple subagent extensions together β they clash on `/agents`.
|
|
54
|
+
## Documentation
|
|
113
55
|
|
|
114
|
-
|
|
56
|
+
- [Commands and navigation](docs/tools-and-ui.md#commands) β watching, steering, stopping, and keyboard shortcuts
|
|
57
|
+
- [Settings](docs/settings.md) β models, tool access, limits, and experimental features
|
|
58
|
+
- [Custom agents](docs/custom-agents.md) Β· [Bundled roles](docs/default-agents.md)
|
|
59
|
+
- [Importing agents](docs/importing-agents.md) from other subagent packages
|
|
60
|
+
- [Development](docs/development.md) Β· [Changelog](CHANGELOG.md)
|
|
115
61
|
|
|
116
|
-
[MIT](LICENSE)
|
|
62
|
+
[MIT license](LICENSE)
|
package/docs/settings.md
CHANGED
|
@@ -102,6 +102,8 @@ Both status modes use the same public Pi status API: third-party footers may als
|
|
|
102
102
|
|
|
103
103
|
**Icon** (`costIcon`) offers `money` (default), `coins`, or `wallet`. With **[labs] Nerd Font icons** off, these appear as π΅, πͺ, or π. With it on, the picker and output use corresponding Nerd Font glyphs instead. The semantic choice survives toggling font mode.
|
|
104
104
|
|
|
105
|
+
**Cost accounting.** Agent rows show estimated USD cost, including cache reads and writes, when the provider reports it. Running costs stay in those rows until the agent completes, pauses, stops, or fails; then only newly incurred costs are added to the total. Resuming, reloading, navigating branches, or reaping agents does not lose those totals, and nested agents' costs are counted once. These totals do not change Pi's native session statistics.
|
|
106
|
+
|
|
105
107
|
See [Subagent dollar totals in pi-footer](pi-footer.md) for step-by-step setup and copy-paste widget configuration, status-key, and event snippets.
|
|
106
108
|
|
|
107
109
|
## [labs] Enable subagent extensions (`subagentExtensions`)
|
|
@@ -141,7 +143,7 @@ The scheduler retains pending notifications while the main agent is busy (includ
|
|
|
141
143
|
|
|
142
144
|
## [labs] Housekeeping model (`housekeepingEnabled`, `housekeepingModel`)
|
|
143
145
|
|
|
144
|
-
Experimental, **off by default**. A small model of your choice writes a **one-line summary of what each running agent is doing right now**, shown in the fullscreen tree (`/agents tree`) in place of the raw tool-call line (for example `Running the auth unit tests` instead of `Tool: bash`).
|
|
146
|
+
Experimental, **off by default**. A small model of your choice writes a **one-line summary of what each running agent is doing right now**, shown in the fullscreen tree (`/agents tree`) in place of the raw tool-call line (for example `Running the auth unit tests` instead of `Tool: bash`) and in the full status widget in place of the task.
|
|
145
147
|
|
|
146
148
|
Open **[labs] Housekeeping model** in `/agents settings` and set two things, then save with **Ctrl+S**:
|
|
147
149
|
|
|
@@ -155,7 +157,7 @@ Pick the model in the dialog's searchable picker. It lists **scoped models first
|
|
|
155
157
|
**What it does**
|
|
156
158
|
|
|
157
159
|
- After an agent's tool or text activity, the agent's task and its last few activity lines (tool names, a short single-line argument snippet such as a command or path, and assistant text) are sent to the housekeeping model, which replies with a single line of at most 80 characters.
|
|
158
|
-
-
|
|
160
|
+
- A nonblank summary is shown only while the agent is **starting or running**. Without one, or after completion, failure, pause or stop, the tree shows the original status (or task if empty) and the full status widget shows the task as before. The minimal count-only widget and live agent view are unchanged. The original status stays available on the thread (`agent_status` returns both `status` and `summary`).
|
|
159
161
|
- An explicit `agent_update` progress message or pause reason replaces the summary until fresh activity arrives.
|
|
160
162
|
- Summaries are display-only and live-only: they are never written to the session registry, restored after a reload, or counted in cost totals.
|
|
161
163
|
|
|
@@ -163,7 +165,7 @@ Pick the model in the dialog's searchable picker. It lists **scoped models first
|
|
|
163
165
|
|
|
164
166
|
**Throttling.** Each agent has at most one housekeeping call in flight and at most one every 10 seconds (activity during a call is coalesced into the next one, after a 1.5 s quiet period), with exponential backoff after failures. At most two calls run at once across all agents, each times out after 20 seconds, and a call is cancelled β and a late answer discarded β when the agent settles or restarts, the toggle or model changes, or the session changes.
|
|
165
167
|
|
|
166
|
-
**Privacy and cost.** The housekeeping model sees each agent's task and recent activity text, including command and path snippets, so choose a provider you are comfortable sending that to. Calls use extra tokens at that model's price and
|
|
168
|
+
**Privacy and cost.** The housekeeping model sees each agent's task and recent activity text, including command and path snippets, so choose a provider you are comfortable sending that to. Calls use extra tokens at that model's price. Reported usage (including failed, cancelled, or discarded answers) is recorded in the main session as native `usage` entries, contributing to Pi's session totals and the **Total** cost display, but not the **Subagents** cost total. Extensions such as pi-stats display the actual response model as `provider/model (subagent-manager)`. These accounting entries contain no task, prompt, tool arguments, or summary text and do not enter the model's conversation context.
|
|
167
169
|
|
|
168
170
|
## Model Picking (`modelSelection`)
|
|
169
171
|
|
package/docs/tools-and-ui.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Tools and UI
|
|
2
2
|
|
|
3
|
+
Use [commands](#commands) to manage agents yourself, or let the main agent use the [tools](#model-facing-tools) below. For context inheritance, saved sessions, and resuming work, see [Threads and lifecycle](threads.md).
|
|
4
|
+
|
|
3
5
|
## Tool picker
|
|
4
6
|
|
|
5
7
|
The allow/block tool picker lists session tools flat, except MCP tools named `mcp__<mcp>__<tool>`: those are grouped under one `mcp__<mcp>` row, collapsed by default. The row shows `[x]`, `[ ]` or `[-]` (mixed) and Enter toggles every tool in the group. Right expands the group, Left collapses it (Left on a child also collapses and selects the group). While searching, matching groups are expanded automatically.
|
|
@@ -47,14 +49,20 @@ Child progress and completion notifications are retained in the main agent's con
|
|
|
47
49
|
|
|
48
50
|
## Commands
|
|
49
51
|
|
|
50
|
-
| Command | Does
|
|
51
|
-
| ----------------------------- |
|
|
52
|
-
| `/agents`, `/agents settings` | [
|
|
53
|
-
| `/agents types` |
|
|
54
|
-
| `/agents tree [path]` |
|
|
55
|
-
| `/agents
|
|
56
|
-
| `/agents
|
|
57
|
-
| `/agents
|
|
52
|
+
| Command | Does |
|
|
53
|
+
| ----------------------------- | ---- |
|
|
54
|
+
| `/agents`, `/agents settings` | Open [settings](settings.md). **Agent definitions** opens the type editor. |
|
|
55
|
+
| `/agents types` | Browse and edit [agent types](custom-agents.md#editing-in-the-tui). |
|
|
56
|
+
| `/agents tree [path]` | Open the live tree; an optional path selects an agent. |
|
|
57
|
+
| `/agents fork:<agent> <task>` | Start an agent with your current conversation as context. |
|
|
58
|
+
| `/agents fresh:<agent> <task>` | Start an agent without inherited conversation context. |
|
|
59
|
+
| `/agents import` | Open the [import picker](importing-agents.md). |
|
|
60
|
+
| `/agents reload` | Reload definitions and settings; show diagnostics. |
|
|
61
|
+
| `/agents reap` | Confirm removal of eligible completed agents from the retained tree. |
|
|
62
|
+
|
|
63
|
+
Both `fork:` and `fresh:` autocomplete available agent types and start detached agents: you can keep working in the main conversation while they run.
|
|
64
|
+
|
|
65
|
+
`reap` shows how many agents are eligible before asking you to confirm. It frees retained-thread slots but preserves active parents and ancestors of retained threads. Reaped agents cannot be resumed; their session files are not deleted.
|
|
58
66
|
|
|
59
67
|
### `/agents tree` keys
|
|
60
68
|
|
|
@@ -103,7 +111,7 @@ Once the main turn has ended and no subagents are starting or running, either mo
|
|
|
103
111
|
|
|
104
112
|
In full mode:
|
|
105
113
|
|
|
106
|
-
- One row per agent: colored type pill, path, state, task, active time, input `β` / output `β` tokens.
|
|
114
|
+
- One row per agent: colored type pill, path, state, task, active time, input `β` / output `β` tokens. With **[labs] Housekeeping model** enabled, a nonblank summary replaces the task while the agent is starting/running; otherwise the task remains.
|
|
107
115
|
- Activity and lifecycle messages (such as `Completed; session retained`) are omitted to save space; detailed status remains available in `/agents tree` and `agent_status`.
|
|
108
116
|
- 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.
|
|
109
117
|
- Time freezes while paused and resumes on continue.
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -81,6 +81,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
81
81
|
complete: createHousekeepingCompleter(
|
|
82
82
|
() => context,
|
|
83
83
|
() => limits.housekeepingModel,
|
|
84
|
+
refreshCostFooter,
|
|
84
85
|
),
|
|
85
86
|
apply: (path, run, summary) => manager?.setSummary(path, run, summary) ?? false,
|
|
86
87
|
clear: (path, run) => void manager?.clearSummary(path, run),
|
|
@@ -583,7 +584,11 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
583
584
|
limits.checklistIntegration && limits.subagentMode !== "off" && currentChecklistStatus(ctx).eligible,
|
|
584
585
|
);
|
|
585
586
|
if (!prompt) return;
|
|
586
|
-
if (
|
|
587
|
+
if (
|
|
588
|
+
limits.subagentMode === "opportunistic" &&
|
|
589
|
+
"prompt" in event &&
|
|
590
|
+
event.prompt.startsWith(IMPORT_REQUEST_PREFIX)
|
|
591
|
+
) {
|
|
587
592
|
try {
|
|
588
593
|
markImportOffered(getAgentDir());
|
|
589
594
|
} catch (error) {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ExtensionContext, SessionManager } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { AssistantMessage } from "@earendil-works/pi-ai";
|
|
3
|
+
|
|
4
|
+
export const HOUSEKEEPING_USAGE_KIND = "subagent-manager";
|
|
5
|
+
|
|
6
|
+
// ExtensionContext exposes a read-only type; the runtime manager supports appendUsage.
|
|
7
|
+
type UsageSession = Pick<SessionManager, "getSessionId"> &
|
|
8
|
+
Partial<Pick<SessionManager, "appendUsage">>;
|
|
9
|
+
|
|
10
|
+
export interface HousekeepingUsageSession {
|
|
11
|
+
manager: UsageSession;
|
|
12
|
+
sessionId: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Capture before async provider work: old extension-context getters become invalid on replacement. */
|
|
16
|
+
export function captureHousekeepingUsageSession(
|
|
17
|
+
ctx: Pick<ExtensionContext, "sessionManager">,
|
|
18
|
+
): HousekeepingUsageSession | undefined {
|
|
19
|
+
try {
|
|
20
|
+
const manager = ctx.sessionManager as UsageSession;
|
|
21
|
+
return { manager, sessionId: manager.getSessionId() };
|
|
22
|
+
} catch {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Account once even when the answer is failed, aborted, empty or no longer displayable. */
|
|
28
|
+
export function reportHousekeepingUsage(
|
|
29
|
+
session: HousekeepingUsageSession | undefined,
|
|
30
|
+
response: AssistantMessage,
|
|
31
|
+
): ReturnType<SessionManager["appendUsage"]> | undefined {
|
|
32
|
+
if (!response.usage || !session) return undefined;
|
|
33
|
+
try {
|
|
34
|
+
// SDK callers can mutate a manager in place; never charge its replacement session.
|
|
35
|
+
if (session.manager.getSessionId() !== session.sessionId) return undefined;
|
|
36
|
+
return session.manager.appendUsage?.(
|
|
37
|
+
HOUSEKEEPING_USAGE_KIND,
|
|
38
|
+
response.provider,
|
|
39
|
+
response.responseModel ?? response.model,
|
|
40
|
+
response.usage,
|
|
41
|
+
"housekeeping model call",
|
|
42
|
+
);
|
|
43
|
+
} catch {
|
|
44
|
+
// Accounting failure must not change housekeeping's success/fallback behavior.
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
package/src/orch/housekeeping.ts
CHANGED
|
@@ -3,6 +3,10 @@ import { stripTerminalSequences } from "@earendil-works/pi-tui";
|
|
|
3
3
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
4
4
|
import type { ThreadActivity } from "../types.ts";
|
|
5
5
|
import { modelIdentity } from "../prefs/models.ts";
|
|
6
|
+
import {
|
|
7
|
+
captureHousekeepingUsageSession,
|
|
8
|
+
reportHousekeepingUsage,
|
|
9
|
+
} from "./housekeeping-usage.ts";
|
|
6
10
|
|
|
7
11
|
/**
|
|
8
12
|
* [labs] Housekeeping: a user-chosen model names each active agent's current work in one line.
|
|
@@ -305,6 +309,7 @@ export function resolveHousekeepingModel(
|
|
|
305
309
|
export function createHousekeepingCompleter(
|
|
306
310
|
getContext: () => ExtensionContext | undefined,
|
|
307
311
|
getModelIdentity: () => string,
|
|
312
|
+
onUsageRecorded?: (ctx: ExtensionContext) => void,
|
|
308
313
|
): HousekeepingOptions["complete"] {
|
|
309
314
|
return async (request, signal) => {
|
|
310
315
|
const ctx = getContext();
|
|
@@ -312,6 +317,7 @@ export function createHousekeepingCompleter(
|
|
|
312
317
|
const identity = getModelIdentity();
|
|
313
318
|
const model = resolveHousekeepingModel(ctx, identity);
|
|
314
319
|
if (!model) throw new Error(`Housekeeping model ${identity || "(none)"} is unavailable`);
|
|
320
|
+
const session = captureHousekeepingUsageSession(ctx);
|
|
315
321
|
const response = await ctx.modelRegistry
|
|
316
322
|
.streamSimple(
|
|
317
323
|
model,
|
|
@@ -328,6 +334,13 @@ export function createHousekeepingCompleter(
|
|
|
328
334
|
{ signal, maxTokens: 96, cacheRetention: "none" },
|
|
329
335
|
)
|
|
330
336
|
.result();
|
|
337
|
+
// Account reported usage before checking whether this answer is usable or still current.
|
|
338
|
+
const entry = reportHousekeepingUsage(session, response);
|
|
339
|
+
try {
|
|
340
|
+
if (entry && getContext() === ctx) onUsageRecorded?.(ctx);
|
|
341
|
+
} catch {
|
|
342
|
+
/* A stale context or UI failure must not turn a successful summary into a failure. */
|
|
343
|
+
}
|
|
331
344
|
if (response.stopReason === "error" || response.stopReason === "aborted")
|
|
332
345
|
throw new Error(response.errorMessage || `Housekeeping model ${response.stopReason}`);
|
|
333
346
|
return response.content
|
package/src/orch/manager.ts
CHANGED
|
@@ -36,7 +36,7 @@ interface Record {
|
|
|
36
36
|
liveInputTokens?: number;
|
|
37
37
|
liveOutputTokens?: number;
|
|
38
38
|
liveCostUsd?: number;
|
|
39
|
-
/** Detached (spawned with wait:false): completion is reported as an event. */
|
|
39
|
+
/** Detached (spawned with wait:false or resumed): completion is reported as an event. */
|
|
40
40
|
async?: boolean;
|
|
41
41
|
timeoutTimer?: ReturnType<typeof setTimeout>;
|
|
42
42
|
pauseRequested: boolean;
|
|
@@ -414,6 +414,8 @@ export class ThreadManager {
|
|
|
414
414
|
return rearm();
|
|
415
415
|
}
|
|
416
416
|
this.assertCapacity();
|
|
417
|
+
// Resumes return immediately, regardless of the original spawn mode or restored metadata.
|
|
418
|
+
record.async = true;
|
|
417
419
|
this.start(record, message);
|
|
418
420
|
return rearm();
|
|
419
421
|
}
|
package/src/ui/thread-tree.ts
CHANGED
|
@@ -3,13 +3,16 @@ import type { ThreadView } from "../types.ts";
|
|
|
3
3
|
const ROOT = "/root";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* A [labs] housekeeping summary is shown only while the agent is active.
|
|
7
|
+
* Detailed rows fall back to status/task; the compact widget supplies its task-only fallback.
|
|
8
8
|
*/
|
|
9
|
-
export function threadActivity(
|
|
9
|
+
export function threadActivity(
|
|
10
|
+
thread: ThreadView,
|
|
11
|
+
fallback = thread.status || thread.task,
|
|
12
|
+
): string {
|
|
10
13
|
const active = thread.state === "starting" || thread.state === "running";
|
|
11
14
|
const summary = typeof thread.summary === "string" ? thread.summary.trim() : "";
|
|
12
|
-
return (active && summary) ||
|
|
15
|
+
return (active && summary) || fallback;
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
export interface StatusRow {
|
package/src/ui/ui.ts
CHANGED
|
@@ -42,7 +42,7 @@ import { getModelPreferences } from "../prefs/models.ts";
|
|
|
42
42
|
import type { LoaderStyle, WidgetMode } from "../prefs/settings.ts";
|
|
43
43
|
import { AGENT_PROGRESS_INTERVAL, agentProgressIcon, isAgentLoaderGlyph } from "./agent-loader.ts";
|
|
44
44
|
export { AGENT_PROGRESS_INTERVAL, agentProgressIcon } from "./agent-loader.ts";
|
|
45
|
-
import { buildStatusTree, lastStarted, type StatusRow } from "./thread-tree.ts";
|
|
45
|
+
import { buildStatusTree, lastStarted, threadActivity, type StatusRow } from "./thread-tree.ts";
|
|
46
46
|
import { THINKING_LEVELS, type AgentType, type ThreadService, type ThreadView } from "../types.ts";
|
|
47
47
|
|
|
48
48
|
export type ThreadController = Pick<
|
|
@@ -200,7 +200,7 @@ export function renderThreads(
|
|
|
200
200
|
);
|
|
201
201
|
const path = agentPath(thread.path, thread.color, theme);
|
|
202
202
|
const state = theme.fg(stateColor, `[${sanitizeText(thread.state)}]`);
|
|
203
|
-
const left = `${badge} ${path} ${state} ${sanitizeText(thread
|
|
203
|
+
const left = `${badge} ${path} ${state} ${sanitizeText(threadActivity(thread))}`;
|
|
204
204
|
return fitLine(left, theme.fg("muted", threadMetrics(thread)), Math.max(0, width));
|
|
205
205
|
});
|
|
206
206
|
if (visible.length > limit) {
|
|
@@ -277,7 +277,7 @@ function agentLine(
|
|
|
277
277
|
nerdFontIcons,
|
|
278
278
|
agentProgressIcon(thread, nerdFontIcons, Date.now(), animate, loaderStyle),
|
|
279
279
|
);
|
|
280
|
-
const left = `${row.prefix}${badge} ${agentPath(thread.path, thread.color, theme)} ${theme.fg(agentStateColor(thread.state), `[${sanitizeText(thread.state)}]`)} ${sanitizeText(thread.task)}`;
|
|
280
|
+
const left = `${row.prefix}${badge} ${agentPath(thread.path, thread.color, theme)} ${theme.fg(agentStateColor(thread.state), `[${sanitizeText(thread.state)}]`)} ${sanitizeText(threadActivity(thread, thread.task))}`;
|
|
281
281
|
return fitLine(left, theme.fg("muted", threadMetrics(thread)), width);
|
|
282
282
|
}
|
|
283
283
|
|