codex-supervisor-mcp 0.12.2 → 0.13.1

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 CHANGED
@@ -64,12 +64,15 @@ Say it in plain words in Claude Code; the skill makes it follow the right steps:
64
64
  What the main thread does underneath (you can call the tools yourself):
65
65
 
66
66
  ```
67
- create_codex_worker ×3 each with session_id, session_title, ownedPaths, goal
67
+ preflight_codex_worker run required probes with the target workspace/base/sandbox/guard
68
+ get_worker_preflight require passed; rerun when the contract changes
69
+ create_codex_worker ×3 each with preflight_id, session_id, ownedPaths, goal
68
70
  wait_codex_workers 60 seconds by default, then a snapshot, call again until done
69
71
  get_worker_result ×3 each worker's report, with the commands it really ran
72
+ get_worker_diff ×3 inspect the real change before deciding to land
70
73
  ```
71
74
 
72
- Each worker's changes sit on its own `codex/<taskId>` branch; whether and how to merge is the main thread's call.
75
+ Each worker's changes sit on its own `codex/<taskId>` branch. After acceptance and diff review, the main thread lands them with `land_codex_worker` and `commitMessage`; the worker does not commit.
73
76
 
74
77
  ### 3. Open the board
75
78
 
@@ -90,7 +93,7 @@ Anything that speaks MCP can be the main thread; this is just my way. I run two
90
93
  | Me | | Decide what to build, make the calls, read the reports |
91
94
  | Planning session | The requirements and docs repository | Talk through the requirement, write the design, write one brief per block of work with a paragraph for the main brain at the end |
92
95
  | Main-brain session | A worktree of the code repository | Read the brief, dispatch Codex workers, check every worker's diff, write results back into the brief, report to me. Writes no business code |
93
- | Codex workers | Their own worktrees | One worker per step, one commit per step, build and verify on a remote machine. No push, no merge |
96
+ | Codex workers | Their own worktrees | One worker per independently verifiable feature package. It edits and runs acceptance. It does not commit, push or merge |
94
97
 
95
98
  One block of text passes between the two sessions, pasted into the main-brain session and handed over with `/goal`. Its shape is fixed:
96
99
 
@@ -100,12 +103,14 @@ One block of text passes between the two sessions, pasted into the main-brain se
100
103
  [Background] Why this block exists, what the previous one left behind
101
104
  [Read first] Which sections of which documents. Which one wins when they disagree
102
105
  [Repos] Where the worktrees are, which commit each branch is on, which branches are read-only
103
- [Do] Follow the table in section N of the brief. One commit per step; verify a step before starting the next. Nothing outside the table
106
+ [Do] Follow the table in section N of the brief. Split by independently verifiable feature packages. Nothing outside the table. Workers do not commit
104
107
  [Dispatch] search_works first, do not dispatch twice
105
108
  One session_id for the whole batch
106
- Serial when steps touch the same files, parallel only when ownedPaths do not overlap
107
- One worker per step. Write the task in full: background, where in the docs, files to change, verify command, output format
108
- Put the verify command in acceptance too; the supervisor runs it, the worker's word does not count
109
+ Serial when writes overlap, parallel only with disjoint write sets
110
+ ownedPaths covers implementation, tests, routing, DI, configuration and migrations
111
+ Prepare dependencies with workspaceSetup; every writer passes preflight with the same contract
112
+ Write the task in full: background, where in the docs, complete write set, verify command, output format
113
+ Put the verify command in acceptance too; the worker self-checks through CODEX_SUPERVISOR_ACCEPTANCE_CLI
109
114
  Read the diff when a worker returns. Its word is not enough; what you see is
110
115
  [Build/test] Everything on the remote machine, nothing locally
111
116
  [Red lines] What not to change, push or read
@@ -117,18 +122,16 @@ What the main brain calls in one round:
117
122
 
118
123
  ```
119
124
  search_works has this batch been dispatched before
120
- create_codex_worker one worker per step, same session_id, ownedPaths disjoint
125
+ create_codex_worker one worker per feature package, same session_id, ownedPaths disjoint
121
126
  wait_codex_workers 60 seconds a round, compact: true, call again until done
122
127
  get_worker_result what it says it did; verification is what it really ran
123
128
  get_worker_diff what it actually did
124
129
  ask_codex_worker when the two differ, ask why; read-only, its thread untouched
125
- resume_codex_worker when it must change something, one follow-up, amended into the same commit; rebaseOnto when main has moved
126
- land_codex_worker checked, then landed on the integration branch
130
+ resume_codex_worker continue the same thread when it must change something; rebaseOnto when main has moved
131
+ land_codex_worker reviewed; commit with commitMessage and land on the integration branch
127
132
  ```
128
133
 
129
- The last block was 25 steps. One main-brain session watched all 25, with nothing in its context but the brief and each worker's report; the workers' output never reached it.
130
-
131
- Why one worker does one step: when step 5 is wrong, the worker that did step 5 gets one `resume_codex_worker`, amends its own commit, the main brain checks again, and only then lands it. A worker that did steps 5, 6 and 7 cannot be fixed that way: 6 and 7 already sit on top of 5, so fixing 5 means redoing them too.
134
+ A feature package can still be resumed before landing. Split it when writes conflict, dependencies need sequencing, or the work has separate acceptance, not because every step needs a new model thread.
132
135
 
133
136
  ## What the board shows
134
137
 
@@ -148,20 +151,20 @@ Thirty-nine.
148
151
 
149
152
  | Tool | Arguments | What it does |
150
153
  |---|---|---|
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 |
154
+ | `check_workers` | none | Report newly settled runs and actionable changes; recover a new-format first `lost`, `no_work` or `invalid_report` 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
155
  | `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 |
153
156
  | `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 |
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 |
157
+ | `preflight_codex_worker` | `cwd`, `workspaceKind`, `inPlaceAuthorization`, `workspaceSetup`, `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
158
  | `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. |
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 |
159
+ | `create_codex_worker` | `task`, `cwd`, `workspaceKind`, `inPlaceAuthorization`, `workspaceSetup`, **`ownedPaths`**, **`goal`**, `preflight_id`, `forbid`, `allowedCommands`, `context`, `contracts`, `externalOutputs`, `networkAccess`, `writableRoots`, `maxRunMs`, `maxTotalMs`, `acceptance`, `acceptanceTimeoutMs`, `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. `workspaceSetup` prepares dependencies before the worker starts; when `preflight_id` is present its complete runtime contract must match. |
160
+ | `create_codex_followup_worker` | `task_id`, `followup_prompt`, `session_id`, `session_title`, `title`, `cwd`, `sandbox`, `model`, `ownedPaths`, `forbid`, `allowedCommands`, `context`, `contracts`, `externalOutputs`, `networkAccess`, `writableRoots`, `workspaceKind`, `workspaceSetup`, `goal`, `baseRef`, `acceptance` | A new session seeded with the old worker's prompt, status and recent events. It does not accept `preflight_id`, `dependsOn` or `skipGitRepoCheck`. |
158
161
  | `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 |
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 |
162
+ | `wait_codex_workers` | `task_ids`, `mode` (any/all), `timeoutMinutes`, `timeoutMs`, `pollMs`, `compact`, `emitProgress`, `includeEvents`, `eventLimit`, `eventMaxChars`, `eventKinds` | Wait for terminal states. 60 seconds by default. `termination_reason` distinguishes settled, exhausted budget and client cancellation. `emitProgress: true` emits progress every 30 seconds when the client supplies a progress token. `compact` returns one row per worker |
160
163
  | `get_orchestration_overview` | `status`, `limit` | Every worker in one table, capped at 7000 bytes. Carries `version` and `update` |
161
164
  | `get_worker_result` | `task_id`, `limit`, `maxChars`, `includeFiles` | The worker's own report, clipped past 6000 bytes with `truncated` and the size to ask for. `acceptance` is whether the supervisor's own checks passed, `verification` the commands the worker ran with exit codes, `base_behind` how far main has moved (`behind` is `null` with a note when `contains_base` is false, meaning the directory switched lines) |
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 |
165
+ | `get_worker_diff` | `task_id`, `file`, `hunk`, `pageSize`, `cursor`, `maxChars`, `paths` | What the worker actually changed. The default response is a complete file/hunk index. Select one file and page hunks with `hunk` or `cursor`; `maxChars` without `file` keeps the legacy bounded full-diff mode |
163
166
  | `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 |
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 |
167
+ | `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. A malformed report summary no longer blocks an explicit landing when acceptance and the reviewed diff are sound. `commitMessage` first commits its uncommitted edits as one commit; `ignoreAcceptance` lands anyway |
165
168
  | `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
169
  | `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
