codex-supervisor-mcp 0.5.3 → 0.5.5

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 CHANGED
@@ -191,8 +191,8 @@ Fourteen of them.
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 |
193
193
  | `get_orchestration_overview` | `status`, `limit` | A compact status table for every worker, meant for the main thread |
194
- | `wait_codex_workers` | `task_ids`, `mode`(any/all), `timeoutMinutes`, `timeoutMs`, `includeEvents`, `eventLimit`, `eventMaxChars`, `eventKinds` | Wait for a terminal state, then return summaries. The default wait is 2 minutes: when it runs out you get a progress snapshot and the workers keep going, so call it again |
195
- | `get_codex_worker_status` | `task_id` | The full record for one worker |
194
+ | `wait_codex_workers` | `task_ids`, `mode`(any/all), `timeoutMinutes`, `timeoutMs`, `includeEvents`, `eventLimit`, `eventMaxChars`, `eventKinds` | Wait for a terminal state, then return summaries. The default wait is 2 minutes: when it runs out you get a progress snapshot and the workers keep going, so call it again. Events are **off** by default (`includeEvents: false`) |
195
+ | `get_codex_worker_status` | `task_id`, `includePrompt`, `promptMaxChars` | Status for one worker: lifecycle, phase, current action, changed files, goal, recent commands, with the prompt clipped. Pass `includePrompt: true` for the full prompt |
196
196
  | `get_codex_worker_events` | `task_id`, `limit`, `maxChars`, `kinds` | Read the raw event stream |
197
197
  | `get_worker_goal` | `task_id` | Read a worker's goal (supervisor side and native Codex side) |
198
198
  | `get_worker_summary` | `task_id` | One paragraph about a worker; what the main thread reads when wrapping up |
@@ -307,8 +307,10 @@ When the MCP client starts without `codex` on `PATH`, which is common for GUI-la
307
307
  - **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
308
  - **The worktree is created from `HEAD`, so uncommitted work isn't in it.** `ensureWorktree` runs `git worktree add --detach <dir> HEAD` (`src/codex-runner.js:64`). 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
309
  - **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
