codex-supervisor-mcp 0.13.5 → 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/package.json +18 -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} +11 -12
- 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 -265
- 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 -3
- 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} +56 -41
- 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} +7 -6
- 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,307 @@
|
|
|
1
|
+
import { ACTIVE_STATUSES, TERMINAL_STATUSES } from "../../domain/status.js";
|
|
2
|
+
import { readPreflightResult } from "../../domain/worker-preflight.js";
|
|
3
|
+
import { runsDir } from "../paths.js";
|
|
4
|
+
import { canonicalRemoteForRoot, decodeJson, encodeJson, ensureControlRecords, ensureFilesystem, openDb, runWithRetry } from "./db.js";
|
|
5
|
+
import { readNativeGoal } from "./runner-readers.js";
|
|
6
|
+
import { TASK_COLUMNS } from "./schema.js";
|
|
7
|
+
import { randomUUID } from "node:crypto";
|
|
8
|
+
import { join, resolve } from "node:path";
|
|
9
|
+
|
|
10
|
+
export function rowToTask(row) {
|
|
11
|
+
if (!row) return null;
|
|
12
|
+
const nativeGoal = readNativeGoal(row.thread_id);
|
|
13
|
+
return {
|
|
14
|
+
...row,
|
|
15
|
+
workspace_kind: row.workspace_kind ?? "legacy",
|
|
16
|
+
skip_git_repo_check: Boolean(row.skip_git_repo_check),
|
|
17
|
+
changed_files: decodeJson(row.changed_files, []),
|
|
18
|
+
commands: decodeJson(row.commands, []),
|
|
19
|
+
owned_paths: decodeJson(row.owned_paths, []),
|
|
20
|
+
depends_on: decodeJson(row.depends_on, []),
|
|
21
|
+
acceptance: decodeJson(row.acceptance, null),
|
|
22
|
+
acceptance_local: decodeJson(row.acceptance_local, null),
|
|
23
|
+
acceptance_results: decodeJson(row.acceptance_results, null),
|
|
24
|
+
run_evidence: decodeJson(row.run_evidence, null),
|
|
25
|
+
guard_policy: decodeJson(row.guard_policy, null),
|
|
26
|
+
input_context: decodeJson(row.input_context, null),
|
|
27
|
+
workspace_metadata: decodeJson(row.workspace_metadata, null),
|
|
28
|
+
pid: row.pid ?? null,
|
|
29
|
+
exit_code: row.exit_code ?? null,
|
|
30
|
+
phase: row.phase ?? null,
|
|
31
|
+
goal_token_budget: row.goal_token_budget ?? null,
|
|
32
|
+
goal_status: nativeGoal?.storage_status ?? row.goal_status ?? null,
|
|
33
|
+
goal_tokens_used: nativeGoal?.tokens_used ?? row.goal_tokens_used ?? null,
|
|
34
|
+
goal_time_used_seconds: nativeGoal?.time_used_seconds ?? row.goal_time_used_seconds ?? null,
|
|
35
|
+
goal_updated_at: nativeGoal?.updated_at ?? row.goal_updated_at ?? null
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function isPidAlive(pid) {
|
|
40
|
+
if (!pid) return false;
|
|
41
|
+
try {
|
|
42
|
+
process.kill(pid, 0);
|
|
43
|
+
return true;
|
|
44
|
+
} catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export async function readTasks() {
|
|
50
|
+
await ensureFilesystem();
|
|
51
|
+
const rows = openDb().prepare("SELECT * FROM tasks ORDER BY created_at ASC").all();
|
|
52
|
+
return rows.map(rowToTask);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function readActiveTasks() {
|
|
56
|
+
const tasks = await readTasks();
|
|
57
|
+
return tasks.filter((task) => ACTIVE_STATUSES.has(task.status));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// A worker whose process is gone and that never wrote a terminal event is not
|
|
61
|
+
// "failed": nothing told us it failed. It is lost, and the fix is to re-run it.
|
|
62
|
+
// A row can also be active without ever having had a process: the dispatch
|
|
63
|
+
// wrote the row and then died before the spawn was recorded (one real store
|
|
64
|
+
// carried such a row for days, pid 0 and no created_at, forever "running").
|
|
65
|
+
// Only a row old enough that the dispatch cannot still be in flight is judged
|
|
66
|
+
// this way; a row with an unreadable created_at is treated as old.
|
|
67
|
+
const NEVER_STARTED_GRACE_MS = 5 * 60 * 1000;
|
|
68
|
+
|
|
69
|
+
export function neverStarted(task, now = Date.now()) {
|
|
70
|
+
if (task.pid) return false;
|
|
71
|
+
if (task.started_at) return false;
|
|
72
|
+
const created = Date.parse(task.created_at ?? "");
|
|
73
|
+
if (Number.isNaN(created)) return true;
|
|
74
|
+
return now - created > NEVER_STARTED_GRACE_MS;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export async function writeTask(task) {
|
|
78
|
+
await ensureFilesystem();
|
|
79
|
+
return runWithRetry(openDb(), () => writeTaskNow(task));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function writeTaskNow(task, { refreshRepo = false, canonicalRemote = undefined } = {}) {
|
|
83
|
+
const placeholders = TASK_COLUMNS.map((name) => `@${name}`).join(", ");
|
|
84
|
+
const updates = TASK_COLUMNS
|
|
85
|
+
.filter((name) => name !== "id" && name !== "created_at")
|
|
86
|
+
.map((name) => `${name} = excluded.${name}`)
|
|
87
|
+
.join(",\n ");
|
|
88
|
+
const stmt = openDb().prepare(`
|
|
89
|
+
INSERT INTO tasks (${TASK_COLUMNS.join(", ")}) VALUES (${placeholders})
|
|
90
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
91
|
+
${updates}
|
|
92
|
+
`);
|
|
93
|
+
|
|
94
|
+
const params = {};
|
|
95
|
+
for (const name of TASK_COLUMNS) params[name] = task[name] ?? null;
|
|
96
|
+
params.reasoning_effort = task.reasoning_effort ?? "high";
|
|
97
|
+
params.workspace_kind = task.workspace_kind ?? "legacy";
|
|
98
|
+
params.skip_git_repo_check = task.skip_git_repo_check ? 1 : 0;
|
|
99
|
+
params.changed_files = encodeJson(task.changed_files);
|
|
100
|
+
params.commands = encodeJson(task.commands);
|
|
101
|
+
params.owned_paths = encodeJson(task.owned_paths);
|
|
102
|
+
params.depends_on = encodeJson(task.depends_on);
|
|
103
|
+
// JSON columns: node:sqlite refuses to bind an array or object, and a
|
|
104
|
+
// refused bind drops the whole row update.
|
|
105
|
+
params.acceptance = task.acceptance ? JSON.stringify(task.acceptance) : null;
|
|
106
|
+
params.acceptance_local = task.acceptance_local ? JSON.stringify(task.acceptance_local) : null;
|
|
107
|
+
params.acceptance_results = task.acceptance_results ? JSON.stringify(task.acceptance_results) : null;
|
|
108
|
+
params.run_evidence = task.run_evidence ? JSON.stringify(task.run_evidence) : null;
|
|
109
|
+
params.guard_policy = task.guard_policy ? JSON.stringify(task.guard_policy) : null;
|
|
110
|
+
params.input_context = task.input_context ? JSON.stringify(task.input_context) : null;
|
|
111
|
+
params.workspace_metadata = task.workspace_metadata ? JSON.stringify(task.workspace_metadata) : null;
|
|
112
|
+
params.run_count = task.run_count ?? 0;
|
|
113
|
+
params.phase = task.phase ?? null;
|
|
114
|
+
|
|
115
|
+
stmt.run(params);
|
|
116
|
+
ensureControlRecords(openDb(), task, { refreshRepo, canonicalRemote });
|
|
117
|
+
return task;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function checkOwnership(taskId, incoming) {
|
|
121
|
+
const normalized = (value) => process.platform === "win32" ? value.replace(/\\/g, "/").toLowerCase() : value;
|
|
122
|
+
const overlaps = (left, right) => {
|
|
123
|
+
const a=normalized(left).replace(/\/$/,""),b=normalized(right).replace(/\/$/,"");
|
|
124
|
+
return a===b || a.startsWith(`${b}/`) || b.startsWith(`${a}/`);
|
|
125
|
+
};
|
|
126
|
+
const conflicts = [];
|
|
127
|
+
const pending = openDb().prepare("SELECT t.id,t.title,t.status,t.owned_paths,t.acceptance_results,t.started_at,t.exit_code,t.guard_policy,t.commands,t.attention_reason,c.owner_pid FROM tasks t LEFT JOIN run_claims c ON c.task_id=t.id WHERE t.id<>? AND (c.owner_pid IS NOT NULL OR status IN ('queued','running') OR json_extract(acceptance_results,'$.status')='running' OR (status IN ('completed','failed') AND started_at IS NOT NULL AND exit_code IS NULL AND acceptance_results IS NULL))").all(taskId);
|
|
128
|
+
for (const row of pending) {
|
|
129
|
+
const settling = decodeJson(row.acceptance_results,null)?.status === "running"
|
|
130
|
+
|| (["completed","failed"].includes(row.status) && row.started_at && row.exit_code == null && !row.acceptance_results);
|
|
131
|
+
if (row.owner_pid && !ACTIVE_STATUSES.has(row.status) && !settling && !isPidAlive(row.owner_pid)) continue;
|
|
132
|
+
const preflightTask = {
|
|
133
|
+
...row,
|
|
134
|
+
guard_policy: decodeJson(row.guard_policy, null),
|
|
135
|
+
commands: decodeJson(row.commands, [])
|
|
136
|
+
};
|
|
137
|
+
if (preflightTask.guard_policy?.preflight && readPreflightResult(preflightTask).status === "passed") continue;
|
|
138
|
+
const paths=decodeJson(row.owned_paths,[]);
|
|
139
|
+
const matching=incoming.flatMap(path=>paths.filter(other=>overlaps(path,other)).map(other=>({incoming:path,existing:other})));
|
|
140
|
+
if(matching.length)conflicts.push({task_id:row.id,title:row.title,status:row.status,overlapping_paths:matching});
|
|
141
|
+
}
|
|
142
|
+
if(conflicts.length){const error=new Error("ownedPaths overlap with an active worker claimed by another dispatcher");error.code="ownership_conflict";error.conflicts=conflicts;throw error;}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export async function reserveTaskOwnership(task) {
|
|
146
|
+
await ensureFilesystem();
|
|
147
|
+
const canonicalRemote = task?.project_root ? canonicalRemoteForRoot(resolve(task.project_root)) : null;
|
|
148
|
+
const connection=openDb();
|
|
149
|
+
return runWithRetry(connection,()=>{
|
|
150
|
+
connection.exec("BEGIN IMMEDIATE");
|
|
151
|
+
try { checkOwnership(task.id,task.owned_paths??[]);writeTaskNow(task, { refreshRepo: true, canonicalRemote });connection.exec("COMMIT");return task; }
|
|
152
|
+
catch(error){connection.exec("ROLLBACK");throw error;}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export async function upsertTask(task) {
|
|
157
|
+
await writeTask(task);
|
|
158
|
+
return task;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export async function getTask(taskId) {
|
|
162
|
+
await ensureFilesystem();
|
|
163
|
+
const row = openDb().prepare("SELECT * FROM tasks WHERE id = ?").get(taskId);
|
|
164
|
+
return rowToTask(row);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Compare and claim under one write lock before rebase or spawning. A claim
|
|
168
|
+
// whose dispatcher died can be replaced; a different run cannot be resumed
|
|
169
|
+
// using an earlier snapshot, even when both dispatchers read it together.
|
|
170
|
+
export async function claimTaskRun(taskId, expectedRun) {
|
|
171
|
+
await ensureFilesystem();
|
|
172
|
+
const connection = openDb();
|
|
173
|
+
return runWithRetry(connection, () => {
|
|
174
|
+
connection.exec("BEGIN IMMEDIATE");
|
|
175
|
+
try {
|
|
176
|
+
const row = connection.prepare("SELECT * FROM tasks WHERE id=?").get(taskId);
|
|
177
|
+
const claim = connection.prepare("SELECT * FROM run_claims WHERE task_id=?").get(taskId);
|
|
178
|
+
const busy = !row || row.run_count !== expectedRun || ACTIVE_STATUSES.has(row.status)
|
|
179
|
+
|| (["completed", "failed"].includes(row.status) && row.exit_code == null)
|
|
180
|
+
|| decodeJson(row.acceptance_results, null)?.status === "running"
|
|
181
|
+
|| (claim && isPidAlive(claim.owner_pid));
|
|
182
|
+
let token = null;
|
|
183
|
+
if (!busy) {
|
|
184
|
+
checkOwnership(taskId,decodeJson(row.owned_paths,[]));
|
|
185
|
+
token = randomUUID();
|
|
186
|
+
connection.prepare("INSERT INTO run_claims VALUES (?,?,?) ON CONFLICT(task_id) DO UPDATE SET token=excluded.token,owner_pid=excluded.owner_pid")
|
|
187
|
+
.run(taskId, token, process.pid);
|
|
188
|
+
}
|
|
189
|
+
connection.exec("COMMIT");
|
|
190
|
+
return token;
|
|
191
|
+
} catch (error) { connection.exec("ROLLBACK"); throw error; }
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export async function releaseTaskRun(taskId, token) {
|
|
196
|
+
openDb().prepare("DELETE FROM run_claims WHERE task_id=? AND token=?").run(taskId, token);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export async function readObserverCursor(observerId) {
|
|
200
|
+
await ensureFilesystem();
|
|
201
|
+
return decodeJson(openDb().prepare("SELECT cursor FROM observer_cursors WHERE id=?").get(observerId)?.cursor, {});
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export async function writeObserverCursor(observerId, cursor) {
|
|
205
|
+
await ensureFilesystem();
|
|
206
|
+
runWithRetry(openDb(), () => openDb().prepare("INSERT INTO observer_cursors VALUES (?,?,?) ON CONFLICT(id) DO UPDATE SET cursor=excluded.cursor,updated_at=excluded.updated_at")
|
|
207
|
+
.run(observerId, JSON.stringify(cursor), new Date().toISOString()));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Keyword search over the fields that describe what a work was for and how it
|
|
211
|
+
// ended. Substring match, newest first. Deliberately not full-text and not
|
|
212
|
+
// vector search: at this scale a LIKE scan over a few hundred rows is faster
|
|
213
|
+
// than any index would be to maintain.
|
|
214
|
+
export async function searchTasks(query, limit = 20) {
|
|
215
|
+
await ensureFilesystem();
|
|
216
|
+
const pattern = `%${String(query).trim()}%`;
|
|
217
|
+
const rows = openDb().prepare(`
|
|
218
|
+
SELECT * FROM tasks
|
|
219
|
+
WHERE title LIKE @pattern
|
|
220
|
+
OR goal_objective LIKE @pattern
|
|
221
|
+
OR prompt LIKE @pattern
|
|
222
|
+
OR last_message LIKE @pattern
|
|
223
|
+
ORDER BY created_at DESC
|
|
224
|
+
LIMIT @limit
|
|
225
|
+
`).all({ pattern, limit });
|
|
226
|
+
return rows.map(rowToTask);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export async function readTasksBySession(sessionId) {
|
|
230
|
+
await ensureFilesystem();
|
|
231
|
+
const rows = openDb()
|
|
232
|
+
.prepare("SELECT * FROM tasks WHERE session_id = ? ORDER BY created_at ASC")
|
|
233
|
+
.all(sessionId);
|
|
234
|
+
return rows.map(rowToTask);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Record the files a terminal worker changed, and nothing else. The summary
|
|
238
|
+
// read used to upsert the whole row, which on a running worker put stale
|
|
239
|
+
// copies of every live field (phase, current_action, exit_code) back over
|
|
240
|
+
// what the runner had just written. A terminal row has no writer left, and
|
|
241
|
+
// even then only this one column is touched.
|
|
242
|
+
export async function recordTerminalChangedFiles(taskId, changedFiles) {
|
|
243
|
+
await ensureFilesystem();
|
|
244
|
+
const terminal = Array.from(TERMINAL_STATUSES).map((s) => `'${s}'`).join(", ");
|
|
245
|
+
const result = openDb()
|
|
246
|
+
.prepare(`UPDATE tasks SET changed_files = @files WHERE id = @id AND status IN (${terminal})`)
|
|
247
|
+
.run({ id: taskId, files: encodeJson(changedFiles) });
|
|
248
|
+
return result.changes > 0;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export async function getTasks(taskIds) {
|
|
252
|
+
await ensureFilesystem();
|
|
253
|
+
return taskIds.map((taskId) => {
|
|
254
|
+
const row = openDb().prepare("SELECT * FROM tasks WHERE id = ?").get(taskId);
|
|
255
|
+
return rowToTask(row);
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export function taskRunPath(taskId) {
|
|
260
|
+
return join(runsDir, `${taskId}.jsonl`);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export async function taskCount() {
|
|
264
|
+
await ensureFilesystem();
|
|
265
|
+
const row = openDb().prepare("SELECT COUNT(*) AS count FROM tasks").get();
|
|
266
|
+
return row.count;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export async function taskExists(taskId) {
|
|
270
|
+
return Boolean(await getTask(taskId));
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export async function taskHasEvents(taskId) {
|
|
274
|
+
await ensureFilesystem();
|
|
275
|
+
const row = openDb().prepare("SELECT 1 FROM task_events WHERE task_id = ? LIMIT 1").get(taskId);
|
|
276
|
+
return Boolean(row);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export async function taskEventCount(taskId) {
|
|
280
|
+
await ensureFilesystem();
|
|
281
|
+
const row = openDb().prepare("SELECT COUNT(*) AS count FROM task_events WHERE task_id = ?").get(taskId);
|
|
282
|
+
return row.count;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export async function deleteTasks(taskIds) {
|
|
286
|
+
await ensureFilesystem();
|
|
287
|
+
if (taskIds.length === 0) return;
|
|
288
|
+
const dbInstance = openDb();
|
|
289
|
+
const deleteEvents = dbInstance.prepare("DELETE FROM task_events WHERE task_id = ?");
|
|
290
|
+
const deleteTask = dbInstance.prepare("DELETE FROM tasks WHERE id = ?");
|
|
291
|
+
dbInstance.exec("BEGIN IMMEDIATE;");
|
|
292
|
+
try {
|
|
293
|
+
for (const taskId of taskIds) {
|
|
294
|
+
deleteEvents.run(taskId);
|
|
295
|
+
deleteTask.run(taskId);
|
|
296
|
+
}
|
|
297
|
+
dbInstance.exec("COMMIT;");
|
|
298
|
+
} catch (error) {
|
|
299
|
+
dbInstance.exec("ROLLBACK;");
|
|
300
|
+
throw error;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export async function vacuumStore() {
|
|
305
|
+
await ensureFilesystem();
|
|
306
|
+
openDb().exec("VACUUM;");
|
|
307
|
+
}
|
|
@@ -6,15 +6,15 @@
|
|
|
6
6
|
//
|
|
7
7
|
// Writes data/auto-update.json at every step so the server (and a human)
|
|
8
8
|
// can see what happened without a terminal: running -> done | failed | skipped.
|
|
9
|
-
import {
|
|
9
|
+
import { runFile } from "../process.js";
|
|
10
10
|
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
11
11
|
import { mkdir, open, readFile, rm, writeFile } from "node:fs/promises";
|
|
12
12
|
import { dirname, join } from "node:path";
|
|
13
13
|
import { promisify } from "node:util";
|
|
14
|
-
import { dataDir } from "
|
|
15
|
-
import { resolveCommand } from "
|
|
14
|
+
import { dataDir } from "../paths.js";
|
|
15
|
+
import { resolveCommand } from "../bin-resolver.js";
|
|
16
16
|
|
|
17
|
-
const run = promisify(
|
|
17
|
+
const run = promisify(runFile);
|
|
18
18
|
const PACKAGE_NAME = "codex-supervisor-mcp";
|
|
19
19
|
const statePath = join(dataDir, "auto-update.json");
|
|
20
20
|
const lockPath = join(dataDir, "auto-update.lock");
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
// It only ever touches a copy that npm installed globally. A git checkout,
|
|
12
12
|
// an `npm link`, a project-local dependency and an npx cache copy are left
|
|
13
13
|
// alone, and the worker double-checks against `npm root -g` before writing.
|
|
14
|
-
import {
|
|
14
|
+
import { spawnProcess } from "../process.js";
|
|
15
15
|
import { closeSync, openSync } from "node:fs";
|
|
16
16
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
17
17
|
import { dirname, join } from "node:path";
|
|
18
18
|
import { fileURLToPath } from "node:url";
|
|
19
|
-
import { dataDir } from "
|
|
19
|
+
import { dataDir } from "../paths.js";
|
|
20
20
|
|
|
21
21
|
export const statePath = join(dataDir, "auto-update.json");
|
|
22
22
|
export const lockPath = join(dataDir, "auto-update.lock");
|
|
@@ -68,7 +68,7 @@ async function launchWorker({ version, packageRoot, registry }) {
|
|
|
68
68
|
if (registry) args.push("--registry", registry);
|
|
69
69
|
const log = openSync(logPath, "a");
|
|
70
70
|
try {
|
|
71
|
-
const child =
|
|
71
|
+
const child = spawnProcess(process.execPath, args, {
|
|
72
72
|
detached: true,
|
|
73
73
|
stdio: ["ignore", log, log],
|
|
74
74
|
env: { ...process.env, CODEX_SUPERVISOR_NO_AUTO_UPDATE: "1" },
|
|
@@ -7,15 +7,15 @@
|
|
|
7
7
|
// integrity of what npm unpacked in node_modules/.package-lock.json, and
|
|
8
8
|
// the registry says what the integrity of that version should be. A
|
|
9
9
|
// mismatch means the files on disk are not the published build.
|
|
10
|
+
import { runGit } from "../git.js";
|
|
10
11
|
import { existsSync, readFileSync } from "node:fs";
|
|
11
12
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
12
|
-
import { execFileSync } from "node:child_process";
|
|
13
13
|
import { basename, dirname, join, resolve } from "node:path";
|
|
14
14
|
import { fileURLToPath } from "node:url";
|
|
15
|
-
import { dataDir } from "
|
|
15
|
+
import { dataDir } from "../paths.js";
|
|
16
16
|
|
|
17
17
|
const PACKAGE_NAME = "codex-supervisor-mcp";
|
|
18
|
-
const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
18
|
+
const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..", "..", "..");
|
|
19
19
|
const packageJson = JSON.parse(readFileSync(join(packageRoot, "package.json"), "utf8"));
|
|
20
20
|
|
|
21
21
|
export const INSTALL_COMMAND = `npm i -g ${PACKAGE_NAME}@latest`;
|
|
@@ -97,7 +97,7 @@ export function installedPackage() {
|
|
|
97
97
|
}
|
|
98
98
|
if (info.source === "git") {
|
|
99
99
|
try {
|
|
100
|
-
info.commit =
|
|
100
|
+
info.commit = runGit(packageRoot, ["rev-parse", "HEAD"], { timeout: 5000, stderr: "ignore" });
|
|
101
101
|
} catch {
|
|
102
102
|
// a checkout without a usable git: still a checkout
|
|
103
103
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { runGit } from "./git.js";
|
|
1
2
|
import { createHash } from "node:crypto";
|
|
2
3
|
import { createReadStream, existsSync } from "node:fs";
|
|
3
4
|
import { lstat, mkdir, readdir, readlink, rm } from "node:fs/promises";
|
|
4
|
-
import { execFileSync } from "node:child_process";
|
|
5
5
|
import { join, relative, resolve } from "node:path";
|
|
6
6
|
import { scratchDir } from "./paths.js";
|
|
7
7
|
|
|
@@ -21,11 +21,7 @@ function isInside(root, path) {
|
|
|
21
21
|
|
|
22
22
|
export function isGitCheckout(cwd) {
|
|
23
23
|
try {
|
|
24
|
-
return
|
|
25
|
-
encoding: "utf8",
|
|
26
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
27
|
-
timeout: 15000
|
|
28
|
-
}).trim() === "true";
|
|
24
|
+
return runGit(cwd, ["rev-parse", "--is-inside-work-tree"], { stderr: "ignore", timeout: 15000 }) === "true";
|
|
29
25
|
} catch {
|
|
30
26
|
return false;
|
|
31
27
|
}
|
|
@@ -133,7 +129,9 @@ export async function captureWorkspaceManifest(sourceRoot, paths) {
|
|
|
133
129
|
};
|
|
134
130
|
}
|
|
135
131
|
|
|
136
|
-
export async function prepareWorkspace(
|
|
132
|
+
export async function prepareWorkspace(options) {
|
|
133
|
+
const { cwd, workspaceKind = null, sandbox, ownedPaths, networkAccess, acceptance } = options;
|
|
134
|
+
const { externalOutputs = [], inPlaceAuthorization = null, taskId, isPreflight = false } = options;
|
|
137
135
|
const sourceRoot = resolve(cwd);
|
|
138
136
|
if (!existsSync(sourceRoot)) throw workspaceError("workspace_source_missing", `workspace source directory does not exist: ${sourceRoot}`);
|
|
139
137
|
const kind = selectedKind({ sourceRoot, workspaceKind, sandbox });
|
|
@@ -10,13 +10,12 @@
|
|
|
10
10
|
// of five workers all did exactly that and reported no changed files at all -
|
|
11
11
|
// so the committed part is read as `git diff --name-only <base> HEAD`, where
|
|
12
12
|
// base is the commit the worktree was created from.
|
|
13
|
-
import {
|
|
13
|
+
import { runGit } from "./git.js";
|
|
14
14
|
import { existsSync, readFileSync, lstatSync } from "node:fs";
|
|
15
15
|
import { join, relative, resolve } from "node:path";
|
|
16
|
-
import { truncateMiddleChars } from "
|
|
16
|
+
import { truncateMiddleChars } from "../domain/truncate.js";
|
|
17
17
|
import { createHash } from "node:crypto";
|
|
18
18
|
|
|
19
|
-
const defaultGitBin = process.env.GIT_BIN?.trim() || "git";
|
|
20
19
|
|
|
21
20
|
// Two global flags on every read here.
|
|
22
21
|
//
|
|
@@ -30,13 +29,7 @@ const defaultGitBin = process.env.GIT_BIN?.trim() || "git";
|
|
|
30
29
|
// worktree, from status polls and the board, and on Windows a status poll
|
|
31
30
|
// holding index.lock made the worker's own `git add` fail and the worker
|
|
32
31
|
// exit non-zero. An observer must never lock what it observes.
|
|
33
|
-
|
|
34
|
-
return execFileSync(defaultGitBin, ["--no-optional-locks", "-C", worktreePath, "-c", "core.quotePath=false", ...args], {
|
|
35
|
-
encoding: "utf8",
|
|
36
|
-
timeout: 15000,
|
|
37
|
-
stdio: ["ignore", "pipe", "ignore"]
|
|
38
|
-
});
|
|
39
|
-
}
|
|
32
|
+
const git = (worktreePath, args) => runGit(worktreePath, args, { timeout: 15000, noOptionalLocks: true, rawPaths: true, stderr: "ignore", trim: false });
|
|
40
33
|
|
|
41
34
|
export function parsePorcelainLine(line) {
|
|
42
35
|
// " M path", "?? path", "R old -> new"
|
|
@@ -120,33 +113,23 @@ export function filterWorkspaceSetupChanges(task, changes) {
|
|
|
120
113
|
});
|
|
121
114
|
}
|
|
122
115
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const base = resolveWorktreeBase(worktreePath, { baseCommit, branch });
|
|
126
|
-
if (!base) return { error: "no_base_commit", files: [] };
|
|
127
|
-
let head = null;
|
|
128
|
-
try {
|
|
129
|
-
head = git(worktreePath, ["rev-parse", "HEAD"]).trim();
|
|
130
|
-
} catch {
|
|
131
|
-
// a worktree without a resolvable HEAD still has a working tree to diff
|
|
132
|
-
}
|
|
133
|
-
const scope = Array.isArray(paths) && paths.length > 0 ? ["--", ...paths] : [];
|
|
134
|
-
const ignored = ignorePaths.map(normalizedPath);
|
|
135
|
-
const isIgnored = (path) => ignored.some((entry) => underPath(path, entry));
|
|
136
|
-
|
|
116
|
+
// Tracked changes against the base, or null when git cannot diff at all.
|
|
117
|
+
function trackedChanges(worktreePath, base, scope, isIgnored) {
|
|
137
118
|
const files = [];
|
|
138
|
-
const known = new Set();
|
|
139
119
|
try {
|
|
140
120
|
for (const line of nonEmptyLines(git(worktreePath, ["diff", "--name-status", "-M", base, ...scope]))) {
|
|
141
121
|
const [code, ...rest] = line.split("\t");
|
|
142
122
|
const path = rest.at(-1);
|
|
143
123
|
if (!path || isIgnored(path)) continue;
|
|
144
|
-
known.add(path);
|
|
145
124
|
files.push({ path, status: statusWord(code), from: code.startsWith("R") && rest.length > 1 ? rest[0] : null });
|
|
146
125
|
}
|
|
147
126
|
} catch {
|
|
148
|
-
return
|
|
127
|
+
return null;
|
|
149
128
|
}
|
|
129
|
+
return files;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function diffCounts(worktreePath, base, scope, isIgnored) {
|
|
150
133
|
const counts = new Map();
|
|
151
134
|
try {
|
|
152
135
|
for (const line of nonEmptyLines(git(worktreePath, ["diff", "--numstat", "-M", base, ...scope]))) {
|
|
@@ -157,8 +140,13 @@ export function readWorktreeDiff(worktreePath, { baseCommit = null, branch = nul
|
|
|
157
140
|
} catch {
|
|
158
141
|
// counts are decoration
|
|
159
142
|
}
|
|
160
|
-
|
|
161
|
-
|
|
143
|
+
return counts;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Untracked files never show in `git diff`; the worker may have created
|
|
147
|
+
// them with a shell command and not added them.
|
|
148
|
+
function appendUntracked(files, worktreePath, scope, isIgnored) {
|
|
149
|
+
const known = new Set(files.map((file) => file.path));
|
|
162
150
|
try {
|
|
163
151
|
for (const line of git(worktreePath, ["status", "--porcelain", "--untracked-files=all", ...scope]).split("\n")) {
|
|
164
152
|
if (!line.startsWith("??")) continue;
|
|
@@ -170,7 +158,23 @@ export function readWorktreeDiff(worktreePath, { baseCommit = null, branch = nul
|
|
|
170
158
|
} catch {
|
|
171
159
|
// status failing leaves the tracked part
|
|
172
160
|
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// The patch text of one file; an untracked file is shown as all additions.
|
|
164
|
+
function filePatch(worktreePath, base, file) {
|
|
165
|
+
try {
|
|
166
|
+
if (file.status !== "untracked") return git(worktreePath, ["diff", "-M", base, "--", file.path]);
|
|
167
|
+
const text = readFileSync(join(worktreePath, file.path), "utf8");
|
|
168
|
+
const patch = text.split("\n").map((l, i, all) => (i === all.length - 1 && l === "" ? null : `+${l}`)).filter((l) => l !== null).join("\n");
|
|
169
|
+
if (file.additions === null) file.additions = patch === "" ? 0 : patch.split("\n").length;
|
|
170
|
+
return patch;
|
|
171
|
+
} catch {
|
|
172
|
+
return "";
|
|
173
|
+
}
|
|
174
|
+
}
|
|
173
175
|
|
|
176
|
+
// Fills each file's counts and patch within one shared character budget.
|
|
177
|
+
function attachPatches(files, counts, worktreePath, base, maxChars) {
|
|
174
178
|
let remaining = maxChars;
|
|
175
179
|
let truncatedFiles = 0;
|
|
176
180
|
for (const file of files) {
|
|
@@ -184,18 +188,7 @@ export function readWorktreeDiff(worktreePath, { baseCommit = null, branch = nul
|
|
|
184
188
|
truncatedFiles += 1;
|
|
185
189
|
continue;
|
|
186
190
|
}
|
|
187
|
-
|
|
188
|
-
try {
|
|
189
|
-
if (file.status === "untracked") {
|
|
190
|
-
const text = readFileSync(join(worktreePath, file.path), "utf8");
|
|
191
|
-
patch = text.split("\n").map((l, i, all) => (i === all.length - 1 && l === "" ? null : `+${l}`)).filter((l) => l !== null).join("\n");
|
|
192
|
-
if (file.additions === null) file.additions = patch === "" ? 0 : patch.split("\n").length;
|
|
193
|
-
} else {
|
|
194
|
-
patch = git(worktreePath, ["diff", "-M", base, "--", file.path]);
|
|
195
|
-
}
|
|
196
|
-
} catch {
|
|
197
|
-
patch = "";
|
|
198
|
-
}
|
|
191
|
+
const patch = filePatch(worktreePath, base, file);
|
|
199
192
|
if (patch.length > remaining) {
|
|
200
193
|
file.patch = truncateMiddleChars(patch, remaining);
|
|
201
194
|
file.truncated = true;
|
|
@@ -206,6 +199,28 @@ export function readWorktreeDiff(worktreePath, { baseCommit = null, branch = nul
|
|
|
206
199
|
remaining -= patch.length;
|
|
207
200
|
}
|
|
208
201
|
}
|
|
202
|
+
return truncatedFiles;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function readWorktreeDiff(worktreePath, { baseCommit = null, branch = null } = {}, { maxChars = 60000, paths = [], ignorePaths = [] } = {}) {
|
|
206
|
+
if (!worktreePath || !existsSync(worktreePath)) return { error: "no_worktree", files: [] };
|
|
207
|
+
const base = resolveWorktreeBase(worktreePath, { baseCommit, branch });
|
|
208
|
+
if (!base) return { error: "no_base_commit", files: [] };
|
|
209
|
+
let head = null;
|
|
210
|
+
try {
|
|
211
|
+
head = git(worktreePath, ["rev-parse", "HEAD"]).trim();
|
|
212
|
+
} catch {
|
|
213
|
+
// a worktree without a resolvable HEAD still has a working tree to diff
|
|
214
|
+
}
|
|
215
|
+
const scope = Array.isArray(paths) && paths.length > 0 ? ["--", ...paths] : [];
|
|
216
|
+
const ignored = ignorePaths.map(normalizedPath);
|
|
217
|
+
const isIgnored = (path) => ignored.some((entry) => underPath(path, entry));
|
|
218
|
+
|
|
219
|
+
const files = trackedChanges(worktreePath, base, scope, isIgnored);
|
|
220
|
+
if (!files) return { error: "diff_failed", base_commit: base, head, files: [] };
|
|
221
|
+
const counts = diffCounts(worktreePath, base, scope, isIgnored);
|
|
222
|
+
appendUntracked(files, worktreePath, scope, isIgnored);
|
|
223
|
+
const truncatedFiles = attachPatches(files, counts, worktreePath, base, maxChars);
|
|
209
224
|
return { base_commit: base, head, files, total_files: files.length, truncated_files: truncatedFiles };
|
|
210
225
|
}
|
|
211
226
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { DatabaseSync } from "node:sqlite";
|
|
3
|
-
import { DEFAULT_ACCEPTANCE_TIMEOUT_MS, runAcceptance } from "
|
|
4
|
-
import { dbPath } from "
|
|
3
|
+
import { DEFAULT_ACCEPTANCE_TIMEOUT_MS, runAcceptance } from "../../app/acceptance.js";
|
|
4
|
+
import { dbPath } from "../../infra/paths.js";
|
|
5
5
|
|
|
6
6
|
function readTask(taskId) {
|
|
7
7
|
let db;
|
|
@@ -16,7 +16,11 @@ function readTask(taskId) {
|
|
|
16
16
|
`).get(taskId);
|
|
17
17
|
if (!row) return null;
|
|
18
18
|
let acceptance = null;
|
|
19
|
-
try {
|
|
19
|
+
try {
|
|
20
|
+
acceptance = row.acceptance ? JSON.parse(row.acceptance) : null;
|
|
21
|
+
} catch {
|
|
22
|
+
// A contract that does not parse is treated as absent.
|
|
23
|
+
}
|
|
20
24
|
return { ...row, acceptance };
|
|
21
25
|
} finally {
|
|
22
26
|
db?.close();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
2
|
+
import "../../app/compose.js";
|
|
3
|
+
import { applyCleanupPlan, createCleanupPlan } from "../../app/cleanup-plan.js";
|
|
4
|
+
import { getCleanupPlan, saveCleanupPlan } from "../../infra/store/records.js";
|
|
4
5
|
|
|
5
6
|
function parseArgs(argv) {
|
|
6
7
|
const options = { apply: false, taskIds: [], itemIds: [], planId: null };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import "../../app/compose.js";
|
|
2
3
|
import React, { useEffect, useMemo, useState } from "react";
|
|
3
4
|
import { Box, Newline, render, Text, useApp, useInput, useStdout } from "ink";
|
|
4
|
-
import { readTaskEvents
|
|
5
|
+
import { readTaskEvents } from "../../infra/store/events.js";
|
|
6
|
+
import { readTasks } from "../../infra/store/tasks.js";
|
|
7
|
+
import { reconcileDetachedActiveTasks } from "../../infra/store/reconcile.js";
|
|
5
8
|
|
|
6
9
|
const REFRESH_MS = 1000;
|
|
7
10
|
const STATUS_LABELS = {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// codex-supervisor-setup --target claude --force
|
|
10
10
|
//
|
|
11
11
|
// Set CODEX_SUPERVISOR_SKIP_SETUP=1 to opt out of the automatic run.
|
|
12
|
-
import {
|
|
12
|
+
import { runFile } from "../../infra/process.js";
|
|
13
13
|
import { existsSync, readdirSync } from "node:fs";
|
|
14
14
|
import { homedir } from "node:os";
|
|
15
15
|
import { basename, dirname, isAbsolute, join } from "node:path";
|
|
@@ -20,13 +20,13 @@ import {
|
|
|
20
20
|
findBinaryPath,
|
|
21
21
|
resolveCommand,
|
|
22
22
|
shimMessage
|
|
23
|
-
} from "
|
|
23
|
+
} from "../../infra/bin-resolver.js";
|
|
24
24
|
|
|
25
|
-
const run = promisify(
|
|
25
|
+
const run = promisify(runFile);
|
|
26
26
|
|
|
27
|
-
import { installSkill, skillRoots } from "
|
|
27
|
+
import { installSkill, skillRoots } from "../../infra/skill-sync.js";
|
|
28
28
|
|
|
29
|
-
const packageRoot =
|
|
29
|
+
const packageRoot = fileURLToPath(new URL("../../..", import.meta.url)).replace(/[\\/]$/, "");
|
|
30
30
|
const serverEntry = join(packageRoot, "src", "mcp-server.js");
|
|
31
31
|
|
|
32
32
|
const MCP_NAME = "codex-supervisor";
|
|
@@ -179,7 +179,8 @@ async function registeredMcp(target, client) {
|
|
|
179
179
|
if (client.id === "codex") {
|
|
180
180
|
const value = JSON.parse(stdout);
|
|
181
181
|
const transport = value.transport ?? value;
|
|
182
|
-
|
|
182
|
+
const { command, args = [], env = {}, cwd } = transport;
|
|
183
|
+
return { command, args: args ?? [], env: env ?? {}, cwd, enabled: value.enabled !== false, userScope: true };
|
|
183
184
|
}
|
|
184
185
|
const command = stdout.match(/^\s*Command: (.+)$/m)?.[1]?.trim();
|
|
185
186
|
const args = stdout.match(/^\s*Args: (.*)$/m)?.[1]?.trim();
|