codex-supervisor-mcp 0.7.3 → 0.8.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 +14 -10
- package/README.md +14 -10
- package/package.json +1 -1
- package/skills/codex-supervisor/SKILL.md +14 -7
- package/src/codex-runner.js +136 -15
- package/src/event-parser.js +64 -9
- package/src/landing.js +222 -4
- package/src/mcp-server.js +159 -26
- package/src/prompt.js +60 -7
- package/src/task-store.js +40 -2
- package/src/truncate.js +13 -0
- package/src/web-app.js +2 -0
- package/src/worktree.js +28 -0
- 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
|
|
|
@@ -141,15 +145,15 @@ Nineteen.
|
|
|
141
145
|
|
|
142
146
|
| Tool | Arguments | What it does |
|
|
143
147
|
|---|---|---|
|
|
144
|
-
| `create_codex_worker` | `task`, `cwd`, **`ownedPaths`**, **`goal`**, `session_id`, `session_title`, `session_note`, `dependsOn`, `baseRef`, `sandbox`, `model`, `reasoningEffort`, `title`, `skipGitRepoCheck` | Start a worker. `baseRef` picks the commit the worktree is cut from (default `HEAD`); pass another worker's `codex/<id>` to build on it |
|
|
148
|
+
| `create_codex_worker` | `task`, `cwd`, **`ownedPaths`**, **`goal`**, `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
149
|
| `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 |
|
|
150
|
+
| `resume_codex_worker` | `task_id`, `prompt`, `rebaseOnto`, `acceptance` | Continue the same Codex conversation; `thread_id` stays. `rebaseOnto` first moves the worktree onto the project's newer commit (stash, replay its own commits, unstash); a conflict puts it back and does not start the worker |
|
|
151
|
+
| `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
152
|
| `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
|
|
153
|
+
| `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
154
|
| `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
155
|
| `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
|
|
156
|
+
| `land_codex_worker` | `task_id`, `onto`, `commitMessage`, `ignoreAcceptance` | 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
157
|
| `get_worker_summary` | `task_id` | One paragraph: goal, status, changes, last command and message |
|
|
154
158
|
| `get_codex_worker_status` | `task_id`, `includePrompt`, `promptMaxChars` | One worker in detail |
|
|
155
159
|
| `get_codex_worker_events` | `task_id`, `limit`, `maxChars`, `kinds` | The raw event stream |
|
|
@@ -275,7 +279,7 @@ rm -rf ~/.claude/skills/codex-supervisor ~/.agents/skills/codex-supervisor ~/.co
|
|
|
275
279
|
- The worktree is cut from a commit; uncommitted work in your checkout is not in it.
|
|
276
280
|
- Only the working directory is isolated. Temp directories, databases and ports are shared.
|
|
277
281
|
- `ownedPaths` is checked at dispatch only; it does not stop a worker from creating files outside its list. Read the diff.
|
|
278
|
-
-
|
|
282
|
+
- 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
283
|
- One `wait_codex_workers` cannot wait to the end; the client's MCP tool timeout is a hard wall. Call it again.
|
|
280
284
|
- `search_works` is substring matching, fine for hundreds of works.
|
|
281
285
|
|
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
|
|
|
@@ -141,15 +145,15 @@ land_codex_worker 核过了,落进集成分支
|
|
|
141
145
|
|
|
142
146
|
| 工具 | 入参 | 作用 |
|
|
143
147
|
|---|---|---|
|
|
144
|
-
| `create_codex_worker` | `task`, `cwd`, **`ownedPaths`**, **`goal`**, `session_id`, `session_title`, `session_note`, `dependsOn`, `baseRef`, `sandbox`, `model`, `reasoningEffort`, `title`, `skipGitRepoCheck` | 起一个 worker。`baseRef` 指定 worktree 从哪个提交切,默认 `HEAD
|
|
148
|
+
| `create_codex_worker` | `task`, `cwd`, **`ownedPaths`**, **`goal`**, `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
149
|
| `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`
|
|
150
|
+
| `resume_codex_worker` | `task_id`, `prompt`, `rebaseOnto`, `acceptance` | 接同一个 Codex 会话继续跑,`thread_id` 不变。`rebaseOnto` 先把 worktree 挪到主线新头(stash、重放它自己的提交、放回),冲突原样退回不起 worker |
|
|
151
|
+
| `wait_codex_workers` | `task_ids`, `mode`(any/all), `timeoutMinutes`, `timeoutMs`, `compact`, `includeEvents`, `eventLimit`, `eventMaxChars`, `eventKinds` | 等终态。默认 2 分钟,到点带快照返回,worker 照跑;`compact` 每路只回一行,带 `idle_seconds` / `command_running`,分得清长命令和卡住 |
|
|
148
152
|
| `get_orchestration_overview` | `status`, `limit` | 全部 worker 的状态表,封顶 7000 字节。带 `version` 和 `update` |
|
|
149
|
-
| `get_worker_result` | `task_id`, `limit`, `maxChars` | worker
|
|
153
|
+
| `get_worker_result` | `task_id`, `limit`, `maxChars`, `includeFiles` | worker 自己的汇报,默认截 6000 字节、`truncated` 提示读全。`acceptance` 是 supervisor 替你跑的验收过没过,`verification` 是它自己跑过的命令和退出码,`base_behind` 是主线走了多远 |
|
|
150
154
|
| `get_worker_diff` | `task_id`, `maxChars`, `paths` | worker 实际改了什么:从 worktree 起点到工作区的 patch,提交没提交都算。`maxChars` 管总量,超了的文件只列名 |
|
|
151
155
|
| `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
|
|
156
|
+
| `land_codex_worker` | `task_id`, `onto`, `commitMessage`, `ignoreAcceptance` | 把 worker 在 `codex/<id>` 上的提交 cherry-pick 到派单目录的当前分支。目标要干净,冲突回滚,验收 `failed` 拒绝。`commitMessage` 先替它把未提交的改动提交成一笔,`ignoreAcceptance` 放行 |
|
|
153
157
|
| `get_worker_summary` | `task_id` | 一段话:goal、状态、改动、最后一条命令和消息 |
|
|
154
158
|
| `get_codex_worker_status` | `task_id`, `includePrompt`, `promptMaxChars` | 单个 worker 的状态细节 |
|
|
155
159
|
| `get_codex_worker_events` | `task_id`, `limit`, `maxChars`, `kinds` | 原始事件流 |
|
|
@@ -275,7 +279,7 @@ rm -rf ~/.claude/skills/codex-supervisor ~/.agents/skills/codex-supervisor ~/.co
|
|
|
275
279
|
- worktree 从一个提交切,你工作区里没 commit 的东西不在里面。
|
|
276
280
|
- 只隔离工作目录。临时目录、数据库、端口是共用的。
|
|
277
281
|
- `ownedPaths` 只在派单时查,拦不住 worker 新建清单外的文件。收活看 diff。
|
|
278
|
-
-
|
|
282
|
+
- 验收是 `acceptance` 里写了什么就查什么。没写的事它不会替你查,`verification` 只是 worker 自己跑过的命令,剩下的靠主线程看 diff。
|
|
279
283
|
- 一次 `wait_codex_workers` 等不到底,客户端的 MCP 工具超时是硬墙,靠反复调。
|
|
280
284
|
- `search_works` 是子串匹配,几百条够用。
|
|
281
285
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codex-supervisor-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.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.",
|
|
@@ -20,8 +20,9 @@ description: 把 Codex CLI 当并行 worker 派活、盯进度、收结果。用
|
|
|
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 自己的权限跑,等于你自己跑 |
|
|
25
26
|
| `ownedPaths` | 必填。这路允许写的路径,和在跑的 worker 重叠会被拒。冲突是好事,说明该改拆法 |
|
|
26
27
|
| `goal.objective` | 必填。一句话说目标,worker 会建成 Codex 原生 goal |
|
|
27
28
|
| `session_id` | 同一批传同一个值。第一路顺手带 `session_title`(30 字内,看板和 `get_session_works` 显示它),漏了用 `describe_session` 补 |
|
|
@@ -32,19 +33,23 @@ description: 把 Codex CLI 当并行 worker 派活、盯进度、收结果。用
|
|
|
32
33
|
等待的几条规矩:
|
|
33
34
|
|
|
34
35
|
- 等待预算管这次调用,不管 worker。`still_running: true` 是等满了不是挂了,按 `next_step` 再调。
|
|
36
|
+
- 快照里 `idle_seconds` 是距上一条 Codex 事件多久,命令跑着和模型思考时 Codex 都不发事件。`command_running: true` 是长命令(`current_command` 是哪条),接着等;`command_running: false` 且 idle 超过 10 分钟,`get_codex_worker_events` 看最后几条,进程没了状态机会自己标 `lost`。
|
|
35
37
|
- `timeoutMinutes` 别超过客户端的 MCP 工具超时,否则被掐的是这次调用。
|
|
36
38
|
- **不要自己写 shell 循环 grep `data/runs/*.jsonl`**。进程被杀、`failed`、`lost`、`exit_code` 只有状态机知道,文件里没有;resume 过的 worker 文件里有多条 `turn.completed`;用户在终端里看到的是一行黑盒。
|
|
37
39
|
- 想省上下文改调 `get_orchestration_overview`,封顶 7000 字节。
|
|
38
40
|
|
|
39
41
|
## 收活:先看证据,再问,再改,再落
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
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` 是没配,退出码只说明没崩,对不对自己看。
|
|
44
|
+
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
45
|
2. `get_worker_diff`:它实际做了什么。起点到工作区的全部改动,提交没提交都算;`maxChars` 管总量,`paths` 缩范围。它说过了不算,diff 对得上才算。
|
|
43
46
|
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
|
|
47
|
+
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` 填新头。
|
|
48
|
+
5. 过了:`land_codex_worker` 把 `codex/<id>` 上的提交 cherry-pick 到派单目录当前分支。目标脏了、分支不对、冲突都拒绝并原样退回。worker 没提交(默认沙箱提交不了)就带 `commitMessage`,supervisor 在它分支上替它提交一笔再落。验收 `failed` 它会拒,修完再落;`ignoreAcceptance` 只在用户说了"就这样落"时用。
|
|
46
49
|
|
|
47
|
-
一批活全部到终态后:`get_orchestration_overview` 确认没有 `needs_attention
|
|
50
|
+
一批活全部到终态后:`get_orchestration_overview` 确认没有 `needs_attention`、`acceptance_failed` 为空,再逐路走上面几步。合不合、怎么合由主线程定。
|
|
51
|
+
|
|
52
|
+
高风险的步(迁移、改公共接口、"做完了"写不成命令的)再派一路 verifier:`sandbox: "read-only"`、`ownedPaths: []`,task 只给这一步的目标和原 worker 的 `worktree_path`,不给它的汇报,不说你怀疑什么,让它答"目标达成没有,证据是哪几行"。它不改东西,只读只跑。两路说法对不上,两边都别信,自己看 diff。
|
|
48
53
|
|
|
49
54
|
## 读结果别把上下文撑爆
|
|
50
55
|
|
|
@@ -52,10 +57,11 @@ description: 把 Codex CLI 当并行 worker 派活、盯进度、收结果。用
|
|
|
52
57
|
|---|---|
|
|
53
58
|
| 全部 worker 的状态 | `get_orchestration_overview` |
|
|
54
59
|
| 一路的完整结论 | `get_worker_result` |
|
|
55
|
-
| 一路改了什么 | `get_worker_diff` |
|
|
60
|
+
| 一路改了什么 | `get_worker_diff`;只要文件名用 `get_worker_result` 带 `includeFiles: true` |
|
|
56
61
|
| 活着还是完了 | `get_worker_summary` |
|
|
57
62
|
| 过程 | `get_codex_worker_events`,`kinds` 先滤、`limit` 限条数、`maxChars` 截长串,先看 `available_kinds` |
|
|
58
63
|
| 一路的状态细节 | `get_codex_worker_status`,`current_action` 是它正在跑的命令 |
|
|
64
|
+
| 验收过没过 | 每个读都带 `acceptance`;命令和每条的输出在 `get_worker_result.acceptance.checks` |
|
|
59
65
|
|
|
60
66
|
默认读回来的长文本都是裁过的(`current_action` 300 字、`prompt` 300 字、`last_message` 400 字),别把裁剪当成活没干。全量在库里。别一次 `limit: 200` 拉全量事件。
|
|
61
67
|
|
|
@@ -65,6 +71,7 @@ description: 把 Codex CLI 当并行 worker 派活、盯进度、收结果。用
|
|
|
65
71
|
|---|---|
|
|
66
72
|
| 主线程自己挂了 | 先 `get_session_works({ session_id })`,一次拿回那批活 |
|
|
67
73
|
| worker 变 `lost`(MCP 进程没了把它带走了,或被信号杀了) | `resume_codex_worker`。worktree 里的改动和 `thread_id` 都在,同一线程接着干;被杀时正在做的那一步可能要重做 |
|
|
74
|
+
| worktree 落后主线(`base_behind.behind > 0`) | `resume_codex_worker` 带 `rebaseOnto: "HEAD"`,见收活第 4 步 |
|
|
68
75
|
| worker `failed` | 看 `error` 和日志,查完再 resume 或重派 |
|
|
69
76
|
| 没记到 `thread_id` 的老行 | `create_codex_followup_worker`,新线程靠文本重述 |
|
|
70
77
|
|
|
@@ -77,7 +84,7 @@ overview、派单回执、`wait` 返回里出现 `update` 且 `update_available:
|
|
|
77
84
|
## 常见坑
|
|
78
85
|
|
|
79
86
|
- worktree 从一个提交切,你工作区里没 commit 的东西 worker 看不到。要让它读到就给绝对路径或先 commit。
|
|
80
|
-
-
|
|
87
|
+
- `exit_code: 0` 只说明没崩。`acceptance` 是 supervisor 替你跑的验收,`verification` 是它自己跑过的,两个都没有就只剩 diff。验收命令别往 worktree 写文件,会混进它的改动。
|
|
81
88
|
- `ownedPaths` 是派单前的冲突检测,不是运行时沙箱,拦不住 worker 新建清单外的文件。收活看 diff。
|
|
82
89
|
- worktree 只隔离工作区,端口和数据库是共用的。
|
|
83
90
|
- `resume_codex_worker` 不会再建 goal。`cancel_codex_worker` 跨进程靠 pid,要求那个 pid 的命令行里带 `codex`。
|
package/src/codex-runner.js
CHANGED
|
@@ -13,13 +13,18 @@ import {
|
|
|
13
13
|
upsertTask
|
|
14
14
|
} from "./task-store.js";
|
|
15
15
|
import { applyCodexEvent } from "./event-parser.js";
|
|
16
|
-
import { TERMINAL_STATUSES } from "./status.js";
|
|
16
|
+
import { ACTIVE_STATUSES, TERMINAL_STATUSES } from "./status.js";
|
|
17
17
|
import { worktreesDir } from "./paths.js";
|
|
18
|
-
import {
|
|
18
|
+
import { frameWorkerPrompt } from "./prompt.js";
|
|
19
19
|
import { readTaskChanges } from "./worktree.js";
|
|
20
|
+
import { rebaseWorktree } from "./landing.js";
|
|
21
|
+
import { DEFAULT_ACCEPTANCE_TIMEOUT_MS, normalizeAcceptance, runAcceptance } from "./acceptance.js";
|
|
22
|
+
import { appendFile } from "node:fs/promises";
|
|
20
23
|
import { defaultBinDirs, findBinaryPath, resolveCommand, shimMessage } from "./bin-resolver.js";
|
|
21
24
|
|
|
22
25
|
const processes = new Map();
|
|
26
|
+
// taskId -> control object of an acceptance run in progress ({ kill, cancelled }).
|
|
27
|
+
const acceptanceRuns = new Map();
|
|
23
28
|
const cancelledTasks = new Set();
|
|
24
29
|
const CODEX_NPM_ENTRY = { pkg: "@openai/codex", bin: "bin/codex.js" };
|
|
25
30
|
const defaultGitBin = process.env.GIT_BIN?.trim() || "git";
|
|
@@ -241,6 +246,10 @@ async function startTrackedRun({ record, args, prompt, logPath, spawnOptions = {
|
|
|
241
246
|
error: null,
|
|
242
247
|
current_action: null,
|
|
243
248
|
current_command: null,
|
|
249
|
+
// A resumed row still carries the last event of the run that ended;
|
|
250
|
+
// idle time for this run counts from now.
|
|
251
|
+
last_event_at: now,
|
|
252
|
+
last_event_type: null,
|
|
244
253
|
run_count: (record.run_count ?? 0) + 1,
|
|
245
254
|
updated_at: now
|
|
246
255
|
};
|
|
@@ -352,7 +361,49 @@ async function startTrackedRun({ record, args, prompt, logPath, spawnOptions = {
|
|
|
352
361
|
next.error = `codex worker was killed by signal ${signal} before writing a terminal event`;
|
|
353
362
|
}
|
|
354
363
|
if (status === "cancelled") next.error = null;
|
|
355
|
-
|
|
364
|
+
|
|
365
|
+
// Acceptance runs after the worker is gone, in two writes. The first
|
|
366
|
+
// records the terminal status with exit_code still null and the run
|
|
367
|
+
// marked as this process's, so a wait keeps waiting and reconcile
|
|
368
|
+
// (which sees a dead codex pid) leaves the row alone; the second
|
|
369
|
+
// records exit_code and the verdict. changed_files is read before the
|
|
370
|
+
// checks run so build output they leave behind is not counted as the
|
|
371
|
+
// worker's.
|
|
372
|
+
const acceptance = Array.isArray(live.acceptance) && live.acceptance.length > 0 ? live.acceptance : null;
|
|
373
|
+
if (acceptance && (status === "completed" || status === "failed")) {
|
|
374
|
+
const control = { kill: null, cancelled: false, isCancelled: () => control.cancelled };
|
|
375
|
+
acceptanceRuns.set(record.id, control);
|
|
376
|
+
await persist({
|
|
377
|
+
...next,
|
|
378
|
+
exit_code: null,
|
|
379
|
+
signal: null,
|
|
380
|
+
current_action: "Running acceptance",
|
|
381
|
+
acceptance_results: { status: "running", passed: null, run: live.run_count, supervisor_pid: process.pid, started_at: finishedAt }
|
|
382
|
+
});
|
|
383
|
+
const results = await runAcceptance(acceptance, {
|
|
384
|
+
cwd: record.cwd,
|
|
385
|
+
timeoutMs: live.acceptance_timeout_ms ?? DEFAULT_ACCEPTANCE_TIMEOUT_MS,
|
|
386
|
+
run: live.run_count,
|
|
387
|
+
control
|
|
388
|
+
});
|
|
389
|
+
acceptanceRuns.delete(record.id);
|
|
390
|
+
const event = { type: "supervisor.acceptance", ...results };
|
|
391
|
+
await appendTaskEvent(record.id, event).catch(() => {});
|
|
392
|
+
await appendFile(logPath, `${JSON.stringify(event)}\n`).catch(() => {});
|
|
393
|
+
const failing = results.checks.find((check) => check.exit_code !== 0);
|
|
394
|
+
await persist({
|
|
395
|
+
...next,
|
|
396
|
+
acceptance_results: results,
|
|
397
|
+
current_action: results.status === "passed"
|
|
398
|
+
? "Completed, acceptance passed"
|
|
399
|
+
: results.status === "failed"
|
|
400
|
+
? `Acceptance failed: ${failing ? `${failing.command.slice(0, 80)} exit ${failing.exit_code ?? (failing.timed_out ? "timeout" : "?")}` : results.error ?? "see acceptance_results"}`
|
|
401
|
+
: next.current_action,
|
|
402
|
+
updated_at: new Date().toISOString()
|
|
403
|
+
});
|
|
404
|
+
} else {
|
|
405
|
+
await persist(acceptance ? { ...next, acceptance_results: null } : next);
|
|
406
|
+
}
|
|
356
407
|
cancelledTasks.delete(record.id);
|
|
357
408
|
});
|
|
358
409
|
|
|
@@ -405,15 +456,18 @@ export async function createCodexWorker({
|
|
|
405
456
|
dependsOn = [],
|
|
406
457
|
followupOf = null,
|
|
407
458
|
useWorktree = true,
|
|
408
|
-
baseRef = null
|
|
459
|
+
baseRef = null,
|
|
460
|
+
acceptance = null,
|
|
461
|
+
acceptanceTimeoutMs = null
|
|
409
462
|
}) {
|
|
410
463
|
if (!task || typeof task !== "string") throw new Error("task is required");
|
|
464
|
+
const acceptanceCommands = normalizeAcceptance(acceptance);
|
|
411
465
|
if (!cwd || typeof cwd !== "string") throw new Error("cwd is required");
|
|
412
466
|
if (!allowedReasoningEfforts.has(reasoningEffort)) {
|
|
413
467
|
throw new Error(`unsupported reasoningEffort: ${reasoningEffort}`);
|
|
414
468
|
}
|
|
415
|
-
if (!Array.isArray(ownedPaths) || ownedPaths.length === 0) {
|
|
416
|
-
throw new Error("ownedPaths is required and must list at least one path this worker is allowed to write");
|
|
469
|
+
if (!Array.isArray(ownedPaths) || (ownedPaths.length === 0 && sandbox !== "read-only")) {
|
|
470
|
+
throw new Error("ownedPaths is required and must list at least one path this worker is allowed to write (an empty list is allowed only for a read-only worker)");
|
|
417
471
|
}
|
|
418
472
|
const validatedGoal = validateGoal(goal);
|
|
419
473
|
|
|
@@ -460,6 +514,9 @@ export async function createCodexWorker({
|
|
|
460
514
|
run_count: 0,
|
|
461
515
|
worktree_path: worktreePath,
|
|
462
516
|
base_commit: worktree.baseCommit,
|
|
517
|
+
acceptance: acceptanceCommands,
|
|
518
|
+
acceptance_timeout_ms: acceptanceCommands ? (acceptanceTimeoutMs ?? DEFAULT_ACCEPTANCE_TIMEOUT_MS) : null,
|
|
519
|
+
acceptance_results: null,
|
|
463
520
|
prompt: task,
|
|
464
521
|
changed_files: [],
|
|
465
522
|
commands: [],
|
|
@@ -474,10 +531,10 @@ export async function createCodexWorker({
|
|
|
474
531
|
const started = await startTrackedRun({
|
|
475
532
|
record,
|
|
476
533
|
args,
|
|
477
|
-
prompt:
|
|
534
|
+
prompt: frameWorkerPrompt(task, {
|
|
478
535
|
objective: validatedGoal.objective,
|
|
479
536
|
tokenBudget: validatedGoal.tokenBudget
|
|
480
|
-
}),
|
|
537
|
+
}, { acceptance: acceptanceCommands }),
|
|
481
538
|
logPath: record.run_log
|
|
482
539
|
});
|
|
483
540
|
await upsertTask(started.record);
|
|
@@ -487,15 +544,66 @@ export async function createCodexWorker({
|
|
|
487
544
|
// Continue the *same* Codex session. The worktree, thread id, ownership and
|
|
488
545
|
// goal are all inherited from the original task, and the row is reused so one
|
|
489
546
|
// logical piece of work stays one row.
|
|
490
|
-
|
|
547
|
+
//
|
|
548
|
+
// `rebaseOnto` names a ref, resolved in the project directory (HEAD, main, a
|
|
549
|
+
// sha): the worktree is moved onto it first so the worker continues on
|
|
550
|
+
// current code, and base_commit is recorded before the worker starts so a
|
|
551
|
+
// spawn failure cannot leave the row describing the old base. A rebase that
|
|
552
|
+
// does not go through puts the worktree back and throws with the file list;
|
|
553
|
+
// the worker is not started. Refused while the worker is still running.
|
|
554
|
+
export async function resumeCodexWorker({ taskId, prompt, rebaseOnto = null, acceptance = undefined }) {
|
|
491
555
|
if (!prompt || typeof prompt !== "string") throw new Error("prompt is required");
|
|
492
|
-
|
|
556
|
+
let task = await getTask(taskId);
|
|
493
557
|
if (!task) throw new Error(`task not found: ${taskId}`);
|
|
558
|
+
// `acceptance` replaces the stored commands when given; an empty list
|
|
559
|
+
// clears them. Left out, the stored commands stay.
|
|
560
|
+
if (acceptance !== undefined) {
|
|
561
|
+
const commands = normalizeAcceptance(acceptance);
|
|
562
|
+
task = {
|
|
563
|
+
...task,
|
|
564
|
+
acceptance: commands,
|
|
565
|
+
acceptance_timeout_ms: commands ? (task.acceptance_timeout_ms ?? DEFAULT_ACCEPTANCE_TIMEOUT_MS) : null,
|
|
566
|
+
updated_at: new Date().toISOString()
|
|
567
|
+
};
|
|
568
|
+
await upsertTask(task);
|
|
569
|
+
}
|
|
494
570
|
if (!task.thread_id) {
|
|
495
571
|
throw new Error(
|
|
496
572
|
`task ${taskId} has no Codex thread_id recorded. Only workers created by this version of codex-supervisor-mcp can be resumed; use create_codex_followup_worker otherwise.`
|
|
497
573
|
);
|
|
498
574
|
}
|
|
575
|
+
let rebase = null;
|
|
576
|
+
if (rebaseOnto) {
|
|
577
|
+
if (ACTIVE_STATUSES.has(task.status) || processes.has(task.id)) {
|
|
578
|
+
const error = new Error(`task ${taskId} is still ${task.status}; wait for it to settle (or cancel it) before rebasing its worktree`);
|
|
579
|
+
error.code = "worker_active";
|
|
580
|
+
throw error;
|
|
581
|
+
}
|
|
582
|
+
if (!task.worktree_path) {
|
|
583
|
+
const error = new Error(`task ${taskId} ran in place and has no worktree to rebase`);
|
|
584
|
+
error.code = "no_worktree";
|
|
585
|
+
throw error;
|
|
586
|
+
}
|
|
587
|
+
let ontoCommit;
|
|
588
|
+
try {
|
|
589
|
+
ontoCommit = resolveCommit(task.project_root, rebaseOnto);
|
|
590
|
+
} catch {
|
|
591
|
+
const error = new Error(`rebaseOnto "${rebaseOnto}" does not resolve to a commit in ${task.project_root}`);
|
|
592
|
+
error.code = "invalid_rebase_onto";
|
|
593
|
+
throw error;
|
|
594
|
+
}
|
|
595
|
+
rebase = rebaseWorktree(task, ontoCommit);
|
|
596
|
+
if (rebase.error) {
|
|
597
|
+
const error = new Error(rebase.reason);
|
|
598
|
+
error.code = rebase.error;
|
|
599
|
+
error.details = rebase;
|
|
600
|
+
throw error;
|
|
601
|
+
}
|
|
602
|
+
if (!rebase.noop && rebase.base_commit !== task.base_commit) {
|
|
603
|
+
task = { ...task, base_commit: rebase.base_commit, updated_at: new Date().toISOString() };
|
|
604
|
+
await upsertTask(task);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
499
607
|
|
|
500
608
|
const cwd = (await exists(task.cwd)) ? task.cwd : task.project_root;
|
|
501
609
|
const args = ["exec", "resume", "--json"];
|
|
@@ -509,15 +617,15 @@ export async function resumeCodexWorker({ taskId, prompt }) {
|
|
|
509
617
|
const started = await startTrackedRun({
|
|
510
618
|
record: { ...task, resumed_from: task.resumed_from ?? task.id },
|
|
511
619
|
args,
|
|
512
|
-
prompt:
|
|
620
|
+
prompt: frameWorkerPrompt(prompt, {
|
|
513
621
|
objective: task.goal_objective ?? task.title ?? task.id,
|
|
514
622
|
resume: true
|
|
515
|
-
}),
|
|
623
|
+
}, { acceptance: task.acceptance }),
|
|
516
624
|
logPath: task.run_log,
|
|
517
625
|
spawnOptions: { cwd }
|
|
518
626
|
});
|
|
519
627
|
await upsertTask(started.record);
|
|
520
|
-
return started.record;
|
|
628
|
+
return rebase ? { ...started.record, rebase } : started.record;
|
|
521
629
|
}
|
|
522
630
|
|
|
523
631
|
// `powershell` by name is not always on PATH for a process a GUI client
|
|
@@ -607,6 +715,12 @@ function terminatePid(pid) {
|
|
|
607
715
|
}
|
|
608
716
|
|
|
609
717
|
export async function cancelCodexWorker(taskId) {
|
|
718
|
+
const acceptance = acceptanceRuns.get(taskId);
|
|
719
|
+
if (acceptance) {
|
|
720
|
+
acceptance.cancelled = true;
|
|
721
|
+
acceptance.kill?.();
|
|
722
|
+
return { cancelled: true, via: "acceptance", pid: null };
|
|
723
|
+
}
|
|
610
724
|
const child = processes.get(taskId);
|
|
611
725
|
if (child) {
|
|
612
726
|
cancelledTasks.add(taskId);
|
|
@@ -649,7 +763,9 @@ export async function createFollowupWorker({
|
|
|
649
763
|
reasoningEffort,
|
|
650
764
|
ownedPaths,
|
|
651
765
|
goal,
|
|
652
|
-
baseRef
|
|
766
|
+
baseRef,
|
|
767
|
+
acceptance,
|
|
768
|
+
acceptanceTimeoutMs
|
|
653
769
|
}) {
|
|
654
770
|
const parent = await getTask(taskId);
|
|
655
771
|
if (!parent) throw new Error(`task not found: ${taskId}`);
|
|
@@ -693,6 +809,11 @@ export async function createFollowupWorker({
|
|
|
693
809
|
dependsOn: [parent.id],
|
|
694
810
|
followupOf: parent.id,
|
|
695
811
|
useWorktree: true,
|
|
696
|
-
baseRef: baseRef ?? null
|
|
812
|
+
baseRef: baseRef ?? null,
|
|
813
|
+
// Inherited unless given; the follow-up runs in a fresh worktree cut
|
|
814
|
+
// from the project HEAD, so the parent's checks only pass there once
|
|
815
|
+
// the parent's work has landed.
|
|
816
|
+
acceptance: acceptance === undefined ? parent.acceptance : acceptance,
|
|
817
|
+
acceptanceTimeoutMs: acceptanceTimeoutMs ?? parent.acceptance_timeout_ms ?? null
|
|
697
818
|
});
|
|
698
819
|
}
|
package/src/event-parser.js
CHANGED
|
@@ -125,15 +125,17 @@ export function applyCodexEvent(task, event) {
|
|
|
125
125
|
const command = inferCommand(item);
|
|
126
126
|
next.phase = "command";
|
|
127
127
|
next.current_command = null;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
128
|
+
const exitCode = item?.exit_code ?? item?.exitCode ?? null;
|
|
129
|
+
const status = item?.status ?? "completed";
|
|
130
|
+
const entry = { command, exit_code: exitCode, status, completed_at: now };
|
|
131
|
+
// The tail of a failing command's output is the one piece of evidence
|
|
132
|
+
// a reviewer needs to tell "the build is broken" from "the network was
|
|
133
|
+
// down". Only failures keep it: the commands column is one row cell.
|
|
134
|
+
if (commandFailed(entry)) {
|
|
135
|
+
const tail = outputTail(item?.aggregated_output ?? item?.output ?? null);
|
|
136
|
+
if (tail) entry.output_tail = tail;
|
|
137
|
+
}
|
|
138
|
+
next.commands = [...(next.commands ?? []), entry];
|
|
137
139
|
return next;
|
|
138
140
|
}
|
|
139
141
|
if (itemType === "file_change") {
|
|
@@ -204,3 +206,56 @@ function errorText(value) {
|
|
|
204
206
|
}
|
|
205
207
|
return String(value);
|
|
206
208
|
}
|
|
209
|
+
|
|
210
|
+
const OUTPUT_TAIL_BYTES = 300;
|
|
211
|
+
|
|
212
|
+
function outputTail(output) {
|
|
213
|
+
if (typeof output !== "string" || !output) return null;
|
|
214
|
+
const buf = Buffer.from(output, "utf8");
|
|
215
|
+
if (buf.length <= OUTPUT_TAIL_BYTES) return output.trim() || null;
|
|
216
|
+
// Cut on a character boundary: drop bytes until the slice decodes cleanly.
|
|
217
|
+
let start = buf.length - OUTPUT_TAIL_BYTES;
|
|
218
|
+
while (start < buf.length && (buf[start] & 0xc0) === 0x80) start += 1;
|
|
219
|
+
return `…${buf.subarray(start).toString("utf8").trim()}`;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// A sandbox-refused command can come back with no exit code at all, only a
|
|
223
|
+
// failed status, so both are failure.
|
|
224
|
+
export function commandFailed(entry) {
|
|
225
|
+
if (!entry) return false;
|
|
226
|
+
if (entry.status === "failed") return true;
|
|
227
|
+
return entry.exit_code !== null && entry.exit_code !== undefined && entry.exit_code !== 0;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function clipText(value, max) {
|
|
231
|
+
const text = String(value ?? "");
|
|
232
|
+
return text.length > max ? `${text.slice(0, max)}…` : text;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// What the worker actually ran, condensed for a reviewer to hold its report
|
|
236
|
+
// against: a worker that says "tests pass" with commands_run 0, or that ends
|
|
237
|
+
// on a failing command and calls the work done, is caught here without
|
|
238
|
+
// reading the event stream. The commands list accumulates across resumes,
|
|
239
|
+
// so runs says how many turns it covers.
|
|
240
|
+
export function summarizeVerification(task, { limit = 10, clip = 160 } = {}) {
|
|
241
|
+
const commands = Array.isArray(task?.commands) ? task.commands : [];
|
|
242
|
+
const failed = commands.filter(commandFailed);
|
|
243
|
+
const last = commands[commands.length - 1] ?? null;
|
|
244
|
+
return {
|
|
245
|
+
runs: task?.run_count ?? 0,
|
|
246
|
+
commands_run: commands.length,
|
|
247
|
+
failed_count: failed.length,
|
|
248
|
+
last_exit_code: last ? (last.exit_code ?? null) : null,
|
|
249
|
+
last_command_failed: commandFailed(last),
|
|
250
|
+
failed: failed.slice(-limit).map((entry) => ({
|
|
251
|
+
command: clipText(entry.command, clip),
|
|
252
|
+
exit_code: entry.exit_code ?? null,
|
|
253
|
+
output_tail: entry.output_tail ?? null
|
|
254
|
+
})),
|
|
255
|
+
last: commands.slice(-limit).map((entry) => ({
|
|
256
|
+
command: clipText(entry.command, clip),
|
|
257
|
+
exit_code: entry.exit_code ?? null,
|
|
258
|
+
failed: commandFailed(entry)
|
|
259
|
+
}))
|
|
260
|
+
};
|
|
261
|
+
}
|