+ - **`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.
310
311
  - **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.
311
312
  - **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
+ - **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.
312
314
  - **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.
313
315
  - **Native goals depend on the model complying.** `codex exec` does not create a goal on its own; the instruction at dispatch time is what makes the worker create one. The model occasionally skips it, in which case `native_goal` is `null` and `get_worker_goal` falls back to the copy recorded at dispatch. The state machine is unaffected.
314
316
  - **`search_works` is substring matching, not a full-text index.** At a few hundred works, a `LIKE` scan is fast enough and costs nothing to maintain. Talk about something else at tens of thousands.
package/README.md CHANGED
@@ -191,8 +191,8 @@ rm -rf ~/.codex-supervisor # 状态目录:sqlite、事件流、worktree
191
191
  | `resume_codex_worker` | `task_id`, `prompt` | 接**同一个** Codex 会话继续跑 |
192
192
  | `list_codex_workers` | `status`, `includeHistory`, `includeDetails` | 列出 worker,默认只看在跑的 |
193
193
  | `get_orchestration_overview` | `status`, `limit` | 全部 worker 的紧凑状态表,默认给主线程用 |
194
- | `wait_codex_workers` | `task_ids`, `mode`(any/all), `timeoutMinutes`, `timeoutMs`, `includeEvents`, `eventLimit`, `eventMaxChars`, `eventKinds` | 等终态,回摘要。默认只等 2 分钟,到点带进度快照返回,worker 照跑;接着调同一个工具继续等 |
195
- | `get_codex_worker_status` | `task_id` | 单个 worker 的完整记录 |
194
+ | `wait_codex_workers` | `task_ids`, `mode`(any/all), `timeoutMinutes`, `timeoutMs`, `includeEvents`, `eventLimit`, `eventMaxChars`, `eventKinds` | 等终态,回摘要。默认只等 2 分钟,到点带进度快照返回,worker 照跑;接着调同一个工具继续等。默认**不带**事件(`includeEvents: false`),要事件就自己开 |
195
+ | `get_codex_worker_status` | `task_id`, `includePrompt`, `promptMaxChars` | 单个 worker 的状态:生命周期、phase、当前动作、改动文件、goal、最近的命令,prompt 默认截断。要 prompt 全文传 `includePrompt: true` |
196
196
  | `get_codex_worker_events` | `task_id`, `limit`, `maxChars`, `kinds` | 读原始事件流 |
197
197
  | `get_worker_goal` | `task_id` | 读 worker 的 goal(supervisor 侧 + Codex 原生) |
198
198
  | `get_worker_summary` | `task_id` | 单个 worker 的一段话总结,主线程收尾时读这个 |
@@ -307,8 +307,10 @@ Codex 原生 goal 有六个状态,映射到 work 状态:
307
307
  - **worker 的生命周期绑在 MCP 进程上**:`codex` 是 MCP 进程的子进程,MCP 被 kill 时 worker 会被留下。这些 worker 会在下一次 `list_codex_workers` / `get_orchestration_overview` 时被结算成 `lost`。真正的解法是常驻 daemon,见 Roadmap。
308
308
  - **worktree 从 `HEAD` 建,未提交的改动不在里面**:`ensureWorktree` 走的是 `git worktree add --detach <dir> HEAD`(`src/codex-runner.js:64`)。主线程工作区里没 commit 的修改和未跟踪文件,worker 在自己的 worktree 里看不到。要让它读写这些文件,就在 task 里给绝对路径,或者先把改动 commit。worker 的改动落在 `codex/<taskId>` 分支上,不碰主线程的工作区。
309
309
  - **只隔离工作目录**:临时目录(`TMPDIR`)、数据库、端口这些进程级资源是共用的,多个 worker 同时写同一个临时文件照样互相踩。要隔开得自己在 task 里指定各自的临时目录、库名和端口。
310
+ - **`ownedPaths` 是派单前的冲突检测,不是运行时沙箱**:它只挡「两路活登记写同一个文件」,拦不住 worker 在自己 worktree 里新建清单外的文件——sandbox 是 `workspace-write`,写自己 worktree 里的任何路径都合法。校验产出还是得看 diff。
310
311
  - **只管「跑完了」,不管写得对不对**:终态来自 Codex 的 `turn.completed` 和进程退出码,`exit_code: 0` 只说明它没崩。产出对不对得主线程自己核,跑校验、抽看内容。
311
312
  - **长任务别指望一次 `wait_codex_workers` 等到底**:客户端给 MCP 工具调用设的超时是硬墙(`.mcp.json` 里的 `timeout`,或 `MCP_TOOL_TIMEOUT`),撞上就把这次调用掐掉。默认 2 分钟带进度返回,靠反复调而不是一次等到黑。
313
+ - **默认读回来的长文本是裁过的**:`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——客户端把超时调用挪到后台、再把结果当通知回灌一次时,这份代价小得多。
312
314
  - **不往 Codex 原生 goal 写数据**:`goals_1.sqlite` 归 Codex 所有,本 MCP 只读。worker 起来后由它自己调 Codex 的 `create_goal` 建原生 goal,本 MCP 只负责在派单时把这段指令拼进 prompt。
313
315
  - **原生 goal 依赖模型照做**:`codex exec` 不会自动建 goal,是派单时那段指令让 worker 建的。模型偶尔漏调,这时 `native_goal` 为 `null`,`get_worker_goal` 退回派单时记录的那份,不影响状态机。
314
316
  - **`search_works` 是子串匹配,不是全文索引**:几百条 work 的规模下 `LIKE` 扫描足够快,也省掉一套索引的维护成本。上到几万条再谈别的。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-supervisor-mcp",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
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",
@@ -18,12 +18,14 @@ description: 把 Codex CLI 当并行 worker 派活、盯进度、收结果。用
18
18
  ## 一次派单
19
19
 
20
20
  1. 拆活。每路写清楚:干什么、能写哪些文件、怎么算做完。
21
- 2. `create_codex_worker` 派出去。
22
- 3. 派完就 `wait_codex_workers` 等,别轮询。
23
- 4. 收结果走 `get_worker_summary`,别一上来读事件流。
21
+ 2. `create_codex_worker` 派出去。返回的是一张精简回执(`id`、`worktree_path`、`branch`、`owned_paths`、`status`),任务原文不回传,派十一路也不会把你的提示词抄十一遍。
22
+ 3. 派完就 `wait_codex_workers` 等。默认只等 2 分钟,到点返回进度快照,worker 照跑;拿同一批 `task_ids` 接着调,直到 `timed_out: false`。默认**不带**事件(`includeEvents: false`),返回只够看状态,要事件得自己开。
23
+ 4. 收结果走 `get_worker_result`,拿完整汇报,别一上来读事件流。
24
24
 
