@clagentic/console 1.12.0-beta.1 → 1.12.0-beta.3

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 (161) hide show
  1. package/LICENSES/README.md +5 -0
  2. package/README.md +1 -0
  3. package/bin/cli.js +5 -2
  4. package/lib/agent-roster-ws.js +84 -0
  5. package/lib/agent-roster.js +312 -0
  6. package/lib/auth-required-notify.js +42 -0
  7. package/lib/build-changes.js +8 -2
  8. package/lib/build-sha.json +2 -2
  9. package/lib/build-update-notify.js +45 -0
  10. package/lib/build-update-offer.js +34 -11
  11. package/lib/build-update-standing.js +34 -14
  12. package/lib/claude-settings-env.js +142 -0
  13. package/lib/cli/duration.js +27 -0
  14. package/lib/cli/schedule-input-subcommands.js +1 -22
  15. package/lib/cli/session-subcommands.js +60 -11
  16. package/lib/client-address.js +44 -0
  17. package/lib/daemon.js +31 -10
  18. package/lib/idle-compaction-setting.js +203 -0
  19. package/lib/mcp-bridge-credential.js +41 -0
  20. package/lib/notification-prefs.js +18 -22
  21. package/lib/notify/core.js +210 -0
  22. package/lib/notify/index.js +31 -0
  23. package/lib/notify/live-prompts.js +36 -0
  24. package/lib/notify/payload.js +62 -0
  25. package/lib/notify/target.js +5 -0
  26. package/lib/notify/type-registry.js +81 -0
  27. package/lib/notify/types.js +57 -0
  28. package/lib/open-sockets.js +27 -0
  29. package/lib/outbound-access.js +85 -0
  30. package/lib/outbound-entry.js +116 -0
  31. package/lib/outbound-ledger.js +306 -0
  32. package/lib/outbound-query.js +153 -0
  33. package/lib/pending-prompts.js +31 -16
  34. package/lib/project-connection.js +48 -8
  35. package/lib/project-filesystem.js +43 -5
  36. package/lib/project-http.js +9 -1
  37. package/lib/project-loop.js +38 -26
  38. package/lib/project-notifications.js +122 -39
  39. package/lib/project-prompt-responses.js +1 -1
  40. package/lib/project-sessions.js +11 -1
  41. package/lib/project-user-mention.js +22 -34
  42. package/lib/project-user-message.js +208 -4
  43. package/lib/project-user-shell.js +298 -0
  44. package/lib/project.js +41 -5
  45. package/lib/prompt-answer.js +145 -0
  46. package/lib/prompt-expiry.js +50 -0
  47. package/lib/prompt-registry.js +98 -25
  48. package/lib/prompt-reminders.js +38 -33
  49. package/lib/prompt-source.js +59 -8
  50. package/lib/public/app.js +32 -2
  51. package/lib/public/css/agent-messages.css +96 -0
  52. package/lib/public/css/agent-roster.css +93 -0
  53. package/lib/public/css/diagnostics.css +29 -1
  54. package/lib/public/css/home-hub.css +12 -0
  55. package/lib/public/css/icon-strip.css +9 -0
  56. package/lib/public/css/input.css +20 -141
  57. package/lib/public/css/login-panel.css +73 -0
  58. package/lib/public/css/menus.css +2 -2
  59. package/lib/public/css/mobile-nav.css +11 -0
  60. package/lib/public/css/sidebar.css +18 -0
  61. package/lib/public/css/team-panel.css +1 -6
  62. package/lib/public/css/team-view.css +101 -0
  63. package/lib/public/css/title-bar.css +10 -0
  64. package/lib/public/css/user-shell.css +144 -0
  65. package/lib/public/index.html +44 -7
  66. package/lib/public/modules/activity-state.js +20 -4
  67. package/lib/public/modules/agent-avatar-picker.js +162 -0
  68. package/lib/public/modules/agent-avatar.js +153 -0
  69. package/lib/public/modules/agent-messages.js +285 -0
  70. package/lib/public/modules/agent-roster.js +157 -0
  71. package/lib/public/modules/app-connection.js +34 -5
  72. package/lib/public/modules/app-messages.js +55 -16
  73. package/lib/public/modules/app-notifications.js +104 -75
  74. package/lib/public/modules/app-panels.js +26 -3
  75. package/lib/public/modules/app-projects.js +3 -1
  76. package/lib/public/modules/app-rate-limit.js +8 -165
  77. package/lib/public/modules/app-rendering.js +32 -7
  78. package/lib/public/modules/build-update-sessions.js +81 -0
  79. package/lib/public/modules/collapsible-text.js +33 -18
  80. package/lib/public/modules/compaction-state.js +34 -0
  81. package/lib/public/modules/custom-icons.js +23 -5
  82. package/lib/public/modules/diagnostics.js +61 -57
  83. package/lib/public/modules/env-shadow-notice.js +34 -0
  84. package/lib/public/modules/injected-identity.js +24 -21
  85. package/lib/public/modules/input.js +176 -15
  86. package/lib/public/modules/login-panel.js +136 -0
  87. package/lib/public/modules/login-parser.js +73 -0
  88. package/lib/public/modules/login-tab.js +66 -0
  89. package/lib/public/modules/notifications.js +9 -1
  90. package/lib/public/modules/notify-client.js +246 -0
  91. package/lib/public/modules/pending-term-request.js +30 -0
  92. package/lib/public/modules/project-icon.js +22 -2
  93. package/lib/public/modules/project-settings.js +5 -0
  94. package/lib/public/modules/prompt-state.js +3 -3
  95. package/lib/public/modules/prompts.js +1 -1
  96. package/lib/public/modules/queued-button.js +11 -0
  97. package/lib/public/modules/scheduled-input-actions.js +12 -4
  98. package/lib/public/modules/scheduled-outbox.js +230 -0
  99. package/lib/public/modules/send-now.js +200 -0
  100. package/lib/public/modules/server-settings.js +50 -1
  101. package/lib/public/modules/shell-card.js +76 -0
  102. package/lib/public/modules/shell-line.js +49 -0
  103. package/lib/public/modules/shell-queue.js +253 -0
  104. package/lib/public/modules/shell-settings-controls.js +76 -0
  105. package/lib/public/modules/sidebar-mobile.js +3 -3
  106. package/lib/public/modules/sidebar-sessions.js +8 -0
  107. package/lib/public/modules/sidebar-users.js +5 -7
  108. package/lib/public/modules/team-panel.js +30 -88
  109. package/lib/public/modules/team-view.js +211 -0
  110. package/lib/public/modules/terminal-links.js +193 -0
  111. package/lib/public/modules/terminal.js +84 -107
  112. package/lib/public/modules/tools.js +19 -0
  113. package/lib/public/modules/user-shell.js +824 -0
  114. package/lib/public/notify-sw-logic.js +252 -0
  115. package/lib/public/notify-target.js +157 -0
  116. package/lib/public/style.css +5 -0
  117. package/lib/public/sw.js +20 -69
  118. package/lib/push.js +63 -19
  119. package/lib/queued-chat.js +392 -0
  120. package/lib/runtime-env.js +1 -0
  121. package/lib/scheduled-input/ws.js +67 -9
  122. package/lib/sdk-bridge.js +184 -73
  123. package/lib/sdk-message-processor.js +124 -76
  124. package/lib/server-auth.js +6 -4
  125. package/lib/server-dm.js +11 -20
  126. package/lib/server-settings.js +39 -1
  127. package/lib/server.js +112 -16
  128. package/lib/session-directory.js +39 -12
  129. package/lib/session-end.js +97 -0
  130. package/lib/session-input-ipc.js +37 -1
  131. package/lib/session-input.js +263 -21
  132. package/lib/session-liveness.js +53 -0
  133. package/lib/session-reclaim.js +37 -2
  134. package/lib/session-resume.js +1 -0
  135. package/lib/session-settings-file.js +53 -0
  136. package/lib/sessions.js +80 -9
  137. package/lib/team-traffic-ws.js +68 -0
  138. package/lib/team-traffic.js +318 -0
  139. package/lib/usage-store.js +36 -7
  140. package/lib/user-shell-settings.js +105 -0
  141. package/lib/vendor-auth.js +33 -2
  142. package/lib/ws-schema.js +33 -5
  143. package/lib/yoke/adapters/claude-capabilities.js +2 -0
  144. package/lib/yoke/adapters/claude-vendor.js +17 -1
  145. package/lib/yoke/adapters/claude-worker.js +39 -11
  146. package/lib/yoke/adapters/claude.js +225 -6
  147. package/lib/yoke/adapters/codex-capabilities.js +6 -1
  148. package/lib/yoke/adapters/codex-user-shell.js +265 -0
  149. package/lib/yoke/adapters/codex-vendor.js +7 -0
  150. package/lib/yoke/adapters/codex.js +186 -52
  151. package/lib/yoke/auth-checks.js +17 -2
  152. package/lib/yoke/codex-app-server.js +8 -2
  153. package/lib/yoke/index.js +21 -3
  154. package/lib/yoke/interface.js +54 -1
  155. package/lib/yoke/mcp-bridge-server.js +12 -8
  156. package/lib/yoke/provider-credentials.js +24 -0
  157. package/lib/yoke/registry.js +40 -1
  158. package/lib/yoke/user-shell.js +224 -0
  159. package/package.json +2 -2
  160. package/scripts/check-test-count.js +14 -0
  161. package/lib/public/modules/build-notice-gate.js +0 -73
