codex-supervisor-mcp 0.5.5 → 0.5.7
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 +42 -6
- package/README.md +42 -6
- package/package.json +14 -4
- package/skills/codex-supervisor/SKILL.md +17 -5
- package/src/codex-runner.js +62 -12
- package/src/mcp-server.js +129 -17
- package/src/task-store.js +71 -7
- package/src/update-check.js +206 -0
- package/src/web-server.js +302 -0
- package/src/worktree.js +65 -12
- package/web/dist/assets/index-DPTvsjxI.js +85 -0
- package/web/dist/assets/index-DnCjDsN6.css +2 -0
- package/web/dist/index.html +15 -0
package/README.en.md
CHANGED
|
@@ -182,11 +182,11 @@ Auto-install only happens on a **global install**. `npx`, `--ignore-scripts`, an
|
|
|
182
182
|
|
|
183
183
|
## Tools
|
|
184
184
|
|
|
185
|
-
|
|
185
|
+
Sixteen of them.
|
|
186
186
|
|
|
187
187
|
| Tool | Arguments | What it does |
|
|
188
188
|
|---|---|---|
|
|
189
|
-
| `create_codex_worker` | `task`, `cwd`, **`ownedPaths`**, **`goal`**, `session_id`, `dependsOn`, `sandbox`, `model`, `reasoningEffort`, `title`, `skipGitRepoCheck` | Start a worker |
|
|
189
|
+
| `create_codex_worker` | `task`, `cwd`, **`ownedPaths`**, **`goal`**, `session_id`, `session_title`, `session_note`, `dependsOn`, `baseRef`, `sandbox`, `model`, `reasoningEffort`, `title`, `skipGitRepoCheck` | Start a worker. `session_title` / `session_note` record what the batch is for, so the board and `get_session_works` show that instead of a bare id. `baseRef` picks the commit the worktree is cut from (default: the repository's `HEAD`); pass another worker's `codex/<id>` branch to build on work that isn't on the main line yet |
|
|
190
190
|
| `create_codex_followup_worker` | `task_id`, `followup_prompt`, `session_id`, plus the same arguments | Start a **new session**, seeded with the old worker's prompt, status, and recent events |
|
|
191
191
|
| `resume_codex_worker` | `task_id`, `prompt` | Continue the **same** Codex session |
|
|
192
192
|
| `list_codex_workers` | `status`, `includeHistory`, `includeDetails` | List workers; running ones only by default |
|
|
@@ -199,6 +199,8 @@ Fourteen of them.
|
|
|
199
199
|
| `get_worker_result` | `task_id`, `limit`, `maxChars` | A worker's own final report, in full. The overview and `wait_codex_workers` clip the last message to 400 characters and keep only the head; read this for the conclusion |
|
|
200
200
|
| `get_session_works` | `session_id` | Every worker dispatched under one session, oldest first. This is how a dead main thread finds its batch again |
|
|
201
201
|
| `search_works` | `query`, `limit` | Substring match over title / goal / prompt / last_message, newest first |
|
|
202
|
+
| `describe_session` | `session_id`, `title`, `note` | Record a title and a note for a session; fields you leave out keep their value. For when the first dispatch forgot |
|
|
203
|
+
| `check_for_update` | `force` | Ask the npm registry whether a newer version is published and whether the installed files match the published tarball. The same check runs at startup; this forces a fresh one |
|
|
202
204
|
| `cancel_codex_worker` | `task_id` | Stop a worker; falls back to the pid when the process handle isn't in this process |
|
|
203
205
|
|
|
204
206
|
### Why `ownedPaths` and `goal` are required
|
|
@@ -277,7 +279,31 @@ By default under `~/.codex-supervisor/`:
|
|
|
277
279
|
|
|
278
280
|
A database from 0.1.x migrates automatically the first time it's opened. Process values that used to live in `status` (`editing`, `command`, `command_completed`, `reporting`) move into `phase`, and `status` becomes `running`. Nothing is dropped. The migration runs inside one `BEGIN IMMEDIATE` transaction, so if several processes start at once only one of them actually migrates.
|
|
279
281
|
|
|
280
|
-
`changed_files` has
|
|
282
|
+
`changed_files` has three sources: Codex's `file_change` events, `git status --porcelain` in the worker's own worktree (the uncommitted part), and `git diff --name-only <base_commit> HEAD` (the committed part). The last two exist because a worker that edits files through a shell command (`printf > file`) never emits a `file_change` event, and once it commits on its branch `git status` is clean again - a real batch of five workers did exactly that and every read came back empty. `base_commit` is recorded on the row at dispatch; rows older than that column fall back to the oldest reflog entry of the `codex/<taskId>` branch, which is where the branch was created.
|
|
283
|
+
|
|
284
|
+
## The board
|
|
285
|
+
|
|
286
|
+
The package ships a read-only web view over the same SQLite file:
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
codex-supervisor-web # after a global install
|
|
290
|
+
npx -p codex-supervisor-mcp codex-supervisor-web # without installing
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
It listens on `http://127.0.0.1:7877`; `SUPERVISOR_WEB_PORT` / `SUPERVISOR_WEB_HOST` move it, `SUPERVISOR_HOME` points it at another state directory.
|
|
294
|
+
|
|
295
|
+
The left column lists sessions by the `session_title` recorded at dispatch (or, failing that, a line built from the workers' goals) and how many of their workers are still running. A session opens into its worker ledger: status, title, the command being run or the last line reported, time taken, files changed (the worktree's real diff, committed work included), commands run. A worker opens a drawer with the full report rendered from markdown, the change list, commands, the raw event stream, the task text, token usage and the native Codex goal. It refreshes every 2.5 seconds while something is running, every 8 seconds otherwise.
|
|
296
|
+
|
|
297
|
+
It reads. It does not dispatch or cancel; that stays with the MCP.
|
|
298
|
+
|
|
299
|
+
## Update check
|
|
300
|
+
|
|
301
|
+
When the MCP process starts it asks the npm registry which version is `latest` and what that tarball's integrity is, then compares two things:
|
|
302
|
+
|
|
303
|
+
- The installed version. If it is behind `latest`, `get_orchestration_overview`, the dispatch receipt and the `wait_codex_workers` response gain an `update` field with `latest_version` and the command to run (`npm i -g codex-supervisor-mcp@latest`). The skill tells the main thread to pass that on to the user.
|
|
304
|
+
- The installed files. A global install records the integrity of the unpacked tarball in `node_modules/.package-lock.json`; if it differs from what the registry publishes for that version, the files on disk are not the published build, and the notice says to reinstall. A git checkout has no such value and reports its commit instead.
|
|
305
|
+
|
|
306
|
+
The answer is cached for an hour and refreshed every six hours while the process runs. An unreachable registry is not an error: the result says `source: "offline"` and nothing nags. `CODEX_SUPERVISOR_NO_UPDATE_CHECK=1` turns the check off; `CODEX_SUPERVISOR_REGISTRY` points it at a private registry. The board shows the same result in its lower left corner.
|
|
281
307
|
|
|
282
308
|
## Environment variables
|
|
283
309
|
|
|
@@ -287,6 +313,10 @@ A database from 0.1.x migrates automatically the first time it's opened. Process
|
|
|
287
313
|
| `CODEX_HOME` | `~/.codex` | Read-only. Used to read Codex's own `goals_1.sqlite` |
|
|
288
314
|
| `CODEX_BIN` | `codex` (via `PATH`) | Path to the Codex CLI. On Windows a bare name is expanded through `PATHEXT` and the `.cmd` shim is stepped over automatically; a `.js` / `.cjs` / `.mjs` target is started with `node` |
|
|
289
315
|
| `GIT_BIN` | `git` (via `PATH`) | Path to the Git executable |
|
|
316
|
+
| `SUPERVISOR_WEB_PORT` / `SUPERVISOR_WEB_HOST` | `7877` / `127.0.0.1` | Where the board listens |
|
|
317
|
+
| `CODEX_SUPERVISOR_NO_UPDATE_CHECK` | unset | Set to `1` to disable the update check |
|
|
318
|
+
| `CODEX_SUPERVISOR_REGISTRY` | `https://registry.npmjs.org` | Registry the update check asks |
|
|
319
|
+
| `CODEX_SUPERVISOR_UPDATE_TIMEOUT_MS` | `4000` | How long the update check waits for the registry |
|
|
290
320
|
|
|
291
321
|
When the MCP client starts without `codex` on `PATH`, which is common for GUI-launched apps, set `CODEX_BIN` explicitly:
|
|
292
322
|
|
|
@@ -305,10 +335,11 @@ When the MCP client starts without `codex` on `PATH`, which is common for GUI-la
|
|
|
305
335
|
## Known limitations
|
|
306
336
|
|
|
307
337
|
- **A worker's lifetime is tied to the MCP process.** `codex` is a child of the MCP process, so killing the MCP process leaves workers behind. They get settled as `lost` on the next `list_codex_workers` / `get_orchestration_overview`. The real fix is a resident daemon, see the Roadmap.
|
|
308
|
-
- **The worktree is created from
|
|
338
|
+
- **The worktree is created from a commit, so uncommitted work isn't in it.** The default is the repository's `HEAD`; `baseRef` accepts any branch, tag or sha (one that doesn't resolve refuses the dispatch with `invalid_base_ref` instead of quietly falling back to `HEAD`). Modified and untracked files sitting in the main thread's checkout don't exist inside the worker's worktree. Give the task absolute paths, or commit first. The worker's own changes land on the `codex/<taskId>` branch and never touch the main checkout.
|
|
309
339
|
- **Only the working directory is isolated.** Temp directories (`TMPDIR`), databases, and ports are process-level resources and stay shared, so two workers writing the same temp file still collide. Give each one its own paths, database name, and port in the task if you need that.
|
|
310
340
|
- **`ownedPaths` is a pre-dispatch conflict check, not a runtime sandbox.** It stops two workers from registering the same file; it does not stop a worker from creating a file it never listed, because the sandbox is `workspace-write` and any path inside its own worktree is writable. Verify the output from the diff.
|
|
311
341
|
- **It reports "it finished", not "it's correct".** Terminal states come from Codex's `turn.completed` and the process exit code; `exit_code: 0` only means it didn't crash. Judging the output is the main thread's job: run the checks, spot-read the content.
|
|
342
|
+
- **A terminal state lands in two steps, and wait only returns once both have.** `turn.completed` flips `status` to `completed` first; `exit_code` is written when the process exits. `wait_codex_workers` counts a worker as finished only once `exit_code` is recorded (or nobody is left to record it), so the snapshot it returns matches the next `get_codex_worker_status` read. A direct status read can still land between the two steps: `completed` with `exit_code: null` is that gap, read again a moment later.
|
|
312
343
|
- **Don't expect one `wait_codex_workers` call to cover a long job.** Your client's MCP tool timeout is a hard wall (the `timeout` field in `.mcp.json`, or `MCP_TOOL_TIMEOUT`), and hitting it kills the call. The default wait returns after 2 minutes with a progress snapshot; loop instead of waiting once.
|
|
313
344
|
- **Long text comes back clipped by default.** `current_action` is cut at 300 characters, the prompt inside `get_codex_worker_status` is cut at 300 (`includePrompt: true` lifts that), and `last_message` is cut at 400 in the overview and the wait response (4000 in the status response). Nothing is lost: the full command stream is in `get_codex_worker_events` and the full report is in `get_worker_result`. This is what takes one `wait_codex_workers` round trip from tens of KB down to a few KB - which matters because a client that backgrounds a timed-out call replays the whole result as a notification.
|
|
314
345
|
- **Nothing is written to Codex's native goal store.** `goals_1.sqlite` belongs to Codex and this MCP only reads it. Once a worker starts, it calls Codex's own `create_goal`; this MCP only splices that instruction into the prompt at dispatch time.
|
|
@@ -330,7 +361,8 @@ When the MCP client starts without `codex` on `PATH`, which is common for GUI-la
|
|
|
330
361
|
8. ~~Worker-native goals: inject a `create_goal` instruction at dispatch~~
|
|
331
362
|
9. ~~Windows support: `.cmd` shim bypass, `taskkill` process tree, cross-platform `PATH` / `PATHEXT`~~ ✅
|
|
332
363
|
10. Resident daemon: move dispatch and process lifetime out of the MCP process
|
|
333
|
-
11. A live React board
|
|
364
|
+
11. ~~A live React board~~ ✅
|
|
365
|
+
12. ~~Session titles and notes, update check~~ ✅
|
|
334
366
|
|
|
335
367
|
Rejected, with the reasoning, so nobody brings them up again:
|
|
336
368
|
|
|
@@ -361,11 +393,15 @@ The skill covers the dispatch flow, the order to read results in, how to tell `f
|
|
|
361
393
|
|
|
362
394
|
```bash
|
|
363
395
|
npm install
|
|
364
|
-
npm test # deterministic: truncation, state machine, v1→v2 migration, setup, Windows routing,
|
|
396
|
+
npm test # deterministic: truncation, state machine, v1→v2 migration, setup, Windows routing, 23 regression cases, 40 edge cases
|
|
397
|
+
npm run test:edge # test/edge only: update check against a fake registry, session titles, baseRef, non-ASCII paths, ghost rows, board API
|
|
365
398
|
npm run test:real # end-to-end against the real codex CLI (includes cross-process resume and worktree isolation)
|
|
366
399
|
npm run smoke # basic smoke test (real codex)
|
|
367
400
|
npm run smoke:mcp # MCP protocol smoke test
|
|
368
401
|
npm run monitor # Ink terminal board
|
|
402
|
+
npm run web:install # board dependencies (web/)
|
|
403
|
+
npm run web:build # bundle the board into web/dist; runs before publish
|
|
404
|
+
npm run web:dev # board with hot reload, /api proxied to 7877
|
|
369
405
|
```
|
|
370
406
|
|
|
371
407
|
`npm test` replays a fixed Codex event stream through `src/test-fixtures/fake-codex.js`, so it's fast and deterministic. `npm run test:real` actually invokes `codex exec`. It's slower, but it's the evidence that this still works against the current Codex.
|
package/README.md
CHANGED
|
@@ -182,11 +182,11 @@ rm -rf ~/.codex-supervisor # 状态目录:sqlite、事件流、worktree
|
|
|
182
182
|
|
|
183
183
|
## 工具
|
|
184
184
|
|
|
185
|
-
|
|
185
|
+
16 个工具。
|
|
186
186
|
|
|
187
187
|
| 工具 | 入参 | 作用 |
|
|
188
188
|
|---|---|---|
|
|
189
|
-
| `create_codex_worker` | `task`, `cwd`, **`ownedPaths`**, **`goal`**, `session_id`, `dependsOn`, `sandbox`, `model`, `reasoningEffort`, `title`, `skipGitRepoCheck` | 起一个 worker |
|
|
189
|
+
| `create_codex_worker` | `task`, `cwd`, **`ownedPaths`**, **`goal`**, `session_id`, `session_title`, `session_note`, `dependsOn`, `baseRef`, `sandbox`, `model`, `reasoningEffort`, `title`, `skipGitRepoCheck` | 起一个 worker。`session_title` / `session_note` 记下这一批活是干什么的,看板和 `get_session_works` 显示它们而不是光秃秃的 id;`baseRef` 指定 worktree 从哪个提交切(默认仓库 `HEAD`),要接着另一路还没合进主线的 `codex/<id>` 分支干就传它 |
|
|
190
190
|
| `create_codex_followup_worker` | `task_id`, `followup_prompt`, `session_id`, + 同上 | 起一个**新会话**,把老 worker 的 prompt、状态、近期事件拼进去 |
|
|
191
191
|
| `resume_codex_worker` | `task_id`, `prompt` | 接**同一个** Codex 会话继续跑 |
|
|
192
192
|
| `list_codex_workers` | `status`, `includeHistory`, `includeDetails` | 列出 worker,默认只看在跑的 |
|
|
@@ -199,6 +199,8 @@ rm -rf ~/.codex-supervisor # 状态目录:sqlite、事件流、worktree
|
|
|
199
199
|
| `get_worker_result` | `task_id`, `limit`, `maxChars` | 读 worker 自己的完整收尾汇报。总览和 `wait_codex_workers` 把最后一条消息截到 400 字只留开头,要结论读这个 |
|
|
200
200
|
| `get_session_works` | `session_id` | 一个 session 派出去的全部 worker,按时间升序。主线程挂了之后靠它找回那批活 |
|
|
201
201
|
| `search_works` | `query`, `limit` | 在 title / goal / prompt / last_message 里做子串匹配,从新到旧 |
|
|
202
|
+
| `describe_session` | `session_id`, `title`, `note` | 给一个 session 记标题和说明,没传的字段保留原值。派单时漏了可以事后补 |
|
|
203
|
+
| `check_for_update` | `force` | 问 npm registry 有没有更新的版本、本机装的文件和发布的 tarball 是否一致。启动时会自动查一次,这个工具用来强制再查 |
|
|
202
204
|
| `cancel_codex_worker` | `task_id` | 终止 worker,进程句柄不在本进程时按 pid 兜底 |
|
|
203
205
|
|
|
204
206
|
### 为什么 `ownedPaths` 和 `goal` 是必填
|
|
@@ -277,7 +279,31 @@ Codex 原生 goal 有六个状态,映射到 work 状态:
|
|
|
277
279
|
|
|
278
280
|
老版本(0.1.x)的库会在第一次打开时自动迁移:`editing` / `command` / `command_completed` / `reporting` 这些原本塞在 `status` 里的过程值会被拆到 `phase`,`status` 归到 `running`,一行不丢。迁移在一个 `BEGIN IMMEDIATE` 事务里做,多个进程同时启动也只会有一个真的迁移。
|
|
279
281
|
|
|
280
|
-
`changed_files`
|
|
282
|
+
`changed_files` 有三个来源:Codex 的 `file_change` 事件、worker 自己 worktree 里的 `git status --porcelain`(未提交的部分)、以及 `git diff --name-only <base_commit> HEAD`(已提交的部分)。后两个是兜底:worker 用 shell 命令(`printf > file`)改文件时不会产生 `file_change` 事件;它自己在分支上 commit 之后 `git status` 又是干净的,一批五路 worker 全这么干过,读回来全是空数组。`base_commit` 在派单时记在行上;更早的行没有这列,就退回去读 `codex/<taskId>` 分支 reflog 里最老的那条,那是分支建出来的位置。
|
|
283
|
+
|
|
284
|
+
## 看板
|
|
285
|
+
|
|
286
|
+
包里带一个只读的网页看板,读的是同一个 sqlite:
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
codex-supervisor-web # 全局装过之后
|
|
290
|
+
npx -p codex-supervisor-mcp codex-supervisor-web # 没装也能起
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
默认开在 `http://127.0.0.1:7877`,`SUPERVISOR_WEB_PORT` / `SUPERVISOR_WEB_HOST` 改端口和地址,`SUPERVISOR_HOME` 指向别的状态目录。
|
|
294
|
+
|
|
295
|
+
左栏是 session,显示派单时记的 `session_title`(没记就用各路 worker 的 goal 拼一句)和这批活还有几路在跑。点进去是这个 session 的 worker 台账:状态、标题、正在执行的命令或最后一句汇报、耗时、改了几个文件(按 worktree 真实 diff 算,含已 commit 的)、跑了几条命令。再点一路,右侧抽屉给完整汇报(markdown 渲染)、改动清单、命令、原始事件流、任务书,还有 token 消耗和 Codex 原生 goal。有 worker 在跑时每 2.5 秒刷新,静止时 8 秒。
|
|
296
|
+
|
|
297
|
+
它只读,不派单,不取消。派单的事归 MCP。
|
|
298
|
+
|
|
299
|
+
## 更新检查
|
|
300
|
+
|
|
301
|
+
MCP 进程启动时会问一次 npm registry:`latest` 是哪个版本,它的 tarball integrity 是多少。然后和本机比两件事:
|
|
302
|
+
|
|
303
|
+
- 装的版本号。比 `latest` 低,就在 `get_orchestration_overview`、派单回执、`wait_codex_workers` 的返回里多一个 `update` 字段,带 `latest_version` 和要跑的命令(`npm i -g codex-supervisor-mcp@latest`)。skill 让主线程看到这个字段就转告用户。
|
|
304
|
+
- 装的文件。全局安装时 npm 把解出来的 tarball integrity 记在 `node_modules/.package-lock.json` 里,和 registry 上这个版本的 integrity 不一样,说明本机的文件不是发布的那份,同样提示重装。git checkout 没有这个值,只记 commit。
|
|
305
|
+
|
|
306
|
+
结果缓存一小时,运行中每六小时再查一次。registry 连不上就算了,不报错也不提示,本次结果标 `source: "offline"`。不想联网就设 `CODEX_SUPERVISOR_NO_UPDATE_CHECK=1`;私有 registry 用 `CODEX_SUPERVISOR_REGISTRY`。看板左下角也会显示同一个结果。
|
|
281
307
|
|
|
282
308
|
## 环境变量
|
|
283
309
|
|
|
@@ -287,6 +313,10 @@ Codex 原生 goal 有六个状态,映射到 work 状态:
|
|
|
287
313
|
| `CODEX_HOME` | `~/.codex` | 只读,用来读 Codex 原生的 `goals_1.sqlite` |
|
|
288
314
|
| `CODEX_BIN` | `codex`(走 `PATH`) | Codex CLI 可执行文件路径。Windows 上给裸名字时会按 `PATHEXT` 展开,`.cmd` shim 会被自动绕开;指向 `.js` / `.cjs` / `.mjs` 时自动用 `node` 起它 |
|
|
289
315
|
| `GIT_BIN` | `git`(走 `PATH`) | Git 可执行文件路径 |
|
|
316
|
+
| `SUPERVISOR_WEB_PORT` / `SUPERVISOR_WEB_HOST` | `7877` / `127.0.0.1` | 看板监听的端口和地址 |
|
|
317
|
+
| `CODEX_SUPERVISOR_NO_UPDATE_CHECK` | 未设 | 设成 `1` 关闭更新检查 |
|
|
318
|
+
| `CODEX_SUPERVISOR_REGISTRY` | `https://registry.npmjs.org` | 更新检查用的 registry |
|
|
319
|
+
| `CODEX_SUPERVISOR_UPDATE_TIMEOUT_MS` | `4000` | 更新检查等 registry 的上限 |
|
|
290
320
|
|
|
291
321
|
如果 MCP 客户端启动时 `PATH` 里没有 `codex`(GUI 启动的应用常见),显式设置 `CODEX_BIN`:
|
|
292
322
|
|
|
@@ -305,10 +335,11 @@ Codex 原生 goal 有六个状态,映射到 work 状态:
|
|
|
305
335
|
## 已知限制
|
|
306
336
|
|
|
307
337
|
- **worker 的生命周期绑在 MCP 进程上**:`codex` 是 MCP 进程的子进程,MCP 被 kill 时 worker 会被留下。这些 worker 会在下一次 `list_codex_workers` / `get_orchestration_overview` 时被结算成 `lost`。真正的解法是常驻 daemon,见 Roadmap。
|
|
308
|
-
- **worktree
|
|
338
|
+
- **worktree 从一个提交建,未提交的改动不在里面**:默认从仓库 `HEAD` 切,传 `baseRef` 可以换成任何分支、tag 或 sha(解析不到就拒绝派单,错误码 `invalid_base_ref`,不会悄悄退回 `HEAD`)。主线程工作区里没 commit 的修改和未跟踪文件,worker 在自己的 worktree 里看不到。要让它读写这些文件,就在 task 里给绝对路径,或者先把改动 commit。worker 的改动落在 `codex/<taskId>` 分支上,不碰主线程的工作区。
|
|
309
339
|
- **只隔离工作目录**:临时目录(`TMPDIR`)、数据库、端口这些进程级资源是共用的,多个 worker 同时写同一个临时文件照样互相踩。要隔开得自己在 task 里指定各自的临时目录、库名和端口。
|
|
310
340
|
- **`ownedPaths` 是派单前的冲突检测,不是运行时沙箱**:它只挡「两路活登记写同一个文件」,拦不住 worker 在自己 worktree 里新建清单外的文件——sandbox 是 `workspace-write`,写自己 worktree 里的任何路径都合法。校验产出还是得看 diff。
|
|
311
341
|
- **只管「跑完了」,不管写得对不对**:终态来自 Codex 的 `turn.completed` 和进程退出码,`exit_code: 0` 只说明它没崩。产出对不对得主线程自己核,跑校验、抽看内容。
|
|
342
|
+
- **终态分两步落盘,但 wait 只在落稳后返回**:`turn.completed` 先把 `status` 置成 `completed`,进程退出后才写 `exit_code`。`wait_codex_workers` 要等到 `exit_code` 写入(或者进程已经不在)才算这一路到了终态,所以它返回的快照和下一次 `get_codex_worker_status` 读到的是同一份。直接读 status 仍然可能撞上中间态,看到 `completed` 配 `exit_code: null` 就是这种情况,过一会再读。
|
|
312
343
|
- **长任务别指望一次 `wait_codex_workers` 等到底**:客户端给 MCP 工具调用设的超时是硬墙(`.mcp.json` 里的 `timeout`,或 `MCP_TOOL_TIMEOUT`),撞上就把这次调用掐掉。默认 2 分钟带进度返回,靠反复调而不是一次等到黑。
|
|
313
344
|
- **默认读回来的长文本是裁过的**:`current_action` 截到 300 字、`get_codex_worker_status` 的 prompt 截到 300 字(`includePrompt: true` 放开)、`last_message` 在总览和 wait 里截到 400 字(status 里是 4000)。全量都在库里:命令流看 `get_codex_worker_events`,结论看 `get_worker_result`。这样一条 `wait_codex_workers` 往返从几十 KB 降到几 KB——客户端把超时调用挪到后台、再把结果当通知回灌一次时,这份代价小得多。
|
|
314
345
|
- **不往 Codex 原生 goal 写数据**:`goals_1.sqlite` 归 Codex 所有,本 MCP 只读。worker 起来后由它自己调 Codex 的 `create_goal` 建原生 goal,本 MCP 只负责在派单时把这段指令拼进 prompt。
|
|
@@ -330,7 +361,8 @@ Codex 原生 goal 有六个状态,映射到 work 状态:
|
|
|
330
361
|
8. ~~worker 原生 goal:派单时注入 `create_goal` 指令~~
|
|
331
362
|
9. ~~Windows 支持:`.cmd` shim 绕行、`taskkill` 进程树、跨平台 PATH / `PATHEXT`~~ ✅
|
|
332
363
|
10. 常驻 daemon:派单和进程生命周期从 MCP 进程里拿出来
|
|
333
|
-
11. React
|
|
364
|
+
11. ~~React 实时看板~~ ✅
|
|
365
|
+
12. ~~session 标题和说明、更新检查~~ ✅
|
|
334
366
|
|
|
335
367
|
砍掉不做的(说明理由,免得以后又想起来):
|
|
336
368
|
|
|
@@ -361,11 +393,15 @@ skill 里写了派单流程、读结果该按什么顺序、`failed` 和 `lost`
|
|
|
361
393
|
|
|
362
394
|
```bash
|
|
363
395
|
npm install
|
|
364
|
-
npm test # 确定性测试:截断、状态机、v1→v2 迁移、setup、Windows 路由、
|
|
396
|
+
npm test # 确定性测试:截断、状态机、v1→v2 迁移、setup、Windows 路由、23 项端到端回归、40 项边界
|
|
397
|
+
npm run test:edge # 只跑 test/edge:更新检查(假 registry)、session 标题、baseRef、中文路径、僵尸行、看板 API
|
|
365
398
|
npm run test:real # 用真 codex CLI 跑端到端(含跨进程 resume、worktree 隔离)
|
|
366
399
|
npm run smoke # 基础冒烟(真 codex)
|
|
367
400
|
npm run smoke:mcp # MCP 协议冒烟
|
|
368
401
|
npm run monitor # Ink 终端看板
|
|
402
|
+
npm run web:install # 看板前端依赖(web/)
|
|
403
|
+
npm run web:build # 打包看板到 web/dist,发 npm 前自动跑
|
|
404
|
+
npm run web:dev # 看板热更新开发,/api 代理到 7877
|
|
369
405
|
```
|
|
370
406
|
|
|
371
407
|
`npm test` 用 `src/test-fixtures/fake-codex.js` 回放固定的 Codex 事件流,跑得快且确定。`npm run test:real` 会真的调 `codex exec`,慢一些,但它才是「跟最新 Codex 兼容」的证据。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codex-supervisor-mcp",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "MCP server that dispatches and supervises parallel Codex CLI workers, one isolated Git worktree each, with a persisted work state machine.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
],
|
|
25
25
|
"bin": {
|
|
26
26
|
"codex-supervisor-mcp": "./src/mcp-server.js",
|
|
27
|
-
"codex-supervisor-setup": "./src/setup.js"
|
|
27
|
+
"codex-supervisor-setup": "./src/setup.js",
|
|
28
|
+
"codex-supervisor-web": "./src/web-server.js"
|
|
28
29
|
},
|
|
29
30
|
"files": [
|
|
30
31
|
"src/mcp-server.js",
|
|
@@ -41,6 +42,9 @@
|
|
|
41
42
|
"src/prompt.js",
|
|
42
43
|
"src/cleanup.js",
|
|
43
44
|
"src/monitor.jsx",
|
|
45
|
+
"src/web-server.js",
|
|
46
|
+
"src/update-check.js",
|
|
47
|
+
"web/dist/",
|
|
44
48
|
"skills/",
|
|
45
49
|
"README.md",
|
|
46
50
|
"LICENSE"
|
|
@@ -51,12 +55,18 @@
|
|
|
51
55
|
"start": "node ./src/mcp-server.js",
|
|
52
56
|
"monitor": "tsx ./src/monitor.jsx",
|
|
53
57
|
"cleanup": "node ./src/cleanup.js",
|
|
54
|
-
"test": "node ./src/bin-resolver-test.js && node ./src/truncate-test.js && node ./src/status-test.js && node ./src/migration-test.js && node ./src/setup-test.js && node ./src/setup-windows-test.js && node ./src/regression-test.js",
|
|
58
|
+
"test": "node ./src/bin-resolver-test.js && node ./src/truncate-test.js && node ./src/status-test.js && node ./src/migration-test.js && node ./src/setup-test.js && node ./src/setup-windows-test.js && node ./src/regression-test.js && node --test test/edge/*.test.js",
|
|
55
59
|
"test:real": "node ./src/real-codex-test.js",
|
|
56
60
|
"smoke": "node ./src/smoke-test.js",
|
|
57
61
|
"smoke:followup": "node ./src/followup-smoke-test.js",
|
|
58
62
|
"smoke:mcp": "node ./src/mcp-smoke-test.js",
|
|
59
|
-
"smoke:mcp-wait": "node ./src/mcp-wait-smoke-test.js"
|
|
63
|
+
"smoke:mcp-wait": "node ./src/mcp-wait-smoke-test.js",
|
|
64
|
+
"web": "node ./src/web-server.js",
|
|
65
|
+
"web:install": "npm --prefix web install",
|
|
66
|
+
"web:build": "npm --prefix web run build",
|
|
67
|
+
"web:dev": "npm --prefix web run dev",
|
|
68
|
+
"test:edge": "node --test test/edge/*.test.js",
|
|
69
|
+
"prepublishOnly": "npm run web:build && npm test"
|
|
60
70
|
},
|
|
61
71
|
"dependencies": {
|
|
62
72
|
"@modelcontextprotocol/sdk": "^1.21.0"
|
|
@@ -18,9 +18,10 @@ description: 把 Codex CLI 当并行 worker 派活、盯进度、收结果。用
|
|
|
18
18
|
## 一次派单
|
|
19
19
|
|
|
20
20
|
1. 拆活。每路写清楚:干什么、能写哪些文件、怎么算做完。
|
|
21
|
-
2. `
|
|
22
|
-
3.
|
|
23
|
-
4.
|
|
21
|
+
2. 第一路派单时带 `session_id` + `session_title`(一句话说这批活是干什么的,30 字以内,比如「给 12 个接口补单测」),要交代背景再加 `session_note`。看板左栏和 `get_session_works` 显示的是这个标题,不是 id。漏了就事后调 `describe_session` 补。
|
|
22
|
+
3. `create_codex_worker` 派出去。返回的是一张精简回执(`id`、`worktree_path`、`branch`、`owned_paths`、`status`),任务原文不回传,派十一路也不会把你的提示词抄十一遍。
|
|
23
|
+
4. 派完就 `wait_codex_workers` 等。默认只等 2 分钟,到点返回进度快照,worker 照跑;拿同一批 `task_ids` 接着调,直到 `timed_out: false`。默认**不带**事件(`includeEvents: false`),返回只够看状态,要事件得自己开。
|
|
24
|
+
5. 收结果走 `get_worker_result`,拿完整汇报,别一上来读事件流。
|
|
24
25
|
|
|
25
26
|
`ownedPaths` 和 `goal` 必填,不是可选项。
|
|
26
27
|
|
|
@@ -33,7 +34,9 @@ description: 把 Codex CLI 当并行 worker 派活、盯进度、收结果。用
|
|
|
33
34
|
| `ownedPaths` | 这个 worker 允许写的路径。和正在跑的 worker 重叠会被拒,返回冲突的 `task_id` |
|
|
34
35
|
| `goal.objective` | 一句话说清这路活的目标 |
|
|
35
36
|
| `session_id` | 同一批派单传同一个值。断线重连靠它 |
|
|
37
|
+
| `session_title` / `session_note` | 这批活是干什么的,一句话 + 可选说明。第一路带上就行,后面几路不用重复 |
|
|
36
38
|
| `dependsOn` | 有先后依赖时填上游的 `task_id` |
|
|
39
|
+
| `baseRef` | worktree 从哪个提交切。默认仓库 `HEAD`;要接着另一路还没合进主线的活干,填它的分支 `codex/<taskId>` |
|
|
37
40
|
|
|
38
41
|
一次派一批:
|
|
39
42
|
|
|
@@ -42,6 +45,10 @@ create_codex_worker × N (同一个 session_id)
|
|
|
42
45
|
wait_codex_workers (task_ids: [...], mode: "all")
|
|
43
46
|
```
|
|
44
47
|
|
|
48
|
+
## 看到 `update` 字段就转告用户
|
|
49
|
+
|
|
50
|
+
`get_orchestration_overview`、派单回执、`wait_codex_workers` 的返回里出现 `update` 且 `update_available: true`(或 `integrity_matches: false`)时,当轮回复里告诉用户一句:现在装的是 `installed_version`,npm 上已经是 `latest_version`,跑 `install_command` 里那条命令,然后重启 Claude Code / Codex。只说一次,不要每轮重复。用户让你查时调 `check_for_update`。
|
|
51
|
+
|
|
45
52
|
## 读结果别把上下文撑爆
|
|
46
53
|
|
|
47
54
|
按这个顺序读,能不动后面就别动:
|
|
@@ -107,13 +114,18 @@ wait_codex_workers (task_ids: [...], mode: "all")
|
|
|
107
114
|
## 常见坑
|
|
108
115
|
|
|
109
116
|
- **worker 的命绑在 MCP 进程上**。MCP 被 kill,正在跑的 worker 会被留下,下次读状态时结算成 `lost`。
|
|
110
|
-
- **worktree
|
|
117
|
+
- **worktree 是从一个提交建的,你工作区里没 commit 的东西不在里面**。默认从 `HEAD` 切;要让第 5 步接着还没合进主线的第 4 步干,派单时传 `baseRef: "codex/<第4步的taskId>"`,不用自己垫临时分支。未提交的修改和未跟踪文件 worker 既看不到也写不到。要让它读到就把绝对路径写进 `task`,或者先把改动 commit。它自己的改动落在 `codex/<taskId>` 分支上,不碰你的工作区。
|
|
111
118
|
- **它只管"跑完了",不管写得对不对**。终态来自 Codex 的 `turn.completed` 和进程退出码,`exit_code: 0` 只说明没崩。每批活回来,验收得自己做:跑校验、抽看内容。
|
|
119
|
+
- **`completed` 配 `exit_code: null` 是中间态,不是崩了**。`turn.completed` 先写状态,进程退出才写退出码。`wait_codex_workers` 会等到退出码落了再返回;直接读 status 撞上这个组合就过一会再读。
|
|
112
120
|
- **`ownedPaths` 冲突是好事**。说明两路活会踩同一个文件,这时候该改拆法,不是绕过检测。
|
|
113
|
-
- **`ownedPaths` 是派单前的冲突检测,不是运行时的沙箱**。它只挡「两路活登记写同一个文件」,拦不住 worker 在自己 worktree 里新建清单外的文件——sandbox 是 `workspace-write`,写自己 worktree 里的任何路径都合法。收活时该看 diff 还得看:`
|
|
121
|
+
- **`ownedPaths` 是派单前的冲突检测,不是运行时的沙箱**。它只挡「两路活登记写同一个文件」,拦不住 worker 在自己 worktree 里新建清单外的文件——sandbox 是 `workspace-write`,写自己 worktree 里的任何路径都合法。收活时该看 diff 还得看:`get_worker_result` / `get_worker_summary` 里的 `changed_files` 已经包含 worker 在自己分支上 commit 过的文件(按 `base_commit` 和 `HEAD` 比),不用再去 worktree 里跑 `git show --stat`。
|
|
114
122
|
- **worktree 只隔离工作区,不隔离端口和数据库**。多路活要是都会连同一个 dev server 或同一个库,得自己错开。
|
|
115
123
|
- **`cancel_codex_worker` 跨进程靠 pid**。要求那个 pid 的命令行里带 `codex`,防止误杀复用 pid 的进程。
|
|
116
124
|
|
|
125
|
+
## 看板
|
|
126
|
+
|
|
127
|
+
用户想用眼睛看这批活在干什么时,告诉他起 `codex-supervisor-web`(全局装过)或 `npx -p codex-supervisor-mcp codex-supervisor-web`,开 `http://127.0.0.1:7877`。看板按 session 分组,显示的就是派单时记的 `session_title`,所以标题要写得让人一眼看懂。
|
|
128
|
+
|
|
117
129
|
## 收尾
|
|
118
130
|
|
|
119
131
|
一批活全部到终态后:
|
package/src/codex-runner.js
CHANGED
|
@@ -9,13 +9,14 @@ import {
|
|
|
9
9
|
readActiveTasks,
|
|
10
10
|
readTaskEvents,
|
|
11
11
|
taskRunPath,
|
|
12
|
+
upsertSession,
|
|
12
13
|
upsertTask
|
|
13
14
|
} from "./task-store.js";
|
|
14
15
|
import { applyCodexEvent } from "./event-parser.js";
|
|
15
16
|
import { TERMINAL_STATUSES } from "./status.js";
|
|
16
17
|
import { worktreesDir } from "./paths.js";
|
|
17
18
|
import { withGoalPreamble } from "./prompt.js";
|
|
18
|
-
import {
|
|
19
|
+
import { readTaskChanges } from "./worktree.js";
|
|
19
20
|
import { defaultBinDirs, findBinaryPath, resolveCommand, shimMessage } from "./bin-resolver.js";
|
|
20
21
|
|
|
21
22
|
const processes = new Map();
|
|
@@ -51,21 +52,53 @@ function runCommand(command, args, options = {}) {
|
|
|
51
52
|
});
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
|
|
55
|
+
function resolveCommit(cwd, ref) {
|
|
56
|
+
return execFileSync(defaultGitBin, ["-C", cwd, "rev-parse", "--verify", "--quiet", `${ref}^{commit}`], {
|
|
57
|
+
encoding: "utf8",
|
|
58
|
+
timeout: 15000,
|
|
59
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
60
|
+
}).trim();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function invalidBaseRefError(cwd, baseRef) {
|
|
64
|
+
const error = new Error(`baseRef "${baseRef}" does not resolve to a commit in ${cwd}`);
|
|
65
|
+
error.code = "invalid_base_ref";
|
|
66
|
+
return error;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// The worktree is cut from baseRef when given, else from the repository's
|
|
70
|
+
// HEAD. The resolved commit is recorded on the task: it is what
|
|
71
|
+
// readWorktreeChanges diffs against, so committed work stays visible. An
|
|
72
|
+
// explicit baseRef that does not resolve is an error, not a silent fallback
|
|
73
|
+
// to HEAD - the caller asked for a specific baseline for a reason.
|
|
74
|
+
async function ensureWorktree(cwd, taskId, baseRef = null) {
|
|
55
75
|
const taskWorktreeDir = join(worktreesDir, taskId);
|
|
56
76
|
await mkdir(worktreesDir, { recursive: true });
|
|
57
77
|
const gitDir = join(cwd, ".git");
|
|
58
78
|
if (!(await exists(cwd)) || !(await exists(gitDir))) {
|
|
59
|
-
|
|
79
|
+
if (baseRef) throw invalidBaseRefError(cwd, baseRef);
|
|
80
|
+
return { path: null, baseCommit: null };
|
|
81
|
+
}
|
|
82
|
+
let baseCommit;
|
|
83
|
+
try {
|
|
84
|
+
baseCommit = resolveCommit(cwd, baseRef ?? "HEAD");
|
|
85
|
+
} catch {
|
|
86
|
+
if (baseRef) throw invalidBaseRefError(cwd, baseRef);
|
|
87
|
+
return { path: null, baseCommit: null };
|
|
88
|
+
}
|
|
89
|
+
if (!baseCommit) {
|
|
90
|
+
if (baseRef) throw invalidBaseRefError(cwd, baseRef);
|
|
91
|
+
return { path: null, baseCommit: null };
|
|
60
92
|
}
|
|
61
93
|
try {
|
|
62
94
|
await rm(taskWorktreeDir, { recursive: true, force: true });
|
|
63
95
|
const branch = `codex/${taskId}`;
|
|
64
|
-
await runCommand(defaultGitBin, ["-C", cwd, "worktree", "add", "--detach", taskWorktreeDir,
|
|
96
|
+
await runCommand(defaultGitBin, ["-C", cwd, "worktree", "add", "--detach", taskWorktreeDir, baseCommit]);
|
|
65
97
|
await runCommand(defaultGitBin, ["-C", taskWorktreeDir, "switch", "-c", branch]);
|
|
66
|
-
return taskWorktreeDir;
|
|
67
|
-
} catch {
|
|
68
|
-
|
|
98
|
+
return { path: taskWorktreeDir, baseCommit };
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (baseRef) throw error;
|
|
101
|
+
return { path: null, baseCommit: null };
|
|
69
102
|
}
|
|
70
103
|
}
|
|
71
104
|
|
|
@@ -298,7 +331,7 @@ async function startTrackedRun({ record, args, prompt, logPath, spawnOptions = {
|
|
|
298
331
|
...live,
|
|
299
332
|
status,
|
|
300
333
|
phase: null,
|
|
301
|
-
changed_files:
|
|
334
|
+
changed_files: readTaskChanges(live),
|
|
302
335
|
exit_code: code,
|
|
303
336
|
signal,
|
|
304
337
|
current_command: null,
|
|
@@ -354,6 +387,8 @@ export async function createCodexWorker({
|
|
|
354
387
|
title,
|
|
355
388
|
task,
|
|
356
389
|
sessionId = null,
|
|
390
|
+
sessionTitle = null,
|
|
391
|
+
sessionNote = null,
|
|
357
392
|
cwd,
|
|
358
393
|
sandbox = "workspace-write",
|
|
359
394
|
model = null,
|
|
@@ -363,7 +398,8 @@ export async function createCodexWorker({
|
|
|
363
398
|
goal,
|
|
364
399
|
dependsOn = [],
|
|
365
400
|
followupOf = null,
|
|
366
|
-
useWorktree = true
|
|
401
|
+
useWorktree = true,
|
|
402
|
+
baseRef = null
|
|
367
403
|
}) {
|
|
368
404
|
if (!task || typeof task !== "string") throw new Error("task is required");
|
|
369
405
|
if (!cwd || typeof cwd !== "string") throw new Error("cwd is required");
|
|
@@ -380,8 +416,15 @@ export async function createCodexWorker({
|
|
|
380
416
|
const conflicts = await findOwnershipConflicts(normalizedOwnedPaths);
|
|
381
417
|
if (conflicts.length > 0) throw ownershipConflictError(conflicts);
|
|
382
418
|
|
|
419
|
+
if (sessionId && (sessionTitle || sessionNote)) {
|
|
420
|
+
await upsertSession({ id: sessionId, title: sessionTitle, note: sessionNote });
|
|
421
|
+
}
|
|
422
|
+
|
|
383
423
|
const id = `codex-${Date.now()}-${randomUUID().slice(0, 8)}`;
|
|
384
|
-
const
|
|
424
|
+
const worktree = useWorktree
|
|
425
|
+
? await ensureWorktree(projectRoot, id, baseRef)
|
|
426
|
+
: { path: null, baseCommit: null };
|
|
427
|
+
const worktreePath = worktree.path;
|
|
385
428
|
const effectiveCwd = worktreePath ?? projectRoot;
|
|
386
429
|
|
|
387
430
|
const record = {
|
|
@@ -410,6 +453,7 @@ export async function createCodexWorker({
|
|
|
410
453
|
goal_updated_at: null,
|
|
411
454
|
run_count: 0,
|
|
412
455
|
worktree_path: worktreePath,
|
|
456
|
+
base_commit: worktree.baseCommit,
|
|
413
457
|
prompt: task,
|
|
414
458
|
changed_files: [],
|
|
415
459
|
commands: [],
|
|
@@ -590,13 +634,16 @@ export async function createFollowupWorker({
|
|
|
590
634
|
taskId,
|
|
591
635
|
followupPrompt,
|
|
592
636
|
sessionId = null,
|
|
637
|
+
sessionTitle = null,
|
|
638
|
+
sessionNote = null,
|
|
593
639
|
title,
|
|
594
640
|
cwd,
|
|
595
641
|
sandbox,
|
|
596
642
|
model,
|
|
597
643
|
reasoningEffort,
|
|
598
644
|
ownedPaths,
|
|
599
|
-
goal
|
|
645
|
+
goal,
|
|
646
|
+
baseRef
|
|
600
647
|
}) {
|
|
601
648
|
const parent = await getTask(taskId);
|
|
602
649
|
if (!parent) throw new Error(`task not found: ${taskId}`);
|
|
@@ -628,6 +675,8 @@ export async function createFollowupWorker({
|
|
|
628
675
|
title: title ?? `Follow-up for ${parent.id}`,
|
|
629
676
|
task: prompt,
|
|
630
677
|
sessionId: sessionId ?? parent.session_id ?? null,
|
|
678
|
+
sessionTitle,
|
|
679
|
+
sessionNote,
|
|
631
680
|
cwd: cwd ?? parent.project_root ?? parent.cwd,
|
|
632
681
|
sandbox: sandbox ?? parent.sandbox,
|
|
633
682
|
model: model ?? parent.model,
|
|
@@ -637,6 +686,7 @@ export async function createFollowupWorker({
|
|
|
637
686
|
goal: goal ?? { objective: parent.goal_objective ?? `Follow-up for ${parent.id}`, tokenBudget: parent.goal_token_budget ?? undefined },
|
|
638
687
|
dependsOn: [parent.id],
|
|
639
688
|
followupOf: parent.id,
|
|
640
|
-
useWorktree: true
|
|
689
|
+
useWorktree: true,
|
|
690
|
+
baseRef: baseRef ?? null
|
|
641
691
|
});
|
|
642
692
|
}
|