170
  | `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 |
@@ -188,9 +191,27 @@ Thirty-nine.
188
191
  | `check_for_update` | `force` | Ask the registry for a newer version |
189
192
  | `cancel_codex_worker` | `task_id` | Stop a worker. Falls back to the pid across processes, after confirming that pid runs codex |
190
193
 
191
- Two are required: `ownedPaths` (checked against every running worker before dispatch, overlap refuses the call, dispatch-time only) and `goal.objective` (the worker turns it into a native Codex goal). Without `session_id` nothing groups the batch; use one value for the whole batch.
194
+ Two fields are required by the MCP schema: `ownedPaths` and `goal.objective`. A writer must also pass the workflow preflight gate described above; the schema keeps `preflight_id` optional for old clients, which is a compatibility escape hatch, not the normal path. `ownedPaths` overlap is reserved at dispatch, the runtime guard checks direct file writes, and landing checks the complete diff.
195
+
196
+ `acceptance` runs in Bash with `errexit` and `pipefail`: an unhandled failure stops the check, including a failing test in `npm test | tail`. Workers run `node "$CODEX_SUPERVISOR_ACCEPTANCE_CLI"` for the exact supervisor contract instead of retyping checks in an interactive zsh. Handle expected failures explicitly with `if` or `||`; a timeout always fails, even when the command exits 0 after termination. Windows requires Git for Windows Bash and reports an error when it is missing. Displayed output is clipped without changing the exit code.
197
+
198
+ In a repository with `package.json`, acceptance that uses local JavaScript tooling such as `npm`, `pnpm`, `vitest`, `vue-tsc`, `eslint` or `nuxi` is rejected with `workspace_setup_required` unless `workspaceSetup` was provided. Dependency preparation is now a runtime gate, not a reminder for the model.
199
+
200
+ The standard frontend worktree setup is:
201
+
202
+ ```json
203
+ {
204
+ "workspaceSetup": {
205
+ "links": [{ "path": "node_modules", "source": "node_modules" }],
206
+ "submodules": true,
207
+ "commands": ["npx nuxi prepare"]
208
+ }
209
+ }
210
+ ```
211
+
212
+ Pass the same setup to `preflight_codex_worker` and the target `create_codex_worker`; otherwise the runtime contracts do not match.
192
213
 
193
- `acceptance` runs in Bash with `errexit` and `pipefail`: an unhandled failure stops the check, including a failing test in `npm test | tail`. Handle expected failures explicitly with `if` or `||`; a timeout always fails, even when the command exits 0 after termination. Windows requires Git for Windows Bash and reports an error when it is missing. Displayed output is clipped without changing the exit code.
214
+ When dispatch omits `goal.tokenBudget`, the worker must omit `token_budget` entirely. The runtime guard rejects `0`, `1`, `null` and any invented value. If a budget is supplied explicitly, the worker must use that exact positive integer.
194
215
 
195
216
  Acceptance commands receive `CODEX_SUPERVISOR_TASK_ID`, `CODEX_SUPERVISOR_BASE_COMMIT` and `CODEX_SUPERVISOR_RUN`: the current task, run base and run number, refreshed after rebase/resume.
196
217
 
@@ -204,13 +225,15 @@ Wait defaults to 60 seconds and compact rows; includeEvents selects details unle
204
225
 
205
226
  Each run injects the shipped PreToolUse guard: apply_patch checks every target including renames and symlinks; forbid rejects red lines. Shell allows simple reads and explicitly declared allowedCommands/acceptance. Declared validation scripts run with dispatcher privileges and may have side effects; this is not a filesystem sandbox for arbitrary programs. Resume/follow-up inherit the policy without changing global hooks. Empty write runs use current output and command evidence and surface no_work; read-only tasks are not empty merely for having no diff.
206
227
 
228
+ Workers are not dispatchers. A worker starts with the codex-supervisor MCP server disabled, so it cannot dispatch, resume, cancel or edit another session. Business MCP servers remain available. Side-chat forks disable every MCP server.
229
+
207
230
  A model with no separate `apply_patch` tool (measured with Codex 0.162 + DeepSeek/cc-switch) sends the patch as a shell call: `apply_patch <<'EOF' ... EOF`. The guard accepts that shape and judges every target path with the same ownedPaths rule, so such a model can still edit; an unquoted heredoc, or one followed by `&&`/`;`, is refused.
208
231
 
209
232
  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.
210
233
 
211
234
  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 worker capsule names its branch and acceptance source without embedding acceptance commands. Repository facts cross checkouts only when canonical `origin`, repository-relative watched paths and base SHA all match; an unrecognized origin leaves them work-scoped. A fact is append-only expired and excluded from a future worker capsule when its base SHA no longer covers the task, a watched path changed, its declared context content hash changed, or its in-place manifest drifted; explicit dependencies provide only delivery summaries.
212
235
 
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.
236
+ 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. Parsing safely normalizes a single string field into string[] and one missing closing `]`/`}`; fabricated shapes still fail. The report is a summary: invalid_report preserves the completed lifecycle and attention, does not override the same run's acceptance or reviewed diff, and an explicit landing remains possible. Existing history is labelled legacy_text.
214
237
 
215
238
  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.
216
239
 
@@ -281,6 +304,7 @@ A terminal state lands in two steps: `turn.completed` sets `completed`, the proc
281
304
  | `CODEX_SUPERVISOR_SKIP_SKILL_SYNC` | unset | `1` turns the skill sync at server start off |
282
305
  | `CODEX_SUPERVISOR_SKIP_SETUP` | unset | `1` skips the `postinstall` setup |
283
306
  | `CODEX_SUPERVISOR_NPM` | unset | npm for the auto-update; default is the one shipped with the running node |
307
+ | `CODEX_SUPERVISOR_HANDOFF_TOKEN_THRESHOLD` | `300000` | Native-goal token count that marks a worker `handoff_recommended`; `0` disables the warning |
284
308
 
285
309
  GUI clients (Claude Desktop, Cursor, Windsurf) are not automatic registration targets of this installer: add this to their MCP config file, and since their `PATH` often lacks `codex`, give `CODEX_BIN` explicitly:
286
310
 
@@ -326,7 +350,7 @@ rm -rf ~/.claude/skills/codex-supervisor ~/.agents/skills/codex-supervisor ~/.co
326
350
  | Worker `failed` at once with `spawn codex ENOENT` | No codex on the process `PATH` | Set `CODEX_BIN` in the config |
327
351
  | `Cannot find module 'node:sqlite'` | Node older than 22.13.0 | Upgrade Node |
328
352
  | Worker `lost` | The worker or independent run process was interrupted | Inspect events, then `resume_codex_worker` |
329
- | Worker reports `git add` failing with `index.lock: Operation not permitted` | The default sandbox keeps `.git` read-only | `land_codex_worker` with `commitMessage`, or dispatch with `danger-full-access` |
353
+ | Worker reports `git add` failing with `index.lock: Operation not permitted` | The default sandbox keeps `.git` read-only; this is the intended boundary | Keep the worker to edits and acceptance, then use `land_codex_worker` with `commitMessage` |
330
354
  | `ownedPaths overlap with active worker(s)` | Two workers claimed the same paths | Split differently, or cancel the one holding them |
331
355
  | The board is empty | The board and the MCP use different `SUPERVISOR_HOME`s | Start it inside the project with the `.mcp.json`, or pass the same `SUPERVISOR_HOME` |
332
356
  | `port 7877 ... is already in use` | A board is already running | Open it, or start another with `SUPERVISOR_WEB_PORT=8080` |
@@ -334,10 +358,10 @@ rm -rf ~/.claude/skills/codex-supervisor ~/.agents/skills/codex-supervisor ~/.co
334
358
  ## Known limitations
335
359
 
336
360
  - Each run has an independent process that drains worker output, records its exit, and runs acceptance before exiting. These continue after the dispatching MCP is killed; a new window uses `get_session_works` to collect results. If the run process is also killed, inspect lost/interrupted evidence before resuming the preserved worktree and thread_id.
337
- - In the default `workspace-write` sandbox a worker cannot commit (Codex keeps `.git` read-only). Either `land_codex_worker` with `commitMessage` commits for it, or dispatch with `danger-full-access`.
361
+ - In the default `workspace-write` sandbox a worker cannot commit (Codex keeps `.git` read-only). Use `land_codex_worker` with `commitMessage`; do not switch to `danger-full-access` just to commit.
338
362
  - The worktree is cut from a commit; uncommitted work in your checkout is not in it.
339
363
  - Only the working directory is isolated. Temp directories, databases and ports are shared.
340
- - `ownedPaths` is checked at dispatch only; it does not stop a worker from creating files outside its list. Read the diff.
364
+ - `ownedPaths` overlap is reserved at dispatch. The runtime guard checks direct file edits and landing checks the complete diff. Declared scripts can still produce side effects outside the list, so this is not a complete filesystem sandbox.
341
365
  - Acceptance checks exactly what `acceptance` says. Anything not written there is not checked; `verification` is only what the worker ran itself, and the rest is the main thread reading the diff.
342
366
  - One `wait_codex_workers` cannot wait to the end; the client's MCP tool timeout is a hard wall. Call it again.
343
367
  - `search_works` is substring matching, fine for hundreds of works.
package/README.md CHANGED
@@ -65,12 +65,15 @@ codex mcp add codex-supervisor -- npx -y codex-supervisor-mcp
65
65
  主线程背后做的事(你也可以自己调工具):
66
66
 
67
67
  ```
68
- create_codex_worker ×3 每路带 session_id、session_title、ownedPaths、goal
68
+ preflight_codex_worker 同 workspace/base/sandbox/guard 先跑必要 probe
69
+ get_worker_preflight 确认 passed;contract 变化就重跑
70
+ create_codex_worker ×3 每路带 preflight_id、session_id、ownedPaths、goal
69
71
  wait_codex_workers 默认等 60 秒,到点返回快照,没完就接着等
70
72
  get_worker_result ×3 收每路的汇报,带它真跑过的命令和退出码
73
+ get_worker_diff ×3 看实际改动;证据对得上再决定是否 land
71
74
  ```
72
75
 
73
- 每路的改动在各自的 `codex/<taskId>` 分支上,合不合、怎么合由主线程定。
76
+ 每路的改动在各自的 `codex/<taskId>` 分支上。验收和 diff 都过了,主线程用 `land_codex_worker` 带 `commitMessage` 合入;worker 不自行提交。
74
77
 
75
78
  ### 3. 开看板
76
79
 
@@ -99,7 +102,7 @@ node "$CODEX_SUPERVISOR_STAGE_CLI" "gate:s3" --detail "integration queue"
99
102
  | 我 | | 定需求,拍板,看汇报 |
100
103
  | 规划会话 | 需求和文档仓 | 聊需求,写详设,每一块活写一份任务书,末尾附一段发给主脑的话 |
101
104
  | 主脑会话 | 代码仓的一个 worktree | 读任务书,派 Codex worker,核每路的 diff,把结果填回任务书,向我汇报。不写业务代码 |
102
- | Codex worker | 各自的 worktree | 一个 worker 做一步,一个提交,在远端机器上编译和验证。不 push,不合并 |
105
+ | Codex worker | 各自的 worktree | 一个 worker 做一个能独立验收的功能包,在远端机器上修改、运行验收。不 commit、不 push、不合并 |
103
106
 
104
107
  两个会话之间只传一段文字,粘进主脑会话用 `/goal` 接上。结构固定:
105
108
 
@@ -109,12 +112,13 @@ node "$CODEX_SUPERVISOR_STAGE_CLI" "gate:s3" --detail "integration queue"
109
112
  【背景】 这一块为什么做,上一块留下了什么
110
113
  【先读】 哪几份文档的哪几节。几份说法不一样时以哪份为准
111
114
  【仓和分支】工作目录在哪,各分支现在在哪个提交,哪些分支只读
112
- 【做什么】 照任务书第几节那张表做。一步一个提交,这步验证过了才做下一步。表里没有的不做
115
+ 【做什么】 照任务书第几节那张表做。按能独立验收的功能包拆,表里没有的不做。worker 不自行 commit
113
116
  【派活】 先 search_works 看有没有派过,别重复
114
117
  整批用同一个 session_id
115
- 改同一批文件就串行,文件完全不重叠才并行,每路 ownedPaths 写清
116
- 一个 worker 只做一步。task 写全:背景、文档出处、要改的文件、验证命令、输出格式
117
- 验证命令同时填 acceptance,supervisor 替你跑,它说过了不算
118
+ 改同一批文件就串行,写入范围不重叠才并行。ownedPaths 覆盖实现、测试、路由、DI、配置和迁移
119
+ 依赖先写 workspaceSetup;写 worker 先过同 contract 的 preflight
120
+ task 写全:背景、文档出处、完整写集、验证命令、输出格式
121
+ 验证命令同时填 acceptance;worker 用 CODEX_SUPERVISOR_ACCEPTANCE_CLI 自查
118
122
  worker 交回来先看 diff。它说过了不算,你看到才算
119
123
  【构建和测试】全走远端机器,本机不跑
120
124
  【红线】 不改什么,不推什么,不读什么
@@ -128,18 +132,16 @@ node "$CODEX_SUPERVISOR_STAGE_CLI" "gate:s3" --detail "integration queue"
128
132
  search_works 查这批活派过没有
129
133
  preflight_codex_worker 同环境跑 probe,确认 sandbox / guard / base / cache 真可用
130
134
  get_worker_preflight 核 probe 的实际 command evidence;passed 才能派目标 worker
131
- create_codex_worker 一步一个 worker,同一个 session_id,ownedPaths 不重叠
135
+ create_codex_worker 一个功能包一个 worker,同一个 session_id,ownedPaths 不重叠
132
136
  wait_codex_workers 60 秒一轮,compact: true,没完接着调
133
137
  get_worker_result 它说自己做了什么,verification 里是它真跑过的命令
134
138
  get_worker_diff 它实际做了什么
135
139
  ask_codex_worker 对不上就问它为什么,只读,不动它的线程
136
- resume_codex_worker 要改就追一条,让它 amend 进原来那个提交;主线走远了带 rebaseOnto
137
- land_codex_worker 核过了,落进集成分支
140
+ resume_codex_worker 要改就继续同一线程;主线走远了带 rebaseOnto
141
+ land_codex_worker 核过了,带 commitMessage 代提交并落进集成分支
138
142
  ```
139
143
 
140
- 上一块活 25 步,主脑会话一个人从第 1 步盯到第 25 步,上下文里只有任务书和每路交回来的汇报,没被 worker 的过程撑爆。
141
-
142
- 为什么一个 worker 只做一步:第 5 步做错了,让做第 5 步的那个 worker `resume_codex_worker` 一下,改完 `--amend` 并回它自己那个提交,主脑再核一次,过了才落进集成分支。要是一个 worker 连做了 5、6、7 三步,第 5 步错了就没法这样改,6 和 7 的提交已经叠在 5 上面,改 5 得连 6、7 一起重做。
144
+ 功能包在 land 前仍可 `resume_codex_worker` 继续修改。真正需要拆开的原因是写集冲突、依赖顺序或独立验收,不是“每一步都必须换一个模型线程”。
143
145
 
144
146
  ## 看板里有什么
145
147
 
@@ -159,20 +161,20 @@ land_codex_worker 核过了,落进集成分支
159
161
 
160
162
  | 工具 | 入参 | 作用 |
161
163
  |---|---|---|
162
- | `check_workers` | 无参 | 交付新终态、验收失败和需处理goal;新格式第1轮lost/no_work自动恢复一次,未变返回quiet;用宿主定时唤醒调用,每个主线程设独立CODEX_SUPERVISOR_OBSERVER_ID可在重启后接回 |
164
+ | `check_workers` | 无参 | 交付新终态、验收失败和需处理goal;新格式第1轮 `lost` / `no_work` / `invalid_report` 自动恢复一次,未变返回quiet;用宿主定时唤醒调用,每个主线程设独立CODEX_SUPERVISOR_OBSERVER_ID可在重启后接回 |
163
165
  | `overview_delta` | `cursor` | 主线程默认轮询入口:只返回 active / needs_attention / ready_to_land / ready_to_clean、cursor 后变化、短版 attention_reason / next_action 和 next_cursor;不返回全量历史、prompt、diff、event 或 worker capsule |
