opencode-subagent-tools 0.2.0 → 0.2.2
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 +28 -0
- package/README.md +2 -2
- package/SKILL.md +1 -1
- package/docs/development.md +13 -1
- package/docs/limitations.md +10 -9
- package/docs/reference.md +6 -6
- package/package.json +7 -8
- package/src/background.ts +62 -41
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,34 @@ All notable changes to this project are documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## 0.2.2 - 2026-11-25
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Background video jobs (`video`) are reported in `backgroundJob.kinds` and count as active work. OpenCode 2.4.0+ reports them through the `experimental.idle` hook; older versions never send this kind.
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- Tested against `@opencode/plugin` 2.4.1.
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- Background probes recognize the current `generate_image` tool name and the older `experimental_image_generate` name.
|
|
21
|
+
|
|
22
|
+
## 0.2.1 - 2026-11-18
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
|
|
26
|
+
- Code Mode background jobs (`codemode`) are reported in `backgroundJob.kinds` and count as active work. OpenCode 2.3.1+ reports them through the `experimental.idle` hook; older versions never send this kind.
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
|
|
30
|
+
- Tested against `@opencode/plugin` 2.3.2.
|
|
31
|
+
|
|
32
|
+
### Fixed
|
|
33
|
+
|
|
34
|
+
- A Code Mode idle item no longer falls into the unknown-kind path and marks its owner `stateUnknown`.
|
|
35
|
+
|
|
8
36
|
## 0.2.0 - 2026-11-17
|
|
9
37
|
|
|
10
38
|
### Added
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ descendants, steer or queue messages, and inject context.
|
|
|
6
6
|
|
|
7
7
|
> Plugin ID: `subagent-tools`. Default tool namespace: `subagent`.
|
|
8
8
|
|
|
9
|
-
Requires OpenCode 2.3.0
|
|
9
|
+
Requires OpenCode 2.3.0+; tested against 2.4.1.
|
|
10
10
|
|
|
11
11
|
## Quick start
|
|
12
12
|
|
|
@@ -84,7 +84,7 @@ to be asked or blocked. See [security model](docs/security-model.md).
|
|
|
84
84
|
## Pitfalls
|
|
85
85
|
|
|
86
86
|
- **`finished` is not task completion.** It means the last execution succeeded.
|
|
87
|
-
The child may still own a shell, image,
|
|
87
|
+
The child may still own a shell, image, video, subagent, or Code Mode job. Use `active` and
|
|
88
88
|
`subtreeActive` to find work that is still in progress.
|
|
89
89
|
- **`cancel` is a soft interrupt.** It does not cascade. A long tool call may
|
|
90
90
|
finish first, and jobs owned by an idle session keep running. The result
|
package/SKILL.md
CHANGED
|
@@ -40,7 +40,7 @@ Tool names below omit the default `subagent_` prefix. With the default namespace
|
|
|
40
40
|
- `activeDescendants` — at least one discovered child is active in its subtree.
|
|
41
41
|
An idle parent with active descendants may wake.
|
|
42
42
|
- `backgroundJob` — the session's own observed background work. `kinds` can
|
|
43
|
-
contain `shell`, `image`, and `
|
|
43
|
+
contain `shell`, `image`, `video`, `subagent`, and `codemode`. `stateUnknown` means work may remain
|
|
44
44
|
but could not be verified.
|
|
45
45
|
- `usageMayLag` — usage may still grow because the session is active or unknown.
|
|
46
46
|
|
package/docs/development.md
CHANGED
|
@@ -49,7 +49,7 @@ import { fileURLToPath } from "node:url";
|
|
|
49
49
|
|
|
50
50
|
The suite lives in `tests/` and mirrors the feature areas: `list`, `usage`, `activity`, `background`, `actions`, `status`, `mutations`, `permissions`, `policy`, `cancel-descendants`, `discovery`, and `options`, plus focused unit tests for config, cursor, events, messages, output, schema validation, and tokens. `tests/harness.ts` builds the mocked plugin context, the idle-hook and synthetic-message helpers, and the per-test cleanup hook. Tests exercise the plugin through its public `setup`/tool surface.
|
|
51
51
|
|
|
52
|
-
CI runs the unit suite against `@opencode/plugin`
|
|
52
|
+
CI runs the unit suite against the `@opencode/plugin` version from `package.json`. Loading the packed package into a real OpenCode server is a manual release check, not a CI job.
|
|
53
53
|
|
|
54
54
|
`tests/`, `.oxlintrc.json`, and `bun.lock` are repository-only; the npm package ships the source tree, `SKILL.md`, `SECURITY.md`, and the user-facing docs.
|
|
55
55
|
|
|
@@ -80,3 +80,15 @@ The tests cover:
|
|
|
80
80
|
- Cooperative-stop abort behavior across discovery, context reads, interrupts, and batches.
|
|
81
81
|
|
|
82
82
|
Discovery, ownership checks, interrupts, prompt/synthetic admission, and read-backs accept the tool's `context.signal`; stopping a tool call stops the underlying work where the client supports it.
|
|
83
|
+
|
|
84
|
+
## CI
|
|
85
|
+
|
|
86
|
+
`.github/workflows/ci.yml` runs on push and pull requests on `ubuntu-latest`:
|
|
87
|
+
|
|
88
|
+
- install with `bun install --frozen-lockfile`;
|
|
89
|
+
- `bun run check`;
|
|
90
|
+
- `npm pack --dry-run`.
|
|
91
|
+
|
|
92
|
+
The workflow uses read-only contents permission, a 15-minute timeout, and cancels superseded runs on the same ref.
|
|
93
|
+
|
|
94
|
+
CI is Ubuntu-only. Windows-specific tests run locally on Windows and are not part of CI.
|
package/docs/limitations.md
CHANGED
|
@@ -20,16 +20,17 @@ and what to do about it.
|
|
|
20
20
|
record, and an `unknown` row may still be running. A resumed child can look
|
|
21
21
|
finished if the server omits its busy/idle timestamps.
|
|
22
22
|
- **`finished` is execution-only.** In OpenCode 2.3.0+ a child can be
|
|
23
|
-
idle while its own shell, image,
|
|
24
|
-
last execution succeeded, not that the delegated task is
|
|
25
|
-
`active` and `subtreeActive` for work that is still in progress.
|
|
23
|
+
idle while its own shell, image, video, subagent, or Code Mode job is still running.
|
|
24
|
+
`finished` means the last execution succeeded, not that the delegated task is
|
|
25
|
+
complete. Use `active` and `subtreeActive` for work that is still in progress.
|
|
26
26
|
- **Background detection is live.** The plugin learns about background work from
|
|
27
27
|
the `experimental.idle` hook, shell events, and structured context probes. A job
|
|
28
28
|
that started before the plugin loaded may not be visible until a later event or
|
|
29
29
|
a `cancel` probe. The idle hook is experimental; if it is unavailable, shell
|
|
30
|
-
events still provide partial coverage, but image
|
|
31
|
-
missed.
|
|
32
|
-
|
|
30
|
+
events still provide partial coverage, but image, video, subagent, and Code Mode jobs
|
|
31
|
+
may be missed. Code Mode jobs are visible only through the idle hook; a
|
|
32
|
+
`cancel` probe cannot see them. The hook has no timestamp, so the plugin stamps
|
|
33
|
+
it locally; large clock skew can delay or drop a snapshot.
|
|
33
34
|
- **`subtreeActive` follows discovered rows.** Incomplete discovery can make it
|
|
34
35
|
false when an active descendant is missing. `discoveryComplete` and the warning
|
|
35
36
|
still apply.
|
|
@@ -44,8 +45,8 @@ and what to do about it.
|
|
|
44
45
|
|
|
45
46
|
- **`cancel` is a soft interrupt.** It uses `session.interrupt({ resume: false })`.
|
|
46
47
|
A long tool call may finish first, and there is no hard abort.
|
|
47
|
-
- **Idle jobs keep running.** OpenCode can keep shell, subagent,
|
|
48
|
-
alive while a session is idle; `session.interrupt` does nothing there. When the
|
|
48
|
+
- **Idle jobs keep running.** OpenCode can keep shell, subagent, image, video, or
|
|
49
|
+
Code Mode jobs alive while a session is idle; `session.interrupt` does nothing there. When the
|
|
49
50
|
session is running, an interrupt cancels its jobs as the session stops; for an
|
|
50
51
|
idle session, use the job's own controls. The plugin context exposes no job
|
|
51
52
|
list or job cancellation API, so the plugin probes the target's structured
|
|
@@ -147,7 +148,7 @@ and what to do about it.
|
|
|
147
148
|
`ctx.session`, `ctx.event`, `ctx.permission`, `ctx.model`, `ctx.skill`, and
|
|
148
149
|
`ctx.options`. The `experimental.idle` hook is experimental and may be
|
|
149
150
|
unavailable in a custom build; in that case shell events still provide partial
|
|
150
|
-
coverage, but image
|
|
151
|
+
coverage, but image, video, subagent, and Code Mode jobs may be missed.
|
|
151
152
|
- **`steer` cannot move a blocking shell.** The UI calls `session.background`
|
|
152
153
|
after admitting a steer; `Plugin.Context` does not expose it. Delivery may wait
|
|
153
154
|
for a blocking shell to finish. This is a UI parity gap, not a plugin bug.
|
package/docs/reference.md
CHANGED
|
@@ -48,7 +48,7 @@ Text output is one row per session plus summary and warning lines. JSON output c
|
|
|
48
48
|
- `active` — true when the session itself is running, unknown, or owns a background job. Descendants are excluded.
|
|
49
49
|
- `subtreeActive` — true when the session or any discovered descendant is active.
|
|
50
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.
|
|
51
|
+
- `backgroundJob?` — the session's own observed work: `kinds` (`shell`, `image`, `video`, `subagent`, `codemode`), and optional `stateUnknown` when work may remain but could not be verified.
|
|
52
52
|
- `ageSeconds?` (omitted when the launch time is unknown), `launchedAt`.
|
|
53
53
|
- `usageMayLag?` — true when the row is active or unknown.
|
|
54
54
|
- `usage?` — `costUSD?`, `tokens?`, and `tokensUsed?` when the server provides them.
|
|
@@ -134,7 +134,7 @@ Text output reports the interrupt result, the current state, and a lag note. JSO
|
|
|
134
134
|
- `accepted` — alias for `interrupt === "accepted"`.
|
|
135
135
|
- `status` — execution status after the interrupt and status check.
|
|
136
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.
|
|
137
|
+
- `backgroundJob?` — the target's own observed work: `kinds` (`shell`, `image`, `video`, `subagent`, `codemode`), `mayRemain?` when work may still run after the call, and `stateUnknown?` when a probe failed.
|
|
138
138
|
- `reason?` — the recorded reason.
|
|
139
139
|
- `readBackMayLag` — true when the interrupt was accepted and the status check after cancellation still reports `running` or `unknown`.
|
|
140
140
|
- `cancellationDoesNotCascade` — always `true`; cancellation is non-cascading, not a claim that the target has no children.
|
|
@@ -147,7 +147,7 @@ Text distinguishes an accepted interrupt with a remaining job ("may continue"),
|
|
|
147
147
|
- An unknown target, a self-target, a malformed ID, or a target outside `sessionControlPolicy` returns `Tool.Error`.
|
|
148
148
|
- Aborting before or during the interrupt returns `Tool.Error`. An abort after the interrupt may return a normal result.
|
|
149
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.
|
|
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/video/subagent tool parts. Video jobs are normally visible through the idle hook because `generate_video` returns before the probe runs. It cannot see a Code Mode job; that requires an idle snapshot. 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
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
152
|
- OpenCode may wake the parent with a cancellation notice.
|
|
153
153
|
- If `interrupt` is `unknown`, `readBackMayLag` is true, or `status` is `running` or `unknown`, re-run `list`.
|
|
@@ -298,15 +298,15 @@ Text output reports the target and size. JSON output contains:
|
|
|
298
298
|
- `finished` — the last run succeeded. This does not mean the delegated task is complete.
|
|
299
299
|
- `unknown` — no reliable status is available; the session may still be running.
|
|
300
300
|
|
|
301
|
-
`status` is execution-oriented. In OpenCode 2.3.0+, shell, image,
|
|
301
|
+
`status` is execution-oriented. In OpenCode 2.3.0+, shell, image, video, subagent, or Code Mode work can stay alive while a session is idle, so use the activity fields for "still working":
|
|
302
302
|
|
|
303
303
|
- `active` — the session itself is running, unknown, or owns a background job. Descendants are not included.
|
|
304
304
|
- `subtreeActive` — the session or any discovered descendant is active.
|
|
305
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 `
|
|
306
|
+
- `backgroundJob` — the session's own observed work: `kinds` can contain `shell`, `image`, `video`, `subagent`, and `codemode`. `stateUnknown` means work may remain but could not be verified.
|
|
307
307
|
- `usageMayLag` — the session is active or unknown, so usage may still grow.
|
|
308
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).
|
|
309
|
+
Status and activity are observed from live events, the idle hook, shell events, structured context probes, and the session record. Code Mode jobs are visible only through the idle hook. They can lag, and an `unknown` row may still be running. See [limitations](limitations.md).
|
|
310
310
|
|
|
311
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
312
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-subagent-tools",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "OpenCode V2 plugin that gives the agent tools to list, inspect, cancel, steer, queue, and inject context into its subagent sessions.",
|
|
5
5
|
"author": "Maxim Matsiushonak",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,15 +26,14 @@
|
|
|
26
26
|
"keywords": [
|
|
27
27
|
"opencode",
|
|
28
28
|
"opencode-plugin",
|
|
29
|
+
"opencode-v2",
|
|
30
|
+
"opencode-v2-plugin",
|
|
31
|
+
"agent-tools",
|
|
29
32
|
"subagent",
|
|
33
|
+
"subagents",
|
|
30
34
|
"subagent-tools",
|
|
31
35
|
"subagent-control",
|
|
32
|
-
"
|
|
33
|
-
"cancel",
|
|
34
|
-
"steer",
|
|
35
|
-
"queue",
|
|
36
|
-
"opencode-v2",
|
|
37
|
-
"plugin"
|
|
36
|
+
"subagent-orchestration"
|
|
38
37
|
],
|
|
39
38
|
"repository": {
|
|
40
39
|
"type": "git",
|
|
@@ -62,7 +61,7 @@
|
|
|
62
61
|
}
|
|
63
62
|
},
|
|
64
63
|
"devDependencies": {
|
|
65
|
-
"@opencode/plugin": "^2.
|
|
64
|
+
"@opencode/plugin": "^2.4.1",
|
|
66
65
|
"@types/bun": "^1.4.3",
|
|
67
66
|
"@types/node": "^26.6.5",
|
|
68
67
|
"oxlint": "1.60.0",
|
package/src/background.ts
CHANGED
|
@@ -2,17 +2,46 @@ import { normalizeSessionID } from "./session";
|
|
|
2
2
|
import { RUN_STATUS, type RunStatus } from "./status";
|
|
3
3
|
import { isUnsafeControlCode } from "./text";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
interface BackgroundJobSpec {
|
|
6
|
+
/** Extract a normalized job key from an idle item. */
|
|
7
|
+
key: (item: Record<string, unknown>) => string | undefined;
|
|
8
|
+
/** Tool names whose running call proves this background kind. */
|
|
9
|
+
tools: readonly string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const BACKGROUND_JOB_SPECS = {
|
|
13
|
+
shell: {
|
|
14
|
+
key: (item) => normalizeBackgroundKey(item.shellID),
|
|
15
|
+
tools: ["shell"],
|
|
16
|
+
},
|
|
17
|
+
image: {
|
|
18
|
+
key: (item) =>
|
|
19
|
+
normalizeBackgroundKey(item.path) ?? normalizeBackgroundKey(item.model),
|
|
20
|
+
tools: ["generate_image", "experimental_image_generate"],
|
|
21
|
+
},
|
|
22
|
+
video: {
|
|
23
|
+
key: (item) => normalizeBackgroundKey(item.path),
|
|
24
|
+
tools: ["generate_video"],
|
|
25
|
+
},
|
|
26
|
+
subagent: {
|
|
27
|
+
key: (item) => normalizeSessionID(item.childSessionID),
|
|
28
|
+
tools: ["subagent"],
|
|
29
|
+
},
|
|
30
|
+
codemode: {
|
|
31
|
+
key: (item) => normalizeBackgroundKey(item.jobID),
|
|
32
|
+
tools: [],
|
|
33
|
+
},
|
|
34
|
+
} as const satisfies Record<string, BackgroundJobSpec>;
|
|
35
|
+
|
|
36
|
+
export type BackgroundJobKind = keyof typeof BACKGROUND_JOB_SPECS;
|
|
10
37
|
|
|
11
|
-
export
|
|
12
|
-
|
|
38
|
+
export const BACKGROUND_JOB_KINDS: readonly BackgroundJobKind[] = Object.keys(
|
|
39
|
+
BACKGROUND_JOB_SPECS,
|
|
40
|
+
) as BackgroundJobKind[];
|
|
13
41
|
|
|
14
|
-
export const
|
|
15
|
-
|
|
42
|
+
export const BACKGROUND_JOB_KIND = Object.fromEntries(
|
|
43
|
+
BACKGROUND_JOB_KINDS.map((kind) => [kind, kind]),
|
|
44
|
+
) as { readonly [K in BackgroundJobKind]: K };
|
|
16
45
|
|
|
17
46
|
const BACKGROUND_JOB_KIND_SET: ReadonlySet<string> = new Set(BACKGROUND_JOB_KINDS);
|
|
18
47
|
|
|
@@ -59,7 +88,7 @@ export const MAX_BACKGROUND_SESSIONS = 500;
|
|
|
59
88
|
export const MAX_BACKGROUND_JOBS_PER_KIND = 100;
|
|
60
89
|
export const MAX_BACKGROUND_KEY_LENGTH = 500;
|
|
61
90
|
|
|
62
|
-
/** Validate a shell/image key without rejecting spaces in
|
|
91
|
+
/** Validate a shell/image/video key without rejecting spaces in paths. */
|
|
63
92
|
export const normalizeBackgroundKey = (value: unknown): string | undefined => {
|
|
64
93
|
if (typeof value !== "string") return undefined;
|
|
65
94
|
const key = value.trim();
|
|
@@ -72,9 +101,8 @@ export const normalizeBackgroundKey = (value: unknown): string | undefined => {
|
|
|
72
101
|
};
|
|
73
102
|
|
|
74
103
|
interface BackgroundState {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
subagent: Map<string, number>;
|
|
104
|
+
/** Jobs grouped by kind, then keyed by their normalized ID or path. */
|
|
105
|
+
jobs: Map<BackgroundJobKind, Map<string, number>>;
|
|
78
106
|
/** Last idle snapshot applied for this session, trusted or not. */
|
|
79
107
|
snapshotAt: number;
|
|
80
108
|
/** Whether an idle snapshot has ever been authoritative for this session. */
|
|
@@ -86,9 +114,7 @@ interface BackgroundState {
|
|
|
86
114
|
}
|
|
87
115
|
|
|
88
116
|
const createState = (): BackgroundState => ({
|
|
89
|
-
|
|
90
|
-
image: new Map(),
|
|
91
|
-
subagent: new Map(),
|
|
117
|
+
jobs: new Map(),
|
|
92
118
|
snapshotAt: 0,
|
|
93
119
|
hasAuthoritativeSnapshot: false,
|
|
94
120
|
snapshotOwners: new Set(),
|
|
@@ -98,7 +124,13 @@ const createState = (): BackgroundState => ({
|
|
|
98
124
|
const stateJobMap = (
|
|
99
125
|
state: BackgroundState,
|
|
100
126
|
kind: BackgroundJobKind,
|
|
101
|
-
): Map<string, number> =>
|
|
127
|
+
): Map<string, number> => {
|
|
128
|
+
const existing = state.jobs.get(kind);
|
|
129
|
+
if (existing) return existing;
|
|
130
|
+
const map = new Map<string, number>();
|
|
131
|
+
state.jobs.set(kind, map);
|
|
132
|
+
return map;
|
|
133
|
+
};
|
|
102
134
|
|
|
103
135
|
const trimMap = (map: Map<string, number>, limit: number) => {
|
|
104
136
|
while (map.size > limit) {
|
|
@@ -117,8 +149,7 @@ const trimSet = (set: Set<string>, limit: number) => {
|
|
|
117
149
|
};
|
|
118
150
|
|
|
119
151
|
const clearAtOrBefore = (state: BackgroundState, at: number) => {
|
|
120
|
-
for (const
|
|
121
|
-
const map = stateJobMap(state, kind);
|
|
152
|
+
for (const map of state.jobs.values()) {
|
|
122
153
|
for (const [key, startedAt] of map) {
|
|
123
154
|
if (startedAt <= at) map.delete(key);
|
|
124
155
|
}
|
|
@@ -175,19 +206,7 @@ const parseIdleItem = (value: unknown): IdleItemParse => {
|
|
|
175
206
|
}
|
|
176
207
|
if (!owner) return { ok: false };
|
|
177
208
|
|
|
178
|
-
|
|
179
|
-
const key = normalizeBackgroundKey(item.shellID);
|
|
180
|
-
return key
|
|
181
|
-
? { ok: true, item: { kind: item.kind, key, owner } }
|
|
182
|
-
: { ok: false, owner };
|
|
183
|
-
}
|
|
184
|
-
if (item.kind === BACKGROUND_JOB_KIND.image) {
|
|
185
|
-
const key = normalizeBackgroundKey(item.path) ?? normalizeBackgroundKey(item.model);
|
|
186
|
-
return key
|
|
187
|
-
? { ok: true, item: { kind: item.kind, key, owner } }
|
|
188
|
-
: { ok: false, owner };
|
|
189
|
-
}
|
|
190
|
-
const key = normalizeSessionID(item.childSessionID);
|
|
209
|
+
const key = BACKGROUND_JOB_SPECS[item.kind].key(item);
|
|
191
210
|
return key ? { ok: true, item: { kind: item.kind, key, owner } } : { ok: false, owner };
|
|
192
211
|
};
|
|
193
212
|
|
|
@@ -251,11 +270,11 @@ const readContext = async (
|
|
|
251
270
|
};
|
|
252
271
|
|
|
253
272
|
/** Tool names whose running call proves the session owns that background kind. */
|
|
254
|
-
const RUNNING_TOOL_KIND: ReadonlyMap<string, BackgroundJobKind> = new Map(
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
273
|
+
const RUNNING_TOOL_KIND: ReadonlyMap<string, BackgroundJobKind> = new Map(
|
|
274
|
+
BACKGROUND_JOB_KINDS.flatMap((kind) =>
|
|
275
|
+
BACKGROUND_JOB_SPECS[kind].tools.map((name) => [name, kind] as const),
|
|
276
|
+
),
|
|
277
|
+
);
|
|
259
278
|
|
|
260
279
|
const scanTargetMessages = (
|
|
261
280
|
messages: readonly ProbeMessage[],
|
|
@@ -331,7 +350,8 @@ export const createBackgroundJobStore = () => {
|
|
|
331
350
|
/**
|
|
332
351
|
* Apply an `experimental.idle` snapshot. The hook lists work owned by the
|
|
333
352
|
* idle session and its descendants; items are stored under their owner so a
|
|
334
|
-
* descendant's job never makes the idle parent active.
|
|
353
|
+
* descendant's job never makes the idle parent active. Code Mode scripts are
|
|
354
|
+
* reported only through this hook; shell events do not cover them.
|
|
335
355
|
*
|
|
336
356
|
* The snapshot is authoritative only when every item can be parsed. An item
|
|
337
357
|
* with a known owner preserves that owner's jobs and marks its state unknown;
|
|
@@ -459,7 +479,7 @@ export const createBackgroundJobStore = () => {
|
|
|
459
479
|
rememberDeleted(id, at);
|
|
460
480
|
states.delete(id);
|
|
461
481
|
for (const state of states.values()) {
|
|
462
|
-
state.subagent
|
|
482
|
+
state.jobs.get(BACKGROUND_JOB_KIND.subagent)?.delete(id);
|
|
463
483
|
state.snapshotOwners.delete(id);
|
|
464
484
|
}
|
|
465
485
|
};
|
|
@@ -468,7 +488,7 @@ export const createBackgroundJobStore = () => {
|
|
|
468
488
|
const state = states.get(sessionID);
|
|
469
489
|
if (!state) return undefined;
|
|
470
490
|
const kinds = BACKGROUND_JOB_KINDS.filter(
|
|
471
|
-
(kind) =>
|
|
491
|
+
(kind) => (state.jobs.get(kind)?.size ?? 0) > 0,
|
|
472
492
|
);
|
|
473
493
|
const stateUnknown = state.unknownAt > 0;
|
|
474
494
|
if (kinds.length === 0 && !stateUnknown) return undefined;
|
|
@@ -488,7 +508,8 @@ export const createBackgroundJobStore = () => {
|
|
|
488
508
|
/**
|
|
489
509
|
* Structured fallback when the store has no authoritative snapshot for the
|
|
490
510
|
* target, such as after a restart. Running shell messages and running
|
|
491
|
-
* shell/image/subagent tool parts are proof of work
|
|
511
|
+
* shell/image/video/subagent tool parts are proof of work. Code Mode scripts
|
|
512
|
+
* are not visible here, so they rely on the idle hook. A missing snapshot, or a
|
|
492
513
|
* failed or malformed read, is unknown, never idle.
|
|
493
514
|
*/
|
|
494
515
|
const probe = async ({
|