codex-supervisor-mcp 0.14.0 → 1.1.0

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.
Files changed (76) hide show
  1. package/README.en.md +37 -45
  2. package/README.md +37 -45
  3. package/package.json +2 -2
  4. package/skills/codex-supervisor/SKILL.md +88 -91
  5. package/src/app/acceptance.js +5 -5
  6. package/src/app/auto-cleanup.js +6 -5
  7. package/src/app/cleanup-facts.js +21 -16
  8. package/src/app/cleanup-plan.js +22 -20
  9. package/src/app/context-compiler.js +2 -1
  10. package/src/app/dispatch.js +17 -15
  11. package/src/app/followup.js +5 -4
  12. package/src/app/land-chain.js +5 -4
  13. package/src/app/landing.js +8 -8
  14. package/src/app/ownership.js +1 -1
  15. package/src/app/rebase.js +1 -1
  16. package/src/app/restore-worktree.js +2 -1
  17. package/src/app/resume.js +11 -6
  18. package/src/app/worktree-setup.js +58 -16
  19. package/src/domain/acceptance-spec.js +1 -1
  20. package/src/domain/failure-class.js +36 -4
  21. package/src/domain/prompt.js +7 -7
  22. package/src/domain/status.js +15 -2
  23. package/src/domain/thread-health.js +2 -2
  24. package/src/domain/worker-branch.js +6 -0
  25. package/src/domain/worker-changes.js +3 -3
  26. package/src/domain/worker-preflight.js +2 -1
  27. package/src/infra/cleanup-hint.js +1 -1
  28. package/src/infra/crash-guard.js +44 -0
  29. package/src/infra/external-output.js +2 -2
  30. package/src/infra/git.js +35 -4
  31. package/src/infra/sandbox-roots.js +1 -1
  32. package/src/infra/store/event-body.js +82 -0
  33. package/src/infra/store/events.js +9 -6
  34. package/src/infra/store/reconcile.js +4 -3
  35. package/src/infra/store/tasks.js +15 -1
  36. package/src/infra/update/auto-update-worker.js +3 -3
  37. package/src/infra/update/auto-update.js +4 -4
  38. package/src/infra/update/update-check.js +3 -3
  39. package/src/infra/workspace-kind.js +8 -8
  40. package/src/infra/worktree.js +4 -3
  41. package/src/interface/bin/acceptance-cli.js +4 -4
  42. package/src/interface/bin/monitor.jsx +6 -6
  43. package/src/interface/bin/setup.js +3 -3
  44. package/src/interface/bin/stage.js +2 -2
  45. package/src/interface/bin/web-server.js +2 -0
  46. package/src/interface/mcp/{tools → handlers}/delivery.js +30 -62
  47. package/src/interface/mcp/handlers/dispatch.js +233 -0
  48. package/src/interface/mcp/{tools → handlers}/facts.js +30 -65
  49. package/src/interface/mcp/handlers/overview.js +106 -0
  50. package/src/interface/mcp/{tools → handlers}/results.js +31 -60
  51. package/src/interface/mcp/{tools → handlers}/review.js +16 -36
  52. package/src/interface/mcp/{tools → handlers}/wait.js +13 -17
  53. package/src/interface/mcp/server.js +20 -50
  54. package/src/interface/mcp/tools/deliver.js +48 -0
  55. package/src/interface/mcp/tools/dispatch.js +78 -257
  56. package/src/interface/mcp/tools/optional.js +57 -0
  57. package/src/interface/mcp/tools/read.js +115 -0
  58. package/src/interface/mcp/tools/run.js +57 -0
  59. package/src/interface/mcp/tools/shapes.js +66 -0
  60. package/src/interface/mcp/tools/track.js +84 -0
  61. package/src/interface/mcp/views/task.js +8 -7
  62. package/src/interface/web/views.js +5 -2
  63. package/src/run-host/entry.js +3 -0
  64. package/src/run-host/finalize.js +8 -1
  65. package/src/run-host/launch.js +7 -7
  66. package/src/run-host/live-run.js +2 -0
  67. package/src/run-host/streams.js +28 -5
  68. package/src/run-host/track.js +5 -2
  69. package/src/runners/codex/tool-guard.js +6 -6
  70. package/web/dist/assets/{index-fJQbspTY.js → index-BnV-AYYI.js} +1 -1
  71. package/web/dist/assets/index-f8esISCp.css +2 -0
  72. package/web/dist/index.html +2 -2
  73. package/src/domain/overview-delta.js +0 -77
  74. package/src/interface/mcp/tools/overview.js +0 -202
  75. package/src/interface/mcp/tools/poll.js +0 -58
  76. package/web/dist/assets/index-DI1hLMxE.css +0 -2
