pi-subagent-manager 0.28.1 β 0.29.1
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 -80
- package/docs/development.md +1 -0
- package/docs/settings.md +30 -0
- package/docs/tools-and-ui.md +18 -10
- package/package.json +1 -1
- package/src/index.ts +53 -1
- package/src/orch/housekeeping-usage.ts +47 -0
- package/src/orch/housekeeping.ts +351 -0
- package/src/orch/manager.ts +69 -0
- package/src/orch/runtime.ts +26 -3
- package/src/prefs/config.ts +22 -0
- package/src/prefs/settings.ts +20 -3
- package/src/types.ts +24 -1
- package/src/ui/model-picker.ts +216 -0
- package/src/ui/settings-ui.ts +53 -0
- package/src/ui/status-ui.ts +2 -2
- package/src/ui/thread-tree.ts +13 -0
- package/src/ui/ui.ts +52 -11
package/README.md
CHANGED
|
@@ -6,109 +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
|
-
```
|
|
19
|
+
## Start using it
|
|
28
20
|
|
|
29
|
-
|
|
21
|
+
Ask pi to delegate in plain language:
|
|
30
22
|
|
|
31
|
-
|
|
23
|
+
> Have a reviewer check my last commit while a researcher looks up how this repo handles retries.
|
|
32
24
|
|
|
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.
|
|
35
|
-
|
|
36
|
-
Type and path are independent. One `reviewer` type can run at `/root/fix-auth/review` and `/root/docs-pass/review` at the same time.
|
|
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).
|
|
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 |
|
|
92
45
|
|
|
93
|
-
|
|
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).
|
|
94
47
|
|
|
95
|
-
##
|
|
48
|
+
## Settings and safety
|
|
96
49
|
|
|
97
|
-
|
|
98
|
-
- [Settings](docs/settings.md) β every setting and option, and when to use each
|
|
99
|
-
- [Threads and lifecycle](docs/threads.md) β paths, context, pause/resume, persistence
|
|
100
|
-
- [Asynchronous lifecycle](docs/async-lifecycle.md) β flow and timing diagrams for completion, wakes, and continuation
|
|
101
|
-
- [Tools and UI](docs/tools-and-ui.md) β model-facing tools, parallel work, dialogs
|
|
102
|
-
- [Importing agents](docs/importing-agents.md) β migrate from other pi subagent packages
|
|
103
|
-
- [Bundled agents](docs/default-agents.md) β routing, tool boundaries, model suggestions
|
|
104
|
-
- [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.
|
|
105
51
|
|
|
106
|
-
|
|
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`.
|
|
107
53
|
|
|
108
|
-
|
|
109
|
-
- 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.
|
|
110
|
-
- Don't run multiple subagent extensions together β they clash on `/agents`.
|
|
54
|
+
## Documentation
|
|
111
55
|
|
|
112
|
-
|
|
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)
|
|
113
61
|
|
|
114
|
-
[MIT](LICENSE)
|
|
62
|
+
[MIT license](LICENSE)
|
package/docs/development.md
CHANGED
|
@@ -20,6 +20,7 @@ Tests run offline with no model credentials. Scripted-provider SDK tests cover n
|
|
|
20
20
|
| `src/orch/mailbox.ts` | Input persistence, replay, transcript reconciliation |
|
|
21
21
|
| `src/orch/tools.ts` | Caller-bound model tools |
|
|
22
22
|
| `src/orch/prompt.ts` | System-prompt guidance per mode |
|
|
23
|
+
| `src/orch/housekeeping.ts` | [labs] Housekeeping summarizer: throttling, cancellation, model resolution and the one-line summary call |
|
|
23
24
|
| `src/prefs/config.ts` | Frontmatter validation, precedence, atomic saves |
|
|
24
25
|
| `src/prefs/settings.ts` | Manager settings, validation, safe paths |
|
|
25
26
|
| `src/prefs/models.ts` | Model selection |
|
package/docs/settings.md
CHANGED
|
@@ -23,6 +23,8 @@ All keys are optional. Defaults:
|
|
|
23
23
|
"finalRecap": false,
|
|
24
24
|
"subagentExtensions": false,
|
|
25
25
|
"checklistIntegration": false,
|
|
26
|
+
"housekeepingEnabled": false,
|
|
27
|
+
"housekeepingModel": "",
|
|
26
28
|
"modelSelection": "pick-first-scoped",
|
|
27
29
|
"toolFiltering": "allowed",
|
|
28
30
|
"maxLevels": 3,
|
|
@@ -100,6 +102,8 @@ Both status modes use the same public Pi status API: third-party footers may als
|
|
|
100
102
|
|
|
101
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.
|
|
102
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
|
+
|
|
103
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.
|
|
104
108
|
|
|
105
109
|
## [labs] Enable subagent extensions (`subagentExtensions`)
|
|
@@ -137,6 +141,32 @@ The scheduler retains pending notifications while the main agent is busy (includ
|
|
|
137
141
|
|
|
138
142
|
**Enabling Final Recap may cause extra model turns and uses more tokens and context.** Leave it off if you prefer to inspect results manually in `/agents tree` or request a summary yourself.
|
|
139
143
|
|
|
144
|
+
## [labs] Housekeeping model (`housekeepingEnabled`, `housekeepingModel`)
|
|
145
|
+
|
|
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.
|
|
147
|
+
|
|
148
|
+
Open **[labs] Housekeeping model** in `/agents settings` and set two things, then save with **Ctrl+S**:
|
|
149
|
+
|
|
150
|
+
| Key | Meaning |
|
|
151
|
+
| --- | --- |
|
|
152
|
+
| `housekeepingEnabled` | The opt-in toggle (`false` by default). |
|
|
153
|
+
| `housekeepingModel` | `provider/model-id` of the housekeeping model, or `""` for none. |
|
|
154
|
+
|
|
155
|
+
Pick the model in the dialog's searchable picker. It lists **scoped models first** (the main session's `/scoped-models`), then **every other available model** (any model with working credentials). A small, fast, inexpensive model is usually enough. Turning **Summaries** Off keeps the chosen model for later; **No model** clears it. Both keys follow the normal Global / Current Project layering, and the dots show where each is saved.
|
|
156
|
+
|
|
157
|
+
**What it does**
|
|
158
|
+
|
|
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.
|
|
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`).
|
|
161
|
+
- An explicit `agent_update` progress message or pause reason replaces the summary until fresh activity arrives.
|
|
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.
|
|
163
|
+
|
|
164
|
+
**Never worse than off.** If the feature is disabled, no model is selected, the model is unknown, lacks credentials, or the request fails, times out or returns nothing usable, agents show exactly the status they would show without the feature. The first failure after you change settings or switch sessions produces one warning; failed calls then back off and stop for that run after three consecutive failures. Subagent Mode **Off** also turns it off.
|
|
165
|
+
|
|
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.
|
|
167
|
+
|
|
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.
|
|
169
|
+
|
|
140
170
|
## Model Picking (`modelSelection`)
|
|
141
171
|
|
|
142
172
|
Which model an agent gets when its session starts.
|
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.
|
|
@@ -34,7 +36,7 @@ are omitted. Spawning under another parent path can change inherited settings.
|
|
|
34
36
|
|
|
35
37
|
Then `agent_wait` or `agent_status` on `/root/controller-security-research`.
|
|
36
38
|
|
|
37
|
-
Child progress and completion notifications are retained in the main agent's context without adding visible chat messages. When a detached (`wait: false`) agent completes, fails or is stopped, the main agent receives a message event that starts a new turn if it is idle (or right after its current turn settles), so it never has to poll. Progress updates and foreground results do not start a turn. The opt-in **[labs] Final Recap** setting changes this: completion messages for async agents are recorded without waking the main agent, and once **all outstanding async agents have reported**, one recap turn summarizes them. Enabling it uses more tokens and context. Use the Agents widget, `/agents tree`, or `agent_output` to inspect child status and answers.
|
|
39
|
+
Child progress and completion notifications are retained in the main agent's context without adding visible chat messages. When a detached (`wait: false`) agent completes, fails or is stopped, the main agent receives a message event that starts a new turn if it is idle (or right after its current turn settles), so it never has to poll. Progress updates and foreground results do not start a turn. The opt-in **[labs] Final Recap** setting changes this: completion messages for async agents are recorded without waking the main agent, and once **all outstanding async agents have reported**, one recap turn summarizes them. Enabling it uses more tokens and context. Use the Agents widget, `/agents tree`, or `agent_output` to inspect child status and answers. With the opt-in **[labs] Housekeeping model**, `/agents tree` shows a model-written one-line summary of each running agent's current work in place of its raw tool-call line (see [settings](settings.md#labs-housekeeping-model-housekeepingenabled-housekeepingmodel)).
|
|
38
40
|
|
|
39
41
|
`agent_spawn` accepts an optional `timeoutMs` (30000β300000, i.e. 30sβ5min; out-of-range values are rejected; no timeout when omitted). If the child is still running when it elapses, the parent receives an event (always waking an idle main agent, even in recap mode) with the child's state, status, elapsed time, tokens and recent output. The child is **not** stopped; the parent decides to wait, steer or stop it. The timer is cleared when the child completes, fails, stops or is cancelled, and on session shutdown. It is not re-armed when a child is later resumed with `agent_steer`. `agent_steer` also accepts `timeoutMs` (same 30sβ5min range) and `message` is then optional: `timeoutMs` alone only re-arms a running child's timer from now (no steering or resume; error if the child is not running), e.g. after a timeout event shows it is still progressing; with both, the child is steered/resumed and the timer re-armed. At least one of the two is required.
|
|
40
42
|
|
|
@@ -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
|
@@ -14,6 +14,11 @@ import { configureAgents } from "./ui/settings-ui.ts";
|
|
|
14
14
|
import { AgentNavigationController } from "./ui/status-ui.ts";
|
|
15
15
|
import { AgentNavigationEditor } from "./ui/agent-navigation-editor.ts";
|
|
16
16
|
import { createDriverFactory } from "./orch/runtime.ts";
|
|
17
|
+
import {
|
|
18
|
+
createHousekeepingCompleter,
|
|
19
|
+
HousekeepingSummarizer,
|
|
20
|
+
resolveHousekeepingModel,
|
|
21
|
+
} from "./orch/housekeeping.ts";
|
|
17
22
|
import { createInheritedToolSource } from "./orch/inherited-tools.ts";
|
|
18
23
|
import { subagentPrompt } from "./orch/prompt.ts";
|
|
19
24
|
import { ChecklistMetaMirror, checklistStatus } from "./orch/checklist-integration.ts";
|
|
@@ -65,6 +70,36 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
65
70
|
agentDir: getAgentDir(),
|
|
66
71
|
includeProject: false,
|
|
67
72
|
}).settings;
|
|
73
|
+
// [labs] Housekeeping: inert unless opted in, a model is chosen, and it resolves with credentials.
|
|
74
|
+
const housekeeping = new HousekeepingSummarizer({
|
|
75
|
+
isEnabled: () =>
|
|
76
|
+
limits.subagentMode !== "off" &&
|
|
77
|
+
limits.housekeepingEnabled &&
|
|
78
|
+
limits.housekeepingModel !== "" &&
|
|
79
|
+
context !== undefined &&
|
|
80
|
+
resolveHousekeepingModel(context, limits.housekeepingModel) !== undefined,
|
|
81
|
+
complete: createHousekeepingCompleter(
|
|
82
|
+
() => context,
|
|
83
|
+
() => limits.housekeepingModel,
|
|
84
|
+
refreshCostFooter,
|
|
85
|
+
),
|
|
86
|
+
apply: (path, run, summary) => manager?.setSummary(path, run, summary) ?? false,
|
|
87
|
+
clear: (path, run) => void manager?.clearSummary(path, run),
|
|
88
|
+
onFailure: (message) =>
|
|
89
|
+
context?.ui.notify(
|
|
90
|
+
`Housekeeping summaries failed (${message}); showing normal agent status instead.`,
|
|
91
|
+
"warning",
|
|
92
|
+
),
|
|
93
|
+
});
|
|
94
|
+
let housekeepingKey = "";
|
|
95
|
+
/** Settings changed: drop in-flight work and stale summaries so the new choice starts clean. */
|
|
96
|
+
const syncHousekeeping = () => {
|
|
97
|
+
const key = `${limits.subagentMode === "off"}|${limits.housekeepingEnabled}|${limits.housekeepingModel}`;
|
|
98
|
+
if (key === housekeepingKey) return;
|
|
99
|
+
housekeepingKey = key;
|
|
100
|
+
housekeeping.cancelAll();
|
|
101
|
+
manager?.clearSummaries();
|
|
102
|
+
};
|
|
68
103
|
const loadLimits = (ctx: ExtensionContext) => {
|
|
69
104
|
const loaded = loadManagerSettings({
|
|
70
105
|
cwd: ctx.cwd,
|
|
@@ -72,6 +107,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
72
107
|
includeProject: ctx.isProjectTrusted(),
|
|
73
108
|
});
|
|
74
109
|
limits = loaded.settings;
|
|
110
|
+
syncHousekeeping();
|
|
75
111
|
refreshCostFooter(ctx);
|
|
76
112
|
return loaded.diagnostics;
|
|
77
113
|
};
|
|
@@ -548,7 +584,11 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
548
584
|
limits.checklistIntegration && limits.subagentMode !== "off" && currentChecklistStatus(ctx).eligible,
|
|
549
585
|
);
|
|
550
586
|
if (!prompt) return;
|
|
551
|
-
if (
|
|
587
|
+
if (
|
|
588
|
+
limits.subagentMode === "opportunistic" &&
|
|
589
|
+
"prompt" in event &&
|
|
590
|
+
event.prompt.startsWith(IMPORT_REQUEST_PREFIX)
|
|
591
|
+
) {
|
|
552
592
|
try {
|
|
553
593
|
markImportOffered(getAgentDir());
|
|
554
594
|
} catch (error) {
|
|
@@ -566,6 +606,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
566
606
|
seedHistory = true,
|
|
567
607
|
) => {
|
|
568
608
|
cancelSummary();
|
|
609
|
+
housekeeping.cancelAll();
|
|
569
610
|
const token = ++generation;
|
|
570
611
|
closeNavigation(installEditor);
|
|
571
612
|
navigation = new AgentNavigationController(returnToWidget);
|
|
@@ -602,8 +643,18 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
602
643
|
const message = error instanceof Error ? error.message : String(error);
|
|
603
644
|
context?.ui.notify(`Subagent ${event.kind} notification failed: ${message}`, "warning");
|
|
604
645
|
},
|
|
646
|
+
onActivity: (activity) => {
|
|
647
|
+
if (token === generation) housekeeping.notify(activity);
|
|
648
|
+
},
|
|
605
649
|
onEvent: (event) => {
|
|
606
650
|
if (token !== generation) return;
|
|
651
|
+
// Settled agents and explicit progress reports (which replace the summary) cancel pending
|
|
652
|
+
// housekeeping so an older request cannot reapply stale text; fresh activity reschedules.
|
|
653
|
+
if (
|
|
654
|
+
event.kind === "update" ||
|
|
655
|
+
(event.thread.state !== "starting" && event.thread.state !== "running")
|
|
656
|
+
)
|
|
657
|
+
housekeeping.settle(event.thread.path);
|
|
607
658
|
refreshWidget(requireContext());
|
|
608
659
|
if (event.kind !== "metrics") persist();
|
|
609
660
|
if (event.kind === "settled") rollupCost(event.thread);
|
|
@@ -669,6 +720,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
669
720
|
pi.on("session_before_fork", stopWorkingThreads);
|
|
670
721
|
pi.on("session_shutdown", async () => {
|
|
671
722
|
cancelSummary();
|
|
723
|
+
housekeeping.cancelAll();
|
|
672
724
|
generation++;
|
|
673
725
|
closeNavigation(true);
|
|
674
726
|
await manager?.shutdown();
|
|
@@ -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
|
+
}
|