opencode-subagent-tools 0.0.0-stage → 0.1.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 +27 -0
- package/LICENSE +21 -0
- package/README.md +113 -2
- package/SECURITY.md +36 -0
- package/SKILL.md +305 -0
- package/docs/configuration.md +238 -0
- package/docs/development.md +78 -0
- package/docs/installation.md +137 -0
- package/docs/limitations.md +120 -0
- package/docs/reference.md +347 -0
- package/docs/security-model.md +79 -0
- package/package.json +74 -4
- package/src/access.ts +236 -0
- package/src/config.ts +143 -0
- package/src/cursor.ts +112 -0
- package/src/discovery.ts +151 -0
- package/src/errors.ts +18 -0
- package/src/events.ts +190 -0
- package/src/format.ts +34 -0
- package/src/index.ts +116 -0
- package/src/interrupt.ts +20 -0
- package/src/live-state.ts +90 -0
- package/src/messages.ts +196 -0
- package/src/permissions.ts +62 -0
- package/src/session-row.ts +55 -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 +527 -0
- package/src/tools/cancel.ts +205 -0
- package/src/tools/index.ts +39 -0
- package/src/tools/input.ts +73 -0
- package/src/tools/list.ts +502 -0
- package/src/tools/names.ts +11 -0
- package/src/tools/output.ts +169 -0
- package/src/tools/send.ts +335 -0
- package/src/tools/usage.ts +396 -0
|
@@ -0,0 +1,347 @@
|
|
|
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 `_`.
|
|
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 | `running`, `stopped`, `failed`, `finished`, or `unknown`. An empty array, an unknown value, or a non-array is rejected. |
|
|
23
|
+
| `limit` | integer? | `maxListRows` (20) | 1 to `maxListRows`; values outside this range are rejected. |
|
|
24
|
+
| `cursor` | string? | — | From a previous `list` call; pass it back unchanged. |
|
|
25
|
+
|
|
26
|
+
### Output
|
|
27
|
+
|
|
28
|
+
Text output is one row per session plus summary and warning lines. JSON output contains:
|
|
29
|
+
|
|
30
|
+
- `root` — subtree root: the caller or `parentID`.
|
|
31
|
+
- `statuses` — applied status filter.
|
|
32
|
+
- `discoveryComplete` — whether discovery walked the whole subtree, not whether all rows fit on this page.
|
|
33
|
+
- `warning?` — set when discovery was incomplete.
|
|
34
|
+
- `known` — all discovered sessions before the status filter and cursor.
|
|
35
|
+
- `matching` — matches in the current discovery pass, before the cursor.
|
|
36
|
+
- `window` — matches after the cursor; equals `matching` on the first page.
|
|
37
|
+
- `remaining` — matches in the window not returned on this page.
|
|
38
|
+
- `remainingPages` — pages left in the cursor walk.
|
|
39
|
+
- `cursor?` — cursor for the next page.
|
|
40
|
+
- `counts` — counts for all five statuses across all discovered sessions, before the filter and cursor.
|
|
41
|
+
- `rows[]` — one entry per session:
|
|
42
|
+
- `id`, `parentID?`, `agent?`, `title?`, `titleTruncated?` (true when the title was truncated).
|
|
43
|
+
- `status`, `ageSeconds?` (omitted when the launch time is unknown), `launchedAt`.
|
|
44
|
+
- `usageMayLag?` — true when the row is running or unknown.
|
|
45
|
+
- `usage?` — `costUSD?`, `tokens?`, and `tokensUsed?` when the server provides them.
|
|
46
|
+
|
|
47
|
+
### Errors and edge cases
|
|
48
|
+
|
|
49
|
+
- A malformed or unreadable `parentID` returns `Tool.Error`.
|
|
50
|
+
- If the caller is unknown and `parentID` is omitted, the tool returns `Tool.Error`.
|
|
51
|
+
- An invalid cursor returns `Tool.Error`; a cursor is bound to the tool, root, and status filter.
|
|
52
|
+
- Aborting discovery returns `Tool.Error` instead of a partial result.
|
|
53
|
+
- An empty result does not prove that no subagents exist. See [limitations](limitations.md).
|
|
54
|
+
- A new child can increase `known` and `matching` without appearing in the current cursor walk; re-run without a cursor to include it.
|
|
55
|
+
|
|
56
|
+
## usage
|
|
57
|
+
|
|
58
|
+
Read cost, tokens, current context, and status for a session. Read-only.
|
|
59
|
+
|
|
60
|
+
### Inputs
|
|
61
|
+
|
|
62
|
+
| Name | Type | Default | Notes |
|
|
63
|
+
| -------------------- | -------- | ------- | ------------------------------------------------------ |
|
|
64
|
+
| `sessionID` | string | — | Required. Any session ID is accepted. |
|
|
65
|
+
| `includeDescendants` | boolean? | `false` | Adds `tree` totals for the target and its descendants. |
|
|
66
|
+
|
|
67
|
+
### Output
|
|
68
|
+
|
|
69
|
+
Text output is a summary. JSON output contains:
|
|
70
|
+
|
|
71
|
+
- `sessionID`, `parentID?`, `status`.
|
|
72
|
+
- `usageMayLag?` — true when the session is running or unknown; values are as of the last persisted step.
|
|
73
|
+
- `costUSD?` — the session's own cost, not a family total.
|
|
74
|
+
- `tokens?` — cumulative `input`, `output`, `reasoning`, `cache.read`, and `cache.write`.
|
|
75
|
+
- `tokensUsed?` — cumulative `input + output + reasoning`.
|
|
76
|
+
- `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`.
|
|
77
|
+
- `lastRequest?` — `input`, `output`, `reasoning`, `cacheRead`, `cacheWrite`, and `total` for that step.
|
|
78
|
+
- `contextLimit?` — when the session's model and its catalog context limit are available.
|
|
79
|
+
- `contextPercent?` — when both `contextLimit` and `contextTokens` are available.
|
|
80
|
+
- `model?` — `id`, `providerID?`, and `variant?` when known.
|
|
81
|
+
- `tree?` — with `includeDescendants: true`:
|
|
82
|
+
- `sessions` includes the target; `descendants` excludes it.
|
|
83
|
+
- `costUSD`, `tokens`, and `tokensUsed` include the target. `tokensUsed` is omitted when no session in the tree reports token data.
|
|
84
|
+
- `discoveryComplete` covers the descendant walk.
|
|
85
|
+
- `descendantsMayLag?` flags running or unknown descendants.
|
|
86
|
+
- `warning?` marks incomplete discovery; it is also mirrored at the top-level `warning`.
|
|
87
|
+
- `warning?` — set when context could not be read or discovery was incomplete.
|
|
88
|
+
|
|
89
|
+
When no tree token data is available, `tree.tokens` and `tree.tokensUsed` are omitted and the tree summary prints `used=unknown`.
|
|
90
|
+
|
|
91
|
+
### Errors and edge cases
|
|
92
|
+
|
|
93
|
+
- An unknown session returns `Tool.Error`.
|
|
94
|
+
- Aborting a context, usage, or tree read returns `Tool.Error`.
|
|
95
|
+
- The caller's own status is `running` while the tool executes.
|
|
96
|
+
- Re-query after the step completes or after cancellation when `usageMayLag` is true.
|
|
97
|
+
- `contextTokens` is the current context; `tokens` and `tokensUsed` are cumulative.
|
|
98
|
+
- `costUSD` is the session's own cost; use `includeDescendants: true` and `tree.costUSD` for a family total.
|
|
99
|
+
|
|
100
|
+
## cancel
|
|
101
|
+
|
|
102
|
+
Stop one session with a soft interrupt.
|
|
103
|
+
|
|
104
|
+
### Inputs
|
|
105
|
+
|
|
106
|
+
| Name | Type | Default | Notes |
|
|
107
|
+
| ----------- | ------- | ------- | ------------------------------------------------------------------------- |
|
|
108
|
+
| `sessionID` | string | — | Required. Target session ID. |
|
|
109
|
+
| `reason` | string? | — | Up to 500 characters. Recorded in the result; not delivered to the child. |
|
|
110
|
+
|
|
111
|
+
### Output
|
|
112
|
+
|
|
113
|
+
Text output reports the interrupt result, the current state, and a lag note. JSON output contains:
|
|
114
|
+
|
|
115
|
+
- `sessionID`, `accepted`, `interrupt`.
|
|
116
|
+
- `interrupt` — `accepted` (the server accepted), `rejected` (no active execution), or `unknown` (no definitive server answer; an abort during the interrupt is a `Tool.Error`).
|
|
117
|
+
- `accepted` — alias for `interrupt === "accepted"`.
|
|
118
|
+
- `status` — status after the interrupt and status check.
|
|
119
|
+
- `reason?` — the recorded reason.
|
|
120
|
+
- `readBackMayLag` — true when the interrupt was accepted and the status check after cancellation still reports `running` or `unknown`.
|
|
121
|
+
- `cancellationDoesNotCascade` — always `true`; cancellation is non-cascading, not a claim that the target has no children.
|
|
122
|
+
- `costUSD?`, `tokens?`, `tokensUsed?` — usage after the interrupt.
|
|
123
|
+
|
|
124
|
+
### Errors and edge cases
|
|
125
|
+
|
|
126
|
+
- An unknown target, a self-target, a malformed ID, or a target outside `sessionControlPolicy` returns `Tool.Error`.
|
|
127
|
+
- Aborting before or during the interrupt returns `Tool.Error`. An abort after the interrupt may return a normal result.
|
|
128
|
+
- Cancelling a stopped, failed, or finished session is not an error.
|
|
129
|
+
- 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.
|
|
130
|
+
- OpenCode may wake the parent with a cancellation notice.
|
|
131
|
+
- If `interrupt` is `unknown`, `readBackMayLag` is true, or `status` is `running` or `unknown`, re-run `list`.
|
|
132
|
+
|
|
133
|
+
## cancel_descendants
|
|
134
|
+
|
|
135
|
+
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.
|
|
136
|
+
|
|
137
|
+
### Inputs
|
|
138
|
+
|
|
139
|
+
| Name | Type | Default | Notes |
|
|
140
|
+
| -------- | ------- | ------- | ------------------------------------------------------------------ |
|
|
141
|
+
| `reason` | string? | — | Up to 500 characters. Recorded in the result. |
|
|
142
|
+
| `cursor` | string? | — | From a previous `cancel_descendants` call; pass it back unchanged. |
|
|
143
|
+
|
|
144
|
+
There is no `sessionID`, `parentID`, `statuses`, or `limit` input.
|
|
145
|
+
|
|
146
|
+
### Output
|
|
147
|
+
|
|
148
|
+
Text output is a summary with counts and per-target details. JSON output contains:
|
|
149
|
+
|
|
150
|
+
- `known` — all discovered descendants in the current pass, before the cursor is applied.
|
|
151
|
+
- `considered` — descendants after the cursor.
|
|
152
|
+
- `running` — running descendants among `considered`.
|
|
153
|
+
- `beforeCursorRunning?` — running descendants before the cursor window; re-run without a cursor to include them.
|
|
154
|
+
- `targets[]` — one entry per attempted target: `sessionID`, `interrupt`, `readBack`, `status?` (status after the check, when `readBack` is `ok`), and `error?` (failure detail).
|
|
155
|
+
- `interrupt` — `accepted` (the server accepted), `rejected` (no active execution), `failed` (the call threw), or `unknown` (aborted or no definitive answer).
|
|
156
|
+
- `readBack` — `ok` (the status check after cancellation returned a status), `failed`, or `not-read` (not attempted or abandoned after an abort).
|
|
157
|
+
- `remaining` — running targets not attempted; use `cursor` to continue, or retry when no cursor is returned.
|
|
158
|
+
- `aborted` — true when the call stopped before the batch completed.
|
|
159
|
+
- `reason?`, `cursor?`, `warning?`.
|
|
160
|
+
|
|
161
|
+
### Errors and edge cases
|
|
162
|
+
|
|
163
|
+
- An unknown caller returns `Tool.Error`.
|
|
164
|
+
- 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.
|
|
165
|
+
- Only `running` rows are targeted. Use `cancel` for `unknown` rows.
|
|
166
|
+
- `maxCancelBatch` limits targets per call (20 by default).
|
|
167
|
+
- The whole batch is checked in one permission request.
|
|
168
|
+
- Cursor retries skip failed, unknown, rejected, and not-read targets. Inspect them manually.
|
|
169
|
+
- Nested cancellation can wake an intermediate parent; re-run `list` and cancel it again if it resumed.
|
|
170
|
+
- Discovery can miss running descendants; the output warns when that is possible.
|
|
171
|
+
|
|
172
|
+
## steer
|
|
173
|
+
|
|
174
|
+
Send an instruction into a session at its next model request. The message does not interrupt current work.
|
|
175
|
+
|
|
176
|
+
### Inputs
|
|
177
|
+
|
|
178
|
+
| Name | Type | Default | Notes |
|
|
179
|
+
| ----------- | -------- | ------- | ------------------------------------------------------------------- |
|
|
180
|
+
| `sessionID` | string | — | Required. Target session ID. |
|
|
181
|
+
| `text` | string | — | Up to `maxTextLength` (16000) characters; longer input is rejected. |
|
|
182
|
+
| `resume` | boolean? | `true` | `false` accepts the message without waking an idle child. |
|
|
183
|
+
|
|
184
|
+
### Output
|
|
185
|
+
|
|
186
|
+
Text output reports the target and delivery. JSON output contains:
|
|
187
|
+
|
|
188
|
+
- `sessionID`, `messageID?`, `delivery`, `chars`, `resume`.
|
|
189
|
+
- `status?` — status observed before the message was accepted; a wake may not be reflected yet.
|
|
190
|
+
- `pending?` — true when the message was accepted without waking an idle child.
|
|
191
|
+
|
|
192
|
+
### Errors and edge cases
|
|
193
|
+
|
|
194
|
+
- An unknown target, a self-target, empty or overlong text, or a target outside `sessionControlPolicy` returns `Tool.Error`.
|
|
195
|
+
- The message is delivered before the child's next model request; the current tool call is not interrupted.
|
|
196
|
+
- Waking an idle child may not produce a completion notice in the parent. Resume that child by `sessionID` with the built-in `subagent` tool to read its result.
|
|
197
|
+
- `delivery` is the server-reported delivery, normally `steer`.
|
|
198
|
+
|
|
199
|
+
## queue
|
|
200
|
+
|
|
201
|
+
Queue a message as the next independent turn after the current task settles.
|
|
202
|
+
|
|
203
|
+
### Inputs
|
|
204
|
+
|
|
205
|
+
| Name | Type | Default | Notes |
|
|
206
|
+
| ----------- | -------- | ------- | ------------------------------------------------------------------- |
|
|
207
|
+
| `sessionID` | string | — | Required. Target session ID. |
|
|
208
|
+
| `text` | string | — | Up to `maxTextLength` (16000) characters; longer input is rejected. |
|
|
209
|
+
| `resume` | boolean? | `true` | `false` accepts the message without waking an idle child. |
|
|
210
|
+
|
|
211
|
+
### Output
|
|
212
|
+
|
|
213
|
+
Text output reports the target and delivery. JSON output contains:
|
|
214
|
+
|
|
215
|
+
- `sessionID`, `messageID?`, `delivery`, `chars`, `resume`.
|
|
216
|
+
- `status?` — status observed before the message was accepted; a wake may not be reflected yet.
|
|
217
|
+
- `pending?` — true when the message was accepted without waking an idle child.
|
|
218
|
+
|
|
219
|
+
### Errors and edge cases
|
|
220
|
+
|
|
221
|
+
- An unknown target, a self-target, empty or overlong text, or a target outside `sessionControlPolicy` returns `Tool.Error`.
|
|
222
|
+
- The message does not join the current run; it waits until the current task settles, then starts a separate turn.
|
|
223
|
+
- `delivery` is the server-reported delivery, normally `queue`.
|
|
224
|
+
|
|
225
|
+
## context
|
|
226
|
+
|
|
227
|
+
Inject a synthetic context message without asking for a turn. The tool always uses `resume: false`.
|
|
228
|
+
|
|
229
|
+
### Inputs
|
|
230
|
+
|
|
231
|
+
| Name | Type | Default | Notes |
|
|
232
|
+
| ------------- | ------- | ------- | ------------------------------------------------------------------- |
|
|
233
|
+
| `sessionID` | string | — | Required. Target session ID. |
|
|
234
|
+
| `text` | string | — | Up to `maxTextLength` (16000) characters; longer input is rejected. |
|
|
235
|
+
| `description` | string? | — | Up to 200 characters. A short label shown in the transcript. |
|
|
236
|
+
|
|
237
|
+
### Output
|
|
238
|
+
|
|
239
|
+
Text output reports the target and size. JSON output contains:
|
|
240
|
+
|
|
241
|
+
- `sessionID`, `messageID?`, `delivery: "next-step"`, `chars`.
|
|
242
|
+
- `description?`.
|
|
243
|
+
- `status?` — status observed before the message was accepted; context does not wake the child.
|
|
244
|
+
- `pending?` — true when the message was accepted without waking an idle child.
|
|
245
|
+
|
|
246
|
+
### Errors and edge cases
|
|
247
|
+
|
|
248
|
+
- An unknown target, a self-target, empty or overlong text, overlong description, or a target outside `sessionControlPolicy` returns `Tool.Error`.
|
|
249
|
+
- This is a synthetic message, not a user instruction.
|
|
250
|
+
- An idle child keeps the message pending until its next run.
|
|
251
|
+
- For an instruction without waking, use `steer` with `resume: false`. For a follow-up turn, use `queue`.
|
|
252
|
+
|
|
253
|
+
## Statuses
|
|
254
|
+
|
|
255
|
+
- `running` — the session is executing; a live start newer than the last idle marker, or `busy > idle` in the session record, keeps it running.
|
|
256
|
+
- `stopped` — the run was interrupted before it finished.
|
|
257
|
+
- `failed` — the last run failed.
|
|
258
|
+
- `finished` — the last run succeeded.
|
|
259
|
+
- `unknown` — no reliable status is available; the session may still be running.
|
|
260
|
+
|
|
261
|
+
Status is observed from live events and the session record. It can lag, and an `unknown` row may still be running. See [limitations](limitations.md).
|
|
262
|
+
|
|
263
|
+
`list` includes all five statuses by default. `statuses` filters the rows; `counts` always covers all five.
|
|
264
|
+
|
|
265
|
+
## Discovery and pagination
|
|
266
|
+
|
|
267
|
+
`ctx.session.list` is required; see the [README](../README.md) for the supported OpenCode V2 version. `list`, `cancel_descendants`, and `usage` with `includeDescendants: true` walk the relevant subtree through that API. This finds children launched before the plugin loaded, from the TUI, or by another process.
|
|
268
|
+
|
|
269
|
+
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.
|
|
270
|
+
|
|
271
|
+
`list` and `cancel_descendants` return a cursor for stable paging. A cursor keeps its place while statuses change. 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.
|
|
272
|
+
|
|
273
|
+
For `list`:
|
|
274
|
+
|
|
275
|
+
- `known` — all discovered sessions before the status filter and cursor.
|
|
276
|
+
- `matching` — matches in the current discovery pass, before the cursor.
|
|
277
|
+
- `window` — matches after the cursor.
|
|
278
|
+
- `remaining` — matches in the window not returned on this page.
|
|
279
|
+
- `remainingPages` — pages left in the cursor walk.
|
|
280
|
+
- `counts` — all discovered sessions by status, before the filter and cursor.
|
|
281
|
+
|
|
282
|
+
A new child can increase `known` and `matching` without appearing in the current cursor walk. `matching - window` then includes previous pages and new children.
|
|
283
|
+
|
|
284
|
+
For `cancel_descendants`, the cursor is bound to the tool and the caller's subtree. `remaining` counts running targets not attempted in the call.
|
|
285
|
+
|
|
286
|
+
## Text vs JSON
|
|
287
|
+
|
|
288
|
+
`format: "json"` returns a structured `output` object. `format: "text"` returns a string `output`.
|
|
289
|
+
|
|
290
|
+
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.
|
|
291
|
+
|
|
292
|
+
Per-tool defaults (when both formats are allowed):
|
|
293
|
+
|
|
294
|
+
| Tool | Default format |
|
|
295
|
+
| -------------------- | -------------- |
|
|
296
|
+
| `list` | `json` |
|
|
297
|
+
| `usage` | `json` |
|
|
298
|
+
| `cancel_descendants` | `json` |
|
|
299
|
+
| `cancel` | `text` |
|
|
300
|
+
| `steer` | `text` |
|
|
301
|
+
| `queue` | `text` |
|
|
302
|
+
| `context` | `text` |
|
|
303
|
+
|
|
304
|
+
Use `text` for a quick read. Use `json` when you need fields such as `targets`, `pending`, `usage`, `tree`, or `lastRequest`. See [configuration](configuration.md) for the option.
|
|
305
|
+
|
|
306
|
+
## Context vs cumulative usage
|
|
307
|
+
|
|
308
|
+
`usage.contextTokens` follows the OpenCode UI formula:
|
|
309
|
+
|
|
310
|
+
```text
|
|
311
|
+
last assistant step after the last completed compaction:
|
|
312
|
+
input + output + reasoning + cache.read + cache.write
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
It resets after a completed compaction and is the best available estimate of the current context footprint.
|
|
316
|
+
|
|
317
|
+
`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.
|
|
318
|
+
|
|
319
|
+
`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.
|
|
320
|
+
|
|
321
|
+
`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.
|
|
322
|
+
|
|
323
|
+
`tree.discoveryComplete` reports discovery completeness, not whether every session finished. `tree.descendantsMayLag` covers descendants; the top-level `usageMayLag` covers the target.
|
|
324
|
+
|
|
325
|
+
## Errors
|
|
326
|
+
|
|
327
|
+
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`.
|
|
328
|
+
|
|
329
|
+
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.
|
|
330
|
+
|
|
331
|
+
The error message is actionable; correct the call and continue.
|
|
332
|
+
|
|
333
|
+
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.
|
|
334
|
+
|
|
335
|
+
Partial batch failures stay in `cancel_descendants.targets` with `interrupt: "failed"` or `readBack: "failed"` so the caller can inspect them.
|
|
336
|
+
|
|
337
|
+
Abort behavior:
|
|
338
|
+
|
|
339
|
+
- `list` and `usage` return `Tool.Error` when discovery or a context read is aborted.
|
|
340
|
+
- `cancel` returns `Tool.Error` when the abort happens before or during the interrupt. An abort after the interrupt may still return a normal result.
|
|
341
|
+
- `cancel_descendants` returns `Tool.Error` before discovery. Otherwise it reports `aborted: true` with the targets it attempted, and a warning when discovery was incomplete.
|
|
342
|
+
|
|
343
|
+
## Permissions and configuration
|
|
344
|
+
|
|
345
|
+
Mutations use the `subagent.control` permission action when `enforcePermissions` is enabled; see the [security model](security-model.md) for targeting rules and policy modes.
|
|
346
|
+
|
|
347
|
+
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.1.0",
|
|
4
|
+
"description": "OpenCode V2 plugin that gives the agent tools to list, inspect usage, cancel, steer, queue, and inject context into its subagent sessions without interrupting the parent or siblings.",
|
|
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.2.5"
|
|
58
|
+
},
|
|
59
|
+
"peerDependenciesMeta": {
|
|
60
|
+
"@opencode/plugin": {
|
|
61
|
+
"optional": true
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@opencode/plugin": "^2.2.5",
|
|
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": false,
|
|
74
|
+
"printWidth": 90
|
|
75
|
+
}
|
|
76
|
+
}
|