@clagentic/console 1.12.0-beta.3 → 1.13.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 (243) hide show
  1. package/README.md +7 -1
  2. package/bin/cli.js +18 -15
  3. package/lib/agent-roster-ws.js +38 -13
  4. package/lib/agent-roster.js +111 -12
  5. package/lib/agents.js +68 -33
  6. package/lib/atomic-install.js +334 -0
  7. package/lib/build-changes.js +33 -4
  8. package/lib/build-sha.json +2 -2
  9. package/lib/build-update-offer.js +12 -0
  10. package/lib/chat-width.js +31 -0
  11. package/lib/cli/agent-usage.js +126 -0
  12. package/lib/cli/arg-validation.js +1 -1
  13. package/lib/cli/compact-output.js +69 -0
  14. package/lib/cli/ipc-subcommands.js +92 -67
  15. package/lib/cli/output.js +28 -0
  16. package/lib/cli/restart-verb.js +132 -0
  17. package/lib/cli/schedule-input-subcommands.js +45 -8
  18. package/lib/cli/session-subcommands.js +37 -11
  19. package/lib/cli/settings-subcommands.js +74 -0
  20. package/lib/cli-transcript-title.js +56 -3
  21. package/lib/client-files.js +79 -0
  22. package/lib/daemon.js +100 -28
  23. package/lib/default-avatar-color.js +4 -0
  24. package/lib/drain.js +58 -10
  25. package/lib/mcp-tool-input.js +2 -2
  26. package/lib/model-families.js +49 -1
  27. package/lib/notify/type-registry.js +4 -0
  28. package/lib/notify/types.js +7 -4
  29. package/lib/pages.js +13 -63
  30. package/lib/permission-summary.js +12 -16
  31. package/lib/plan-usage-reader.js +70 -0
  32. package/lib/project-connection.js +4 -2
  33. package/lib/project-filesystem.js +6 -7
  34. package/lib/project-notifications.js +55 -8
  35. package/lib/project-prompt-expiry-settings.js +42 -0
  36. package/lib/project-sessions.js +52 -0
  37. package/lib/project-settings-gate.js +98 -0
  38. package/lib/project-user-mention.js +3 -2
  39. package/lib/project.js +1 -1
  40. package/lib/prompt-expiry-settings.js +49 -0
  41. package/lib/prompt-expiry.js +24 -3
  42. package/lib/prompt-kinds/codecs.js +6 -2
  43. package/lib/public/app.js +36 -36
  44. package/lib/public/css/admin.css +156 -170
  45. package/lib/public/css/agent-messages.css +24 -24
  46. package/lib/public/css/agent-picker.css +90 -38
  47. package/lib/public/css/agent-roster.css +61 -27
  48. package/lib/public/css/at-agents.css +10 -10
  49. package/lib/public/css/base.css +207 -184
  50. package/lib/public/css/chat-layout.css +228 -0
  51. package/lib/public/css/command-palette.css +86 -88
  52. package/lib/public/css/diagnostics.css +78 -204
  53. package/lib/public/css/diff.css +10 -10
  54. package/lib/public/css/filebrowser.css +32 -60
  55. package/lib/public/css/home-hub.css +100 -100
  56. package/lib/public/css/icon-strip.css +195 -238
  57. package/lib/public/css/input.css +191 -212
  58. package/lib/public/css/login-panel.css +16 -16
  59. package/lib/public/css/loop.css +96 -187
  60. package/lib/public/css/mention.css +49 -110
  61. package/lib/public/css/menus.css +162 -169
  62. package/lib/public/css/messages.css +49 -123
  63. package/lib/public/css/mobile-nav.css +207 -264
  64. package/lib/public/css/notifications-center.css +45 -124
  65. package/lib/public/css/overlay.css +269 -0
  66. package/lib/public/css/overlays.css +134 -156
  67. package/lib/public/css/playbook.css +41 -41
  68. package/lib/public/css/profile.css +43 -112
  69. package/lib/public/css/rewind.css +112 -112
  70. package/lib/public/css/scheduler-modal.css +27 -135
  71. package/lib/public/css/scheduler.css +204 -210
  72. package/lib/public/css/server-settings.css +173 -239
  73. package/lib/public/css/session-search.css +20 -20
  74. package/lib/public/css/settings-nav.css +197 -0
  75. package/lib/public/css/sidebar.css +213 -304
  76. package/lib/public/css/skills.css +121 -135
  77. package/lib/public/css/sticky-notes.css +114 -200
  78. package/lib/public/css/stt.css +17 -26
  79. package/lib/public/css/team-panel.css +36 -36
  80. package/lib/public/css/team-view.css +9 -9
  81. package/lib/public/css/title-bar.css +83 -100
  82. package/lib/public/css/tooltip.css +10 -10
  83. package/lib/public/css/user-settings.css +78 -131
  84. package/lib/public/css/user-shell.css +125 -29
  85. package/lib/public/index.html +178 -177
  86. package/lib/public/manifest.json +0 -2
  87. package/lib/public/modules/admin.js +54 -92
  88. package/lib/public/modules/agent-avatar.js +134 -3
  89. package/lib/public/modules/agent-messages.js +2 -1
  90. package/lib/public/modules/agent-picker.js +23 -21
  91. package/lib/public/modules/agent-roster-groups.js +128 -0
  92. package/lib/public/modules/agent-roster.js +40 -11
  93. package/lib/public/modules/app-connection.js +13 -1
  94. package/lib/public/modules/app-cursors.js +9 -9
  95. package/lib/public/modules/app-favicon.js +8 -16
  96. package/lib/public/modules/app-header.js +28 -19
  97. package/lib/public/modules/app-history-replay.js +67 -4
  98. package/lib/public/modules/app-home-hub.js +15 -0
  99. package/lib/public/modules/app-loop-ui.js +41 -47
  100. package/lib/public/modules/app-loop-wizard.js +9 -10
  101. package/lib/public/modules/app-messages.js +32 -36
  102. package/lib/public/modules/app-misc.js +22 -92
  103. package/lib/public/modules/app-modals.js +98 -0
  104. package/lib/public/modules/app-notifications.js +124 -135
  105. package/lib/public/modules/app-panels.js +28 -32
  106. package/lib/public/modules/app-projects.js +30 -40
  107. package/lib/public/modules/app-rate-limit.js +26 -9
  108. package/lib/public/modules/app-rendering.js +128 -110
  109. package/lib/public/modules/app-skills-install.js +6 -4
  110. package/lib/public/modules/assistant-identity.js +55 -0
  111. package/lib/public/modules/at-agents.js +3 -0
  112. package/lib/public/modules/build-guard.js +25 -11
  113. package/lib/public/modules/chat-width-choice.js +75 -0
  114. package/lib/public/modules/chat-width-prefs.js +52 -0
  115. package/lib/public/modules/chat-width.js +102 -0
  116. package/lib/public/modules/collapsible-text.js +36 -4
  117. package/lib/public/modules/command-palette.js +28 -34
  118. package/lib/public/modules/context-sources.js +3 -5
  119. package/lib/public/modules/diagnostics.js +130 -129
  120. package/lib/public/modules/info-panel.js +31 -0
  121. package/lib/public/modules/injected-identity.js +8 -8
  122. package/lib/public/modules/input-list-menu.js +39 -0
  123. package/lib/public/modules/input.js +22 -21
  124. package/lib/public/modules/markdown.js +10 -11
  125. package/lib/public/modules/mcp-ui.js +4 -14
  126. package/lib/public/modules/mention.js +100 -229
  127. package/lib/public/modules/message-header.js +80 -0
  128. package/lib/public/modules/message-participants.js +39 -0
  129. package/lib/public/modules/mobile-action-sheet.js +46 -0
  130. package/lib/public/modules/mobile-nav-sheet.js +104 -0
  131. package/lib/public/modules/model-families.js +41 -4
  132. package/lib/public/modules/note-order.js +39 -0
  133. package/lib/public/modules/notifications.js +35 -52
  134. package/lib/public/modules/overlay-history.js +73 -19
  135. package/lib/public/modules/overlay-menu.js +123 -0
  136. package/lib/public/modules/overlay-modal.js +186 -0
  137. package/lib/public/modules/overlay-registry.js +392 -0
  138. package/lib/public/modules/overlay-stack.js +110 -0
  139. package/lib/public/modules/overlay.js +117 -0
  140. package/lib/public/modules/popover-position.js +18 -2
  141. package/lib/public/modules/preference-sync.js +28 -0
  142. package/lib/public/modules/profile.js +24 -49
  143. package/lib/public/modules/project-settings.js +27 -172
  144. package/lib/public/modules/prompt-expiry-controls.js +46 -0
  145. package/lib/public/modules/prompt-kinds/command-summary.js +149 -0
  146. package/lib/public/modules/prompt-kinds/permission.js +70 -92
  147. package/lib/public/modules/prompts.js +1 -2
  148. package/lib/public/modules/qrcode.js +6 -21
  149. package/lib/public/modules/queued-button.js +15 -2
  150. package/lib/public/modules/rewind.js +9 -3
  151. package/lib/public/modules/schedule-time.js +32 -7
  152. package/lib/public/modules/scheduled-outbox.js +51 -18
  153. package/lib/public/modules/scheduler-config.js +87 -127
  154. package/lib/public/modules/scheduler.js +29 -26
  155. package/lib/public/modules/serialized-save.js +79 -0
  156. package/lib/public/modules/server-settings.js +75 -65
  157. package/lib/public/modules/session-grants.js +16 -19
  158. package/lib/public/modules/session-list-avatars.js +98 -0
  159. package/lib/public/modules/session-vendor-state.js +86 -0
  160. package/lib/public/modules/settings-access.js +35 -0
  161. package/lib/public/modules/settings-hub.js +125 -0
  162. package/lib/public/modules/settings-nav.js +182 -0
  163. package/lib/public/modules/shell-line.js +24 -0
  164. package/lib/public/modules/sidebar-mobile.js +151 -195
  165. package/lib/public/modules/sidebar-projects.js +88 -129
  166. package/lib/public/modules/sidebar-sessions.js +66 -34
  167. package/lib/public/modules/sidebar.js +2 -2
  168. package/lib/public/modules/skills.js +11 -26
  169. package/lib/public/modules/sticky-notes.js +19 -16
  170. package/lib/public/modules/stt.js +9 -23
  171. package/lib/public/modules/terminal.js +86 -90
  172. package/lib/public/modules/theme-choice.js +126 -0
  173. package/lib/public/modules/theme-colors.js +19 -0
  174. package/lib/public/modules/theme-prefs.js +121 -0
  175. package/lib/public/modules/theme.js +227 -605
  176. package/lib/public/modules/tool-palette.js +7 -17
  177. package/lib/public/modules/tools.js +8 -10
  178. package/lib/public/modules/user-settings.js +59 -115
  179. package/lib/public/modules/user-shell.js +9 -2
  180. package/lib/public/modules/utils.js +10 -12
  181. package/lib/public/modules/vendor-picker.js +4 -2
  182. package/lib/public/modules/vendor-registry.js +1 -2
  183. package/lib/public/style.css +3 -1
  184. package/lib/public/sw.js +9 -2
  185. package/lib/public/theme-core.js +411 -0
  186. package/lib/request-body.js +70 -0
  187. package/lib/sdk-bridge.js +227 -88
  188. package/lib/sdk-message-processor.js +44 -16
  189. package/lib/server-admin.js +198 -200
  190. package/lib/server-auth.js +16 -13
  191. package/lib/server-dm.js +4 -3
  192. package/lib/server-settings.js +177 -130
  193. package/lib/server.js +87 -36
  194. package/lib/session-background-tasks.js +79 -0
  195. package/lib/session-directory.js +138 -13
  196. package/lib/session-input-ipc.js +2 -0
  197. package/lib/session-input.js +39 -5
  198. package/lib/session-list-avatars.js +16 -0
  199. package/lib/session-reclaim.js +37 -25
  200. package/lib/session-vendor.js +37 -0
  201. package/lib/sessions.js +99 -34
  202. package/lib/settings-ipc.js +60 -0
  203. package/lib/settings-registry.js +86 -0
  204. package/lib/terminal-manager.js +17 -5
  205. package/lib/theme-files.js +132 -0
  206. package/lib/theme-seed.js +136 -0
  207. package/lib/themes/clagentic-dark.json +13 -6
  208. package/lib/themes/clagentic-light.json +12 -5
  209. package/lib/updater.js +6 -4
  210. package/lib/usage-store.js +97 -10
  211. package/lib/users-preferences.js +118 -19
  212. package/lib/users.js +19 -10
  213. package/lib/vendor-catalog.js +130 -0
  214. package/lib/ws-schema.js +4 -2
  215. package/lib/yoke/adapters/claude.js +81 -1
  216. package/lib/yoke/adapters/codex-user-shell.js +87 -23
  217. package/lib/yoke/adapters/codex.js +89 -5
  218. package/lib/yoke/codex-binary.js +59 -0
  219. package/package.json +1 -1
  220. package/scripts/check-test-count.js +5 -0
  221. package/scripts/install-local-test.js +50 -9
  222. package/scripts/write-build-sha.js +18 -2
  223. package/lib/public/css/channel-layout.css +0 -329
  224. package/lib/themes/ayu-light.json +0 -9
  225. package/lib/themes/catppuccin-latte.json +0 -9
  226. package/lib/themes/catppuccin-mocha.json +0 -9
  227. package/lib/themes/dracula.json +0 -9
  228. package/lib/themes/everforest-light.json +0 -9
  229. package/lib/themes/everforest.json +0 -9
  230. package/lib/themes/github-light.json +0 -9
  231. package/lib/themes/gruvbox-dark.json +0 -9
  232. package/lib/themes/gruvbox-light.json +0 -9
  233. package/lib/themes/monokai.json +0 -9
  234. package/lib/themes/nord-light.json +0 -9
  235. package/lib/themes/nord.json +0 -9
  236. package/lib/themes/one-dark.json +0 -9
  237. package/lib/themes/one-light.json +0 -9
  238. package/lib/themes/rose-pine-dawn.json +0 -9
  239. package/lib/themes/rose-pine.json +0 -9
  240. package/lib/themes/solarized-dark.json +0 -9
  241. package/lib/themes/solarized-light.json +0 -9
  242. package/lib/themes/tokyo-night-light.json +0 -9
  243. package/lib/themes/tokyo-night.json +0 -9
