@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.
- package/LICENSE +117 -12
- package/LICENSES/MIT-legacy.txt +22 -0
- package/LICENSES/README.md +15 -0
- package/README.md +9 -3
- package/bin/cli.js +40 -5
- package/deploy/clagentic-console.service +10 -6
- package/lib/agent-dispatch-tool.js +20 -0
- package/lib/audit.js +3 -2
- package/lib/build-changes.js +79 -0
- package/lib/build-identity.js +192 -0
- package/lib/build-monitor.js +125 -0
- package/lib/build-sha.json +2 -2
- package/lib/build-update-check.js +138 -0
- package/lib/build-update-offer.js +141 -0
- package/lib/build-update-restart.js +142 -0
- package/lib/build-update-standing.js +184 -0
- package/lib/cli/daemon-launch.js +25 -22
- package/lib/cli/ipc-subcommands.js +6 -0
- package/lib/cli/session-subcommands.js +122 -0
- package/lib/cli-sessions.js +8 -1
- package/lib/codex-defaults.js +8 -2
- package/lib/config.js +32 -20
- package/lib/daemon-env-settings.js +84 -0
- package/lib/daemon-projects.js +57 -0
- package/lib/daemon.js +288 -205
- 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/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/memory-shed.js +13 -32
- 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 +37 -22
- package/lib/project-external-trigger.js +166 -105
- 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 +17 -9
- 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 +217 -0
- package/lib/project-sessions.js +192 -355
- package/lib/project-user-message.js +27 -15
- package/lib/project.js +212 -147
- 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 +680 -0
- package/lib/public/app.js +1 -1
- package/lib/public/css/diagnostics.css +80 -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/agent-dispatch-tool.js +9 -0
- 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 +52 -47
- package/lib/public/modules/app-notifications.js +47 -71
- package/lib/public/modules/app-panels.js +61 -59
- package/lib/public/modules/app-projects.js +2 -1
- package/lib/public/modules/app-rendering.js +4 -10
- package/lib/public/modules/build-update-detail.js +54 -0
- package/lib/public/modules/diagnostics.js +170 -20
- 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 +81 -906
- package/lib/public/modules/vendor-picker.js +53 -0
- package/lib/public/modules/vendor-registry.js +142 -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 +348 -284
- package/lib/sdk-message-processor.js +117 -146
- package/lib/sdk-skill-discovery.js +65 -60
- package/lib/server-hub-sessions.js +13 -10
- package/lib/server-palette.js +28 -19
- package/lib/server.js +156 -115
- package/lib/service-install.js +96 -0
- package/lib/session-capabilities.js +76 -0
- package/lib/session-id.js +33 -0
- package/lib/session-input-ipc.js +32 -0
- package/lib/session-input.js +379 -0
- package/lib/session-reclaim.js +284 -0
- package/lib/session-resume.js +172 -0
- package/lib/sessions.js +61 -30
- package/lib/supervisor.js +39 -0
- package/lib/turn-initiator.js +108 -0
- 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 +66 -0
- package/lib/ws-origin.js +99 -0
- package/lib/ws-schema.js +36 -23
- package/lib/yoke/adapters/claude-capabilities.js +38 -0
- package/lib/yoke/adapters/claude-vendor.js +34 -0
- package/lib/yoke/adapters/claude-worker.js +57 -87
- package/lib/yoke/adapters/claude.js +182 -88
- package/lib/yoke/adapters/codex-capabilities.js +40 -0
- package/lib/yoke/adapters/codex-vendor.js +46 -0
- package/lib/yoke/adapters/codex.js +462 -211
- 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 +91 -0
- package/lib/yoke/capabilities.js +49 -0
- package/lib/yoke/codex-app-server.js +30 -56
- package/lib/yoke/codex-binary.js +254 -0
- package/lib/yoke/codex-command.js +122 -0
- package/lib/yoke/codex-protocol.js +96 -0
- package/lib/yoke/codex-version.js +135 -0
- package/lib/yoke/env-ownership.js +40 -0
- package/lib/yoke/index.js +84 -174
- package/lib/yoke/install-probe.js +136 -0
- package/lib/yoke/instructions.js +7 -11
- package/lib/yoke/interface.js +206 -4
- package/lib/yoke/package.json +1 -1
- package/lib/yoke/provider-credentials.js +96 -0
- package/lib/yoke/registry.js +377 -0
- package/package.json +12 -9
- 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-build.js +59 -17
- package/scripts/verify-installed.js +67 -0
- package/lib/sdk-permission-ownership.js +0 -136
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
var usersModule = require("./users");
|
|
2
2
|
var { discoverWorkflows } = require("./sdk-workflow-discovery");
|
|
3
3
|
var { buildEnrichedSlashCommands } = require("./sdk-slash-enrichment");
|
|
4
|
-
var {
|
|
4
|
+
var { promptsFor } = require("./prompt-registry");
|
|
5
5
|
var sessionActivity = require("./session-activity");
|
|
6
|
+
var yokeRegistry = require("./yoke").registry;
|
|
7
|
+
var { authRequiredFacts } = require("./vendor-auth");
|
|
8
|
+
var sessionReclaim = require("./session-reclaim");
|
|
9
|
+
var { isAgentDispatchTool } = require("./agent-dispatch-tool");
|
|
10
|
+
|
|
11
|
+
// Source names of the activity tokens an agent with the activityTokens
|
|
12
|
+
// trait holds for its own tool and thinking blocks.
|
|
13
|
+
var TOOL_ACTIVITY_SOURCE = "agent-tool";
|
|
14
|
+
var THINKING_ACTIVITY_SOURCE = "agent-thinking";
|
|
15
|
+
|
|
16
|
+
// How the console drives the session's agent (an adapter trait, not a
|
|
17
|
+
// capability: nothing a session or connection negotiates). A vendor that is not
|
|
18
|
+
// registered has no traits.
|
|
19
|
+
function sessionHasTrait(session, trait) {
|
|
20
|
+
return yokeRegistry.traitOf(session.vendor, trait);
|
|
21
|
+
}
|
|
6
22
|
|
|
7
23
|
function attachMessageProcessor(ctx) {
|
|
8
24
|
var sm = ctx.sm;
|
|
@@ -35,6 +51,21 @@ function attachMessageProcessor(ctx) {
|
|
|
35
51
|
sm.sendAndRecord(session, obj);
|
|
36
52
|
}
|
|
37
53
|
|
|
54
|
+
// session.taskIdMap is keyed by the Task's tool-use id (the parentToolId
|
|
55
|
+
// task_started carries) and holds the SDK's task id; the registry tracks
|
|
56
|
+
// Tasks by that same tool-use id. At a turn boundary the mapping is kept
|
|
57
|
+
// for every Task the registry still tracks, so a still-running sub-agent's
|
|
58
|
+
// later task_updated and task_notification correlate; Task liveness itself
|
|
59
|
+
// is the registry's.
|
|
60
|
+
function retainTaskIdMap(session) {
|
|
61
|
+
var tracked = promptsFor(sm).trackedTaskIds(session);
|
|
62
|
+
var next = {};
|
|
63
|
+
for (var parentToolId in (session.taskIdMap || {})) {
|
|
64
|
+
if (tracked[parentToolId]) next[parentToolId] = session.taskIdMap[parentToolId];
|
|
65
|
+
}
|
|
66
|
+
session.taskIdMap = next;
|
|
67
|
+
}
|
|
68
|
+
|
|
38
69
|
function sendToSession(session, obj) {
|
|
39
70
|
sm.sendToSession(session, obj);
|
|
40
71
|
}
|
|
@@ -61,33 +92,33 @@ function attachMessageProcessor(ctx) {
|
|
|
61
92
|
return result;
|
|
62
93
|
}
|
|
63
94
|
|
|
64
|
-
//
|
|
95
|
+
// Activity-token parity wiring for an agent with the activityTokens
|
|
96
|
+
// trait (Codex, lib/yoke/adapters/codex.js). Such an agent has no
|
|
65
97
|
// subagent concept -- ordinary tool_start/thinking_start there are NOT a
|
|
66
98
|
// backgrounded Task the way Claude's Task tool is, so this does not (and
|
|
67
|
-
// must not) fabricate a Task lifecycle. What it DOES need:
|
|
99
|
+
// must not) fabricate a Task lifecycle. What it DOES need: its
|
|
68
100
|
// tool_start/thinking_start/tool_result/result already ride through this
|
|
69
|
-
// same shared processor, but unlike Claude,
|
|
101
|
+
// same shared processor, but unlike Claude, it has no equivalent of the
|
|
70
102
|
// turn-wide isProcessing=true covering ordinary tool activity implicitly --
|
|
71
|
-
// acquiring an explicit token here is how
|
|
72
|
-
// the derived isProcessing/picker-dot path at all. Gated on
|
|
73
|
-
//
|
|
74
|
-
//
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
// tokens.
|
|
103
|
+
// acquiring an explicit token here is how its activity becomes visible to
|
|
104
|
+
// the derived isProcessing/picker-dot path at all. Gated on the capability
|
|
105
|
+
// so this stays independent of Claude's own widened acquisition below
|
|
106
|
+
// (block_stop) -- the two kinds of agent acquire tokens through different
|
|
107
|
+
// yokeType branches (tool_start here vs. block_stop for Claude) and neither
|
|
108
|
+
// path double-acquires the other's tokens.
|
|
78
109
|
//
|
|
79
110
|
// Release happens on tool_result (per-token, matching Claude's tool_result
|
|
80
111
|
// release) OR at the turn's result event, which releases EVERY still-live
|
|
81
|
-
//
|
|
82
|
-
// thinking block (which
|
|
83
|
-
// event that this shared processor does not otherwise
|
|
84
|
-
// left acquired past the end of its own turn. This
|
|
85
|
-
// task_notification acting as a second, idempotent drain
|
|
86
|
-
// that tool_result might not otherwise catch.
|
|
87
|
-
function
|
|
112
|
+
// token of these sources for this session at once -- a catch-all so a
|
|
113
|
+
// thinking block (which such an agent ends via its own top-level
|
|
114
|
+
// thinking_stop event that this shared processor does not otherwise
|
|
115
|
+
// dispatch) is never left acquired past the end of its own turn. This
|
|
116
|
+
// mirrors Claude's task_notification acting as a second, idempotent drain
|
|
117
|
+
// path for a token that tool_result might not otherwise catch.
|
|
118
|
+
function releaseAllAgentActivity(session) {
|
|
88
119
|
var sources = sessionActivity.listActiveSources(session);
|
|
89
120
|
for (var i = 0; i < sources.length; i++) {
|
|
90
|
-
if (sources[i].source ===
|
|
121
|
+
if (sources[i].source === TOOL_ACTIVITY_SOURCE || sources[i].source === THINKING_ACTIVITY_SOURCE) {
|
|
91
122
|
releaseActivity(session, sources[i].token);
|
|
92
123
|
}
|
|
93
124
|
}
|
|
@@ -125,7 +156,7 @@ function attachMessageProcessor(ctx) {
|
|
|
125
156
|
if (name === "Glob" && input && input.pattern) return "Finding " + input.pattern;
|
|
126
157
|
if (name === "WebSearch" && input && input.query) return "Searching: " + input.query;
|
|
127
158
|
if (name === "WebFetch") return "Fetching URL...";
|
|
128
|
-
if (name
|
|
159
|
+
if (isAgentDispatchTool(name) && input && input.description) return input.description;
|
|
129
160
|
return "Running " + name + "...";
|
|
130
161
|
}
|
|
131
162
|
|
|
@@ -174,12 +205,9 @@ function attachMessageProcessor(ctx) {
|
|
|
174
205
|
for (var i = 0; i < content.length; i++) {
|
|
175
206
|
var block = content[i];
|
|
176
207
|
if (block.type === "tool_use") {
|
|
177
|
-
//
|
|
178
|
-
//
|
|
179
|
-
|
|
180
|
-
// before it wipes the map (see sdk-message-processor.js result branch).
|
|
181
|
-
if (!session.subagentToolOwners) session.subagentToolOwners = {};
|
|
182
|
-
session.subagentToolOwners[block.id] = parentId;
|
|
208
|
+
// Ownership decides the scope of any prompt this tool raises: a
|
|
209
|
+
// sub-agent's prompt outlives the parent's turn and query.
|
|
210
|
+
promptsFor(sm).noteSubagentTool(session, block.id, parentId);
|
|
183
211
|
var activityText = toolActivityTextForSubagent(block.name, block.input);
|
|
184
212
|
sendAndRecord(session, {
|
|
185
213
|
type: "subagent_tool",
|
|
@@ -292,7 +320,6 @@ function attachMessageProcessor(ctx) {
|
|
|
292
320
|
models: getModelsForVendor(initVendor),
|
|
293
321
|
vendor: initVendor,
|
|
294
322
|
availableVendors: sm.availableVendors || [],
|
|
295
|
-
installedVendors: sm.installedVendors || [],
|
|
296
323
|
});
|
|
297
324
|
}
|
|
298
325
|
if (parsed.fastModeState) {
|
|
@@ -311,19 +338,19 @@ function attachMessageProcessor(ctx) {
|
|
|
311
338
|
if (parsed.yokeType === "tool_start") {
|
|
312
339
|
session.blocks[idx] = { type: "tool_use", id: parsed.toolId, name: parsed.toolName, inputJson: "" };
|
|
313
340
|
sendAndRecord(session, { type: "tool_start", id: parsed.toolId, name: parsed.toolName });
|
|
314
|
-
//
|
|
315
|
-
//
|
|
316
|
-
if (session
|
|
317
|
-
acquireActivity(session, parsed.toolId, { source:
|
|
341
|
+
// See releaseAllAgentActivity above for why this is gated on the
|
|
342
|
+
// activityTokens trait and not applied to Claude.
|
|
343
|
+
if (sessionHasTrait(session, "activityTokens") && parsed.toolId) {
|
|
344
|
+
acquireActivity(session, parsed.toolId, { source: TOOL_ACTIVITY_SOURCE, label: parsed.toolName || "" });
|
|
318
345
|
}
|
|
319
346
|
} else if (parsed.yokeType === "thinking_start") {
|
|
320
347
|
session.blocks[idx] = { type: "thinking", thinkingText: "", startTime: Date.now() };
|
|
321
348
|
sendAndRecord(session, { type: "thinking_start" });
|
|
322
|
-
//
|
|
323
|
-
//
|
|
324
|
-
//
|
|
325
|
-
if (session
|
|
326
|
-
acquireActivity(session, "thinking_" + idx, { source:
|
|
349
|
+
// Token id keyed on blockId (Codex's "blk_N" counter, see
|
|
350
|
+
// lib/yoke/adapters/codex.js flattenEvent) since a thinking_start
|
|
351
|
+
// event carries no separate tool-style id.
|
|
352
|
+
if (sessionHasTrait(session, "activityTokens")) {
|
|
353
|
+
acquireActivity(session, "thinking_" + idx, { source: THINKING_ACTIVITY_SOURCE, label: "" });
|
|
327
354
|
}
|
|
328
355
|
} else if (parsed.yokeType === "text_start") {
|
|
329
356
|
session.blocks[idx] = { type: "text" };
|
|
@@ -379,11 +406,11 @@ function attachMessageProcessor(ctx) {
|
|
|
379
406
|
is_error: !!parsed.isError,
|
|
380
407
|
});
|
|
381
408
|
|
|
382
|
-
//
|
|
383
|
-
//
|
|
384
|
-
//
|
|
385
|
-
//
|
|
386
|
-
if (session
|
|
409
|
+
// Release the token acquired at tool_start for this same toolId.
|
|
410
|
+
// releaseActivity is idempotent (see session-activity.js), so this is
|
|
411
|
+
// always safe even if the token was already released elsewhere (e.g. by
|
|
412
|
+
// the result-time catch-all below).
|
|
413
|
+
if (sessionHasTrait(session, "activityTokens") && parsed.toolId) {
|
|
387
414
|
releaseActivity(session, parsed.toolId);
|
|
388
415
|
}
|
|
389
416
|
|
|
@@ -460,10 +487,12 @@ function attachMessageProcessor(ctx) {
|
|
|
460
487
|
// (releaseActivity is idempotent either way).
|
|
461
488
|
acquireActivity(session, block.id, { source: "tool", label: input.description || block.name || "" });
|
|
462
489
|
|
|
463
|
-
// Track active Task tools
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
session
|
|
490
|
+
// Track active Task tools (activeTaskToolIds, written by the prompt
|
|
491
|
+
// registry) for sub-agent done detection and prompt ownership.
|
|
492
|
+
if (isAgentDispatchTool(block.name)) {
|
|
493
|
+
promptsFor(sm).taskStarted(session, block.id);
|
|
494
|
+
// Names the agent in any notice about it (reap, shed, its prompts).
|
|
495
|
+
sessionReclaim.noteTaskLabel(session, block.id, input);
|
|
467
496
|
}
|
|
468
497
|
|
|
469
498
|
if (pushModule && block.name === "AskUserQuestion" && input.questions) {
|
|
@@ -533,14 +562,16 @@ function attachMessageProcessor(ctx) {
|
|
|
533
562
|
for (var i = 0; i < content.length; i++) {
|
|
534
563
|
var block = content[i];
|
|
535
564
|
if (block.type === "tool_result" && !session.sentToolResults[block.tool_use_id]) {
|
|
536
|
-
//
|
|
537
|
-
|
|
565
|
+
// A tracked Task's result means its sub-agent is done.
|
|
566
|
+
var resultPrompts = promptsFor(sm);
|
|
567
|
+
if (resultPrompts.isTaskTracked(session, block.tool_use_id)) {
|
|
538
568
|
sendAndRecord(session, {
|
|
539
569
|
type: "subagent_done",
|
|
540
570
|
parentToolId: block.tool_use_id,
|
|
541
571
|
});
|
|
542
|
-
delete session.activeTaskToolIds[block.tool_use_id];
|
|
543
572
|
}
|
|
573
|
+
resultPrompts.taskEnded(session, block.tool_use_id);
|
|
574
|
+
sessionReclaim.pruneTaskLabels(session);
|
|
544
575
|
// lr-9bcd7b (widened lr-6e20f7): release the activity token
|
|
545
576
|
// acquired at block_stop for this tool id, unconditionally --
|
|
546
577
|
// NOT gated on activeTaskToolIds still containing the entry.
|
|
@@ -548,13 +579,10 @@ function attachMessageProcessor(ctx) {
|
|
|
548
579
|
// beyond Task), not only backgrounded Task tools -- the
|
|
549
580
|
// Task-specific bookkeeping above (activeTaskToolIds,
|
|
550
581
|
// subagent_done) is unrelated to this release and unaffected by
|
|
551
|
-
// the widening.
|
|
552
|
-
//
|
|
553
|
-
// activeTaskToolIds
|
|
554
|
-
//
|
|
555
|
-
// of its own has its activeTaskToolIds entry deleted before this
|
|
556
|
-
// tool_result ever arrives -- gating the release on that same map
|
|
557
|
-
// would silently skip it and leak the token forever. releaseToken
|
|
582
|
+
// the widening. A Task's tracking can end before this tool_result
|
|
583
|
+
// arrives (task_notification first), so gating the release on
|
|
584
|
+
// activeTaskToolIds would silently skip it and leak the token
|
|
585
|
+
// forever. releaseToken
|
|
558
586
|
// is idempotent (no-op if this id was never acquired, or already
|
|
559
587
|
// released by task_notification), so calling it unconditionally
|
|
560
588
|
// for every tool_result is always safe.
|
|
@@ -594,62 +622,20 @@ function attachMessageProcessor(ctx) {
|
|
|
594
622
|
} else if (parsed.yokeType === "result") {
|
|
595
623
|
session.blocks = {};
|
|
596
624
|
session.sentToolResults = {};
|
|
597
|
-
//
|
|
598
|
-
//
|
|
599
|
-
//
|
|
600
|
-
//
|
|
601
|
-
//
|
|
602
|
-
// task_notification-equivalent second drain path the way Claude does,
|
|
603
|
-
//
|
|
604
|
-
//
|
|
605
|
-
//
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
//
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
// request is still awaiting the operator's click; that resolver lives in
|
|
612
|
-
// this same session.pendingPermissions map (keyed by requestId) but is
|
|
613
|
-
// unrelated to the parent turn that just ended. Wiping it unconditionally
|
|
614
|
-
// orphans the resolver — the permission card stays on the UI, but the
|
|
615
|
-
// operator's later permission_response finds nothing to resolve and the
|
|
616
|
-
// sub-agent's canUseTool Promise hangs forever (lr-9d4b root cause).
|
|
617
|
-
// Shared with sdk-bridge.js's processQueryStream finally block, which
|
|
618
|
-
// performs the same reset on normal (non-superseded) turn completion —
|
|
619
|
-
// see lib/sdk-permission-ownership.js for the single source of truth.
|
|
620
|
-
// This MUST run before activeTaskToolIds/taskIdMap are reset below, since
|
|
621
|
-
// that is the ownership information this decision depends on. Mirrors the
|
|
622
|
-
// _keepAskUser preservation pattern for pendingAskUser directly below.
|
|
623
|
-
var _perm9d4b = partitionSubagentOwnedPermissions(session);
|
|
624
|
-
// lr-f940 (N3): sweep sm.permissionRequestIndex for every entry this
|
|
625
|
-
// pass is about to drop — see sdk-permission-ownership.js for why this
|
|
626
|
-
// mirrors the same sweep in sdk-bridge.js's processQueryStream finally.
|
|
627
|
-
sweepClearedPermissionIndex(sm, session.pendingPermissions, _perm9d4b.keptPermissions);
|
|
628
|
-
session.pendingPermissions = _perm9d4b.keptPermissions;
|
|
629
|
-
session.pendingElicitations = {};
|
|
630
|
-
// Record ask_user_answered for any leftover pending questions so replay pairs correctly.
|
|
631
|
-
// EXCEPTION: "mcp" mode entries are stateless — the tool returned immediately and the
|
|
632
|
-
// turn is expected to end while the card is still awaiting the user's answer. Those
|
|
633
|
-
// entries must survive across turns so the eventual ask_user_response can inject the
|
|
634
|
-
// answer as the next user message. Only blocking modes (Claude canUseTool) get closed.
|
|
635
|
-
var leftoverAskIds = Object.keys(session.pendingAskUser);
|
|
636
|
-
var keptAskUser = {};
|
|
637
|
-
for (var lai = 0; lai < leftoverAskIds.length; lai++) {
|
|
638
|
-
var lid = leftoverAskIds[lai];
|
|
639
|
-
var lentry = session.pendingAskUser[lid];
|
|
640
|
-
if (lentry && lentry.mode === "mcp") {
|
|
641
|
-
keptAskUser[lid] = lentry;
|
|
642
|
-
continue;
|
|
643
|
-
}
|
|
644
|
-
sendAndRecord(session, { type: "ask_user_answered", toolId: lid });
|
|
645
|
-
}
|
|
646
|
-
session.pendingAskUser = keptAskUser;
|
|
647
|
-
// Only clear activeTaskToolIds/taskIdMap entries for Task ids we did NOT
|
|
648
|
-
// just preserve a permission for above — a still-active backgrounded
|
|
649
|
-
// sub-agent's bookkeeping must survive alongside its pending permission,
|
|
650
|
-
// otherwise a second permission from the same sub-agent (or subagent_done
|
|
651
|
-
// delivery) has nothing to correlate against.
|
|
652
|
-
retainPreservedTaskBookkeeping(session, _perm9d4b.preservedTaskIds);
|
|
625
|
+
// Catch-all -- release EVERY still-live token of an activityTokens agent
|
|
626
|
+
// for this session now, regardless of whether its own
|
|
627
|
+
// tool_result/thinking_stop already fired. This runs first, before the
|
|
628
|
+
// error_during_execution early return below, so a turn that ends in an
|
|
629
|
+
// SDK execution error still drains its tokens (such an agent has no
|
|
630
|
+
// task_notification-equivalent second drain path the way Claude does, so
|
|
631
|
+
// this is the ONLY backstop short of the next startQuery's generation
|
|
632
|
+
// bump, which already covers the harder case of abort/interrupt ending
|
|
633
|
+
// the stream before 'result' is ever reached at all).
|
|
634
|
+
if (sessionHasTrait(session, "activityTokens")) releaseAllAgentActivity(session);
|
|
635
|
+
// Turn boundary: the turn's own prompts, of every kind, end here; a
|
|
636
|
+
// tracked sub-agent keeps its own (the registry decides which).
|
|
637
|
+
promptsFor(sm).endTurn(session);
|
|
638
|
+
retainTaskIdMap(session);
|
|
653
639
|
// Only clear rateLimitResetsAt on genuine success (non-zero cost).
|
|
654
640
|
// When rate-limited, the SDK sends result with zero cost right after
|
|
655
641
|
// rate_limit_event; clearing here would prevent auto-continue scheduling.
|
|
@@ -712,15 +698,15 @@ function attachMessageProcessor(ctx) {
|
|
|
712
698
|
var authLinuxUser = authUser && authUser.linuxUser ? authUser.linuxUser : null;
|
|
713
699
|
var canAutoLogin = !!authLinuxUser
|
|
714
700
|
|| (authUser && authUser.role === "admin");
|
|
715
|
-
var
|
|
716
|
-
var
|
|
717
|
-
|
|
718
|
-
|
|
701
|
+
var loginVendor = [session.vendor, adapter && adapter.vendor].filter(yokeRegistry.isKnown)[0] || yokeRegistry.ids()[0];
|
|
702
|
+
var authFacts = authRequiredFacts(loginVendor);
|
|
703
|
+
var authTitle = authFacts.title;
|
|
704
|
+
var loginCommand = authFacts.loginCommand;
|
|
719
705
|
var _nmLogin = getNotificationsModule();
|
|
720
706
|
var authMsg = {
|
|
721
707
|
type: "auth_required",
|
|
722
708
|
text: authTitle,
|
|
723
|
-
vendor:
|
|
709
|
+
vendor: authFacts.vendor,
|
|
724
710
|
loginCommand: loginCommand,
|
|
725
711
|
linuxUser: authLinuxUser,
|
|
726
712
|
canAutoLogin: canAutoLogin,
|
|
@@ -733,7 +719,7 @@ function attachMessageProcessor(ctx) {
|
|
|
733
719
|
slug: slug,
|
|
734
720
|
sessionId: session.localId,
|
|
735
721
|
ownerId: session.ownerId || null,
|
|
736
|
-
vendor:
|
|
722
|
+
vendor: authFacts.vendor,
|
|
737
723
|
loginCommand: loginCommand,
|
|
738
724
|
linuxUser: authLinuxUser,
|
|
739
725
|
canAutoLogin: canAutoLogin,
|
|
@@ -932,6 +918,8 @@ function attachMessageProcessor(ctx) {
|
|
|
932
918
|
|
|
933
919
|
} else if (parsed.yokeType === "task_notification") {
|
|
934
920
|
var parentId = parsed.parentToolId;
|
|
921
|
+
var notifiedPrompts = promptsFor(sm);
|
|
922
|
+
var parentOwnsLivePrompt = !!parentId && notifiedPrompts.taskOwnsPending(session, parentId);
|
|
935
923
|
if (parentId) {
|
|
936
924
|
sendAndRecord(session, {
|
|
937
925
|
type: "subagent_done",
|
|
@@ -945,8 +933,11 @@ function attachMessageProcessor(ctx) {
|
|
|
945
933
|
// delivered task_notification without a corresponding tool_result
|
|
946
934
|
// block, or delivered it first). releaseActivity is idempotent —
|
|
947
935
|
// if tool_result already released this same token, this is a no-op.
|
|
948
|
-
|
|
949
|
-
|
|
936
|
+
//
|
|
937
|
+
// EXCEPTION: keep the Task's activity while its sub-agent's own
|
|
938
|
+
// prompt is still awaiting the operator; the prompt keeps the Task
|
|
939
|
+
// in scope (see taskEnded below).
|
|
940
|
+
if (!parentOwnsLivePrompt) releaseActivity(session, parentId);
|
|
950
941
|
}
|
|
951
942
|
if (session.taskIdMap) {
|
|
952
943
|
for (var k in session.taskIdMap) {
|
|
@@ -956,33 +947,12 @@ function attachMessageProcessor(ctx) {
|
|
|
956
947
|
}
|
|
957
948
|
}
|
|
958
949
|
}
|
|
959
|
-
//
|
|
960
|
-
//
|
|
961
|
-
//
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
// arrive in the brief window right after. Pruning ownership here would
|
|
966
|
-
// make that entry look like an orphaned top-level permission to the
|
|
967
|
-
// 'result' handler / processQueryStream finally block, which would
|
|
968
|
-
// then clear it and re-orphan the resolver — the same hang via a
|
|
969
|
-
// different timing path. Defer cleanup for those tool ids until the
|
|
970
|
-
// permission itself is resolved (project-sessions.js's permission_response
|
|
971
|
-
// handler deletes the pendingPermissions entry; the ownership record is
|
|
972
|
-
// harmless to leave a little longer since it is keyed by tool-use id,
|
|
973
|
-
// not by Task, and simply becomes inert once no pendingPermissions
|
|
974
|
-
// entry references it).
|
|
975
|
-
if (parentId && session.subagentToolOwners) {
|
|
976
|
-
var liveOwnedToolIds = {};
|
|
977
|
-
for (var lpk in (session.pendingPermissions || {})) {
|
|
978
|
-
var lpEntry = session.pendingPermissions[lpk];
|
|
979
|
-
if (lpEntry && lpEntry.toolUseId) liveOwnedToolIds[lpEntry.toolUseId] = true;
|
|
980
|
-
}
|
|
981
|
-
for (var stk in session.subagentToolOwners) {
|
|
982
|
-
if (session.subagentToolOwners[stk] === parentId && !liveOwnedToolIds[stk]) {
|
|
983
|
-
delete session.subagentToolOwners[stk];
|
|
984
|
-
}
|
|
985
|
-
}
|
|
950
|
+
// The sub-agent is done. Its tracking and ownership records are
|
|
951
|
+
// released, except for a prompt still awaiting the operator, which
|
|
952
|
+
// keeps the Task in scope until it settles.
|
|
953
|
+
if (parentId) {
|
|
954
|
+
notifiedPrompts.taskEnded(session, parentId);
|
|
955
|
+
sessionReclaim.pruneTaskLabels(session);
|
|
986
956
|
}
|
|
987
957
|
|
|
988
958
|
} else if (parsed.yokeType === "rate_limit") {
|
|
@@ -1108,6 +1078,7 @@ function attachMessageProcessor(ctx) {
|
|
|
1108
1078
|
sendToSession: sendToSession,
|
|
1109
1079
|
processSubagentMessage: processSubagentMessage,
|
|
1110
1080
|
toolActivityTextForSubagent: toolActivityTextForSubagent,
|
|
1081
|
+
retainTaskIdMap: retainTaskIdMap,
|
|
1111
1082
|
};
|
|
1112
1083
|
}
|
|
1113
1084
|
|
|
@@ -203,6 +203,66 @@ function extractDescriptionFromContent(content) {
|
|
|
203
203
|
return "";
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
+
// Where skills live, lowest precedence first: each agent reads its own native
|
|
207
|
+
// location (Claude .claude/skills, Codex .agents/skills), and the console
|
|
208
|
+
// presents one list from all of them. A project's skill beats the user's of the
|
|
209
|
+
// same name, and within a level the directory of the agent the list is for beats
|
|
210
|
+
// the other's: .claude by default, .agents when preferAgentsDir is set (the list
|
|
211
|
+
// for a session of the agent that reads .agents/skills natively).
|
|
212
|
+
function skillRoots(cwd, globalHome, preferAgentsDir) {
|
|
213
|
+
var first = preferAgentsDir ? ".claude" : ".agents";
|
|
214
|
+
var second = preferAgentsDir ? ".agents" : ".claude";
|
|
215
|
+
var roots = [];
|
|
216
|
+
if (globalHome) {
|
|
217
|
+
roots.push(path.join(globalHome, first, "skills"));
|
|
218
|
+
roots.push(path.join(globalHome, second, "skills"));
|
|
219
|
+
}
|
|
220
|
+
if (cwd) {
|
|
221
|
+
roots.push(path.join(cwd, first, "skills"));
|
|
222
|
+
roots.push(path.join(cwd, second, "skills"));
|
|
223
|
+
}
|
|
224
|
+
return roots;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// A directory or file that is simply not there is the ordinary case (a user
|
|
228
|
+
// without a .agents directory) and stays quiet. Anything else (permissions, an
|
|
229
|
+
// I/O fault) hides skills the user has, so it is named in the log.
|
|
230
|
+
function warnUnlessAbsent(what, target, err) {
|
|
231
|
+
if (err && (err.code === "ENOENT" || err.code === "ENOTDIR")) return;
|
|
232
|
+
console.warn("[skills] could not read " + what + " " + target + ": " + (err && err.code ? err.code : (err && err.message) || err));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// name -> the skill's real directory, for every skill in every root. A name
|
|
236
|
+
// from a directory listing never indexes an ordinary object.
|
|
237
|
+
function collectSkillDirs(cwd, globalHome, preferAgentsDir) {
|
|
238
|
+
var byName = Object.create(null);
|
|
239
|
+
var roots = skillRoots(cwd, globalHome, preferAgentsDir);
|
|
240
|
+
for (var d = 0; d < roots.length; d++) {
|
|
241
|
+
var base = roots[d];
|
|
242
|
+
var entries;
|
|
243
|
+
try {
|
|
244
|
+
entries = fs.readdirSync(base, { withFileTypes: true });
|
|
245
|
+
} catch (e) {
|
|
246
|
+
warnUnlessAbsent("skills directory", base, e);
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
for (var i = 0; i < entries.length; i++) {
|
|
250
|
+
var entry = entries[i];
|
|
251
|
+
if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
|
|
252
|
+
var skillDir = resolveContainedSkillDir(base, entry.name);
|
|
253
|
+
if (!skillDir) continue;
|
|
254
|
+
var skillMd = path.join(skillDir, "SKILL.md");
|
|
255
|
+
try {
|
|
256
|
+
fs.accessSync(skillMd, fs.constants.R_OK);
|
|
257
|
+
byName[entry.name] = skillDir;
|
|
258
|
+
} catch (e) {
|
|
259
|
+
warnUnlessAbsent("skill file", skillMd, e);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return byName;
|
|
264
|
+
}
|
|
265
|
+
|
|
206
266
|
// Read SKILL.md for a skill directory and extract a short description string.
|
|
207
267
|
// Delegates to extractDescriptionFromContent for the actual parsing logic.
|
|
208
268
|
function extractSkillDescription(skillDir) {
|
|
@@ -226,36 +286,8 @@ function extractSkillDescription(skillDir) {
|
|
|
226
286
|
// it here so the global skills dir is the invoking user's own ~/.claude/skills,
|
|
227
287
|
// not the daemon process's REAL_HOME (lr-3ccc78). Falls back to REAL_HOME when
|
|
228
288
|
// absent — the single-user / no-OS-isolation case, unchanged behavior.
|
|
229
|
-
function discoverSkillsWithMeta(cwd, homeOverride) {
|
|
230
|
-
var
|
|
231
|
-
var dirs = [
|
|
232
|
-
path.join(globalHome, ".claude", "skills"),
|
|
233
|
-
path.join(cwd, ".claude", "skills"),
|
|
234
|
-
];
|
|
235
|
-
// Ordered map so project skills override global skills
|
|
236
|
-
var byName = {};
|
|
237
|
-
for (var d = 0; d < dirs.length; d++) {
|
|
238
|
-
var base = dirs[d];
|
|
239
|
-
var entries;
|
|
240
|
-
try {
|
|
241
|
-
entries = fs.readdirSync(base, { withFileTypes: true });
|
|
242
|
-
} catch (e) {
|
|
243
|
-
continue;
|
|
244
|
-
}
|
|
245
|
-
for (var i = 0; i < entries.length; i++) {
|
|
246
|
-
var entry = entries[i];
|
|
247
|
-
if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
|
|
248
|
-
var skillDir = resolveContainedSkillDir(base, entry.name);
|
|
249
|
-
if (!skillDir) continue;
|
|
250
|
-
var skillMdPath = path.join(skillDir, "SKILL.md");
|
|
251
|
-
try {
|
|
252
|
-
fs.accessSync(skillMdPath, fs.constants.R_OK);
|
|
253
|
-
byName[entry.name] = skillDir;
|
|
254
|
-
} catch (e) {
|
|
255
|
-
// no SKILL.md, skip
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
289
|
+
function discoverSkillsWithMeta(cwd, homeOverride, preferAgentsDir) {
|
|
290
|
+
var byName = collectSkillDirs(cwd, homeOverride || require("./config").REAL_HOME, preferAgentsDir);
|
|
259
291
|
var result = [];
|
|
260
292
|
var names = Object.keys(byName);
|
|
261
293
|
for (var j = 0; j < names.length; j++) {
|
|
@@ -306,36 +338,7 @@ function attachSkillDiscovery(ctx) {
|
|
|
306
338
|
// above) so a caller can resolve the session owner's home instead of the
|
|
307
339
|
// daemon's REAL_HOME on a shared multi-user daemon (lr-3ccc78).
|
|
308
340
|
function discoverSkillDirs(homeOverride) {
|
|
309
|
-
|
|
310
|
-
var globalHome = homeOverride || require("./config").REAL_HOME;
|
|
311
|
-
var dirs = [
|
|
312
|
-
path.join(globalHome, ".claude", "skills"),
|
|
313
|
-
path.join(cwd, ".claude", "skills"),
|
|
314
|
-
];
|
|
315
|
-
for (var d = 0; d < dirs.length; d++) {
|
|
316
|
-
var base = dirs[d];
|
|
317
|
-
var entries;
|
|
318
|
-
try {
|
|
319
|
-
entries = fs.readdirSync(base, { withFileTypes: true });
|
|
320
|
-
} catch (e) {
|
|
321
|
-
continue; // directory doesn't exist
|
|
322
|
-
}
|
|
323
|
-
for (var i = 0; i < entries.length; i++) {
|
|
324
|
-
var entry = entries[i];
|
|
325
|
-
if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
|
|
326
|
-
var skillDir = resolveContainedSkillDir(base, entry.name);
|
|
327
|
-
if (!skillDir) continue;
|
|
328
|
-
var skillMd = path.join(skillDir, "SKILL.md");
|
|
329
|
-
try {
|
|
330
|
-
fs.accessSync(skillMd, fs.constants.R_OK);
|
|
331
|
-
// project skills override global skills with same name
|
|
332
|
-
skills[entry.name] = skillDir;
|
|
333
|
-
} catch (e) {
|
|
334
|
-
// no SKILL.md, skip
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
return skills;
|
|
341
|
+
return collectSkillDirs(cwd, homeOverride || require("./config").REAL_HOME);
|
|
339
342
|
}
|
|
340
343
|
|
|
341
344
|
function mergeSkills(sdkSkills, fsSkills) {
|
|
@@ -366,4 +369,6 @@ module.exports = {
|
|
|
366
369
|
// reuse the same two-stage (lexical + realpath) containment check instead
|
|
367
370
|
// of approximating it — see the function's own doc comment.
|
|
368
371
|
resolveContainedSkillDir: resolveContainedSkillDir,
|
|
372
|
+
collectSkillDirs: collectSkillDirs,
|
|
373
|
+
skillRoots: skillRoots,
|
|
369
374
|
};
|
|
@@ -10,11 +10,9 @@
|
|
|
10
10
|
//
|
|
11
11
|
// userId: REQUIRED to filter results to what the viewing user may actually
|
|
12
12
|
// see. Fails CLOSED: no userId (or no onGetProjectAccess) means no sessions
|
|
13
|
-
// are returned
|
|
14
|
-
// the
|
|
15
|
-
//
|
|
16
|
-
// in single-user/PIN mode (still a real authenticated user, just one
|
|
17
|
-
// account) -- so failing closed here never breaks a real deployment mode.
|
|
13
|
+
// are returned, unless the caller is the implicit single-user owner
|
|
14
|
+
// (implicitOwner, decided by the daemon's mode in lib/project-access.js),
|
|
15
|
+
// who sees every project and session.
|
|
18
16
|
//
|
|
19
17
|
// deps:
|
|
20
18
|
// projects Map<slug, projectCtx> (or anything with .forEach(fn(ctx, slug)))
|
|
@@ -23,6 +21,7 @@
|
|
|
23
21
|
// callerSlug the connecting project's own slug (for includeSelf skip)
|
|
24
22
|
// includeSelf when true, callerSlug's own sessions are included too
|
|
25
23
|
// userId the viewing user's id, or null/undefined to fail closed
|
|
24
|
+
// implicitOwner true for the single-user owner, who has no user record
|
|
26
25
|
function computeAllProjectSessions(deps) {
|
|
27
26
|
var projects = deps.projects;
|
|
28
27
|
var users = deps.users;
|
|
@@ -30,9 +29,10 @@ function computeAllProjectSessions(deps) {
|
|
|
30
29
|
var callerSlug = deps.callerSlug;
|
|
31
30
|
var includeSelf = deps.includeSelf;
|
|
32
31
|
var userId = deps.userId;
|
|
32
|
+
var implicitOwner = deps.implicitOwner === true;
|
|
33
33
|
|
|
34
34
|
var allSessions = [];
|
|
35
|
-
if (!userId || !onGetProjectAccess) return allSessions;
|
|
35
|
+
if (!implicitOwner && (!userId || !onGetProjectAccess)) return allSessions;
|
|
36
36
|
|
|
37
37
|
projects.forEach(function (pCtx, pSlug) {
|
|
38
38
|
if (!includeSelf && pSlug === callerSlug) return; // skip self unless asked
|
|
@@ -45,13 +45,16 @@ function computeAllProjectSessions(deps) {
|
|
|
45
45
|
// the whole project up front if the user cannot access it at all --
|
|
46
46
|
// avoids an O(projects * sessions) repeated-resolution pattern for a
|
|
47
47
|
// value that does not vary per session.
|
|
48
|
-
var access =
|
|
49
|
-
if (!
|
|
50
|
-
|
|
48
|
+
var access = null;
|
|
49
|
+
if (!implicitOwner) {
|
|
50
|
+
access = onGetProjectAccess(pSlug);
|
|
51
|
+
if (!access || access.error) return;
|
|
52
|
+
if (!users.canAccessProject(userId, access)) return;
|
|
53
|
+
}
|
|
51
54
|
var projectTitle = status.title || status.project || pSlug;
|
|
52
55
|
var projectIcon = status.icon || null;
|
|
53
56
|
pSm.sessions.forEach(function (s) {
|
|
54
|
-
if (!s.hidden && users.canAccessSession(userId, s, access)) {
|
|
57
|
+
if (!s.hidden && (implicitOwner || users.canAccessSession(userId, s, access))) {
|
|
55
58
|
// Push a shallow copy annotated with project metadata rather than
|
|
56
59
|
// mutating the live session object with transient UI fields.
|
|
57
60
|
allSessions.push(Object.assign({}, s, {
|