codex-supervisor-mcp 0.14.0 → 1.0.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 +34 -45
- package/README.md +34 -45
- package/package.json +1 -1
- package/skills/codex-supervisor/SKILL.md +86 -90
- package/src/app/acceptance.js +5 -5
- package/src/app/auto-cleanup.js +6 -5
- package/src/app/cleanup-facts.js +7 -4
- package/src/app/cleanup-plan.js +3 -2
- package/src/app/context-compiler.js +2 -1
- package/src/app/dispatch.js +17 -15
- package/src/app/followup.js +5 -4
- package/src/app/land-chain.js +5 -4
- package/src/app/landing.js +8 -8
- package/src/app/ownership.js +1 -1
- package/src/app/rebase.js +1 -1
- package/src/app/restore-worktree.js +2 -1
- package/src/app/resume.js +6 -5
- package/src/app/worktree-setup.js +15 -14
- package/src/domain/acceptance-spec.js +1 -1
- package/src/domain/failure-class.js +2 -2
- package/src/domain/prompt.js +7 -7
- package/src/domain/status.js +9 -0
- package/src/domain/thread-health.js +2 -2
- package/src/domain/worker-branch.js +6 -0
- package/src/domain/worker-changes.js +3 -3
- package/src/infra/cleanup-hint.js +1 -1
- package/src/infra/external-output.js +2 -2
- package/src/infra/sandbox-roots.js +1 -1
- package/src/infra/store/events.js +2 -1
- package/src/infra/store/reconcile.js +4 -3
- package/src/infra/store/tasks.js +1 -1
- package/src/infra/update/auto-update-worker.js +3 -3
- package/src/infra/update/auto-update.js +4 -4
- package/src/infra/update/update-check.js +3 -3
- package/src/infra/workspace-kind.js +8 -8
- package/src/infra/worktree.js +4 -3
- package/src/interface/bin/acceptance-cli.js +4 -4
- package/src/interface/bin/monitor.jsx +6 -6
- package/src/interface/bin/setup.js +3 -3
- package/src/interface/bin/stage.js +2 -2
- package/src/interface/mcp/{tools → handlers}/delivery.js +30 -62
- package/src/interface/mcp/handlers/dispatch.js +233 -0
- package/src/interface/mcp/{tools → handlers}/facts.js +30 -65
- package/src/interface/mcp/handlers/overview.js +103 -0
- package/src/interface/mcp/{tools → handlers}/results.js +31 -60
- package/src/interface/mcp/{tools → handlers}/review.js +16 -36
- package/src/interface/mcp/{tools → handlers}/wait.js +8 -14
- package/src/interface/mcp/server.js +18 -51
- package/src/interface/mcp/tools/deliver.js +48 -0
- package/src/interface/mcp/tools/dispatch.js +78 -257
- package/src/interface/mcp/tools/optional.js +57 -0
- package/src/interface/mcp/tools/read.js +115 -0
- package/src/interface/mcp/tools/run.js +57 -0
- package/src/interface/mcp/tools/shapes.js +66 -0
- package/src/interface/mcp/tools/track.js +84 -0
- package/src/interface/mcp/views/task.js +8 -7
- package/src/interface/web/views.js +2 -1
- package/src/run-host/launch.js +7 -7
- package/src/runners/codex/tool-guard.js +6 -6
- package/src/domain/overview-delta.js +0 -77
- package/src/interface/mcp/tools/overview.js +0 -202
- package/src/interface/mcp/tools/poll.js +0 -58
package/src/domain/prompt.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// its goal.
|
|
10
10
|
//
|
|
11
11
|
// Report format, at the end. A worker's last message is what the supervisor
|
|
12
|
-
// reads back through
|
|
12
|
+
// reads back through get_worker (include result). Left to itself a worker narrates
|
|
13
13
|
// the whole run and lists every file it touched, and one real report ran to
|
|
14
14
|
// four thousand tokens with the conclusion buried in the middle. The format
|
|
15
15
|
// asks for the three things a reviewer checks and nothing else: the result,
|
|
@@ -51,11 +51,11 @@ export const REPORT_SECTIONS = ["Result", "Verification", "Not done / risks"];
|
|
|
51
51
|
|
|
52
52
|
// The first thing a worker reads, and the only place the run's write boundary
|
|
53
53
|
// is stated. A worker is not always an editor: a read-only one can only read,
|
|
54
|
-
// and one with no
|
|
54
|
+
// and one with no owned_paths lands nothing, so both are told what their shell
|
|
55
55
|
// may do instead of being told to use apply_patch they cannot use.
|
|
56
56
|
export function buildGuardPreamble({ sandbox, ownedPaths = [], allowedCommands = [], forbid = [], networkAccess = false, workspaceKind = null } = {}) {
|
|
57
57
|
const forbidden = JSON.stringify(forbid);
|
|
58
|
-
const stage = 'For a long gate, checkpoint phases with node "$
|
|
58
|
+
const stage = 'For a long gate, checkpoint phases with node "$AGENT_SUPERVISOR_STAGE_CLI" "gate:s3" --detail "current check"; stage text is visible to status/overview/wait and must not contain secrets.';
|
|
59
59
|
if (sandbox === "read-only") {
|
|
60
60
|
return [
|
|
61
61
|
"Runtime supervisor guard: this is a read-only task.",
|
|
@@ -70,7 +70,7 @@ export function buildGuardPreamble({ sandbox, ownedPaths = [], allowedCommands =
|
|
|
70
70
|
? "Its execution directory is a supervisor-managed scratch directory, not the user's source directory"
|
|
71
71
|
: "Its worktree is a scratch copy";
|
|
72
72
|
return [
|
|
73
|
-
"Runtime supervisor guard: this worker lands nothing: no
|
|
73
|
+
"Runtime supervisor guard: this worker lands nothing: no owned_paths means nothing it writes is ever merged into the project.",
|
|
74
74
|
`${location}, so the shell is unrestricted apart from the red lines; keep notes and downloads inside it.`,
|
|
75
75
|
networkAccess ? "Network is available." : "There is no network in this sandbox; ask for it instead of retrying a failing fetch.",
|
|
76
76
|
`Forbidden: ${forbidden}.`,
|
|
@@ -83,7 +83,7 @@ export function buildGuardPreamble({ sandbox, ownedPaths = [], allowedCommands =
|
|
|
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
|
|
86
|
+
? "Do not run git add, git commit or git commit --amend: the dispatcher commits reviewed edits with land_worker({commit_message}). 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
87
|
: "";
|
|
88
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}`;
|
|
89
89
|
}
|
|
@@ -96,7 +96,7 @@ export function buildGuardPreamble({ sandbox, ownedPaths = [], allowedCommands =
|
|
|
96
96
|
export function buildAcceptanceBlock(acceptance, { resume = false } = {}) {
|
|
97
97
|
const commands = Array.isArray(acceptance) ? acceptance.filter(Boolean) : [];
|
|
98
98
|
if (commands.length === 0) return "";
|
|
99
|
-
const runner = 'Run node "$
|
|
99
|
+
const runner = 'Run node "$AGENT_SUPERVISOR_ACCEPTANCE_CLI" to execute this exact contract through the supervisor\'s non-interactive Bash with errexit and pipefail. Do not retype the commands in zsh; the interactive shell is not the acceptance shell.';
|
|
100
100
|
if (resume) {
|
|
101
101
|
return ["Acceptance is unchanged.", runner, `Commands: ${commands.map((check) => typeof check === "string" ? check : JSON.stringify(check)).join(" ; ")}`].join("\n");
|
|
102
102
|
}
|
|
@@ -145,7 +145,7 @@ export function frameWorkerPrompt(prompt, goalOptions, { acceptance = null, outp
|
|
|
145
145
|
export function buildHostGoalSync(session) {
|
|
146
146
|
const id = JSON.stringify(String(session.id));
|
|
147
147
|
const condition = [
|
|
148
|
-
`For supervisor session ${id}, read
|
|
148
|
+
`For supervisor session ${id}, read find_works and use its current objective, default_acceptance, approval_state and policy_revision (at least ${session.policy_revision ?? 0}).`,
|
|
149
149
|
"Use the latest explicit human instruction and approved failure baseline; superseded goals and checks must not be revived.",
|
|
150
150
|
"Stop when the current approved objective is verified and all required worker results are collected, checked and integrated as requested.",
|
|
151
151
|
"If approval_state is waiting_user, stop after clearly reporting the blocker, attempted checks, options and recommendation and asking for the required decision; do not auto-resume or repeat unchanged waiting reports.",
|
package/src/domain/status.js
CHANGED
|
@@ -35,3 +35,12 @@ export function isGoalNeedingAttention(nativeStatus) {
|
|
|
35
35
|
const key = String(nativeStatus ?? "").replace(/_/g, "").toLowerCase();
|
|
36
36
|
return ["blocked", "paused", "usagelimited", "budgetlimited"].includes(key);
|
|
37
37
|
}
|
|
38
|
+
|
|
39
|
+
// True once nothing of a worker's last run can still be running: its exit
|
|
40
|
+
// code is recorded (the last thing a run host writes), or the row was marked
|
|
41
|
+
// lost (done only after both processes were seen gone). From then on the pids
|
|
42
|
+
// on the row are history. The system hands them to other processes, on
|
|
43
|
+
// Windows within seconds, and a live stranger must not read as a live worker.
|
|
44
|
+
export function runIsOver(task) {
|
|
45
|
+
return task.status === "lost" || (TERMINAL_STATUSES.has(task.status) && task.exit_code != null);
|
|
46
|
+
}
|
|
@@ -2,7 +2,7 @@ const DEFAULT_HANDOFF_TOKEN_THRESHOLD = 300000;
|
|
|
2
2
|
const LONG_THREAD_RATIO = 0.75;
|
|
3
3
|
|
|
4
4
|
export function handoffTokenThreshold(env = process.env) {
|
|
5
|
-
const raw = env.
|
|
5
|
+
const raw = env.AGENT_SUPERVISOR_HANDOFF_TOKEN_THRESHOLD;
|
|
6
6
|
if (raw == null || raw === "") return DEFAULT_HANDOFF_TOKEN_THRESHOLD;
|
|
7
7
|
const value = Number(raw);
|
|
8
8
|
if (!Number.isFinite(value) || value < 0) return DEFAULT_HANDOFF_TOKEN_THRESHOLD;
|
|
@@ -18,7 +18,7 @@ export function threadHealth(task, { threshold = handoffTokenThreshold() } = {})
|
|
|
18
18
|
state: "handoff_recommended",
|
|
19
19
|
threshold,
|
|
20
20
|
tokens_used: tokens,
|
|
21
|
-
next_step: "Start a fresh 1000-1500-token handoff with
|
|
21
|
+
next_step: "Start a fresh 1000-1500-token handoff with create_worker with followup_of; keep this thread as evidence"
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
if (tokens >= Math.floor(threshold * LONG_THREAD_RATIO)) {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// The branch a worker's commits live on. Workers dispatched before 1.0 used
|
|
2
|
+
// codex/<id>; their rows carry no branch name, so that is the fallback, and
|
|
3
|
+
// they can still be resumed, landed and restored.
|
|
4
|
+
export const newWorkerBranch = (taskId) => `worker/${taskId}`;
|
|
5
|
+
|
|
6
|
+
export const branchOf = (task) => task.workspace_metadata?.branch ?? `codex/${task.id}`;
|
|
@@ -20,7 +20,7 @@ export function collectWorkerChanges(tasks, cursor = {}) {
|
|
|
20
20
|
id: task.id, title: task.title ?? task.id, run: task.run_count, status: task.status,
|
|
21
21
|
reason: "handoff_recommended", tokens_used: health.tokens_used, threshold: health.threshold,
|
|
22
22
|
next_step: {
|
|
23
|
-
tool: "
|
|
23
|
+
tool: "get_worker", arguments: { task_id: task.id, include: ["status"] },
|
|
24
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
25
|
}
|
|
26
26
|
};
|
|
@@ -46,8 +46,8 @@ export function collectWorkerChanges(tasks, cursor = {}) {
|
|
|
46
46
|
const receipt = {
|
|
47
47
|
id: task.id, title: task.title ?? task.id, run: task.run_count, status: task.status,
|
|
48
48
|
reason, next_step: {
|
|
49
|
-
tool: needsAttention ? "
|
|
50
|
-
arguments: { task_id: task.id },
|
|
49
|
+
tool: needsAttention ? "get_worker" : "get_worker_diff",
|
|
50
|
+
arguments: needsAttention ? { task_id: task.id, include: ["result"] } : { task_id: task.id },
|
|
51
51
|
instruction: needsAttention ? "Read the failure or goal evidence before deciding whether to resume; user approval waits must not auto-resume." : "Read the result and diff, then decide whether to land. Completion is not proof of correctness."
|
|
52
52
|
}
|
|
53
53
|
};
|
|
@@ -23,7 +23,7 @@ export async function cleanupHint({ list = readdir, root = supervisorRoot, dir =
|
|
|
23
23
|
threshold,
|
|
24
24
|
command: `SUPERVISOR_HOME=${root} codex-supervisor-cleanup --dry-run`,
|
|
25
25
|
apply: null,
|
|
26
|
-
next_step: "Read the plan: REVIEW items say when they become removable. Land or resume the work you still want;
|
|
26
|
+
next_step: "Read the plan: REVIEW items say when they become removable. Land or resume the work you still want; cleanup (action apply) removes a SAFE item right away.",
|
|
27
27
|
note: "a worktree is SAFE once its work has landed, or has nothing to keep, or its hold period is over; uncommitted edits are saved on the worker branch first, and branches and evidence are never removed"
|
|
28
28
|
};
|
|
29
29
|
}
|
|
@@ -3,10 +3,10 @@ import { isAbsolute, dirname } from "node:path";
|
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
|
|
5
5
|
export async function captureExternalOutputs(declarations, { checkBaseline = false } = {}) {
|
|
6
|
-
if (!Array.isArray(declarations) || declarations.length > 20) throw new Error("
|
|
6
|
+
if (!Array.isArray(declarations) || declarations.length > 20) throw new Error("workspace.external_outputs must contain at most 20 files");
|
|
7
7
|
const captured = [];
|
|
8
8
|
for (const entry of declarations) {
|
|
9
|
-
if (!entry || !isAbsolute(entry.path)) throw new Error("
|
|
9
|
+
if (!entry || !isAbsolute(entry.path)) throw new Error("workspace.external_outputs must use absolute file paths");
|
|
10
10
|
let info;
|
|
11
11
|
try { info = await lstat(entry.path); } catch (error) { if (error.code !== "ENOENT") throw error; }
|
|
12
12
|
let snapshot = { path: entry.path, exists: false, sha256: null, content: null, truncated: false };
|
|
@@ -68,7 +68,7 @@ export const TOOLCHAIN_CACHE_DIRS = [
|
|
|
68
68
|
];
|
|
69
69
|
|
|
70
70
|
// Credentials are never granted automatically. A dispatcher that needs them
|
|
71
|
-
// names the directory in
|
|
71
|
+
// names the directory in sandbox.writable_roots for that one dispatch: an ssh test wants
|
|
72
72
|
// ~/.ssh (known_hosts, ControlMaster sockets), a kubectl test ~/.kube, a registry
|
|
73
73
|
// push ~/.docker, an aws test ~/.aws, a signed commit ~/.gnupg. Everything here is
|
|
74
74
|
// granted automatically only when it holds build state, not secrets, so a worker
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { branchOf } from "../../domain/worker-branch.js";
|
|
1
2
|
import { ensureControlRecords, ensureFilesystem, openDb, runIdFor, runWithRetry, workItemIdForTask } from "./db.js";
|
|
2
3
|
import { extractAgentMessage } from "./runner-readers.js";
|
|
3
4
|
import { createHash } from "node:crypto";
|
|
@@ -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 ?
|
|
28
|
+
branch: task.worktree_path ? branchOf(task) : null,
|
|
28
29
|
base_sha: task.base_commit ?? null,
|
|
29
30
|
started_at: now
|
|
30
31
|
});
|
|
@@ -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
|
-
|
|
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
|
package/src/infra/store/tasks.js
CHANGED
|
@@ -139,7 +139,7 @@ function checkOwnership(taskId, incoming) {
|
|
|
139
139
|
const matching=incoming.flatMap(path=>paths.filter(other=>overlaps(path,other)).map(other=>({incoming:path,existing:other})));
|
|
140
140
|
if(matching.length)conflicts.push({task_id:row.id,title:row.title,status:row.status,overlapping_paths:matching});
|
|
141
141
|
}
|
|
142
|
-
if(conflicts.length){const error=new Error("
|
|
142
|
+
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
143
|
}
|
|
144
144
|
|
|
145
145
|
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.
|
|
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.
|
|
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,
|
|
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.
|
|
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
|
|
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,
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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", `
|
|
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
|
|
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", "
|
|
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,
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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");
|
package/src/infra/worktree.js
CHANGED
|
@@ -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
|
|
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
|
-
// `
|
|
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 ?
|
|
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.
|
|
30
|
+
const taskId = process.env.AGENT_SUPERVISOR_TASK_ID;
|
|
31
31
|
if (!taskId) {
|
|
32
|
-
console.error("
|
|
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.
|
|
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.
|
|
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>
|
|
177
|
-
<Text dimColor>
|
|
178
|
-
<Text dimColor>
|
|
179
|
-
<Text dimColor>
|
|
180
|
-
<Text dimColor>
|
|
181
|
-
<Text dimColor>
|
|
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
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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
|
|
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`);
|
|
@@ -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
|
|
12
|
-
|
|
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
|
|
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
|
|
89
|
-
|
|
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
|
-
|
|
100
|
-
];
|
|
87
|
+
}),
|
|
88
|
+
handler: async ({ task_id, remote, branch }) => textResult(await verifyDeliveryPush({ taskId: task_id, remote, branch }))
|
|
89
|
+
};
|
|
101
90
|
|
|
102
|
-
export const
|
|
103
|
-
|
|
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
|
|
131
|
-
|
|
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
|
|
149
|
-
|
|
150
|
-
{
|
|
151
|
-
|
|
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
|
|
159
|
-
|
|
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
|
+
};
|