164
166
  | `check_acceptance` | `cwd`, `acceptance`, `baseRef`, `timeoutMs` | 派单前实际运行给定验收命令,不建 worker,不证明 worker 完成;数量 grep 会提示不能证明失败名单和必跑执行 |
165
167
  | `preflight_codex_worker` | `cwd`, `workspaceKind`, `inPlaceAuthorization`, `workspaceSetup`, `ownedPaths`, `probeCommands`, `baseRef`, `sandbox`, `allowedCommands`, `context`, `contracts`, `networkAccess`, `writableRoots` | 用与目标 worker 相同的 workspace/base/sandbox/guard 起短 probe worker;它必须实际跑完每条 probe command。probe 自动获得本次 guard-only 允许,但不进入目标 worker contract;联网和凭据目录仍须显式授权 |
166
168
  | `get_worker_preflight` | `task_id` | 返回 probe 的实际 command evidence、运行环境 contract hash、worker outcome 和 `running/passed/failed`;probe 全部执行通过时,报告 JSON 错误或已 exit 0 的 close-handler 缺失只留诊断,不误判环境失败 |
167
169
  | `create_codex_worker` | `task`, `cwd`, `workspaceKind`, `inPlaceAuthorization`, `workspaceSetup`, **`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`。`workspaceSetup` 在起 worker 前链接依赖、初始化子模块、跑 prepare;`preflight_id` 给了就必须是通过的同环境 probe |
168
- | `create_codex_followup_worker` | `task_id`, `followup_prompt`, `session_id`, 其余同上 | 开一个新会话,把老 worker 的 prompt、状态、近期事件拼进去 |
170
+ | `create_codex_followup_worker` | `task_id`, `followup_prompt`, `session_id`, `session_title`, `title`, `cwd`, `sandbox`, `model`, `ownedPaths`, `forbid`, `allowedCommands`, `context`, `contracts`, `externalOutputs`, `networkAccess`, `writableRoots`, `workspaceKind`, `workspaceSetup`, `goal`, `baseRef`, `acceptance` | 开一个新会话,把老 worker 的 prompt、状态、近期事件拼进去;不支持 `preflight_id`、`dependsOn`、`skipGitRepoCheck` |
169
171
  | `resume_codex_worker` | `task_id`, `prompt`, `rebaseOnto`, `acceptance`, `context` | 接同一个 Codex 会话继续跑,`thread_id` 不变。`rebaseOnto` 先把 worktree 挪到主线新头(stash、跳过已合入补丁、重放新增提交、放回),冲突原样退回不起 worker |
170
172
  | `wait_codex_workers` | `task_ids`, `mode`(any/all), `timeoutMinutes`, `timeoutMs`, `compact`, `emitProgress`, `includeEvents`, `eventLimit`, `eventMaxChars`, `eventKinds` | 等终态。默认 60 秒且不推周期 heartbeat;显式 `emitProgress: true` 才每 30 秒通知。`termination_reason` 区分 settled / budget_exhausted / client_cancelled;`compact` 每路一行 |
171
173
  | `get_orchestration_overview` | `status`, `limit` | 全部 worker 的状态表,封顶 7000 字节。带 `version` 和 `update` |
172
174
  | `get_worker_result` | `task_id`, `limit`, `maxChars`, `includeFiles` | worker 自己的汇报,默认截 6000 字节、`truncated` 提示读全。`acceptance` 是 supervisor 替你跑的验收过没过,`verification` 是它自己跑过的命令和退出码,`base_behind` 是主线走了多远(`contains_base: false` 时 `behind` 为 `null`,那是换了线) |
173
175
  | `get_worker_diff` | `task_id`, `file`, `hunk`, `pageSize`, `cursor`, `maxChars`, `paths` | worker 实际改了什么。默认完整文件索引与 hunk 数;按 `file` + `hunk`/`cursor` 分页读 patch。显式 `maxChars` 且不传 `file` 保留旧整份限流模式 |
174
176
  | `ask_codex_worker` | `task_id`, `question`, `timeoutMs`, `maxChars`, `fresh`, `end` | 旁路问 worker 一句。线程 fork 成只读侧会话,没网络、没 MCP 工具,worker 本身不动。worker 被 resume 过会自动换新 fork,`fresh` 强制换,`end` 删 |
175
- | `land_codex_worker` | `task_id`, `onto`, `commitMessage`, `ignoreAcceptance`, `allowOutsideOwned` | 把 worker 在 `codex/<id>` 上的提交 cherry-pick 到派单目录的当前分支。目标要干净,冲突回滚,验收 `failed` 拒绝。`commitMessage` 先替它把未提交的改动提交成一笔,`ignoreAcceptance` 放行 |
177
+ | `land_codex_worker` | `task_id`, `onto`, `commitMessage`, `ignoreAcceptance`, `allowOutsideOwned` | 把 worker 在 `codex/<id>` 上的提交 cherry-pick 到派单目录的当前分支。目标要干净,冲突回滚,验收 `failed` 拒绝;报告格式错不再单独阻止显式 land。`commitMessage` 先替它把未提交的改动提交成一笔,`ignoreAcceptance` 放行 |
176
178
  | `verify_delivery_push` | `task_id`, `remote`, `branch` | fetch 指定 remote branch 并证明 `landed_head` 已可达;只读验证,不会 push 或部署。通过后记录 `push_verified` 并生成 cleanup plan |
177
179
  | `cleanup_plan` | `task_ids`, `project_root` | 生成 15 分钟有效的 SAFE / REVIEW / BLOCKED 计划,含原因、fingerprint 与回收空间估算;SAFE 必须 acceptance passed、push verified、干净且无活跃依赖/进程 |
178
180
  | `apply_cleanup` | `plan_id`, `item_ids` | 只在未过期计划上二次校验 SAFE item、重新 fetch remote 并确认 landed SHA 仍可达后执行 `git worktree remove/prune`;保留 branch、task、events、JSONL、artifacts |
@@ -199,9 +201,25 @@ land_codex_worker 核过了,落进集成分支
199
201
  | `check_for_update` | `force` | 问 registry 有没有新版本 |
200
202
  | `cancel_codex_worker` | `task_id` | 终止 worker。跨进程按 pid 兜底,先确认那个 pid 跑的是 codex |
201
203
 
202
- 必填的两个:`ownedPaths`(派单前和在跑的 worker 求交集,重叠就拒,只在派单时查)和 `goal.objective`(worker 会建成 Codex 原生 goal)。`session_id` 不传就归不了组,一批活传同一个值。
204
+ MCP schema 必填两个:`ownedPaths` 和 `goal.objective`。写 worker 还必须通过上面的 preflight 工作流门禁;`preflight_id` 暂时保留为 optional 只为兼容旧客户端,不是正常流程可以跳过。`ownedPaths` 的写冲突在派单时预留,运行时 guard 会查直接写入,land 会再查完整 diff。
205
+
206
+ `acceptance` 在 Bash 中启用 `errexit` 和 `pipefail`:未处理的失败会停止检查,`npm test | tail` 中的测试失败也会保留。worker 自查必须运行 `node "$CODEX_SUPERVISOR_ACCEPTANCE_CLI"`,它执行同一份 supervisor 验收契约;不要手抄到 zsh,变量拆词等交互壳差异不会污染证据。写 worker 不能只用 `test -s`、`test -f` 或 `[ -e ]` 这类文件存在性命令交付;要加真实 test、endpoint probe 或结构化执行证据。识别到的 test runner 输出 `no tests to run` / `[no test files]` 时,即使退出码是 0 也判失败。预期失败用 `if` 或 `||` 显式处理;超时始终判失败,即使命令收到终止信号后退出 0。Windows 需要 Git for Windows 的 Bash;找不到会报错。显示的输出会裁剪,退出码不会因此改变。
207
+
208
+ `package.json` 仓库里,如果 `acceptance` 使用 `npm`、`pnpm`、`vitest`、`vue-tsc`、`eslint`、`nuxi` 等本地 JavaScript 工具,而派单没有 `workspaceSetup`,会直接拒绝为 `workspace_setup_required`。这条是 runtime 硬门禁,不再靠模型记得手工链接依赖。
209
+
210
+ 前端 worktree 的标准配置:
211
+
212
+ ```json
213
+ {
214
+ "workspaceSetup": {
215
+ "links": [{ "path": "node_modules", "source": "node_modules" }],
216
+ "submodules": true,
217
+ "commands": ["npx nuxi prepare"]
218
+ }
219
+ }
220
+ ```
203
221
 
204
- `acceptance` 在 Bash 中启用 `errexit` 和 `pipefail`:未处理的失败会停止检查,`npm test | tail` 中的测试失败也会保留。写 worker 不能只用 `test -s`、`test -f` 或 `[ -e ]` 这类文件存在性命令交付;要加真实 test、endpoint probe 或结构化执行证据。识别到的 test runner 输出 `no tests to run` / `[no test files]` 时,即使退出码是 0 也判失败。预期失败用 `if` 或 `||` 显式处理;超时始终判失败,即使命令收到终止信号后退出 0。Windows 需要 Git for Windows 的 Bash;找不到会报错。显示的输出会裁剪,退出码不会因此改变。
222
+ 同一份配置要同时传给 `preflight_codex_worker` 和目标 `create_codex_worker`,否则 runtime contract 不匹配。
205
223
 
206
224
  普通 worker 启动时会关闭它继承到的 `codex-supervisor` MCP,不能再派 worker、resume、cancel 或改编排状态;主线程是唯一编排者。其他业务 MCP 不受影响;旁问 fork 仍关闭全部 MCP,因为它只允许只读回答。
207
225
 
@@ -231,7 +249,7 @@ wait 默认预算60秒、默认compact;includeEvents会选择详细结果(
231
249
 
232
250
  守卫按 worker 形状放权:`git_worktree` 编辑 worker 只放声明过的命令和简单读取;`read_only_in_place` 无写入无网络;`scratch` 的联网草稿只能写在 `SUPERVISOR_HOME/scratch/<taskId>`;`in_place_write` 必须有显式授权、ownedPaths 与 acceptance,并保存前后 manifest。非 Git `workspace-write` 没写 `workspaceKind` 会拒绝,绝不默认写用户目录。
233
251
 
234
- 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。
252
+ 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;解析只做安全修复:字符串字段归一成 string[],以及唯一缺少的 `]`/`}`,伪造字段仍拒绝。报告只是摘要;invalid_report 保持 `completed` 生命周期和 attention,不否定同 run acceptance 和真实 diff,显式 land 仍可用;旧历史标legacy_text。
235
253
 
236
254
  context用绝对文件路径与可选sha256声明材料,最多20份、与contracts合计6000字;文件不超过5 MB。首次派单记录实际哈希,resume校验原材料未变,需要新材料时显式传context。handoff最多1800字/16行,截断明确标记;完整约束和引用单独保留,材料不授予写权限。
237
255
 
@@ -348,7 +366,7 @@ rm -rf ~/.claude/skills/codex-supervisor ~/.agents/skills/codex-supervisor ~/.co
348
366
  | worker 一起来就 `failed`,`spawn codex ENOENT` | 进程 `PATH` 里没有 codex | 配置里设 `CODEX_BIN` |
349
367
  | `Cannot find module 'node:sqlite'` | Node 低于 22.13.0 | 升 Node |
350
368
  | worker `lost` | worker 或独立运行进程中断 | 查事件后用 `resume_codex_worker` 接回 |
351
- | worker 说 `git add` 报 `index.lock: Operation not permitted` | 默认沙箱把 `.git` 设成只读 | 收活时 `land_codex_worker` 带 `commitMessage`,或派单用 `danger-full-access` |
369
+ | worker 说 `git add` 报 `index.lock: Operation not permitted` | 默认沙箱把 `.git` 设成只读,这是正常边界 | 保持 worker 只改和验收,收活时 `land_codex_worker` 带 `commitMessage` |
352
370
  | `ownedPaths overlap with active worker(s)` | 两路认领了同一片路径 | 改拆法,或先取消占着的那路 |
353
371
  | 看板打开是空的 | 看板和 MCP 的 `SUPERVISOR_HOME` 不是同一个 | 在配了 `.mcp.json` 的项目目录里起,或显式传同一个 `SUPERVISOR_HOME` |
354
372
  | `port 7877 ... is already in use` | 已经有一个看板在跑 | 直接开它,或 `SUPERVISOR_WEB_PORT=8080` 再起一个 |
@@ -356,10 +374,10 @@ rm -rf ~/.claude/skills/codex-supervisor ~/.agents/skills/codex-supervisor ~/.co
356
374
  ## 已知限制
357
375
 
358
376
  - 每次运行由独立进程读取 worker 输出、落状态和执行验收,直到结算后退出。派单 MCP 被 kill 后这些工作继续;新窗口用 `get_session_works` 收结果。若运行进程也被杀,保留 worktree 和 thread_id,核对 lost/interrupted 后恢复。
359
- - 默认 `workspace-write` 沙箱里 worker 提交不了(Codex 把 `.git` 设成只读)。要么收活时 `land_codex_worker` 带 `commitMessage` 替它提交,要么派单用 `danger-full-access`。
377
+ - 默认 `workspace-write` 沙箱里 worker 提交不了(Codex 把 `.git` 设成只读)。收活时 `land_codex_worker` 带 `commitMessage` 替它提交;不要为了提交改用 `danger-full-access`。
360
378
  - worktree 从一个提交切,你工作区里没 commit 的东西不在里面。
361
379
  - 只隔离工作目录。临时目录、数据库、端口是共用的。
362
- - `ownedPaths` 只在派单时查,拦不住 worker 新建清单外的文件。收活看 diff。
380
+ - `ownedPaths` 的冲突预留只在派单时计算;运行时 guard 会拦直接文件写入,land 会再查完整 diff。声明脚本仍可能产生清单外副作用,不能把它当完整文件系统沙箱。
363
381
  - 验收是 `acceptance` 里写了什么就查什么。没写的事它不会替你查,`verification` 只是 worker 自己跑过的命令,剩下的靠主线程看 diff。
364
382
  - 一次 `wait_codex_workers` 等不到底,客户端的 MCP 工具超时是硬墙,靠反复调。
365
383
  - `search_works` 是子串匹配,几百条够用。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-supervisor-mcp",
3
- "version": "0.12.2",
3
+ "version": "0.13.1",
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.",
@@ -25,6 +25,7 @@
25
25
  ],
