codex-supervisor-mcp 0.13.6 → 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 +35 -46
- package/README.md +35 -46
- package/package.json +3 -2
- package/skills/codex-supervisor/SKILL.md +86 -89
- package/src/app/acceptance.js +5 -5
- package/src/app/auto-cleanup.js +91 -0
- package/src/app/cleanup-facts.js +99 -0
- package/src/app/cleanup-plan.js +108 -100
- 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 +14 -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 +51 -0
- package/src/app/resume.js +24 -6
- package/src/app/side-chat.js +3 -0
- package/src/app/verify-push.js +2 -7
- package/src/app/worktree-setup.js +15 -14
- package/src/domain/acceptance-spec.js +1 -1
- package/src/domain/cleanup-policy.js +44 -0
- 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 +7 -8
- 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/records.js +18 -7
- package/src/infra/store/tasks.js +31 -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/cleanup.js +1 -1
- 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 +45 -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 -62
|
@@ -9,10 +9,10 @@ export function cleanupThreshold(raw = process.env.SUPERVISOR_CLEANUP_HINT) {
|
|
|
9
9
|
return Number.isFinite(value) && value >= 0 ? value : DEFAULT_THRESHOLD;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
12
|
+
// Safe worktrees are removed automatically, so a store that still holds this
|
|
13
|
+
// many has work that is being kept on purpose (unlanded and inside the hold
|
|
14
|
+
// period, or needing review) or has automatic cleanup switched off. The hint
|
|
15
|
+
// reports the count and where to look.
|
|
16
16
|
export async function cleanupHint({ list = readdir, root = supervisorRoot, dir = worktreesDir, threshold = cleanupThreshold() } = {}) {
|
|
17
17
|
if (!threshold) return null;
|
|
18
18
|
let entries;
|
|
@@ -21,10 +21,9 @@ export async function cleanupHint({ list = readdir, root = supervisorRoot, dir =
|
|
|
21
21
|
return {
|
|
22
22
|
worktrees: entries,
|
|
23
23
|
threshold,
|
|
24
|
-
command: `SUPERVISOR_HOME=${root}
|
|
24
|
+
command: `SUPERVISOR_HOME=${root} codex-supervisor-cleanup --dry-run`,
|
|
25
25
|
apply: null,
|
|
26
|
-
next_step: "
|
|
27
|
-
note: "
|
|
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
|
+
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
|
}
|
|
30
|
-
|
|
@@ -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
|
|
@@ -101,6 +101,23 @@ export async function updateWorkItemDelivery(taskId, deliveryState) {
|
|
|
101
101
|
return result.changes > 0;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
// A safe item marks its work item cleanup_eligible. An item that is no longer
|
|
105
|
+
// safe goes back to the furthest delivery step its task row proves.
|
|
106
|
+
function markCleanupEligibility(dbInstance, item) {
|
|
107
|
+
const now = new Date().toISOString();
|
|
108
|
+
if (item.verdict === "safe") {
|
|
109
|
+
dbInstance.prepare("UPDATE work_items SET delivery_state = 'cleanup_eligible', updated_at = ? WHERE task_id = ? AND delivery_state NOT IN ('cleanup_eligible', 'cleanup_removed')")
|
|
110
|
+
.run(now, item.task_id);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
dbInstance.prepare(`
|
|
114
|
+
UPDATE work_items SET updated_at = ?, delivery_state = (
|
|
115
|
+
SELECT CASE WHEN push_verified_at IS NOT NULL THEN 'push_verified' WHEN landed_at IS NOT NULL THEN 'landed' ELSE 'draft' END
|
|
116
|
+
FROM tasks WHERE tasks.id = work_items.task_id
|
|
117
|
+
) WHERE task_id = ? AND delivery_state = 'cleanup_eligible'
|
|
118
|
+
`).run(now, item.task_id);
|
|
119
|
+
}
|
|
120
|
+
|
|
104
121
|
export async function saveCleanupPlan(plan) {
|
|
105
122
|
await ensureFilesystem();
|
|
106
123
|
const dbInstance = openDb();
|
|
@@ -117,13 +134,7 @@ export async function saveCleanupPlan(plan) {
|
|
|
117
134
|
for (const item of plan.items) {
|
|
118
135
|
item.id = item.id ?? randomUUID();
|
|
119
136
|
insert.run(item.id, plan.id, item.task_id, item.verdict, JSON.stringify(item.reasons), item.fingerprint, item.reclaimable_bytes, item.eligible_after);
|
|
120
|
-
|
|
121
|
-
dbInstance.prepare("UPDATE work_items SET delivery_state = 'cleanup_eligible', updated_at = ? WHERE task_id = ? AND delivery_state = 'push_verified'")
|
|
122
|
-
.run(new Date().toISOString(), item.task_id);
|
|
123
|
-
} else {
|
|
124
|
-
dbInstance.prepare("UPDATE work_items SET delivery_state = 'push_verified', updated_at = ? WHERE task_id = ? AND delivery_state = 'cleanup_eligible'")
|
|
125
|
-
.run(new Date().toISOString(), item.task_id);
|
|
126
|
-
}
|
|
137
|
+
markCleanupEligibility(dbInstance, item);
|
|
127
138
|
}
|
|
128
139
|
dbInstance.exec("COMMIT");
|
|
129
140
|
} catch (error) {
|
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) {
|
|
@@ -192,6 +192,36 @@ export async function claimTaskRun(taskId, expectedRun) {
|
|
|
192
192
|
});
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
+
// The same lock a dispatcher takes before it runs a task, for work that needs
|
|
196
|
+
// the task to stay idle without running it (removing its worktree). Null when
|
|
197
|
+
// the task is running, settling, or held by a live dispatcher.
|
|
198
|
+
export async function claimIdleTask(taskId) {
|
|
199
|
+
await ensureFilesystem();
|
|
200
|
+
const connection = openDb();
|
|
201
|
+
return runWithRetry(connection, () => {
|
|
202
|
+
connection.exec("BEGIN IMMEDIATE");
|
|
203
|
+
try {
|
|
204
|
+
const row = connection.prepare("SELECT * FROM tasks WHERE id=?").get(taskId);
|
|
205
|
+
const claim = connection.prepare("SELECT * FROM run_claims WHERE task_id=?").get(taskId);
|
|
206
|
+
const busy = !row || ACTIVE_STATUSES.has(row.status)
|
|
207
|
+
|| (["completed", "failed"].includes(row.status) && row.exit_code == null)
|
|
208
|
+
|| decodeJson(row.acceptance_results, null)?.status === "running"
|
|
209
|
+
|| (claim && isPidAlive(claim.owner_pid));
|
|
210
|
+
let token = null;
|
|
211
|
+
if (!busy) {
|
|
212
|
+
token = randomUUID();
|
|
213
|
+
connection.prepare("INSERT INTO run_claims VALUES (?,?,?) ON CONFLICT(task_id) DO UPDATE SET token=excluded.token,owner_pid=excluded.owner_pid")
|
|
214
|
+
.run(taskId, token, process.pid);
|
|
215
|
+
}
|
|
216
|
+
connection.exec("COMMIT");
|
|
217
|
+
return token;
|
|
218
|
+
} catch (error) {
|
|
219
|
+
connection.exec("ROLLBACK");
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
195
225
|
export async function releaseTaskRun(taskId, token) {
|
|
196
226
|
openDb().prepare("DELETE FROM run_claims WHERE task_id=? AND token=?").run(taskId, token);
|
|
197
227
|
}
|
|
@@ -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; cleanup eligibility may depend on this evidence.",
|
|
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: "Classify managed worktrees as safe, review or blocked. The plan is read-only, expires after 15 minutes, estimates reclaimable bytes and never deletes branches, task rows, events, JSONL logs or artifacts.",
|
|
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 only selected SAFE worktrees from an unexpired cleanup plan after a second proof check. Uses git worktree remove and prune only; retains 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
|
+
};
|