package/lib/sdk-bridge.js CHANGED
@@ -21,6 +21,7 @@ var { toolApprovalKind } = require("./prompt-kinds");
21
21
  var sessionActivity = require("./session-activity");
22
22
  var queuedChat = require("./queued-chat");
23
23
  var sessionReclaim = require("./session-reclaim");
24
+ var backgroundTasks = require("./session-background-tasks");
24
25
  var usageStore = require("./usage-store");
25
26
  var { withPromptLabel } = require("./prompt-label");
26
27
  var { isAgentDispatchTool } = require("./agent-dispatch-tool");
@@ -30,6 +31,7 @@ var runtimeEnv = require("./runtime-env");
30
31
  var mcpToolSchema = require("./mcp-tool-schema");
31
32
  var { registry: yokeRegistry } = require("./yoke");
32
33
  var sessionCapabilities = require("./session-capabilities");
34
+ var { resolveVendor } = require("./session-vendor");
33
35
  var { buildVendorRegistryMessage, recordInstallState } = require("./vendor-registry-message");
34
36
  var { authRequiredFacts, providerAuthFailure } = require("./vendor-auth");
35
37
  var { bumpLastActivity } = require("./activity-clock");
@@ -576,6 +578,39 @@ function createSDKBridge(opts) {
576
578
  return session.vendor || (adapter && adapter.vendor) || yokeRegistry.ids()[0];
577
579
  }
