pi-session-subagents 0.3.0 → 0.4.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/CHANGELOG.md +11 -0
- package/README.md +22 -25
- package/package.json +2 -1
- package/skills/subagents/SKILL.md +130 -0
- package/src/copy.ts +10 -44
- package/src/index.ts +16 -6
- package/src/tools.ts +183 -183
- package/src/ui/conversation-viewer.ts +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.4.0](https://github.com/rbajaj1997/pi-session-subagents/compare/v0.3.0...v0.4.0) (2026-11-28)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### ⚠ BREAKING CHANGES
|
|
7
|
+
|
|
8
|
+
* Replaced list_subagents, inspect_subagent, message_subagent, await_subagents, and stop_subagent with manage_subagents. Both spawn_subagent and manage_subagents are now active by default.
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* expose spawn_subagent and manage_subagents by default with bundled skill ([6a2432b](https://github.com/rbajaj1997/pi-session-subagents/commit/6a2432bf0599dee4b6649d7a77ede978dfae3f45))
|
|
13
|
+
|
|
3
14
|
## [0.3.0](https://github.com/rbajaj1997/pi-session-subagents/compare/v0.2.0...v0.3.0) (2026-11-28)
|
|
4
15
|
|
|
5
16
|
|
package/README.md
CHANGED
|
@@ -21,7 +21,6 @@ This is conversational reuse, not a background job service. Workers do not survi
|
|
|
21
21
|
|
|
22
22
|
- Pi 1.5.2 is the SDK and TUI compatibility target. Older versions are not supported; other versions have not been validated.
|
|
23
23
|
- Node.js 24 or newer.
|
|
24
|
-
- Model credentials and configuration available to Pi.
|
|
25
24
|
|
|
26
25
|
## Install
|
|
27
26
|
|
|
@@ -47,10 +46,10 @@ Restart Pi or use `/reload` after changing enabled extensions. Keep only one cop
|
|
|
47
46
|
|
|
48
47
|
## Quick start
|
|
49
48
|
|
|
50
|
-
|
|
49
|
+
`spawn_subagent` and `manage_subagents` are active by default, alongside a bundled `subagents` skill (`skills/subagents/SKILL.md`) that holds detailed workflow guidance and examples. Ask Pi to delegate directly:
|
|
51
50
|
|
|
52
51
|
```text
|
|
53
|
-
|
|
52
|
+
Create two idle workers named scout and reviewer using Haiku. Keep them ready without assigning tasks.
|
|
54
53
|
```
|
|
55
54
|
|
|
56
55
|
Then ask Pi to use an existing worker:
|
|
@@ -73,27 +72,23 @@ Workers can be limited and given deadlines:
|
|
|
73
72
|
Spawn a read-only worker with only read, grep, find, and ls, low thinking, and a 5 minute timeout to map the database layer.
|
|
74
73
|
```
|
|
75
74
|
|
|
76
|
-
|
|
75
|
+
To stop and remove all workers and turn both tools off, use `/subagents off`. It stops workers right away, even while the parent waits in `manage_subagents` (`action: "wait"`), and turns the tools off once the parent's current run ends. Turning them off lasts until `/subagents on` or `/reload`, while the bundled `subagents` skill remains listed in Pi's skill list. Use `/subagents on` or `/subagents <request>` to turn both tools back on.
|
|
77
76
|
|
|
78
77
|
## Commands and tools
|
|
79
78
|
|
|
80
79
|
| Command | Purpose |
|
|
81
80
|
| --- | --- |
|
|
82
|
-
| `/subagents
|
|
83
|
-
| `/subagents
|
|
84
|
-
| `/subagents <request>` |
|
|
81
|
+
| `/subagents off` | Stop and remove workers, then disable both subagent tools. |
|
|
82
|
+
| `/subagents on` | Re-enable both subagent tools. |
|
|
83
|
+
| `/subagents <request>` | Ensure both subagent tools are enabled and send the request. |
|
|
85
84
|
| `/subagents:inspect [name]` | Open a live, read-only conversation inspector. Interactive TUI only. |
|
|
86
85
|
|
|
87
86
|
| Tool | Purpose |
|
|
88
87
|
| --- | --- |
|
|
89
|
-
| `spawn_subagent` | Create a worker.
|
|
90
|
-
| `
|
|
91
|
-
| `inspect_subagent` | Read status, capabilities, the session file path, recent conversation lines, or paginated result text. |
|
|
92
|
-
| `message_subagent` | Start an idle worker, continue a completed worker, or steer a running one. |
|
|
93
|
-
| `await_subagents` | Wait for named workers, or all running ones. |
|
|
94
|
-
| `stop_subagent` | Stop a worker, remove it, and wait until its session is closed. |
|
|
88
|
+
| `spawn_subagent` | Create a worker. Pass `task` to start it immediately, or omit `task` to keep it idle without a model call. |
|
|
89
|
+
| `manage_subagents` | Run `list`, `inspect`, `message`, `wait`, or `stop` via an action-specific `request` schema. |
|
|
95
90
|
|
|
96
|
-
Only the parent uses these tools. Workers do not load this extension, so they cannot spawn other workers or message siblings.
|
|
91
|
+
Only the parent uses these tools and the bundled `subagents` skill. Workers do not load this extension, so they cannot spawn other workers or message siblings.
|
|
97
92
|
|
|
98
93
|
## Worker options
|
|
99
94
|
|
|
@@ -109,13 +104,13 @@ Only the parent uses these tools. Workers do not load this extension, so they ca
|
|
|
109
104
|
| `cwd` | parent's cwd | Working directory, absolute or relative to the parent's. It must exist. |
|
|
110
105
|
| `timeoutMs` | no limit | Deadline for the initial task. |
|
|
111
106
|
|
|
112
|
-
`
|
|
107
|
+
`manage_subagents` with `action: "message"` also accepts `timeoutMs` for the task it starts. It is ignored when the message steers a running worker. A steering message belongs to the current task: if the worker finishes while the message is still being processed, the message starts another turn of that task, and the report waits for it. When a deadline expires, the run is aborted and reported as an error, steering messages it has not read yet are dropped, and the worker stays available for follow-ups.
|
|
113
108
|
|
|
114
109
|
If you press Escape while `spawn_subagent` is still creating a worker, the worker is discarded before its task starts. Once `spawn_subagent` returns, the worker runs on its own until it finishes or you stop it.
|
|
115
110
|
|
|
116
|
-
`
|
|
111
|
+
`manage_subagents` with `action: "wait"` accepts `names` and `timeoutMs`. With a timeout it stops waiting when the time is up and lists the workers still running. Those workers keep running.
|
|
117
112
|
|
|
118
|
-
Waiting is rarely needed, because completion reports arrive on their own. While `
|
|
113
|
+
Waiting is rarely needed, because completion reports arrive on their own. While `wait` runs, the parent's turn stays open and messages you send are held until it returns. The tool guidelines tell the model to wait only when it needs results now or you ask it to.
|
|
119
114
|
|
|
120
115
|
## Results and reports
|
|
121
116
|
|
|
@@ -125,13 +120,13 @@ In the TUI, Escape clears the parent's queued messages, including reports it has
|
|
|
125
120
|
|
|
126
121
|
The model-visible report contains the first 12,000 UTF-16 code units of the result, keeping line breaks and surrogate pairs intact at page boundaries. The full result stays in the expandable report card, which renders it as Markdown, and in the worker's session file.
|
|
127
122
|
|
|
128
|
-
For longer results, call `
|
|
123
|
+
For longer results, call `manage_subagents` with `action: "inspect"`, `includeResult: true`, the report's `runId`, and the continuation `resultOffset`. Starting another assignment clears the latest result, but earlier output stays in the conversation. Run ids are unique within the parent session, across all workers, so a `runId` that is not the worker's latest returns an error rather than a later assignment's output, even when a new worker reuses a removed worker's name.
|
|
129
124
|
|
|
130
|
-
`
|
|
125
|
+
`manage_subagents` with `action: "inspect"` and `tailLines` returns the last lines of the conversation as plain text, up to 50KB.
|
|
131
126
|
|
|
132
127
|
## Inspection
|
|
133
128
|
|
|
134
|
-
The main widget and the inspector need the interactive TUI. In RPC mode, use `
|
|
129
|
+
The main widget and the inspector need the interactive TUI. In RPC mode, use `manage_subagents` with `action: "list"` and `action: "inspect"`. The main widget shows worker status and activity. In fullscreen mode, Pi's default, click a worker in the widget to open its inspector. In regular mode the terminal handles the mouse, so use `/subagents:inspect [name]`. The inspector renders the worker's full session branch, including messages before compaction, with Pi's native assistant, user, custom-message, tool, and summary components. Tool cards use registered renderers, including edit diffs. Inline tool images are off in the inspector.
|
|
135
130
|
|
|
136
131
|
The header shows elapsed time for the current or most recent assignment in whole minutes (`<1m` for the first minute). The cost at the end, for example `~$0.123 total`, is Pi’s estimate across all assignments in that worker session, not a billing total.
|
|
137
132
|
|
|
@@ -147,7 +142,7 @@ The header shows elapsed time for the current or most recent assignment in whole
|
|
|
147
142
|
|
|
148
143
|
Each worker that runs a task writes its conversation to a session file under `~/.pi/agent/subagent-sessions/`, outside Pi's normal session list, so `pi -r` is not affected. Pi writes the file once the conversation starts, so a worker that stays idle leaves no file. All of a worker's tasks go into the same file, and the file records the parent session's path.
|
|
149
144
|
|
|
150
|
-
The completion report card shows `Session: pi --session <path>`, and the model-visible report and `
|
|
145
|
+
The completion report card shows `Session: pi --session <path>`, and the model-visible report and `manage_subagents` (`action: "inspect"`) include the path. After a worker is removed, or after Pi restarts, open its file with:
|
|
151
146
|
|
|
152
147
|
```sh
|
|
153
148
|
pi --session <path>
|
|
@@ -165,7 +160,7 @@ A worker in the parent's working directory uses the parent's project trust decis
|
|
|
165
160
|
|
|
166
161
|
Spawn results and inspection report the worker's enabled tools, callable tools, missing requested tools, and extension diagnostics. When a worker's tools include `codemode` or `tool_search`, the worker also loads Pi's codemode, tool search, and MCP extensions, so each such worker opens its own MCP connections. Worker extensions receive `session_shutdown` when the worker is removed.
|
|
167
162
|
|
|
168
|
-
The parent's system prompt does not change as workers start and finish, so the prompt cache stays valid. The model learns about workers from the tool guidelines and `
|
|
163
|
+
The parent's system prompt does not change as workers start and finish, so the prompt cache stays valid. The model learns about workers from the tool guidelines, the `subagents` skill, and `manage_subagents` (`action: "list"`).
|
|
169
164
|
|
|
170
165
|
Idle workers make no model calls but still use memory. Follow-ups include existing conversation context and are billed normally. There is no package-level concurrency cap. A host that exits disposes its workers; do not assume jobs outlive the parent process.
|
|
171
166
|
|
|
@@ -191,10 +186,12 @@ The package ships TypeScript source through `pi.extensions`. Pi loads it directl
|
|
|
191
186
|
`npm test` uses Node's built-in test runner with tsx to run the TypeScript tests. The tests use normal imports, and `tsc --noEmit` checks both `src/` and `tests/`. Tests exercise commands, the roster, worker lifecycle and steering, deadlines, report delivery, model selection, result pagination, transcript inspection, the widget, the inspector, and session cleanup. They use a controlled Pi session substitute and temporary directories, without model calls or credentials. Live provider discovery, trust configuration, and interactive TUI behavior still need checks in Pi.
|
|
192
187
|
|
|
193
188
|
```text
|
|
189
|
+
skills/
|
|
190
|
+
subagents/SKILL.md Bundled workflow guidance and examples for the parent model
|
|
194
191
|
src/
|
|
195
|
-
index.ts Wiring: tools, commands, session events
|
|
196
|
-
copy.ts
|
|
197
|
-
tools.ts
|
|
192
|
+
index.ts Wiring: tools, commands, skill discovery, session events
|
|
193
|
+
copy.ts Upfront tool copy, rules, and report hints; tool names come from here
|
|
194
|
+
tools.ts spawn_subagent and manage_subagents definitions and output formatting
|
|
198
195
|
roster.ts The session's workers: naming, spawning, messaging, waiting, stopping
|
|
199
196
|
worker.ts One worker and its run; stats and status are derived from its session
|
|
200
197
|
worker-session.ts Builds and shuts down a worker's Pi session
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-session-subagents",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Session-scoped subagents for Pi with idle workers, steering, and native transcript inspection.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
29
|
"src/",
|
|
30
|
+
"skills/",
|
|
30
31
|
"README.md",
|
|
31
32
|
"CHANGELOG.md",
|
|
32
33
|
"LICENSE"
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: subagents
|
|
3
|
+
description: Read when the user asks to delegate work using subagents; simple follow-ups do not require it.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Session subagents
|
|
7
|
+
|
|
8
|
+
Use `spawn_subagent` to create a worker in the current Pi session and `manage_subagents` to list, inspect, message, wait on, or stop existing workers. Workers have their own isolated context windows and cannot spawn nested subagents.
|
|
9
|
+
|
|
10
|
+
Only spawn workers when the user asks to delegate work or create workers. Do not use `spawn_subagent` as a probe or test; use `manage_subagents` to interact with existing workers.
|
|
11
|
+
|
|
12
|
+
## Write self-contained assignments
|
|
13
|
+
|
|
14
|
+
Subagents do not share conversation history or hidden reasoning with the parent or with each other. Include the goal, relevant file paths, constraints, and expected output format in the task.
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
"name": "auth-scout",
|
|
19
|
+
"task": "Inspect src/auth/ and summarize how access tokens are issued and refreshed. List key file paths and functions.",
|
|
20
|
+
"model": "haiku",
|
|
21
|
+
"thinking": "low",
|
|
22
|
+
"tools": ["read", "grep", "find", "ls"],
|
|
23
|
+
"timeoutMs": 300000
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Worker options
|
|
28
|
+
|
|
29
|
+
- `name`: Brief label (defaults to `worker`, `worker-2`, ...). Set this when the user asks for a specific role or name.
|
|
30
|
+
- `task`: Initial prompt. Omit or leave blank to create an idle worker without making a model call.
|
|
31
|
+
- `model`: Fuzzy name or `provider/id`. Defaults to the parent's model.
|
|
32
|
+
- `thinking`: `off`, `minimal`, `low`, `medium`, `high`, `xhigh`, or `max`. Defaults to the parent's level.
|
|
33
|
+
- `tools`: Subset of the parent's active tools. Use `["read", "grep", "find", "ls"]` for read-only exploration.
|
|
34
|
+
- `cwd`: Working directory, absolute or relative to the parent's `cwd`.
|
|
35
|
+
- `timeoutMs`: Deadline in milliseconds for the initial task. On expiry the run aborts and reports an error, while the worker stays available for follow-ups.
|
|
36
|
+
|
|
37
|
+
Workers discover configured credentials, providers, and extensions independently. Check `Enabled tools`, `Missing requested tools`, and `Warning` lines in the spawn result before relying on a capability or project resource in another directory.
|
|
38
|
+
|
|
39
|
+
## Create idle workers
|
|
40
|
+
|
|
41
|
+
When the user asks to keep workers ready or on standby, omit `task`. Do not assign a readiness-acknowledgment task.
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{
|
|
45
|
+
"name": "reviewer",
|
|
46
|
+
"model": "haiku"
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Start an idle worker later using `manage_subagents` with `action: "message"`.
|
|
51
|
+
|
|
52
|
+
## Follow up and steer
|
|
53
|
+
|
|
54
|
+
`manage_subagents` takes a `request` object whose `action` selects the operation.
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"request": {
|
|
59
|
+
"action": "message",
|
|
60
|
+
"name": "auth-scout",
|
|
61
|
+
"message": "Examine the token-refresh error handling in more detail.",
|
|
62
|
+
"timeoutMs": 180000
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
- On an idle or completed worker, `message` starts a new turn in that worker's existing conversation.
|
|
68
|
+
- On a running worker, `message` steers the current run (`timeoutMs` is ignored when steering).
|
|
69
|
+
- For unrelated work that needs a clean context, spawn a separate worker instead of reusing an existing one.
|
|
70
|
+
|
|
71
|
+
## Automatic reports vs waiting
|
|
72
|
+
|
|
73
|
+
Completion reports arrive on their own and wake you when you are idle. While workers run, end your turn instead of waiting so the user can keep talking to you.
|
|
74
|
+
|
|
75
|
+
Use `action: "wait"` only when you cannot answer without the workers' results now, or when the user asks you to wait. User messages are held until `wait` returns.
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"request": {
|
|
80
|
+
"action": "wait",
|
|
81
|
+
"names": ["auth-scout", "reviewer"],
|
|
82
|
+
"timeoutMs": 60000
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Omit `names` to wait for all running workers. If `timeoutMs` expires, `wait` returns the workers still running and leaves them running.
|
|
88
|
+
|
|
89
|
+
## Inspect and page long results
|
|
90
|
+
|
|
91
|
+
Completion reports include the first 12,000 characters of the result. When a report sets `truncated: true`, read the next page with `action: "inspect"`, passing `includeResult: true`, the report's `runId`, and `resultOffset: nextResultOffset`.
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"request": {
|
|
96
|
+
"action": "inspect",
|
|
97
|
+
"name": "auth-scout",
|
|
98
|
+
"includeResult": true,
|
|
99
|
+
"runId": 7,
|
|
100
|
+
"resultOffset": 11999
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Always pass the exact `nextResultOffset` value from the report or previous page.
|
|
106
|
+
|
|
107
|
+
Pass `runId` so you never accidentally read output from a later assignment. To inspect recent conversation lines instead, pass `tailLines` (up to 50KB). Omit both to read status, capabilities, and the session file path.
|
|
108
|
+
|
|
109
|
+
## List and stop workers
|
|
110
|
+
|
|
111
|
+
List all active workers in the session:
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"request": {
|
|
116
|
+
"action": "list"
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Stop a worker and remove it from the roster when it is no longer needed:
|
|
122
|
+
|
|
123
|
+
```json
|
|
124
|
+
{
|
|
125
|
+
"request": {
|
|
126
|
+
"action": "stop",
|
|
127
|
+
"name": "auth-scout"
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
```
|
package/src/copy.ts
CHANGED
|
@@ -1,57 +1,23 @@
|
|
|
1
|
-
import { RESULT_PAGE_CHARS } from "./text";
|
|
2
|
-
|
|
3
1
|
interface ToolCopy {
|
|
4
2
|
label: string;
|
|
5
3
|
description: string;
|
|
6
|
-
|
|
7
|
-
promptGuidelines?: string[];
|
|
4
|
+
promptGuidelines: string[];
|
|
8
5
|
}
|
|
9
6
|
|
|
10
7
|
export const TOOL_COPY = {
|
|
11
8
|
spawn_subagent: {
|
|
12
9
|
label: "Spawn Subagent",
|
|
13
10
|
description:
|
|
14
|
-
"Create a session-scoped
|
|
15
|
-
|
|
11
|
+
"Create a session-scoped worker with its own context. Pass task to start it immediately, or omit task to leave it idle.",
|
|
12
|
+
promptGuidelines: ["Only call spawn_subagent when the user asks to delegate work or create workers."],
|
|
13
|
+
},
|
|
14
|
+
manage_subagents: {
|
|
15
|
+
label: "Manage Subagents",
|
|
16
|
+
description: "Manage existing session subagents: list, inspect, message, wait, or stop.",
|
|
16
17
|
promptGuidelines: [
|
|
17
|
-
"
|
|
18
|
-
"Subagents do not share context with the parent or with each other.",
|
|
19
|
-
"Workers independently discover configured tools and providers. Check enabled and missing tools in the spawn result before assigning work that depends on a capability.",
|
|
20
|
-
"When asked to keep workers ready or on standby, omit task. Do not assign a readiness acknowledgment task. Start an idle worker later with message_subagent.",
|
|
21
|
-
"When the user wants a specific subagent name or role label, set the optional name field to that brief label.",
|
|
22
|
-
"Completion reports from workers arrive on their own and start a new turn when you are idle. While workers run, end your turn instead of waiting, so the user can keep talking to you.",
|
|
23
|
-
"Use await_subagents only when you cannot continue without the workers' results, such as combining several results in one answer, or when the user asks you to wait. Messages the user sends are held until await_subagents returns.",
|
|
24
|
-
"Do not use spawn_subagent as a probe or test. If the goal is to inspect, wait on, message, or stop an existing subagent, use those tools directly.",
|
|
18
|
+
"Worker completion reports arrive automatically; only use manage_subagents with action wait when you need results now or the user asks you to wait.",
|
|
25
19
|
],
|
|
26
20
|
},
|
|
27
|
-
list_subagents: {
|
|
28
|
-
label: "List Subagents",
|
|
29
|
-
description: "List all active subagents in the current session.",
|
|
30
|
-
promptSnippet: "List known subagents and their statuses.",
|
|
31
|
-
},
|
|
32
|
-
inspect_subagent: {
|
|
33
|
-
label: "Inspect Subagent",
|
|
34
|
-
description: `Inspect a subagent's status and actual capabilities. Optionally read the last result in ${RESULT_PAGE_CHARS.toLocaleString("en-US")}-character pages or include a recent transcript tail.`,
|
|
35
|
-
promptSnippet:
|
|
36
|
-
"Inspect worker status and capabilities, or read its full result with includeResult and resultOffset.",
|
|
37
|
-
},
|
|
38
|
-
message_subagent: {
|
|
39
|
-
label: "Message Subagent",
|
|
40
|
-
description:
|
|
41
|
-
"Send an instruction to a subagent. Starts an idle worker or continues a completed worker. If it is already running, the message steers its current work.",
|
|
42
|
-
promptSnippet: "Start an idle worker, continue a completed worker, or steer a busy worker.",
|
|
43
|
-
},
|
|
44
|
-
await_subagents: {
|
|
45
|
-
label: "Await Subagents",
|
|
46
|
-
description:
|
|
47
|
-
"Wait until the named subagents, or all running ones, finish. With timeoutMs, return when it expires and list the workers still running.",
|
|
48
|
-
promptSnippet: "Block until running subagents finish. Only when you need their results now.",
|
|
49
|
-
},
|
|
50
|
-
stop_subagent: {
|
|
51
|
-
label: "Stop Subagent",
|
|
52
|
-
description: "Stop a subagent and remove it from the roster.",
|
|
53
|
-
promptSnippet: "Stop a subagent and clear it from the active subagent list.",
|
|
54
|
-
},
|
|
55
21
|
} satisfies Record<string, ToolCopy>;
|
|
56
22
|
|
|
57
23
|
export type ToolName = keyof typeof TOOL_COPY;
|
|
@@ -72,8 +38,8 @@ export const WORKER_SYSTEM_PROMPT = [
|
|
|
72
38
|
export const LATE_STEER_TURN_MESSAGE = "The parent sent another instruction as you finished.";
|
|
73
39
|
|
|
74
40
|
export const READ_MORE_HINT =
|
|
75
|
-
|
|
41
|
+
'Use manage_subagents with request: { action: "inspect", name: "<agent>", includeResult: true, runId: <runId>, resultOffset: <nextResultOffset> }.';
|
|
76
42
|
|
|
77
43
|
export function timeoutMessage(duration: string): string {
|
|
78
|
-
return `Timed out after ${duration}. Its conversation is intact; send a follow-up with
|
|
44
|
+
return `Timed out after ${duration}. Its conversation is intact; send a follow-up with manage_subagents (action: "message") to continue.`;
|
|
79
45
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { dirname, join } from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
1
3
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
4
|
import { isSubagentTool, TOOL_NAMES } from "./copy";
|
|
3
5
|
import { registerReportDelivery } from "./report";
|
|
@@ -5,6 +7,8 @@ import { Roster } from "./roster";
|
|
|
5
7
|
import { subagentTools } from "./tools";
|
|
6
8
|
import { openInspector } from "./ui/conversation-viewer";
|
|
7
9
|
|
|
10
|
+
const packageDir = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
11
|
+
|
|
8
12
|
export default function (pi: ExtensionAPI) {
|
|
9
13
|
const roster = new Roster(pi);
|
|
10
14
|
|
|
@@ -13,6 +17,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
13
17
|
pi.setActiveTools(enabled ? [...others, ...TOOL_NAMES] : others);
|
|
14
18
|
}
|
|
15
19
|
|
|
20
|
+
// Register via resources_discover (not package.json pi.skills) so workers skip it when this extension is filtered out.
|
|
21
|
+
pi.on("resources_discover", () => ({ skillPaths: [join(packageDir, "skills")] }));
|
|
22
|
+
|
|
16
23
|
for (const tool of subagentTools(roster)) pi.registerTool(tool);
|
|
17
24
|
registerReportDelivery(pi, roster.reports);
|
|
18
25
|
|
|
@@ -24,11 +31,11 @@ export default function (pi: ExtensionAPI) {
|
|
|
24
31
|
|
|
25
32
|
pi.registerCommand("subagents", {
|
|
26
33
|
description:
|
|
27
|
-
"Use '
|
|
34
|
+
"Use 'off' to stop all workers and disable subagent tools, 'on' to re-enable them, or pass a request to ensure they are enabled and send it",
|
|
28
35
|
handler: async (args, ctx) => {
|
|
29
36
|
const request = args?.trim() || "";
|
|
30
37
|
if (!request) {
|
|
31
|
-
if (ctx.hasUI) ctx.ui.notify("Usage: /subagents
|
|
38
|
+
if (ctx.hasUI) ctx.ui.notify("Usage: /subagents off, /subagents on, or /subagents <request>", "info");
|
|
32
39
|
return;
|
|
33
40
|
}
|
|
34
41
|
const command = request.toLowerCase();
|
|
@@ -39,14 +46,18 @@ export default function (pi: ExtensionAPI) {
|
|
|
39
46
|
await ctx.waitForIdle();
|
|
40
47
|
setEnabled(false);
|
|
41
48
|
}
|
|
42
|
-
if (ctx.hasUI) ctx.ui.notify("
|
|
49
|
+
if (ctx.hasUI) ctx.ui.notify("All subagents stopped and subagent tools disabled.", "info");
|
|
43
50
|
return;
|
|
44
51
|
}
|
|
45
52
|
await ctx.waitForIdle();
|
|
46
|
-
|
|
53
|
+
const active = pi.getActiveTools();
|
|
54
|
+
if (!TOOL_NAMES.every((name) => active.includes(name))) {
|
|
47
55
|
setEnabled(true);
|
|
48
56
|
if (ctx.hasUI)
|
|
49
|
-
ctx.ui.notify(
|
|
57
|
+
ctx.ui.notify(
|
|
58
|
+
"Subagent tools on. Use /subagents off to stop all workers and disable the tools.",
|
|
59
|
+
"info",
|
|
60
|
+
);
|
|
50
61
|
}
|
|
51
62
|
if (command !== "on") pi.sendUserMessage(request);
|
|
52
63
|
},
|
|
@@ -54,7 +65,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
54
65
|
|
|
55
66
|
pi.on("session_start", async (_event, ctx) => {
|
|
56
67
|
roster.attach(ctx);
|
|
57
|
-
setEnabled(false);
|
|
58
68
|
});
|
|
59
69
|
|
|
60
70
|
pi.on("session_shutdown", async () => {
|
package/src/tools.ts
CHANGED
|
@@ -13,63 +13,76 @@ import { type TSchema, Type } from "typebox";
|
|
|
13
13
|
import { TOOL_COPY, type ToolName } from "./copy";
|
|
14
14
|
import type { Roster } from "./roster";
|
|
15
15
|
import { clip, formatDuration, getResultPage, messageText, shortModelLabel, summarizeToolArgs } from "./text";
|
|
16
|
-
import type { Worker } from "./worker";
|
|
16
|
+
import type { Worker, WorkerStatus } from "./worker";
|
|
17
17
|
|
|
18
18
|
const THINKING_LEVELS: ThinkingLevel[] = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
19
19
|
|
|
20
|
+
// Plain single-value string enum so every provider accepts the discriminator without const rewriting.
|
|
21
|
+
function actionLiteral<A extends string>(action: A) {
|
|
22
|
+
return Type.Unsafe<A>({ type: "string", enum: [action] });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const ManageRequestSchema = Type.Union([
|
|
26
|
+
Type.Object({ action: actionLiteral("list") }),
|
|
27
|
+
Type.Object({
|
|
28
|
+
action: actionLiteral("inspect"),
|
|
29
|
+
name: Type.String({ description: "Worker name" }),
|
|
30
|
+
tailLines: Type.Optional(Type.Integer({ minimum: 1, description: "Recent transcript lines, up to 50KB" })),
|
|
31
|
+
includeResult: Type.Optional(Type.Boolean({ description: "Include a page of the latest result" })),
|
|
32
|
+
runId: Type.Optional(Type.Integer({ minimum: 1, description: "Expected run id from the report" })),
|
|
33
|
+
resultOffset: Type.Optional(Type.Integer({ minimum: 0, description: "Character offset into the result" })),
|
|
34
|
+
}),
|
|
35
|
+
Type.Object({
|
|
36
|
+
action: actionLiteral("message"),
|
|
37
|
+
name: Type.String({ description: "Worker name" }),
|
|
38
|
+
message: Type.String({ description: "Instruction to send" }),
|
|
39
|
+
timeoutMs: Type.Optional(Type.Integer({ minimum: 1, description: "Deadline in ms when starting a task" })),
|
|
40
|
+
}),
|
|
41
|
+
Type.Object({
|
|
42
|
+
action: actionLiteral("wait"),
|
|
43
|
+
names: Type.Optional(Type.Array(Type.String(), { description: "Worker names; defaults to all running" })),
|
|
44
|
+
timeoutMs: Type.Optional(Type.Integer({ minimum: 1, description: "Stop waiting after this many ms" })),
|
|
45
|
+
}),
|
|
46
|
+
Type.Object({
|
|
47
|
+
action: actionLiteral("stop"),
|
|
48
|
+
name: Type.String({ description: "Worker name" }),
|
|
49
|
+
}),
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
type ManageDetails =
|
|
53
|
+
| { action: "list" }
|
|
54
|
+
| { action: "inspect"; name: string; status: WorkerStatus; runId: number }
|
|
55
|
+
| { action: "message"; name: string; mode: "steer" | "start" | "handled" }
|
|
56
|
+
| { action: "wait"; waiting: string[] }
|
|
57
|
+
| { action: "stop"; name: string };
|
|
58
|
+
|
|
20
59
|
function tool<P extends TSchema, D>(
|
|
21
60
|
name: ToolName,
|
|
22
|
-
definition: Omit<ToolDefinition<P, D>, "name" | "label" | "description" | "
|
|
61
|
+
definition: Omit<ToolDefinition<P, D>, "name" | "label" | "description" | "promptGuidelines">,
|
|
23
62
|
) {
|
|
24
|
-
return defineTool<P, D>({ ...definition, ...TOOL_COPY[name], name
|
|
63
|
+
return defineTool<P, D>({ ...definition, ...TOOL_COPY[name], name });
|
|
25
64
|
}
|
|
26
65
|
|
|
27
66
|
export function subagentTools(roster: Roster) {
|
|
28
67
|
return [
|
|
29
68
|
tool("spawn_subagent", {
|
|
30
69
|
parameters: Type.Object({
|
|
31
|
-
name: Type.Optional(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}),
|
|
36
|
-
),
|
|
37
|
-
task: Type.Optional(
|
|
38
|
-
Type.String({
|
|
39
|
-
description:
|
|
40
|
-
"Optional task to start immediately. Omit or leave blank to create an idle worker without a model call.",
|
|
41
|
-
}),
|
|
42
|
-
),
|
|
43
|
-
model: Type.Optional(
|
|
44
|
-
Type.String({ description: "Fuzzy model name such as 'opus', 'gpt-4.1', or provider/id" }),
|
|
45
|
-
),
|
|
46
|
-
cwd: Type.Optional(
|
|
47
|
-
Type.String({
|
|
48
|
-
description:
|
|
49
|
-
"Working directory for the subagent, absolute or relative to your cwd. Defaults to your cwd.",
|
|
50
|
-
}),
|
|
51
|
-
),
|
|
70
|
+
name: Type.Optional(Type.String({ description: "Short worker name. Defaults to 'worker'." })),
|
|
71
|
+
task: Type.Optional(Type.String({ description: "Initial task. Omit to create an idle worker." })),
|
|
72
|
+
model: Type.Optional(Type.String({ description: "Fuzzy model query or provider/id." })),
|
|
73
|
+
cwd: Type.Optional(Type.String({ description: "Working directory. Defaults to yours." })),
|
|
52
74
|
tools: Type.Optional(
|
|
53
|
-
Type.Array(Type.String(), {
|
|
54
|
-
description:
|
|
55
|
-
"Tool names for the worker, for example read, grep, find, ls for read-only exploration. Each must be active in this session. Defaults to all of your active tools.",
|
|
56
|
-
}),
|
|
75
|
+
Type.Array(Type.String(), { description: "Subset of your active tools. Defaults to all of them." }),
|
|
57
76
|
),
|
|
58
77
|
// A plain string enum, which every provider accepts. pi-ai's StringEnum is untyped for TypeBox.
|
|
59
78
|
thinking: Type.Optional(
|
|
60
79
|
Type.Unsafe<ThinkingLevel>({
|
|
61
80
|
type: "string",
|
|
62
81
|
enum: THINKING_LEVELS,
|
|
63
|
-
description: "
|
|
64
|
-
}),
|
|
65
|
-
),
|
|
66
|
-
timeoutMs: Type.Optional(
|
|
67
|
-
Type.Integer({
|
|
68
|
-
minimum: 1,
|
|
69
|
-
description:
|
|
70
|
-
"Deadline in milliseconds for the initial task. On expiry the run is aborted and reported as an error; the worker stays available. Defaults to no limit.",
|
|
82
|
+
description: "Thinking level. Defaults to yours.",
|
|
71
83
|
}),
|
|
72
84
|
),
|
|
85
|
+
timeoutMs: Type.Optional(Type.Integer({ minimum: 1, description: "Deadline in ms for the initial task." })),
|
|
73
86
|
}),
|
|
74
87
|
async execute(_id, params, signal, _onUpdate: unknown, ctx) {
|
|
75
88
|
const worker = await roster.spawn(params, ctx, signal);
|
|
@@ -120,156 +133,129 @@ export function subagentTools(roster: Roster) {
|
|
|
120
133
|
}),
|
|
121
134
|
}),
|
|
122
135
|
|
|
123
|
-
tool("
|
|
124
|
-
parameters: Type.Object({}),
|
|
125
|
-
async execute() {
|
|
126
|
-
const workers = roster.list();
|
|
127
|
-
const text = workers.length
|
|
128
|
-
? workers
|
|
129
|
-
.map(
|
|
130
|
-
(worker) =>
|
|
131
|
-
`${worker.name} [${worker.status} · ${shortModelLabel(worker.info.modelLabel)}] — ${clip(worker.task || "(idle)", 90)}`,
|
|
132
|
-
)
|
|
133
|
-
.join("\n")
|
|
134
|
-
: "No subagents.";
|
|
135
|
-
return { content: [{ type: "text", text }], details: undefined };
|
|
136
|
-
},
|
|
137
|
-
renderCall: (_args, theme) => new Text(theme.fg("toolTitle", theme.bold("list_subagents")), 0, 0),
|
|
138
|
-
}),
|
|
139
|
-
|
|
140
|
-
tool("inspect_subagent", {
|
|
136
|
+
tool("manage_subagents", {
|
|
141
137
|
parameters: Type.Object({
|
|
142
|
-
|
|
143
|
-
tailLines: Type.Optional(
|
|
144
|
-
Type.Integer({ minimum: 1, description: "Number of recent conversation lines to include, up to 50KB" }),
|
|
145
|
-
),
|
|
146
|
-
includeResult: Type.Optional(
|
|
147
|
-
Type.Boolean({ description: "Include a page of the latest run's result. Defaults to false." }),
|
|
148
|
-
),
|
|
149
|
-
runId: Type.Optional(
|
|
150
|
-
Type.Integer({
|
|
151
|
-
minimum: 1,
|
|
152
|
-
description:
|
|
153
|
-
"Expected run id when reading a result. Pass the report's runId to avoid reading output from a later assignment or another worker.",
|
|
154
|
-
}),
|
|
155
|
-
),
|
|
156
|
-
resultOffset: Type.Optional(
|
|
157
|
-
Type.Integer({
|
|
158
|
-
minimum: 0,
|
|
159
|
-
description:
|
|
160
|
-
"Character offset into the result, starting at 0. Use the next offset returned by the previous page.",
|
|
161
|
-
}),
|
|
162
|
-
),
|
|
138
|
+
request: ManageRequestSchema,
|
|
163
139
|
}),
|
|
164
|
-
async execute(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
140
|
+
async execute(
|
|
141
|
+
_id,
|
|
142
|
+
params,
|
|
143
|
+
signal,
|
|
144
|
+
onUpdate: AgentToolUpdateCallback<ManageDetails> | undefined,
|
|
145
|
+
): Promise<AgentToolResult<ManageDetails>> {
|
|
146
|
+
const { request } = params;
|
|
147
|
+
switch (request.action) {
|
|
148
|
+
case "list": {
|
|
149
|
+
const workers = roster.list();
|
|
150
|
+
const text = workers.length
|
|
151
|
+
? workers
|
|
152
|
+
.map(
|
|
153
|
+
(worker) =>
|
|
154
|
+
`${worker.name} [${worker.status} · ${shortModelLabel(worker.info.modelLabel)}] — ${clip(worker.task || "(idle)", 90)}`,
|
|
155
|
+
)
|
|
156
|
+
.join("\n")
|
|
157
|
+
: "No subagents.";
|
|
158
|
+
return { content: [{ type: "text", text }], details: { action: "list" } };
|
|
159
|
+
}
|
|
160
|
+
case "inspect": {
|
|
161
|
+
const worker = roster.find(request.name);
|
|
162
|
+
return {
|
|
163
|
+
content: [{ type: "text", text: inspectText(worker, request) }],
|
|
164
|
+
details: { action: "inspect", name: worker.name, status: worker.status, runId: worker.runId },
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
case "message": {
|
|
168
|
+
const { worker, mode } = await roster.message(request.name, request.message, request.timeoutMs);
|
|
169
|
+
const verb =
|
|
170
|
+
mode === "steer"
|
|
171
|
+
? "Steered"
|
|
172
|
+
: mode === "start"
|
|
173
|
+
? "Started"
|
|
174
|
+
: "An input handler in the worker consumed the message for";
|
|
175
|
+
return {
|
|
176
|
+
content: [{ type: "text", text: `${verb} ${worker.name}: ${request.message}` }],
|
|
177
|
+
details: { action: "message", name: worker.name, mode },
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
case "wait": {
|
|
181
|
+
const waitUpdate: AgentToolUpdateCallback<{ waiting: string[] }> | undefined = onUpdate
|
|
182
|
+
? (update) =>
|
|
183
|
+
onUpdate({
|
|
184
|
+
content: update.content,
|
|
185
|
+
details: { action: "wait", waiting: update.details.waiting },
|
|
186
|
+
})
|
|
187
|
+
: undefined;
|
|
188
|
+
const waiting = (await roster.waitFor(request.names, request.timeoutMs, signal, waitUpdate)).map(
|
|
189
|
+
(worker) => worker.name,
|
|
190
|
+
);
|
|
191
|
+
const text = waiting.length
|
|
192
|
+
? `Stopped waiting after ${formatDuration(request.timeoutMs ?? 0)}. Still running: ${waiting.join(", ")}.`
|
|
193
|
+
: "All awaited subagents have finished.";
|
|
194
|
+
return { content: [{ type: "text", text }], details: { action: "wait", waiting } };
|
|
195
|
+
}
|
|
196
|
+
case "stop": {
|
|
197
|
+
const worker = await roster.stop(request.name);
|
|
198
|
+
return {
|
|
199
|
+
content: [{ type: "text", text: `Stopped and removed ${worker.name}.` }],
|
|
200
|
+
details: { action: "stop", name: worker.name },
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
}
|
|
170
204
|
},
|
|
171
|
-
renderCall: (args, theme) =>
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
"
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
content: [{ type: "text", text: `${verb} ${worker.name}: ${params.message}` }],
|
|
202
|
-
details: { name: worker.name, mode },
|
|
203
|
-
};
|
|
205
|
+
renderCall: (args, theme) => {
|
|
206
|
+
const request = args.request;
|
|
207
|
+
switch (request?.action) {
|
|
208
|
+
case "list":
|
|
209
|
+
return callLine(theme, "manage_subagents", "list");
|
|
210
|
+
case "inspect":
|
|
211
|
+
return callLine(
|
|
212
|
+
theme,
|
|
213
|
+
"manage_subagents inspect",
|
|
214
|
+
request.name || "",
|
|
215
|
+
request.includeResult
|
|
216
|
+
? "result"
|
|
217
|
+
: request.tailLines
|
|
218
|
+
? `last ${request.tailLines} lines`
|
|
219
|
+
: undefined,
|
|
220
|
+
);
|
|
221
|
+
case "message":
|
|
222
|
+
return callLine(theme, "manage_subagents message", request.name || "", request.message);
|
|
223
|
+
case "wait":
|
|
224
|
+
return callLine(
|
|
225
|
+
theme,
|
|
226
|
+
"manage_subagents wait",
|
|
227
|
+
request.names?.join(", ") || "all running",
|
|
228
|
+
request.timeoutMs ? `timeout ${formatDuration(request.timeoutMs)}` : undefined,
|
|
229
|
+
);
|
|
230
|
+
case "stop":
|
|
231
|
+
return callLine(theme, "manage_subagents stop", request.name || "");
|
|
232
|
+
default:
|
|
233
|
+
return new Text(theme.fg("toolTitle", theme.bold("manage_subagents")), 0, 0);
|
|
234
|
+
}
|
|
204
235
|
},
|
|
205
|
-
renderCall: (args, theme) => callLine(theme, "message_subagent", args.name, args.message),
|
|
206
236
|
renderResult: (result, options, theme, context) =>
|
|
207
|
-
resultLine(result, options, theme, context, () => {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
237
|
+
resultLine(result, options, theme, context, (text) => {
|
|
238
|
+
switch (result.details.action) {
|
|
239
|
+
case "message": {
|
|
240
|
+
const { name, mode } = result.details;
|
|
241
|
+
return (
|
|
242
|
+
theme.fg(
|
|
243
|
+
"success",
|
|
244
|
+
mode === "steer" ? "↪ steered " : mode === "start" ? "▶ started " : "✓ handled by ",
|
|
245
|
+
) + theme.bold(name)
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
case "wait":
|
|
249
|
+
return result.details.waiting.length
|
|
250
|
+
? theme.fg("warning", `… still running: ${result.details.waiting.join(", ")}`)
|
|
251
|
+
: theme.fg("success", "✓ all finished");
|
|
252
|
+
case "stop":
|
|
253
|
+
return theme.fg("muted", "■ removed ") + theme.bold(result.details.name);
|
|
254
|
+
default:
|
|
255
|
+
return previewLines(text, options.expanded, theme);
|
|
256
|
+
}
|
|
215
257
|
}),
|
|
216
258
|
}),
|
|
217
|
-
|
|
218
|
-
tool("await_subagents", {
|
|
219
|
-
parameters: Type.Object({
|
|
220
|
-
names: Type.Optional(
|
|
221
|
-
Type.Array(Type.String(), { description: "Subagents to wait for. Defaults to all running subagents." }),
|
|
222
|
-
),
|
|
223
|
-
timeoutMs: Type.Optional(
|
|
224
|
-
Type.Integer({
|
|
225
|
-
minimum: 1,
|
|
226
|
-
description: "Stop waiting after this many milliseconds. The workers keep running.",
|
|
227
|
-
}),
|
|
228
|
-
),
|
|
229
|
-
}),
|
|
230
|
-
async execute(_id, params, signal, onUpdate: AgentToolUpdateCallback<{ waiting: string[] }> | undefined) {
|
|
231
|
-
const waiting = (await roster.waitFor(params.names, params.timeoutMs, signal, onUpdate)).map(
|
|
232
|
-
(worker) => worker.name,
|
|
233
|
-
);
|
|
234
|
-
const text = waiting.length
|
|
235
|
-
? `Stopped waiting after ${formatDuration(params.timeoutMs ?? 0)}. Still running: ${waiting.join(", ")}.`
|
|
236
|
-
: "All awaited subagents have finished.";
|
|
237
|
-
return { content: [{ type: "text", text }], details: { waiting } };
|
|
238
|
-
},
|
|
239
|
-
renderCall: (args, theme) =>
|
|
240
|
-
callLine(
|
|
241
|
-
theme,
|
|
242
|
-
"await_subagents",
|
|
243
|
-
args.names?.join(", ") || "all running",
|
|
244
|
-
args.timeoutMs ? `timeout ${formatDuration(args.timeoutMs)}` : undefined,
|
|
245
|
-
),
|
|
246
|
-
renderResult: (result, options, theme, context) =>
|
|
247
|
-
resultLine(result, options, theme, context, () =>
|
|
248
|
-
result.details.waiting.length
|
|
249
|
-
? theme.fg("warning", `… still running: ${result.details.waiting.join(", ")}`)
|
|
250
|
-
: theme.fg("success", "✓ all finished"),
|
|
251
|
-
),
|
|
252
|
-
}),
|
|
253
|
-
|
|
254
|
-
tool("stop_subagent", {
|
|
255
|
-
parameters: Type.Object({ name: Type.String({ description: "Subagent name" }) }),
|
|
256
|
-
async execute(_id, params) {
|
|
257
|
-
const worker = await roster.stop(params.name);
|
|
258
|
-
return {
|
|
259
|
-
content: [{ type: "text", text: `Stopped and removed ${worker.name}.` }],
|
|
260
|
-
details: { name: worker.name },
|
|
261
|
-
};
|
|
262
|
-
},
|
|
263
|
-
renderCall: (args, theme) => callLine(theme, "stop_subagent", args.name),
|
|
264
|
-
renderResult: (result, options, theme, context) =>
|
|
265
|
-
resultLine(
|
|
266
|
-
result,
|
|
267
|
-
options,
|
|
268
|
-
theme,
|
|
269
|
-
context,
|
|
270
|
-
() => theme.fg("muted", "■ removed ") + theme.bold(result.details.name),
|
|
271
|
-
),
|
|
272
|
-
}),
|
|
273
259
|
];
|
|
274
260
|
}
|
|
275
261
|
|
|
@@ -311,7 +297,9 @@ function inspectText(
|
|
|
311
297
|
page.content || "(no result)",
|
|
312
298
|
);
|
|
313
299
|
if (page.nextOffset !== undefined)
|
|
314
|
-
lines.push(
|
|
300
|
+
lines.push(
|
|
301
|
+
`Continue with manage_subagents request: { action: "inspect", name: "${worker.name}", includeResult: true, runId: ${worker.runId}, resultOffset: ${page.nextOffset} }.`,
|
|
302
|
+
);
|
|
315
303
|
}
|
|
316
304
|
if (options.tailLines) {
|
|
317
305
|
const transcript = worker.session.sessionManager
|
|
@@ -342,9 +330,21 @@ function inspectText(
|
|
|
342
330
|
return lines.join("\n");
|
|
343
331
|
}
|
|
344
332
|
|
|
333
|
+
function previewLines(text: string, expanded: boolean, theme: Theme, maxLines = 5): string {
|
|
334
|
+
if (expanded) return text;
|
|
335
|
+
const lines = text.split("\n");
|
|
336
|
+
if (lines.length <= maxLines) return lines.map((line) => clip(line, 200)).join("\n");
|
|
337
|
+
const shown = lines
|
|
338
|
+
.slice(0, maxLines)
|
|
339
|
+
.map((line) => clip(line, 200))
|
|
340
|
+
.join("\n");
|
|
341
|
+
return `${shown}\n${theme.fg("muted", `… (${lines.length - maxLines} more lines)`)}`;
|
|
342
|
+
}
|
|
343
|
+
|
|
345
344
|
function callLine(theme: Theme, tool: string, subject: string, detail?: string): Text {
|
|
345
|
+
const target = subject ? ` ${theme.fg("accent", subject)}` : "";
|
|
346
346
|
const suffix = detail ? theme.fg("dim", " — ") + theme.fg("muted", clip(detail.replace(/\s+/g, " "), 60)) : "";
|
|
347
|
-
return new Text(`${theme.fg("toolTitle", theme.bold(tool))}
|
|
347
|
+
return new Text(`${theme.fg("toolTitle", theme.bold(tool))}${target}${suffix}`, 0, 0);
|
|
348
348
|
}
|
|
349
349
|
|
|
350
350
|
function resultLine(
|
|
@@ -352,10 +352,10 @@ function resultLine(
|
|
|
352
352
|
options: ToolRenderResultOptions,
|
|
353
353
|
theme: Theme,
|
|
354
354
|
context: { isError: boolean },
|
|
355
|
-
summary: () => string,
|
|
355
|
+
summary: (text: string) => string,
|
|
356
356
|
): Text {
|
|
357
357
|
const text = result.content.flatMap((part) => (part.type === "text" ? [part.text] : [])).join("\n");
|
|
358
358
|
if (context.isError) return new Text(theme.fg("error", text), 0, 0);
|
|
359
359
|
if (options.isPartial) return new Text(theme.fg("muted", text), 0, 0);
|
|
360
|
-
return new Text(summary(), 0, 0);
|
|
360
|
+
return new Text(summary(text), 0, 0);
|
|
361
361
|
}
|
|
@@ -38,7 +38,10 @@ const VIEWPORT_BOTTOM = 3;
|
|
|
38
38
|
export async function openInspector(ctx: ExtensionContext, workers: Worker[], name?: string): Promise<void> {
|
|
39
39
|
if (ctx.mode !== "tui") {
|
|
40
40
|
if (ctx.hasUI)
|
|
41
|
-
ctx.ui.notify(
|
|
41
|
+
ctx.ui.notify(
|
|
42
|
+
'The subagent inspector needs the interactive TUI. Use manage_subagents with action "inspect" instead.',
|
|
43
|
+
"warning",
|
|
44
|
+
);
|
|
42
45
|
return;
|
|
43
46
|
}
|
|
44
47
|
let worker = name?.trim() ? workers.find((candidate) => candidate.name === name.trim()) : undefined;
|