@clagentic/console 1.9.0 → 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 (172) 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 +9 -3
  5. package/bin/cli.js +40 -5
  6. package/deploy/clagentic-console.service +10 -6
  7. package/lib/agent-dispatch-tool.js +20 -0
  8. package/lib/audit.js +3 -2
  9. package/lib/build-changes.js +79 -0
  10. package/lib/build-identity.js +192 -0
  11. package/lib/build-monitor.js +125 -0
  12. package/lib/build-sha.json +2 -2
  13. package/lib/build-update-check.js +138 -0
  14. package/lib/build-update-offer.js +141 -0
  15. package/lib/build-update-restart.js +142 -0
  16. package/lib/build-update-standing.js +184 -0
  17. package/lib/cli/daemon-launch.js +25 -22
  18. package/lib/cli/ipc-subcommands.js +6 -0
  19. package/lib/cli/session-subcommands.js +122 -0
  20. package/lib/cli-sessions.js +8 -1
  21. package/lib/codex-defaults.js +8 -2
  22. package/lib/config.js +32 -20
  23. package/lib/daemon-env-settings.js +84 -0
  24. package/lib/daemon-projects.js +57 -0
  25. package/lib/daemon.js +288 -205
  26. package/lib/drain.js +74 -17
  27. package/lib/env-compat.js +61 -0
  28. package/lib/extension-commands.js +45 -0
  29. package/lib/history-visibility.js +4 -0
  30. package/lib/idle-adapter-reaper.js +71 -0
  31. package/lib/link-trap.js +78 -0
  32. package/lib/mcp-local.js +8 -6
  33. package/lib/mcp-tool-input.js +116 -0
  34. package/lib/mcp-tool-schema.js +179 -0
  35. package/lib/memory-limits.js +61 -5
  36. package/lib/memory-setting-validate.js +65 -0
  37. package/lib/memory-shed.js +13 -32
  38. package/lib/new-work-gate.js +47 -0
  39. package/lib/os-users.js +5 -3
  40. package/lib/project-access.js +139 -0
  41. package/lib/project-connection.js +37 -22
  42. package/lib/project-external-trigger.js +166 -105
  43. package/lib/project-file-scope.js +172 -0
  44. package/lib/project-file-watch.js +86 -61
  45. package/lib/project-filesystem.js +144 -128
  46. package/lib/project-git.js +119 -0
  47. package/lib/project-http.js +44 -28
  48. package/lib/project-loop.js +17 -9
  49. package/lib/project-mcp.js +53 -72
  50. package/lib/project-message-gate.js +70 -0
  51. package/lib/project-notifications.js +31 -4
  52. package/lib/project-prompt-responses.js +217 -0
  53. package/lib/project-sessions.js +192 -355
  54. package/lib/project-user-message.js +27 -15
  55. package/lib/project.js +212 -147
  56. package/lib/projects-dir.js +90 -0
  57. package/lib/prompt-access.js +22 -0
  58. package/lib/prompt-kinds/answer-limits.js +15 -0
  59. package/lib/prompt-kinds/ask-user.js +58 -0
  60. package/lib/prompt-kinds/codecs.js +97 -0
  61. package/lib/prompt-kinds/elicitation.js +77 -0
  62. package/lib/prompt-kinds/extension.js +39 -0
  63. package/lib/prompt-kinds/index.js +68 -0
  64. package/lib/prompt-kinds/permission.js +114 -0
  65. package/lib/prompt-kinds/plan.js +79 -0
  66. package/lib/prompt-kinds/tool-call.js +38 -0
  67. package/lib/prompt-registry.js +680 -0
  68. package/lib/public/app.js +1 -1
  69. package/lib/public/css/diagnostics.css +80 -0
  70. package/lib/public/css/input.css +17 -3
  71. package/lib/public/css/menus.css +10 -0
  72. package/lib/public/css/messages.css +5 -0
  73. package/lib/public/css/rewind.css +22 -0
  74. package/lib/public/index.html +4 -12
  75. package/lib/public/modules/agent-dispatch-tool.js +9 -0
  76. package/lib/public/modules/app-connection.js +7 -0
  77. package/lib/public/modules/app-cursors.js +7 -5
  78. package/lib/public/modules/app-messages.js +52 -47
  79. package/lib/public/modules/app-notifications.js +47 -71
  80. package/lib/public/modules/app-panels.js +61 -59
  81. package/lib/public/modules/app-projects.js +2 -1
  82. package/lib/public/modules/app-rendering.js +4 -10
  83. package/lib/public/modules/build-update-detail.js +54 -0
  84. package/lib/public/modules/diagnostics.js +170 -20
  85. package/lib/public/modules/filebrowser.js +18 -16
  86. package/lib/public/modules/history-visibility.js +4 -0
  87. package/lib/public/modules/mention.js +3 -2
  88. package/lib/public/modules/mode-options.js +38 -0
  89. package/lib/public/modules/project-settings.js +19 -8
  90. package/lib/public/modules/prompt-banner.js +78 -0
  91. package/lib/public/modules/prompt-card.js +201 -0
  92. package/lib/public/modules/prompt-kinds/ask-user-codec.js +131 -0
  93. package/lib/public/modules/prompt-kinds/ask-user.js +213 -0
  94. package/lib/public/modules/prompt-kinds/elicitation-codec.js +343 -0
  95. package/lib/public/modules/prompt-kinds/elicitation.js +176 -0
  96. package/lib/public/modules/prompt-kinds/index.js +18 -0
  97. package/lib/public/modules/prompt-kinds/own-key.js +29 -0
  98. package/lib/public/modules/prompt-kinds/package.json +3 -0
  99. package/lib/public/modules/prompt-kinds/permission-choices.js +31 -0
  100. package/lib/public/modules/prompt-kinds/permission.js +209 -0
  101. package/lib/public/modules/prompt-kinds/plan.js +102 -0
  102. package/lib/public/modules/prompt-state.js +142 -0
  103. package/lib/public/modules/prompts.js +134 -0
  104. package/lib/public/modules/rewind.js +4 -1
  105. package/lib/public/modules/server-settings.js +2 -4
  106. package/lib/public/modules/sidebar-mobile.js +19 -9
  107. package/lib/public/modules/sidebar-sessions.js +21 -14
  108. package/lib/public/modules/sticky-notes.js +3 -2
  109. package/lib/public/modules/team-panel.js +5 -4
  110. package/lib/public/modules/tools.js +81 -906
  111. package/lib/public/modules/vendor-picker.js +53 -0
  112. package/lib/public/modules/vendor-registry.js +142 -0
  113. package/lib/public/sw.js +3 -1
  114. package/lib/rc-migrate.js +44 -0
  115. package/lib/runtime-env-keys.js +109 -0
  116. package/lib/runtime-env.js +236 -0
  117. package/lib/sdk-bridge.js +348 -284
  118. package/lib/sdk-message-processor.js +117 -146
  119. package/lib/sdk-skill-discovery.js +65 -60
  120. package/lib/server-hub-sessions.js +13 -10
  121. package/lib/server-palette.js +28 -19
  122. package/lib/server.js +156 -115
  123. package/lib/service-install.js +96 -0
  124. package/lib/session-capabilities.js +76 -0
  125. package/lib/session-id.js +33 -0
  126. package/lib/session-input-ipc.js +32 -0
  127. package/lib/session-input.js +379 -0
  128. package/lib/session-reclaim.js +284 -0
  129. package/lib/session-resume.js +172 -0
  130. package/lib/sessions.js +61 -30
  131. package/lib/supervisor.js +39 -0
  132. package/lib/turn-initiator.js +108 -0
  133. package/lib/users-permissions.js +9 -6
  134. package/lib/users.js +9 -0
  135. package/lib/utils.js +4 -2
  136. package/lib/vendor-auth.js +22 -0
  137. package/lib/vendor-registry-message.js +66 -0
  138. package/lib/ws-origin.js +99 -0
  139. package/lib/ws-schema.js +36 -23
  140. package/lib/yoke/adapters/claude-capabilities.js +38 -0
  141. package/lib/yoke/adapters/claude-vendor.js +34 -0
  142. package/lib/yoke/adapters/claude-worker.js +57 -87
  143. package/lib/yoke/adapters/claude.js +182 -88
  144. package/lib/yoke/adapters/codex-capabilities.js +40 -0
  145. package/lib/yoke/adapters/codex-vendor.js +46 -0
  146. package/lib/yoke/adapters/codex.js +462 -211
  147. package/lib/yoke/adapters/effort-control.js +34 -0
  148. package/lib/yoke/adapters/permission-relay.js +58 -0
  149. package/lib/yoke/adapters/worker-mcp-servers.js +81 -0
  150. package/lib/yoke/auth-checks.js +91 -0
  151. package/lib/yoke/capabilities.js +49 -0
  152. package/lib/yoke/codex-app-server.js +30 -56
  153. package/lib/yoke/codex-binary.js +254 -0
  154. package/lib/yoke/codex-command.js +122 -0
  155. package/lib/yoke/codex-protocol.js +96 -0
  156. package/lib/yoke/codex-version.js +135 -0
  157. package/lib/yoke/env-ownership.js +40 -0
  158. package/lib/yoke/index.js +84 -174
  159. package/lib/yoke/install-probe.js +136 -0
  160. package/lib/yoke/instructions.js +7 -11
  161. package/lib/yoke/interface.js +206 -4
  162. package/lib/yoke/package.json +1 -1
  163. package/lib/yoke/provider-credentials.js +96 -0
  164. package/lib/yoke/registry.js +377 -0
  165. package/package.json +12 -9
  166. package/scripts/check-sdk-lock-drift.js +160 -0
  167. package/scripts/check-test-count.js +76 -1
  168. package/scripts/postinstall.js +218 -136
  169. package/scripts/prompt-harness-history.js +202 -0
  170. package/scripts/verify-installed-build.js +59 -17
  171. package/scripts/verify-installed.js +67 -0
  172. package/lib/sdk-permission-ownership.js +0 -136
