codex-supervisor-mcp 0.7.3 → 0.9.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 +51 -17
- package/README.md +51 -17
- package/package.json +10 -1
- package/skills/codex-supervisor/SKILL.md +43 -11
- package/src/acceptance-baseline.js +64 -0
- package/src/acceptance.js +264 -0
- package/src/cleanup.js +66 -19
- package/src/codex-runner.js +410 -31
- package/src/event-parser.js +68 -10
- package/src/external-output.js +29 -0
- package/src/goal-store.js +10 -7
- package/src/handoff.js +31 -0
- package/src/landing.js +247 -5
- package/src/mcp-server.js +326 -40
- package/src/owned-changes.js +27 -0
- package/src/prompt.js +80 -7
- package/src/status.js +1 -1
- package/src/task-store.js +195 -9
- package/src/tool-guard.js +66 -0
- package/src/truncate.js +13 -0
- package/src/web-app.js +4 -1
- package/src/worker-changes.js +38 -0
- package/src/worker-report.js +15 -0
- package/src/worker-report.schema.json +10 -0
- package/src/worktree.js +53 -1
- package/web/dist/assets/{index-CqG_XY9n.js → index-fJQbspTY.js} +1 -1
- package/web/dist/index.html +1 -1
package/README.en.md
CHANGED
|
@@ -23,6 +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 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 |
|
|
26
27
|
| Worker output floods the main thread | Events go to `data/runs/<taskId>.jsonl`; reads are gated by `limit` / `maxChars` / `kinds` |
|
|
27
28
|
| One status read fills the context | `get_orchestration_overview` fits every worker into 7000 bytes |
|
|
28
29
|
| Nobody knows who is still running after a restart | `supervisor.sqlite`, one row per work, with `thread_id` |
|
|
@@ -62,7 +63,7 @@ What the main thread does underneath (you can call the tools yourself):
|
|
|
62
63
|
```
|
|
63
64
|
create_codex_worker ×3 each with session_id, session_title, ownedPaths, goal
|
|
64
65
|
wait_codex_workers two minutes by default, then a snapshot, call again until done
|
|
65
|
-
get_worker_result ×3 each worker's
|
|
66
|
+
get_worker_result ×3 each worker's report, with the commands it really ran
|
|
66
67
|
```
|
|
67
68
|
|
|
68
69
|
Each worker's changes sit on its own `codex/<taskId>` branch; whether and how to merge is the main thread's call.
|
|
@@ -101,6 +102,7 @@ One block of text passes between the two sessions, pasted into the main-brain se
|
|
|
101
102
|
One session_id for the whole batch
|
|
102
103
|
Serial when steps touch the same files, parallel only when ownedPaths do not overlap
|
|
103
104
|
One worker per step. Write the task in full: background, where in the docs, files to change, verify command, output format
|
|
105
|
+
Put the verify command in acceptance too; the supervisor runs it, the worker's word does not count
|
|
104
106
|
Read the diff when a worker returns. Its word is not enough; what you see is
|
|
105
107
|
[Build/test] Everything on the remote machine, nothing locally
|
|
106
108
|
[Red lines] What not to change, push or read
|
|
@@ -114,14 +116,16 @@ What the main brain calls in one round:
|
|
|
114
116
|
search_works has this batch been dispatched before
|
|
115
117
|
create_codex_worker one worker per step, same session_id, ownedPaths disjoint
|
|
116
118
|
wait_codex_workers two minutes a round, compact: true, call again until done
|
|
117
|
-
get_worker_result what it says it did
|
|
119
|
+
get_worker_result what it says it did; verification is what it really ran
|
|
118
120
|
get_worker_diff what it actually did
|
|
119
121
|
ask_codex_worker when the two differ, ask why; read-only, its thread untouched
|
|
120
|
-
resume_codex_worker when it must change something, one follow-up, amended into the same commit
|
|
122
|
+
resume_codex_worker when it must change something, one follow-up, amended into the same commit; rebaseOnto when main has moved
|
|
121
123
|
land_codex_worker checked, then landed on the integration branch
|
|
122
124
|
```
|
|
123
125
|
|
|
124
|
-
The last block was 25 steps
|
|
126
|
+
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.
|
|
127
|
+
|
|
128
|
+
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.
|
|
125
129
|
|
|
126
130
|
## What the board shows
|
|
127
131
|
|
|
@@ -137,32 +141,62 @@ Light and dark follow the system. No external resources.
|
|
|
137
141
|
|
|
138
142
|
## Tools
|
|
139
143
|
|
|
140
|
-
|
|
144
|
+
Twenty-one.
|
|
141
145
|
|
|
142
146
|
| Tool | Arguments | What it does |
|
|
143
147
|
|---|---|---|
|
|
144
|
-
| `
|
|
148
|
+
| `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 |
|
|
149
|
+
| `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 |
|
|
150
|
+
| `create_codex_worker` | `task`, `cwd`, **`ownedPaths`**, **`goal`**, `forbid`, `allowedCommands`, `context`, `contracts`, `externalOutputs`, `networkAccess`, `maxRunMs`, `maxTotalMs`, `acceptance`, `session_id`, `session_title`, `session_note`, `dependsOn`, `baseRef`, `sandbox`, `model`, `reasoningEffort`, `title`, `skipGitRepoCheck` | Start a worker. `acceptance` lists the commands the supervisor runs in the worktree once the worker exits; exit 0 on every one passes. `baseRef` picks the commit the worktree is cut from (default `HEAD`); pass another worker's `codex/<id>` to build on it |
|
|
145
151
|
| `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 |
|
|
146
|
-
| `resume_codex_worker` | `task_id`, `prompt` | Continue the same Codex conversation; `thread_id` stays |
|
|
147
|
-
| `wait_codex_workers` | `task_ids`, `mode` (any/all), `timeoutMinutes`, `timeoutMs`, `compact`, `includeEvents`, `eventLimit`, `eventMaxChars`, `eventKinds` | Wait for terminal states. Two minutes by default, then a snapshot while the workers keep running; `compact` returns one line per worker |
|
|
152
|
+
| `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 |
|
|
153
|
+
| `wait_codex_workers` | `task_ids`, `mode` (any/all), `timeoutMinutes`, `timeoutMs`, `compact`, `includeEvents`, `eventLimit`, `eventMaxChars`, `eventKinds` | Wait for terminal states. Two minutes 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 |
|
|
148
154
|
| `get_orchestration_overview` | `status`, `limit` | Every worker in one table, capped at 7000 bytes. Carries `version` and `update` |
|
|
149
|
-
| `get_worker_result` | `task_id`, `limit`, `maxChars` | The worker's own
|
|
155
|
+
| `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 |
|
|
150
156
|
| `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 |
|
|
151
157
|
| `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 |
|
|
152
|
-
| `land_codex_worker` | `task_id`, `onto`, `commitMessage` | Cherry-pick the worker's `codex/<id>` commits onto the current branch of the directory
|
|
158
|
+
| `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 |
|
|
153
159
|
| `get_worker_summary` | `task_id` | One paragraph: goal, status, changes, last command and message |
|
|
154
160
|
| `get_codex_worker_status` | `task_id`, `includePrompt`, `promptMaxChars` | One worker in detail |
|
|
155
161
|
| `get_codex_worker_events` | `task_id`, `limit`, `maxChars`, `kinds` | The raw event stream |
|
|
156
162
|
| `get_worker_goal` | `task_id` | The goal recorded at dispatch plus the native Codex goal (tokens, time) |
|
|
157
163
|
| `list_codex_workers` | `status`, `includeHistory`, `includeDetails` | List workers, active ones by default |
|
|
158
164
|
| `get_session_works` | `session_id` | Every worker of one session. The way back after a main-thread restart |
|
|
159
|
-
| `describe_session` | `session_id`, `title`, `note` | Record a title and note for a session |
|
|
165
|
+
| `describe_session` | `session_id`, `title`, `note`, `objective`, `default_acceptance`, `approval_state`, `expected_revision` | Record a title and note for a session |
|
|
160
166
|
| `search_works` | `query`, `limit` | Substring search over title / goal / prompt / last_message, newest first |
|
|
161
167
|
| `check_for_update` | `force` | Ask the registry for a newer version |
|
|
162
168
|
| `cancel_codex_worker` | `task_id` | Stop a worker. Falls back to the pid across processes, after confirming that pid runs codex |
|
|
163
169
|
|
|
164
170
|
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.
|
|
165
171
|
|
|
172
|
+
`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.
|
|
173
|
+
|
|
174
|
+
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.
|
|
175
|
+
|
|
176
|
+
Structured acceptance entries use `{command, reportPath, baseline}`. The baseline contains `identity.base_commit`, `failures` (test_id/kind/signature), and `required`; the report contains complete, identity, failures, executed, skipped, and the current `CODEX_SUPERVISOR_CHECK_ID`. Missing/skipped required tests, reused evidence, and changed failures reject acceptance while preserving the shell exit code. reportPath must remain inside the working directory; write reports to an ignored temporary directory so they are not landed.
|
|
177
|
+
|
|
178
|
+
Landing checks the real diff against ownedPaths before committing drafts; only use allowOutsideOwned for an explicitly approved exception.
|
|
179
|
+
|
|
180
|
+
Session default_acceptance is prepended to local checks; resume uses the latest policy. describe_session returns policy_revision and expected_revision prevents stale edits. waiting_user blocks dispatch/resume until approved. host_goal_sync returns a current-policy /goal command. Replace an active native goal through /goal, or propose the same condition through ProposeGoal for host approval when available. The condition reads the latest session revision and approved scope; MCP does not silently modify or disable the host Stop hook.
|
|
181
|
+
|
|
182
|
+
Wait defaults to 60 seconds and compact rows; includeEvents selects details unless compact is explicit. Clients supplying a progress token receive notifications every 30 seconds. MCP SDK and real Claude 2.1.299 are verified: a 65-second wait succeeds with a 35-second idle timeout after three progress notifications. Native /loop scheduling is also verified.
|
|
183
|
+
|
|
184
|
+
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.
|
|
185
|
+
|
|
186
|
+
After reconciliation, check_workers atomically resumes a dead first lost/no_work run once and returns recovery receipts. A second failure remains actionable; 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.
|
|
187
|
+
|
|
188
|
+
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.
|
|
189
|
+
|
|
190
|
+
Declare externalOutputs:[{path,sha256?}] and acceptance for shared writes. Targets are absolute file paths, at most 1 MB each. Current-run before/after hashes and bounded content appear in result/diff as shared_file_already_written_not_cherry_pick; land cannot integrate external files. Targets participate in ownership conflict checks and hook policy; the dispatcher is responsible for validation script side effects.
|
|
191
|
+
|
|
192
|
+
workspace-write defaults to networkAccess:false; explicitly enable it for ssh/network checks. Resume/follow-up inherit the setting. maxRunMs bounds one run and maxTotalMs bounds wall time since dispatch; exceeding either stops the worker and preserves actionable partial results without automatic retry. A wait budget does not change these quotas.
|
|
193
|
+
|
|
194
|
+
Dispatch checks required hooks/output-schema support (Codex 0.162+); unsupported capability returns settled start_failed. get_worker_goal.native_goal_read distinguishes missing_goal, missing_database, locked and read_error; a read failure is not evidence that no goal exists. Native budget/usage limits need attention. Cleanup preserves ignored artifacts, shared evidence and unresolved attention.
|
|
195
|
+
|
|
196
|
+
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.
|
|
197
|
+
|
|
198
|
+
Cleanup previews by default: `npm run cleanup -- --dry-run`. `--apply` removes only integrated, clean completed worktrees with no active dependents and verified Git registration/ownership. Dirty, unlanded, lost/failed or unproven work is preserved with a reason.
|
|
199
|
+
|
|
166
200
|
## How this differs from Claude Code subagents
|
|
167
201
|
|
|
168
202
|
File isolation is not the difference: a subagent can open a worktree too. The difference is the model and the process.
|
|
@@ -172,7 +206,7 @@ File isolation is not the difference: a subagent can open a worktree too. The di
|
|
|
172
206
|
| Model | Claude only | `model` passed to the Codex CLI; DeepSeek works |
|
|
173
207
|
| Who does the work | Claude Code itself | A separate `codex exec` process |
|
|
174
208
|
| Two writers on one file | Worktrees keep them apart, no path declaration | `ownedPaths` overlap is refused before dispatch |
|
|
175
|
-
| Main-thread process dies |
|
|
209
|
+
| Main-thread process dies | The main window cannot collect results | An independent run process records worker output and acceptance; a new window reads the same session_id |
|
|
176
210
|
| Who can drive it | Claude Code only | Any MCP client |
|
|
177
211
|
| Seeing the process | Only the returned conclusion | Raw JSONL and the web board |
|
|
178
212
|
|
|
@@ -185,7 +219,7 @@ File isolation is not the difference: a subagent can open a worktree too. The di
|
|
|
185
219
|
| `completed` | Done |
|
|
186
220
|
| `failed` | Non-zero exit, `turn.failed`, spawn failure |
|
|
187
221
|
| `cancelled` | Stopped by `cancel_codex_worker` |
|
|
188
|
-
| `lost` |
|
|
222
|
+
| `lost` | Worker killed by an outside signal, run process disappeared, or a row whose process never started. `resume_codex_worker` picks it up |
|
|
189
223
|
|
|
190
224
|
A terminal state lands in two steps: `turn.completed` sets `completed`, the process exit writes `exit_code`; `wait_codex_workers` returns only after the exit code is in. Windows has no signals, so an outside kill reports as `failed` with an exit code. Native Codex goals: `paused` / `blocked` count as `running` and go to `needs_attention`, `usageLimited` / `budgetLimited` as `failed`.
|
|
191
225
|
|
|
@@ -262,7 +296,7 @@ rm -rf ~/.claude/skills/codex-supervisor ~/.agents/skills/codex-supervisor ~/.co
|
|
|
262
296
|
| Dispatch says `codex only resolved to a shell shim` | Windows found only the `.cmd`; the package entry behind it is gone | Reinstall `@openai/codex`, or point `CODEX_BIN` at `codex.js` |
|
|
263
297
|
| Worker `failed` at once with `spawn codex ENOENT` | No codex on the process `PATH` | Set `CODEX_BIN` in the config |
|
|
264
298
|
| `Cannot find module 'node:sqlite'` | Node older than 22.13.0 | Upgrade Node |
|
|
265
|
-
| Worker `lost` | The
|
|
299
|
+
| Worker `lost` | The worker or independent run process was interrupted | Inspect events, then `resume_codex_worker` |
|
|
266
300
|
| 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` |
|
|
267
301
|
| `ownedPaths overlap with active worker(s)` | Two workers claimed the same paths | Split differently, or cancel the one holding them |
|
|
268
302
|
| 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` |
|
|
@@ -270,12 +304,12 @@ rm -rf ~/.claude/skills/codex-supervisor ~/.agents/skills/codex-supervisor ~/.co
|
|
|
270
304
|
|
|
271
305
|
## Known limitations
|
|
272
306
|
|
|
273
|
-
-
|
|
307
|
+
- 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.
|
|
274
308
|
- 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`.
|
|
275
309
|
- The worktree is cut from a commit; uncommitted work in your checkout is not in it.
|
|
276
310
|
- Only the working directory is isolated. Temp directories, databases and ports are shared.
|
|
277
311
|
- `ownedPaths` is checked at dispatch only; it does not stop a worker from creating files outside its list. Read the diff.
|
|
278
|
-
-
|
|
312
|
+
- 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.
|
|
279
313
|
- One `wait_codex_workers` cannot wait to the end; the client's MCP tool timeout is a hard wall. Call it again.
|
|
280
314
|
- `search_works` is substring matching, fine for hundreds of works.
|
|
281
315
|
|
|
@@ -283,7 +317,7 @@ rm -rf ~/.claude/skills/codex-supervisor ~/.agents/skills/codex-supervisor ~/.co
|
|
|
283
317
|
|
|
284
318
|
Done: `CODEX_BIN` / `SUPERVISOR_HOME` / `GIT_BIN`; `status` and `phase` split; `ownedPaths` / `goal` / `dependsOn`; `thread_id` on disk + `resume_codex_worker`; concurrency and multi-process writes; `session_id`, `search_works`, native goals; Windows; the web board; `baseRef`; collecting work with `get_worker_diff` / `ask_codex_worker` / `land_codex_worker`; background auto-update.
|
|
285
319
|
|
|
286
|
-
|
|
320
|
+
Run lifetime is independent of MCP; each run process exits after settlement without a global resident daemon.
|
|
287
321
|
|
|
288
322
|
Not planned: vector search (substring matching is faster at this scale and costs nothing to maintain), `usage_count` ordering (2 of 80 real works were ever referenced again).
|
|
289
323
|
|
package/README.md
CHANGED
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
| 进程重启后不知道谁还在跑 | `supervisor.sqlite` 一行一个 work,带 `thread_id` |
|
|
29
29
|
| 换个会话接不上之前的 worker | `resume_codex_worker` 走 `codex exec resume <thread_id>`,接的是同一个 Codex 会话 |
|
|
30
30
|
| 分不清「跑失败」和「进程没了」 | 状态机把 `failed` 和 `lost` 分开 |
|
|
31
|
+
| worker 说做完了其实没有 | 派单给 `acceptance` 验收命令,worker 退出后 supervisor 在它的 worktree 里跑,失败 `land` 拒绝 |
|
|
31
32
|
| 看不见一批活现在到哪了 | `codex-supervisor-web` 开一个看板,按 session 看每路 worker 在干什么 |
|
|
32
33
|
|
|
33
34
|
worker 跑的是 `codex exec`,`model` 透传:主线程留在 Claude,worker 可以挂 DeepSeek 或任何 Codex 配了 provider 的模型,账单分开算。
|
|
@@ -62,7 +63,7 @@ codex mcp add codex-supervisor -- npx -y codex-supervisor-mcp
|
|
|
62
63
|
```
|
|
63
64
|
create_codex_worker ×3 每路带 session_id、session_title、ownedPaths、goal
|
|
64
65
|
wait_codex_workers 默认等 2 分钟,到点返回快照,没完就接着等
|
|
65
|
-
get_worker_result ×3
|
|
66
|
+
get_worker_result ×3 收每路的汇报,带它真跑过的命令和退出码
|
|
66
67
|
```
|
|
67
68
|
|
|
68
69
|
每路的改动在各自的 `codex/<taskId>` 分支上,合不合、怎么合由主线程定。
|
|
@@ -101,6 +102,7 @@ npx -p codex-supervisor-mcp codex-supervisor-web
|
|
|
101
102
|
整批用同一个 session_id
|
|
102
103
|
改同一批文件就串行,文件完全不重叠才并行,每路 ownedPaths 写清
|
|
103
104
|
一个 worker 只做一步。task 写全:背景、文档出处、要改的文件、验证命令、输出格式
|
|
105
|
+
验证命令同时填 acceptance,supervisor 替你跑,它说过了不算
|
|
104
106
|
worker 交回来先看 diff。它说过了不算,你看到才算
|
|
105
107
|
【构建和测试】全走远端机器,本机不跑
|
|
106
108
|
【红线】 不改什么,不推什么,不读什么
|
|
@@ -114,14 +116,16 @@ npx -p codex-supervisor-mcp codex-supervisor-web
|
|
|
114
116
|
search_works 查这批活派过没有
|
|
115
117
|
create_codex_worker 一步一个 worker,同一个 session_id,ownedPaths 不重叠
|
|
116
118
|
wait_codex_workers 2 分钟一轮,compact: true,没完接着调
|
|
117
|
-
get_worker_result
|
|
119
|
+
get_worker_result 它说自己做了什么,verification 里是它真跑过的命令
|
|
118
120
|
get_worker_diff 它实际做了什么
|
|
119
121
|
ask_codex_worker 对不上就问它为什么,只读,不动它的线程
|
|
120
|
-
resume_codex_worker 要改就追一条,让它 amend
|
|
122
|
+
resume_codex_worker 要改就追一条,让它 amend 进原来那个提交;主线走远了带 rebaseOnto
|
|
121
123
|
land_codex_worker 核过了,落进集成分支
|
|
122
124
|
```
|
|
123
125
|
|
|
124
|
-
上一块活 25
|
|
126
|
+
上一块活 25 步,主脑会话一个人从第 1 步盯到第 25 步,上下文里只有任务书和每路交回来的汇报,没被 worker 的过程撑爆。
|
|
127
|
+
|
|
128
|
+
为什么一个 worker 只做一步:第 5 步做错了,让做第 5 步的那个 worker `resume_codex_worker` 一下,改完 `--amend` 并回它自己那个提交,主脑再核一次,过了才落进集成分支。要是一个 worker 连做了 5、6、7 三步,第 5 步错了就没法这样改,6 和 7 的提交已经叠在 5 上面,改 5 得连 6、7 一起重做。
|
|
125
129
|
|
|
126
130
|
## 看板里有什么
|
|
127
131
|
|
|
@@ -137,32 +141,62 @@ land_codex_worker 核过了,落进集成分支
|
|
|
137
141
|
|
|
138
142
|
## 工具
|
|
139
143
|
|
|
140
|
-
|
|
144
|
+
21 个。
|
|
141
145
|
|
|
142
146
|
| 工具 | 入参 | 作用 |
|
|
143
147
|
|---|---|---|
|
|
144
|
-
| `
|
|
148
|
+
| `check_workers` | 无参 | 交付新终态、验收失败和需处理goal;新格式第1轮lost/no_work自动恢复一次,未变返回quiet;用宿主定时唤醒调用,每个主线程设独立CODEX_SUPERVISOR_OBSERVER_ID可在重启后接回 |
|
|
149
|
+
| `check_acceptance` | `cwd`, `acceptance`, `baseRef`, `timeoutMs` | 派单前实际运行给定验收命令,不建 worker,不证明 worker 完成;数量 grep 会提示不能证明失败名单和必跑执行 |
|
|
150
|
+
| `create_codex_worker` | `task`, `cwd`, **`ownedPaths`**, **`goal`**, `forbid`, `allowedCommands`, `context`, `contracts`, `externalOutputs`, `networkAccess`, `maxRunMs`, `maxTotalMs`, `acceptance`, `session_id`, `session_title`, `session_note`, `dependsOn`, `baseRef`, `sandbox`, `model`, `reasoningEffort`, `title`, `skipGitRepoCheck` | 起一个 worker。`acceptance` 是验收命令,worker 退出后 supervisor 在它的 worktree 里跑,退出码 0 算过。`baseRef` 指定 worktree 从哪个提交切,默认 `HEAD`,接另一路填它的 `codex/<id>` |
|
|
145
151
|
| `create_codex_followup_worker` | `task_id`, `followup_prompt`, `session_id`, 其余同上 | 开一个新会话,把老 worker 的 prompt、状态、近期事件拼进去 |
|
|
146
|
-
| `resume_codex_worker` | `task_id`, `prompt` | 接同一个 Codex 会话继续跑,`thread_id`
|
|
147
|
-
| `wait_codex_workers` | `task_ids`, `mode`(any/all), `timeoutMinutes`, `timeoutMs`, `compact`, `includeEvents`, `eventLimit`, `eventMaxChars`, `eventKinds` | 等终态。默认 2 分钟,到点带快照返回,worker 照跑;`compact`
|
|
152
|
+
| `resume_codex_worker` | `task_id`, `prompt`, `rebaseOnto`, `acceptance`, `context` | 接同一个 Codex 会话继续跑,`thread_id` 不变。`rebaseOnto` 先把 worktree 挪到主线新头(stash、跳过已合入补丁、重放新增提交、放回),冲突原样退回不起 worker |
|
|
153
|
+
| `wait_codex_workers` | `task_ids`, `mode`(any/all), `timeoutMinutes`, `timeoutMs`, `compact`, `includeEvents`, `eventLimit`, `eventMaxChars`, `eventKinds` | 等终态。默认 2 分钟,到点带快照返回,worker 照跑;`compact` 每路只回一行,带 `idle_seconds` / `command_running`,分得清长命令和卡住 |
|
|
148
154
|
| `get_orchestration_overview` | `status`, `limit` | 全部 worker 的状态表,封顶 7000 字节。带 `version` 和 `update` |
|
|
149
|
-
| `get_worker_result` | `task_id`, `limit`, `maxChars` | worker
|
|
155
|
+
| `get_worker_result` | `task_id`, `limit`, `maxChars`, `includeFiles` | worker 自己的汇报,默认截 6000 字节、`truncated` 提示读全。`acceptance` 是 supervisor 替你跑的验收过没过,`verification` 是它自己跑过的命令和退出码,`base_behind` 是主线走了多远 |
|
|
150
156
|
| `get_worker_diff` | `task_id`, `maxChars`, `paths` | worker 实际改了什么:从 worktree 起点到工作区的 patch,提交没提交都算。`maxChars` 管总量,超了的文件只列名 |
|
|
151
157
|
| `ask_codex_worker` | `task_id`, `question`, `timeoutMs`, `maxChars`, `fresh`, `end` | 旁路问 worker 一句。线程 fork 成只读侧会话,没网络、没 MCP 工具,worker 本身不动。worker 被 resume 过会自动换新 fork,`fresh` 强制换,`end` 删 |
|
|
152
|
-
| `land_codex_worker` | `task_id`, `onto`, `commitMessage` | 把 worker 在 `codex/<id>` 上的提交 cherry-pick
|
|
158
|
+
| `land_codex_worker` | `task_id`, `onto`, `commitMessage`, `ignoreAcceptance`, `allowOutsideOwned` | 把 worker 在 `codex/<id>` 上的提交 cherry-pick 到派单目录的当前分支。目标要干净,冲突回滚,验收 `failed` 拒绝。`commitMessage` 先替它把未提交的改动提交成一笔,`ignoreAcceptance` 放行 |
|
|
153
159
|
| `get_worker_summary` | `task_id` | 一段话:goal、状态、改动、最后一条命令和消息 |
|
|
154
160
|
| `get_codex_worker_status` | `task_id`, `includePrompt`, `promptMaxChars` | 单个 worker 的状态细节 |
|
|
155
161
|
| `get_codex_worker_events` | `task_id`, `limit`, `maxChars`, `kinds` | 原始事件流 |
|
|
156
162
|
| `get_worker_goal` | `task_id` | 派单时记的 goal + Codex 原生 goal(token、用时) |
|
|
157
163
|
| `list_codex_workers` | `status`, `includeHistory`, `includeDetails` | 列 worker,默认只看在跑的 |
|
|
158
164
|
| `get_session_works` | `session_id` | 一个 session 的全部 worker。主线程重启后靠它找回那批活 |
|
|
159
|
-
| `describe_session` | `session_id`, `title`, `note` | 给 session 记标题和说明 |
|
|
165
|
+
| `describe_session` | `session_id`, `title`, `note`, `objective`, `default_acceptance`, `approval_state`, `expected_revision` | 给 session 记标题和说明 |
|
|
160
166
|
| `search_works` | `query`, `limit` | 在 title / goal / prompt / last_message 里找子串,从新到旧 |
|
|
161
167
|
| `check_for_update` | `force` | 问 registry 有没有新版本 |
|
|
162
168
|
| `cancel_codex_worker` | `task_id` | 终止 worker。跨进程按 pid 兜底,先确认那个 pid 跑的是 codex |
|
|
163
169
|
|
|
164
170
|
必填的两个:`ownedPaths`(派单前和在跑的 worker 求交集,重叠就拒,只在派单时查)和 `goal.objective`(worker 会建成 Codex 原生 goal)。`session_id` 不传就归不了组,一批活传同一个值。
|
|
165
171
|
|
|
172
|
+
`acceptance` 在 Bash 中启用 `errexit` 和 `pipefail`:未处理的失败会停止检查,`npm test | tail` 中的测试失败也会保留。预期失败用 `if` 或 `||` 显式处理;超时始终判失败,即使命令收到终止信号后退出 0。Windows 需要 Git for Windows 的 Bash;找不到会报错。显示的输出会裁剪,退出码不会因此改变。
|
|
173
|
+
|
|
174
|
+
验收命令的环境包含 `CODEX_SUPERVISOR_TASK_ID`、`CODEX_SUPERVISOR_BASE_COMMIT` 和 `CODEX_SUPERVISOR_RUN`;分别是当前任务、当前运行基线和运行次数,rebase/resume 后会更新。
|
|
175
|
+
|
|
176
|
+
结构化验收项用 `{command, reportPath, baseline}`。baseline 包含 `identity.base_commit`、`failures`(test_id/kind/signature)和 `required`;报告包含 complete、identity、failures、executed、skipped,以及本次 `CODEX_SUPERVISOR_CHECK_ID`。必跑用例缺失/跳过、旧报告、失败名单变化都拒绝通过,原始退出码保留。reportPath 必须在工作目录内;测试报告可能写文件,要用忽略的临时目录,避免把报告合入。
|
|
177
|
+
|
|
178
|
+
落地前按真实 diff 核对 ownedPaths,越界拒绝且不提交草稿;只有用户明确授权时才用 allowOutsideOwned。
|
|
179
|
+
|
|
180
|
+
同 session 的 `default_acceptance` 自动加到每路本地检查前;resume 会取最新策略。`describe_session` 返回 policy_revision,改目标/门禁可传 expected_revision 防旧窗口覆盖;waiting_user 拒绝派单与恢复,approved 后再继续。回执host_goal_sync包含按当前策略生成的/goal命令;宿主已有原生goal时用/goal替换条件,支持ProposeGoal时可提议同一条件并走宿主批准。条件要求读取最新session revision及批准范围;MCP不会偷偷修改或禁用宿主Stop hook。
|
|
181
|
+
|
|
182
|
+
wait 默认预算60秒、默认compact;includeEvents会选择详细结果(显式compact优先)。带progress token的客户端每30秒收到通知;已验证MCP SDK及真实Claude2.1.299:idle35秒、wait65秒,三次progress后正常返回;原生/loop定时调用也已实测。
|
|
183
|
+
|
|
184
|
+
每路临时注入随包PreToolUse守卫:apply_patch核对全部目标路径(含rename和symlink),forbid拒绝红线;Shell仅允许简单读取和派单显式allowedCommands/acceptance。声明的验证脚本以派单者权限执行,可有副作用,不能当作任意程序的文件沙箱。guard策略随resume/followup继承,不写全局hooks。空跑write run按本轮输出前后内容和命令判断,no_work进入needs_attention;只读任务不因没改文件判空跑。
|
|
185
|
+
|
|
186
|
+
check_workers在状态协调后,对已结束的第1轮lost/no_work原子resume一次;第2轮仍有问题则保留证据等处理。审批、认证、权限和quota等待不重试,返回recoveries记录。worker最终输出强制JSON result/verification/not_done;get_worker_result的structured_report给格式校验,独立命令与acceptance仍为实际证据。非法JSON标failed/invalid_report并拒绝land;旧历史标legacy_text。
|
|
187
|
+
|
|
188
|
+
context用绝对文件路径与可选sha256声明材料,最多20份、与contracts合计6000字;文件不超过5 MB。首次派单记录实际哈希,resume校验原材料未变,需要新材料时显式传context。handoff最多1800字/16行,截断明确标记;完整约束和引用单独保留,材料不授予写权限。
|
|
189
|
+
|
|
190
|
+
确需共享写入时声明externalOutputs:[{path,sha256?}]并配置acceptance。目标必须是绝对文件路径、每份≤1 MB;记录本轮前后哈希和有界内容,result/diff标shared_file_already_written_not_cherry_pick,不能通过land合入外部文件。外部目标参与归属冲突与hook;验证脚本的共享副作用由派单者负责。
|
|
191
|
+
|
|
192
|
+
workspace-write默认networkAccess:false;需要ssh/联网验证显式true,随resume/followup继承,不以danger-full-access代替。maxRunMs限制单轮、maxTotalMs限制从派单开始的总时长;超限中止worker并保留needs_attention/partial work,不自动重试。wait预算不改变这些quota。
|
|
193
|
+
|
|
194
|
+
运行前核验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。
|
|
195
|
+
|
|
196
|
+
ownedPaths预留和任务入库在同一事务内,跨MCP并发派单/恢复不能抢同一输出;验收或退出尚未结算时仍保留归属。Git工作区隔离创建失败明确报错,不退回主目录执行。
|
|
197
|
+
|
|
198
|
+
清理默认只预览:`npm run cleanup -- --dry-run`。`--apply` 只删除已合入、干净、无活跃依赖、Git注册与目录归属可证明的 completed worktree;脏、未合、lost/failed 及证据不足的目录保留并给出原因。
|
|
199
|
+
|
|
166
200
|
## 和 Claude Code 的 subagent 有什么区别
|
|
167
201
|
|
|
168
202
|
文件隔离不是差别:subagent 自己也能开 worktree。差别在模型和进程。
|
|
@@ -172,7 +206,7 @@ land_codex_worker 核过了,落进集成分支
|
|
|
172
206
|
| 能跑什么模型 | 只能选 Claude | `model` 透传给 Codex CLI,DeepSeek 也能挂 |
|
|
173
207
|
| 干活的是谁 | Claude Code 自己 | 独立的 `codex exec` 进程 |
|
|
174
208
|
| 两路写同一个文件 | 靠 worktree 隔开,没有路径声明 | 派单前查 `ownedPaths` 交集,重叠直接拒 |
|
|
175
|
-
| 主线程进程挂了 |
|
|
209
|
+
| 主线程进程挂了 | 主窗口无法收活 | 独立运行进程继续记录 worker 和验收;新窗口用 session_id 收回同批结果 |
|
|
176
210
|
| 谁能驱动 | 只有 Claude Code | 任何 MCP 客户端 |
|
|
177
211
|
| 看过程 | 只有它返回的结论 | 原始 JSONL 和网页看板 |
|
|
178
212
|
|
|
@@ -185,7 +219,7 @@ land_codex_worker 核过了,落进集成分支
|
|
|
185
219
|
| `completed` | 成功 |
|
|
186
220
|
| `failed` | 非零退出码、`turn.failed`、spawn 失败 |
|
|
187
221
|
| `cancelled` | 被 `cancel_codex_worker` 中断 |
|
|
188
|
-
| `lost` |
|
|
222
|
+
| `lost` | worker 被外部信号杀掉、运行进程失踪、或者行写了但进程从没起来。`resume_codex_worker` 接回 |
|
|
189
223
|
|
|
190
224
|
终态分两步落盘:`turn.completed` 先把 status 置成 completed,进程退出后才写 `exit_code`;`wait_codex_workers` 等到 `exit_code` 落了才返回。Windows 没有信号,外部 kill 只报 `failed` 加退出码。Codex 原生 goal 的 `paused` / `blocked` 算 `running` 并进 `needs_attention`,`usageLimited` / `budgetLimited` 算 `failed`。
|
|
191
225
|
|
|
@@ -262,7 +296,7 @@ rm -rf ~/.claude/skills/codex-supervisor ~/.agents/skills/codex-supervisor ~/.co
|
|
|
262
296
|
| 派单报 `codex only resolved to a shell shim` | Windows 只找到 `.cmd`,背后的包入口没了 | 重装 `@openai/codex`,或 `CODEX_BIN` 指到 `codex.js` |
|
|
263
297
|
| worker 一起来就 `failed`,`spawn codex ENOENT` | 进程 `PATH` 里没有 codex | 配置里设 `CODEX_BIN` |
|
|
264
298
|
| `Cannot find module 'node:sqlite'` | Node 低于 22.13.0 | 升 Node |
|
|
265
|
-
| worker `lost` |
|
|
299
|
+
| worker `lost` | worker 或独立运行进程中断 | 查事件后用 `resume_codex_worker` 接回 |
|
|
266
300
|
| worker 说 `git add` 报 `index.lock: Operation not permitted` | 默认沙箱把 `.git` 设成只读 | 收活时 `land_codex_worker` 带 `commitMessage`,或派单用 `danger-full-access` |
|
|
267
301
|
| `ownedPaths overlap with active worker(s)` | 两路认领了同一片路径 | 改拆法,或先取消占着的那路 |
|
|
268
302
|
| 看板打开是空的 | 看板和 MCP 的 `SUPERVISOR_HOME` 不是同一个 | 在配了 `.mcp.json` 的项目目录里起,或显式传同一个 `SUPERVISOR_HOME` |
|
|
@@ -270,12 +304,12 @@ rm -rf ~/.claude/skills/codex-supervisor ~/.agents/skills/codex-supervisor ~/.co
|
|
|
270
304
|
|
|
271
305
|
## 已知限制
|
|
272
306
|
|
|
273
|
-
- worker
|
|
307
|
+
- 每次运行由独立进程读取 worker 输出、落状态和执行验收,直到结算后退出。派单 MCP 被 kill 后这些工作继续;新窗口用 `get_session_works` 收结果。若运行进程也被杀,保留 worktree 和 thread_id,核对 lost/interrupted 后恢复。
|
|
274
308
|
- 默认 `workspace-write` 沙箱里 worker 提交不了(Codex 把 `.git` 设成只读)。要么收活时 `land_codex_worker` 带 `commitMessage` 替它提交,要么派单用 `danger-full-access`。
|
|
275
309
|
- worktree 从一个提交切,你工作区里没 commit 的东西不在里面。
|
|
276
310
|
- 只隔离工作目录。临时目录、数据库、端口是共用的。
|
|
277
311
|
- `ownedPaths` 只在派单时查,拦不住 worker 新建清单外的文件。收活看 diff。
|
|
278
|
-
-
|
|
312
|
+
- 验收是 `acceptance` 里写了什么就查什么。没写的事它不会替你查,`verification` 只是 worker 自己跑过的命令,剩下的靠主线程看 diff。
|
|
279
313
|
- 一次 `wait_codex_workers` 等不到底,客户端的 MCP 工具超时是硬墙,靠反复调。
|
|
280
314
|
- `search_works` 是子串匹配,几百条够用。
|
|
281
315
|
|
|
@@ -283,7 +317,7 @@ rm -rf ~/.claude/skills/codex-supervisor ~/.agents/skills/codex-supervisor ~/.co
|
|
|
283
317
|
|
|
284
318
|
做完的:`CODEX_BIN` / `SUPERVISOR_HOME` / `GIT_BIN`;`status` 和 `phase` 拆开;`ownedPaths` / `goal` / `dependsOn`;`thread_id` 落库 + `resume_codex_worker`;并发和多进程写库;`session_id`、`search_works`、原生 goal;Windows;网页看板;`baseRef`;收活三件套 `get_worker_diff` / `ask_codex_worker` / `land_codex_worker`;后台自动更新。
|
|
285
319
|
|
|
286
|
-
|
|
320
|
+
运行生命周期已独立于 MCP;每路结算后退出,不需要常驻全局 daemon。
|
|
287
321
|
|
|
288
322
|
不做的:向量检索(子串匹配在这个规模更快、零维护)、`usage_count` 排序(实测 80 个 work 里只有 2 个被回头引用过)。
|
|
289
323
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codex-supervisor-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.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.",
|
|
@@ -39,6 +39,15 @@
|
|
|
39
39
|
"src/event-parser.js",
|
|
40
40
|
"src/worktree.js",
|
|
41
41
|
"src/landing.js",
|
|
42
|
+
"src/acceptance.js",
|
|
43
|
+
"src/acceptance-baseline.js",
|
|
44
|
+
"src/worker-changes.js",
|
|
45
|
+
"src/owned-changes.js",
|
|
46
|
+
"src/tool-guard.js",
|
|
47
|
+
"src/worker-report.js",
|
|
48
|
+
"src/worker-report.schema.json",
|
|
49
|
+
"src/handoff.js",
|
|
50
|
+
"src/external-output.js",
|
|
42
51
|
"src/truncate.js",
|
|
43
52
|
"src/status.js",
|
|
44
53
|
"src/paths.js",
|
|
@@ -16,12 +16,14 @@ description: 把 Codex CLI 当并行 worker 派活、盯进度、收结果。用
|
|
|
16
16
|
1. 先 `search_works` 搜一下,别重复派。
|
|
17
17
|
2. 拆活。每路写清楚:干什么、能写哪些文件、怎么算做完。改同一批文件就串行,文件完全不重叠才并行。
|
|
18
18
|
3. `create_codex_worker` 派出去。回执只有 `id`、`worktree_path`、`branch`、`owned_paths`、`status`,不回传任务原文。
|
|
19
|
-
4. `
|
|
19
|
+
4. 长任务配宿主 `/loop 5m check_workers` 定时收活,没变化 quiet,有新结果按 next_step 收。工具会按规则恢复一次,但不会唤醒关闭的主窗口;每个主线程设独立 `CODEX_SUPERVISOR_OBSERVER_ID` 可重启接回。短等用 `wait_codex_workers` 的 `timeoutMs: 60000`、`compact: true`,到点继续同批 task_ids。
|
|
20
20
|
|
|
21
21
|
| 参数 | 怎么填 |
|
|
22
22
|
|---|---|
|
|
23
|
-
| `task` | 这一路具体干什么。要能直接开工,别写"优化一下" |
|
|
23
|
+
| `task` | 这一路具体干什么。要能直接开工,别写"优化一下"。汇报格式 supervisor 已经附在 task 后面(结论 / 验证 / 没做的),别再要它列改动文件,diff 自己看 |
|
|
24
24
|
| `cwd` | 项目根目录。worker 在自己的 worktree 里干活,不动你的工作区 |
|
|
25
|
+
| `acceptance` | 这一步"做完了"的判据,shell 命令列表,worker 退出后 supervisor 在它的 worktree 里逐条跑,退出码 0 算过,worker 在 prompt 里看得到。任务书里的验证命令原样抄:查那个文件在不在、那个接口通不通、那个测试文件过不过。写能判这一步的,不写全仓回归;远端机器的检查包进 `ssh`。命令用 supervisor 自己的权限跑,等于你自己跑 |
|
|
26
|
+
| `forbid` / `allowedCommands` | 原样声明红线与验证命令;守卫拒绝未声明Shell程序,编辑用apply_patch |
|
|
25
27
|
| `ownedPaths` | 必填。这路允许写的路径,和在跑的 worker 重叠会被拒。冲突是好事,说明该改拆法 |
|
|
26
28
|
| `goal.objective` | 必填。一句话说目标,worker 会建成 Codex 原生 goal |
|
|
27
29
|
| `session_id` | 同一批传同一个值。第一路顺手带 `session_title`(30 字内,看板和 `get_session_works` 显示它),漏了用 `describe_session` 补 |
|
|
@@ -29,22 +31,48 @@ description: 把 Codex CLI 当并行 worker 派活、盯进度、收结果。用
|
|
|
29
31
|
| `baseRef` | worktree 从哪个提交切,默认 `HEAD`。第 N+1 步要建立在第 N 步上,填 `codex/<第 N 步 task_id>` |
|
|
30
32
|
| `sandbox` | 默认 `workspace-write`,worker 提交不了(Codex 把 `.git` 设成只读)。要它自己提交就 `danger-full-access`,否则收活时让 supervisor 替它提交 |
|
|
31
33
|
|
|
34
|
+
验收用 Bash 的 `errexit` + `pipefail`:`npm test | tail` 不能吞失败;预期失败用 `if` / `||` 显式判。超时即失败,别只看退出码 0。Windows 要有 Git for Windows Bash;缺失先修工具,别换回 cmd。
|
|
35
|
+
|
|
36
|
+
验收取当前身份用 `CODEX_SUPERVISOR_TASK_ID` / `CODEX_SUPERVISOR_BASE_COMMIT` / `CODEX_SUPERVISOR_RUN`;不要在命令里写死旧 base,rebase/resume 后这些值会更新。
|
|
37
|
+
|
|
38
|
+
派单前可用 `check_acceptance` 实跑验收命令;预检通过不代表 worker 已完成。已知失败必须按结构化 baseline 的用例名/类型/签名比,必跑项写 required;报告必须标本次 `CODEX_SUPERVISOR_CHECK_ID`,给 complete/identity/failures/executed/skipped,缺失、跳过和旧报告都不算过。reportPath 用工作区内忽略的临时目录,验收报告别混进业务提交。
|
|
39
|
+
|
|
40
|
+
同批公共门禁用 `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。
|
|
41
|
+
|
|
42
|
+
wait默认60秒和compact,带includeEvents则详细返回;客户端带progress token时每30秒收到通知。已实测Claude2.1.299在35秒idle下收到三次progress,65秒wait正常返回;通知不能唤醒关闭的宿主。/loop实测可定时调用,主窗口须保持运行。
|
|
43
|
+
|
|
44
|
+
派单写forbid红线、allowedCommands验证命令;runtime守卫按次注入并随resume/followup继承。apply_patch核对ownedPaths,Shell仅放简单读取和显式声明的验证命令;声明脚本可以有副作用,须先核对,不能当万能文件沙箱。no_work表示本轮write无输出变化且没跑命令;先看run_evidence,不拿上轮提交/命令当本轮完成。
|
|
45
|
+
|
|
46
|
+
check_workers可对已死的第1轮lost/no_work自动resume一次,recoveries记动作;第2轮仍失败看证据处理,审批/认证/权限/quota不盲重试。最终报告强制JSON,structured_report仅验证格式;invalid_report拒land,resume让模型提交合法JSON,命令和acceptance另外核对。
|
|
47
|
+
|
|
48
|
+
未提交材料用context:[{path:绝对路径,sha256:可选}];首次记哈希,resume材料变了要显式换context。context/contracts总6000字、最多20份文件,每份≤5 MB;handoff1800字/16行可裁,完整约束和refs另传。输入路径不等于写授权。
|
|
49
|
+
|
|
50
|
+
共享写入必须externalOutputs:[{path,sha256?}]+acceptance;绝对文件每份≤1 MB,参与归属冲突/hook。看external_outputs的前后内容、哈希与验收;外部文件已经写在共享目录,不用land,不能拿空worktree diff否认成果。
|
|
51
|
+
|
|
52
|
+
远端编译/ssh在workspace-write显式networkAccess:true,默认false,resume/followup继承;不要用danger-full-access代替联网配置。需要时声明maxRunMs/maxTotalMs,超限保留partial work并提示处理,不自动恢复;wait预算与quota分开。
|
|
53
|
+
|
|
54
|
+
Codex需0.162+支持hooks/output-schema,能力不够派单start_failed先修CLI。goal查询看native_goal_read,missing与locked/read_error分开;budget/usage限制也要处理。cleanup保留ignored成果、共享证据及未解决attention。
|
|
55
|
+
|
|
32
56
|
等待的几条规矩:
|
|
33
57
|
|
|
34
58
|
- 等待预算管这次调用,不管 worker。`still_running: true` 是等满了不是挂了,按 `next_step` 再调。
|
|
59
|
+
- 快照里 `idle_seconds` 是距上一条 Codex 事件多久,命令跑着和模型思考时 Codex 都不发事件。`command_running: true` 是长命令(`current_command` 是哪条),接着等;`command_running: false` 且 idle 超过 10 分钟,`get_codex_worker_events` 看最后几条,进程没了状态机会自己标 `lost`。
|
|
35
60
|
- `timeoutMinutes` 别超过客户端的 MCP 工具超时,否则被掐的是这次调用。
|
|
36
61
|
- **不要自己写 shell 循环 grep `data/runs/*.jsonl`**。进程被杀、`failed`、`lost`、`exit_code` 只有状态机知道,文件里没有;resume 过的 worker 文件里有多条 `turn.completed`;用户在终端里看到的是一行黑盒。
|
|
37
62
|
- 想省上下文改调 `get_orchestration_overview`,封顶 7000 字节。
|
|
38
63
|
|
|
39
64
|
## 收活:先看证据,再问,再改,再落
|
|
40
65
|
|
|
41
|
-
|
|
66
|
+
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` 是没配,退出码只说明没崩,对不对自己看。
|
|
67
|
+
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 步)。
|
|
42
68
|
2. `get_worker_diff`:它实际做了什么。起点到工作区的全部改动,提交没提交都算;`maxChars` 管总量,`paths` 缩范围。它说过了不算,diff 对得上才算。
|
|
43
69
|
3. 对不上、看不懂为什么:`ask_codex_worker` 带 `question` 问它。fork 出一个只读旁路,worker 自己的线程不动;fork 没网络没 MCP 工具,问"改了什么、为什么、在哪",别问要联网才能答的事。超时回 `running`,只带 `task_id` 再调拿答案。worker 被 resume 过后下一问自动换新 fork,`fresh: true` 强制换,问完 `end: true` 删。
|
|
44
|
-
4. 要它改:`resume_codex_worker`,写清问题在哪,让它改完 `git commit --amend --no-edit` 并进原来那个提交。旁路只读,改东西永远走 resume
|
|
45
|
-
5. 过了:`land_codex_worker` 把 `codex/<id>` 上的提交 cherry-pick 到派单目录当前分支。目标脏了、分支不对、冲突都拒绝并原样退回。worker 没提交(默认沙箱提交不了)就带 `commitMessage`,supervisor
|
|
70
|
+
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` 填新头。
|
|
71
|
+
5. 过了:`land_codex_worker` 把 `codex/<id>` 上的提交 cherry-pick 到派单目录当前分支。目标脏了、分支不对、冲突都拒绝并原样退回。worker 没提交(默认沙箱提交不了)就带 `commitMessage`,supervisor 在它分支上替它提交一笔再落。验收 `failed` 它会拒,修完再落;`ignoreAcceptance` 只在用户说了"就这样落"时用。
|
|
72
|
+
|
|
73
|
+
一批活全部到终态后:`get_orchestration_overview` 确认没有 `needs_attention`、`acceptance_failed` 为空,再逐路走上面几步。合不合、怎么合由主线程定。
|
|
46
74
|
|
|
47
|
-
|
|
75
|
+
高风险的步(迁移、改公共接口、"做完了"写不成命令的)再派一路 verifier:`sandbox: "read-only"`、`ownedPaths: []`,task 只给这一步的目标和原 worker 的 `worktree_path`,不给它的汇报,不说你怀疑什么,让它答"目标达成没有,证据是哪几行"。它不改东西,只读只跑。两路说法对不上,两边都别信,自己看 diff。
|
|
48
76
|
|
|
49
77
|
## 读结果别把上下文撑爆
|
|
50
78
|
|
|
@@ -52,10 +80,11 @@ description: 把 Codex CLI 当并行 worker 派活、盯进度、收结果。用
|
|
|
52
80
|
|---|---|
|
|
53
81
|
| 全部 worker 的状态 | `get_orchestration_overview` |
|
|
54
82
|
| 一路的完整结论 | `get_worker_result` |
|
|
55
|
-
| 一路改了什么 | `get_worker_diff` |
|
|
83
|
+
| 一路改了什么 | `get_worker_diff`;只要文件名用 `get_worker_result` 带 `includeFiles: true` |
|
|
56
84
|
| 活着还是完了 | `get_worker_summary` |
|
|
57
85
|
| 过程 | `get_codex_worker_events`,`kinds` 先滤、`limit` 限条数、`maxChars` 截长串,先看 `available_kinds` |
|
|
58
86
|
| 一路的状态细节 | `get_codex_worker_status`,`current_action` 是它正在跑的命令 |
|
|
87
|
+
| 验收过没过 | 每个读都带 `acceptance`;命令和每条的输出在 `get_worker_result.acceptance.checks` |
|
|
59
88
|
|
|
60
89
|
默认读回来的长文本都是裁过的(`current_action` 300 字、`prompt` 300 字、`last_message` 400 字),别把裁剪当成活没干。全量在库里。别一次 `limit: 200` 拉全量事件。
|
|
61
90
|
|
|
@@ -63,8 +92,9 @@ description: 把 Codex CLI 当并行 worker 派活、盯进度、收结果。用
|
|
|
63
92
|
|
|
64
93
|
| 情况 | 用什么 |
|
|
65
94
|
|---|---|
|
|
66
|
-
| 主线程自己挂了 |
|
|
67
|
-
| worker 变 `lost`(
|
|
95
|
+
| 主线程自己挂了 | 独立运行进程继续记日志、状态和验收;新窗口 `get_session_works({ session_id })` 收回同批活 |
|
|
96
|
+
| worker 变 `lost`(worker 或独立运行进程中断) | `resume_codex_worker`。worktree 里的改动和 `thread_id` 都在,同一线程接着干;被杀时正在做的那一步可能要重做 |
|
|
97
|
+
| worktree 落后主线(`base_behind.behind > 0`) | `resume_codex_worker` 带 `rebaseOnto: "HEAD"`,见收活第 4 步 |
|
|
68
98
|
| worker `failed` | 看 `error` 和日志,查完再 resume 或重派 |
|
|
69
99
|
| 没记到 `thread_id` 的老行 | `create_codex_followup_worker`,新线程靠文本重述 |
|
|
70
100
|
|
|
@@ -77,11 +107,13 @@ overview、派单回执、`wait` 返回里出现 `update` 且 `update_available:
|
|
|
77
107
|
## 常见坑
|
|
78
108
|
|
|
79
109
|
- worktree 从一个提交切,你工作区里没 commit 的东西 worker 看不到。要让它读到就给绝对路径或先 commit。
|
|
80
|
-
-
|
|
81
|
-
- `ownedPaths`
|
|
110
|
+
- `exit_code: 0` 只说明没崩。`acceptance` 是 supervisor 替你跑的验收,`verification` 是它自己跑过的,两个都没有就只剩 diff。验收命令别往 worktree 写文件,会混进它的改动。
|
|
111
|
+
- `ownedPaths` 在跨MCP派单/恢复时原子预留,验收和退出结算前仍占用;Git隔离创建失败不退回主目录。land 按真实 diff 拒越界(提交草稿前就查)。仍不等于运行时沙箱,收活看 diff;`allowOutsideOwned` 只用于用户明确批准的例外。
|
|
82
112
|
- worktree 只隔离工作区,端口和数据库是共用的。
|
|
83
113
|
- `resume_codex_worker` 不会再建 goal。`cancel_codex_worker` 跨进程靠 pid,要求那个 pid 的命令行里带 `codex`。
|
|
84
114
|
|
|
115
|
+
收尾先 `npm run cleanup -- --dry-run` 看清理候选;只有已合入、干净、无活跃依赖的目录才可apply。脏、未合、lost/failed和证明不了的保留,禁止强删未知成果。
|
|
116
|
+
|
|
85
117
|
## 看板
|
|
86
118
|
|
|
87
119
|
用户想用眼睛看就让他起 `codex-supervisor-web`(或 `npx -p codex-supervisor-mcp codex-supervisor-web`),开 `http://127.0.0.1:7877`。按 session 分组,每路有「旁问」tab,用户可以自己问 worker。
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Compare complete test identities, never a grep of the total failure count.
|
|
2
|
+
// The caller supplies an approved baseline and the current runner's evidence.
|
|
3
|
+
export function compareFailureBaseline(expected, actual) {
|
|
4
|
+
const errors = [];
|
|
5
|
+
const result = { passed: false, added: [], removed: [], changed: [], missing_required: [], errors };
|
|
6
|
+
const object = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
7
|
+
const text = (value) => typeof value === "string" && value.trim().length > 0;
|
|
8
|
+
if (!object(expected) || !object(actual)) {
|
|
9
|
+
errors.push("baseline and report must be objects");
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
if (!object(expected.identity) || !text(expected.identity.base_commit)) errors.push("baseline identity.base_commit is required");
|
|
13
|
+
if (!object(actual.identity) || !text(actual.identity.base_commit)) errors.push("report identity.base_commit is required");
|
|
14
|
+
if (expected.identity?.base_commit !== actual.identity?.base_commit) errors.push("base_commit mismatch");
|
|
15
|
+
if (actual.complete !== true) errors.push("report is not complete");
|
|
16
|
+
// Any explicitly approved identity component must match, including suite
|
|
17
|
+
// version, dataset hash or measured commit. Extra actual fields are allowed.
|
|
18
|
+
for (const [key, value] of Object.entries(expected.identity ?? {})) {
|
|
19
|
+
if (!text(value)) errors.push(`baseline identity.${key} must be a nonempty string`);
|
|
20
|
+
else if (actual.identity?.[key] !== value && key !== "base_commit") errors.push(`identity.${key} mismatch`);
|
|
21
|
+
}
|
|
22
|
+
const ids = (value, label) => {
|
|
23
|
+
if (!Array.isArray(value) || value.some((entry) => !text(entry))) {
|
|
24
|
+
errors.push(`${label} must be an array of nonempty test IDs`);
|
|
25
|
+
return new Set();
|
|
26
|
+
}
|
|
27
|
+
const unique = new Set(value);
|
|
28
|
+
if (unique.size !== value.length) errors.push(`${label} has duplicate test IDs`);
|
|
29
|
+
return unique;
|
|
30
|
+
};
|
|
31
|
+
const required = ids(expected.required, "required");
|
|
32
|
+
const executed = ids(actual.executed, "executed");
|
|
33
|
+
const skipped = ids(actual.skipped, "skipped");
|
|
34
|
+
for (const id of skipped) if (executed.has(id)) errors.push(`test ${id} is both executed and skipped`);
|
|
35
|
+
result.missing_required = [...required].filter((id) => !executed.has(id) || skipped.has(id)).sort();
|
|
36
|
+
const failures = (value, label) => {
|
|
37
|
+
const map = new Map();
|
|
38
|
+
if (!Array.isArray(value)) {
|
|
39
|
+
errors.push(`${label} failures must be an array`);
|
|
40
|
+
return map;
|
|
41
|
+
}
|
|
42
|
+
for (const item of value) {
|
|
43
|
+
if (!object(item) || !text(item.test_id) || !["failure", "error"].includes(item.kind) || !text(item.signature)) {
|
|
44
|
+
errors.push(`${label} has a malformed failure record`);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (map.has(item.test_id)) errors.push(`${label} has duplicate failure ${item.test_id}`);
|
|
48
|
+
map.set(item.test_id, { test_id: item.test_id, kind: item.kind, signature: item.signature });
|
|
49
|
+
}
|
|
50
|
+
return map;
|
|
51
|
+
};
|
|
52
|
+
const baseline = failures(expected.failures, "baseline");
|
|
53
|
+
const observed = failures(actual.failures, "report");
|
|
54
|
+
for (const [id, item] of observed) {
|
|
55
|
+
if (!executed.has(id)) errors.push(`failure ${id} was not executed`);
|
|
56
|
+
const before = baseline.get(id);
|
|
57
|
+
if (!before) result.added.push(item);
|
|
58
|
+
else if (before.kind !== item.kind || before.signature !== item.signature) result.changed.push({ test_id: id, expected: before, actual: item });
|
|
59
|
+
}
|
|
60
|
+
for (const [id, item] of baseline) if (!observed.has(id)) result.removed.push(item);
|
|
61
|
+
for (const key of ["added", "removed", "changed"]) result[key].sort((a, b) => a.test_id.localeCompare(b.test_id));
|
|
62
|
+
result.passed = errors.length === 0 && result.added.length === 0 && result.removed.length === 0 && result.changed.length === 0 && result.missing_required.length === 0;
|
|
63
|
+
return result;
|
|
64
|
+
}
|