codex-supervisor-mcp 0.14.0 → 1.1.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 +37 -45
- package/README.md +37 -45
- package/package.json +2 -2
- package/skills/codex-supervisor/SKILL.md +88 -91
- package/src/app/acceptance.js +5 -5
- package/src/app/auto-cleanup.js +6 -5
- package/src/app/cleanup-facts.js +21 -16
- package/src/app/cleanup-plan.js +22 -20
- 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 +11 -6
- package/src/app/worktree-setup.js +58 -16
- package/src/domain/acceptance-spec.js +1 -1
- package/src/domain/failure-class.js +36 -4
- package/src/domain/prompt.js +7 -7
- package/src/domain/status.js +15 -2
- 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/domain/worker-preflight.js +2 -1
- package/src/infra/cleanup-hint.js +1 -1
- package/src/infra/crash-guard.js +44 -0
- package/src/infra/external-output.js +2 -2
- package/src/infra/git.js +35 -4
- package/src/infra/sandbox-roots.js +1 -1
- package/src/infra/store/event-body.js +82 -0
- package/src/infra/store/events.js +9 -6
- package/src/infra/store/reconcile.js +4 -3
- package/src/infra/store/tasks.js +15 -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/bin/web-server.js +2 -0
- 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 +106 -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 +13 -17
- package/src/interface/mcp/server.js +20 -50
- 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 +5 -2
- package/src/run-host/entry.js +3 -0
- package/src/run-host/finalize.js +8 -1
- package/src/run-host/launch.js +7 -7
- package/src/run-host/live-run.js +2 -0
- package/src/run-host/streams.js +28 -5
- package/src/run-host/track.js +5 -2
- package/src/runners/codex/tool-guard.js +6 -6
- package/web/dist/assets/{index-fJQbspTY.js → index-BnV-AYYI.js} +1 -1
- package/web/dist/assets/index-f8esISCp.css +2 -0
- package/web/dist/index.html +2 -2
- 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/web/dist/assets/index-DI1hLMxE.css +0 -2
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { sweepCleanup } from "../../../app/auto-cleanup.js";
|
|
4
|
+
import { recoverEligibleRuns } from "../../../app/resume.js";
|
|
5
|
+
import { ACTIVE_STATUSES, TASK_STATUSES } from "../../../domain/status.js";
|
|
6
|
+
import { collectWorkerChanges } from "../../../domain/worker-changes.js";
|
|
7
|
+
import { cleanupHint } from "../../../infra/cleanup-hint.js";
|
|
8
|
+
import { reconcileDetachedActiveTasks } from "../../../infra/store/reconcile.js";
|
|
9
|
+
import { readObserverCursor, readTasks, writeObserverCursor } from "../../../infra/store/tasks.js";
|
|
10
|
+
import { waitCodexWorkersOp } from "../handlers/wait.js";
|
|
11
|
+
import { packageVersion } from "../meta.js";
|
|
12
|
+
import { updateField, updateState } from "../update-state.js";
|
|
13
|
+
import { buildOverview } from "../views/overview.js";
|
|
14
|
+
import { defineTool, run } from "./run.js";
|
|
15
|
+
|
|
16
|
+
// Polls from one process run one at a time: recovery and cleanup must not overlap themselves.
|
|
17
|
+
let pollChain = Promise.resolve();
|
|
18
|
+
|
|
19
|
+
// With a cursor this is the loop tick: it reports what changed and does the
|
|
20
|
+
// housekeeping a loop is for (one recovery of a dead first run, cleanup).
|
|
21
|
+
// Without one it is a plain read of the table and starts nothing.
|
|
22
|
+
async function pollOnce({ cursor, status, limit }) {
|
|
23
|
+
await reconcileDetachedActiveTasks();
|
|
24
|
+
if (cursor) {
|
|
25
|
+
const recoveries = await recoverEligibleRuns();
|
|
26
|
+
const cleaned = await sweepCleanup();
|
|
27
|
+
const cleanup = await cleanupHint();
|
|
28
|
+
const tasks = await readTasks();
|
|
29
|
+
const changes = collectWorkerChanges(tasks, await readObserverCursor(cursor));
|
|
30
|
+
await writeObserverCursor(cursor, changes.cursor);
|
|
31
|
+
return {
|
|
32
|
+
generated_at: new Date().toISOString(),
|
|
33
|
+
quiet: changes.quiet && recoveries.length === 0 && cleaned.length === 0,
|
|
34
|
+
active: tasks.filter((task) => ACTIVE_STATUSES.has(task.status)).length,
|
|
35
|
+
transitions: changes.transitions,
|
|
36
|
+
attention: changes.attention,
|
|
37
|
+
recoveries,
|
|
38
|
+
...(cleaned.length ? { cleaned } : {}),
|
|
39
|
+
...(cleanup ? { cleanup } : {}),
|
|
40
|
+
next_cursor: cursor
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const tasks = await readTasks();
|
|
44
|
+
// The cursor handed out here makes the next poll report only what changes from now on.
|
|
45
|
+
const token = `poll-${randomUUID().slice(0, 12)}`;
|
|
46
|
+
await writeObserverCursor(token, collectWorkerChanges(tasks, {}).cursor);
|
|
47
|
+
const shown = (status ? tasks.filter((task) => task.status === status) : tasks).slice(-limit);
|
|
48
|
+
const update = updateField() ?? { update_available: false, installed_version: packageVersion, checked: updateState?.source ?? "pending" };
|
|
49
|
+
return buildOverview(shown, { version: packageVersion, update, next_cursor: token });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const pollWorkersTool = defineTool("poll_workers", {
|
|
53
|
+
title: "See what the workers are doing",
|
|
54
|
+
description: "The main thread's read. Without cursor: a compact table of every worker and a next_cursor. With that cursor: only what happened since, as transitions (finished, failed, needs attention) with the next step; quiet when nothing did. A poll with a cursor also recovers a dead first run once and removes safe worktrees (listed under cleaned). Call it from a loop.",
|
|
55
|
+
inputSchema: {
|
|
56
|
+
cursor: z.string().optional().describe("next_cursor from the previous poll"),
|
|
57
|
+
status: z.enum(TASK_STATUSES).optional().describe("Filter the full table"),
|
|
58
|
+
limit: z.number().int().min(1).max(200).default(50).describe("Rows in the full table, newest last")
|
|
59
|
+
}
|
|
60
|
+
}, (args) => {
|
|
61
|
+
const poll = pollChain.then(() => pollOnce(args));
|
|
62
|
+
pollChain = poll.catch(() => {});
|
|
63
|
+
return poll;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
export const waitWorkersTool = defineTool("wait_workers", {
|
|
67
|
+
title: "Wait for workers to finish",
|
|
68
|
+
description: "Block until the given workers settle (process exited and acceptance run), then return one row each. A call waits 60 seconds at most and says so in timed_out; call again with the same ids. allow_long_wait lifts the cap only when the client's own tool timeout is known to be longer.",
|
|
69
|
+
inputSchema: {
|
|
70
|
+
task_ids: z.array(z.string()).min(1),
|
|
71
|
+
mode: z.enum(["any", "all"]).default("all"),
|
|
72
|
+
timeout_ms: z.number().int().min(1000).max(21600000).optional(),
|
|
73
|
+
allow_long_wait: z.boolean().default(false),
|
|
74
|
+
emit_progress: z.boolean().default(false).describe("Send progress notifications while waiting"),
|
|
75
|
+
compact: z.boolean().optional().describe("One short row per worker; the default unless include_events"),
|
|
76
|
+
include_events: z.boolean().default(false),
|
|
77
|
+
event_limit: z.number().int().min(1).max(50).default(10),
|
|
78
|
+
poll_ms: z.number().int().min(250).max(10000).optional()
|
|
79
|
+
}
|
|
80
|
+
}, (args, extra) => run(waitCodexWorkersOp, {
|
|
81
|
+
task_ids: args.task_ids, mode: args.mode, timeoutMs: args.timeout_ms ?? 60000, allowLongWait: args.allow_long_wait, emitProgress: args.emit_progress,
|
|
82
|
+
compact: args.compact, includeEvents: args.include_events, eventLimit: args.event_limit,
|
|
83
|
+
pollMs: args.poll_ms
|
|
84
|
+
}, extra));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { branchOf } from "../../../domain/worker-branch.js";
|
|
1
2
|
import { acceptanceVerdict } from "../../../app/acceptance.js";
|
|
2
3
|
import { classifyFailure } from "../../../domain/failure-class.js";
|
|
3
4
|
import { ACTIVE_STATUSES, isGoalNeedingAttention } from "../../../domain/status.js";
|
|
@@ -11,14 +12,14 @@ import { clip } from "../result.js";
|
|
|
11
12
|
// writes a whole file. Returning it whole put tens of thousands of characters
|
|
12
13
|
// into every wait response, which then blew past the client's MCP output cap
|
|
13
14
|
// and came back a second time as a notification. The full command stays in
|
|
14
|
-
// current_command / commands and is readable through
|
|
15
|
+
// current_command / commands and is readable through get_worker (include events).
|
|
15
16
|
export const ACTION_PREVIEW_CHARS = 300;
|
|
16
17
|
const COMMAND_PREVIEW_CHARS = 300;
|
|
17
18
|
const COMMAND_TAIL = 20;
|
|
18
19
|
const PROMPT_PREVIEW_CHARS = 300;
|
|
19
20
|
// The single-worker status read is the drill-in for one worker, so its copy of
|
|
20
21
|
// the last message stays much larger than the overview's 400. The full report
|
|
21
|
-
// is still
|
|
22
|
+
// is still get_worker (include result)'s job.
|
|
22
23
|
const STATUS_MESSAGE_CHARS = 4000;
|
|
23
24
|
|
|
24
25
|
// Codex emits nothing while a command runs and nothing while the model
|
|
@@ -70,7 +71,7 @@ export function compactLiveness(task) {
|
|
|
70
71
|
};
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
// The acceptance verdict as
|
|
74
|
+
// The acceptance verdict as get_worker (include result) reports it, with the one
|
|
74
75
|
// contradiction a tool can see spelled out: checks passed, worker says
|
|
75
76
|
// otherwise (the "it was never built" case, where it was).
|
|
76
77
|
export function acceptanceView(task, behind) {
|
|
@@ -99,9 +100,9 @@ export function acceptanceView(task, behind) {
|
|
|
99
100
|
const verification = summarizeVerification(task);
|
|
100
101
|
const workerSaysNo = task.status === "failed" || isGoalNeedingAttention(task.goal_status) || verification.last_command_failed;
|
|
101
102
|
if (workerSaysNo) view.next_step = "the checks passed but the worker reports otherwise; trust the checks and read the diff";
|
|
102
|
-
else if (view.stale) view.next_step = "the checks passed on the old base and the project has moved since; resume with
|
|
103
|
+
else if (view.stale) view.next_step = "the checks passed on the old base and the project has moved since; resume with rebase_onto to re-run them on current code before landing";
|
|
103
104
|
} else if (view.status === "running") {
|
|
104
|
-
view.next_step = "acceptance is still running in the supervisor;
|
|
105
|
+
view.next_step = "acceptance is still running in the supervisor; wait_workers returns when it is done";
|
|
105
106
|
} else if (view.status === "interrupted") {
|
|
106
107
|
view.next_step = "the supervisor exited while running acceptance; resume the worker (or cancel and redispatch) to run it again";
|
|
107
108
|
} else if (view.status === "cancelled") {
|
|
@@ -188,7 +189,7 @@ export function statusView(task, { includePrompt, promptMaxChars }) {
|
|
|
188
189
|
// events - back to the caller on every call. Dispatching eleven workers made
|
|
189
190
|
// the main thread pay for its own instructions eleven times, and pushed the
|
|
190
191
|
// result into the client's MCP output cap. Read the rest per worker with
|
|
191
|
-
//
|
|
192
|
+
// get_worker / get_worker (include result) when you actually need it.
|
|
192
193
|
export function receipt(task) {
|
|
193
194
|
return {
|
|
194
195
|
id: task.id,
|
|
@@ -200,7 +201,7 @@ export function receipt(task) {
|
|
|
200
201
|
project_root: task.project_root,
|
|
201
202
|
workspace_kind: task.workspace_kind ?? "legacy",
|
|
202
203
|
worktree_path: task.worktree_path,
|
|
203
|
-
branch: task.worktree_path ?
|
|
204
|
+
branch: task.worktree_path ? branchOf(task) : null,
|
|
204
205
|
base_commit: task.base_commit ?? null,
|
|
205
206
|
sandbox: task.sandbox,
|
|
206
207
|
model: task.model,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// What the board shows: session and worker rows built from the store, read-only.
|
|
2
|
+
import { branchOf } from "../../domain/worker-branch.js";
|
|
2
3
|
import { ACTIVE_STATUSES } from "../../domain/status.js";
|
|
3
4
|
import { supervisorRoot } from "../../infra/paths.js";
|
|
5
|
+
import { restoreEventBodies } from "../../infra/store/event-body.js";
|
|
4
6
|
import { listTaskEventKinds, readAgentMessages, readTaskEvents } from "../../infra/store/events.js";
|
|
5
7
|
import { reconcileDetachedActiveTasks } from "../../infra/store/reconcile.js";
|
|
6
8
|
import { readSessions } from "../../infra/store/sessions.js";
|
|
@@ -40,7 +42,7 @@ function workerRow(task) {
|
|
|
40
42
|
sandbox: task.sandbox,
|
|
41
43
|
project_root: task.project_root,
|
|
42
44
|
worktree_path: task.worktree_path ?? null,
|
|
43
|
-
branch: task.worktree_path ?
|
|
45
|
+
branch: task.worktree_path ? branchOf(task) : null,
|
|
44
46
|
base_commit: task.base_commit ?? null,
|
|
45
47
|
owned_paths: task.owned_paths ?? [],
|
|
46
48
|
depends_on: task.depends_on ?? [],
|
|
@@ -220,5 +222,6 @@ export async function worker(taskId) {
|
|
|
220
222
|
export async function events(taskId, url) {
|
|
221
223
|
const limit = Math.min(1000, Math.max(1, Number(url.searchParams.get("limit") ?? 150)));
|
|
222
224
|
const kinds = url.searchParams.get("kinds")?.split(",").filter(Boolean) ?? null;
|
|
223
|
-
|
|
225
|
+
const task = await getTask(taskId);
|
|
226
|
+
return { task_id: taskId, events: await restoreEventBodies(await readTaskEvents(taskId, limit, kinds), task?.run_log ?? null) };
|
|
224
227
|
}
|
package/src/run-host/entry.js
CHANGED
|
@@ -4,8 +4,11 @@
|
|
|
4
4
|
import "../app/compose.js";
|
|
5
5
|
import { failedStart } from "../app/run-state.js";
|
|
6
6
|
import { upsertTask } from "../infra/store/tasks.js";
|
|
7
|
+
import { installCrashGuard } from "../infra/crash-guard.js";
|
|
7
8
|
import { trackRunInHost } from "./track.js";
|
|
8
9
|
|
|
10
|
+
installCrashGuard("run-host", { exitOnRejection: true });
|
|
11
|
+
|
|
9
12
|
process.once("message", async (job) => {
|
|
10
13
|
const keepAlive = setInterval(() => {}, 1000);
|
|
11
14
|
let result;
|
package/src/run-host/finalize.js
CHANGED
|
@@ -27,6 +27,8 @@ function terminalStatus(run, stored, code, signal) {
|
|
|
27
27
|
if (stored && TERMINAL_STATUSES.has(stored.status) && stored.status !== live.status) return stored.status;
|
|
28
28
|
if (run.terminalEvent && TERMINAL_STATUSES.has(live.status)) return live.status;
|
|
29
29
|
if (cancelRequested) return "cancelled";
|
|
30
|
+
// The supervisor stopped it for running out of time; the signal was its own.
|
|
31
|
+
if (run.quotaReason) return "timed_out";
|
|
30
32
|
// Killed by a signal nobody asked for: the worker did not fail, it
|
|
31
33
|
// vanished. Re-running is the fix, so it is reported as lost.
|
|
32
34
|
if (signal) return "lost";
|
|
@@ -117,8 +119,13 @@ async function attachEvidence(run, next) {
|
|
|
117
119
|
})).digest("hex");
|
|
118
120
|
}
|
|
119
121
|
|
|
120
|
-
|
|
122
|
+
// "The evidence could not be read" outranks what the evidence would have
|
|
123
|
+
// said: no_work and invalid_report are both conclusions drawn from it.
|
|
124
|
+
const UNVERIFIED = new Set(["external_output_unverified", "workspace_manifest_unverified"]);
|
|
125
|
+
|
|
126
|
+
export function flagAttention(run, next, status, code) {
|
|
121
127
|
const { live } = run;
|
|
128
|
+
if (UNVERIFIED.has(next.attention_reason)) return;
|
|
122
129
|
if (status === "completed" && code === 0 && live.sandbox !== "read-only"
|
|
123
130
|
&& !next.run_evidence.output_changed && next.run_evidence.output_changed !== null
|
|
124
131
|
&& live.commands.length === 0 && !run.reportOnlyRecovery) {
|
package/src/run-host/launch.js
CHANGED
|
@@ -23,8 +23,8 @@ function guardPolicyFor(record, externalBefore, outputSchema) {
|
|
|
23
23
|
// This CLI writes only data/stages/<this task>.json. It is part of the
|
|
24
24
|
// runtime contract, not an ad-hoc command the model must declare. The
|
|
25
25
|
// task id comes from the injected environment; stage.js has no override.
|
|
26
|
-
'node "$
|
|
27
|
-
'node "$
|
|
26
|
+
'node "$AGENT_SUPERVISOR_STAGE_CLI"*',
|
|
27
|
+
'node "$AGENT_SUPERVISOR_ACCEPTANCE_CLI"*'
|
|
28
28
|
] };
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -54,10 +54,10 @@ export function buildLaunch({ record, args, prompt, outputSchema, externalBefore
|
|
|
54
54
|
const configArgs = configArgsFor(record, externalBefore, outputSchema);
|
|
55
55
|
// Insert before the prompt/session positional arguments for exec/resume.
|
|
56
56
|
const guardedArgs = [...args.slice(0, -1), ...configArgs, args.at(-1)];
|
|
57
|
-
const env = () => withWorkerToolPath({ ...process.env, NO_COLOR: "1",
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
const env = () => withWorkerToolPath({ ...process.env, NO_COLOR: "1", AGENT_SUPERVISOR_TASK_ID: record.id,
|
|
58
|
+
AGENT_SUPERVISOR_BASE_COMMIT: record.base_commit ?? "",
|
|
59
|
+
AGENT_SUPERVISOR_STAGE_CLI: stageCli,
|
|
60
|
+
AGENT_SUPERVISOR_ACCEPTANCE_CLI: acceptanceCli,
|
|
61
|
+
AGENT_SUPERVISOR_RUN: String((record.run_count ?? 0) + 1), AGENT_SUPERVISOR_GUARD_POLICY: JSON.stringify(guardPolicy) });
|
|
62
62
|
return { guardedArgs, prompt: `${buildGuardPreamble(guardPolicy)}\n\n${prompt}`, env };
|
|
63
63
|
}
|
package/src/run-host/live-run.js
CHANGED
|
@@ -21,6 +21,8 @@ export function startingRow(record, child, outputSchema, now) {
|
|
|
21
21
|
exit_code: null,
|
|
22
22
|
signal: null,
|
|
23
23
|
error: null,
|
|
24
|
+
// What an earlier run wrote to stderr says nothing about how this one ends.
|
|
25
|
+
stderr_tail: null,
|
|
24
26
|
cancel_requested_at: null,
|
|
25
27
|
acceptance_results: null,
|
|
26
28
|
attention_reason: null,
|
package/src/run-host/streams.js
CHANGED
|
@@ -5,19 +5,40 @@ import { appendTaskEvents } from "../infra/store/events.js";
|
|
|
5
5
|
import { codexRunner } from "../runners/codex/adapter.js";
|
|
6
6
|
import { persist } from "./live-run.js";
|
|
7
7
|
|
|
8
|
+
const STDERR_KEEP = 64 * 1024;
|
|
9
|
+
|
|
10
|
+
// Resolves once the line is handed to the file, false when it was not.
|
|
11
|
+
function logLine(run, text) {
|
|
12
|
+
const offset = run.logOffset;
|
|
13
|
+
run.logOffset += Buffer.byteLength(text, "utf8");
|
|
14
|
+
const written = new Promise((resolveWrite) => {
|
|
15
|
+
run.logStream.write(text, (error) => {
|
|
16
|
+
if (error) run.logFailed = true;
|
|
17
|
+
resolveWrite(!error);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
return { offset, written };
|
|
21
|
+
}
|
|
22
|
+
|
|
8
23
|
async function handleLines(run, lines) {
|
|
9
24
|
const events = [];
|
|
25
|
+
const logged = [];
|
|
10
26
|
for (const line of lines) {
|
|
11
27
|
try {
|
|
12
28
|
const event = JSON.parse(line);
|
|
13
|
-
|
|
29
|
+
logged.push(logLine(run, `${JSON.stringify(event)}\n`));
|
|
14
30
|
events.push(event);
|
|
15
31
|
} catch (error) {
|
|
16
|
-
run
|
|
32
|
+
logLine(run, `${JSON.stringify({ type: "supervisor.parse_error", line, error: error.message })}\n`);
|
|
17
33
|
}
|
|
18
34
|
}
|
|
19
35
|
if (events.length === 0) return;
|
|
20
|
-
|
|
36
|
+
// The store keeps only a clipped copy of a large event when the log has the
|
|
37
|
+
// whole of it, so the log comes first and a failed write keeps the event whole.
|
|
38
|
+
const inLog = (await Promise.all(logged.map((entry) => entry.written))).every(Boolean) && !run.logFailed;
|
|
39
|
+
const storedEvents = await appendTaskEvents(run.record.id, events, {
|
|
40
|
+
runId: run.runId, actor: "codex", bodyInLog: inLog, logOffsets: logged.map((entry) => entry.offset)
|
|
41
|
+
});
|
|
21
42
|
let next = run.live;
|
|
22
43
|
for (const [index, event] of events.entries()) {
|
|
23
44
|
if (event.type === "item.completed" && event.item?.type === "agent_message") {
|
|
@@ -59,9 +80,11 @@ export function attachStreams(run, earlyOutput) {
|
|
|
59
80
|
child.stdout.on("data", handleStdoutChunk);
|
|
60
81
|
child.stdout.on("error", () => {});
|
|
61
82
|
|
|
62
|
-
run.stderr = earlyOutput.stderr.map((chunk) => chunk.toString("utf8")).join("");
|
|
83
|
+
run.stderr = earlyOutput.stderr.map((chunk) => chunk.toString("utf8")).join("").slice(-STDERR_KEEP);
|
|
63
84
|
child.stderr.on("data", (chunk) => {
|
|
64
|
-
|
|
85
|
+
// Only the tail is ever used, so only the tail is kept: a worker that
|
|
86
|
+
// logs for hours must not grow this process without bound.
|
|
87
|
+
run.stderr = (run.stderr + chunk.toString("utf8")).slice(-STDERR_KEEP);
|
|
65
88
|
persist(run, { ...run.live, stderr_tail: run.stderr.slice(-4000), updated_at: new Date().toISOString() });
|
|
66
89
|
});
|
|
67
90
|
child.stderr.on("error", () => {});
|
package/src/run-host/track.js
CHANGED
|
@@ -14,7 +14,7 @@ import { finalizeChild } from "./finalize.js";
|
|
|
14
14
|
import { buildLaunch } from "./launch.js";
|
|
15
15
|
import { persist, startingRow, watchQuota } from "./live-run.js";
|
|
16
16
|
import { attachStreams } from "./streams.js";
|
|
17
|
-
import { createWriteStream } from "node:fs";
|
|
17
|
+
import { createWriteStream, statSync } from "node:fs";
|
|
18
18
|
|
|
19
19
|
// Spawn can fail either by throwing synchronously, or by emitting "error"
|
|
20
20
|
// instead of "spawn". Both paths are handled so a bad CODEX_BIN marks the task
|
|
@@ -108,8 +108,11 @@ export async function trackRunInHost({ record, args, prompt, logPath, spawnOptio
|
|
|
108
108
|
run.quotaWatch = watchQuota(run, now);
|
|
109
109
|
await persist(run, run.live);
|
|
110
110
|
run.runId = await ensureRunRecord(run.live, run.live.run_count);
|
|
111
|
+
// Where the next line will start, so a stored event can say where its full body is.
|
|
112
|
+
run.logOffset = statSync(logPath, { throwIfNoEntry: false })?.size ?? 0;
|
|
111
113
|
run.logStream = createWriteStream(logPath, { flags: "a" });
|
|
112
|
-
|
|
114
|
+
// A log that cannot be written is not the place to keep the only copy of anything.
|
|
115
|
+
run.logStream.on("error", () => { run.logFailed = true; });
|
|
113
116
|
child.stdin.on("error", (error) => { noteStdinFailure(run, error); });
|
|
114
117
|
attachStreams(run, earlyOutput);
|
|
115
118
|
|
|
@@ -54,13 +54,13 @@ function judgePatch(paths, { event, policy, readOnly, deny }) {
|
|
|
54
54
|
if (readOnly) return deny("read-only worker: the sandbox denies every write, including the temp directory; report the change instead of editing");
|
|
55
55
|
if (!paths.length) return deny("patch has no recognized file paths");
|
|
56
56
|
try {
|
|
57
|
-
// With no
|
|
57
|
+
// With no owned_paths the worker may still keep scratch notes, but only
|
|
58
58
|
// inside its own worktree, which is never landed.
|
|
59
59
|
const owners = policy.ownedPaths.length ? policy.ownedPaths.map(canonical) : [canonical(policy.worktree ?? policy.cwd)];
|
|
60
60
|
for (const path of paths) {
|
|
61
61
|
const target = canonical(resolve(event.cwd ?? policy.cwd, path));
|
|
62
62
|
if (!owners.some((owner) => inside(target, owner))) return deny(policy.ownedPaths.length
|
|
63
|
-
? "outside
|
|
63
|
+
? "outside owned_paths: " + path
|
|
64
64
|
: "outside this worker's own worktree: " + path);
|
|
65
65
|
}
|
|
66
66
|
} catch (error) { return deny("cannot prove patch ownership: " + error.message); }
|
|
@@ -105,9 +105,9 @@ export function evaluateToolUse(event, policy) {
|
|
|
105
105
|
const deny = (reason) => ({ allow: false, reason });
|
|
106
106
|
if (!policy || !Array.isArray(policy.ownedPaths) || !policy.cwd) return deny("missing supervisor guard policy");
|
|
107
107
|
// Who needs the shell allowlist? It exists to stop a writing worker from
|
|
108
|
-
// going around
|
|
108
|
+
// going around owned_paths. Two shapes have no landable write boundary left:
|
|
109
109
|
// the read-only sandbox denies every file write, temp directory included, and
|
|
110
|
-
// a workspace-write worker with no
|
|
110
|
+
// a workspace-write worker with no owned_paths can only write its own throwaway
|
|
111
111
|
// worktree, its temp dir and the OS cache dir while land refuses everything it
|
|
112
112
|
// produced. Both are what a research worker looks like, and the allowlist would
|
|
113
113
|
// only stop it from running curl, gh or python.
|
|
@@ -146,7 +146,7 @@ export function evaluateToolUse(event, policy) {
|
|
|
146
146
|
const shellPatch = patchFromHeredoc(command);
|
|
147
147
|
if (shellPatch) return judgePatch(patchPaths(shellPatch), { event, policy, readOnly, deny });
|
|
148
148
|
// Reading is never exclusive: no branch below looks at another worker's
|
|
149
|
-
//
|
|
149
|
+
// owned_paths, so two workers may read the same file at the same time.
|
|
150
150
|
if (landsNothing) return { allow: true, reason: readOnly
|
|
151
151
|
? "read-only sandbox: every write is denied by the OS, so shell commands need no allowlist"
|
|
152
152
|
: "no landable path: writes stay in this worker's own worktree" };
|
|
@@ -176,7 +176,7 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
|
176
176
|
let input = "";
|
|
177
177
|
for await (const chunk of process.stdin) input += chunk;
|
|
178
178
|
let decision;
|
|
179
|
-
try { decision = evaluateToolUse(JSON.parse(input), JSON.parse(process.env.
|
|
179
|
+
try { decision = evaluateToolUse(JSON.parse(input), JSON.parse(process.env.AGENT_SUPERVISOR_GUARD_POLICY ?? "null")); }
|
|
180
180
|
catch (error) { decision = { allow: false, reason: "invalid supervisor guard input: " + error.message }; }
|
|
181
181
|
process.stdout.write(JSON.stringify({ hookSpecificOutput: { hookEventName: "PreToolUse",
|
|
182
182
|
permissionDecision: decision.allow ? "allow" : "deny", permissionDecisionReason: decision.reason } }) + "\n");
|