@@ -1,6 +1,7 @@
1
+ import { branchOf } from "../../domain/worker-branch.js";
1
2
  import { ensureControlRecords, ensureFilesystem, openDb, runIdFor, runWithRetry, workItemIdForTask } from "./db.js";
3
+ import { storedForm } from "./event-body.js";
2
4
  import { extractAgentMessage } from "./runner-readers.js";
3
- import { createHash } from "node:crypto";
4
5
 
5
6
  export async function ensureRunRecord(task, attempt) {
6
7
  await ensureFilesystem();
@@ -24,7 +25,7 @@ export async function ensureRunRecord(task, attempt) {
24
25
  attempt,
25
26
  codex_thread_id: task.thread_id ?? null,
26
27
  worktree_path: task.worktree_path ?? null,
27
- branch: task.worktree_path ? `codex/${task.id}` : null,
28
+ branch: task.worktree_path ? branchOf(task) : null,
28
29
  base_sha: task.base_commit ?? null,
29
30
  started_at: now
30
31
  });
@@ -50,7 +51,10 @@ export async function completeRunRecord(task, attempt) {
50
51
  }));
51
52
  }
52
53
 
53
- export async function appendTaskEvents(taskId, events, { runId = null, actor = "supervisor" } = {}) {
54
+ // bodyInLog: each event is already in the run log (the caller waited for the
55
+ // write), so a large one need not be kept whole here as well. logOffsets says
56
+ // where each line starts.
57
+ export async function appendTaskEvents(taskId, events, { runId = null, actor = "supervisor", bodyInLog = false, logOffsets = [] } = {}) {
54
58
  await ensureFilesystem();
55
59
  if (!Array.isArray(events) || events.length === 0) return [];
56
60
  const dbInstance = openDb();
@@ -64,9 +68,8 @@ export async function appendTaskEvents(taskId, events, { runId = null, actor = "
64
68
  `);
65
69
  const createdAt = new Date().toISOString();
66
70
  const records = events.map((event, index) => {
67
- const payload = JSON.stringify(event);
68
- const result = insert.run(taskId, runId, nextSeqRow.seq + index, createdAt, actor, event.type ?? "unknown", payload,
69
- createHash("sha256").update(payload).digest("hex"));
71
+ const stored = storedForm(event, { bodyInLog, offset: logOffsets[index] ?? null });
72
+ const result = insert.run(taskId, runId, nextSeqRow.seq + index, createdAt, actor, event.type ?? "unknown", stored.payload, stored.sha256);
70
73
  return { id: Number(result.lastInsertRowid), run_id: runId, actor };
71
74
  });
72
75
  dbInstance.exec("COMMIT");
@@ -1,4 +1,4 @@
1
- import { TERMINAL_STATUSES } from "../../domain/status.js";
1
+ import { runIsOver, TERMINAL_STATUSES } from "../../domain/status.js";
2
2
  import { parseWorkerReportForRun } from "../../domain/worker-report.js";
3
3
  import { decodeJson, openDb, runIdFor } from "./db.js";
4
4
  import { appendTaskEvent, completeRunRecord, readTaskEvents } from "./events.js";
@@ -102,8 +102,9 @@ function recoveredRow(task, recoveredEvidence, now) {
102
102
  // not evidence that the worker vanished. Acceptance keeps its own verdict;
103
103
  // recovering the worker completion must never imply that checks passed.
104
104
  async function recoverTerminalTurn(task) {
105
- if (task.exit_code != null || task.signal || !task.started_at
106
- || isPidAlive(task.pid) || isPidAlive(task.run_host_pid)) return false;
105
+ if (task.exit_code != null || task.signal || !task.started_at) return false;
106
+ // Once the run is over its pids may belong to anyone.
107
+ if (!runIsOver(task) && (isPidAlive(task.pid) || isPidAlive(task.run_host_pid))) return false;
107
108
  const runId = runIdFor(task.id, task.run_count);
108
109
  const events = openDb().prepare(`
109
110
  SELECT payload FROM task_events WHERE task_id = ? AND run_id = ? ORDER BY seq
@@ -46,6 +46,20 @@ export function isPidAlive(pid) {
46
46
  }
47
47
  }
48
48
 
49
+ // The run host leads its own process group and the worker runs inside it. A
50
+ // worker CLI is often a launcher around the real binary, so the recorded pid
51
+ // can be gone while the binary is still writing to the session. True while
52
+ // anything in the group is left. Windows has no process groups.
53
+ export function isGroupAlive(leaderPid) {
54
+ if (!leaderPid || process.platform === "win32") return false;
55
+ try {
56
+ process.kill(-leaderPid, 0);
57
+ return true;
58
+ } catch (error) {
59
+ return error.code === "EPERM";
60
+ }
61
+ }
62
+
49
63
  export async function readTasks() {
50
64
  await ensureFilesystem();
51
65
  const rows = openDb().prepare("SELECT * FROM tasks ORDER BY created_at ASC").all();
@@ -139,7 +153,7 @@ function checkOwnership(taskId, incoming) {
139
153
  const matching=incoming.flatMap(path=>paths.filter(other=>overlaps(path,other)).map(other=>({incoming:path,existing:other})));
140
154
  if(matching.length)conflicts.push({task_id:row.id,title:row.title,status:row.status,overlapping_paths:matching});
141
155
  }
142
- if(conflicts.length){const error=new Error("ownedPaths overlap with an active worker claimed by another dispatcher");error.code="ownership_conflict";error.conflicts=conflicts;throw error;}
156
+ if(conflicts.length){const error=new Error("owned_paths overlap with an active worker claimed by another dispatcher");error.code="ownership_conflict";error.conflicts=conflicts;throw error;}
143
157
  }
144
158
 
145
159
  export async function reserveTaskOwnership(task) {
@@ -83,10 +83,10 @@ async function acquireLock() {
83
83
  }
84
84
 
85
85
  // npm as `node npm-cli.js`: steps over the npm.cmd shim on Windows and uses
86
- // the npm that belongs to the node running this server. CODEX_SUPERVISOR_NPM
86
+ // the npm that belongs to the node running this server. AGENT_SUPERVISOR_NPM
87
87
  // points at another npm-cli.js (or any executable) when that is wrong.
88
88
  function npmCommand() {
89
- const override = process.env.CODEX_SUPERVISOR_NPM?.trim();
89
+ const override = process.env.AGENT_SUPERVISOR_NPM?.trim();
90
90
  if (override) {
91
91
  const target = resolveCommand(override);
92
92
  return [target.cmd, ...target.prefixArgs];
@@ -106,7 +106,7 @@ async function npm(args, { registry, timeout = NPM_TIMEOUT_MS } = {}) {
106
106
  const [cmd, ...prefix] = npmCommand();
107
107
  const full = [...prefix, ...args, "--no-fund", "--no-audit", "--loglevel=error"];
108
108
  if (registry) full.push(`--registry=${registry}`);
109
- const env = { ...process.env, CODEX_SUPERVISOR_NO_AUTO_UPDATE: "1" };
109
+ const env = { ...process.env, AGENT_SUPERVISOR_NO_AUTO_UPDATE: "1" };
110
110
  return run(cmd, full, { timeout, env, maxBuffer: 4 * 1024 * 1024, windowsHide: true });
111
111
  }
112
112
 
@@ -24,13 +24,13 @@ export const logPath = join(dataDir, "auto-update.log");
24
24
  const workerEntry = join(dirname(fileURLToPath(import.meta.url)), "auto-update-worker.js");
25
25
 
26
26
  export function autoUpdateDisabled(env = process.env) {
27
- return /^(1|true|yes)$/i.test(env.CODEX_SUPERVISOR_NO_AUTO_UPDATE?.trim() ?? "");
27
+ return /^(1|true|yes)$/i.test(env.AGENT_SUPERVISOR_NO_AUTO_UPDATE?.trim() ?? "");
28
28
  }
29
29
 
30
30
  // Pure. The reason not to install, or null when an install should start.
31
31
  export function autoUpdateBlocker(update, env = process.env) {
32
32
  if (!update) return "no update check result yet";
33
- if (autoUpdateDisabled(env)) return "disabled by CODEX_SUPERVISOR_NO_AUTO_UPDATE";
33
+ if (autoUpdateDisabled(env)) return "disabled by AGENT_SUPERVISOR_NO_AUTO_UPDATE";
34
34
  if (env.CI) return "CI environment";
35
35
  if (update.disabled) return "update check is disabled";
36
36
  if (!update.update_available) return "already current";
@@ -71,7 +71,7 @@ async function launchWorker({ version, packageRoot, registry }) {
71
71
  const child = spawnProcess(process.execPath, args, {
72
72
  detached: true,
73
73
  stdio: ["ignore", log, log],
74
- env: { ...process.env, CODEX_SUPERVISOR_NO_AUTO_UPDATE: "1" },
74
+ env: { ...process.env, AGENT_SUPERVISOR_NO_AUTO_UPDATE: "1" },
75
75
  windowsHide: true
76
76
  });
77
77
  child.unref();
@@ -116,7 +116,7 @@ async function decide(update, { env = process.env, launch = launchWorker } = {})
116
116
  const pid = await launch({
117
117
  version,
118
118
  packageRoot: update.installed.path,
119
- registry: env.CODEX_SUPERVISOR_REGISTRY?.trim() || null
119
+ registry: env.AGENT_SUPERVISOR_REGISTRY?.trim() || null
120
120
  });
121
121
  record = { state: "started", version, pid, started_at: new Date().toISOString() };
122
122
  } catch (error) {
@@ -24,16 +24,16 @@ const CACHE_TTL_MS = 60 * 60 * 1000;
24
24
  const cachePath = join(dataDir, "update-check.json");
25
25
 
26
26
  function registryUrl() {
27
- return (process.env.CODEX_SUPERVISOR_REGISTRY?.trim() || DEFAULT_REGISTRY).replace(/\/+$/, "");
27
+ return (process.env.AGENT_SUPERVISOR_REGISTRY?.trim() || DEFAULT_REGISTRY).replace(/\/+$/, "");
28
28
  }
29
29
 
30
30
  function timeoutMs() {
31
- const raw = Number(process.env.CODEX_SUPERVISOR_UPDATE_TIMEOUT_MS ?? 4000);
31
+ const raw = Number(process.env.AGENT_SUPERVISOR_UPDATE_TIMEOUT_MS ?? 4000);
32
32
  return Number.isFinite(raw) && raw > 0 ? raw : 4000;
33
33
  }
34
34
 
35
35
  export function updateCheckDisabled() {
36
- return /^(1|true|yes)$/i.test(process.env.CODEX_SUPERVISOR_NO_UPDATE_CHECK?.trim() ?? "");
36
+ return /^(1|true|yes)$/i.test(process.env.AGENT_SUPERVISOR_NO_UPDATE_CHECK?.trim() ?? "");
37
37
  }
38
38
 
39
39
  // "1.2.3" -> [1,2,3]; a prerelease tag sorts below the release it precedes.
@@ -29,38 +29,38 @@ export function isGitCheckout(cwd) {
29
29
 
30
30
  function selectedKind({ sourceRoot, workspaceKind, sandbox }) {
31
31
  if (workspaceKind != null && !WORKSPACE_KINDS.includes(workspaceKind)) {
32
- throw workspaceError("invalid_workspace_kind", `workspaceKind must be one of ${WORKSPACE_KINDS.join(", ")}`);
32
+ throw workspaceError("invalid_workspace_kind", `workspace.kind must be one of ${WORKSPACE_KINDS.join(", ")}`);
33
33
  }
34
34
  if (workspaceKind) return workspaceKind;
35
35
  if (isGitCheckout(sourceRoot)) return "git_worktree";
36
36
  if (sandbox === "read-only") return "read_only_in_place";
37
- throw workspaceError("workspace_kind_required", "a non-Git worker that can write must declare workspaceKind: scratch or in_place_write; the supervisor never writes a user directory by default");
37
+ throw workspaceError("workspace_kind_required", "a non-Git worker that can write must declare workspace.kind: scratch or in_place_write; the supervisor never writes a user directory by default");
38
38
  }
39
39
 
40
40
  function validateKind({ kind, sourceRoot, sandbox, ownedPaths, networkAccess, acceptance, externalOutputs, inPlaceAuthorization, isPreflight }) {
41
41
  if (kind === "git_worktree") {
42
- if (!isGitCheckout(sourceRoot)) throw workspaceError("git_worktree_requires_git", "workspaceKind git_worktree requires a Git checkout with a resolvable commit; use read_only_in_place, scratch or explicitly authorized in_place_write for a non-Git directory");
42
+ if (!isGitCheckout(sourceRoot)) throw workspaceError("git_worktree_requires_git", "workspace.kind git_worktree requires a Git checkout with a resolvable commit; use read_only_in_place, scratch or explicitly authorized in_place_write for a non-Git directory");
43
43
  return;
44
44
  }
45
45
  if (kind === "read_only_in_place") {
46
46
  if (sandbox !== "read-only" || ownedPaths.length !== 0 || networkAccess) {
47
- throw workspaceError("invalid_read_only_workspace", "read_only_in_place requires sandbox read-only, ownedPaths: [] and networkAccess: false");
47
+ throw workspaceError("invalid_read_only_workspace", "read_only_in_place requires sandbox read-only, owned_paths: [] and sandbox.network_access: false");
48
48
  }
49
- if (externalOutputs.length) throw workspaceError("invalid_read_only_workspace", "read_only_in_place cannot declare externalOutputs");
49
+ if (externalOutputs.length) throw workspaceError("invalid_read_only_workspace", "read_only_in_place cannot declare workspace.external_outputs");
50
50
  return;
51
51
  }
52
52
  if (kind === "scratch") {
53
53
  if (sandbox !== "workspace-write" || ownedPaths.length !== 0) {
54
- throw workspaceError("invalid_scratch_workspace", "scratch requires sandbox workspace-write and ownedPaths: []; it never lands project changes");
54
+ throw workspaceError("invalid_scratch_workspace", "scratch requires sandbox workspace-write and owned_paths: []; it never lands project changes");
55
55
  }
56
- if (externalOutputs.length) throw workspaceError("invalid_scratch_workspace", "scratch cannot write externalOutputs; keep generated material inside the supervisor scratch directory");
56
+ if (externalOutputs.length) throw workspaceError("invalid_scratch_workspace", "scratch cannot write workspace.external_outputs; keep generated material inside the supervisor scratch directory");
57
57
  return;
58
58
  }
59
59
  if (isGitCheckout(sourceRoot)) {
60
60
  throw workspaceError("in_place_write_requires_non_git", "in_place_write is only for an explicitly authorized non-Git directory; use git_worktree for a Git checkout");
61
61
  }
62
62
  if (sandbox !== "workspace-write" || ownedPaths.length === 0 || !String(inPlaceAuthorization ?? "").trim()) {
63
- throw workspaceError("invalid_in_place_workspace", "in_place_write requires sandbox workspace-write, nonempty ownedPaths and an explicit inPlaceAuthorization");
63
+ throw workspaceError("invalid_in_place_workspace", "in_place_write requires sandbox workspace-write, nonempty owned_paths and an explicit workspace.in_place_authorization");
64
64
  }
65
65
  if (!isPreflight && (!Array.isArray(acceptance) || acceptance.length === 0)) {
66
66
  throw workspaceError("in_place_acceptance_required", "in_place_write requires explicit acceptance; file changes in a user directory cannot be accepted by worker exit status alone");
@@ -10,6 +10,7 @@
10
10
  // of five workers all did exactly that and reported no changed files at all -
11
11
  // so the committed part is read as `git diff --name-only <base> HEAD`, where
12
12
  // base is the commit the worktree was created from.
13
+ import { branchOf } from "../domain/worker-branch.js";
13
14
  import { runGit } from "./git.js";
14
15
  import { existsSync, readFileSync, lstatSync } from "node:fs";
15
16
  import { join, relative, resolve } from "node:path";
@@ -48,7 +49,7 @@ function nonEmptyLines(output) {
48
49
 
49
50
  // The commit the worker started from. Rows written by this version carry it
50
51
  // as base_commit. Older rows do not, but the branch reflog still has it: the
51
- // oldest reflog entry of `codex/<id>` is the branch's creation point.
52
+ // oldest reflog entry of the worker's branch is its creation point.
52
53
  export function resolveWorktreeBase(worktreePath, { baseCommit = null, branch = null } = {}) {
53
54
  if (baseCommit) return baseCommit;
54
55
  if (!branch) return null;
@@ -86,7 +87,7 @@ export function readWorktreeChanges(worktreePath, { baseCommit = null, branch =
86
87
  // git does not track yet. This is the main thread's ground truth for "what
87
88
  // did it do", as opposed to what the worker says it did.
88
89
  //
89
- // `maxChars` bounds the whole answer. Files are served in git's order; a
90
+ // `max_chars` bounds the whole answer. Files are served in git's order; a
90
91
  // file that does not fit is cut in the middle (truncated: true), and files
91
92
  // after the budget is spent come back without a patch so the list of what
92
93
  // changed is still complete.
@@ -272,7 +273,7 @@ export function mergeChangedFiles(existing, discovered) {
272
273
  export function worktreeRef(task) {
273
274
  return {
274
275
  baseCommit: task.base_commit ?? null,
275
- branch: task.worktree_path ? `codex/${task.id}` : null
276
+ branch: task.worktree_path ? branchOf(task) : null
276
277
  };
277
278
  }
278
279
 
@@ -27,9 +27,9 @@ function readTask(taskId) {
27
27
  }
28
28
  }
29
29
 
30
- const taskId = process.env.CODEX_SUPERVISOR_TASK_ID;
30
+ const taskId = process.env.AGENT_SUPERVISOR_TASK_ID;
31
31
  if (!taskId) {
32
- console.error("CODEX_SUPERVISOR_TASK_ID is required");
32
+ console.error("AGENT_SUPERVISOR_TASK_ID is required");
33
33
  process.exit(2);
34
34
  }
35
35
 
@@ -49,14 +49,14 @@ if (!Array.isArray(task.acceptance) || task.acceptance.length === 0) {
49
49
  process.exit(2);
50
50
  }
51
51
 
52
- const run = Number(process.env.CODEX_SUPERVISOR_RUN);
52
+ const run = Number(process.env.AGENT_SUPERVISOR_RUN);
53
53
  const result = await runAcceptance(task.acceptance, {
54
54
  cwd: task.worktree_path || task.cwd,
55
55
  env: process.env,
56
56
  timeoutMs: task.acceptance_timeout_ms ?? DEFAULT_ACCEPTANCE_TIMEOUT_MS,
57
57
  run: Number.isInteger(run) && run > 0 ? run : task.run_count,
58
58
  taskId,
59
- baseCommit: process.env.CODEX_SUPERVISOR_BASE_COMMIT || task.base_commit || null
59
+ baseCommit: process.env.AGENT_SUPERVISOR_BASE_COMMIT || task.base_commit || null
60
60
  });
61
61
  process.stdout.write(`${JSON.stringify(result)}\n`);
62
62
  process.exit(result.passed === true ? 0 : 1);
@@ -173,12 +173,12 @@ function ClaudePlanPanel({ width }) {
173
173
  <Text>5. 完成后让 Claude 或 Codex review worker 审查。</Text>
174
174
  <Newline />
175
175
  <Text dimColor>Claude 可调用的 MCP 工具名:</Text>
176
- <Text dimColor>create_codex_worker</Text>
177
- <Text dimColor>create_codex_followup_worker</Text>
178
- <Text dimColor>list_codex_workers</Text>
179
- <Text dimColor>get_codex_worker_status</Text>
180
- <Text dimColor>get_codex_worker_events</Text>
181
- <Text dimColor>cancel_codex_worker</Text>
176
+ <Text dimColor>create_worker</Text>
177
+ <Text dimColor>create_worker with followup_of</Text>
178
+ <Text dimColor>poll_workers</Text>
179
+ <Text dimColor>get_worker</Text>
180
+ <Text dimColor>get_worker (include events)</Text>
181
+ <Text dimColor>cancel_worker</Text>
182
182
  </Box>
183
183
  );
184
184
  }
@@ -8,7 +8,7 @@
8
8
  // npx codex-supervisor-setup
9
9
  // codex-supervisor-setup --target claude --force
10
10
  //
11
- // Set CODEX_SUPERVISOR_SKIP_SETUP=1 to opt out of the automatic run.
11
+ // Set AGENT_SUPERVISOR_SKIP_SETUP=1 to opt out of the automatic run.
12
12
  import { runFile } from "../../infra/process.js";
13
13
  import { existsSync, readdirSync } from "node:fs";
14
14
  import { homedir } from "node:os";
@@ -114,7 +114,7 @@ Options:
114
114
  -h, --help Show help.
115
115
 
116
116
  Environment:
117
- CODEX_SUPERVISOR_SKIP_SETUP=1 Skip the automatic postinstall run entirely.
117
+ AGENT_SUPERVISOR_SKIP_SETUP=1 Skip the automatic postinstall run entirely.
118
118
  `);
119
119
  }
120
120
 
@@ -264,7 +264,7 @@ async function main() {
264
264
  }
265
265
 
266
266
  if (options.auto) {
267
- if (process.env.CODEX_SUPERVISOR_SKIP_SETUP) {
267
+ if (process.env.AGENT_SUPERVISOR_SKIP_SETUP) {
268
268
  return 0;
269
269
  }
270
270
  if (process.env.npm_config_global !== "true") {
@@ -2,7 +2,7 @@
2
2
  import { writeStage } from "../../infra/stage-store.js";
3
3
 
4
4
  const argv = process.argv.slice(2);
5
- let taskId = process.env.CODEX_SUPERVISOR_TASK_ID;
5
+ let taskId = process.env.AGENT_SUPERVISOR_TASK_ID;
6
6
  let detail = null;
7
7
  const positional = [];
8
8
  for (let index = 0; index < argv.length; index += 1) {
@@ -11,7 +11,7 @@ for (let index = 0; index < argv.length; index += 1) {
11
11
  }
12
12
  const stage = positional.join(" ").trim();
13
13
  if (!taskId || !stage) {
14
- console.error('usage: codex-supervisor-stage "gate:s3" [--detail "..."] (task comes from CODEX_SUPERVISOR_TASK_ID)');
14
+ console.error('usage: codex-supervisor-stage "gate:s3" [--detail "..."] (task comes from AGENT_SUPERVISOR_TASK_ID)');
15
15
  process.exit(2);
16
16
  }
17
17
  process.stdout.write(`${JSON.stringify(writeStage(taskId, stage, detail))}\n`);
@@ -45,5 +45,7 @@ if (!process.env.SUPERVISOR_HOME?.trim()) {
45
45
 
46
46
  // paths.js reads SUPERVISOR_HOME when it is first imported, so the import
47
47
  // has to come after the detection above.
48
+ const { installCrashGuard } = await import("../../infra/crash-guard.js");
49
+ installCrashGuard("web");
48
50
  const { startWebServer } = await import("../web/app.js");
49
51
  startWebServer({ storeOrigin });
@@ -8,13 +8,8 @@ import { getTask, upsertTask } from "../../../infra/store/tasks.js";
8
8
  import { errorResult, textResult } from "../result.js";
9
9
  import { z } from "zod";
10
10
 
11
- export const landCodexWorkerTool = [
12
- "land_codex_worker",
13
- {
14
- title: "Land a worker's commits",
15
- description:
16
- "Cherry-pick the commits a worker made on its codex/<taskId> branch onto the current branch of the directory it was dispatched from. The target must be clean and is never switched to another branch; `onto` is a guard that names the branch you expect to be on. A conflict aborts the cherry-pick, lists the files, and leaves the target as it was. A worker in the workspace-write sandbox cannot commit (Codex keeps .git read-only there): pass commitMessage and its uncommitted edits are committed as one commit on its branch first, then landed. Without commitMessage uncommitted edits are reported, not landed. includeFollowupParents lands an unlanded followup chain root-first; commitMessages supplies a per-task checkpoint message when an ancestor has uncommitted edits. Check the work first with get_worker_result and get_worker_diff; land once it passes. A malformed report summary is attention, not a separate landing veto when the same run's acceptance passed and the reviewed diff is sound. Refuses with acceptance_failed while the worker's last acceptance run failed (and acceptance_not_run while one is running or was interrupted): resume it with the failing output, land once it passes. ignoreAcceptance: true lands anyway; use it only when the user said to land regardless.",
17
- inputSchema: {
11
+ export const landCodexWorkerOp = {
12
+ input: z.object({
18
13
  task_id: z.string().min(1),
19
14
  onto: z.string().min(1).optional(),
20
15
  commitMessage: z.string().min(1).optional(),
@@ -22,9 +17,8 @@ export const landCodexWorkerTool = [
22
17
  commitMessages: z.record(z.string(), z.string().min(1)).optional(),
23
18
  ignoreAcceptance: z.boolean().default(false),
24
19
  allowOutsideOwned: z.boolean().default(false)
25
- }
26
- },
27
- async ({ task_id, onto, commitMessage, includeFollowupParents, commitMessages, ignoreAcceptance, allowOutsideOwned }) => {
20
+ }),
21
+ handler: async ({ task_id, onto, commitMessage, includeFollowupParents, commitMessages, ignoreAcceptance, allowOutsideOwned }) => {
28
22
  if (!includeFollowupParents) {
29
23
  const task = await getTask(task_id);
30
24
  if (task?.followup_of) {
@@ -46,7 +40,7 @@ export const landCodexWorkerTool = [
46
40
  error: "followup_parents_not_landed",
47
41
  task_id,
48
42
  unlanded,
49
- reason: "this follow-up starts from its parent branch; landing only the leaf would integrate a partial chain. Use includeFollowupParents: true after reviewing every task's acceptance and diff."
43
+ reason: "this follow-up starts from its parent branch; landing only the leaf would integrate a partial chain. Use include_followup_parents: true after reviewing every task's acceptance and diff."
50
44
  });
51
45
  }
52
46
  }
@@ -83,33 +77,23 @@ export const landCodexWorkerTool = [
83
77
  }
84
78
  return textResult({ task_id, chain });
85
79
  }
86
- ];
80
+ };
87
81
 
88
- export const verifyDeliveryPushTool = [
89
- "verify_delivery_push",
90
- {
91
- title: "Verify landed work reached a remote branch",
92
- description: "Fetch a remote branch and prove the worker's landed_head is reachable from it. This never pushes or deploys. A passing check records push_verified.",
93
- inputSchema: {
82
+ export const verifyDeliveryPushOp = {
83
+ input: z.object({
94
84
  task_id: z.string().min(1),
95
85
  remote: z.string().min(1).default("origin"),
96
86
  branch: z.string().min(1).optional()
97
- }
98
- },
99
- async ({ task_id, remote, branch }) => textResult(await verifyDeliveryPush({ taskId: task_id, remote, branch }))
100
- ];
87
+ }),
88
+ handler: async ({ task_id, remote, branch }) => textResult(await verifyDeliveryPush({ taskId: task_id, remote, branch }))
89
+ };
101
90
 
102
- export const cleanupPlanTool = [
103
- "cleanup_plan",
104
- {
105
- title: "Plan safe worktree cleanup",
106
- description: "Show why each managed worktree is safe, review or blocked. Safe worktrees (landed, or nothing to keep, or past the hold period) are removed automatically during polling, so call this to see reasons and dates or to remove one right away with apply_cleanup. Read-only; the plan expires after 15 minutes.",
107
- inputSchema: {
91
+ export const cleanupPlanOp = {
92
+ input: z.object({
108
93
  task_ids: z.array(z.string().min(1)).max(200).optional(),
109
94
  project_root: z.string().min(1).optional()
110
- }
111
- },
112
- async ({ task_ids, project_root }) => {
95
+ }),
96
+ handler: async ({ task_ids, project_root }) => {
113
97
  try {
114
98
  const plan = await createCleanupPlan({ taskIds: task_ids ?? null, projectRoot: project_root ?? null });
115
99
  await saveCleanupPlan(plan);
@@ -125,47 +109,31 @@ export const cleanupPlanTool = [
125
109
  return errorResult(error);
126
110
  }
127
111
  }
128
- ];
112
+ };
129
113
 
130
- export const applyCleanupTool = [
131
- "apply_cleanup",
132
- {
133
- title: "Apply a safe cleanup plan",
134
- description: "Remove selected SAFE worktrees from an unexpired cleanup plan now, after assessing them again. Uncommitted edits are committed to the worker branch first. Keeps the branch, task row, event stream, JSONL log and artifacts.",
135
- inputSchema: {
114
+ export const applyCleanupOp = {
115
+ input: z.object({
136
116
  plan_id: z.string().uuid(),
137
117
  item_ids: z.array(z.string().uuid()).min(1).max(200)
138
- }
139
- },
140
- async ({ plan_id, item_ids }) => {
118
+ }),
119
+ handler: async ({ plan_id, item_ids }) => {
141
120
  const plan = await getCleanupPlan(plan_id);
142
121
  if (!plan) return textResult({ error: "cleanup_plan_not_found", plan_id });
143
122
  if (Date.parse(plan.expires_at) <= Date.now()) return textResult({ error: "cleanup_plan_expired", plan_id, expires_at: plan.expires_at });
144
123
  return textResult(await applyCleanupPlan({ plan, itemIds: item_ids, actor: "main_thread" }));
145
124
  }
146
- ];
125
+ };
147
126
 
148
- export const cleanupHistoryTool = [
149
- "cleanup_history",
150
- {
151
- title: "Read cleanup history",
152
- description: "Read cleanup plan decisions and applied worktree removals, including safe/review/blocked reasons. This is audit history, not a delete command.",
153
- inputSchema: { task_id: z.string().min(1).optional(), limit: z.number().int().min(1).max(500).default(100) }
154
- },
155
- async ({ task_id, limit }) => textResult({ items: await readCleanupHistory(task_id ?? null, limit) })
156
- ];
127
+ export const cleanupHistoryOp = {
128
+ input: z.object({ task_id: z.string().min(1).optional(), limit: z.number().int().min(1).max(500).default(100) }),
129
+ handler: async ({ task_id, limit }) => textResult({ items: await readCleanupHistory(task_id ?? null, limit) })
130
+ };
157
131
 
158
- export const cancelCodexWorkerTool = [
159
- "cancel_codex_worker",
160
- {
161
- title: "Cancel Codex worker",
162
- description:
163
- "Terminate a running Codex worker. Uses the in-process handle when available, otherwise the pid recorded on disk so a different MCP session can still cancel it.",
164
- inputSchema: {
132
+ export const cancelCodexWorkerOp = {
133
+ input: z.object({
165
134
  task_id: z.string().min(1)
166
- }
167
- },
168
- async ({ task_id }) => {
135
+ }),
136
+ handler: async ({ task_id }) => {
169
137
  const now = new Date().toISOString();
170
138
  const task = await getTask(task_id);
171
139
  // The marker is persisted before the signal is sent so the process that
@@ -194,4 +162,4 @@ export const cancelCodexWorkerTool = [
194
162
  }
195
163
  return textResult(result);
196
164
  }
197
- ];
165
+ };