@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
@@ -19,6 +19,10 @@ var path = require("path");
19
19
  var fs = require("fs");
20
20
  var os = require("os");
21
21
  var parseDiagnosticLine = require("./diagnostic-patterns").parseDiagnosticLine;
22
+ var permissionRelay = require("./permission-relay");
23
+ var effortControl = require("./effort-control");
24
+ var turnInitiator = require("../../turn-initiator");
25
+ var workerMcpServers = require("./worker-mcp-servers");
22
26
 
23
27
  var socketPath = process.argv[2];
24
28
  if (!socketPath) {
@@ -93,15 +97,34 @@ function applyWorkerClaudeBinary(options) {
93
97
  return options;
94
98
  }
95
99
 
100
+ // The variables Settings add arrive as an overlay. The SDK REPLACES the CLI
101
+ // subprocess environment with options.env, so they are laid over this
102
+ // worker's own environment (the OS user's, in multi-user mode) and the SDK is
103
+ // handed the complete result. The overlay is removed from the options so it
104
+ // goes no further than this function.
105
+ function applyRuntimeEnv(options) {
106
+ if (!options) return options;
107
+ var overlay = options.runtimeEnv;
108
+ var initiator = options.initiator;
109
+ delete options.runtimeEnv;
110
+ delete options.initiator;
111
+ // Always built: the product identity is part of every Claude process's
112
+ // environment, with the initiator of the turn that starts the query.
113
+ options.env = turnInitiator.claudeProcessEnv(process.env, overlay, initiator);
114
+ return options;
115
+ }
116
+
96
117
  // --- State ---
97
118
  var sdkModule = null;
98
119
  var queryInstance = null;
99
120
  var messageQueue = null;
100
121
  var abortController = null;
101
- var pendingPermissions = {}; // requestId -> resolve
102
- var pendingAskUser = {}; // toolUseId -> resolve
103
- var pendingElicitations = {}; // requestId -> resolve
104
- var pendingMcpToolCalls = {}; // requestId -> { resolve, reject }
122
+ // Keyed by ids that come in over the daemon socket: no prototype, so an id
123
+ // such as "constructor" finds nothing instead of an inherited function.
124
+ var pendingPermissions = Object.create(null); // requestId -> resolve
125
+ var pendingAskUser = Object.create(null); // toolUseId -> resolve
126
+ var pendingElicitations = Object.create(null); // requestId -> resolve
127
+ var pendingMcpToolCalls = Object.create(null); // requestId -> { resolve, reject }
105
128
  var conn = null;
106
129
  var buffer = "";
107
130
  // Reference to the claude CLI child process spawned by spawnClaudeCodeProcess.
@@ -153,40 +176,6 @@ function getSDK() {
153
176
  return sdkModule;
154
177
  }
155
178
 
156
- function buildZodShape(z, inputSchema) {
157
- if (!inputSchema || !inputSchema.properties) return {};
158
- var shape = {};
159
- var props = inputSchema.properties;
160
- var required = inputSchema.required || [];
161
- var keys = Object.keys(props);
162
-
163
- for (var i = 0; i < keys.length; i++) {
164
- var key = keys[i];
165
- var prop = props[key];
166
- var field;
167
-
168
- if (prop.type === "number" || prop.type === "integer") {
169
- field = z.number();
170
- } else if (prop.type === "boolean") {
171
- field = z.boolean();
172
- } else if (prop.type === "array") {
173
- field = z.array(z.any());
174
- } else if (prop.type === "object") {
175
- field = z.record(z.any());
176
- } else if (prop.enum) {
177
- field = z.enum(prop.enum);
178
- } else {
179
- field = z.string();
180
- }
181
-
182
- if (prop.description) field = field.describe(prop.description);
183
- if (required.indexOf(key) === -1) field = field.optional();
184
- shape[key] = field;
185
- }
186
-
187
- return shape;
188
- }
189
-
190
179
  function createWorkerMcpToolHandler(serverName, toolName) {
191
180
  return function(args) {
192
181
  var requestId = crypto.randomUUID();
@@ -204,37 +193,10 @@ function createWorkerMcpToolHandler(serverName, toolName) {
204
193
  }
205
194
 
206
195
  function buildMcpServersFromDescriptors(descriptors, sdk) {
207
- if (!descriptors || !descriptors.length) return null;
208
- var z;
209
- try { z = require("zod").z; } catch (e) {
210
- try { z = require("zod"); } catch (e2) { return null; }
211
- }
212
-
213
- var servers = {};
214
- for (var i = 0; i < descriptors.length; i++) {
215
- var descriptor = descriptors[i];
216
- if (!descriptor || !descriptor.serverName || !descriptor.tools || !descriptor.tools.length) continue;
217
- var tools = [];
218
- for (var j = 0; j < descriptor.tools.length; j++) {
219
- var toolDescriptor = descriptor.tools[j];
220
- if (!toolDescriptor || !toolDescriptor.name) continue;
221
- tools.push(sdk.tool(
222
- toolDescriptor.name,
223
- toolDescriptor.description || toolDescriptor.name,
224
- buildZodShape(z, toolDescriptor.inputSchema),
225
- createWorkerMcpToolHandler(descriptor.serverName, toolDescriptor.name)
226
- ));
227
- }
228
- if (tools.length > 0) {
229
- servers[descriptor.serverName] = sdk.createSdkMcpServer({
230
- name: descriptor.serverName,
231
- version: "1.0.0",
232
- tools: tools,
233
- });
234
- }
235
- }
236
-
237
- return Object.keys(servers).length > 0 ? servers : null;
196
+ return workerMcpServers.buildMcpServersFromDescriptors(descriptors, sdk, {
197
+ createHandler: createWorkerMcpToolHandler,
198
+ onSkipped: function(diagnostic) { sendToDaemon({ type: "sdk_event", event: diagnostic }); },
199
+ });
238
200
  }
239
201
 
240
202
  // --- IPC helpers ---
@@ -303,19 +265,15 @@ function handleMessage(msg) {
303
265
  // --- canUseTool: delegates to daemon via IPC ---
304
266
  function canUseTool(toolName, input, opts) {
305
267
  var requestId = crypto.randomUUID();
306
- sendToDaemon({
307
- type: "permission_request",
308
- requestId: requestId,
309
- toolName: toolName,
310
- input: input,
311
- toolUseId: opts.toolUseID || "",
312
- decisionReason: opts.decisionReason || "",
313
- });
268
+ sendToDaemon(permissionRelay.toRequestMessage(requestId, toolName, input, opts));
314
269
  return new Promise(function(resolve) {
315
270
  var timeoutId = setTimeout(function() {
316
271
  if (pendingPermissions[requestId]) {
317
272
  delete pendingPermissions[requestId];
318
273
  resolve({ behavior: "deny", message: "Permission request timed out after 30s" });
274
+ // The daemon still shows the request as answerable; tell it the
275
+ // decision can no longer take effect.
276
+ sendToDaemon({ type: "permission_expired", requestId: requestId });
319
277
  }
320
278
  }, 30000);
321
279
  pendingPermissions[requestId] = function(result) {
@@ -328,6 +286,7 @@ function canUseTool(toolName, input, opts) {
328
286
  clearTimeout(timeoutId);
329
287
  delete pendingPermissions[requestId];
330
288
  resolve({ behavior: "deny", message: "Cancelled" });
289
+ sendToDaemon({ type: "prompt_cancelled", kind: "permission", id: requestId });
331
290
  }
332
291
  });
333
292
  }
@@ -351,8 +310,10 @@ function onElicitation(request, opts) {
351
310
  pendingElicitations[requestId] = resolve;
352
311
  if (opts.signal) {
353
312
  opts.signal.addEventListener("abort", function() {
313
+ if (!pendingElicitations[requestId]) return;
354
314
  delete pendingElicitations[requestId];
355
315
  resolve({ action: "reject" });
316
+ sendToDaemon({ type: "prompt_cancelled", kind: "elicitation", id: requestId });
356
317
  });
357
318
  }
358
319
  });
@@ -421,8 +382,8 @@ async function handleQueryStart(msg) {
421
382
  // Build query options (callbacks are local, everything else from daemon)
422
383
  var options = msg.options || {};
423
384
  options.abortController = abortController;
424
- if (process.env.CLAGENTIC_DEBUG === "1") {
425
- var _logDir = path.join(os.homedir(), ".clagentic", "worker-logs");
385
+ if (require("../../env-compat").readConsoleEnv("CLAGENTIC_CONSOLE_DEBUG") === "1") {
386
+ var _logDir = path.join(os.homedir(), ".clagentic", "console", "worker-logs");
426
387
  fs.mkdirSync(_logDir, { recursive: true, mode: 0o700 });
427
388
  var _logFile = path.join(_logDir, process.pid + ".log");
428
389
  // Create with 0o600 before passing to the SDK so the file is never world-readable
@@ -431,6 +392,7 @@ async function handleQueryStart(msg) {
431
392
  options.debugFile = _logFile;
432
393
  }
433
394
  applyWorkerClaudeBinary(options);
395
+ applyRuntimeEnv(options);
434
396
  if (options.mcpServerDescriptors && options.mcpServerDescriptors.length) {
435
397
  try {
436
398
  var mcpServers = buildMcpServersFromDescriptors(options.mcpServerDescriptors, sdk);
@@ -501,8 +463,10 @@ async function handleQueryStart(msg) {
501
463
  pendingAskUser[toolUseId] = resolve;
502
464
  if (toolOpts.signal) {
503
465
  toolOpts.signal.addEventListener("abort", function() {
466
+ if (!pendingAskUser[toolUseId]) return;
504
467
  delete pendingAskUser[toolUseId];
505
468
  resolve({ behavior: "deny", message: "Cancelled" });
469
+ sendToDaemon({ type: "prompt_cancelled", kind: "ask_user", id: toolUseId });
506
470
  });
507
471
  }
508
472
  });
@@ -607,10 +571,10 @@ async function handleQueryStart(msg) {
607
571
  queryInstance = null;
608
572
  messageQueue = null;
609
573
  abortController = null;
610
- pendingPermissions = {};
611
- pendingAskUser = {};
612
- pendingElicitations = {};
613
- pendingMcpToolCalls = {};
574
+ pendingPermissions = Object.create(null);
575
+ pendingAskUser = Object.create(null);
576
+ pendingElicitations = Object.create(null);
577
+ pendingMcpToolCalls = Object.create(null);
614
578
  }
615
579
  }
616
580
 
@@ -633,13 +597,18 @@ async function handleSetModel(msg) {
633
597
  }
634
598
  }
635
599
 
600
+ // requestId is echoed on both outcomes so the daemon's pending setEffort()
601
+ // resolves or rejects on the real result.
636
602
  async function handleSetEffort(msg) {
637
- if (!queryInstance) return;
603
+ if (!queryInstance) {
604
+ sendToDaemon({ type: "worker_error", error: "Failed to set effort: no running query", requestId: msg.requestId });
605
+ return;
606
+ }
638
607
  try {
639
- await queryInstance.setEffort(msg.effort);
640
- sendToDaemon({ type: "effort_changed", effort: msg.effort });
608
+ await effortControl.applyEffort(queryInstance, msg.effort);
609
+ sendToDaemon({ type: "effort_changed", effort: msg.effort, requestId: msg.requestId });
641
610
  } catch (e) {
642
- sendToDaemon({ type: "worker_error", error: "Failed to set effort: " + (e.message || e) });
611
+ sendToDaemon({ type: "worker_error", error: "Failed to set effort: " + (e.message || e), requestId: msg.requestId });
643
612
  }
644
613
  }
645
614
 
@@ -700,6 +669,7 @@ async function handleWarmup(msg) {
700
669
  var warmupOptions = msg.options || {};
701
670
  warmupOptions.abortController = ac;
702
671
  applyWorkerClaudeBinary(warmupOptions);
672
+ applyRuntimeEnv(warmupOptions);
703
673
 
704
674
  try {
705
675
  var stream = sdk.query({