codex-supervisor-mcp 0.13.4 → 0.13.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +101 -297
- package/README.md +99 -310
- package/package.json +24 -63
- package/src/{acceptance.js → app/acceptance.js} +54 -68
- package/src/app/cancel.js +60 -0
- package/src/{cleanup-plan.js → app/cleanup-plan.js} +13 -14
- package/src/app/compose.js +7 -0
- package/src/{context-compiler.js → app/context-compiler.js} +7 -13
- package/src/app/dispatch.js +396 -0
- package/src/app/followup.js +98 -0
- package/src/app/land-chain.js +124 -0
- package/src/app/landing.js +357 -0
- package/src/app/ownership.js +57 -0
- package/src/app/rebase.js +216 -0
- package/src/app/resume.js +164 -0
- package/src/app/run-state.js +26 -0
- package/src/app/settled.js +28 -0
- package/src/{side-chat.js → app/side-chat.js} +79 -266
- package/src/app/sse.js +20 -0
- package/src/app/start-run.js +77 -0
- package/src/app/verify-push.js +119 -0
- package/src/app/worktree-setup.js +176 -0
- package/src/{acceptance-baseline.js → domain/acceptance-baseline.js} +2 -1
- package/src/domain/acceptance-spec.js +30 -0
- package/src/domain/command-outcome.js +6 -0
- package/src/{overview-delta.js → domain/overview-delta.js} +5 -1
- package/src/domain/side-turn-view.js +73 -0
- package/src/{worker-preflight.js → domain/worker-preflight.js} +1 -1
- package/src/infra/git.js +30 -0
- package/src/infra/process.js +59 -0
- package/src/{sandbox-roots.js → infra/sandbox-roots.js} +2 -1
- package/src/{skill-sync.js → infra/skill-sync.js} +1 -1
- package/src/infra/store/db.js +265 -0
- package/src/infra/store/events.js +146 -0
- package/src/infra/store/facts.js +338 -0
- package/src/infra/store/reconcile.js +172 -0
- package/src/infra/store/records.js +160 -0
- package/src/infra/store/runner-readers.js +16 -0
- package/src/infra/store/schema.js +306 -0
- package/src/infra/store/sessions.js +138 -0
- package/src/infra/store/tasks.js +307 -0
- package/src/{auto-update-worker.js → infra/update/auto-update-worker.js} +4 -4
- package/src/{auto-update.js → infra/update/auto-update.js} +3 -4
- package/src/{update-check.js → infra/update/update-check.js} +4 -4
- package/src/{workspace-kind.js → infra/workspace-kind.js} +5 -7
- package/src/{worktree.js → infra/worktree.js} +57 -42
- package/src/{acceptance-cli.js → interface/bin/acceptance-cli.js} +7 -3
- package/src/{cleanup.js → interface/bin/cleanup.js} +3 -2
- package/src/{monitor.jsx → interface/bin/monitor.jsx} +4 -1
- package/src/{setup.js → interface/bin/setup.js} +9 -8
- package/src/{stage.js → interface/bin/stage.js} +1 -1
- package/src/{web-server.js → interface/bin/web-server.js} +2 -2
- package/src/interface/mcp/meta.js +7 -0
- package/src/interface/mcp/result.js +34 -0
- package/src/interface/mcp/schemas.js +24 -0
- package/src/interface/mcp/server.js +94 -0
- package/src/interface/mcp/tools/delivery.js +197 -0
- package/src/interface/mcp/tools/dispatch.js +267 -0
- package/src/interface/mcp/tools/facts.js +239 -0
- package/src/interface/mcp/tools/overview.js +202 -0
- package/src/interface/mcp/tools/poll.js +62 -0
- package/src/interface/mcp/tools/results.js +270 -0
- package/src/interface/mcp/tools/review.js +135 -0
- package/src/interface/mcp/tools/wait.js +145 -0
- package/src/interface/mcp/update-state.js +34 -0
- package/src/interface/mcp/views/overview.js +183 -0
- package/src/interface/mcp/views/task.js +223 -0
- package/src/interface/web/app.js +226 -0
- package/src/interface/web/views.js +224 -0
- package/src/mcp-server.js +3 -2223
- package/src/run-host/entry.js +23 -0
- package/src/run-host/finalize.js +236 -0
- package/src/run-host/launch.js +63 -0
- package/src/run-host/live-run.js +73 -0
- package/src/run-host/outcome-facts.js +61 -0
- package/src/run-host/streams.js +76 -0
- package/src/run-host/track.js +128 -0
- package/src/{runner-adapter.js → runners/codex/adapter.js} +6 -6
- package/src/runners/codex/chat-chunks.js +97 -0
- package/src/{event-parser.js → runners/codex/event-parser.js} +57 -55
- package/src/{goal-store.js → runners/codex/goal-store.js} +2 -2
- package/src/{mcp-config.js → runners/codex/mcp-config.js} +1 -1
- package/src/codex-runner.js +0 -1586
- package/src/landing.js +0 -507
- package/src/task-store.js +0 -1800
- package/src/web-app.js +0 -425
- /package/src/{failure-class.js → domain/failure-class.js} +0 -0
- /package/src/{owned-changes.js → domain/owned-changes.js} +0 -0
- /package/src/{prompt.js → domain/prompt.js} +0 -0
- /package/src/{status.js → domain/status.js} +0 -0
- /package/src/{thread-health.js → domain/thread-health.js} +0 -0
- /package/src/{truncate.js → domain/truncate.js} +0 -0
- /package/src/{worker-changes.js → domain/worker-changes.js} +0 -0
- /package/src/{worker-env.js → domain/worker-env.js} +0 -0
- /package/src/{worker-report.js → domain/worker-report.js} +0 -0
- /package/src/{worker-report.schema.json → domain/worker-report.schema.json} +0 -0
- /package/src/{bin-resolver.js → infra/bin-resolver.js} +0 -0
- /package/src/{cleanup-hint.js → infra/cleanup-hint.js} +0 -0
- /package/src/{external-output.js → infra/external-output.js} +0 -0
- /package/src/{handoff.js → infra/handoff.js} +0 -0
- /package/src/{paths.js → infra/paths.js} +0 -0
- /package/src/{stage-store.js → infra/stage-store.js} +0 -0
- /package/src/{tool-guard.js → runners/codex/tool-guard.js} +0 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { acceptanceVerdict } from "../../../app/acceptance.js";
|
|
2
|
+
import { ACTIVE_STATUSES } from "../../../domain/status.js";
|
|
3
|
+
import { truncateEventStrings } from "../../../domain/truncate.js";
|
|
4
|
+
import { getTasks } from "../../../infra/store/tasks.js";
|
|
5
|
+
import { readTaskEvents } from "../../../infra/store/events.js";
|
|
6
|
+
import { reconcileDetachedActiveTasks } from "../../../infra/store/reconcile.js";
|
|
7
|
+
import { readTaskChanges } from "../../../infra/worktree.js";
|
|
8
|
+
import { clip, sleep, textResult } from "../result.js";
|
|
9
|
+
import { withUpdate } from "../update-state.js";
|
|
10
|
+
import { isSettled } from "../../../app/settled.js";
|
|
11
|
+
import { compactLiveness, summarizeTask } from "../views/task.js";
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
|
|
14
|
+
// Polls until the selected workers settle, the budget runs out or the client
|
|
15
|
+
// cancels. Returns whether the client cancelled.
|
|
16
|
+
async function pollUntilSettled({ task_ids, mode, pollMs, emitProgress }, { startedAt, effectiveTimeoutMs }, extra) {
|
|
17
|
+
const progressToken = extra?._meta?.progressToken;
|
|
18
|
+
let lastProgressAt = -Infinity;
|
|
19
|
+
while (Date.now() - startedAt < effectiveTimeoutMs) {
|
|
20
|
+
if (extra?.signal.aborted) return true;
|
|
21
|
+
await reconcileDetachedActiveTasks();
|
|
22
|
+
const tasks = (await getTasks(task_ids)).filter(Boolean);
|
|
23
|
+
const settledCount = tasks.filter(isSettled).length;
|
|
24
|
+
const isDone = mode === "any" ? settledCount > 0 : settledCount === task_ids.length;
|
|
25
|
+
if (isDone) break;
|
|
26
|
+
const elapsed = Date.now() - startedAt;
|
|
27
|
+
if (emitProgress && progressToken != null && elapsed - lastProgressAt >= 30000) {
|
|
28
|
+
await extra.sendNotification({ method: "notifications/progress", params: {
|
|
29
|
+
progressToken, progress: elapsed, total: effectiveTimeoutMs,
|
|
30
|
+
message: `${settledCount}/${task_ids.length} workers settled; wait budget only`
|
|
31
|
+
} }).catch(() => {});
|
|
32
|
+
lastProgressAt = elapsed;
|
|
33
|
+
}
|
|
34
|
+
await sleep(Math.min(pollMs, Math.max(0, effectiveTimeoutMs - (Date.now() - startedAt))));
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function budgetExhaustedHint(effectiveTimeoutMs) {
|
|
40
|
+
const budgetLabel =
|
|
41
|
+
effectiveTimeoutMs >= 60000
|
|
42
|
+
? `${Math.round(effectiveTimeoutMs / 60000)}-minute`
|
|
43
|
+
: `${Math.round(effectiveTimeoutMs / 1000)}-second`;
|
|
44
|
+
return `Workers are still running; the ${budgetLabel} wait budget ran out. Reuse the same task_ids for a short wait, or schedule check_workers for long monitoring. Set allowLongWait only after verifying the client's MCP timeout supports the requested budget; do not start another long wait while a background wait is active.`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function compactWorkerRow(task) {
|
|
48
|
+
return {
|
|
49
|
+
id: task.id,
|
|
50
|
+
title: clip(task.title, 60),
|
|
51
|
+
status: task.status,
|
|
52
|
+
phase: task.phase ?? null,
|
|
53
|
+
exit_code: task.exit_code ?? null,
|
|
54
|
+
changed_file_count: readTaskChanges(task).length,
|
|
55
|
+
acceptance: acceptanceVerdict(task),
|
|
56
|
+
...compactLiveness(task),
|
|
57
|
+
updated_at: task.updated_at ?? null
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function fullWorkerRows(tasks, { includeEvents, eventLimit, eventMaxChars, eventKinds }) {
|
|
62
|
+
return Promise.all(
|
|
63
|
+
tasks.map(async (task) => ({
|
|
64
|
+
...summarizeTask(task),
|
|
65
|
+
recent_events: includeEvents
|
|
66
|
+
? await readTaskEvents(task.id, eventLimit, eventKinds ?? null).then((events) =>
|
|
67
|
+
eventMaxChars === undefined ? events : events.map((event) => truncateEventStrings(event, eventMaxChars))
|
|
68
|
+
)
|
|
69
|
+
: undefined
|
|
70
|
+
}))
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function waitForWorkers(input, extra) {
|
|
75
|
+
const { task_ids, mode, timeoutMinutes, timeoutMs, allowLongWait, includeEvents, compact: requestedCompact } = input;
|
|
76
|
+
const compact = requestedCompact ?? !includeEvents;
|
|
77
|
+
const startedAt = Date.now();
|
|
78
|
+
const requestedTimeoutMs = timeoutMs ?? timeoutMinutes * 60 * 1000;
|
|
79
|
+
const effectiveTimeoutMs = allowLongWait ? requestedTimeoutMs : Math.min(requestedTimeoutMs, 60000);
|
|
80
|
+
const clientCancelled = await pollUntilSettled(input, { startedAt, effectiveTimeoutMs }, extra);
|
|
81
|
+
|
|
82
|
+
await reconcileDetachedActiveTasks();
|
|
83
|
+
const tasks = (await getTasks(task_ids)).filter(Boolean);
|
|
84
|
+
const missingIds = task_ids.filter((taskId) => !tasks.some((task) => task.id === taskId));
|
|
85
|
+
const settledTasks = tasks.filter(isSettled);
|
|
86
|
+
const timedOut =
|
|
87
|
+
mode === "any" ? settledTasks.length === 0 : settledTasks.length !== task_ids.length;
|
|
88
|
+
const summaries = await fullWorkerRows(tasks, input);
|
|
89
|
+
|
|
90
|
+
return textResult(withUpdate({
|
|
91
|
+
mode,
|
|
92
|
+
timed_out: timedOut,
|
|
93
|
+
still_running: timedOut,
|
|
94
|
+
termination_reason: clientCancelled ? "client_cancelled" : timedOut ? "budget_exhausted" : "settled",
|
|
95
|
+
next_step: timedOut ? budgetExhaustedHint(effectiveTimeoutMs) : null,
|
|
96
|
+
waited_ms: Date.now() - startedAt,
|
|
97
|
+
timeout_ms: effectiveTimeoutMs,
|
|
98
|
+
requested_timeout_ms: requestedTimeoutMs,
|
|
99
|
+
timeout_capped: effectiveTimeoutMs !== requestedTimeoutMs,
|
|
100
|
+
timeout_minutes: Math.round(effectiveTimeoutMs / 60000),
|
|
101
|
+
missing_ids: missingIds,
|
|
102
|
+
completed_count: tasks.filter((task) => task.status === "completed").length,
|
|
103
|
+
failed_count: tasks.filter((task) => task.status === "failed").length,
|
|
104
|
+
cancelled_count: tasks.filter((task) => task.status === "cancelled").length,
|
|
105
|
+
lost_count: tasks.filter((task) => task.status === "lost").length,
|
|
106
|
+
active_count: tasks.filter((task) => ACTIVE_STATUSES.has(task.status)).length,
|
|
107
|
+
acceptance_failed_count: tasks.filter((task) => task.acceptance_results?.passed === false).length,
|
|
108
|
+
workers: compact ? tasks.map(compactWorkerRow) : summaries
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export const waitCodexWorkersTool = [
|
|
113
|
+
"wait_codex_workers",
|
|
114
|
+
{
|
|
115
|
+
title: "Wait for Codex workers",
|
|
116
|
+
description:
|
|
117
|
+
"Block until selected Codex workers reach a terminal status, then return summaries. Each call is capped at 60 seconds unless allowLongWait is explicitly true and the caller has verified its MCP timeout supports the requested budget. A spent wait budget returns a snapshot while workers continue; reuse the same task_ids or schedule check_workers for longer monitoring. compact: true returns one line per worker with status, phase, exit_code, changed_file_count, acceptance and liveness. command_running means a command may still be working despite a long idle interval.",
|
|
118
|
+
inputSchema: {
|
|
119
|
+
task_ids: z.array(z.string().min(1)).min(1),
|
|
120
|
+
mode: z.enum(["any", "all"]).default("all"),
|
|
121
|
+
timeoutMinutes: z.number().int().min(1).max(360).default(1),
|
|
122
|
+
timeoutMs: z.number().int().min(1000).max(21600000).optional(),
|
|
123
|
+
allowLongWait: z.boolean().default(false),
|
|
124
|
+
pollMs: z.number().int().min(250).max(10000).default(1000),
|
|
125
|
+
emitProgress: z.boolean().default(false),
|
|
126
|
+
// Off by default. A wait is the call clients background and then replay
|
|
127
|
+
// as a notification, so its payload has to stay small; ten events per
|
|
128
|
+
// worker was the bulk of it. Ask for events explicitly, or read
|
|
129
|
+
// get_codex_worker_events for one worker.
|
|
130
|
+
includeEvents: z.boolean().default(false),
|
|
131
|
+
eventLimit: z.number().int().min(1).max(50).default(10),
|
|
132
|
+
// Events used to come back whole: one command event can carry a heredoc
|
|
133
|
+
// that is tens of KB, and ten of those made a single wait response
|
|
134
|
+
// unreadable. The default bounds each string; pass a bigger number when
|
|
135
|
+
// you actually want the raw text.
|
|
136
|
+
eventMaxChars: z.number().int().min(0).max(1000000).default(800),
|
|
137
|
+
eventKinds: z.array(z.string().min(1)).optional(),
|
|
138
|
+
// The smallest useful answer: one line per worker, for a caller that
|
|
139
|
+
// only wants to know who is done. Everything else comes from
|
|
140
|
+
// get_worker_result / get_worker_diff afterwards.
|
|
141
|
+
compact: z.boolean().optional()
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
waitForWorkers
|
|
145
|
+
];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { maybeAutoUpdate } from "../../infra/update/auto-update.js";
|
|
2
|
+
import { checkForUpdate, updateNotice } from "../../infra/update/update-check.js";
|
|
3
|
+
|
|
4
|
+
// Nobody should keep running an old build without hearing about it. The
|
|
5
|
+
// registry is asked once at start and every six hours after; the answer
|
|
6
|
+
// rides along in the overview, the dispatch receipt and the wait response,
|
|
7
|
+
// which are the calls every orchestrating session makes.
|
|
8
|
+
export const UPDATE_RECHECK_MS = 6 * 60 * 60 * 1000;
|
|
9
|
+
export let updateState = null;
|
|
10
|
+
// The last word from auto-update.js: null until a check found a newer
|
|
11
|
+
// version, then started | running | done | failed | skipped.
|
|
12
|
+
export let autoUpdateState = null;
|
|
13
|
+
export async function refreshUpdateState({ force = false } = {}) {
|
|
14
|
+
try {
|
|
15
|
+
updateState = await checkForUpdate({ force });
|
|
16
|
+
autoUpdateState = await maybeAutoUpdate(updateState);
|
|
17
|
+
const notice = updateNotice(updateState, autoUpdateState)?.notice;
|
|
18
|
+
if (notice) process.stderr.write(`[codex-supervisor] ${notice}\n`);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
process.stderr.write(`[codex-supervisor] update check failed: ${error.message}\n`);
|
|
21
|
+
}
|
|
22
|
+
return updateState;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// The short form for tool results: null when the install is current.
|
|
26
|
+
export function updateField() {
|
|
27
|
+
return updateNotice(updateState, autoUpdateState);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Spread into a result: adds `update` only when there is something to say.
|
|
31
|
+
export function withUpdate(payload) {
|
|
32
|
+
const update = updateField();
|
|
33
|
+
return update ? { ...payload, update } : payload;
|
|
34
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { acceptanceVerdict } from "../../../app/acceptance.js";
|
|
2
|
+
import { classifyFailure } from "../../../domain/failure-class.js";
|
|
3
|
+
import { ACTIVE_STATUSES, isGoalNeedingAttention } from "../../../domain/status.js";
|
|
4
|
+
import { threadHealth } from "../../../domain/thread-health.js";
|
|
5
|
+
import { approxTokenCount } from "../../../domain/truncate.js";
|
|
6
|
+
import { readTaskChanges } from "../../../infra/worktree.js";
|
|
7
|
+
import { clip } from "../result.js";
|
|
8
|
+
import { ACTION_PREVIEW_CHARS, liveness } from "./task.js";
|
|
9
|
+
|
|
10
|
+
const OVERVIEW_BYTE_BUDGET = 7000;
|
|
11
|
+
const OVERVIEW_CAP_LEVELS = [
|
|
12
|
+
{ title: 40, goal: 60, action: 60, path: 60 },
|
|
13
|
+
{ title: 28, goal: 40, action: 40, path: 40 },
|
|
14
|
+
{ title: 18, goal: 24, action: 24, path: 24 },
|
|
15
|
+
{ title: 12, goal: 16, action: 16, path: 16 },
|
|
16
|
+
{ title: 8, goal: 8, action: 8, path: 8 },
|
|
17
|
+
{ title: 0, goal: 0, action: 0, path: 0 }
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
function overviewRow(task, caps) {
|
|
21
|
+
const live = liveness(task);
|
|
22
|
+
return {
|
|
23
|
+
id: task.id,
|
|
24
|
+
title: clip(task.title, caps.title),
|
|
25
|
+
status: task.status,
|
|
26
|
+
phase: task.phase ?? null,
|
|
27
|
+
goal: clip(task.goal_objective, caps.goal),
|
|
28
|
+
goal_status: task.goal_status ?? null,
|
|
29
|
+
last_action: clip(task.current_action, caps.action),
|
|
30
|
+
idle_seconds: live.idle_seconds,
|
|
31
|
+
command_running: Boolean(task.current_command) && ACTIVE_STATUSES.has(task.status),
|
|
32
|
+
...(live.current_stage ? { current_stage: live.current_stage } : {}),
|
|
33
|
+
...(live.last_stage ? { last_stage: live.last_stage } : {}),
|
|
34
|
+
acceptance: acceptanceVerdict(task),
|
|
35
|
+
...(classifyFailure(task)?.code ? { failure_code: classifyFailure(task).code } : {}),
|
|
36
|
+
...(threadHealth(task).state === "handoff_recommended" ? { handoff_recommended: true } : {}),
|
|
37
|
+
changed_files: (task.changed_files ?? []).length,
|
|
38
|
+
depends_on: task.depends_on ?? [],
|
|
39
|
+
owned_paths: (task.owned_paths ?? []).map((entry) => clip(entry, caps.path))
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// One line per work for the listing tools. Kept deliberately small: the caller
|
|
44
|
+
// is usually a main thread that will drill into at most one of these.
|
|
45
|
+
export function workRow(task) {
|
|
46
|
+
return {
|
|
47
|
+
id: task.id,
|
|
48
|
+
title: task.title,
|
|
49
|
+
status: task.status,
|
|
50
|
+
phase: task.phase ?? null,
|
|
51
|
+
goal: task.goal_objective ?? null,
|
|
52
|
+
session_id: task.session_id ?? null,
|
|
53
|
+
thread_id: task.thread_id ?? null,
|
|
54
|
+
created_at: task.created_at,
|
|
55
|
+
updated_at: task.updated_at
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// The overview is the tool the orchestrator calls by default, so it has to fit
|
|
60
|
+
// a fixed budget no matter how long titles and goals are. Field caps are
|
|
61
|
+
// lowered until the payload fits, and the payload reports what it cost.
|
|
62
|
+
function settleTokenCount(payload) {
|
|
63
|
+
// The reported cost has to include the field that reports it, so iterate to
|
|
64
|
+
// a fixed point instead of measuring a payload that lacks the number.
|
|
65
|
+
let tokens = 0;
|
|
66
|
+
for (let attempt = 0; attempt < 6; attempt += 1) {
|
|
67
|
+
payload.approx_tokens = tokens;
|
|
68
|
+
const next = approxTokenCount(JSON.stringify(payload));
|
|
69
|
+
if (next === tokens) break;
|
|
70
|
+
tokens = next;
|
|
71
|
+
}
|
|
72
|
+
payload.approx_tokens = tokens;
|
|
73
|
+
return Buffer.byteLength(JSON.stringify(payload), "utf8");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function buildOverview(tasks, extras = {}) {
|
|
77
|
+
let payload;
|
|
78
|
+
for (const [index, caps] of OVERVIEW_CAP_LEVELS.entries()) {
|
|
79
|
+
payload = {
|
|
80
|
+
generated_at: new Date().toISOString(),
|
|
81
|
+
...extras,
|
|
82
|
+
total: tasks.length,
|
|
83
|
+
active: tasks.filter((task) => ACTIVE_STATUSES.has(task.status)).length,
|
|
84
|
+
needs_attention: tasks
|
|
85
|
+
.filter((task) => isGoalNeedingAttention(task.goal_status) || task.attention_reason)
|
|
86
|
+
.map((task) => task.id),
|
|
87
|
+
// Terminal rows whose acceptance run failed. Kept apart from
|
|
88
|
+
// needs_attention, which means "running and stuck"; this means
|
|
89
|
+
// "finished and wrong", and the next step is a resume with the output.
|
|
90
|
+
acceptance_failed: tasks.filter((task) => task.acceptance_results?.passed === false).map((task) => task.id),
|
|
91
|
+
workers: tasks.map((task) => overviewRow(task, caps))
|
|
92
|
+
};
|
|
93
|
+
const bytes = settleTokenCount(payload);
|
|
94
|
+
if (bytes <= OVERVIEW_BYTE_BUDGET) return payload;
|
|
95
|
+
if (index === OVERVIEW_CAP_LEVELS.length - 1) {
|
|
96
|
+
payload.budget_exceeded = true;
|
|
97
|
+
payload.truncated_fields = true;
|
|
98
|
+
settleTokenCount(payload);
|
|
99
|
+
return payload;
|
|
100
|
+
}
|
|
101
|
+
delete payload.approx_tokens;
|
|
102
|
+
}
|
|
103
|
+
return payload;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function acceptanceLine(task) {
|
|
107
|
+
if (!Array.isArray(task.acceptance) || task.acceptance.length === 0) return "acceptance: none configured";
|
|
108
|
+
const results = task.acceptance_results;
|
|
109
|
+
if (!results) return `acceptance: ${task.acceptance.length} configured, not run yet`;
|
|
110
|
+
const ran = results.checks?.length ?? 0;
|
|
111
|
+
const ok = (results.checks ?? []).filter((check) => check.passed !== false && check.exit_code === 0 && !check.timed_out).length;
|
|
112
|
+
const failing = (results.checks ?? []).find((check) => check.passed === false || check.exit_code !== 0 || check.timed_out);
|
|
113
|
+
return `acceptance: ${results.status}, ${ok}/${task.acceptance.length} passed (${ran} ran)${failing ? `, first failure: ${clip(failing.command, 80)} exit ${failing.timed_out ? "timeout" : failing.exit_code}` : ""}`;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function buildWorkerSummary(task, nativeGoal) {
|
|
117
|
+
// Read the worktree too: a worker that edits via shell commands emits no
|
|
118
|
+
// file_change events, so the checkout is the authoritative diff.
|
|
119
|
+
const changed = readTaskChanges(task);
|
|
120
|
+
const commands = task.commands ?? [];
|
|
121
|
+
const lines = [
|
|
122
|
+
`${task.title ?? task.id} — status=${task.status}${task.phase ? `, phase=${task.phase}` : ""}`,
|
|
123
|
+
`goal: ${task.goal_objective ?? "-"}${task.goal_token_budget ? ` (budget ${task.goal_token_budget} tokens)` : ""}`,
|
|
124
|
+
nativeGoal
|
|
125
|
+
? `codex goal: ${nativeGoal.status}, ${nativeGoal.tokens_used} tokens used, ${nativeGoal.time_used_seconds}s elapsed`
|
|
126
|
+
: "codex goal: none recorded for this thread",
|
|
127
|
+
`changed files (${changed.length}): ${changed.slice(0, 10).join(", ") || "-"}`,
|
|
128
|
+
`last command: ${commands.at(-1)?.command ?? "-"}`,
|
|
129
|
+
acceptanceLine(task),
|
|
130
|
+
`last action: ${clip(task.current_action, ACTION_PREVIEW_CHARS) ?? "-"}`,
|
|
131
|
+
`runs: ${task.run_count ?? 0}${task.resumed_from ? `, resumed from ${task.resumed_from}` : ""}`,
|
|
132
|
+
task.error ? `error: ${task.error}` : null
|
|
133
|
+
].filter(Boolean);
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
id: task.id,
|
|
137
|
+
title: task.title,
|
|
138
|
+
status: task.status,
|
|
139
|
+
phase: task.phase ?? null,
|
|
140
|
+
thread_id: task.thread_id,
|
|
141
|
+
goal_objective: task.goal_objective,
|
|
142
|
+
goal_token_budget: task.goal_token_budget,
|
|
143
|
+
goal_status: task.goal_status,
|
|
144
|
+
native_goal: nativeGoal,
|
|
145
|
+
owned_paths: task.owned_paths ?? [],
|
|
146
|
+
depends_on: task.depends_on ?? [],
|
|
147
|
+
run_count: task.run_count ?? 0,
|
|
148
|
+
changed_files: changed,
|
|
149
|
+
command_count: commands.length,
|
|
150
|
+
last_command: commands.at(-1)?.command ?? null,
|
|
151
|
+
last_message: task.last_message ?? null,
|
|
152
|
+
notices: task.notices ?? null,
|
|
153
|
+
error: task.error ?? null,
|
|
154
|
+
created_at: task.created_at,
|
|
155
|
+
updated_at: task.updated_at,
|
|
156
|
+
completed_at: task.completed_at,
|
|
157
|
+
summary: lines.join("\n")
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function externalOutputView(task, maxChars = 6000) {
|
|
162
|
+
const outputs = task.run_evidence?.external_outputs ?? [];
|
|
163
|
+
const perContent = Math.floor(maxChars / Math.max(1, outputs.length * 2));
|
|
164
|
+
return outputs.map((entry) => ({ ...entry, before: { ...entry.before, content: clip(entry.before.content, perContent) },
|
|
165
|
+
after: { ...entry.after, content: clip(entry.after.content, perContent) } }));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function reportView(task, maxChars) {
|
|
169
|
+
const value = task.run_evidence?.structured_report;
|
|
170
|
+
if (!value) return { format: "legacy_text", valid: null };
|
|
171
|
+
if (!value.valid || !maxChars) return value;
|
|
172
|
+
const report = value.report;
|
|
173
|
+
const perEntry = Math.floor(maxChars / Math.max(1, 2 + report.verification.length + report.not_done.length));
|
|
174
|
+
return { ...value, report: { result: clip(report.result, perEntry * 2),
|
|
175
|
+
verification: report.verification.map((entry) => clip(entry, perEntry)),
|
|
176
|
+
not_done: report.not_done.map((entry) => clip(entry, perEntry)) } };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function runEvidenceView(task) {
|
|
180
|
+
if (!task.run_evidence) return null;
|
|
181
|
+
const { structured_report, external_outputs, ...evidence } = task.run_evidence;
|
|
182
|
+
return { ...evidence, external_changed_count: (external_outputs ?? []).filter((entry) => entry.changed).length };
|
|
183
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { acceptanceVerdict } from "../../../app/acceptance.js";
|
|
2
|
+
import { classifyFailure } from "../../../domain/failure-class.js";
|
|
3
|
+
import { ACTIVE_STATUSES, isGoalNeedingAttention } from "../../../domain/status.js";
|
|
4
|
+
import { threadHealth } from "../../../domain/thread-health.js";
|
|
5
|
+
import { readStage } from "../../../infra/stage-store.js";
|
|
6
|
+
import { readTaskChanges } from "../../../infra/worktree.js";
|
|
7
|
+
import { summarizeVerification } from "../../../runners/codex/event-parser.js";
|
|
8
|
+
import { clip } from "../result.js";
|
|
9
|
+
|
|
10
|
+
// `current_action` is "Running <command>", and a command can be a heredoc that
|
|
11
|
+
// writes a whole file. Returning it whole put tens of thousands of characters
|
|
12
|
+
// into every wait response, which then blew past the client's MCP output cap
|
|
13
|
+
// and came back a second time as a notification. The full command stays in
|
|
14
|
+
// current_command / commands and is readable through get_codex_worker_events.
|
|
15
|
+
export const ACTION_PREVIEW_CHARS = 300;
|
|
16
|
+
const COMMAND_PREVIEW_CHARS = 300;
|
|
17
|
+
const COMMAND_TAIL = 20;
|
|
18
|
+
const PROMPT_PREVIEW_CHARS = 300;
|
|
19
|
+
// The single-worker status read is the drill-in for one worker, so its copy of
|
|
20
|
+
// the last message stays much larger than the overview's 400. The full report
|
|
21
|
+
// is still get_worker_result's job.
|
|
22
|
+
const STATUS_MESSAGE_CHARS = 4000;
|
|
23
|
+
|
|
24
|
+
// Codex emits nothing while a command runs and nothing while the model
|
|
25
|
+
// thinks, so a snapshot that has not moved for ten minutes looks the same
|
|
26
|
+
// either way. These three fields tell them apart: current_command is set
|
|
27
|
+
// from the command's item.started until its item.completed, so a long idle
|
|
28
|
+
// with a command is a long command, and a long idle without one is the model
|
|
29
|
+
// (or a stuck process, which reconcile turns into lost on its own).
|
|
30
|
+
const LIVE_COMMAND_PREVIEW_CHARS = 120;
|
|
31
|
+
export function liveness(task) {
|
|
32
|
+
if (!ACTIVE_STATUSES.has(task.status)) {
|
|
33
|
+
const stage = readStage(task.id);
|
|
34
|
+
return {
|
|
35
|
+
idle_seconds: null,
|
|
36
|
+
command_running: false,
|
|
37
|
+
current_command: null,
|
|
38
|
+
current_stage: null,
|
|
39
|
+
current_stage_detail: null,
|
|
40
|
+
last_stage: stage?.stage ?? null,
|
|
41
|
+
stage_updated_at: stage?.updated_at ?? null
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const since = Date.parse(task.last_event_at ?? task.started_at ?? "");
|
|
45
|
+
const idle = Number.isFinite(since) ? Math.max(0, Math.floor((Date.now() - since) / 1000)) : null;
|
|
46
|
+
const command = task.current_command ? clip(task.current_command, LIVE_COMMAND_PREVIEW_CHARS) : null;
|
|
47
|
+
const stage = readStage(task.id);
|
|
48
|
+
const active = ACTIVE_STATUSES.has(task.status);
|
|
49
|
+
return {
|
|
50
|
+
idle_seconds: idle,
|
|
51
|
+
command_running: Boolean(task.current_command),
|
|
52
|
+
current_command: command,
|
|
53
|
+
current_stage: active ? stage?.stage ?? null : null,
|
|
54
|
+
current_stage_detail: active ? stage?.detail ?? null : null,
|
|
55
|
+
last_stage: active ? null : stage?.stage ?? null,
|
|
56
|
+
stage_updated_at: stage?.updated_at ?? null
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function compactLiveness(task) {
|
|
61
|
+
const live = liveness(task);
|
|
62
|
+
return {
|
|
63
|
+
idle_seconds: live.idle_seconds,
|
|
64
|
+
command_running: live.command_running,
|
|
65
|
+
current_command: live.current_command,
|
|
66
|
+
...(live.current_stage ? { current_stage: live.current_stage } : {}),
|
|
67
|
+
...(live.current_stage_detail ? { current_stage_detail: live.current_stage_detail } : {}),
|
|
68
|
+
...(live.last_stage ? { last_stage: live.last_stage } : {}),
|
|
69
|
+
...(live.stage_updated_at ? { stage_updated_at: live.stage_updated_at } : {})
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// The acceptance verdict as get_worker_result reports it, with the one
|
|
74
|
+
// contradiction a tool can see spelled out: checks passed, worker says
|
|
75
|
+
// otherwise (the "it was never built" case, where it was).
|
|
76
|
+
export function acceptanceView(task, behind) {
|
|
77
|
+
const configured = Array.isArray(task.acceptance) && task.acceptance.length > 0;
|
|
78
|
+
const results = task.acceptance_results ?? null;
|
|
79
|
+
const view = {
|
|
80
|
+
configured,
|
|
81
|
+
commands: configured ? task.acceptance : [],
|
|
82
|
+
status: results?.status ?? null,
|
|
83
|
+
passed: results?.passed ?? null,
|
|
84
|
+
run: results?.run ?? null,
|
|
85
|
+
checks: results?.checks ?? [],
|
|
86
|
+
error: results?.error ?? null,
|
|
87
|
+
// Drift matters only before the work is landed: once it is on the
|
|
88
|
+
// branch, the branch having moved is expected.
|
|
89
|
+
stale: Boolean(results && behind && behind.behind > 0 && !(task.landed_at && task.landed_at >= (results.finished_at ?? ""))),
|
|
90
|
+
next_step: null
|
|
91
|
+
};
|
|
92
|
+
if (!configured) return view;
|
|
93
|
+
if (view.status === "failed") {
|
|
94
|
+
const failing = view.checks.find((check) => check.passed === false || check.exit_code !== 0 || check.timed_out) ?? null;
|
|
95
|
+
view.next_step = failing
|
|
96
|
+
? `acceptance failed: ${clip(failing.command, 120)} failed ${failing.error ?? (failing.baseline?.passed === false ? "baseline/evidence mismatch" : failing.timed_out ? "by timeout" : `exit ${failing.exit_code}`)}; resume the worker with checks[].output_tail in the prompt, or fix it yourself. Do not land until it passes.`
|
|
97
|
+
: `acceptance could not run (${view.error ?? "unknown"}); fix that first`;
|
|
98
|
+
} else if (view.status === "passed") {
|
|
99
|
+
const verification = summarizeVerification(task);
|
|
100
|
+
const workerSaysNo = task.status === "failed" || isGoalNeedingAttention(task.goal_status) || verification.last_command_failed;
|
|
101
|
+
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 rebaseOnto to re-run them on current code before landing";
|
|
103
|
+
} else if (view.status === "running") {
|
|
104
|
+
view.next_step = "acceptance is still running in the supervisor; wait_codex_workers returns when it is done";
|
|
105
|
+
} else if (view.status === "interrupted") {
|
|
106
|
+
view.next_step = "the supervisor exited while running acceptance; resume the worker (or cancel and redispatch) to run it again";
|
|
107
|
+
} else if (view.status === "cancelled") {
|
|
108
|
+
view.next_step = "acceptance was cancelled; resume the worker to run it again";
|
|
109
|
+
} else if (view.status === null) {
|
|
110
|
+
view.next_step = "acceptance has not run yet for this worker";
|
|
111
|
+
}
|
|
112
|
+
return view;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function summarizeTask(task) {
|
|
116
|
+
return {
|
|
117
|
+
id: task.id,
|
|
118
|
+
title: task.title,
|
|
119
|
+
worker: task.worker,
|
|
120
|
+
status: task.status,
|
|
121
|
+
phase: task.phase ?? null,
|
|
122
|
+
cwd: task.cwd,
|
|
123
|
+
project_root: task.project_root,
|
|
124
|
+
workspace_kind: task.workspace_kind ?? "legacy",
|
|
125
|
+
sandbox: task.sandbox,
|
|
126
|
+
model: task.model,
|
|
127
|
+
reasoning_effort: task.reasoning_effort ?? "high",
|
|
128
|
+
thread_id: task.thread_id,
|
|
129
|
+
followup_of: task.followup_of,
|
|
130
|
+
resumed_from: task.resumed_from,
|
|
131
|
+
depends_on: task.depends_on ?? [],
|
|
132
|
+
owned_paths: task.owned_paths ?? [],
|
|
133
|
+
worktree_path: task.worktree_path,
|
|
134
|
+
goal_objective: task.goal_objective,
|
|
135
|
+
goal_token_budget: task.goal_token_budget,
|
|
136
|
+
goal_status: task.goal_status,
|
|
137
|
+
goal_tokens_used: task.goal_tokens_used ?? null,
|
|
138
|
+
thread_health: threadHealth(task),
|
|
139
|
+
attention_reason: task.attention_reason ?? null,
|
|
140
|
+
failure: classifyFailure(task),
|
|
141
|
+
changed_file_count: (task.changed_files ?? []).length,
|
|
142
|
+
command_count: (task.commands ?? []).length,
|
|
143
|
+
run_count: task.run_count ?? 0,
|
|
144
|
+
acceptance: acceptanceVerdict(task),
|
|
145
|
+
landed_at: task.landed_at ?? null,
|
|
146
|
+
current_action: clip(task.current_action, ACTION_PREVIEW_CHARS),
|
|
147
|
+
...liveness(task),
|
|
148
|
+
last_event_at: task.last_event_at ?? null,
|
|
149
|
+
last_event_type: task.last_event_type,
|
|
150
|
+
last_message: clip(task.last_message, 400),
|
|
151
|
+
notices: clip(task.notices, 400),
|
|
152
|
+
error: task.error,
|
|
153
|
+
created_at: task.created_at,
|
|
154
|
+
updated_at: task.updated_at,
|
|
155
|
+
started_at: task.started_at,
|
|
156
|
+
completed_at: task.completed_at,
|
|
157
|
+
exit_code: task.exit_code
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// The status read used to hand back the stored row verbatim. For a follow-up
|
|
162
|
+
// worker that row carries the parent prompt plus the whole command history and
|
|
163
|
+
// the events folded into it; one real call returned 180k characters, past the
|
|
164
|
+
// client's MCP output cap, so the reply landed on disk and had to be grepped.
|
|
165
|
+
// This is the same status surface the other reads use, plus explicitly bounded
|
|
166
|
+
// extras. includePrompt is the escape hatch for the full task text.
|
|
167
|
+
export function statusView(task, { includePrompt, promptMaxChars }) {
|
|
168
|
+
const promptText = task.prompt ?? null;
|
|
169
|
+
const promptBudget = includePrompt ? promptMaxChars : PROMPT_PREVIEW_CHARS;
|
|
170
|
+
const commands = (task.commands ?? []).slice(-COMMAND_TAIL);
|
|
171
|
+
return {
|
|
172
|
+
...summarizeTask(task),
|
|
173
|
+
last_message: clip(task.last_message, STATUS_MESSAGE_CHARS),
|
|
174
|
+
session_id: task.session_id ?? null,
|
|
175
|
+
pid: task.pid ?? null,
|
|
176
|
+
run_log: task.run_log ?? null,
|
|
177
|
+
base_commit: task.base_commit ?? null,
|
|
178
|
+
changed_files: readTaskChanges(task),
|
|
179
|
+
current_command: clip(task.current_command, COMMAND_PREVIEW_CHARS),
|
|
180
|
+
commands: commands.map((entry) => ({ ...entry, command: clip(entry.command, COMMAND_PREVIEW_CHARS) })),
|
|
181
|
+
prompt: clip(promptText, promptBudget),
|
|
182
|
+
prompt_truncated: Boolean(promptText) && String(promptText).length > promptBudget
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// The dispatch receipt. Dispatch used to return the whole task record, which
|
|
187
|
+
// echoes the task text - and for a follow-up, the parent prompt plus 20 raw
|
|
188
|
+
// events - back to the caller on every call. Dispatching eleven workers made
|
|
189
|
+
// the main thread pay for its own instructions eleven times, and pushed the
|
|
190
|
+
// result into the client's MCP output cap. Read the rest per worker with
|
|
191
|
+
// get_worker_summary / get_worker_result when you actually need it.
|
|
192
|
+
export function receipt(task) {
|
|
193
|
+
return {
|
|
194
|
+
id: task.id,
|
|
195
|
+
title: task.title,
|
|
196
|
+
worker: task.worker,
|
|
197
|
+
status: task.status,
|
|
198
|
+
phase: task.phase ?? null,
|
|
199
|
+
cwd: task.cwd,
|
|
200
|
+
project_root: task.project_root,
|
|
201
|
+
workspace_kind: task.workspace_kind ?? "legacy",
|
|
202
|
+
worktree_path: task.worktree_path,
|
|
203
|
+
branch: task.worktree_path ? `codex/${task.id}` : null,
|
|
204
|
+
base_commit: task.base_commit ?? null,
|
|
205
|
+
sandbox: task.sandbox,
|
|
206
|
+
model: task.model,
|
|
207
|
+
reasoning_effort: task.reasoning_effort,
|
|
208
|
+
thread_id: task.thread_id,
|
|
209
|
+
session_id: task.session_id ?? null,
|
|
210
|
+
followup_of: task.followup_of,
|
|
211
|
+
resumed_from: task.resumed_from,
|
|
212
|
+
depends_on: task.depends_on ?? [],
|
|
213
|
+
owned_paths: task.owned_paths ?? [],
|
|
214
|
+
goal_objective: task.goal_objective,
|
|
215
|
+
goal_token_budget: task.goal_token_budget,
|
|
216
|
+
error: task.error ?? null,
|
|
217
|
+
failure: classifyFailure(task),
|
|
218
|
+
run_count: task.run_count ?? 0,
|
|
219
|
+
run_log: task.run_log,
|
|
220
|
+
created_at: task.created_at,
|
|
221
|
+
updated_at: task.updated_at
|
|
222
|
+
};
|
|
223
|
+
}
|