578
580
 
581
+ // The shared vendor resolution (session, else stored meta, else the project's
582
+ // default vendor); see session-vendor.js.
583
+ function resolveVendorFor(session) {
584
+ return resolveVendor(session, {
585
+ lookupMetaVendor: sm.lookupMetaVendor,
586
+ defaultVendor: sm.defaultVendor || (adapter && adapter.vendor) || null,
587
+ });
588
+ }
589
+
590
+ // Makes sure the session carries a vendor before a query starts. A vendor
591
+ // recorded in the meta is put back on the session. With none recorded the
592
+ // session is bound once to the project's default vendor, written into its
593
+ // meta, and the session is told so in one line. Returns null when the
594
+ // session is ready, else the reason it is refused: "unreadable" (the meta
595
+ // could not be read, so its vendor is unknown) or "no-default". Nothing is
596
+ // bound or saved on a refusal.
597
+ function ensureSessionVendor(session) {
598
+ if (session.vendor) return null;
599
+ var resolved = resolveVendorFor(session);
600
+ if (resolved.source === "error") return "unreadable";
601
+ if (!resolved.vendor) return "no-default";
602
+ session.vendor = resolved.vendor;
603
+ if (resolved.source === "default") {
604
+ if (typeof sm.saveSessionFile === "function") sm.saveSessionFile(session);
605
+ var boundName = yokeRegistry.isKnown(resolved.vendor) ? yokeRegistry.displayNameFor(resolved.vendor) : resolved.vendor;
606
+ sendAndRecord(session, {
607
+ type: "info",
608
+ text: "This session had no recorded agent. It is now bound to " + boundName + ", the project's default agent.",
609
+ });
610
+ }
611
+ return null;
612
+ }
613
+
579
614
  // Message shown when the user stops a turn; each agent words it itself.
