codex-supervisor-mcp 0.9.7 → 0.10.2

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/src/mcp-server.js CHANGED
@@ -14,6 +14,8 @@ import {
14
14
  } from "./codex-runner.js";
15
15
  import {
16
16
  getSession,
17
+ getFact,
18
+ getWorkItemForTask,
17
19
  getTask,
18
20
  getTasks,
19
21
  isPidAlive,
@@ -24,17 +26,27 @@ import {
24
26
  readObserverCursor,
25
27
  writeObserverCursor,
26
28
  readTasksBySession,
29
+ latestContextSnapshotForTask,
27
30
  reconcileDetachedActiveTasks,
28
31
  recordTerminalChangedFiles,
29
32
  searchTasks,
30
33
  upsertSession,
31
- upsertTask
34
+ upsertTask,
35
+ appendTaskEvent,
36
+ recordFact,
37
+ runIdFor,
38
+ updateWorkItemDelivery,
39
+ saveCleanupPlan,
40
+ getCleanupPlan,
41
+ markCleanupPlanItemApplied,
42
+ readCleanupHistory
32
43
  } from "./task-store.js";
33
44
  import { readNativeGoal, readNativeGoalState } from "./goal-store.js";
34
45
  import { collectWorkerChanges } from "./worker-changes.js";
35
46
  import { buildHostGoalSync } from "./prompt.js";
36
47
  import { baseBehind, readTaskChanges, readWorktreeDiff, worktreeRef } from "./worktree.js";
37
48
  import { summarizeVerification } from "./event-parser.js";
49
+ import { readPreflightResult } from "./worker-preflight.js";
38
50
  import { acceptanceVerdict, runAcceptance } from "./acceptance.js";
39
51
  import { ACTIVE_STATUSES, TERMINAL_STATUSES, TASK_STATUSES, isGoalNeedingAttention } from "./status.js";
40
52
  import { approxTokenCount, truncateEventStrings, truncateMiddleChars, truncateReport } from "./truncate.js";
@@ -44,6 +56,8 @@ import { maybeAutoUpdate } from "./auto-update.js";
44
56
  import { askWorker, endSideSession, latestSideTurn } from "./side-chat.js";
45
57
  import { landWorker } from "./landing.js";
46
58
  import { cleanupHint } from "./cleanup-hint.js";
59
+ import { createCleanupPlan, removePlannedWorktree } from "./cleanup-plan.js";
60
+ import { buildOverviewDelta } from "./overview-delta.js";
47
61
 
48
62
  // Report the real package version. This string had drifted to 0.4.0 while the
49
63
  // package shipped 0.5.x, so the handshake named a version nobody was running.
@@ -123,6 +137,14 @@ const OVERVIEW_CAP_LEVELS = [
123
137
  { title: 0, goal: 0, action: 0, path: 0 }
124
138
  ];
125
139
 
140
+ function git(cwd, args) {
141
+ return execFileSync(process.env.GIT_BIN?.trim() || "git", ["-C", cwd, ...args], {
142
+ encoding: "utf8",
143
+ timeout: 60000,
144
+ stdio: ["ignore", "pipe", "pipe"]
145
+ }).trim();
146
+ }
147
+
126
148
  // `current_action` is "Running <command>", and a command can be a heredoc that
127
149
  // writes a whole file. Returning it whole put tens of thousands of characters
128
150
  // into every wait response, which then blew past the client's MCP output cap
@@ -527,7 +549,30 @@ const acceptanceCheck = z.union([
527
549
  const acceptanceInput = z.union([z.string().min(1), z.array(acceptanceCheck).max(10)]);
528
550
 
529
551
  const observerId = process.env.CODEX_SUPERVISOR_OBSERVER_ID?.trim() || `mcp-${randomUUID()}`;
552
+ const deltaObserverId = process.env.CODEX_SUPERVISOR_DELTA_OBSERVER_ID?.trim() || `${observerId}:delta`;
530
553
  let observerRead = Promise.resolve();
554
+ let deltaRead = Promise.resolve();
555
+ server.registerTool(
556
+ "overview_delta",
557
+ {
558
+ title: "Get orchestration delta",
559
+ description: "Return a small cursor-based orchestration view: active, needs_attention, ready_to_land, ready_to_clean and changed task summaries. It never returns full history, prompts, diffs, events or worker capsules.",
560
+ inputSchema: { cursor: z.record(z.string(), z.string()).optional() }
561
+ },
562
+ async ({ cursor }) => {
563
+ const read = deltaRead.then(async () => {
564
+ await reconcileDetachedActiveTasks();
565
+ const tasks = await readTasks();
566
+ const previous = cursor ?? await readObserverCursor(deltaObserverId);
567
+ const result = buildOverviewDelta(tasks, previous);
568
+ await writeObserverCursor(deltaObserverId, result.cursor);
569
+ const { cursor: nextCursor, ...reply } = result;
570
+ return textResult({ ...reply, next_cursor: nextCursor });
571
+ });
572
+ deltaRead = read.catch(() => {});
573
+ return read;
574
+ }
575
+ );
531
576
  server.registerTool("check_workers", {
532
577
  title: "Check changed workers",
533
578
  description: "Check newly settled runs and actionable failures; automatically resume a dead lost/no_work first run once, except approval, authentication, permission and quota waits. Returns recovery receipts; unchanged state is quiet. Call from a host-scheduled loop; it cannot wake a closed host. Set a distinct CODEX_SUPERVISOR_OBSERVER_ID per main thread to retain its cursor across restarts.",
@@ -576,6 +621,70 @@ server.registerTool(
576
621
  }
577
622
  );
578
623
 
624
+ server.registerTool(
625
+ "preflight_codex_worker",
626
+ {
627
+ title: "Preflight Codex worker environment",
628
+ description:
629
+ "Launch a short-lived Codex probe worker in the same base commit, sandbox, guard, network and writable-root configuration intended for a later write worker. The probe must run every requested command in the actual worker environment. Read get_worker_preflight after it settles, then pass its task_id as create_codex_worker.preflight_id; a changed runtime contract is refused.",
630
+ inputSchema: {
631
+ title: z.string().optional(),
632
+ cwd: z.string().min(1),
633
+ sandbox: z.enum(["read-only", "workspace-write", "danger-full-access"]).default("workspace-write"),
634
+ model: z.string().optional(),
635
+ reasoningEffort: z.enum(["minimal", "low", "medium", "high"]).default("high"),
636
+ skipGitRepoCheck: z.boolean().default(true),
637
+ ownedPaths: z.array(z.string().min(1)),
638
+ forbid: z.array(z.string().min(1)).max(100).optional(),
639
+ allowedCommands: z.array(z.string().min(1)).max(100).optional(),
640
+ context: z.array(z.object({ path: z.string().min(1), sha256: z.string().regex(/^[a-f0-9]{64}$/).optional() })).max(20).optional(),
641
+ contracts: z.array(z.string().min(1).max(2000)).max(20).optional(),
642
+ networkAccess: z.boolean().default(false),
643
+ writableRoots: z.array(z.string().min(1)).max(20).optional(),
644
+ maxRunMs: z.number().int().min(1000).max(86400000).optional(),
645
+ maxTotalMs: z.number().int().min(1000).max(604800000).optional(),
646
+ baseRef: z.string().min(1).optional(),
647
+ probeCommands: z.array(z.string().min(1)).min(1).max(20)
648
+ }
649
+ },
650
+ async (input) => {
651
+ try {
652
+ const task = [
653
+ "Runtime environment preflight. Do not edit files, create files, install packages, dispatch workers or call MCP tools.",
654
+ "Run every command below exactly once, in the listed order, without wrapping it in another shell command.",
655
+ "If any command is denied, missing, times out or exits nonzero, stop and quote the raw error under Not done / risks.",
656
+ "Commands:",
657
+ ...input.probeCommands.map((command) => `- ${command}`)
658
+ ].join("\n");
659
+ const record = await createCodexWorker({
660
+ ...input,
661
+ title: input.title ? `Preflight: ${input.title}` : "Runtime environment preflight",
662
+ task,
663
+ goal: { objective: `Prove the requested Codex worker runtime environment before dispatching ${input.title ?? "the dependent worker"}` },
664
+ acceptance: null,
665
+ preflight: { probeCommands: input.probeCommands }
666
+ });
667
+ return textResult(withUpdate({ ...receipt(record), preflight: { status: "running", probe_commands: input.probeCommands } }));
668
+ } catch (error) {
669
+ return errorResult(error);
670
+ }
671
+ }
672
+ );
673
+
674
+ server.registerTool(
675
+ "get_worker_preflight",
676
+ {
677
+ title: "Get worker preflight result",
678
+ description: "Read whether a preflight probe ran every required command successfully in the tracked worker environment, plus the immutable runtime contract hash required by create_codex_worker.preflight_id.",
679
+ inputSchema: { task_id: z.string().min(1) }
680
+ },
681
+ async ({ task_id }) => {
682
+ const task = await getTask(task_id);
683
+ if (!task) return textResult({ error: "task_not_found", task_id });
684
+ return textResult(readPreflightResult(task));
685
+ }
686
+ );
687
+
579
688
  server.registerTool(
580
689
  "create_codex_worker",
581
690
  {
@@ -620,6 +729,9 @@ server.registerTool(
620
729
  // HEAD; pass a branch, tag or sha to build on work that is not on the
621
730
  // main line yet (for example another worker's codex/<id> branch).
622
731
  baseRef: z.string().min(1).optional(),
732
+ // A successful preflight_codex_worker task id. When present, this worker
733
+ // is refused unless base commit and the complete runtime contract match.
734
+ preflight_id: z.string().min(1).optional(),
623
735
  // Shell commands that decide whether the work is done. The supervisor
624
736
  // runs them in the worktree after codex exits; each must exit 0.
625
737
  acceptance: acceptanceInput.optional(),
@@ -630,6 +742,7 @@ server.registerTool(
630
742
  try {
631
743
  const record = await createCodexWorker({
632
744
  ...input,
745
+ preflightId: input.preflight_id ?? null,
633
746
  sessionId: input.session_id ?? null,
634
747
  sessionTitle: input.session_title ?? null,
635
748
  sessionNote: input.session_note ?? null
@@ -1033,6 +1146,48 @@ server.registerTool(
1033
1146
  }
1034
1147
  );
1035
1148
 
1149
+ server.registerTool(
1150
+ "get_context_snapshot_meta",
1151
+ {
1152
+ title: "Get worker context snapshot metadata",
1153
+ description: "Read the latest worker-only context snapshot metadata for one task. Returns fact IDs, token estimate and excluded categories, never the capsule text or raw history.",
1154
+ inputSchema: { task_id: z.string().min(1) }
1155
+ },
1156
+ async ({ task_id }) => {
1157
+ const task = await getTask(task_id);
1158
+ if (!task) return textResult({ error: "task_not_found", task_id });
1159
+ const snapshot = await latestContextSnapshotForTask(task_id);
1160
+ if (!snapshot) return textResult({ task_id, snapshot: null });
1161
+ return textResult({
1162
+ task_id,
1163
+ snapshot: {
1164
+ id: snapshot.id,
1165
+ run_id: snapshot.run_id,
1166
+ recipient: snapshot.recipient,
1167
+ fact_ids: JSON.parse(snapshot.fact_versions),
1168
+ base_sha: snapshot.base_sha,
1169
+ prompt_sha256: snapshot.prompt_sha256,
1170
+ estimated_tokens: snapshot.estimated_tokens,
1171
+ excluded: JSON.parse(snapshot.excluded_json),
1172
+ created_at: snapshot.created_at
1173
+ }
1174
+ });
1175
+ }
1176
+ );
1177
+
1178
+ server.registerTool(
1179
+ "get_fact",
1180
+ {
1181
+ title: "Get one verified or candidate fact",
1182
+ description: "Read one fact by ID for audit. Facts are never automatically expanded into the main thread's context.",
1183
+ inputSchema: { fact_id: z.string().uuid() }
1184
+ },
1185
+ async ({ fact_id }) => {
1186
+ const fact = await getFact(fact_id);
1187
+ return textResult(fact ? { fact } : { error: "fact_not_found", fact_id });
1188
+ }
1189
+ );
1190
+
1036
1191
  server.registerTool(
1037
1192
  "get_worker_goal",
1038
1193
  {
@@ -1254,12 +1409,196 @@ server.registerTool(
1254
1409
  // Recorded so a later read knows the work is on the branch: the
1255
1410
  // board shows it, and base_behind after this is not drift.
1256
1411
  const now = new Date().toISOString();
1257
- await upsertTask({ ...task, landed_at: now, landed_head: outcome.head ?? null, updated_at: now });
1412
+ const landed = { ...task, landed_at: now, landed_head: outcome.head ?? null, landed_branch: outcome.onto ?? null, updated_at: now };
1413
+ await upsertTask(landed);
1414
+ await updateWorkItemDelivery(task_id, "landed");
1415
+ const event = await appendTaskEvent(task_id, {
1416
+ type: "supervisor.landed",
1417
+ head: outcome.head ?? null,
1418
+ branch: outcome.onto ?? null,
1419
+ target: outcome.target ?? null,
1420
+ landed_at: now
1421
+ }, { runId: runIdFor(task_id, task.run_count ?? 1), actor: "supervisor" });
1422
+ const workItem = await getWorkItemForTask(task_id);
1423
+ if (workItem && outcome.head) {
1424
+ await recordFact({
1425
+ workItemId: workItem.id,
1426
+ scopeType: "work_item",
1427
+ scopeId: workItem.id,
1428
+ key: "landed",
1429
+ value: { head: outcome.head, branch: outcome.onto ?? null },
1430
+ state: "verified",
1431
+ sourceEventId: event.id,
1432
+ validForSha: outcome.head,
1433
+ watchedPaths: task.owned_paths ?? []
1434
+ });
1435
+ }
1258
1436
  }
1259
1437
  return textResult({ task_id, title: task.title, status: task.status, branch: `codex/${task.id}`, ...outcome });
1260
1438
  }
1261
1439
  );
1262
1440
 
1441
+ server.registerTool(
1442
+ "verify_delivery_push",
1443
+ {
1444
+ title: "Verify landed work reached a remote branch",
1445
+ description: "Fetch a remote branch and prove the worker's landed_head is reachable from it. This never pushes or deploys. A passing check records push_verified; cleanup eligibility may depend on this evidence.",
1446
+ inputSchema: {
1447
+ task_id: z.string().min(1),
1448
+ remote: z.string().min(1).default("origin"),
1449
+ branch: z.string().min(1).optional()
1450
+ }
1451
+ },
1452
+ async ({ task_id, remote, branch }) => {
1453
+ const task = await getTask(task_id);
1454
+ if (!task) return textResult({ error: "task_not_found", task_id });
1455
+ const targetBranch = branch ?? task.landed_branch;
1456
+ if (!task.landed_at || !task.landed_head || !targetBranch) {
1457
+ return textResult({ error: "not_landed", task_id, reason: "land the worker first; this task has no landed head and branch to verify" });
1458
+ }
1459
+ try {
1460
+ git(task.project_root, ["remote", "get-url", remote]);
1461
+ git(task.project_root, ["fetch", "--no-tags", remote, `refs/heads/${targetBranch}`]);
1462
+ const remoteHead = git(task.project_root, ["rev-parse", "FETCH_HEAD"]);
1463
+ try {
1464
+ git(task.project_root, ["merge-base", "--is-ancestor", task.landed_head, remoteHead]);
1465
+ } catch {
1466
+ return textResult({
1467
+ error: "not_pushed",
1468
+ task_id,
1469
+ remote,
1470
+ branch: targetBranch,
1471
+ landed_head: task.landed_head,
1472
+ remote_head: remoteHead,
1473
+ reason: "landed_head is not reachable from the fetched remote branch"
1474
+ });
1475
+ }
1476
+ const now = new Date().toISOString();
1477
+ const verified = { ...task, push_verified_at: now, push_remote: remote, push_branch: targetBranch, updated_at: now };
1478
+ await upsertTask(verified);
1479
+ await updateWorkItemDelivery(task_id, "push_verified");
1480
+ const event = await appendTaskEvent(task_id, {
1481
+ type: "supervisor.push_verified",
1482
+ remote,
1483
+ branch: targetBranch,
1484
+ landed_head: task.landed_head,
1485
+ remote_head: remoteHead,
1486
+ verified_at: now
1487
+ }, { runId: runIdFor(task_id, task.run_count ?? 1), actor: "supervisor" });
1488
+ const workItem = await getWorkItemForTask(task_id);
1489
+ if (workItem) {
1490
+ await recordFact({
1491
+ workItemId: workItem.id,
1492
+ scopeType: "work_item",
1493
+ scopeId: workItem.id,
1494
+ key: "push_verified",
1495
+ value: { remote, branch: targetBranch, landed_head: task.landed_head, remote_head: remoteHead },
1496
+ state: "verified",
1497
+ sourceEventId: event.id,
1498
+ validForSha: task.landed_head,
1499
+ watchedPaths: task.owned_paths ?? []
1500
+ });
1501
+ }
1502
+ const cleanupPlan = await createCleanupPlan({ taskIds: [task_id] });
1503
+ await saveCleanupPlan(cleanupPlan);
1504
+ return textResult({
1505
+ task_id,
1506
+ remote,
1507
+ branch: targetBranch,
1508
+ landed_head: task.landed_head,
1509
+ remote_head: remoteHead,
1510
+ push_verified_at: now,
1511
+ cleanup_plan: { id: cleanupPlan.id, summary: cleanupPlan.summary, expires_at: cleanupPlan.expires_at, next_step: "Review SAFE items, then call apply_cleanup with their item IDs; cleanup is never automatic." }
1512
+ });
1513
+ } catch (error) {
1514
+ return textResult({ error: "push_verification_failed", task_id, remote, branch: targetBranch, reason: error.message.split("\n")[0] });
1515
+ }
1516
+ }
1517
+ );
1518
+
1519
+ server.registerTool(
1520
+ "cleanup_plan",
1521
+ {
1522
+ title: "Plan safe worktree cleanup",
1523
+ description: "Classify managed worktrees as safe, review or blocked. The plan is read-only, expires after 15 minutes, estimates reclaimable bytes and never deletes branches, task rows, events, JSONL logs or artifacts.",
1524
+ inputSchema: {
1525
+ task_ids: z.array(z.string().min(1)).max(200).optional(),
1526
+ project_root: z.string().min(1).optional()
1527
+ }
1528
+ },
1529
+ async ({ task_ids, project_root }) => {
1530
+ try {
1531
+ const plan = await createCleanupPlan({ taskIds: task_ids ?? null, projectRoot: project_root ?? null });
1532
+ await saveCleanupPlan(plan);
1533
+ return textResult({
1534
+ plan_id: plan.id,
1535
+ generated_at: plan.generated_at,
1536
+ expires_at: plan.expires_at,
1537
+ policy: plan.policy,
1538
+ summary: plan.summary,
1539
+ items: plan.items
1540
+ });
1541
+ } catch (error) {
1542
+ return errorResult(error);
1543
+ }
1544
+ }
1545
+ );
1546
+
1547
+ server.registerTool(
1548
+ "apply_cleanup",
1549
+ {
1550
+ title: "Apply a safe cleanup plan",
1551
+ description: "Remove only selected SAFE worktrees from an unexpired cleanup plan after a second proof check. Uses git worktree remove and prune only; retains the branch, task row, event stream, JSONL log and artifacts.",
1552
+ inputSchema: {
1553
+ plan_id: z.string().uuid(),
1554
+ item_ids: z.array(z.string().uuid()).min(1).max(200)
1555
+ }
1556
+ },
1557
+ async ({ plan_id, item_ids }) => {
1558
+ const plan = await getCleanupPlan(plan_id);
1559
+ if (!plan) return textResult({ error: "cleanup_plan_not_found", plan_id });
1560
+ if (Date.parse(plan.expires_at) <= Date.now()) return textResult({ error: "cleanup_plan_expired", plan_id, expires_at: plan.expires_at });
1561
+ const selected = plan.items.filter((item) => item_ids.includes(item.id));
1562
+ if (selected.length !== item_ids.length) return textResult({ error: "cleanup_plan_item_not_found", plan_id });
1563
+ const applied = [];
1564
+ const skipped = [];
1565
+ for (const item of selected) {
1566
+ if (item.verdict !== "safe") {
1567
+ skipped.push({ item_id: item.id, task_id: item.task_id, reason: "only SAFE plan items may be applied" });
1568
+ continue;
1569
+ }
1570
+ const task = await getTask(item.task_id);
1571
+ if (!task) {
1572
+ skipped.push({ item_id: item.id, task_id: item.task_id, reason: "task no longer exists" });
1573
+ continue;
1574
+ }
1575
+ try {
1576
+ await removePlannedWorktree(task, item.fingerprint);
1577
+ const now = await markCleanupPlanItemApplied(item.id);
1578
+ await updateWorkItemDelivery(task.id, "cleanup_removed");
1579
+ await appendTaskEvent(task.id, { type: "supervisor.cleanup_removed", plan_id, item_id: item.id, removed_at: now, retained: ["branch", "task", "events", "jsonl", "artifacts"] }, {
1580
+ runId: runIdFor(task.id, task.run_count ?? 1),
1581
+ actor: "supervisor"
1582
+ });
1583
+ applied.push({ item_id: item.id, task_id: task.id, worktree_path: task.worktree_path, removed_at: now });
1584
+ } catch (error) {
1585
+ skipped.push({ item_id: item.id, task_id: item.task_id, reason: error.message.split("\n")[0] });
1586
+ }
1587
+ }
1588
+ return textResult({ plan_id, applied, skipped, retained: ["branch", "task", "events", "jsonl", "artifacts"] });
1589
+ }
1590
+ );
1591
+
1592
+ server.registerTool(
1593
+ "cleanup_history",
1594
+ {
1595
+ title: "Read cleanup history",
1596
+ description: "Read cleanup plan decisions and applied worktree removals, including safe/review/blocked reasons. This is audit history, not a delete command.",
1597
+ inputSchema: { task_id: z.string().min(1).optional(), limit: z.number().int().min(1).max(500).default(100) }
1598
+ },
1599
+ async ({ task_id, limit }) => textResult({ items: await readCleanupHistory(task_id ?? null, limit) })
1600
+ );
1601
+
1263
1602
  server.registerTool(
1264
1603
  "cancel_codex_worker",
1265
1604
  {
@@ -0,0 +1,34 @@
1
+ import { ACTIVE_STATUSES, isGoalNeedingAttention } from "./status.js";
2
+
3
+ function readyToLand(task) {
4
+ return task.status === "completed" && task.exit_code === 0 && (!task.acceptance_results || task.acceptance_results.passed === true) && !task.landed_at;
5
+ }
6
+
7
+ function readyToClean(task) {
8
+ return task.push_verified_at && ["cleanup_eligible"].includes(task.delivery_state);
9
+ }
10
+
11
+ export function buildOverviewDelta(tasks, cursor = {}) {
12
+ const active = tasks.filter((task) => ACTIVE_STATUSES.has(task.status));
13
+ const attention = tasks.filter((task) => isGoalNeedingAttention(task.goal_status) || task.attention_reason || task.acceptance_results?.passed === false);
14
+ const land = tasks.filter(readyToLand);
15
+ const clean = tasks.filter(readyToClean);
16
+ const nextCursor = {};
17
+ const changes = [];
18
+ for (const task of tasks) {
19
+ const fingerprint = JSON.stringify([task.run_count ?? 0, task.status, task.exit_code ?? null, task.attention_reason ?? null, task.landed_head ?? null, task.push_verified_at ?? null, task.delivery_state ?? null, task.updated_at]);
20
+ nextCursor[task.id] = fingerprint;
21
+ if (cursor[task.id] !== fingerprint) {
22
+ changes.push({ id: task.id, title: task.title ?? task.id, status: task.status, delivery_state: task.delivery_state ?? "draft", attention: attention.some((item) => item.id === task.id), ready_to_land: land.some((item) => item.id === task.id), ready_to_clean: clean.some((item) => item.id === task.id), updated_at: task.updated_at });
23
+ }
24
+ }
25
+ return {
26
+ generated_at: new Date().toISOString(),
27
+ active: active.length,
28
+ needs_attention: attention.length,
29
+ ready_to_land: land.length,
30
+ ready_to_clean: clean.length,
31
+ changes,
32
+ cursor: nextCursor
33
+ };
34
+ }
package/src/side-chat.js CHANGED
@@ -24,10 +24,8 @@
24
24
  // session ended ................... fork deleted, history cleared
25
25
  import { execFileSync, spawn } from "node:child_process";
26
26
  import { randomUUID } from "node:crypto";
27
- import { readFileSync } from "node:fs";
28
- import { join } from "node:path";
29
- import { codexHome } from "./paths.js";
30
27
  import { defaultBinDirs, findBinaryPath, resolveCommand, shimMessage } from "./bin-resolver.js";
28
+ import { codexConfigText, disableMcpServerArgs } from "./mcp-config.js";
31
29
  import {
32
30
  closeSideSession,
33
31
  getSideSession,
@@ -68,25 +66,7 @@ export function sideQuestionText(question) {
68
66
  // server literally called "name", quotes included, with no transport, and
69
67
  // the whole config then fails to load.
70
68
  export function sideTurnConfigArgs(configText) {
71
- const names = new Set();
72
- for (const line of String(configText ?? "").split("\n")) {
73
- const match = line.match(/^\s*\[mcp_servers\.(?:"([^"]+)"|([^\].]+))\]\s*(?:#.*)?$/);
74
- if (match) names.add(match[1] ?? match[2]);
75
- }
76
- const args = [];
77
- for (const name of names) {
78
- if (!/^[A-Za-z0-9_-]+$/.test(name)) continue; // a name codex cannot take bare on the command line
79
- args.push("-c", `mcp_servers.${name}.enabled=false`);
80
- }
81
- return args;
82
- }
83
-
84
- function codexConfigText() {
85
- try {
86
- return readFileSync(join(codexHome, "config.toml"), "utf8");
87
- } catch {
88
- return "";
89
- }
69
+ return disableMcpServerArgs(configText);
90
70
  }
91
71
 
92
72
  // The session to ask on. A fork taken before the worker was resumed no