@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
package/lib/yoke/index.js CHANGED
@@ -3,8 +3,13 @@
3
3
 
4
4
  var iface = require("./interface");
5
5
  var instructions = require("./instructions");
6
- var createClaudeAdapter = require("./adapters/claude").createClaudeAdapter;
7
- var createCodexAdapter = require("./adapters/codex").createCodexAdapter;
6
+ var registry = require("./registry");
7
+ var installProbe = require("./install-probe");
8
+ var capabilities = require("./capabilities");
9
+ // Requiring the vendor modules registers the shipped agents. They are light on
10
+ // purpose: the adapters themselves are loaded when one is created.
11
+ require("./adapters/claude-vendor");
12
+ require("./adapters/codex-vendor");
8
13
 
9
14
  /**
10
15
  * Wrap adapter.createQuery to inject cross-vendor project instructions.
@@ -34,25 +39,25 @@ function wrapCreateQuery(adapter, defaultCwd) {
34
39
  };
35
40
  }
36
41
 
42
+ // A vendor name that arrives from a client is checked here before it is used as
43
+ // a key or handed to a lookup.
44
+ function isKnownVendor(vendor) {
45
+ return registry.isKnown(vendor);
46
+ }
47
+
37
48
  /**
38
- * Create a YOKE adapter.
49
+ * Create a YOKE adapter for a registered vendor.
39
50
  *
40
51
  * @param {object} opts
41
- * @param {string} [opts.vendor="claude"] - Adapter vendor name
52
+ * @param {string} [opts.vendor] - Registered vendor id (default: the most preferred)
42
53
  * @param {string} opts.cwd - Project working directory
43
54
  * @param {object} [opts.adapterOpts] - Vendor-specific adapter construction options
44
55
  * @returns {Adapter}
56
+ * @throws {Error} code YOKE_UNKNOWN_VENDOR for a vendor that is not registered
45
57
  */
