@clagentic/console 1.9.0-beta.3 → 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
|
@@ -1,8 +1,23 @@
|
|
|
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 loreAttestation = require("./lore-attestation");
|
|
7
|
+
var yokeRegistry = require("./yoke").registry;
|
|
8
|
+
var { authRequiredFacts } = require("./vendor-auth");
|
|
9
|
+
|
|
10
|
+
// Source names of the activity tokens an agent with the activityTokens
|
|
11
|
+
// trait holds for its own tool and thinking blocks.
|
|
12
|
+
var TOOL_ACTIVITY_SOURCE = "agent-tool";
|
|
13
|
+
var THINKING_ACTIVITY_SOURCE = "agent-thinking";
|
|
14
|
+
|
|
15
|
+
// How the console drives the session's agent (an adapter trait, not a
|
|
16
|
+
// capability: nothing a session or connection negotiates). A vendor that is not
|
|
17
|
+
// registered has no traits.
|
|
18
|
+
function sessionHasTrait(session, trait) {
|
|
19
|
+
return yokeRegistry.traitOf(session.vendor, trait);
|
|
20
|
+
}
|
|
6
21
|
|
|
7
22
|
function attachMessageProcessor(ctx) {
|
|
8
23
|
var sm = ctx.sm;
|
|
@@ -35,6 +50,21 @@ function attachMessageProcessor(ctx) {
|
|
|
35
50
|
sm.sendAndRecord(session, obj);
|
|
36
51
|
}
|
|
37
52
|
|
|
53
|
+
// session.taskIdMap is keyed by the Task's tool-use id (the parentToolId
|
|
54
|
+
// task_started carries) and holds the SDK's task id; the registry tracks
|
|
55
|
+
// Tasks by that same tool-use id. At a turn boundary the mapping is kept
|
|
56
|
+
// for every Task the registry still tracks, so a still-running sub-agent's
|
|
57
|
+
// later task_updated and task_notification correlate; Task liveness itself
|
|
58
|
+
// is the registry's.
|
|
59
|
+
function retainTaskIdMap(session) {
|
|
60
|
+
var tracked = promptsFor(sm).trackedTaskIds(session);
|
|
61
|
+
var next = {};
|
|
62
|
+
for (var parentToolId in (session.taskIdMap || {})) {
|
|
63
|
+
if (tracked[parentToolId]) next[parentToolId] = session.taskIdMap[parentToolId];
|
|
64
|
+
}
|
|
65
|
+
session.taskIdMap = next;
|
|
66
|
+
}
|
|
67
|
+
|
|
38
68
|
function sendToSession(session, obj) {
|
|
39
69
|
sm.sendToSession(session, obj);
|
|
40
70
|
}
|
|
@@ -61,33 +91,33 @@ function attachMessageProcessor(ctx) {
|
|
|
61
91
|
return result;
|
|
62
92
|
}
|
|
63
93
|
|
|
64
|
-
//
|
|
94
|
+
// Activity-token parity wiring for an agent with the activityTokens
|
|
95
|
+
// trait (Codex, lib/yoke/adapters/codex.js). Such an agent has no
|
|
65
96
|
// subagent concept -- ordinary tool_start/thinking_start there are NOT a
|
|
66
97
|
// 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:
|
|
98
|
+
// must not) fabricate a Task lifecycle. What it DOES need: its
|
|
68
99
|
// tool_start/thinking_start/tool_result/result already ride through this
|
|
69
|
-
// same shared processor, but unlike Claude,
|
|
100
|
+
// same shared processor, but unlike Claude, it has no equivalent of the
|
|
70
101
|
// 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.
|
|
102
|
+
// acquiring an explicit token here is how its activity becomes visible to
|
|
103
|
+
// the derived isProcessing/picker-dot path at all. Gated on the capability
|
|
104
|
+
// so this stays independent of Claude's own widened acquisition below
|
|
105
|
+
// (block_stop) -- the two kinds of agent acquire tokens through different
|
|
106
|
+
// yokeType branches (tool_start here vs. block_stop for Claude) and neither
|
|
107
|
+
// path double-acquires the other's tokens.
|
|
78
108
|
//
|
|
79
109
|
// Release happens on tool_result (per-token, matching Claude's tool_result
|
|
80
110
|
// 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
|
|
111
|
+
// token of these sources for this session at once -- a catch-all so a
|
|
112
|
+
// thinking block (which such an agent ends via its own top-level
|
|
113
|
+
// thinking_stop event that this shared processor does not otherwise
|
|
114
|
+
// dispatch) is never left acquired past the end of its own turn. This
|
|
115
|
+
// mirrors Claude's task_notification acting as a second, idempotent drain
|
|
116
|
+
// path for a token that tool_result might not otherwise catch.
|
|
117
|
+
function releaseAllAgentActivity(session) {
|
|
88
118
|
var sources = sessionActivity.listActiveSources(session);
|
|
89
119
|
for (var i = 0; i < sources.length; i++) {
|
|
90
|
-
if (sources[i].source ===
|
|
120
|
+
if (sources[i].source === TOOL_ACTIVITY_SOURCE || sources[i].source === THINKING_ACTIVITY_SOURCE) {
|
|
91
121
|
releaseActivity(session, sources[i].token);
|
|
92
122
|
}
|
|
93
123
|
}
|
|
@@ -174,12 +204,9 @@ function attachMessageProcessor(ctx) {
|
|
|
174
204
|
for (var i = 0; i < content.length; i++) {
|
|
175
205
|
var block = content[i];
|
|
176
206
|
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;
|
|
207
|
+
// Ownership decides the scope of any prompt this tool raises: a
|
|
208
|
+
// sub-agent's prompt outlives the parent's turn and query.
|
|
209
|
+
promptsFor(sm).noteSubagentTool(session, block.id, parentId);
|
|
183
210
|
var activityText = toolActivityTextForSubagent(block.name, block.input);
|
|
184
211
|
sendAndRecord(session, {
|
|
185
212
|
type: "subagent_tool",
|
|
@@ -237,6 +264,22 @@ function attachMessageProcessor(ctx) {
|
|
|
237
264
|
sm.saveSessionFile(session);
|
|
238
265
|
if (_isNewSessionId) {
|
|
239
266
|
sendAndRecord(session, { type: "session_id", cliSessionId: session.cliSessionId });
|
|
267
|
+
// Declare human presence to LORE for a session of an agent with the
|
|
268
|
+
// attestsHumanSessions trait (Codex) that the operator is driving
|
|
269
|
+
// through the console, keyed on the rollout/thread id captured just
|
|
270
|
+
// above (parsed.sessionId is that id — see
|
|
271
|
+
// lib/yoke/adapters/codex.js's thread/start-and-resume handling).
|
|
272
|
+
// Claude console sessions are already covered by LORE's own pulse hook
|
|
273
|
+
// and are deliberately not duplicated here (see lib/lore-attestation.js
|
|
274
|
+
// header). Gated on session.humanOriginated, set ONLY by the WS
|
|
275
|
+
// "message"/"send_scheduled_now" handlers in project-user-message.js —
|
|
276
|
+
// never true for a headless session (Ralph Loop, external trigger,
|
|
277
|
+
// scheduler), so a scheduled/autonomous dispatch is never attested.
|
|
278
|
+
// Fire-and-forget and fail-open by construction — see
|
|
279
|
+
// attestHumanSession's own contract.
|
|
280
|
+
if (sessionHasTrait(session, "attestsHumanSessions") && session.humanOriginated) {
|
|
281
|
+
loreAttestation.attestHumanSession(session.cliSessionId);
|
|
282
|
+
}
|
|
240
283
|
}
|
|
241
284
|
}
|
|
242
285
|
|
|
@@ -292,7 +335,6 @@ function attachMessageProcessor(ctx) {
|
|
|
292
335
|
models: getModelsForVendor(initVendor),
|
|
293
336
|
vendor: initVendor,
|
|
294
337
|
availableVendors: sm.availableVendors || [],
|
|
295
|
-
installedVendors: sm.installedVendors || [],
|
|
296
338
|
});
|
|
297
339
|
}
|
|
298
340
|
if (parsed.fastModeState) {
|
|
@@ -311,19 +353,19 @@ function attachMessageProcessor(ctx) {
|
|
|
311
353
|
if (parsed.yokeType === "tool_start") {
|
|
312
354
|
session.blocks[idx] = { type: "tool_use", id: parsed.toolId, name: parsed.toolName, inputJson: "" };
|
|
313
355
|
sendAndRecord(session, { type: "tool_start", id: parsed.toolId, name: parsed.toolName });
|
|
314
|
-
//
|
|
315
|
-
//
|
|
316
|
-
if (session
|
|
317
|
-
acquireActivity(session, parsed.toolId, { source:
|
|
356
|
+
// See releaseAllAgentActivity above for why this is gated on the
|
|
357
|
+
// activityTokens trait and not applied to Claude.
|
|
358
|
+
if (sessionHasTrait(session, "activityTokens") && parsed.toolId) {
|
|
359
|
+
acquireActivity(session, parsed.toolId, { source: TOOL_ACTIVITY_SOURCE, label: parsed.toolName || "" });
|
|
318
360
|
}
|
|
319
361
|
} else if (parsed.yokeType === "thinking_start") {
|
|
320
362
|
session.blocks[idx] = { type: "thinking", thinkingText: "", startTime: Date.now() };
|
|
321
363
|
sendAndRecord(session, { type: "thinking_start" });
|
|
322
|
-
//
|
|
323
|
-
//
|
|
324
|
-
//
|
|
325
|
-
if (session
|
|
326
|
-
acquireActivity(session, "thinking_" + idx, { source:
|
|
364
|
+
// Token id keyed on blockId (Codex's "blk_N" counter, see
|
|
365
|
+
// lib/yoke/adapters/codex.js flattenEvent) since a thinking_start
|
|
366
|
+
// event carries no separate tool-style id.
|
|
367
|
+
if (sessionHasTrait(session, "activityTokens")) {
|
|
368
|
+
acquireActivity(session, "thinking_" + idx, { source: THINKING_ACTIVITY_SOURCE, label: "" });
|
|
327
369
|
}
|
|
328
370
|
} else if (parsed.yokeType === "text_start") {
|
|
329
371
|
session.blocks[idx] = { type: "text" };
|
|
@@ -379,11 +421,11 @@ function attachMessageProcessor(ctx) {
|
|
|
379
421
|
is_error: !!parsed.isError,
|
|
380
422
|
});
|
|
381
423
|
|
|
382
|
-
//
|
|
383
|
-
//
|
|
384
|
-
//
|
|
385
|
-
//
|
|
386
|
-
if (session
|
|
424
|
+
// Release the token acquired at tool_start for this same toolId.
|
|
425
|
+
// releaseActivity is idempotent (see session-activity.js), so this is
|
|
426
|
+
// always safe even if the token was already released elsewhere (e.g. by
|
|
427
|
+
// the result-time catch-all below).
|
|
428
|
+
if (sessionHasTrait(session, "activityTokens") && parsed.toolId) {
|
|
387
429
|
releaseActivity(session, parsed.toolId);
|
|
388
430
|
}
|
|
389
431
|
|
|
@@ -460,10 +502,10 @@ function attachMessageProcessor(ctx) {
|
|
|
460
502
|
// (releaseActivity is idempotent either way).
|
|
461
503
|
acquireActivity(session, block.id, { source: "tool", label: input.description || block.name || "" });
|
|
462
504
|
|
|
463
|
-
// Track active Task tools
|
|
505
|
+
// Track active Task tools (activeTaskToolIds, written by the prompt
|
|
506
|
+
// registry) for sub-agent done detection and prompt ownership.
|
|
464
507
|
if (block.name === "Task") {
|
|
465
|
-
|
|
466
|
-
session.activeTaskToolIds[block.id] = true;
|
|
508
|
+
promptsFor(sm).taskStarted(session, block.id);
|
|
467
509
|
}
|
|
468
510
|
|
|
469
511
|
if (pushModule && block.name === "AskUserQuestion" && input.questions) {
|
|
@@ -533,14 +575,15 @@ function attachMessageProcessor(ctx) {
|
|
|
533
575
|
for (var i = 0; i < content.length; i++) {
|
|
534
576
|
var block = content[i];
|
|
535
577
|
if (block.type === "tool_result" && !session.sentToolResults[block.tool_use_id]) {
|
|
536
|
-
//
|
|
537
|
-
|
|
578
|
+
// A tracked Task's result means its sub-agent is done.
|
|
579
|
+
var resultPrompts = promptsFor(sm);
|
|
580
|
+
if (resultPrompts.isTaskTracked(session, block.tool_use_id)) {
|
|
538
581
|
sendAndRecord(session, {
|
|
539
582
|
type: "subagent_done",
|
|
540
583
|
parentToolId: block.tool_use_id,
|
|
541
584
|
});
|
|
542
|
-
delete session.activeTaskToolIds[block.tool_use_id];
|
|
543
585
|
}
|
|
586
|
+
resultPrompts.taskEnded(session, block.tool_use_id);
|
|
544
587
|
// lr-9bcd7b (widened lr-6e20f7): release the activity token
|
|
545
588
|
// acquired at block_stop for this tool id, unconditionally --
|
|
546
589
|
// NOT gated on activeTaskToolIds still containing the entry.
|
|
@@ -548,13 +591,10 @@ function attachMessageProcessor(ctx) {
|
|
|
548
591
|
// beyond Task), not only backgrounded Task tools -- the
|
|
549
592
|
// Task-specific bookkeeping above (activeTaskToolIds,
|
|
550
593
|
// 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
|
|
594
|
+
// the widening. A Task's tracking can end before this tool_result
|
|
595
|
+
// arrives (task_notification first), so gating the release on
|
|
596
|
+
// activeTaskToolIds would silently skip it and leak the token
|
|
597
|
+
// forever. releaseToken
|
|
558
598
|
// is idempotent (no-op if this id was never acquired, or already
|
|
559
599
|
// released by task_notification), so calling it unconditionally
|
|
560
600
|
// for every tool_result is always safe.
|
|
@@ -594,62 +634,20 @@ function attachMessageProcessor(ctx) {
|
|
|
594
634
|
} else if (parsed.yokeType === "result") {
|
|
595
635
|
session.blocks = {};
|
|
596
636
|
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);
|
|
637
|
+
// Catch-all -- release EVERY still-live token of an activityTokens agent
|
|
638
|
+
// for this session now, regardless of whether its own
|
|
639
|
+
// tool_result/thinking_stop already fired. This runs first, before the
|
|
640
|
+
// error_during_execution early return below, so a turn that ends in an
|
|
641
|
+
// SDK execution error still drains its tokens (such an agent has no
|
|
642
|
+
// task_notification-equivalent second drain path the way Claude does, so
|
|
643
|
+
// this is the ONLY backstop short of the next startQuery's generation
|
|
644
|
+
// bump, which already covers the harder case of abort/interrupt ending
|
|
645
|
+
// the stream before 'result' is ever reached at all).
|
|
646
|
+
if (sessionHasTrait(session, "activityTokens")) releaseAllAgentActivity(session);
|
|
647
|
+
// Turn boundary: the turn's own prompts, of every kind, end here; a
|
|
648
|
+
// tracked sub-agent keeps its own (the registry decides which).
|
|
649
|
+
promptsFor(sm).endTurn(session);
|
|
650
|
+
retainTaskIdMap(session);
|
|
653
651
|
// Only clear rateLimitResetsAt on genuine success (non-zero cost).
|
|
654
652
|
// When rate-limited, the SDK sends result with zero cost right after
|
|
655
653
|
// rate_limit_event; clearing here would prevent auto-continue scheduling.
|
|
@@ -712,15 +710,15 @@ function attachMessageProcessor(ctx) {
|
|
|
712
710
|
var authLinuxUser = authUser && authUser.linuxUser ? authUser.linuxUser : null;
|
|
713
711
|
var canAutoLogin = !!authLinuxUser
|
|
714
712
|
|| (authUser && authUser.role === "admin");
|
|
715
|
-
var
|
|
716
|
-
var
|
|
717
|
-
|
|
718
|
-
|
|
713
|
+
var loginVendor = [session.vendor, adapter && adapter.vendor].filter(yokeRegistry.isKnown)[0] || yokeRegistry.ids()[0];
|
|
714
|
+
var authFacts = authRequiredFacts(loginVendor);
|
|
715
|
+
var authTitle = authFacts.title;
|
|
716
|
+
var loginCommand = authFacts.loginCommand;
|
|
719
717
|
var _nmLogin = getNotificationsModule();
|
|
720
718
|
var authMsg = {
|
|
721
719
|
type: "auth_required",
|
|
722
720
|
text: authTitle,
|
|
723
|
-
vendor:
|
|
721
|
+
vendor: authFacts.vendor,
|
|
724
722
|
loginCommand: loginCommand,
|
|
725
723
|
linuxUser: authLinuxUser,
|
|
726
724
|
canAutoLogin: canAutoLogin,
|
|
@@ -733,7 +731,7 @@ function attachMessageProcessor(ctx) {
|
|
|
733
731
|
slug: slug,
|
|
734
732
|
sessionId: session.localId,
|
|
735
733
|
ownerId: session.ownerId || null,
|
|
736
|
-
vendor:
|
|
734
|
+
vendor: authFacts.vendor,
|
|
737
735
|
loginCommand: loginCommand,
|
|
738
736
|
linuxUser: authLinuxUser,
|
|
739
737
|
canAutoLogin: canAutoLogin,
|
|
@@ -932,6 +930,8 @@ function attachMessageProcessor(ctx) {
|
|
|
932
930
|
|
|
933
931
|
} else if (parsed.yokeType === "task_notification") {
|
|
934
932
|
var parentId = parsed.parentToolId;
|
|
933
|
+
var notifiedPrompts = promptsFor(sm);
|
|
934
|
+
var parentOwnsLivePrompt = !!parentId && notifiedPrompts.taskOwnsPending(session, parentId);
|
|
935
935
|
if (parentId) {
|
|
936
936
|
sendAndRecord(session, {
|
|
937
937
|
type: "subagent_done",
|
|
@@ -945,8 +945,11 @@ function attachMessageProcessor(ctx) {
|
|
|
945
945
|
// delivered task_notification without a corresponding tool_result
|
|
946
946
|
// block, or delivered it first). releaseActivity is idempotent —
|
|
947
947
|
// if tool_result already released this same token, this is a no-op.
|
|
948
|
-
|
|
949
|
-
|
|
948
|
+
//
|
|
949
|
+
// EXCEPTION: keep the Task's activity while its sub-agent's own
|
|
950
|
+
// prompt is still awaiting the operator; the prompt keeps the Task
|
|
951
|
+
// in scope (see taskEnded below).
|
|
952
|
+
if (!parentOwnsLivePrompt) releaseActivity(session, parentId);
|
|
950
953
|
}
|
|
951
954
|
if (session.taskIdMap) {
|
|
952
955
|
for (var k in session.taskIdMap) {
|
|
@@ -956,34 +959,10 @@ function attachMessageProcessor(ctx) {
|
|
|
956
959
|
}
|
|
957
960
|
}
|
|
958
961
|
}
|
|
959
|
-
//
|
|
960
|
-
//
|
|
961
|
-
//
|
|
962
|
-
|
|
963
|
-
// while the sub-agent's own permission request (e.g. its last Bash
|
|
964
|
-
// call) is still awaiting the operator's click, or a permission can
|
|
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
|
-
}
|
|
986
|
-
}
|
|
962
|
+
// The sub-agent is done. Its tracking and ownership records are
|
|
963
|
+
// released, except for a prompt still awaiting the operator, which
|
|
964
|
+
// keeps the Task in scope until it settles.
|
|
965
|
+
if (parentId) notifiedPrompts.taskEnded(session, parentId);
|
|
987
966
|
|
|
988
967
|
} else if (parsed.yokeType === "rate_limit") {
|
|
989
968
|
var info = parsed.rateLimitInfo;
|
|
@@ -1108,6 +1087,7 @@ function attachMessageProcessor(ctx) {
|
|
|
1108
1087
|
sendToSession: sendToSession,
|
|
1109
1088
|
processSubagentMessage: processSubagentMessage,
|
|
1110
1089
|
toolActivityTextForSubagent: toolActivityTextForSubagent,
|
|
1090
|
+
retainTaskIdMap: retainTaskIdMap,
|
|
1111
1091
|
};
|
|
1112
1092
|
}
|
|
1113
1093
|
|
|
@@ -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, {
|
package/lib/server-palette.js
CHANGED
|
@@ -4,13 +4,32 @@ function attachPalette(ctx) {
|
|
|
4
4
|
var users = ctx.users;
|
|
5
5
|
var projects = ctx.projects;
|
|
6
6
|
var getMultiUserFromReq = ctx.getMultiUserFromReq;
|
|
7
|
-
var
|
|
7
|
+
var isRequestAuthed = ctx.isRequestAuthed;
|
|
8
|
+
var projectAccess = ctx.projectAccess;
|
|
9
|
+
|
|
10
|
+
// What the single-user owner is shown: every project, as a public one.
|
|
11
|
+
var OWNER_PROJECT_ACCESS = { visibility: "public" };
|
|
12
|
+
|
|
13
|
+
// The project's access record when the principal may use that project, else
|
|
14
|
+
// null. A failed lookup is a refusal, never an allow.
|
|
15
|
+
function accessibleProject(principal, slug) {
|
|
16
|
+
if (principal.implicit) return OWNER_PROJECT_ACCESS;
|
|
17
|
+
var access = projectAccess.resolve(slug);
|
|
18
|
+
return access && users.canAccessProject(principal.id, access) ? access : null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function canSeeSession(principal, session, access) {
|
|
22
|
+
return principal.implicit || users.canAccessSession(principal.id, session, access);
|
|
23
|
+
}
|
|
8
24
|
|
|
9
25
|
function handleRequest(req, res, fullUrl) {
|
|
10
26
|
if (req.method !== "GET" || fullUrl !== "/api/palette/search") return false;
|
|
11
27
|
|
|
12
|
-
|
|
13
|
-
|
|
28
|
+
// Authentication first: appHandler has no login check ahead of this
|
|
29
|
+
// route, and "no user" is the implicit owner only for a request that
|
|
30
|
+
// proved it logged in. Without that proof there is no principal in any mode.
|
|
31
|
+
var principal = projectAccess.principalFor(getMultiUserFromReq(req), { authenticated: isRequestAuthed(req) === true });
|
|
32
|
+
if (!principal) {
|
|
14
33
|
res.writeHead(401, { "Content-Type": "application/json" });
|
|
15
34
|
res.end('{"error":"unauthorized"}');
|
|
16
35
|
return true;
|
|
@@ -24,16 +43,11 @@ function attachPalette(ctx) {
|
|
|
24
43
|
projects.forEach(function (pCtx, pSlug) {
|
|
25
44
|
var status = pCtx.getStatus();
|
|
26
45
|
if (status.isWorktree) return;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (pAccess && !pAccess.error && !users.canAccessProject(paletteUser.id, pAccess)) return;
|
|
30
|
-
}
|
|
46
|
+
var pAccess = accessibleProject(principal, pSlug);
|
|
47
|
+
if (!pAccess) return;
|
|
31
48
|
pCtx.sm.sessions.forEach(function (session) {
|
|
32
49
|
if (session.hidden) return;
|
|
33
|
-
if (
|
|
34
|
-
var sAccess = onGetProjectAccess ? onGetProjectAccess(pSlug) : null;
|
|
35
|
-
if (!users.canAccessSession(paletteUser.id, session, sAccess)) return;
|
|
36
|
-
}
|
|
50
|
+
if (!canSeeSession(principal, session, pAccess)) return;
|
|
37
51
|
var pItem = {
|
|
38
52
|
projectSlug: pSlug,
|
|
39
53
|
projectTitle: status.title || status.project,
|
|
@@ -64,17 +78,12 @@ function attachPalette(ctx) {
|
|
|
64
78
|
projects.forEach(function (pCtx, pSlug) {
|
|
65
79
|
var status = pCtx.getStatus();
|
|
66
80
|
if (status.isWorktree) return;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (pAccess && !pAccess.error && !users.canAccessProject(paletteUser.id, pAccess)) return;
|
|
70
|
-
}
|
|
81
|
+
var pAccess = accessibleProject(principal, pSlug);
|
|
82
|
+
if (!pAccess) return;
|
|
71
83
|
var accessibleSessions = [];
|
|
72
84
|
pCtx.sm.sessions.forEach(function (session) {
|
|
73
85
|
if (session.hidden) return;
|
|
74
|
-
if (
|
|
75
|
-
var sAccess = onGetProjectAccess ? onGetProjectAccess(pSlug) : null;
|
|
76
|
-
if (!users.canAccessSession(paletteUser.id, session, sAccess)) return;
|
|
77
|
-
}
|
|
86
|
+
if (!canSeeSession(principal, session, pAccess)) return;
|
|
78
87
|
smBySession.set(session, pCtx.sm);
|
|
79
88
|
accessibleSessions.push(session);
|
|
80
89
|
});
|