@clagentic/console 1.10.0-beta.1 → 1.10.0-beta.3

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 (94) hide show
  1. package/README.md +1 -1
  2. package/bin/cli.js +10 -0
  3. package/lib/activity-clock.js +23 -0
  4. package/lib/agent-dispatch-tool.js +20 -0
  5. package/lib/build-changes.js +79 -0
  6. package/lib/build-identity.js +192 -0
  7. package/lib/build-monitor.js +125 -0
  8. package/lib/build-sha.json +2 -2
  9. package/lib/build-update-offer.js +141 -0
  10. package/lib/build-update-restart.js +142 -0
  11. package/lib/build-update-standing.js +184 -0
  12. package/lib/cli/daemon-launch.js +8 -5
  13. package/lib/cli/ipc-subcommands.js +6 -0
  14. package/lib/cli/session-subcommands.js +122 -0
  15. package/lib/cli-sessions.js +8 -1
  16. package/lib/cli-transcript-title.js +131 -0
  17. package/lib/codex-defaults.js +8 -2
  18. package/lib/daemon-projects.js +19 -0
  19. package/lib/daemon.js +166 -127
  20. package/lib/debug-log.js +17 -0
  21. package/lib/exit-flush.js +44 -0
  22. package/lib/grant-keys.js +179 -0
  23. package/lib/log-field.js +34 -0
  24. package/lib/memory-shed.js +13 -32
  25. package/lib/project-connection.js +14 -0
  26. package/lib/project-external-trigger.js +91 -123
  27. package/lib/project-http.js +2 -0
  28. package/lib/project-loop.js +5 -4
  29. package/lib/project-notifications.js +4 -0
  30. package/lib/project-prompt-responses.js +7 -5
  31. package/lib/project-session-grants.js +73 -0
  32. package/lib/project-sessions.js +55 -68
  33. package/lib/project-user-message.js +13 -25
  34. package/lib/project.js +25 -5
  35. package/lib/prompt-kinds/permission.js +18 -0
  36. package/lib/prompt-label.js +60 -0
  37. package/lib/prompt-registry.js +123 -13
  38. package/lib/prompt-source.js +65 -0
  39. package/lib/public/css/diagnostics.css +30 -0
  40. package/lib/public/css/notifications-center.css +15 -0
  41. package/lib/public/css/overlays.css +18 -0
  42. package/lib/public/css/rewind.css +8 -0
  43. package/lib/public/modules/agent-dispatch-tool.js +9 -0
  44. package/lib/public/modules/app-messages.js +10 -2
  45. package/lib/public/modules/app-notifications.js +9 -1
  46. package/lib/public/modules/app-panels.js +0 -1
  47. package/lib/public/modules/build-update-detail.js +54 -0
  48. package/lib/public/modules/diagnostics.js +126 -20
  49. package/lib/public/modules/prompt-banner.js +12 -0
  50. package/lib/public/modules/prompt-kinds/permission-choices.js +6 -1
  51. package/lib/public/modules/prompt-kinds/permission.js +15 -0
  52. package/lib/public/modules/prompt-label.js +44 -0
  53. package/lib/public/modules/prompts.js +9 -0
  54. package/lib/public/modules/session-grants.js +131 -0
  55. package/lib/public/modules/sidebar-sessions.js +11 -0
  56. package/lib/public/modules/tools.js +14 -2
  57. package/lib/public/modules/vendor-picker.js +2 -2
  58. package/lib/public/modules/vendor-registry.js +11 -2
  59. package/lib/runtime-env.js +1 -1
  60. package/lib/sdk-bridge.js +114 -115
  61. package/lib/sdk-message-processor.js +25 -87
  62. package/lib/sdk-skill-discovery.js +65 -60
  63. package/lib/server.js +15 -2
  64. package/lib/session-ai-title.js +80 -0
  65. package/lib/session-id.js +33 -0
  66. package/lib/session-input-ipc.js +32 -0
  67. package/lib/session-input.js +409 -0
  68. package/lib/session-reclaim.js +284 -0
  69. package/lib/session-resume.js +172 -0
  70. package/lib/sessions.js +31 -21
  71. package/lib/supervisor.js +39 -0
  72. package/lib/turn-initiator.js +108 -0
  73. package/lib/utils.js +9 -47
  74. package/lib/vendor-registry-message.js +1 -0
  75. package/lib/ws-schema.js +9 -4
  76. package/lib/yoke/adapters/claude-vendor.js +0 -1
  77. package/lib/yoke/adapters/claude-worker.js +6 -4
  78. package/lib/yoke/adapters/claude.js +29 -86
  79. package/lib/yoke/adapters/codex-capabilities.js +9 -6
  80. package/lib/yoke/adapters/codex-vendor.js +15 -15
  81. package/lib/yoke/adapters/codex.js +125 -136
  82. package/lib/yoke/auth-checks.js +8 -21
  83. package/lib/yoke/codex-app-server.js +27 -71
  84. package/lib/yoke/codex-binary.js +254 -0
  85. package/lib/yoke/codex-command.js +122 -0
  86. package/lib/yoke/codex-protocol.js +96 -0
  87. package/lib/yoke/codex-version.js +135 -0
  88. package/lib/yoke/index.js +20 -4
  89. package/lib/yoke/install-probe.js +21 -6
  90. package/lib/yoke/interface.js +14 -12
  91. package/lib/yoke/registry.js +41 -4
  92. package/package.json +1 -2
  93. package/scripts/verify-installed-build.js +59 -17
  94. 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";