@@ -14,6 +14,30 @@
14
14
  // Added: 'diagnostic' event type (DIAGNOSTIC_SEVERITIES, DIAGNOSTIC_SOURCES,
15
15
  // validateDiagnosticEvent). Existing consumers are unaffected — no existing
16
16
  // shape was narrowed or removed.
17
+ //
18
+ // 0.2.0 → 0.3.0 (2026-10, additive plus one tightening)
19
+ // Added: the capability ledger (CAPABILITIES, resolveCapabilities), the
20
+ // vendor registry that carries each adapter's declaration (registry.js), and
21
+ // the optional adapter / query-handle surface the console already consumed
22
+ // off-contract (ADAPTER_OPTIONAL_METHODS, QUERY_HANDLE_OPTIONAL_METHODS).
23
+ // Removed from the contract: nothing.
24
+ // Tightened: endInput joins QUERY_HANDLE_METHODS, since the console ends the
25
+ // input of every query it finishes and both shipped adapters implement it.
26
+ //
27
+ // 0.3.0 → 0.4.0 (2026-10, breaking for descriptors)
28
+ // Moved: perProjectRuntime, activityTokens and attestsHumanSessions leave the
29
+ // capability ledger and become descriptor traits (TRAITS). They describe how
30
+ // the console drives an adapter, not what a session negotiates, so they are
31
+ // never resolved, narrowed or overridden. A descriptor that still declares
32
+ // one as a capability is refused with a named error.
33
+ //
34
+ // 0.4.0 → 0.5.0 (2026-10, additive plus one removal)
35
+ // Added: QueryHandle.pushMessage takes an optional third argument, the
36
+ // initiator of the turn (lib/turn-initiator.js INITIATORS), which an adapter
37
+ // maps to its vendor's per-turn provenance field. An adapter that has none
38
+ // ignores it.
39
+ // Removed: the attestsHumanSessions trait. Provenance is per turn and carried
40
+ // by the turn itself, not declared per adapter.
17
41
 