46
58
  function createAdapter(opts) {
47
- var vendor = (opts && opts.vendor) || "claude";
48
- var adapter;
49
- if (vendor === "claude") {
50
- adapter = createClaudeAdapter(opts);
51
- } else if (vendor === "codex") {
52
- adapter = createCodexAdapter(opts);
53
- } else {
54
- throw new Error("[YOKE] Unknown adapter vendor: " + vendor);
55
- }
59
+ var vendor = (opts && opts.vendor) || registry.ids()[0];
60
+ var adapter = registry.get(vendor).createAdapter(opts);
56
61
  iface.validateAdapter(adapter);
57
62
  wrapCreateQuery(adapter, opts && opts.cwd);
58
63
  return adapter;
@@ -73,115 +78,17 @@ function logAuthCheck(auth) {
73
78
  if (_lastAuthLogKey === key && now - _lastAuthLogAt < 30000) return;
74
79
  _lastAuthLogKey = key;
75
80
  _lastAuthLogAt = now;
76
- console.log("[yoke] Auth check: claude=" + auth.claude + " codex=" + auth.codex);
81
+ console.log("[yoke] Auth check: " + Object.keys(auth).map(function(id) { return id + "=" + auth[id]; }).join(" "));
77
82
  }
78
83
 
79
84
  function checkAuth() {
80
85
  if (_authCache) return _authCache;
81
86
 
82
- var execSync = require("child_process").execSync;
83
- var execFileSync = require("child_process").execFileSync;
84
-
85
- function lookupBinary(name) {
86
- try {
87
- if (process.platform === "win32") {
88
- return execFileSync("where", [name], { timeout: 3000, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] }).trim().split(/\r?\n/)[0] || null;
89
- }
90
- return execFileSync("which", [name], { timeout: 3000, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] }).trim().split(/\r?\n/)[0] || null;
91
- } catch (e) {
92
- return null;
93
- }
94
- }
95
-
96
- function parseClaudeAuthStatusJson(out) {
97
- if (!out) return null;
98
- try {
99
- return JSON.parse(out);
100
- } catch (e) {
101
- return null;
102
- }
103
- }
104
-
105
- function isClaudeLoggedInText(out) {
106
- if (!out) return false;
107
- var text = String(out).toLowerCase();
108
- if (text.indexOf("not logged in") !== -1) return false;
109
- if (text.indexOf("login method:") !== -1) return true;
110
- if (text.indexOf("logged in") !== -1) return true;
111
- return false;
112
- }
113
-
114
- function hasThirdPartyProviderAuth() {
115
- // Claude Code supports third-party providers via env vars. When these are set,
116
- // `claude auth status` reports "not logged in" because there is no OAuth session,
117
- // but Claude Code itself authenticates directly through the provider.
118
- var env = process.env;
119
- if (env.CLAUDE_CODE_USE_BEDROCK === "1"
120
- && (env.AWS_BEARER_TOKEN_BEDROCK
121
- || env.AWS_ACCESS_KEY_ID
122
- || env.AWS_PROFILE
123
- || env.AWS_SESSION_TOKEN)) {
124
- return "bedrock";
125
- }
126
- if (env.CLAUDE_CODE_USE_VERTEX === "1") return "vertex";
127
- if (env.ANTHROPIC_API_KEY) return "api_key";
128
- if (env.ANTHROPIC_AUTH_TOKEN) return "auth_token";
129
- return null;
130
- }
131
-
132
- function checkClaude() {
133
- var provider = hasThirdPartyProviderAuth();
134
- if (provider) {
135
- console.log("[yoke] Claude auth via third-party provider: " + provider);
136
- return true;
137
- }
138
-
139
- try {
140
- var out = execSync("claude auth status --json", { timeout: 5000, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] });
141
- var parsed = parseClaudeAuthStatusJson(out);
142
- if (parsed) return !!parsed.loggedIn;
143
- console.warn("[yoke] Claude auth status JSON parse failed; falling back to text output");
144
- } catch (e) {
145
- var stdout = e && e.stdout ? String(e.stdout) : "";
146
- if (stdout) {
147
- var parsedFallback = parseClaudeAuthStatusJson(stdout);
148
- if (parsedFallback) return !!parsedFallback.loggedIn;
149
- }
150
- console.warn("[yoke] Claude auth status JSON check failed; falling back to text output:", e.message);
151
- }
152
-
153
- try {
154
- var textOut = execSync("claude auth status --text", { timeout: 5000, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] });
155
- return isClaudeLoggedInText(textOut);
156
- } catch (e) {
157
- return false;
158
- }
159
- }
160
-
161
- function resolveCodexBinary() {
162
- var fs = require("fs");
163
- var findCodexPath = require("./codex-app-server").findCodexPath;
164
-
165
- try {
166
- var codexBin = findCodexPath();
167
- if (codexBin && fs.existsSync(codexBin)) return codexBin;
168
- } catch (e) {}
169
-
170
- return lookupBinary("codex");
171
- }
172
-
173
- function checkCodex() {
174
- try {
175
- var codexBin = resolveCodexBinary();
176
- if (!codexBin) return false;
177
- execFileSync(codexBin, ["login", "status"], { timeout: 5000, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] });
178
- return true;
179
- } catch (e) {
180
- return false;
181
- }
182
- }
183
-
184
- _authCache = { claude: checkClaude(), codex: checkCodex() };
87
+ var result = {};
88
+ registry.list().forEach(function(vendor) {
89
+ result[vendor.id] = !!vendor.checkAuth();
90
+ });
91
+ _authCache = result;
185
92
  logAuthCheck(_authCache);
186
93
  return _authCache;
187
94
  }