package/lib/sdk-bridge.js CHANGED
@@ -3,7 +3,9 @@ var path = require("path");
3
3
  var execSync = require("child_process").execSync;
4
4
  var execFileSync = require("child_process").execFileSync;
5
5
  var usersModule = require("./users");
6
- var { pushForSession } = require("./push-audience");
6
+ var openSockets = require("./open-sockets");
7
+ var { notifyFor } = require("./notify");
8
+ var { notifyAuthRequired: notifyAuthRequiredCore } = require("./auth-required-notify");
7
9
  var { getCodexConfig } = require("./codex-defaults");
8
10
  var { isAutoApprovableSegment } = require("./bash-auto-approve");
9
11
  var { splitShellSegments, hasUnapprovableShellSyntax, attachSkillDiscovery, discoverSkillsWithMeta, mergeSkillsWithMeta } = require("./sdk-skill-discovery");
@@ -13,9 +15,11 @@ var { parseFrontmatter, slugifyAgentName, AGENTS_SOURCE_DIR } = require("./agent
13
15
  var { discoverWorkflows } = require("./sdk-workflow-discovery");
14
16
  var { buildEnrichedSlashCommands } = require("./sdk-slash-enrichment");
15
17
  var { runPreflight } = require("./settings-preflight");
18
+ var { composeSettings } = require("./session-settings-file");
16
19
  var { promptsFor } = require("./prompt-registry");
17
20
  var { toolApprovalKind } = require("./prompt-kinds");
18
21
  var sessionActivity = require("./session-activity");
22
+ var queuedChat = require("./queued-chat");
19
23
  var sessionReclaim = require("./session-reclaim");
20
24
  var usageStore = require("./usage-store");
21
25
  var { withPromptLabel } = require("./prompt-label");
@@ -27,7 +31,7 @@ var mcpToolSchema = require("./mcp-tool-schema");
27
31
  var { registry: yokeRegistry } = require("./yoke");
28
32
  var sessionCapabilities = require("./session-capabilities");
29
33
  var { buildVendorRegistryMessage, recordInstallState } = require("./vendor-registry-message");
30
- var { authRequiredFacts } = require("./vendor-auth");
34
+ var { authRequiredFacts, providerAuthFailure } = require("./vendor-auth");
31
35
  var { bumpLastActivity } = require("./activity-clock");
32
36
  var { logField } = require("./log-field");
33
37
  var { debugLog } = require("./debug-log");
@@ -169,6 +173,7 @@ function buildActivityDiagnosticsResponse() {
169
173
  activeLiveCount: getActiveLiveCount(),
170
174
  activityDivergenceCount: divergence.count,
171
175
  activityDivergenceRecentSamples: divergence.recentSamples,
176
+ openSockets: openSockets.snapshot(),
172
177
  };
173
178
  }
