@clagentic/console 1.9.0 → 1.10.0-beta.1

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 (146) hide show
  1. package/LICENSE +117 -12
  2. package/LICENSES/MIT-legacy.txt +22 -0
  3. package/LICENSES/README.md +15 -0
  4. package/README.md +8 -2
  5. package/bin/cli.js +30 -5
  6. package/deploy/clagentic-console.service +10 -6
  7. package/lib/audit.js +3 -2
  8. package/lib/build-sha.json +2 -2
  9. package/lib/build-update-check.js +138 -0
  10. package/lib/cli/daemon-launch.js +17 -17
  11. package/lib/config.js +32 -20
  12. package/lib/daemon-env-settings.js +84 -0
  13. package/lib/daemon-projects.js +38 -0
  14. package/lib/daemon.js +202 -158
  15. package/lib/drain.js +74 -17
  16. package/lib/env-compat.js +61 -0
  17. package/lib/extension-commands.js +45 -0
  18. package/lib/history-visibility.js +4 -0
  19. package/lib/idle-adapter-reaper.js +71 -0
  20. package/lib/link-trap.js +78 -0
  21. package/lib/lore-attestation.js +73 -0
  22. package/lib/mcp-local.js +8 -6
  23. package/lib/mcp-tool-input.js +116 -0
  24. package/lib/mcp-tool-schema.js +179 -0
  25. package/lib/memory-limits.js +61 -5
  26. package/lib/memory-setting-validate.js +65 -0
  27. package/lib/new-work-gate.js +47 -0
  28. package/lib/os-users.js +5 -3
  29. package/lib/project-access.js +139 -0
  30. package/lib/project-connection.js +23 -22
  31. package/lib/project-external-trigger.js +103 -10
  32. package/lib/project-file-scope.js +172 -0
  33. package/lib/project-file-watch.js +86 -61
  34. package/lib/project-filesystem.js +144 -128
  35. package/lib/project-git.js +119 -0
  36. package/lib/project-http.js +44 -28
  37. package/lib/project-loop.js +12 -5
  38. package/lib/project-mcp.js +53 -72
  39. package/lib/project-message-gate.js +70 -0
  40. package/lib/project-notifications.js +31 -4
  41. package/lib/project-prompt-responses.js +216 -0
  42. package/lib/project-sessions.js +164 -302
  43. package/lib/project-user-message.js +36 -11
  44. package/lib/project.js +189 -142
  45. package/lib/projects-dir.js +90 -0
  46. package/lib/prompt-access.js +22 -0
  47. package/lib/prompt-kinds/answer-limits.js +15 -0
  48. package/lib/prompt-kinds/ask-user.js +58 -0
  49. package/lib/prompt-kinds/codecs.js +97 -0
  50. package/lib/prompt-kinds/elicitation.js +77 -0
  51. package/lib/prompt-kinds/extension.js +39 -0
  52. package/lib/prompt-kinds/index.js +68 -0
  53. package/lib/prompt-kinds/permission.js +114 -0
  54. package/lib/prompt-kinds/plan.js +79 -0
  55. package/lib/prompt-kinds/tool-call.js +38 -0
  56. package/lib/prompt-registry.js +673 -0
  57. package/lib/public/app.js +1 -1
  58. package/lib/public/css/diagnostics.css +50 -0
  59. package/lib/public/css/input.css +17 -3
  60. package/lib/public/css/menus.css +10 -0
  61. package/lib/public/css/messages.css +5 -0
  62. package/lib/public/css/rewind.css +22 -0
  63. package/lib/public/index.html +4 -12
  64. package/lib/public/modules/app-connection.js +7 -0
  65. package/lib/public/modules/app-cursors.js +7 -5
  66. package/lib/public/modules/app-messages.js +45 -45
  67. package/lib/public/modules/app-notifications.js +47 -71
  68. package/lib/public/modules/app-panels.js +61 -58
  69. package/lib/public/modules/app-projects.js +2 -1
  70. package/lib/public/modules/app-rendering.js +4 -10
  71. package/lib/public/modules/diagnostics.js +60 -16
  72. package/lib/public/modules/filebrowser.js +18 -16
  73. package/lib/public/modules/history-visibility.js +4 -0
  74. package/lib/public/modules/mention.js +3 -2
  75. package/lib/public/modules/mode-options.js +38 -0
  76. package/lib/public/modules/project-settings.js +19 -8
  77. package/lib/public/modules/prompt-banner.js +78 -0
  78. package/lib/public/modules/prompt-card.js +201 -0
  79. package/lib/public/modules/prompt-kinds/ask-user-codec.js +131 -0
  80. package/lib/public/modules/prompt-kinds/ask-user.js +213 -0
  81. package/lib/public/modules/prompt-kinds/elicitation-codec.js +343 -0
  82. package/lib/public/modules/prompt-kinds/elicitation.js +176 -0
  83. package/lib/public/modules/prompt-kinds/index.js +18 -0
  84. package/lib/public/modules/prompt-kinds/own-key.js +29 -0
  85. package/lib/public/modules/prompt-kinds/package.json +3 -0
  86. package/lib/public/modules/prompt-kinds/permission-choices.js +31 -0
  87. package/lib/public/modules/prompt-kinds/permission.js +209 -0
  88. package/lib/public/modules/prompt-kinds/plan.js +102 -0
  89. package/lib/public/modules/prompt-state.js +142 -0
  90. package/lib/public/modules/prompts.js +134 -0
  91. package/lib/public/modules/rewind.js +4 -1
  92. package/lib/public/modules/server-settings.js +2 -4
  93. package/lib/public/modules/sidebar-mobile.js +19 -9
  94. package/lib/public/modules/sidebar-sessions.js +21 -14
  95. package/lib/public/modules/sticky-notes.js +3 -2
  96. package/lib/public/modules/team-panel.js +5 -4
  97. package/lib/public/modules/tools.js +67 -904
  98. package/lib/public/modules/vendor-picker.js +53 -0
  99. package/lib/public/modules/vendor-registry.js +133 -0
  100. package/lib/public/sw.js +3 -1
  101. package/lib/rc-migrate.js +44 -0
  102. package/lib/runtime-env-keys.js +109 -0
  103. package/lib/runtime-env.js +236 -0
  104. package/lib/sdk-bridge.js +290 -273
  105. package/lib/sdk-message-processor.js +125 -145
  106. package/lib/server-hub-sessions.js +13 -10
  107. package/lib/server-palette.js +28 -19
  108. package/lib/server.js +141 -113
  109. package/lib/service-install.js +96 -0
  110. package/lib/session-capabilities.js +76 -0
  111. package/lib/sessions.js +45 -28
  112. package/lib/users-permissions.js +9 -6
  113. package/lib/users.js +9 -0
  114. package/lib/utils.js +4 -2
  115. package/lib/vendor-auth.js +22 -0
  116. package/lib/vendor-registry-message.js +65 -0
  117. package/lib/ws-origin.js +99 -0
  118. package/lib/ws-schema.js +33 -22
  119. package/lib/yoke/adapters/claude-capabilities.js +38 -0
  120. package/lib/yoke/adapters/claude-vendor.js +35 -0
  121. package/lib/yoke/adapters/claude-worker.js +55 -87
  122. package/lib/yoke/adapters/claude.js +156 -62
  123. package/lib/yoke/adapters/codex-capabilities.js +37 -0
  124. package/lib/yoke/adapters/codex-vendor.js +46 -0
  125. package/lib/yoke/adapters/codex.js +347 -156
  126. package/lib/yoke/adapters/effort-control.js +34 -0
  127. package/lib/yoke/adapters/permission-relay.js +58 -0
  128. package/lib/yoke/adapters/worker-mcp-servers.js +81 -0
  129. package/lib/yoke/auth-checks.js +104 -0
  130. package/lib/yoke/capabilities.js +49 -0
  131. package/lib/yoke/codex-app-server.js +23 -5
  132. package/lib/yoke/env-ownership.js +40 -0
  133. package/lib/yoke/index.js +67 -173
  134. package/lib/yoke/install-probe.js +121 -0
  135. package/lib/yoke/instructions.js +7 -11
  136. package/lib/yoke/interface.js +199 -3
  137. package/lib/yoke/package.json +1 -1
  138. package/lib/yoke/provider-credentials.js +96 -0
  139. package/lib/yoke/registry.js +340 -0
  140. package/package.json +12 -8
  141. package/scripts/check-sdk-lock-drift.js +160 -0
  142. package/scripts/check-test-count.js +76 -1
  143. package/scripts/postinstall.js +218 -136
  144. package/scripts/prompt-harness-history.js +202 -0
  145. package/scripts/verify-installed.js +67 -0
  146. package/lib/sdk-permission-ownership.js +0 -136
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ // Changing the reasoning effort of a Claude session that is already running.
4
+ // The SDK's Query has no setEffort; the live control is applyFlagSettings
5
+ // with an effortLevel, which takes effect for the rest of the session.
6
+ // 'max' is session-only and runs as 'high' on a model without it, which the
7
+ // SDK decides, so the console passes it through.
8
+ //
9
+ // Shared by the in-process query handle and the worker process, so the two
10
+ // paths cannot disagree about what a valid level is or what a failure is.
11
+
12
+ var EFFORT_LEVELS = ["low", "medium", "high", "xhigh", "max"];
13
+
14
+ /**
15
+ * @param {object} query - the SDK Query.
16
+ * @param {string} effort - one of EFFORT_LEVELS.
17
+ * @returns {Promise<void>} rejects with a message fit to show the operator.
18
+ */
19
+ function applyEffort(query, effort) {
20
+ if (EFFORT_LEVELS.indexOf(effort) === -1) {
21
+ return Promise.reject(new Error("Unknown effort level: " + String(effort).slice(0, 40)));
22
+ }
23
+ if (!query || typeof query.applyFlagSettings !== "function") {
24
+ return Promise.reject(new Error("This Claude Code version cannot change effort in a running session"));
25
+ }
26
+ return Promise.resolve().then(function () {
27
+ return query.applyFlagSettings({ effortLevel: effort });
28
+ });
29
+ }
30
+
31
+ module.exports = {
32
+ EFFORT_LEVELS: EFFORT_LEVELS,
33
+ applyEffort: applyEffort,
34
+ };
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ // The wire shape of a tool-permission ask between a Claude worker process and
4
+ // the daemon. The worker builds the message from the options the SDK handed
5
+ // its canUseTool callback; the daemon turns it back into the options its own
6
+ // canUseTool callback takes. Both sides use these two functions so a field the
7
+ // SDK adds to an ask cannot be carried by one and dropped by the other.
8
+ //
9
+ // The presentation hints travel with the ask: suppressAlwaysAllowRule (no
10
+ // persistent "don't ask again" choice), defaultToNo (the ask must not open on
11
+ // an approve choice) and matchedAskRule (a user-written ask rule forced the
12
+ // prompt, so no host-side auto-approval may answer it). Only a literal true
13
+ // restricts, and a rule is data, not a flag: anything present but not an object
14
+ // is still a rule-forced ask.
15
+
16
+ /**
17
+ * @param {string} requestId - the worker's id for this ask.
18
+ * @param {string} toolName
19
+ * @param {object} input
20
+ * @param {object} opts - the SDK's canUseTool options.
21
+ * @returns {object} the IPC message.
22
+ */
23
+ function toRequestMessage(requestId, toolName, input, opts) {
24
+ var msg = {
25
+ type: "permission_request",
26
+ requestId: requestId,
27
+ toolName: toolName,
28
+ input: input,
29
+ toolUseId: opts.toolUseID || "",
30
+ decisionReason: opts.decisionReason || "",
31
+ };
32
+ if (opts.suppressAlwaysAllowRule === true) msg.suppressAlwaysAllowRule = true;
33
+ if (opts.defaultToNo === true) msg.defaultToNo = true;
34
+ if (opts.matchedAskRule) msg.matchedAskRule = opts.matchedAskRule;
35
+ return msg;
36
+ }
37
+
38
+ /**
39
+ * @param {object} msg - a permission_request IPC message from a worker.
40
+ * @param {AbortSignal} signal - ends the ask when the worker stops waiting.
41
+ * @returns {object} canUseTool options for the daemon-side callback.
42
+ */
43
+ function toCanUseToolOptions(msg, signal) {
44
+ var opts = {
45
+ toolUseID: msg.toolUseId,
46
+ decisionReason: msg.decisionReason,
47
+ signal: signal,
48
+ };
49
+ if (msg.suppressAlwaysAllowRule === true) opts.suppressAlwaysAllowRule = true;
50
+ if (msg.defaultToNo === true) opts.defaultToNo = true;
51
+ if (msg.matchedAskRule) opts.matchedAskRule = typeof msg.matchedAskRule === "object" ? msg.matchedAskRule : {};
52
+ return opts;
53
+ }
54
+
55
+ module.exports = {
56
+ toRequestMessage: toRequestMessage,
57
+ toCanUseToolOptions: toCanUseToolOptions,
58
+ };
@@ -0,0 +1,81 @@
1
+ // worker-mcp-servers.js - rebuilds the in-process MCP servers inside the
2
+ // worker process from the JSON-schema descriptors the daemon sends over IPC
3
+ // (the SDK's server objects are not serializable). A tool whose schema cannot
4
+ // be read (mcp-tool-input.js) is left out and reported; the other tools on its
5
+ // server, and the other servers, are still registered.
6
+
7
+ var mcpToolSchema = require("../../mcp-tool-schema");
8
+ var { prepareTool } = require("../../mcp-tool-input");
9
+
10
+ // Throws when zod cannot be loaded; the caller reports the cause per tool.
11
+ function loadZod() {
12
+ var mod = require("zod");
13
+ return mod.z || mod;
14
+ }
15
+
16
+ /**
17
+ * @param {Array} descriptors [{ serverName, tools: [{ name, description, inputSchema }] }]
18
+ * @param {object} sdk the SDK module (tool, createSdkMcpServer)
19
+ * @param {object} hooks
20
+ * @param {function(string, string): function} hooks.createHandler (serverName, toolName) -> tool handler
21
+ * @param {function(object): void} [hooks.onSkipped] receives the diagnostic for a tool left out
22
+ * @param {function(): ?object} [hooks.loadZod] returns zod, or null/throws when it cannot be loaded; tests inject it
23
+ * @returns {?object} serverName -> server, or null when none was built
24
+ */
25
+ function buildMcpServersFromDescriptors(descriptors, sdk, hooks) {
26
+ if (!descriptors || !descriptors.length) return null;
27
+ var z = null;
28
+ var zodLoadError = "";
29
+ try {
30
+ z = (hooks.loadZod || loadZod)();
31
+ } catch (e) {
32
+ zodLoadError = ": " + ((e && e.message) || String(e));
33
+ }
34
+
35
+ var servers = {};
36
+ for (var i = 0; i < descriptors.length; i++) {
37
+ var descriptor = descriptors[i];
38
+ if (!descriptor || !descriptor.serverName || !descriptor.tools || !descriptor.tools.length) continue;
39
+ var tools = [];
40
+ for (var j = 0; j < descriptor.tools.length; j++) {
41
+ var toolDescriptor = descriptor.tools[j];
42
+ if (!toolDescriptor || !toolDescriptor.name) continue;
43
+ var prepared;
44
+ try {
45
+ if (!z) throw new Error("zod could not be loaded in the worker" + zodLoadError);
46
+ prepared = prepareTool(
47
+ z,
48
+ toolDescriptor.inputSchema,
49
+ hooks.createHandler(descriptor.serverName, toolDescriptor.name)
50
+ );
51
+ } catch (e) {
52
+ mcpToolSchema.reportSkippedTool(
53
+ descriptor.serverName,
54
+ toolDescriptor.name,
55
+ (e && e.message) || String(e),
56
+ hooks.onSkipped
57
+ );
58
+ continue;
59
+ }
60
+ tools.push(sdk.tool(
61
+ toolDescriptor.name,
62
+ toolDescriptor.description || toolDescriptor.name,
63
+ prepared.inputSchema,
64
+ prepared.handler
65
+ ));
66
+ }
67
+ if (tools.length > 0) {
68
+ servers[descriptor.serverName] = sdk.createSdkMcpServer({
69
+ name: descriptor.serverName,
70
+ version: "1.0.0",
71
+ tools: tools,
72
+ });
73
+ }
74
+ }
75
+
76
+ return Object.keys(servers).length > 0 ? servers : null;
77
+ }
78
+
79
+ module.exports = {
80
+ buildMcpServersFromDescriptors: buildMcpServersFromDescriptors,
81
+ };
@@ -0,0 +1,104 @@
1
+ // auth-checks.js - per-agent "is a login in place" probes. Each registered
2
+ // vendor points at one of these through its descriptor's checkAuth.
3
+
4
+ var fs = require("fs");
5
+ var execSync = require("child_process").execSync;
6
+ var execFileSync = require("child_process").execFileSync;
7
+ var installProbe = require("./install-probe");
8
+ var providerCredentials = require("./provider-credentials");
9
+
10
+ function parseClaudeAuthStatusJson(out) {
11
+ if (!out) return null;
12
+ try {
13
+ return JSON.parse(out);
14
+ } catch (e) {
15
+ return null;
16
+ }
17
+ }
18
+
19
+ function isClaudeLoggedInText(out) {
20
+ if (!out) return false;
21
+ var text = String(out).toLowerCase();
22
+ if (text.indexOf("not logged in") !== -1) return false;
23
+ if (text.indexOf("login method:") !== -1) return true;
24
+ if (text.indexOf("logged in") !== -1) return true;
25
+ return false;
26
+ }
27
+
28
+ function hasThirdPartyProviderAuth(env) {
29
+ // Claude Code supports third-party providers via env vars. When these are set,
30
+ // `claude auth status` reports "not logged in" because there is no OAuth session,
31
+ // but Claude Code itself authenticates directly through the provider.
32
+ env = env || process.env;
33
+ var cloud = providerCredentials.completeProvider(env);
34
+ if (cloud) return cloud;
35
+ if (env.ANTHROPIC_API_KEY) return "api_key";
36
+ if (env.ANTHROPIC_AUTH_TOKEN) return "auth_token";
37
+ return null;
38
+ }
39
+
40
+ function checkClaudeAuth() {
41
+ var provider = hasThirdPartyProviderAuth();
42
+ if (provider) {
43
+ console.log("[yoke] Claude auth via third-party provider: " + provider);
44
+ return true;
45
+ }
46
+
47
+ try {
48
+ var out = execSync("claude auth status --json", { timeout: 5000, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] });
49
+ var parsed = parseClaudeAuthStatusJson(out);
50
+ if (parsed) return !!parsed.loggedIn;
51
+ console.warn("[yoke] Claude auth status JSON parse failed; falling back to text output");
52
+ } catch (e) {
53
+ var stdout = e && e.stdout ? String(e.stdout) : "";
54
+ if (stdout) {
55
+ var parsedFallback = parseClaudeAuthStatusJson(stdout);
56
+ if (parsedFallback) return !!parsedFallback.loggedIn;
57
+ }
58
+ console.warn("[yoke] Claude auth status JSON check failed; falling back to text output:", e.message);
59
+ }
60
+
61
+ try {
62
+ var textOut = execSync("claude auth status --text", { timeout: 5000, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] });
63
+ return isClaudeLoggedInText(textOut);
64
+ } catch (e) {
65
+ return false;
66
+ }
67
+ }
68
+
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
+ function checkCodexAuth() {
83
+ var codexBin;
84
+ try {
85
+ codexBin = resolveCodexBinary();
86
+ } catch (e) {
87
+ // Not an absent bundle (that falls back to PATH): a defect worth seeing.
88
+ console.error("[yoke] Codex binary lookup failed:", e && e.message ? e.message : e);
89
+ return false;
90
+ }
91
+ if (!codexBin) return false;
92
+ try {
93
+ execFileSync(codexBin, ["login", "status"], { timeout: 5000, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] });
94
+ return true;
95
+ } catch (e) {
96
+ return false;
97
+ }
98
+ }
99
+
100
+ module.exports = {
101
+ hasThirdPartyProviderAuth: hasThirdPartyProviderAuth,
102
+ checkClaudeAuth: checkClaudeAuth,
103
+ checkCodexAuth: checkCodexAuth,
104
+ };
@@ -0,0 +1,49 @@
1
+ // capabilities.js - what one agent can do right now: the yoke's declaration,
2
+ // overlaid with a connection's overrides, narrowed by what the live session
3
+ // advertises. The result is what the UI gates controls on.
4
+
5
+ var iface = require("./interface");
6
+
7
+ function intersect(a, b) {
8
+ return a.filter(function (item) { return b.indexOf(item) !== -1; });
9
+ }
10
+
11
+ /**
12
+ * @param {{capabilities: object}} yoke a registered vendor descriptor; its
13
+ * declared capabilities are the starting point
14
+ * @param {?{capabilityOverrides: object}} connection optional. Overrides may
15
+ * widen or narrow the declaration: a connection knows which model sits
16
+ * behind the agent.
17
+ * @param {?object} sessionAdvertised optional. What the running session
18
+ * reports. It can only narrow: a flag it reports false turns the capability
19
+ * off, a list it reports restricts the entries to those it names, and a key
20
+ * it does not report is left as it was. Keys outside the ledger are ignored.
21
+ * @returns {object} every ledger key, flags as booleans, lists as arrays
22
+ */
23
+ function resolveCapabilities(yoke, connection, sessionAdvertised) {
24
+ if (!yoke || typeof yoke !== "object") {
25
+ throw new Error("[YOKE] resolveCapabilities needs a yoke declaration");
26
+ }
27
+ var out = iface.completeCapabilities(yoke.capabilities);
28
+
29
+ var overrides = connection && connection.capabilityOverrides;
30
+ if (overrides) {
31
+ iface.validateCapabilities(overrides, "capabilityOverrides");
32
+ Object.keys(overrides).forEach(function (key) {
33
+ out[key] = iface.CAPABILITIES[key].kind === "list" ? overrides[key].slice() : overrides[key];
34
+ });
35
+ }
36
+
37
+ if (sessionAdvertised) {
38
+ iface.validateCapabilities(sessionAdvertised, "the session's advertised", { ignoreUnknown: true });
39
+ Object.keys(sessionAdvertised).forEach(function (key) {
40
+ if (!iface.isCapabilityKey(key)) return;
41
+ if (iface.CAPABILITIES[key].kind === "list") out[key] = intersect(out[key], sessionAdvertised[key]);
42
+ else out[key] = out[key] && sessionAdvertised[key];
43
+ });
44
+ }
45
+
46
+ return out;
47
+ }
48
+
49
+ module.exports = { resolveCapabilities: resolveCapabilities };
@@ -35,12 +35,27 @@ function getTargetTriple() {
35
35
  return null;
36
36
  }