580
615
  function interruptMessageFor(session) {
581
616
  var vendor = sessionVendorId(session);
@@ -694,14 +729,16 @@ function createSDKBridge(opts) {
694
729
  // tool_progress/task_progress/task_updated/task_started branches in
695
730
  // sdk-message-processor.js), so a progressing child keeps pushing this
696
731
  // loop's idle clock forward for as long as it keeps producing output.
697
- // Deliberately NOT "never reap if session.activeTaskToolIds is non-empty"
698
- // — a dead/silent child (crashed, stuck, or simply never checks back in)
699
- // must still become reapable once IDLE_TIMEOUT_MS genuinely elapses with
700
- // no activity at all, or a leaked child registration would pin the
701
- // session (and its process) alive forever. Because that case was never
702
- // "live" at the moment of reap (no activity for the full timeout window),
703
- // it is reaped; the reap and the pressure path in lib/memory-shed.js both
704
- // announce it through lib/session-reclaim.js.
732
+ // A background agent that was launched and has not sent its terminal
733
+ // task_notification holds an activity token, so isProcessing stays true and
734
+ // the reaper skips the session however long the agent is silent: a long
735
+ // build or test run emits nothing for tens of minutes, and ending the query
736
+ // would kill it. The token is released by the terminal notification or the
737
+ // query ending; a token leaked with no query is recovered by the
738
+ // sweepStaleTokens backstop below, and memory pressure (lib/memory-shed.js)
739
+ // still ends such a session and names its agents through
740
+ // lib/session-reclaim.js. A tracked Task with no held token (isProcessing
741
+ // false) is not protected by this rule and is reaped after the timeout.
705
742
  //
706
743
  // A session with ANY open operator prompt is never reaped (see the
707
744
  // pendingCount check in startIdleReaper): a background agent blocked on a
@@ -726,6 +763,7 @@ function createSDKBridge(opts) {
726
763
  var now = Date.now();
727
764
  var skippedForPrompt = [];
728
765
  var skippedForKeepAlive = [];
766
+ var skippedForBackground = [];
729
767
  sm.sessions.forEach(function (session) {
730
768
  if (session.destroying) return;
731
769
 
@@ -762,10 +800,13 @@ function createSDKBridge(opts) {
762
800
 
763
801
  // Skip sessions that are actively processing, have no query,
764
802
  // or are single-turn (Ralph Loop — managed by onQueryComplete).
765
- // A session busy only through background agents is waiting on them,
766
- // not running a turn: it stays reapable, so a silent agent is named
767
- // in the reclaim notice instead of pinning the session forever.
768
- if (session.isProcessing && !sessionReclaim.onlyBackgroundAgentsActive(session)) return;
803
+ // A session whose isProcessing is held by a tracked background agent
804
+ // that has not reached its terminal notification is skipped like any
805
+ // processing session: killing it closes the query that hosts the
806
+ // agent and the work it is doing. The token is released at the
807
+ // terminal task_notification or when the query ends, and a token
808
+ // leaked with no query is recovered by the sweep above.
809
+ if (session.isProcessing) return;
769
810
  if (!session.queryInstance) return;
770
811
  if (session.singleTurn) return;
771
812
 
@@ -791,6 +832,17 @@ function createSDKBridge(opts) {
791
832
  return;
792
833
  }
793
834
 
835
+ // A live background task of any type (a Bash the lane waits on, a
836
+ // monitor, an agent) is work the session is waiting for: it emits
837
+ // nothing until its notification, and ending the query kills the
838
+ // waiter. The set is cleared when the query ends.
839
+ var liveTasks = backgroundTasks.count(session);
840
+ if (liveTasks > 0) {
841
+ skippedForBackground.push(logField(session.localId) + ":tasks=" + liveTasks
842
+ + ":idle=" + Math.round((now - (session.lastActivityAt || 0)) / 60000) + "min");
843
+ return;
844
+ }
845
+
794
846
  var lastActivity = session.lastActivityAt || 0;
795
847
  if (now - lastActivity > IDLE_TIMEOUT_MS) {
796
848
  console.log("[sdk-bridge] Reaping idle session " + session.localId +
@@ -830,6 +882,11 @@ function createSDKBridge(opts) {
830
882
  + " session(s) with an open prompt: project=" + logField(slug)
831
883
  + " sessions=" + skippedForPrompt.join(","));
832
884
  }
885
+ if (skippedForBackground.length) {
886
+ console.log("[sdk-bridge] Idle reaper: skipped " + skippedForBackground.length
887
+ + " session(s) with live background tasks: project=" + logField(slug)
888
+ + " sessions=" + skippedForBackground.join(","));
889
+ }
833
890
  }, IDLE_CHECK_INTERVAL_MS);
834
891
  // Don't prevent process exit
835
892
  if (_idleReaperTimer.unref) _idleReaperTimer.unref();
@@ -892,6 +949,7 @@ function createSDKBridge(opts) {
892
949
  // is the same pattern already used elsewhere in this file (getFreshAuthState).
893
950
  resolveSessionHome: resolveOwnerHome,
894
951
  providerFailureFor: providerFailureFor,
952
+ interruptMessageFor: interruptMessageFor,
895
953
  });
896
954
  var processSDKMessage = msgProcessor.processSDKMessage;
897
955
  var sendAndRecord = msgProcessor.sendAndRecord;
@@ -907,17 +965,20 @@ function createSDKBridge(opts) {
907
965
 
908
966
  var opened = promptsFor(sm).open(session, "elicitation", request, { signal: opts && opts.signal });
909
967
 
910
- // No push for a prompt that ended at once (its signal was already aborted).
911
- if (pushModule && opened.pending) {
968
+ // No push or banner for a prompt that ended at once (its signal was already
969
+ // aborted). The registry closes both when the prompt settles.
970
+ var inAppNotifications = getNotificationsModule();
971
+ if ((pushModule || inAppNotifications) && opened.pending) {
972
+ var elicitationText = {
973
+ title: (request.serverName || "MCP Server") + " needs input",
974
+ body: withPromptLabel(opened.label, request.message || "Waiting for your response"),
975
+ };
912
976
  // Body carries MCP message text: owner only, never a blind broadcast.
913
- notifyFor(pushModule).notify("elicitation", {
977
+ notifyFor(pushModule, inAppNotifications).notify("elicitation", {
914
978
  slug: slug,
915
979
  sessionId: session.localId,
916
980
  requestId: opened.requestId,
917
- }, {
918
- title: (request.serverName || "MCP Server") + " needs input",
919
- body: withPromptLabel(opened.label, request.message || "Waiting for your response"),
920
- }, { ownerId: session.ownerId });
981
+ }, { push: elicitationText, banner: elicitationText }, { ownerId: session.ownerId });
921
982
  }
922
983
 
923
984
  return opened.answer;
@@ -1154,10 +1215,29 @@ function createSDKBridge(opts) {
1154
1215
 
1155
1216
  // AskUserQuestion: the operator's answers become the tool's input.
1156
1217
  if (toolName === "AskUserQuestion") {
1157
- return prompts.open(session, "ask_user", { input: input }, {
1218
+ var asked = prompts.open(session, "ask_user", { input: input }, {
1158
1219
  toolUseId: opts.toolUseID,
1159
1220
  signal: opts.signal,
1160
- }).answer;
1221
+ });
1222
+ // The push and the banner follow the prompt, not the tool call: a call
1223
+ // the loop denied above, or one whose signal had already aborted, opens
1224
+ // no prompt and so has nothing to close the notification later. The
1225
+ // registry closes both when the prompt settles.
1226
+ var askNotifications = getNotificationsModule();
1227
+ var firstQuestion = input && input.questions && input.questions[0];
1228
+ if ((pushModule || askNotifications) && asked.pending && input && input.questions) {
1229
+ var askText = {
1230
+ title: "Claude has a question",
1231
+ body: withPromptLabel(asked.label, firstQuestion ? firstQuestion.question : "Waiting for your response"),
1232
+ };
1233
+ // Content carries prompt text: owner only, never a blind broadcast.
1234
+ notifyFor(pushModule, askNotifications).notify("ask_user", {
1235
+ slug: slug,
1236
+ sessionId: session.localId,
1237
+ requestId: asked.requestId,
1238
+ }, { push: askText, banner: askText }, { ownerId: session.ownerId });
1239
+ }
1240
+ return asked.answer;
1161
1241
  }
1162
1242
 
1163
1243
  var kind = toolApprovalKind(toolName);
@@ -1285,7 +1365,11 @@ function createSDKBridge(opts) {
1285
1365
  if (myIdentityLease) session._identityLease = null;
1286
1366
  console.log("[sdk-bridge] processQueryStream: starting for-await loop, vendor=" + (session.vendor || adapter.vendor));
1287
1367
  try {
1368
+ // Per-query receive sequence: a Send now marker records it, so a result the
1369
+ // stream had already yielded cannot be taken for the abort the marker expects.
1370
+ session.queryReceiveSeq = 0;
1288
1371
  for await (var msg of myQueryInstance) {
1372
+ session.queryReceiveSeq++;
1289
1373
  if (msg && msg.yokeType !== "text_delta" && msg.yokeType !== "thinking_delta" && msg.yokeType !== "tool_input_delta") {
1290
1374
  console.log("[sdk-bridge] processQueryStream: received event yokeType=" + msg.yokeType);
1291
1375
  }
@@ -1475,6 +1559,11 @@ function createSDKBridge(opts) {
1475
1559
  }
1476
1560
  } catch (e) {}
1477
1561
  session.queryInstance = null;
1562
+ // The tasks lived in this query's process; none outlives it.
1563
+ backgroundTasks.clear(session);
1564
+ // An interrupt that resolved but never got a result must not outlive its
1565
+ // query, or it would hide a later unrelated abort as an interruption.
1566
+ session.selfCausedInterrupt = false;
1478
1567
  }
1479
1568
  // lr-b61b: In the in-process path, close() ends the messageQueue but the
1480
1569
  // underlying claude child process may survive in epoll_wait on its stdin
@@ -1671,8 +1760,18 @@ function createSDKBridge(opts) {
1671
1760
  }
1672
1761
 
1673
1762
  function getAdapterForSession(session) {
1674
- var vendor = session.vendor || sm.defaultVendor || "claude";
1675
- return adapters[vendor] || adapter;
1763
+ var resolved = resolveVendorFor(session);
1764
+ if (!resolved.vendor) {
1765
+ throw new Error(resolved.source === "error"
1766
+ ? "This session's stored record could not be read, so its agent is unknown."
1767
+ : "This session has no recorded agent (vendor) and the project has no default agent.");
1768
+ }
1769
+ // No fallback to the default adapter: a recorded agent that is not loaded
1770
+ // (signed out, say) must not fork or rewind on a different agent.
1771
+ if (!adapters[resolved.vendor]) {
1772
+ throw new Error("The agent for this session (" + resolved.vendor + ") is not available, so the session cannot be forked or rewound.");
1773
+ }
1774
+ return adapters[resolved.vendor];
1676
1775
  }
1677
1776
 
1678
1777
  async function forkSessionUnified(session, uuid) {
@@ -1763,6 +1862,20 @@ function createSDKBridge(opts) {
1763
1862
  return vendorAdapter;
1764
1863
  }
1765
1864
 
1865
+ // A query never runs on an unrecorded vendor: the session's vendor is
1866
+ // restored from its stored meta, else bound once to the project default
1867
+ // (visibly), else the query is refused with a line that says so.
1868
+ var vendorRefusal = ensureSessionVendor(session);
1869
+ if (vendorRefusal) {
1870
+ sendAndRecord(session, {
1871
+ type: "error",
1872
+ text: vendorRefusal === "unreadable"
1873
+ ? "This session's stored record could not be read, so its agent is unknown and the query was not started. Try again; nothing was changed."
1874
+ : "This session has no recorded agent (vendor) and the project has no default agent, so the query was not started. Open a new session and pick an agent.",
1875
+ });
1876
+ sendAndRecord(session, { type: "done", code: 1 });
1877
+ return;
1878
+ }
1766
1879
  // A vendor that is not registered cannot be started, logged into or
1767
1880
  // looked up: say so by name instead of falling through to a default.
1768
1881
  if (session.vendor && !yokeRegistry.isKnown(session.vendor)) {
@@ -1777,69 +1890,6 @@ function createSDKBridge(opts) {
1777
1890
  sendAndRecord(session, { type: "done", code: 1 });
1778
1891
  return;
1779
1892
  }
1780
- // If vendor is set but adapter not ready, try lazy creation (user may have logged in)
1781
- if (session.vendor && !adapters[session.vendor]) {
1782
- var lazyAdapter = await ensureVendorReady(session.vendor);
1783
- if (lazyAdapter) {
1784
- console.log("[sdk-bridge] Lazy adapter created for " + session.vendor);
1785
- }
1786
- } else if (session.vendor) {
1787
- await ensureVendorReady(session.vendor);
1788
- }
1789
- if (session.vendor && !adapters[session.vendor]) {
1790
- var freshAuth = getFreshAuthState(false, session);
1791
- logAuthDecision("pre-auth-required", session, null, freshAuth);
1792
- if (freshAuth[session.vendor]) {
1793
- var recoveredAdapter = await ensureVendorReady(session.vendor);
1794
- if (recoveredAdapter) {
1795
- console.log("[sdk-bridge] Auth recheck recovered adapter for " + session.vendor);
1796
- }
1797
- }
1798
- }
1799
- // If still not available after lazy check, send auth_required
1800
- if (session.vendor && !adapters[session.vendor]) {
1801
- var authFacts2 = authRequiredFacts(session.vendor);
1802
- var vendorName = authFacts2.displayName;
1803
- var authUser = session.ownerId ? usersModule.findUserById(session.ownerId) : null;
1804
- var authLinuxUser = authUser && authUser.linuxUser ? authUser.linuxUser : null;
1805
- var canAutoLogin = !!authLinuxUser
1806
- || (authUser && authUser.role === "admin");
1807
- var authState = getFreshAuthState(false, session);
1808
- logAuthDecision("emit-auth-required", session, "missing adapter", authState);
1809
- if (authState[session.vendor]) {
1810
- sendAndRecord(session, {
1811
- type: "error",
1812
- text: vendorName + " auth is available, but the adapter could not be initialized.",
1813
- });
1814
- sendAndRecord(session, { type: "done", code: 1 });
1815
- return;
1816
- }
1817
- // A provider selected in the environment whose credential set is
1818
- // incomplete: naming the provider, not offering a sign-in.
1819
- var providerFailure = providerFailureFor(session, session.vendor);
1820
- if (providerFailure) {
1821
- sendAndRecord(session, { type: "error", text: providerFailure.message });
1822
- sendAndRecord(session, { type: "done", code: 1 });
1823
- return;
1824
- }
1825
- var authMsg2 = {
1826
- type: "auth_required",
1827
- text: authFacts2.title,
1828
- vendor: authFacts2.vendor,
1829
- loginCommand: authFacts2.loginCommand,
1830
- linuxUser: authLinuxUser,
1831
- canAutoLogin: canAutoLogin,
1832
- };
1833
- sendAndRecord(session, authMsg2);
1834
- notifyAuthRequired(session, authFacts2.title, authLinuxUser, canAutoLogin, authFacts2.loginCommand);
1835
- sendAndRecord(session, { type: "done", code: 1 });
1836
- return;
1837
- }
1838
- // Select adapter based on session vendor (fallback to default)
1839
- var sessionAdapter = (session.vendor && adapters[session.vendor]) || adapter;
1840
- // Console session ids repeat across projects, so the line names the project.
1841
- // The prompt text is not logged.
1842
- console.log("[sdk-bridge] startQuery: project=" + slug + " vendor=" + sessionAdapter.vendor + " session=" + session.localId);
1843
1893
  // Remember linuxUser for auto-continue after rate limit
1844
1894
  session.lastLinuxUser = linuxUser || null;
1845
1895
 
@@ -2026,6 +2076,74 @@ function createSDKBridge(opts) {
2026
2076
  // the slot claimed above and surfaces a visible error (no spinner-forever).
2027
2077
  try {
2028
2078
 
2079
+ // The agent is made ready after the slot is claimed (never before), so
2080
+ // concurrent starts cannot all pass the ceiling while one awaits its agent;
2081
+ // every refusal below gives the slot back.
2082
+ // If vendor is set but adapter not ready, try lazy creation (user may have logged in)
2083
+ if (session.vendor && !adapters[session.vendor]) {
2084
+ var lazyAdapter = await ensureVendorReady(session.vendor);
2085
+ if (lazyAdapter) {
2086
+ console.log("[sdk-bridge] Lazy adapter created for " + session.vendor);
2087
+ }
2088
+ } else if (session.vendor) {
2089
+ await ensureVendorReady(session.vendor);
2090
+ }
2091
+ if (session.vendor && !adapters[session.vendor]) {
2092
+ var freshAuth = getFreshAuthState(false, session);
2093
+ logAuthDecision("pre-auth-required", session, null, freshAuth);
2094
+ if (freshAuth[session.vendor]) {
2095
+ var recoveredAdapter = await ensureVendorReady(session.vendor);
2096
+ if (recoveredAdapter) {
2097
+ console.log("[sdk-bridge] Auth recheck recovered adapter for " + session.vendor);
2098
+ }
2099
+ }
2100
+ }
2101
+ // If still not available after lazy check, send auth_required
2102
+ if (session.vendor && !adapters[session.vendor]) {
2103
+ var authFacts2 = authRequiredFacts(session.vendor);
2104
+ var vendorName = authFacts2.displayName;
2105
+ var authUser = session.ownerId ? usersModule.findUserById(session.ownerId) : null;
2106
+ var authLinuxUser = authUser && authUser.linuxUser ? authUser.linuxUser : null;
2107
+ var canAutoLogin = !!authLinuxUser
2108
+ || (authUser && authUser.role === "admin");
2109
+ var authState = getFreshAuthState(false, session);
2110
+ logAuthDecision("emit-auth-required", session, "missing adapter", authState);
2111
+ releaseSlot();
2112
+ if (authState[session.vendor]) {
2113
+ sendAndRecord(session, {
2114
+ type: "error",
2115
+ text: vendorName + " auth is available, but the adapter could not be initialized.",
2116
+ });
2117
+ sendAndRecord(session, { type: "done", code: 1 });
2118
+ return;
2119
+ }
2120
+ // A provider selected in the environment whose credential set is
2121
+ // incomplete: naming the provider, not offering a sign-in.
2122
+ var providerFailure = providerFailureFor(session, session.vendor);
2123
+ if (providerFailure) {
2124
+ sendAndRecord(session, { type: "error", text: providerFailure.message });
2125
+ sendAndRecord(session, { type: "done", code: 1 });
2126
+ return;
2127
+ }
2128
+ var authMsg2 = {
2129
+ type: "auth_required",
2130
+ text: authFacts2.title,
2131
+ vendor: authFacts2.vendor,
2132
+ loginCommand: authFacts2.loginCommand,
2133
+ linuxUser: authLinuxUser,
2134
+ canAutoLogin: canAutoLogin,
2135
+ };
2136
+ sendAndRecord(session, authMsg2);
2137
+ notifyAuthRequired(session, authFacts2.title, authLinuxUser, canAutoLogin, authFacts2.loginCommand);
2138
+ sendAndRecord(session, { type: "done", code: 1 });
2139
+ return;
2140
+ }
2141
+ // The session carries a vendor here (ensureSessionVendor above).
2142
+ var sessionAdapter = adapters[session.vendor] || adapter;
2143
+ // Console session ids repeat across projects, so the line names the project.
2144
+ // The prompt text is not logged.
2145
+ console.log("[sdk-bridge] startQuery: project=" + slug + " vendor=" + sessionAdapter.vendor + " session=" + session.localId);
2146
+
2029
2147
  // Wait for previous worker to fully exit before spawning a new one.
2030
2148
  // Without this, the new worker may try to resume the SDK session file
2031
2149
  // while the old worker is still flushing it to disk, causing
@@ -2132,7 +2250,7 @@ function createSDKBridge(opts) {
2132
2250
  }
2133
2251
  // lr-5bd7 — capture the agent's declared model so we can override queryModel below.
2134
2252
  // The UI-selected model (sm.currentModel / session.model) must not override the
2135
- // agent's own model declaration (e.g. opus for holden).
2253
+ // agent's own model declaration (e.g. a named agent that declares opus).
2136
2254
  if (agentParsed && agentParsed.meta && agentParsed.meta.model) {
2137
2255
  _agentDeclaredModel = agentParsed.meta.model;
2138
2256
  console.log("[sdk-bridge] agent declared model for " + session.agentName + ": " + _agentDeclaredModel);
@@ -2502,13 +2620,34 @@ function createSDKBridge(opts) {
2502
2620
  // turn with the agent's queue kept (Stop, the AbortController, is a different
2503
2621
  // path and is not touched). Resolves { stillQueued: string[]|null }; rejects
2504
2622
  // when the agent cannot interrupt or no query is live.
2623
+ var interruptSeq = 0;
2505
2624
  function interruptKeepingQueued(session) {
2506
2625
  var handle = session.queryInstance;
2507
2626
  if (!handle || typeof handle.interruptKeepingQueued !== "function") {
2508
2627
  return Promise.reject(new Error("This agent cannot interrupt the running turn."));
2509
2628
  }
2510
2629
  bumpLastActivity(session, "send-now-interrupt", slug);
2511
- return handle.interruptKeepingQueued();
2630
+ // Marked before the interrupt: the turn's result can arrive ahead of the
2631
+ // interrupt's reply, and the result handler must already know the abort is ours.
2632
+ // The marker is a per-interrupt token, so a late failure of an older interrupt
2633
+ // cannot clear the marker a newer interrupt has set.
2634
+ var token = ++interruptSeq;
2635
+ session.selfCausedInterrupt = { token: token, seq: session.queryReceiveSeq || 0 };
2636
+ console.log("[sdk-bridge] Send now interrupt requested: project=" + slug + " session=" + session.localId);
2637
+ function clearOwnMarker() {
2638
+ if (session.selfCausedInterrupt && session.selfCausedInterrupt.token === token) session.selfCausedInterrupt = false;
2639
+ }
2640
+ var pending;
2641
+ try {
2642
+ pending = handle.interruptKeepingQueued();
2643
+ } catch (err) {
2644
+ clearOwnMarker();
2645
+ throw err;
2646
+ }
2647
+ return Promise.resolve(pending).catch(function (err) {
2648
+ clearOwnMarker();
2649
+ throw err;
2650
+ });
2512
2651
  }
2513
2652
 
2514
2653
  function permissionPushTitle(toolName, input) {
@@ -8,10 +8,11 @@ var sessionActivity = require("./session-activity");
8
8
  var queuedChat = require("./queued-chat");
9
9
  var yokeRegistry = require("./yoke").registry;
10
10
  var usageStore = require("./usage-store");
11
+ var planUsageReader = require("./plan-usage-reader").createPlanUsageReader();
11
12
 
12
13
  var { authRequiredFacts } = require("./vendor-auth");
13
14
  var sessionReclaim = require("./session-reclaim");
14
- var { withPromptLabel } = require("./prompt-label");
15
+ var backgroundTasks = require("./session-background-tasks");
15
16
  var { isAgentDispatchTool } = require("./agent-dispatch-tool");
16
17
  var { bumpLastActivity } = require("./activity-clock");
17
18
 
@@ -420,12 +421,16 @@ function attachMessageProcessor(ctx) {
420
421
  if (parsed.model) {
421
422
  sm.currentModel = sm.currentModel || sm._savedDefaultModel || parsed.model;
422
423
  var initVendor = usageStore.usageVendorFor(session, adapter);
423
- send({
424
+ // Only the clients on this session hear its init: a project-wide send
425
+ // let one session's query set the vendor of a browser on another. The
426
+ // id lets a client that is on a different session drop it too.
427
+ sendToSession(session, {
424
428
  type: "model_info",
425
429
  model: sm.currentModel,
426
430
  models: getModelsForVendor(initVendor),
427
431
  vendor: initVendor,
428
432
  availableVendors: sm.availableVendors || [],
433
+ sessionId: session.localId,
429
434
  });
430
435
  }
431
436
  if (parsed.fastModeState) {
@@ -608,19 +613,8 @@ function attachMessageProcessor(ctx) {
608
613
  sessionReclaim.noteTaskLabel(session, block.id, input);
609
614
  }
610
615
 
611
- if (pushModule && block.name === "AskUserQuestion" && input.questions) {
612
- var q = input.questions[0];
613
- // Content carries prompt text: owner only, never a blind broadcast.
614
- // The prompt's id is the tool call's id.
615
- notifyFor(pushModule).notify("ask_user", {
616
- slug: slug,
617
- sessionId: session.localId,
618
- requestId: block.id,
619
- }, {
620
- title: "Claude has a question",
621
- body: withPromptLabel(promptsFor(sm).labelFor(session, block.id), q ? q.question : "Waiting for your response"),
622
- }, { ownerId: session.ownerId });
623
- }
616
+ // The ask_user push and banner are raised where the prompt opens
617
+ // (sdk-bridge handleCanUseTool), so a denied call raises none.
624
618
  } else if (block && block.type === "thinking") {
625
619
  var duration = block.startTime ? (Date.now() - block.startTime) / 1000 : 0;
626
620
  sendAndRecord(session, { type: "thinking_stop", duration: duration });
@@ -668,6 +662,13 @@ function attachMessageProcessor(ctx) {
668
662
  }
669
663
  }
670
664
 
665
+ // Fallback source of the live background task set, for a CLI that never
666
+ // emits background_tasks_changed: the Bash launch result names its task,
667
+ // and the matching task_notification (any status) removes it.
668
+ if (parsed.backgroundTaskId) {
669
+ backgroundTasks.add(session, parsed.backgroundTaskId, "local_bash", "background command");
670
+ }
671
+
671
672
  if (Array.isArray(content)) {
672
673
  for (var i = 0; i < content.length; i++) {
673
674
  var block = content[i];
@@ -741,11 +742,31 @@ function attachMessageProcessor(ctx) {
741
742
  var resultVendor = usageStore.usageVendorFor(session, adapter);
742
743
  if (confirmsUsageByResult(resultVendor) && isSuccessfulResult(parsed)) {
743
744
  usageStore.confirm(resultVendor, { sessionLocalId: session.localId, processKey: session.queryInstance });
745
+ // A low utilization is never in a rate-limit event, so the adapter is
746
+ // also asked for the plan numbers (rate-limited, and silent on failure).
747
+ planUsageReader.maybeRead(session.queryInstance, resultVendor);
744
748
  }
745
749
  console.log("[sdk-bridge] result handler: project " + slug + " session " + session.localId + " cost=" + parsed.cost + " rateLimitResetsAt=" + session.rateLimitResetsAt);
746
750
 
747
751
  // Handle SDK execution errors: show the error to the user instead of
748
752
  // silently swallowing it. These have subtype "error_during_execution".
753
+ // A Send now interrupt marks the session; the marker belongs to the next
754
+ // result of any kind, so a later unrelated abort still shows its error.
755
+ // The marker proves timing, not cause: a result is ours only when the stream
756
+ // yielded it after the marker was set, and a Stop on this query voids it.
757
+ var marker = session.selfCausedInterrupt;
758
+ var selfCaused = !!marker && !session.taskStopRequested
759
+ && typeof session.queryReceiveSeq === "number" && session.queryReceiveSeq > marker.seq;
760
+ session.selfCausedInterrupt = false;
761
+ if (parsed.subtype === "error_during_execution" && selfCaused
762
+ && (parsed.terminalReason === "aborted_streaming" || parsed.terminalReason === "aborted_tools")) {
763
+ setIsProcessingFromRegistry(session);
764
+ onProcessingChanged();
765
+ sendAndRecord(session, { type: "info", text: ctx.interruptMessageFor ? ctx.interruptMessageFor(session) : "Interrupted." });
766
+ sendAndRecord(session, { type: "done", code: 0 });
767
+ sm.broadcastSessionList();
768
+ return;
769
+ }
749
770
  if (parsed.subtype === "error_during_execution") {
750
771
  var execErrors = parsed.errors || [];
751
772
  var execError = execErrors.length > 0
@@ -755,7 +776,8 @@ function attachMessageProcessor(ctx) {
755
776
  console.error("[sdk-bridge] Execution error for session " + session.localId + ": " + execError);
756
777
  setIsProcessingFromRegistry(session);
757
778
  onProcessingChanged();
758
- sendAndRecord(session, { type: "error", text: "Claude error: " + execError });
779
+ var errorVendor = yokeRegistry.isKnown(resultVendor) ? yokeRegistry.displayNameFor(resultVendor) : "Agent";
780
+ sendAndRecord(session, { type: "error", text: errorVendor + " error: " + execError });
759
781
  sendAndRecord(session, { type: "done", code: 1 });
760
782
  sm.broadcastSessionList();
761
783
  return;
@@ -966,7 +988,13 @@ function attachMessageProcessor(ctx) {
966
988
  });
967
989
  }
968
990
 
991
+ } else if (parsed.yokeType === "background_tasks_changed") {
992
+ // REPLACE semantics: the payload is every live background task now.
993
+ backgroundTasks.replaceAll(session, parsed.tasks);
994
+
969
995
  } else if (parsed.yokeType === "task_notification") {
996
+ // Ends a background task of any type, with or without a parent tool call.
997
+ backgroundTasks.remove(session, parsed.taskId);
970
998
  var parentId = parsed.parentToolId;
971
999
  var notifiedPrompts = promptsFor(sm);
972
1000
  var parentOwnsLivePrompt = !!parentId && notifiedPrompts.taskOwnsPending(session, parentId);