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,3 +1,4 @@
1
+ import { branchOf } from "../../../domain/worker-branch.js";
1
2
  import { ensureTaskWorktree } from "../../../app/restore-worktree.js";
2
3
  import { askWorker, endSideSession, latestSideTurn } from "../../../app/side-chat.js";
3
4
  import { isGoalNeedingAttention, TERMINAL_STATUSES } from "../../../domain/status.js";
@@ -12,17 +13,11 @@ import { buildWorkerSummary, externalOutputView, reportView, runEvidenceView } f
12
13
  import { acceptanceView } from "../views/task.js";
13
14
  import { z } from "zod";
14
15
 
15
- export const getWorkerGoalTool = [
16
- "get_worker_goal",
17
- {
18
- title: "Get worker goal",
19
- description:
20
- "Read the goal recorded for a worker, plus the native Codex thread goal when the thread has one (status, tokens used, time used).",
21
- inputSchema: {
16
+ export const getWorkerGoalOp = {
17
+ input: z.object({
22
18
  task_id: z.string().min(1)
23
- }
24
- },
25
- async ({ task_id }) => {
19
+ }),
20
+ handler: async ({ task_id }) => {
26
21
  const task = await getTask(task_id);
27
22
  if (!task) return textResult({ error: "task_not_found", task_id });
28
23
  return textResult({
@@ -37,19 +32,13 @@ export const getWorkerGoalTool = [
37
32
  native_goal_read: readNativeGoalState(task.thread_id)
38
33
  });
39
34
  }
40
- ];
35
+ };
41
36
 
42
- export const getWorkerSummaryTool = [
43
- "get_worker_summary",
44
- {
45
- title: "Get worker summary",
46
- description:
47
- "One compact summary per worker: goal, status, changed files, last command, last message. Cheap enough for a main thread to read every worker at the end of a run.",
48
- inputSchema: {
37
+ export const getWorkerSummaryOp = {
38
+ input: z.object({
49
39
  task_id: z.string().min(1)
50
- }
51
- },
52
- async ({ task_id }) => {
40
+ }),
41
+ handler: async ({ task_id }) => {
53
42
  const task = await getTask(task_id);
54
43
  if (!task) return textResult({ error: "task_not_found", task_id });
55
44
  const summary = buildWorkerSummary(task, readNativeGoal(task.thread_id));
@@ -60,23 +49,17 @@ export const getWorkerSummaryTool = [
60
49
  }
61
50
  return textResult(summary);
62
51
  }
63
- ];
52
+ };
64
53
 
65
- export const getWorkerResultTool = [
66
- "get_worker_result",
67
- {
68
- title: "Get worker result",
69
- description:
70
- "Read a worker's own final report. The overview and the wait response clip the last message; this is the door for the actual conclusion. Returns the last N agent messages (each clipped past maxChars, default 6000 bytes, with truncated: true and the full size so you can re-read it whole), the status fields that tell a real finish from a crash, verification (the commands the worker ran, their exit codes and the tail of any failing output, to hold its report against), acceptance (the supervisor's own run of the dispatch-time acceptance commands, independent of the report: configured, passed, and each check's exit code and output tail; passed: false means resume the worker with that output instead of reading its report, passed: true against a report that says blocked or not done means trust the checks and read the diff), changed_file_count, and base_behind (how many commits the project's HEAD is past the worktree's base; resume with rebaseOnto when it is not 0). includeFiles: true adds the changed_files list; get_worker_diff is the ground truth for what changed.",
71
- inputSchema: {
54
+ export const getWorkerResultOp = {
55
+ input: z.object({
72
56
  task_id: z.string().min(1),
73
57
  limit: z.number().int().min(1).max(20).default(1),
74
58
  // Per report, UTF-8 bytes. 0 means no clipping.
75
59
  maxChars: z.number().int().min(0).max(1000000).default(6000),
76
60
  includeFiles: z.boolean().default(false)
77
- }
78
- },
79
- async ({ task_id, limit, maxChars, includeFiles }) => {
61
+ }),
62
+ handler: async ({ task_id, limit, maxChars, includeFiles }) => {
80
63
  const task = await getTask(task_id);
81
64
  if (!task) return textResult({ error: "task_not_found", task_id });
82
65
  let reports = await readAgentMessages(task_id, limit);
@@ -122,7 +105,7 @@ export const getWorkerResultTool = [
122
105
  report_bytes: reportBytes,
123
106
  truncated,
124
107
  next_step: truncated
125
- ? `a report was clipped to ${maxChars} bytes; call again with maxChars: ${Math.max(...reportBytes)} (or 0) to read it whole`
108
+ ? `a report was clipped to ${maxChars} bytes; call again with max_chars: ${Math.max(...reportBytes)} (or 0) to read it whole`
126
109
  : null,
127
110
  reports: clipped,
128
111
  source,
@@ -130,7 +113,7 @@ export const getWorkerResultTool = [
130
113
  completed_at: task.completed_at ?? null
131
114
  });
132
115
  }
133
- ];
116
+ };
134
117
 
135
118
  // Cleanup keeps the branch; the diff is read from a worktree cut from it
136
119
  // again. Null when the worktree is there, a refusal when it cannot come back.
@@ -143,13 +126,8 @@ async function restoreRefusal(task) {
143
126
  }
144
127
  }
145
128
 
146
- export const getWorkerDiffTool = [
147
- "get_worker_diff",
148
- {
149
- title: "Get worker diff",
150
- description:
151
- "The worker's actual changes. By default this is a complete file/hunk index; request one file to page through hunks with pageSize or cursor. Supplying maxChars without file preserves the legacy bounded full-diff response. This is the ground truth to check a worker's report against.",
152
- inputSchema: {
129
+ export const getWorkerDiffOp = {
130
+ input: z.object({
153
131
  task_id: z.string().min(1),
154
132
  maxChars: z.number().int().min(0).max(1000000).optional(),
155
133
  file: z.string().min(1).optional(),
@@ -157,13 +135,12 @@ export const getWorkerDiffTool = [
157
135
  pageSize: z.number().int().min(1).max(20).default(4),
158
136
  cursor: z.string().min(1).optional(),
159
137
  paths: z.array(z.string().min(1)).optional()
160
- }
161
- },
162
- async ({ task_id, maxChars, file, hunk, pageSize, cursor, paths }) => {
138
+ }),
139
+ handler: async ({ task_id, maxChars, file, hunk, pageSize, cursor, paths }) => {
163
140
  const task = await getTask(task_id);
164
141
  if (!task) return textResult({ error: "task_not_found", task_id });
165
142
  if (!task.worktree_path) {
166
- return textResult({ error: "no_worktree", task_id, external_outputs: externalOutputView(task, maxChars), reason: "this worker ran in place (its cwd is not a git repository or the worktree could not be created), so there is no isolated diff to read; call get_worker_result with includeFiles: true for the files it touched" });
143
+ return textResult({ error: "no_worktree", task_id, external_outputs: externalOutputView(task, maxChars), reason: "this worker ran in place (its cwd is not a git repository or the worktree could not be created), so there is no isolated diff to read; call get_worker with include result and include_files: true for the files it touched" });
167
144
  }
168
145
  const refusal = await restoreRefusal(task);
169
146
  if (refusal) return refusal;
@@ -174,7 +151,7 @@ export const getWorkerDiffTool = [
174
151
  title: task.title,
175
152
  status: task.status,
176
153
  worktree_path: task.worktree_path,
177
- branch: `codex/${task.id}`,
154
+ branch: branchOf(task),
178
155
  ...diff,
179
156
  external_outputs: externalOutputView(task, maxChars)
180
157
  });
@@ -192,7 +169,7 @@ export const getWorkerDiffTool = [
192
169
  title: task.title,
193
170
  status: task.status,
194
171
  worktree_path: task.worktree_path,
195
- branch: `codex/${task.id}`,
172
+ branch: branchOf(task),
196
173
  ...diff,
197
174
  files,
198
175
  external_outputs: externalOutputView(task, maxChars || 6000)
@@ -237,24 +214,18 @@ export const getWorkerDiffTool = [
237
214
  summary_only: false
238
215
  });
239
216
  }
240
- ];
217
+ };
241
218
 
242
- export const askCodexWorkerTool = [
243
- "ask_codex_worker",
244
- {
245
- title: "Ask a worker on the side",
246
- description:
247
- "Ask a finished or running worker a question without touching its thread: the worker's Codex thread is forked once into a read-only side session (like Codex's own /btw), the question is asked there, and later questions resume that fork. The fork carries everything the worker saw and did, so 'why did you change X' or 'where is Y handled' costs one short answer instead of a read of the event stream. The fork has no network and no MCP tools and is told so; it answers from its context and the worktree. Once the worker has been resumed, the next question automatically takes a new fork from the updated thread (refreshed: \"worker_resumed\"); fresh: true forces a new fork. Changes still go through resume_codex_worker. Without a question it returns the latest side turn (for an answer that outran timeoutMs). end: true deletes the fork.",
248
- inputSchema: {
219
+ export const askCodexWorkerOp = {
220
+ input: z.object({
249
221
  task_id: z.string().min(1),
250
222
  question: z.string().min(1).optional(),
251
223
  timeoutMs: z.number().int().min(1000).max(600000).default(110000),
252
224
  maxChars: z.number().int().min(0).max(1000000).default(8000),
253
225
  fresh: z.boolean().default(false),
254
226
  end: z.boolean().default(false)
255
- }
256
- },
257
- async ({ task_id, question, timeoutMs, maxChars, fresh, end }) => {
227
+ }),
228
+ handler: async ({ task_id, question, timeoutMs, maxChars, fresh, end }) => {
258
229
  const task = await getTask(task_id);
259
230
  if (!task) return textResult({ error: "task_not_found", task_id });
260
231
  const clipAnswer = (state) => {
@@ -271,7 +242,7 @@ export const askCodexWorkerTool = [
271
242
  try {
272
243
  const state = clipAnswer(await askWorker({ task, question, timeoutMs, fresh }));
273
244
  const next = state.timed_out
274
- ? `The side turn is still running; call ask_codex_worker again with only task_id to read the answer when it lands.`
245
+ ? `The side turn is still running; call ask_worker again with only task_id to read the answer when it lands.`
275
246
  : null;
276
247
  return textResult({ task_id, ...state, next_step: next });
277
248
  } catch (error) {
@@ -281,4 +252,4 @@ export const askCodexWorkerTool = [
281
252
  return textResult({ task_id, error: error.code ?? "side_turn_failed", reason: error.message });
282
253
  }
283
254
  }
284
- ];
255
+ };
@@ -9,14 +9,9 @@ import { receipt } from "../views/task.js";
9
9
  import { createHash } from "node:crypto";
10
10
  import { z } from "zod";
11
11
 
12
- export const createIndependentVerifierTool = [
13
- "create_independent_verifier",
14
- {
15
- title: "Create an independent read-only verifier",
16
- description: "Create a fresh read-only verifier for one settled worker. It receives the target objective and current worktree path, never the target report or candidate facts, has no network and cannot dispatch workers. The review relation is persisted for later finding and resolution.",
17
- inputSchema: { task_id: z.string().min(1), title: z.string().min(1).max(120).optional() }
18
- },
19
- async ({ task_id, title }) => {
12
+ export const createIndependentVerifierOp = {
13
+ input: z.object({ task_id: z.string().min(1), title: z.string().min(1).max(120).optional() }),
14
+ handler: async ({ task_id, title }) => {
20
15
  try {
21
16
  const subject = await getTask(task_id);
22
17
  if (!subject) return textResult({ error: "task_not_found", task_id });
@@ -59,16 +54,11 @@ export const createIndependentVerifierTool = [
59
54
  return errorResult(error);
60
55
  }
61
56
  }
62
- ];
57
+ };
63
58
 
64
- export const recordIndependentFindingTool = [
65
- "record_independent_finding",
66
- {
67
- title: "Record an independent verifier finding",
68
- description: "After a verifier settles, record its passes/fails/inconclusive verdict with a concise reason. The supervisor stores a retained finding artifact and appends an event to the reviewed worker; this does not change the reviewed worker's delivery state automatically.",
69
- inputSchema: { verifier_task_id: z.string().min(1), verdict: z.enum(["passes", "fails", "inconclusive"]), reason: z.string().min(1).max(4000) }
70
- },
71
- async ({ verifier_task_id, verdict, reason }) => {
59
+ export const recordIndependentFindingOp = {
60
+ input: z.object({ verifier_task_id: z.string().min(1), verdict: z.enum(["passes", "fails", "inconclusive"]), reason: z.string().min(1).max(4000) }),
61
+ handler: async ({ verifier_task_id, verdict, reason }) => {
72
62
  try {
73
63
  const review = await getReviewByVerifierTask(verifier_task_id);
74
64
  if (!review) return textResult({ error: "review_not_found", verifier_task_id });
@@ -97,16 +87,11 @@ export const recordIndependentFindingTool = [
97
87
  return errorResult(error);
98
88
  }
99
89
  }
100
- ];
90
+ };
101
91
 
102
- export const resolveIndependentFindingTool = [
103
- "resolve_independent_finding",
104
- {
105
- title: "Resolve an independent verifier finding",
106
- description: "Record how a previously recorded independent finding was resolved. This is an audit transition only; it does not hide the finding or alter worker code.",
107
- inputSchema: { verifier_task_id: z.string().min(1), resolution: z.string().min(1).max(4000) }
108
- },
109
- async ({ verifier_task_id, resolution }) => {
92
+ export const resolveIndependentFindingOp = {
93
+ input: z.object({ verifier_task_id: z.string().min(1), resolution: z.string().min(1).max(4000) }),
94
+ handler: async ({ verifier_task_id, resolution }) => {
110
95
  try {
111
96
  const review = await resolveReviewFinding({ verifierTaskId: verifier_task_id, resolution });
112
97
  if (!review) return textResult({ error: "review_not_recorded", verifier_task_id });
@@ -119,17 +104,12 @@ export const resolveIndependentFindingTool = [
119
104
  return errorResult(error);
120
105
  }
121
106
  }
122
- ];
107
+ };
123
108
 
124
- export const getIndependentReviewTool = [
125
- "get_independent_review",
126
- {
127
- title: "Get one independent review relation",
128
- description: "Read the persisted subject/verifier/finding/resolution relation for a verifier task. Use get_artifact for the retained finding evidence.",
129
- inputSchema: { verifier_task_id: z.string().min(1) }
130
- },
131
- async ({ verifier_task_id }) => {
109
+ export const getIndependentReviewOp = {
110
+ input: z.object({ verifier_task_id: z.string().min(1) }),
111
+ handler: async ({ verifier_task_id }) => {
132
112
  const review = await getReviewByVerifierTask(verifier_task_id);
133
113
  return textResult(review ? { review } : { error: "review_not_found", verifier_task_id });
134
114
  }
135
- ];
115
+ };
@@ -2,6 +2,7 @@ import { acceptanceVerdict } from "../../../app/acceptance.js";
2
2
  import { ACTIVE_STATUSES } from "../../../domain/status.js";
3
3
  import { truncateEventStrings } from "../../../domain/truncate.js";
4
4
  import { getTasks } from "../../../infra/store/tasks.js";
5
+ import { restoreEventBodies } from "../../../infra/store/event-body.js";
5
6
  import { readTaskEvents } from "../../../infra/store/events.js";
6
7
  import { reconcileDetachedActiveTasks } from "../../../infra/store/reconcile.js";
7
8
  import { readTaskChanges } from "../../../infra/worktree.js";
@@ -41,7 +42,7 @@ function budgetExhaustedHint(effectiveTimeoutMs) {
41
42
  effectiveTimeoutMs >= 60000
42
43
  ? `${Math.round(effectiveTimeoutMs / 60000)}-minute`
43
44
  : `${Math.round(effectiveTimeoutMs / 1000)}-second`;
44
- return `Workers are still running; the ${budgetLabel} wait budget ran out. Reuse the same task_ids for a short wait, or schedule check_workers for long monitoring. Set allowLongWait only after verifying the client's MCP timeout supports the requested budget; do not start another long wait while a background wait is active.`;
45
+ return `Workers are still running; the ${budgetLabel} wait budget ran out. Reuse the same task_ids for a short wait, or schedule poll_workers for long monitoring. Set allow_long_wait only after verifying the client's MCP timeout supports the requested budget; do not start another long wait while a background wait is active.`;
45
46
  }
46
47
 
47
48
  function compactWorkerRow(task) {
@@ -63,9 +64,9 @@ function fullWorkerRows(tasks, { includeEvents, eventLimit, eventMaxChars, event
63
64
  tasks.map(async (task) => ({
64
65
  ...summarizeTask(task),
65
66
  recent_events: includeEvents
66
- ? await readTaskEvents(task.id, eventLimit, eventKinds ?? null).then((events) =>
67
- eventMaxChars === undefined ? events : events.map((event) => truncateEventStrings(event, eventMaxChars))
68
- )
67
+ ? await readTaskEvents(task.id, eventLimit, eventKinds ?? null)
68
+ .then((stored) => restoreEventBodies(stored, task.run_log))
69
+ .then((events) => (eventMaxChars === undefined ? events : events.map((event) => truncateEventStrings(event, eventMaxChars))))
69
70
  : undefined
70
71
  }))
71
72
  );
@@ -103,19 +104,15 @@ async function waitForWorkers(input, extra) {
103
104
  failed_count: tasks.filter((task) => task.status === "failed").length,
104
105
  cancelled_count: tasks.filter((task) => task.status === "cancelled").length,
105
106
  lost_count: tasks.filter((task) => task.status === "lost").length,
107
+ timed_out_count: tasks.filter((task) => task.status === "timed_out").length,
106
108
  active_count: tasks.filter((task) => ACTIVE_STATUSES.has(task.status)).length,
107
109
  acceptance_failed_count: tasks.filter((task) => task.acceptance_results?.passed === false).length,
108
110
  workers: compact ? tasks.map(compactWorkerRow) : summaries
109
111
  }));
110
112
  }
111
113
 
112
- export const waitCodexWorkersTool = [
113
- "wait_codex_workers",
114
- {
115
- title: "Wait for Codex workers",
116
- description:
117
- "Block until selected Codex workers reach a terminal status, then return summaries. Each call is capped at 60 seconds unless allowLongWait is explicitly true and the caller has verified its MCP timeout supports the requested budget. A spent wait budget returns a snapshot while workers continue; reuse the same task_ids or schedule check_workers for longer monitoring. compact: true returns one line per worker with status, phase, exit_code, changed_file_count, acceptance and liveness. command_running means a command may still be working despite a long idle interval.",
118
- inputSchema: {
114
+ export const waitCodexWorkersOp = {
115
+ input: z.object({
119
116
  task_ids: z.array(z.string().min(1)).min(1),
120
117
  mode: z.enum(["any", "all"]).default("all"),
121
118
  timeoutMinutes: z.number().int().min(1).max(360).default(1),
@@ -126,7 +123,7 @@ export const waitCodexWorkersTool = [
126
123
  // Off by default. A wait is the call clients background and then replay
127
124
  // as a notification, so its payload has to stay small; ten events per
128
125
  // worker was the bulk of it. Ask for events explicitly, or read
129
- // get_codex_worker_events for one worker.
126
+ // get_worker (include events) for one worker.
130
127
  includeEvents: z.boolean().default(false),
131
128
  eventLimit: z.number().int().min(1).max(50).default(10),
132
129
  // Events used to come back whole: one command event can carry a heredoc
@@ -137,9 +134,8 @@ export const waitCodexWorkersTool = [
137
134
  eventKinds: z.array(z.string().min(1)).optional(),
138
135
  // The smallest useful answer: one line per worker, for a caller that
139
136
  // only wants to know who is done. Everything else comes from
140
- // get_worker_result / get_worker_diff afterwards.
137
+ // get_worker (include result) / get_worker_diff afterwards.
141
138
  compact: z.boolean().optional()
142
- }
143
- },
144
- waitForWorkers
145
- ];
139
+ }),
140
+ handler: waitForWorkers
141
+ };
@@ -1,19 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
  import "../../app/compose.js";
3
+ import { installCrashGuard } from "../../infra/crash-guard.js";
3
4
  import { syncSkills } from "../../infra/skill-sync.js";
4
5
  import { packageVersion } from "./meta.js";
5
6
  import { refreshUpdateState, UPDATE_RECHECK_MS } from "./update-state.js";
6
7
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
7
8
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
9
+ import { cancelWorkerTool, createWorkerTool, preflightWorkerTool, resumeWorkerTool } from "./tools/dispatch.js";
10
+ import { cleanupTool, landWorkerTool, verifyPushTool } from "./tools/deliver.js";
11
+ import { factsTool, getArtifactTool, reviewTool } from "./tools/optional.js";
12
+ import { askWorkerTool, describeSessionTool, findWorksTool, getWorkerDiffTool, getWorkerTool } from "./tools/read.js";
13
+ import { pollWorkersTool, waitWorkersTool } from "./tools/track.js";
8
14
 
9
- import { overviewDeltaTool, checkWorkersTool } from "./tools/poll.js";
10
- import { checkAcceptanceTool, preflightCodexWorkerTool, getWorkerPreflightTool, createCodexWorkerTool, createCodexFollowupWorkerTool, resumeCodexWorkerTool } from "./tools/dispatch.js";
11
- import { listCodexWorkersTool, getOrchestrationOverviewTool, getSessionWorksTool, checkForUpdateTool, describeSessionTool, searchWorksTool, getCodexWorkerStatusTool, getCodexWorkerEventsTool } from "./tools/overview.js";
12
- import { waitCodexWorkersTool } from "./tools/wait.js";
13
- import { getContextSnapshotMetaTool, getFactTool, getArtifactTool, promoteWorkerFactTool, revokeWorkerFactTool, getWorkerEvidenceTool, searchWorkerFactsTool } from "./tools/facts.js";
14
- import { createIndependentVerifierTool, recordIndependentFindingTool, resolveIndependentFindingTool, getIndependentReviewTool } from "./tools/review.js";
15
- import { getWorkerGoalTool, getWorkerSummaryTool, getWorkerResultTool, getWorkerDiffTool, askCodexWorkerTool } from "./tools/results.js";
16
- import { landCodexWorkerTool, verifyDeliveryPushTool, cleanupPlanTool, applyCleanupTool, cleanupHistoryTool, cancelCodexWorkerTool } from "./tools/delivery.js";
15
+ installCrashGuard("mcp-server");
17
16
 
18
17
  const server = new McpServer({
19
18
  name: "codex-supervisor",
@@ -28,7 +27,7 @@ setInterval(() => refreshUpdateState({ force: true }), UPDATE_RECHECK_MS).unref(
28
27
  // and a global install only synced the skill on the day it was installed.
29
28
  // Runs in the background; a client that cannot write its skill directory
30
29
  // only costs a line on stderr.
31
- if (!process.env.CODEX_SUPERVISOR_SKIP_SKILL_SYNC) {
30
+ if (!process.env.AGENT_SUPERVISOR_SKIP_SKILL_SYNC) {
32
31
  syncSkills()
33
32
  .then((result) => {
34
33
  const changed = [...result.installed, ...result.updated];
@@ -46,49 +45,20 @@ if (!process.env.CODEX_SUPERVISOR_SKIP_SKILL_SYNC) {
46
45
  });
47
46
  }
48
47
 
49
- // Registration order is part of the contract: tools/list returns it.
48
+ // The order is the order tools/list returns, which is the order a model reads
49
+ // them in: the path of a batch from preflight to cleanup.
50
50
  const TOOLS = [
51
- overviewDeltaTool,
52
- checkWorkersTool,
53
- checkAcceptanceTool,
54
- preflightCodexWorkerTool,
55
- getWorkerPreflightTool,
56
- createCodexWorkerTool,
57
- createCodexFollowupWorkerTool,
58
- resumeCodexWorkerTool,
59
- listCodexWorkersTool,
60
- getOrchestrationOverviewTool,
61
- waitCodexWorkersTool,
62
- getSessionWorksTool,
63
- checkForUpdateTool,
64
- describeSessionTool,
65
- searchWorksTool,
66
- getCodexWorkerStatusTool,
67
- getCodexWorkerEventsTool,
68
- getContextSnapshotMetaTool,
69
- getFactTool,
70
- getArtifactTool,
71
- promoteWorkerFactTool,
72
- revokeWorkerFactTool,
73
- getWorkerEvidenceTool,
74
- searchWorkerFactsTool,
75
- createIndependentVerifierTool,
76
- recordIndependentFindingTool,
77
- resolveIndependentFindingTool,
78
- getIndependentReviewTool,
79
- getWorkerGoalTool,
80
- getWorkerSummaryTool,
81
- getWorkerResultTool,
82
- getWorkerDiffTool,
83
- askCodexWorkerTool,
84
- landCodexWorkerTool,
85
- verifyDeliveryPushTool,
86
- cleanupPlanTool,
87
- applyCleanupTool,
88
- cleanupHistoryTool,
89
- cancelCodexWorkerTool
51
+ preflightWorkerTool, createWorkerTool, resumeWorkerTool, cancelWorkerTool,
52
+ pollWorkersTool, waitWorkersTool,
53
+ getWorkerTool, getWorkerDiffTool, askWorkerTool,
54
+ landWorkerTool, verifyPushTool, cleanupTool,
55
+ findWorksTool, describeSessionTool
90
56
  ];
91
- for (const tool of TOOLS) server.registerTool(...tool);
57
+ // The fact ledger, independent review and raw artifacts are rarely needed and
58
+ // cost context in every session, so they are opt-in.
59
+ const OPTIONAL_TOOLS = [factsTool, reviewTool, getArtifactTool];
60
+ const enabled = process.env.AGENT_SUPERVISOR_TOOLS === "all" ? [...TOOLS, ...OPTIONAL_TOOLS] : TOOLS;
61
+ for (const tool of enabled) server.registerTool(...tool);
92
62
 
93
63
  const transport = new StdioServerTransport();
94
64
  await server.connect(transport);
@@ -0,0 +1,48 @@
1
+ import { z } from "zod";
2
+ import { applyCleanupOp, cleanupHistoryOp, cleanupPlanOp, landCodexWorkerOp, verifyDeliveryPushOp } from "../handlers/delivery.js";
3
+ import { defineTool, run } from "./run.js";
4
+
5
+ export const landWorkerTool = defineTool("land_worker", {
6
+ title: "Land a worker's commits",
7
+ description: "Cherry-pick the worker's commits onto the branch checked out where it was dispatched. commit_message first commits its uncommitted edits, which is how a sandboxed worker's work gets committed. Refused when acceptance failed or has not run, the target is dirty, or the diff leaves owned_paths; a conflict leaves the target as it was. Read get_worker_diff first.",
8
+ inputSchema: {
9
+ task_id: z.string(),
10
+ commit_message: z.string().optional(),
11
+ onto: z.string().optional().describe("Refuse unless the target is on this branch"),
12
+ include_followup_parents: z.boolean().default(false).describe("Land the whole follow-up chain, root first"),
13
+ commit_messages: z.record(z.string(), z.string()).optional().describe("Task id to commit message, for the chain"),
14
+ ignore_acceptance: z.boolean().default(false).describe("Only when the user said so"),
15
+ allow_outside_owned: z.boolean().default(false).describe("Only when the user said so")
16
+ }
17
+ }, (args) => run(landCodexWorkerOp, {
18
+ task_id: args.task_id, onto: args.onto, commitMessage: args.commit_message, includeFollowupParents: args.include_followup_parents,
19
+ commitMessages: args.commit_messages, ignoreAcceptance: args.ignore_acceptance, allowOutsideOwned: args.allow_outside_owned
20
+ }));
21
+
22
+ export const verifyPushTool = defineTool("verify_push", {
23
+ title: "Prove landed work is on the remote",
24
+ description: "Fetch a remote branch and check the landed commit is reachable from it. It only verifies: it never pushes or deploys. Landing is local; this is the proof the work left the machine.",
25
+ inputSchema: {
26
+ task_id: z.string(),
27
+ remote: z.string().default("origin"),
28
+ branch: z.string().optional().describe("Default: the branch the work landed on")
29
+ }
30
+ }, (args) => run(verifyDeliveryPushOp, args));
31
+
32
+ export const cleanupTool = defineTool("cleanup", {
33
+ title: "Inspect or force worktree cleanup",
34
+ description: "Cleanup is automatic during poll_workers: landed or unchanged work goes at once, unlanded work after a hold period, with uncommitted edits committed to the worker's branch first; branches and evidence stay. Use this to see why a worktree is still there (plan), remove SAFE ones now (apply, with plan_id and item_ids), or read what was removed (history).",
35
+ inputSchema: {
36
+ action: z.enum(["plan", "apply", "history"]),
37
+ task_ids: z.array(z.string()).max(200).optional().describe("plan: limit to these workers; history: the first one"),
38
+ project_root: z.string().optional(),
39
+ plan_id: z.string().optional(),
40
+ item_ids: z.array(z.string()).max(200).optional(),
41
+ limit: z.number().int().min(1).max(500).optional()
42
+ }
43
+ }, (args) => {
44
+ if (args.action === "plan") return run(cleanupPlanOp, { task_ids: args.task_ids, project_root: args.project_root });
45
+ if (args.action === "history") return run(cleanupHistoryOp, { task_id: args.task_ids?.[0], limit: args.limit });
46
+ if (!args.plan_id || !args.item_ids?.length) return { error: "invalid_arguments", message: "apply needs plan_id and item_ids from a plan" };
47
+ return run(applyCleanupOp, { plan_id: args.plan_id, item_ids: args.item_ids });
48
+ });