18
42
  /**
19
43
  * YOKE contract version. Bumped on every additive or breaking change.
@@ -24,8 +48,11 @@
24
48
  * History:
25
49
  * 0.1.0 — initial contract (Adapter + QueryHandle shapes)
26
50
  * 0.2.0 — added 'diagnostic' event type (lr-8c43)
51
+ * 0.3.0 — capability ledger, vendor registry, reconciled method lists
52
+ * 0.4.0 — adapter traits split out of the capability ledger
53
+ * 0.5.0 — per-turn initiator on pushMessage; attestsHumanSessions removed
27
54
  */
28
- var INTERFACE_VERSION = "0.2.0";
55
+ var INTERFACE_VERSION = "0.5.0";
29
56
 
30
57
  var TOOL_POLICIES = ["ask", "allow-all"];
31
58
 
@@ -36,7 +63,9 @@ var TOOL_POLICIES = ["ask", "allow-all"];
36
63
  * Adapter shape:
37
64
  * .vendor : string - e.g. "claude", "opencode", "codex"
38
65
  * .init(opts) : Promise<InitResult>
39
- * .supportedModels(): Promise<string[]>
66
+ * .supportedModels(opts): Promise<string[]> - opts.runtimeEnv (the Settings
67
+ * overlay, or null for none) is required by an adapter that keeps a server
68
+ * per environment (Codex); the list is that server's own
40
69
  * .createToolServer(def): ToolServer (opaque)