26
26
  "bin": {
27
27
  "codex-supervisor-mcp": "src/mcp-server.js",
28
+ "codex-supervisor-accept": "src/acceptance-cli.js",
28
29
  "codex-supervisor-setup": "src/setup.js",
29
30
  "codex-supervisor-web": "src/web-server.js",
30
31
  "codex-supervisor-stage": "src/stage.js"
@@ -41,6 +42,7 @@
41
42
  "src/worktree.js",
42
43
  "src/landing.js",
43
44
  "src/acceptance.js",
45
+ "src/acceptance-cli.js",
44
46
  "src/acceptance-baseline.js",
45
47
  "src/worker-changes.js",
46
48
  "src/owned-changes.js",
@@ -1,187 +1,133 @@
1
1
  ---
2
2
  name: codex-supervisor
3
- description: 把 Codex CLI 当并行 worker 派活、盯进度、收结果。用户说"派 codex 干""并行跑""开几个 worker""这批活分几路""多 agent 做"时用;工作线程断了要接回来、要查以前派过什么活,也用这个。
3
+ description: 用 Codex CLI 并行做可独立验收的功能包,每路一个 Git worktree,能派单、等待、验收、恢复、合入和清理。用户说“派 codex”“并行跑”“多 agent”“接回旧 worker”时使用。
4
4
  ---
5
5
 
6
6
  # codex-supervisor
7
7
 
8
- 主线程派活给 Codex worker,一个 worker 一个独立 Git worktree,状态全部落盘。
8
+ 主线程负责拆包、定写集、准备环境、验收和合入。worker 只在自己的 worktree 里完成一个功能包,不负责编排,也不负责交付到远端。
9
9
 
10
10
  ## 什么时候用
11
11
 
12
- 一批能拆开的活、活偏大不想占自己的上下文、跑到一半可能断要能接回来。一个文件的小改、纯问答、要来回确认的活,自己干更快。
12
+ 适合能拆成几路、每路能单独验收的活,也适合耗时长、中途可能断、需要保留证据的工作。纯问答、单文件小改、需要频繁来回确认的活,主线程自己做更快。
13
13
 
14
- ## 派单
14
+ ## 派单前必须确认
15
15
 
16
- 1. 先 `search_works` 搜一下,别重复派。
17
- 2. 拆功能包。每路写清楚:干什么、能写哪些文件、依赖谁、怎么算做完和谁负责集成。改同一批文件就串行;文件不重叠只是并行前提,不等于依赖已满足。
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
- 4. `create_codex_worker` 派出去。回执只有 `id`、`worktree_path`、`branch`、`owned_paths`、`status`,不回传任务原文。
20
- 5. 长任务配宿主 `/loop 5m check_workers` 定时收活,没变化 quiet,有新结果按 next_step 收。工具会按规则恢复一次,但不会唤醒关闭的主窗口;每个主线程设独立 `CODEX_SUPERVISOR_OBSERVER_ID` 可重启接回。短等用 `wait_codex_workers` 的 `timeoutMs: 60000`、`compact: true`,到点继续同批 task_ids。
16
+ 1. 先 `search_works`,确认没有重复派工。
17
+ 2. 按功能闭环拆包,不按 DTO、方法或单个测试拆。每路要有清楚的输入、产出和 acceptance。
18
+ 3. `ownedPaths` 要覆盖完整写集:实现、测试、路由、注册表、DI、配置、迁移、i18n、模板接线都算。拿不准就给唯一模块目录。
19
+ 4. 依赖必须提前放进 worktree。前端链接 `node_modules` 并执行 `nuxi prepare`;后端初始化 submodule。不要 sleep 抢时间,也不要等主线程事后补。
20
+ 5. 写 worker 先跑同 contract 的 `preflight_codex_worker`。`get_worker_preflight` 必须是 `passed`,再把 preflight task id 填进 `preflight_id`。`check_acceptance` 不能代替 worker 环境预检。
21
+ 6. 只要 worker 会 land,就必须有能证明结果的 acceptance。文件存在检查只能当附加条件,不能单独当完成证据。
22
+ 7. `workspace-write` worker 不执行 `git add`、`git commit` 或 `amend`。验收通过后由主线程 `land_codex_worker(commitMessage)` 代提交并落地。
23
+ 8. worker 不 push、不合并、不再派生 worker。临时 `codex/<id>` 分支不是交付物。
21
24
 
22
- worker 默认不是调度员:启动时会禁用它继承到的 `codex-supervisor` MCP,不能再派 worker、resume、cancel 或改 session。要拆新路只能主线程决定并派;业务 MCP 仍按原配置可用。旁问 fork 则关闭全部 MCP。
25
+ `preflight_id` 是 AI 派单硬规则。MCP schema 为了兼容旧客户端仍允许省略,但不能把“没被 schema 拒绝”当成可以跳过预检。
23
26
 
24
- | 参数 | 怎么填 |
25
- |---|---|
26
- | `task` | 这一路具体干什么。要能直接开工,别写"优化一下"。汇报格式 supervisor 已经附在 task 后面(结论 / 验证 / 没做的),别再要它列改动文件,diff 自己看 |
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 |
30
- | `workspaceSetup` | 仅 Git worktree,在 worker 启动前完成环境准备:`links` 把主仓依赖链接进 worktree;`submodules: true` 初始化子模块;`commands` 跑 `nuxi prepare` 等准备工作。setup 失败会在派单阶段回收 worktree。链接名为 `node_modules` 时自动把 `.vite`、`.vite-temp`、`.cache` 放进该 worker 可写缓存根 |
31
- | `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` |
32
- | `forbid` / `allowedCommands` | 原样声明红线与验证命令;守卫拒绝未声明Shell程序,编辑用apply_patch |
33
- | `writableRoots` | 只有需要凭据目录时才传(绝对路径、已存在、自动解析软链、只对 workspace-write 生效):ssh/远程测试 → `["~/.ssh"]`;kubectl → `["~/.kube"]`;推私有镜像 → `["~/.docker"]`;aws cli → `["~/.aws"]`;签名提交 → `["~/.gnupg"]`。缓存目录不用写,已经自动加 |
34
- | `ownedPaths` | 必填。这路允许写的路径,和在跑的 worker 重叠会被拒(**读不排他**,多路读同一份共享文件合法)。冲突是好事,说明该改拆法。传 `[]` 表示这路不落地:只读验证或研究 |
35
- | `goal.objective` | 必填。一句话说目标,worker 会建成 Codex 原生 goal;不传 `goal.tokenBudget` 就是不限预算,runtime guard 会拒绝 worker 自填 `token_budget` |
36
- | `session_id` | 同一批传同一个值。只管批次、默认验收和审批,不是上下文继承边界;第一路顺手带 `session_title`(30 字内,看板和 `get_session_works` 显示它),漏了用 `describe_session` 补 |
37
- | `dependsOn` | 有先后依赖填上游的 `task_id`,它是硬门禁:上游必须同 `project_root`、成功结算、配置了 acceptance 就已通过、已 `land_codex_worker`,并且本路实际 `baseRef` 包含上游 `landed_head`。没满足先集成/修验收,不会启动下游 |
38
- | `baseRef` | worktree 从哪个提交切,默认 `HEAD`。第 N+1 步要建立在第 N 步上,填 `codex/<第 N 步 task_id>` |
39
- | `preflight_id` | 写 worker 必填。先跑 `preflight_codex_worker`,它实际在目标 sandbox/guard 里执行 `probeCommands`;`get_worker_preflight.status` 必须是 `passed`。base、ownedPaths、命令、context、contracts、network、可写根有变化就重跑 |
40
-
41
- `probeCommands` 会自动加入这次 probe worker 的 guard-only allowlist,不会进入目标 worker 的 runtime contract;目标 worker 仍只声明自己真正需要的 `allowedCommands`。ssh 等联网探针仍要显式 `networkAccess: true`,需要写 `known_hosts` 时同时声明 `writableRoots: ["~/.ssh"]`。
42
-
43
- 预检结论以 probe command evidence 为准,不把模型最终 JSON 或进程 close handler 当环境事实:所有探针都实际执行且通过、没有失败命令时,最终报告格式错误不会让预检失败;probe-only worker 即使最终变 `lost` 且退出码未记录,也只记诊断,不重跑。命令未执行、非零或取消仍失败。
44
- | `sandbox` | 默认 `workspace-write`,worker 提交不了(Codex 把 `.git` 设成只读)。要它自己提交就 `danger-full-access`,否则收活时让 supervisor 替它提交 |
45
-
46
- 验收用 Bash 的 `errexit` + `pipefail`:`npm test | tail` 不能吞失败;文件存在只可做附加门禁,不能单独证明业务完成。预期失败用 `if` / `||` 显式判。超时、`no tests to run`、`[no test files]` 都失败,别只看退出码 0。Windows 要有 Git for Windows Bash;缺失先修工具,别换回 cmd。
47
-
48
- 验收取当前身份用 `CODEX_SUPERVISOR_TASK_ID` / `CODEX_SUPERVISOR_BASE_COMMIT` / `CODEX_SUPERVISOR_RUN`;worker 进程和 supervisor 验收子进程都会注入同一组当前值,rebase/resume 后一起更新。不要在命令里写死旧 base。
49
-
50
- `check_acceptance` 只是在宿主权限跑验收命令,预检通过不代表 worker sandbox/guard/PATH/cache/network 可用;写 worker 的实际环境预检必须走上面的 `preflight_codex_worker`。已知失败必须按结构化 baseline 的用例名/类型/签名比,必跑项写 required;报告必须标本次 `CODEX_SUPERVISOR_CHECK_ID`,给 complete/identity/failures/executed/skipped,缺失、跳过和旧报告都不算过。reportPath 用工作区内忽略的临时目录,验收报告别混进业务提交。
51
-
52
- 同批公共门禁用 `describe_session.default_acceptance`,自动追加本路验收;更新目标/门禁传 `expected_revision`,避免旧窗口覆盖。需要用户拍板时设 `approval_state: waiting_user`,不得自动resume;获批改approved并同步宿主goal。回执host_goal_sync给当前策略的/goal命令;宿主已有原生goal时,用/goal替换条件,支持ProposeGoal时提议同一condition并走宿主批准。这个条件要求读取最新session revision,批准旧失败或waiting_user后不再追旧目标;工具不偷偷改/禁用Stop hook。
27
+ ## 标准派单
53
28
 
54
- wait默认60秒和compact,带includeEvents则详细返回;默认不推周期 heartbeat,只有显式 `emitProgress: true` 才在客户端带 progress token 时每30秒通知。需要一条长 wait 被宿主转后台后只收终态,就保持默认;需要桌面进度才 opt-in。返回的 `termination_reason` 区分 `settled` / `budget_exhausted` / `client_cancelled`,通知不能唤醒关闭的宿主。/loop实测可定时调用,主窗口须保持运行。
29
+ 前端示例,preflight 和目标 worker 必须使用同一份 contract:
55
30
 
56
- 派单写forbid红线、allowedCommands验证命令;runtime守卫按次注入并随resume/followup继承。apply_patch核对ownedPaths;安全只读检查(rg/cat/sed无-i/git只读/jq无-i/find无-exec或-delete)默认允许且不占其他 worker 的写路径,写入/执行/有副作用的 Shell 命令必须显式声明;声明脚本可以有副作用,须先核对,不能当万能文件沙箱。no_work表示本轮write无输出变化且没跑命令;先看run_evidence,不拿上轮提交/命令当本轮完成。
31
+ ```json
32
+ {
33
+ "workspaceSetup": {
34
+ "links": [{ "path": "node_modules", "source": "node_modules" }],
35
+ "submodules": true,
36
+ "commands": ["npx nuxi prepare"]
37
+ }
38
+ }
39
+ ```
57
40
 
58
- 没有独立 `apply_patch` 工具的模型会把补丁当 shell 命令发过来(`apply_patch <<'EOF' ... EOF`):守卫认这个形状,按同一套 ownedPaths 判路径、同样拒越界,所以模型不需要有那个工具也能改文件。Quoted heredoc 才认;后面跟 `&&`/`;` 的、未加引号的都不算。
41
+ `package.json` 项目如果用 `npm`、`pnpm`、`vitest`、`vue-tsc`、`eslint`、`nuxi` 等本地工具做验收,却没传 `workspaceSetup`,supervisor 会直接返回 `workspace_setup_required`。
59
42
 
60
- `allowedCommands` 里以 `*` 结尾的条目是**前缀**:声明 `go test ./internal/*` 就覆盖 `go test ./internal/service -run TestX`,但只对没有 shell 元字符的单条命令生效(`; rm -rf /` 不会通过)。守卫的只读白名单包含 grep/sed/find/jq/awk/go env、git 的只读子命令和 `cmd | head|tail|wc|sort|uniq` 这类纯读管道;`sed -i`、`find -delete/-exec`、`jq -i`、`tee`、重定向仍被拒。
43
+ ## 关键参数
61
44
 
62
- worker不止改代码,按这路要什么选形状:
63
-
64
- | 形状 | 参数 | 能干什么 |
45
+ | 参数 | 怎么填 |
46
+ |---|---|
47
+ | `task` | 写清目标、背景、要改的交付面、边界和验收。不要写“优化一下”。最终报告格式由 supervisor 追加,不在这里重复 |
48
+ | `cwd` | Git 项目根,或非 Git 输入目录;实际执行目录由 `workspaceKind` 决定 |
49
+ | `workspaceKind` | Git 代码默认 `git_worktree`;非 Git 只读用 `read_only_in_place`;联网研究用 `scratch`;明确授权修改非 Git 目录才用 `in_place_write` |
50
+ | `workspaceSetup` | Git worktree 启动前准备依赖。支持 `links`、`submodules`、`commands`。链接 `node_modules` 时会给 `.vite`、`.vite-temp`、`.cache` 可写缓存根 |
51
+ | `ownedPaths` | 必填。完整写入范围;不同 worker 的写入范围不能重叠。读取不排他。`[]` 只用于不 land 的只读或研究 worker |
52
+ | `sandbox` | 默认 `workspace-write`。这个沙箱不能 commit,这是正常边界;不要为了提交改用 `danger-full-access` |
53
+ | `preflight_id` | 写 worker 必填。preflight 的 base、`workspaceKind`、`sandbox`、`workspaceSetup`、`ownedPaths`、命令、context、contracts、network、可写根有任何变化都要重跑 |
54
+ | `acceptance` | worker 退出后由 supervisor 在 worktree 里执行。worker 自查统一运行 `node "$CODEX_SUPERVISOR_ACCEPTANCE_CLI"`,不要手抄到 zsh。每个检查必须真实证明功能 |
55
+ | `allowedCommands` | 声明会执行、会写入或有副作用的验证命令。read 命令有安全白名单;命令末尾 `*` 表示只匹配单条命令的前缀 |
56
+ | `forbid` | 明确禁止的命令片段。forbid 优先于 allowedCommands 和 acceptance |
57
+ | `goal.objective` | 必填。worker 会创建 Codex 原生 goal |
58
+ | `goal.tokenBudget` | 可选。不传就是不限预算,worker 必须完全省略 `token_budget`;传 `0`、`1` 或 `null` 会被 runtime guard 拒绝 |
59
+ | `session_id` | 同一批使用同一个值。它只负责分组、默认验收和审批,不会把同批 worker 的上下文互相注入 |
60
+ | `session_title` | 建议 30 字内,schema 上限 120 字;漏了可用 `describe_session` 补 |
61
+ | `dependsOn` | 填上游 task id。上游必须成功结算、acceptance 通过并 `land_codex_worker`,且本路 base 包含上游 landed head |
62
+ | `baseRef` | worktree 从哪个提交切。下一步要包含上一步时,填 `codex/<task_id>` 或已集成分支 |
63
+
64
+ 派 `create_codex_worker` 后,回执不回传 task 原文。回执至少带 `id`、`worktree_path`、`branch`、`owned_paths`、`status`;有 base、session、failure 或 run log 时也会返回。
65
+
66
+ ## worker 形状
67
+
68
+ | 形状 | 参数 | 用途 |
65
69
  |---|---|---|
66
- | Git 编辑 worker | `workspaceKind: "git_worktree"` + `ownedPaths` 非空 | apply_patch 只能落在 ownedPaths,shell 只放声明过的命令和简单读取 |
67
- | 只读验证 worker | `workspaceKind: "read_only_in_place"` + `sandbox: "read-only"` + `ownedPaths: []` | 随便跑读命令(rg/cat/git/jq),**沙箱没有任何写入(连 /tmp 都不行)、也没有网络**;结论写在最终报告 |
68
- | 研究/检索 worker | `workspaceKind: "scratch"` + `sandbox: "workspace-write"` + `networkAccess: true` + `ownedPaths: []` | 能联网 curl/gh,只能往 supervisor 管理 scratch 写草稿;没有任何东西会 land,也不碰原始非 Git 目录 |
69
- | 非 Git 写入 worker | `workspaceKind: "in_place_write"` + 授权 + `ownedPaths` + `acceptance` | 仅用户明确授权时使用;记录授权和前后 manifest,不能 land |
70
-
71
- read-only 下 `networkAccess: true` 会被拒(实测该沙箱连 DNS 都不通,配了也没用);要联网就按 `scratch` 研究 worker 派。非 Git `workspace-write` 不写 `workspaceKind` 会拒绝,绝不偷偷落到用户目录。研究 worker 的 shell 不受 allowedCommands 限制,forbid 红线照旧。读共享文件永远不排他,只有写按 ownedPaths 排他。
72
-
73
- 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另外核对。
74
-
75
- 未提交材料用context:[{path:绝对路径,sha256:可选}];首次记哈希,resume材料变了要显式换context。context/contracts总6000字、最多20份文件,每份≤5 MB;handoff1800字/16行可裁,完整约束和refs另传。输入路径不等于写授权。
76
-
77
- 共享写入必须externalOutputs:[{path,sha256?}]+acceptance;绝对文件每份≤1 MB,参与归属冲突/hook。看external_outputs的前后内容、哈希与验收;外部文件已经写在共享目录,不用land,不能拿空worktree diff否认成果。
78
-
79
- 远端编译/ssh在workspace-write显式networkAccess:true,默认false,resume/followup继承;不要用danger-full-access代替联网配置。需要时声明maxRunMs/maxTotalMs,超限保留partial work并提示处理,不自动恢复;wait预算与quota分开。
70
+ | Git 编辑 | `workspaceKind: "git_worktree"`、非空 `ownedPaths` | 改代码、跑 acceptance、等待主线程 land |
71
+ | 只读验收 | `workspaceKind: "read_only_in_place"`、`sandbox: "read-only"`、`ownedPaths: []` | 无写入、无网络,只给结论 |
72
+ | 联网研究 | `workspaceKind: "scratch"`、`workspace-write`、`networkAccess: true`、`ownedPaths: []` | 可以 curl/gh,只写 supervisor 管理的 scratch,永不 land |
73
+ | 非 Git 写入 | `workspaceKind: "in_place_write"`、授权、完整 `ownedPaths`、acceptance | 只改明确授权的非 Git 目录,不能 land |
80
74
 
81
- 沙箱只放工作区、临时目录、OS cache目录(macOS ~/Library/Caches、Linux ~/.cache、Windows %LOCALAPPDATA%)以及home下已存在的工具链缓存目录(.cargo/.npm/.yarn/.pnpm-store/.bun/.m2/.gradle/.nuget/.ivy2/.bundle/.composer/.pub-cache/.mix/.hex/.stack/.cpanm/.deno/.conda、go/pkg)。Go build cache(平台默认 `go-build` 或显式 `GOCACHE`)会单独解析 realpath 并放行真实目录,所以它指向外置盘 symlink 时 worker 也能用;其他语言也不需要逐个加环境变量。**凭据目录一律不自动放开**(.ssh/.gnupg/.config/.aws/.docker/.kube/.netrc/.git-credentials/~/Library/Keychains):ssh 连服务器要写 known_hosts、kubectl、推私有镜像、签名提交这类需求,派单时按参数表显式传 writableRoots,只在这一路生效、随 resume/followup 继承。SUPERVISOR_NO_AUTO_CACHE_ROOTS=1 关掉全部自动缓存根,显式声明的照常生效。Codex 拒绝含软链的可写根,所以自动 cache 与 `writableRoots` 都先按 realpath 解析;解析不到无软链路径的根直接不传。其他 cache 在别处(如 ~/.m2、~/.gradle、vendor 镜像)就传 `writableRoots:[绝对路径]`(已存在目录、最多20个、只对workspace-write生效、随resume/followup继承);能只读复用就不用传。
75
+ ## 等待与状态
82
76
 
83
- 前端多 worktree 的标准派单不要让人手补目录:`workspaceSetup: { links: [{ path: "node_modules", source: "node_modules" }], commands: ["npx nuxi prepare"] }`;后端有 proto 等子模块时用 `workspaceSetup: { submodules: true }`。同一个 setup 必须同时传给 preflight 和目标 worker,contract 才会匹配。
77
+ - 日常增量看 `overview_delta`,保存 `next_cursor`。需要全量状态时才用 `get_orchestration_overview`。
78
+ - 短等用 `wait_codex_workers`,建议 `timeoutMs: 60000`、`compact: true`。`still_running: true` 只表示这次等待预算用完。
79
+ - 长任务用宿主 `/loop 5m check_workers`。不同主线程设置不同的 `CODEX_SUPERVISOR_OBSERVER_ID`。
80
+ - `idle_seconds` 是距上一条 Codex 事件的时间。`command_running: true` 时长命令可能仍在跑;没有命令且长时间无事件,再查 `get_codex_worker_events`。
81
+ - 不要用 shell 循环 grep `data/runs/*.jsonl` 判断状态。`failed`、`lost`、退出码和恢复状态以 supervisor 状态机为准。
84
82
 
85
- Codex需0.162+支持hooks/output-schema,能力不够派单start_failed先修CLI。goal查询看native_goal_read,missing与locked/read_error分开;budget/usage限制也要处理。cleanup保留ignored成果、共享证据及未解决attention。
83
+ ## 收活顺序
86
84
 
87
- 等待的几条规矩:
85
+ 1. 先看 `acceptance`。失败时把 `checks[].output_tail` 原样带回 resume,不改验收标准。
86
+ 2. 读 `get_worker_result`。注意 `commands_run`、命令退出码和 `last_command_failed`,不要只听结论。
87
+ 3. 读 `get_worker_diff`。默认先看文件和 hunk 索引,再按 `file` + `hunk`/`cursor` 分页读 patch。
88
+ 4. 对不上就问 `ask_codex_worker`。旁路只读,不改 worker 线程。
89
+ 5. 要改就 `resume_codex_worker`。不要要求 worker commit 或 amend;主线前进时按需带 `rebaseOnto: "HEAD"`。
90
+ 6. 验收和 diff 都过了,用 `land_codex_worker({commitMessage})` 把未提交改动提交到 worker 分支并 cherry-pick 到当前集成分支。
88
91
 
89
- - 等待预算管这次调用,不管 worker。`still_running: true` 是等满了不是挂了,按 `next_step` 再调。
90
- - 快照里 `idle_seconds` 是距上一条 Codex 事件多久,命令跑着和模型思考时 Codex 都不发事件。`command_running: true` 是长命令(`current_command` 是哪条),接着等;`command_running: false` 且 idle 超过 10 分钟,`get_codex_worker_events` 看最后几条,进程没了状态机会自己标 `lost`。
91
- - `timeoutMinutes` 别超过客户端的 MCP 工具超时,否则被掐的是这次调用。
92
- - **不要自己写 shell 循环 grep `data/runs/*.jsonl`**。进程被杀、`failed`、`lost`、`exit_code` 只有状态机知道,文件里没有;resume 过的 worker 文件里有多条 `turn.completed`;用户在终端里看到的是一行黑盒。
93
- - 想省上下文改调 `get_orchestration_overview`,封顶 7000 字节。
92
+ `invalid_report` 不是业务失败。常见情况是单个字符串字段、缺一个 `]`/`}`,或内容完整但 schema 不合规。先让 `check_workers` 做一次 report-only 修复;仍失败时,acceptance 通过且 diff 审过,可以显式 land。报告只是摘要,不是交付证据。
94
93
 
95
- ## 收活:先看证据,再问,再改,再落
94
+ ## 上下文与事实
96
95
 
97
- 0. 先看 `acceptance`(compact wait、overview 的 `acceptance_failed`、`get_worker_result.acceptance` 都有)。`failed`:不用读它的汇报,直接走第 4 步,把 `checks[].output_tail` 原样贴进 resume 的 prompt。`passed` 但它说没做成、goal 是 `blocked`:信命令不信它,去看 diff。命令本身写错了,resume 带新的 `acceptance` 换掉,别 `ignoreAcceptance`。`null` 是没配,退出码只说明没崩,对不对自己看。
98
- 1. `get_worker_result`:它说自己做了什么。默认截到 6000 字节,`truncated: true` 就按 `next_step` 带 `maxChars` 读全。`verification` 是它真跑过的命令和退出码:说"测过了"但 `commands_run: 0`、说"没建成"但那条命令退出码是 0、`last_command_failed: true` 却说完成、说"环境问题"但 `failed[].output_tail` 里是代码报错,都打回(走第 4 步),别替它圆。`base_behind.behind > 0` 说明派单后主线往前走了,改之前先 rebase(第 4 步);`contains_base: false` 时 `behind` 是 `null` 并带 `note`,那是派单目录换了线,不是落后。
99
- 2. `get_worker_diff`:它实际做了什么。默认只回完整文件/hunk 索引;再传 `file` + `hunk` 或 `cursor` 分页读 patch,避免 500 行测试文件一次灌满上下文。显式传 `maxChars` 且不传 `file` 才走旧的整份 bounded diff。它说过了不算,diff 对得上才算。
100
- 3. 对不上、看不懂为什么:`ask_codex_worker` 带 `question` 问它。fork 出一个只读旁路,worker 自己的线程不动;fork 没网络没 MCP 工具,问"改了什么、为什么、在哪",别问要联网才能答的事。超时回 `running`,只带 `task_id` 再调拿答案。worker 被 resume 过后下一问自动换新 fork,`fresh: true` 强制换,问完 `end: true` 删。
101
- 4. 要它改:`resume_codex_worker`,写清问题在哪,让它改完 `git commit --amend --no-edit` 并进原来那个提交。旁路只读,改东西永远走 resume。主线往前走过(`base_behind.behind > 0`)就带 `rebaseOnto: "HEAD"`(在派单目录里解析):未提交的改动先 stash,跳过已合入的补丁,只把新增提交重放到新头,stash 放回,`base_commit` 跟着动。冲突(`rebase_conflict` / `stash_conflict`)会原样退回、不起 worker、`files` 列冲突文件;这时让它先 `land_codex_worker` 带 `commitMessage` 提交成一笔再 rebase,或者重派一路 `baseRef` 填新头。
102
- 5. 过了:`land_codex_worker` 把 `codex/<id>` 上的提交 cherry-pick 到派单目录当前分支。目标脏了、分支不对、冲突都拒绝并原样退回。worker 没提交(默认沙箱提交不了)就带 `commitMessage`,supervisor 在它分支上替它提交一笔再落。验收 `failed` 它会拒,修完再落;`ignoreAcceptance` 只在用户说了"就这样落"时用。
96
+ - worker capsule 只在新派单或 resume 时生成。默认注入 L0 身份、当前任务、依赖摘要和路径/SHA 命中的 verified facts。
97
+ - `session_id` peers、完整事件、完整 diff、历史报告和 candidate facts 不会自动注入。
98
+ - 主线程看事实摘要用 `search_worker_facts`;追溯来源用 `get_fact`;看证据索引用 `get_worker_evidence` / `get_artifact`。
99
+ - worker 的报告先记为 candidate。只有 supervisor acceptance 通过后,才有资格成为当前 work 的 verified outcome。
100
+ - base SHA、watched path、context hash 或 in-place manifest 变化后,旧 fact 会过期并从后续 capsule 排除。
103
101
 
104
- 一批活全部到终态后:`get_orchestration_overview` 确认没有 `needs_attention`、`acceptance_failed` 为空,再逐路走上面几步。合不合、怎么合由主线程定。
102
+ ## 中断与恢复
105
103
 
106
- 高风险的步(迁移、改公共接口、"做完了"写不成命令的)用 `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。
107
-
108
-
109
- ## 收工口径:活儿必须落地
110
-
111
- **"文件写好了"不等于交付。** 本地 worktree / 未提交改动 / 未 push 的 commit,线上都看不到 —— 部署会因为缺类、缺文件、缺 bean 直接挂。派单和主线程自己的改动都按这四条走:
112
-
113
- 1. **worker 的产出默认要合并**:每个终态 worker 走 `get_worker_result` → `get_worker_diff`,过了就 `land_codex_worker`(sandbox 是 workspace-write 的 worker 没提交,带 `commitMessage` 一起提交再落)。不合并必须在报告里写清原因(验收失败 / 越界 / 等审批),不能默认留在 codex/<id> 分支上。
114
- 2. **主线程自己的改动必须 add + commit + push**:`git add <paths> && git commit -m ... && git push`。跳过任何一步都要显式说明,不允许说"改好了"然后留在工作区。
115
- 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,先查这一条,再查代码逻辑。
116
- 4. **交付报告三件套**:本地改动 → commit SHA → push 后的远端 SHA(以及部署状态)。缺远端 SHA 就不算完成。
117
- 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` 只提醒,不执行删除。
118
-
119
- `land_codex_worker` 只到本地集成 `landed`,不是远端交付。用户已经 push 后,主线程调 `verify_delivery_push({task_id,remote:"origin"})`,它只 fetch + 祖先校验、不替你 push/部署;通过才记 `push_verified`,后续才可进入安全 cleanup 候选。
120
-
121
- 典型事故:两个实现类只存在于主线程的 worktree 里,没 add / 没 commit / 没 push,线上跑的还是上一个提交,Spring 找不到 bean 启动失败 —— 不是代码错,是没上线。
122
-
123
- 多 worktree 场景同理:worker 的分支、主线程的改动、集成 worktree 的合并,三者都要各自 push 到远端;只在自己 worktree 里"跑通了"不算。
124
-
125
-
126
- ## 读结果别把上下文撑爆
127
-
128
- | 想干什么 | 用哪个 |
104
+ | 情况 | 处理 |
129
105
  |---|---|
130
- | 主线程日常增量 | `overview_delta`,保存 `next_cursor`;只看计数、变化 task 摘要、短版阻塞原因和下一步 |
131
- | 全部 worker 的状态 | `get_orchestration_overview`,只在需要全量状态时用 |
132
- | 一路的完整结论 | `get_worker_result` |
133
- | 一路改了什么 | `get_worker_diff` 默认拿文件/hunk 索引;选一个 `file` 后用 `hunk` 或 `cursor` 分页。只要文件名用 `get_worker_result` 带 `includeFiles: true` |
134
- | 活着还是完了 | `get_worker_summary` |
135
- | 过程 | `get_codex_worker_events`,`kinds` 先滤、`limit` 限条数、`maxChars` 截长串,先看 `available_kinds` |
136
- | 门禁内部阶段 | worker 脚本调用 `node "$CODEX_SUPERVISOR_STAGE_CLI" "gate:s3" --detail "..."`;status/overview/wait 显示 `current_stage`,终态保留 `last_stage`。不要写 secret |
137
- | 一路的状态细节 | `get_codex_worker_status`,`current_action` 是它正在跑的命令 |
138
- | 验收过没过 | 每个读都带 `acceptance`;命令和每条的输出在 `get_worker_result.acceptance.checks` |
139
- | worker 吃了哪些上下文 | `get_context_snapshot_meta`,只看 fact IDs/token/排除项,不会回 capsule 正文 |
140
- | 线程是否太长 | `thread_health`:`ok` / `getting_long` / `handoff_recommended`;达到阈值时用 `create_codex_followup_worker` 起新线程,原线程留作证据 |
141
- | 一条共享事实的来源 | `get_fact`,按 ID 精确读;不要把一批 facts 全拉进主线程 |
142
- | 找当前任务的已验证事实 | `search_worker_facts`,传 task_id/query/cursor;只回 scope 内 verified summary + coverage,绝不拉 raw history |
143
- | 找某路的证据索引 | `get_worker_evidence`,再按需 `get_artifact` 或 `get_codex_worker_events` |
144
- | 主线程确认候选事实 | `promote_worker_fact`;只有主线程审过才会追加 verified,repo scope 必须给 watchedPaths |
145
- | 主线程推翻事实 | `revoke_worker_fact`;写明 reason,追加撤销版本保留原始 fact;`get_fact.effective_state` 显示撤销状态,不进入 search 或后续 capsule |
146
-
147
- 默认读回来的长文本都是裁过的(`current_action` 300 字、`prompt` 300 字、`last_message` 400 字),别把裁剪当成活没干。全量在库里。别一次 `limit: 200` 拉全量事件。
148
-
149
- worker 的 capsule 只在内部 create/resume 时生成:L0 身份会标 branch 与 acceptance 来源但不放 acceptance 命令正文、当前 work 的 verified facts、显式 `dependsOn` 的最小交付摘要、路径命中且 SHA 有效的 repo facts。repo fact 跨 checkout 必须 canonical `origin`、repo-relative watched path 与 SHA 同时命中;没有可识别 origin 就不共享。`session_id` peers、raw event、完整 diff/报告、candidate facts 一律不自动注入。base SHA 不再覆盖、watched path 有 Git diff、context 输入 content hash 或 in_place_write manifest 漂移时,旧 fact 自动 append-only `expired` 并排除,保留原始版本。主线程只能看 snapshot 元数据;要查事实用 `search_worker_facts` / `get_fact`,查证据用 `get_worker_evidence` / `get_artifact`,不能把自己变成 worker。
150
-
151
- `thread_health` 依据 native goal 的累计 tokens;默认 30 万建议 handoff,可用 `CODEX_SUPERVISOR_HANDOFF_TOKEN_THRESHOLD` 调整,设 0 关闭。它只提醒,不自动结束线程。
152
-
153
- worker 最终 JSON 只是 `candidate`:先留在本 run 做审计,绝不因为它自己说“完成”就变共享事实。supervisor acceptance 通过才会派生当前 work 的 `verified` outcome;验收失败/未配置、脏 diff、未 land/push 都不是 verified 交付证据。
154
-
155
- ## 断了怎么接
156
-
157
- | 情况 | 用什么 |
158
- |---|---|
159
- | 主线程自己挂了 | 独立运行进程继续记日志、状态和验收;新窗口 `get_session_works({ session_id })` 收回同批活 |
160
- | worker 变 `lost`(worker 或独立运行进程中断) | `resume_codex_worker`。worktree 里的改动和 `thread_id` 都在,同一线程接着干;被杀时正在做的那一步可能要重做 |
161
- | worktree 落后主线(`base_behind.behind > 0`) | `resume_codex_worker` 带 `rebaseOnto: "HEAD"`,见收活第 4 步 |
162
- | worker `failed` | 看 `error` 和日志,查完再 resume 或重派 |
163
- | 没记到 `thread_id` 的老行 | `create_codex_followup_worker`,新线程靠文本重述 |
106
+ | 主线程挂了 | worker 的独立 run host 会继续记录日志、状态和验收。新窗口用 `get_session_works` 接回 |
107
+ | worker 变 `lost` | `resume_codex_worker`,worktree、改动和 thread id 都保留 |
108
+ | worktree 落后主线 | `resume_codex_worker` 带 `rebaseOnto: "HEAD"` |
109
+ | worker 失败 | 先看 `failure.source` 和 `error`,区分 provider、supervisor、workspace setup、model output、acceptance、worker process |
110
+ | 没有 thread id 的旧行 | 用 `create_codex_followup_worker`,通过文本重述上下文 |
164
111
 
165
- `status` 是生命周期:`queued` / `running` / `completed` / `failed` / `cancelled` / `lost`。`phase` 只在跑着时有值:`starting` → `thinking` → `command` → `editing` → `reporting`。`completed` 配 `exit_code: null` 是中间态,`wait` 会等到退出码落了再返回;验收已被中断且 worker/run-host 都已退出时,宽限 5 秒后自动转成可 `resume` 的 `lost`,不会永远卡在 completed。goal 的 `paused` / `blocked` 不是结束,是等人管,overview 会列进 `needs_attention`。
112
+ `check_workers` 会自动恢复一次已死的第一轮 `lost`、`no_work` 或 `invalid_report`,不会盲重试审批、认证、权限、quota 或时间限制。`completed` 但 `exit_code: null` 是中间态;验收已跑完的 durable 事件会优先于 PID 推断。
166
113
 
167
- 终态优先看 `failure.source` / `failure.code`:`provider` 是模型代理或上游,`supervisor_process` 是 exit 未收口/启动/超时,`workspace_setup` 是依赖链接、子模块或 prepare,`model_output` 是最终报告格式,`acceptance` 是验收命令,`worker_process` 是 worker 进程非零退出,`worker_progress` 是 no_work/two_stall。不要把所有 failed/lost 都当业务代码失败。
114
+ ## 落地、push 和清理
168
115
 
169
- ## 看到 `update` 字段就转告用户
116
+ `land_codex_worker` 只完成本地集成,不等于远端交付。
170
117
 
171
- overview、派单回执、`wait` 返回里出现 `update` 且 `update_available: true` 时,当轮回复里照 `notice` 告诉用户一句。`auto_update.state` 是 `started` / `running` / `done` 时新版已在后台装,重开会话即可;`install_command` 有值才让用户自己跑。只说一次。
118
+ 1. 主线程自己的改动要 commit 并 push。用户批准的集成分支也要在 push 后核对远端 SHA。
119
+ 2. worker 分支通常不 push。只有用户明确要求保留远端 worker 分支时再推。
120
+ 3. push 后用 `verify_delivery_push` 证明 landed head 已到远端,并生成 cleanup plan。
121
+ 4. `check_workers` 只提示清理,不执行删除。
122
+ 5. 只有 `acceptance passed`、`push_verified`、worktree 干净、没有活跃进程/依赖、fingerprint 未变化的 SAFE item,才可用 `apply_cleanup(plan_id, item_ids)` 删除。
123
+ 6. cleanup 只执行 `git worktree remove/prune`。task、run event、JSONL、artifact 和 branch 都保留。
172
124
 
173
125
  ## 常见坑
174
126
 
175
- - worktree 从一个提交切,你工作区里没 commit 的东西 worker 看不到。要让它读到就给绝对路径或先 commit;Git worktree 建不出来会明确拒绝,不会退回主目录执行。
176
- - `exit_code: 0` 只说明没崩。`acceptance` 是 supervisor 替你跑的验收,`verification` 是它自己跑过的,两个都没有就只剩 diff。验收命令别往 worktree 写文件,会混进它的改动。
177
- - `ownedPaths` 在跨MCP派单/恢复时原子预留,验收和退出结算前仍占用;Git隔离创建失败不退回主目录。land 按真实 diff 拒越界(提交草稿前就查)。仍不等于运行时沙箱,收活看 diff;`allowOutsideOwned` 只用于用户明确批准的例外。
178
- - worktree 只隔离工作区,端口和数据库是共用的。
179
- - `resume_codex_worker` 不会再建 goal。`cancel_codex_worker` 跨进程靠 pid,要求那个 pid 的命令行里带 `codex`。
180
-
181
- 收尾先 `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和证明不了的一律不删。
182
-
183
- ## 看板
184
-
185
- 用户想用眼睛看就让他起 `codex-supervisor-web`(或 `npx -p codex-supervisor-mcp codex-supervisor-web`),开 `http://127.0.0.1:7877`。按 session 分组,每路有「旁问」tab,用户可以自己问 worker。
186
-
187
- 安装后没工具:先查Claude/Codex的mcp get codex-supervisor;运行codex-supervisor-setup修复本包旧入口,手动失败非0,skill写入失败仍尝试注册。CLI不在PATH设CLAUDE_BIN/CODEX_BIN;skill跟随CLAUDE_CONFIG_DIR/CODEX_HOME。禁用安装脚本时不会自动注册,自定义/disabled/project配置保留并提示处理;重开会话加载新工具和skill。
127
+ - worktree 从提交创建。主工作区未提交的依赖不会被 worker 看到,先 commit 或用受控 context。
128
+ - `exit_code: 0` 不等于业务完成;acceptance 和 diff 才是证据。
129
+ - `ownedPaths` 的写冲突在派单时预留。运行时 guard 会拦直接文件写入,land 会再查完整 diff;声明脚本仍可能有清单外副作用,不能把它当完整文件系统沙箱。
130
+ - worktree 只隔离工作目录。端口、数据库、临时目录和其它外部资源仍可能共享。
131
+ - `resume_codex_worker` 不会再次创建 goal。
132
+ - 看板用 `codex-supervisor-web` 打开 `http://127.0.0.1:7877`。看板只观察,不派单、不取消。
133
+ - 安装或升级后要重开会话,MCP 和 skill 才会加载新版本。
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+ import { DEFAULT_ACCEPTANCE_TIMEOUT_MS, runAcceptance } from "./acceptance.js";
3
+ import { getTask } from "./task-store.js";
4
+
5
+ const taskId = process.env.CODEX_SUPERVISOR_TASK_ID;
6
+ if (!taskId) {
7
+ console.error("CODEX_SUPERVISOR_TASK_ID is required");
8
+ process.exit(2);
9
+ }
10
+
11
+ const task = await getTask(taskId);
12
+ if (!task) {
13
+ console.error(`unknown supervisor task: ${taskId}`);
14
+ process.exit(2);
15
+ }
16
+ if (!Array.isArray(task.acceptance) || task.acceptance.length === 0) {
17
+ console.error(`task ${taskId} has no acceptance commands`);
18
+ process.exit(2);
19
+ }
20
+
21
+ const run = Number(process.env.CODEX_SUPERVISOR_RUN);
22
+ const result = await runAcceptance(task.acceptance, {
23
+ cwd: task.worktree_path || task.cwd,
24
+ env: process.env,
25
+ timeoutMs: task.acceptance_timeout_ms ?? DEFAULT_ACCEPTANCE_TIMEOUT_MS,
26
+ run: Number.isInteger(run) && run > 0 ? run : task.run_count,
27
+ taskId,
28
+ baseCommit: process.env.CODEX_SUPERVISOR_BASE_COMMIT || task.base_commit || null
29
+ });
30
+ process.stdout.write(`${JSON.stringify(result)}\n`);
31
+ process.exit(result.passed === true ? 0 : 1);
@@ -190,6 +190,17 @@ function normalizeWorkspaceSetup(value, projectRoot) {
190
190
  return links.length || submodules || commands.length ? { links, submodules, commands } : null;
191
191
  }
192
192
 
193
+ const JS_DEPENDENCY_COMMAND = /(?:^|[\s"'/])(?:npm|pnpm|yarn|npx|vitest|jest|vue-tsc|tsc|eslint|oxlint|nuxi)(?:\s|$)/;
194
+
195
+ function requireDependencySetup({ kind, projectRoot, setup, commands }) {
196
+ if (kind !== "git_worktree" || setup || !existsSync(join(projectRoot, "package.json"))) return;
197
+ const commandText = (commands ?? []).map((check) => typeof check === "string" ? check : check?.command).filter(Boolean).join("\n");
198
+ if (!JS_DEPENDENCY_COMMAND.test(commandText)) return;
199
+ const error = new Error("workspace_setup_required: this JavaScript acceptance uses local project tooling, but the new worktree has no node_modules or generated prepare files; pass workspaceSetup with dependency links and prepare commands (the same setup must be used by preflight)");
200
+ error.code = "workspace_setup_required";
201
+ throw error;
202
+ }
203
+
193
204
  async function prepareWorktreeWorkspace(setup, projectRoot, worktreePath, taskId) {
194
205
  if (!setup) return;
195
206
  for (const link of setup.links) {
@@ -377,10 +388,12 @@ async function trackRunInHost({ record, args, prompt, logPath, spawnOptions = {}
377
388
  // This CLI writes only data/stages/<this task>.json. It is part of the
378
389
  // runtime contract, not an ad-hoc command the model must declare. The
379
390
  // task id comes from the injected environment; stage.js has no override.
380
- 'node "$CODEX_SUPERVISOR_STAGE_CLI"*'
391
+ 'node "$CODEX_SUPERVISOR_STAGE_CLI"*',
392
+ 'node "$CODEX_SUPERVISOR_ACCEPTANCE_CLI"*'
381
393
  ] };
382
394
  const guard = fileURLToPath(new URL("./tool-guard.js", import.meta.url));
383
395
  const stageCli = fileURLToPath(new URL("./stage.js", import.meta.url));
396
+ const acceptanceCli = fileURLToPath(new URL("./acceptance-cli.js", import.meta.url));
384
397
  const quoteCommand = (path) => process.platform === "win32" ? `"${path.replace(/"/g, '""')}"` : `'${path.replace(/'/g, "'\\''")}'`;
385
398
  const hookCommand = `${quoteCommand(process.execPath)} ${quoteCommand(guard)}`;
386
399
  const configArgs = ["--output-schema", workerReportSchemaPath, "--dangerously-bypass-hook-trust", "-c",
@@ -407,6 +420,7 @@ async function trackRunInHost({ record, args, prompt, logPath, spawnOptions = {}
407
420
  env: withWorkerToolPath({ ...process.env, NO_COLOR: "1", CODEX_SUPERVISOR_TASK_ID: record.id,
408
421
  CODEX_SUPERVISOR_BASE_COMMIT: record.base_commit ?? "",
409
422
  CODEX_SUPERVISOR_STAGE_CLI: stageCli,
423
+ CODEX_SUPERVISOR_ACCEPTANCE_CLI: acceptanceCli,
410
424
  CODEX_SUPERVISOR_RUN: String((record.run_count ?? 0) + 1), CODEX_SUPERVISOR_GUARD_POLICY: JSON.stringify(guardPolicy) }),
411
425
  windowsHide: true,
412
426
  ...spawnOptions
@@ -648,9 +662,12 @@ async function trackRunInHost({ record, args, prompt, logPath, spawnOptions = {}
648
662
  if (next.attention_reason === "two_stall") next.current_action = "No progress in two consecutive runs; needs attention";
649
663
  }
650
664
  if (status === "completed" && !next.run_evidence.structured_report.valid && !live.guard_policy?.preflight) {
651
- next.status = "failed";
665
+ // The report is a summary, not the business result. Keep the completed
666
+ // lifecycle and let acceptance plus the reviewed diff decide whether it
667
+ // can land; a report-only recovery can still repair the summary.
652
668
  next.attention_reason = "invalid_report";
653
669
  next.error = `Invalid final worker report: ${next.run_evidence.structured_report.error}`;
670
+ next.current_action = "Work completed, but the final report is invalid; acceptance and diff remain authoritative";
654
671
  }
655
672
 
656
673
  // Acceptance runs after the worker is gone, in two writes. The first
@@ -977,6 +994,8 @@ export async function createCodexWorker({
977
994
  throw error;
978
995
  }
979
996
  const combinedAcceptance = normalizeAcceptance([...(session?.default_acceptance ?? []), ...(acceptanceCommands ?? [])]);
997
+ requireDependencySetup({ kind: workspace.kind, projectRoot, setup: normalizedWorkspaceSetup,
998
+ commands: [...(combinedAcceptance ?? []), ...(preflight?.probeCommands ?? [])] });
980
999
 
981
1000
  const worktree = workspace.kind === "git_worktree"
982
1001
  ? await withWorktreeCreationLock(projectRoot, () => ensureWorktree(projectRoot, id, baseRef))
package/src/mcp-server.js CHANGED
@@ -773,7 +773,7 @@ server.registerTool(
773
773
  {
774
774
  title: "Create Codex worker",
775
775
  description:
776
- "Launch a Codex CLI worker with codex exec --json and track its events. workspaceKind controls where it runs: Git work writes only in an isolated git_worktree; read_only_in_place cannot write or use network; scratch writes only under SUPERVISOR_HOME and never lands; in_place_write is only for an explicitly authorized non-Git directory with ownedPaths and acceptance. A non-Git worker may never write the user directory by default. ownedPaths reserves files a landable worker may write; reading is never exclusive. acceptance is the list of shell commands that decide whether the work is done: the supervisor runs them after Codex exits. The worker's sandbox may write its execution directory, the temp directory and the OS cache directory; a toolchain whose cache lives elsewhere needs writableRoots, a list of existing absolute directories.",
776
+ "Launch a Codex CLI worker with codex exec --json and track its events. workspaceKind controls where it runs: Git work writes only in an isolated git_worktree; read_only_in_place cannot write or use network; scratch writes only under SUPERVISOR_HOME and never lands; in_place_write is only for an explicitly authorized non-Git directory with ownedPaths and acceptance. A non-Git worker may never write the user directory by default. ownedPaths reserves files a landable worker may write; reading is never exclusive. acceptance is the list of shell commands that decide whether the work is done: the supervisor runs them after Codex exits, and workers run the same contract with codex-supervisor-accept. In a Git package project, acceptance using local JavaScript tooling requires workspaceSetup so node_modules and generated prepare files exist before dispatch. The worker's sandbox may write its execution directory, the temp directory and the OS cache directory; a toolchain whose cache lives elsewhere needs writableRoots, a list of existing absolute directories.",
777
777
  inputSchema: {
778
778
  title: z.string().optional(),
779
779
  task: z.string().min(1),
@@ -1842,7 +1842,7 @@ server.registerTool(
1842
1842
  {
1843
1843
  title: "Land a worker's commits",
1844
1844
  description:
1845
- "Cherry-pick the commits a worker made on its codex/<taskId> branch onto the current branch of the directory it was dispatched from. The target must be clean and is never switched to another branch; `onto` is a guard that names the branch you expect to be on. A conflict aborts the cherry-pick, lists the files, and leaves the target as it was. A worker in the workspace-write sandbox cannot commit (Codex keeps .git read-only there): pass commitMessage and its uncommitted edits are committed as one commit on its branch first, then landed. Without commitMessage uncommitted edits are reported, not landed. Check the work first with get_worker_result and get_worker_diff; land once it passes. Refuses with acceptance_failed while the worker's last acceptance run failed (and acceptance_not_run while one is running or was interrupted): resume it with the failing output, land once it passes. ignoreAcceptance: true lands anyway; use it only when the user said to land regardless.",
1845
+ "Cherry-pick the commits a worker made on its codex/<taskId> branch onto the current branch of the directory it was dispatched from. The target must be clean and is never switched to another branch; `onto` is a guard that names the branch you expect to be on. A conflict aborts the cherry-pick, lists the files, and leaves the target as it was. A worker in the workspace-write sandbox cannot commit (Codex keeps .git read-only there): pass commitMessage and its uncommitted edits are committed as one commit on its branch first, then landed. Without commitMessage uncommitted edits are reported, not landed. Check the work first with get_worker_result and get_worker_diff; land once it passes. A malformed report summary is attention, not a separate landing veto when the same run's acceptance passed and the reviewed diff is sound. Refuses with acceptance_failed while the worker's last acceptance run failed (and acceptance_not_run while one is running or was interrupted): resume it with the failing output, land once it passes. ignoreAcceptance: true lands anyway; use it only when the user said to land regardless.",
1846
1846
  inputSchema: {
1847
1847
  task_id: z.string().min(1),
1848
1848
  onto: z.string().min(1).optional(),
@@ -1858,7 +1858,6 @@ server.registerTool(
1858
1858
  return textResult({ error: "workspace_kind_not_landable", task_id, workspace_kind: task.workspace_kind, reason: `${task.workspace_kind} does not create a Git worktree and cannot be landed` });
1859
1859
  }
1860
1860
  const session = task.session_id ? await getSession(task.session_id) : null;
1861
- if (task.attention_reason === "invalid_report") return textResult({ error: "invalid_report", task_id, reason: task.error });
1862
1861
  if (!isSettled(task)) return textResult({ error: "worker_active", task_id, reason: "wait for this run and acceptance to settle before landing" });
1863
1862
  if (session?.approval_state === "waiting_user") return textResult({ error: "session_waiting_user", task_id, reason: "session requires user approval before landing" });
1864
1863
  if (session && task.session_policy_revision !== session.policy_revision) return textResult({ error: "session_policy_stale", task_id, current_revision: session.policy_revision, checked_revision: task.session_policy_revision, reason: "requirements changed; resume with the current objective and rerun acceptance before landing" });
package/src/prompt.js CHANGED
@@ -93,13 +93,15 @@ export function buildGuardPreamble({ sandbox, ownedPaths = [], allowedCommands =
93
93
  export function buildAcceptanceBlock(acceptance, { resume = false } = {}) {
94
94
  const commands = Array.isArray(acceptance) ? acceptance.filter(Boolean) : [];
95
95
  if (commands.length === 0) return "";
96
+ const runner = 'Run node "$CODEX_SUPERVISOR_ACCEPTANCE_CLI" to execute this exact contract through the supervisor\'s non-interactive Bash with errexit and pipefail. Do not retype the commands in zsh; the interactive shell is not the acceptance shell.';
96
97
  if (resume) {
97
- return `Acceptance is unchanged; run it before you report: ${commands.map((check) => typeof check === "string" ? check : JSON.stringify(check)).join(" ; ")}`;
98
+ return ["Acceptance is unchanged.", runner, `Commands: ${commands.map((check) => typeof check === "string" ? check : JSON.stringify(check)).join(" ; ")}`].join("\n");
98
99
  }
99
100
  return [
100
101
  "Acceptance: when you exit, the supervisor runs these commands in this directory and each must exit 0:",
101
102
  ...commands.map((command) => `- ${typeof command === "string" ? command : JSON.stringify(command)}`),
102
- "Run them yourself before you report and put their exit codes under Verification. Do not edit what they test to make them pass; if a check is wrong, say why under Not done / risks."
103
+ runner,
104
+ "Run that contract before you report and put its exit code and key evidence under Verification. Do not edit what it tests to make it pass; if a check is wrong, say why under Not done / risks."
103
105
  ].join("\n");
104
106
  }
105
107
 
package/src/task-store.js CHANGED
@@ -654,6 +654,21 @@ async function reconcileInterruptedAcceptance() {
654
654
  && !isPidAlive(task.acceptance_results.supervisor_pid));
655
655
  for (const task of interrupted) {
656
656
  const now = new Date().toISOString();
657
+ const durable = (await readTaskEvents(task.id, 1, ["supervisor.acceptance"]))[0] ?? null;
658
+ if (durable && durable.run === task.run_count) {
659
+ const reportInvalid = task.attention_reason === "invalid_report";
660
+ await writeTask({
661
+ ...task,
662
+ status: reportInvalid ? "completed" : task.status,
663
+ exit_code: task.exit_code ?? (reportInvalid ? 0 : null),
664
+ acceptance_results: durable,
665
+ current_action: durable.passed === true
666
+ ? "Acceptance passed (recovered from the durable event)"
667
+ : `Acceptance ${durable.status} (recovered from the durable event)`,
668
+ updated_at: now
669
+ });
670
+ continue;
671
+ }
657
672
  await writeTask({
658
673
  ...task,
659
674
  acceptance_results: { ...task.acceptance_results, status: "interrupted", passed: null, finished_at: now },
@@ -19,19 +19,54 @@ function reportCandidates(text) {
19
19
  return candidates;
20
20
  }
21
21
 
22
+ function validateReport(value) {
23
+ if (!value || typeof value !== "object" || Array.isArray(value)) return { valid: false, error: "report must be a JSON object" };
24
+ if (Object.keys(value).sort().join(",") !== "not_done,result,verification") {
25
+ return { valid: false, error: "report must contain result:string, verification:string[], not_done:string[] only" };
26
+ }
27
+ if (typeof value.result !== "string") return { valid: false, error: "report.result must be a string" };
28
+ const repaired = [];
29
+ const normalized = { ...value };
30
+ for (const field of ["verification", "not_done"]) {
31
+ if (typeof value[field] === "string") {
32
+ normalized[field] = [value[field]];
33
+ repaired.push(`${field}_string`);
34
+ }
35
+ if (!Array.isArray(normalized[field]) || !normalized[field].every((entry) => typeof entry === "string")) {
36
+ return { valid: false, error: `report.${field} must be a string or string[]` };
37
+ }
38
+ }
39
+ return { valid: true, report: normalized, repaired };
40
+ }
41
+
42
+ function parseWithClosure(candidate) {
43
+ try { return { value: JSON.parse(candidate), repair: null }; } catch (error) {
44
+ const parsedError = error;
45
+ const attempts = [
46
+ [candidate, "}", "closed_object"],
47
+ [candidate, "]", "closed_array"]
48
+ ];
49
+ if (candidate.endsWith("}")) {
50
+ const body = candidate.slice(0, -1);
51
+ attempts.push([body, "]}", "closed_array"]);
52
+ }
53
+ for (const [body, suffix, repair] of attempts) {
54
+ try { return { value: JSON.parse(body + suffix), repair }; } catch { /* try the next bounded repair */ }
55
+ }
56
+ return { value: null, repair: null, error: parsedError };
57
+ }
58
+ }
59
+
22
60
  export function parseWorkerReport(text) {
23
61
  if (typeof text !== "string" || !text.trim()) return { format: "json_schema", valid: false, error: "worker wrote no final report" };
24
62
  let parseError = null;
25
63
  for (const { source, text: candidate } of reportCandidates(text)) {
26
- let value;
27
- try { value = JSON.parse(candidate); }
28
- catch (error) { parseError = parseError ?? error; continue; }
29
- const valid = value && typeof value === "object" && !Array.isArray(value)
30
- && Object.keys(value).sort().join(",") === "not_done,result,verification"
31
- && typeof value.result === "string" && Array.isArray(value.verification) && Array.isArray(value.not_done)
32
- && [...value.verification, ...value.not_done].every((entry) => typeof entry === "string");
33
- if (!valid) return { format: "json_schema", valid: false, error: "report must contain result:string, verification:string[], not_done:string[] only" };
34
- return { format: "json_schema", valid: true, report: value, ...(source === "bare" ? {} : { repaired: source }) };
64
+ const parsed = parseWithClosure(candidate);
65
+ if (parsed.error) { parseError = parseError ?? parsed.error; continue; }
66
+ const checked = validateReport(parsed.value);
67
+ if (!checked.valid) return { format: "json_schema", valid: false, error: checked.error };
68
+ const repairs = [source === "bare" ? null : source, parsed.repair, ...checked.repaired].filter(Boolean);
69
+ return { format: "json_schema", valid: true, report: checked.report, ...(repairs.length ? { repaired: repairs.join("+") } : {}) };
35
70
  }
36
71
  return { format: "json_schema", valid: false, error: parseError?.message ?? "report is not JSON" };
37
72
  }