@songsid/agend 2.4.0-beta.11 → 2.4.0-beta.13

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 (214) hide show
  1. package/dist/accounts-view.d.ts +29 -0
  2. package/dist/accounts-view.js +2 -14
  3. package/dist/accounts-view.js.map +1 -1
  4. package/dist/agent-endpoint.d.ts +1 -0
  5. package/dist/agent-endpoint.js +4 -2
  6. package/dist/agent-endpoint.js.map +1 -1
  7. package/dist/auth-api.d.ts +2 -0
  8. package/dist/auth-api.js +33 -2
  9. package/dist/auth-api.js.map +1 -1
  10. package/dist/backend/codex.js +11 -0
  11. package/dist/backend/codex.js.map +1 -1
  12. package/dist/backend/types.d.ts +1 -1
  13. package/dist/build-provenance.json +1 -1
  14. package/dist/channel/mcp-server.js +1 -1
  15. package/dist/channel/mcp-server.js.map +1 -1
  16. package/dist/channel/mcp-tools.js +3 -1
  17. package/dist/channel/mcp-tools.js.map +1 -1
  18. package/dist/claude-install-kind.d.ts +19 -0
  19. package/dist/claude-install-kind.js +54 -0
  20. package/dist/claude-install-kind.js.map +1 -0
  21. package/dist/daemon.d.ts +13 -1
  22. package/dist/daemon.js +54 -9
  23. package/dist/daemon.js.map +1 -1
  24. package/dist/dispatcher-liveness.js +2 -2
  25. package/dist/dispatcher-liveness.js.map +1 -1
  26. package/dist/fleet-manager.d.ts +110 -1
  27. package/dist/fleet-manager.js +387 -25
  28. package/dist/fleet-manager.js.map +1 -1
  29. package/dist/general-knowledge/skills/credential-profiles/SKILL.md +7 -0
  30. package/dist/general-knowledge/skills/hub/SKILL.md +25 -0
  31. package/dist/general-knowledge/skills/web-dashboard/SKILL.md +6 -0
  32. package/dist/hub/agent-intro-model.d.ts +38 -0
  33. package/dist/hub/agent-intro-model.js +14 -0
  34. package/dist/hub/agent-intro-model.js.map +1 -0
  35. package/dist/hub/agent-intro-tool.d.ts +35 -0
  36. package/dist/hub/agent-intro-tool.js +83 -0
  37. package/dist/hub/agent-intro-tool.js.map +1 -0
  38. package/dist/hub/client.d.ts +1 -0
  39. package/dist/hub/client.js +26 -0
  40. package/dist/hub/client.js.map +1 -1
  41. package/dist/hub/compose/member.d.ts +13 -5
  42. package/dist/hub/compose/member.js +28 -5
  43. package/dist/hub/compose/member.js.map +1 -1
  44. package/dist/hub/compose/server.d.ts +1 -0
  45. package/dist/hub/compose/server.js +5 -1
  46. package/dist/hub/compose/server.js.map +1 -1
  47. package/dist/hub/http/compose.d.ts +1 -0
  48. package/dist/hub/http/compose.js +28 -5
  49. package/dist/hub/http/compose.js.map +1 -1
  50. package/dist/hub/http/schema.js +6 -0
  51. package/dist/hub/http/schema.js.map +1 -1
  52. package/dist/hub/member/agent-intro.d.ts +28 -0
  53. package/dist/hub/member/agent-intro.js +66 -0
  54. package/dist/hub/member/agent-intro.js.map +1 -0
  55. package/dist/hub/member/room-ask.d.ts +10 -0
  56. package/dist/hub/member/room-ask.js +70 -7
  57. package/dist/hub/member/room-ask.js.map +1 -1
  58. package/dist/hub/member/room-notification.d.ts +1 -1
  59. package/dist/hub/member/room-post.d.ts +6 -3
  60. package/dist/hub/member/room-post.js +9 -3
  61. package/dist/hub/member/room-post.js.map +1 -1
  62. package/dist/hub/protocol.d.ts +172 -4
  63. package/dist/hub/protocol.js +10 -5
  64. package/dist/hub/protocol.js.map +1 -1
  65. package/dist/hub/room-answer-status-model.d.ts +3 -0
  66. package/dist/hub/room-answer-status-model.js +4 -0
  67. package/dist/hub/room-answer-status-model.js.map +1 -0
  68. package/dist/hub/room-brief-model.d.ts +30 -0
  69. package/dist/hub/room-brief-model.js +37 -0
  70. package/dist/hub/room-brief-model.js.map +1 -0
  71. package/dist/hub/room-context-model.d.ts +2 -0
  72. package/dist/hub/room-context-model.js +2 -2
  73. package/dist/hub/room-context-model.js.map +1 -1
  74. package/dist/hub/room-members-model.d.ts +63 -0
  75. package/dist/hub/room-members-model.js +7 -0
  76. package/dist/hub/room-members-model.js.map +1 -0
  77. package/dist/hub/rooms/agents.js +50 -10
  78. package/dist/hub/rooms/agents.js.map +1 -1
  79. package/dist/hub/rooms/brief.d.ts +18 -0
  80. package/dist/hub/rooms/brief.js +39 -0
  81. package/dist/hub/rooms/brief.js.map +1 -0
  82. package/dist/hub/rooms/members-page.d.ts +33 -0
  83. package/dist/hub/rooms/members-page.js +37 -0
  84. package/dist/hub/rooms/members-page.js.map +1 -0
  85. package/dist/hub/rooms/purpose.d.ts +7 -0
  86. package/dist/hub/rooms/purpose.js +14 -0
  87. package/dist/hub/rooms/purpose.js.map +1 -0
  88. package/dist/hub/rooms/service.d.ts +11 -0
  89. package/dist/hub/rooms/service.js +56 -12
  90. package/dist/hub/rooms/service.js.map +1 -1
  91. package/dist/hub/rooms/types.d.ts +6 -2
  92. package/dist/hub/runtime.d.ts +1 -1
  93. package/dist/hub/server.js +27 -1
  94. package/dist/hub/server.js.map +1 -1
  95. package/dist/hub/types.d.ts +9 -5
  96. package/dist/hub-room-reply-warning.d.ts +2 -0
  97. package/dist/hub-room-reply-warning.js +16 -0
  98. package/dist/hub-room-reply-warning.js.map +1 -0
  99. package/dist/instance-lifecycle.d.ts +18 -0
  100. package/dist/instance-lifecycle.js +43 -4
  101. package/dist/instance-lifecycle.js.map +1 -1
  102. package/dist/locale.js +26 -0
  103. package/dist/locale.js.map +1 -1
  104. package/dist/login-controller.d.ts +26 -0
  105. package/dist/login-controller.js +72 -2
  106. package/dist/login-controller.js.map +1 -1
  107. package/dist/native-mcp.js +1 -1
  108. package/dist/native-mcp.js.map +1 -1
  109. package/dist/needs-you-hub.js +1 -1
  110. package/dist/needs-you-hub.js.map +1 -1
  111. package/dist/needs-you.d.ts +12 -1
  112. package/dist/needs-you.js +9 -0
  113. package/dist/needs-you.js.map +1 -1
  114. package/dist/office-share-page.js +1 -1
  115. package/dist/office-share-page.js.map +1 -1
  116. package/dist/outbound-handlers.d.ts +2 -1
  117. package/dist/outbound-handlers.js +19 -4
  118. package/dist/outbound-handlers.js.map +1 -1
  119. package/dist/outbound-schemas.d.ts +10 -0
  120. package/dist/outbound-schemas.js +3 -1
  121. package/dist/outbound-schemas.js.map +1 -1
  122. package/dist/pause-marker.d.ts +1 -1
  123. package/dist/pause-marker.js +1 -1
  124. package/dist/pause-marker.js.map +1 -1
  125. package/dist/public-web-gateway.d.ts +20 -0
  126. package/dist/public-web-gateway.js +66 -5
  127. package/dist/public-web-gateway.js.map +1 -1
  128. package/dist/restart-progress.d.ts +6 -0
  129. package/dist/restart-progress.js +5 -0
  130. package/dist/restart-progress.js.map +1 -1
  131. package/dist/settings-effect.js +17 -1
  132. package/dist/settings-effect.js.map +1 -1
  133. package/dist/tool-permissions.js +3 -3
  134. package/dist/tool-permissions.js.map +1 -1
  135. package/dist/ui/accounts-keepalive.js +2 -1
  136. package/dist/ui/accounts-view.js +2 -1
  137. package/dist/ui/chat-quote.js +3 -261
  138. package/dist/ui/fleet-canvas.js +3 -1
  139. package/dist/ui/fleet-office-skin.js +4 -3
  140. package/dist/ui/fleet-route.js +44 -6
  141. package/dist/ui/fleet-task-view.js +2 -1
  142. package/dist/ui/host-install.js +82 -5
  143. package/dist/ui/hub-agent-intro.js +15 -6
  144. package/dist/ui/hub-ai-apps.js +2 -1
  145. package/dist/ui/hub-attachments.js +81 -3
  146. package/dist/ui/hub-chat-strings.js +2 -1
  147. package/dist/ui/hub-client.js +4 -0
  148. package/dist/ui/hub-grant-picker.js +2 -1
  149. package/dist/ui/hub-group-strings.js +2 -1
  150. package/dist/ui/hub-intro-notice.js +16 -0
  151. package/dist/ui/hub-my-agents.js +7 -3
  152. package/dist/ui/hub-owner-strings.js +2 -1
  153. package/dist/ui/hub-personal-agent.js +2 -1
  154. package/dist/ui/hub-quota.js +2 -1
  155. package/dist/ui/hub-roles-strings.js +2 -1
  156. package/dist/ui/hub-room-composer.js +10 -2
  157. package/dist/ui/hub-room-list.js +1 -1
  158. package/dist/ui/hub-room-members.js +2 -0
  159. package/dist/ui/hub-room-new-strings.js +2 -1
  160. package/dist/ui/hub-room-new.js +7 -4
  161. package/dist/ui/hub-room-purpose.js +19 -0
  162. package/dist/ui/hub-room-search.js +1 -1
  163. package/dist/ui/hub-room-settings.js +9 -0
  164. package/dist/ui/hub-room-source.js +2 -1
  165. package/dist/ui/hub-room-strings.js +6 -4
  166. package/dist/ui/hub-room-thread.js +68 -17
  167. package/dist/ui/hub-strings.js +2 -1
  168. package/dist/ui/hub-teams.js +2 -1
  169. package/dist/ui/model-picker.js +3 -2
  170. package/dist/ui/panel-chat.js +25 -7
  171. package/dist/ui/panel-hub.js +67 -20
  172. package/dist/ui/panel-needs.js +3 -2
  173. package/dist/ui/panel-runtimes.js +2 -1
  174. package/dist/ui/reply-file-preview.js +2 -1
  175. package/dist/ui/settings-access-overview.js +2 -1
  176. package/dist/ui/settings-connector.js +2 -1
  177. package/dist/ui/shared/agent-sheet.js +2 -1
  178. package/dist/ui/shared/app-i18n.js +2 -2
  179. package/dist/ui/shared/app-shell.js +39 -9
  180. package/dist/ui/shared/app.css +11 -0
  181. package/dist/ui/shared/app.js +3 -1
  182. package/dist/ui/shared/asset-url.d.ts +2 -0
  183. package/dist/ui/shared/asset-url.js +20 -0
  184. package/dist/ui/shared/chat-msg-actions.js +3 -1
  185. package/dist/ui/shared/chat-quote.js +261 -0
  186. package/dist/ui/shared/chat-table-select.js +175 -0
  187. package/dist/ui/shared/hub-chat.css +28 -0
  188. package/dist/ui/shared/hub-rooms-u2.css +5 -0
  189. package/dist/ui/shared/image-annotate.js +2 -1
  190. package/dist/ui/shared/module-warm.d.ts +3 -0
  191. package/dist/ui/shared/module-warm.js +39 -0
  192. package/dist/ui/shared/ui-states.js +3 -2
  193. package/dist/ui/shared/view-history.js +2 -1
  194. package/dist/ui/subagent-row.js +3 -2
  195. package/dist/ui/usage-pool.js +2 -1
  196. package/dist/ui/workspace-panel.js +2 -1
  197. package/dist/wake-coordinator.js +3 -2
  198. package/dist/wake-coordinator.js.map +1 -1
  199. package/dist/web-api.d.ts +17 -4
  200. package/dist/web-api.js +83 -6
  201. package/dist/web-api.js.map +1 -1
  202. package/dist/web-asset-version.d.ts +65 -0
  203. package/dist/web-asset-version.js +259 -0
  204. package/dist/web-asset-version.js.map +1 -0
  205. package/dist/web-host-guard.js +3 -1
  206. package/dist/web-host-guard.js.map +1 -1
  207. package/dist/web-host-install.d.ts +30 -3
  208. package/dist/web-host-install.js +50 -4
  209. package/dist/web-host-install.js.map +1 -1
  210. package/dist/web-terminal.d.ts +5 -0
  211. package/dist/web-terminal.js +11 -0
  212. package/dist/web-terminal.js.map +1 -1
  213. package/launcher/agend-install.cjs +48 -7
  214. package/package.json +1 -1