@@ -189,43 +96,21 @@ function checkAuth() {
189
96
  /**
190
97
  * Check which vendor binaries are installed (regardless of auth status).
191
98
  *
192
- * Result is cached at module scope because the check runs two execFileSync
193
- * calls per invocation and is triggered once per project context on daemon
194
- * startup. With N projects this used to cost ~2N synchronous subprocesses;
195
- * caching collapses it to two total. The cache is invalidated alongside
196
- * the auth cache (via invalidateAuthCache) since "just installed" is the
197
- * same situation as "just logged in" from the daemon's perspective.
99
+ * Result is cached at module scope because the check runs a subprocess per
100
+ * vendor per invocation and is triggered once per project context on daemon
101
+ * startup. With N projects that would cost N times the vendors synchronous
102
+ * subprocesses; caching collapses it to one pass. The cache is invalidated
103
+ * alongside the auth cache (via invalidateAuthCache) since "just installed" is
104
+ * the same situation as "just logged in" from the daemon's perspective.
198
105
  */
199
106
  var _installedCache = null;
200
107
 
201
108
  function checkInstalled() {
202
109
  if (_installedCache) return _installedCache;
203
110
 
204
- var fs = require("fs");
205
- var execFileSync = require("child_process").execFileSync;
206
- var result = { claude: false, codex: false };
207
- try {
208
- if (process.platform === "win32") execFileSync("where", ["claude"], { timeout: 3000, stdio: ["pipe", "pipe", "pipe"] });
209
- else execFileSync("which", ["claude"], { timeout: 3000, stdio: ["pipe", "pipe", "pipe"] });
210
- result.claude = true;
211
- } catch (e) {}
212
- try {
213
- var codexBin = null;
214
- try {
215
- var findCodexPath = require("./codex-app-server").findCodexPath;
216
- codexBin = findCodexPath();
217
- if (codexBin && fs.existsSync(codexBin)) {
218
- result.codex = true;
219
- _installedCache = result;
220
- return result;
221
- }
222
- } catch (e) {}
223
-
224
- var whichOut = process.platform === "win32"
225
- ? execFileSync("where", ["codex"], { timeout: 3000, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] })
226
- : execFileSync("which", ["codex"], { timeout: 3000, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] });
227
- if (whichOut.trim()) result.codex = true;
228
- } catch (e) {}
111
+ var installedIds = installProbe.detectInstalledVendors(null);
112
+ var result = {};
113
+ registry.ids().forEach(function(id) { result[id] = installedIds.indexOf(id) !== -1; });
229
114
  _installedCache = result;
230
115
  return result;
231
116
  }
@@ -236,12 +121,13 @@ function invalidateAuthCache() {
236
121
  }
237
122
 
238
123
  /**
239
- * Create adapters for all authenticated vendors.
240
- * Claude may be shared across projects, but Codex is instantiated per project
241
- * so its app-server and bridge stay scoped to a single project slug.
124
+ * Create adapters for all installed vendors.
125
+ * A vendor whose runtime is per project (the perProjectRuntime trait: its
126
+ * app-server and bridge stay scoped to one project slug) is instantiated per
127
+ * project; the others are shared across projects.
242
128
  * Returns { adapters: { vendor: Adapter }, auth: { vendor: boolean } }
243
129
  */
244
- var _sharedClaudeAdapter = null;
130
+ var _sharedAdapters = {};
245
131
 
