opencode-subagent-tools 0.0.0-stage → 0.2.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 +49 -0
- package/LICENSE +21 -0
- package/README.md +118 -2
- package/SECURITY.md +36 -0
- package/SKILL.md +345 -0
- package/docs/configuration.md +238 -0
- package/docs/development.md +82 -0
- package/docs/installation.md +131 -0
- package/docs/limitations.md +155 -0
- package/docs/reference.md +398 -0
- package/docs/security-model.md +79 -0
- package/package.json +74 -4
- package/src/access.ts +236 -0
- package/src/background.ts +591 -0
- package/src/config.ts +143 -0
- package/src/cursor.ts +114 -0
- package/src/discovery.ts +159 -0
- package/src/errors.ts +18 -0
- package/src/events.ts +236 -0
- package/src/format.ts +34 -0
- package/src/index.ts +129 -0
- package/src/interrupt.ts +20 -0
- package/src/live-state.ts +113 -0
- package/src/messages.ts +246 -0
- package/src/permissions.ts +62 -0
- package/src/session-row.ts +116 -0
- package/src/session.ts +141 -0
- package/src/skill.ts +57 -0
- package/src/status.ts +119 -0
- package/src/text.ts +42 -0
- package/src/tokens.ts +171 -0
- package/src/tools/cancel-descendants.ts +660 -0
- package/src/tools/cancel.ts +271 -0
- package/src/tools/index.ts +41 -0
- package/src/tools/input.ts +75 -0
- package/src/tools/list.ts +608 -0
- package/src/tools/names.ts +11 -0
- package/src/tools/output.ts +169 -0
- package/src/tools/send.ts +369 -0
- package/src/tools/usage.ts +434 -0
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
# Tool reference
|
|
2
|
+
|
|
3
|
+
The plugin registers seven tools under a namespace. With the default namespace `subagent`, the names are `subagent_list`, `subagent_usage`, `subagent_cancel`, `subagent_cancel_descendants`, `subagent_steer`, `subagent_queue`, and `subagent_context`.
|
|
4
|
+
|
|
5
|
+
The prefix follows the plugin's `namespace` option. OpenCode normalizes unsupported characters in names and namespaces to `_`. In Code Mode, call the same tools as `tools.subagent.list`, `tools.subagent.usage`, and so on; the namespace separator is `.` instead of `_`.
|
|
6
|
+
|
|
7
|
+
Inputs marked `?` are optional; unknown properties are rejected.
|
|
8
|
+
|
|
9
|
+
- When `allowedOutputFormats` allows both formats (the default), every tool accepts `format`; see [Text vs JSON](#text-vs-json).
|
|
10
|
+
- Mutations follow the targeting rules in the [security model](security-model.md).
|
|
11
|
+
- For operational guidance, see the bundled `SKILL.md`.
|
|
12
|
+
|
|
13
|
+
## list
|
|
14
|
+
|
|
15
|
+
List discovered sessions in a subtree, newest launch first. Read-only.
|
|
16
|
+
|
|
17
|
+
### Inputs
|
|
18
|
+
|
|
19
|
+
| Name | Type | Default | Notes |
|
|
20
|
+
| --------------- | --------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
21
|
+
| `parentID` | string? | caller | Any session ID is accepted. |
|
|
22
|
+
| `statuses` | string[]? | all five | Execution statuses: `running`, `stopped`, `failed`, `finished`, or `unknown`. An empty array, an unknown value, or a non-array is rejected. |
|
|
23
|
+
| `active` | boolean? | — | Filter on the session's own activity. Omit to include both active and inactive rows. |
|
|
24
|
+
| `subtreeActive` | boolean? | — | Filter on the session or any discovered descendant. Omit to include both. |
|
|
25
|
+
| `limit` | integer? | `maxListRows` (20) | 1 to `maxListRows`; values outside this range are rejected. |
|
|
26
|
+
| `cursor` | string? | — | From a previous `list` call; pass it back unchanged. A cursor is bound to the status and activity filters. |
|
|
27
|
+
|
|
28
|
+
### Output
|
|
29
|
+
|
|
30
|
+
Text output is one row per session plus summary and warning lines. JSON output contains:
|
|
31
|
+
|
|
32
|
+
- `root` — subtree root: the caller or `parentID`.
|
|
33
|
+
- `statuses` — applied execution-status filter.
|
|
34
|
+
- `discoveryComplete` — whether discovery walked the whole subtree, not whether all rows fit on this page.
|
|
35
|
+
- `warning?` — set when discovery was incomplete.
|
|
36
|
+
- `known` — all discovered sessions before the status and activity filters and cursor.
|
|
37
|
+
- `activeCount` — all discovered sessions with their own active execution or background job, before filters.
|
|
38
|
+
- `subtreeActiveCount` — all discovered sessions that are active or have an active descendant, before filters.
|
|
39
|
+
- `matching` — matches in the current discovery pass, before the cursor.
|
|
40
|
+
- `window` — matches after the cursor; equals `matching` on the first page.
|
|
41
|
+
- `remaining` — matches in the window not returned on this page.
|
|
42
|
+
- `remainingPages` — pages left in the cursor walk.
|
|
43
|
+
- `cursor?` — cursor for the next page.
|
|
44
|
+
- `counts` — counts for all five execution statuses across all discovered sessions, before the status and activity filters and cursor. It sums to `known`.
|
|
45
|
+
- `rows[]` — one entry per session:
|
|
46
|
+
- `id`, `parentID?`, `agent?`, `title?`, `titleTruncated?` (true when the title was truncated).
|
|
47
|
+
- `status` — execution status; `finished` means the last execution succeeded, not that the delegated task is complete.
|
|
48
|
+
- `active` — true when the session itself is running, unknown, or owns a background job. Descendants are excluded.
|
|
49
|
+
- `subtreeActive` — true when the session or any discovered descendant is active.
|
|
50
|
+
- `activeDescendants?` — true only when at least one discovered child is active in its subtree.
|
|
51
|
+
- `backgroundJob?` — the session's own observed work: `kinds` (`shell`, `image`, `subagent`), and optional `stateUnknown` when work may remain but could not be verified.
|
|
52
|
+
- `ageSeconds?` (omitted when the launch time is unknown), `launchedAt`.
|
|
53
|
+
- `usageMayLag?` — true when the row is active or unknown.
|
|
54
|
+
- `usage?` — `costUSD?`, `tokens?`, and `tokensUsed?` when the server provides them.
|
|
55
|
+
|
|
56
|
+
Text output adds `active` or `subtree` markers, `background=<kinds>`, `descendants=active`, and `usage=lagging` when relevant.
|
|
57
|
+
|
|
58
|
+
### Errors and edge cases
|
|
59
|
+
|
|
60
|
+
- A malformed or unreadable `parentID` returns `Tool.Error`.
|
|
61
|
+
- If the caller is unknown and `parentID` is omitted, the tool returns `Tool.Error`.
|
|
62
|
+
- An invalid cursor returns `Tool.Error`; a cursor is bound to the tool, root, status filter, and activity filters.
|
|
63
|
+
- A non-boolean `active` or `subtreeActive` returns `Tool.Error`.
|
|
64
|
+
- Aborting discovery returns `Tool.Error` instead of a partial result.
|
|
65
|
+
- An empty result does not prove that no subagents exist. See [limitations](limitations.md).
|
|
66
|
+
- A new child can increase `known` and `matching` without appearing in the current cursor walk; re-run without a cursor to include it.
|
|
67
|
+
- `statuses` filters executions only. Use `active` or `subtreeActive` for work that is still in progress.
|
|
68
|
+
|
|
69
|
+
## usage
|
|
70
|
+
|
|
71
|
+
Read cost, tokens, current context, status, and activity for a session. Read-only.
|
|
72
|
+
|
|
73
|
+
### Inputs
|
|
74
|
+
|
|
75
|
+
| Name | Type | Default | Notes |
|
|
76
|
+
| -------------------- | -------- | ------- | ------------------------------------------------------ |
|
|
77
|
+
| `sessionID` | string | — | Required. Any session ID is accepted. |
|
|
78
|
+
| `includeDescendants` | boolean? | `false` | Adds `tree` totals for the target and its descendants. |
|
|
79
|
+
|
|
80
|
+
### Output
|
|
81
|
+
|
|
82
|
+
Text output is a summary. JSON output contains:
|
|
83
|
+
|
|
84
|
+
- `sessionID`, `parentID?`, `status`, `active`.
|
|
85
|
+
- `status` — execution status; the caller is reported as `running` while the tool executes.
|
|
86
|
+
- `active` — true when the session itself is running, unknown, or owns a background job.
|
|
87
|
+
- `subtreeActive?` — present only with `includeDescendants: true`; true when the target or any discovered descendant is active. Without the tree, descendant activity is unknown and the field is omitted.
|
|
88
|
+
- `backgroundJob?` — the target's own observed work: `kinds`, and optional `stateUnknown`.
|
|
89
|
+
- `usageMayLag?` — true when the session is active or unknown; values are as of the last persisted step.
|
|
90
|
+
- `costUSD?` — the session's own cost, not a family total.
|
|
91
|
+
- `tokens?` — cumulative `input`, `output`, `reasoning`, `cache.read`, and `cache.write`.
|
|
92
|
+
- `tokensUsed?` — cumulative `input + output + reasoning`.
|
|
93
|
+
- `contextTokens?` — the last assistant step after the last completed compaction: `input + output + reasoning + cache.read + cache.write`. `0` is legitimate; the field is omitted when context is unavailable, with `warning`.
|
|
94
|
+
- `lastRequest?` — `input`, `output`, `reasoning`, `cacheRead`, `cacheWrite`, and `total` for that step.
|
|
95
|
+
- `contextLimit?` — when the session's model and its catalog context limit are available.
|
|
96
|
+
- `contextPercent?` — when both `contextLimit` and `contextTokens` are available.
|
|
97
|
+
- `model?` — `id`, `providerID?`, and `variant?` when known.
|
|
98
|
+
- `tree?` — with `includeDescendants: true`:
|
|
99
|
+
- `sessions` includes the target; `descendants` excludes it.
|
|
100
|
+
- `costUSD`, `tokens`, and `tokensUsed` include the target. `tokensUsed` is omitted when no session in the tree reports token data.
|
|
101
|
+
- `discoveryComplete` covers the descendant walk.
|
|
102
|
+
- `descendantsMayLag?` flags active or unknown descendants.
|
|
103
|
+
- `warning?` marks incomplete discovery; it is also mirrored at the top-level `warning`.
|
|
104
|
+
- `warning?` — set when context could not be read or discovery was incomplete.
|
|
105
|
+
|
|
106
|
+
When no tree token data is available, `tree.tokens` and `tree.tokensUsed` are omitted and the tree summary prints `used=unknown`.
|
|
107
|
+
|
|
108
|
+
### Errors and edge cases
|
|
109
|
+
|
|
110
|
+
- An unknown session returns `Tool.Error`.
|
|
111
|
+
- Aborting a context, usage, or tree read returns `Tool.Error`.
|
|
112
|
+
- The caller's own status is `running` while the tool executes.
|
|
113
|
+
- Re-query after the step completes or after cancellation when `usageMayLag` is true.
|
|
114
|
+
- `contextTokens` is the current context; `tokens` and `tokensUsed` are cumulative.
|
|
115
|
+
- `costUSD` is the session's own cost; use `includeDescendants: true` and `tree.costUSD` for a family total.
|
|
116
|
+
|
|
117
|
+
## cancel
|
|
118
|
+
|
|
119
|
+
Stop one session with a soft interrupt.
|
|
120
|
+
|
|
121
|
+
### Inputs
|
|
122
|
+
|
|
123
|
+
| Name | Type | Default | Notes |
|
|
124
|
+
| ----------- | ------- | ------- | ------------------------------------------------------------------------- |
|
|
125
|
+
| `sessionID` | string | — | Required. Target session ID. |
|
|
126
|
+
| `reason` | string? | — | Up to 500 characters. Recorded in the result; not delivered to the child. |
|
|
127
|
+
|
|
128
|
+
### Output
|
|
129
|
+
|
|
130
|
+
Text output reports the interrupt result, the current state, and a lag note. JSON output contains:
|
|
131
|
+
|
|
132
|
+
- `sessionID`, `accepted`, `interrupt`.
|
|
133
|
+
- `interrupt` — `accepted` (the server accepted), `rejected` (no active execution), or `unknown` (no definitive server answer; an abort during the interrupt is a `Tool.Error`).
|
|
134
|
+
- `accepted` — alias for `interrupt === "accepted"`.
|
|
135
|
+
- `status` — execution status after the interrupt and status check.
|
|
136
|
+
- `active` — true when the target is running, unknown, or owns observed background work after the call.
|
|
137
|
+
- `backgroundJob?` — the target's own observed work: `kinds` (`shell`, `image`, `subagent`), `mayRemain?` when work may still run after the call, and `stateUnknown?` when a probe failed.
|
|
138
|
+
- `reason?` — the recorded reason.
|
|
139
|
+
- `readBackMayLag` — true when the interrupt was accepted and the status check after cancellation still reports `running` or `unknown`.
|
|
140
|
+
- `cancellationDoesNotCascade` — always `true`; cancellation is non-cascading, not a claim that the target has no children.
|
|
141
|
+
- `costUSD?`, `tokens?`, `tokensUsed?` — usage after the interrupt.
|
|
142
|
+
|
|
143
|
+
Text distinguishes an accepted interrupt with a remaining job ("may continue"), an idle target with a job ("cannot stop the background job"), and an unverified probe ("state could not be verified"). If the target's subtree may still be active and no own background job was observed, the text says so.
|
|
144
|
+
|
|
145
|
+
### Errors and edge cases
|
|
146
|
+
|
|
147
|
+
- An unknown target, a self-target, a malformed ID, or a target outside `sessionControlPolicy` returns `Tool.Error`.
|
|
148
|
+
- Aborting before or during the interrupt returns `Tool.Error`. An abort after the interrupt may return a normal result.
|
|
149
|
+
- Cancelling a stopped, failed, or finished session is not an error.
|
|
150
|
+
- If the target is idle or terminal and no live background job is known, the tool probes `session.context(target)` for running shell messages and shell/image/subagent tool parts. A failed probe, or a probe without an authoritative idle snapshot for the target, sets `backgroundJob.stateUnknown`; it does not claim there is no job.
|
|
151
|
+
- This is a soft interrupt: it does not cascade, a long tool call may finish first, and jobs owned by an idle session keep running. The tool reports those jobs but cannot stop them.
|
|
152
|
+
- OpenCode may wake the parent with a cancellation notice.
|
|
153
|
+
- If `interrupt` is `unknown`, `readBackMayLag` is true, or `status` is `running` or `unknown`, re-run `list`.
|
|
154
|
+
|
|
155
|
+
## cancel_descendants
|
|
156
|
+
|
|
157
|
+
Stop the running descendants of the calling session, including grandchildren (requires `experimental.subagent_depth` at least 2). The tool always works in the caller's subtree and has no `sessionID` argument.
|
|
158
|
+
|
|
159
|
+
### Inputs
|
|
160
|
+
|
|
161
|
+
| Name | Type | Default | Notes |
|
|
162
|
+
| -------- | ------- | ------- | ------------------------------------------------------------------ |
|
|
163
|
+
| `reason` | string? | — | Up to 500 characters. Recorded in the result. |
|
|
164
|
+
| `cursor` | string? | — | From a previous `cancel_descendants` call; pass it back unchanged. |
|
|
165
|
+
|
|
166
|
+
There is no `sessionID`, `parentID`, `statuses`, or `limit` input.
|
|
167
|
+
|
|
168
|
+
### Output
|
|
169
|
+
|
|
170
|
+
Text output is a summary with counts and per-target details. JSON output contains:
|
|
171
|
+
|
|
172
|
+
- `known` — all discovered descendants in the current pass, before the cursor is applied.
|
|
173
|
+
- `considered` — descendants after the cursor.
|
|
174
|
+
- `running` — running descendants among `considered`.
|
|
175
|
+
- `activeCount` — considered descendants with their own active execution or background job.
|
|
176
|
+
- `subtreeActiveCount` — considered descendants that are active or have an active descendant.
|
|
177
|
+
- `backgroundJobCount` — considered descendants with `status !== "running"` that own a background job.
|
|
178
|
+
- `backgroundJobMayRemain?` — true when an observed background job may still run after the call.
|
|
179
|
+
- `beforeCursorRunning?` — running descendants before the cursor window; re-run without a cursor to include them.
|
|
180
|
+
- `targets[]` — one entry per attempted target: `sessionID`, `interrupt`, `readBack`, `status?` (status after the check, when `readBack` is `ok`), `backgroundJob?` (observed work with `mayRemain?`), and `error?` (failure detail).
|
|
181
|
+
- `interrupt` — `accepted` (the server accepted), `rejected` (no active execution), `failed` (the call threw), or `unknown` (aborted or no definitive answer).
|
|
182
|
+
- `readBack` — `ok` (the status check after cancellation returned a status), `failed`, or `not-read` (not attempted or abandoned after an abort).
|
|
183
|
+
- `remaining` — running targets not attempted; use `cursor` to continue, or retry when no cursor is returned.
|
|
184
|
+
- `aborted` — true when the call stopped before the batch completed.
|
|
185
|
+
- `reason?`, `cursor?`, `warning?`.
|
|
186
|
+
|
|
187
|
+
If no execution is running but idle descendants own background jobs, the result is normal with `running: 0` and `backgroundJobCount > 0`; the summary says those jobs cannot be stopped. Idle parents with active descendants are reported through `subtreeActiveCount` and the summary, not interrupted.
|
|
188
|
+
|
|
189
|
+
### Errors and edge cases
|
|
190
|
+
|
|
191
|
+
- An unknown caller returns `Tool.Error`.
|
|
192
|
+
- Aborting before discovery returns `Tool.Error`. Aborting during discovery or the batch returns `aborted: true` with the targets that were attempted and a warning when discovery was incomplete.
|
|
193
|
+
- Only `running` rows are targeted. Use `cancel` for `unknown` rows.
|
|
194
|
+
- Idle rows that own background jobs are counted in `backgroundJobCount`; this tool cannot stop those jobs.
|
|
195
|
+
- Idle parents with active descendants are counted in `subtreeActiveCount`; the running descendant is the target, not the parent.
|
|
196
|
+
- `maxCancelBatch` limits targets per call (20 by default).
|
|
197
|
+
- The whole batch is checked in one permission request.
|
|
198
|
+
- Cursor retries skip failed, unknown, rejected, and not-read targets. Inspect them manually.
|
|
199
|
+
- Nested cancellation can wake an intermediate parent; re-run `list` and cancel it again if it resumed.
|
|
200
|
+
- Discovery can miss running descendants; the output warns when that is possible.
|
|
201
|
+
|
|
202
|
+
## steer
|
|
203
|
+
|
|
204
|
+
Send an instruction into a session at its next model request. The message does not interrupt current work.
|
|
205
|
+
|
|
206
|
+
### Inputs
|
|
207
|
+
|
|
208
|
+
| Name | Type | Default | Notes |
|
|
209
|
+
| ----------- | -------- | ------- | ------------------------------------------------------------------- |
|
|
210
|
+
| `sessionID` | string | — | Required. Target session ID. |
|
|
211
|
+
| `text` | string | — | Up to `maxTextLength` (16000) characters; longer input is rejected. |
|
|
212
|
+
| `resume` | boolean? | `true` | `false` accepts the message without waking an idle child. |
|
|
213
|
+
|
|
214
|
+
### Output
|
|
215
|
+
|
|
216
|
+
Text output reports the target and delivery. JSON output contains:
|
|
217
|
+
|
|
218
|
+
- `sessionID`, `messageID?`, `delivery`, `chars`, `resume`.
|
|
219
|
+
- `status?` — status observed before the message was accepted; a wake may not be reflected yet.
|
|
220
|
+
- `active` — the observed target was running, unknown, or owned a background job.
|
|
221
|
+
- `backgroundJob?` — the target's own observed work.
|
|
222
|
+
- `pending?` — true when the message was accepted without waking an idle child.
|
|
223
|
+
|
|
224
|
+
### Errors and edge cases
|
|
225
|
+
|
|
226
|
+
- An unknown target, a self-target, empty or overlong text, or a target outside `sessionControlPolicy` returns `Tool.Error`.
|
|
227
|
+
- The message is delivered before the child's next model request; the current tool call is not interrupted.
|
|
228
|
+
- The plugin cannot move a blocking shell to the background, so delivery may wait for that shell. This is a UI parity gap, not a hard failure.
|
|
229
|
+
- OpenCode sends a `<subagent>` report each time the child goes idle. A report can say `state="running"` and `Background work still running` when the execution is idle but background work remains. Read the report; do not resume the child just to read its result.
|
|
230
|
+
- `delivery` is the server-reported delivery, normally `steer`.
|
|
231
|
+
|
|
232
|
+
## queue
|
|
233
|
+
|
|
234
|
+
Queue a message as the next independent turn after the current execution settles.
|
|
235
|
+
|
|
236
|
+
### Inputs
|
|
237
|
+
|
|
238
|
+
| Name | Type | Default | Notes |
|
|
239
|
+
| ----------- | -------- | ------- | ------------------------------------------------------------------- |
|
|
240
|
+
| `sessionID` | string | — | Required. Target session ID. |
|
|
241
|
+
| `text` | string | — | Up to `maxTextLength` (16000) characters; longer input is rejected. |
|
|
242
|
+
| `resume` | boolean? | `true` | `false` accepts the message without waking an idle child. |
|
|
243
|
+
|
|
244
|
+
### Output
|
|
245
|
+
|
|
246
|
+
Text output reports the target and delivery. JSON output contains:
|
|
247
|
+
|
|
248
|
+
- `sessionID`, `messageID?`, `delivery`, `chars`, `resume`.
|
|
249
|
+
- `status?` — status observed before the message was accepted; a wake may not be reflected yet.
|
|
250
|
+
- `active` — the observed target was running, unknown, or owned a background job.
|
|
251
|
+
- `backgroundJob?` — the target's own observed work.
|
|
252
|
+
- `queued?` — true when the message was accepted but has not started yet. Inferred from the observed status and `resume`; it does not inspect the server's existing queue, so other queued prompts may be ahead.
|
|
253
|
+
- `pending?` — true when the message was accepted without waking an idle child.
|
|
254
|
+
|
|
255
|
+
### Errors and edge cases
|
|
256
|
+
|
|
257
|
+
- An unknown target, a self-target, empty or overlong text, or a target outside `sessionControlPolicy` returns `Tool.Error`.
|
|
258
|
+
- The message does not join the current run; it waits for the current execution to settle, then starts a separate turn.
|
|
259
|
+
- Background jobs are not waited for and continue in parallel. The queue is promoted at the idle boundary even when background work remains.
|
|
260
|
+
- `queued` is `true` when the target was running/unknown, when its status could not be observed, or when it was idle with `resume: false`; it is `false` when the target was idle and `resume: true`.
|
|
261
|
+
- `delivery` is the server-reported delivery, normally `queue`.
|
|
262
|
+
|
|
263
|
+
## context
|
|
264
|
+
|
|
265
|
+
Inject a synthetic context message without asking for a turn. The tool always uses `resume: false`.
|
|
266
|
+
|
|
267
|
+
### Inputs
|
|
268
|
+
|
|
269
|
+
| Name | Type | Default | Notes |
|
|
270
|
+
| ------------- | ------- | ------- | ------------------------------------------------------------------- |
|
|
271
|
+
| `sessionID` | string | — | Required. Target session ID. |
|
|
272
|
+
| `text` | string | — | Up to `maxTextLength` (16000) characters; longer input is rejected. |
|
|
273
|
+
| `description` | string? | — | Up to 200 characters. A short label shown in the transcript. |
|
|
274
|
+
|
|
275
|
+
### Output
|
|
276
|
+
|
|
277
|
+
Text output reports the target and size. JSON output contains:
|
|
278
|
+
|
|
279
|
+
- `sessionID`, `messageID?`, `delivery: "next-step"`, `chars`.
|
|
280
|
+
- `description?`.
|
|
281
|
+
- `status?` — status observed before the message was accepted; context does not wake the child.
|
|
282
|
+
- `active` — the observed target was running, unknown, or owned a background job.
|
|
283
|
+
- `backgroundJob?` — the target's own observed work.
|
|
284
|
+
- `pending?` — true when the message was accepted without waking an idle child.
|
|
285
|
+
|
|
286
|
+
### Errors and edge cases
|
|
287
|
+
|
|
288
|
+
- An unknown target, a self-target, empty or overlong text, overlong description, or a target outside `sessionControlPolicy` returns `Tool.Error`.
|
|
289
|
+
- This is a synthetic message, not a user instruction.
|
|
290
|
+
- An idle child keeps the message pending until its next run.
|
|
291
|
+
- For an instruction without waking, use `steer` with `resume: false`. For a follow-up turn, use `queue`.
|
|
292
|
+
|
|
293
|
+
## Statuses and activity
|
|
294
|
+
|
|
295
|
+
- `running` — the session is executing; a live start newer than the last idle marker, or `busy > idle` in the session record, keeps it running.
|
|
296
|
+
- `stopped` — the run was interrupted before it finished.
|
|
297
|
+
- `failed` — the last run failed.
|
|
298
|
+
- `finished` — the last run succeeded. This does not mean the delegated task is complete.
|
|
299
|
+
- `unknown` — no reliable status is available; the session may still be running.
|
|
300
|
+
|
|
301
|
+
`status` is execution-oriented. In OpenCode 2.3.0+, shell, image, or subagent work can stay alive while a session is idle, so use the activity fields for "still working":
|
|
302
|
+
|
|
303
|
+
- `active` — the session itself is running, unknown, or owns a background job. Descendants are not included.
|
|
304
|
+
- `subtreeActive` — the session or any discovered descendant is active.
|
|
305
|
+
- `activeDescendants` — at least one discovered child is active. An idle parent with active descendants may wake.
|
|
306
|
+
- `backgroundJob` — the session's own observed work: `kinds` can contain `shell`, `image`, and `subagent`. `stateUnknown` means work may remain but could not be verified.
|
|
307
|
+
- `usageMayLag` — the session is active or unknown, so usage may still grow.
|
|
308
|
+
|
|
309
|
+
Status and activity are observed from live events, the idle hook, shell events, structured context probes, and the session record. They can lag, and an `unknown` row may still be running. See [limitations](limitations.md).
|
|
310
|
+
|
|
311
|
+
`list` includes all five statuses by default. `statuses` filters executions only; use `active` and `subtreeActive` for work that is still in progress. `counts` always covers all five statuses and sums to `known`.
|
|
312
|
+
|
|
313
|
+
## Discovery and pagination
|
|
314
|
+
|
|
315
|
+
OpenCode 2.3.0+ is required. `list`, `cancel_descendants`, and `usage` with `includeDescendants: true` walk the relevant subtree through `ctx.session.list`. This finds children launched before the plugin loaded, from the TUI, or by another process.
|
|
316
|
+
|
|
317
|
+
Discovery stops after `maxDiscoveryNodes` nodes, `maxDiscoveryDepth` levels, or `maxDiscoveryPages` pages per parent. The defaults are 200, 8, and 5. An incomplete result includes a warning; an empty result is not proof that no subagents exist. See [configuration](configuration.md) for the limits.
|
|
318
|
+
|
|
319
|
+
`list` and `cancel_descendants` return a cursor for stable paging. A cursor keeps its place while statuses change. A `list` cursor is bound to the status and activity filters. A cursor walk sees the sessions found when it started; children launched after the first page may not appear in that walk. Re-run without a cursor to include them.
|
|
320
|
+
|
|
321
|
+
For `list`:
|
|
322
|
+
|
|
323
|
+
- `known` — all discovered sessions before the status and activity filters and cursor.
|
|
324
|
+
- `activeCount`, `subtreeActiveCount` — all discovered sessions with own or subtree activity, before filters.
|
|
325
|
+
- `matching` — matches in the current discovery pass, before the cursor.
|
|
326
|
+
- `window` — matches after the cursor.
|
|
327
|
+
- `remaining` — matches in the window not returned on this page.
|
|
328
|
+
- `remainingPages` — pages left in the cursor walk.
|
|
329
|
+
- `counts` — all discovered sessions by status, before the filters and cursor; it sums to `known`.
|
|
330
|
+
|
|
331
|
+
A new child can increase `known` and `matching` without appearing in the current cursor walk. `matching - window` then includes previous pages and new children.
|
|
332
|
+
|
|
333
|
+
For `cancel_descendants`, the cursor is bound to the tool and the caller's subtree. `remaining` counts running targets not attempted in the call.
|
|
334
|
+
|
|
335
|
+
## Text vs JSON
|
|
336
|
+
|
|
337
|
+
`format: "json"` returns a structured `output` object. `format: "text"` returns a string `output`.
|
|
338
|
+
|
|
339
|
+
If only one format is allowed, the `format` input is omitted. `["text"]` also omits the output schema and returns text only; `["json"]` keeps the structured output schema and always returns an object.
|
|
340
|
+
|
|
341
|
+
Per-tool defaults (when both formats are allowed):
|
|
342
|
+
|
|
343
|
+
| Tool | Default format |
|
|
344
|
+
| -------------------- | -------------- |
|
|
345
|
+
| `list` | `json` |
|
|
346
|
+
| `usage` | `json` |
|
|
347
|
+
| `cancel_descendants` | `json` |
|
|
348
|
+
| `cancel` | `text` |
|
|
349
|
+
| `steer` | `text` |
|
|
350
|
+
| `queue` | `text` |
|
|
351
|
+
| `context` | `text` |
|
|
352
|
+
|
|
353
|
+
Use `text` for a quick read. Use `json` when you need fields such as `targets`, `pending`, `queued`, `active`, `subtreeActive`, `backgroundJob`, `usage`, `tree`, or `lastRequest`. See [configuration](configuration.md) for the option.
|
|
354
|
+
|
|
355
|
+
## Context vs cumulative usage
|
|
356
|
+
|
|
357
|
+
`usage.contextTokens` follows the OpenCode UI formula:
|
|
358
|
+
|
|
359
|
+
```text
|
|
360
|
+
last assistant step after the last completed compaction:
|
|
361
|
+
input + output + reasoning + cache.read + cache.write
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
It resets after a completed compaction and is the best available estimate of the current context footprint.
|
|
365
|
+
|
|
366
|
+
`Session.Info.tokens` is cumulative across the whole session and includes every cache read; it is not the current context. Use `tokensUsed` (`input + output + reasoning`) for a cumulative non-cache budget, and `costUSD` for spend.
|
|
367
|
+
|
|
368
|
+
`contextTokens: 0` is legitimate when no assistant step exists after the last completed compaction. If context cannot be read, the field is omitted and `warning` explains why.
|
|
369
|
+
|
|
370
|
+
`usage.tree` includes the target: `tree.sessions` counts the target plus descendants, `tree.descendants` counts only descendants, and `tree.costUSD`/`tokensUsed` include the target's own values. `tokensUsed` is omitted when no session in the tree reports token data.
|
|
371
|
+
|
|
372
|
+
`tree.discoveryComplete` reports discovery completeness, not whether every session finished. `tree.descendantsMayLag` covers descendants; the top-level `usageMayLag` covers the target.
|
|
373
|
+
|
|
374
|
+
## Errors
|
|
375
|
+
|
|
376
|
+
Validation and ownership refusals return `Tool.Error`, not a successful output. This covers an unknown target, a self-target, an invalid cursor, and invalid, empty, or non-array `statuses`.
|
|
377
|
+
|
|
378
|
+
It also covers a malformed or overlong session/parent ID, a target that cannot be verified through the server's session tree, a target outside `sessionControlPolicy`, and a permission denial.
|
|
379
|
+
|
|
380
|
+
The error message is actionable; correct the call and continue.
|
|
381
|
+
|
|
382
|
+
No-op outcomes are not errors: `cancel` on a stopped, failed, or finished session, and `cancel_descendants` with no running children, return a normal result.
|
|
383
|
+
|
|
384
|
+
Partial batch failures stay in `cancel_descendants.targets` with `interrupt: "failed"` or `readBack: "failed"` so the caller can inspect them.
|
|
385
|
+
|
|
386
|
+
Abort behavior:
|
|
387
|
+
|
|
388
|
+
- `list` and `usage` return `Tool.Error` when discovery or a context read is aborted.
|
|
389
|
+
- `cancel` returns `Tool.Error` when the abort happens before or during the interrupt. An abort after the interrupt may still return a normal result.
|
|
390
|
+
- `cancel_descendants` returns `Tool.Error` before discovery. Otherwise it reports `aborted: true` with the targets it attempted, and a warning when discovery was incomplete.
|
|
391
|
+
|
|
392
|
+
In OpenCode 2.3.0+, these `Tool.Error` results are normal call results from a cooperative stop, not interrupted tool calls.
|
|
393
|
+
|
|
394
|
+
## Permissions and configuration
|
|
395
|
+
|
|
396
|
+
Mutations use the `subagent.control` permission action when `enforcePermissions` is enabled; see the [security model](security-model.md) for targeting rules and policy modes.
|
|
397
|
+
|
|
398
|
+
Configuration options, including `enforcePermissions`, `sessionControlPolicy`, `allowedOutputFormats`, `registerSkill`, and limits, are described in [configuration](configuration.md). When `registerSkill` is `true` (the default), the plugin registers `SKILL.md` as the `subagent-tools` skill.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Security model
|
|
2
|
+
|
|
3
|
+
These are **destructive tools that the model can call**. The defaults are
|
|
4
|
+
deliberately scoped.
|
|
5
|
+
|
|
6
|
+
## Permissions
|
|
7
|
+
|
|
8
|
+
Every mutating tool (`cancel`, `cancel_descendants`, `steer`, `queue`, `context`) calls
|
|
9
|
+
`ctx.permission.assert` with action `subagent.control` when
|
|
10
|
+
`enforcePermissions` is `true` (the default). A denial returns a tool error.
|
|
11
|
+
`cancel_descendants` checks the whole batch in one request: any `deny` blocks the batch,
|
|
12
|
+
and an `ask` policy prompts once per call.
|
|
13
|
+
|
|
14
|
+
Read-only `list` and `usage` do not request `subagent.control`. They can read
|
|
15
|
+
any session, including the caller and its ancestors.
|
|
16
|
+
|
|
17
|
+
OpenCode's base policy allows all actions, so `enforcePermissions: true` by
|
|
18
|
+
itself does not prompt. Add an `ask` or `deny` rule for `subagent.control` if
|
|
19
|
+
you want a prompt or a block; see [configuration](configuration.md) for the option.
|
|
20
|
+
|
|
21
|
+
The TUI may render the custom `subagent.control` action without the target IDs
|
|
22
|
+
or titles carried in the permission metadata. When target visibility matters,
|
|
23
|
+
review the tool call or use explicit `allow`/`deny` rules instead of relying
|
|
24
|
+
only on an `ask` prompt.
|
|
25
|
+
|
|
26
|
+
## Session control policy
|
|
27
|
+
|
|
28
|
+
`sessionControlPolicy` applies only to mutations:
|
|
29
|
+
|
|
30
|
+
| Value | Mutations may target |
|
|
31
|
+
| ------------------------- | ------------------------------------------------------------------------ |
|
|
32
|
+
| `"descendants"` (default) | Only the calling session's subtree. |
|
|
33
|
+
| `"all-except-ancestors"` | Any session except the caller and its ancestors. |
|
|
34
|
+
| `"all"` | Any session, including the caller's ancestors, except the caller itself. |
|
|
35
|
+
|
|
36
|
+
`cancel_descendants` always remains scoped to the calling session's subtree, regardless
|
|
37
|
+
of policy. Use individual `cancel` for foreign sessions.
|
|
38
|
+
|
|
39
|
+
`"all"` is security-sensitive: a subagent can target its parent or root session
|
|
40
|
+
if it knows the ID. A subagent can also discover IDs through `list` because
|
|
41
|
+
reads are unrestricted. Enable `"all"` only for deliberate orchestration
|
|
42
|
+
setups.
|
|
43
|
+
|
|
44
|
+
`"all-except-ancestors"` walks the caller's parent chain and refuses a target
|
|
45
|
+
that appears in it. If the chain is too deep, cyclic, or unreadable, the plugin
|
|
46
|
+
fails closed and refuses the mutation rather than assuming the target is safe.
|
|
47
|
+
|
|
48
|
+
Under `"descendants"`, single-target mutations verify the target by walking its
|
|
49
|
+
`parentID` chain with `session.get`. This lets them control a descendant that
|
|
50
|
+
the current discovery pass did not return. A chain that exceeds
|
|
51
|
+
`maxDiscoveryDepth` or is malformed is unverified, not foreign. Under
|
|
52
|
+
`"all-except-ancestors"`, the plugin walks the caller's parent chain. Under
|
|
53
|
+
`"all"`, it only reads the target.
|
|
54
|
+
|
|
55
|
+
## Read-only access
|
|
56
|
+
|
|
57
|
+
`list` may inspect any `parentID`'s subtree, and `usage` may read any session's
|
|
58
|
+
cost, tokens, and context. This is intentional: `sessionControlPolicy` is a
|
|
59
|
+
mutation policy, not a read policy. Treat session cost/context and subtree
|
|
60
|
+
metadata as visible to any agent that can call these tools.
|
|
61
|
+
|
|
62
|
+
## Other protections
|
|
63
|
+
|
|
64
|
+
- Mutating tools can never target the calling session itself. `usage` is
|
|
65
|
+
read-only and may read the caller.
|
|
66
|
+
- Session IDs are validated for length and control characters; they are never
|
|
67
|
+
silently truncated. Every mutation target is verified through `session.get`
|
|
68
|
+
or the discovered session tree before use.
|
|
69
|
+
- `cancel_descendants` only targets descendants discovered through
|
|
70
|
+
`ctx.session.list`.
|
|
71
|
+
- Discovery stops at the configured limits and can miss sessions. An empty or
|
|
72
|
+
partial result is not proof that no subagents exist; see
|
|
73
|
+
[limitations](limitations.md).
|
|
74
|
+
- `enforcePermissions: false` skips permission evaluation entirely. Do not
|
|
75
|
+
combine it with `sessionControlPolicy: "all"` unless you intend to allow
|
|
76
|
+
unrestricted control of any session except the caller.
|
|
77
|
+
|
|
78
|
+
See [SECURITY.md](../SECURITY.md) for vulnerability reporting and
|
|
79
|
+
[configuration](configuration.md) for the full option reference.
|
package/package.json
CHANGED
|
@@ -1,6 +1,76 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-subagent-tools",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "OpenCode V2 plugin that gives the agent tools to list, inspect, cancel, steer, queue, and inject context into its subagent sessions.",
|
|
5
|
+
"author": "Maxim Matsiushonak",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./src/index.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./src/index.ts"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"src",
|
|
14
|
+
"SKILL.md",
|
|
15
|
+
"README.md",
|
|
16
|
+
"LICENSE",
|
|
17
|
+
"SECURITY.md",
|
|
18
|
+
"CHANGELOG.md",
|
|
19
|
+
"docs/configuration.md",
|
|
20
|
+
"docs/development.md",
|
|
21
|
+
"docs/installation.md",
|
|
22
|
+
"docs/reference.md",
|
|
23
|
+
"docs/security-model.md",
|
|
24
|
+
"docs/limitations.md"
|
|
25
|
+
],
|
|
26
|
+
"keywords": [
|
|
27
|
+
"opencode",
|
|
28
|
+
"opencode-plugin",
|
|
29
|
+
"subagent",
|
|
30
|
+
"subagent-tools",
|
|
31
|
+
"subagent-control",
|
|
32
|
+
"agent",
|
|
33
|
+
"cancel",
|
|
34
|
+
"steer",
|
|
35
|
+
"queue",
|
|
36
|
+
"opencode-v2",
|
|
37
|
+
"plugin"
|
|
38
|
+
],
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/finnseefly/opencode-subagent-tools.git"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/finnseefly/opencode-subagent-tools#readme",
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/finnseefly/opencode-subagent-tools/issues"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"lint": "oxlint",
|
|
49
|
+
"format": "prettier --ignore-unknown --write .",
|
|
50
|
+
"format:check": "prettier --ignore-unknown --check .",
|
|
51
|
+
"typecheck": "tsc --noEmit",
|
|
52
|
+
"test": "bun test",
|
|
53
|
+
"check": "bun run lint && bun run format:check && bun run typecheck && bun test",
|
|
54
|
+
"prepublishOnly": "bun run check"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"@opencode/plugin": "^2.3.0"
|
|
58
|
+
},
|
|
59
|
+
"peerDependenciesMeta": {
|
|
60
|
+
"@opencode/plugin": {
|
|
61
|
+
"optional": true
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@opencode/plugin": "^2.3.0",
|
|
66
|
+
"@types/bun": "^1.4.3",
|
|
67
|
+
"@types/node": "^26.6.5",
|
|
68
|
+
"oxlint": "1.60.0",
|
|
69
|
+
"prettier": "3.6.2",
|
|
70
|
+
"typescript": "^7.0.2"
|
|
71
|
+
},
|
|
72
|
+
"prettier": {
|
|
73
|
+
"semi": true,
|
|
74
|
+
"printWidth": 90
|
|
75
|
+
}
|
|
76
|
+
}
|