41
70
  * .createQuery(opts): QueryHandle
42
71
  *
@@ -54,14 +83,26 @@ var TOOL_POLICIES = ["ask", "allow-all"];
54
83
  *
55
84
  * QueryHandle shape:
56
85
  * [Symbol.asyncIterator]() - yields SDK events (raw in Phase 3, normalized later)
57
- * .pushMessage(text, images)
86
+ * .pushMessage(text, images, initiator) - initiator optional, per turn
58
87
  * .setModel(model)
59
- * .setEffort(effort)
88
+ * .setEffort(effort) - Promise; settles once the running query has
89
+ * taken the change and rejects (with a message
90
+ * fit to show the operator) when it did not. The
91
+ * Claude SDK's Query has no setEffort: the Claude
92
+ * adapter applies it through applyFlagSettings
93
+ * ({effortLevel}); Codex reads it on the next turn.
60
94
  * .setToolPolicy(policy) - "ask" | "allow-all"
61
95
  * .stopTask(taskId)
62
96
  * .getContextUsage() - Promise<object|null>
63
97
  * .abort()
64
98
  * .close()
99
+ * .endInput() - no more messages will be pushed to this query
100
+ *
101
+ * Each adapter also registers a vendor descriptor with registry.js (from a
102
+ * small adapters/<name>-vendor.js module, so listing the agents does not load
103
+ * the adapter): its id, display metadata, install probe, login command, environment needs
104
+ * and its declared capabilities (CAPABILITIES below). The adapter factory is
105
+ * part of that descriptor; nothing else in the console names a vendor.
65
106
  */
66
107
 