25
25
  `ownedPaths` 和 `goal` 必填,不是可选项。
26
26
 
27
+ `wait_codex_workers` 的等待预算管的是这一次调用,不是 worker。返回里 `still_running: true` 是等满了,不是活挂了,按 `next_step` 接着调就行。别把 `timeoutMinutes` 开到超过客户端的 MCP 工具超时——那样被掐掉的是这次调用,丢的是这次的结果。
28
+
27
29
  | 参数 | 怎么填 |
28
30
  |---|---|
29
31
  | `task` | 这一路具体干什么。要能让对方直接开工,别写"优化一下" |
@@ -47,11 +49,16 @@ wait_codex_workers (task_ids: [...], mode: "all")
47
49
  | 想干什么 | 用哪个 | 代价 |
48
50
  |---|---|---|
49
51
  | 看全部 worker 现在什么状态 | `get_orchestration_overview` | ~1750 token,封顶 |
50
- | 收一路活的结果 | `get_worker_summary` | 一段话 |
52
+ | 收一路活的完整结论 | `get_worker_result` | 汇报全文,大活可能上万字 |
53
+ | 只想知道活着还是完了 | `get_worker_summary` | 一段话 |
51
54
  | 看某个 worker 干了什么 | `get_codex_worker_events` | 用 `limit` / `kinds` / `maxChars` 压 |
52
- | 看某个 worker 的完整记录 | `get_codex_worker_status` | 中等,比 overview 一行细 |
55
+ | 看某个 worker 的状态 | `get_codex_worker_status` | 比 overview 一行细,命令和 prompt 都裁过 |
53
56
  | 看 goal 和 token 消耗 | `get_worker_goal` | 很小 |
54
57
 
58
+ **收结论必须走 `get_worker_result`。** `wait_codex_workers` 返回里的 `last_message` 会被截到 400 字只留开头,`get_orchestration_overview` 干脆不给这一列。拿截断版当结论,后面的证据、数字和结论全会漏掉。`get_worker_result` 还会带回 `status`、`exit_code`、`changed_files`,顺便就能判断是真跑完还是崩了。
59
+
60
+ **默认读回来的长文本都是裁过的**,别把裁剪当成"活没干":`current_action` 截 300 字(一条 heredoc 命令能写一整个文件,原样回传一次就是几万字)、`get_codex_worker_status` 的 `prompt` 截 300 字(要全文传 `includePrompt: true`)、`last_message` 在 overview 和 wait 里截 400 字、在 status 里截 4000 字。全量在库里:命令流看 `get_codex_worker_events`,结论看 `get_worker_result`。
61
+
55
62
  `get_codex_worker_events` 的三个闸门:`kinds` 先过滤再取 `limit`;`maxChars` 把超长字符串中间截断;不知道有哪些 `kinds` 时先看返回里的 `available_kinds`。
56
63
 
57
64
  **别做**:一次 `limit: 200` 拉全量事件。那是几万 token。
@@ -100,7 +107,10 @@ wait_codex_workers (task_ids: [...], mode: "all")
100
107
  ## 常见坑
101
108
 
102
109
  - **worker 的命绑在 MCP 进程上**。MCP 被 kill,正在跑的 worker 会被留下,下次读状态时结算成 `lost`。
110
+ - **worktree 是从 `HEAD` 建的,你工作区里没 commit 的东西不在里面**。未提交的修改和未跟踪文件 worker 既看不到也写不到。要让它读到就把绝对路径写进 `task`,或者先把改动 commit。它自己的改动落在 `codex/<taskId>` 分支上,不碰你的工作区。
111
+ - **它只管"跑完了",不管写得对不对**。终态来自 Codex 的 `turn.completed` 和进程退出码,`exit_code: 0` 只说明没崩。每批活回来,验收得自己做:跑校验、抽看内容。
103
112
  - **`ownedPaths` 冲突是好事**。说明两路活会踩同一个文件,这时候该改拆法,不是绕过检测。
113
+ - **`ownedPaths` 是派单前的冲突检测,不是运行时的沙箱**。它只挡「两路活登记写同一个文件」,拦不住 worker 在自己 worktree 里新建清单外的文件——sandbox 是 `workspace-write`,写自己 worktree 里的任何路径都合法。收活时该看 diff 还得看:`git -C <worktree_path> show --stat`,或者 `get_worker_summary` 里的 `changed_files`。
104
114
  - **worktree 只隔离工作区,不隔离端口和数据库**。多路活要是都会连同一个 dev server 或同一个库,得自己错开。
