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
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## 0.1.0 - 2026-11-07
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Initial release of the `subagent-tools` OpenCode plugin.
|
|
13
|
+
- Seven tools under the default `subagent` namespace:
|
|
14
|
+
- `subagent_list` — list subagent sessions, filter by status, and page through results.
|
|
15
|
+
- `subagent_usage` — read cost, tokens, current context, and optional descendant totals for any session.
|
|
16
|
+
- `subagent_cancel` — stop one session with a soft interrupt.
|
|
17
|
+
- `subagent_cancel_descendants` — stop the caller's running descendants in batches.
|
|
18
|
+
- `subagent_steer` — send an instruction at the target session's next model request.
|
|
19
|
+
- `subagent_queue` — queue a message as the next independent turn.
|
|
20
|
+
- `subagent_context` — inject a synthetic context message without starting a turn.
|
|
21
|
+
- Options: `namespace`, `enforcePermissions`, `sessionControlPolicy`, `allowedOutputFormats`, `registerSkill`, and `limits` for discovery, list size, cancellation batch, and text length.
|
|
22
|
+
- Permission action `subagent.control` for mutations; `list` and `usage` are read-only. `cancel_descendants` checks the whole batch in one permission request.
|
|
23
|
+
- Per-call text or JSON output when both formats are allowed; `list`, `usage`, and `cancel_descendants` default to JSON. Set `allowedOutputFormats` to one format to omit the per-call choice.
|
|
24
|
+
- Discovery through `ctx.session.list`; requires OpenCode 2.2.5+. Tested against `@opencode/plugin` 2.2.5.
|
|
25
|
+
- Input validation for session IDs and text lengths.
|
|
26
|
+
- Bundled `SKILL.md` skill with operational guidance.
|
|
27
|
+
- Bun test suite, lint, typecheck, and CI scripts.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Maxim Matsiushonak
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,114 @@
|
|
|
1
|
-
#
|
|
1
|
+
# opencode-subagent-tools
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Seven tools for OpenCode V2 that let an agent inspect and control subagent
|
|
4
|
+
sessions: list children and usage, cancel one session or the caller's running
|
|
5
|
+
descendants, steer or queue messages, and inject context.
|
|
6
|
+
|
|
7
|
+
> Plugin ID: `subagent-tools`. Default tool namespace: `subagent`.
|
|
8
|
+
|
|
9
|
+
Requires OpenCode 2.2.5+ with `ctx.session.list`.
|
|
10
|
+
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
opencode plugin add opencode-subagent-tools
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
GitHub:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
opencode plugin add github:finnseefly/opencode-subagent-tools
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
After install, run `opencode reload` and ask the agent to call `subagent_list`.
|
|
24
|
+
For manual/local installation, see [installation](docs/installation.md).
|
|
25
|
+
|
|
26
|
+
## Tools
|
|
27
|
+
|
|
28
|
+
| Tool | What it does |
|
|
29
|
+
| ----------------------------- | ------------------------------------------------------------ |
|
|
30
|
+
| `subagent_list` | List child sessions with status, age, cost, and token usage. |
|
|
31
|
+
| `subagent_usage` | Read cost, tokens, and current context for a session. |
|
|
32
|
+
| `subagent_cancel` | Stop one session. |
|
|
33
|
+
| `subagent_cancel_descendants` | Stop running descendants of the calling session. |
|
|
34
|
+
| `subagent_steer` | Send an instruction at the child's next model request. |
|
|
35
|
+
| `subagent_queue` | Queue a message as the next independent turn. |
|
|
36
|
+
| `subagent_context` | Inject a synthetic context message without starting a turn. |
|
|
37
|
+
|
|
38
|
+
The plugin also registers a `subagent-tools` skill with operational guidance.
|
|
39
|
+
See the [tool reference](docs/reference.md#text-vs-json) for output formats and
|
|
40
|
+
per-tool defaults. Set `allowedOutputFormats` to `["text"]` or `["json"]` to
|
|
41
|
+
allow only one format; the default `["text", "json"]` enables the per-call
|
|
42
|
+
`format` choice.
|
|
43
|
+
|
|
44
|
+
Tool names above use the default `subagent` namespace. Change the `namespace`
|
|
45
|
+
option to use a different prefix. Nested subagents require
|
|
46
|
+
`experimental.subagent_depth` to be at least `2` in OpenCode; this is an OpenCode
|
|
47
|
+
setting, not a plugin option.
|
|
48
|
+
|
|
49
|
+
## Configuration
|
|
50
|
+
|
|
51
|
+
One power-user example; every option is optional. The values below are the
|
|
52
|
+
defaults. See [configuration](docs/configuration.md) for ranges and examples.
|
|
53
|
+
|
|
54
|
+
```jsonc
|
|
55
|
+
{
|
|
56
|
+
"$schema": "https://opencode.ai/config.json",
|
|
57
|
+
"plugins": [
|
|
58
|
+
{
|
|
59
|
+
"package": "opencode-subagent-tools",
|
|
60
|
+
"options": {
|
|
61
|
+
"namespace": "subagent", // tool prefix
|
|
62
|
+
"enforcePermissions": true, // check mutations with subagent.control
|
|
63
|
+
"sessionControlPolicy": "descendants", // mutations only; reads are unrestricted
|
|
64
|
+
"allowedOutputFormats": ["text", "json"], // or ["text"] / ["json"]
|
|
65
|
+
"registerSkill": true, // register SKILL.md as a skill
|
|
66
|
+
"limits": {
|
|
67
|
+
"maxDiscoveryNodes": 200,
|
|
68
|
+
"maxDiscoveryDepth": 8,
|
|
69
|
+
"maxDiscoveryPages": 5,
|
|
70
|
+
"maxListRows": 20,
|
|
71
|
+
"maxCancelBatch": 20,
|
|
72
|
+
"maxTextLength": 16000,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Mutations call the `subagent.control` permission action. Setting
|
|
81
|
+
`enforcePermissions: true` by itself does not prompt; add an `ask` or `deny` rule
|
|
82
|
+
to be asked or blocked. See [security model](docs/security-model.md).
|
|
83
|
+
|
|
84
|
+
## Pitfalls
|
|
85
|
+
|
|
86
|
+
- **Foreground children block the parent.** If you want to control a child while
|
|
87
|
+
it runs, launch it as a background subagent.
|
|
88
|
+
- **`cancel` is a soft interrupt.** It does not cascade. A long tool call may
|
|
89
|
+
finish first, and jobs owned by an idle session keep running.
|
|
90
|
+
- **Discovery stops at 200 nodes, 8 levels, or 5 pages by default.** Raise them
|
|
91
|
+
for large trees. An empty or partial list is not proof that no subagents
|
|
92
|
+
exist. See [limitations](docs/limitations.md).
|
|
93
|
+
- **Usage can lag while a child is running.** Values are persisted at step
|
|
94
|
+
boundaries; `usageMayLag` means re-query after the step or after cancellation.
|
|
95
|
+
- **`cancel_descendants` stops up to `maxCancelBatch` running descendants per
|
|
96
|
+
call.** It only touches the caller's subtree; use `cursor` to continue. Nested
|
|
97
|
+
cancellation can wake an intermediate parent.
|
|
98
|
+
- **Permissions are not prompted by default.** Add an `ask` or `deny` rule for
|
|
99
|
+
`subagent.control` if you rely on approval.
|
|
100
|
+
|
|
101
|
+
## Documentation
|
|
102
|
+
|
|
103
|
+
- [Installation](docs/installation.md)
|
|
104
|
+
- [Configuration](docs/configuration.md)
|
|
105
|
+
- [Tool reference](docs/reference.md)
|
|
106
|
+
- [Security model](docs/security-model.md)
|
|
107
|
+
- [Security policy](SECURITY.md)
|
|
108
|
+
- [Limitations](docs/limitations.md)
|
|
109
|
+
- [Development](docs/development.md)
|
|
110
|
+
- [Changelog](CHANGELOG.md)
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
MIT. See [LICENSE](./LICENSE).
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported versions
|
|
4
|
+
|
|
5
|
+
Security fixes are applied to the latest published `0.1.x` release.
|
|
6
|
+
|
|
7
|
+
## Reporting a vulnerability
|
|
8
|
+
|
|
9
|
+
Do not open a public issue for a security problem.
|
|
10
|
+
|
|
11
|
+
Use GitHub's private vulnerability reporting:
|
|
12
|
+
|
|
13
|
+
<https://github.com/finnseefly/opencode-subagent-tools/security/advisories/new>
|
|
14
|
+
|
|
15
|
+
Include:
|
|
16
|
+
|
|
17
|
+
- the affected version;
|
|
18
|
+
- the OpenCode version;
|
|
19
|
+
- a minimal reproduction or the relevant plugin configuration;
|
|
20
|
+
- the impact you observed;
|
|
21
|
+
- any suggested fix or mitigation.
|
|
22
|
+
|
|
23
|
+
If private reporting is unavailable, open a minimal public issue asking for a
|
|
24
|
+
private channel. Do not include exploit details in that issue.
|
|
25
|
+
|
|
26
|
+
## Scope
|
|
27
|
+
|
|
28
|
+
This plugin exposes model-facing tools that can interrupt, steer, queue
|
|
29
|
+
messages for, and inject context into OpenCode sessions. Reports about
|
|
30
|
+
permission or ownership bypass, session-ID confusion, ancestor control under
|
|
31
|
+
`sessionControlPolicy`, prompt injection through session titles or metadata,
|
|
32
|
+
and denial of service are in scope.
|
|
33
|
+
|
|
34
|
+
Known limitations are documented in [docs/limitations.md](docs/limitations.md).
|
|
35
|
+
The default `sessionControlPolicy` is `"descendants"`; the `"all"` policy is
|
|
36
|
+
security-sensitive and should be enabled deliberately.
|
package/SKILL.md
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: subagent-tools
|
|
3
|
+
description: Use the subagent tools to list, inspect usage, cancel, steer, queue, and inject context into OpenCode subagent sessions. Covers tool contracts, delivery modes, soft interrupts, status-check lag, parent wake, nested depth, permissions, and budget handoffs.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Subagent Tools
|
|
7
|
+
|
|
8
|
+
Use these tools when you need to inspect or control OpenCode subagent sessions. They complement the built-in `subagent` launch tool; they do not replace it.
|
|
9
|
+
|
|
10
|
+
## Names and namespace
|
|
11
|
+
|
|
12
|
+
Tool names below omit the default `subagent_` prefix. With the default namespace, call `subagent_list`, `subagent_usage`, `subagent_cancel`, `subagent_cancel_descendants`, `subagent_steer`, `subagent_queue`, and `subagent_context`. The prefix follows the plugin's `namespace` option and may be different in the user's config.
|
|
13
|
+
|
|
14
|
+
## Choose the tool
|
|
15
|
+
|
|
16
|
+
| Goal | Tool |
|
|
17
|
+
| --------------------------------------------- | -------------------- |
|
|
18
|
+
| See children, cost, and cumulative usage | `list` |
|
|
19
|
+
| Read current context, cost, and context limit | `usage` |
|
|
20
|
+
| Correct a running child at its next boundary | `steer` |
|
|
21
|
+
| Make a message the next independent turn | `queue` |
|
|
22
|
+
| Give a child a fact without waking it | `context` |
|
|
23
|
+
| Stop one target session | `cancel` |
|
|
24
|
+
| Stop the caller's running descendants | `cancel_descendants` |
|
|
25
|
+
|
|
26
|
+
## Token and cost terms
|
|
27
|
+
|
|
28
|
+
- `tokens` — cumulative token breakdown for the session: `input`, `output`, `reasoning`, `cache.read`, `cache.write`. It includes every cache read and is not the current context.
|
|
29
|
+
- `tokensUsed` — `input + output + reasoning`; a cumulative non-cache budget.
|
|
30
|
+
- `contextTokens` — current context footprint: the last assistant step after the last completed compaction, `input + output + reasoning + cache.read + cache.write`. Only `usage` returns it.
|
|
31
|
+
- `costUSD` — the session's own cost. For a family total, use `usage` with `includeDescendants: true` and read `tree.costUSD`.
|
|
32
|
+
|
|
33
|
+
## Text vs JSON
|
|
34
|
+
|
|
35
|
+
When both formats are allowed (the default), every tool accepts `format`. If the user configured only one format, the `format` input is absent: `["text"]` returns text only, and `["json"]` always returns structured output.
|
|
36
|
+
|
|
37
|
+
- Use `text` for a quick read. Use `json` when you need fields such as `targets`, `pending`, `usage`, `tree`, or `lastRequest`.
|
|
38
|
+
- Choose by task; do not force JSON everywhere.
|
|
39
|
+
|
|
40
|
+
## list
|
|
41
|
+
|
|
42
|
+
List child sessions discovered through the server's session tree, newest launch first.
|
|
43
|
+
|
|
44
|
+
### Inputs
|
|
45
|
+
|
|
46
|
+
- `parentID?` — parent session ID. Defaults to the calling session. Any parent is accepted because reads are unrestricted.
|
|
47
|
+
- `statuses?` — array of `running`, `stopped`, `failed`, `finished`, or `unknown`. Omit it to include all five. An empty array is an error; unknown values are rejected.
|
|
48
|
+
- `limit?` — maximum rows. Defaults to `maxListRows` (20); values outside 1 to `maxListRows` are rejected.
|
|
49
|
+
- `cursor?` — cursor from a previous `list` call. Pass it back unchanged.
|
|
50
|
+
- `format?` — default `json`.
|
|
51
|
+
|
|
52
|
+
### Output
|
|
53
|
+
|
|
54
|
+
Text is a table-like summary. With `format: "json"`, the output contains:
|
|
55
|
+
|
|
56
|
+
- `root`, `statuses`, `discoveryComplete`, `warning?`
|
|
57
|
+
- `known` — all discovered sessions before the status filter and cursor.
|
|
58
|
+
- `matching` — all matches in the current discovery pass, before the cursor.
|
|
59
|
+
- `window` — matches after the cursor; `remaining` is the part not returned; `remainingPages` is pages left.
|
|
60
|
+
- `counts` — counts for all five statuses across all discovered sessions, before filter and cursor.
|
|
61
|
+
- `rows[]` — `id`, `parentID?`, `agent?`, `title?`, `titleTruncated?`, `status`, `ageSeconds?`, `launchedAt`, `usageMayLag?`, and optional `usage` with `costUSD?`, `tokens?`, and `tokensUsed?`.
|
|
62
|
+
|
|
63
|
+
### Notes
|
|
64
|
+
|
|
65
|
+
- A cursor walk sees the sessions found when it started. New children can increase `known`/`matching` without appearing in `window`; re-run without a cursor to include them.
|
|
66
|
+
- Discovery can miss sessions. `discoveryComplete: false` and `warning` mean the result may be incomplete; an empty list is not proof that no subagents exist.
|
|
67
|
+
- `usageMayLag: true` means the row is running or unknown and its usage is as of the last persisted step.
|
|
68
|
+
- `usage.tokens` and `usage.tokensUsed` are cumulative; neither is the current context. `list` does not return `contextTokens`; use `usage` for that.
|
|
69
|
+
- Use `cursor` until `remaining` is 0.
|
|
70
|
+
|
|
71
|
+
## usage
|
|
72
|
+
|
|
73
|
+
Read cost, tokens, and current context for a session. Read-only: any session ID is accepted, including the caller, its parents, and foreign sessions.
|
|
74
|
+
|
|
75
|
+
### Inputs
|
|
76
|
+
|
|
77
|
+
- `sessionID` — required. Target session ID.
|
|
78
|
+
- `includeDescendants?` — when `true`, add `tree` totals for the target and its descendants.
|
|
79
|
+
- `format?` — default `json`.
|
|
80
|
+
|
|
81
|
+
### Output
|
|
82
|
+
|
|
83
|
+
With `format: "json"`:
|
|
84
|
+
|
|
85
|
+
- `sessionID`, `parentID?`, `status`, `usageMayLag?`
|
|
86
|
+
- `costUSD?` — own cost, not a family total.
|
|
87
|
+
- `tokens?`, `tokensUsed?` — cumulative counts; `tokensUsed` is `input + output + reasoning`.
|
|
88
|
+
- `contextTokens?` — last assistant step after the last completed compaction: `input + output + reasoning + cache.read + cache.write`.
|
|
89
|
+
- `lastRequest?` — input/output/reasoning/cache read/cache write/total for that step.
|
|
90
|
+
- `contextLimit?`, `contextPercent?`, `model?`, `warning?`.
|
|
91
|
+
- `tree?` — with `includeDescendants: true`: `sessions` includes the target, `descendants` excludes it, and `costUSD`/`tokensUsed` include the target's own values when available. `tokensUsed` is omitted when no session in the tree reports token data. `discoveryComplete` covers the descendant walk; `descendantsMayLag?` flags running/unknown descendants; `warning?` marks incomplete discovery.
|
|
92
|
+
|
|
93
|
+
### Notes
|
|
94
|
+
|
|
95
|
+
- `contextTokens: 0` is legitimate when no assistant step exists after the last completed compaction. If context is unavailable, the field is omitted and `warning` explains why.
|
|
96
|
+
- `contextTokens` is the current context; `tokens` and `tokensUsed` are cumulative.
|
|
97
|
+
- `costUSD` is the session's own cost. For a family total, use `includeDescendants: true` and read `tree.costUSD`.
|
|
98
|
+
- The caller's own status is reported as `running` while the tool executes.
|
|
99
|
+
- Re-query after the step completes or after cancellation when `usageMayLag` is true.
|
|
100
|
+
|
|
101
|
+
## cancel
|
|
102
|
+
|
|
103
|
+
Stop one session with a soft interrupt.
|
|
104
|
+
|
|
105
|
+
### Inputs
|
|
106
|
+
|
|
107
|
+
- `sessionID` — required. Target session ID; the policy may allow a session outside the caller's subtree.
|
|
108
|
+
- `reason?` — up to 500 characters. Recorded in the result; not delivered to the child.
|
|
109
|
+
- `format?` — default `text`.
|
|
110
|
+
|
|
111
|
+
### Output
|
|
112
|
+
|
|
113
|
+
With `format: "json"`:
|
|
114
|
+
|
|
115
|
+
- `sessionID`, `accepted`, `interrupt`, `status`
|
|
116
|
+
- `reason?`, `readBackMayLag`, `cancellationDoesNotCascade`
|
|
117
|
+
- `costUSD?`, `tokens?`, `tokensUsed?`
|
|
118
|
+
|
|
119
|
+
`interrupt` is `accepted`, `rejected`, or `unknown`:
|
|
120
|
+
|
|
121
|
+
- `accepted` — the server accepted the interrupt.
|
|
122
|
+
- `rejected` — the target was not running; this is not an error.
|
|
123
|
+
- `unknown` — the server returned no definitive boolean. An abort during the interrupt is a `Tool.Error`.
|
|
124
|
+
|
|
125
|
+
`accepted` is a convenience alias for `interrupt === "accepted"`. `cancellationDoesNotCascade` is always `true`.
|
|
126
|
+
|
|
127
|
+
### Notes
|
|
128
|
+
|
|
129
|
+
- This is a soft interrupt: it does not cascade to the child's children, 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
|
+
- The status check after cancellation can lag. If `status` is `running` or `unknown`, or `readBackMayLag` is true, re-run `list`.
|
|
132
|
+
- The target may settle as `stopped`, `failed`, or `finished`; `stopped` is not guaranteed.
|
|
133
|
+
|
|
134
|
+
## cancel_descendants
|
|
135
|
+
|
|
136
|
+
Stop the running descendants of the calling session. It stops at most `maxCancelBatch` targets per call.
|
|
137
|
+
|
|
138
|
+
### Inputs
|
|
139
|
+
|
|
140
|
+
- `reason?` — up to 500 characters. Recorded in the result.
|
|
141
|
+
- `cursor?` — cursor from a previous `cancel_descendants` call; pass it back unchanged.
|
|
142
|
+
- `format?` — default `json`.
|
|
143
|
+
|
|
144
|
+
There is no `sessionID`, `parentID`, `statuses`, or `limit` argument. The tool always works in the calling session's subtree, regardless of `sessionControlPolicy`.
|
|
145
|
+
|
|
146
|
+
### Output
|
|
147
|
+
|
|
148
|
+
With `format: "json"`:
|
|
149
|
+
|
|
150
|
+
- `known` — all discovered descendants in the current pass, before the cursor is applied; `considered` — after the cursor; `running` — running among `considered`.
|
|
151
|
+
- `beforeCursorRunning?` — running descendants before the cursor window.
|
|
152
|
+
- `targets[]` — `sessionID`, `interrupt` (`accepted`/`rejected`/`failed`/`unknown`), `readBack` (`ok`/`failed`/`not-read`), optional `status`, optional `error`.
|
|
153
|
+
- `remaining` — running targets not attempted; `aborted` — the call stopped before the batch completed.
|
|
154
|
+
- `reason?`, `cursor?`, `warning?`.
|
|
155
|
+
|
|
156
|
+
### Notes
|
|
157
|
+
|
|
158
|
+
- Only `running` rows are targeted. `unknown` rows need an individual `cancel`.
|
|
159
|
+
- The whole batch is checked in one permission request.
|
|
160
|
+
- `maxCancelBatch` limits targets per call. Use `cursor` to continue; `remaining` counts what is left.
|
|
161
|
+
- Failed, unknown, rejected, and not-read targets are reported in `targets` and are not retried by the cursor. Inspect them manually.
|
|
162
|
+
- `aborted: true` means the call stopped before the batch completed; inspect `targets` and `remaining`.
|
|
163
|
+
- Nested cancellation can wake an intermediate parent inside the subtree. Re-run `list` after the batch and cancel that parent again if it resumed.
|
|
164
|
+
- Discovery can be incomplete; the output warns when some running descendants may be missing.
|
|
165
|
+
- It stops all running descendants of the calling session, not one selected branch. From a parent, it also stops the target child's siblings and their descendants.
|
|
166
|
+
- To stop one child and its descendants without touching siblings, `steer` that child to run `cancel_descendants` itself, then `cancel` it. Alternatively, list its descendants with `list(parentID: childID)` and cancel them individually. `cancel` does not cascade.
|
|
167
|
+
- JSON is the default because `targets[]` is the main result; use `format: "text"` for a short summary.
|
|
168
|
+
|
|
169
|
+
## steer
|
|
170
|
+
|
|
171
|
+
Send an instruction into a session at its next model request.
|
|
172
|
+
|
|
173
|
+
### Inputs
|
|
174
|
+
|
|
175
|
+
- `sessionID` — required.
|
|
176
|
+
- `text` — required; up to 16000 characters by default (`maxTextLength`).
|
|
177
|
+
- `resume?` — default `true`. `false` accepts the message without waking an idle child.
|
|
178
|
+
- `format?` — default `text`.
|
|
179
|
+
|
|
180
|
+
### Output
|
|
181
|
+
|
|
182
|
+
With `format: "json"`:
|
|
183
|
+
|
|
184
|
+
- `sessionID`, `messageID?`, `delivery`, `chars`, `resume`
|
|
185
|
+
- `status?` — status observed before the message was accepted
|
|
186
|
+
- `pending?` — true when the message was accepted without waking an idle child
|
|
187
|
+
|
|
188
|
+
### Notes
|
|
189
|
+
|
|
190
|
+
- Delivered before the child's next model request. It does not interrupt the current tool call.
|
|
191
|
+
- 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.
|
|
192
|
+
- `delivery` is the server-reported delivery, normally `steer`.
|
|
193
|
+
|
|
194
|
+
## queue
|
|
195
|
+
|
|
196
|
+
Queue a message as the next independent turn after the current task settles.
|
|
197
|
+
|
|
198
|
+
### Inputs
|
|
199
|
+
|
|
200
|
+
- `sessionID` — required.
|
|
201
|
+
- `text` — required; up to 16000 characters by default (`maxTextLength`).
|
|
202
|
+
- `resume?` — default `true`. `false` accepts the message without waking an idle child.
|
|
203
|
+
- `format?` — default `text`.
|
|
204
|
+
|
|
205
|
+
### Output
|
|
206
|
+
|
|
207
|
+
With `format: "json"`:
|
|
208
|
+
|
|
209
|
+
- `sessionID`, `messageID?`, `delivery`, `chars`, `resume`
|
|
210
|
+
- `status?` — status observed before the message was accepted
|
|
211
|
+
- `pending?` — true when the message was accepted without waking an idle child
|
|
212
|
+
|
|
213
|
+
### Notes
|
|
214
|
+
|
|
215
|
+
- The message does not join the current run. It waits until the current task settles, then starts a separate turn.
|
|
216
|
+
- `delivery` is the server-reported delivery, normally `queue`.
|
|
217
|
+
|
|
218
|
+
## context
|
|
219
|
+
|
|
220
|
+
Inject a synthetic context message without starting a turn.
|
|
221
|
+
|
|
222
|
+
### Inputs
|
|
223
|
+
|
|
224
|
+
- `sessionID` — required.
|
|
225
|
+
- `text` — required; up to 16000 characters by default (`maxTextLength`).
|
|
226
|
+
- `description?` — up to 200 characters. A short label shown in the transcript.
|
|
227
|
+
- `format?` — default `text`.
|
|
228
|
+
|
|
229
|
+
### Output
|
|
230
|
+
|
|
231
|
+
With `format: "json"`:
|
|
232
|
+
|
|
233
|
+
- `sessionID`, `messageID?`, `delivery: "next-step"`, `chars`
|
|
234
|
+
- `description?`
|
|
235
|
+
- `status?` — status observed before the message was accepted
|
|
236
|
+
- `pending?` — true when the message was accepted without waking an idle child
|
|
237
|
+
|
|
238
|
+
### Notes
|
|
239
|
+
|
|
240
|
+
- This is a synthetic message, not a user instruction.
|
|
241
|
+
- It always uses `resume: false`. An idle child keeps the message pending until its next run.
|
|
242
|
+
- For an instruction without waking, use `steer` with `resume: false`. For a follow-up turn, use `queue`.
|
|
243
|
+
|
|
244
|
+
## Permissions and policy
|
|
245
|
+
|
|
246
|
+
- Mutations use `subagent.control` when `enforcePermissions` is `true` (the default); `false` skips the permission check, but ownership still follows `sessionControlPolicy`.
|
|
247
|
+
- `list` and `usage` are read-only, do not request `subagent.control`, and may read any session, including the caller and its ancestors.
|
|
248
|
+
- `sessionControlPolicy` limits mutations only: `"descendants"` (default), `"all-except-ancestors"`, or `"all"`.
|
|
249
|
+
- `cancel_descendants` always stays in the caller's subtree; the policy does not widen it.
|
|
250
|
+
- A mutation cannot target the caller; `usage` may read it.
|
|
251
|
+
- OpenCode's base policy allows all actions, so add an `ask` or `deny` rule to prompt or block. `"all"` is privileged: a subagent can target its parent or root if it knows the ID.
|
|
252
|
+
|
|
253
|
+
## Errors
|
|
254
|
+
|
|
255
|
+
Refusals are `Tool.Error`: unknown target, self-target, invalid cursor, invalid, empty, or non-array `statuses`, malformed or overlong session/parent ID, target outside `sessionControlPolicy`, or permission denial.
|
|
256
|
+
|
|
257
|
+
Abort behavior:
|
|
258
|
+
|
|
259
|
+
- `list` and `usage` return `Tool.Error` when discovery or context read is aborted.
|
|
260
|
+
- `cancel` returns `Tool.Error` if the abort happens before or during the interrupt; an abort after the interrupt may still return a normal result.
|
|
261
|
+
- `cancel_descendants` returns `Tool.Error` before discovery; otherwise it reports `aborted: true` with the targets it attempted and a warning when discovery was incomplete.
|
|
262
|
+
|
|
263
|
+
The error message is actionable. Correct the arguments and continue.
|
|
264
|
+
|
|
265
|
+
No-op outcomes are not errors: `cancel` on an already stopped, failed, or finished session, and `cancel_descendants` with no running children, return a normal result.
|
|
266
|
+
|
|
267
|
+
## Foreground and background
|
|
268
|
+
|
|
269
|
+
These tools are most useful with background children. A foreground `subagent` call blocks the parent until the child finishes, so the parent cannot call these tools while it waits. If you plan to control a child while it runs, launch it as a background subagent.
|
|
270
|
+
|
|
271
|
+
## Nested subagents
|
|
272
|
+
|
|
273
|
+
OpenCode creates nested subagents only when `experimental.subagent_depth` is at least `2`; this is an OpenCode setting, not a plugin option. The plugin can list, inspect, steer, queue, and stop nested descendants up to the configured limits, but it does not expose a grandchild's transcript. Use the intermediate parent as a relay or have the grandchild write a handoff file.
|
|
274
|
+
|
|
275
|
+
## Limits
|
|
276
|
+
|
|
277
|
+
- `list` returns up to 20 rows by default.
|
|
278
|
+
- `cancel_descendants` interrupts up to 20 targets per call by default.
|
|
279
|
+
- `steer`, `queue`, and `context` accept up to 16000 characters by default.
|
|
280
|
+
- `reason` is capped at 500 characters and `description` at 200. These two are fixed, not `limits` options.
|
|
281
|
+
- Discovery defaults: 200 nodes, 8 levels, and 5 pages.
|
|
282
|
+
- The discovery, list, cancel-batch, and text limits are configurable through the plugin's `limits` options.
|
|
283
|
+
|
|
284
|
+
## Example: budget handoff
|
|
285
|
+
|
|
286
|
+
If cost matters for your workflow, one way to use the tools together is: check `list` for `tokensUsed`, call `usage` for a child that is approaching your budget, `steer` it to write a handoff summary and stop new work, then `cancel` if it does not wind down. Read the handoff and start a fresh child. Keep the old session for audit; `contextTokens` resets after compaction, but `costUSD` and cumulative tokens do not.
|
|
287
|
+
|
|
288
|
+
## Workflow
|
|
289
|
+
|
|
290
|
+
1. Call `list`; it includes all statuses by default. Pass `statuses: ["running"]` when you only need active children.
|
|
291
|
+
2. Pick the session ID from the result. Do not invent or guess IDs.
|
|
292
|
+
3. To change what a running child is doing, use `steer`; to add a follow-up turn, use `queue`; to add a fact without waking it, use `context`. These adjust the existing session and keep its current run and context. `cancel` stops the session; restarting it with the built-in `subagent` tool is a different workflow.
|
|
293
|
+
4. To stop one child, use `cancel`. To stop all your running descendants, use `cancel_descendants`; it cannot select one branch.
|
|
294
|
+
5. After `cancel`, re-run `list` if `interrupt` is `unknown`, `status` is `running` or `unknown`, or `readBackMayLag` is true. After `cancel_descendants`, inspect `targets[].status`/`targets[].readBack`; re-run `list` if a target still looks running. After a nested `cancel_descendants`, also check whether an intermediate parent resumed.
|
|
295
|
+
|
|
296
|
+
## Examples
|
|
297
|
+
|
|
298
|
+
- The child is editing the wrong file: use `steer` with a concrete constraint.
|
|
299
|
+
- The child should run the benchmark after its current task: use `queue`.
|
|
300
|
+
- The child is idle and you want to leave it idle: use `steer` with `resume: false`.
|
|
301
|
+
- The migration is already applied: use `context` with that fact; do not wake the child.
|
|
302
|
+
- Stop one child but keep its sibling: use `cancel` with the child's session ID.
|
|
303
|
+
- Stop every running descendant of the current session: use `cancel_descendants`.
|
|
304
|
+
- Stop one child and its descendants without touching siblings: `steer` that child to run `cancel_descendants` itself, then `cancel` it; or list its descendants and cancel them individually.
|
|
305
|
+
- If cost matters for a child: `usage` it, then `steer` a handoff before starting a fresh child.
|