codex-supervisor-mcp 0.9.2 → 0.9.4

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
@@ -198,7 +198,7 @@ Declare externalOutputs:[{path,sha256?}] and acceptance for shared writes. Targe
198
198
 
199
199
  workspace-write defaults to networkAccess:false; explicitly enable it for ssh/network checks. Resume/follow-up inherit the setting. maxRunMs bounds one run and maxTotalMs bounds wall time since dispatch; exceeding either stops the worker and preserves actionable partial results without automatic retry. A wait budget does not change these quotas.
200
200
 
201
- Besides the worktree and the temp directory the sandbox writes the OS cache directory only (macOS `~/Library/Caches`, Linux `~/.cache`, Windows `%LOCALAPPDATA%`). Toolchains that cache there, Go's build cache among them, need no per-language variable and no patch when a new language shows up. A toolchain that caches elsewhere (`~/.m2`, `~/.gradle`, a vendored mirror) passes `writableRoots:[absolute paths]`: existing directories, at most 20, workspace-write only, inherited by resume/follow-up. Read-only reuse needs nothing.
201
+ Besides the worktree and the temp directory the sandbox writes the OS cache directory (macOS `~/Library/Caches`, Linux `~/.cache`, Windows `%LOCALAPPDATA%`), the toolchain cache directories that exist under the home directory (`.cargo`, `.npm`, `.yarn`, `.pnpm-store`, `.bun`, `.m2`, `.gradle`, `.nuget`, `.ivy2`, `.bundle`, `.composer`, `.pub-cache`, `.mix`, `.hex`, `.stack`, `.cpanm`, `.deno`, `.conda`, `go/pkg`) Credential directories (`.ssh`, `.gnupg`, `.config`, `.aws`, `.docker`, `.kube`, `.netrc`, `.git-credentials`, `~/Library/Keychains`) are never granted automatically: a dispatch that needs ssh, kubectl, a private registry or a signed commit names the directory in `writableRoots` for that run. `SUPERVISOR_NO_AUTO_CACHE_ROOTS=1` turns every automatic cache root off; an explicit `writableRoots` still applies. Toolchains that cache there, Go's build cache among them, need no per-language variable and no patch when a new language shows up. Codex refuses a writable root with a symlink component, and such a root fails every command in the worker, so both the cache directory and every declared `writableRoots` entry are resolved through realpath first and a root that cannot be resolved to a symlink-free path is dropped. A toolchain that caches elsewhere (`~/.m2`, `~/.gradle`, a vendored mirror) passes `writableRoots:[absolute paths]`: existing directories, at most 20, workspace-write only, inherited by resume/follow-up. Read-only reuse needs nothing.
202
202
 
203
203
  Dispatch checks required hooks/output-schema support (Codex 0.162+); unsupported capability returns settled start_failed. get_worker_goal.native_goal_read distinguishes missing_goal, missing_database, locked and read_error; a read failure is not evidence that no goal exists. Native budget/usage limits need attention. Cleanup preserves ignored artifacts, shared evidence and unresolved attention.
204
204
 
package/README.md CHANGED
@@ -198,7 +198,7 @@ context用绝对文件路径与可选sha256声明材料,最多20份、与contr
198
198
 
199
199
  workspace-write默认networkAccess:false;需要ssh/联网验证显式true,随resume/followup继承,不以danger-full-access代替。maxRunMs限制单轮、maxTotalMs限制从派单开始的总时长;超限中止worker并保留needs_attention/partial work,不自动重试。wait预算不改变这些quota。
200
200
 
