codex-supervisor-mcp 0.10.2 → 0.11.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/README.en.md +25 -7
- package/README.md +23 -14
- package/package.json +6 -4
- package/skills/codex-supervisor/SKILL.md +20 -13
- package/src/cleanup-hint.js +3 -2
- package/src/cleanup-plan.js +67 -7
- package/src/cleanup.js +48 -40
- package/src/codex-runner.js +101 -79
- package/src/mcp-server.js +377 -36
- package/src/overview-delta.js +37 -5
- package/src/paths.js +2 -0
- package/src/prompt.js +5 -2
- package/src/runner-adapter.js +100 -0
- package/src/side-chat.js +10 -38
- package/src/task-store.js +284 -23
- package/src/worker-preflight.js +5 -1
- package/src/workspace-kind.js +167 -0
package/README.en.md
CHANGED
|
@@ -23,7 +23,7 @@ Point several agents at one repository and they overwrite each other, nobody can
|
|
|
23
23
|
| Problem | What it does |
|
|
24
24
|
|---|---|
|
|
25
25
|
| Workers trample each other's files | One Git worktree per worker, `ownedPaths` checked for overlap before dispatch |
|
|
26
|
-
| A worker is not only an editor |
|
|
26
|
+
| A worker is not only an editor | Four `workspaceKind` shapes: Git edit `git_worktree`, read-only `read_only_in_place`, networked research `scratch`, and explicitly authorized non-Git writes `in_place_write`. A non-Git source directory is never writable by default. |
|
|
27
27
|
| A worker says it is done and it is not | Dispatch with `acceptance` commands; the supervisor runs them in the worktree after the worker exits, and `land` refuses while they fail |
|
|
28
28
|
| Worker output floods the main thread | Events go to `data/runs/<taskId>.jsonl`; reads are gated by `limit` / `maxChars` / `kinds` |
|
|
29
29
|
| One status read fills the context | `get_orchestration_overview` fits every worker into 7000 bytes |
|
|
@@ -32,7 +32,7 @@ Point several agents at one repository and they overwrite each other, nobody can
|
|
|
32
32
|
| "Failed" and "process gone" look alike | The state machine keeps `failed` and `lost` apart |
|
|
33
33
|
| No view of where a batch is | `codex-supervisor-web`, a board that shows every worker by session |
|
|
34
34
|
| Work sits uncommitted or unpushed | Collecting a worker means `land_codex_worker` by default; the main thread commits and pushes its own edits; before deploying, check the remote SHA really contains the files |
|
|
35
|
-
| Worktrees and branches pile up |
|
|
35
|
+
| Worktrees and branches pile up | `verify_delivery_push` creates a cleanup plan. Only acceptance-passed, remotely verified, clean worktrees can be SAFE; review an item before explicitly applying it, while branches and evidence stay retained |
|
|
36
36
|
|
|
37
37
|
Workers run `codex exec` with `model` passed through: the main thread stays on Claude, workers can run DeepSeek or any model Codex has a provider for, and the bills stay separate.
|
|
38
38
|
|
|
@@ -144,13 +144,16 @@ Light and dark follow the system. No external resources.
|
|
|
144
144
|
|
|
145
145
|
## Tools
|
|
146
146
|
|
|
147
|
-
|
|
147
|
+
Thirty-nine.
|
|
148
148
|
|
|
149
149
|
| Tool | Arguments | What it does |
|
|
150
150
|
|---|---|---|
|
|
151
151
|
| `check_workers` | none | Report newly settled runs and actionable changes; recover a new-format first lost/no_work run once. Unchanged state is quiet. Call from a host-scheduled loop and use a distinct CODEX_SUPERVISOR_OBSERVER_ID for each reconnecting main thread |
|
|
152
|
+
| `overview_delta` | `cursor` | Main-thread incremental view: counters, changed summaries, short attention reason / next action and next_cursor; no prompt, diff, event or capsule history |
|
|
152
153
|
| `check_acceptance` | `cwd`, `acceptance`, `baseRef`, `timeoutMs` | Execute supplied checks before dispatch, without creating a worker or proving completion; warns that failure-count greps do not establish an approved failure list or required execution |
|
|
153
|
-
| `
|
|
154
|
+
| `preflight_codex_worker` | `cwd`, `workspaceKind`, `inPlaceAuthorization`, `ownedPaths`, `probeCommands`, `baseRef`, `sandbox`, `allowedCommands`, `context`, `contracts`, `networkAccess`, `writableRoots` | Run a short probe worker under the exact workspace/base/sandbox/guard contract intended for the later worker; wait for `get_worker_preflight` to report passed before dispatch |
|
|
155
|
+
| `get_worker_preflight` | `task_id` | Read probe command evidence and the immutable runtime contract hash |
|
|
156
|
+
| `create_codex_worker` | `task`, `cwd`, `workspaceKind`, `inPlaceAuthorization`, **`ownedPaths`**, **`goal`**, `forbid`, `allowedCommands`, `context`, `contracts`, `externalOutputs`, `networkAccess`, `writableRoots`, `maxRunMs`, `maxTotalMs`, `acceptance`, `session_id`, `session_title`, `session_note`, `dependsOn`, `baseRef`, `sandbox`, `model`, `reasoningEffort`, `title`, `skipGitRepoCheck` | Git defaults to an isolated worktree. A non-Git write must choose `scratch`, or an authorized `in_place_write` with paths and acceptance. |
|
|
154
157
|
| `create_codex_followup_worker` | `task_id`, `followup_prompt`, `session_id`, plus the above | A new session seeded with the old worker's prompt, status and recent events |
|
|
155
158
|
| `resume_codex_worker` | `task_id`, `prompt`, `rebaseOnto`, `acceptance`, `context` | Continue the same Codex conversation; `thread_id` stays. `rebaseOnto` first moves the worktree onto the project's newer commit (stash, skip integrated patches, replay new commits, unstash); a conflict puts it back and does not start the worker |
|
|
156
159
|
| `wait_codex_workers` | `task_ids`, `mode` (any/all), `timeoutMinutes`, `timeoutMs`, `compact`, `includeEvents`, `eventLimit`, `eventMaxChars`, `eventKinds` | Wait for terminal states. 60 seconds by default, then a snapshot while the workers keep running; `compact` returns one line per worker with `idle_seconds` / `command_running`, so a long command and a stuck worker look different |
|
|
@@ -159,9 +162,24 @@ Twenty-one.
|
|
|
159
162
|
| `get_worker_diff` | `task_id`, `maxChars`, `paths` | What the worker actually changed: patches from the worktree's start to its working tree, committed or not. `maxChars` bounds the answer; files past it are listed without a patch |
|
|
160
163
|
| `ask_codex_worker` | `task_id`, `question`, `timeoutMs`, `maxChars`, `fresh`, `end` | Ask the worker on the side. Its thread is forked into a read-only session with no network and no MCP tools; the worker itself is untouched. A resumed worker gets a new fork by itself, `fresh` forces one, `end` deletes it |
|
|
161
164
|
| `land_codex_worker` | `task_id`, `onto`, `commitMessage`, `ignoreAcceptance`, `allowOutsideOwned` | Cherry-pick the worker's `codex/<id>` commits onto the current branch of the dispatch directory: clean target only, a conflict rolls back, a failed acceptance is refused. `commitMessage` first commits its uncommitted edits as one commit; `ignoreAcceptance` lands anyway |
|
|
165
|
+
| `verify_delivery_push` | `task_id`, `remote`, `branch` | Fetch a remote branch and prove landed_head is reachable; records push_verified and creates a cleanup plan without pushing or deploying |
|
|
166
|
+
| `cleanup_plan` | `task_ids`, `project_root` | Create a 15-minute SAFE / REVIEW / BLOCKED plan with reasons and fingerprints; SAFE requires explicit acceptance, delivery proof, clean state and no active process/dependency |
|
|
167
|
+
| `apply_cleanup` | `plan_id`, `item_ids` | Revalidate selected SAFE items, fetch the remote and prove landed SHA reachability, then run only git worktree remove/prune |
|
|
168
|
+
| `cleanup_history` | `task_id`, `limit` | Read cleanup decisions and applied removals; never deletes anything |
|
|
162
169
|
| `get_worker_summary` | `task_id` | One paragraph: goal, status, changes, last command and message |
|
|
163
170
|
| `get_codex_worker_status` | `task_id`, `includePrompt`, `promptMaxChars` | One worker in detail |
|
|
164
171
|
| `get_codex_worker_events` | `task_id`, `limit`, `maxChars`, `kinds` | The raw event stream |
|
|
172
|
+
| `get_context_snapshot_meta` | `task_id` | Worker-only context snapshot metadata: fact IDs, token count and excluded categories, never capsule text |
|
|
173
|
+
| `get_fact` | `fact_id` | Read one fact by ID for audit without injecting it into main-thread context |
|
|
174
|
+
| `search_worker_facts` | `task_id`, `query`, `limit`, `cursor` | Search only verified facts scoped to the current work, explicit dependencies and path-matched repository facts; returns coverage and next_cursor, never raw history |
|
|
175
|
+
| `get_worker_evidence` | `task_id`, `limit` | Bounded event metadata and retained artifact IDs for one worker; select an artifact or event explicitly for detail |
|
|
176
|
+
| `get_artifact` | `artifact_id`, `maxChars` | Read one supervisor-managed evidence artifact without expanding a worker capsule into main context |
|
|
177
|
+
| `promote_worker_fact` | `fact_id`, `scope`, `watchedPaths`, `expiresAt` | Explicitly promote a candidate to a new verified fact after main-thread review; repo scope requires watched paths |
|
|
178
|
+
| `revoke_worker_fact` | `fact_id`, `reason` | Revoke a candidate or verified fact after audit; it is excluded from search and future worker capsules |
|
|
179
|
+
| `create_independent_verifier` | `task_id`, `title` | Create a fresh read-only, no-network verifier for a settled worker; it receives the objective and current worktree, never the target report or candidate facts |
|
|
180
|
+
| `record_independent_finding` | `verifier_task_id`, `verdict`, `reason` | Persist an independent passes/fails/inconclusive finding with a subject event and retained evidence artifact |
|
|
181
|
+
| `resolve_independent_finding` | `verifier_task_id`, `resolution` | Record how a finding was resolved without deleting the finding or evidence |
|
|
182
|
+
| `get_independent_review` | `verifier_task_id` | Read the persistent subject/verifier/finding/resolution relation |
|
|
165
183
|
| `get_worker_goal` | `task_id` | The goal recorded at dispatch plus the native Codex goal (tokens, time) |
|
|
166
184
|
| `list_codex_workers` | `status`, `includeHistory`, `includeDetails` | List workers, active ones by default |
|
|
167
185
|
| `get_session_works` | `session_id` | Every worker of one session. The way back after a main-thread restart |
|
|
@@ -190,9 +208,9 @@ A model with no separate `apply_patch` tool (measured with Codex 0.162 + DeepSee
|
|
|
190
208
|
|
|
191
209
|
An `allowedCommands` entry ending in `*` is a prefix match (so `go test ./internal/*` covers `go test ./internal/service -run TestX`), valid only for a single command without shell metacharacters. An editor worker may also read with grep/sed (without `-i`)/find (without `-exec`/`-delete`)/jq (without `-i`)/awk, the git read subcommands and pure read pipes such as `cmd | head|tail|wc|sort|uniq`; `tee`, redirects and `env` stay refused. The guard is not a filesystem sandbox: a miss only writes inside the worker's own worktree, and land refuses it.
|
|
192
210
|
|
|
193
|
-
The guard relaxes by
|
|
211
|
+
The guard relaxes by workspace shape: a `git_worktree` editor with non-empty `ownedPaths` gets only declared commands and simple reads; `read_only_in_place` cannot write or use network; networked research uses `scratch` under `SUPERVISOR_HOME`, never the source directory; `in_place_write` requires explicit authorization, owned paths and acceptance with before/after manifests. A non-Git `workspace-write` request without `workspaceKind` is refused. A fact is expired and excluded from a future worker capsule when its base SHA no longer covers the task, a watched path changed, or its in-place manifest drifted; explicit dependencies provide only delivery summaries.
|
|
194
212
|
|
|
195
|
-
After reconciliation, check_workers atomically resumes a dead first lost/no_work/invalid_report run once and returns recovery receipts (an invalid report only re-asks for the bare JSON; it does not redo the work).
|
|
213
|
+
After reconciliation, check_workers atomically resumes a dead first lost/no_work/invalid_report run once and returns recovery receipts (an invalid report only re-asks for the bare JSON; it does not redo the work). Two consecutive no-output/no-command runs with the same fingerprint become `two_stall` and `needs_attention`, never another blind retry; approval, authentication, permission and quota waits are not retried. Final reports use JSON result/verification/not_done; structured_report exposes validation independently of command history and acceptance. Invalid JSON is failed/invalid_report and cannot land. Existing history is labelled legacy_text.
|
|
196
214
|
|
|
197
215
|
context declares up to 20 absolute file paths with optional sha256, within a combined 6000-character budget with contracts; each file is at most 5 MB. Dispatch pins actual hashes and resume refuses drift unless new context is explicitly supplied. Handoffs are limited to 1800 characters/16 lines with a truncation marker; complete contracts and refs remain separate, and inputs grant no write permission.
|
|
198
216
|
|
|
@@ -206,7 +224,7 @@ Dispatch checks required hooks/output-schema support (Codex 0.162+); unsupported
|
|
|
206
224
|
|
|
207
225
|
Ownership reservation and task insertion are atomic across MCP dispatch/resume processes; ownership remains reserved during acceptance or exit settlement. Failure to create an isolated Git checkout is explicit and never falls back to executing in the project directory.
|
|
208
226
|
|
|
209
|
-
Cleanup previews by default: `npm run cleanup -- --dry-run`.
|
|
227
|
+
Cleanup previews by default: `npm run cleanup -- --dry-run`. Apply only selected existing items: `npm run cleanup -- --apply --plan <plan_id> --item <item_id>`. SAFE requires acceptance passed, remote delivery proof, a clean worktree, no active process/dependent and verified Git registration/ownership; apply re-fetches the remote and proves the landed SHA remains reachable. Dirty, unaccepted, unlanded, force-pushed-away, lost/failed or unproven work is preserved with a reason.
|
|
210
228
|
|
|
211
229
|
## How this differs from Claude Code subagents
|
|
212
230
|
|
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
| 问题 | 做法 |
|
|
24
24
|
|---|---|
|
|
25
25
|
| 几个 worker 互相踩文件 | 一个 worker 一个 Git worktree,`ownedPaths` 在派单前查冲突 |
|
|
26
|
-
| worker 不是只会改代码 |
|
|
26
|
+
| worker 不是只会改代码 | 四种 `workspaceKind`:Git 编辑 `git_worktree`、只读 `read_only_in_place`、联网研究 `scratch`、显式授权的非 Git 写入 `in_place_write`;非 Git 默认绝不写原目录 |
|
|
27
27
|
| worker 的过程塞爆主线程上下文 | 事件写 `data/runs/<taskId>.jsonl`,读的时候有 `limit` / `maxChars` / `kinds` 三道闸 |
|
|
28
28
|
| 主线程读一次状态就顶满 | `get_orchestration_overview` 把全部 worker 压进 7000 字节 |
|
|
29
29
|
| 进程重启后不知道谁还在跑 | `supervisor.sqlite` 一行一个 work,带 `thread_id` |
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
| worker 说做完了其实没有 | 派单给 `acceptance` 验收命令,worker 退出后 supervisor 在它的 worktree 里跑,失败 `land` 拒绝 |
|
|
33
33
|
| 看不见一批活现在到哪了 | `codex-supervisor-web` 开一个看板,按 session 看每路 worker 在干什么 |
|
|
34
34
|
| 改动留在本地没上线 | 收活默认 `land_codex_worker` 合回主分支;主线程自己的改动必须 commit + push;部署前用远端 SHA 核对文件真的在线上 |
|
|
35
|
-
| worktree / 分支越堆越多 | `verify_delivery_push` 后自动生成 cleanup plan;只对 `push_verified + clean` 判 SAFE,主线程显式 `apply_cleanup` 才删 worktree,branch/证据永远保留 |
|
|
35
|
+
| worktree / 分支越堆越多 | `verify_delivery_push` 后自动生成 cleanup plan;只对 `acceptance passed + push_verified + clean` 判 SAFE,主线程显式 `apply_cleanup` 才删 worktree,branch/证据永远保留 |
|
|
36
36
|
|
|
37
37
|
worker 跑的是 `codex exec`,`model` 透传:主线程留在 Claude,worker 可以挂 DeepSeek 或任何 Codex 配了 provider 的模型,账单分开算。
|
|
38
38
|
|
|
@@ -146,16 +146,16 @@ land_codex_worker 核过了,落进集成分支
|
|
|
146
146
|
|
|
147
147
|
## 工具
|
|
148
148
|
|
|
149
|
-
|
|
149
|
+
39 个。
|
|
150
150
|
|
|
151
151
|
| 工具 | 入参 | 作用 |
|
|
152
152
|
|---|---|---|
|
|
153
153
|
| `check_workers` | 无参 | 交付新终态、验收失败和需处理goal;新格式第1轮lost/no_work自动恢复一次,未变返回quiet;用宿主定时唤醒调用,每个主线程设独立CODEX_SUPERVISOR_OBSERVER_ID可在重启后接回 |
|
|
154
|
-
| `overview_delta` | `cursor` | 主线程默认轮询入口:只返回 active / needs_attention / ready_to_land / ready_to_clean、cursor
|
|
154
|
+
| `overview_delta` | `cursor` | 主线程默认轮询入口:只返回 active / needs_attention / ready_to_land / ready_to_clean、cursor 后变化、短版 attention_reason / next_action 和 next_cursor;不返回全量历史、prompt、diff、event 或 worker capsule |
|
|
155
155
|
| `check_acceptance` | `cwd`, `acceptance`, `baseRef`, `timeoutMs` | 派单前实际运行给定验收命令,不建 worker,不证明 worker 完成;数量 grep 会提示不能证明失败名单和必跑执行 |
|
|
156
|
-
| `preflight_codex_worker` | `cwd`, `ownedPaths`, `probeCommands`, `baseRef`, `sandbox`, `allowedCommands`, `context`, `contracts`, `networkAccess`, `writableRoots` | 用与目标 worker 相同的 base/sandbox/guard 起短 probe worker;它必须实际跑完每条 probe command。等终态后读 `get_worker_preflight` |
|
|
156
|
+
| `preflight_codex_worker` | `cwd`, `workspaceKind`, `inPlaceAuthorization`, `ownedPaths`, `probeCommands`, `baseRef`, `sandbox`, `allowedCommands`, `context`, `contracts`, `networkAccess`, `writableRoots` | 用与目标 worker 相同的 workspace/base/sandbox/guard 起短 probe worker;它必须实际跑完每条 probe command。等终态后读 `get_worker_preflight` |
|
|
157
157
|
| `get_worker_preflight` | `task_id` | 返回 probe 的实际 command evidence、运行环境 contract hash 和 `running/passed/failed`;只有 `passed` 才能复用 |
|
|
158
|
-
| `create_codex_worker` | `task`, `cwd`, **`ownedPaths`**, **`goal`**, `preflight_id`, `forbid`, `allowedCommands`, `context`, `contracts`, `externalOutputs`, `networkAccess`, `writableRoots`, `maxRunMs`, `maxTotalMs`, `acceptance`, `session_id`, `session_title`, `session_note`, `dependsOn`, `baseRef`, `sandbox`, `model`, `reasoningEffort`, `title`, `skipGitRepoCheck` |
|
|
158
|
+
| `create_codex_worker` | `task`, `cwd`, `workspaceKind`, `inPlaceAuthorization`, **`ownedPaths`**, **`goal`**, `preflight_id`, `forbid`, `allowedCommands`, `context`, `contracts`, `externalOutputs`, `networkAccess`, `writableRoots`, `maxRunMs`, `maxTotalMs`, `acceptance`, `session_id`, `session_title`, `session_note`, `dependsOn`, `baseRef`, `sandbox`, `model`, `reasoningEffort`, `title`, `skipGitRepoCheck` | Git 默认隔离 worktree;非 Git 写入必须选 `scratch` 或有授权、paths、acceptance 的 `in_place_write`。`preflight_id` 给了就必须是通过的同环境 probe |
|
|
159
159
|
| `create_codex_followup_worker` | `task_id`, `followup_prompt`, `session_id`, 其余同上 | 开一个新会话,把老 worker 的 prompt、状态、近期事件拼进去 |
|
|
160
160
|
| `resume_codex_worker` | `task_id`, `prompt`, `rebaseOnto`, `acceptance`, `context` | 接同一个 Codex 会话继续跑,`thread_id` 不变。`rebaseOnto` 先把 worktree 挪到主线新头(stash、跳过已合入补丁、重放新增提交、放回),冲突原样退回不起 worker |
|
|
161
161
|
| `wait_codex_workers` | `task_ids`, `mode`(any/all), `timeoutMinutes`, `timeoutMs`, `compact`, `includeEvents`, `eventLimit`, `eventMaxChars`, `eventKinds` | 等终态。默认 60 秒,到点带快照返回,worker 照跑;`compact` 每路只回一行,带 `idle_seconds` / `command_running`,分得清长命令和卡住 |
|
|
@@ -165,14 +165,23 @@ land_codex_worker 核过了,落进集成分支
|
|
|
165
165
|
| `ask_codex_worker` | `task_id`, `question`, `timeoutMs`, `maxChars`, `fresh`, `end` | 旁路问 worker 一句。线程 fork 成只读侧会话,没网络、没 MCP 工具,worker 本身不动。worker 被 resume 过会自动换新 fork,`fresh` 强制换,`end` 删 |
|
|
166
166
|
| `land_codex_worker` | `task_id`, `onto`, `commitMessage`, `ignoreAcceptance`, `allowOutsideOwned` | 把 worker 在 `codex/<id>` 上的提交 cherry-pick 到派单目录的当前分支。目标要干净,冲突回滚,验收 `failed` 拒绝。`commitMessage` 先替它把未提交的改动提交成一笔,`ignoreAcceptance` 放行 |
|
|
167
167
|
| `verify_delivery_push` | `task_id`, `remote`, `branch` | fetch 指定 remote branch 并证明 `landed_head` 已可达;只读验证,不会 push 或部署。通过后记录 `push_verified` 并生成 cleanup plan |
|
|
168
|
-
| `cleanup_plan` | `task_ids`, `project_root` | 生成 15 分钟有效的 SAFE / REVIEW / BLOCKED 计划,含原因、fingerprint 与回收空间估算;SAFE
|
|
169
|
-
| `apply_cleanup` | `plan_id`, `item_ids` | 只在未过期计划上二次校验 SAFE item
|
|
168
|
+
| `cleanup_plan` | `task_ids`, `project_root` | 生成 15 分钟有效的 SAFE / REVIEW / BLOCKED 计划,含原因、fingerprint 与回收空间估算;SAFE 必须 acceptance passed、push verified、干净且无活跃依赖/进程 |
|
|
169
|
+
| `apply_cleanup` | `plan_id`, `item_ids` | 只在未过期计划上二次校验 SAFE item、重新 fetch remote 并确认 landed SHA 仍可达后执行 `git worktree remove/prune`;保留 branch、task、events、JSONL、artifacts |
|
|
170
170
|
| `cleanup_history` | `task_id`, `limit` | 查询 cleanup 的计划、理由、fingerprint 和实际回收记录 |
|
|
171
171
|
| `get_worker_summary` | `task_id` | 一段话:goal、状态、改动、最后一条命令和消息 |
|
|
172
172
|
| `get_codex_worker_status` | `task_id`, `includePrompt`, `promptMaxChars` | 单个 worker 的状态细节 |
|
|
173
173
|
| `get_codex_worker_events` | `task_id`, `limit`, `maxChars`, `kinds` | 原始事件流 |
|
|
174
174
|
| `get_context_snapshot_meta` | `task_id` | 只读 worker context 的 snapshot ID、fact IDs、token 估算和排除项;不返回 capsule 正文或历史记录 |
|
|
175
175
|
| `get_fact` | `fact_id` | 按 ID 审计一条 candidate/verified fact;不会自动扩展进主线程上下文 |
|
|
176
|
+
| `search_worker_facts` | `task_id`, `query`, `limit`, `cursor` | 只检索当前 work、显式依赖和路径命中 repo scope 的 verified facts;返回 coverage / next_cursor,不返回 raw history |
|
|
177
|
+
| `get_worker_evidence` | `task_id`, `limit` | 返回某 worker 的有界 event 元数据和 retained artifact 索引;按需再点查 artifact / event |
|
|
178
|
+
| `get_artifact` | `artifact_id`, `maxChars` | 读取一个 supervisor-managed evidence artifact;不影响 worker capsule 或主线程自动上下文 |
|
|
179
|
+
| `promote_worker_fact` | `fact_id`, `scope`, `watchedPaths`, `expiresAt` | 主线程显式把 candidate 追加为 verified fact;repo scope 必须声明 watchedPaths,worker 不能自升真相 |
|
|
180
|
+
| `revoke_worker_fact` | `fact_id`, `reason` | 主线程审计后撤销 candidate / verified fact,追加事件并从 search / capsule 排除 |
|
|
181
|
+
| `create_independent_verifier` | `task_id`, `title` | 为已结算 worker 创建独立 read-only / 无网络 verifier;只给目标与当前 worktree,不给原 report/candidate facts |
|
|
182
|
+
| `record_independent_finding` | `verifier_task_id`, `verdict`, `reason` | 记录独立 verifier 的 passes/fails/inconclusive finding,写 subject event 和 retained artifact |
|
|
183
|
+
| `resolve_independent_finding` | `verifier_task_id`, `resolution` | 记录 finding 的收口方式,保留原 finding 与证据 |
|
|
184
|
+
| `get_independent_review` | `verifier_task_id` | 查询 subject / verifier / finding / resolution 的持久关联 |
|
|
176
185
|
| `get_worker_goal` | `task_id` | 派单时记的 goal + Codex 原生 goal(token、用时) |
|
|
177
186
|
| `list_codex_workers` | `status`, `includeHistory`, `includeDetails` | 列 worker,默认只看在跑的 |
|
|
178
187
|
| `get_session_works` | `session_id` | 一个 session 的全部 worker。主线程重启后靠它找回那批活 |
|
|
@@ -187,9 +196,9 @@ land_codex_worker 核过了,落进集成分支
|
|
|
187
196
|
|
|
188
197
|
普通 worker 启动时会关闭它继承到的 `codex-supervisor` MCP,不能再派 worker、resume、cancel 或改编排状态;主线程是唯一编排者。其他业务 MCP 不受影响;旁问 fork 仍关闭全部 MCP,因为它只允许只读回答。
|
|
189
198
|
|
|
190
|
-
`session_id` 只负责批次、默认门禁和审批,不再把同批 worker 的标题、汇报或 session objective 自动塞进新 worker。worker 只收到内部编译的 context capsule
|
|
199
|
+
`session_id` 只负责批次、默认门禁和审批,不再把同批 worker 的标题、汇报或 session objective 自动塞进新 worker。worker 只收到内部编译的 context capsule:自身身份/任务、显式依赖的最小交付摘要和路径/SHA 命中的 verified facts;raw event、完整 diff、历史报告、candidate facts 都只可按需读取。事实的 base SHA 不再覆盖、watched path 发生 Git diff、或非 Git in-place manifest 漂移时会自动标为 expired 并从 capsule 排除。主线程只看 `get_context_snapshot_meta`,需要证据时再显式 `get_fact` / `get_worker_result` / `get_worker_diff`。
|
|
191
200
|
|
|
192
|
-
worker 的最终 JSON 报告会先记录为该 run 的 `candidate` fact,不能跨 work 自动注入;supervisor acceptance 通过后才生成当前 work 的 `verified` outcome,并带 report/acceptance event 来源、base SHA 与 watched paths。验收失败、未配置验收或 worker 自报完成都不会升级成共享真相。
|
|
201
|
+
worker 的最终 JSON 报告会先记录为该 run 的 `candidate` fact,不能跨 work 自动注入;supervisor acceptance 通过后才生成当前 work 的 `verified` outcome,并带 report/acceptance event 来源、base SHA 与 watched paths。push proof 另存为 retained artifact,verified fact 可回指该 artifact。验收失败、未配置验收或 worker 自报完成都不会升级成共享真相。
|
|
193
202
|
|
|
194
203
|
交付状态分开:acceptance 通过只是 `verified`,`land_codex_worker` 只是 `landed`,仍不代表远端有这笔提交。需要显式 `verify_delivery_push` fetch 并校验 `landed_head` 已在目标 remote branch 上,才是 `push_verified`;它会自动生成 cleanup plan,SAFE 项进入 `cleanup_eligible`,但永远不会自己删除。该工具绝不代替用户执行 push 或部署。
|
|
195
204
|
|
|
@@ -209,9 +218,9 @@ wait 默认预算60秒、默认compact;includeEvents会选择详细结果(
|
|
|
209
218
|
|
|
210
219
|
`allowedCommands` 里以 `*` 结尾的条目是前缀匹配(如 `go test ./internal/*` 覆盖 `go test ./internal/service -run TestX`),只对没有 shell 元字符的单条命令生效。编辑器 worker 的只读白名单覆盖 grep/sed(无 `-i`)/find(无 `-exec`/`-delete`)/jq(无 `-i`)/awk、git 只读子命令和 `cmd | head|tail|wc|sort|uniq` 纯读管道;`tee`、重定向、`env` 仍拒。守卫不是文件沙箱,漏网的写入只会落在 worker 自己的 worktree,land 会拒。
|
|
211
220
|
|
|
212
|
-
守卫按 worker 形状放权:`
|
|
221
|
+
守卫按 worker 形状放权:`git_worktree` 编辑 worker 只放声明过的命令和简单读取;`read_only_in_place` 无写入无网络;`scratch` 的联网草稿只能写在 `SUPERVISOR_HOME/scratch/<taskId>`;`in_place_write` 必须有显式授权、ownedPaths 与 acceptance,并保存前后 manifest。非 Git `workspace-write` 没写 `workspaceKind` 会拒绝,绝不默认写用户目录。
|
|
213
222
|
|
|
214
|
-
check_workers在状态协调后,对已结束的第1轮lost/no_work/invalid_report原子resume一次(invalid_report只要求重发裸JSON
|
|
223
|
+
check_workers在状态协调后,对已结束的第1轮lost/no_work/invalid_report原子resume一次(invalid_report只要求重发裸JSON,不重做活)。两轮同 fingerprint 的无输出/无命令会升级为 `two_stall` 和 `needs_attention`,不再自动重试;审批、认证、权限和quota等待也不重试,返回recoveries记录。worker最终输出强制JSON result/verification/not_done;get_worker_result的structured_report给格式校验,独立命令与acceptance仍为实际证据。非法JSON标failed/invalid_report并拒绝land;旧历史标legacy_text。
|
|
215
224
|
|
|
216
225
|
context用绝对文件路径与可选sha256声明材料,最多20份、与contracts合计6000字;文件不超过5 MB。首次派单记录实际哈希,resume校验原材料未变,需要新材料时显式传context。handoff最多1800字/16行,截断明确标记;完整约束和引用单独保留,材料不授予写权限。
|
|
217
226
|
|
|
@@ -223,9 +232,9 @@ workspace-write默认networkAccess:false;需要ssh/联网验证显式true,
|
|
|
223
232
|
|
|
224
233
|
运行前核验Codex CLI是否具备hooks/output-schema(要求0.162+);能力不足返回start_failed,wait可正常结算。get_worker_goal.native_goal_read区分missing_goal、missing_database、locked和read_error,不能把读取失败当没建goal。原生budget/usage限制也进入needs_attention。cleanup保留ignored artifacts、共享证据和未解决attention。
|
|
225
234
|
|
|
226
|
-
ownedPaths预留和任务入库在同一事务内,跨MCP并发派单/恢复不能抢同一输出;验收或退出尚未结算时仍保留归属。Git
|
|
235
|
+
ownedPaths预留和任务入库在同一事务内,跨MCP并发派单/恢复不能抢同一输出;验收或退出尚未结算时仍保留归属。Git工作区隔离创建失败明确报错,不退回主目录执行;非 Git `scratch` 也不落回原目录。
|
|
227
236
|
|
|
228
|
-
清理先 `cleanup_plan`(CLI 对应 `npm run cleanup -- --dry-run`)分类 SAFE / REVIEW / BLOCKED;SAFE 要求
|
|
237
|
+
清理先 `cleanup_plan`(CLI 对应 `npm run cleanup -- --dry-run`)分类 SAFE / REVIEW / BLOCKED;SAFE 要求 acceptance 明确 passed、`push_verified`、干净、无活跃进程/依赖、Git 注册和路径归属可证明。`apply_cleanup` 会在删除前重验 fingerprint 并 fetch remote 再验 landed SHA;CLI 只能 `npm run cleanup -- --apply --plan <plan_id> --item <item_id>` 显式选项执行。branch、task row、event、JSONL、artifact 永远保留;脏、未验收、未合、未 push、force-push 回退、lost/failed 和证明不足的一律不删。
|
|
229
238
|
|
|
230
239
|
## 和 Claude Code 的 subagent 有什么区别
|
|
231
240
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codex-supervisor-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"mcpName": "io.github.zriyox/codex-supervisor-mcp",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "MCP server that dispatches and supervises parallel Codex CLI workers, one isolated Git worktree each, with a persisted work state machine.",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"supervisor"
|
|
25
25
|
],
|
|
26
26
|
"bin": {
|
|
27
|
-
"codex-supervisor-mcp": "
|
|
28
|
-
"codex-supervisor-setup": "
|
|
29
|
-
"codex-supervisor-web": "
|
|
27
|
+
"codex-supervisor-mcp": "src/mcp-server.js",
|
|
28
|
+
"codex-supervisor-setup": "src/setup.js",
|
|
29
|
+
"codex-supervisor-web": "src/web-server.js"
|
|
30
30
|
},
|
|
31
31
|
"files": [
|
|
32
32
|
"src/mcp-server.js",
|
|
@@ -57,6 +57,8 @@
|
|
|
57
57
|
"src/cleanup.js",
|
|
58
58
|
"src/cleanup-plan.js",
|
|
59
59
|
"src/worker-preflight.js",
|
|
60
|
+
"src/workspace-kind.js",
|
|
61
|
+
"src/runner-adapter.js",
|
|
60
62
|
"src/mcp-config.js",
|
|
61
63
|
"src/context-compiler.js",
|
|
62
64
|
"src/overview-delta.js",
|
|
@@ -15,7 +15,7 @@ description: 把 Codex CLI 当并行 worker 派活、盯进度、收结果。用
|
|
|
15
15
|
|
|
16
16
|
1. 先 `search_works` 搜一下,别重复派。
|
|
17
17
|
2. 拆功能包。每路写清楚:干什么、能写哪些文件、依赖谁、怎么算做完和谁负责集成。改同一批文件就串行;文件不重叠只是并行前提,不等于依赖已满足。
|
|
18
|
-
3. 写 worker 先 `preflight_codex_worker`:用目标同一份 `baseRef` / `ownedPaths` / `sandbox` / `allowedCommands` / `context` / `networkAccess` / `writableRoots` 跑必要命令。等它终态后 `get_worker_preflight` 必须 `passed`,再把它的 `task_id` 填进 `create_codex_worker.preflight_id`。contract 变了重跑,不能拿宿主 `check_acceptance` 冒充 worker 环境成功。
|
|
18
|
+
3. 写 worker 先 `preflight_codex_worker`:用目标同一份 `workspaceKind` / `baseRef` / `ownedPaths` / `sandbox` / `allowedCommands` / `context` / `networkAccess` / `writableRoots` 跑必要命令。等它终态后 `get_worker_preflight` 必须 `passed`,再把它的 `task_id` 填进 `create_codex_worker.preflight_id`。contract 变了重跑,不能拿宿主 `check_acceptance` 冒充 worker 环境成功。
|
|
19
19
|
4. `create_codex_worker` 派出去。回执只有 `id`、`worktree_path`、`branch`、`owned_paths`、`status`,不回传任务原文。
|
|
20
20
|
5. 长任务配宿主 `/loop 5m check_workers` 定时收活,没变化 quiet,有新结果按 next_step 收。工具会按规则恢复一次,但不会唤醒关闭的主窗口;每个主线程设独立 `CODEX_SUPERVISOR_OBSERVER_ID` 可重启接回。短等用 `wait_codex_workers` 的 `timeoutMs: 60000`、`compact: true`,到点继续同批 task_ids。
|
|
21
21
|
|
|
@@ -24,7 +24,9 @@ worker 默认不是调度员:启动时会禁用它继承到的 `codex-supervis
|
|
|
24
24
|
| 参数 | 怎么填 |
|
|
25
25
|
|---|---|
|
|
26
26
|
| `task` | 这一路具体干什么。要能直接开工,别写"优化一下"。汇报格式 supervisor 已经附在 task 后面(结论 / 验证 / 没做的),别再要它列改动文件,diff 自己看 |
|
|
27
|
-
| `cwd` |
|
|
27
|
+
| `cwd` | Git 项目根,或非 Git 输入目录;实际执行目录由 `workspaceKind` 决定,不能默认写原目录 |
|
|
28
|
+
| `workspaceKind` | Git 代码默认 `git_worktree`;非 Git 只读用 `read_only_in_place`,联网研究用 `scratch`,要改用户非 Git 目录只能显式 `in_place_write` |
|
|
29
|
+
| `inPlaceAuthorization` | 仅 `in_place_write`:写明用户授权原因;同时必须有非空 `ownedPaths` 和 `acceptance`,系统记录前后 manifest |
|
|
28
30
|
| `acceptance` | 这一步"做完了"的判据,worker 退出后 supervisor 在它的 worktree 里逐条跑。写 worker 不能只用 `test -s/-f`、`[ -e ]` 这类文件存在性检查;要有真实 test、endpoint probe 或结构化执行证据。识别到的 test runner 输出 `no tests to run` / `[no test files]` 即使 exit 0 也失败。必跑用例、skip、旧报告和失败身份用 `{command,reportPath,baseline}` 结构化验收证明;远端机器的检查包进 `ssh` |
|
|
29
31
|
| `forbid` / `allowedCommands` | 原样声明红线与验证命令;守卫拒绝未声明Shell程序,编辑用apply_patch |
|
|
30
32
|
| `writableRoots` | 只有需要凭据目录时才传(绝对路径、已存在、自动解析软链、只对 workspace-write 生效):ssh/远程测试 → `["~/.ssh"]`;kubectl → `["~/.kube"]`;推私有镜像 → `["~/.docker"]`;aws cli → `["~/.aws"]`;签名提交 → `["~/.gnupg"]`。缓存目录不用写,已经自动加 |
|
|
@@ -56,13 +58,14 @@ worker不止改代码,按这路要什么选形状:
|
|
|
56
58
|
|
|
57
59
|
| 形状 | 参数 | 能干什么 |
|
|
58
60
|
|---|---|---|
|
|
59
|
-
| 编辑 worker | `ownedPaths`
|
|
60
|
-
| 只读验证 worker | `sandbox: "read-only"` + `ownedPaths: []` | 随便跑读命令(rg/cat/git/jq),**沙箱没有任何写入(连 /tmp 都不行)、也没有网络**;结论写在最终报告 |
|
|
61
|
-
| 研究/检索 worker | `sandbox: "workspace-write"` + `networkAccess: true` + `ownedPaths: []` | 能联网 curl/gh
|
|
61
|
+
| Git 编辑 worker | `workspaceKind: "git_worktree"` + `ownedPaths` 非空 | apply_patch 只能落在 ownedPaths,shell 只放声明过的命令和简单读取 |
|
|
62
|
+
| 只读验证 worker | `workspaceKind: "read_only_in_place"` + `sandbox: "read-only"` + `ownedPaths: []` | 随便跑读命令(rg/cat/git/jq),**沙箱没有任何写入(连 /tmp 都不行)、也没有网络**;结论写在最终报告 |
|
|
63
|
+
| 研究/检索 worker | `workspaceKind: "scratch"` + `sandbox: "workspace-write"` + `networkAccess: true` + `ownedPaths: []` | 能联网 curl/gh,只能往 supervisor 管理 scratch 写草稿;没有任何东西会 land,也不碰原始非 Git 目录 |
|
|
64
|
+
| 非 Git 写入 worker | `workspaceKind: "in_place_write"` + 授权 + `ownedPaths` + `acceptance` | 仅用户明确授权时使用;记录授权和前后 manifest,不能 land |
|
|
62
65
|
|
|
63
|
-
read-only 下 `networkAccess: true` 会被拒(实测该沙箱连 DNS
|
|
66
|
+
read-only 下 `networkAccess: true` 会被拒(实测该沙箱连 DNS 都不通,配了也没用);要联网就按 `scratch` 研究 worker 派。非 Git `workspace-write` 不写 `workspaceKind` 会拒绝,绝不偷偷落到用户目录。研究 worker 的 shell 不受 allowedCommands 限制,forbid 红线照旧。读共享文件永远不排他,只有写按 ownedPaths 排他。
|
|
64
67
|
|
|
65
|
-
check_workers可对已死的第1轮lost/no_work/invalid_report自动resume一次,recoveries记动作;invalid_report只让它重发裸JSON
|
|
68
|
+
check_workers可对已死的第1轮lost/no_work/invalid_report自动resume一次,recoveries记动作;invalid_report只让它重发裸JSON、不重做活,审批/认证/权限/quota不盲重试。连续两轮同 fingerprint 的无输出/无命令会变 `two_stall` + `needs_attention`,禁止再自动 resume;看 evidence 决定主线程接管、修工具或重派。最终报告强制JSON,structured_report仅验证格式;invalid_report拒land,resume让模型提交合法JSON,命令和acceptance另外核对。
|
|
66
69
|
|
|
67
70
|
未提交材料用context:[{path:绝对路径,sha256:可选}];首次记哈希,resume材料变了要显式换context。context/contracts总6000字、最多20份文件,每份≤5 MB;handoff1800字/16行可裁,完整约束和refs另传。输入路径不等于写授权。
|
|
68
71
|
|
|
@@ -93,7 +96,7 @@ Codex需0.162+支持hooks/output-schema,能力不够派单start_failed先修CL
|
|
|
93
96
|
|
|
94
97
|
一批活全部到终态后:`get_orchestration_overview` 确认没有 `needs_attention`、`acceptance_failed` 为空,再逐路走上面几步。合不合、怎么合由主线程定。
|
|
95
98
|
|
|
96
|
-
高风险的步(迁移、改公共接口、"做完了"
|
|
99
|
+
高风险的步(迁移、改公共接口、"做完了"写不成命令的)用 `create_independent_verifier(task_id)`:它建独立 thread、`read_only_in_place`、无网络、无原 report/candidate facts,只给目标和当前 worktree。verifier 结算后主线程调用 `record_independent_finding` 记 passes/fails/inconclusive,必要时 `resolve_independent_finding` 收口;两路说法对不上,两边都别信,自己看 diff。
|
|
97
100
|
|
|
98
101
|
|
|
99
102
|
## 收工口径:活儿必须落地
|
|
@@ -104,7 +107,7 @@ Codex需0.162+支持hooks/output-schema,能力不够派单start_failed先修CL
|
|
|
104
107
|
2. **主线程自己的改动必须 add + commit + push**:`git add <paths> && git commit -m ... && git push`。跳过任何一步都要显式说明,不允许说"改好了"然后留在工作区。
|
|
105
108
|
3. **上线前核对远端,不认本地**:部署或重启服务前先 `git fetch`,再确认目标提交里真有那些改动 —— `git log --oneline origin/<branch> -1`、`git ls-tree -r --name-only origin/<branch> | rg <新文件>`、必要时 `git show origin/<branch>:<path>`。线上报 `NoSuchBeanDefinition`、找不到类/模块、404,先查这一条,再查代码逻辑。
|
|
106
109
|
4. **交付报告三件套**:本地改动 → commit SHA → push 后的远端 SHA(以及部署状态)。缺远端 SHA 就不算完成。
|
|
107
|
-
5. **push 后计划清理**:`land_codex_worker` 只到本地集成;用户 push 后先 `verify_delivery_push`,它会生成 15 分钟有效的 `cleanup_plan
|
|
110
|
+
5. **push 后计划清理**:`land_codex_worker` 只到本地集成;用户 push 后先 `verify_delivery_push`,它会生成 15 分钟有效的 `cleanup_plan`。SAFE 必须是「acceptance 明确 passed + push_verified + worktree 干净 + 无活跃进程/依赖 + Git 注册/归属可证明」;主线程复核 item 后才 `apply_cleanup(plan_id,item_ids)`。apply 前会重验 fingerprint,并重新 fetch remote 确认 landed SHA 仍可达;只执行 `git worktree remove/prune`。**branch、task、event、JSONL、artifact 永远保留**。脏、未验收、未合、未 push、force-push 回退、lost、failed、证明不足一律不删。`check_workers` 只提醒,不执行删除。
|
|
108
111
|
|
|
109
112
|
`land_codex_worker` 只到本地集成 `landed`,不是远端交付。用户已经 push 后,主线程调 `verify_delivery_push({task_id,remote:"origin"})`,它只 fetch + 祖先校验、不替你 push/部署;通过才记 `push_verified`,后续才可进入安全 cleanup 候选。
|
|
110
113
|
|
|
@@ -117,7 +120,7 @@ Codex需0.162+支持hooks/output-schema,能力不够派单start_failed先修CL
|
|
|
117
120
|
|
|
118
121
|
| 想干什么 | 用哪个 |
|
|
119
122
|
|---|---|
|
|
120
|
-
| 主线程日常增量 | `overview_delta`,保存 `next_cursor
|
|
123
|
+
| 主线程日常增量 | `overview_delta`,保存 `next_cursor`;只看计数、变化 task 摘要、短版阻塞原因和下一步 |
|
|
121
124
|
| 全部 worker 的状态 | `get_orchestration_overview`,只在需要全量状态时用 |
|
|
122
125
|
| 一路的完整结论 | `get_worker_result` |
|
|
123
126
|
| 一路改了什么 | `get_worker_diff`;只要文件名用 `get_worker_result` 带 `includeFiles: true` |
|
|
@@ -127,10 +130,14 @@ Codex需0.162+支持hooks/output-schema,能力不够派单start_failed先修CL
|
|
|
127
130
|
| 验收过没过 | 每个读都带 `acceptance`;命令和每条的输出在 `get_worker_result.acceptance.checks` |
|
|
128
131
|
| worker 吃了哪些上下文 | `get_context_snapshot_meta`,只看 fact IDs/token/排除项,不会回 capsule 正文 |
|
|
129
132
|
| 一条共享事实的来源 | `get_fact`,按 ID 精确读;不要把一批 facts 全拉进主线程 |
|
|
133
|
+
| 找当前任务的已验证事实 | `search_worker_facts`,传 task_id/query/cursor;只回 scope 内 verified summary + coverage,绝不拉 raw history |
|
|
134
|
+
| 找某路的证据索引 | `get_worker_evidence`,再按需 `get_artifact` 或 `get_codex_worker_events` |
|
|
135
|
+
| 主线程确认候选事实 | `promote_worker_fact`;只有主线程审过才会追加 verified,repo scope 必须给 watchedPaths |
|
|
136
|
+
| 主线程推翻事实 | `revoke_worker_fact`;写明 reason,撤销后不会进入 search 或后续 capsule |
|
|
130
137
|
|
|
131
138
|
默认读回来的长文本都是裁过的(`current_action` 300 字、`prompt` 300 字、`last_message` 400 字),别把裁剪当成活没干。全量在库里。别一次 `limit: 200` 拉全量事件。
|
|
132
139
|
|
|
133
|
-
worker 的 capsule 只在内部 create/resume 时生成:自身 L0 身份、当前 work 的 verified facts、显式 `dependsOn`
|
|
140
|
+
worker 的 capsule 只在内部 create/resume 时生成:自身 L0 身份、当前 work 的 verified facts、显式 `dependsOn` 的最小交付摘要、路径命中且 SHA 有效的 repo facts。`session_id` peers、raw event、完整 diff/报告、candidate facts 一律不自动注入。base SHA 不再覆盖、watched path 有 Git diff、或 in_place_write 的 manifest 漂移时,旧 fact 自动 expired 并排除。主线程只能看 snapshot 元数据;要查事实用 `search_worker_facts` / `get_fact`,查证据用 `get_worker_evidence` / `get_artifact`,不能把自己变成 worker。
|
|
134
141
|
|
|
135
142
|
worker 最终 JSON 只是 `candidate`:先留在本 run 做审计,绝不因为它自己说“完成”就变共享事实。supervisor acceptance 通过才会派生当前 work 的 `verified` outcome;验收失败/未配置、脏 diff、未 land/push 都不是 verified 交付证据。
|
|
136
143
|
|
|
@@ -152,13 +159,13 @@ overview、派单回执、`wait` 返回里出现 `update` 且 `update_available:
|
|
|
152
159
|
|
|
153
160
|
## 常见坑
|
|
154
161
|
|
|
155
|
-
- worktree 从一个提交切,你工作区里没 commit 的东西 worker 看不到。要让它读到就给绝对路径或先 commit
|
|
162
|
+
- worktree 从一个提交切,你工作区里没 commit 的东西 worker 看不到。要让它读到就给绝对路径或先 commit;Git worktree 建不出来会明确拒绝,不会退回主目录执行。
|
|
156
163
|
- `exit_code: 0` 只说明没崩。`acceptance` 是 supervisor 替你跑的验收,`verification` 是它自己跑过的,两个都没有就只剩 diff。验收命令别往 worktree 写文件,会混进它的改动。
|
|
157
164
|
- `ownedPaths` 在跨MCP派单/恢复时原子预留,验收和退出结算前仍占用;Git隔离创建失败不退回主目录。land 按真实 diff 拒越界(提交草稿前就查)。仍不等于运行时沙箱,收活看 diff;`allowOutsideOwned` 只用于用户明确批准的例外。
|
|
158
165
|
- worktree 只隔离工作区,端口和数据库是共用的。
|
|
159
166
|
- `resume_codex_worker` 不会再建 goal。`cancel_codex_worker` 跨进程靠 pid,要求那个 pid 的命令行里带 `codex`。
|
|
160
167
|
|
|
161
|
-
收尾先 `cleanup_plan` 看 SAFE / REVIEW / BLOCKED;只有 push_verified
|
|
168
|
+
收尾先 `cleanup_plan` 看 SAFE / REVIEW / BLOCKED;只有 acceptance passed、push_verified、干净、无活跃进程/依赖且 fingerprint 未变化的 SAFE item 才可 `apply_cleanup`。CLI 先 `npm run cleanup -- --dry-run`,再显式 `npm run cleanup -- --apply --plan <plan_id> --item <item_id>`;`--apply` 不带计划和 item 会拒绝。apply 会再 fetch remote 验 landed SHA,branch、task、event、JSONL、artifact 保留;脏、未验收、未合、未 push、force-push 回退、lost/failed和证明不了的一律不删。
|
|
162
169
|
|
|
163
170
|
## 看板
|
|
164
171
|
|
package/src/cleanup-hint.js
CHANGED
|
@@ -22,8 +22,9 @@ export async function cleanupHint({ list = readdir, root = supervisorRoot, dir =
|
|
|
22
22
|
worktrees: entries,
|
|
23
23
|
threshold,
|
|
24
24
|
command: `SUPERVISOR_HOME=${root} npm run cleanup -- --dry-run`,
|
|
25
|
-
apply:
|
|
26
|
-
|
|
25
|
+
apply: null,
|
|
26
|
+
next_step: "Review the dry-run plan_id and a SAFE item id, then call apply_cleanup; CLI apply also requires --plan and --item.",
|
|
27
|
+
note: "only acceptance-passed, push-verified, clean worktrees without active processes or dependents become SAFE; apply retains branches and evidence"
|
|
27
28
|
};
|
|
28
29
|
}
|
|
29
30
|
|
package/src/cleanup-plan.js
CHANGED
|
@@ -4,7 +4,7 @@ import { execFileSync } from "node:child_process";
|
|
|
4
4
|
import { isAbsolute, relative, resolve } from "node:path";
|
|
5
5
|
import { ACTIVE_STATUSES } from "./status.js";
|
|
6
6
|
import { worktreesDir } from "./paths.js";
|
|
7
|
-
import { readTasks } from "./task-store.js";
|
|
7
|
+
import { appendTaskEvent, getTask, isPidAlive, markCleanupPlanItemApplied, readTasks, updateWorkItemDelivery, runIdFor } from "./task-store.js";
|
|
8
8
|
|
|
9
9
|
export const CLEANUP_PLAN_TTL_MS = 15 * 60 * 1000;
|
|
10
10
|
|
|
@@ -30,13 +30,40 @@ async function directoryBytes(path) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
function remoteProof(task, { fetch = false } = {}) {
|
|
34
|
+
if (!task.push_remote || !task.push_branch || !task.push_remote_head) {
|
|
35
|
+
return { error: "remote delivery proof is incomplete; rerun verify_delivery_push" };
|
|
36
|
+
}
|
|
37
|
+
let remoteHead = task.push_remote_head;
|
|
38
|
+
if (fetch) {
|
|
39
|
+
try {
|
|
40
|
+
git(task.project_root, ["remote", "get-url", task.push_remote]);
|
|
41
|
+
git(task.project_root, ["fetch", "--no-tags", task.push_remote, `refs/heads/${task.push_branch}`]);
|
|
42
|
+
remoteHead = git(task.project_root, ["rev-parse", "FETCH_HEAD"]);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
return { error: `remote delivery proof could not be refreshed: ${error.message.split("\n")[0]}` };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
git(task.project_root, ["merge-base", "--is-ancestor", task.landed_head, remoteHead]);
|
|
49
|
+
} catch {
|
|
50
|
+
return { error: "landed head is no longer reachable from the remote branch" };
|
|
51
|
+
}
|
|
52
|
+
return { remoteHead };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function taskVerdict(task, tasks, { revalidateRemote = false } = {}) {
|
|
34
56
|
if (task.status !== "completed") return { verdict: "blocked", reasons: ["worker is unfinished, failed, cancelled or lost"] };
|
|
35
|
-
if (task.acceptance_results
|
|
57
|
+
if (task.acceptance_results?.passed !== true) return { verdict: "blocked", reasons: ["acceptance is not explicitly passed"] };
|
|
58
|
+
if (task.pid && isPidAlive(task.pid)) return { verdict: "blocked", reasons: ["worker process is still active"] };
|
|
59
|
+
if (task.run_host_pid && isPidAlive(task.run_host_pid)) return { verdict: "blocked", reasons: ["run host process is still active"] };
|
|
60
|
+
if (task.acceptance_results?.status === "running" || (task.acceptance_results?.supervisor_pid && isPidAlive(task.acceptance_results.supervisor_pid))) return { verdict: "blocked", reasons: ["acceptance process is still active"] };
|
|
36
61
|
if (tasks.some((other) => ACTIVE_STATUSES.has(other.status) && (other.depends_on ?? []).includes(task.id))) return { verdict: "blocked", reasons: ["an active dependent still needs this work"] };
|
|
37
62
|
if (!task.worktree_path || !task.project_root) return { verdict: "review", reasons: ["no registered isolated worktree"] };
|
|
38
63
|
if (!task.landed_at || !task.landed_head) return { verdict: "blocked", reasons: ["work has not been landed"] };
|
|
39
64
|
if (!task.push_verified_at) return { verdict: "blocked", reasons: ["remote delivery has not been verified"] };
|
|
65
|
+
const delivery = remoteProof(task, { fetch: revalidateRemote });
|
|
66
|
+
if (delivery.error) return { verdict: "blocked", reasons: [delivery.error] };
|
|
40
67
|
try {
|
|
41
68
|
const path = resolve(task.worktree_path);
|
|
42
69
|
if (path !== resolve(worktreesDir, task.id)) return { verdict: "review", reasons: ["worktree is outside its managed task directory"] };
|
|
@@ -56,19 +83,19 @@ async function taskVerdict(task, tasks) {
|
|
|
56
83
|
return {
|
|
57
84
|
verdict: "safe",
|
|
58
85
|
reasons: ["acceptance passed", "landed", "remote delivery verified", "worktree clean", "no active dependent"],
|
|
59
|
-
fingerprint: hash(JSON.stringify({ path, branch, head: git(path, ["rev-parse", "HEAD"]), landed: task.landed_head, push: task.
|
|
86
|
+
fingerprint: hash(JSON.stringify({ path, branch, head: git(path, ["rev-parse", "HEAD"]), landed: task.landed_head, push: { remote: task.push_remote, branch: task.push_branch, head: delivery.remoteHead } }))
|
|
60
87
|
};
|
|
61
88
|
} catch (error) {
|
|
62
89
|
return { verdict: "review", reasons: [`cleanup proof failed: ${error.message.split("\n")[0]}`] };
|
|
63
90
|
}
|
|
64
91
|
}
|
|
65
92
|
|
|
66
|
-
export async function createCleanupPlan({ taskIds = null, projectRoot = null, now = Date.now() } = {}) {
|
|
93
|
+
export async function createCleanupPlan({ taskIds = null, projectRoot = null, now = Date.now(), revalidateRemote = true } = {}) {
|
|
67
94
|
const tasks = await readTasks();
|
|
68
95
|
const selected = tasks.filter((task) => (!taskIds || taskIds.includes(task.id)) && (!projectRoot || resolve(task.project_root) === resolve(projectRoot)));
|
|
69
96
|
const items = [];
|
|
70
97
|
for (const task of selected) {
|
|
71
|
-
const result = await taskVerdict(task, tasks);
|
|
98
|
+
const result = await taskVerdict(task, tasks, { revalidateRemote });
|
|
72
99
|
const bytes = result.verdict === "safe" ? await directoryBytes(task.worktree_path) : 0;
|
|
73
100
|
items.push({ task_id: task.id, verdict: result.verdict, reasons: result.reasons, fingerprint: result.fingerprint ?? null, reclaimable_bytes: bytes, eligible_after: result.verdict === "safe" ? new Date(now).toISOString() : null });
|
|
74
101
|
}
|
|
@@ -90,9 +117,42 @@ export async function createCleanupPlan({ taskIds = null, projectRoot = null, no
|
|
|
90
117
|
}
|
|
91
118
|
|
|
92
119
|
export async function removePlannedWorktree(task, fingerprint) {
|
|
93
|
-
const result = await taskVerdict(task, await readTasks());
|
|
120
|
+
const result = await taskVerdict(task, await readTasks(), { revalidateRemote: true });
|
|
94
121
|
if (result.verdict !== "safe") throw new Error(`worktree is no longer safe: ${result.reasons.join("; ")}`);
|
|
95
122
|
if (result.fingerprint !== fingerprint) throw new Error("worktree changed since cleanup plan; create a new plan");
|
|
96
123
|
git(task.project_root, ["worktree", "remove", task.worktree_path]);
|
|
97
124
|
try { git(task.project_root, ["worktree", "prune"]); } catch { /* best effort */ }
|
|
98
125
|
}
|
|
126
|
+
|
|
127
|
+
export async function applyCleanupPlan({ plan, itemIds, actor = "main_thread" }) {
|
|
128
|
+
if (Date.parse(plan.expires_at) <= Date.now()) {
|
|
129
|
+
return { error: "cleanup_plan_expired", plan_id: plan.id, expires_at: plan.expires_at };
|
|
130
|
+
}
|
|
131
|
+
const selected = plan.items.filter((item) => itemIds.includes(item.id));
|
|
132
|
+
if (selected.length !== itemIds.length) return { error: "cleanup_plan_item_not_found", plan_id: plan.id };
|
|
133
|
+
const applied = [];
|
|
134
|
+
const skipped = [];
|
|
135
|
+
for (const item of selected) {
|
|
136
|
+
if (item.verdict !== "safe") {
|
|
137
|
+
skipped.push({ item_id: item.id, task_id: item.task_id, reason: "only SAFE plan items may be applied" });
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const task = await getTask(item.task_id);
|
|
141
|
+
if (!task) {
|
|
142
|
+
skipped.push({ item_id: item.id, task_id: item.task_id, reason: "task no longer exists" });
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
await removePlannedWorktree(task, item.fingerprint);
|
|
147
|
+
const now = await markCleanupPlanItemApplied(item.id, actor);
|
|
148
|
+
await updateWorkItemDelivery(task.id, "cleanup_removed");
|
|
149
|
+
await appendTaskEvent(task.id, { type: "supervisor.cleanup_removed", plan_id: plan.id, item_id: item.id, removed_at: now, retained: ["branch", "task", "events", "jsonl", "artifacts"] }, {
|
|
150
|
+
runId: runIdFor(task.id, task.run_count ?? 1), actor
|
|
151
|
+
});
|
|
152
|
+
applied.push({ item_id: item.id, task_id: task.id, worktree_path: task.worktree_path, removed_at: now });
|
|
153
|
+
} catch (error) {
|
|
154
|
+
skipped.push({ item_id: item.id, task_id: item.task_id, reason: error.message.split("\n")[0] });
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return { plan_id: plan.id, applied, skipped, retained: ["branch", "task", "events", "jsonl", "artifacts"] };
|
|
158
|
+
}
|