@@ -643,33 +633,15 @@ function _test_resolveModel(queryOpts) {
643
633
  return queryOpts.model || queryOpts.defaultModel || "gpt-5.5";
644
634
  }
645
635
 
646
- // Selects the model used for background title generation.
647
- //
648
- // The live "model/list" RPC's Model objects (see the model/list handler
649
- // below, and the shape of an instance's models) carry no cost-tier field — only
650
- // value/displayName/supportedEffortLevels/isLatest ("isLatest" means "not
651
- // superseded by an upgrade", not "cheap"). There is no robust signal in the
652
- // live catalog to identify a mini/small-tier model, and this codebase does
653
- // not substring-match displayName/value for a tier (that class of fragile
654
- // string matching was deliberately removed elsewhere — see the Context
655
- // meter section of docs/guides/architecture.md).
656
- //
657
- // So titling — a trivial 3-8 word job — falls back to the server's default
658
- // model, the adapter's only non-staling model identifier (refreshed from the live
659
- // model/list response). This is a deliberate cost/staleness tradeoff: every
660
- // auto-title now runs on the user's main model instead of a cheaper
661
- // mini-tier one, in exchange for auto-titling never breaking silently when
662
- // OpenAI retires a pinned mini snapshot. See PR body for the reasoning.
663
- function resolveTitleModel(defaultModel) {
664
- return defaultModel || "gpt-5.5";
665
- }
666
-
667
636
  function createCodexQueryHandle(appServer, queryOpts) {
668
637
  var abortController = queryOpts.abortController;
669
638
  var systemPrompt = queryOpts.systemPrompt || "";
670
639
  var canUseTool = queryOpts.canUseTool || null;
671
640
  var onElicitation = queryOpts.onElicitation || null;
672
641
  var onFinished = queryOpts.onFinished || null;
642
+ // What the running Codex accepts (codex-protocol.js). A handle made without
643
+ // one is taken to run the oldest supported Codex.
644
+ var features = queryOpts.features || codexProtocol.protocolFeatures(null);
673
645
 
674
646
  // Check if the query was cancelled (either via handle.abort() or direct signal abort)
675
647
  function isCancelled() {
@@ -893,9 +865,10 @@ function createCodexQueryHandle(appServer, queryOpts) {
893
865
  if (isAllowAll()) {
894
866
  appServer.respond(msg.id, { decision: "accept" });
895
867
  } else if (canUseTool) {
896
- var changeInfo = (fcParams.changes || []).map(function(c) { return c.kind + " " + c.path; }).join(", ");
868
+ var fcChanges = Array.isArray(fcParams.changes) ? fcParams.changes : [];
869
+ var changeInfo = fcChanges.map(function(c) { return c.kind + " " + c.path; }).join(", ");
897
870
  awaitApproval(msg.id, function (signal) {
898
- return canUseTool("Edit", { changes: changeInfo, path: fcParams.path }, { signal: signal });
871
+ return canUseTool("Edit", { changes: changeInfo }, { signal: signal });
899
872
  }, function (decision) {
900
873
  appServer.respond(msg.id, { decision: isApproved(decision) ? "accept" : "decline" });
901
874
  }, function (err) {
@@ -990,7 +963,9 @@ function createCodexQueryHandle(appServer, queryOpts) {
990
963
  }
991
964
 
992
965
  // --- Main query loop ---
993
- async function runQueryLoop(initialMessage) {
966
+ async function runQueryLoop(initialMessage, initialInitiator) {
967
+ // Who started the turn being sent, per turn (turn-initiator.js).
968
+ var currentInitiator = initialInitiator;
994
969
  // Prepend system prompt (project instructions from YOKE layer) to first message.
995
970
  // initialMessage may be a string (text-only) or an array of content items
996
971
  // (e.g. [{ type: "text", text: "..." }, ...] when images/attachments are present).
@@ -1034,7 +1009,7 @@ function createCodexQueryHandle(appServer, queryOpts) {
1034
1009
  var threadParams = {
1035
1010
  model: _test_resolveModel(queryOpts),
1036
1011
  sandbox: queryOpts.sandboxMode || "workspace-write",
1037
- approvalPolicy: queryOpts.approvalPolicy || "on-failure",
1012
+ approvalPolicy: codexProtocol.normalizeApprovalPolicy(queryOpts.approvalPolicy),
1038
1013
  cwd: queryOpts.cwd,
1039
1014
  skipGitRepoCheck: true,
1040
1015
  };
@@ -1061,7 +1036,7 @@ function createCodexQueryHandle(appServer, queryOpts) {
1061
1036
  if (threadResult && threadResult.thread) {
1062
1037
  state.threadId = threadResult.thread.id;
1063
1038
  // Narrow the handler to only receive events for this thread so other
1064
- // concurrent queries (e.g. auto-title) are not routed to us.
1039
+ // concurrent queries are not routed to us.
1065
1040
  appServer.updateHandlerThreadId(_handlerEntry, state.threadId);
1066
1041
  }
1067
1042
 
@@ -1107,7 +1082,7 @@ function createCodexQueryHandle(appServer, queryOpts) {
1107
1082
  // was wired (e.g. warmup/init queries), while this newer site failed
1108
1083
  // closed in the same situation — an inconsistency BOBBIE flagged on
1109
1084
  // the lr-4a13c3 PR. All four sites now fail closed identically.
1110
- var availableSkills = discoverClaudeSkills(queryOpts.cwd, queryOpts.homeOverride);
1085
+ var availableSkills = discoverSkillFiles(queryOpts.cwd, queryOpts.homeOverride);
1111
1086
  var skillItemsToInject = [];
1112
1087
  var candidateSkills = [];
1113
1088
  var seenSkillNames = {};
@@ -1148,7 +1123,7 @@ function createCodexQueryHandle(appServer, queryOpts) {
1148
1123
  }
1149
1124
  }
1150
1125
  if (skillItemsToInject.length > 0) {
1151
- console.log("[yoke/codex] injecting Claude skills:", skillItemsToInject.map(function(s) { return s.name; }).join(", "));
1126
+ console.log("[yoke/codex] injecting skills:", skillItemsToInject.map(function(s) { return s.name; }).join(", "));
1152
1127
  input = input.concat(skillItemsToInject);
1153
1128
  }
1154
1129
 
@@ -1160,6 +1135,10 @@ function createCodexQueryHandle(appServer, queryOpts) {
1160
1135
  if (state.modelReasoningEffort) {
1161
1136
  turnParams.effort = state.modelReasoningEffort;
1162
1137
  }
1138
+ // Codex tells an automated turn from a typed one by this field alone,
1139
+ // and only a Codex that has it is sent it.
1140
+ var turnTrigger = features.turnTrigger ? codexProtocol.turnTriggerFor(currentInitiator) : null;
1141
+ if (turnTrigger) turnParams.turnTrigger = turnTrigger;
1163
1142
  await appServer.send("turn/start", turnParams, 60000);
1164
1143
 
1165
1144
  // Wait for turn to complete
@@ -1178,7 +1157,8 @@ function createCodexQueryHandle(appServer, queryOpts) {
1178
1157
  // Wait for next message (multi-turn)
1179
1158
  var nextMsg = await waitForMessage();
1180
1159
  if (nextMsg === null) break;
1181
- currentMessage = nextMsg;
1160
+ currentMessage = nextMsg.input;
1161
+ currentInitiator = nextMsg.initiator;
1182
1162
  }
1183
1163
  } catch (e) {
1184
1164
  // Suppress AbortError when the user stopped the query.
@@ -1221,7 +1201,7 @@ function createCodexQueryHandle(appServer, queryOpts) {
1221
1201
  };
1222
1202
  },
1223
1203
 
1224
- pushMessage: function(text, images) {
1204
+ pushMessage: function(text, images, initiator) {
1225
1205
  var input;
1226
1206
  if (images && images.length > 0) {
1227
1207
  input = [];
@@ -1254,9 +1234,9 @@ function createCodexQueryHandle(appServer, queryOpts) {
1254
1234
 
1255
1235
  if (!state.loopStarted) {
1256
1236
  state.loopStarted = true;
1257
- runQueryLoop(input);
1237
+ runQueryLoop(input, initiator);
1258
1238
  } else {
1259
- pushMessageToQueue(input);
1239
+ pushMessageToQueue({ input: input, initiator: initiator });
1260
1240
  }
1261
1241
  },
1262
1242
 
@@ -1428,9 +1408,42 @@ var CODEX_DEFAULT_MODELS = [
1428
1408
  },
1429
1409
  ];
1430
1410
 
1411
+ // --- Running version ---
1412
+
1413
+ // Config objects merged key by key; where both name a leaf, the later one wins.
1414
+ function mergeConfig(base, over) {
1415
+ var out = Object.assign({}, base);
1416
+ Object.keys(over || {}).forEach(function(key) {
1417
+ var a = out[key];
1418
+ var b = over[key];
1419
+ var plain = function(v) { return v && typeof v === "object" && !Array.isArray(v); };
1420
+ out[key] = plain(a) && plain(b) ? mergeConfig(a, b) : b;
1421
+ });
1422
+ return out;
1423
+ }
1424
+
1425
+ // The version of the Codex that is running: what the app-server's userAgent
1426
+ // reports, else what the binary reported when it was resolved. initialize has
1427
+ // no version field of its own, so a userAgent that cannot be read is no reason
1428
+ // to refuse a server whose binary reported one.
1429
+ function settleRunningVersion(binaryVersion, initializeResult) {
1430
+ var reported = codexVersion.versionFromUserAgent(initializeResult && initializeResult.userAgent);
1431
+ var binary = codexVersion.parseVersion(typeof binaryVersion === "string" ? binaryVersion : "");
1432
+ if (reported && binary && codexVersion.compareVersions(reported, binary) !== 0) {
1433
+ console.warn("[codex] the app-server reports " + reported.text + " but the binary reported " + binary.text + "; using the app-server's");
1434
+ }
1435
+ return reported || binary || null;
1436
+ }
1437
+
1431
1438
  // --- Adapter factory ---
1432
1439
 
1433
1440
  function createCodexAdapter(opts) {
1441
+ // Fail closed: under per-user OS isolation no Codex app-server is ever started
1442
+ // (it would run as the daemon's user). The registry keeps the agent from being
1443
+ // created in that mode; this refuses a caller that got here anyway.
1444
+ if (opts && opts.osUsers) {
1445
+ throw codexError("CODEX_OS_USERS_UNSUPPORTED", "Codex is not yet isolated per OS user");
1446
+ }
1434
1447
  var _cwd = (opts && opts.cwd) || process.cwd();
1435
1448
  var _slug = (opts && opts.slug) || "";
1436
1449
  var _defaultInitOpts = Object.assign({}, opts || {});
@@ -1458,6 +1471,10 @@ function createCodexAdapter(opts) {
1458
1471
  // Fallback-only (lr-d91ecf): the value before init() reads the live
1459
1472
  // model/list RPC; overwritten as soon as that succeeds.
1460
1473
  defaultModel: FALLBACK_DEFAULT_MODEL,
1474
+ // What the running Codex accepts (codex-protocol.js), and which version
1475
+ // that is; both are settled when the server has started.
1476
+ features: codexProtocol.protocolFeatures(null),
1477
+ version: null,
1461
1478
  };
1462
1479
  }
1463
1480
 
@@ -1525,7 +1542,7 @@ function createCodexAdapter(opts) {
1525
1542
  // Returns {name, desc, type}[] with skills first (type:'skill'), then workflows
1526
1543
  // (type:'workflow'), deduplicated by name. This mirrors the enrichment done in
1527
1544
  // sdk-message-processor for the Claude adapter path.
1528
- // homeOverride (lr-3ccc78): session owner's home, see discoverClaudeSkills doc comment.
1545
+ // homeOverride: session owner's home, see discoverSkillFiles doc comment.
1529
1546
  function buildEnrichedSlashCommands(skillNames, cwd, homeOverride) {
1530
1547
  var effectiveCwd = cwd || _cwd;
1531
1548
  var seen = {};
@@ -1534,7 +1551,7 @@ function createCodexAdapter(opts) {
1534
1551
  // Skills: enrich with descriptions from SKILL.md where available
1535
1552
  var fsSkillsMeta;
1536
1553
  try {
1537
- fsSkillsMeta = discoverSkillsWithMeta(effectiveCwd, homeOverride);
1554
+ fsSkillsMeta = discoverSkillsWithMeta(effectiveCwd, homeOverride, true);
1538
1555
  } catch (e) {
1539
1556
  fsSkillsMeta = [];
1540
1557
  }
@@ -1783,8 +1800,9 @@ function createCodexAdapter(opts) {
1783
1800
  if (serverEnv) serverOpts.env = serverEnv;
1784
1801
 
1785
1802
  // Extract adapter options
1803
+ var co = null;
1786
1804
  if (effectiveInitOpts && effectiveInitOpts.adapterOptions && effectiveInitOpts.adapterOptions.CODEX) {
1787
- var co = effectiveInitOpts.adapterOptions.CODEX;
1805
+ co = effectiveInitOpts.adapterOptions.CODEX;
1788
1806
  if (co.config) serverOpts.config = co.config;
1789
1807
  }
1790
1808
 
@@ -1844,17 +1862,34 @@ function createCodexAdapter(opts) {
1844
1862
  } catch (e) {}
1845
1863
  }
1846
1864
 
1847
- // Spawn and initialize app-server
1865
+ // Spawn and initialize app-server. Constructing it resolves the Codex
1866
+ // the user installed, which fixes the version, and the version decides
1867
+ // which config keys exist: so the console's own keys are added to the
1868
+ // config after the binary is known and before the process starts.
1848
1869
  var server = new CodexAppServer(null, serverOpts);
1870
+ var binaryVersion = server.resolution && server.resolution.version;
1871
+ var spawnFeatures = codexProtocol.protocolFeatures(binaryVersion);
1872
+ serverOpts.config = mergeConfig(codexProtocol.sessionConfig(spawnFeatures), serverOpts.config);
1849
1873
  inst.appServer = server;
1850
1874
  await server.start();
1851
1875
 
1852
- await server.send("initialize", {
1853
- clientInfo: { name: "clagentic", title: "Clagentic: Console", version: "1.0.0" },
1876
+ var initializeResult = await server.send("initialize", {
1877
+ clientInfo: { name: "clagentic-console", title: "Clagentic: Console", version: require("../../../package.json").version },
1854
1878
  capabilities: { experimentalApi: true },
1855
1879
  });
1856
1880
  server.notify("initialized", {});
1857
1881
 
1882
+ var running = settleRunningVersion(binaryVersion, initializeResult);
1883
+ if (running && codexVersion.compareVersions(running, codexVersion.MIN_CODEX_VERSION) < 0) {
1884
+ await stopAppServer(server, Date.now() + 1000);
1885
+ throw codexError("CODEX_TOO_OLD", "Codex " + running.text + " is too old; Clagentic: Console needs " + codexVersion.MIN_CODEX_VERSION + " or newer");
1886
+ }
1887
+ inst.version = running ? running.text : null;
1888
+ inst.features = codexProtocol.protocolFeatures(running);
1889
+ if (JSON.stringify(inst.features) !== JSON.stringify(spawnFeatures)) {
1890
+ console.warn("[codex] the running app-server (" + inst.version + ") differs from the binary that was resolved (" + binaryVersion + "); its config was set for the binary");
1891
+ }
1892
+
1858
1893
  if (_shuttingDown || inst.retirePromise) {
1859
1894
  await stopAppServer(server, Date.now() + 1000);
1860
1895
  throw createShutdownError();
@@ -1938,7 +1973,7 @@ function createCodexAdapter(opts) {
1938
1973
  }
1939
1974
  }
1940
1975
  // Also discover Claude skills directly as fallback
1941
- var claudeSkills = discoverClaudeSkills(_cwd, initHomeOverride);
1976
+ var claudeSkills = discoverSkillFiles(_cwd, initHomeOverride);
1942
1977
  var claudeSkillNames = Object.keys(claudeSkills);
1943
1978
  for (var csn = 0; csn < claudeSkillNames.length; csn++) {
1944
1979
  if (skillNames.indexOf(claudeSkillNames[csn]) === -1) skillNames.push(claudeSkillNames[csn]);
@@ -2019,10 +2054,12 @@ function createCodexAdapter(opts) {
2019
2054
  canUseTool: queryOpts.canUseTool || null,
2020
2055
  onElicitation: queryOpts.onElicitation || null,
2021
2056
  resumeSessionId: queryOpts.resumeSessionId || null,
2022
- // lr-3ccc78 — session owner's home for discoverClaudeSkills below,
2057
+ // Session owner's home for discoverSkillFiles below,
2023
2058
  // resolved once per query so a shared multi-user daemon shows each
2024
2059
  // user their own ~/.claude/skills, not the daemon operator's.
2025
2060
  homeOverride: resolveLinuxUserHome(codexOpts.linuxUser),
2061
+ // What the Codex this query runs on accepts.
2062
+ features: inst.features,
2026
2063
  };
2027
2064
 
2028
2065
  // Reasoning effort
@@ -2038,7 +2075,7 @@ function createCodexAdapter(opts) {
2038
2075
  if (queryOpts.toolPolicy === "allow-all") {
2039
2076
  handleOpts.approvalPolicy = "never";
2040
2077
  } else {
2041
- handleOpts.approvalPolicy = codexOpts.approvalPolicy || "on-failure";
2078
+ handleOpts.approvalPolicy = codexProtocol.normalizeApprovalPolicy(codexOpts.approvalPolicy);
2042
2079
  }
2043
2080
 
2044
2081
  // Sandbox mode
@@ -2081,53 +2118,6 @@ function createCodexAdapter(opts) {
2081
2118
  return handle;
2082
2119
  },
2083
2120
 
2084
- // --- Title generation ---
2085
- generateTitle: async function(messages, opts) {
2086
- var systemPrompt = "You are a title generator. Output only a short title (3-8 words). No quotes, no punctuation at the end, no explanation.";
2087
- var prompt = "Below is a conversation between a user and an AI assistant. Generate a short, descriptive title (3-8 words) that captures the main topic. Reply with ONLY the title, nothing else.\n\n";
2088
- for (var i = 0; i < messages.length; i++) {
2089
- prompt += "User message " + (i + 1) + ": " + messages[i] + "\n";
2090
- }
2091
- var ac = new AbortController();
2092
- // The title is generated on the server of the caller's environment, and
2093
- // with that server's own default model.
2094
- var envOpts = { runtimeEnv: opts && opts.runtimeEnv };
2095
- var titleInst = await acquireInstance(envOpts, fingerprintFor(envOpts, "generateTitle"));
2096
- var handle = await adapter.createQuery({
2097
- cwd: (opts && opts.cwd) || _cwd,
2098
- systemPrompt: systemPrompt,
2099
- model: resolveTitleModel(titleInst.defaultModel),
2100
- abortController: ac,
2101
- canUseTool: function() { return Promise.resolve({ behavior: "deny", message: "No tools." }); },
2102
- runtimeEnv: envOpts.runtimeEnv,
2103
- });
2104
- handle.pushMessage(prompt);
2105
- var title = "";
2106
- var streamed = false;
2107
- try {
2108
- for await (var msg of handle) {
2109
- if (msg.yokeType === "text_delta" && msg.text) {
2110
- streamed = true;
2111
- title += msg.text;
2112
- } else if (msg.yokeType === "message" && msg.messageRole === "assistant" && !streamed && msg.content) {
2113
- var content = msg.content;
2114
- if (Array.isArray(content)) {
2115
- for (var ci = 0; ci < content.length; ci++) {
2116
- if (content[ci].type === "text" && content[ci].text) {
2117
- title += content[ci].text;
2118
- }
2119
- }
2120
- }
2121
- } else if (msg.yokeType === "result") {
2122
- break;
2123
- }
2124
- }
2125
- } finally {
2126
- handle.close();
2127
- }
2128
- return title.replace(/[\r\n]+/g, " ").replace(/^["'\s]+|["'\s.]+$/g, "").trim();
2129
- },
2130
-
2131
2121
  // Codex has session persistence via thread IDs
2132
2122
  getSessionInfo: function(sessionId) {
2133
2123
  return Promise.resolve(null);
@@ -2143,12 +2133,14 @@ function createCodexAdapter(opts) {
2143
2133
  });
2144
2134
  });
2145
2135
  },
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
- });
2136
+ // Rewinding a Codex thread in place is not offered: the app-server's
2137
+ // thread/rollback is gone from the supported releases, and its replacement
2138
+ // cannot be made safe against a turn appended while it runs. The method
2139
+ // stays because callers read it as "this adapter keeps its own threads";
2140
+ // it always rejects, so the caller leaves its own history as it was, and it
2141
+ // sends the server nothing.
2142
+ rollbackThread: function() {
2143
+ return Promise.reject(codexError("CODEX_REWIND_UNAVAILABLE", "Rewind is not available for Codex sessions yet"));
2152
2144
  },
2153
2145
 
2154
2146
  // Shutdown the app-server process
@@ -2181,10 +2173,6 @@ function createCodexAdapter(opts) {
2181
2173
  module.exports = {
2182
2174
  createCodexAdapter: createCodexAdapter,
2183
2175
  _test_resolveModel: _test_resolveModel,
2184
- // Exported so tests exercise the real title-generation model selection
2185
- // (including the catalog-unavailable fallback) rather than reimplementing
2186
- // a copy of it.
2187
- _test_resolveTitleModel: resolveTitleModel,
2188
2176
  // lr-f7a4 — exported so tests can drive the real approval-routing and
2189
2177
  // setToolPolicy logic against a fake appServer, rather than reimplementing
2190
2178
  // a copy of handleServerEvent's approval branches inline.
@@ -2192,5 +2180,6 @@ module.exports = {
2192
2180
  // lr-3ccc78 — exported so tests can exercise the real per-user home
2193
2181
  // resolution in discoverClaudeSkills directly, rather than driving it
2194
2182
  // indirectly through a full query/init round trip.
2195
- _test_discoverClaudeSkills: discoverClaudeSkills,
2183
+ _test_discoverClaudeSkills: discoverSkillFiles,
2184
+ _test_mergeConfig: mergeConfig,
2196
2185
  };
@@ -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
  };