@clagentic/console 1.10.0-beta.1 → 1.10.0-beta.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.
Files changed (68) hide show
  1. package/README.md +1 -1
  2. package/bin/cli.js +10 -0
  3. package/lib/agent-dispatch-tool.js +20 -0
  4. package/lib/build-changes.js +79 -0
  5. package/lib/build-identity.js +192 -0
  6. package/lib/build-monitor.js +125 -0
  7. package/lib/build-sha.json +2 -2
  8. package/lib/build-update-offer.js +141 -0
  9. package/lib/build-update-restart.js +142 -0
  10. package/lib/build-update-standing.js +184 -0
  11. package/lib/cli/daemon-launch.js +8 -5
  12. package/lib/cli/ipc-subcommands.js +6 -0
  13. package/lib/cli/session-subcommands.js +122 -0
  14. package/lib/cli-sessions.js +8 -1
  15. package/lib/codex-defaults.js +8 -2
  16. package/lib/daemon-projects.js +19 -0
  17. package/lib/daemon.js +166 -127
  18. package/lib/memory-shed.js +13 -32
  19. package/lib/project-connection.js +14 -0
  20. package/lib/project-external-trigger.js +91 -123
  21. package/lib/project-loop.js +5 -4
  22. package/lib/project-prompt-responses.js +5 -4
  23. package/lib/project-sessions.js +43 -68
  24. package/lib/project-user-message.js +7 -20
  25. package/lib/project.js +23 -5
  26. package/lib/prompt-registry.js +7 -0
  27. package/lib/public/css/diagnostics.css +30 -0
  28. package/lib/public/modules/agent-dispatch-tool.js +9 -0
  29. package/lib/public/modules/app-messages.js +7 -2
  30. package/lib/public/modules/app-panels.js +0 -1
  31. package/lib/public/modules/build-update-detail.js +54 -0
  32. package/lib/public/modules/diagnostics.js +126 -20
  33. package/lib/public/modules/tools.js +14 -2
  34. package/lib/public/modules/vendor-picker.js +2 -2
  35. package/lib/public/modules/vendor-registry.js +11 -2
  36. package/lib/sdk-bridge.js +62 -15
  37. package/lib/sdk-message-processor.js +11 -20
  38. package/lib/sdk-skill-discovery.js +65 -60
  39. package/lib/server.js +15 -2
  40. package/lib/session-id.js +33 -0
  41. package/lib/session-input-ipc.js +32 -0
  42. package/lib/session-input.js +379 -0
  43. package/lib/session-reclaim.js +284 -0
  44. package/lib/session-resume.js +172 -0
  45. package/lib/sessions.js +16 -2
  46. package/lib/supervisor.js +39 -0
  47. package/lib/turn-initiator.js +108 -0
  48. package/lib/vendor-registry-message.js +1 -0
  49. package/lib/ws-schema.js +3 -1
  50. package/lib/yoke/adapters/claude-vendor.js +0 -1
  51. package/lib/yoke/adapters/claude-worker.js +6 -4
  52. package/lib/yoke/adapters/claude.js +34 -34
  53. package/lib/yoke/adapters/codex-capabilities.js +9 -6
  54. package/lib/yoke/adapters/codex-vendor.js +15 -15
  55. package/lib/yoke/adapters/codex.js +121 -61
  56. package/lib/yoke/auth-checks.js +8 -21
  57. package/lib/yoke/codex-app-server.js +27 -71
  58. package/lib/yoke/codex-binary.js +254 -0
  59. package/lib/yoke/codex-command.js +122 -0
  60. package/lib/yoke/codex-protocol.js +96 -0
  61. package/lib/yoke/codex-version.js +135 -0
  62. package/lib/yoke/index.js +20 -4
  63. package/lib/yoke/install-probe.js +21 -6
  64. package/lib/yoke/interface.js +11 -5
  65. package/lib/yoke/registry.js +41 -4
  66. package/package.json +1 -2
  67. package/scripts/verify-installed-build.js +59 -17
  68. package/lib/lore-attestation.js +0 -73
@@ -7,53 +7,37 @@ var path = require("path");
7
7
  var fs = require("fs");
8
8
  var { CodexAppServer } = require("../codex-app-server");
9
9
  var { discoverWorkflows } = require("../../sdk-workflow-discovery");