201
- 沙箱除工作区和临时目录外,只再放开 OS cache 目录(macOS `~/Library/Caches`、Linux `~/.cache`、Windows `%LOCALAPPDATA%`):Go 的 build cache 这类默认落在 cache 目录的工具链直接可用,换语言也不用改 supervisor。cache 放在别处(`~/.m2`、`~/.gradle`、vendor 镜像)就传 `writableRoots:[绝对路径]`,要求是已存在目录、最多 20 个、只对 workspace-write 生效、随 resume/followup 继承;只读复用就不用传。
201
+ 沙箱除工作区和临时目录外,自动放开 OS cache 目录(macOS `~/Library/Caches`、Linux `~/.cache`、Windows `%LOCALAPPDATA%`)、home 下已存在的工具链缓存目录(`.cargo`/`.npm`/`.yarn`/`.pnpm-store`/`.bun`/`.m2`/`.gradle`/`.nuget`/`.ivy2`/`.bundle`/`.composer`/`.pub-cache`/`.mix`/`.hex`/`.stack`/`.cpanm`/`.deno`/`.conda`、`go/pkg`):Go 的 build cache 这类默认落在 cache 目录的工具链直接可用,换语言也不用改 supervisor;**凭据目录一律不自动放开**(`.ssh`/`.gnupg`/`.config`/`.aws`/`.docker`/`.kube`/`.netrc`/`.git-credentials`/`~/Library/Keychains`):ssh 连服务器要写 known_hosts、kubectl、推私有镜像、签名提交这类需求,派单时显式传 `writableRoots`,只在这一路生效。`SUPERVISOR_NO_AUTO_CACHE_ROOTS=1` 关掉全部自动缓存根,显式声明的照常生效。Codex 拒绝带软链的可写根(这种根会让 worker 所有命令都失败),所以 cache 目录和 `writableRoots` 都先按 realpath 解析,解析不出无软链路径的根直接不带。cache 放在别处(`~/.m2`、`~/.gradle`、vendor 镜像)就传 `writableRoots:[绝对路径]`,要求是已存在目录、最多 20 个、只对 workspace-write 生效、随 resume/followup 继承;只读复用就不用传。
202
202
 
203
203
  运行前核验Codex CLI是否具备hooks/output-schema(要求0.162+);能力不足返回start_failed,wait可正常结算。get_worker_goal.native_goal_read区分missing_goal、missing_database、locked和read_error,不能把读取失败当没建goal。原生budget/usage限制也进入needs_attention。cleanup保留ignored artifacts、共享证据和未解决attention。
204
204
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-supervisor-mcp",
3
- "version": "0.9.2",
3
+ "version": "0.9.4",
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.",
@@ -24,6 +24,7 @@ description: 把 Codex CLI 当并行 worker 派活、盯进度、收结果。用
24
24
  | `cwd` | 项目根目录。worker 在自己的 worktree 里干活,不动你的工作区 |
25
25
  | `acceptance` | 这一步"做完了"的判据,shell 命令列表,worker 退出后 supervisor 在它的 worktree 里逐条跑,退出码 0 算过,worker 在 prompt 里看得到。任务书里的验证命令原样抄:查那个文件在不在、那个接口通不通、那个测试文件过不过。写能判这一步的,不写全仓回归;远端机器的检查包进 `ssh`。命令用 supervisor 自己的权限跑,等于你自己跑 |
26
26
  | `forbid` / `allowedCommands` | 原样声明红线与验证命令;守卫拒绝未声明Shell程序,编辑用apply_patch |
27
+ | `writableRoots` | 只有需要凭据目录时才传(绝对路径、已存在、自动解析软链、只对 workspace-write 生效):ssh/远程测试 → `["~/.ssh"]`;kubectl → `["~/.kube"]`;推私有镜像 → `["~/.docker"]`;aws cli → `["~/.aws"]`;签名提交 → `["~/.gnupg"]`。缓存目录不用写,已经自动加 |
27
28
  | `ownedPaths` | 必填。这路允许写的路径,和在跑的 worker 重叠会被拒(**读不排他**,多路读同一份共享文件合法)。冲突是好事,说明该改拆法。传 `[]` 表示这路不落地:只读验证或研究 |
28
29
  | `goal.objective` | 必填。一句话说目标,worker 会建成 Codex 原生 goal |
29
30
  | `session_id` | 同一批传同一个值。第一路顺手带 `session_title`(30 字内,看板和 `get_session_works` 显示它),漏了用 `describe_session` 补 |