246
132
  function createAdapters(opts) {
247
133
  opts = opts || {};
@@ -250,31 +136,27 @@ function createAdapters(opts) {
250
136
  // that `claude auth status` does not always detect. Runtime auth failures are
251
137
  // handled downstream via query-level error detection.
252
138
  var installed = checkInstalled();
253
- var auth = { claude: false, codex: false };
139
+ var auth = {};
254
140
  var adapters = {};
255
141
 
256
- if (installed.claude) {
142
+ registry.list().forEach(function(vendor) {
143
+ auth[vendor.id] = false;
144
+ if (!installed[vendor.id]) return;
257
145
  try {
258
- if (!_sharedClaudeAdapter) {
259
- _sharedClaudeAdapter = createAdapter({ vendor: "claude", cwd: opts.cwd });
146
+ if (vendor.perProjectRuntime) {
147
+ adapters[vendor.id] = createAdapter({ vendor: vendor.id, cwd: opts.cwd, slug: opts.slug });
148
+ } else {
149
+ if (!_sharedAdapters[vendor.id]) {
150
+ _sharedAdapters[vendor.id] = createAdapter({ vendor: vendor.id, cwd: opts.cwd });
151
+ }
152
+ adapters[vendor.id] = _sharedAdapters[vendor.id];
260
153
  }
261
- adapters.claude = _sharedClaudeAdapter;
262
- auth.claude = true;
263
- console.log("[yoke] Adapter created: claude");
154
+ auth[vendor.id] = true;
155
+ console.log("[yoke] Adapter created: " + vendor.id);
264
156
  } catch (e) {
265
- console.error("[yoke] Failed to create adapter for claude:", e.message);
157
+ console.error("[yoke] Failed to create adapter for " + vendor.id + ":", e.message);
266
158
  }
267
- }
268
-
269
- if (installed.codex) {
270
- try {
271
- adapters.codex = createAdapter({ vendor: "codex", cwd: opts.cwd, slug: opts.slug });
272
- auth.codex = true;
273
- console.log("[yoke] Adapter created: codex");
274
- } catch (e) {
275
- console.error("[yoke] Failed to create adapter for codex:", e.message);
276
- }
277
- }
159
+ });
278
160
 
279
161
  return { adapters: adapters, auth: auth };
280
162
  }
@@ -283,8 +165,12 @@ function createAdapters(opts) {
283
165
  * Lazy-create an adapter for a vendor that wasn't available at startup.
284
166
  * Re-checks auth, creates adapter if now logged in.
285
167
  * Returns the adapter or null.
168
+ *
169
+ * onInit, when given, is called with what the adapter's init() resolved with
170
+ * (its models and the capabilities the live session advertises), so the caller
171
+ * records them: the init result is the only place those are reported.
286
172
  */
287
- async function lazyCreateAdapter(adapters, vendor, opts) {
173
+ async function lazyCreateAdapter(adapters, vendor, opts, onInit) {
288
174
  opts = opts || {};
289
175
 
290
176
  // Force re-check since user may have logged in after server start
@@ -295,7 +181,8 @@ async function lazyCreateAdapter(adapters, vendor, opts) {
295
181
  try {
296
182
  var ad = createAdapter({ vendor: vendor, cwd: opts.cwd, slug: opts.slug });
297
183
  if (typeof ad.init === "function") {
298
- await ad.init(opts || {});
184
+ var initResult = await ad.init(opts || {});
185
+ if (typeof onInit === "function") onInit(initResult);
299
186
  }
300
187
  console.log("[yoke] Lazy adapter created: " + vendor);
301
188
  adapters[vendor] = ad;
@@ -307,6 +194,12 @@ async function lazyCreateAdapter(adapters, vendor, opts) {
307
194
  }
308
195
 
309
196
  module.exports = {
197
+ isKnownVendor: isKnownVendor,
198
+ registry: registry,
199
+ resolveCapabilities: capabilities.resolveCapabilities,
200
+ completeCapabilities: iface.completeCapabilities,
201
+ detectInstalledVendors: installProbe.detectInstalledVendors,
202
+ detectVendorInstallState: installProbe.detectVendorInstallState,
310
203
  createAdapter: createAdapter,
311
204
  createAdapters: createAdapters,
312
205
  lazyCreateAdapter: lazyCreateAdapter,
@@ -315,6 +208,7 @@ module.exports = {
315
208
  invalidateAuthCache: invalidateAuthCache,
316
209
  INTERFACE_VERSION: iface.INTERFACE_VERSION,
317
210
  TOOL_POLICIES: iface.TOOL_POLICIES,
211
+ CAPABILITIES: iface.CAPABILITIES,
318
212
  DIAGNOSTIC_SEVERITIES: iface.DIAGNOSTIC_SEVERITIES,
319
213
  DIAGNOSTIC_SOURCES: iface.DIAGNOSTIC_SOURCES,
320
214
  validateAdapter: iface.validateAdapter,
@@ -0,0 +1,121 @@
1
+ // install-probe.js - finds out which registered agents are installed, for the
2
+ // daemon's own user or for a specific OS user. Every executable name looked up
3
+ // must belong to a registered vendor (registry.binaryNames): the name reaches
4
+ // a shell command for the OS-user case, so an unregistered name is refused with
5
+ // a named error instead of being passed on.
6
+ //
7
+ // A lookup has three outcomes, never two: found, not installed, or the lookup
8
+ // itself failed (timeout, permission, su or which unusable). A failed lookup
9
+ // is reported as such so the picker can say it could not check, instead of
10
+ // telling the user an installed agent is missing.
11
+
12
+ var execFileSync = require("child_process").execFileSync;
13
+ var registry = require("./registry");
14
+
15
+ var LOOKUP_TIMEOUT_MS = 3000;
16
+ var PROBE_FAILED_CODE = "YOKE_PROBE_FAILED";
17
+
18
+ function ProbeFailedError(probeClass, cause) {
19
+ var err = new Error("[YOKE] Install lookup failed: " + probeClass + (cause && cause.message ? " (" + cause.message + ")" : ""));
20
+ err.code = PROBE_FAILED_CODE;
21
+ err.probeClass = probeClass;
22
+ return err;
23
+ }
24
+
25
+ /**
26
+ * Names why a lookup command did not succeed.
27
+ * @param {Error} e what execFileSync threw
28
+ * @param {boolean} asUser the lookup ran through su
29
+ * @returns {?string} null when the command ran and found nothing, otherwise
30
+ * the failure class
31
+ */
32
+ function classifyLookupFailure(e, asUser) {
33
+ if (e && (e.code === "ETIMEDOUT" || e.killed || e.signal)) return "timeout";
34
+ if (e && (e.code === "EACCES" || e.code === "EPERM")) return "permission-denied";
35
+ if (e && e.code === "ENOENT") return asUser ? "su-unavailable" : "lookup-tool-missing";
36
+ var stderr = e && e.stderr ? String(e.stderr).trim() : "";
37
+ // which exits 1 and prints nothing when the name is not on PATH. Output on
38
+ // stderr with that exit is su (or the shell) failing, not the name missing.
39
+ if (e && e.status === 1 && !stderr) return null;
40
+ return asUser ? "su-failed" : "lookup-failed";
41
+ }
42
+
43
+ /**
44
+ * Outcome of looking up one registered executable.
45
+ * @param {string} name must be a registered binary name
46
+ * @param {?string} linuxUser look it up as this OS user instead
47
+ * @returns {{state: "found", path: string}|{state: "missing"}|{state: "failed", probeClass: string}}
48
+ */
49
+ function probeBinary(name, linuxUser) {
50
+ registry.assertAllowedBinary(name);
51
+ var options = { timeout: LOOKUP_TIMEOUT_MS, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] };
52
+ try {
53
+ var out;
54
+ if (linuxUser) {
55
+ out = execFileSync("su", ["-", linuxUser, "-c", "which " + name], options);
56
+ } else if (process.platform === "win32") {
57
+ out = execFileSync("where", [name], options);
58
+ } else {
59
+ out = execFileSync("which", [name], options);
60
+ }
61
+ return { state: "found", path: String(out).trim().split(/\r?\n/)[0] };
62
+ } catch (e) {
63
+ var probeClass = classifyLookupFailure(e, !!linuxUser);
64
+ return probeClass ? { state: "failed", probeClass: probeClass } : { state: "missing" };
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Path of a registered executable on PATH, or null when it was not found or
70
+ * the lookup failed. Callers that must tell the two apart use probeBinary.
71
+ * @param {string} name must be a registered binary name
72
+ * @param {?string} linuxUser look it up as this OS user instead
73
+ */
74
+ function findBinaryPath(name, linuxUser) {
75
+ var result = probeBinary(name, linuxUser);
76
+ return result.state === "found" ? result.path : null;
77
+ }
78
+
79
+ /**
80
+ * Which registered vendors are installed, and which could not be checked.
81
+ * @param {?string} linuxUser
82
+ * @returns {{installed: string[], failures: Object<string, string>}}
83
+ * failures maps a vendor id to the class of the lookup failure
84
+ */
85
+ function detectVendorInstallState(linuxUser) {
86
+ var installed = [];
87
+ var failures = {};
88
+ registry.list().forEach(function (vendor) {
89
+ try {
90
+ var found = vendor.probeInstalled({
91
+ lookupBinary: function (name) {
92
+ var result = probeBinary(name, linuxUser);
93
+ if (result.state === "failed") throw ProbeFailedError(result.probeClass);
94
+ return result.state === "found";
95
+ },
96
+ });
97
+ if (found) installed.push(vendor.id);
98
+ } catch (e) {
99
+ if (!e || e.code !== PROBE_FAILED_CODE) throw e;
100
+ failures[vendor.id] = e.probeClass;
101
+ }
102
+ });
103
+ return { installed: installed, failures: failures };
104
+ }
105
+
106
+ /**
107
+ * Ids of the registered vendors that are installed.
108
+ * @param {?string} linuxUser
109
+ * @returns {string[]}
110
+ */
111
+ function detectInstalledVendors(linuxUser) {
112
+ return detectVendorInstallState(linuxUser).installed;
113
+ }
114
+
115
+ module.exports = {
116
+ classifyLookupFailure: classifyLookupFailure,
117
+ probeBinary: probeBinary,
118
+ findBinaryPath: findBinaryPath,
119
+ detectVendorInstallState: detectVendorInstallState,
120
+ detectInstalledVendors: detectInstalledVendors,
121
+ };
@@ -4,11 +4,13 @@
4
4
  // (CLAUDE.md, AGENTS.md, .cursorrules, etc.) and merges them into
5
5
  // a single string that any adapter can inject as context.
6
6
  //
7
- // Each adapter declares which files its vendor reads natively so
8
- // those are excluded from the merged output (no double-injection).
7
+ // Each adapter declares (in its registered descriptor) which files its vendor
8
+ // reads natively so those are excluded from the merged output (no
9
+ // double-injection).
9
10
 
10
11
  var fs = require("fs");
11
12
  var path = require("path");
13
+ var registry = require("./registry");
12
14
 
13
15
  // Known instruction files in priority order.
14
16
  // { file: relative path, label: human-readable label }
@@ -20,20 +22,15 @@ var KNOWN_FILES = [
20
22
  { file: "COPILOT.md", label: "COPILOT.md" },
21
23
  ];
22
24
 
23
- // Files each vendor reads natively (skip these to avoid duplication).
24
- var NATIVE_FILES = {
25
- claude: ["CLAUDE.md"],
26
- codex: ["AGENTS.md"],
27
- };
28
-
29
25
  // Scan projectDir for instruction files and return merged text.
30
- // Excludes files the given vendor already reads natively.
26
+ // Excludes the files the given vendor reads natively (its registered
27
+ // nativeInstructionFiles); a vendor that is not registered reads none.
31
28
  //
32
29
  // Returns "" if no files found (callers can skip injection).
33
30
  function scanAndMerge(projectDir, vendor) {
34
31
  if (!projectDir) return "";
35
32
 
36
- var exclude = NATIVE_FILES[vendor] || [];
33
+ var exclude = registry.isKnown(vendor) ? registry.get(vendor).nativeInstructionFiles : [];
37
34
  var sections = [];
38
35
 
39
36
  for (var i = 0; i < KNOWN_FILES.length; i++) {
@@ -57,5 +54,4 @@ function scanAndMerge(projectDir, vendor) {
57
54
  module.exports = {
58
55
  scanAndMerge: scanAndMerge,
59
56
  KNOWN_FILES: KNOWN_FILES,
60
- NATIVE_FILES: NATIVE_FILES,
61
57
  };