codex-supervisor-mcp 0.5.0 → 0.5.2
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.md +80 -23
- package/package.json +3 -3
- package/src/bin-resolver.js +18 -3
- package/src/codex-runner.js +21 -4
package/README.md
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
# codex-supervisor-mcp
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/codex-supervisor-mcp)
|
|
4
|
+
[](https://www.npmjs.com/package/codex-supervisor-mcp)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](https://github.com/zriyox/codex-supervisor-mcp/actions/workflows/ci.yml)
|
|
7
|
+
[](package.json)
|
|
8
|
+
|
|
3
9
|
让一个主线程(Claude Code、Codex、任何 MCP 客户端)同时指挥多个 Codex worker 干活。
|
|
4
10
|
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
*30 秒演示(真跑,非摆拍):Claude Code 主线程 `create_codex_worker` ×3 → 三个 worker 在各自 worktree 里并行干活 → 主线程收 3 份 diff 合并成一次 commit。*
|
|
14
|
+
|
|
5
15
|
一个 worker 一个独立 Git worktree,一个 worker 一个原生 Codex goal,状态全部落盘。主线程负责派单、等待、读结果、断线重连、取消。
|
|
6
16
|
|
|
7
17
|
## 它解决什么
|
|
@@ -33,40 +43,48 @@ Codex worker ──► data/runs/<taskId>.jsonl 原始 JSONL 事件流
|
|
|
33
43
|
|
|
34
44
|
## 安装
|
|
35
45
|
|
|
36
|
-
|
|
46
|
+
前置:**Node.js >= 22.13.0**(`node:sqlite` 在这个版本之前没有无 flag 的构建)和 `codex` CLI 在 `PATH` 里。macOS、Linux、Windows 都支持。
|
|
47
|
+
|
|
48
|
+
### 快速开始
|
|
37
49
|
|
|
38
50
|
```bash
|
|
51
|
+
# 1. 装
|
|
39
52
|
npm install -g codex-supervisor-mcp
|
|
53
|
+
|
|
54
|
+
# 2. 确认挂上了
|
|
55
|
+
claude mcp list | grep codex-supervisor
|
|
56
|
+
codex mcp list | grep codex-supervisor
|
|
40
57
|
```
|
|
41
58
|
|
|
42
|
-
|
|
59
|
+
全局安装的 `postinstall` 会自动做两件事,**不需要手动配置**:
|
|
43
60
|
|
|
44
61
|
1. 把配套 skill 装进检测到的客户端目录:`~/.claude/skills/`、`~/.agents/skills/`、`~/.codex/skills/`。
|
|
45
|
-
2. 用客户端自带的 CLI 注册 MCP:`claude mcp add -s user` / `codex mcp add
|
|
62
|
+
2. 用客户端自带的 CLI 注册 MCP:`claude mcp add -s user` / `codex mcp add`,注册的是 `node <包内绝对路径>`。
|
|
46
63
|
|
|
47
|
-
|
|
64
|
+
skill 已存在且内容不同时,先写一份 `SKILL.md.bak-<时间戳>` 再覆盖。任何一步失败都不会让安装失败。
|
|
48
65
|
|
|
49
|
-
|
|
66
|
+
### 手动挂载
|
|
50
67
|
|
|
51
|
-
|
|
52
|
-
codex-supervisor-setup # 自动检测客户端
|
|
53
|
-
codex-supervisor-setup --target claude,codex
|
|
54
|
-
codex-supervisor-setup --skill-only # 只装 skill
|
|
55
|
-
codex-supervisor-setup --dry-run # 只打印计划
|
|
56
|
-
```
|
|
68
|
+
`postinstall` 没跑到(`--ignore-scripts`、`npx`、pnpm 之类)时,自己补一条:
|
|
57
69
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
70
|
+
| 客户端 | 命令 |
|
|
71
|
+
|---|---|
|
|
72
|
+
| Claude Code | `claude mcp add -s user codex-supervisor -- npx -y codex-supervisor-mcp` |
|
|
73
|
+
| Codex | `codex mcp add codex-supervisor -- npx -y codex-supervisor-mcp` |
|
|
61
74
|
|
|
62
|
-
|
|
63
|
-
- 跨进程取消用 `taskkill /PID <pid> /T /F` 结束整棵进程树;确认这个 pid 还是 Codex 用 PowerShell 的 `Get-CimInstance Win32_Process` 读命令行(拿不到时退到 `tasklist`)。`ps` 只在 macOS / Linux 上用。
|
|
75
|
+
重跑、修复、只装某一个客户端,或者先看它打算干什么:
|
|
64
76
|
|
|
65
|
-
|
|
77
|
+
```bash
|
|
78
|
+
codex-supervisor-setup # 自动检测客户端,补装 skill + 注册 MCP
|
|
79
|
+
codex-supervisor-setup --target claude,codex
|
|
80
|
+
codex-supervisor-setup --skill-only # 只装 skill,不碰 MCP 配置
|
|
81
|
+
codex-supervisor-setup --mcp-only # 只注册 MCP,不装 skill
|
|
82
|
+
codex-supervisor-setup --dry-run # 只打印计划,不改任何东西
|
|
83
|
+
```
|
|
66
84
|
|
|
67
|
-
|
|
85
|
+
### 挂到 GUI 客户端
|
|
68
86
|
|
|
69
|
-
|
|
87
|
+
自己建/改下面的配置文件,加这一段(GUI 客户端不会跑 `postinstall`):
|
|
70
88
|
|
|
71
89
|
```json
|
|
72
90
|
{
|
|
@@ -79,12 +97,47 @@ codex-supervisor-setup --dry-run # 只打印计划
|
|
|
79
97
|
}
|
|
80
98
|
```
|
|
81
99
|
|
|
82
|
-
|
|
100
|
+
| 客户端 | macOS | Windows | Linux |
|
|
101
|
+
|---|---|---|---|
|
|
102
|
+
| Claude Desktop | `~/Library/Application Support/Claude/claude_desktop_config.json` | `%APPDATA%\Claude\claude_desktop_config.json` | `~/.config/Claude/claude_desktop_config.json` |
|
|
103
|
+
| Cursor | `~/.cursor/mcp.json` | `%APPDATA%\Cursor\mcp.json` | `~/.config/cursor/mcp.json` |
|
|
104
|
+
| Windsurf | `~/.codeium/windsurf/mcp_config.json` | `%APPDATA%\Codeium\windsurf\mcp_config.json` | `~/.config/.codeium/windsurf/mcp_config.json` |
|
|
105
|
+
|
|
106
|
+
### npx 的坑
|
|
107
|
+
|
|
108
|
+
`npx` 不跑 `postinstall`,所以 **skill 不会自动装、MCP 也不会自动注册**,只有 MCP server 本身能起来。要用配套 skill 就还是得 `npm install -g`,或者手动跑一次 `codex-supervisor-setup`。
|
|
109
|
+
|
|
110
|
+
### 卸载
|
|
83
111
|
|
|
84
112
|
```bash
|
|
85
|
-
|
|
113
|
+
npm uninstall -g codex-supervisor-mcp
|
|
114
|
+
claude mcp remove -s user codex-supervisor
|
|
115
|
+
codex mcp remove codex-supervisor
|
|
116
|
+
rm -rf ~/.claude/skills/codex-supervisor ~/.agents/skills/codex-supervisor ~/.codex/skills/codex-supervisor
|
|
117
|
+
rm -rf ~/.codex-supervisor # 状态目录:sqlite、事件流、worktree 全在这
|
|
86
118
|
```
|
|
87
119
|
|
|
120
|
+
### Windows
|
|
121
|
+
|
|
122
|
+
三条实现细节值得知道:
|
|
123
|
+
|
|
124
|
+
- npm 装的 CLI 在 Windows 上是 `codex.cmd` 而不是可执行文件,Node 从 18.20 / 20.12 起拒绝直接 `spawn` 它(CVE-2024-27980 之后的行为,报 `EINVAL`)。这里不用 `shell: true` 绕——那样 shell 会变成子进程,取消时只杀掉 shell 而真正的 Codex 还在跑,状态机会卡在 `running`。做法是绕到 npm 包自己的入口(`node_modules/@openai/codex/bin/codex.js`),用 `node` 起它;`CODEX_BIN` 指向 `.js` 时同样处理。
|
|
125
|
+
- 跨进程取消用 `taskkill /PID <pid> /T /F` 结束整棵进程树;确认这个 pid 还是 Codex 用 PowerShell 的 `Get-CimInstance Win32_Process` 读命令行(拿不到时退到 `tasklist`)。`ps` 只在 macOS / Linux 上用。
|
|
126
|
+
- 除了 `PATH`,还会探 `%APPDATA%\npm`、`%LOCALAPPDATA%\pnpm`、`%LOCALAPPDATA%\Volta\bin`、`%ProgramFiles%\nodejs`。
|
|
127
|
+
|
|
128
|
+
自动安装只在**全局安装**时发生。`npx`、`--ignore-scripts`、以及被别人当项目依赖装的场景都不会触发。要跳过用 `CODEX_SUPERVISOR_SKIP_SETUP=1`。
|
|
129
|
+
|
|
130
|
+
### 疑难排查
|
|
131
|
+
|
|
132
|
+
| 症状 | 原因 | 处理 |
|
|
133
|
+
|---|---|---|
|
|
134
|
+
| `claude mcp list` 里没有 `codex-supervisor` | `npx` / `--ignore-scripts` 装法不跑 `postinstall` | 跑 `codex-supervisor-setup`,或用上面的手动挂载 |
|
|
135
|
+
| 派单报 `codex only resolved to a shell shim` | Windows 上只找到 `.cmd`,背后的 npm 包入口不在了 | 重装 `@openai/codex`,或把 `CODEX_BIN` 指到真正的可执行文件 / `codex.js` |
|
|
136
|
+
| worker 起来就 `failed`,错误是 `spawn codex ENOENT` | GUI 客户端启动的进程 `PATH` 里没有 `codex` | 在客户端配置里显式设 `CODEX_BIN` |
|
|
137
|
+
| `Cannot find module 'node:sqlite'` | Node < 22.13.0 | 升 Node |
|
|
138
|
+
| worker 卡在 `lost` | MCP 进程被 kill,worker 成了孤儿 | `list_codex_workers` 结算一次,或 `resume_codex_worker` 接回来 |
|
|
139
|
+
| 报 `ownedPaths overlap with active worker(s)` | 两个 worker 认领了同一片路径 | 换路径,或先 `cancel_codex_worker` 掉占用的那个 |
|
|
140
|
+
|
|
88
141
|
## 工具
|
|
89
142
|
|
|
90
143
|
13 个工具。
|
|
@@ -152,6 +205,8 @@ starting → thinking → command → editing → reporting
|
|
|
152
205
|
|
|
153
206
|
`failed` 和 `lost` 分开是有用的:前者要看日志找原因,后者直接重跑。
|
|
154
207
|
|
|
208
|
+
Windows 上没有信号,所以这两者在那里只有一种能判出来。libuv 杀进程走的是 `TerminateProcess(handle, 1)`,外部 kill 和进程自己 `exit(1)` 落到父进程手里完全一样(都是 `exit_code=1`、`signal=null`)。这种情况下报能证明的那个——`failed` 加退出码——而不是编一个平台根本没收到的信号名。Windows 上的 `lost` 仍然会发生,走的是 MCP 进程消失、下次启动结算孤儿那条路。
|
|
209
|
+
|
|
155
210
|
### goal 和 work 的映射
|
|
156
211
|
|
|
157
212
|
Codex 原生 goal 有六个状态,映射到 work 状态:
|
|
@@ -187,7 +242,7 @@ Codex 原生 goal 有六个状态,映射到 work 状态:
|
|
|
187
242
|
|---|---|---|
|
|
188
243
|
| `SUPERVISOR_HOME` | `~/.codex-supervisor` | 状态根目录(sqlite / 事件流 / worktree 都在它下面) |
|
|
189
244
|
| `CODEX_HOME` | `~/.codex` | 只读,用来读 Codex 原生的 `goals_1.sqlite` |
|
|
190
|
-
| `CODEX_BIN` | `codex`(走 `PATH`) | Codex CLI 可执行文件路径。Windows 上给裸名字时会按 `PATHEXT` 展开,`.cmd` shim
|
|
245
|
+
| `CODEX_BIN` | `codex`(走 `PATH`) | Codex CLI 可执行文件路径。Windows 上给裸名字时会按 `PATHEXT` 展开,`.cmd` shim 会被自动绕开;指向 `.js` / `.cjs` / `.mjs` 时自动用 `node` 起它 |
|
|
191
246
|
| `GIT_BIN` | `git`(走 `PATH`) | Git 可执行文件路径 |
|
|
192
247
|
|
|
193
248
|
如果 MCP 客户端启动时 `PATH` 里没有 `codex`(GUI 启动的应用常见),显式设置 `CODEX_BIN`:
|
|
@@ -257,7 +312,7 @@ skill 里写了派单流程、读结果该按什么顺序、`failed` 和 `lost`
|
|
|
257
312
|
|
|
258
313
|
```bash
|
|
259
314
|
npm install
|
|
260
|
-
npm test #
|
|
315
|
+
npm test # 确定性测试:截断、状态机、v1→v2 迁移、setup、Windows 路由、17 项端到端回归
|
|
261
316
|
npm run test:real # 用真 codex CLI 跑端到端(含跨进程 resume、worktree 隔离)
|
|
262
317
|
npm run smoke # 基础冒烟(真 codex)
|
|
263
318
|
npm run smoke:mcp # MCP 协议冒烟
|
|
@@ -266,6 +321,8 @@ npm run monitor # Ink 终端看板
|
|
|
266
321
|
|
|
267
322
|
`npm test` 用 `src/test-fixtures/fake-codex.js` 回放固定的 Codex 事件流,跑得快且确定。`npm run test:real` 会真的调 `codex exec`,慢一些,但它才是「跟最新 Codex 兼容」的证据。
|
|
268
323
|
|
|
324
|
+
CI 跑 Ubuntu / macOS / Windows 三个平台,另外单独跑一个 Node 22.13.0 的 job 卡住 `engines` 声明的下界(`node:sqlite` 在它之前没有无 flag 的构建)。Windows 那 4 项 `setup-windows-test.js` 用真实文件系统模拟 `%APPDATA%\npm` 下的 `.cmd` shim,验证自动注册 MCP 这条路真的走得通,而不只是「解析函数单测过了」。
|
|
325
|
+
|
|
269
326
|
## License
|
|
270
327
|
|
|
271
328
|
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codex-supervisor-mcp",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
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",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"start": "node ./src/mcp-server.js",
|
|
52
52
|
"monitor": "tsx ./src/monitor.jsx",
|
|
53
53
|
"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/regression-test.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",
|
|
55
55
|
"test:real": "node ./src/real-codex-test.js",
|
|
56
56
|
"smoke": "node ./src/smoke-test.js",
|
|
57
57
|
"smoke:followup": "node ./src/followup-smoke-test.js",
|
|
@@ -67,6 +67,6 @@
|
|
|
67
67
|
"tsx": "^4.21.0"
|
|
68
68
|
},
|
|
69
69
|
"engines": {
|
|
70
|
-
"node": ">=22"
|
|
70
|
+
"node": ">=22.13.0"
|
|
71
71
|
}
|
|
72
72
|
}
|
package/src/bin-resolver.js
CHANGED
|
@@ -23,6 +23,8 @@ const DIRECT_EXTS = new Set([".exe", ".com"]);
|
|
|
23
23
|
const SHIM_EXTS = new Set([".cmd", ".bat", ".ps1"]);
|
|
24
24
|
/** Fallback when PATHEXT is unset, matching the Windows default. */
|
|
25
25
|
const DEFAULT_PATHEXT = ".COM;.EXE;.BAT;.CMD";
|
|
26
|
+
/** Extensions that need node in front of them on every platform. */
|
|
27
|
+
const JS_EXTS = new Set([".js", ".cjs", ".mjs"]);
|
|
26
28
|
|
|
27
29
|
/**
|
|
28
30
|
* Well-known global install directories, probed after PATH. A CLI installed with
|
|
@@ -125,9 +127,17 @@ export function findBinaryPath(binary, options = {}) {
|
|
|
125
127
|
/**
|
|
126
128
|
* Resolve a command name into a spawnable target.
|
|
127
129
|
*
|
|
130
|
+
* A JS entry point (`.js` / `.cjs` / `.mjs`) is run under node on every
|
|
131
|
+
* platform, because a script is not something either kernel can spawn on its
|
|
132
|
+
* own: Windows refuses outright, and POSIX only manages it while the shebang
|
|
133
|
+
* and the executable bit survive - which a checkout or a copy can drop. This
|
|
134
|
+
* matters for `CODEX_BIN`, whose natural value is the npm package's own entry
|
|
135
|
+
* point (`node_modules/@openai/codex/bin/codex.js`) - the same file the shim
|
|
136
|
+
* bypass produces.
|
|
137
|
+
*
|
|
128
138
|
* Pass-through cases (behaviour identical to a bare `spawn(name, argv)`):
|
|
129
|
-
* - any name containing a path separator - an explicit path is the
|
|
130
|
-
* business, and the tests rely on this
|
|
139
|
+
* - any other name containing a path separator - an explicit path is the
|
|
140
|
+
* caller's business, and the tests rely on this
|
|
131
141
|
* - any non-win32 platform - macOS and Linux behaviour must not change
|
|
132
142
|
* - win32 with no PATH match - preserve the ordinary ENOENT
|
|
133
143
|
*
|
|
@@ -145,11 +155,16 @@ export function resolveCommand(name, options = {}) {
|
|
|
145
155
|
if (typeof name !== "string" || !name) return passthrough;
|
|
146
156
|
|
|
147
157
|
const platform = options.platform ?? process.platform;
|
|
158
|
+
const nodePath = options.nodePath ?? process.execPath;
|
|
159
|
+
|
|
160
|
+
if (JS_EXTS.has(pathImpl(platform).extname(name).toLowerCase())) {
|
|
161
|
+
return { cmd: nodePath, prefixArgs: [name], shim: false };
|
|
162
|
+
}
|
|
163
|
+
|
|
148
164
|
if (!isWindows(platform)) return passthrough;
|
|
149
165
|
|
|
150
166
|
const env = options.env ?? process.env;
|
|
151
167
|
const exists = options.exists ?? existsSync;
|
|
152
|
-
const nodePath = options.nodePath ?? process.execPath;
|
|
153
168
|
const bypass = (shimPath) => npmBypass(shimPath, options.npmEntry, exists, nodePath);
|
|
154
169
|
|
|
155
170
|
const dirs = String(env.PATH ?? env.Path ?? "")
|
package/src/codex-runner.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createWriteStream } from "node:fs";
|
|
1
|
+
import { createWriteStream, existsSync } from "node:fs";
|
|
2
2
|
import { mkdir, rm, stat } from "node:fs/promises";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
import { execFileSync, spawn } from "node:child_process";
|
|
@@ -470,20 +470,37 @@ export async function resumeCodexWorker({ taskId, prompt }) {
|
|
|
470
470
|
return started.record;
|
|
471
471
|
}
|
|
472
472
|
|
|
473
|
+
// `powershell` by name is not always on PATH for a process a GUI client
|
|
474
|
+
// started, so prefer the copy that ships with Windows. Only the CIM path needs
|
|
475
|
+
// it; the rest of this file shells out to nothing but taskkill and git.
|
|
476
|
+
function powershellBin() {
|
|
477
|
+
const root = process.env.SystemRoot?.trim() || "C:\\Windows";
|
|
478
|
+
const full = join(root, "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
|
|
479
|
+
return existsSync(full) ? full : "powershell";
|
|
480
|
+
}
|
|
481
|
+
|
|
473
482
|
// A pid recorded on disk is only signalled once it is confirmed to still be a
|
|
474
483
|
// Codex worker, so a recycled pid belonging to an unrelated process is never
|
|
475
484
|
// killed. Windows has no `ps`: CIM is the only reliable source for a full command
|
|
476
485
|
// line, and the full line matters because the npm shim is bypassed by running
|
|
477
486
|
// `node <entry>`, which puts the word "codex" in the arguments, not the image
|
|
478
|
-
// name. `tasklist` is the fallback when PowerShell is unavailable
|
|
487
|
+
// name. `tasklist` is the fallback when PowerShell is unavailable - it only
|
|
488
|
+
// reports the image name, so it can confirm a native codex.exe but never a
|
|
489
|
+
// `node <entry>` worker.
|
|
490
|
+
//
|
|
491
|
+
// The timeout is generous on purpose: this runs once per cross-process cancel,
|
|
492
|
+
// and a cold Windows PowerShell on a fresh machine routinely takes several
|
|
493
|
+
// seconds to print anything. A tight timeout here silently degrades to the
|
|
494
|
+
// useless tasklist probe, and the cancel comes back "process_not_found".
|
|
479
495
|
function describeProcess(pid) {
|
|
480
|
-
const options = { encoding: "utf8", timeout:
|
|
496
|
+
const options = { encoding: "utf8", timeout: 15000, windowsHide: true };
|
|
481
497
|
try {
|
|
482
498
|
if (process.platform === "win32") {
|
|
483
499
|
try {
|
|
484
500
|
const viaCim = execFileSync(
|
|
485
|
-
|
|
501
|
+
powershellBin(),
|
|
486
502
|
[
|
|
503
|
+
"-NoLogo",
|
|
487
504
|
"-NoProfile",
|
|
488
505
|
"-NonInteractive",
|
|
489
506
|
"-Command",
|