codex-supervisor-mcp 0.7.3 → 0.8.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.
- package/README.en.md +14 -10
- package/README.md +14 -10
- package/package.json +1 -1
- package/skills/codex-supervisor/SKILL.md +14 -7
- package/src/codex-runner.js +136 -15
- package/src/event-parser.js +64 -9
- package/src/landing.js +222 -4
- package/src/mcp-server.js +159 -26
- package/src/prompt.js +60 -7
- package/src/task-store.js +40 -2
- package/src/truncate.js +13 -0
- package/src/web-app.js +2 -0
- package/src/worktree.js +28 -0
- package/web/dist/assets/{index-CqG_XY9n.js → index-fJQbspTY.js} +1 -1
- package/web/dist/index.html +1 -1
package/src/landing.js
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
// the target must be clean, it is never switched to another branch, and a
|
|
8
8
|
// conflict leaves nothing half-applied.
|
|
9
9
|
import { execFileSync } from "node:child_process";
|
|
10
|
-
import { existsSync } from "node:fs";
|
|
10
|
+
import { existsSync, rmSync } from "node:fs";
|
|
11
|
+
import { join } from "node:path";
|
|
11
12
|
import { parsePorcelainLine, resolveWorktreeBase, worktreeRef } from "./worktree.js";
|
|
12
13
|
|
|
13
14
|
const defaultGitBin = process.env.GIT_BIN?.trim() || "git";
|
|
@@ -19,7 +20,7 @@ const defaultGitBin = process.env.GIT_BIN?.trim() || "git";
|
|
|
19
20
|
// directory. An identity git already has is used untouched.
|
|
20
21
|
const FALLBACK_IDENTITY = { name: "codex-supervisor", email: "codex-supervisor@localhost" };
|
|
21
22
|
const identityCache = new Map();
|
|
22
|
-
function identityEnv(cwd) {
|
|
23
|
+
export function identityEnv(cwd) {
|
|
23
24
|
if (identityCache.has(cwd)) return identityCache.get(cwd);
|
|
24
25
|
let name = "";
|
|
25
26
|
let email = "";
|
|
@@ -79,8 +80,28 @@ function currentBranch(cwd) {
|
|
|
79
80
|
//
|
|
80
81
|
// Returns { landed: [{ sha, original, subject }], onto, head } on success;
|
|
81
82
|
// otherwise { error, reason, ... } with nothing changed in the target.
|
|
82
|
-
export function landWorker(task, { onto = null, commitMessage = null } = {}) {
|
|
83
|
+
export function landWorker(task, { onto = null, commitMessage = null, ignoreAcceptance = false } = {}) {
|
|
83
84
|
const target = task.project_root;
|
|
85
|
+
// The dispatcher's own checks are the gate. A failed run is refused until
|
|
86
|
+
// it passes; a run that was cut short is refused until it has run.
|
|
87
|
+
const acceptance = task.acceptance_results ?? null;
|
|
88
|
+
if (!ignoreAcceptance && acceptance) {
|
|
89
|
+
const failing = (acceptance.checks ?? []).find((check) => check.exit_code !== 0) ?? null;
|
|
90
|
+
if (acceptance.passed === false) {
|
|
91
|
+
return {
|
|
92
|
+
error: "acceptance_failed",
|
|
93
|
+
reason: `the worker's acceptance run failed${failing ? ` on "${failing.command.slice(0, 120)}" (exit ${failing.timed_out ? "timeout" : failing.exit_code})` : acceptance.error ? ` (${acceptance.error})` : ""}; resume the worker with the failing output and land once it passes. ignoreAcceptance: true lands anyway, only when the user said to.`,
|
|
94
|
+
acceptance: { status: acceptance.status, passed: false, checks: acceptance.checks ?? [], error: acceptance.error ?? null }
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
if (acceptance.status === "running" || acceptance.status === "interrupted" || acceptance.status === "cancelled") {
|
|
98
|
+
return {
|
|
99
|
+
error: "acceptance_not_run",
|
|
100
|
+
reason: `the worker's acceptance is ${acceptance.status}; wait for it (or resume the worker to run it again) before landing. ignoreAcceptance: true lands anyway, only when the user said to.`,
|
|
101
|
+
acceptance: { status: acceptance.status, passed: null }
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
84
105
|
if (!task.worktree_path || !existsSync(task.worktree_path)) {
|
|
85
106
|
return { error: "no_worktree", reason: "this worker has no worktree (it ran in place), so there is nothing on a codex/ branch to land" };
|
|
86
107
|
}
|
|
@@ -124,6 +145,30 @@ export function landWorker(task, { onto = null, commitMessage = null } = {}) {
|
|
|
124
145
|
commits.push(committedForWorker);
|
|
125
146
|
uncommitted = [];
|
|
126
147
|
}
|
|
148
|
+
// Commits whose patch is already on the target (a previous land, or the
|
|
149
|
+
// main thread cherry-picked by hand) are skipped by patch id; picking
|
|
150
|
+
// them again produces an empty commit and git stops with an error.
|
|
151
|
+
const targetHead = git(target, ["rev-parse", "HEAD"]).trim();
|
|
152
|
+
let alreadyLanded = [];
|
|
153
|
+
if (commits.length > 0) {
|
|
154
|
+
try {
|
|
155
|
+
const workerHead = git(task.worktree_path, ["rev-parse", "HEAD"]).trim();
|
|
156
|
+
const pending = new Set(lines(git(target, ["rev-list", "--cherry-pick", "--right-only", `${targetHead}...${workerHead}`])));
|
|
157
|
+
alreadyLanded = commits.filter((sha) => !pending.has(sha));
|
|
158
|
+
commits = commits.filter((sha) => pending.has(sha));
|
|
159
|
+
} catch {
|
|
160
|
+
// comparison failed; try to land everything and let the pick decide
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (commits.length === 0 && alreadyLanded.length > 0) {
|
|
164
|
+
return {
|
|
165
|
+
error: "nothing_to_land",
|
|
166
|
+
reason: `every commit on this worker's branch is already on ${branch} (landed before, by patch); nothing new to land`,
|
|
167
|
+
already_landed: alreadyLanded,
|
|
168
|
+
uncommitted,
|
|
169
|
+
base_commit: base
|
|
170
|
+
};
|
|
171
|
+
}
|
|
127
172
|
if (commits.length === 0) {
|
|
128
173
|
return {
|
|
129
174
|
error: "nothing_to_land",
|
|
@@ -135,7 +180,7 @@ export function landWorker(task, { onto = null, commitMessage = null } = {}) {
|
|
|
135
180
|
};
|
|
136
181
|
}
|
|
137
182
|
|
|
138
|
-
const before =
|
|
183
|
+
const before = targetHead;
|
|
139
184
|
try {
|
|
140
185
|
git(target, ["cherry-pick", "--allow-empty-message", ...commits], { timeout: 10 * 60 * 1000 });
|
|
141
186
|
} catch (error) {
|
|
@@ -170,7 +215,180 @@ export function landWorker(task, { onto = null, commitMessage = null } = {}) {
|
|
|
170
215
|
base_commit: base,
|
|
171
216
|
head: landed.at(-1) ?? before,
|
|
172
217
|
landed: landed.map((sha, index) => ({ sha, original: commits[index] ?? null, subject: subjectOf.get(sha) ?? null })),
|
|
218
|
+
already_landed: alreadyLanded,
|
|
173
219
|
committed_for_worker: committedForWorker,
|
|
174
220
|
uncommitted
|
|
175
221
|
};
|
|
176
222
|
}
|
|
223
|
+
|
|
224
|
+
function gitTail(error) {
|
|
225
|
+
return `${error.stdout ?? ""}${error.stderr ?? ""}`.trim().split("\n").slice(-4).join("\n") || error.message.split("\n")[0];
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function conflictFiles(cwd) {
|
|
229
|
+
try {
|
|
230
|
+
return lines(git(cwd, ["diff", "--name-only", "--diff-filter=U"]));
|
|
231
|
+
} catch {
|
|
232
|
+
return [];
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function stashRef(cwd) {
|
|
237
|
+
try {
|
|
238
|
+
return git(cwd, ["rev-parse", "-q", "--verify", "refs/stash"]).trim() || null;
|
|
239
|
+
} catch {
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function operationInProgress(cwd) {
|
|
245
|
+
for (const marker of ["rebase-merge", "rebase-apply", "CHERRY_PICK_HEAD", "MERGE_HEAD"]) {
|
|
246
|
+
try {
|
|
247
|
+
const path = git(cwd, ["rev-parse", "--git-path", marker]).trim();
|
|
248
|
+
if (path && existsSync(path.startsWith("/") || /^[A-Za-z]:/.test(path) ? path : join(cwd, path))) return marker;
|
|
249
|
+
} catch {
|
|
250
|
+
// not a repo; the caller reports that
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Moves a worker's worktree onto a newer commit of the project before the
|
|
257
|
+
// worker is resumed. The worktree was cut from base_commit when the worker
|
|
258
|
+
// was dispatched; by the time it is sent back for a fix the project's branch
|
|
259
|
+
// has often moved on, and a worker that keeps editing the old base does
|
|
260
|
+
// work that cannot land.
|
|
261
|
+
//
|
|
262
|
+
// Exactly the worker's own commits are replayed: `git rebase --onto <onto>
|
|
263
|
+
// <base>`, never a plain rebase, whose merge-base start would also replay
|
|
264
|
+
// the project's own commits when the base was rewritten. Edits the worker
|
|
265
|
+
// left uncommitted (every workspace-write worker: the sandbox keeps .git
|
|
266
|
+
// read-only) are stashed around the rebase, untracked files included.
|
|
267
|
+
//
|
|
268
|
+
// Nothing is left half done. A conflict in the replay aborts the rebase; a
|
|
269
|
+
// conflict when the stash comes back resets the branch to where it was and
|
|
270
|
+
// pops the stash there, which cannot conflict. Either way the worktree is as
|
|
271
|
+
// it was and the caller gets the file list.
|
|
272
|
+
//
|
|
273
|
+
// Returns { ok: true, noop: true, base_commit, head } when onto is already in
|
|
274
|
+
// the branch's history, { ok: true, base_commit: onto, head, replayed,
|
|
275
|
+
// stashed } after a real rebase, or { error, reason, files?, git?,
|
|
276
|
+
// base_commit, head } with nothing changed.
|
|
277
|
+
export function rebaseWorktree(task, ontoCommit) {
|
|
278
|
+
const cwd = task.worktree_path;
|
|
279
|
+
if (!cwd || !existsSync(cwd)) {
|
|
280
|
+
return { error: "no_worktree", reason: "this worker has no worktree (it ran in place), so there is nothing to rebase" };
|
|
281
|
+
}
|
|
282
|
+
const base = resolveWorktreeBase(cwd, worktreeRef(task));
|
|
283
|
+
if (!base) return { error: "no_base_commit", reason: "the commit this worker started from is unknown, so its own commits cannot be told apart for the replay" };
|
|
284
|
+
const inProgress = operationInProgress(cwd);
|
|
285
|
+
if (inProgress) {
|
|
286
|
+
return { error: "rebase_in_progress", reason: `${cwd} has a ${inProgress} in progress; finish or abort it first`, base_commit: base };
|
|
287
|
+
}
|
|
288
|
+
let head;
|
|
289
|
+
try {
|
|
290
|
+
head = git(cwd, ["rev-parse", "HEAD"]).trim();
|
|
291
|
+
} catch (error) {
|
|
292
|
+
return { error: "no_worktree", reason: `${cwd} has no resolvable HEAD: ${gitTail(error)}`, base_commit: base };
|
|
293
|
+
}
|
|
294
|
+
try {
|
|
295
|
+
git(cwd, ["merge-base", "--is-ancestor", ontoCommit, "HEAD"]);
|
|
296
|
+
// onto is already behind or at this branch: a rebase would move the
|
|
297
|
+
// worker's commits backwards. Nothing to do and base stays.
|
|
298
|
+
return { ok: true, noop: true, base_commit: base, head };
|
|
299
|
+
} catch (error) {
|
|
300
|
+
if (error.status !== 1) {
|
|
301
|
+
return { error: "rebase_failed", reason: `could not compare ${ontoCommit} with HEAD: ${gitTail(error)}`, git: gitTail(error), base_commit: base, head };
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const stashBefore = stashRef(cwd);
|
|
306
|
+
let stashed = false;
|
|
307
|
+
try {
|
|
308
|
+
git(cwd, ["stash", "push", "--include-untracked", "-q", "-m", "codex-supervisor: rebase"]);
|
|
309
|
+
} catch (error) {
|
|
310
|
+
return { error: "rebase_failed", reason: `could not stash the worker's uncommitted edits: ${gitTail(error)}`, git: gitTail(error), base_commit: base, head };
|
|
311
|
+
}
|
|
312
|
+
// "No local changes to save" also exits 0, so the stash ref decides.
|
|
313
|
+
stashed = stashRef(cwd) !== stashBefore;
|
|
314
|
+
|
|
315
|
+
// A pop that fails has already written the stash's untracked files back
|
|
316
|
+
// into the worktree, and reset --hard does not touch untracked files, so
|
|
317
|
+
// the next pop would stop on "already exists". Those files are the
|
|
318
|
+
// stash's third parent; they are removed before the pop that restores
|
|
319
|
+
// them for good.
|
|
320
|
+
const removeStashedUntracked = () => {
|
|
321
|
+
let paths = [];
|
|
322
|
+
try {
|
|
323
|
+
paths = lines(git(cwd, ["ls-tree", "-r", "--name-only", "refs/stash^3"]));
|
|
324
|
+
} catch {
|
|
325
|
+
return; // the stash carries no untracked files
|
|
326
|
+
}
|
|
327
|
+
for (const path of paths) rmSync(join(cwd, path), { force: true });
|
|
328
|
+
};
|
|
329
|
+
const restoreStash = () => {
|
|
330
|
+
if (!stashed) return null;
|
|
331
|
+
try {
|
|
332
|
+
removeStashedUntracked();
|
|
333
|
+
git(cwd, ["stash", "pop", "-q"]);
|
|
334
|
+
return null;
|
|
335
|
+
} catch (error) {
|
|
336
|
+
return gitTail(error);
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
try {
|
|
341
|
+
git(cwd, ["rebase", "--onto", ontoCommit, base], { timeout: 10 * 60 * 1000 });
|
|
342
|
+
} catch (error) {
|
|
343
|
+
const files = conflictFiles(cwd);
|
|
344
|
+
try {
|
|
345
|
+
git(cwd, ["rebase", "--abort"]);
|
|
346
|
+
} catch {
|
|
347
|
+
// nothing in progress to abort
|
|
348
|
+
}
|
|
349
|
+
const popError = restoreStash();
|
|
350
|
+
return {
|
|
351
|
+
error: files.length > 0 ? "rebase_conflict" : "rebase_failed",
|
|
352
|
+
reason: files.length > 0
|
|
353
|
+
? `replaying the worker's commits onto ${ontoCommit.slice(0, 12)} hit a conflict; the worktree is back as it was${popError ? " (but its stash could not be restored: run git stash pop there)" : ""}`
|
|
354
|
+
: `the rebase failed; the worktree is back as it was${popError ? " (but its stash could not be restored: run git stash pop there)" : ""}`,
|
|
355
|
+
files,
|
|
356
|
+
git: gitTail(error),
|
|
357
|
+
base_commit: base,
|
|
358
|
+
head
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
const newHead = git(cwd, ["rev-parse", "HEAD"]).trim();
|
|
362
|
+
let replayed = 0;
|
|
363
|
+
try {
|
|
364
|
+
replayed = lines(git(cwd, ["rev-list", `${ontoCommit}..HEAD`])).length;
|
|
365
|
+
} catch {
|
|
366
|
+
// reported as 0
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (stashed) {
|
|
370
|
+
try {
|
|
371
|
+
git(cwd, ["stash", "pop", "-q"]);
|
|
372
|
+
} catch (error) {
|
|
373
|
+
// The replay succeeded but the worker's uncommitted edits do not fit
|
|
374
|
+
// the new base. Back to the old base, where the same stash pops clean.
|
|
375
|
+
const files = conflictFiles(cwd);
|
|
376
|
+
const tail = gitTail(error);
|
|
377
|
+
try {
|
|
378
|
+
git(cwd, ["reset", "-q", "--hard", head]);
|
|
379
|
+
} catch {
|
|
380
|
+
// fall through; the stash is still there
|
|
381
|
+
}
|
|
382
|
+
const popError = restoreStash();
|
|
383
|
+
return {
|
|
384
|
+
error: "stash_conflict",
|
|
385
|
+
reason: `the worker's uncommitted edits conflict with ${ontoCommit.slice(0, 12)}; the worktree is back as it was${popError ? " (but its stash could not be restored: run git stash pop there)" : ""}. Commit them first (land_codex_worker with commitMessage) so the conflict is in a commit that can be resolved, or redispatch from the new commit with baseRef`,
|
|
386
|
+
files,
|
|
387
|
+
git: tail,
|
|
388
|
+
base_commit: base,
|
|
389
|
+
head
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return { ok: true, base_commit: ontoCommit, head: newHead, previous_head: head, replayed, stashed };
|
|
394
|
+
}
|
package/src/mcp-server.js
CHANGED
|
@@ -26,9 +26,11 @@ import {
|
|
|
26
26
|
upsertTask
|
|
27
27
|
} from "./task-store.js";
|
|
28
28
|
import { readNativeGoal } from "./goal-store.js";
|
|
29
|
-
import { readTaskChanges, readWorktreeDiff, worktreeRef } from "./worktree.js";
|
|
29
|
+
import { baseBehind, readTaskChanges, readWorktreeDiff, worktreeRef } from "./worktree.js";
|
|
30
|
+
import { summarizeVerification } from "./event-parser.js";
|
|
31
|
+
import { acceptanceVerdict } from "./acceptance.js";
|
|
30
32
|
import { ACTIVE_STATUSES, TERMINAL_STATUSES, TASK_STATUSES, isGoalNeedingAttention } from "./status.js";
|
|
31
|
-
import { approxTokenCount, truncateEventStrings, truncateMiddleChars } from "./truncate.js";
|
|
33
|
+
import { approxTokenCount, truncateEventStrings, truncateMiddleChars, truncateReport } from "./truncate.js";
|
|
32
34
|
import { checkForUpdate, updateNotice } from "./update-check.js";
|
|
33
35
|
import { syncSkills } from "./skill-sync.js";
|
|
34
36
|
import { maybeAutoUpdate } from "./auto-update.js";
|
|
@@ -155,10 +157,72 @@ function sleep(ms) {
|
|
|
155
157
|
function isSettled(task) {
|
|
156
158
|
if (!TERMINAL_STATUSES.has(task.status)) return false;
|
|
157
159
|
if (task.status !== "completed" && task.status !== "failed") return true;
|
|
160
|
+
// Acceptance is running in the supervisor process that owned the worker;
|
|
161
|
+
// the codex pid is already dead, so that process is what to wait on.
|
|
162
|
+
if (task.acceptance_results?.status === "running") return !isPidAlive(task.acceptance_results.supervisor_pid);
|
|
158
163
|
if (task.exit_code !== null && task.exit_code !== undefined) return true;
|
|
159
164
|
return !isPidAlive(task.pid);
|
|
160
165
|
}
|
|
161
166
|
|
|
167
|
+
// Codex emits nothing while a command runs and nothing while the model
|
|
168
|
+
// thinks, so a snapshot that has not moved for ten minutes looks the same
|
|
169
|
+
// either way. These three fields tell them apart: current_command is set
|
|
170
|
+
// from the command's item.started until its item.completed, so a long idle
|
|
171
|
+
// with a command is a long command, and a long idle without one is the model
|
|
172
|
+
// (or a stuck process, which reconcile turns into lost on its own).
|
|
173
|
+
const LIVE_COMMAND_PREVIEW_CHARS = 120;
|
|
174
|
+
function liveness(task) {
|
|
175
|
+
if (!ACTIVE_STATUSES.has(task.status)) {
|
|
176
|
+
return { idle_seconds: null, command_running: false, current_command: null };
|
|
177
|
+
}
|
|
178
|
+
const since = Date.parse(task.last_event_at ?? task.started_at ?? "");
|
|
179
|
+
const idle = Number.isFinite(since) ? Math.max(0, Math.floor((Date.now() - since) / 1000)) : null;
|
|
180
|
+
const command = task.current_command ? clip(task.current_command, LIVE_COMMAND_PREVIEW_CHARS) : null;
|
|
181
|
+
return { idle_seconds: idle, command_running: Boolean(task.current_command), current_command: command };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// The acceptance verdict as get_worker_result reports it, with the one
|
|
185
|
+
// contradiction a tool can see spelled out: checks passed, worker says
|
|
186
|
+
// otherwise (the "it was never built" case, where it was).
|
|
187
|
+
function acceptanceView(task, behind) {
|
|
188
|
+
const configured = Array.isArray(task.acceptance) && task.acceptance.length > 0;
|
|
189
|
+
const results = task.acceptance_results ?? null;
|
|
190
|
+
const view = {
|
|
191
|
+
configured,
|
|
192
|
+
commands: configured ? task.acceptance : [],
|
|
193
|
+
status: results?.status ?? null,
|
|
194
|
+
passed: results?.passed ?? null,
|
|
195
|
+
run: results?.run ?? null,
|
|
196
|
+
checks: results?.checks ?? [],
|
|
197
|
+
error: results?.error ?? null,
|
|
198
|
+
// Drift matters only before the work is landed: once it is on the
|
|
199
|
+
// branch, the branch having moved is expected.
|
|
200
|
+
stale: Boolean(results && behind && behind.behind > 0 && !(task.landed_at && task.landed_at >= (results.finished_at ?? ""))),
|
|
201
|
+
next_step: null
|
|
202
|
+
};
|
|
203
|
+
if (!configured) return view;
|
|
204
|
+
if (view.status === "failed") {
|
|
205
|
+
const failing = view.checks.find((check) => check.exit_code !== 0) ?? null;
|
|
206
|
+
view.next_step = failing
|
|
207
|
+
? `acceptance failed: ${clip(failing.command, 120)} exited ${failing.timed_out ? "by timeout" : failing.exit_code}; resume the worker with checks[].output_tail in the prompt, or fix it yourself. Do not land until it passes.`
|
|
208
|
+
: `acceptance could not run (${view.error ?? "unknown"}); fix that first`;
|
|
209
|
+
} else if (view.status === "passed") {
|
|
210
|
+
const verification = summarizeVerification(task);
|
|
211
|
+
const workerSaysNo = task.status === "failed" || isGoalNeedingAttention(task.goal_status) || verification.last_command_failed;
|
|
212
|
+
if (workerSaysNo) view.next_step = "the checks passed but the worker reports otherwise; trust the checks and read the diff";
|
|
213
|
+
else if (view.stale) view.next_step = "the checks passed on the old base and the project has moved since; resume with rebaseOnto to re-run them on current code before landing";
|
|
214
|
+
} else if (view.status === "running") {
|
|
215
|
+
view.next_step = "acceptance is still running in the supervisor; wait_codex_workers returns when it is done";
|
|
216
|
+
} else if (view.status === "interrupted") {
|
|
217
|
+
view.next_step = "the supervisor exited while running acceptance; resume the worker (or cancel and redispatch) to run it again";
|
|
218
|
+
} else if (view.status === "cancelled") {
|
|
219
|
+
view.next_step = "acceptance was cancelled; resume the worker to run it again";
|
|
220
|
+
} else if (view.status === null) {
|
|
221
|
+
view.next_step = "acceptance has not run yet for this worker";
|
|
222
|
+
}
|
|
223
|
+
return view;
|
|
224
|
+
}
|
|
225
|
+
|
|
162
226
|
function summarizeTask(task) {
|
|
163
227
|
return {
|
|
164
228
|
id: task.id,
|
|
@@ -183,7 +247,11 @@ function summarizeTask(task) {
|
|
|
183
247
|
changed_file_count: (task.changed_files ?? []).length,
|
|
184
248
|
command_count: (task.commands ?? []).length,
|
|
185
249
|
run_count: task.run_count ?? 0,
|
|
250
|
+
acceptance: acceptanceVerdict(task),
|
|
251
|
+
landed_at: task.landed_at ?? null,
|
|
186
252
|
current_action: clip(task.current_action, ACTION_PREVIEW_CHARS),
|
|
253
|
+
...liveness(task),
|
|
254
|
+
last_event_at: task.last_event_at ?? null,
|
|
187
255
|
last_event_type: task.last_event_type,
|
|
188
256
|
last_message: clip(task.last_message, 400),
|
|
189
257
|
notices: clip(task.notices, 400),
|
|
@@ -267,6 +335,9 @@ function overviewRow(task, caps) {
|
|
|
267
335
|
goal: clip(task.goal_objective, caps.goal),
|
|
268
336
|
goal_status: task.goal_status ?? null,
|
|
269
337
|
last_action: clip(task.current_action, caps.action),
|
|
338
|
+
idle_seconds: liveness(task).idle_seconds,
|
|
339
|
+
command_running: Boolean(task.current_command) && ACTIVE_STATUSES.has(task.status),
|
|
340
|
+
acceptance: acceptanceVerdict(task),
|
|
270
341
|
changed_files: (task.changed_files ?? []).length,
|
|
271
342
|
depends_on: task.depends_on ?? [],
|
|
272
343
|
owned_paths: (task.owned_paths ?? []).map((entry) => clip(entry, caps.path))
|
|
@@ -317,6 +388,10 @@ function buildOverview(tasks, extras = {}) {
|
|
|
317
388
|
needs_attention: tasks
|
|
318
389
|
.filter((task) => task.status === "running" && isGoalNeedingAttention(task.goal_status))
|
|
319
390
|
.map((task) => task.id),
|
|
391
|
+
// Terminal rows whose acceptance run failed. Kept apart from
|
|
392
|
+
// needs_attention, which means "running and stuck"; this means
|
|
393
|
+
// "finished and wrong", and the next step is a resume with the output.
|
|
394
|
+
acceptance_failed: tasks.filter((task) => task.acceptance_results?.passed === false).map((task) => task.id),
|
|
320
395
|
workers: tasks.map((task) => overviewRow(task, caps))
|
|
321
396
|
};
|
|
322
397
|
const bytes = settleTokenCount(payload);
|
|
@@ -332,6 +407,16 @@ function buildOverview(tasks, extras = {}) {
|
|
|
332
407
|
return payload;
|
|
333
408
|
}
|
|
334
409
|
|
|
410
|
+
function acceptanceLine(task) {
|
|
411
|
+
if (!Array.isArray(task.acceptance) || task.acceptance.length === 0) return "acceptance: none configured";
|
|
412
|
+
const results = task.acceptance_results;
|
|
413
|
+
if (!results) return `acceptance: ${task.acceptance.length} configured, not run yet`;
|
|
414
|
+
const ran = results.checks?.length ?? 0;
|
|
415
|
+
const ok = (results.checks ?? []).filter((check) => check.exit_code === 0).length;
|
|
416
|
+
const failing = (results.checks ?? []).find((check) => check.exit_code !== 0);
|
|
417
|
+
return `acceptance: ${results.status}, ${ok}/${task.acceptance.length} passed (${ran} ran)${failing ? `, first failure: ${clip(failing.command, 80)} exit ${failing.timed_out ? "timeout" : failing.exit_code}` : ""}`;
|
|
418
|
+
}
|
|
419
|
+
|
|
335
420
|
function buildWorkerSummary(task, nativeGoal) {
|
|
336
421
|
// Read the worktree too: a worker that edits via shell commands emits no
|
|
337
422
|
// file_change events, so the checkout is the authoritative diff.
|
|
@@ -345,6 +430,7 @@ function buildWorkerSummary(task, nativeGoal) {
|
|
|
345
430
|
: "codex goal: none recorded for this thread",
|
|
346
431
|
`changed files (${changed.length}): ${changed.slice(0, 10).join(", ") || "-"}`,
|
|
347
432
|
`last command: ${commands.at(-1)?.command ?? "-"}`,
|
|
433
|
+
acceptanceLine(task),
|
|
348
434
|
`last action: ${clip(task.current_action, ACTION_PREVIEW_CHARS) ?? "-"}`,
|
|
349
435
|
`runs: ${task.run_count ?? 0}${task.resumed_from ? `, resumed from ${task.resumed_from}` : ""}`,
|
|
350
436
|
task.error ? `error: ${task.error}` : null
|
|
@@ -380,7 +466,8 @@ function errorResult(error) {
|
|
|
380
466
|
return textResult({
|
|
381
467
|
error: error.code ?? "error",
|
|
382
468
|
message: error.message,
|
|
383
|
-
...(error.conflicts ? { conflicts: error.conflicts } : {})
|
|
469
|
+
...(error.conflicts ? { conflicts: error.conflicts } : {}),
|
|
470
|
+
...(error.details ? { files: error.details.files ?? [], git: error.details.git ?? null, base_commit: error.details.base_commit ?? null, head: error.details.head ?? null } : {})
|
|
384
471
|
});
|
|
385
472
|
}
|
|
386
473
|
|
|
@@ -389,7 +476,7 @@ server.registerTool(
|
|
|
389
476
|
{
|
|
390
477
|
title: "Create Codex worker",
|
|
391
478
|
description:
|
|
392
|
-
"Launch a Codex CLI worker with codex exec --json and track its events. ownedPaths and goal are required: ownedPaths reserves the files this worker may write, goal records what the worker is for.",
|
|
479
|
+
"Launch a Codex CLI worker with codex exec --json and track its events. ownedPaths and goal are required: ownedPaths reserves the files this worker may write (empty only for a read-only verifier), goal records what the worker is for. acceptance is the list of shell commands that decide whether the work is done: the supervisor runs them in the worker's worktree after codex exits, each must exit 0, and the worker sees them in its prompt so it can run them first. Write the check for this step (a test file, a file that must exist, an endpoint that must answer), not the whole suite; a check on another machine goes through ssh. They run with the supervisor's own privileges, as if you ran them yourself. The verdict shows as acceptance on wait, the overview and get_worker_result, and land_codex_worker refuses while it is failed.",
|
|
393
480
|
inputSchema: {
|
|
394
481
|
title: z.string().optional(),
|
|
395
482
|
task: z.string().min(1),
|
|
@@ -404,7 +491,9 @@ server.registerTool(
|
|
|
404
491
|
model: z.string().optional(),
|
|
405
492
|
reasoningEffort: z.enum(["minimal", "low", "medium", "high"]).default("high"),
|
|
406
493
|
skipGitRepoCheck: z.boolean().default(true),
|
|
407
|
-
|
|
494
|
+
// Empty only for a read-only worker (a verifier): it writes nothing,
|
|
495
|
+
// so it owns nothing.
|
|
496
|
+
ownedPaths: z.array(z.string().min(1)),
|
|
408
497
|
goal: z.object({
|
|
409
498
|
objective: z.string().min(1),
|
|
410
499
|
tokenBudget: z.number().int().positive().optional()
|
|
@@ -413,7 +502,11 @@ server.registerTool(
|
|
|
413
502
|
// Which commit the worktree is cut from. Defaults to the repository's
|
|
414
503
|
// HEAD; pass a branch, tag or sha to build on work that is not on the
|
|
415
504
|
// main line yet (for example another worker's codex/<id> branch).
|
|
416
|
-
baseRef: z.string().min(1).optional()
|
|
505
|
+
baseRef: z.string().min(1).optional(),
|
|
506
|
+
// Shell commands that decide whether the work is done. The supervisor
|
|
507
|
+
// runs them in the worktree after codex exits; each must exit 0.
|
|
508
|
+
acceptance: z.union([z.string().min(1), z.array(z.string().min(1)).max(10)]).optional(),
|
|
509
|
+
acceptanceTimeoutMs: z.number().int().min(1000).max(1800000).optional()
|
|
417
510
|
}
|
|
418
511
|
},
|
|
419
512
|
async (input) => {
|
|
@@ -455,7 +548,11 @@ server.registerTool(
|
|
|
455
548
|
tokenBudget: z.number().int().positive().optional()
|
|
456
549
|
})
|
|
457
550
|
.optional(),
|
|
458
|
-
baseRef: z.string().min(1).optional()
|
|
551
|
+
baseRef: z.string().min(1).optional(),
|
|
552
|
+
// Left out, the parent's acceptance commands are inherited; given, they
|
|
553
|
+
// replace them, and an empty list clears them.
|
|
554
|
+
acceptance: z.union([z.string().min(1), z.array(z.string().min(1)).max(10)]).optional(),
|
|
555
|
+
acceptanceTimeoutMs: z.number().int().min(1000).max(1800000).optional()
|
|
459
556
|
}
|
|
460
557
|
},
|
|
461
558
|
async ({ task_id, followup_prompt, session_id, session_title, session_note, ...options }) => {
|
|
@@ -480,16 +577,20 @@ server.registerTool(
|
|
|
480
577
|
{
|
|
481
578
|
title: "Resume Codex worker",
|
|
482
579
|
description:
|
|
483
|
-
"Continue the SAME Codex session for an existing worker via `codex exec resume <thread_id>`. Works from a different MCP process or a fresh client session as long as the task recorded a thread_id.",
|
|
580
|
+
"Continue the SAME Codex session for an existing worker via `codex exec resume <thread_id>`. Works from a different MCP process or a fresh client session as long as the task recorded a thread_id. The worktree stays on the commit it was cut from unless rebaseOnto names a ref (resolved in the project directory, e.g. HEAD or main): uncommitted edits are stashed, the worker's own commits are replayed onto it, the stash comes back and base_commit moves, so the worker continues on current code. A conflict in either step puts the worktree back as it was, lists the files and does not start the worker. The receipt carries base_behind: how many commits the project's HEAD is past the worktree's base. acceptance replaces the worker's acceptance commands when the ones given at dispatch were wrong; the supervisor runs them again after this run.",
|
|
484
581
|
inputSchema: {
|
|
485
582
|
task_id: z.string().min(1),
|
|
486
|
-
prompt: z.string().min(1)
|
|
583
|
+
prompt: z.string().min(1),
|
|
584
|
+
rebaseOnto: z.string().min(1).optional(),
|
|
585
|
+
// Replaces the stored acceptance commands for this and later runs; an
|
|
586
|
+
// empty list clears them. Left out, the stored commands stay.
|
|
587
|
+
acceptance: z.union([z.string().min(1), z.array(z.string().min(1)).max(10)]).optional()
|
|
487
588
|
}
|
|
488
589
|
},
|
|
489
|
-
async ({ task_id, prompt }) => {
|
|
590
|
+
async ({ task_id, prompt, rebaseOnto, acceptance }) => {
|
|
490
591
|
try {
|
|
491
|
-
const record = await resumeCodexWorker({ taskId: task_id, prompt });
|
|
492
|
-
return textResult(receipt(record));
|
|
592
|
+
const record = await resumeCodexWorker({ taskId: task_id, prompt, rebaseOnto: rebaseOnto ?? null, acceptance });
|
|
593
|
+
return textResult({ ...receipt(record), rebase: record.rebase ?? null, base_behind: baseBehind(record.project_root, record.base_commit) });
|
|
493
594
|
} catch (error) {
|
|
494
595
|
return errorResult(error);
|
|
495
596
|
}
|
|
@@ -550,7 +651,7 @@ server.registerTool(
|
|
|
550
651
|
{
|
|
551
652
|
title: "Wait for Codex workers",
|
|
552
653
|
description:
|
|
553
|
-
"Block until selected Codex workers reach a terminal status, then return summaries. The wait budget bounds this call, not the workers: when it runs out you get a progress snapshot and the workers keep running, so call this again with the same task_ids to keep waiting. Keep the budget under your client's MCP tool timeout, or the client kills the call instead of the wait returning.",
|
|
654
|
+
"Block until selected Codex workers reach a terminal status, then return summaries. The wait budget bounds this call, not the workers: when it runs out you get a progress snapshot and the workers keep running, so call this again with the same task_ids to keep waiting. Keep the budget under your client's MCP tool timeout, or the client kills the call instead of the wait returning. compact: true returns one line per worker: status, phase, exit_code, changed_file_count, acceptance (passed / failed / null when none was configured or it did not run), plus idle_seconds since the last Codex event of this run, command_running and current_command. Codex emits nothing while a command runs or while the model thinks, so a long idle with command_running: true is a long command and a long idle without it is thinking (or a process that reconcile will report as lost).",
|
|
554
655
|
inputSchema: {
|
|
555
656
|
task_ids: z.array(z.string().min(1)).min(1),
|
|
556
657
|
mode: z.enum(["any", "all"]).default("all"),
|
|
@@ -639,6 +740,7 @@ server.registerTool(
|
|
|
639
740
|
cancelled_count: tasks.filter((task) => task.status === "cancelled").length,
|
|
640
741
|
lost_count: tasks.filter((task) => task.status === "lost").length,
|
|
641
742
|
active_count: tasks.filter((task) => ACTIVE_STATUSES.has(task.status)).length,
|
|
743
|
+
acceptance_failed_count: tasks.filter((task) => task.acceptance_results?.passed === false).length,
|
|
642
744
|
workers: compact
|
|
643
745
|
? tasks.map((task) => ({
|
|
644
746
|
id: task.id,
|
|
@@ -647,6 +749,8 @@ server.registerTool(
|
|
|
647
749
|
phase: task.phase ?? null,
|
|
648
750
|
exit_code: task.exit_code ?? null,
|
|
649
751
|
changed_file_count: readTaskChanges(task).length,
|
|
752
|
+
acceptance: acceptanceVerdict(task),
|
|
753
|
+
...liveness(task),
|
|
650
754
|
updated_at: task.updated_at ?? null
|
|
651
755
|
}))
|
|
652
756
|
: summaries
|
|
@@ -834,14 +938,16 @@ server.registerTool(
|
|
|
834
938
|
{
|
|
835
939
|
title: "Get worker result",
|
|
836
940
|
description:
|
|
837
|
-
"Read a worker's own final report
|
|
941
|
+
"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.",
|
|
838
942
|
inputSchema: {
|
|
839
943
|
task_id: z.string().min(1),
|
|
840
944
|
limit: z.number().int().min(1).max(20).default(1),
|
|
841
|
-
|
|
945
|
+
// Per report, UTF-8 bytes. 0 means no clipping.
|
|
946
|
+
maxChars: z.number().int().min(0).max(1000000).default(6000),
|
|
947
|
+
includeFiles: z.boolean().default(false)
|
|
842
948
|
}
|
|
843
949
|
},
|
|
844
|
-
async ({ task_id, limit, maxChars }) => {
|
|
950
|
+
async ({ task_id, limit, maxChars, includeFiles }) => {
|
|
845
951
|
const task = await getTask(task_id);
|
|
846
952
|
if (!task) return textResult({ error: "task_not_found", task_id });
|
|
847
953
|
let reports = await readAgentMessages(task_id, limit);
|
|
@@ -852,8 +958,14 @@ server.registerTool(
|
|
|
852
958
|
reports = [task.last_message];
|
|
853
959
|
source = "task_row";
|
|
854
960
|
}
|
|
855
|
-
const
|
|
961
|
+
const reportBytes = reports.map((text) => Buffer.byteLength(text, "utf8"));
|
|
962
|
+
const clipped = maxChars === 0 ? reports : reports.map((text) => truncateReport(text, maxChars));
|
|
963
|
+
const truncated = clipped.some((text, index) => text !== reports[index]);
|
|
856
964
|
const changed = readTaskChanges(task);
|
|
965
|
+
const behind = task.worktree_path ? baseBehind(task.project_root, task.base_commit) : null;
|
|
966
|
+
// A worker that ran in place has no worktree to diff, so this list is
|
|
967
|
+
// the only record of what it touched; it is never hidden for those.
|
|
968
|
+
const listFiles = includeFiles || !task.worktree_path;
|
|
857
969
|
return textResult({
|
|
858
970
|
task_id,
|
|
859
971
|
title: task.title,
|
|
@@ -864,9 +976,20 @@ server.registerTool(
|
|
|
864
976
|
session_id: task.session_id ?? null,
|
|
865
977
|
worktree_path: task.worktree_path,
|
|
866
978
|
goal_status: task.goal_status,
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
979
|
+
changed_file_count: changed.length,
|
|
980
|
+
changed_files: listFiles ? changed : undefined,
|
|
981
|
+
base_commit: task.base_commit ?? null,
|
|
982
|
+
base_behind: behind,
|
|
983
|
+
landed: task.landed_at ? { at: task.landed_at, head: task.landed_head ?? null } : null,
|
|
984
|
+
acceptance: acceptanceView(task, behind),
|
|
985
|
+
verification: summarizeVerification(task),
|
|
986
|
+
report_count: clipped.length,
|
|
987
|
+
report_bytes: reportBytes,
|
|
988
|
+
truncated,
|
|
989
|
+
next_step: truncated
|
|
990
|
+
? `a report was clipped to ${maxChars} bytes; call again with maxChars: ${Math.max(...reportBytes)} (or 0) to read it whole`
|
|
991
|
+
: null,
|
|
992
|
+
reports: clipped,
|
|
870
993
|
source,
|
|
871
994
|
error: task.error ?? null,
|
|
872
995
|
completed_at: task.completed_at ?? null
|
|
@@ -890,7 +1013,7 @@ server.registerTool(
|
|
|
890
1013
|
const task = await getTask(task_id);
|
|
891
1014
|
if (!task) return textResult({ error: "task_not_found", task_id });
|
|
892
1015
|
if (!task.worktree_path) {
|
|
893
|
-
return textResult({ error: "no_worktree", task_id, 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;
|
|
1016
|
+
return textResult({ error: "no_worktree", task_id, 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" });
|
|
894
1017
|
}
|
|
895
1018
|
const diff = readWorktreeDiff(task.worktree_path, worktreeRef(task), { maxChars, paths: paths ?? [] });
|
|
896
1019
|
return textResult({
|
|
@@ -953,17 +1076,25 @@ server.registerTool(
|
|
|
953
1076
|
{
|
|
954
1077
|
title: "Land a worker's commits",
|
|
955
1078
|
description:
|
|
956
|
-
"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. Check the work first with get_worker_result and get_worker_diff; land once it passes.",
|
|
1079
|
+
"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. Check the work first with get_worker_result and get_worker_diff; land once it passes. 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.",
|
|
957
1080
|
inputSchema: {
|
|
958
1081
|
task_id: z.string().min(1),
|
|
959
1082
|
onto: z.string().min(1).optional(),
|
|
960
|
-
commitMessage: z.string().min(1).optional()
|
|
1083
|
+
commitMessage: z.string().min(1).optional(),
|
|
1084
|
+
ignoreAcceptance: z.boolean().default(false)
|
|
961
1085
|
}
|
|
962
1086
|
},
|
|
963
|
-
async ({ task_id, onto, commitMessage }) => {
|
|
1087
|
+
async ({ task_id, onto, commitMessage, ignoreAcceptance }) => {
|
|
964
1088
|
const task = await getTask(task_id);
|
|
965
1089
|
if (!task) return textResult({ error: "task_not_found", task_id });
|
|
966
|
-
|
|
1090
|
+
const outcome = landWorker(task, { onto, commitMessage: commitMessage ?? null, ignoreAcceptance });
|
|
1091
|
+
if (!outcome.error) {
|
|
1092
|
+
// Recorded so a later read knows the work is on the branch: the
|
|
1093
|
+
// board shows it, and base_behind after this is not drift.
|
|
1094
|
+
const now = new Date().toISOString();
|
|
1095
|
+
await upsertTask({ ...task, landed_at: now, landed_head: outcome.head ?? null, updated_at: now });
|
|
1096
|
+
}
|
|
1097
|
+
return textResult({ task_id, title: task.title, status: task.status, branch: `codex/${task.id}`, ...outcome });
|
|
967
1098
|
}
|
|
968
1099
|
);
|
|
969
1100
|
|
|
@@ -986,7 +1117,9 @@ server.registerTool(
|
|
|
986
1117
|
await upsertTask({ ...task, cancel_requested_at: now, updated_at: now });
|
|
987
1118
|
}
|
|
988
1119
|
const result = await cancelCodexWorker(task_id);
|
|
989
|
-
|
|
1120
|
+
// A cancel that stopped an acceptance run leaves the worker's own
|
|
1121
|
+
// terminal status in place; the exit handler records the verdict.
|
|
1122
|
+
if (result.cancelled && task && result.via !== "acceptance") {
|
|
990
1123
|
await upsertTask({
|
|
991
1124
|
...task,
|
|
992
1125
|
status: "cancelled",
|