37
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
+
38
53
  function findCodexPath() {
39
54
  var triple = getTargetTriple();
40
- if (!triple) throw new Error("Unsupported platform: " + process.platform + "/" + process.arch);
55
+ if (!triple) throw bundleAbsentError("Unsupported platform: " + process.platform + "/" + process.arch);
41
56
 
42
57
  var platformPkg = PLATFORM_PACKAGE_BY_TARGET[triple];
43
- if (!platformPkg) throw new Error("No codex binary package for: " + triple);
58
+ if (!platformPkg) throw bundleAbsentError("No codex binary package for: " + triple);
44
59
 
45
60
  try {
46
61
  var codexPkgJson = require.resolve("@openai/codex/package.json");
@@ -50,7 +65,8 @@ function findCodexPath() {
50
65
  var binaryName = process.platform === "win32" ? "codex.exe" : "codex";
51
66
  return path.join(vendorRoot, triple, "codex", binaryName);
52
67
  } catch (e) {
53
- throw new Error("Could not find codex binary: " + e.message);
68
+ if (e && e.code === "MODULE_NOT_FOUND") throw bundleAbsentError("Could not find codex binary: " + e.message);
69
+ throw e;
54
70
  }
55
71
  }
56
72
 
@@ -98,7 +114,8 @@ function CodexAppServer(executablePath, opts) {
98
114
  this.proc = null;
99
115
  this.rl = null;
100
116
  this.nextId = 1;
101
- this.pendingRequests = {}; // id -> { resolve, reject, timer }
117
+ // Keyed by ids the app-server echoes back: no prototype to answer for them.
118
+ this.pendingRequests = Object.create(null); // id -> { resolve, reject, timer }
102
119
  // eventHandler kept for backward-compat but superseded by the multiplexer below.
103
120
  // Use addEventHandler / removeEventHandler instead of setting this directly.
104
121
  this.eventHandler = null;
@@ -300,7 +317,7 @@ CodexAppServer.prototype._rejectAllPending = function(err) {
300
317
  if (pending.timer) clearTimeout(pending.timer);
301
318
  pending.reject(err);
302
319
  }
303
- this.pendingRequests = {};
320
+ this.pendingRequests = Object.create(null);
304
321
  };
305
322
 
306
323
  // Register an event handler for a specific thread (or null to receive all events).
@@ -349,4 +366,5 @@ CodexAppServer.prototype.stop = function() {
349
366
  module.exports = {
350
367
  CodexAppServer: CodexAppServer,
351
368
  findCodexPath: findCodexPath,
369
+ isBundleAbsent: isBundleAbsent,
352
370
  };
@@ -0,0 +1,40 @@
1
+ // env-ownership.js - the one rule for whether an environment variable name
2
+ // belongs to a namespace. Ownership is by prefix (or an exact name), never by a
3
+ // list of the variables known today: a list is one name short the day a
4
+ // provider adds a variable, and that variable then leaks from the daemon's
5
+ // environment into a session that was meant to use its own.
6
+ //
7
+ // Names compare case-insensitively, as runtime-env-keys.js does.
8
+
9
+ function normalize(name) {
10
+ return typeof name === "string" ? name.toUpperCase() : "";
11
+ }
12
+
13
+ /** Whether name starts with any of the prefixes. */
14
+ function matchesPrefix(prefixes, name) {
15
+ var upper = normalize(name);
16
+ if (!upper) return false;
17
+ return (prefixes || []).some(function (p) { return upper.indexOf(normalize(p)) === 0; });
18
+ }
19
+
20
+ /** Whether name is one of the exact names. */
21
+ function matchesName(names, name) {
22
+ var upper = normalize(name);
23
+ if (!upper) return false;
24
+ return (names || []).some(function (n) { return normalize(n) === upper; });
25
+ }
26
+
27
+ /**
28
+ * Whether a scope ({names, prefixes}) owns the variable name.
29
+ * @param {{names: ?string[], prefixes: ?string[]}} scope
30
+ * @param {string} name
31
+ */
32
+ function owns(scope, name) {
33
+ return matchesName(scope.names, name) || matchesPrefix(scope.prefixes, name);
34
+ }
35
+
36
+ module.exports = {
37
+ matchesPrefix: matchesPrefix,
38
+ matchesName: matchesName,
39
+ owns: owns,
40
+ };