@@ -1,3 +1,4 @@
1
+ import { withHubRoomReplyWarning } from "./hub-room-reply-warning.js";
1
2
  import { hubSharingNoticeText } from "./hub-sharing-notice.js";
2
3
  import { hubPageSharingSettings } from "./hub-page-sharing-settings.js";
3
4
  import { replyPreviews } from "./reply-preview-spec.js";
@@ -71,6 +72,7 @@ import { atomicWriteFileSync } from "./atomic-write.js";
71
72
  import { createHash, randomBytes, randomUUID } from "node:crypto";
72
73
  import { freemem, totalmem, homedir, hostname } from "node:os";
73
74
  import { effectiveCpuCount } from "./cpu-quota.js";
75
+ import { realpath } from "node:fs/promises";
74
76
  import { createServer } from "node:http";
75
77
  import { Worker } from "node:worker_threads";
76
78
  import { ProbeWorkerPool } from "./probe-worker-pool.js";
@@ -297,7 +299,8 @@ import { resolveUpdateLaunch, openUpdateLog, updateLogPath, watchUpdateLaunch }
297
299
  import { isWebUpdateTarget, readLogTail, RUNNING_AGEND_VERSION, updateOffer, webProgressOf, webUpdateTarget } from "./web-update.js";
298
300
  import { admitProfileLogin, LoginController, LOGIN_TOKEN_RESEND_PREFIX, POST_LOGIN_RECOVERY_DEADLINE_MS } from "./login-controller.js";
299
301
  import { WebBackendLogins, dashboardSignInSupported } from "./web-backend-login.js";
300
- import { WebHostInstalls, hostUpdatePlan } from "./web-host-install.js";
302
+ import { CLAUDE_NPM_PACKAGE, claudeInstallKind, displayHostPath } from "./claude-install-kind.js";
303
+ import { WebHostInstalls, claudeSelfUpdating, hostUpdatePlan, npmUninstallCommand } from "./web-host-install.js";
301
304
  import { cliUpdateView, versionOf } from "./cli-audited.js";
302
305
  import { runBeforeDeadline } from "./deadline.js";
303
306
  import { LoginWindowLock } from "./login-window-lock.js";
@@ -353,6 +356,7 @@ import { sharedRolloutIndex } from "./rollout-index.js";
353
356
  import { TASK_BOARD_ON_NOTICE, dashboardRefusalIn, taskBoardOffIn, taskBoardSwitchedOn } from "./dashboard-permissions.js";
354
357
  import { mayUseTool, resolveToolSet, scheduleOpRefusal, toolForIpcType, toolRefusedMessage, } from "./tool-permissions.js";
355
358
  import { authorizeSession, decideWebGate, loadOrCreateWebToken, readSessionCookies, readWebToken, sessionCookieUpgrade } from "./web-auth.js";
359
+ import { takeAssetVersion, warmAssetVersion } from "./web-asset-version.js";
356
360
  import { bypassesWebGate, handleAuthRequest, serveGuestRefusedPage, serveSigninPage } from "./auth-api.js";
357
361
  import { isWebPageNavigation } from "./web-shell-routes.js";
