codex-supervisor-mcp 0.10.3 → 0.11.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 +25 -7
- package/README.md +23 -14
- package/package.json +3 -1
- package/skills/codex-supervisor/SKILL.md +20 -13
- package/src/cleanup-hint.js +3 -2
- package/src/cleanup-plan.js +67 -7
- package/src/cleanup.js +48 -40
- package/src/codex-runner.js +101 -79
- package/src/mcp-server.js +377 -36
- package/src/overview-delta.js +37 -5
- package/src/paths.js +2 -0
- package/src/prompt.js +5 -2
- package/src/runner-adapter.js +100 -0
- package/src/side-chat.js +10 -38
- package/src/task-store.js +284 -23
- package/src/worker-preflight.js +5 -1
- package/src/workspace-kind.js +167 -0
package/src/mcp-server.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
import { execFileSync } from "node:child_process";
|
|
4
|
-
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
5
5
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
6
6
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
7
7
|
import { z } from "zod";
|
|
@@ -14,12 +14,20 @@ import {
|
|
|
14
14
|
} from "./codex-runner.js";
|
|
15
15
|
import {
|
|
16
16
|
getSession,
|
|
17
|
+
getArtifact,
|
|
17
18
|
getFact,
|
|
19
|
+
getReviewByVerifierTask,
|
|
20
|
+
getTaskForWorkItem,
|
|
18
21
|
getWorkItemForTask,
|
|
19
22
|
getTask,
|
|
20
23
|
getTasks,
|
|
21
24
|
isPidAlive,
|
|
22
25
|
listTaskEventKinds,
|
|
26
|
+
listArtifactsForTask,
|
|
27
|
+
listContextFacts,
|
|
28
|
+
countVerifiedFacts,
|
|
29
|
+
readArtifact,
|
|
30
|
+
readTaskEventRecords,
|
|
23
31
|
readAgentMessages,
|
|
24
32
|
readTaskEvents,
|
|
25
33
|
readTasks,
|
|
@@ -34,11 +42,16 @@ import {
|
|
|
34
42
|
upsertTask,
|
|
35
43
|
appendTaskEvent,
|
|
36
44
|
recordFact,
|
|
45
|
+
recordJsonArtifact,
|
|
46
|
+
createReviewAssignment,
|
|
47
|
+
recordReviewFinding,
|
|
48
|
+
resolveReviewFinding,
|
|
49
|
+
promoteCandidateFact,
|
|
50
|
+
revokeFact,
|
|
37
51
|
runIdFor,
|
|
38
52
|
updateWorkItemDelivery,
|
|
39
53
|
saveCleanupPlan,
|
|
40
54
|
getCleanupPlan,
|
|
41
|
-
markCleanupPlanItemApplied,
|
|
42
55
|
readCleanupHistory
|
|
43
56
|
} from "./task-store.js";
|
|
44
57
|
import { readNativeGoal, readNativeGoalState } from "./goal-store.js";
|
|
@@ -56,7 +69,7 @@ import { maybeAutoUpdate } from "./auto-update.js";
|
|
|
56
69
|
import { askWorker, endSideSession, latestSideTurn } from "./side-chat.js";
|
|
57
70
|
import { landWorker } from "./landing.js";
|
|
58
71
|
import { cleanupHint } from "./cleanup-hint.js";
|
|
59
|
-
import {
|
|
72
|
+
import { applyCleanupPlan, createCleanupPlan } from "./cleanup-plan.js";
|
|
60
73
|
import { buildOverviewDelta } from "./overview-delta.js";
|
|
61
74
|
|
|
62
75
|
// Report the real package version. This string had drifted to 0.4.0 while the
|
|
@@ -269,6 +282,7 @@ function summarizeTask(task) {
|
|
|
269
282
|
phase: task.phase ?? null,
|
|
270
283
|
cwd: task.cwd,
|
|
271
284
|
project_root: task.project_root,
|
|
285
|
+
workspace_kind: task.workspace_kind ?? "legacy",
|
|
272
286
|
sandbox: task.sandbox,
|
|
273
287
|
model: task.model,
|
|
274
288
|
reasoning_effort: task.reasoning_effort ?? "high",
|
|
@@ -342,6 +356,7 @@ function receipt(task) {
|
|
|
342
356
|
phase: task.phase ?? null,
|
|
343
357
|
cwd: task.cwd,
|
|
344
358
|
project_root: task.project_root,
|
|
359
|
+
workspace_kind: task.workspace_kind ?? "legacy",
|
|
345
360
|
worktree_path: task.worktree_path,
|
|
346
361
|
branch: task.worktree_path ? `codex/${task.id}` : null,
|
|
347
362
|
base_commit: task.base_commit ?? null,
|
|
@@ -564,7 +579,14 @@ server.registerTool(
|
|
|
564
579
|
await reconcileDetachedActiveTasks();
|
|
565
580
|
const tasks = await readTasks();
|
|
566
581
|
const previous = cursor ?? await readObserverCursor(deltaObserverId);
|
|
567
|
-
const
|
|
582
|
+
const candidateIds = tasks.filter((task) => task.delivery_state === "cleanup_eligible").map((task) => task.id);
|
|
583
|
+
const cleanupReadiness = candidateIds.length > 0
|
|
584
|
+
? await createCleanupPlan({ taskIds: candidateIds, revalidateRemote: false })
|
|
585
|
+
: null;
|
|
586
|
+
const readyToCleanTaskIds = cleanupReadiness
|
|
587
|
+
? new Set(cleanupReadiness.items.filter((item) => item.verdict === "safe").map((item) => item.task_id))
|
|
588
|
+
: new Set();
|
|
589
|
+
const result = buildOverviewDelta(tasks, previous, { readyToCleanTaskIds });
|
|
568
590
|
await writeObserverCursor(deltaObserverId, result.cursor);
|
|
569
591
|
const { cursor: nextCursor, ...reply } = result;
|
|
570
592
|
return textResult({ ...reply, next_cursor: nextCursor });
|
|
@@ -644,6 +666,8 @@ server.registerTool(
|
|
|
644
666
|
maxRunMs: z.number().int().min(1000).max(86400000).optional(),
|
|
645
667
|
maxTotalMs: z.number().int().min(1000).max(604800000).optional(),
|
|
646
668
|
baseRef: z.string().min(1).optional(),
|
|
669
|
+
workspaceKind: z.enum(["git_worktree", "read_only_in_place", "scratch", "in_place_write"]).optional(),
|
|
670
|
+
inPlaceAuthorization: z.string().min(1).max(2000).optional(),
|
|
647
671
|
probeCommands: z.array(z.string().min(1)).min(1).max(20)
|
|
648
672
|
}
|
|
649
673
|
},
|
|
@@ -690,7 +714,7 @@ server.registerTool(
|
|
|
690
714
|
{
|
|
691
715
|
title: "Create Codex worker",
|
|
692
716
|
description:
|
|
693
|
-
"Launch a Codex CLI worker with codex exec --json and track its events.
|
|
717
|
+
"Launch a Codex CLI worker with codex exec --json and track its events. workspaceKind controls where it runs: Git work writes only in an isolated git_worktree; read_only_in_place cannot write or use network; scratch writes only under SUPERVISOR_HOME and never lands; in_place_write is only for an explicitly authorized non-Git directory with ownedPaths and acceptance. A non-Git worker may never write the user directory by default. ownedPaths reserves files a landable worker may write; reading is never exclusive. acceptance is the list of shell commands that decide whether the work is done: the supervisor runs them after Codex exits. The worker's sandbox may write its execution directory, the temp directory and the OS cache directory; a toolchain whose cache lives elsewhere needs writableRoots, a list of existing absolute directories.",
|
|
694
718
|
inputSchema: {
|
|
695
719
|
title: z.string().optional(),
|
|
696
720
|
task: z.string().min(1),
|
|
@@ -729,6 +753,8 @@ server.registerTool(
|
|
|
729
753
|
// HEAD; pass a branch, tag or sha to build on work that is not on the
|
|
730
754
|
// main line yet (for example another worker's codex/<id> branch).
|
|
731
755
|
baseRef: z.string().min(1).optional(),
|
|
756
|
+
workspaceKind: z.enum(["git_worktree", "read_only_in_place", "scratch", "in_place_write"]).optional(),
|
|
757
|
+
inPlaceAuthorization: z.string().min(1).max(2000).optional(),
|
|
732
758
|
// A successful preflight_codex_worker task id. When present, this worker
|
|
733
759
|
// is refused unless base commit and the complete runtime contract match.
|
|
734
760
|
preflight_id: z.string().min(1).optional(),
|
|
@@ -781,6 +807,8 @@ server.registerTool(
|
|
|
781
807
|
writableRoots: z.array(z.string().min(1)).max(20).optional(),
|
|
782
808
|
maxRunMs: z.number().int().min(1000).max(86400000).optional(),
|
|
783
809
|
maxTotalMs: z.number().int().min(1000).max(604800000).optional(),
|
|
810
|
+
workspaceKind: z.enum(["git_worktree", "read_only_in_place", "scratch", "in_place_write"]).optional(),
|
|
811
|
+
inPlaceAuthorization: z.string().min(1).max(2000).optional(),
|
|
784
812
|
goal: z
|
|
785
813
|
.object({
|
|
786
814
|
objective: z.string().min(1),
|
|
@@ -1188,6 +1216,307 @@ server.registerTool(
|
|
|
1188
1216
|
}
|
|
1189
1217
|
);
|
|
1190
1218
|
|
|
1219
|
+
server.registerTool(
|
|
1220
|
+
"get_artifact",
|
|
1221
|
+
{
|
|
1222
|
+
title: "Get one retained evidence artifact",
|
|
1223
|
+
description: "Read one supervisor-managed artifact by ID for audit. This is explicit evidence retrieval and never expands a worker context capsule into the main thread.",
|
|
1224
|
+
inputSchema: { artifact_id: z.string().uuid(), maxChars: z.number().int().min(0).max(100000).default(12000) }
|
|
1225
|
+
},
|
|
1226
|
+
async ({ artifact_id, maxChars }) => {
|
|
1227
|
+
const artifact = await getArtifact(artifact_id);
|
|
1228
|
+
if (!artifact) return textResult({ error: "artifact_not_found", artifact_id });
|
|
1229
|
+
return textResult({ artifact: await readArtifact(artifact_id, maxChars) });
|
|
1230
|
+
}
|
|
1231
|
+
);
|
|
1232
|
+
|
|
1233
|
+
server.registerTool(
|
|
1234
|
+
"promote_worker_fact",
|
|
1235
|
+
{
|
|
1236
|
+
title: "Promote a candidate worker fact",
|
|
1237
|
+
description: "Explicitly promote one candidate fact after main-thread review. The worker cannot call this: promotion writes a new verified fact with an audit event; repo scope requires watched paths.",
|
|
1238
|
+
inputSchema: {
|
|
1239
|
+
fact_id: z.string().uuid(),
|
|
1240
|
+
scope: z.enum(["work_item", "repo_verified"]).default("work_item"),
|
|
1241
|
+
watchedPaths: z.array(z.string().min(1)).max(100).optional(),
|
|
1242
|
+
expiresAt: z.string().datetime().optional()
|
|
1243
|
+
}
|
|
1244
|
+
},
|
|
1245
|
+
async ({ fact_id, scope, watchedPaths, expiresAt }) => {
|
|
1246
|
+
try {
|
|
1247
|
+
const source = await getFact(fact_id);
|
|
1248
|
+
if (!source) return textResult({ error: "fact_not_found", fact_id });
|
|
1249
|
+
const task = await getTaskForWorkItem(source.work_item_id);
|
|
1250
|
+
if (!task) return textResult({ error: "fact_task_not_found", fact_id });
|
|
1251
|
+
const event = await appendTaskEvent(task.id, { type: "supervisor.fact_promoted", source_fact_id: fact_id, scope, watched_paths: watchedPaths ?? source.watched_paths ?? [], expires_at: expiresAt ?? null }, {
|
|
1252
|
+
runId: runIdFor(task.id, task.run_count ?? 1), actor: "main_thread"
|
|
1253
|
+
});
|
|
1254
|
+
const fact = await promoteCandidateFact({
|
|
1255
|
+
factId: fact_id,
|
|
1256
|
+
scopeType: scope,
|
|
1257
|
+
watchedPaths,
|
|
1258
|
+
expiresAt: expiresAt ?? null,
|
|
1259
|
+
sourceEventId: event.id,
|
|
1260
|
+
verifiedBy: "main_thread"
|
|
1261
|
+
});
|
|
1262
|
+
return textResult({ fact, source_fact_id: fact_id });
|
|
1263
|
+
} catch (error) {
|
|
1264
|
+
return errorResult(error);
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
);
|
|
1268
|
+
|
|
1269
|
+
server.registerTool(
|
|
1270
|
+
"revoke_worker_fact",
|
|
1271
|
+
{
|
|
1272
|
+
title: "Revoke a candidate or verified worker fact",
|
|
1273
|
+
description: "Explicitly revoke one candidate or verified fact after audit. Revoked facts are excluded from search and worker capsules; the revocation is appended to the worker event log.",
|
|
1274
|
+
inputSchema: { fact_id: z.string().uuid(), reason: z.string().min(1).max(2000) }
|
|
1275
|
+
},
|
|
1276
|
+
async ({ fact_id, reason }) => {
|
|
1277
|
+
try {
|
|
1278
|
+
const source = await getFact(fact_id);
|
|
1279
|
+
if (!source) return textResult({ error: "fact_not_found", fact_id });
|
|
1280
|
+
const task = await getTaskForWorkItem(source.work_item_id);
|
|
1281
|
+
if (!task) return textResult({ error: "fact_task_not_found", fact_id });
|
|
1282
|
+
const revoked = await revokeFact(fact_id);
|
|
1283
|
+
await appendTaskEvent(task.id, { type: "supervisor.fact_revoked", fact_id, reason }, {
|
|
1284
|
+
runId: runIdFor(task.id, task.run_count ?? 1), actor: "main_thread"
|
|
1285
|
+
});
|
|
1286
|
+
return textResult({ fact: revoked, reason });
|
|
1287
|
+
} catch (error) {
|
|
1288
|
+
return errorResult(error);
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
);
|
|
1292
|
+
|
|
1293
|
+
server.registerTool(
|
|
1294
|
+
"get_worker_evidence",
|
|
1295
|
+
{
|
|
1296
|
+
title: "Get a worker evidence index",
|
|
1297
|
+
description: "Return bounded event metadata and retained artifact IDs for one worker. It does not return raw history, prompts or a worker context capsule; use get_artifact or get_codex_worker_events for a selected item.",
|
|
1298
|
+
inputSchema: { task_id: z.string().min(1), limit: z.number().int().min(1).max(100).default(30) }
|
|
1299
|
+
},
|
|
1300
|
+
async ({ task_id, limit }) => {
|
|
1301
|
+
const task = await getTask(task_id);
|
|
1302
|
+
if (!task) return textResult({ error: "task_not_found", task_id });
|
|
1303
|
+
const events = await readTaskEventRecords(task_id, limit);
|
|
1304
|
+
const artifacts = await listArtifactsForTask(task_id, limit);
|
|
1305
|
+
return textResult({
|
|
1306
|
+
task_id,
|
|
1307
|
+
events: events.map((event) => ({ id: event.id, run_id: event.run_id, type: event.event_type, actor: event.actor, payload_sha256: event.payload_sha256, created_at: event.created_at })),
|
|
1308
|
+
artifacts: artifacts.map((artifact) => ({ id: artifact.id, run_id: artifact.run_id, type: artifact.type, sha256: artifact.sha256, security_class: artifact.security_class, retention: artifact.retention, created_at: artifact.created_at }))
|
|
1309
|
+
});
|
|
1310
|
+
}
|
|
1311
|
+
);
|
|
1312
|
+
|
|
1313
|
+
function decodeFactCursor(cursor, taskId, query) {
|
|
1314
|
+
if (!cursor) return 0;
|
|
1315
|
+
try {
|
|
1316
|
+
const payload = JSON.parse(Buffer.from(cursor, "base64url").toString("utf8"));
|
|
1317
|
+
if (payload.task_id !== taskId || payload.query !== query || !Number.isInteger(payload.offset) || payload.offset < 0) throw new Error("mismatch");
|
|
1318
|
+
return payload.offset;
|
|
1319
|
+
} catch {
|
|
1320
|
+
const error = new Error("fact cursor does not match this task and query");
|
|
1321
|
+
error.code = "invalid_fact_cursor";
|
|
1322
|
+
throw error;
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
function encodeFactCursor(taskId, query, offset) {
|
|
1327
|
+
return Buffer.from(JSON.stringify({ task_id: taskId, query, offset })).toString("base64url");
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
function factFreshForTask(task, fact) {
|
|
1331
|
+
if (!fact.valid_for_sha || !task.base_commit) return true;
|
|
1332
|
+
try {
|
|
1333
|
+
git(task.project_root, ["merge-base", "--is-ancestor", fact.valid_for_sha, task.base_commit]);
|
|
1334
|
+
return true;
|
|
1335
|
+
} catch {
|
|
1336
|
+
return false;
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
server.registerTool(
|
|
1341
|
+
"search_worker_facts",
|
|
1342
|
+
{
|
|
1343
|
+
title: "Search verified worker facts in scope",
|
|
1344
|
+
description: "Search only verified facts relevant to one task: its own work, explicit dependencies and path-matched repository facts. Returns compact summaries, coverage and a cursor; never raw events, reports, prompts or worker capsules.",
|
|
1345
|
+
inputSchema: {
|
|
1346
|
+
task_id: z.string().min(1),
|
|
1347
|
+
query: z.string().max(500).default(""),
|
|
1348
|
+
limit: z.number().int().min(1).max(50).default(20),
|
|
1349
|
+
cursor: z.string().min(1).optional()
|
|
1350
|
+
}
|
|
1351
|
+
},
|
|
1352
|
+
async ({ task_id, query, limit, cursor }) => {
|
|
1353
|
+
const task = await getTask(task_id);
|
|
1354
|
+
if (!task) return textResult({ error: "task_not_found", task_id });
|
|
1355
|
+
try {
|
|
1356
|
+
const normalizedQuery = query.trim().toLocaleLowerCase();
|
|
1357
|
+
const offset = decodeFactCursor(cursor, task_id, normalizedQuery);
|
|
1358
|
+
const scoped = (await listContextFacts({
|
|
1359
|
+
taskId: task_id,
|
|
1360
|
+
baseSha: task.base_commit ?? null,
|
|
1361
|
+
ownedPaths: task.owned_paths ?? [],
|
|
1362
|
+
dependencyTaskIds: task.depends_on ?? []
|
|
1363
|
+
})).filter((fact) => factFreshForTask(task, fact));
|
|
1364
|
+
const matching = scoped.filter((fact) => !normalizedQuery || `${fact.key}\n${JSON.stringify(fact.value)}`.toLocaleLowerCase().includes(normalizedQuery));
|
|
1365
|
+
const page = matching.slice(offset, offset + limit);
|
|
1366
|
+
const nextOffset = offset + page.length;
|
|
1367
|
+
const totalVerified = await countVerifiedFacts();
|
|
1368
|
+
return textResult({
|
|
1369
|
+
task_id,
|
|
1370
|
+
facts: page.map((fact) => ({
|
|
1371
|
+
id: fact.id,
|
|
1372
|
+
key: fact.key,
|
|
1373
|
+
summary: clip(typeof fact.value === "string" ? fact.value : JSON.stringify(fact.value), 360),
|
|
1374
|
+
state: fact.state,
|
|
1375
|
+
scope: fact.scope_type,
|
|
1376
|
+
valid_for_sha: fact.valid_for_sha ?? null,
|
|
1377
|
+
freshness: "current",
|
|
1378
|
+
source_refs: [
|
|
1379
|
+
...(fact.source_event_id ? [`event:${fact.source_event_id}`] : []),
|
|
1380
|
+
...(fact.source_artifact_id ? [`artifact:${fact.source_artifact_id}`] : [])
|
|
1381
|
+
]
|
|
1382
|
+
})),
|
|
1383
|
+
coverage: {
|
|
1384
|
+
scope: "current_work+explicit_dependencies+path_matched_repo_facts",
|
|
1385
|
+
included_count: scoped.length,
|
|
1386
|
+
matched_count: matching.length,
|
|
1387
|
+
omitted: [
|
|
1388
|
+
{ reason: "other_verified_scopes_excluded", count: Math.max(0, totalVerified - scoped.length) },
|
|
1389
|
+
{ reason: "candidate_and_nonverified_facts_excluded", count: null }
|
|
1390
|
+
]
|
|
1391
|
+
},
|
|
1392
|
+
next_cursor: nextOffset < matching.length ? encodeFactCursor(task_id, normalizedQuery, nextOffset) : null
|
|
1393
|
+
});
|
|
1394
|
+
} catch (error) {
|
|
1395
|
+
return errorResult(error);
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
);
|
|
1399
|
+
|
|
1400
|
+
server.registerTool(
|
|
1401
|
+
"create_independent_verifier",
|
|
1402
|
+
{
|
|
1403
|
+
title: "Create an independent read-only verifier",
|
|
1404
|
+
description: "Create a fresh read-only verifier for one settled worker. It receives the target objective and current worktree path, never the target report or candidate facts, has no network and cannot dispatch workers. The review relation is persisted for later finding and resolution.",
|
|
1405
|
+
inputSchema: { task_id: z.string().min(1), title: z.string().min(1).max(120).optional() }
|
|
1406
|
+
},
|
|
1407
|
+
async ({ task_id, title }) => {
|
|
1408
|
+
try {
|
|
1409
|
+
const subject = await getTask(task_id);
|
|
1410
|
+
if (!subject) return textResult({ error: "task_not_found", task_id });
|
|
1411
|
+
if (!isSettled(subject)) return textResult({ error: "review_subject_active", task_id, reason: "wait for the worker and any acceptance to settle before independent review" });
|
|
1412
|
+
const sourceRoot = subject.worktree_path ?? subject.project_root;
|
|
1413
|
+
const verifier = await createCodexWorker({
|
|
1414
|
+
title: title ?? `Independent review: ${subject.title ?? subject.id}`,
|
|
1415
|
+
task: [
|
|
1416
|
+
"Independently verify the target worker's objective from the current source tree and Git state.",
|
|
1417
|
+
`Target task ID: ${subject.id}`,
|
|
1418
|
+
`Target objective: ${subject.goal_objective ?? subject.title ?? "unspecified"}`,
|
|
1419
|
+
`Inspect root: ${sourceRoot}`,
|
|
1420
|
+
"Do not trust or request the target worker's report. Do not inspect candidate facts. Do not edit files, use network, create workers or call MCP tools.",
|
|
1421
|
+
"Return whether the stated objective is met, the exact evidence you inspected, and any unresolved gap."
|
|
1422
|
+
].join("\n"),
|
|
1423
|
+
cwd: sourceRoot,
|
|
1424
|
+
workspaceKind: "read_only_in_place",
|
|
1425
|
+
sandbox: "read-only",
|
|
1426
|
+
ownedPaths: [],
|
|
1427
|
+
networkAccess: false,
|
|
1428
|
+
goal: { objective: `Independently verify worker ${subject.id} without relying on its self-report` }
|
|
1429
|
+
});
|
|
1430
|
+
const fingerprint = createHash("sha256").update(JSON.stringify({
|
|
1431
|
+
task_id: subject.id,
|
|
1432
|
+
run: subject.run_count ?? 0,
|
|
1433
|
+
base_sha: subject.base_commit ?? null,
|
|
1434
|
+
worktree: sourceRoot,
|
|
1435
|
+
updated_at: subject.updated_at ?? null,
|
|
1436
|
+
changed_files: subject.changed_files ?? []
|
|
1437
|
+
})).digest("hex");
|
|
1438
|
+
const review = await createReviewAssignment({
|
|
1439
|
+
subjectTaskId: subject.id,
|
|
1440
|
+
verifierTaskId: verifier.id,
|
|
1441
|
+
subjectRunId: runIdFor(subject.id, subject.run_count ?? 1),
|
|
1442
|
+
subjectBaseSha: subject.base_commit ?? null,
|
|
1443
|
+
subjectFingerprint: fingerprint
|
|
1444
|
+
});
|
|
1445
|
+
return textResult({ ...receipt(verifier), review });
|
|
1446
|
+
} catch (error) {
|
|
1447
|
+
return errorResult(error);
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
);
|
|
1451
|
+
|
|
1452
|
+
server.registerTool(
|
|
1453
|
+
"record_independent_finding",
|
|
1454
|
+
{
|
|
1455
|
+
title: "Record an independent verifier finding",
|
|
1456
|
+
description: "After a verifier settles, record its passes/fails/inconclusive verdict with a concise reason. The supervisor stores a retained finding artifact and appends an event to the reviewed worker; this does not change the reviewed worker's delivery state automatically.",
|
|
1457
|
+
inputSchema: { verifier_task_id: z.string().min(1), verdict: z.enum(["passes", "fails", "inconclusive"]), reason: z.string().min(1).max(4000) }
|
|
1458
|
+
},
|
|
1459
|
+
async ({ verifier_task_id, verdict, reason }) => {
|
|
1460
|
+
try {
|
|
1461
|
+
const review = await getReviewByVerifierTask(verifier_task_id);
|
|
1462
|
+
if (!review) return textResult({ error: "review_not_found", verifier_task_id });
|
|
1463
|
+
if (review.status !== "pending") return textResult({ error: "review_not_pending", verifier_task_id, status: review.status });
|
|
1464
|
+
const verifier = await getTask(verifier_task_id);
|
|
1465
|
+
if (!verifier || !isSettled(verifier)) return textResult({ error: "verifier_not_settled", verifier_task_id });
|
|
1466
|
+
const subject = await getTask(review.subject_task_id);
|
|
1467
|
+
if (!subject) return textResult({ error: "review_subject_not_found", task_id: review.subject_task_id });
|
|
1468
|
+
const artifact = await recordJsonArtifact({
|
|
1469
|
+
runId: runIdFor(verifier.id, verifier.run_count ?? 1),
|
|
1470
|
+
type: "independent_review_finding",
|
|
1471
|
+
value: { review_id: review.id, subject_task_id: subject.id, verifier_task_id, verdict, reason, verifier_run: verifier.run_count ?? 1, recorded_at: new Date().toISOString() },
|
|
1472
|
+
securityClass: "internal"
|
|
1473
|
+
});
|
|
1474
|
+
const event = await appendTaskEvent(subject.id, { type: "supervisor.independent_finding", review_id: review.id, verifier_task_id, verdict, reason, artifact_id: artifact.id }, {
|
|
1475
|
+
runId: review.subject_run_id ?? runIdFor(subject.id, subject.run_count ?? 1), actor: "main_thread"
|
|
1476
|
+
});
|
|
1477
|
+
const recorded = await recordReviewFinding({ verifierTaskId: verifier_task_id, verdict, reason, evidenceArtifactId: artifact.id, findingEventId: event.id });
|
|
1478
|
+
return textResult({ review: recorded, artifact_id: artifact.id });
|
|
1479
|
+
} catch (error) {
|
|
1480
|
+
return errorResult(error);
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
);
|
|
1484
|
+
|
|
1485
|
+
server.registerTool(
|
|
1486
|
+
"resolve_independent_finding",
|
|
1487
|
+
{
|
|
1488
|
+
title: "Resolve an independent verifier finding",
|
|
1489
|
+
description: "Record how a previously recorded independent finding was resolved. This is an audit transition only; it does not hide the finding or alter worker code.",
|
|
1490
|
+
inputSchema: { verifier_task_id: z.string().min(1), resolution: z.string().min(1).max(4000) }
|
|
1491
|
+
},
|
|
1492
|
+
async ({ verifier_task_id, resolution }) => {
|
|
1493
|
+
try {
|
|
1494
|
+
const review = await resolveReviewFinding({ verifierTaskId: verifier_task_id, resolution });
|
|
1495
|
+
if (!review) return textResult({ error: "review_not_recorded", verifier_task_id });
|
|
1496
|
+
const subject = await getTask(review.subject_task_id);
|
|
1497
|
+
if (subject) await appendTaskEvent(subject.id, { type: "supervisor.independent_finding_resolved", review_id: review.id, verifier_task_id, resolution }, {
|
|
1498
|
+
runId: review.subject_run_id ?? runIdFor(subject.id, subject.run_count ?? 1), actor: "main_thread"
|
|
1499
|
+
});
|
|
1500
|
+
return textResult({ review });
|
|
1501
|
+
} catch (error) {
|
|
1502
|
+
return errorResult(error);
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
);
|
|
1506
|
+
|
|
1507
|
+
server.registerTool(
|
|
1508
|
+
"get_independent_review",
|
|
1509
|
+
{
|
|
1510
|
+
title: "Get one independent review relation",
|
|
1511
|
+
description: "Read the persisted subject/verifier/finding/resolution relation for a verifier task. Use get_artifact for the retained finding evidence.",
|
|
1512
|
+
inputSchema: { verifier_task_id: z.string().min(1) }
|
|
1513
|
+
},
|
|
1514
|
+
async ({ verifier_task_id }) => {
|
|
1515
|
+
const review = await getReviewByVerifierTask(verifier_task_id);
|
|
1516
|
+
return textResult(review ? { review } : { error: "review_not_found", verifier_task_id });
|
|
1517
|
+
}
|
|
1518
|
+
);
|
|
1519
|
+
|
|
1191
1520
|
server.registerTool(
|
|
1192
1521
|
"get_worker_goal",
|
|
1193
1522
|
{
|
|
@@ -1279,6 +1608,7 @@ server.registerTool(
|
|
|
1279
1608
|
exit_code: task.exit_code ?? null,
|
|
1280
1609
|
thread_id: task.thread_id,
|
|
1281
1610
|
session_id: task.session_id ?? null,
|
|
1611
|
+
workspace_kind: task.workspace_kind ?? "legacy",
|
|
1282
1612
|
worktree_path: task.worktree_path,
|
|
1283
1613
|
goal_status: task.goal_status,
|
|
1284
1614
|
attention_reason: task.attention_reason ?? null,
|
|
@@ -1399,6 +1729,9 @@ server.registerTool(
|
|
|
1399
1729
|
async ({ task_id, onto, commitMessage, ignoreAcceptance, allowOutsideOwned }) => {
|
|
1400
1730
|
const task = await getTask(task_id);
|
|
1401
1731
|
if (!task) return textResult({ error: "task_not_found", task_id });
|
|
1732
|
+
if (task.workspace_kind && task.workspace_kind !== "legacy" && task.workspace_kind !== "git_worktree") {
|
|
1733
|
+
return textResult({ error: "workspace_kind_not_landable", task_id, workspace_kind: task.workspace_kind, reason: `${task.workspace_kind} does not create a Git worktree and cannot be landed` });
|
|
1734
|
+
}
|
|
1402
1735
|
const session = task.session_id ? await getSession(task.session_id) : null;
|
|
1403
1736
|
if (task.attention_reason === "invalid_report") return textResult({ error: "invalid_report", task_id, reason: task.error });
|
|
1404
1737
|
if (!isSettled(task)) return textResult({ error: "worker_active", task_id, reason: "wait for this run and acceptance to settle before landing" });
|
|
@@ -1430,7 +1763,20 @@ server.registerTool(
|
|
|
1430
1763
|
state: "verified",
|
|
1431
1764
|
sourceEventId: event.id,
|
|
1432
1765
|
validForSha: outcome.head,
|
|
1433
|
-
watchedPaths: task.owned_paths ?? []
|
|
1766
|
+
watchedPaths: task.owned_paths ?? [],
|
|
1767
|
+
verifiedBy: "supervisor.git_land"
|
|
1768
|
+
});
|
|
1769
|
+
await recordFact({
|
|
1770
|
+
workItemId: workItem.id,
|
|
1771
|
+
scopeType: "dependency",
|
|
1772
|
+
scopeId: workItem.id,
|
|
1773
|
+
key: "landed_delivery_summary",
|
|
1774
|
+
value: { task_id, landed_head: outcome.head, branch: outcome.onto ?? null, acceptance: task.acceptance_results?.passed === true ? "passed" : "not_configured_or_not_passed" },
|
|
1775
|
+
state: "verified",
|
|
1776
|
+
sourceEventId: event.id,
|
|
1777
|
+
validForSha: outcome.head,
|
|
1778
|
+
watchedPaths: task.owned_paths ?? [],
|
|
1779
|
+
verifiedBy: "supervisor.git_land"
|
|
1434
1780
|
});
|
|
1435
1781
|
}
|
|
1436
1782
|
}
|
|
@@ -1474,7 +1820,7 @@ server.registerTool(
|
|
|
1474
1820
|
});
|
|
1475
1821
|
}
|
|
1476
1822
|
const now = new Date().toISOString();
|
|
1477
|
-
const verified = { ...task, push_verified_at: now, push_remote: remote, push_branch: targetBranch, updated_at: now };
|
|
1823
|
+
const verified = { ...task, push_verified_at: now, push_remote: remote, push_branch: targetBranch, push_remote_head: remoteHead, updated_at: now };
|
|
1478
1824
|
await upsertTask(verified);
|
|
1479
1825
|
await updateWorkItemDelivery(task_id, "push_verified");
|
|
1480
1826
|
const event = await appendTaskEvent(task_id, {
|
|
@@ -1485,6 +1831,12 @@ server.registerTool(
|
|
|
1485
1831
|
remote_head: remoteHead,
|
|
1486
1832
|
verified_at: now
|
|
1487
1833
|
}, { runId: runIdFor(task_id, task.run_count ?? 1), actor: "supervisor" });
|
|
1834
|
+
const artifact = await recordJsonArtifact({
|
|
1835
|
+
runId: runIdFor(task_id, task.run_count ?? 1),
|
|
1836
|
+
type: "push_proof",
|
|
1837
|
+
value: { remote, branch: targetBranch, landed_head: task.landed_head, remote_head: remoteHead, verified_at: now, event_id: event.id },
|
|
1838
|
+
securityClass: "internal"
|
|
1839
|
+
});
|
|
1488
1840
|
const workItem = await getWorkItemForTask(task_id);
|
|
1489
1841
|
if (workItem) {
|
|
1490
1842
|
await recordFact({
|
|
@@ -1495,8 +1847,23 @@ server.registerTool(
|
|
|
1495
1847
|
value: { remote, branch: targetBranch, landed_head: task.landed_head, remote_head: remoteHead },
|
|
1496
1848
|
state: "verified",
|
|
1497
1849
|
sourceEventId: event.id,
|
|
1850
|
+
sourceArtifactId: artifact.id,
|
|
1851
|
+
validForSha: task.landed_head,
|
|
1852
|
+
watchedPaths: task.owned_paths ?? [],
|
|
1853
|
+
verifiedBy: "supervisor.remote_readback"
|
|
1854
|
+
});
|
|
1855
|
+
await recordFact({
|
|
1856
|
+
workItemId: workItem.id,
|
|
1857
|
+
scopeType: "dependency",
|
|
1858
|
+
scopeId: workItem.id,
|
|
1859
|
+
key: "push_delivery_summary",
|
|
1860
|
+
value: { task_id, landed_head: task.landed_head, remote, branch: targetBranch, remote_head: remoteHead },
|
|
1861
|
+
state: "verified",
|
|
1862
|
+
sourceEventId: event.id,
|
|
1863
|
+
sourceArtifactId: artifact.id,
|
|
1498
1864
|
validForSha: task.landed_head,
|
|
1499
|
-
watchedPaths: task.owned_paths ?? []
|
|
1865
|
+
watchedPaths: task.owned_paths ?? [],
|
|
1866
|
+
verifiedBy: "supervisor.remote_readback"
|
|
1500
1867
|
});
|
|
1501
1868
|
}
|
|
1502
1869
|
const cleanupPlan = await createCleanupPlan({ taskIds: [task_id] });
|
|
@@ -1507,6 +1874,7 @@ server.registerTool(
|
|
|
1507
1874
|
branch: targetBranch,
|
|
1508
1875
|
landed_head: task.landed_head,
|
|
1509
1876
|
remote_head: remoteHead,
|
|
1877
|
+
artifact_id: artifact.id,
|
|
1510
1878
|
push_verified_at: now,
|
|
1511
1879
|
cleanup_plan: { id: cleanupPlan.id, summary: cleanupPlan.summary, expires_at: cleanupPlan.expires_at, next_step: "Review SAFE items, then call apply_cleanup with their item IDs; cleanup is never automatic." }
|
|
1512
1880
|
});
|
|
@@ -1558,34 +1926,7 @@ server.registerTool(
|
|
|
1558
1926
|
const plan = await getCleanupPlan(plan_id);
|
|
1559
1927
|
if (!plan) return textResult({ error: "cleanup_plan_not_found", plan_id });
|
|
1560
1928
|
if (Date.parse(plan.expires_at) <= Date.now()) return textResult({ error: "cleanup_plan_expired", plan_id, expires_at: plan.expires_at });
|
|
1561
|
-
|
|
1562
|
-
if (selected.length !== item_ids.length) return textResult({ error: "cleanup_plan_item_not_found", plan_id });
|
|
1563
|
-
const applied = [];
|
|
1564
|
-
const skipped = [];
|
|
1565
|
-
for (const item of selected) {
|
|
1566
|
-
if (item.verdict !== "safe") {
|
|
1567
|
-
skipped.push({ item_id: item.id, task_id: item.task_id, reason: "only SAFE plan items may be applied" });
|
|
1568
|
-
continue;
|
|
1569
|
-
}
|
|
1570
|
-
const task = await getTask(item.task_id);
|
|
1571
|
-
if (!task) {
|
|
1572
|
-
skipped.push({ item_id: item.id, task_id: item.task_id, reason: "task no longer exists" });
|
|
1573
|
-
continue;
|
|
1574
|
-
}
|
|
1575
|
-
try {
|
|
1576
|
-
await removePlannedWorktree(task, item.fingerprint);
|
|
1577
|
-
const now = await markCleanupPlanItemApplied(item.id);
|
|
1578
|
-
await updateWorkItemDelivery(task.id, "cleanup_removed");
|
|
1579
|
-
await appendTaskEvent(task.id, { type: "supervisor.cleanup_removed", plan_id, item_id: item.id, removed_at: now, retained: ["branch", "task", "events", "jsonl", "artifacts"] }, {
|
|
1580
|
-
runId: runIdFor(task.id, task.run_count ?? 1),
|
|
1581
|
-
actor: "supervisor"
|
|
1582
|
-
});
|
|
1583
|
-
applied.push({ item_id: item.id, task_id: task.id, worktree_path: task.worktree_path, removed_at: now });
|
|
1584
|
-
} catch (error) {
|
|
1585
|
-
skipped.push({ item_id: item.id, task_id: item.task_id, reason: error.message.split("\n")[0] });
|
|
1586
|
-
}
|
|
1587
|
-
}
|
|
1588
|
-
return textResult({ plan_id, applied, skipped, retained: ["branch", "task", "events", "jsonl", "artifacts"] });
|
|
1929
|
+
return textResult(await applyCleanupPlan({ plan, itemIds: item_ids, actor: "main_thread" }));
|
|
1589
1930
|
}
|
|
1590
1931
|
);
|
|
1591
1932
|
|
package/src/overview-delta.js
CHANGED
|
@@ -4,22 +4,54 @@ function readyToLand(task) {
|
|
|
4
4
|
return task.status === "completed" && task.exit_code === 0 && (!task.acceptance_results || task.acceptance_results.passed === true) && !task.landed_at;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
function readyToClean(task) {
|
|
7
|
+
function readyToClean(task, readyToCleanTaskIds = null) {
|
|
8
|
+
if (readyToCleanTaskIds) return readyToCleanTaskIds.has(task.id);
|
|
8
9
|
return task.push_verified_at && ["cleanup_eligible"].includes(task.delivery_state);
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
function attentionReason(task) {
|
|
13
|
+
if (task.attention_reason) return String(task.attention_reason).slice(0, 180);
|
|
14
|
+
if (task.acceptance_results?.passed === false) return "acceptance_failed";
|
|
15
|
+
if (isGoalNeedingAttention(task.goal_status)) return `goal_${task.goal_status}`;
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function nextAction(task, { attention, readyToLand, readyToClean }) {
|
|
20
|
+
if (attention) return "inspect the worker evidence and resolve the recorded blocker";
|
|
21
|
+
if (task.delivery_state === "cleanup_eligible" && !readyToClean) return "rerun cleanup_plan; the previous cleanup proof is no longer current";
|
|
22
|
+
if (readyToLand) return "review the diff and acceptance, then land the worker";
|
|
23
|
+
if (readyToClean) return "review the cleanup plan item, then explicitly apply it";
|
|
24
|
+
if (task.status === "completed" && !task.landed_at) return "review the worker result and decide whether to land it";
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function buildOverviewDelta(tasks, cursor = {}, { readyToCleanTaskIds = null } = {}) {
|
|
12
29
|
const active = tasks.filter((task) => ACTIVE_STATUSES.has(task.status));
|
|
13
30
|
const attention = tasks.filter((task) => isGoalNeedingAttention(task.goal_status) || task.attention_reason || task.acceptance_results?.passed === false);
|
|
14
31
|
const land = tasks.filter(readyToLand);
|
|
15
|
-
const clean = tasks.filter(readyToClean);
|
|
32
|
+
const clean = tasks.filter((task) => readyToClean(task, readyToCleanTaskIds));
|
|
16
33
|
const nextCursor = {};
|
|
17
34
|
const changes = [];
|
|
18
35
|
for (const task of tasks) {
|
|
19
|
-
const
|
|
36
|
+
const isAttention = attention.some((item) => item.id === task.id);
|
|
37
|
+
const isReadyToLand = land.some((item) => item.id === task.id);
|
|
38
|
+
const isReadyToClean = clean.some((item) => item.id === task.id);
|
|
39
|
+
const reason = attentionReason(task);
|
|
40
|
+
const fingerprint = JSON.stringify([task.run_count ?? 0, task.status, task.exit_code ?? null, task.attention_reason ?? null, task.landed_head ?? null, task.push_verified_at ?? null, task.delivery_state ?? null, isReadyToClean, reason, task.updated_at]);
|
|
20
41
|
nextCursor[task.id] = fingerprint;
|
|
21
42
|
if (cursor[task.id] !== fingerprint) {
|
|
22
|
-
changes.push({
|
|
43
|
+
changes.push({
|
|
44
|
+
id: task.id,
|
|
45
|
+
title: task.title ?? task.id,
|
|
46
|
+
status: task.status,
|
|
47
|
+
delivery_state: task.delivery_state ?? "draft",
|
|
48
|
+
attention: isAttention,
|
|
49
|
+
attention_reason: reason,
|
|
50
|
+
ready_to_land: isReadyToLand,
|
|
51
|
+
ready_to_clean: isReadyToClean,
|
|
52
|
+
next_action: nextAction(task, { attention: isAttention, readyToLand: isReadyToLand, readyToClean: isReadyToClean }),
|
|
53
|
+
updated_at: task.updated_at
|
|
54
|
+
});
|
|
23
55
|
}
|
|
24
56
|
}
|
|
25
57
|
return {
|
package/src/paths.js
CHANGED
|
@@ -19,4 +19,6 @@ export const goalsDbPath = join(codexHome, "goals_1.sqlite");
|
|
|
19
19
|
export const dataDir = join(supervisorRoot, "data");
|
|
20
20
|
export const dbPath = join(dataDir, "supervisor.sqlite");
|
|
21
21
|
export const runsDir = join(dataDir, "runs");
|
|
22
|
+
export const artifactsDir = join(dataDir, "artifacts");
|
|
22
23
|
export const worktreesDir = join(supervisorRoot, "worktrees");
|
|
24
|
+
export const scratchDir = join(supervisorRoot, "scratch");
|
package/src/prompt.js
CHANGED
|
@@ -50,7 +50,7 @@ export const REPORT_SECTIONS = ["Result", "Verification", "Not done / risks"];
|
|
|
50
50
|
// is stated. A worker is not always an editor: a read-only one can only read,
|
|
51
51
|
// and one with no ownedPaths lands nothing, so both are told what their shell
|
|
52
52
|
// may do instead of being told to use apply_patch they cannot use.
|
|
53
|
-
export function buildGuardPreamble({ sandbox, ownedPaths = [], allowedCommands = [], forbid = [], networkAccess = false } = {}) {
|
|
53
|
+
export function buildGuardPreamble({ sandbox, ownedPaths = [], allowedCommands = [], forbid = [], networkAccess = false, workspaceKind = null } = {}) {
|
|
54
54
|
const forbidden = JSON.stringify(forbid);
|
|
55
55
|
if (sandbox === "read-only") {
|
|
56
56
|
return [
|
|
@@ -61,9 +61,12 @@ export function buildGuardPreamble({ sandbox, ownedPaths = [], allowedCommands =
|
|
|
61
61
|
].join(" ");
|
|
62
62
|
}
|
|
63
63
|
if (Array.isArray(ownedPaths) && ownedPaths.length === 0) {
|
|
64
|
+
const location = workspaceKind === "scratch"
|
|
65
|
+
? "Its execution directory is a supervisor-managed scratch directory, not the user's source directory"
|
|
66
|
+
: "Its worktree is a scratch copy";
|
|
64
67
|
return [
|
|
65
68
|
"Runtime supervisor guard: this worker lands nothing: no ownedPaths means nothing it writes is ever merged into the project.",
|
|
66
|
-
|
|
69
|
+
`${location}, so the shell is unrestricted apart from the red lines; keep notes and downloads inside it.`,
|
|
67
70
|
networkAccess ? "Network is available." : "There is no network in this sandbox; ask for it instead of retrying a failing fetch.",
|
|
68
71
|
`Forbidden: ${forbidden}.`,
|
|
69
72
|
"Report what you found and name the files a writer would have to change."
|