174
179
 
@@ -422,7 +427,6 @@ function createSDKBridge(opts) {
422
427
  }
423
428
  var clayPort = opts.clayPort || 2633;
424
429
  var clayTls = opts.clayTls || false;
425
- var clayAuthToken = opts.clayAuthToken || null;
426
430
  var onProcessingChanged = opts.onProcessingChanged || function () {};
427
431
 
428
432
  // --- Environment saved in Settings ---
@@ -525,18 +529,37 @@ function createSDKBridge(opts) {
525
529
  var _cachedFreshAuthState = null;
526
530
  var _cachedFreshAuthAt = 0;
527
531
 
528
- function getFreshAuthState(force) {
532
+ var _cachedFreshAuthSig = null;
533
+
534
+ // The auth probes read the environment the session's runtime starts with
535
+ // (Settings over the daemon's), so a provider chosen in Settings counts.
536
+ function getFreshAuthState(force, session) {
529
537
  var yoke = require("./yoke");
530
538
  var now = Date.now();
531
- if (!force && _cachedFreshAuthState && now - _cachedFreshAuthAt < 15000) {
539
+ var overlay = getRuntimeEnvOverlay(session);
540
+ var sig = runtimeEnv.envSignature(overlay) + "\0" + (osUsersMode ? "os" : "");
541
+ if (!force && _cachedFreshAuthState && _cachedFreshAuthSig === sig && now - _cachedFreshAuthAt < 15000) {
532
542
  return _cachedFreshAuthState;
533
543
  }
534
544
  if (force) yoke.invalidateAuthCache();
535
- _cachedFreshAuthState = yoke.checkAuth();
545
+ _cachedFreshAuthState = yoke.checkAuth(overlay, osUsersMode);
546
+ _cachedFreshAuthSig = sig;
536
547
  _cachedFreshAuthAt = now;
537
548
  return _cachedFreshAuthState;
538
549
  }
539
550
 
551
+ // The environment a session's runtime is started with: the daemon's own,
552
+ // then the Settings variables. The same composition the spawn performs.
553
+ function getEffectiveRuntimeEnv(session) {
554
+ return runtimeEnv.composeRuntimeEnv(process.env, getRuntimeEnvOverlay(session));
555
+ }
556
+
557
+ // The message that replaces "not logged in" when the session's agent talks
558
+ // to a configured cloud provider, or null.
559
+ function providerFailureFor(session, vendorId) {
560
+ return providerAuthFailure(vendorId, getEffectiveRuntimeEnv(session), osUsersMode);
561
+ }
562
+
540
563
  function isAuthErrorMessage(errDetail) {
541
564
  if (!errDetail) return false;
542
565
  var errLower = String(errDetail).toLowerCase();
@@ -561,21 +584,16 @@ function createSDKBridge(opts) {
561
584
  : "Interrupted.";
562
585
  }
563
586
 
564
- function notifyAuthRequired(session, title, body, authLinuxUser, canAutoLogin, loginCommand) {
565
- var _nm = getNotificationsModule();
566
- if (!_nm) return false;
567
- _nm.notify("auth_required", {
568
- title: title,
569
- body: body,
587
+ function notifyAuthRequired(session, title, authLinuxUser, canAutoLogin, loginCommand) {
588
+ return notifyAuthRequiredCore(pushModule, getNotificationsModule(), {
570
589
  slug: slug,
571
- sessionId: session.localId,
572
- ownerId: session.ownerId || null,
590
+ session: session,
591
+ title: title,
573
592
  vendor: session.vendor || (adapter && adapter.vendor) || "claude",
574
593
  loginCommand: loginCommand,
575
594
  linuxUser: authLinuxUser,
576
595
  canAutoLogin: canAutoLogin,
577
596
  });
578
- return true;
579
597
  }
580
598
 
581
599
  function logAuthDecision(stage, session, errDetail, authState) {
@@ -744,7 +762,10 @@ function createSDKBridge(opts) {
744
762
 
745
763
  // Skip sessions that are actively processing, have no query,
746
764
  // or are single-turn (Ralph Loop — managed by onQueryComplete).
747
- if (session.isProcessing) return;
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;
748
769
  if (!session.queryInstance) return;
749
770
  if (session.singleTurn) return;
750
771
 
@@ -860,6 +881,7 @@ function createSDKBridge(opts) {
860
881
  refreshAiTitle: refreshAiTitle,
861
882
  onTeamCreate: opts.onTeamCreate || null,
862
883
  onTeamDelete: opts.onTeamDelete || null,
884
+ onAgentSeen: opts.onAgentSeen || null,
863
885
  opts: opts,
864
886
  discoverSkillDirs: discoverSkillDirs,
865
887
  mergeSkills: mergeSkills,
@@ -869,6 +891,7 @@ function createSDKBridge(opts) {
869
891
  // a shared multi-user daemon. usersModule.findUserById(session.ownerId)
870
892
  // is the same pattern already used elsewhere in this file (getFreshAuthState).
871
893
  resolveSessionHome: resolveOwnerHome,
894
+ providerFailureFor: providerFailureFor,
872
895
  });
873
896
  var processSDKMessage = msgProcessor.processSDKMessage;
874
897
  var sendAndRecord = msgProcessor.sendAndRecord;
@@ -886,15 +909,15 @@ function createSDKBridge(opts) {
886
909
 
887
910
  // No push for a prompt that ended at once (its signal was already aborted).
888
911
  if (pushModule && opened.pending) {
889
- var _elicitPayload = {
890
- type: "elicitation",
912
+ // Body carries MCP message text: owner only, never a blind broadcast.
913
+ notifyFor(pushModule).notify("elicitation", {
891
914
  slug: slug,
915
+ sessionId: session.localId,
916
+ requestId: opened.requestId,
917
+ }, {
892
918
  title: (request.serverName || "MCP Server") + " needs input",
893
919
  body: withPromptLabel(opened.label, request.message || "Waiting for your response"),
894
- tag: "claude-elicitation",
895
- };
896
- // Body carries MCP message text: owner only, never a blind broadcast.
897
- pushForSession(pushModule, session.ownerId, _elicitPayload);
920
+ }, { ownerId: session.ownerId });
898
921
  }
899
922
 
900
923
  return opened.answer;
@@ -1072,6 +1095,12 @@ function createSDKBridge(opts) {
1072
1095
  });
1073
1096
  }
1074
1097
 
1098
+ // Whether the session's vendor declares the additive-settings capability.
1099
+ function supportsSettingsFile(session) {
1100
+ var vendor = sessionCapabilities.effectiveVendorId(sm, session, adapter && adapter.vendor);
1101
+ return sessionCapabilities.capabilitiesFor(sm, vendor).additiveSettings === true;
1102
+ }
1103
+
1075
1104
  // checkModeFor, with a refusal logged under `what`; true when the mode is allowed.
1076
1105
  function modeAllowed(session, mode, what, checkVendor) {
1077
1106
  var verdict = checkModeFor(session, mode, checkVendor);
@@ -1150,16 +1179,8 @@ function createSDKBridge(opts) {
1150
1179
  }
1151
1180
 
1152
1181
  // Regular tool permission request: send to client and wait
1153
- // TODO(lr-9d4b): unlike the worker path's canUseTool (claude-worker.js:315,
1154
- // 30s auto-deny), this in-process path has no timeout, so an orphaned
1155
- // resolver (e.g. one whose owning session/sub-agent tracking bug is not
1156
- // yet known) wedges the turn forever instead of failing closed. Deferred
1157
- // out of this PR: a uniform timeout here would also auto-deny normal
1158
- // foreground human-review latency for every non-sub-agent permission
1159
- // request in the in-process path, which is a broader behavior change than
1160
- // this hang-fix should bundle silently. Needs a design pass (e.g. scope
1161
- // the timeout to sub-agent-owned entries only, or make it operator-
1162
- // configurable) rather than copying the worker's blanket 30s.
1182
+ // The registry bounds the wait (daemon.json promptExpiryMinutes) and
1183
+ // fails closed when it ends.
1163
1184
  // The registry creates the notification and dismisses it when the
1164
1185
  // prompt settles.
1165
1186
  // A prompt raised by a background agent says so, on the card, the banner
@@ -1183,28 +1204,16 @@ function createSDKBridge(opts) {
1183
1204
  notification: {
1184
1205
  title: agentPrefix + permissionPushTitle(toolName, input),
1185
1206
  body: permissionPushBody(toolName, input),
1207
+ // Body carries tool name and input (may contain paths/code); the core
1208
+ // sends it to the session's owner only, never as a blind broadcast.
1209
+ push: { title: agentPrefix + permissionPushTitle(toolName, input), body: permissionPushBody(toolName, input) },
1186
1210
  slug: slug,
1187
1211
  sessionId: session.localId,
1188
- ownerId: session.ownerId || null,
1189
1212
  toolName: toolName,
1190
1213
  toolInput: input,
1191
1214
  },
1192
1215
  });
1193
1216
 
1194
- // No push for a prompt that ended at once (its signal was already aborted).
1195
- if (pushModule && opened.pending) {
1196
- var _permPayload = {
1197
- type: "permission_request",
1198
- slug: slug,
1199
- requestId: opened.requestId,
1200
- title: agentPrefix + permissionPushTitle(toolName, input),
1201
- body: withPromptLabel(opened.label, permissionPushBody(toolName, input)),
1202
- };
1203
- // Body carries tool name and input (may contain paths/code): owner only,
1204
- // never a blind broadcast.
1205
- pushForSession(pushModule, session.ownerId, _permPayload);
1206
- }
1207
-
1208
1217
  return opened.answer;
1209
1218
  }
1210
1219
 
@@ -1397,13 +1406,19 @@ function createSDKBridge(opts) {
1397
1406
  || errLower.indexOf("context_length") !== -1
1398
1407
  || errLower.indexOf("maximum context length") !== -1;
1399
1408
  var isAuthError = isAuthErrorMessage(errDetail);
1409
+ var providerFail = null;
1400
1410
  if (isContextOverflow) {
1401
1411
  sendAndRecord(session, {
1402
1412
  type: "context_overflow",
1403
1413
  text: "Conversation too long to continue.",
1404
1414
  });
1415
+ } else if (isAuthError && (providerFail = providerFailureFor(session, sessionVendorId(session)))) {
1416
+ sendAndRecord(session, { type: "error", text: providerFail.message });
1417
+ sendAndRecord(session, { type: "done", code: 1 });
1418
+ sm.broadcastSessionList();
1419
+ return;
1405
1420
  } else if (isAuthError) {
1406
- var freshAuth = getFreshAuthState();
1421
+ var freshAuth = getFreshAuthState(false, session);
1407
1422
  logAuthDecision("catch-auth-error", session, errDetail, freshAuth);
1408
1423
  if (freshAuth[session.vendor]) {
1409
1424
  sendAndRecord(session, {
@@ -1428,16 +1443,7 @@ function createSDKBridge(opts) {
1428
1443
  canAutoLogin: canAutoLogin,
1429
1444
  };
1430
1445
  sendAndRecord(session, authMsg);
1431
- if (!notifyAuthRequired(
1432
- session,
1433
- authFacts.title,
1434
- "Open a terminal, then click the URL and follow the instructions.",
1435
- authLinuxUser,
1436
- canAutoLogin,
1437
- authFacts.loginCommand
1438
- )) {
1439
- // chat message already sent above
1440
- }
1446
+ notifyAuthRequired(session, authFacts.title, authLinuxUser, canAutoLogin, authFacts.loginCommand);
1441
1447
  } else {
1442
1448
  sendAndRecord(session, { type: "error", text: "Claude process error: " + err.message });
1443
1449
  }
@@ -1455,6 +1461,13 @@ function createSDKBridge(opts) {
1455
1461
  // Only clean up if the session still references OUR resources.
1456
1462
  // A rewind + new startQuery may have already replaced these with
1457
1463
  // a newer query — clobbering them would kill the new query.
1464
+ // Chat pushed into this query that it never took in will not be delivered
1465
+ // now that the query is over: the page is told, so it can hand the text
1466
+ // back instead of showing it as queued for ever. Not behind the ownership
1467
+ // check below: after a rewind unlinks this query the session may already
1468
+ // hold a newer one, and this query's messages are still orphans. Only this
1469
+ // query's own messages go; the newer query's are left alone.
1470
+ queuedChat.dropAll(session, myQueryInstance);
1458
1471
  if (session.queryInstance === myQueryInstance) {
1459
1472
  try {
1460
1473
  if (typeof session.queryInstance.close === "function") {
@@ -1527,6 +1540,10 @@ function createSDKBridge(opts) {
1527
1540
  promptsFor(sm).endQuery(session, myQueryInstance, ownsSession);
1528
1541
  if (ownsSession) {
1529
1542
  msgProcessor.retainTaskIdMap(session);
1543
+ // The query's end took its background agents down; only a Task still
1544
+ // owning an open prompt stays tracked, so every other token (a
1545
+ // launched agent's included) is released here.
1546
+ msgProcessor.releaseTurnActivity(session);
1530
1547
 
1531
1548
  // Auto-continue on rate limit (scheduler sessions, or user setting)
1532
1549
  // Mark session as done processing so the late rate_limit_event handler
@@ -1725,7 +1742,6 @@ function createSDKBridge(opts) {
1725
1742
  linuxUser: linuxUser || undefined,
1726
1743
  clayPort: clayPort,
1727
1744
  clayTls: clayTls,
1728
- clayAuthToken: clayAuthToken,
1729
1745
  slug: slug,
1730
1746
  }), recordInit);
1731
1747
  } else if ((!sm.modelsByVendor || !sm.modelsByVendor[vendor]) && typeof vendorAdapter.init === "function") {
@@ -1734,7 +1750,6 @@ function createSDKBridge(opts) {
1734
1750
  linuxUser: linuxUser || undefined,
1735
1751
  clayPort: clayPort,
1736
1752
  clayTls: clayTls,
1737
- clayAuthToken: clayAuthToken,
1738
1753
  slug: slug,
1739
1754
  })));
1740
1755
  }
@@ -1772,7 +1787,7 @@ function createSDKBridge(opts) {
1772
1787
  await ensureVendorReady(session.vendor);
1773
1788
  }
1774
1789
  if (session.vendor && !adapters[session.vendor]) {
1775
- var freshAuth = getFreshAuthState();
1790
+ var freshAuth = getFreshAuthState(false, session);
1776
1791
  logAuthDecision("pre-auth-required", session, null, freshAuth);
1777
1792
  if (freshAuth[session.vendor]) {
1778
1793
  var recoveredAdapter = await ensureVendorReady(session.vendor);
@@ -1789,7 +1804,7 @@ function createSDKBridge(opts) {
1789
1804
  var authLinuxUser = authUser && authUser.linuxUser ? authUser.linuxUser : null;
1790
1805
  var canAutoLogin = !!authLinuxUser
1791
1806
  || (authUser && authUser.role === "admin");
1792
- var authState = getFreshAuthState();
1807
+ var authState = getFreshAuthState(false, session);
1793
1808
  logAuthDecision("emit-auth-required", session, "missing adapter", authState);
1794
1809
  if (authState[session.vendor]) {
1795
1810
  sendAndRecord(session, {
@@ -1799,6 +1814,14 @@ function createSDKBridge(opts) {
1799
1814
  sendAndRecord(session, { type: "done", code: 1 });
1800
1815
  return;
1801
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
+ }
1802
1825
  var authMsg2 = {
1803
1826
  type: "auth_required",
1804
1827
  text: authFacts2.title,
@@ -1808,16 +1831,7 @@ function createSDKBridge(opts) {
1808
1831
  canAutoLogin: canAutoLogin,
1809
1832
  };
1810
1833
  sendAndRecord(session, authMsg2);
1811
- if (!notifyAuthRequired(
1812
- session,
1813
- authFacts2.title,
1814
- "Open a terminal, then click the URL and follow the instructions.",
1815
- authLinuxUser,
1816
- canAutoLogin,
1817
- authFacts2.loginCommand
1818
- )) {
1819
- // chat message already sent above
1820
- }
1834
+ notifyAuthRequired(session, authFacts2.title, authLinuxUser, canAutoLogin, authFacts2.loginCommand);
1821
1835
  sendAndRecord(session, { type: "done", code: 1 });
1822
1836
  return;
1823
1837
  }
@@ -1862,6 +1876,28 @@ function createSDKBridge(opts) {
1862
1876
  return;
1863
1877
  }
1864
1878
 
1879
+ // A session's additive settings file must still be usable on every turn,
1880
+ // a resumed one included: a missing or unreadable file fails the turn
1881
+ // rather than running without it.
1882
+ var sessionSettings = null;
1883
+ if (session.settingsFile) {
1884
+ var loopSettings = session.loopSettings || {};
1885
+ var fileCheck = composeSettings(
1886
+ session.settingsFile,
1887
+ loopSettings.disableAllHooks !== undefined ? { disableAllHooks: loopSettings.disableAllHooks } : null
1888
+ );
1889
+ if (!fileCheck.error) sessionSettings = fileCheck.settings;
1890
+ if (fileCheck.error) {
1891
+ console.warn("[sdk-bridge] " + fileCheck.error + " — refusing the turn for project " + slug + " session " + session.localId);
1892
+ session.isProcessing = false;
1893
+ onProcessingChanged();
1894
+ sendAndRecord(session, { type: "error", text: fileCheck.error });
1895
+ sendAndRecord(session, { type: "done", code: 1 });
1896
+ sm.broadcastSessionList();
1897
+ return;
1898
+ }
1899
+ }
1900
+
1865
1901
  // lr-2d91: MemAvailable gate — check before claiming a slot so a rejected
1866
1902
  // query never increments the live counter.
1867
1903
  if (isNewQuery) {
@@ -2061,6 +2097,10 @@ function createSDKBridge(opts) {
2061
2097
  var _injectionVendor = sessionCapabilities.effectiveVendorId(sm, session, sessionAdapter.vendor);
2062
2098
  if (session.agentName && sessionCapabilities.capabilitiesFor(sm, _injectionVendor).agentInjection) {
2063
2099
  claudeOpts.agent = session.agentName;
2100
+ // The agent the session runs as is an identity the roster records, as named.
2101
+ if (typeof opts.onAgentSeen === "function") {
2102
+ opts.onAgentSeen({ key: session.agentName, source: "session", project: slug, sessionId: String(session.localId) });
2103
+ }
2064
2104
 
2065
2105
  // lr-3ccc78 — on a shared multi-user daemon (linuxUser set), read the
2066
2106
  // session owner's own ~/.claude/agents, not the daemon process's
@@ -2125,6 +2165,8 @@ function createSDKBridge(opts) {
2125
2165
  if (ls.disableAllHooks !== undefined) {
2126
2166
  claudeOpts.settings = Object.assign({}, claudeOpts.settings || {}, { disableAllHooks: ls.disableAllHooks });
2127
2167
  }
2168
+ // The session's settings file and the object above both apply (composed before the slot was claimed).
2169
+ if (sessionSettings !== null) claudeOpts.settings = sessionSettings;
2128
2170
 
2129
2171
  var globalMode = session.permissionMode || sm.currentPermissionMode || "default";
2130
2172
  // A stored mode (session file, saved default) is checked again here: a
@@ -2406,6 +2448,69 @@ function createSDKBridge(opts) {
2406
2448
  }
2407
2449
  }
2408
2450
 
2451
+ // Send-now: deliver a message into the running turn. Resolves
2452
+ // { steered, reason }. An agent whose resolved capabilities lack steering, or
2453
+ // a session with no live query, takes the message down the normal path
2454
+ // (steered false). An agent whose handle has no steerMessage of its own takes
2455
+ // the live input stream, which is where its running turn reads from.
2456
+ function canSteer(session) {
2457
+ var vendor = sessionCapabilities.effectiveVendorId(sm, session, adapter && adapter.vendor);
2458
+ return sessionCapabilities.capabilitiesFor(sm, vendor).steering === true;
2459
+ }
2460
+
2461
+ function steerMessage(session, text, images, initiator, messageId) {
2462
+ var canSteer_ = canSteer(session);
2463
+ var handle = session.queryInstance;
2464
+ if (!canSteer_ || !handle || typeof handle.pushMessage !== "function") {
2465
+ pushMessage(session, text, images, initiator, messageId);
2466
+ return Promise.resolve({ steered: false, reason: canSteer_ ? "no-running-turn" : "unsupported" });
2467
+ }
2468
+ bumpLastActivity(session, "push-message", slug);
2469
+ if (typeof handle.steerMessage === "function") {
2470
+ return handle.steerMessage(text, images, initiator, messageId);
2471
+ }
2472
+ handle.pushMessage(text, images, initiator, messageId);
2473
+ return Promise.resolve({ steered: true });
2474
+ }
2475
+
2476
+ // Withdrawing a message pushed into a running turn (queuedMessageCancel).
2477
+ function canCancelQueued(session) {
2478
+ var vendor = sessionCapabilities.effectiveVendorId(sm, session, adapter && adapter.vendor);
2479
+ return sessionCapabilities.capabilitiesFor(sm, vendor).queuedMessageCancel === true;
2480
+ }
2481
+
2482
+ // Resolves true when the message was withdrawn before the agent took it, false
2483
+ // when it was already taken or is unknown, and rejects when the agent cannot
2484
+ // say. A message still buffered between turns (no live query yet) is dropped
2485
+ // from the buffer, which is the same withdrawal.
2486
+ function cancelQueuedMessage(session, messageId) {
2487
+ var handle = session.queryInstance;
2488
+ if (handle && typeof handle.cancelQueuedMessage === "function") {
2489
+ return handle.cancelQueuedMessage(messageId);
2490
+ }
2491
+ var buffered = session.pendingMessages || [];
2492
+ for (var i = 0; i < buffered.length; i++) {
2493
+ if (buffered[i].messageId === messageId) {
2494
+ buffered.splice(i, 1);
2495
+ return Promise.resolve(true);
2496
+ }
2497
+ }
2498
+ return Promise.resolve(false);
2499
+ }
2500
+
2501
+ // Send now on a message already pushed into the running query: interrupts the
2502
+ // turn with the agent's queue kept (Stop, the AbortController, is a different
2503
+ // path and is not touched). Resolves { stillQueued: string[]|null }; rejects
2504
+ // when the agent cannot interrupt or no query is live.
2505
+ function interruptKeepingQueued(session) {
2506
+ var handle = session.queryInstance;
2507
+ if (!handle || typeof handle.interruptKeepingQueued !== "function") {
2508
+ return Promise.reject(new Error("This agent cannot interrupt the running turn."));
2509
+ }
2510
+ bumpLastActivity(session, "send-now-interrupt", slug);
2511
+ return handle.interruptKeepingQueued();
2512
+ }
2513
+
2409
2514
  function permissionPushTitle(toolName, input) {
2410
2515
  if (!input) return "Claude wants to use " + toolName;
2411
2516
  var file = input.file_path ? input.file_path.split(/[/\\]/).pop() : "";
@@ -2469,7 +2574,6 @@ function createSDKBridge(opts) {
2469
2574
  linuxUser: linuxUser || undefined,
2470
2575
  clayPort: clayPort,
2471
2576
  clayTls: clayTls,
2472
- clayAuthToken: clayAuthToken,
2473
2577
  slug: slug,
2474
2578
  }));
2475
2579
 
@@ -2696,10 +2800,16 @@ function createSDKBridge(opts) {
2696
2800
  forkSession: forkSessionUnified,
2697
2801
  startQuery: startQuery,
2698
2802
  pushMessage: pushMessage,
2803
+ steerMessage: steerMessage,
2804
+ canSteer: canSteer,
2805
+ canCancelQueued: canCancelQueued,
2806
+ cancelQueuedMessage: cancelQueuedMessage,
2807
+ interruptKeepingQueued: interruptKeepingQueued,
2699
2808
  setModel: setModel,
2700
2809
  setEffort: setEffort,
2701
2810
  setPermissionMode: setPermissionMode,
2702
2811
  checkModeFor: checkModeFor,
2812
+ supportsSettingsFile: supportsSettingsFile,
2703
2813
  isClaudeProcess: isClaudeProcess,
2704
2814
  permissionPushTitle: permissionPushTitle,
2705
2815
  permissionPushBody: permissionPushBody,
@@ -2709,6 +2819,7 @@ function createSDKBridge(opts) {
2709
2819
  startIdleReaper: startIdleReaper,
2710
2820
  stopIdleReaper: stopIdleReaper,
2711
2821
  getRuntimeEnvOverlay: getRuntimeEnvOverlay,
2822
+ providerFailureFor: providerFailureFor,
2712
2823
  getMemoryStats: getMemoryStats,
2713
2824
  refreshAiTitle: refreshAiTitle,
2714
2825
  };