@@ -65,7 +66,7 @@ check_workers可对已死的第1轮lost/no_work/invalid_report自动resume一次
65
66
 
66
67
  远端编译/ssh在workspace-write显式networkAccess:true,默认false,resume/followup继承;不要用danger-full-access代替联网配置。需要时声明maxRunMs/maxTotalMs,超限保留partial work并提示处理,不自动恢复;wait预算与quota分开。
67
68
 
68
- 沙箱只放工作区、临时目录和OS cache目录(macOS ~/Library/Caches、Linux ~/.cache、Windows %LOCALAPPDATA%):Go 这类默认把build cache写那儿的工具链不用再单独设 GOCACHE,加语言也不用改supervisor。cache在别处(如 ~/.m2、~/.gradle、vendor镜像)就传 `writableRoots:[绝对路径]`(已存在目录、最多20个、只对workspace-write生效、随resume/followup继承);能只读复用就不用传。
69
+ 沙箱只放工作区、临时目录、OS cache目录(macOS ~/Library/Caches、Linux ~/.cache、Windows %LOCALAPPDATA%)以及home下已存在的工具链缓存目录(.cargo/.npm/.yarn/.pnpm-store/.bun/.m2/.gradle/.nuget/.ivy2/.bundle/.composer/.pub-cache/.mix/.hex/.stack/.cpanm/.deno/.conda、go/pkg):Go 这类默认把build cache写那儿的工具链不用再单独设 GOCACHE,加语言也不用改supervisor;**凭据目录一律不自动放开**(.ssh/.gnupg/.config/.aws/.docker/.kube/.netrc/.git-credentials/~/Library/Keychains):ssh 连服务器要写 known_hosts、kubectl、推私有镜像、签名提交这类需求,派单时按参数表显式传 writableRoots,只在这一路生效、随 resume/followup 继承。SUPERVISOR_NO_AUTO_CACHE_ROOTS=1 关掉全部自动缓存根,显式声明的照常生效。Codex 拒绝含软链的可写根(给了这种根worker连命令都起不来),所以cache目录和writableRoots都会被realpath解析后再交给沙箱;解析不到无软链路径就直接不带这个根。cache在别处(如 ~/.m2、~/.gradle、vendor镜像)就传 `writableRoots:[绝对路径]`(已存在目录、最多20个、只对workspace-write生效、随resume/followup继承);能只读复用就不用传。
69
70
 
70
71
  Codex需0.162+支持hooks/output-schema,能力不够派单start_failed先修CLI。goal查询看native_goal_read,missing与locked/read_error分开;budget/usage限制也要处理。cleanup保留ignored成果、共享证据及未解决attention。
71
72
 
@@ -1,4 +1,4 @@
1
- import { createWriteStream, existsSync, statSync } 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";
@@ -23,7 +23,7 @@ import { applyCodexEvent } from "./event-parser.js";
23
23
  import { ACTIVE_STATUSES, TERMINAL_STATUSES } from "./status.js";
24
24
  import { worktreesDir } from "./paths.js";
25
25
  import { buildGuardPreamble, frameWorkerPrompt } from "./prompt.js";
26
- import { cacheRoots } from "./sandbox-roots.js";
26
+ import { cacheRoots, resolveWritableRoot } from "./sandbox-roots.js";
27
27
  import { readTaskChanges, snapshotTaskOutput } from "./worktree.js";
28
28
  import { rebaseWorktree } from "./landing.js";
29
29
  import { DEFAULT_ACCEPTANCE_TIMEOUT_MS, normalizeAcceptance, runAcceptance } from "./acceptance.js";