10
- var { discoverSkillsWithMeta, resolveContainedSkillDir } = require("../../sdk-skill-discovery");
10
+ var { discoverSkillsWithMeta, collectSkillDirs } = require("../../sdk-skill-discovery");
11
11
  var codexLocalImage = require("../codex-local-image");
12
12
  var runtimeEnv = require("../../runtime-env");
13
13
  var codexCapabilities = require("./codex-capabilities").codexCapabilities;
14
-
15
- // --- Claude skill discovery ---
16
- // Finds Claude skills in ~/.claude/skills/ and <cwd>/.claude/skills/
17
- // so Codex can recognize $<skill-name> in user input.
14
+ var codexProtocol = require("../codex-protocol");
15
+ var codexVersion = require("../codex-version");
16
+
17
+ // --- Skill discovery ---
18
+ // Finds the skills of both agents: the user's and the project's .claude/skills
19
+ // and .agents/skills (sdk-skill-discovery.js owns where they live and how a
20
+ // directory entry is contained). Codex takes a skill as an input item carrying
21
+ // the path of its SKILL.md, so a $<skill-name> in the user's text is matched
22
+ // against this list whichever agent's directory the skill sits in.
18
23
  //
19
24
  // homeOverride: optional. On a shared multi-user daemon, the caller resolves
20
25
  // the SESSION OWNER's home (os-users.getLinuxUserHome(linuxUser)) and passes
21
- // it here so the global skills dir is the invoking user's own ~/.claude/skills,
22
- // not the daemon process's REAL_HOME (lr-3ccc78). Falls back to REAL_HOME
23
- // (config.js) / os.homedir() when absent — single-user case, unchanged.
24
- function discoverClaudeSkills(cwd, homeOverride) {
25
- var skills = {};
26
+ // it here so the global skills dir is the invoking user's own, not the daemon
27
+ // process's REAL_HOME. Falls back to REAL_HOME (config.js) / os.homedir() when
28
+ // absent — single-user case, unchanged.
29
+ function discoverSkillFiles(cwd, homeOverride) {
26
30
  var globalHome = homeOverride;
27
31
  if (!globalHome) {
28
32
  try { globalHome = require("../../config").REAL_HOME; } catch (e) { globalHome = require("os").homedir(); }
29
33
  }
30
- var dirs = [
31
- path.join(globalHome, ".claude", "skills"),
32
- path.join(cwd || "", ".claude", "skills"),
33
- ];
34
- for (var d = 0; d < dirs.length; d++) {
35
- var base = dirs[d];
36
- if (!base) continue;
37
- var entries;
38
- try { entries = fs.readdirSync(path.resolve(base), { withFileTypes: true }); } catch (e) { continue; }
39
- for (var i = 0; i < entries.length; i++) {
40
- var entry = entries[i];
41
- if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
42
- // Two-stage containment (lexical + realpath) — see
43
- // sdk-skill-discovery.js's resolveContainedSkillDir doc comment.
44
- // entry.name comes from readdirSync and may be a symlink; a lexical
45
- // check alone does not stop fs.accessSync below from following a
46
- // symlinked entry outside base.
47
- var skillDir = resolveContainedSkillDir(base, entry.name);
48
- if (!skillDir) continue;
49
- var skillMd = path.join(skillDir, "SKILL.md");
50
- try {
51
- fs.accessSync(skillMd, fs.constants.R_OK);
52
- // project skills override global skills
53
- skills[entry.name] = skillMd;
54
- } catch (e) {}
55
- }
56
- }
34
+ // A session of this agent reads .agents/skills natively, so a same-named
35
+ // skill there beats the one in .claude/skills.
36
+ var dirs = collectSkillDirs(cwd, globalHome, true);
37
+ var skills = Object.create(null);
38
+ Object.keys(dirs).forEach(function(name) {
39
+ skills[name] = path.join(dirs[name], "SKILL.md");
40
+ });
57
41
  return skills;
58
42
  }
59
43
 
@@ -168,6 +152,12 @@ function waitForProcessExit(proc, timeoutMs) {
168
152
  });
169
153
  }
170
154
 