105
115
  - **`cancel_codex_worker` 跨进程靠 pid**。要求那个 pid 的命令行里带 `codex`,防止误杀复用 pid 的进程。
106
116
 
@@ -109,6 +119,6 @@ wait_codex_workers (task_ids: [...], mode: "all")
109
119
  一批活全部到终态后:
110
120
 
111
121
  1. `get_orchestration_overview` 确认没有 `needs_attention`
112
- 2. 逐路 `get_worker_summary`
122
+ 2. 逐路 `get_worker_result` 拿完整汇报,对着验收标准核内容
113
123
  3. 失败的区分 `failed`(查原因)和 `lost`(重跑)
114
124
  4. 改动在各自 worktree 的 `codex/<taskId>` 分支上,合并由主线程决定
package/src/mcp-server.js CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import { readFileSync } from "node:fs";
2
3
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
4
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
5
  import { z } from "zod";
@@ -25,9 +26,15 @@ import { mergeChangedFiles, readWorktreeChanges } from "./worktree.js";
25
26
  import { ACTIVE_STATUSES, TERMINAL_STATUSES, TASK_STATUSES, isGoalNeedingAttention } from "./status.js";
26
27
  import { approxTokenCount, truncateEventStrings, truncateMiddleChars } from "./truncate.js";
27
28
 
29
+ // Report the real package version. This string had drifted to 0.4.0 while the
30
+ // package shipped 0.5.x, so the handshake named a version nobody was running.
31
+ const packageVersion = JSON.parse(
32
+ readFileSync(new URL("../package.json", import.meta.url), "utf8")
33
+ ).version;
34
+
28
35
  const server = new McpServer({
29
36
  name: "codex-supervisor",
30
- version: "0.4.0"
37
+ version: packageVersion
31
38
  });
32
39
 
33
40
  const OVERVIEW_BYTE_BUDGET = 7000;
@@ -38,6 +45,20 @@ const OVERVIEW_CAP_LEVELS = [
38
45
  { title: 12, goal: 16, action: 16, path: 16 }
39
46
  ];
40
47
 