@@ -624,8 +624,14 @@ export async function createCodexWorker({
624
624
  throw new Error("writableRoots must be a list of at most 20 absolute paths");
625
625
  }
626
626
  if (writableRoots.length && sandbox !== "workspace-write") throw new Error("writableRoots is only configurable for workspace-write workers");
627
+ // Codex refuses a writable root with a symlink component and then fails every
628
+ // command in the worker, so a declared root is stored resolved. Passing the
629
+ // alias would look fine in the receipt and break the run.
630
+ const resolvedWritableRoots = [];
627
631
  for (const root of writableRoots) {
628
- if (!existsSync(root) || !statSync(root).isDirectory()) throw new Error(`writableRoots entry must be an existing directory: ${root}`);
632
+ const resolved = resolveWritableRoot(root);
633
+ if (resolved.error) throw new Error(`writableRoots entry is unusable: ${root} (${resolved.error}); pass an existing directory whose path has no symlink component`);
634
+ resolvedWritableRoots.push(resolved.path);
629
635
  }
630
636
  for (const value of [maxRunMs, maxTotalMs]) if (value !== null && (!Number.isInteger(value) || value < 1000)) throw new Error("time limits must be integer milliseconds of at least 1000");
631
637
  for (const [name, values] of Object.entries({ forbid, allowedCommands })) {
@@ -673,7 +679,7 @@ export async function createCodexWorker({
673
679
  session_id: sessionId ?? null,
674
680
  thread_id: null,
675
681
  owned_paths: normalizedOwnedPaths,
676
- guard_policy: { forbid, allowedCommands, externalOutputs, networkAccess, writableRoots, maxRunMs, maxTotalMs },
682
+ guard_policy: { forbid, allowedCommands, externalOutputs, networkAccess, writableRoots: [...new Set(resolvedWritableRoots)], maxRunMs, maxTotalMs },
677
683
  input_context: { context, contracts },
678
684
  depends_on: Array.isArray(dependsOn) ? dependsOn : [],
679
685
  goal_objective: validatedGoal.objective,
@@ -1,18 +1,89 @@
1
- import { existsSync } from "node:fs";
1
+ import { lstatSync, realpathSync } from "node:fs";
2
2
  import { homedir } from "node:os";
3
- import { join } from "node:path";
3
+ import { dirname, isAbsolute, join, resolve } from "node:path";
4
4
 
5
- // A worker runs in Codex's workspace-write sandbox, which may write the
6
- // worktree and the temp directory and nothing else. Every toolchain that keeps
7
- // a build cache in the OS cache directory then dies on permissions before it
8
- // runs any project code (Go's ~/Library/Caches/go-build on macOS is the one
9
- // seen in practice). Naming one environment variable per language does not
10
- // hold: the next language adds another name and another patch. The sandbox
11
- // instead gets the OS cache directory itself as a writable root, which is
12
- // where those default caches live on every platform.
13
- export function cacheRoots({ env = process.env, platform = process.platform, home = homedir(), exists = existsSync } = {}) {
14
- const candidates = platform === "win32"
15
- ? [env.LOCALAPPDATA]
16
- : [env.XDG_CACHE_HOME, platform === "darwin" ? join(home, "Library", "Caches") : null, join(home, ".cache")];
17
- return [...new Set(candidates.map((dir) => dir?.trim()).filter(Boolean))].filter((dir) => exists(dir));
5
+ // Codex refuses a writable root that contains a symlink component: the worker
6
+ // does not merely lose that directory, every command in it fails with
7
+ // UnsupportedOperation("writable root ... contains symlink component ...").
8
+ // ~/.cache is a symlink on the machine this was found on, so every candidate is
9
+ // resolved to a symlink-free absolute path before the sandbox sees it, and a
10
+ // candidate that cannot be resolved that way is dropped instead of poisoning
11
+ // the whole run. allow_symlinked_codex_home does not help here: it only covers
12
+ // writable roots under CODEX_HOME.
13
+ export function symlinkComponents(target) {
14
+ const links = [];
15
+ let current = resolve(target);
16
+ for (;;) {
17
+ try { if (lstatSync(current).isSymbolicLink()) links.push(current); }
18
+ catch { /* a missing component is reported by the caller */ }
19
+ const parent = dirname(current);
20
+ if (parent === current) break;
21
+ current = parent;
22
+ }
23
+ return links;
18
24
  }
25
+
26
+ export function resolveWritableRoot(candidate) {
27
+ if (typeof candidate !== "string" || !candidate.trim()) return { error: "empty path" };
28
+ if (!isAbsolute(candidate)) return { error: "not an absolute path" };
29
+ let resolved;
30
+ try { resolved = realpathSync(candidate.trim()); } catch { return { error: "does not exist" }; }
31
+ try { if (!lstatSync(resolved).isDirectory()) return { error: "not a directory" }; } catch { return { error: "not a directory" }; }
32
+ const links = symlinkComponents(resolved);
33
+ if (links.length) return { error: "resolved path still contains a symlink component: " + links.join(", ") };
34
+ return { path: resolved };
35
+ }
36
+
37
+ // Cache locations a build writes to outside the worktree. The OS cache
38
+ // directory covers everything that follows XDG or the platform convention
39
+ // (Go build cache, pip, uv, huggingface, gh, ...). Toolchains that keep their
40
+ // own store under the home directory are listed by directory instead, because
41
+ // naming one environment variable per language stops working the moment a new
42
+ // language shows up: a directory that exists is granted, one that does not is
43
+ // not, and a new toolchain only adds a line here at most.
44
+ export const TOOLCHAIN_CACHE_DIRS = [
45
+ ".cargo", // Rust: registry, git checkouts, .package-cache
46
+ ".npm", // Node: _cacache, _logs
47
+ ".yarn",
48
+ ".pnpm-store",
49
+ ".bun",
50
+ ".m2", // Maven local repository
51
+ ".gradle", // Gradle user home
52
+ ".nuget", // NuGet global packages
53
+ ".ivy2", // sbt / Ivy
54
+ ".bundle", // Ruby Bundler
55
+ ".composer", // PHP Composer
56
+ ".pub-cache", // Dart / Flutter
57
+ ".mix", // Elixir
58
+ ".hex",
59
+ ".stack", // Haskell
60
+ ".cpanm", // Perl
61
+ ".deno",
62
+ ".conda", // conda package cache
63
+ "go/pkg" // Go module cache
64
+ ];
65
+
66
+ // Credentials are never granted automatically. A dispatcher that needs them
67
+ // names the directory in writableRoots for that one dispatch: an ssh test wants
68
+ // ~/.ssh (known_hosts, ControlMaster sockets), a kubectl test ~/.kube, a registry
69
+ // push ~/.docker, an aws test ~/.aws, a signed commit ~/.gnupg. Everything here is
70
+ // granted automatically only when it holds build state, not secrets, so a worker
71
+ // steered by injected text cannot persist a key or swap a trust anchor.
72
+ export const EXPLICIT_ONLY_DIRS = [".ssh", ".gnupg", ".config", ".aws", ".docker", ".kube", ".netrc", ".git-credentials", "Library/Keychains"];
73
+ function osCacheCandidates({ env, platform, home }) {
74
+ if (platform === "win32") return [env.LOCALAPPDATA];
75
+ return [env.XDG_CACHE_HOME, platform === "darwin" ? join(home, "Library", "Caches") : null, join(home, ".cache")];
76
+ }
77
+
78
+ export function cacheRoots({ env = process.env, platform = process.platform, home = homedir(), resolveRoot = resolveWritableRoot, includeToolchain = true } = {}) {
79
+ if (/^(1|true|yes)$/i.test((env.SUPERVISOR_NO_AUTO_CACHE_ROOTS ?? "").trim())) return [];
80
+ const candidates = [...osCacheCandidates({ env, platform, home }), ...(includeToolchain ? TOOLCHAIN_CACHE_DIRS.map((dir) => join(home, dir)) : [])];
81
+ const roots = [];
82
+ for (const candidate of candidates) {
83
+ if (!candidate?.trim()) continue;
84
+ const resolved = resolveRoot(candidate.trim());
85
+ if (resolved?.path) roots.push(resolved.path);
86
+ }
87
+ return [...new Set(roots)];
88
+ }
89
+