358
362
  import { guestSessionPolicy, localSessionPolicy, publicLinkSessionPolicy, sessionVia, tokenEpoch, WebSessionStore } from "./web-session.js";
@@ -766,6 +770,11 @@ function emojiListFilter(opts) {
766
770
  }
767
771
  /** #1920: a guest's scope until phase 2 derives one: nothing. */
768
772
  const NO_GUEST_SCOPE = new Set();
773
+ /** M-3302: what a delivery log line says of a notice — its first line, places as plain text, at most 100 characters. */
774
+ export function noticePreview(text) {
775
+ const first = stripPlaceRefs(text).split("\n").find(l => l.trim() !== "")?.trim() ?? "";
776
+ return first.length > 100 ? `${first.slice(0, 99)}…` : first;
777
+ }
769
778
  /** #1490 row 27: a restart asked for one lifecycle of an instance after it was stopped, restarted or replaced. */
770
779
  export class RestartSupersededError extends Error {
771
780
  /** `shown`: the instance as the chat list names it (shownInstanceName). */
@@ -1464,7 +1473,7 @@ export class FleetManager {
1464
1473
  return { result: null, error: "Native panes can only read Windows runtime model inventories" };
1465
1474
  return { result: await this.listModelCatalog({ instanceName: target }) };
1466
1475
  }
1467
- const ops = { hub_room_list: "hub-room-list", hub_room_post: "hub-room-post", hub_room_members: "hub-room-members", hub_people_search: "hub-people-search", list_instances: "list", describe_instance: "describe", task: "task", send_to_instance: "send",
1476
+ const ops = { hub_set_intro: "hub-set-intro", hub_room_list: "hub-room-list", hub_room_post: "hub-room-post", hub_room_members: "hub-room-members", hub_people_search: "hub-people-search", list_instances: "list", describe_instance: "describe", task: "task", send_to_instance: "send",
1468
1477
  delegate_task: "delegate", request_information: "ask", report_result: "report", delivery_status: "delivery-status" };
1469
1478
  const { nativeAgentAdmissionContext } = await import("./native-agent-admission.js");
1470
1479
  const { dispatchAgentOperation } = await import("./agent-endpoint.js");
@@ -2617,8 +2626,9 @@ export class FleetManager {
2617
2626
  locale: getLocale(),
2618
2627
  readState: agent => {
2619
2628
  const process = this.getInstanceStatus(agent), interaction = this.getInstanceInteraction(agent);
2629
+ const reason = process === "paused" ? readPauseReason(this.getInstanceDir(agent)) : null;
2620
2630
  return { process, execution: this.getInstanceExecutionState(agent),
2621
- pauseReason: process === "paused" ? readPauseReason(this.getInstanceDir(agent)) : null,
2631
+ pauseReason: reason === "stale_auth" ? "error" : reason,
2622
2632
  waitingForApproval: interaction?.phase === "waiting" && !interaction.stale && !interaction.suspected
2623
2633
  && (interaction.kind === "permission" || interaction.kind === "dangerous_command") };
2624
2634
  },
@@ -2632,11 +2642,15 @@ export class FleetManager {
2632
2642
  attachPrivateQuestions: read => { this.hubPrivateQuestions = read; },
2633
2643
  attachReacts: handler => { this.hubReacts = handler; },
2634
2644
  },
2645
+ attachAgentIntro: port => { this.hubAgentIntro = port; },
2635
2646
  attachAgentRooms: port => { this.hubAgentRooms = port; this.notifyHubRoomTools(); },
2636
2647
  roomToolsChanged: () => this.notifyHubRoomTools(),
2637
2648
  roomConversationGeneration: agent => this.daemons.get(agent)?.roomConversationGeneration() ?? null,
2638
2649
  attachRoomInputs: handler => { this.hubRoomInput = handler; },
2650
+ attachRoomOwed: port => { this.hubRoomOwed = port; },
2639
2651
  roomNotify: input => this.deliverHubRoomNotification(input),
2652
+ // M-3313: a sign-in token in what the Hub sends is taken back the moment the link receives it.
2653
+ sawText: text => this.sawHubText(text),
2640
2654
  roomReceipt: (caller, receiptId) => verifyRoomReceipt({
2641
2655
  lookup: (agent, id) => {
2642
2656
  const item = this.queryDurableDeliveryStatus(agent, { messageId: id }).items[0];
@@ -3021,6 +3035,32 @@ export class FleetManager {
3021
3035
  return this.hubContactWindows ??= new HubContactWindows(join(this.dataDir, "hub-contact-windows.json"));
3022
3036
  }
3023
3037
  hubContactRestricted(agent) { return this.contactWindows().restricted(agent); }
3038
+ /**
3039
+ * M-3313 (#4145 for the Hub): what a Hub question or room notification hands the agent, with this fleet's sign-in
3040
+ * access token hidden (exact match, as a chat's). The live one is taken back and replaced, and the sign-in's chat told.
3041
+ * The Hub's own copy of the post is beyond the Fleet: it keeps it (encrypted) until its retention deletes it.
3042
+ */
3043
+ /**
3044
+ * M-3313 (Fable #4165 F1): a Hub frame's content as the member link receives it — before it waits for its agent (busy,
3045
+ * paused, offline) or is dropped undelivered — so a live sign-in token in it is taken back at once, not at delivery.
3046
+ * Nothing is changed here: the delivery hides it from the agent (screenHubText).
3047
+ */
3048
+ sawHubText(text) {
3049
+ const screened = this.screenLoginToken(text);
3050
+ if (!screened?.live)
3051
+ return;
3052
+ this.logger.warn("A sign-in access token arrived from the Hub: taken back and replaced");
3053
+ void this.loginController?.tokenPastedElsewhere().catch((err) => this.logger.warn({ err: err.message }, "Taking back a sign-in token pasted on the Hub failed"));
3054
+ }
3055
+ screenHubText(text) {
3056
+ const screened = this.screenLoginToken(text);
3057
+ if (!screened)
3058
+ return text;
3059
+ this.logger.warn("A sign-in access token reached this Fleet in a Hub question: hidden from the agent, taken back and replaced");
3060
+ if (screened.live)
3061
+ void this.loginController?.tokenPastedElsewhere().catch((err) => this.logger.warn({ err: err.message }, "Taking back a sign-in token pasted on the Hub failed"));
3062
+ return screened.text;
3063
+ }
3024
3064
  /**
3025
3065
  * A Hub question to its representative agent: ordinary cross-instance delivery (idle gate, wake, retries), from the
3026
3066
  * reserved Hub sender with the Hub-issued correlation id. beforeInput runs immediately before the IPC hand-off.
@@ -3049,12 +3089,17 @@ export class FleetManager {
3049
3089
  };
3050
3090
  if (input.roomContextGeneration)
3051
3091
  ipcMeta.hub_room_context_generation = input.roomContextGeneration;
3052
- const result = await this.deliverToInstance(input.agent, { type: "fleet_inbound", targetSession: input.agent, content: input.text, meta: ipcMeta }, { isCrossInstance: true, stillCurrent: input.stillCurrent, beforeInput: async () => {
3092
+ const result = await this.deliverToInstance(input.agent, { type: "fleet_inbound", targetSession: input.agent, content: this.screenHubText(input.text), meta: ipcMeta }, { isCrossInstance: true, stillCurrent: input.stillCurrent, beforeInput: async () => {
3053
3093
  const classic = this.isClassicInstance(input.agent);
3054
3094
  // A busy Classic room must finish its public turn first; never force a private question into that turn's queue.
3055
3095
  const idle = () => this.waitForInstanceIdle(input.agent, 0, this.lastDeliveryAt.get(input.agent) ?? 0, () => !input.stillCurrent());
3056
3096
  if (classic && !await idle())
3057
3097
  return false;
3098
+ if (!ipcMeta.hub_room_context_generation && /^hub-room-[a-f0-9-]{36}$/.test(input.correlationId)) {
3099
+ const generation = this.daemons.get(input.agent)?.roomConversationGeneration();
3100
+ if (generation)
3101
+ ipcMeta.hub_room_context_generation = generation;
3102
+ }
3058
3103
  if (!(await input.beforeInput()))
3059
3104
  return false;
3060
3105
  if (classic) {
@@ -3071,13 +3116,14 @@ export class FleetManager {
3071
3116
  }
3072
3117
  async deliverHubRoomNotification(input) {
3073
3118
  const { HUB_REPORT_TARGET } = await import("./hub/representative.js");
3074
- if (this.shuttingDown || !this.fleetConfig?.instances[input.agent] || isNativeExecInstance(this.fleetConfig.instances[input.agent]))
3119
+ const config = input.kind === "answer-reminder" ? this.hubAgentConfig(input.agent) : this.fleetConfig?.instances[input.agent];
3120
+ if (this.shuttingDown || !config || isNativeExecInstance(config))
3075
3121
  return false;
3076
- const prefix = input.kind === "mention-feedback" ? "hub-room-mention-feedback" : "hub-room-post-answer";
3077
- const result = await this.deliverToInstance(input.agent, { type: "fleet_inbound", targetSession: input.agent, content: input.text,
3122
+ const prefix = input.kind === "answer-reminder" ? "hub-room-answer-reminder" : input.kind === "mention-feedback" ? "hub-room-mention-feedback" : "hub-room-post-answer";
3123
+ const result = await this.deliverToInstance(input.agent, { type: "fleet_inbound", targetSession: input.agent, content: this.screenHubText(input.text),
3078
3124
  meta: { chat_id: "", message_id: `${prefix}-${input.id}`, user: `instance:${HUB_REPORT_TARGET}`, user_id: `instance:${HUB_REPORT_TARGET}`,
3079
3125
  ts: new Date().toISOString(), thread_id: "", from_instance: HUB_REPORT_TARGET, from_display: "Hub", correlation_id: `${prefix}-${input.id}`,
3080
- request_kind: "notification", requires_reply: "false", task_summary: input.kind === "mention-feedback" ? "Hub mention delivery feedback" : "A reply to your Hub room post" } }, { isCrossInstance: true, stillCurrent: input.stillCurrent, beforeInput: input.beforeInput });
3126
+ request_kind: "notification", requires_reply: "false", task_summary: input.kind === "answer-reminder" ? "Hub room answer reminder" : input.kind === "mention-feedback" ? "Hub mention delivery feedback" : "A reply to your Hub room post" } }, { isCrossInstance: true, stillCurrent: input.stillCurrent, beforeInput: input.beforeInput });
3081
3127
  return result !== false;
3082
3128
  }
3083
3129
  /** S-51: why the Hub (or this fleet's Hub membership) is not running, if it is held. Empty while off or running. */
@@ -3207,16 +3253,25 @@ export class FleetManager {
3207
3253
  }
3208
3254
  hubReacts = null;
3209
3255
  /** The member side's pane-failure hook for a Hub-issued correlation id (else null). */
3256
+ hubRoomOwed = null;
3257
+ hubRoomReplyWarning(agent) { try {
3258
+ return this.hubRoomOwed?.replyWarning(agent);
3259
+ }
3260
+ catch {
3261
+ return undefined;
3262
+ } }
3210
3263
  hubRoomInput = null;
3211
3264
  hubDeliveryFailed = null;
3212
3265
  /** The connected member adapter; never an agent-selectable identity. */
3213
3266
  hubAgentRooms = null;
3267
+ hubAgentIntro = null;
3268
+ hubSetIntro(caller, text, operationId) { return this.hubAgentIntro?.set(caller, text, operationId) ?? Promise.resolve({ ok: false, code: "unavailable" }); }
3214
3269
  hubRoomToolsAvailable() { return this.hubAgentRooms?.available() === true; }
3215
3270
  hubRoomList(caller) {
3216
3271
  return this.hubAgentRooms?.rooms(caller) ?? Promise.resolve({ ok: false, code: "unavailable" });
3217
3272
  }
3218
- hubRoomMembers(caller, room) {
3219
- return this.hubAgentRooms?.members(caller, room) ?? Promise.resolve({ ok: false, code: "unavailable" });
3273
+ hubRoomMembers(caller, room, options) {
3274
+ return this.hubAgentRooms?.members(caller, room, options) ?? Promise.resolve({ ok: false, code: "unavailable" });
3220
3275
  }
3221
3276
  hubPeopleSearch(caller, q) {
3222
3277
  return this.hubAgentRooms?.people(caller, q) ?? Promise.resolve({ ok: false, code: "unavailable" });
@@ -3385,6 +3440,11 @@ export class FleetManager {
3385
3440
  startupRetries = new Map();
3386
3441
  /** #2484: instances whose automatic startup retry is running now (between its timer and its outcome). */
3387
3442
  startupRetriesRunning = new Set();
3443
+ /** M-3302 (#4146): instances held because their backend's CLI is not installed — started again the moment it is (watchMissingBinaries). */
3444
+ missingBinaryHolds = new Map();
3445
+ missingBinaryWatch = null;
3446
+ missingBinaryNotices = new Map();
3447
+ static MISSING_BINARY_WATCH_MS = 15_000;
3388
3448
  /** Bumped by every explicit stop (incl. the stop half of a restart); fences the outage hand-off. */
3389
3449
  explicitStopGeneration = new Map();
3390
3450
  /** instanceName → outage hand-off currently executing; a repeat joins it. */
@@ -9648,6 +9708,8 @@ export class FleetManager {
9648
9708
  return false;
9649
9709
  if (this.stopOnUnsupportedCli(name, err, what))
9650
9710
  return false;
9711
+ if (this.holdMissingBinary(name, err))
9712
+ return false;
9651
9713
  this.logger.error({ err, name }, `Failed to start ${what}`);
9652
9714
  this.scheduleStartupRetry(name, 0);
9653
9715
  return false;
@@ -9691,6 +9753,11 @@ export class FleetManager {
9691
9753
  }
9692
9754
  /** Drop a pending automatic retry (an operator start/stop/restart supersedes it). */
9693
9755
  cancelStartupRetry(name) {
9756
+ // M-3302: a person's start/stop/restart supersedes the hold too (a start that still finds no binary holds it again).
9757
+ if (this.missingBinaryHolds?.delete(name)) {
9758
+ this.needsYou?.poke();
9759
+ this.stopMissingBinaryWatchIfIdle();
9760
+ }
9694
9761
  const pending = this.startupRetries.get(name);
9695
9762
  if (!pending)
9696
9763
  return;
@@ -9698,11 +9765,124 @@ export class FleetManager {
9698
9765
  this.startupRetries.delete(name);
9699
9766
  this.logger.info({ name }, "Pending automatic startup retry cancelled");
9700
9767
  }
9768
+ /**
9769
+ * M-3302 (#4146): the start failed because the backend's CLI is not installed (BackendBinaryMissingError). That does not get better
9770
+ * on the 1 → 5 → 15 min backoff and should not be given up on either: the instance is held, one notice per binary names the binary
9771
+ * and the install command (Needs you shows it too), and the fleet looks for the binary every MISSING_BINARY_WATCH_MS and starts each
9772
+ * held instance the moment it is back. True: handled.
9773
+ */
9774
+ holdMissingBinary(name, failure) {
9775
+ if (failure instanceof SupersededStartError)
9776
+ return false;
9777
+ const err = this.lifecycle?.missingBinaryAt?.(name, failure) ?? null;
9778
+ if (!err)
9779
+ return false;
9780
+ const pending = this.startupRetries.get(name);
9781
+ if (pending) {
9782
+ clearTimeout(pending.timer);
9783
+ this.startupRetries.delete(name);
9784
+ }
9785
+ const known = this.missingBinaryHolds.get(name);
9786
+ if (!known || known.binary !== err.binary) {
9787
+ this.missingBinaryHolds.set(name, { backend: err.backend, binary: err.binary, since: known?.since ?? Date.now() });
9788
+ this.logger.error({ name, backend: err.backend, binary: err.binary }, `Not starting ${name}: its backend binary "${err.binary}" is not installed — held until it is back`);
9789
+ this.queueMissingBinaryNotice(name, err.backend, err.binary);
9790
+ this.needsYou?.poke();
9791
+ }
9792
+ this.instanceProcessStatus.set(name, "stopped");
9793
+ this.ensureMissingBinaryWatch();
9794
+ return true;
9795
+ }
9796
+ /** The install command shown for a missing binary: the registry's (what /login and the dashboard run). */
9797
+ missingBinaryFix(backend) {
9798
+ return BACKEND_INSTALLATION_INFO[backend]?.install ?? "";
9799
+ }
9800
+ /**
9801
+ * M-3302: the summary a restart/update completion posts — `base` plus the "why" of its failed instances (missingBinarySummary). The one place both completions
9802
+ * (the startup batch after an update or restart, and the in-process restart) build it, so neither can drop the line (Fable on #4161).
9803
+ */
9804
+ completionSummary(base) {
9805
+ return { ...base, ...this.missingBinarySummary(base.failedNames ?? []) };
9806
+ }
9807
+ /** M-3302: the restart/update completion's "why" for the failed instances held on a missing binary, grouped by binary ({} when none). */
9808
+ missingBinarySummary(failedNames) {
9809
+ const groups = new Map();
9810
+ for (const name of failedNames) {
9811
+ const hold = this.missingBinaryHold(name);
9812
+ if (!hold)
9813
+ continue;
9814
+ const group = groups.get(hold.binary) ?? { binary: hold.binary, fix: hold.fix, names: [] };
9815
+ group.names.push(name);
9816
+ groups.set(hold.binary, group);
9817
+ }
9818
+ return groups.size ? { missingBinaries: [...groups.values()] } : {};
9819
+ }
9820
+ /** M-3302: a missing binary's hold, for Needs you (null: none). */
9821
+ missingBinaryHold(name) {
9822
+ const hold = this.missingBinaryHolds?.get(name);
9823
+ return hold ? { ...hold, fix: this.missingBinaryFix(hold.backend) } : null;
9824
+ }
9825
+ /** One notice per missing binary, however many instances it stopped (the same aggregation window as the start-retry notices). */
9826
+ queueMissingBinaryNotice(name, backend, binary) {
9827
+ const pending = this.missingBinaryNotices.get(binary);
9828
+ if (pending) {
9829
+ if (!pending.names.includes(name))
9830
+ pending.names.push(name);
9831
+ return;
9832
+ }
9833
+ const timer = setTimeout(() => {
9834
+ const entry = this.missingBinaryNotices.get(binary);
9835
+ this.missingBinaryNotices.delete(binary);
9836
+ if (entry)
9837
+ this.notifyFleetError(t("fleet.backend_binary_missing", entry.names.length, entry.names.join(", "), binary, this.missingBinaryFix(entry.backend)));
9838
+ }, FleetManager.STARTUP_RETRY_NOTICE_AGGREGATE_MS);
9839
+ timer.unref?.();
9840
+ this.missingBinaryNotices.set(binary, { names: [name], backend, timer });
9841
+ }
9842
+ ensureMissingBinaryWatch() {
9843
+ if (this.missingBinaryWatch || this.shuttingDown)
9844
+ return;
9845
+ this.missingBinaryWatch = setInterval(() => { void this.checkMissingBinaries(); }, FleetManager.MISSING_BINARY_WATCH_MS);
9846
+ this.missingBinaryWatch.unref?.();
9847
+ }
9848
+ stopMissingBinaryWatchIfIdle() {
9849
+ if (this.missingBinaryHolds?.size || !this.missingBinaryWatch)
9850
+ return;
9851
+ clearInterval(this.missingBinaryWatch);
9852
+ this.missingBinaryWatch = null;
9853
+ }
9854
+ missingBinaryCheckRunning = false;
9855
+ /** One look per backend still missing; each held instance whose binary is back is started now (through the spawn gate, as a retry). */
9856
+ async checkMissingBinaries() {
9857
+ if (this.missingBinaryCheckRunning || this.shuttingDown)
9858
+ return;
9859
+ this.missingBinaryCheckRunning = true;
9860
+ try {
9861
+ const backends = [...new Set([...this.missingBinaryHolds.values()].map(h => h.backend))];
9862
+ for (const backend of backends) {
9863
+ const path = await resolveBackendBinary(backend).catch(() => undefined);
9864
+ if (typeof path !== "string" || !path)
9865
+ continue;
9866
+ for (const [name, hold] of [...this.missingBinaryHolds]) {
9867
+ if (hold.backend !== backend)
9868
+ continue;
9869
+ this.missingBinaryHolds.delete(name);
9870
+ this.logger.info({ name, backend, binary: hold.binary, path }, `Backend binary "${hold.binary}" is back — starting ${name}`);
9871
+ void this.runStartupRetry(name, 0);
9872
+ }
9873
+ this.needsYou?.poke();
9874
+ }
9875
+ }
9876
+ finally {
9877
+ this.missingBinaryCheckRunning = false;
9878
+ this.stopMissingBinaryWatchIfIdle();
9879
+ }
9880
+ }
9701
9881
  /** #2484: the instance's own start retry is scheduled or running, and no person paused it (a stop cancels the retry). */
9702
9882
  inStartRetryBackoff(name) {
9703
9883
  if (this.shuttingDown || this.lifecycle.isPaused(name))
9704
9884
  return false;
9705
- return this.startupRetries.has(name) || this.startupRetriesRunning.has(name);
9885
+ return this.startupRetries.has(name) || this.startupRetriesRunning.has(name) || this.missingBinaryHolds?.has(name) === true;
9706
9886
  }
9707
9887
  /** Pending automatic retry, if any (status display / tests). */
9708
9888
  pendingStartupRetry(name) {
@@ -9791,6 +9971,8 @@ export class FleetManager {
9791
9971
  return;
9792
9972
  if (this.stopOnUnsupportedCli(name, err, "instance"))
9793
9973
  return;
9974
+ if (this.holdMissingBinary(name, err))
9975
+ return;
9794
9976
  this.logger.error({ err, name, attempt: attempt + 1 }, "Automatic startup retry failed");
9795
9977
  this.scheduleStartupRetry(name, attempt + 1);
9796
9978
  }
@@ -12622,7 +12804,7 @@ export class FleetManager {
12622
12804
  // version it aimed for, the one running, and the one repair), never just "updated".
12623
12805
  const aimedAt = pendingProgressOperation === "update" ? pendingUpdateProgress?.progress.version : undefined;
12624
12806
  const notLanded = aimedAt && agendVersion !== "unknown" && aimedAt !== agendVersion ? t("update.not_landed", aimedAt, agendVersion) : null;
12625
- const completionSummary = {
12807
+ const completionSummary = this.completionSummary({
12626
12808
  running: started,
12627
12809
  total,
12628
12810
  version: agendVersion,
@@ -12632,7 +12814,7 @@ export class FleetManager {
12632
12814
  ...(cleanupOutcome && "render" in cleanupOutcome
12633
12815
  ? { warningText: cleanupOutcome.render.warning, warningCommand: cleanupOutcome.render.cleanupCommand }
12634
12816
  : notLanded ? { warningText: notLanded } : {}),
12635
- };
12817
+ });
12636
12818
  const progressCompleted = await startupProgress.finish(completionSummary);
12637
12819
  // Armed only after the completion posted: an append racing ahead of it would be overwritten by it.
12638
12820
  if (cleanupOutcome && "watch" in cleanupOutcome)
@@ -13741,6 +13923,10 @@ export class FleetManager {
13741
13923
  else if (msg.type === "instance_progress") {
13742
13924
  this.cacheInstanceProgress(name, msg.progress || null);
13743
13925
  }
13926
+ else if (msg.type === "hub_room_turn_ended") {
13927
+ if (this.instanceIpcClients.get(name) === ipc && typeof msg.generation === "string" && typeof msg.turn === "string")
13928
+ void this.hubRoomOwed?.turnEnded(name, msg.generation, msg.turn).catch(err => this.logger.warn({ err }, "Hub room completion notice held"));
13929
+ }
13744
13930
  else if (msg.type === "hub_room_input") {
13745
13931
  if (this.instanceIpcClients.get(name) === ipc && typeof msg.correlationId === "string" && typeof msg.generation === "string")
13746
13932
  this.hubRoomInput?.(msg.correlationId, name, msg.generation);
@@ -14417,10 +14603,42 @@ export class FleetManager {
14417
14603
  }
14418
14604
  async handleInboundMessage(msg) {
14419
14605
  msg = { ...msg, humanOriginalBody: msg.humanOriginalBody ?? msg.text, humanOrigin: msg.isBotMessage ? undefined : msg.humanOrigin && { ...msg.humanOrigin } };
14606
+ // #4145: this fleet's sign-in access token pasted into a chat is hidden before anything logs, indexes, keeps or
14607
+ // delivers the message — then taken back and replaced, and the chat told where it goes.
14608
+ const pasted = this.screenPastedLoginToken(msg);
14609
+ if (pasted) {
14610
+ msg = pasted.msg;
14611
+ if (pasted.live)
14612
+ await this.takeBackPastedLoginToken(msg);
14613
+ }
14420
14614
  if (msg.isBotMessage)
14421
14615
  return withSpawnHoldReply(undefined, () => this.handleInboundMessageCore(msg));
14422
14616
  return withSpawnHoldReply(text => this.inboundNoticeAdapter(msg)?.sendText(msg.chatId, text, { threadId: msg.threadId }) ?? Promise.resolve(), () => this.handleInboundMessageCore(msg));
14423
14617
  }
14618
+ /** #4145 (the web chat's /ui/send too): `text` with this fleet's sign-in access token hidden; null when there is none in it. */
14619
+ screenLoginToken(text) { return this.loginController?.screenToken(text) ?? null; }
14620
+ /** #4145: take a pasted access token back (a new one goes the way the first went); the line for the chat it was pasted in, or null. */
14621
+ loginTokenPasted() { return this.loginController?.tokenPasted() ?? Promise.resolve(null); }
14622
+ /** #4145: the message with the live (or a just-taken-back) sign-in access token hidden in its text and its receipt body; null when neither has one. */
14623
+ screenPastedLoginToken(msg) {
14624
+ const text = this.screenLoginToken(msg.text ?? "");
14625
+ const body = msg.humanOriginalBody === undefined || msg.humanOriginalBody === msg.text ? text : this.screenLoginToken(msg.humanOriginalBody);
14626
+ if (!text && !body)
14627
+ return null;
14628
+ return { msg: { ...msg, ...(text ? { text: text.text } : {}), ...(body ? { humanOriginalBody: body.text } : {}) }, live: !!(text?.live || body?.live) };
14629
+ }
14630
+ /** #4145: take the pasted token back (a new one goes privately) and say so once, where it was pasted. Never the token in a log line. */
14631
+ async takeBackPastedLoginToken(msg) {
14632
+ this.logger.warn({ source: msg.source, adapterId: msg.adapterId, chatId: msg.chatId, threadId: msg.threadId, userId: msg.userId }, "A sign-in access token was pasted into a chat: hidden, taken back and replaced");
14633
+ const notice = await this.loginTokenPasted().catch((err) => {
14634
+ this.logger.warn({ err: err.message }, "Taking back a pasted sign-in token failed");
14635
+ return null;
14636
+ });
14637
+ if (!notice || msg.isBotMessage)
14638
+ return;
14639
+ await this.inboundNoticeAdapter(msg)?.sendText(msg.chatId, notice, { threadId: msg.threadId || undefined })
14640
+ .catch((err) => this.logger.warn({ err: err.message }, "Pasted sign-in token notice failed"));
14641
+ }
14424
14642
  /**
14425
14643
  * #1752: the bot that speaks back about an inbound message — in a fleet topic the owning instance's adapter, never
14426
14644
  * the sibling that happened to win the dedup race; elsewhere (ClassicBot rooms, no routed instance) the receiver.
@@ -15201,6 +15419,8 @@ export class FleetManager {
15201
15419
  const operationId = typeof msg.operationId === "string" ? msg.operationId : undefined;
15202
15420
  const sourceDaemonBootId = typeof msg.sourceDaemonBootId === "string" ? msg.sourceDaemonBootId : undefined;
15203
15421
  const respond = (result, error) => {
15422
+ if (tool === "reply" && msg.statusOnly !== true)
15423
+ result = withHubRoomReplyWarning(result, () => this.hubRoomReplyWarning(instanceName), error);
15204
15424
  const ipc = this.instanceIpcClients.get(instanceName);
15205
15425
  let sent = false;
15206
15426
  if (fleetRequestId) {
@@ -17544,6 +17764,11 @@ export class FleetManager {
17544
17764
  await this.lifecycle.remove(name, authorization, execution, transition);
17545
17765
  else
17546
17766
  await this.lifecycle.remove(name, authorization);
17767
+ // M-3302: a removed instance is no longer held for its missing binary (the watch would only skip it).
17768
+ if (this.missingBinaryHolds?.delete(name)) {
17769
+ this.needsYou?.poke();
17770
+ this.stopMissingBinaryWatchIfIdle();
17771
+ }
17547
17772
  // #1490 row 27: its hang/exit offers were for the instance now gone (stopInstance clears them; removal stops
17548
17773
  // through the lifecycle directly). The offers' own lifecycle pins refuse them too.
17549
17774
  this.clearNoncePromptsForInstance(name);
@@ -19096,7 +19321,7 @@ export class FleetManager {
19096
19321
  if (this.adapter && target) {
19097
19322
  const out = this.renderPlaces(this.getPrimaryAdapterId(), body, target.opts);
19098
19323
  this.adapter.sendText(target.chatId, out.text, out.opts)
19099
- .then(() => opts.ack?.(true), err => { this.logger.warn({ err }, "Failed to send fleet error notification"); opts.ack?.(false); });
19324
+ .then(() => { this.logger.info({ notice: noticePreview(body) }, "Fleet notice delivered"); opts.ack?.(true); }, err => { this.logger.warn({ err }, "Failed to send fleet error notification"); opts.ack?.(false); });
19100
19325
  dispatched = true;
19101
19326
  }
19102
19327
  }
@@ -19203,7 +19428,8 @@ export class FleetManager {
19203
19428
  if (!send)
19204
19429
  return false;
19205
19430
  // `ack` (a caller that must not lose the message) is told when the platform took it or refused it; everyone else only gets the log line.
19206
- send.sent.then(() => ack?.(true), e => { this.logger.warn({ err: e, instanceName }, send.failure); ack?.(false); });
19431
+ // M-3302 (#4146): a delivered notice leaves one line, so the log can tell whether the person was told (only failures were logged).
19432
+ send.sent.then(() => { this.logger.info({ instanceName, notice: noticePreview(text) }, "Notice delivered"); ack?.(true); }, e => { this.logger.warn({ err: e, instanceName }, send.failure); ack?.(false); });
19207
19433
  return true;
19208
19434
  }
19209
19435
  /**
@@ -19898,7 +20124,9 @@ export class FleetManager {
19898
20124
  interaction: p.interaction ? { kind: p.interaction.kind, owner: wait?.owner ?? null, episode: p.interaction.episode, since: p.interaction.since } : null,
19899
20125
  interactionSummary: p.interaction?.kind === "kiro_choice" ? t("kiro3.running") : p.interaction_summary ?? null,
19900
20126
  kiroCompatibility: this.kiroCompatibilityHolds?.get(name),
20127
+ backendMissing: this.missingBinaryHold(name),
19901
20128
  pauseReason, pausedAt,
20129
+ staleAuth: this.daemons.get(name)?.staleAuthIssue?.() ?? null,
19902
20130
  crashedAt: crashed ? (this.needsCrashedAt.get(name) ?? null) : null,
19903
20131
  signIn: pauseReason === "auth" ? this.signInFor(name) : null,
19904
20132
  modelSwitch: this.modelObservationForInstance(name)?.active ?? null,
@@ -23351,7 +23579,58 @@ export class FleetManager {
23351
23579
  }
23352
23580
  }
23353
23581
  return buildAccountsView({ targets, diskProfiles, agents, classic, fleetDefaults, usage, keepAlive, machines, installShown: this.webHostInstalls.view()?.backend ?? null,
23354
- versions: new Map(this.backendAvailabilityRows().map(row => [row.backend, row.version ?? null])) });
23582
+ versions: new Map(this.backendAvailabilityRows().map(row => [row.backend, row.version ?? null])), claudeInstall: await this.claudeInstallShown() });
23583
+ }
23584
+ /**
23585
+ * M-3307: the install kind as the AI accounts page is told it — paths `~`-abbreviated (Fable note 2 on #4163) — and, for a native install, the npm copy still left on
23586
+ * this computer (note 1: found again here, not only remembered from a switch in this process), so its removal is offered after a restart too.
23587
+ */
23588
+ async claudeInstallShown() {
23589
+ const ci = await this.claudeInstall();
23590
+ if (!ci)
23591
+ return null;
23592
+ const home = homedir();
23593
+ if (ci.kind === "npm-global")
23594
+ return { kind: ci.kind, ...(ci.npmPackageDir ? { npmPackageDir: displayHostPath(ci.npmPackageDir, home) } : {}) };
23595
+ if (ci.kind !== "native")
23596
+ return { kind: ci.kind };
23597
+ const left = await this.findClaudeNpmCopy().catch(() => null);
23598
+ return { kind: "native", ...(left ? { npmLeftover: displayHostPath(left, home) } : {}) };
23599
+ }
23600
+ claudeNpmCopyCache = null;
23601
+ /**
23602
+ * M-3307 (Fable note 1 on #4163): an npm copy of Claude Code on this computer, looked for afresh: the one a switch in this process found, else `<npm root -g>/@anthropic-ai/claude-code`
23603
+ * (a fresh login shell's npm), else the system prefixes' (/usr/lib, /usr/local/lib). The answer is kept a minute (the page reads it on each view). Null: none.
23604
+ */
23605
+ async findClaudeNpmCopy() {
23606
+ if (this.claudeNpmCopy && existsSync(this.claudeNpmCopy))
23607
+ return this.claudeNpmCopy;
23608
+ const now = performance.now();
23609
+ if (this.claudeNpmCopyCache && now - this.claudeNpmCopyCache.at < 60_000)
23610
+ return this.claudeNpmCopyCache.dir;
23611
+ const roots = [];
23612
+ try {
23613
+ const r = await runOnLoginShell("npm root -g 2>/dev/null");
23614
+ const root = r.status === 0 ? r.stdout.trim().split("\n").pop()?.trim() ?? "" : "";
23615
+ if (isAbsolute(root))
23616
+ roots.push(root);
23617
+ }
23618
+ catch { /* no npm */ }
23619
+ roots.push("/usr/lib/node_modules", "/usr/local/lib/node_modules");
23620
+ const dir = roots.map(root => join(root, CLAUDE_NPM_PACKAGE)).find(d => existsSync(d)) ?? null;
23621
+ this.claudeNpmCopyCache = { at: now, dir };
23622
+ return dir;
23623
+ }
23624
+ /** M-3307 (#4146): the kind of the host's Claude Code install, from the real path of the `claude` the availability snapshot resolved (null: none, or unreadable). */
23625
+ async claudeInstall(path = this.backendAvailabilityRows().find(row => row.backend === "claude-code")?.path ?? null) {
23626
+ if (!path)
23627
+ return null;
23628
+ try {
23629
+ return claudeInstallKind(await realpath(path), process.env, homedir());
23630
+ }
23631
+ catch {
23632
+ return null;
23633
+ }
23355
23634
  }
23356
23635
  /**
23357
23636
  * AGEND-113: a dashboard sign-in just finished: read the usage once more now (the panel's own forced read, so its 30-second floor and Retry-After hold), instead of showing what was read
@@ -24635,14 +24914,36 @@ export class FleetManager {
24635
24914
  if (!base || isRemovedBackend(backend))
24636
24915
  return { refused: "unsupported" };
24637
24916
  // AGEND-136: an update runs the registry's `host.update` command with the audited release in it (hostUpdatePlan); the window, its judgement and its release are the install's.
24638
- const plan = mode === "update" ? hostUpdatePlan(backend) : null;
24639
- if (mode === "update" && !plan)
24917
+ const plan = mode === "update" || mode === "native" ? hostUpdatePlan(backend) : null;
24918
+ if ((mode === "update" || mode === "native") && !plan)
24919
+ return { refused: "unsupported" };
24920
+ // M-3307 (#4146): the switch and the npm copy's removal are Claude Code's alone.
24921
+ if ((mode === "native" || mode === "remove-npm") && backend !== "claude-code")
24640
24922
  return { refused: "unsupported" };
24641
- const info = plan ? { install: plan.command } : base;
24923
+ // remove-npm: the npm copy the switch found (its package directory), removed with npm of that same prefix (<prefix>/lib/node_modules/@anthropic-ai/claude-code).
24924
+ // Fable note 1 on #4163: found afresh, so a restart after the switch does not lose it.
24925
+ if (mode === "remove-npm")
24926
+ this.claudeNpmCopyCache = null;
24927
+ const npmCopy = mode === "remove-npm" ? await this.findClaudeNpmCopy().catch(() => null) : null;
24928
+ if (mode === "remove-npm" && (!npmCopy || !existsSync(npmCopy)))
24929
+ return { refused: "no_npm_copy" };
24930
+ // M-3318 (#4146's shape): never run npm's uninstall while another npm is changing packages on this computer — e.g. an agent's Claude Code updating itself with
24931
+ // `npm install -g` in that same prefix. The same judgement as the AgEnD installer's wait (#4148, launcher/agend-install.cjs); here it is refused with what runs, never queued.
24932
+ if (mode === "remove-npm") {
24933
+ const busy = await this.otherNpmChanging().catch(() => null);
24934
+ if (busy && busy.length)
24935
+ return { refused: "npm_busy", message: busy.map(row => `pid ${row.pid}: npm ${row.command}`).join("; ") };
24936
+ }
24937
+ const info = plan ? { install: plan.command } : npmCopy ? { install: npmUninstallCommand(npmCopy) } : base;
24642
24938
  // The fleet-wide window, claimed before the first await (shared with /login, chat's install and sign-in).
24643
24939
  const claim = this.loginWindow.tryClaim("install", backend);
24644
24940
  if (!claim)
24645
24941
  return { refused: this.loginWindow.isClosed ? "shutting_down" : "busy" };
24942
+ // M-3302: Claude Code downloading an update of its own right now — its installer, started from here, would race it. Asked to try again in a few minutes.
24943
+ if (backend === "claude-code" && claudeSelfUpdating()) {
24944
+ this.loginWindow.release(claim);
24945
+ return { refused: "cli_self_updating" };
24946
+ }
24646
24947
  // #3542 / AGEND-144 (Prism on #3539): the claim is a lock, not the asker's authority. The confirmed change's own execution (its session, role, confirmation and the settings it was held
24647
24948
  // against) is asked again after each wait (the binary check, the version refresh), and its admission ends at the tmux command that starts the installer (openInstallWindow → `launch`).
24648
24949
  const asker = () => { try {
@@ -24657,10 +24958,25 @@ export class FleetManager {
24657
24958
  return { refused: "already" };
24658
24959
  }
24659
24960
  // An update needs the CLI where the Accounts page found it: on the fleet's PATH, else (a fresh login shell, then) the installer's own directories (~/.grok/bin, ~/.opencode/bin …).
24660
- if (mode === "update" && !present && !(await this.locateInstalledCli(backend, base.binary).catch(() => null))) {
24961
+ if (mode !== "install" && !present && !(await this.locateInstalledCli(backend, base.binary).catch(() => null))) {
24661
24962
  this.loginWindow.release(claim);
24662
24963
  return { refused: "not_installed" };
24663
24964
  }
24965
+ // M-3307: the switch is offered only over an npm-global install; the removal only once `claude` resolves to the native install (else nothing would be left).
24966
+ if (mode === "native" || mode === "remove-npm") {
24967
+ const now = await this.claudeInstallAfter(base.binary, null);
24968
+ if (mode === "native" && now.kind !== "npm-global") {
24969
+ this.loginWindow.release(claim);
24970
+ return { refused: "not_npm" };
24971
+ }
24972
+ if (mode === "native")
24973
+ this.claudeNpmCopy = (await this.claudeInstall(now.path))?.npmPackageDir ?? null;
24974
+ // The removal needs a native install to fall back on: `claude` resolves to it already, or it is there behind the npm copy on PATH (the switch's "still npm" case).
24975
+ if (mode === "remove-npm" && now.kind !== "native" && !(await this.nativeClaudePresent())) {
24976
+ this.loginWindow.release(claim);
24977
+ return { refused: "still_npm" };
24978
+ }
24979
+ }
24664
24980
  if (!asker()) {
24665
24981
  this.loginWindow.release(claim);
24666
24982
  return { refused: "failed" };
@@ -24689,7 +25005,7 @@ export class FleetManager {
24689
25005
  return { refused: "version_unreadable" };
24690
25006
  }
24691
25007
  // AGEND-153: the named exception (`release: "latest-unaudited"`) is offered at any readable version (it goes to the vendor's newest, not to our audited release), so "behind" does not decide it.
24692
- if (cliUpdateView(backend, versionBefore, true, plan.target === null)?.button !== true) {
25008
+ if (mode === "update" && cliUpdateView(backend, versionBefore, true, plan.target === null)?.button !== true) {
24693
25009
  this.loginWindow.release(claim);
24694
25010
  return { refused: "up_to_date" };
24695
25011
  }
@@ -24720,9 +25036,17 @@ export class FleetManager {
24720
25036
  version = this.backendAvailabilityRows().find(row => row.backend === backend)?.version ?? null;
24721
25037
  }
24722
25038
  }
24723
- this.logger.info({ backend, mode, ok, verified, ...(plan ? { to: plan.target } : {}), ...(ok ? {} : { detail }) }, mode === "update" ? "Dashboard update ended" : "Dashboard install ended");
25039
+ // M-3307: after the switch or the removal, where `claude` resolves now (a fresh login shell), its kind, and whether the npm copy is still there.
25040
+ const claude = ok && (mode === "native" || mode === "remove-npm") ? await this.claudeInstallAfter(base.binary, mode === "remove-npm" ? npmCopy : this.claudeNpmCopy).catch(() => undefined) : undefined;
25041
+ if (claude && mode === "remove-npm" && !claude.npmLeftover) {
25042
+ this.claudeNpmCopy = null;
25043
+ this.claudeNpmCopyCache = null;
25044
+ }
25045
+ this.logger.info({ backend, mode, ok, verified, ...(plan ? { to: plan.target } : {}), ...(claude ? { claude } : {}), ...(ok ? {} : { detail }) }, mode === "install" ? "Dashboard install ended" : mode === "update" ? "Dashboard update ended" : mode === "native" ? "Dashboard switch to Claude's native install ended" : "Dashboard removal of the npm Claude Code ended");
25046
+ // Fable note 2 on #4163: what the page is told names no user — paths are shown `~`-abbreviated (the log above keeps them whole, on this computer).
25047
+ const shown = claude ? { ...claude, path: displayHostPath(claude.path, homedir()), npmLeftover: displayHostPath(claude.npmLeftover, homedir()) } : undefined;
24724
25048
  try {
24725
- reporter.done({ ok, detail, cleanupFailed, verified, version, signIn: !!LOGIN_FLOWS[backend] && dashboardSignInSupported(backend) });
25049
+ reporter.done({ ok, detail, cleanupFailed, verified, version, signIn: mode === "install" && !!LOGIN_FLOWS[backend] && dashboardSignInSupported(backend), ...(shown ? { claude: shown } : {}) });
24726
25050
  }
24727
25051
  catch { /* a view never stops the install */ }
24728
25052
  },
@@ -24736,6 +25060,31 @@ export class FleetManager {
24736
25060
  }
24737
25061
  return { started: true };
24738
25062
  }
25063
+ /** M-3307: the npm copy of Claude Code the last switch found (its package directory), the one `remove-npm` removes. */
25064
+ claudeNpmCopy = null;
25065
+ /**
25066
+ * M-3318: the other npm processes on this computer that may be changing packages (pid and npm's command word only — never the argv, which can carry
25067
+ * a registry credential), judged as the AgEnD installer judges them (#4148). Null when the process list cannot be read.
25068
+ */
25069
+ async otherNpmChanging() {
25070
+ const [{ createRequire }, { promisify }, { execFile }] = await Promise.all([import("node:module"), import("node:util"), import("./child-process.js")]);
25071
+ const judge = createRequire(import.meta.url)("../launcher/agend-install.cjs");
25072
+ const { stdout } = await promisify(execFile)("ps", ["-A", "-o", "pid=,ppid=,args="], { timeout: 5_000, maxBuffer: 4 * 1024 * 1024 });
25073
+ const rows = judge.npmChangingFromProcessList(String(stdout), process.pid);
25074
+ return rows ? rows.map(row => ({ pid: row.pid, command: (judge.npmCommands(row.args) ?? ["?"])[0] ?? "?" })) : null;
25075
+ }
25076
+ /** M-3307: Claude's native install is there: `~/.local/bin/claude` leads into its versions folder. */
25077
+ async nativeClaudePresent() {
25078
+ const real = await realpath(join(homedir(), ".local", "bin", "claude")).catch(() => null);
25079
+ return !!real && claudeInstallKind(real, process.env, homedir()).kind === "native";
25080
+ }
25081
+ /** M-3307: where `binary` resolves in a fresh login shell now, the kind of that install, and whether `npmCopy` (a package directory) is still there. */
25082
+ async claudeInstallAfter(binary, npmCopy) {
25083
+ const at = await this.locateBinaryOnLoginShell(binary).catch(() => null);
25084
+ const real = at ? await realpath(at).catch(() => null) : null;
25085
+ const kind = real ? claudeInstallKind(real, process.env, homedir()).kind : null;
25086
+ return { kind, path: real, npmLeftover: npmCopy && existsSync(npmCopy) ? npmCopy : null };
25087
+ }
24739
25088
  /** A fresh login shell's answer for `binary`, else the installer's own directories (see locateBinaryOnLoginShell / locateInstalledBackend). */
24740
25089
  async locateInstalledCli(backend, binary) {
24741
25090
  return (await this.locateBinaryOnLoginShell(binary)) ?? (await this.locateInstalledBackend(backend));
@@ -28668,6 +29017,13 @@ export class FleetManager {
28668
29017
  for (const pending of this.startupRetries.values())
28669
29018
  clearTimeout(pending.timer);
28670
29019
  this.startupRetries.clear();
29020
+ if (this.missingBinaryWatch) {
29021
+ clearInterval(this.missingBinaryWatch);
29022
+ this.missingBinaryWatch = null;
29023
+ }
29024
+ for (const pending of this.missingBinaryNotices?.values() ?? [])
29025
+ clearTimeout(pending.timer);
29026
+ this.missingBinaryNotices?.clear();
28671
29027
  for (const pending of this.startupRetryNotices.values())
28672
29028
  clearTimeout(pending.timer);
28673
29029
  this.startupRetryNotices.clear();
@@ -30874,13 +31230,13 @@ export class FleetManager {
30874
31230
  const { createRequire } = await import("node:module");
30875
31231
  const _require2 = createRequire(import.meta.url);
30876
31232
  const agendVersion2 = _require2("../package.json").version ?? "unknown";
30877
- const progressCompleted = await restartProgress.finish({
31233
+ const progressCompleted = await restartProgress.finish(this.completionSummary({
30878
31234
  running: started,
30879
31235
  total,
30880
31236
  version: agendVersion2,
30881
31237
  pausedNames: pausedNames2,
30882
31238
  failedNames,
30883
- });
31239
+ }));
30884
31240
  if (groupId && this.adapter) {
30885
31241
  let restartText;
30886
31242
  if (failedNames.length === 0 && pausedNames2.length === 0) {
@@ -31474,6 +31830,9 @@ export class FleetManager {
31474
31830
  res.end(JSON.stringify({ error: "fleet stopping" }));
31475
31831
  return;
31476
31832
  }
31833
+ // M-3314: a versioned asset path goes through every check below as its plain path (the public link's gateway did
31834
+ // this already for its own requests; once per request).
31835
+ takeAssetVersion(req);
31477
31836
  const requestPath = new URL(req.url ?? "/", `http://localhost:${port}`).pathname;
31478
31837
  const publicUrl = new URL(req.url ?? "/", `http://localhost:${port}`);
31479
31838
  if (remoteRuntimeEnabled() && !gatewayRequestContext(req)
@@ -31860,6 +32219,9 @@ export class FleetManager {
31860
32219
  }
31861
32220
  }
31862
32221
  startHealthServer(port) {
32222
+ // M-3314: <V> describes the files this process started with, taken now — not at the first page, which may come after
32223
+ // an update rewrote them.
32224
+ warmAssetVersion();
31863
32225
  let settled;
31864
32226
  const listening = new Promise(resolve => { settled = resolve; });
31865
32227
  this.startedAt = Date.now();