codex-supervisor-mcp 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # codex-supervisor-mcp
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/codex-supervisor-mcp.svg)](https://www.npmjs.com/package/codex-supervisor-mcp)
4
+ [![npm downloads](https://img.shields.io/npm/dm/codex-supervisor-mcp.svg)](https://www.npmjs.com/package/codex-supervisor-mcp)
5
+ [![license](https://img.shields.io/npm/l/codex-supervisor-mcp.svg)](LICENSE)
6
+ [![CI](https://github.com/zriyox/codex-supervisor-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/zriyox/codex-supervisor-mcp/actions/workflows/ci.yml)
7
+ [![node](https://img.shields.io/badge/node-%3E%3D22.13.0-339933.svg)](package.json)
8
+
3
9
  让一个主线程(Claude Code、Codex、任何 MCP 客户端)同时指挥多个 Codex worker 干活。
4
10
 
5
11
  一个 worker 一个独立 Git worktree,一个 worker 一个原生 Codex goal,状态全部落盘。主线程负责派单、等待、读结果、断线重连、取消。
@@ -33,40 +39,48 @@ Codex worker ──► data/runs/<taskId>.jsonl 原始 JSONL 事件流
33
39
 
34
40
  ## 安装
35
41
 
36
- 需要 Node.js >= 22 和 `codex` CLI 在 `PATH` 里。macOS、Linux、Windows 都支持。
42
+ 前置:**Node.js >= 22.13.0**(`node:sqlite` 在这个版本之前没有无 flag 的构建)和 `codex` CLI 在 `PATH` 里。macOS、Linux、Windows 都支持。
43
+
44
+ ### 快速开始
37
45
 
38
46
  ```bash
47
+ # 1. 装
39
48
  npm install -g codex-supervisor-mcp
49
+
50
+ # 2. 确认挂上了
51
+ claude mcp list | grep codex-supervisor
52
+ codex mcp list | grep codex-supervisor
40
53
  ```
41
54
 
42
- 全局安装会自动完成两件事(`postinstall`):
55
+ 全局安装的 `postinstall` 会自动做两件事,**不需要手动配置**:
43
56
 
44
57
  1. 把配套 skill 装进检测到的客户端目录:`~/.claude/skills/`、`~/.agents/skills/`、`~/.codex/skills/`。
45
- 2. 用客户端自带的 CLI 注册 MCP:`claude mcp add -s user` / `codex mcp add`。
46
-
47
- 目标 skill 已存在且内容不同时,先写一份 `SKILL.md.bak-<时间戳>` 再覆盖。任何一步失败都不会让安装失败。
58
+ 2. 用客户端自带的 CLI 注册 MCP:`claude mcp add -s user` / `codex mcp add`,注册的是 `node <包内绝对路径>`。
48
59
 
49
- 重跑、修复、或只装某一个客户端:
60
+ skill 已存在且内容不同时,先写一份 `SKILL.md.bak-<时间戳>` 再覆盖。任何一步失败都不会让安装失败。
50
61
 
51
- ```bash
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
- ```
62
+ ### 手动挂载
57
63
 
58
- ### Windows
64
+ `postinstall` 没跑到(`--ignore-scripts`、`npx`、pnpm 之类)时,自己补一条:
59
65
 
60
- 支持 Windows,两条实现细节值得知道:
66
+ | 客户端 | 命令 |
67
+ |---|---|
68
+ | Claude Code | `claude mcp add -s user codex-supervisor -- npx -y codex-supervisor-mcp` |
69
+ | Codex | `codex mcp add codex-supervisor -- npx -y codex-supervisor-mcp` |
61
70
 
62
- - 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` 起它。
63
- - 跨进程取消用 `taskkill /PID <pid> /T /F` 结束整棵进程树;确认这个 pid 还是 Codex 用 PowerShell 的 `Get-CimInstance Win32_Process` 读命令行(拿不到时退到 `tasklist`)。`ps` 只在 macOS / Linux 上用。
71
+ 重跑、修复、只装某一个客户端,或者先看它打算干什么:
64
72
 
65
- 除了 `PATH`,还会探 `%APPDATA%\npm`、`%LOCALAPPDATA%\pnpm`、`%LOCALAPPDATA%\Volta\bin`、`%ProgramFiles%\nodejs`。
73
+ ```bash
74
+ codex-supervisor-setup # 自动检测客户端,补装 skill + 注册 MCP
75
+ codex-supervisor-setup --target claude,codex
76
+ codex-supervisor-setup --skill-only # 只装 skill,不碰 MCP 配置
77
+ codex-supervisor-setup --mcp-only # 只注册 MCP,不装 skill
78
+ codex-supervisor-setup --dry-run # 只打印计划,不改任何东西
79
+ ```
66
80
 
67
- 自动安装只在**全局安装**时发生。`npx`、`--ignore-scripts`、以及被别人当项目依赖装的场景都不会触发。要跳过用 `CODEX_SUPERVISOR_SKIP_SETUP=1`;要补装手动跑一次 `codex-supervisor-setup`。
81
+ ### 挂到 GUI 客户端
68
82
 
69
- ### 手动配置到 Claude Code
83
+ 自己建/改下面的配置文件,加这一段(GUI 客户端不会跑 `postinstall`):
70
84
 
71
85
  ```json
72
86
  {
@@ -79,12 +93,47 @@ codex-supervisor-setup --dry-run # 只打印计划
79
93
  }
80
94
  ```
81
95
 
82
- ### 配置到 Codex
96
+ | 客户端 | macOS | Windows | Linux |
97
+ |---|---|---|---|
98
+ | Claude Desktop | `~/Library/Application Support/Claude/claude_desktop_config.json` | `%APPDATA%\Claude\claude_desktop_config.json` | `~/.config/Claude/claude_desktop_config.json` |
99
+ | Cursor | `~/.cursor/mcp.json` | `%APPDATA%\Cursor\mcp.json` | `~/.config/cursor/mcp.json` |
100
+ | Windsurf | `~/.codeium/windsurf/mcp_config.json` | `%APPDATA%\Codeium\windsurf\mcp_config.json` | `~/.config/.codeium/windsurf/mcp_config.json` |
101
+
102
+ ### npx 的坑
103
+
104
+ `npx` 不跑 `postinstall`,所以 **skill 不会自动装、MCP 也不会自动注册**,只有 MCP server 本身能起来。要用配套 skill 就还是得 `npm install -g`,或者手动跑一次 `codex-supervisor-setup`。
105
+
106
+ ### 卸载
83
107
 
84
108
  ```bash
85
- codex mcp add codex-supervisor -- npx -y codex-supervisor-mcp
109
+ npm uninstall -g codex-supervisor-mcp
110
+ claude mcp remove -s user codex-supervisor
111
+ codex mcp remove codex-supervisor
112
+ rm -rf ~/.claude/skills/codex-supervisor ~/.agents/skills/codex-supervisor ~/.codex/skills/codex-supervisor
113
+ rm -rf ~/.codex-supervisor # 状态目录:sqlite、事件流、worktree 全在这
86
114
  ```
87
115
 
116
+ ### Windows
117
+
118
+ 三条实现细节值得知道:
119
+
120
+ - 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` 时同样处理。
121
+ - 跨进程取消用 `taskkill /PID <pid> /T /F` 结束整棵进程树;确认这个 pid 还是 Codex 用 PowerShell 的 `Get-CimInstance Win32_Process` 读命令行(拿不到时退到 `tasklist`)。`ps` 只在 macOS / Linux 上用。
122
+ - 除了 `PATH`,还会探 `%APPDATA%\npm`、`%LOCALAPPDATA%\pnpm`、`%LOCALAPPDATA%\Volta\bin`、`%ProgramFiles%\nodejs`。
123
+
124
+ 自动安装只在**全局安装**时发生。`npx`、`--ignore-scripts`、以及被别人当项目依赖装的场景都不会触发。要跳过用 `CODEX_SUPERVISOR_SKIP_SETUP=1`。
125
+
126
+ ### 疑难排查
127
+
128
+ | 症状 | 原因 | 处理 |
129
+ |---|---|---|
130
+ | `claude mcp list` 里没有 `codex-supervisor` | `npx` / `--ignore-scripts` 装法不跑 `postinstall` | 跑 `codex-supervisor-setup`,或用上面的手动挂载 |
131
+ | 派单报 `codex only resolved to a shell shim` | Windows 上只找到 `.cmd`,背后的 npm 包入口不在了 | 重装 `@openai/codex`,或把 `CODEX_BIN` 指到真正的可执行文件 / `codex.js` |
132
+ | worker 起来就 `failed`,错误是 `spawn codex ENOENT` | GUI 客户端启动的进程 `PATH` 里没有 `codex` | 在客户端配置里显式设 `CODEX_BIN` |
133
+ | `Cannot find module 'node:sqlite'` | Node < 22.13.0 | 升 Node |
134
+ | worker 卡在 `lost` | MCP 进程被 kill,worker 成了孤儿 | `list_codex_workers` 结算一次,或 `resume_codex_worker` 接回来 |
135
+ | 报 `ownedPaths overlap with active worker(s)` | 两个 worker 认领了同一片路径 | 换路径,或先 `cancel_codex_worker` 掉占用的那个 |
136
+
88
137
  ## 工具
89
138
 
90
139
  13 个工具。
@@ -152,6 +201,8 @@ starting → thinking → command → editing → reporting
152
201
 
153
202
  `failed` 和 `lost` 分开是有用的:前者要看日志找原因,后者直接重跑。
154
203
 
204
+ Windows 上没有信号,所以这两者在那里只有一种能判出来。libuv 杀进程走的是 `TerminateProcess(handle, 1)`,外部 kill 和进程自己 `exit(1)` 落到父进程手里完全一样(都是 `exit_code=1`、`signal=null`)。这种情况下报能证明的那个——`failed` 加退出码——而不是编一个平台根本没收到的信号名。Windows 上的 `lost` 仍然会发生,走的是 MCP 进程消失、下次启动结算孤儿那条路。
205
+
155
206
  ### goal 和 work 的映射
156
207
 
157
208
  Codex 原生 goal 有六个状态,映射到 work 状态:
@@ -187,7 +238,7 @@ Codex 原生 goal 有六个状态,映射到 work 状态:
187
238
  |---|---|---|
188
239
  | `SUPERVISOR_HOME` | `~/.codex-supervisor` | 状态根目录(sqlite / 事件流 / worktree 都在它下面) |
189
240
  | `CODEX_HOME` | `~/.codex` | 只读,用来读 Codex 原生的 `goals_1.sqlite` |
190
- | `CODEX_BIN` | `codex`(走 `PATH`) | Codex CLI 可执行文件路径。Windows 上给裸名字时会按 `PATHEXT` 展开,`.cmd` shim 会被自动绕开 |
241
+ | `CODEX_BIN` | `codex`(走 `PATH`) | Codex CLI 可执行文件路径。Windows 上给裸名字时会按 `PATHEXT` 展开,`.cmd` shim 会被自动绕开;指向 `.js` / `.cjs` / `.mjs` 时自动用 `node` 起它 |
191
242
  | `GIT_BIN` | `git`(走 `PATH`) | Git 可执行文件路径 |
192
243
 
193
244
  如果 MCP 客户端启动时 `PATH` 里没有 `codex`(GUI 启动的应用常见),显式设置 `CODEX_BIN`:
@@ -257,7 +308,7 @@ skill 里写了派单流程、读结果该按什么顺序、`failed` 和 `lost`
257
308
 
258
309
  ```bash
259
310
  npm install
260
- npm test # 确定性测试:截断移植、状态机、v1→v2 迁移、setup、Windows 解析器、17 项端到端回归
311
+ npm test # 确定性测试:截断、状态机、v1→v2 迁移、setup、Windows 路由、17 项端到端回归
261
312
  npm run test:real # 用真 codex CLI 跑端到端(含跨进程 resume、worktree 隔离)
262
313
  npm run smoke # 基础冒烟(真 codex)
263
314
  npm run smoke:mcp # MCP 协议冒烟
@@ -266,6 +317,8 @@ npm run monitor # Ink 终端看板
266
317
 
267
318
  `npm test` 用 `src/test-fixtures/fake-codex.js` 回放固定的 Codex 事件流,跑得快且确定。`npm run test:real` 会真的调 `codex exec`,慢一些,但它才是「跟最新 Codex 兼容」的证据。
268
319
 
320
+ CI 跑 Ubuntu / macOS / Windows 三个平台,另外单独跑一个 Node 22.13.0 的 job 卡住 `engines` 声明的下界(`node:sqlite` 在它之前没有无 flag 的构建)。Windows 那 4 项 `setup-windows-test.js` 用真实文件系统模拟 `%APPDATA%\npm` 下的 `.cmd` shim,验证自动注册 MCP 这条路真的走得通,而不只是「解析函数单测过了」。
321
+
269
322
  ## License
270
323
 
271
324
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-supervisor-mcp",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
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
  }
@@ -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 caller's
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 ?? "")
@@ -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: 2000, windowsHide: true };
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
- "powershell",
501
+ powershellBin(),
486
502
  [
503
+ "-NoLogo",
487
504
  "-NoProfile",
488
505
  "-NonInteractive",
489
506
  "-Command",