@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.
- package/LICENSE +117 -12
- package/LICENSES/MIT-legacy.txt +22 -0
- package/LICENSES/README.md +15 -0
- package/README.md +8 -2
- package/bin/cli.js +30 -5
- package/deploy/clagentic-console.service +10 -6
- package/lib/audit.js +3 -2
- package/lib/build-sha.json +2 -2
- package/lib/build-update-check.js +138 -0
- package/lib/cli/daemon-launch.js +17 -17
- package/lib/config.js +32 -20
- package/lib/daemon-env-settings.js +84 -0
- package/lib/daemon-projects.js +38 -0
- package/lib/daemon.js +202 -158
- package/lib/drain.js +74 -17
- package/lib/env-compat.js +61 -0
- package/lib/extension-commands.js +45 -0
- package/lib/history-visibility.js +4 -0
- package/lib/idle-adapter-reaper.js +71 -0
- package/lib/link-trap.js +78 -0
- package/lib/lore-attestation.js +73 -0
- package/lib/mcp-local.js +8 -6
- package/lib/mcp-tool-input.js +116 -0
- package/lib/mcp-tool-schema.js +179 -0
- package/lib/memory-limits.js +61 -5
- package/lib/memory-setting-validate.js +65 -0
- package/lib/new-work-gate.js +47 -0
- package/lib/os-users.js +5 -3
- package/lib/project-access.js +139 -0
- package/lib/project-connection.js +23 -22
- package/lib/project-external-trigger.js +103 -10
- package/lib/project-file-scope.js +172 -0
- package/lib/project-file-watch.js +86 -61
- package/lib/project-filesystem.js +144 -128
- package/lib/project-git.js +119 -0
- package/lib/project-http.js +44 -28
- package/lib/project-loop.js +12 -5
- package/lib/project-mcp.js +53 -72
- package/lib/project-message-gate.js +70 -0
- package/lib/project-notifications.js +31 -4
- package/lib/project-prompt-responses.js +216 -0
- package/lib/project-sessions.js +164 -302
- package/lib/project-user-message.js +36 -11
- package/lib/project.js +189 -142
- package/lib/projects-dir.js +90 -0
- package/lib/prompt-access.js +22 -0
- package/lib/prompt-kinds/answer-limits.js +15 -0
- package/lib/prompt-kinds/ask-user.js +58 -0
- package/lib/prompt-kinds/codecs.js +97 -0
- package/lib/prompt-kinds/elicitation.js +77 -0
- package/lib/prompt-kinds/extension.js +39 -0
- package/lib/prompt-kinds/index.js +68 -0
- package/lib/prompt-kinds/permission.js +114 -0
- package/lib/prompt-kinds/plan.js +79 -0
- package/lib/prompt-kinds/tool-call.js +38 -0
- package/lib/prompt-registry.js +673 -0
- package/lib/public/app.js +1 -1
- package/lib/public/css/diagnostics.css +50 -0
- package/lib/public/css/input.css +17 -3
- package/lib/public/css/menus.css +10 -0
- package/lib/public/css/messages.css +5 -0
- package/lib/public/css/rewind.css +22 -0
- package/lib/public/index.html +4 -12
- package/lib/public/modules/app-connection.js +7 -0
- package/lib/public/modules/app-cursors.js +7 -5
- package/lib/public/modules/app-messages.js +45 -45
- package/lib/public/modules/app-notifications.js +47 -71
- package/lib/public/modules/app-panels.js +61 -58
- package/lib/public/modules/app-projects.js +2 -1
- package/lib/public/modules/app-rendering.js +4 -10
- package/lib/public/modules/diagnostics.js +60 -16
- package/lib/public/modules/filebrowser.js +18 -16
- package/lib/public/modules/history-visibility.js +4 -0
- package/lib/public/modules/mention.js +3 -2
- package/lib/public/modules/mode-options.js +38 -0
- package/lib/public/modules/project-settings.js +19 -8
- package/lib/public/modules/prompt-banner.js +78 -0
- package/lib/public/modules/prompt-card.js +201 -0
- package/lib/public/modules/prompt-kinds/ask-user-codec.js +131 -0
- package/lib/public/modules/prompt-kinds/ask-user.js +213 -0
- package/lib/public/modules/prompt-kinds/elicitation-codec.js +343 -0
- package/lib/public/modules/prompt-kinds/elicitation.js +176 -0
- package/lib/public/modules/prompt-kinds/index.js +18 -0
- package/lib/public/modules/prompt-kinds/own-key.js +29 -0
- package/lib/public/modules/prompt-kinds/package.json +3 -0
- package/lib/public/modules/prompt-kinds/permission-choices.js +31 -0
- package/lib/public/modules/prompt-kinds/permission.js +209 -0
- package/lib/public/modules/prompt-kinds/plan.js +102 -0
- package/lib/public/modules/prompt-state.js +142 -0
- package/lib/public/modules/prompts.js +134 -0
- package/lib/public/modules/rewind.js +4 -1
- package/lib/public/modules/server-settings.js +2 -4
- package/lib/public/modules/sidebar-mobile.js +19 -9
- package/lib/public/modules/sidebar-sessions.js +21 -14
- package/lib/public/modules/sticky-notes.js +3 -2
- package/lib/public/modules/team-panel.js +5 -4
- package/lib/public/modules/tools.js +67 -904
- package/lib/public/modules/vendor-picker.js +53 -0
- package/lib/public/modules/vendor-registry.js +133 -0
- package/lib/public/sw.js +3 -1
- package/lib/rc-migrate.js +44 -0
- package/lib/runtime-env-keys.js +109 -0
- package/lib/runtime-env.js +236 -0
- package/lib/sdk-bridge.js +290 -273
- package/lib/sdk-message-processor.js +125 -145
- package/lib/server-hub-sessions.js +13 -10
- package/lib/server-palette.js +28 -19
- package/lib/server.js +141 -113
- package/lib/service-install.js +96 -0
- package/lib/session-capabilities.js +76 -0
- package/lib/sessions.js +45 -28
- package/lib/users-permissions.js +9 -6
- package/lib/users.js +9 -0
- package/lib/utils.js +4 -2
- package/lib/vendor-auth.js +22 -0
- package/lib/vendor-registry-message.js +65 -0
- package/lib/ws-origin.js +99 -0
- package/lib/ws-schema.js +33 -22
- package/lib/yoke/adapters/claude-capabilities.js +38 -0
- package/lib/yoke/adapters/claude-vendor.js +35 -0
- package/lib/yoke/adapters/claude-worker.js +55 -87
- package/lib/yoke/adapters/claude.js +156 -62
- package/lib/yoke/adapters/codex-capabilities.js +37 -0
- package/lib/yoke/adapters/codex-vendor.js +46 -0
- package/lib/yoke/adapters/codex.js +347 -156
- package/lib/yoke/adapters/effort-control.js +34 -0
- package/lib/yoke/adapters/permission-relay.js +58 -0
- package/lib/yoke/adapters/worker-mcp-servers.js +81 -0
- package/lib/yoke/auth-checks.js +104 -0
- package/lib/yoke/capabilities.js +49 -0
- package/lib/yoke/codex-app-server.js +23 -5
- package/lib/yoke/env-ownership.js +40 -0
- package/lib/yoke/index.js +67 -173
- package/lib/yoke/install-probe.js +121 -0
- package/lib/yoke/instructions.js +7 -11
- package/lib/yoke/interface.js +199 -3
- package/lib/yoke/package.json +1 -1
- package/lib/yoke/provider-credentials.js +96 -0
- package/lib/yoke/registry.js +340 -0
- package/package.json +12 -8
- package/scripts/check-sdk-lock-drift.js +160 -0
- package/scripts/check-test-count.js +76 -1
- package/scripts/postinstall.js +218 -136
- package/scripts/prompt-harness-history.js +202 -0
- package/scripts/verify-installed.js +67 -0
- 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 runtimeEnv = require("../../runtime-env");
|
|
25
|
+
var workerMcpServers = require("./worker-mcp-servers");
|
|
22
26
|
|
|
23
27
|
var socketPath = process.argv[2];
|
|
24
28
|
if (!socketPath) {
|
|
@@ -93,15 +97,32 @@ 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
|
+
delete options.runtimeEnv;
|
|
109
|
+
if (runtimeEnv.hasOverlay(overlay)) {
|
|
110
|
+
options.env = runtimeEnv.composeRuntimeEnv(process.env, overlay);
|
|
111
|
+
}
|
|
112
|
+
return options;
|
|
113
|
+
}
|
|
114
|
+
|
|
96
115
|
// --- State ---
|
|
97
116
|
var sdkModule = null;
|
|
98
117
|
var queryInstance = null;
|
|
99
118
|
var messageQueue = null;
|
|
100
119
|
var abortController = null;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
var
|
|
104
|
-
var
|
|
120
|
+
// Keyed by ids that come in over the daemon socket: no prototype, so an id
|
|
121
|
+
// such as "constructor" finds nothing instead of an inherited function.
|
|
122
|
+
var pendingPermissions = Object.create(null); // requestId -> resolve
|
|
123
|
+
var pendingAskUser = Object.create(null); // toolUseId -> resolve
|
|
124
|
+
var pendingElicitations = Object.create(null); // requestId -> resolve
|
|
125
|
+
var pendingMcpToolCalls = Object.create(null); // requestId -> { resolve, reject }
|
|
105
126
|
var conn = null;
|
|
106
127
|
var buffer = "";
|
|
107
128
|
// Reference to the claude CLI child process spawned by spawnClaudeCodeProcess.
|
|
@@ -153,40 +174,6 @@ function getSDK() {
|
|
|
153
174
|
return sdkModule;
|
|
154
175
|
}
|
|
155
176
|
|
|
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
177
|
function createWorkerMcpToolHandler(serverName, toolName) {
|
|
191
178
|
return function(args) {
|
|
192
179
|
var requestId = crypto.randomUUID();
|
|
@@ -204,37 +191,10 @@ function createWorkerMcpToolHandler(serverName, toolName) {
|
|
|
204
191
|
}
|
|
205
192
|
|
|
206
193
|
function buildMcpServersFromDescriptors(descriptors, sdk) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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;
|
|
194
|
+
return workerMcpServers.buildMcpServersFromDescriptors(descriptors, sdk, {
|
|
195
|
+
createHandler: createWorkerMcpToolHandler,
|
|
196
|
+
onSkipped: function(diagnostic) { sendToDaemon({ type: "sdk_event", event: diagnostic }); },
|
|
197
|
+
});
|
|
238
198
|
}
|
|
239
199
|
|
|
240
200
|
// --- IPC helpers ---
|
|
@@ -303,19 +263,15 @@ function handleMessage(msg) {
|
|
|
303
263
|
// --- canUseTool: delegates to daemon via IPC ---
|
|
304
264
|
function canUseTool(toolName, input, opts) {
|
|
305
265
|
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
|
-
});
|
|
266
|
+
sendToDaemon(permissionRelay.toRequestMessage(requestId, toolName, input, opts));
|
|
314
267
|
return new Promise(function(resolve) {
|
|
315
268
|
var timeoutId = setTimeout(function() {
|
|
316
269
|
if (pendingPermissions[requestId]) {
|
|
317
270
|
delete pendingPermissions[requestId];
|
|
318
271
|
resolve({ behavior: "deny", message: "Permission request timed out after 30s" });
|
|
272
|
+
// The daemon still shows the request as answerable; tell it the
|
|
273
|
+
// decision can no longer take effect.
|
|
274
|
+
sendToDaemon({ type: "permission_expired", requestId: requestId });
|
|
319
275
|
}
|
|
320
276
|
}, 30000);
|
|
321
277
|
pendingPermissions[requestId] = function(result) {
|
|
@@ -328,6 +284,7 @@ function canUseTool(toolName, input, opts) {
|
|
|
328
284
|
clearTimeout(timeoutId);
|
|
329
285
|
delete pendingPermissions[requestId];
|
|
330
286
|
resolve({ behavior: "deny", message: "Cancelled" });
|
|
287
|
+
sendToDaemon({ type: "prompt_cancelled", kind: "permission", id: requestId });
|
|
331
288
|
}
|
|
332
289
|
});
|
|
333
290
|
}
|
|
@@ -351,8 +308,10 @@ function onElicitation(request, opts) {
|
|
|
351
308
|
pendingElicitations[requestId] = resolve;
|
|
352
309
|
if (opts.signal) {
|
|
353
310
|
opts.signal.addEventListener("abort", function() {
|
|
311
|
+
if (!pendingElicitations[requestId]) return;
|
|
354
312
|
delete pendingElicitations[requestId];
|
|
355
313
|
resolve({ action: "reject" });
|
|
314
|
+
sendToDaemon({ type: "prompt_cancelled", kind: "elicitation", id: requestId });
|
|
356
315
|
});
|
|
357
316
|
}
|
|
358
317
|
});
|
|
@@ -421,8 +380,8 @@ async function handleQueryStart(msg) {
|
|
|
421
380
|
// Build query options (callbacks are local, everything else from daemon)
|
|
422
381
|
var options = msg.options || {};
|
|
423
382
|
options.abortController = abortController;
|
|
424
|
-
if (
|
|
425
|
-
var _logDir = path.join(os.homedir(), ".clagentic", "worker-logs");
|
|
383
|
+
if (require("../../env-compat").readConsoleEnv("CLAGENTIC_CONSOLE_DEBUG") === "1") {
|
|
384
|
+
var _logDir = path.join(os.homedir(), ".clagentic", "console", "worker-logs");
|
|
426
385
|
fs.mkdirSync(_logDir, { recursive: true, mode: 0o700 });
|
|
427
386
|
var _logFile = path.join(_logDir, process.pid + ".log");
|
|
428
387
|
// Create with 0o600 before passing to the SDK so the file is never world-readable
|
|
@@ -431,6 +390,7 @@ async function handleQueryStart(msg) {
|
|
|
431
390
|
options.debugFile = _logFile;
|
|
432
391
|
}
|
|
433
392
|
applyWorkerClaudeBinary(options);
|
|
393
|
+
applyRuntimeEnv(options);
|
|
434
394
|
if (options.mcpServerDescriptors && options.mcpServerDescriptors.length) {
|
|
435
395
|
try {
|
|
436
396
|
var mcpServers = buildMcpServersFromDescriptors(options.mcpServerDescriptors, sdk);
|
|
@@ -501,8 +461,10 @@ async function handleQueryStart(msg) {
|
|
|
501
461
|
pendingAskUser[toolUseId] = resolve;
|
|
502
462
|
if (toolOpts.signal) {
|
|
503
463
|
toolOpts.signal.addEventListener("abort", function() {
|
|
464
|
+
if (!pendingAskUser[toolUseId]) return;
|
|
504
465
|
delete pendingAskUser[toolUseId];
|
|
505
466
|
resolve({ behavior: "deny", message: "Cancelled" });
|
|
467
|
+
sendToDaemon({ type: "prompt_cancelled", kind: "ask_user", id: toolUseId });
|
|
506
468
|
});
|
|
507
469
|
}
|
|
508
470
|
});
|
|
@@ -607,10 +569,10 @@ async function handleQueryStart(msg) {
|
|
|
607
569
|
queryInstance = null;
|
|
608
570
|
messageQueue = null;
|
|
609
571
|
abortController = null;
|
|
610
|
-
pendingPermissions =
|
|
611
|
-
pendingAskUser =
|
|
612
|
-
pendingElicitations =
|
|
613
|
-
pendingMcpToolCalls =
|
|
572
|
+
pendingPermissions = Object.create(null);
|
|
573
|
+
pendingAskUser = Object.create(null);
|
|
574
|
+
pendingElicitations = Object.create(null);
|
|
575
|
+
pendingMcpToolCalls = Object.create(null);
|
|
614
576
|
}
|
|
615
577
|
}
|
|
616
578
|
|
|
@@ -633,13 +595,18 @@ async function handleSetModel(msg) {
|
|
|
633
595
|
}
|
|
634
596
|
}
|
|
635
597
|
|
|
598
|
+
// requestId is echoed on both outcomes so the daemon's pending setEffort()
|
|
599
|
+
// resolves or rejects on the real result.
|
|
636
600
|
async function handleSetEffort(msg) {
|
|
637
|
-
if (!queryInstance)
|
|
601
|
+
if (!queryInstance) {
|
|
602
|
+
sendToDaemon({ type: "worker_error", error: "Failed to set effort: no running query", requestId: msg.requestId });
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
638
605
|
try {
|
|
639
|
-
await
|
|
640
|
-
sendToDaemon({ type: "effort_changed", effort: msg.effort });
|
|
606
|
+
await effortControl.applyEffort(queryInstance, msg.effort);
|
|
607
|
+
sendToDaemon({ type: "effort_changed", effort: msg.effort, requestId: msg.requestId });
|
|
641
608
|
} catch (e) {
|
|
642
|
-
sendToDaemon({ type: "worker_error", error: "Failed to set effort: " + (e.message || e) });
|
|
609
|
+
sendToDaemon({ type: "worker_error", error: "Failed to set effort: " + (e.message || e), requestId: msg.requestId });
|
|
643
610
|
}
|
|
644
611
|
}
|
|
645
612
|
|
|
@@ -700,6 +667,7 @@ async function handleWarmup(msg) {
|
|
|
700
667
|
var warmupOptions = msg.options || {};
|
|
701
668
|
warmupOptions.abortController = ac;
|
|
702
669
|
applyWorkerClaudeBinary(warmupOptions);
|
|
670
|
+
applyRuntimeEnv(warmupOptions);
|
|
703
671
|
|
|
704
672
|
try {
|
|
705
673
|
var stream = sdk.query({
|
|
@@ -13,6 +13,10 @@ var { spawn } = require("child_process");
|
|
|
13
13
|
var { resolveOsUserInfo } = require("../../os-users");
|
|
14
14
|
var modelFamilies = require("../../model-families");
|
|
15
15
|
var modelCatalog = require("../../model-catalog");
|
|
16
|
+
var permissionRelay = require("./permission-relay");
|
|
17
|
+
var effortControl = require("./effort-control");
|
|
18
|
+
var runtimeEnv = require("../../runtime-env");
|
|
19
|
+
var claudeCapabilities = require("./claude-capabilities").claudeCapabilities;
|
|
16
20
|
|
|
17
21
|
// --- SDK loading ---
|
|
18
22
|
// Async loader (ESM dynamic import, same pattern as current project.js getSDK)
|
|
@@ -380,10 +384,11 @@ function createQueryHandle(rawQuery, messageQueue, abortController) {
|
|
|
380
384
|
return Promise.resolve();
|
|
381
385
|
},
|
|
382
386
|
|
|
387
|
+
// The SDK's Query has no setEffort; applyFlagSettings is the live control.
|
|
388
|
+
// Rejects when the change did not take effect, so the caller never
|
|
389
|
+
// reports an effort the session is not running at.
|
|
383
390
|
setEffort: function(effort) {
|
|
384
|
-
|
|
385
|
-
// Stored at the console level for next query.
|
|
386
|
-
return Promise.resolve();
|
|
391
|
+
return effortControl.applyEffort(rawQuery, effort);
|
|
387
392
|
},
|
|
388
393
|
|
|
389
394
|
setToolPolicy: function(policy) {
|
|
@@ -792,7 +797,9 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool)
|
|
|
792
797
|
// Pending request/response correlation for handle methods that need a
|
|
793
798
|
// result from the worker (e.g. rewindFiles). Each entry is keyed by a
|
|
794
799
|
// requestId and holds { resolve, reject } of the in-flight Promise.
|
|
795
|
-
|
|
800
|
+
// These three tables are keyed by ids the worker echoes back, so they have
|
|
801
|
+
// no prototype to answer for "constructor" or "__proto__".
|
|
802
|
+
var pendingRewinds = Object.create(null);
|
|
796
803
|
|
|
797
804
|
// lr-f22787: same correlation pattern as pendingRewinds, for setModel.
|
|
798
805
|
// Without this, an invalid/unentitled model ID sent to a worker session
|
|
@@ -802,7 +809,65 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool)
|
|
|
802
809
|
// Promise.resolve() immediately without ever waiting for that reply, so
|
|
803
810
|
// the failure had no path back to the caller (sdk-bridge.js's setModel,
|
|
804
811
|
// then project-sessions.js) to surface to the user.
|
|
805
|
-
var pendingSetModel =
|
|
812
|
+
var pendingSetModel = Object.create(null);
|
|
813
|
+
|
|
814
|
+
// Same correlation for setEffort: the returned promise settles on the
|
|
815
|
+
// worker's real outcome, or rejects when the worker never answers.
|
|
816
|
+
var pendingSetEffort = Object.create(null);
|
|
817
|
+
var SET_EFFORT_TIMEOUT_MS = 15000;
|
|
818
|
+
|
|
819
|
+
function settleSetEffort(requestId, error) {
|
|
820
|
+
var pending = pendingSetEffort[requestId];
|
|
821
|
+
if (!pending) return;
|
|
822
|
+
delete pendingSetEffort[requestId];
|
|
823
|
+
clearTimeout(pending.timer);
|
|
824
|
+
if (error) pending.reject(error);
|
|
825
|
+
else pending.resolve();
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
// The worker's query is over: no pending effort change can still land.
|
|
829
|
+
function failPendingEfforts() {
|
|
830
|
+
Object.keys(pendingSetEffort).forEach(function (requestId) {
|
|
831
|
+
settleSetEffort(requestId, new Error("The Claude query ended before the effort change took effect"));
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
// "<kind>:<worker prompt id>" -> AbortController whose signal is handed to
|
|
836
|
+
// the daemon-side callback, so the daemon-side prompt ends when the worker
|
|
837
|
+
// stops waiting for it: its own timeout, the SDK cancelling the callback,
|
|
838
|
+
// or the worker's query ending.
|
|
839
|
+
var promptAborts = Object.create(null);
|
|
840
|
+
|
|
841
|
+
function abortPrompt(key, reason) {
|
|
842
|
+
var ac = promptAborts[key];
|
|
843
|
+
if (ac) ac.abort(reason);
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
function abortAllPrompts() {
|
|
847
|
+
Object.keys(promptAborts).forEach(function (key) { abortPrompt(key); });
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
// Relays one worker prompt to a daemon-side callback and its answer back.
|
|
851
|
+
// The abort entry lives exactly as long as the callback is pending, on
|
|
852
|
+
// every path out of it.
|
|
853
|
+
function relayPrompt(key, ask, reply, label) {
|
|
854
|
+
var ac = new AbortController();
|
|
855
|
+
promptAborts[key] = ac;
|
|
856
|
+
var pending;
|
|
857
|
+
try {
|
|
858
|
+
pending = Promise.resolve(ask(ac.signal));
|
|
859
|
+
} catch (e) {
|
|
860
|
+
pending = Promise.reject(e);
|
|
861
|
+
}
|
|
862
|
+
pending
|
|
863
|
+
.then(reply)
|
|
864
|
+
.catch(function (e) {
|
|
865
|
+
console.error("[yoke/claude] " + label + " send failed:", (e && e.message) || e);
|
|
866
|
+
})
|
|
867
|
+
.finally(function () {
|
|
868
|
+
if (promptAborts[key] === ac) delete promptAborts[key];
|
|
869
|
+
});
|
|
870
|
+
}
|
|
806
871
|
|
|
807
872
|
function pushToIter(value) {
|
|
808
873
|
if (iterEnded) return;
|
|
@@ -846,47 +911,51 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool)
|
|
|
846
911
|
|
|
847
912
|
case "permission_request":
|
|
848
913
|
if (canUseTool) {
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
signal: { addEventListener: function() {} },
|
|
853
|
-
}).then(function(result) {
|
|
914
|
+
relayPrompt("permission:" + msg.requestId, function (signal) {
|
|
915
|
+
return canUseTool(msg.toolName, msg.input, permissionRelay.toCanUseToolOptions(msg, signal));
|
|
916
|
+
}, function (result) {
|
|
854
917
|
worker.send({ type: "permission_response", requestId: msg.requestId, result: result });
|
|
855
|
-
})
|
|
856
|
-
console.error("[yoke/claude] permission_response send failed:", e.message || e);
|
|
857
|
-
});
|
|
918
|
+
}, "permission_response");
|
|
858
919
|
}
|
|
859
920
|
break;
|
|
860
921
|
|
|
922
|
+
// The worker stopped waiting for a prompt; ending it daemon-side keeps
|
|
923
|
+
// a card from offering an answer that can no longer take effect.
|
|
924
|
+
case "permission_expired":
|
|
925
|
+
abortPrompt("permission:" + msg.requestId, "expired");
|
|
926
|
+
break;
|
|
927
|
+
|
|
928
|
+
case "prompt_cancelled":
|
|
929
|
+
abortPrompt(msg.kind + ":" + msg.id);
|
|
930
|
+
break;
|
|
931
|
+
|
|
861
932
|
case "ask_user_request":
|
|
862
933
|
if (canUseTool) {
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
934
|
+
relayPrompt("ask_user:" + msg.toolUseId, function (signal) {
|
|
935
|
+
return canUseTool("AskUserQuestion", msg.input, {
|
|
936
|
+
toolUseID: msg.toolUseId,
|
|
937
|
+
signal: signal,
|
|
938
|
+
});
|
|
939
|
+
}, function (result) {
|
|
867
940
|
worker.send({ type: "ask_user_response", toolUseId: msg.toolUseId, result: result });
|
|
868
|
-
})
|
|
869
|
-
console.error("[yoke/claude] ask_user_response send failed:", e.message || e);
|
|
870
|
-
});
|
|
941
|
+
}, "ask_user_response");
|
|
871
942
|
}
|
|
872
943
|
break;
|
|
873
944
|
|
|
874
945
|
case "elicitation_request":
|
|
875
946
|
if (onElicitation) {
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
}
|
|
947
|
+
relayPrompt("elicitation:" + msg.requestId, function (signal) {
|
|
948
|
+
return onElicitation({
|
|
949
|
+
serverName: msg.serverName,
|
|
950
|
+
message: msg.message,
|
|
951
|
+
mode: msg.mode,
|
|
952
|
+
url: msg.url,
|
|
953
|
+
elicitationId: msg.elicitationId,
|
|
954
|
+
requestedSchema: msg.requestedSchema,
|
|
955
|
+
}, { signal: signal });
|
|
956
|
+
}, function (result) {
|
|
886
957
|
worker.send({ type: "elicitation_response", requestId: msg.requestId, result: result });
|
|
887
|
-
})
|
|
888
|
-
console.error("[yoke/claude] elicitation_response send failed:", e.message || e);
|
|
889
|
-
});
|
|
958
|
+
}, "elicitation_response");
|
|
890
959
|
}
|
|
891
960
|
break;
|
|
892
961
|
|
|
@@ -905,12 +974,16 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool)
|
|
|
905
974
|
break;
|
|
906
975
|
|
|
907
976
|
case "context_usage":
|
|
908
|
-
case "effort_changed":
|
|
909
977
|
case "permission_mode_changed":
|
|
910
978
|
// Yield these as _worker_meta events so processQueryStream can handle them
|
|
911
979
|
pushToIter({ type: "_worker_meta", subtype: msg.type, data: msg });
|
|
912
980
|
break;
|
|
913
981
|
|
|
982
|
+
case "effort_changed":
|
|
983
|
+
pushToIter({ type: "_worker_meta", subtype: msg.type, data: msg });
|
|
984
|
+
settleSetEffort(msg.requestId, null);
|
|
985
|
+
break;
|
|
986
|
+
|
|
914
987
|
case "model_changed":
|
|
915
988
|
// lr-f22787: still yielded as a _worker_meta event (unchanged
|
|
916
989
|
// consumer contract for sdk-bridge.js), AND resolves the pending
|
|
@@ -926,11 +999,18 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool)
|
|
|
926
999
|
break;
|
|
927
1000
|
|
|
928
1001
|
case "worker_error":
|
|
1002
|
+
// A failure of an in-flight set_effort request is reported by the
|
|
1003
|
+
// rejection of setEffort() alone: also yielding it as a _worker_meta
|
|
1004
|
+
// event would show the operator the same error twice.
|
|
1005
|
+
if (msg.requestId && pendingSetEffort[msg.requestId]) {
|
|
1006
|
+
settleSetEffort(msg.requestId, new Error(msg.error || "Failed to set effort"));
|
|
1007
|
+
break;
|
|
1008
|
+
}
|
|
929
1009
|
// Yielded as a _worker_meta event (unchanged consumer contract), AND
|
|
930
1010
|
// rejects the pending setModel() promise when this worker_error
|
|
931
|
-
// belongs to an in-flight set_model request (lr-f22787).
|
|
932
|
-
//
|
|
933
|
-
//
|
|
1011
|
+
// belongs to an in-flight set_model request (lr-f22787). A
|
|
1012
|
+
// permission-mode failure carries no requestId and so never matches
|
|
1013
|
+
// a pendingSetModel entry.
|
|
934
1014
|
pushToIter({ type: "_worker_meta", subtype: msg.type, data: msg });
|
|
935
1015
|
if (msg.requestId && pendingSetModel[msg.requestId]) {
|
|
936
1016
|
var smErr = pendingSetModel[msg.requestId];
|
|
@@ -952,6 +1032,9 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool)
|
|
|
952
1032
|
case "query_done":
|
|
953
1033
|
console.log("[yoke/claude] IPC query_done received, pid=" + (worker.process ? worker.process.pid : "?"));
|
|
954
1034
|
worker._queryEnded = true;
|
|
1035
|
+
// The worker's query is over; nothing in it waits for an answer.
|
|
1036
|
+
abortAllPrompts();
|
|
1037
|
+
failPendingEfforts();
|
|
955
1038
|
endIter();
|
|
956
1039
|
break;
|
|
957
1040
|
|
|
@@ -960,6 +1043,8 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool)
|
|
|
960
1043
|
// Skip fallback errors from exit handler if we already handled the real one
|
|
961
1044
|
if (msg._fallback && worker._queryEnded) break;
|
|
962
1045
|
worker._queryEnded = true;
|
|
1046
|
+
abortAllPrompts();
|
|
1047
|
+
failPendingEfforts();
|
|
963
1048
|
var err = new Error(msg.error || "Worker query error");
|
|
964
1049
|
err.exitCode = msg.exitCode;
|
|
965
1050
|
err.stderr = msg.stderr;
|
|
@@ -1045,8 +1130,18 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool)
|
|
|
1045
1130
|
},
|
|
1046
1131
|
|
|
1047
1132
|
setEffort: function(effort) {
|
|
1048
|
-
|
|
1049
|
-
return Promise
|
|
1133
|
+
var requestId = crypto.randomUUID();
|
|
1134
|
+
return new Promise(function(resolve, reject) {
|
|
1135
|
+
var timer = setTimeout(function() {
|
|
1136
|
+
settleSetEffort(requestId, new Error("The Claude worker did not confirm the effort change"));
|
|
1137
|
+
}, SET_EFFORT_TIMEOUT_MS);
|
|
1138
|
+
pendingSetEffort[requestId] = { resolve: resolve, reject: reject, timer: timer };
|
|
1139
|
+
try {
|
|
1140
|
+
worker.send({ type: "set_effort", requestId: requestId, effort: effort });
|
|
1141
|
+
} catch (e) {
|
|
1142
|
+
settleSetEffort(requestId, e);
|
|
1143
|
+
}
|
|
1144
|
+
});
|
|
1050
1145
|
},
|
|
1051
1146
|
|
|
1052
1147
|
setToolPolicy: function(policy) {
|
|
@@ -1149,7 +1244,7 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool)
|
|
|
1149
1244
|
// vendor-reported list always wins outright when present (see
|
|
1150
1245
|
// enrichClaudeModel below) — this table exists purely to cover the case
|
|
1151
1246
|
// where the vendor reports no levels at all, not as the primary source.
|
|
1152
|
-
var CLAUDE_EFFORT_LEVELS =
|
|
1247
|
+
var CLAUDE_EFFORT_LEVELS = effortControl.EFFORT_LEVELS;
|
|
1153
1248
|
|
|
1154
1249
|
// Display name, thinking/effort capability heuristics, and family/version
|
|
1155
1250
|
// parsing all live in ../../model-families.js (lr-d91ecf) — the single
|
|
@@ -1556,6 +1651,12 @@ function createClaudeAdapter(opts) {
|
|
|
1556
1651
|
if (co.resumeSessionAt) sdkOptions.resumeSessionAt = co.resumeSessionAt;
|
|
1557
1652
|
if (co.settings) sdkOptions.settings = co.settings;
|
|
1558
1653
|
|
|
1654
|
+
// options.env REPLACES the subprocess environment, so a query with
|
|
1655
|
+
// Settings variables is handed the whole environment, not the additions.
|
|
1656
|
+
if (runtimeEnv.hasOverlay(queryOpts.runtimeEnv)) {
|
|
1657
|
+
sdkOptions.env = runtimeEnv.composeRuntimeEnv(process.env, queryOpts.runtimeEnv);
|
|
1658
|
+
}
|
|
1659
|
+
|
|
1559
1660
|
var rawQuery = sdk.query({ prompt: mq, options: sdkOptions });
|
|
1560
1661
|
return createQueryHandle(rawQuery, mq, ac);
|
|
1561
1662
|
},
|
|
@@ -1581,6 +1682,7 @@ function createClaudeAdapter(opts) {
|
|
|
1581
1682
|
}
|
|
1582
1683
|
},
|
|
1583
1684
|
abortController: ac,
|
|
1685
|
+
runtimeEnv: opts && opts.runtimeEnv,
|
|
1584
1686
|
});
|
|
1585
1687
|
console.log("[auto-title/claude] Query created, pushing message...");
|
|
1586
1688
|
handle.pushMessage(prompt);
|
|
@@ -1720,6 +1822,9 @@ function createClaudeAdapter(opts) {
|
|
|
1720
1822
|
if (claudeOpts.permissionMode) queryOptions.permissionMode = claudeOpts.permissionMode;
|
|
1721
1823
|
if (claudeOpts.allowDangerouslySkipPermissions) queryOptions.allowDangerouslySkipPermissions = true;
|
|
1722
1824
|
if (claudeOpts.settings) queryOptions.settings = claudeOpts.settings;
|
|
1825
|
+
// The worker lays these over its own environment (the OS user's), then
|
|
1826
|
+
// hands the SDK the complete result.
|
|
1827
|
+
if (runtimeEnv.hasOverlay(queryOpts.runtimeEnv)) queryOptions.runtimeEnv = queryOpts.runtimeEnv;
|
|
1723
1828
|
|
|
1724
1829
|
if (queryOpts.toolServerDescriptors) queryOptions.mcpServerDescriptors = queryOpts.toolServerDescriptors;
|
|
1725
1830
|
if (queryOpts.model) queryOptions.model = queryOpts.model;
|
|
@@ -1768,6 +1873,10 @@ function createClaudeAdapter(opts) {
|
|
|
1768
1873
|
warmupOptions.permissionMode = "bypassPermissions";
|
|
1769
1874
|
warmupOptions.allowDangerouslySkipPermissions = true;
|
|
1770
1875
|
}
|
|
1876
|
+
// The warmup starts the same CLI a query does, so it gets the same environment.
|
|
1877
|
+
if (initOpts && runtimeEnv.hasOverlay(initOpts.runtimeEnv)) {
|
|
1878
|
+
warmupOptions.env = runtimeEnv.composeRuntimeEnv(process.env, initOpts.runtimeEnv);
|
|
1879
|
+
}
|
|
1771
1880
|
|
|
1772
1881
|
var result = {
|
|
1773
1882
|
models: [],
|
|
@@ -1775,17 +1884,7 @@ function createClaudeAdapter(opts) {
|
|
|
1775
1884
|
skills: [],
|
|
1776
1885
|
slashCommands: [],
|
|
1777
1886
|
fastModeState: null,
|
|
1778
|
-
capabilities:
|
|
1779
|
-
thinking: true,
|
|
1780
|
-
betas: true,
|
|
1781
|
-
rewind: true,
|
|
1782
|
-
sessionResume: true,
|
|
1783
|
-
promptSuggestions: true,
|
|
1784
|
-
elicitation: true,
|
|
1785
|
-
fileCheckpointing: true,
|
|
1786
|
-
contextCompacting: true,
|
|
1787
|
-
toolPolicy: ["ask", "allow-all"],
|
|
1788
|
-
},
|
|
1887
|
+
capabilities: claudeCapabilities(),
|
|
1789
1888
|
};
|
|
1790
1889
|
|
|
1791
1890
|
try {
|
|
@@ -1849,6 +1948,7 @@ function createClaudeAdapter(opts) {
|
|
|
1849
1948
|
warmupOptions.permissionMode = "bypassPermissions";
|
|
1850
1949
|
warmupOptions.allowDangerouslySkipPermissions = true;
|
|
1851
1950
|
}
|
|
1951
|
+
if (initOpts && runtimeEnv.hasOverlay(initOpts.runtimeEnv)) warmupOptions.runtimeEnv = initOpts.runtimeEnv;
|
|
1852
1952
|
|
|
1853
1953
|
return new Promise(function(resolve, reject) {
|
|
1854
1954
|
var warmupDone = false;
|
|
@@ -1865,17 +1965,7 @@ function createClaudeAdapter(opts) {
|
|
|
1865
1965
|
skills: r.skills || [],
|
|
1866
1966
|
slashCommands: r.slashCommands || [],
|
|
1867
1967
|
fastModeState: r.fastModeState || null,
|
|
1868
|
-
capabilities:
|
|
1869
|
-
thinking: true,
|
|
1870
|
-
betas: true,
|
|
1871
|
-
rewind: true,
|
|
1872
|
-
sessionResume: true,
|
|
1873
|
-
promptSuggestions: true,
|
|
1874
|
-
elicitation: true,
|
|
1875
|
-
fileCheckpointing: true,
|
|
1876
|
-
contextCompacting: true,
|
|
1877
|
-
toolPolicy: ["ask", "allow-all"],
|
|
1878
|
-
},
|
|
1968
|
+
capabilities: claudeCapabilities(),
|
|
1879
1969
|
});
|
|
1880
1970
|
worker.kill();
|
|
1881
1971
|
} else if (msg.type === "warmup_error" && !warmupDone) {
|
|
@@ -1912,5 +2002,9 @@ module.exports = {
|
|
|
1912
2002
|
// alias untouched, not a substituted concrete ID.)
|
|
1913
2003
|
_test_mergeStaticCatalog: mergeStaticCatalog,
|
|
1914
2004
|
_test_enrichClaudeModelsWithCatalog: enrichClaudeModelsWithCatalog,
|
|
2005
|
+
// Test seams: drive the in-process query handle over a fake SDK Query and
|
|
2006
|
+
// the worker IPC relay over a fake worker.
|
|
2007
|
+
_test_createQueryHandle: createQueryHandle,
|
|
2008
|
+
_test_createWorkerQueryHandle: createWorkerQueryHandle,
|
|
1915
2009
|
};
|
|
1916
2010
|
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// What a Codex session can do: the declaration the Codex adapter registers and
|
|
4
|
+
// the capabilities its init advertises. Every key is one of the YOKE
|
|
5
|
+
// capability ledger (lib/yoke/interface.js). A Codex thread is resumed,
|
|
6
|
+
// forked and rolled back through the app-server; it has no thinking budget,
|
|
7
|
+
// file checkpoints, beta switches or subagents, and no permission modes beyond
|
|
8
|
+
// the approval policy Codex owns, so those are declared off and the UI shows
|
|
9
|
+
// them disabled.
|
|
10
|
+
|
|
11
|
+
function codexCapabilities() {
|
|
12
|
+
return {
|
|
13
|
+
thinking: false,
|
|
14
|
+
betas: false,
|
|
15
|
+
effort: true,
|
|
16
|
+
rewind: false,
|
|
17
|
+
fork: true,
|
|
18
|
+
rollback: true,
|
|
19
|
+
sessionResume: true,
|
|
20
|
+
sessionList: false,
|
|
21
|
+
sessionRename: false,
|
|
22
|
+
sessionArchive: false,
|
|
23
|
+
promptSuggestions: true,
|
|
24
|
+
elicitation: true,
|
|
25
|
+
fileCheckpointing: false,
|
|
26
|
+
contextCompacting: false,
|
|
27
|
+
mcpPanel: true,
|
|
28
|
+
backgroundTasks: false,
|
|
29
|
+
steering: false,
|
|
30
|
+
agentInjection: false,
|
|
31
|
+
executionPolicy: true,
|
|
32
|
+
toolPolicy: ["ask", "allow-all"],
|
|
33
|
+
permissionModes: [],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = { codexCapabilities: codexCapabilities };
|