48
+ // `current_action` is "Running <command>", and a command can be a heredoc that
49
+ // writes a whole file. Returning it whole put tens of thousands of characters
50
+ // into every wait response, which then blew past the client's MCP output cap
51
+ // and came back a second time as a notification. The full command stays in
52
+ // current_command / commands and is readable through get_codex_worker_events.
53
+ const ACTION_PREVIEW_CHARS = 300;
54
+ const COMMAND_PREVIEW_CHARS = 300;
55
+ const COMMAND_TAIL = 20;
56
+ const PROMPT_PREVIEW_CHARS = 300;
57
+ // The single-worker status read is the drill-in for one worker, so its copy of
58
+ // the last message stays much larger than the overview's 400. The full report
59
+ // is still get_worker_result's job.
60
+ const STATUS_MESSAGE_CHARS = 4000;
61
+
41
62
  function textResult(value) {
42
63
  return {
43
64
  content: [
@@ -83,7 +104,7 @@ function summarizeTask(task) {
83
104
  changed_file_count: (task.changed_files ?? []).length,
84
105
  command_count: (task.commands ?? []).length,
85
106
  run_count: task.run_count ?? 0,
86
- current_action: task.current_action,
107
+ current_action: clip(task.current_action, ACTION_PREVIEW_CHARS),
87
108
  last_event_type: task.last_event_type,
88
109
  last_message: clip(task.last_message, 400),
89
110
  notices: clip(task.notices, 400),
@@ -96,6 +117,30 @@ function summarizeTask(task) {
96
117
  };
97
118
  }
98
119
 
120
+ // The status read used to hand back the stored row verbatim. For a follow-up
121
+ // worker that row carries the parent prompt plus the whole command history and
122
+ // the events folded into it; one real call returned 180k characters, past the
123
+ // client's MCP output cap, so the reply landed on disk and had to be grepped.
124
+ // This is the same status surface the other reads use, plus explicitly bounded
125
+ // extras. includePrompt is the escape hatch for the full task text.
126
+ function statusView(task, { includePrompt, promptMaxChars }) {
127
+ const promptText = task.prompt ?? null;
128
+ const promptBudget = includePrompt ? promptMaxChars : PROMPT_PREVIEW_CHARS;
129
+ const commands = (task.commands ?? []).slice(-COMMAND_TAIL);
130
+ return {
131
+ ...summarizeTask(task),
132
+ last_message: clip(task.last_message, STATUS_MESSAGE_CHARS),
133
+ session_id: task.session_id ?? null,
134
+ pid: task.pid ?? null,
135
+ run_log: task.run_log ?? null,
136
+ changed_files: task.changed_files ?? [],
137
+ current_command: clip(task.current_command, COMMAND_PREVIEW_CHARS),
138
+ commands: commands.map((entry) => ({ ...entry, command: clip(entry.command, COMMAND_PREVIEW_CHARS) })),
139
+ prompt: clip(promptText, promptBudget),
140
+ prompt_truncated: Boolean(promptText) && String(promptText).length > promptBudget
141
+ };
142
+ }
143
+
99
144
  // The dispatch receipt. Dispatch used to return the whole task record, which
100
145
  // echoes the task text - and for a follow-up, the parent prompt plus 20 raw
101
146
  // events - back to the caller on every call. Dispatching eleven workers made
@@ -218,7 +263,7 @@ function buildWorkerSummary(task, nativeGoal) {
218
263
  : "codex goal: none recorded for this thread",
219
264
  `changed files (${changed.length}): ${changed.slice(0, 10).join(", ") || "-"}`,
220
265
  `last command: ${commands.at(-1)?.command ?? "-"}`,
221
- `last action: ${task.current_action ?? "-"}`,
266
+ `last action: ${clip(task.current_action, ACTION_PREVIEW_CHARS) ?? "-"}`,
222
267
  `runs: ${task.run_count ?? 0}${task.resumed_from ? `, resumed from ${task.resumed_from}` : ""}`,
223
268
  task.error ? `error: ${task.error}` : null
224
269
  ].filter(Boolean);
@@ -404,9 +449,17 @@ server.registerTool(
404
449
  timeoutMinutes: z.number().int().min(1).max(360).default(2),
405
450
  timeoutMs: z.number().int().min(1000).max(21600000).optional(),
406
451
  pollMs: z.number().int().min(250).max(10000).default(1000),
407
- includeEvents: z.boolean().default(true),
452
+ // Off by default. A wait is the call clients background and then replay
453
+ // as a notification, so its payload has to stay small; ten events per
454
+ // worker was the bulk of it. Ask for events explicitly, or read
455
+ // get_codex_worker_events for one worker.
456
+ includeEvents: z.boolean().default(false),
408
457
  eventLimit: z.number().int().min(1).max(50).default(10),
409
- eventMaxChars: z.number().int().min(0).max(1000000).optional(),
458
+ // Events used to come back whole: one command event can carry a heredoc
459
+ // that is tens of KB, and ten of those made a single wait response
460
+ // unreadable. The default bounds each string; pass a bigger number when
461
+ // you actually want the raw text.
462
+ eventMaxChars: z.number().int().min(0).max(1000000).default(800),
410
463
  eventKinds: z.array(z.string().min(1)).optional()
411
464
  }
412
465
  },
@@ -524,15 +577,18 @@ server.registerTool(
524
577
  "get_codex_worker_status",
525
578
  {
526
579
  title: "Get Codex worker status",
527
- description: "Read the latest normalized status for one Codex worker.",
580
+ description:
581
+ "Read the latest normalized status for one Codex worker: lifecycle, phase, current action, changed files, goal, recent commands, and the task prompt (clipped by default). Set includePrompt to read the prompt in full, or use get_codex_worker_events for the raw stream.",
528
582
  inputSchema: {
529
- task_id: z.string().min(1)
583
+ task_id: z.string().min(1),
584
+ includePrompt: z.boolean().default(false),
585
+ promptMaxChars: z.number().int().min(0).max(1000000).default(5000)
530
586
  }
531
587
  },
532
- async ({ task_id }) => {
588
+ async ({ task_id, includePrompt, promptMaxChars }) => {
533
589
  const task = await getTask(task_id);
534
590
  if (!task) return textResult({ error: "task_not_found", task_id });
535
- return textResult(task);
591
+ return textResult(statusView(task, { includePrompt, promptMaxChars }));
536
592
  }
537
593
  );
538
594