155
+ function codexError(code, message) {
156
+ var err = new Error("[yoke/codex] " + message);
157
+ err.code = code;
158
+ return err;
159
+ }
160
+
171
161
  function createShutdownError() {
172
162
  var err = new Error("Codex adapter is shutting down, retry shortly");
173
163
  err.code = "CODEX_ADAPTER_SHUTTING_DOWN";
@@ -670,6 +660,9 @@ function createCodexQueryHandle(appServer, queryOpts) {
670
660
  var canUseTool = queryOpts.canUseTool || null;
671
661
  var onElicitation = queryOpts.onElicitation || null;
672
662
  var onFinished = queryOpts.onFinished || null;
663
+ // What the running Codex accepts (codex-protocol.js). A handle made without
664
+ // one is taken to run the oldest supported Codex.
665
+ var features = queryOpts.features || codexProtocol.protocolFeatures(null);
673
666
 
674
667
  // Check if the query was cancelled (either via handle.abort() or direct signal abort)
675
668
  function isCancelled() {
@@ -990,7 +983,9 @@ function createCodexQueryHandle(appServer, queryOpts) {
990
983
  }
991
984
 
992
985
  // --- Main query loop ---
993
- async function runQueryLoop(initialMessage) {
986
+ async function runQueryLoop(initialMessage, initialInitiator) {
987
+ // Who started the turn being sent, per turn (turn-initiator.js).
988
+ var currentInitiator = initialInitiator;
994
989
  // Prepend system prompt (project instructions from YOKE layer) to first message.
995
990
  // initialMessage may be a string (text-only) or an array of content items
996
991
  // (e.g. [{ type: "text", text: "..." }, ...] when images/attachments are present).
@@ -1034,7 +1029,7 @@ function createCodexQueryHandle(appServer, queryOpts) {
1034
1029
  var threadParams = {
1035
1030
  model: _test_resolveModel(queryOpts),
1036
1031
  sandbox: queryOpts.sandboxMode || "workspace-write",
1037
- approvalPolicy: queryOpts.approvalPolicy || "on-failure",
1032
+ approvalPolicy: codexProtocol.normalizeApprovalPolicy(queryOpts.approvalPolicy),
1038
1033
  cwd: queryOpts.cwd,
1039
1034
  skipGitRepoCheck: true,
1040
1035
  };
@@ -1107,7 +1102,7 @@ function createCodexQueryHandle(appServer, queryOpts) {
1107
1102
  // was wired (e.g. warmup/init queries), while this newer site failed
1108
1103
  // closed in the same situation — an inconsistency BOBBIE flagged on
1109
1104
  // the lr-4a13c3 PR. All four sites now fail closed identically.
1110
- var availableSkills = discoverClaudeSkills(queryOpts.cwd, queryOpts.homeOverride);
1105
+ var availableSkills = discoverSkillFiles(queryOpts.cwd, queryOpts.homeOverride);
1111
1106
  var skillItemsToInject = [];
1112
1107
  var candidateSkills = [];
1113
1108
  var seenSkillNames = {};
@@ -1148,7 +1143,7 @@ function createCodexQueryHandle(appServer, queryOpts) {
1148
1143
  }
1149
1144
  }
1150
1145
  if (skillItemsToInject.length > 0) {
1151
- console.log("[yoke/codex] injecting Claude skills:", skillItemsToInject.map(function(s) { return s.name; }).join(", "));
1146
+ console.log("[yoke/codex] injecting skills:", skillItemsToInject.map(function(s) { return s.name; }).join(", "));
1152
1147
  input = input.concat(skillItemsToInject);
1153
1148
  }
1154
1149
 
@@ -1160,6 +1155,10 @@ function createCodexQueryHandle(appServer, queryOpts) {
1160
1155
  if (state.modelReasoningEffort) {
1161
1156
  turnParams.effort = state.modelReasoningEffort;
1162
1157
  }
1158
+ // Codex tells an automated turn from a typed one by this field alone,
1159
+ // and only a Codex that has it is sent it.
1160
+ var turnTrigger = features.turnTrigger ? codexProtocol.turnTriggerFor(currentInitiator) : null;
1161
+ if (turnTrigger) turnParams.turnTrigger = turnTrigger;
1163
1162
  await appServer.send("turn/start", turnParams, 60000);
1164
1163
 
1165
1164
  // Wait for turn to complete
@@ -1178,7 +1177,8 @@ function createCodexQueryHandle(appServer, queryOpts) {
1178
1177
  // Wait for next message (multi-turn)
1179
1178
  var nextMsg = await waitForMessage();
1180
1179
  if (nextMsg === null) break;
1181
- currentMessage = nextMsg;
1180
+ currentMessage = nextMsg.input;
1181
+ currentInitiator = nextMsg.initiator;
1182
1182
  }
1183
1183
  } catch (e) {
1184
1184
  // Suppress AbortError when the user stopped the query.
@@ -1221,7 +1221,7 @@ function createCodexQueryHandle(appServer, queryOpts) {
1221
1221
  };
1222
1222
  },
1223
1223
 
1224
- pushMessage: function(text, images) {
1224
+ pushMessage: function(text, images, initiator) {
1225
1225
  var input;
1226
1226
  if (images && images.length > 0) {
1227
1227
  input = [];
@@ -1254,9 +1254,9 @@ function createCodexQueryHandle(appServer, queryOpts) {
1254
1254
 
1255
1255
  if (!state.loopStarted) {
1256
1256
  state.loopStarted = true;
1257
- runQueryLoop(input);
1257
+ runQueryLoop(input, initiator);
1258
1258
  } else {
1259
- pushMessageToQueue(input);
1259
+ pushMessageToQueue({ input: input, initiator: initiator });
1260
1260
  }
1261
1261
  },
1262
1262
 
@@ -1428,9 +1428,42 @@ var CODEX_DEFAULT_MODELS = [
1428
1428
  },
1429
1429
  ];
1430
1430
 
1431
+ // --- Running version ---
1432
+
1433
+ // Config objects merged key by key; where both name a leaf, the later one wins.
1434
+ function mergeConfig(base, over) {
1435
+ var out = Object.assign({}, base);
1436
+ Object.keys(over || {}).forEach(function(key) {
1437
+ var a = out[key];
1438
+ var b = over[key];
1439
+ var plain = function(v) { return v && typeof v === "object" && !Array.isArray(v); };
1440
+ out[key] = plain(a) && plain(b) ? mergeConfig(a, b) : b;
1441
+ });
1442
+ return out;
1443
+ }
1444
+
1445
+ // The version of the Codex that is running: what the app-server's userAgent
1446
+ // reports, else what the binary reported when it was resolved. initialize has
1447
+ // no version field of its own, so a userAgent that cannot be read is no reason
1448
+ // to refuse a server whose binary reported one.
1449
+ function settleRunningVersion(binaryVersion, initializeResult) {
1450
+ var reported = codexVersion.versionFromUserAgent(initializeResult && initializeResult.userAgent);
1451
+ var binary = codexVersion.parseVersion(typeof binaryVersion === "string" ? binaryVersion : "");
1452
+ if (reported && binary && codexVersion.compareVersions(reported, binary) !== 0) {
1453
+ console.warn("[codex] the app-server reports " + reported.text + " but the binary reported " + binary.text + "; using the app-server's");
1454
+ }
1455
+ return reported || binary || null;
1456
+ }
1457
+
1431
1458
  // --- Adapter factory ---
1432
1459
 
1433
1460
  function createCodexAdapter(opts) {
1461
+ // Fail closed: under per-user OS isolation no Codex app-server is ever started
1462
+ // (it would run as the daemon's user). The registry keeps the agent from being
1463
+ // created in that mode; this refuses a caller that got here anyway.
1464
+ if (opts && opts.osUsers) {
1465
+ throw codexError("CODEX_OS_USERS_UNSUPPORTED", "Codex is not yet isolated per OS user");
1466
+ }
1434
1467
  var _cwd = (opts && opts.cwd) || process.cwd();
1435
1468
  var _slug = (opts && opts.slug) || "";
1436
1469
  var _defaultInitOpts = Object.assign({}, opts || {});
@@ -1458,6 +1491,10 @@ function createCodexAdapter(opts) {
1458
1491
  // Fallback-only (lr-d91ecf): the value before init() reads the live
1459
1492
  // model/list RPC; overwritten as soon as that succeeds.
1460
1493
  defaultModel: FALLBACK_DEFAULT_MODEL,
1494
+ // What the running Codex accepts (codex-protocol.js), and which version
1495
+ // that is; both are settled when the server has started.
1496
+ features: codexProtocol.protocolFeatures(null),
1497
+ version: null,
1461
1498
  };
1462
1499
  }
1463
1500
 
@@ -1525,7 +1562,7 @@ function createCodexAdapter(opts) {
1525
1562
  // Returns {name, desc, type}[] with skills first (type:'skill'), then workflows
1526
1563
  // (type:'workflow'), deduplicated by name. This mirrors the enrichment done in
1527
1564
  // sdk-message-processor for the Claude adapter path.
1528
- // homeOverride (lr-3ccc78): session owner's home, see discoverClaudeSkills doc comment.
1565
+ // homeOverride: session owner's home, see discoverSkillFiles doc comment.
1529
1566
  function buildEnrichedSlashCommands(skillNames, cwd, homeOverride) {
1530
1567
  var effectiveCwd = cwd || _cwd;
1531
1568
  var seen = {};
@@ -1534,7 +1571,7 @@ function createCodexAdapter(opts) {
1534
1571
  // Skills: enrich with descriptions from SKILL.md where available
1535
1572
  var fsSkillsMeta;
1536
1573
  try {
1537
- fsSkillsMeta = discoverSkillsWithMeta(effectiveCwd, homeOverride);
1574
+ fsSkillsMeta = discoverSkillsWithMeta(effectiveCwd, homeOverride, true);
1538
1575
  } catch (e) {
1539
1576
  fsSkillsMeta = [];
1540
1577
  }
@@ -1783,8 +1820,9 @@ function createCodexAdapter(opts) {
1783
1820
  if (serverEnv) serverOpts.env = serverEnv;
1784
1821
 
1785
1822
  // Extract adapter options
1823
+ var co = null;
1786
1824
  if (effectiveInitOpts && effectiveInitOpts.adapterOptions && effectiveInitOpts.adapterOptions.CODEX) {
1787
- var co = effectiveInitOpts.adapterOptions.CODEX;
1825
+ co = effectiveInitOpts.adapterOptions.CODEX;
1788
1826
  if (co.config) serverOpts.config = co.config;
1789
1827
  }
1790
1828
 
@@ -1844,17 +1882,34 @@ function createCodexAdapter(opts) {
1844
1882
  } catch (e) {}
1845
1883
  }
1846
1884
 
1847
- // Spawn and initialize app-server
1885
+ // Spawn and initialize app-server. Constructing it resolves the Codex
1886
+ // the user installed, which fixes the version, and the version decides
1887
+ // which config keys exist: so the console's own keys are added to the
1888
+ // config after the binary is known and before the process starts.
1848
1889
  var server = new CodexAppServer(null, serverOpts);
1890
+ var binaryVersion = server.resolution && server.resolution.version;
1891
+ var spawnFeatures = codexProtocol.protocolFeatures(binaryVersion);
1892
+ serverOpts.config = mergeConfig(codexProtocol.sessionConfig(spawnFeatures), serverOpts.config);
1849
1893
  inst.appServer = server;
1850
1894
  await server.start();
1851
1895
 
1852
- await server.send("initialize", {
1853
- clientInfo: { name: "clagentic", title: "Clagentic: Console", version: "1.0.0" },
1896
+ var initializeResult = await server.send("initialize", {
1897
+ clientInfo: { name: "clagentic-console", title: "Clagentic: Console", version: require("../../../package.json").version },
1854
1898
  capabilities: { experimentalApi: true },
1855
1899
  });
1856
1900
  server.notify("initialized", {});
1857
1901
 
1902
+ var running = settleRunningVersion(binaryVersion, initializeResult);
1903
+ if (running && codexVersion.compareVersions(running, codexVersion.MIN_CODEX_VERSION) < 0) {
1904
+ await stopAppServer(server, Date.now() + 1000);
1905
+ throw codexError("CODEX_TOO_OLD", "Codex " + running.text + " is too old; Clagentic: Console needs " + codexVersion.MIN_CODEX_VERSION + " or newer");
1906
+ }
1907
+ inst.version = running ? running.text : null;
1908
+ inst.features = codexProtocol.protocolFeatures(running);
1909
+ if (JSON.stringify(inst.features) !== JSON.stringify(spawnFeatures)) {
1910
+ console.warn("[codex] the running app-server (" + inst.version + ") differs from the binary that was resolved (" + binaryVersion + "); its config was set for the binary");
1911
+ }
1912
+
1858
1913
  if (_shuttingDown || inst.retirePromise) {
1859
1914
  await stopAppServer(server, Date.now() + 1000);
1860
1915
  throw createShutdownError();
@@ -1938,7 +1993,7 @@ function createCodexAdapter(opts) {
1938
1993
  }
1939
1994
  }
1940
1995
  // Also discover Claude skills directly as fallback
1941
- var claudeSkills = discoverClaudeSkills(_cwd, initHomeOverride);
1996
+ var claudeSkills = discoverSkillFiles(_cwd, initHomeOverride);
1942
1997
  var claudeSkillNames = Object.keys(claudeSkills);
1943
1998
  for (var csn = 0; csn < claudeSkillNames.length; csn++) {
1944
1999
  if (skillNames.indexOf(claudeSkillNames[csn]) === -1) skillNames.push(claudeSkillNames[csn]);
@@ -2019,10 +2074,12 @@ function createCodexAdapter(opts) {
2019
2074
  canUseTool: queryOpts.canUseTool || null,
2020
2075
  onElicitation: queryOpts.onElicitation || null,
2021
2076
  resumeSessionId: queryOpts.resumeSessionId || null,
2022
- // lr-3ccc78 — session owner's home for discoverClaudeSkills below,
2077
+ // Session owner's home for discoverSkillFiles below,
2023
2078
  // resolved once per query so a shared multi-user daemon shows each
2024
2079
  // user their own ~/.claude/skills, not the daemon operator's.
2025
2080
  homeOverride: resolveLinuxUserHome(codexOpts.linuxUser),
2081
+ // What the Codex this query runs on accepts.
2082
+ features: inst.features,
2026
2083
  };
2027
2084
 
2028
2085
  // Reasoning effort
@@ -2038,7 +2095,7 @@ function createCodexAdapter(opts) {
2038
2095
  if (queryOpts.toolPolicy === "allow-all") {
2039
2096
  handleOpts.approvalPolicy = "never";
2040
2097
  } else {
2041
- handleOpts.approvalPolicy = codexOpts.approvalPolicy || "on-failure";
2098
+ handleOpts.approvalPolicy = codexProtocol.normalizeApprovalPolicy(codexOpts.approvalPolicy);
2042
2099
  }
2043
2100
 
2044
2101
  // Sandbox mode
@@ -2143,12 +2200,14 @@ function createCodexAdapter(opts) {
2143
2200
  });
2144
2201
  });
2145
2202
  },
2146
- // Rejects when the thread could not be rolled back; the caller must not
2147
- // trim its own history in that case.
2148
- rollbackThread: function(threadId, numTurns, callerOpts) {
2149
- return runOnCallerInstance(callerOpts, "rollbackThread", function(inst) {
2150
- return inst.appServer.send("thread/rollback", { threadId: threadId, numTurns: numTurns }, 30000);
2151
- });
2203
+ // Rewinding a Codex thread in place is not offered: the app-server's
2204
+ // thread/rollback is gone from the supported releases, and its replacement
2205
+ // cannot be made safe against a turn appended while it runs. The method
2206
+ // stays because callers read it as "this adapter keeps its own threads";
2207
+ // it always rejects, so the caller leaves its own history as it was, and it
2208
+ // sends the server nothing.
2209
+ rollbackThread: function() {
2210
+ return Promise.reject(codexError("CODEX_REWIND_UNAVAILABLE", "Rewind is not available for Codex sessions yet"));
2152
2211
  },
2153
2212
 
2154
2213
  // Shutdown the app-server process
@@ -2192,5 +2251,6 @@ module.exports = {
2192
2251
  // lr-3ccc78 — exported so tests can exercise the real per-user home
2193
2252
  // resolution in discoverClaudeSkills directly, rather than driving it
2194
2253
  // indirectly through a full query/init round trip.
2195
- _test_discoverClaudeSkills: discoverClaudeSkills,
2254
+ _test_discoverClaudeSkills: discoverSkillFiles,
2255
+ _test_mergeConfig: mergeConfig,
2196
2256
  };
@@ -1,10 +1,8 @@
1
1
  // auth-checks.js - per-agent "is a login in place" probes. Each registered
2
2
  // vendor points at one of these through its descriptor's checkAuth.
3
3
 
4
- var fs = require("fs");
5
4
  var execSync = require("child_process").execSync;
6
- var execFileSync = require("child_process").execFileSync;
7
- var installProbe = require("./install-probe");
5
+ var codexCommand = require("./codex-command");
8
6
  var providerCredentials = require("./provider-credentials");
9
7
 
10
8
  function parseClaudeAuthStatusJson(out) {
@@ -66,31 +64,20 @@ function checkClaudeAuth() {
66
64
  }
67
65
  }
68
66
 
69
- function resolveCodexBinary() {
70
- var appServer = require("./codex-app-server");
71
-
72
- try {
73
- var codexBin = appServer.findCodexPath();
74
- if (codexBin && fs.existsSync(codexBin)) return codexBin;
75
- } catch (e) {
76
- if (!appServer.isBundleAbsent(e)) throw e;
77
- }
78
-
79
- return installProbe.findBinaryPath("codex") || null;
80
- }
81
-
82
67
  function checkCodexAuth() {
83
- var codexBin;
68
+ var resolved;
84
69
  try {
85
- codexBin = resolveCodexBinary();
70
+ resolved = require("./codex-binary").resolveCached();
86
71
  } catch (e) {
87
- // Not an absent bundle (that falls back to PATH): a defect worth seeing.
72
+ // The lookup itself broke: a defect worth seeing, not "not installed".
88
73
  console.error("[yoke] Codex binary lookup failed:", e && e.message ? e.message : e);
89
74
  return false;
90
75
  }
91
- if (!codexBin) return false;
76
+ // A Codex that is absent, too old or an invalid override is reported by the
77
+ // install probe with its reason; there is nothing to sign in to here.
78
+ if (resolved.state !== "ready") return false;
92
79
  try {
93
- execFileSync(codexBin, ["login", "status"], { timeout: 5000, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] });
80
+ codexCommand.execCodexSync(resolved.path, ["login", "status"], { timeout: 5000, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] });
94
81
  return true;
95
82
  } catch (e) {
96
83
  return false;
@@ -2,73 +2,11 @@
2
2
  // ---------------------------------
3
3
  // Manages a codex app-server child process with bidirectional JSON-RPC
4
4
  // communication over stdin/stdout. Replaces the SDK exec mode to enable
5
- // interactive approval flows.
5
+ // interactive approval flows. The binary is the Codex the user installed
6
+ // (codex-binary.js resolves it); the console bundles none.
6
7
 
7
- var { spawn } = require("child_process");
8
8
  var readline = require("readline");
9
- var path = require("path");
10
- var { createRequire } = require("module");
11
-
12
- // --- Find the codex binary path ---
13
- // Mirrors the logic from @openai/codex-sdk findCodexPath()
14
-
15
- var PLATFORM_PACKAGE_BY_TARGET = {
16
- "aarch64-apple-darwin": "@openai/codex-darwin-arm64",
17
- "x86_64-apple-darwin": "@openai/codex-darwin-x64",
18
- "aarch64-unknown-linux-musl": "@openai/codex-linux-arm64",
19
- "x86_64-unknown-linux-musl": "@openai/codex-linux-x64",
20
- "x86_64-pc-windows-msvc": "@openai/codex-win32-x64",
21
- };
22
-
23
- function getTargetTriple() {
24
- var arch = process.arch;
25
- var platform = process.platform;
26
- if (platform === "darwin") {
27
- return arch === "arm64" ? "aarch64-apple-darwin" : "x86_64-apple-darwin";
28
- }
29
- if (platform === "linux") {
30
- return arch === "arm64" ? "aarch64-unknown-linux-musl" : "x86_64-unknown-linux-musl";
31
- }
32
- if (platform === "win32") {
33
- return "x86_64-pc-windows-msvc";
34
- }
35
- return null;
36
- }
37
-
38
- // The bundled binary is simply not there on this host: an unsupported
39
- // platform, or the packages that carry it are not installed. Callers that only
40
- // want to know whether a bundle exists catch this and nothing else.
41
- var BUNDLE_ABSENT_CODE = "CODEX_BUNDLE_ABSENT";
42
-
43
- function bundleAbsentError(message) {
44
- var err = new Error(message);
45
- err.code = BUNDLE_ABSENT_CODE;
46
- return err;
47
- }
48
-
49
- function isBundleAbsent(err) {
50
- return !!err && err.code === BUNDLE_ABSENT_CODE;
51
- }
52
-
53
- function findCodexPath() {
54
- var triple = getTargetTriple();
55
- if (!triple) throw bundleAbsentError("Unsupported platform: " + process.platform + "/" + process.arch);
56
-
57
- var platformPkg = PLATFORM_PACKAGE_BY_TARGET[triple];
58
- if (!platformPkg) throw bundleAbsentError("No codex binary package for: " + triple);
59
-
60
- try {
61
- var codexPkgJson = require.resolve("@openai/codex/package.json");
62
- var codexRequire = createRequire(codexPkgJson);
63
- var platformPkgJson = codexRequire.resolve(platformPkg + "/package.json");
64
- var vendorRoot = path.join(path.dirname(platformPkgJson), "vendor");
65
- var binaryName = process.platform === "win32" ? "codex.exe" : "codex";
66
- return path.join(vendorRoot, triple, "codex", binaryName);
67
- } catch (e) {
68
- if (e && e.code === "MODULE_NOT_FOUND") throw bundleAbsentError("Could not find codex binary: " + e.message);
69
- throw e;
70
- }
71
- }
9
+ var { spawnCodex } = require("./codex-command");
72
10
 
73
11
  // --- Config serialization ---
74
12
  // Flattens a nested config object into --config key=value pairs.
@@ -76,13 +14,19 @@ function findCodexPath() {
76
14
  // e.g. { mcp_servers: { "clay-tools": { command: "node", args: ["a.js"] } } }
77
15
  // -> ["mcp_servers.clay-tools.command=\"node\"", "mcp_servers.clay-tools.args=[\"a.js\"]"]
78
16
 
17
+ // A TOML key segment that is not made of letters, digits, "_" and "-" (a
18
+ // project path, say) must be quoted, or its dots and slashes split the key.
19
+ function tomlKeySegment(key) {
20
+ return /^[A-Za-z0-9_-]+$/.test(key) ? key : JSON.stringify(key);
21
+ }
22
+
79
23
  function serializeConfig(obj, prefix) {
80
24
  var result = [];
81
25
  var keys = Object.keys(obj);
82
26
  for (var i = 0; i < keys.length; i++) {
83
27
  var key = keys[i];
84
28
  var val = obj[key];
85
- var fullKey = prefix ? prefix + "." + key : key;
29
+ var fullKey = prefix ? prefix + "." + tomlKeySegment(key) : tomlKeySegment(key);
86
30
 
87
31
  if (val === null || val === undefined) continue;
88
32
 
@@ -110,6 +54,12 @@ function toTomlValue(val) {
110
54
 
111
55
  // --- CodexAppServer ---
112
56
 
57
+ // executablePath is the resolved Codex binary (codex-binary.js). Without one
58
+ // the user's installed Codex is resolved here, and a Codex that is absent or
59
+ // too old fails construction with a named error.
60
+ //
61
+ // opts: { cwd, env, config }
62
+ // env the environment laid over the daemon's own
113
63
  function CodexAppServer(executablePath, opts) {
114
64
  this.proc = null;
115
65
  this.rl = null;
@@ -120,8 +70,14 @@ function CodexAppServer(executablePath, opts) {
120
70
  // Use addEventHandler / removeEventHandler instead of setting this directly.
121
71
  this.eventHandler = null;
122
72
  this._eventHandlers = []; // [{ threadId: string|null, fn: function }]
123
- this.executablePath = executablePath || findCodexPath();
124
73
  this.opts = opts || {};
74
+ // What resolving the binary found (path, version), when it was resolved here.
75
+ this.resolution = null;
76
+ if (!executablePath) {
77
+ this.resolution = require("./codex-binary").requireCodex();
78
+ executablePath = this.resolution.path;
79
+ }
80
+ this.executablePath = executablePath;
125
81
  this.started = false;
126
82
  this._stderrBuf = "";
127
83
  }
@@ -144,11 +100,12 @@ CodexAppServer.prototype.start = function() {
144
100
 
145
101
  console.log("[codex-app-server] Spawning:", self.executablePath, args.join(" "));
146
102
 
147
- self.proc = spawn(self.executablePath, args, {
103
+ // spawnCodex runs a Windows .cmd/.bat shim through the command interpreter.
104
+ self.proc = spawnCodex(self.executablePath, args, {
148
105
  stdio: ["pipe", "pipe", "pipe"],
149
106
  env: env,
150
107
  cwd: self.opts.cwd || process.cwd(),
151
- });
108
+ }, self.opts.commandDeps);
152
109
 
153
110
  self.proc.on("error", function(err) {
154
111
  console.error("[codex-app-server] Process error:", err.message);
@@ -365,6 +322,5 @@ CodexAppServer.prototype.stop = function() {
365
322
 
366
323
  module.exports = {
367
324
  CodexAppServer: CodexAppServer,
368
- findCodexPath: findCodexPath,
369
- isBundleAbsent: isBundleAbsent,
325
+ serializeConfig: serializeConfig,
370
326
  };