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.
Files changed (101) hide show
  1. package/package.json +18 -63
  2. package/src/{acceptance.js → app/acceptance.js} +54 -68
  3. package/src/app/cancel.js +60 -0
  4. package/src/{cleanup-plan.js → app/cleanup-plan.js} +11 -12
  5. package/src/app/compose.js +7 -0
  6. package/src/{context-compiler.js → app/context-compiler.js} +7 -13
  7. package/src/app/dispatch.js +396 -0
  8. package/src/app/followup.js +98 -0
  9. package/src/app/land-chain.js +124 -0
  10. package/src/app/landing.js +357 -0
  11. package/src/app/ownership.js +57 -0
  12. package/src/app/rebase.js +216 -0
  13. package/src/app/resume.js +164 -0
  14. package/src/app/run-state.js +26 -0
  15. package/src/app/settled.js +28 -0
  16. package/src/{side-chat.js → app/side-chat.js} +79 -265
  17. package/src/app/sse.js +20 -0
  18. package/src/app/start-run.js +77 -0
  19. package/src/app/verify-push.js +119 -0
  20. package/src/app/worktree-setup.js +176 -0
  21. package/src/{acceptance-baseline.js → domain/acceptance-baseline.js} +2 -1
  22. package/src/domain/acceptance-spec.js +30 -0
  23. package/src/domain/command-outcome.js +6 -0
  24. package/src/{overview-delta.js → domain/overview-delta.js} +5 -1
  25. package/src/domain/side-turn-view.js +73 -0
  26. package/src/{worker-preflight.js → domain/worker-preflight.js} +1 -1
  27. package/src/infra/git.js +30 -0
  28. package/src/infra/process.js +59 -0
  29. package/src/{sandbox-roots.js → infra/sandbox-roots.js} +2 -1
  30. package/src/{skill-sync.js → infra/skill-sync.js} +1 -1
  31. package/src/infra/store/db.js +265 -0
  32. package/src/infra/store/events.js +146 -0
  33. package/src/infra/store/facts.js +338 -0
  34. package/src/infra/store/reconcile.js +172 -0
  35. package/src/infra/store/records.js +160 -0
  36. package/src/infra/store/runner-readers.js +16 -0
  37. package/src/infra/store/schema.js +306 -0
  38. package/src/infra/store/sessions.js +138 -0
  39. package/src/infra/store/tasks.js +307 -0
  40. package/src/{auto-update-worker.js → infra/update/auto-update-worker.js} +4 -4
  41. package/src/{auto-update.js → infra/update/auto-update.js} +3 -3
  42. package/src/{update-check.js → infra/update/update-check.js} +4 -4
  43. package/src/{workspace-kind.js → infra/workspace-kind.js} +5 -7
  44. package/src/{worktree.js → infra/worktree.js} +56 -41
  45. package/src/{acceptance-cli.js → interface/bin/acceptance-cli.js} +7 -3
  46. package/src/{cleanup.js → interface/bin/cleanup.js} +3 -2
  47. package/src/{monitor.jsx → interface/bin/monitor.jsx} +4 -1
  48. package/src/{setup.js → interface/bin/setup.js} +7 -6
  49. package/src/{stage.js → interface/bin/stage.js} +1 -1
  50. package/src/{web-server.js → interface/bin/web-server.js} +2 -2
  51. package/src/interface/mcp/meta.js +7 -0
  52. package/src/interface/mcp/result.js +34 -0
  53. package/src/interface/mcp/schemas.js +24 -0
  54. package/src/interface/mcp/server.js +94 -0
  55. package/src/interface/mcp/tools/delivery.js +197 -0
  56. package/src/interface/mcp/tools/dispatch.js +267 -0
  57. package/src/interface/mcp/tools/facts.js +239 -0
  58. package/src/interface/mcp/tools/overview.js +202 -0
  59. package/src/interface/mcp/tools/poll.js +62 -0
  60. package/src/interface/mcp/tools/results.js +270 -0
  61. package/src/interface/mcp/tools/review.js +135 -0
  62. package/src/interface/mcp/tools/wait.js +145 -0
  63. package/src/interface/mcp/update-state.js +34 -0
  64. package/src/interface/mcp/views/overview.js +183 -0
  65. package/src/interface/mcp/views/task.js +223 -0
  66. package/src/interface/web/app.js +226 -0
  67. package/src/interface/web/views.js +224 -0
  68. package/src/mcp-server.js +3 -2223
  69. package/src/run-host/entry.js +23 -0
  70. package/src/run-host/finalize.js +236 -0
  71. package/src/run-host/launch.js +63 -0
  72. package/src/run-host/live-run.js +73 -0
  73. package/src/run-host/outcome-facts.js +61 -0
  74. package/src/run-host/streams.js +76 -0
  75. package/src/run-host/track.js +128 -0
  76. package/src/{runner-adapter.js → runners/codex/adapter.js} +6 -6
  77. package/src/runners/codex/chat-chunks.js +97 -0
  78. package/src/{event-parser.js → runners/codex/event-parser.js} +57 -55
  79. package/src/{goal-store.js → runners/codex/goal-store.js} +2 -2
  80. package/src/{mcp-config.js → runners/codex/mcp-config.js} +1 -1
  81. package/src/codex-runner.js +0 -1586
  82. package/src/landing.js +0 -507
  83. package/src/task-store.js +0 -1800
  84. package/src/web-app.js +0 -425
  85. /package/src/{failure-class.js → domain/failure-class.js} +0 -0
  86. /package/src/{owned-changes.js → domain/owned-changes.js} +0 -0
  87. /package/src/{prompt.js → domain/prompt.js} +0 -0
  88. /package/src/{status.js → domain/status.js} +0 -0
  89. /package/src/{thread-health.js → domain/thread-health.js} +0 -0
  90. /package/src/{truncate.js → domain/truncate.js} +0 -0
  91. /package/src/{worker-changes.js → domain/worker-changes.js} +0 -0
  92. /package/src/{worker-env.js → domain/worker-env.js} +0 -0
  93. /package/src/{worker-report.js → domain/worker-report.js} +0 -0
  94. /package/src/{worker-report.schema.json → domain/worker-report.schema.json} +0 -0
  95. /package/src/{bin-resolver.js → infra/bin-resolver.js} +0 -0
  96. /package/src/{cleanup-hint.js → infra/cleanup-hint.js} +0 -0
  97. /package/src/{external-output.js → infra/external-output.js} +0 -0
  98. /package/src/{handoff.js → infra/handoff.js} +0 -0
  99. /package/src/{paths.js → infra/paths.js} +0 -0
  100. /package/src/{stage-store.js → infra/stage-store.js} +0 -0
  101. /package/src/{tool-guard.js → runners/codex/tool-guard.js} +0 -0
