codex-supervisor-mcp 0.13.3 → 0.13.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +101 -295
- package/README.md +99 -308
- package/package.json +7 -1
- package/skills/codex-supervisor/SKILL.md +3 -1
- package/src/auto-update.js +0 -1
- package/src/cleanup-plan.js +2 -2
- package/src/codex-runner.js +1 -1
- package/src/landing.js +1 -1
- package/src/mcp-server.js +10 -5
- package/src/prompt.js +4 -1
- package/src/setup.js +2 -2
- package/src/side-chat.js +0 -1
- package/src/task-store.js +1 -1
- package/src/worker-changes.js +21 -1
- package/src/worktree.js +2 -2
package/src/cleanup-plan.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
-
import { lstat, realpath
|
|
2
|
+
import { lstat, realpath } from "node:fs/promises";
|
|
3
3
|
import { execFileSync } from "node:child_process";
|
|
4
|
-
import {
|
|
4
|
+
import { resolve } from "node:path";
|
|
5
5
|
import { ACTIVE_STATUSES } from "./status.js";
|
|
6
6
|
import { worktreesDir } from "./paths.js";
|
|
7
7
|
import { appendTaskEvent, getTask, isPidAlive, markCleanupPlanItemApplied, readTasks, updateWorkItemDelivery, runIdFor } from "./task-store.js";
|
package/src/codex-runner.js
CHANGED
|
@@ -263,7 +263,7 @@ async function withWorktreeCreationLock(cwd, work) {
|
|
|
263
263
|
await mkdir(lockPath);
|
|
264
264
|
break;
|
|
265
265
|
} catch (error) {
|
|
266
|
-
if (error.code !== "EEXIST" || Date.now() >= deadline) throw new Error(`worktree creation lock timed out for ${cwd}
|
|
266
|
+
if (error.code !== "EEXIST" || Date.now() >= deadline) throw new Error(`worktree creation lock timed out for ${cwd}`, { cause: error });
|
|
267
267
|
await sleep(100);
|
|
268
268
|
}
|
|
269
269
|
}
|
package/src/landing.js
CHANGED
|
@@ -427,7 +427,7 @@ export function rebaseWorktree(task, ontoCommit) {
|
|
|
427
427
|
// stash's third parent; they are removed before the pop that restores
|
|
428
428
|
// them for good.
|
|
429
429
|
const removeStashedUntracked = () => {
|
|
430
|
-
let paths
|
|
430
|
+
let paths;
|
|
431
431
|
try {
|
|
432
432
|
paths = lines(git(cwd, ["ls-tree", "-r", "--name-only", "refs/stash^3"]));
|
|
433
433
|
} catch {
|
package/src/mcp-server.js
CHANGED
|
@@ -765,7 +765,7 @@ server.registerTool(
|
|
|
765
765
|
);
|
|
766
766
|
server.registerTool("check_workers", {
|
|
767
767
|
title: "Check changed workers",
|
|
768
|
-
description: "Check newly settled runs and
|
|
768
|
+
description: "Check newly settled runs, actionable failures and active threads crossing the handoff threshold; automatically resume a dead lost/no_work first run once, except approval, authentication, permission and quota waits. Handoff reminders occur once per run and never cancel, replace or resume a live worker. Unchanged state is quiet. Call from a host-scheduled loop; it cannot wake a closed host. Set a distinct CODEX_SUPERVISOR_OBSERVER_ID per main thread to retain its cursor across restarts.",
|
|
769
769
|
inputSchema: {}
|
|
770
770
|
}, async () => {
|
|
771
771
|
const read = observerRead.then(async () => {
|
|
@@ -1090,12 +1090,13 @@ server.registerTool(
|
|
|
1090
1090
|
{
|
|
1091
1091
|
title: "Wait for Codex workers",
|
|
1092
1092
|
description:
|
|
1093
|
-
"Block until selected Codex workers reach a terminal status, then return summaries.
|
|
1093
|
+
"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.",
|
|
1094
1094
|
inputSchema: {
|
|
1095
1095
|
task_ids: z.array(z.string().min(1)).min(1),
|
|
1096
1096
|
mode: z.enum(["any", "all"]).default("all"),
|
|
1097
1097
|
timeoutMinutes: z.number().int().min(1).max(360).default(1),
|
|
1098
1098
|
timeoutMs: z.number().int().min(1000).max(21600000).optional(),
|
|
1099
|
+
allowLongWait: z.boolean().default(false),
|
|
1099
1100
|
pollMs: z.number().int().min(250).max(10000).default(1000),
|
|
1100
1101
|
emitProgress: z.boolean().default(false),
|
|
1101
1102
|
// Off by default. A wait is the call clients background and then replay
|
|
@@ -1121,6 +1122,7 @@ server.registerTool(
|
|
|
1121
1122
|
mode,
|
|
1122
1123
|
timeoutMinutes,
|
|
1123
1124
|
timeoutMs,
|
|
1125
|
+
allowLongWait,
|
|
1124
1126
|
pollMs,
|
|
1125
1127
|
emitProgress,
|
|
1126
1128
|
includeEvents,
|
|
@@ -1131,7 +1133,8 @@ server.registerTool(
|
|
|
1131
1133
|
}, extra) => {
|
|
1132
1134
|
const compact = requestedCompact ?? !includeEvents;
|
|
1133
1135
|
const startedAt = Date.now();
|
|
1134
|
-
const
|
|
1136
|
+
const requestedTimeoutMs = timeoutMs ?? timeoutMinutes * 60 * 1000;
|
|
1137
|
+
const effectiveTimeoutMs = allowLongWait ? requestedTimeoutMs : Math.min(requestedTimeoutMs, 60000);
|
|
1135
1138
|
let tasks = [];
|
|
1136
1139
|
const progressToken = extra?._meta?.progressToken;
|
|
1137
1140
|
let lastProgressAt = -Infinity;
|
|
@@ -1152,7 +1155,7 @@ server.registerTool(
|
|
|
1152
1155
|
} }).catch(() => {});
|
|
1153
1156
|
lastProgressAt = elapsed;
|
|
1154
1157
|
}
|
|
1155
|
-
await sleep(pollMs);
|
|
1158
|
+
await sleep(Math.min(pollMs, Math.max(0, effectiveTimeoutMs - (Date.now() - startedAt))));
|
|
1156
1159
|
}
|
|
1157
1160
|
|
|
1158
1161
|
await reconcileDetachedActiveTasks();
|
|
@@ -1184,10 +1187,12 @@ server.registerTool(
|
|
|
1184
1187
|
still_running: timedOut,
|
|
1185
1188
|
termination_reason: clientCancelled ? "client_cancelled" : timedOut ? "budget_exhausted" : "settled",
|
|
1186
1189
|
next_step: timedOut
|
|
1187
|
-
? `Workers are still running; the ${budgetLabel} wait budget ran out
|
|
1190
|
+
? `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.`
|
|
1188
1191
|
: null,
|
|
1189
1192
|
waited_ms: Date.now() - startedAt,
|
|
1190
1193
|
timeout_ms: effectiveTimeoutMs,
|
|
1194
|
+
requested_timeout_ms: requestedTimeoutMs,
|
|
1195
|
+
timeout_capped: effectiveTimeoutMs !== requestedTimeoutMs,
|
|
1191
1196
|
timeout_minutes: Math.round(effectiveTimeoutMs / 60000),
|
|
1192
1197
|
missing_ids: missingIds,
|
|
1193
1198
|
completed_count: tasks.filter((task) => task.status === "completed").length,
|
package/src/prompt.js
CHANGED
|
@@ -82,7 +82,10 @@ export function buildGuardPreamble({ sandbox, ownedPaths = [], allowedCommands =
|
|
|
82
82
|
// shell as a heredoc; the guard accepts that shape too, so the worker is told
|
|
83
83
|
// about it instead of stalling on a tool it does not have.
|
|
84
84
|
const shellEdit = "If your toolset has no apply_patch tool, run it through the shell as apply_patch <<'EOF' ... EOF; the guard checks the file paths the same way. A declared command ending in * is a prefix, so go test ./internal/* covers go test ./internal/service -run TestX.";
|
|
85
|
-
|
|
85
|
+
const delivery = sandbox === "workspace-write" && (!workspaceKind || workspaceKind === "git_worktree")
|
|
86
|
+
? "Do not run git add, git commit or git commit --amend: the dispatcher commits reviewed edits with land_codex_worker({commitMessage}). Leave your edits uncommitted; clean status and commit-count checks belong after landing. If the task or acceptance requires a self-commit or a clean edited worktree, report the contract conflict instead of bypassing the guard."
|
|
87
|
+
: "";
|
|
88
|
+
return `Runtime supervisor guard: edits must use apply_patch within ${JSON.stringify(ownedPaths)}. ${shellEdit} ${delivery} Safe read-only inspection commands (rg, cat, sed without -i, git status/diff/log, jq without -i, find without -exec/-delete) are allowed and never reserve another worker's paths. Commands that validate, write, execute code or have side effects must exactly match declared commands ${JSON.stringify(allowedCommands)}. Forbidden: ${forbidden}. Undeclared shell programs are denied; report a needed validation command instead of bypassing the guard. ${stage}`;
|
|
86
89
|
}
|
|
87
90
|
|
|
88
91
|
// The acceptance commands are shown to the worker. Hiding them would not
|
package/src/setup.js
CHANGED
|
@@ -132,7 +132,7 @@ function versionManagerBinDirs() {
|
|
|
132
132
|
const dirs = [];
|
|
133
133
|
for (const [root, suffix] of VERSION_MANAGER_ROOTS) {
|
|
134
134
|
if (!existsSync(root)) continue;
|
|
135
|
-
let entries
|
|
135
|
+
let entries;
|
|
136
136
|
try {
|
|
137
137
|
entries = readdirSync(root);
|
|
138
138
|
} catch {
|
|
@@ -188,7 +188,7 @@ async function registeredMcp(target, client) {
|
|
|
188
188
|
} catch (error) {
|
|
189
189
|
const message = `${error.stdout ?? ""}${error.stderr ?? ""}${error.message}`;
|
|
190
190
|
if (/not found|no mcp server|could not find|does not exist/i.test(message)) return null;
|
|
191
|
-
throw new Error(`cannot read ${client.label} MCP registration: ${error.message.split("\n")[0]}
|
|
191
|
+
throw new Error(`cannot read ${client.label} MCP registration: ${error.message.split("\n")[0]}`, { cause: error });
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
|
package/src/side-chat.js
CHANGED
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
// turn failed / timed out / stopped error on the turn, session still usable
|
|
23
23
|
// board restarted mid-turn ........ turn marked interrupted
|
|
24
24
|
// session ended ................... fork deleted, history cleared
|
|
25
|
-
import { execFileSync, spawn } from "node:child_process";
|
|
26
25
|
import { randomUUID } from "node:crypto";
|
|
27
26
|
import { codexConfigText, disableMcpServerArgs } from "./mcp-config.js";
|
|
28
27
|
import { codexRunner } from "./runner-adapter.js";
|
package/src/task-store.js
CHANGED
|
@@ -1741,7 +1741,7 @@ export async function readAgentMessages(taskId, limit = 1) {
|
|
|
1741
1741
|
`).all(taskId, limit * 5 + 10);
|
|
1742
1742
|
const messages = [];
|
|
1743
1743
|
for (const row of rows) {
|
|
1744
|
-
let text
|
|
1744
|
+
let text;
|
|
1745
1745
|
try {
|
|
1746
1746
|
text = extractAgentMessage(JSON.parse(row.payload));
|
|
1747
1747
|
} catch {
|
package/src/worker-changes.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { TERMINAL_STATUSES, isGoalNeedingAttention } from "./status.js";
|
|
1
|
+
import { ACTIVE_STATUSES, TERMINAL_STATUSES, isGoalNeedingAttention } from "./status.js";
|
|
2
|
+
import { threadHealth } from "./thread-health.js";
|
|
2
3
|
|
|
3
4
|
// Cursors belong to observers, not workers. A resumed run gets a new receipt;
|
|
4
5
|
// old acceptance cannot produce a current-run completion or failure notice.
|
|
@@ -8,6 +9,25 @@ export function collectWorkerChanges(tasks, cursor = {}) {
|
|
|
8
9
|
const attention = [];
|
|
9
10
|
for (const task of tasks) {
|
|
10
11
|
const acceptance = task.acceptance_results?.run === task.run_count ? task.acceptance_results : null;
|
|
12
|
+
const health = threadHealth(task);
|
|
13
|
+
const healthKey = `${task.id}:thread_health`;
|
|
14
|
+
if (cursor[healthKey]) next[healthKey] = cursor[healthKey];
|
|
15
|
+
if (ACTIVE_STATUSES.has(task.status) && health.state === "handoff_recommended") {
|
|
16
|
+
const healthFingerprint = JSON.stringify([task.run_count, health.state]);
|
|
17
|
+
next[healthKey] = healthFingerprint;
|
|
18
|
+
if (cursor[healthKey] !== healthFingerprint) {
|
|
19
|
+
const receipt = {
|
|
20
|
+
id: task.id, title: task.title ?? task.id, run: task.run_count, status: task.status,
|
|
21
|
+
reason: "handoff_recommended", tokens_used: health.tokens_used, threshold: health.threshold,
|
|
22
|
+
next_step: {
|
|
23
|
+
tool: "get_codex_worker_status", arguments: { task_id: task.id },
|
|
24
|
+
instruction: "Inspect the live command and stage. Let this bounded step settle or explicitly cancel it before preparing a reviewed checkpoint and a fresh follow-up; do not launch a duplicate while it is active."
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
transitions.push(receipt);
|
|
28
|
+
attention.push(receipt);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
11
31
|
let reason = null;
|
|
12
32
|
if (isGoalNeedingAttention(task.goal_status)) reason = `goal_${task.goal_status}`;
|
|
13
33
|
else if (task.attention_reason) reason = task.attention_reason;
|
package/src/worktree.js
CHANGED
|
@@ -184,7 +184,7 @@ export function readWorktreeDiff(worktreePath, { baseCommit = null, branch = nul
|
|
|
184
184
|
truncatedFiles += 1;
|
|
185
185
|
continue;
|
|
186
186
|
}
|
|
187
|
-
let patch
|
|
187
|
+
let patch;
|
|
188
188
|
try {
|
|
189
189
|
if (file.status === "untracked") {
|
|
190
190
|
const text = readFileSync(join(worktreePath, file.path), "utf8");
|
|
@@ -295,7 +295,7 @@ export function snapshotTaskOutput(task) {
|
|
|
295
295
|
// base is not in; every git error is reported as null, never as 0.
|
|
296
296
|
export function baseBehind(projectRoot, baseCommit) {
|
|
297
297
|
if (!projectRoot || !baseCommit || !existsSync(projectRoot)) return { behind: null, contains_base: null, ref: null };
|
|
298
|
-
let ref
|
|
298
|
+
let ref;
|
|
299
299
|
try {
|
|
300
300
|
ref = git(projectRoot, ["symbolic-ref", "--short", "-q", "HEAD"]).trim() || "HEAD";
|
|
301
301
|
} catch {
|