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
package/src/web-app.js
DELETED
|
@@ -1,425 +0,0 @@
|
|
|
1
|
-
// The board's HTTP server: a thin read-only view over the supervisor store.
|
|
2
|
-
// Which sessions exist, what each one is doing right now, what every Codex
|
|
3
|
-
// thread under a session has done. It reads the same SQLite file the MCP
|
|
4
|
-
// server writes and never writes to it, apart from the same orphan
|
|
5
|
-
// reconcile every read does. web-server.js is the entry that decides which
|
|
6
|
-
// store to open and then calls startWebServer().
|
|
7
|
-
import { createServer } from "node:http";
|
|
8
|
-
import { createReadStream, existsSync, statSync } from "node:fs";
|
|
9
|
-
import { extname, join, normalize, resolve } from "node:path";
|
|
10
|
-
import { fileURLToPath } from "node:url";
|
|
11
|
-
import {
|
|
12
|
-
getTask,
|
|
13
|
-
listTaskEventKinds,
|
|
14
|
-
readAgentMessages,
|
|
15
|
-
readSessions,
|
|
16
|
-
readTaskEvents,
|
|
17
|
-
readTasks,
|
|
18
|
-
reconcileDetachedActiveTasks
|
|
19
|
-
} from "./task-store.js";
|
|
20
|
-
import { readNativeGoal } from "./goal-store.js";
|
|
21
|
-
import { readTaskChanges } from "./worktree.js";
|
|
22
|
-
import { ACTIVE_STATUSES } from "./status.js";
|
|
23
|
-
import { supervisorRoot } from "./paths.js";
|
|
24
|
-
import { checkForUpdate } from "./update-check.js";
|
|
25
|
-
import { attachToTurn, endSideSession, runSideTurn, sideSessionState, stopSideTurn } from "./side-chat.js";
|
|
26
|
-
|
|
27
|
-
const here = fileURLToPath(new URL(".", import.meta.url));
|
|
28
|
-
const distDir = resolve(here, "..", "web", "dist");
|
|
29
|
-
const port = Number(process.env.SUPERVISOR_WEB_PORT ?? 7877);
|
|
30
|
-
const host = process.env.SUPERVISOR_WEB_HOST ?? "127.0.0.1";
|
|
31
|
-
const NO_SESSION = "none";
|
|
32
|
-
|
|
33
|
-
const MIME = {
|
|
34
|
-
".html": "text/html; charset=utf-8",
|
|
35
|
-
".js": "text/javascript; charset=utf-8",
|
|
36
|
-
".css": "text/css; charset=utf-8",
|
|
37
|
-
".json": "application/json; charset=utf-8",
|
|
38
|
-
".svg": "image/svg+xml",
|
|
39
|
-
".woff2": "font/woff2",
|
|
40
|
-
".woff": "font/woff",
|
|
41
|
-
".png": "image/png",
|
|
42
|
-
".ico": "image/x-icon"
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
function clip(value, maxChars) {
|
|
46
|
-
if (value === null || value === undefined) return null;
|
|
47
|
-
const text = String(value);
|
|
48
|
-
return text.length <= maxChars ? text : `${text.slice(0, maxChars)}…`;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function durationMs(task) {
|
|
52
|
-
const start = Date.parse(task.started_at ?? task.created_at ?? "");
|
|
53
|
-
if (Number.isNaN(start)) return null;
|
|
54
|
-
const end = Date.parse(task.completed_at ?? "");
|
|
55
|
-
const stop = Number.isNaN(end) ? Date.now() : end;
|
|
56
|
-
return Math.max(0, stop - start);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// The row every list shows. No prompt, no raw events: those are per-worker
|
|
60
|
-
// reads, so a session with forty threads stays one cheap request.
|
|
61
|
-
function workerRow(task) {
|
|
62
|
-
return {
|
|
63
|
-
id: task.id,
|
|
64
|
-
title: task.title,
|
|
65
|
-
status: task.status,
|
|
66
|
-
phase: task.phase ?? null,
|
|
67
|
-
session_id: task.session_id ?? null,
|
|
68
|
-
thread_id: task.thread_id ?? null,
|
|
69
|
-
goal: task.goal_objective ?? null,
|
|
70
|
-
goal_status: task.goal_status ?? null,
|
|
71
|
-
model: task.model ?? null,
|
|
72
|
-
sandbox: task.sandbox,
|
|
73
|
-
project_root: task.project_root,
|
|
74
|
-
worktree_path: task.worktree_path ?? null,
|
|
75
|
-
branch: task.worktree_path ? `codex/${task.id}` : null,
|
|
76
|
-
base_commit: task.base_commit ?? null,
|
|
77
|
-
owned_paths: task.owned_paths ?? [],
|
|
78
|
-
depends_on: task.depends_on ?? [],
|
|
79
|
-
followup_of: task.followup_of ?? null,
|
|
80
|
-
resumed_from: task.resumed_from ?? null,
|
|
81
|
-
run_count: task.run_count ?? 0,
|
|
82
|
-
current_action: clip(task.current_action, 300),
|
|
83
|
-
last_message: clip(task.last_message, 400),
|
|
84
|
-
changed_file_count: liveChangeCount(task),
|
|
85
|
-
acceptance: task.acceptance_results?.status ?? null,
|
|
86
|
-
landed_at: task.landed_at ?? null,
|
|
87
|
-
command_count: (task.commands ?? []).length,
|
|
88
|
-
error: task.error ?? null,
|
|
89
|
-
exit_code: task.exit_code ?? null,
|
|
90
|
-
pid: task.pid ?? null,
|
|
91
|
-
created_at: task.created_at || null,
|
|
92
|
-
started_at: task.started_at || null,
|
|
93
|
-
updated_at: task.updated_at || null,
|
|
94
|
-
completed_at: task.completed_at || null,
|
|
95
|
-
duration_ms: durationMs(task)
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Changed-file counts for the list. The stored changed_files on a row only
|
|
100
|
-
// knows about file_change events; the truth is the worktree diff, which costs
|
|
101
|
-
// two git calls per worker. Terminal rows never change again, so their count
|
|
102
|
-
// is memoised on (id, updated_at); running rows are re-read every time.
|
|
103
|
-
const changeCountCache = new Map();
|
|
104
|
-
function liveChangeCount(task) {
|
|
105
|
-
const key = `${task.id}:${task.updated_at}:${task.status}`;
|
|
106
|
-
const cached = changeCountCache.get(key);
|
|
107
|
-
if (cached !== undefined && !ACTIVE_STATUSES.has(task.status)) return cached;
|
|
108
|
-
const count = readTaskChanges(task).length;
|
|
109
|
-
changeCountCache.set(key, count);
|
|
110
|
-
if (changeCountCache.size > 2000) changeCountCache.delete(changeCountCache.keys().next().value);
|
|
111
|
-
return count;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function sessionKey(task) {
|
|
115
|
-
return task.session_id || NO_SESSION;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function latest(values) {
|
|
119
|
-
return values.filter(Boolean).sort().at(-1) ?? null;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// What a session is about. The title the main thread recorded wins; without
|
|
123
|
-
// one, the goals of its workers are the next best description.
|
|
124
|
-
function aboutSession(meta, tasks) {
|
|
125
|
-
if (meta?.title) return { title: meta.title, note: meta.note ?? null, derived: false };
|
|
126
|
-
const goals = Array.from(new Set(tasks.map((task) => task.goal_objective).filter(Boolean)));
|
|
127
|
-
const summary = goals.slice(0, 3).map((goal) => clip(goal, 60)).join(";");
|
|
128
|
-
return { title: summary || null, note: null, derived: true };
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function sessionRow(key, tasks, meta = null) {
|
|
132
|
-
const counts = {};
|
|
133
|
-
for (const task of tasks) counts[task.status] = (counts[task.status] ?? 0) + 1;
|
|
134
|
-
const active = tasks.filter((task) => ACTIVE_STATUSES.has(task.status));
|
|
135
|
-
const byActivity = [...tasks].sort((a, b) => String(b.updated_at ?? "").localeCompare(String(a.updated_at ?? "")));
|
|
136
|
-
const lastReport = byActivity.find((task) => task.last_message);
|
|
137
|
-
const about = aboutSession(meta, tasks);
|
|
138
|
-
return {
|
|
139
|
-
id: key,
|
|
140
|
-
unsessioned: key === NO_SESSION,
|
|
141
|
-
title: about.title,
|
|
142
|
-
note: about.note,
|
|
143
|
-
title_derived: about.derived,
|
|
144
|
-
worker_count: tasks.length,
|
|
145
|
-
active_count: active.length,
|
|
146
|
-
counts,
|
|
147
|
-
project_roots: Array.from(new Set(tasks.map((task) => task.project_root).filter(Boolean))),
|
|
148
|
-
first_created_at: tasks.map((task) => task.created_at).filter(Boolean).sort()[0] ?? null,
|
|
149
|
-
last_activity_at: latest(tasks.map((task) => task.updated_at)),
|
|
150
|
-
// What the session is doing right now: one line per running thread.
|
|
151
|
-
now: active.map((task) => ({
|
|
152
|
-
id: task.id,
|
|
153
|
-
title: task.title,
|
|
154
|
-
phase: task.phase ?? null,
|
|
155
|
-
current_action: clip(task.current_action, 160)
|
|
156
|
-
})),
|
|
157
|
-
last_report: lastReport
|
|
158
|
-
? { id: lastReport.id, title: lastReport.title, text: clip(lastReport.last_message, 240), at: lastReport.updated_at }
|
|
159
|
-
: null
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Pagination for the lists: `limit` rows after `offset`, newest activity
|
|
164
|
-
// first for sessions, dispatch order for workers. The page says whether
|
|
165
|
-
// there is more so the board loads the rest as the user scrolls.
|
|
166
|
-
function pageParams(url, defaultLimit) {
|
|
167
|
-
const limit = Math.min(200, Math.max(1, Number(url.searchParams.get("limit") ?? defaultLimit) || defaultLimit));
|
|
168
|
-
const offset = Math.max(0, Number(url.searchParams.get("offset") ?? 0) || 0);
|
|
169
|
-
return { limit, offset };
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function paginate(items, { limit, offset }) {
|
|
173
|
-
return { items: items.slice(offset, offset + limit), total: items.length, offset, limit, has_more: offset + limit < items.length };
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
async function overview({ limit, offset } = { limit: 20, offset: 0 }) {
|
|
177
|
-
await reconcileDetachedActiveTasks();
|
|
178
|
-
const tasks = await readTasks();
|
|
179
|
-
const metas = new Map((await readSessions()).map((row) => [row.id, row]));
|
|
180
|
-
const groups = new Map();
|
|
181
|
-
for (const task of tasks) {
|
|
182
|
-
const key = sessionKey(task);
|
|
183
|
-
if (!groups.has(key)) groups.set(key, []);
|
|
184
|
-
groups.get(key).push(task);
|
|
185
|
-
}
|
|
186
|
-
const sessions = Array.from(groups, ([key, group]) => sessionRow(key, group, metas.get(key) ?? null)).sort((a, b) => {
|
|
187
|
-
if (a.active_count !== b.active_count) return b.active_count - a.active_count;
|
|
188
|
-
return String(b.last_activity_at ?? "").localeCompare(String(a.last_activity_at ?? ""));
|
|
189
|
-
});
|
|
190
|
-
const page = paginate(sessions, { limit, offset });
|
|
191
|
-
return {
|
|
192
|
-
generated_at: new Date().toISOString(),
|
|
193
|
-
store: supervisorRoot,
|
|
194
|
-
total_workers: tasks.length,
|
|
195
|
-
active_workers: tasks.filter((task) => ACTIVE_STATUSES.has(task.status)).length,
|
|
196
|
-
total_sessions: sessions.length,
|
|
197
|
-
offset: page.offset,
|
|
198
|
-
limit: page.limit,
|
|
199
|
-
has_more: page.has_more,
|
|
200
|
-
sessions: page.items
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
async function session(key, { limit, offset } = { limit: 40, offset: 0 }) {
|
|
205
|
-
await reconcileDetachedActiveTasks();
|
|
206
|
-
const tasks = (await readTasks()).filter((task) => sessionKey(task) === key);
|
|
207
|
-
if (tasks.length === 0) return null;
|
|
208
|
-
const meta = (await readSessions()).find((row) => row.id === key) ?? null;
|
|
209
|
-
const ordered = [...tasks].sort((a, b) => String(a.created_at ?? "").localeCompare(String(b.created_at ?? "")));
|
|
210
|
-
const page = paginate(ordered, { limit, offset });
|
|
211
|
-
return {
|
|
212
|
-
...sessionRow(key, tasks, meta),
|
|
213
|
-
offset: page.offset,
|
|
214
|
-
limit: page.limit,
|
|
215
|
-
has_more: page.has_more,
|
|
216
|
-
workers: page.items.map(workerRow)
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
async function worker(taskId) {
|
|
221
|
-
const task = await getTask(taskId);
|
|
222
|
-
if (!task) return null;
|
|
223
|
-
const reports = await readAgentMessages(taskId, 10);
|
|
224
|
-
// Token spend comes from Codex's own turn.completed usage blocks; one per
|
|
225
|
-
// run, so a resumed worker sums its runs.
|
|
226
|
-
const usage = { input_tokens: 0, cached_input_tokens: 0, output_tokens: 0, reasoning_output_tokens: 0, turns: 0 };
|
|
227
|
-
for (const event of await readTaskEvents(taskId, 50, ["turn.completed"])) {
|
|
228
|
-
const block = event?.usage ?? {};
|
|
229
|
-
usage.turns += 1;
|
|
230
|
-
for (const key of ["input_tokens", "cached_input_tokens", "output_tokens", "reasoning_output_tokens"]) {
|
|
231
|
-
usage[key] += Number(block[key] ?? 0) || 0;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
const commands = (task.commands ?? []).slice(-40).map((entry) => ({
|
|
235
|
-
...entry,
|
|
236
|
-
command: clip(entry.command, 600)
|
|
237
|
-
}));
|
|
238
|
-
return {
|
|
239
|
-
...workerRow(task),
|
|
240
|
-
prompt: task.prompt ?? null,
|
|
241
|
-
changed_files: readTaskChanges(task),
|
|
242
|
-
commands,
|
|
243
|
-
reports: reports.length > 0 ? reports : task.last_message ? [task.last_message] : [],
|
|
244
|
-
native_goal: readNativeGoal(task.thread_id),
|
|
245
|
-
usage,
|
|
246
|
-
notices: task.notices ?? null,
|
|
247
|
-
run_log: task.run_log ?? null,
|
|
248
|
-
event_kinds: await listTaskEventKinds(taskId)
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
async function events(taskId, url) {
|
|
253
|
-
const limit = Math.min(1000, Math.max(1, Number(url.searchParams.get("limit") ?? 150)));
|
|
254
|
-
const kinds = url.searchParams.get("kinds")?.split(",").filter(Boolean) ?? null;
|
|
255
|
-
return { task_id: taskId, events: await readTaskEvents(taskId, limit, kinds) };
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// Read a JSON request body, capped so a stray client cannot fill memory.
|
|
259
|
-
function readJson(req, limit = 2 * 1024 * 1024) {
|
|
260
|
-
return new Promise((resolve, reject) => {
|
|
261
|
-
let size = 0;
|
|
262
|
-
const chunks = [];
|
|
263
|
-
req.on("data", (chunk) => {
|
|
264
|
-
size += chunk.length;
|
|
265
|
-
if (size > limit) {
|
|
266
|
-
reject(Object.assign(new Error("request body too large"), { code: "too_large" }));
|
|
267
|
-
req.destroy();
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
chunks.push(chunk);
|
|
271
|
-
});
|
|
272
|
-
req.on("end", () => {
|
|
273
|
-
const text = Buffer.concat(chunks).toString("utf8");
|
|
274
|
-
if (!text.trim()) return resolve({});
|
|
275
|
-
try {
|
|
276
|
-
resolve(JSON.parse(text));
|
|
277
|
-
} catch (error) {
|
|
278
|
-
reject(Object.assign(new Error(`invalid JSON body: ${error.message}`), { code: "bad_json" }));
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
req.on("error", reject);
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
// The last user message of an AI SDK useChat request, as plain text.
|
|
286
|
-
function lastUserText(body) {
|
|
287
|
-
if (typeof body?.text === "string") return body.text;
|
|
288
|
-
const messages = Array.isArray(body?.messages) ? body.messages : [];
|
|
289
|
-
for (let i = messages.length - 1; i >= 0; i -= 1) {
|
|
290
|
-
const m = messages[i];
|
|
291
|
-
if (m?.role !== "user") continue;
|
|
292
|
-
const parts = Array.isArray(m.parts) ? m.parts : [];
|
|
293
|
-
const text = parts.filter((p) => p?.type === "text").map((p) => p.text ?? "").join("\n").trim();
|
|
294
|
-
if (text) return text;
|
|
295
|
-
if (typeof m.content === "string" && m.content.trim()) return m.content.trim();
|
|
296
|
-
}
|
|
297
|
-
return "";
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
function json(res, status, body) {
|
|
301
|
-
const text = JSON.stringify(body);
|
|
302
|
-
res.writeHead(status, {
|
|
303
|
-
"content-type": "application/json; charset=utf-8",
|
|
304
|
-
"cache-control": "no-store",
|
|
305
|
-
"content-length": Buffer.byteLength(text)
|
|
306
|
-
});
|
|
307
|
-
res.end(text);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
function serveStatic(res, pathname) {
|
|
311
|
-
if (!existsSync(distDir)) {
|
|
312
|
-
res.writeHead(503, { "content-type": "text/plain; charset=utf-8" });
|
|
313
|
-
res.end("web/dist is missing. Run `npm run web:build` first.\n");
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
const safe = normalize(pathname).replace(/^(\.\.[/\\])+/, "");
|
|
317
|
-
let file = join(distDir, safe);
|
|
318
|
-
if (!file.startsWith(distDir)) {
|
|
319
|
-
res.writeHead(403);
|
|
320
|
-
res.end();
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
if (!existsSync(file) || statSync(file).isDirectory()) file = join(distDir, "index.html");
|
|
324
|
-
const type = MIME[extname(file)] ?? "application/octet-stream";
|
|
325
|
-
res.writeHead(200, {
|
|
326
|
-
"content-type": type,
|
|
327
|
-
"cache-control": file.endsWith("index.html") ? "no-store" : "public, max-age=31536000, immutable"
|
|
328
|
-
});
|
|
329
|
-
createReadStream(file).pipe(res);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
async function route(req, res) {
|
|
333
|
-
const url = new URL(req.url ?? "/", `http://${host}`);
|
|
334
|
-
const parts = url.pathname.split("/").filter(Boolean);
|
|
335
|
-
if (parts[0] !== "api") return serveStatic(res, url.pathname);
|
|
336
|
-
|
|
337
|
-
// The side chat is the one place the board does something: it forks the
|
|
338
|
-
// worker's Codex thread for a read-only side question.
|
|
339
|
-
if (parts[1] === "workers" && parts.length >= 4 && parts[3] === "chat") {
|
|
340
|
-
const taskId = decodeURIComponent(parts[2]);
|
|
341
|
-
const task = await getTask(taskId);
|
|
342
|
-
if (!task) return json(res, 404, { error: "task_not_found" });
|
|
343
|
-
const action = parts[4] ?? null;
|
|
344
|
-
// GET .../chat/<chatId>/stream is what the AI SDK client calls to
|
|
345
|
-
// resume: replay the running turn, or 204 when nothing is running.
|
|
346
|
-
if (req.method === "GET" && parts.length === 6 && parts[5] === "stream") {
|
|
347
|
-
attachToTurn(taskId, res);
|
|
348
|
-
return undefined;
|
|
349
|
-
}
|
|
350
|
-
if (req.method === "GET" && !action) return json(res, 200, { task_id: taskId, can_ask: Boolean(task.thread_id), worker_status: task.status, ...(await sideSessionState(taskId)) });
|
|
351
|
-
if (req.method === "DELETE" && !action) return json(res, 200, { task_id: taskId, ...(await endSideSession(taskId)) });
|
|
352
|
-
if (req.method === "POST" && action === "stop") return json(res, 200, { task_id: taskId, ...stopSideTurn(taskId) });
|
|
353
|
-
if (req.method === "POST" && !action) {
|
|
354
|
-
let body;
|
|
355
|
-
try {
|
|
356
|
-
body = await readJson(req);
|
|
357
|
-
} catch (error) {
|
|
358
|
-
return json(res, 400, { error: error.code ?? "bad_request", message: error.message });
|
|
359
|
-
}
|
|
360
|
-
const text = lastUserText(body);
|
|
361
|
-
if (!text) return json(res, 400, { error: "empty_question", message: "send a user message with text" });
|
|
362
|
-
try {
|
|
363
|
-
await runSideTurn({ task, text, res });
|
|
364
|
-
} catch (error) {
|
|
365
|
-
if (res.headersSent) return undefined;
|
|
366
|
-
const status = error.code === "busy" ? 409 : error.code === "no_thread" ? 400 : error.code === "codex_missing" ? 503 : 500;
|
|
367
|
-
return json(res, status, { error: error.code ?? "side_chat_failed", message: error.message });
|
|
368
|
-
}
|
|
369
|
-
return undefined;
|
|
370
|
-
}
|
|
371
|
-
return json(res, 405, { error: "method_not_allowed" });
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
if (req.method !== "GET") return json(res, 405, { error: "method_not_allowed" });
|
|
375
|
-
|
|
376
|
-
if (parts[1] === "overview" && parts.length === 2) return json(res, 200, await overview(pageParams(url, 20)));
|
|
377
|
-
if (parts[1] === "version" && parts.length === 2) {
|
|
378
|
-
return json(res, 200, await checkForUpdate({ force: url.searchParams.get("force") === "1" }));
|
|
379
|
-
}
|
|
380
|
-
if (parts[1] === "sessions" && parts.length === 3) {
|
|
381
|
-
const body = await session(decodeURIComponent(parts[2]), pageParams(url, 40));
|
|
382
|
-
return body ? json(res, 200, body) : json(res, 404, { error: "session_not_found" });
|
|
383
|
-
}
|
|
384
|
-
if (parts[1] === "workers" && parts.length === 3) {
|
|
385
|
-
const body = await worker(decodeURIComponent(parts[2]));
|
|
386
|
-
return body ? json(res, 200, body) : json(res, 404, { error: "task_not_found" });
|
|
387
|
-
}
|
|
388
|
-
if (parts[1] === "workers" && parts.length === 4 && parts[3] === "events") {
|
|
389
|
-
const taskId = decodeURIComponent(parts[2]);
|
|
390
|
-
if (!(await getTask(taskId))) return json(res, 404, { error: "task_not_found" });
|
|
391
|
-
return json(res, 200, await events(taskId, url));
|
|
392
|
-
}
|
|
393
|
-
return json(res, 404, { error: "not_found" });
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
export function startWebServer({ storeOrigin = "default" } = {}) {
|
|
397
|
-
const server = createServer((req, res) => {
|
|
398
|
-
route(req, res).catch((error) => {
|
|
399
|
-
process.stderr.write(`[codex-supervisor-web] ${error.stack ?? error.message}\n`);
|
|
400
|
-
if (!res.headersSent) json(res, 500, { error: "internal", message: error.message });
|
|
401
|
-
else res.end();
|
|
402
|
-
});
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
// A taken port is the one error a person will actually hit, usually because
|
|
406
|
-
// a board is already running. Say that, not a stack trace.
|
|
407
|
-
server.on("error", (error) => {
|
|
408
|
-
if (error.code === "EADDRINUSE") {
|
|
409
|
-
process.stderr.write(
|
|
410
|
-
`codex-supervisor-web: port ${port} on ${host} is already in use.\n` +
|
|
411
|
-
` A board may already be running at http://${host}:${port}\n` +
|
|
412
|
-
` To run a second one, pick another port: SUPERVISOR_WEB_PORT=8080 codex-supervisor-web\n`
|
|
413
|
-
);
|
|
414
|
-
process.exit(1);
|
|
415
|
-
}
|
|
416
|
-
process.stderr.write(`codex-supervisor-web: ${error.message}\n`);
|
|
417
|
-
process.exit(1);
|
|
418
|
-
});
|
|
419
|
-
|
|
420
|
-
server.listen(port, host, () => {
|
|
421
|
-
const boundPort = server.address().port;
|
|
422
|
-
process.stdout.write(`codex-supervisor web view on http://${host}:${boundPort}\n store: ${supervisorRoot} (${storeOrigin})\n`);
|
|
423
|
-
});
|
|
424
|
-
return server;
|
|
425
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|