@@ -0,0 +1,224 @@
1
+ // What the board shows: session and worker rows built from the store, read-only.
2
+ import { ACTIVE_STATUSES } from "../../domain/status.js";
3
+ import { supervisorRoot } from "../../infra/paths.js";
4
+ import { listTaskEventKinds, readAgentMessages, readTaskEvents } from "../../infra/store/events.js";
5
+ import { reconcileDetachedActiveTasks } from "../../infra/store/reconcile.js";
6
+ import { readSessions } from "../../infra/store/sessions.js";
7
+ import { getTask, readTasks } from "../../infra/store/tasks.js";
8
+ import { readTaskChanges } from "../../infra/worktree.js";
9
+ import { readNativeGoal } from "../../runners/codex/goal-store.js";
10
+
11
+ const NO_SESSION = "none";
12
+
13
+ function clip(value, maxChars) {
14
+ if (value === null || value === undefined) return null;
15
+ const text = String(value);
16
+ return text.length <= maxChars ? text : `${text.slice(0, maxChars)}…`;
17
+ }
18
+
19
+ function durationMs(task) {
20
+ const start = Date.parse(task.started_at ?? task.created_at ?? "");
21
+ if (Number.isNaN(start)) return null;
22
+ const end = Date.parse(task.completed_at ?? "");
23
+ const stop = Number.isNaN(end) ? Date.now() : end;
24
+ return Math.max(0, stop - start);
25
+ }
26
+
27
+ // The row every list shows. No prompt, no raw events: those are per-worker
28
+ // reads, so a session with forty threads stays one cheap request.
29
+ function workerRow(task) {
30
+ return {
31
+ id: task.id,
32
+ title: task.title,
33
+ status: task.status,
34
+ phase: task.phase ?? null,
35
+ session_id: task.session_id ?? null,
36
+ thread_id: task.thread_id ?? null,
37
+ goal: task.goal_objective ?? null,
38
+ goal_status: task.goal_status ?? null,
39
+ model: task.model ?? null,
40
+ sandbox: task.sandbox,
41
+ project_root: task.project_root,
42
+ worktree_path: task.worktree_path ?? null,
43
+ branch: task.worktree_path ? `codex/${task.id}` : null,
44
+ base_commit: task.base_commit ?? null,
45
+ owned_paths: task.owned_paths ?? [],
46
+ depends_on: task.depends_on ?? [],
47
+ followup_of: task.followup_of ?? null,
48
+ resumed_from: task.resumed_from ?? null,
49
+ run_count: task.run_count ?? 0,
50
+ current_action: clip(task.current_action, 300),
51
+ last_message: clip(task.last_message, 400),
52
+ changed_file_count: liveChangeCount(task),
53
+ acceptance: task.acceptance_results?.status ?? null,
54
+ landed_at: task.landed_at ?? null,
55
+ command_count: (task.commands ?? []).length,
56
+ error: task.error ?? null,
57
+ exit_code: task.exit_code ?? null,
58
+ pid: task.pid ?? null,
59
+ created_at: task.created_at || null,
60
+ started_at: task.started_at || null,
61
+ updated_at: task.updated_at || null,
62
+ completed_at: task.completed_at || null,
63
+ duration_ms: durationMs(task)
64
+ };
65
+ }
66
+
67
+ // Changed-file counts for the list. The stored changed_files on a row only
68
+ // knows about file_change events; the truth is the worktree diff, which costs
69
+ // two git calls per worker. Terminal rows never change again, so their count
70
+ // is memoised on (id, updated_at); running rows are re-read every time.
71
+ const changeCountCache = new Map();
72
+ function liveChangeCount(task) {
73
+ const key = `${task.id}:${task.updated_at}:${task.status}`;
74
+ const cached = changeCountCache.get(key);
75
+ if (cached !== undefined && !ACTIVE_STATUSES.has(task.status)) return cached;
76
+ const count = readTaskChanges(task).length;
77
+ changeCountCache.set(key, count);
78
+ if (changeCountCache.size > 2000) changeCountCache.delete(changeCountCache.keys().next().value);
79
+ return count;
80
+ }
81
+
82
+ function sessionKey(task) {
83
+ return task.session_id || NO_SESSION;
84
+ }
85
+
86
+ function latest(values) {
87
+ return values.filter(Boolean).sort().at(-1) ?? null;
88
+ }
89
+
90
+ // What a session is about. The title the main thread recorded wins; without
91
+ // one, the goals of its workers are the next best description.
92
+ function aboutSession(meta, tasks) {
93
+ if (meta?.title) return { title: meta.title, note: meta.note ?? null, derived: false };
94
+ const goals = Array.from(new Set(tasks.map((task) => task.goal_objective).filter(Boolean)));
95
+ const summary = goals.slice(0, 3).map((goal) => clip(goal, 60)).join(";");
96
+ return { title: summary || null, note: null, derived: true };
97
+ }
98
+
99
+ function sessionRow(key, tasks, meta = null) {
100
+ const counts = {};
101
+ for (const task of tasks) counts[task.status] = (counts[task.status] ?? 0) + 1;
102
+ const active = tasks.filter((task) => ACTIVE_STATUSES.has(task.status));
103
+ const byActivity = [...tasks].sort((a, b) => String(b.updated_at ?? "").localeCompare(String(a.updated_at ?? "")));
104
+ const lastReport = byActivity.find((task) => task.last_message);
105
+ const about = aboutSession(meta, tasks);
106
+ return {
107
+ id: key,
108
+ unsessioned: key === NO_SESSION,
109
+ title: about.title,
110
+ note: about.note,
111
+ title_derived: about.derived,
112
+ worker_count: tasks.length,
113
+ active_count: active.length,
114
+ counts,
115
+ project_roots: Array.from(new Set(tasks.map((task) => task.project_root).filter(Boolean))),
116
+ first_created_at: tasks.map((task) => task.created_at).filter(Boolean).sort()[0] ?? null,
117
+ last_activity_at: latest(tasks.map((task) => task.updated_at)),
118
+ // What the session is doing right now: one line per running thread.
119
+ now: active.map((task) => ({
120
+ id: task.id,
121
+ title: task.title,
122
+ phase: task.phase ?? null,
123
+ current_action: clip(task.current_action, 160)
124
+ })),
125
+ last_report: lastReport
126
+ ? { id: lastReport.id, title: lastReport.title, text: clip(lastReport.last_message, 240), at: lastReport.updated_at }
127
+ : null
128
+ };
129
+ }
130
+
131
+ // Pagination for the lists: `limit` rows after `offset`, newest activity
132
+ // first for sessions, dispatch order for workers. The page says whether
133
+ // there is more so the board loads the rest as the user scrolls.
134
+ export function pageParams(url, defaultLimit) {
135
+ const limit = Math.min(200, Math.max(1, Number(url.searchParams.get("limit") ?? defaultLimit) || defaultLimit));
136
+ const offset = Math.max(0, Number(url.searchParams.get("offset") ?? 0) || 0);
137
+ return { limit, offset };
138
+ }
139
+
140
+ function paginate(items, { limit, offset }) {
141
+ return { items: items.slice(offset, offset + limit), total: items.length, offset, limit, has_more: offset + limit < items.length };
142
+ }
143
+
144
+ export async function overview({ limit, offset } = { limit: 20, offset: 0 }) {
145
+ await reconcileDetachedActiveTasks();
146
+ const tasks = await readTasks();
147
+ const metas = new Map((await readSessions()).map((row) => [row.id, row]));
148
+ const groups = new Map();
149
+ for (const task of tasks) {
150
+ const key = sessionKey(task);
151
+ if (!groups.has(key)) groups.set(key, []);
152
+ groups.get(key).push(task);
153
+ }
154
+ const sessions = Array.from(groups, ([key, group]) => sessionRow(key, group, metas.get(key) ?? null)).sort((a, b) => {
155
+ if (a.active_count !== b.active_count) return b.active_count - a.active_count;
156
+ return String(b.last_activity_at ?? "").localeCompare(String(a.last_activity_at ?? ""));
157
+ });
158
+ const page = paginate(sessions, { limit, offset });
159
+ return {
160
+ generated_at: new Date().toISOString(),
161
+ store: supervisorRoot,
162
+ total_workers: tasks.length,
163
+ active_workers: tasks.filter((task) => ACTIVE_STATUSES.has(task.status)).length,
164
+ total_sessions: sessions.length,
165
+ offset: page.offset,
166
+ limit: page.limit,
167
+ has_more: page.has_more,
168
+ sessions: page.items
169
+ };
170
+ }
171
+
172
+ export async function session(key, { limit, offset } = { limit: 40, offset: 0 }) {
173
+ await reconcileDetachedActiveTasks();
174
+ const tasks = (await readTasks()).filter((task) => sessionKey(task) === key);
175
+ if (tasks.length === 0) return null;
176
+ const meta = (await readSessions()).find((row) => row.id === key) ?? null;
177
+ const ordered = [...tasks].sort((a, b) => String(a.created_at ?? "").localeCompare(String(b.created_at ?? "")));
178
+ const page = paginate(ordered, { limit, offset });
179
+ return {
180
+ ...sessionRow(key, tasks, meta),
181
+ offset: page.offset,
182
+ limit: page.limit,
183
+ has_more: page.has_more,
184
+ workers: page.items.map(workerRow)
185
+ };
186
+ }
187
+
188
+ export async function worker(taskId) {
189
+ const task = await getTask(taskId);
190
+ if (!task) return null;
191
+ const reports = await readAgentMessages(taskId, 10);
192
+ // Token spend comes from Codex's own turn.completed usage blocks; one per
193
+ // run, so a resumed worker sums its runs.
194
+ const usage = { input_tokens: 0, cached_input_tokens: 0, output_tokens: 0, reasoning_output_tokens: 0, turns: 0 };
195
+ for (const event of await readTaskEvents(taskId, 50, ["turn.completed"])) {
196
+ const block = event?.usage ?? {};
197
+ usage.turns += 1;
198
+ for (const key of ["input_tokens", "cached_input_tokens", "output_tokens", "reasoning_output_tokens"]) {
199
+ usage[key] += Number(block[key] ?? 0) || 0;
200
+ }
201
+ }
202
+ const commands = (task.commands ?? []).slice(-40).map((entry) => ({
203
+ ...entry,
204
+ command: clip(entry.command, 600)
205
+ }));
206
+ return {
207
+ ...workerRow(task),
208
+ prompt: task.prompt ?? null,
209
+ changed_files: readTaskChanges(task),
210
+ commands,
211
+ reports: reports.length > 0 ? reports : task.last_message ? [task.last_message] : [],
212
+ native_goal: readNativeGoal(task.thread_id),
213
+ usage,
214
+ notices: task.notices ?? null,
215
+ run_log: task.run_log ?? null,
216
+ event_kinds: await listTaskEventKinds(taskId)
217
+ };
218
+ }
219
+
220
+ export async function events(taskId, url) {
221
+ const limit = Math.min(1000, Math.max(1, Number(url.searchParams.get("limit") ?? 150)));
222
+ const kinds = url.searchParams.get("kinds")?.split(",").filter(Boolean) ?? null;
223
+ return { task_id: taskId, events: await readTaskEvents(taskId, limit, kinds) };
224
+ }