67
108
  var ADAPTER_METHODS = [
@@ -80,8 +121,160 @@ var QUERY_HANDLE_METHODS = [
80
121
  "getContextUsage",
81
122
  "abort",
82
123
  "close",
124
+ "endInput",
83
125
  ];
84
126
 
127
+ /**
128
+ * Methods the console calls on a query handle only when the adapter's
129
+ * declared capabilities say it can use them. A caller checks the capability
130
+ * (or the method) first; absence is not an error.
131
+ * .setPermissionMode(mode) - capability permissionModes
132
+ * .rewindFiles(uuid, opts) - capability rewind
133
+ */
134
+ var QUERY_HANDLE_OPTIONAL_METHODS = [
135
+ "setPermissionMode",
136
+ "rewindFiles",
137
+ ];
138
+
139
+ /**
140
+ * Adapter methods and properties the console uses beyond ADAPTER_METHODS.
141
+ * Optional: the console feature behind each is gated by a capability.
142
+ * .generateTitle(messages, opts) - session titles
143
+ * .getSessionInfo / .listSessions / .renameSession - capabilities
144
+ * sessionList, sessionRename
145
+ * .forkSession(sessionId, opts) - capability fork
146
+ * .rollbackThread(threadId, n, opts) - capability rollback
147
+ * .shutdown() - trait perProjectRuntime
148
+ * .shutdownIfIdle(idleMs) - idle runtime reclaim
149
+ * .workerScriptPath - OS-user isolation worker (string)
150
+ * .interfaceVersion - the INTERFACE_VERSION it was built for
151
+ * init() resolves with { models, defaultModel, skills, slashCommands,
152
+ * capabilities }; the capabilities member is the live session's advertised
153
+ * capabilities, which can only narrow the declaration (resolveCapabilities).
154
+ */
155
+ var ADAPTER_OPTIONAL_METHODS = [
156
+ "generateTitle",
157
+ "getSessionInfo",
158
+ "listSessions",
159
+ "renameSession",
160
+ "forkSession",
161
+ "rollbackThread",
162
+ "shutdown",
163
+ "shutdownIfIdle",
164
+ ];
165
+
166
+ /**
167
+ * The capability ledger: the one list of what an agent can do, and so the one
168
+ * list the UI gates on. A control is shown, disabled or hidden from these keys,
169
+ * never from a vendor name. Every key is declared by every adapter (an absent
170
+ * flag is false, an absent list is empty).
171
+ *
172
+ * kind "flag" - boolean
173
+ * kind "list" - array of strings; narrowing intersects, overriding replaces
174
+ * reason - the one line shown beside a control that is disabled
175
+ * because the agent lacks the capability
176
+ */
177
+ var CAPABILITIES = {
178
+ thinking: { kind: "flag", reason: "This agent has no extended thinking control." },
179
+ betas: { kind: "flag", reason: "This agent has no beta feature switches." },
180
+ effort: { kind: "flag", reason: "This agent does not take a reasoning effort setting." },
181
+ rewind: { kind: "flag", reason: "This agent cannot rewind file changes to an earlier message." },
182
+ fork: { kind: "flag", reason: "This agent cannot fork a conversation at a message." },
183
+ rollback: { kind: "flag", reason: "This agent cannot roll a conversation back." },
184
+ sessionResume: { kind: "flag", reason: "This agent cannot resume a previous session." },
185
+ sessionList: { kind: "flag", reason: "This agent cannot list its own sessions." },
186
+ sessionRename: { kind: "flag", reason: "This agent cannot rename its own sessions." },
187
+ sessionArchive: { kind: "flag", reason: "This agent cannot archive its own sessions." },
188
+ promptSuggestions: { kind: "flag", reason: "This agent does not suggest follow-up prompts." },
189
+ elicitation: { kind: "flag", reason: "This agent cannot ask for structured input mid-turn." },
190
+ fileCheckpointing: { kind: "flag", reason: "This agent does not checkpoint file changes." },
191
+ contextCompacting: { kind: "flag", reason: "This agent cannot compact its context." },
192
+ mcpPanel: { kind: "flag", reason: "This agent does not use the MCP servers managed here." },
193
+ backgroundTasks: { kind: "flag", reason: "This agent has no background tasks." },
194
+ steering: { kind: "flag", reason: "This agent cannot take a message while it is working." },
195
+ agentInjection: { kind: "flag", reason: "This agent cannot take on a named agent identity." },
196
+ executionPolicy: { kind: "flag", reason: "This agent has no approval, sandbox or web search settings." },
197
+ toolPolicy: { kind: "list", reason: "This agent has no tool approval policy." },
198
+ permissionModes: { kind: "list", reason: "This agent has no permission modes." },
199
+ };
200
+
201
+ var CAPABILITY_KEYS = Object.keys(CAPABILITIES);
202
+
203
+ /**
204
+ * Adapter traits: booleans on the vendor descriptor describing how the console
205
+ * drives the adapter. Unlike a capability, a trait is a fact about the adapter
206
+ * itself, read where no session exists yet (adapter creation) or where the
207
+ * answer must not change with a connection (shutdown, activity bookkeeping).
208
+ * A trait is never resolved, narrowed or overridden. An absent trait is false.
209
+ *
210
+ * perProjectRuntime - the adapter's runtime belongs to one project and is
211
+ * created and shut down with it
212
+ * activityTokens - the adapter's tool and thinking blocks are tracked as
213
+ * activity tokens by the console
214
+ */
215
+ var TRAITS = {
216
+ perProjectRuntime: true,
217
+ activityTokens: true,
218
+ };
219
+
220
+ var TRAIT_KEYS = Object.keys(TRAITS);
221
+
222
+ function isTraitKey(key) {
223
+ return Object.prototype.hasOwnProperty.call(TRAITS, key);
224
+ }
225
+
226
+ function isCapabilityKey(key) {
227
+ return Object.prototype.hasOwnProperty.call(CAPABILITIES, key);
228
+ }
229
+
230
+ /**
231
+ * Checks a capability object (a declaration, an override or an advertisement)
232
+ * and throws a named error for a key outside the ledger or a value of the
233
+ * wrong kind. Keys it does not carry are simply absent.
234
+ *
235
+ * @param {object} caps
236
+ * @param {string} where what is being checked, for the message
237
+ * @param {{ignoreUnknown: boolean}} [options] skip keys outside the ledger
238
+ * (a live session may advertise more than the ledger names)
239
+ */
240
+ function validateCapabilities(caps, where, options) {
241
+ if (!caps || typeof caps !== "object" || Array.isArray(caps)) {
242
+ throw new Error("[YOKE] " + where + " capabilities must be an object");
243
+ }
244
+ var ignoreUnknown = !!(options && options.ignoreUnknown);
245
+ Object.keys(caps).forEach(function (key) {
246
+ if (!isCapabilityKey(key)) {
247
+ if (ignoreUnknown) return;
248
+ if (isTraitKey(key)) {
249
+ throw new Error("[YOKE] " + where + " names '" + key + "' as a capability; it is an adapter trait set on the descriptor");
250
+ }
251
+ throw new Error("[YOKE] " + where + " names an unknown capability: " + key);
252
+ }
253
+ var kind = CAPABILITIES[key].kind;
254
+ var value = caps[key];
255
+ if (kind === "flag" && typeof value !== "boolean") {
256
+ throw new Error("[YOKE] " + where + " capability '" + key + "' must be a boolean");
257
+ }
258
+ if (kind === "list" && (!Array.isArray(value) || value.some(function (v) { return typeof v !== "string"; }))) {
259
+ throw new Error("[YOKE] " + where + " capability '" + key + "' must be an array of strings");
260
+ }
261
+ });
262
+ }
263
+
264
+ /**
265
+ * A declaration with every ledger key present: absent flags are false, absent
266
+ * lists are empty. The result is a copy.
267
+ */
268
+ function completeCapabilities(caps) {
269
+ var out = {};
270
+ CAPABILITY_KEYS.forEach(function (key) {
271
+ var has = caps && Object.prototype.hasOwnProperty.call(caps, key);
272
+ if (CAPABILITIES[key].kind === "list") out[key] = has ? caps[key].slice() : [];
273
+ else out[key] = has ? !!caps[key] : false;
274
+ });
275
+ return out;
276
+ }
277
+
85
278
  /**
86
279
  * 'diagnostic' event type — vendor-agnostic signal for CLI-surfaced warnings,
87
280
  * validation failures, deprecations, and load errors that adapters capture
@@ -189,6 +382,15 @@ module.exports = {
189
382
  TOOL_POLICIES: TOOL_POLICIES,
190
383
  ADAPTER_METHODS: ADAPTER_METHODS,
191
384
  QUERY_HANDLE_METHODS: QUERY_HANDLE_METHODS,
385
+ QUERY_HANDLE_OPTIONAL_METHODS: QUERY_HANDLE_OPTIONAL_METHODS,
386
+ ADAPTER_OPTIONAL_METHODS: ADAPTER_OPTIONAL_METHODS,
387
+ CAPABILITIES: CAPABILITIES,
388
+ CAPABILITY_KEYS: CAPABILITY_KEYS,
389
+ isCapabilityKey: isCapabilityKey,
390
+ TRAIT_KEYS: TRAIT_KEYS,
391
+ isTraitKey: isTraitKey,
392
+ validateCapabilities: validateCapabilities,
393
+ completeCapabilities: completeCapabilities,
192
394
  DIAGNOSTIC_SEVERITIES: DIAGNOSTIC_SEVERITIES,
193
395
  DIAGNOSTIC_SOURCES: DIAGNOSTIC_SOURCES,
194
396
  validateAdapter: validateAdapter,
@@ -3,5 +3,5 @@
3
3
  "version": "0.1.0",
4
4
  "description": "YOKE - Yoke Overrides Known Engines. Vendor-independent harness abstraction for Clay.",
5
5
  "main": "index.js",
6
- "license": "MIT"
6
+ "license": "FSL-1.1-MIT"
7
7
  }
@@ -0,0 +1,96 @@
1
+ // provider-credentials.js - the cloud providers Claude Code can reach
2
+ // (Bedrock, Vertex, Foundry): the namespaces of environment variables each one
3
+ // reads, and the rule for when a provider counts as configured. The namespaces
4
+ // feed the vendor descriptor's owned prefixes, so a credential set is owned
5
+ // whole by namespace and an unlisted variable (AWS_ROLE_ARN, AWS_CA_BUNDLE,
6
+ // GOOGLE_CLOUD_PROJECT) is owned the same as a listed one.
7
+
8
+ var envOwnership = require("./env-ownership");
9
+
10
+ /**
11
+ * Credential sets that must each be owned whole (see registry.register). A
12
+ * group owns every variable under its prefixes plus its exact names.
13
+ */
14
+ var CREDENTIAL_GROUPS = [
15
+ { id: "bedrock", prefixes: ["AWS_"], envNames: ["CLAUDE_CODE_USE_BEDROCK"] },
16
+ {
17
+ id: "vertex",
18
+ prefixes: ["GOOGLE_", "GCLOUD_", "CLOUDSDK_", "CLOUD_ML_", "ANTHROPIC_VERTEX_"],
19
+ envNames: ["CLAUDE_CODE_USE_VERTEX"],
20
+ },
21
+ { id: "foundry", prefixes: ["ANTHROPIC_FOUNDRY_"], envNames: ["CLAUDE_CODE_USE_FOUNDRY"] },
22
+ ];
23
+
24
+ /**
25
+ * The one matcher: which credential group owns a variable name, or null.
26
+ * Owned-name resolution, the registry's whole-group check and every env cleanup
27
+ * go through this or through env-ownership.owns, never a name list.
28
+ * @param {string} name
29
+ * @returns {?string} the group id
30
+ */
31
+ function groupOf(name) {
32
+ for (var i = 0; i < CREDENTIAL_GROUPS.length; i++) {
33
+ var group = CREDENTIAL_GROUPS[i];
34
+ if (envOwnership.owns({ names: group.envNames, prefixes: group.prefixes }, name)) return group.id;
35
+ }
36
+ return null;
37
+ }
38
+
39
+ /** Every namespace prefix of every group, without repeats. */
40
+ function allCredentialPrefixes() {
41
+ var out = [];
42
+ CREDENTIAL_GROUPS.forEach(function (group) {
43
+ group.prefixes.forEach(function (p) { if (out.indexOf(p) === -1) out.push(p); });
44
+ });
45
+ return out;
46
+ }
47
+
48
+ /** Every exact name of every group, without repeats. */
49
+ function allCredentialNames() {
50
+ var out = [];
51
+ CREDENTIAL_GROUPS.forEach(function (group) {
52
+ group.envNames.forEach(function (n) { if (out.indexOf(n) === -1) out.push(n); });
53
+ });
54
+ return out;
55
+ }
56
+
57
+ function has(env, name) {
58
+ return typeof env[name] === "string" && env[name] !== "";
59
+ }
60
+
61
+ /**
62
+ * Which cloud provider is selected AND carries a complete credential source,
63
+ * or null. A provider switched on with an incomplete set (an access key id
64
+ * without its secret, a project without credentials) is not authenticated: the
65
+ * caller falls through to the normal login probe.
66
+ * @param {object} env process.env-shaped
67
+ * @returns {?string} "bedrock" | "vertex" | "foundry" | null
68
+ */
69
+ function completeProvider(env) {
70
+ if (env.CLAUDE_CODE_USE_BEDROCK === "1"
71
+ && (has(env, "AWS_BEARER_TOKEN_BEDROCK")
72
+ || has(env, "AWS_PROFILE")
73
+ || (has(env, "AWS_ACCESS_KEY_ID") && has(env, "AWS_SECRET_ACCESS_KEY"))
74
+ || (has(env, "AWS_ROLE_ARN") && has(env, "AWS_WEB_IDENTITY_TOKEN_FILE")))) {
75
+ return "bedrock";
76
+ }
77
+ if (env.CLAUDE_CODE_USE_VERTEX === "1"
78
+ && has(env, "ANTHROPIC_VERTEX_PROJECT_ID")
79
+ && has(env, "GOOGLE_APPLICATION_CREDENTIALS")) {
80
+ return "vertex";
81
+ }
82
+ if (env.CLAUDE_CODE_USE_FOUNDRY === "1"
83
+ && has(env, "ANTHROPIC_FOUNDRY_API_KEY")
84
+ && (has(env, "ANTHROPIC_FOUNDRY_RESOURCE") || has(env, "ANTHROPIC_FOUNDRY_BASE_URL"))) {
85
+ return "foundry";
86
+ }
87
+ return null;
88
+ }
89
+
90
+ module.exports = {
91
+ CREDENTIAL_GROUPS: CREDENTIAL_GROUPS,
92
+ groupOf: groupOf,
93
+ completeProvider: completeProvider,
94
+ allCredentialPrefixes: allCredentialPrefixes,
95
+ allCredentialNames: allCredentialNames,
96
+ };