@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.
Files changed (146) hide show
  1. package/LICENSE +117 -12
  2. package/LICENSES/MIT-legacy.txt +22 -0
  3. package/LICENSES/README.md +15 -0
  4. package/README.md +8 -2
  5. package/bin/cli.js +30 -5
  6. package/deploy/clagentic-console.service +10 -6
  7. package/lib/audit.js +3 -2
  8. package/lib/build-sha.json +2 -2
  9. package/lib/build-update-check.js +138 -0
  10. package/lib/cli/daemon-launch.js +17 -17
  11. package/lib/config.js +32 -20
  12. package/lib/daemon-env-settings.js +84 -0
  13. package/lib/daemon-projects.js +38 -0
  14. package/lib/daemon.js +202 -158
  15. package/lib/drain.js +74 -17
  16. package/lib/env-compat.js +61 -0
  17. package/lib/extension-commands.js +45 -0
  18. package/lib/history-visibility.js +4 -0
  19. package/lib/idle-adapter-reaper.js +71 -0
  20. package/lib/link-trap.js +78 -0
  21. package/lib/lore-attestation.js +73 -0
  22. package/lib/mcp-local.js +8 -6
  23. package/lib/mcp-tool-input.js +116 -0
  24. package/lib/mcp-tool-schema.js +179 -0
  25. package/lib/memory-limits.js +61 -5
  26. package/lib/memory-setting-validate.js +65 -0
  27. package/lib/new-work-gate.js +47 -0
  28. package/lib/os-users.js +5 -3
  29. package/lib/project-access.js +139 -0
  30. package/lib/project-connection.js +23 -22
  31. package/lib/project-external-trigger.js +103 -10
  32. package/lib/project-file-scope.js +172 -0
  33. package/lib/project-file-watch.js +86 -61
  34. package/lib/project-filesystem.js +144 -128
  35. package/lib/project-git.js +119 -0
  36. package/lib/project-http.js +44 -28
  37. package/lib/project-loop.js +12 -5
  38. package/lib/project-mcp.js +53 -72
  39. package/lib/project-message-gate.js +70 -0
  40. package/lib/project-notifications.js +31 -4
  41. package/lib/project-prompt-responses.js +216 -0
  42. package/lib/project-sessions.js +164 -302
  43. package/lib/project-user-message.js +36 -11
  44. package/lib/project.js +189 -142
  45. package/lib/projects-dir.js +90 -0
  46. package/lib/prompt-access.js +22 -0
  47. package/lib/prompt-kinds/answer-limits.js +15 -0
  48. package/lib/prompt-kinds/ask-user.js +58 -0
  49. package/lib/prompt-kinds/codecs.js +97 -0
  50. package/lib/prompt-kinds/elicitation.js +77 -0
  51. package/lib/prompt-kinds/extension.js +39 -0
  52. package/lib/prompt-kinds/index.js +68 -0
  53. package/lib/prompt-kinds/permission.js +114 -0
  54. package/lib/prompt-kinds/plan.js +79 -0
  55. package/lib/prompt-kinds/tool-call.js +38 -0
  56. package/lib/prompt-registry.js +673 -0
  57. package/lib/public/app.js +1 -1
  58. package/lib/public/css/diagnostics.css +50 -0
  59. package/lib/public/css/input.css +17 -3
  60. package/lib/public/css/menus.css +10 -0
  61. package/lib/public/css/messages.css +5 -0
  62. package/lib/public/css/rewind.css +22 -0
  63. package/lib/public/index.html +4 -12
  64. package/lib/public/modules/app-connection.js +7 -0
  65. package/lib/public/modules/app-cursors.js +7 -5
  66. package/lib/public/modules/app-messages.js +45 -45
  67. package/lib/public/modules/app-notifications.js +47 -71
  68. package/lib/public/modules/app-panels.js +61 -58
  69. package/lib/public/modules/app-projects.js +2 -1
  70. package/lib/public/modules/app-rendering.js +4 -10
  71. package/lib/public/modules/diagnostics.js +60 -16
  72. package/lib/public/modules/filebrowser.js +18 -16
  73. package/lib/public/modules/history-visibility.js +4 -0
  74. package/lib/public/modules/mention.js +3 -2
  75. package/lib/public/modules/mode-options.js +38 -0
  76. package/lib/public/modules/project-settings.js +19 -8
  77. package/lib/public/modules/prompt-banner.js +78 -0
  78. package/lib/public/modules/prompt-card.js +201 -0
  79. package/lib/public/modules/prompt-kinds/ask-user-codec.js +131 -0
  80. package/lib/public/modules/prompt-kinds/ask-user.js +213 -0
  81. package/lib/public/modules/prompt-kinds/elicitation-codec.js +343 -0
  82. package/lib/public/modules/prompt-kinds/elicitation.js +176 -0
  83. package/lib/public/modules/prompt-kinds/index.js +18 -0
  84. package/lib/public/modules/prompt-kinds/own-key.js +29 -0
  85. package/lib/public/modules/prompt-kinds/package.json +3 -0
  86. package/lib/public/modules/prompt-kinds/permission-choices.js +31 -0
  87. package/lib/public/modules/prompt-kinds/permission.js +209 -0
  88. package/lib/public/modules/prompt-kinds/plan.js +102 -0
  89. package/lib/public/modules/prompt-state.js +142 -0
  90. package/lib/public/modules/prompts.js +134 -0
  91. package/lib/public/modules/rewind.js +4 -1
  92. package/lib/public/modules/server-settings.js +2 -4
  93. package/lib/public/modules/sidebar-mobile.js +19 -9
  94. package/lib/public/modules/sidebar-sessions.js +21 -14
  95. package/lib/public/modules/sticky-notes.js +3 -2
  96. package/lib/public/modules/team-panel.js +5 -4
  97. package/lib/public/modules/tools.js +67 -904
  98. package/lib/public/modules/vendor-picker.js +53 -0
  99. package/lib/public/modules/vendor-registry.js +133 -0
  100. package/lib/public/sw.js +3 -1
  101. package/lib/rc-migrate.js +44 -0
  102. package/lib/runtime-env-keys.js +109 -0
  103. package/lib/runtime-env.js +236 -0
  104. package/lib/sdk-bridge.js +290 -273
  105. package/lib/sdk-message-processor.js +125 -145
  106. package/lib/server-hub-sessions.js +13 -10
  107. package/lib/server-palette.js +28 -19
  108. package/lib/server.js +141 -113
  109. package/lib/service-install.js +96 -0
  110. package/lib/session-capabilities.js +76 -0
  111. package/lib/sessions.js +45 -28
  112. package/lib/users-permissions.js +9 -6
  113. package/lib/users.js +9 -0
  114. package/lib/utils.js +4 -2
  115. package/lib/vendor-auth.js +22 -0
  116. package/lib/vendor-registry-message.js +65 -0
  117. package/lib/ws-origin.js +99 -0
  118. package/lib/ws-schema.js +33 -22
  119. package/lib/yoke/adapters/claude-capabilities.js +38 -0
  120. package/lib/yoke/adapters/claude-vendor.js +35 -0
  121. package/lib/yoke/adapters/claude-worker.js +55 -87
  122. package/lib/yoke/adapters/claude.js +156 -62
  123. package/lib/yoke/adapters/codex-capabilities.js +37 -0
  124. package/lib/yoke/adapters/codex-vendor.js +46 -0
  125. package/lib/yoke/adapters/codex.js +347 -156
  126. package/lib/yoke/adapters/effort-control.js +34 -0
  127. package/lib/yoke/adapters/permission-relay.js +58 -0
  128. package/lib/yoke/adapters/worker-mcp-servers.js +81 -0
  129. package/lib/yoke/auth-checks.js +104 -0
  130. package/lib/yoke/capabilities.js +49 -0
  131. package/lib/yoke/codex-app-server.js +23 -5
  132. package/lib/yoke/env-ownership.js +40 -0
  133. package/lib/yoke/index.js +67 -173
  134. package/lib/yoke/install-probe.js +121 -0
  135. package/lib/yoke/instructions.js +7 -11
  136. package/lib/yoke/interface.js +199 -3
  137. package/lib/yoke/package.json +1 -1
  138. package/lib/yoke/provider-credentials.js +96 -0
  139. package/lib/yoke/registry.js +340 -0
  140. package/package.json +12 -8
  141. package/scripts/check-sdk-lock-drift.js +160 -0
  142. package/scripts/check-test-count.js +76 -1
  143. package/scripts/postinstall.js +218 -136
  144. package/scripts/prompt-harness-history.js +202 -0
  145. package/scripts/verify-installed.js +67 -0
  146. 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 { partitionSubagentOwnedPermissions, retainPreservedTaskBookkeeping, sweepClearedPermissionIndex } = require("./sdk-permission-ownership");
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
- // lr-c56476: Codex parity wiring. Codex (lib/yoke/adapters/codex.js) has no
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: Codex's
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, Codex has no equivalent of the
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 Codex activity becomes visible to
72
- // the derived isProcessing/picker-dot path at all. Gated on
73
- // session.vendor === "codex" so this stays independent of Claude's own
74
- // widened acquisition below (lr-6e20f7, block_stop) -- the two vendors
75
- // acquire tokens through different yokeType branches (tool_start here vs.
76
- // block_stop for Claude) and neither path double-acquires the other's
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
- // Codex-sourced token for this session at once -- a catch-all so a
82
- // thinking block (which Codex ends via its own top-level thinking_stop
83
- // event that this shared processor does not otherwise dispatch) is never
84
- // left acquired past the end of its own turn. This mirrors Claude's
85
- // task_notification acting as a second, idempotent drain path for a token
86
- // that tool_result might not otherwise catch.
87
- function releaseAllCodexActivity(session) {
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 === "codex-tool" || sources[i].source === "codex-thinking") {
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
- // lr-9d4b: Record which backgrounded Task (parentId) owns this tool
178
- // call's id so the parent turn's 'result' handler can tell a
179
- // sub-agent-owned pendingPermissions entry apart from an orphaned one
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
- // lr-c56476: Codex parity -- see releaseAllCodexActivity above for why
315
- // this is gated to vendor === "codex" and not applied to Claude.
316
- if (session.vendor === "codex" && parsed.toolId) {
317
- acquireActivity(session, parsed.toolId, { source: "codex-tool", label: parsed.toolName || "" });
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
- // lr-c56476: Codex parity. Token id keyed on blockId (Codex's
323
- // "blk_N" counter, see lib/yoke/adapters/codex.js flattenEvent) since
324
- // a thinking_start event carries no separate tool-style id.
325
- if (session.vendor === "codex") {
326
- acquireActivity(session, "thinking_" + idx, { source: "codex-thinking", label: "" });
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
- // lr-c56476: Codex parity -- release the token acquired at tool_start
383
- // for this same toolId. releaseActivity is idempotent (see
384
- // session-activity.js), so this is always safe even if the token was
385
- // already released elsewhere (e.g. by the result-time catch-all below).
386
- if (session.vendor === "codex" && parsed.toolId) {
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 for sub-agent done detection
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
- if (!session.activeTaskToolIds) session.activeTaskToolIds = {};
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
- // Clear active Task tool when its result arrives
537
- if (session.activeTaskToolIds && session.activeTaskToolIds[block.tool_use_id]) {
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. The 'result' handler's pre-existing lr-9d4b
552
- // cleanup (retainPreservedTaskBookkeeping) already trims
553
- // activeTaskToolIds down to only Task ids with a preserved
554
- // permission on EVERY result, so a Task with no pending permission
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
- // lr-c56476: Codex parity catch-all -- release EVERY still-live
598
- // Codex-sourced token for this session now, regardless of whether its
599
- // own tool_result/thinking_stop already fired. This runs first, before
600
- // the error_during_execution early return below, so a turn that ends
601
- // in an SDK execution error still drains Codex's tokens (Codex has no
602
- // task_notification-equivalent second drain path the way Claude does,
603
- // so this is the ONLY backstop short of the next startQuery's
604
- // generation bump -- see this task's PR body for why that generation
605
- // bump already covers the harder case of abort/interrupt ending the
606
- // stream before 'result' is ever reached at all).
607
- if (session.vendor === "codex") releaseAllCodexActivity(session);
608
- // lr-9d4b: Preserve pendingPermissions entries owned by a backgrounded
609
- // sub-agent that is still running when the PARENT turn's 'result' arrives.
610
- // A Task tool launched an async sub-agent whose own Bash/etc permission
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 authTitle = session.vendor === "codex" ? "Codex is not logged in." : "Claude Code is not logged in.";
716
- var loginCommand = session.vendor === "codex"
717
- ? "codex login --device-auth"
718
- : "claude login";
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: session.vendor || "claude",
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: session.vendor || "claude",
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
- if (session.activeTaskToolIds) delete session.activeTaskToolIds[parentId];
949
- releaseActivity(session, parentId);
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
- // lr-9d4b: the sub-agent is done — release any tool-ownership records
960
- // for tool ids it registered, so they don't linger as orphaned entries.
961
- // EXCEPTION: do not prune a tool id that still has a live
962
- // pendingPermissions entry pointing at it. task_notification can arrive
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. There is no legitimate no-auth caller of this function --
14
- // the WS upgrade handler in lib/server.js rejects any connection without an
15
- // authenticated user with 401 before ws._clagenticUser can ever be set, including
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 = onGetProjectAccess(pSlug);
49
- if (!access || access.error) return;
50
- if (!users.canAccessProject(userId, access)) return;
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, {
@@ -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 onGetProjectAccess = ctx.onGetProjectAccess;
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
- var paletteUser = getMultiUserFromReq(req);
13
- if (!paletteUser) {
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
- if (paletteUser && onGetProjectAccess) {
28
- var pAccess = onGetProjectAccess(pSlug);
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 (paletteUser) {
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
- if (paletteUser && onGetProjectAccess) {
68
- var pAccess = onGetProjectAccess(pSlug);
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 (paletteUser) {
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
  });