@songsid/agend 2.4.0-beta.2 → 2.4.0-beta.4

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 (294) hide show
  1. package/dist/agent-cli.js +1 -1
  2. package/dist/agent-endpoint.d.ts +1 -1
  3. package/dist/agent-endpoint.js +8 -2
  4. package/dist/agent-endpoint.js.map +1 -1
  5. package/dist/agent-token-header.d.ts +1 -1
  6. package/dist/agent-token-header.js +1 -1
  7. package/dist/auth-api.d.ts +3 -0
  8. package/dist/auth-api.js +15 -1
  9. package/dist/auth-api.js.map +1 -1
  10. package/dist/backend/agy-model-switch.d.ts +22 -0
  11. package/dist/backend/agy-model-switch.js +62 -0
  12. package/dist/backend/agy-model-switch.js.map +1 -0
  13. package/dist/backend/antigravity.js +60 -3
  14. package/dist/backend/antigravity.js.map +1 -1
  15. package/dist/backend/cli-runtime-switch.d.ts +71 -0
  16. package/dist/backend/cli-runtime-switch.js +176 -0
  17. package/dist/backend/cli-runtime-switch.js.map +1 -0
  18. package/dist/backend/codex-model-switch.d.ts +41 -0
  19. package/dist/backend/codex-model-switch.js +170 -0
  20. package/dist/backend/codex-model-switch.js.map +1 -0
  21. package/dist/backend/credential-profile.js +1 -1
  22. package/dist/backend/credential-profile.js.map +1 -1
  23. package/dist/backend/grok-model-switch.d.ts +16 -0
  24. package/dist/backend/grok-model-switch.js +45 -0
  25. package/dist/backend/grok-model-switch.js.map +1 -0
  26. package/dist/backend/grok.js +1 -1
  27. package/dist/backend/grok.js.map +1 -1
  28. package/dist/backend/muse.d.ts +2 -0
  29. package/dist/backend/muse.js +7 -3
  30. package/dist/backend/muse.js.map +1 -1
  31. package/dist/build-provenance.json +1 -1
  32. package/dist/channel/mcp-server.js +10 -1
  33. package/dist/channel/mcp-server.js.map +1 -1
  34. package/dist/channel/mcp-tools.js +8 -0
  35. package/dist/channel/mcp-tools.js.map +1 -1
  36. package/dist/classic-channel-manager.d.ts +1 -1
  37. package/dist/classic-channel-manager.js +1 -1
  38. package/dist/cli-audited.js +12 -12
  39. package/dist/cli-audited.js.map +1 -1
  40. package/dist/daemon.d.ts +48 -2
  41. package/dist/daemon.js +302 -21
  42. package/dist/daemon.js.map +1 -1
  43. package/dist/delivery-consumed-watch.js +3 -0
  44. package/dist/delivery-consumed-watch.js.map +1 -1
  45. package/dist/event-log.d.ts +1 -1
  46. package/dist/event-log.js +1 -1
  47. package/dist/fleet-manager.d.ts +104 -2
  48. package/dist/fleet-manager.js +665 -27
  49. package/dist/fleet-manager.js.map +1 -1
  50. package/dist/general-knowledge/skills/credential-profiles/SKILL.md +10 -0
  51. package/dist/general-knowledge/skills/cross-instance-messaging/SKILL.md +2 -0
  52. package/dist/general-knowledge/skills/fleet-health/SKILL.md +18 -0
  53. package/dist/general-knowledge/skills/hub/SKILL.md +154 -0
  54. package/dist/general-knowledge/skills/model-discovery/SKILL.md +4 -0
  55. package/dist/general-knowledge/skills/web-dashboard/SKILL.md +17 -3
  56. package/dist/hub/admin-dashboard.d.ts +85 -0
  57. package/dist/hub/admin-dashboard.js +161 -0
  58. package/dist/hub/admin-dashboard.js.map +1 -0
  59. package/dist/hub/attachments/store.d.ts +2 -0
  60. package/dist/hub/attachments/store.js +6 -0
  61. package/dist/hub/attachments/store.js.map +1 -1
  62. package/dist/hub/client.d.ts +10 -0
  63. package/dist/hub/client.js +72 -10
  64. package/dist/hub/client.js.map +1 -1
  65. package/dist/hub/compose/member.d.ts +20 -0
  66. package/dist/hub/compose/member.js +212 -17
  67. package/dist/hub/compose/member.js.map +1 -1
  68. package/dist/hub/compose/server.d.ts +8 -0
  69. package/dist/hub/compose/server.js +13 -2
  70. package/dist/hub/compose/server.js.map +1 -1
  71. package/dist/hub/display-name.d.ts +10 -0
  72. package/dist/hub/display-name.js +35 -0
  73. package/dist/hub/display-name.js.map +1 -0
  74. package/dist/hub/execution/service.d.ts +1 -0
  75. package/dist/hub/execution/service.js +1 -1
  76. package/dist/hub/execution/service.js.map +1 -1
  77. package/dist/hub/fleet-info.d.ts +12 -0
  78. package/dist/hub/fleet-info.js +14 -0
  79. package/dist/hub/fleet-info.js.map +1 -0
  80. package/dist/hub/fleet-update-model.d.ts +100 -0
  81. package/dist/hub/fleet-update-model.js +15 -0
  82. package/dist/hub/fleet-update-model.js.map +1 -0
  83. package/dist/hub/fleet-updates.d.ts +46 -0
  84. package/dist/hub/fleet-updates.js +282 -0
  85. package/dist/hub/fleet-updates.js.map +1 -0
  86. package/dist/hub/fleet-versions.d.ts +28 -0
  87. package/dist/hub/fleet-versions.js +80 -0
  88. package/dist/hub/fleet-versions.js.map +1 -0
  89. package/dist/hub/http/compose.d.ts +2 -0
  90. package/dist/hub/http/compose.js +192 -16
  91. package/dist/hub/http/compose.js.map +1 -1
  92. package/dist/hub/http/deps.d.ts +1 -0
  93. package/dist/hub/http/schema.js +13 -1
  94. package/dist/hub/http/schema.js.map +1 -1
  95. package/dist/hub/member/display-name.d.ts +9 -0
  96. package/dist/hub/member/display-name.js +71 -0
  97. package/dist/hub/member/display-name.js.map +1 -0
  98. package/dist/hub/member/exposure-api.d.ts +4 -0
  99. package/dist/hub/member/exposure-api.js +8 -3
  100. package/dist/hub/member/exposure-api.js.map +1 -1
  101. package/dist/hub/member/exposures.d.ts +4 -0
  102. package/dist/hub/member/exposures.js +20 -0
  103. package/dist/hub/member/exposures.js.map +1 -1
  104. package/dist/hub/member/pairing-api.js +3 -2
  105. package/dist/hub/member/pairing-api.js.map +1 -1
  106. package/dist/hub/member/recommendations.d.ts +37 -0
  107. package/dist/hub/member/recommendations.js +129 -0
  108. package/dist/hub/member/recommendations.js.map +1 -0
  109. package/dist/hub/member/room-ask.d.ts +60 -1
  110. package/dist/hub/member/room-ask.js +254 -24
  111. package/dist/hub/member/room-ask.js.map +1 -1
  112. package/dist/hub/member/room-post-answers.d.ts +52 -0
  113. package/dist/hub/member/room-post-answers.js +152 -0
  114. package/dist/hub/member/room-post-answers.js.map +1 -0
  115. package/dist/hub/member/room-post-receipt.d.ts +21 -0
  116. package/dist/hub/member/room-post-receipt.js +49 -0
  117. package/dist/hub/member/room-post-receipt.js.map +1 -0
  118. package/dist/hub/member/room-post.d.ts +100 -0
  119. package/dist/hub/member/room-post.js +223 -0
  120. package/dist/hub/member/room-post.js.map +1 -0
  121. package/dist/hub/member/updates.d.ts +92 -0
  122. package/dist/hub/member/updates.js +316 -0
  123. package/dist/hub/member/updates.js.map +1 -0
  124. package/dist/hub/protocol.d.ts +658 -1
  125. package/dist/hub/protocol.js +90 -13
  126. package/dist/hub/protocol.js.map +1 -1
  127. package/dist/hub/published-version.d.ts +3 -0
  128. package/dist/hub/published-version.js +35 -0
  129. package/dist/hub/published-version.js.map +1 -0
  130. package/dist/hub/recommendation-model.d.ts +36 -0
  131. package/dist/hub/recommendation-model.js +9 -0
  132. package/dist/hub/recommendation-model.js.map +1 -0
  133. package/dist/hub/recommendations.d.ts +58 -0
  134. package/dist/hub/recommendations.js +211 -0
  135. package/dist/hub/recommendations.js.map +1 -0
  136. package/dist/hub/representative.d.ts +3 -0
  137. package/dist/hub/representative.js +2 -1
  138. package/dist/hub/representative.js.map +1 -1
  139. package/dist/hub/room-context-model.d.ts +43 -0
  140. package/dist/hub/room-context-model.js +12 -0
  141. package/dist/hub/room-context-model.js.map +1 -0
  142. package/dist/hub/rooms/agents.d.ts +41 -9
  143. package/dist/hub/rooms/agents.js +183 -21
  144. package/dist/hub/rooms/agents.js.map +1 -1
  145. package/dist/hub/rooms/assistant.d.ts +1 -6
  146. package/dist/hub/rooms/assistant.js +7 -2
  147. package/dist/hub/rooms/assistant.js.map +1 -1
  148. package/dist/hub/rooms/automation.d.ts +24 -0
  149. package/dist/hub/rooms/automation.js +66 -0
  150. package/dist/hub/rooms/automation.js.map +1 -0
  151. package/dist/hub/rooms/buttons.d.ts +85 -0
  152. package/dist/hub/rooms/buttons.js +62 -0
  153. package/dist/hub/rooms/buttons.js.map +1 -0
  154. package/dist/hub/rooms/context-cursor.d.ts +18 -0
  155. package/dist/hub/rooms/context-cursor.js +61 -0
  156. package/dist/hub/rooms/context-cursor.js.map +1 -0
  157. package/dist/hub/rooms/context.d.ts +1 -1
  158. package/dist/hub/rooms/context.js +4 -4
  159. package/dist/hub/rooms/context.js.map +1 -1
  160. package/dist/hub/rooms/mentions.d.ts +15 -0
  161. package/dist/hub/rooms/mentions.js +43 -0
  162. package/dist/hub/rooms/mentions.js.map +1 -0
  163. package/dist/hub/rooms/post-replies.d.ts +23 -0
  164. package/dist/hub/rooms/post-replies.js +114 -0
  165. package/dist/hub/rooms/post-replies.js.map +1 -0
  166. package/dist/hub/rooms/schema.d.ts +9 -0
  167. package/dist/hub/rooms/schema.js +43 -0
  168. package/dist/hub/rooms/schema.js.map +1 -1
  169. package/dist/hub/rooms/service.d.ts +136 -1
  170. package/dist/hub/rooms/service.js +727 -18
  171. package/dist/hub/rooms/service.js.map +1 -1
  172. package/dist/hub/rooms/types.d.ts +27 -3
  173. package/dist/hub/rooms.js +1 -1
  174. package/dist/hub/rooms.js.map +1 -1
  175. package/dist/hub/runtime.d.ts +1 -1
  176. package/dist/hub/runtime.js +12 -0
  177. package/dist/hub/runtime.js.map +1 -1
  178. package/dist/hub/server.d.ts +6 -1
  179. package/dist/hub/server.js +75 -5
  180. package/dist/hub/server.js.map +1 -1
  181. package/dist/hub/settings-directory-proof.js +22 -1
  182. package/dist/hub/settings-directory-proof.js.map +1 -1
  183. package/dist/hub/types.d.ts +133 -2
  184. package/dist/hub-contact-windows.d.ts +11 -0
  185. package/dist/hub-contact-windows.js +56 -0
  186. package/dist/hub-contact-windows.js.map +1 -0
  187. package/dist/hub-pairing-summary.d.ts +1 -1
  188. package/dist/hub-room-conversation.d.ts +14 -0
  189. package/dist/hub-room-conversation.js +60 -0
  190. package/dist/hub-room-conversation.js.map +1 -0
  191. package/dist/hub-update-notice.d.ts +12 -0
  192. package/dist/hub-update-notice.js +35 -0
  193. package/dist/hub-update-notice.js.map +1 -0
  194. package/dist/locale.js +58 -2
  195. package/dist/locale.js.map +1 -1
  196. package/dist/native-mcp.js +9 -6
  197. package/dist/native-mcp.js.map +1 -1
  198. package/dist/outbound-handlers.d.ts +14 -4
  199. package/dist/outbound-handlers.js +54 -1
  200. package/dist/outbound-handlers.js.map +1 -1
  201. package/dist/outbound-schemas.d.ts +12 -0
  202. package/dist/outbound-schemas.js +12 -0
  203. package/dist/outbound-schemas.js.map +1 -1
  204. package/dist/pane-port.d.ts +2 -0
  205. package/dist/queued-handoffs.d.ts +16 -4
  206. package/dist/queued-handoffs.js +18 -1
  207. package/dist/queued-handoffs.js.map +1 -1
  208. package/dist/runtime-cli-install.js +13 -10
  209. package/dist/runtime-cli-install.js.map +1 -1
  210. package/dist/settings-api.d.ts +1 -0
  211. package/dist/settings-api.js +87 -0
  212. package/dist/settings-api.js.map +1 -1
  213. package/dist/tmux-manager.d.ts +2 -0
  214. package/dist/tmux-manager.js +2 -0
  215. package/dist/tmux-manager.js.map +1 -1
  216. package/dist/tool-permissions.js +3 -0
  217. package/dist/tool-permissions.js.map +1 -1
  218. package/dist/ui/chat-msg-actions.js +3 -222
  219. package/dist/ui/hub-admin-overview.js +189 -0
  220. package/dist/ui/hub-client.js +36 -4
  221. package/dist/ui/hub-fleet-versions.js +393 -0
  222. package/dist/ui/hub-room-agent-strings.js +28 -0
  223. package/dist/ui/hub-room-composer.js +16 -8
  224. package/dist/ui/hub-room-members-strings.js +2 -2
  225. package/dist/ui/hub-room-members.js +3 -2
  226. package/dist/ui/hub-room-notify.js +161 -0
  227. package/dist/ui/hub-room-search.js +126 -0
  228. package/dist/ui/hub-room-strings.js +47 -1
  229. package/dist/ui/hub-room-thread.js +243 -35
  230. package/dist/ui/hub-room-unread.js +2 -1
  231. package/dist/ui/hub-strings.js +8 -0
  232. package/dist/ui/image-annotate.js +2 -283
  233. package/dist/ui/image-lightbox.js +2 -176
  234. package/dist/ui/image-zoom.js +2 -242
  235. package/dist/ui/notice-hub-update.js +94 -0
  236. package/dist/ui/panel-chat.js +121 -12
  237. package/dist/ui/panel-hub.js +133 -19
  238. package/dist/ui/panel-notices.js +3 -1
  239. package/dist/ui/panel-settings.js +1 -1
  240. package/dist/ui/settings-hub-updates.js +67 -0
  241. package/dist/ui/settings-hub.js +28 -3
  242. package/dist/ui/settings-registry.js +1 -0
  243. package/dist/ui/settings-update.js +11 -5
  244. package/dist/ui/settings-web-authority.js +1 -1
  245. package/dist/ui/shared/app-i18n.js +2 -0
  246. package/dist/ui/shared/app-nav.js +6 -2
  247. package/dist/ui/shared/app-prefs.js +2 -1
  248. package/dist/ui/shared/app-shell.js +29 -4
  249. package/dist/ui/shared/app-update.js +90 -8
  250. package/dist/ui/shared/app.css +33 -0
  251. package/dist/ui/shared/chat-composer.js +6 -3
  252. package/dist/ui/shared/chat-msg-actions.js +225 -0
  253. package/dist/ui/shared/chat-thread.js +70 -5
  254. package/dist/ui/shared/chat-work-bar.css +48 -0
  255. package/dist/ui/shared/hub-chat.css +16 -2
  256. package/dist/ui/shared/hub-owner.css +104 -0
  257. package/dist/ui/shared/hub-rooms-u2.css +16 -0
  258. package/dist/ui/shared/hub.css +5 -0
  259. package/dist/ui/shared/image-annotate.js +306 -0
  260. package/dist/ui/shared/image-lightbox.js +183 -0
  261. package/dist/ui/shared/image-zoom.js +242 -0
  262. package/dist/ui/shared/instance-nav.js +36 -7
  263. package/dist/ui/shared/model-picker.css +4 -3
  264. package/dist/ui/shared/view-strings.js +8 -0
  265. package/dist/ui/shared/web-authorize.js +2 -2
  266. package/dist/update-dispatch.d.ts +8 -1
  267. package/dist/update-dispatch.js +16 -1
  268. package/dist/update-dispatch.js.map +1 -1
  269. package/dist/update-idle.d.ts +65 -0
  270. package/dist/update-idle.js +190 -0
  271. package/dist/update-idle.js.map +1 -0
  272. package/dist/update-launch.d.ts +1 -1
  273. package/dist/update-launch.js +9 -2
  274. package/dist/update-launch.js.map +1 -1
  275. package/dist/usage/i18n-keys.d.ts +1 -1
  276. package/dist/usage/i18n-keys.js +1 -1
  277. package/dist/usage/i18n-keys.js.map +1 -1
  278. package/dist/usage/profile-timeline.d.ts +2 -0
  279. package/dist/usage/profile-timeline.js +4 -0
  280. package/dist/usage/profile-timeline.js.map +1 -1
  281. package/dist/usage/providers.js +4 -4
  282. package/dist/usage/providers.js.map +1 -1
  283. package/dist/usage/quota-history.d.ts +1 -1
  284. package/dist/view-api.js +1 -1
  285. package/dist/view-api.js.map +1 -1
  286. package/dist/web-api.js +19 -2
  287. package/dist/web-api.js.map +1 -1
  288. package/dist/web-notices.d.ts +3 -0
  289. package/dist/web-notices.js +17 -2
  290. package/dist/web-notices.js.map +1 -1
  291. package/dist/web-prefs.js +1 -0
  292. package/dist/web-prefs.js.map +1 -1
  293. package/dist/web-update.d.ts +15 -1
  294. package/package.json +1 -1
@@ -63,6 +63,7 @@ import { measureSyncWork } from "./sync-work-attribution.js";
63
63
  import { RuntimeCpuProfiler, ProfileBusyError, profileDuration } from "./runtime-cpu-profile.js";
64
64
  import { ProfileControlServer } from "./profile-control.js";
65
65
  import { existsSync, readFileSync, mkdirSync, writeFileSync, unlinkSync, rmSync, readdirSync, renameSync, copyFileSync, chmodSync, statSync, realpathSync, lstatSync, constants as fsConstants, openSync, closeSync, fsyncSync } from "node:fs";
66
+ import { HubContactWindows } from "./hub-contact-windows.js";
66
67
  import { atomicWriteFileSync } from "./atomic-write.js";
67
68
  import { createHash, randomBytes, randomUUID } from "node:crypto";
68
69
  import { freemem, totalmem, homedir, hostname } from "node:os";
@@ -285,7 +286,8 @@ import { GUEST_COMMAND_RUNS, GUEST_PREF_WRITES, GUEST_SEARCHES, bindGuestRequest
285
286
  import { GUEST_ROOM_TICK_MS, GuestRoomMembership, guestGroupRooms } from "./web-guest-rooms.js";
286
287
  import { Delegations, TrafficLog, trafficItem } from "./fleet-traffic.js";
287
288
  import { installedChannel, updateNoticeKey } from "./update-check.js";
288
- import { resolveInstalledAgend } from "./update-dispatch.js";
289
+ import { resolveInstalledAgend, npmForRunningInstall } from "./update-dispatch.js";
290
+ import { HUB_UPDATE_NOTICE_FILE, HUB_UPDATE_REMIND_MS, hubNoticeDue, hubNoticeKey, readHubNoticeState, writeHubNoticeState } from "./hub-update-notice.js";
289
291
  import { resolveUpdateLaunch, openUpdateLog, updateLogPath, watchUpdateLaunch } from "./update-launch.js";
290
292
  import { isWebUpdateTarget, readLogTail, RUNNING_AGEND_VERSION, updateOffer, webProgressOf, webUpdateTarget } from "./web-update.js";
291
293
  import { admitProfileLogin, LoginController, LOGIN_TOKEN_RESEND_PREFIX, POST_LOGIN_RECOVERY_DEADLINE_MS } from "./login-controller.js";
@@ -317,6 +319,8 @@ import { assertNoSessionOomStop, readSessionOomStop, captureSessionOomRetry, cle
317
319
  import { redactSecrets } from "./tool-progress.js";
318
320
  import { idleGateTimeoutLog } from "./idle-gate-log.js";
319
321
  import { DEFAULT_STUCK_TIMEOUT_MS, readLastInboundAt } from "./daemon.js";
322
+ import { CODEX_INLINE_MODEL_MIN, codexModelCommand } from "./backend/codex-model-switch.js";
323
+ import { CLI_RUNTIME_SWITCH } from "./backend/cli-runtime-switch.js";
320
324
  import { clearPausedMarker, readPausedAt, readPauseReason, writePausedMarker } from "./pause-marker.js";
321
325
  import { readBackgroundWorkEndedMarker } from "./background-work-ended.js";
322
326
  import { DEFAULT_WARM_OVERFLOW, WakeCoordinator } from "./wake-coordinator.js";
@@ -612,6 +616,9 @@ const HANG_CALLBACK_PREFIX = "hang:";
612
616
  const CLEAR_CONFIRM_CALLBACK_PREFIX = "clear-confirm:";
613
617
  /** #2598 B2: a kiro classic → TUI move's Confirm in General. "kiro-migrate:" (13) + 32 hex + ":confirm" (8) = 53 bytes. */
614
618
  const KIRO_MIGRATE_CALLBACK_PREFIX = "kiro-migrate:";
619
+ /** M-3140: Update now on a Hub-recommended-version notice in General ("hub-update:" + 32 hex + ":update" = 50 bytes). */
620
+ const HUB_UPDATE_CALLBACK_PREFIX = "hub-update:";
621
+ const HUB_FLEET_UPDATE_CALLBACK_PREFIX = "hub-fleet-update:";
615
622
  const KIRO_RECONCILE_CALLBACK_PREFIX = "kiro-reconcile:";
616
623
  /** #2692: a fleet admin's Approve / Reject on an agent's pending skin-pack change, in General. */
617
624
  const OFFICE_PACK_CALLBACK_PREFIX = "office-pack:";
@@ -708,6 +715,8 @@ const CLI_ENV_FRESH_MS = 60 * 60 * 1000;
708
715
  */
709
716
  /** #1690: how long `/model` waits for the daemon's word on our own runtime switch (its dialog wait plus settling). */
710
717
  export const RUNTIME_SWITCH_RESULT_MS = 12_000;
718
+ /** M-3175: a codex switch may wait up to a minute for its pane to be idle, then up to 10 s for codex to record it. */
719
+ export const CODEX_RUNTIME_SWITCH_RESULT_MS = 80_000;
711
720
  export const CLI_ENV_PROBE_DEADLINE_MS = 16_000;
712
721
  /**
713
722
  * How many CLIs may cold-start at once, from BOTH memory and cores.
@@ -1379,7 +1388,7 @@ export class FleetManager {
1379
1388
  if (this.paneManager)
1380
1389
  return this.paneManager;
1381
1390
  const store = windowsAgentsFor(this, this.runtimeWindowsExecutor());
1382
- const allowed = (name, tool) => nativePaneToolAvailable(tool) && mayUseTool(resolveToolSet(this.fleetConfig?.instances[name], name), tool)
1391
+ const allowed = (name, tool) => (!["hub_room_list", "hub_room_post", "hub_room_members", "hub_people_search"].includes(tool) || this.hubRoomToolsAvailable()) && nativePaneToolAvailable(tool) && mayUseTool(resolveToolSet(this.fleetConfig?.instances[name], name), tool)
1383
1392
  && !dashboardRefusalIn(this.fleetConfig, name, tool);
1384
1393
  return this.paneManager = new NativePaneManager({
1385
1394
  home: this.dataDir, store, config: name => this.fleetConfig?.instances[name],
@@ -1440,14 +1449,14 @@ export class FleetManager {
1440
1449
  return { result: null, error: "Native panes can only read Windows runtime model inventories" };
1441
1450
  return { result: await this.listModelCatalog({ instanceName: target }) };
1442
1451
  }
1443
- const ops = { list_instances: "list", describe_instance: "describe", task: "task", send_to_instance: "send",
1452
+ 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",
1444
1453
  delegate_task: "delegate", request_information: "ask", report_result: "report", delivery_status: "delivery-status" };
1445
1454
  const { nativeAgentAdmissionContext } = await import("./native-agent-admission.js");
1446
1455
  const { dispatchAgentOperation } = await import("./agent-endpoint.js");
1447
1456
  return daemon.handlePaneToolCall(input, { current, allowed: tool => allowed(name, tool),
1448
1457
  dispatch: (tool, args) => ops[tool] ? dispatchAgentOperation(nativeAgentAdmissionContext(this, {
1449
1458
  instance: name, current: () => current() && allowed(name, tool), taskAllowed: () => current() && allowed(name, "task"),
1450
- }), name, ops[tool], args, input.operationId) : undefined });
1459
+ }), name, ops[tool], args, input.operationId, () => current() && allowed(name, tool)) : undefined });
1451
1460
  },
1452
1461
  });
1453
1462
  }
@@ -1671,6 +1680,276 @@ export class FleetManager {
1671
1680
  }
1672
1681
  invalidateHubCompanyJoin() { this.companyJoinController?.invalidate(); }
1673
1682
  hubMemberPairingApi = null;
1683
+ hubRecommendationRead = null;
1684
+ hubRecommendationListeners = new Set();
1685
+ hubRecommendedUpdate() { return this.hubRecommendationRead?.() ?? null; }
1686
+ /**
1687
+ * M-3140: the Hub's advice the asker was shown, if it is still this Fleet's current verified advice and still newer
1688
+ * than what runs (same Hub, version and revision) — else null. What a pinned Update installs comes only from here.
1689
+ */
1690
+ hubRecommendationFor(pin) {
1691
+ const advice = this.hubRecommendedUpdate();
1692
+ if (!advice || advice.version !== pin.version || advice.revision !== pin.revision)
1693
+ return null;
1694
+ let current;
1695
+ try {
1696
+ current = this.runningAgendVersion();
1697
+ }
1698
+ catch {
1699
+ return null;
1700
+ }
1701
+ return this.semverGt(advice.version, current) ? advice : null;
1702
+ }
1703
+ onHubRecommendation(listener) { this.hubRecommendationListeners.add(listener); return () => { this.hubRecommendationListeners.delete(listener); }; }
1704
+ hubRecommendationChanged() {
1705
+ for (const listener of this.hubRecommendationListeners) {
1706
+ try {
1707
+ listener();
1708
+ }
1709
+ catch { /* local presentation observer */ }
1710
+ }
1711
+ void this.maybeNotifyHubRecommendation(); // M-3140: the first notice need not wait for the daily check
1712
+ }
1713
+ /**
1714
+ * M-3140 (spec §3.3, chat): the Hub's recommended version in General, with Update now — when it first applies to this
1715
+ * Fleet, then every 7 days while still behind (hub-update-notice.ts). A web-only fleet has no chat: its banner says it.
1716
+ * Asked on every change of the advice and on the daily update check.
1717
+ */
1718
+ async maybeNotifyHubRecommendation() {
1719
+ if (this.hubUpdateNoticeBusy || this.shuttingDown)
1720
+ return;
1721
+ this.hubUpdateNoticeBusy = true;
1722
+ try {
1723
+ const advice = this.hubRecommendedUpdate();
1724
+ let current = null;
1725
+ try {
1726
+ current = this.runningAgendVersion();
1727
+ }
1728
+ catch {
1729
+ return;
1730
+ }
1731
+ const path = join(this.dataDir, HUB_UPDATE_NOTICE_FILE), now = Date.now();
1732
+ if (!hubNoticeDue(readHubNoticeState(path), advice, current, now, (a, b) => this.semverGt(a, b)) || !advice)
1733
+ return;
1734
+ if (this.webOnlyPromptPlace())
1735
+ return;
1736
+ const general = this.findGeneralInstance();
1737
+ const adapterId = general ? this.getInstanceAdapterId(general) : undefined;
1738
+ const adapter = general ? this.getAdapterForInstance(general) : undefined;
1739
+ const chatId = general ? this.getGroupIdForInstance(general) : undefined;
1740
+ const topic = general ? String(this.fleetConfig?.instances[general]?.topic_id ?? "") : "";
1741
+ if (!general || !adapterId || !adapter || !chatId)
1742
+ return;
1743
+ const nonce = await this.postNonceButtonPromptOrThrow({
1744
+ prefix: HUB_UPDATE_CALLBACK_PREFIX, alertType: "tip", instanceName: general, adapter, adapterId, chatId,
1745
+ ...(topic ? { threadId: topic } : {}),
1746
+ message: t("hub_update.notice", advice.hubName, `v${advice.version}`, `v${current}`),
1747
+ choices: [{ action: "update", label: t("hub_update.button") }],
1748
+ expiredText: t("hub_update.expired"),
1749
+ timeoutMs: HUB_UPDATE_REMIND_MS,
1750
+ });
1751
+ this.pendingHubUpdates.set(nonce, { version: advice.version, revision: advice.revision });
1752
+ const expiry = setTimeout(() => this.pendingHubUpdates.delete(nonce), HUB_UPDATE_REMIND_MS + 60_000);
1753
+ expiry.unref?.();
1754
+ writeHubNoticeState(path, { key: hubNoticeKey(advice), at: now });
1755
+ }
1756
+ catch (err) {
1757
+ this.logger.warn({ err: err.message }, "Hub recommended-version notice not posted");
1758
+ }
1759
+ finally {
1760
+ this.hubUpdateNoticeBusy = false;
1761
+ }
1762
+ }
1763
+ /**
1764
+ * M-3140: Update now on that notice — what chat /update does (a fleet admin's, the installed agend launched
1765
+ * independently, its progress on the message), pinned to the advice the notice named, re-read now and at the launch.
1766
+ */
1767
+ async handleHubUpdateCallback(data, adapterId, adapter) {
1768
+ // Fable #3955: a fleet admin's press only. Anyone else in General is told privately, and the nonce and the button stay
1769
+ // for an admin (consumeNonceCallback's authorize: refused before anything is consumed or retired).
1770
+ const claimed = this.consumeNonceCallback(HUB_UPDATE_CALLBACK_PREFIX, /^hub-update:([0-9a-f]{32}):(update)$/, data, adapterId, adapter, undefined, userId => this.fleetAdminGate(userId, adapterId) === "ok");
1771
+ if (claimed === null)
1772
+ return false;
1773
+ if (claimed === "consumed")
1774
+ return true;
1775
+ const { entry } = claimed;
1776
+ const nonce = data.callbackData.slice(HUB_UPDATE_CALLBACK_PREFIX.length, HUB_UPDATE_CALLBACK_PREFIX.length + 32);
1777
+ const pin = this.pendingHubUpdates.get(nonce);
1778
+ this.pendingHubUpdates.delete(nonce);
1779
+ const messageId = entry.messageId ?? data.messageId;
1780
+ const advice = pin ? this.hubRecommendationFor(pin) : null;
1781
+ if (!pin || !advice) {
1782
+ await this.retireNonceButtons(entry, messageId, t("hub_update.changed"));
1783
+ return true;
1784
+ }
1785
+ const by = data.userId ?? "";
1786
+ await this.retireNonceButtons(entry, messageId, t("update.progress.preparing", 0));
1787
+ if (messageId && entry.adapter)
1788
+ this.beginUpdateProgress(entry.adapter, entry.chatId, entry.threadId, messageId);
1789
+ await this.launchInstalledUpdate(`hub-recommended /update by ${adapterId}:${by}`, () => this.fleetAdminGate(by, adapterId) === "ok" && !this.shuttingDown && this.hubRecommendationFor(pin) !== null, advice.version);
1790
+ return true;
1791
+ }
1792
+ hubUpdates = null;
1793
+ hubUpdateOwned = null;
1794
+ hubUpdateBootProgress = null;
1795
+ pendingHubFleetUpdates = new Map();
1796
+ hubFleetUpdates() { return this.hubUpdates; }
1797
+ hubUpdateIdle() {
1798
+ if (!this.startupComplete || this.shuttingDown || this.reconcileInFlight || this.topicCleanupInFlight
1799
+ || this.deliveryPumpRunning || (this.webUpdateOwned && this.webUpdateOwned !== this.hubUpdateOwned?.claim))
1800
+ return false;
1801
+ for (const name of Object.keys(this.fleetConfig?.instances ?? {})) {
1802
+ if (this.restartsInFlight.has(name) || this.stopsInFlight.has(name) || this.handOffsInFlight.has(name)
1803
+ || this.ipcConnectInFlight.has(name) || this.ipcReconnectInFlight.has(name) || this.hasPendingIdleGatedDelivery(name)
1804
+ || this.webChannelEchoTails.has(name))
1805
+ return false;
1806
+ const worker = this.queueWorkers.get(name);
1807
+ if (worker?.busy || worker?.inFlight)
1808
+ return false;
1809
+ const process = this.getInstanceStatus(name);
1810
+ if (process === "stopped" || process === "crashed")
1811
+ continue;
1812
+ if (process === "paused" && ["stopped", "crashed"].includes(this.daemons.get(name)?.getProcessStatus?.() ?? "unknown"))
1813
+ continue;
1814
+ if (process !== "running" || this.getInstanceExecutionState(name) !== "idle")
1815
+ return false;
1816
+ if (this.getInstanceInteraction(name)?.phase === "waiting")
1817
+ return false;
1818
+ }
1819
+ return true;
1820
+ }
1821
+ async hubUpdateCanInstall() {
1822
+ const found = await npmForRunningInstall();
1823
+ if ("reason" in found)
1824
+ return false;
1825
+ const { access } = await import("node:fs/promises"), { constants } = await import("node:fs");
1826
+ try {
1827
+ await access(found.root, constants.W_OK);
1828
+ await access(found.prefix, constants.W_OK);
1829
+ return true;
1830
+ }
1831
+ catch {
1832
+ return false;
1833
+ }
1834
+ }
1835
+ async launchHubUpdate(row, control) {
1836
+ if (this.shuttingDown || this.webUpdateOwned || isUpdateInProgress(this.dataDir) || !control.current())
1837
+ return false;
1838
+ const claim = { startedAt: Date.now() }, owned = { id: row.id, claim };
1839
+ this.hubUpdateOwned = owned;
1840
+ this.webUpdateOwned = claim;
1841
+ const release = () => { if (this.hubUpdateOwned === owned)
1842
+ this.hubUpdateOwned = null; if (this.webUpdateOwned === claim)
1843
+ this.webUpdateOwned = null; };
1844
+ if (!persistUpdateProgress(this.dataDir, { ...webUpdateTarget(claim.startedAt), messageId: `hub-fleet-update:${row.id}` }, claim.startedAt)
1845
+ || !setUpdateProgressStage(this.dataDir, "preparing", { version: row.version })) {
1846
+ release();
1847
+ return false;
1848
+ }
1849
+ try {
1850
+ const child = await this.launchInstalledUpdate(`Hub-requested update ${row.id}`, () => !this.shuttingDown && this.hubUpdateOwned === owned && control.current() && control.claim(), row.version);
1851
+ if (!child) {
1852
+ release();
1853
+ return false;
1854
+ }
1855
+ let endedOnce = false;
1856
+ const ended = () => {
1857
+ if (endedOnce)
1858
+ return;
1859
+ endedOnce = true;
1860
+ const settle = () => {
1861
+ if (this.shuttingDown || this.hubUpdateOwned !== owned)
1862
+ return;
1863
+ // systemd-run may exit before its independent updater. Keep the claim while its bounded marker is active.
1864
+ const marker = readUpdateProgress(this.dataDir)?.progress;
1865
+ if (marker?.target.messageId === `hub-fleet-update:${row.id}` && isUpdateInProgress(this.dataDir)) {
1866
+ const timer = setTimeout(settle, 5000);
1867
+ timer.unref();
1868
+ return;
1869
+ }
1870
+ release();
1871
+ const outcome = this.hubUpdateOutcome(row);
1872
+ if (outcome)
1873
+ this.hubUpdates?.complete(row.id, outcome.state, outcome.currentVersion, "interrupted");
1874
+ };
1875
+ settle();
1876
+ };
1877
+ child.once("exit", ended);
1878
+ child.once("error", ended);
1879
+ return true;
1880
+ }
1881
+ catch {
1882
+ release();
1883
+ return false;
1884
+ }
1885
+ }
1886
+ hubUpdateOutcome(row) {
1887
+ if (!this.startupComplete || this.hubUpdateOwned?.id === row.id)
1888
+ return null;
1889
+ const currentVersion = this.runningAgendVersion();
1890
+ if (currentVersion.replace(/^v/, "") === row.version.replace(/^v/, ""))
1891
+ return { state: "done", currentVersion };
1892
+ const matches = (m) => m?.progress.target.messageId === `hub-fleet-update:${row.id}` && m.progress.version === row.version;
1893
+ const saved = readUpdateProgress(this.dataDir);
1894
+ // Startup may clear the ordinary progress marker before the optional Hub mount finishes.
1895
+ const marker = (matches(saved) ? saved : matches(this.hubUpdateBootProgress) ? this.hubUpdateBootProgress : null)?.progress;
1896
+ const reachedRestart = marker && (["installed", "stopping", "starting", "complete"].includes(marker.stage)
1897
+ || marker.stage === "failed" && (marker.failedStage === "starting" || marker.failedStage === "stopping"));
1898
+ return { state: reachedRestart ? "rolled-back" : "failed", currentVersion };
1899
+ }
1900
+ recordHubUpdateNotice(n) {
1901
+ const store = this.webNoticeStore();
1902
+ if (!store)
1903
+ return false;
1904
+ const text = t(`hub_fleet_update.${n.state}`, n.hubName, n.requestedBy, n.version, n.currentVersion ?? "");
1905
+ const prior = store.view().items.some(i => i.hubUpdate?.requestId === n.requestId && i.hubUpdate.state === n.state);
1906
+ const notice = store.addDurable({ kind: "update", text, hubUpdate: n });
1907
+ if (!notice)
1908
+ return false;
1909
+ this.emitSseEvent("notice", { notice, unread: store.unread() });
1910
+ if (!prior && !this.webOnlyPromptPlace())
1911
+ void this.postHubUpdateChat(n, text).catch(() => this.logger.warn("Hub update owner chat notice could not be posted"));
1912
+ return true;
1913
+ }
1914
+ async postHubUpdateChat(n, text) {
1915
+ const general = this.findGeneralInstance();
1916
+ if (!general)
1917
+ return;
1918
+ if (n.state !== "waiting" && n.state !== "expired") {
1919
+ this.notifyInstanceTopic(general, text);
1920
+ return;
1921
+ }
1922
+ const adapter = this.getAdapterForInstance(general), adapterId = this.getInstanceAdapterId(general), chatId = this.getGroupIdForInstance(general);
1923
+ if (!adapter || !adapterId || !chatId)
1924
+ return;
1925
+ const threadId = String(this.fleetConfig?.instances[general]?.topic_id ?? "");
1926
+ const nonce = await this.postNonceButtonPromptOrThrow({ prefix: HUB_FLEET_UPDATE_CALLBACK_PREFIX, alertType: "tip", instanceName: general,
1927
+ adapter, adapterId, chatId, ...(threadId ? { threadId } : {}), message: text,
1928
+ choices: [{ action: "update", label: t("hub_update.button") }, ...(n.state === "waiting" ? [{ action: "cancel", label: t("hub_fleet_update.cancel") }] : [])],
1929
+ expiredText: t("hub_update.expired"), timeoutMs: 24 * 60 * 60_000 });
1930
+ this.pendingHubFleetUpdates.set(nonce, n.requestId);
1931
+ const timer = setTimeout(() => this.pendingHubFleetUpdates.delete(nonce), 24 * 60 * 60_000 + 60_000);
1932
+ timer.unref();
1933
+ }
1934
+ async handleHubFleetUpdateCallback(data, adapterId, adapter) {
1935
+ const claimed = this.consumeNonceCallback(HUB_FLEET_UPDATE_CALLBACK_PREFIX, /^hub-fleet-update:([0-9a-f]{32}):(update|cancel)$/, data, adapterId, adapter, undefined, userId => this.fleetAdminGate(userId, adapterId) === "ok");
1936
+ if (claimed === null)
1937
+ return false;
1938
+ if (claimed === "consumed")
1939
+ return true;
1940
+ const nonce = data.callbackData.slice(HUB_FLEET_UPDATE_CALLBACK_PREFIX.length, HUB_FLEET_UPDATE_CALLBACK_PREFIX.length + 32);
1941
+ const id = this.pendingHubFleetUpdates.get(nonce);
1942
+ this.pendingHubFleetUpdates.delete(nonce);
1943
+ const owner = this.hubUpdates, value = id ? owner?.view(id) : null;
1944
+ await this.retireNonceButtons(claimed.entry, claimed.entry.messageId ?? data.messageId, t("hub_update.expired"));
1945
+ if (!id || !owner || !value)
1946
+ return true;
1947
+ if (claimed.action === "cancel")
1948
+ owner.cancel({ id, version: value.version });
1949
+ else
1950
+ await this.startHubRequestedUpdateOnce(`chat:${nonce}`, `${adapterId}:${data.userId}`, () => this.fleetAdminGate(data.userId ?? "", adapterId) === "ok" && !this.shuttingDown, id);
1951
+ return true;
1952
+ }
1674
1953
  hubPairingNotices = null;
1675
1954
  hubMemberPairing() { return this.hubMemberPairingApi; }
1676
1955
  /** Explicit owner Settings read only. A paused binding is not permission to mount or connect a member. */
@@ -2194,6 +2473,7 @@ export class FleetManager {
2194
2473
  hubRuntimeCreated() {
2195
2474
  this.hubRuntimeInit ??= (async () => {
2196
2475
  const { HubRuntime } = await import("./hub/runtime.js");
2476
+ const { verifyRoomReceipt } = await import("./hub/member/room-post-receipt.js");
2197
2477
  // M-2682: the one writer for sealed Hub settings (a rename from Hub Administration). It saves hub.* through this
2198
2478
  // fleet's own synchronous writer, so nothing else here runs between its commit point and the new pair in force.
2199
2479
  const { createHubSettingsWriter } = await import("./hub/settings-commit.js");
@@ -2262,9 +2542,33 @@ export class FleetManager {
2262
2542
  inboxDir: agent => isSafeInstanceDirName(agent) ? join(this.dataDir, "workspaces", agent, "inbox") : null,
2263
2543
  scratchDir: agent => isSafeInstanceDirName(agent) ? join(this.dataDir, "workspaces", agent, "hub-files") : null },
2264
2544
  attachReports: (handler, failed) => { this.hubReports = handler; this.hubDeliveryFailed = failed; },
2545
+ attachReacts: handler => { this.hubReacts = handler; },
2265
2546
  },
2547
+ attachAgentRooms: port => { this.hubAgentRooms = port; this.notifyHubRoomTools(); },
2548
+ roomToolsChanged: () => this.notifyHubRoomTools(),
2549
+ roomConversationGeneration: agent => this.daemons.get(agent)?.roomConversationGeneration() ?? null,
2550
+ attachRoomInputs: handler => { this.hubRoomInput = handler; },
2551
+ roomNotify: input => this.deliverHubRoomPostAnswer(input),
2552
+ roomReceipt: (caller, receiptId) => verifyRoomReceipt({
2553
+ lookup: (agent, id) => {
2554
+ const item = this.queryDurableDeliveryStatus(agent, { messageId: id }).items[0];
2555
+ if (item?.message_id !== id || !item.authority)
2556
+ return null;
2557
+ const row = this.deliveryOutbox?.getHumanReceipt(id.slice(5));
2558
+ return row ? { row, authority: item.authority } : null;
2559
+ },
2560
+ admin: (agent, actor) => actor.adapter_id === HOST_OPERATOR.adapterId && actor.user_id === HOST_OPERATOR.userId
2561
+ ? this.isWebOnlyFleet()
2562
+ : this.getInstanceAdapterId(agent) === actor.adapter_id && this.isFleetAdmin(actor.user_id, actor.adapter_id),
2563
+ }, caller.agent, receiptId),
2266
2564
  attachExposures: api => this.attachHubMemberExposures(api),
2267
2565
  attachAttention: read => this.attachHubExecutionAttention(read),
2566
+ updates: { idle: () => this.hubUpdateIdle(), busy: () => !!this.webUpdateOwned || isUpdateInProgress(this.dataDir),
2567
+ canInstall: () => this.hubUpdateCanInstall(), launch: (row, control) => this.launchHubUpdate(row, control),
2568
+ active: id => this.hubUpdateOwned?.id === id, outcome: row => this.hubUpdateOutcome(row), notify: n => this.recordHubUpdateNotice(n) },
2569
+ attachUpdates: updates => { this.hubUpdates = updates; },
2570
+ attachRecommendations: read => { this.hubRecommendationRead = read; },
2571
+ recommendationChanged: () => this.hubRecommendationChanged(),
2268
2572
  attachPairingNotices: read => { this.hubPairingNotices = read; },
2269
2573
  pokeAttention: () => this.needsYou?.poke(),
2270
2574
  linkState: (state, digest) => { this.hubMemberLink = state; this.hubMemberLinkBinding = digest ?? null; },
@@ -2544,6 +2848,11 @@ export class FleetManager {
2544
2848
  throw new Error(`Hub consent for ${agent} could not be invalidated durably; refusing the change (${err?.message})`);
2545
2849
  }
2546
2850
  }
2851
+ hubContactWindows = null;
2852
+ contactWindows() {
2853
+ return this.hubContactWindows ??= new HubContactWindows(join(this.dataDir, "hub-contact-windows.json"));
2854
+ }
2855
+ hubContactRestricted(agent) { return this.contactWindows().restricted(agent); }
2547
2856
  /**
2548
2857
  * A Hub question to its representative agent: ordinary cross-instance delivery (idle gate, wake, retries), from the
2549
2858
  * reserved Hub sender with the Hub-issued correlation id. beforeInput runs immediately before the IPC hand-off.
@@ -2569,7 +2878,26 @@ export class FleetManager {
2569
2878
  requires_reply: "true",
2570
2879
  task_summary: "A question from the Hub",
2571
2880
  };
2572
- const result = await this.deliverToInstance(input.agent, { type: "fleet_inbound", targetSession: input.agent, content: input.text, meta: ipcMeta }, { isCrossInstance: true, stillCurrent: input.stillCurrent, beforeInput: input.beforeInput });
2881
+ if (input.roomContextGeneration)
2882
+ ipcMeta.hub_room_context_generation = input.roomContextGeneration;
2883
+ 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 () => {
2884
+ if (!(await input.beforeInput()))
2885
+ return false;
2886
+ // Before any possible IPC exposure. An uncertain write retains the window, never replays the question.
2887
+ if (input.contactLimit !== false)
2888
+ this.contactWindows().begin(input.agent, input.correlationId);
2889
+ return input.stillCurrent();
2890
+ } });
2891
+ return result !== false;
2892
+ }
2893
+ async deliverHubRoomPostAnswer(input) {
2894
+ const { HUB_REPORT_TARGET } = await import("./hub/representative.js");
2895
+ if (this.shuttingDown || !this.fleetConfig?.instances[input.agent] || isNativeExecInstance(this.fleetConfig.instances[input.agent]))
2896
+ return false;
2897
+ const result = await this.deliverToInstance(input.agent, { type: "fleet_inbound", targetSession: input.agent, content: input.text,
2898
+ meta: { chat_id: "", message_id: `hub-room-post-answer-${input.id}`, user: `instance:${HUB_REPORT_TARGET}`, user_id: `instance:${HUB_REPORT_TARGET}`,
2899
+ ts: new Date().toISOString(), thread_id: "", from_instance: HUB_REPORT_TARGET, from_display: "Hub", correlation_id: `hub-room-post-answer-${input.id}`,
2900
+ request_kind: "notification", requires_reply: "false", task_summary: "A reply to your Hub room post" } }, { isCrossInstance: true, stillCurrent: input.stillCurrent, beforeInput: input.beforeInput });
2573
2901
  return result !== false;
2574
2902
  }
2575
2903
  /** S-51: why the Hub (or this fleet's Hub membership) is not running, if it is held. Empty while off or running. */
@@ -2673,10 +3001,48 @@ export class FleetManager {
2673
3001
  hubMemberLinkBinding = null;
2674
3002
  /** OutboundContext: the Hub representative's answer hook (null: no member service running, or not a Hub answer). */
2675
3003
  hubReport(input) {
2676
- return this.hubReports?.(input) ?? null;
3004
+ const result = this.hubReports?.(input) ?? null;
3005
+ if (!result)
3006
+ return null;
3007
+ return result.then(outcome => {
3008
+ if (outcome.ok) {
3009
+ try {
3010
+ this.contactWindows().answered(input.caller, input.correlationId);
3011
+ }
3012
+ catch (err) {
3013
+ this.logger.warn({ err }, "Hub contact window could not be closed; it will expire");
3014
+ }
3015
+ }
3016
+ return outcome;
3017
+ });
3018
+ }
3019
+ /** M-3127 OutboundContext: an agent's `react` on a Hub room question (its correlation id as message_id); null: not one. */
3020
+ hubReact(input) {
3021
+ return this.hubReacts?.(input) ?? null;
2677
3022
  }
3023
+ hubReacts = null;
2678
3024
  /** The member side's pane-failure hook for a Hub-issued correlation id (else null). */
3025
+ hubRoomInput = null;
2679
3026
  hubDeliveryFailed = null;
3027
+ /** The connected member adapter; never an agent-selectable identity. */
3028
+ hubAgentRooms = null;
3029
+ hubRoomToolsAvailable() { return this.hubAgentRooms?.available() === true; }
3030
+ hubRoomList(caller) {
3031
+ return this.hubAgentRooms?.rooms(caller) ?? Promise.resolve({ ok: false, code: "unavailable" });
3032
+ }
3033
+ hubRoomMembers(caller, room) {
3034
+ return this.hubAgentRooms?.members(caller, room) ?? Promise.resolve({ ok: false, code: "unavailable" });
3035
+ }
3036
+ hubPeopleSearch(caller, q) {
3037
+ return this.hubAgentRooms?.people(caller, q) ?? Promise.resolve({ ok: false, code: "unavailable" });
3038
+ }
3039
+ hubRoomPost(caller, value) {
3040
+ return this.hubAgentRooms?.post(caller, value) ?? Promise.resolve({ ok: false, code: "unavailable" });
3041
+ }
3042
+ notifyHubRoomTools() {
3043
+ for (const ipc of this.instanceIpcClients.values())
3044
+ ipc.send({ type: "hub_room_tools_changed" });
3045
+ }
2680
3046
  /** The member side's report_result hook for HUB_REPORT_TARGET while a representative service runs (else null). */
2681
3047
  hubReports = null;
2682
3048
  /** The one in-flight creation (single flight): overlapping first observations share it, Stop waits for it. */
@@ -2867,6 +3233,9 @@ export class FleetManager {
2867
3233
  pendingNonceButtons = new Map();
2868
3234
  /** #2598 B2: the kiro moves waiting on a fleet admin's Confirm in General, by prompt nonce. */
2869
3235
  pendingKiroMigrations = new Map();
3236
+ /** M-3140: a posted Hub-update notice's advice (by its nonce) — which advice the button was offered for. */
3237
+ pendingHubUpdates = new Map();
3238
+ hubUpdateNoticeBusy = false;
2870
3239
  pendingKiroReconciliations = new Map();
2871
3240
  kiroMigrationRuns = new Map();
2872
3241
  /** #1386 "Needs you": the list, its live chat messages and Acknowledge. Started with the fleet (finishStartup). */
@@ -6444,7 +6813,7 @@ export class FleetManager {
6444
6813
  * independently with its log — or a failure in the progress marker. `stillAllowed` is asked again once the awaits
6445
6814
  * are done (the asker may have lost the right, or the fleet begun stopping, meanwhile).
6446
6815
  */
6447
- async launchInstalledUpdate(origin, stillAllowed) {
6816
+ async launchInstalledUpdate(origin, stillAllowed, pin) {
6448
6817
  const { spawn } = await import("./child-process.js");
6449
6818
  const installed = await resolveInstalledAgend();
6450
6819
  if (!installed.ok) {
@@ -6452,7 +6821,8 @@ export class FleetManager {
6452
6821
  return null;
6453
6822
  }
6454
6823
  recordInternalRequest(this.dataDir, "update", origin);
6455
- const launch = await resolveUpdateLaunch(installed.agend, undefined, installed.npmDir);
6824
+ // M-3140: `pin` — this exact version (a Hub's recommendation, re-resolved by the caller), not the install's channel.
6825
+ const launch = await resolveUpdateLaunch(installed.agend, undefined, installed.npmDir, pin);
6456
6826
  if (!launch.ok) {
6457
6827
  this.failUpdateProgress(`${t("update.failure.shell")} ${t("update.failure.independent", launch.reason)}`);
6458
6828
  return null;
@@ -9895,6 +10265,22 @@ export class FleetManager {
9895
10265
  && this.getInstanceAdapterId(name) === owner.adapterId && String(this.getGroupIdForInstance(name) ?? "") === owner.chatId
9896
10266
  && cfg.topic_id?.toString() === owner.threadId);
9897
10267
  }
10268
+ /**
10269
+ * M-3163: the one General of `adapterId` (its group and topic) as `userId`'s code owner — where a returning device's new code is
10270
+ * meant for (#1570; requestReturningCode still checks it all again, with the live binding, before anything is sent). Null when
10271
+ * that connection has no General with a topic, or more than one.
10272
+ */
10273
+ generalOwnerOf(adapterId, userId) {
10274
+ const found = [];
10275
+ for (const [name, cfg] of Object.entries(this.fleetConfig?.instances ?? {})) {
10276
+ if (!cfg.general_topic || this.getInstanceAdapterId(name) !== adapterId)
10277
+ continue;
10278
+ const group = String(this.getGroupIdForInstance(name) ?? ""), topic = cfg.topic_id?.toString();
10279
+ if (group && topic)
10280
+ found.push({ adapterId, userId, chatId: group, threadId: topic });
10281
+ }
10282
+ return found.length === 1 ? found[0] : null;
10283
+ }
9898
10284
  /** Exact owning General. No primary-adapter or name fallback participates in authorization. */
9899
10285
  dashboardOwner(userId, adapterId, address, threadId, username) {
9900
10286
  const world = this.worlds.get(adapterId);
@@ -11429,6 +11815,7 @@ export class FleetManager {
11429
11815
  // #1737 review: the marker this boot adopts — the startup clear may only ever clear this one.
11430
11816
  const bootUpdateMarker = updateMarkerIdentity(this.dataDir);
11431
11817
  const savedUpdateProgress = readUpdateProgress(this.dataDir);
11818
+ this.hubUpdateBootProgress = savedUpdateProgress;
11432
11819
  const pendingUpdateProgress = savedUpdateProgress
11433
11820
  && savedUpdateProgress.progress.stage !== "failed"
11434
11821
  && savedUpdateProgress.progress.stage !== "complete"
@@ -12118,7 +12505,7 @@ export class FleetManager {
12118
12505
  /**
12119
12506
  * #3066 §1: estimate each account's weekly 100% from the quota history (§1d) and the usage ledger's hours — both read
12120
12507
  * asynchronously, the arithmetic small (usage/capacity.ts). An account is its usage provider id ("claude",
12121
- * "claude:hsinlin", "codex:yanxianchen"): its hours are the ledger sources of that backend under that credential profile
12508
+ * "claude:work", "codex:team"): its hours are the ledger sources of that backend under that credential profile
12122
12509
  * (Codex's "unrecorded" hours are no account's). A per-model weekly ("Sonnet (weekly)") counts only that model's tokens.
12123
12510
  *
12124
12511
  * Prism #3073: no estimate rather than a wrong one —
@@ -13060,6 +13447,10 @@ export class FleetManager {
13060
13447
  else if (msg.type === "instance_progress") {
13061
13448
  this.cacheInstanceProgress(name, msg.progress || null);
13062
13449
  }
13450
+ else if (msg.type === "hub_room_input") {
13451
+ if (this.instanceIpcClients.get(name) === ipc && typeof msg.correlationId === "string" && typeof msg.generation === "string")
13452
+ this.hubRoomInput?.(msg.correlationId, name, msg.generation);
13453
+ }
13063
13454
  else if (msg.type === "cross_instance_delivery_failed") {
13064
13455
  const senderSession = String(msg.senderSession ?? "");
13065
13456
  const targetInstance = String(msg.targetInstance ?? name);
@@ -13387,7 +13778,7 @@ export class FleetManager {
13387
13778
  * A reaction is context, not a message (#432, reworking #413): it never triggers
13388
13779
  * an agent turn and never wakes anything. It is queued in the event log and rides
13389
13780
  * into the instance's NEXT real message as one compact leading line —
13390
- * `[Recent reactions: 👍×2 from hanhanv]` — after which it is marked consumed.
13781
+ * `[Recent reactions: 👍×2 from user1]` — after which it is marked consumed.
13391
13782
  * No pending reactions → no line → zero context spent, which is the common case.
13392
13783
  */
13393
13784
  async handleInboundReaction(r) {
@@ -14501,7 +14892,7 @@ export class FleetManager {
14501
14892
  // Above the adapter check on purpose: "retry shortly" is the wrong answer
14502
14893
  // to a call that will never be allowed, and an agent that believes it is a
14503
14894
  // timing problem will keep trying.
14504
- const permitted = this.checkToolPermission("ipc-outbound", instanceName, tool);
14895
+ const permitted = this.checkToolPermission("ipc-outbound", instanceName, tool === "hub_room_status" ? "hub_room_list" : tool);
14505
14896
  if (!permitted.allowed) {
14506
14897
  respond(null, permitted.message);
14507
14898
  return;
@@ -14516,6 +14907,27 @@ export class FleetManager {
14516
14907
  });
14517
14908
  return;
14518
14909
  }
14910
+ // M-3127: a reaction to a Hub room question (message_id = the correlation id it came with) goes to that room, under
14911
+ // the question — never to a chat. Only that question's agent; the same source-daemon fence as its Hub answer.
14912
+ if (tool === "react" && typeof args.message_id === "string" && /^hub-room-[0-9a-f-]{36}$/.test(args.message_id)) {
14913
+ const bootNow = this.getDaemonBootId(instanceName), bootSent = sourceDaemonBootId ?? bootNow;
14914
+ if (!bootNow || bootSent !== bootNow) {
14915
+ respond(null, "Source daemon generation is no longer current; outcome is unknown");
14916
+ return;
14917
+ }
14918
+ const claimed = this.hubReact({ correlationId: args.message_id, caller: instanceName, emoji: typeof args.emoji === "string" ? args.emoji : "",
14919
+ callerCurrent: () => this.getDaemonBootId(instanceName) === bootSent });
14920
+ if (!claimed) {
14921
+ respond(null, "That message_id is not a Hub room question you were asked.");
14922
+ return;
14923
+ }
14924
+ const outcome = await claimed;
14925
+ if (outcome.ok)
14926
+ respond("ok");
14927
+ else
14928
+ respond(null, outcome.message);
14929
+ return;
14930
+ }
14519
14931
  // #2305: a reaction to a web chat message is the web chat's own (any fleet, web-only included): never an adapter's.
14520
14932
  if (tool === "react" && typeof args.message_id === "string" && isWebMessageId(args.message_id)) {
14521
14933
  // The socket's own instance, never a session name the caller wrote itself (as checkToolPermission: it was not
@@ -18792,6 +19204,10 @@ export class FleetManager {
18792
19204
  return true;
18793
19205
  if (await this.handleKiroMigrateCallback(data, adapterId, adapter))
18794
19206
  return true;
19207
+ if (await this.handleHubFleetUpdateCallback(data, adapterId, adapter))
19208
+ return true;
19209
+ if (await this.handleHubUpdateCallback(data, adapterId, adapter))
19210
+ return true;
18795
19211
  if (await this.handleKiroReconcileCallback(data, adapterId, adapter))
18796
19212
  return true;
18797
19213
  if (await this.handleOfficePackCallback(data, adapterId, adapter))
@@ -20220,6 +20636,8 @@ export class FleetManager {
20220
20636
  kind: "ok",
20221
20637
  knownCookie: addSigninKnownDevice(webToken, input.knownCookie, who, enrollment, epoch, now),
20222
20638
  session: outside ? { remote: "totp" } : actor ? { owner: actor } : {},
20639
+ // M-3163: a chat admin's browser becomes their returning device, as a code DM'd to them makes it (#1570).
20640
+ ...(!outside && actor ? (() => { const o = this.generalOwnerOf(actor.adapterId, actor.userId); return o ? { returningOwner: o } : {}; })() : {}),
20223
20641
  // Asked again as the session is made: the same app, still an admin, still allowed here.
20224
20642
  commit: (record, label) => {
20225
20643
  if (!this.totpSignInOpen(exposureId, peer) || store.enrollmentOf(who) !== enrollment)
@@ -25033,6 +25451,103 @@ export class FleetManager {
25033
25451
  this.logger.info({ instanceName, model }, "Runtime model switch sent");
25034
25452
  });
25035
25453
  }
25454
+ /**
25455
+ * M-3175: codex's `/model [NAME] --reasoning=LEVEL` in the running session. The daemon types it only into an idle pane of a
25456
+ * codex at 0.164.0 or later (else `not_sent`, with the reason) and reports what codex recorded. Its wait for idle is part of
25457
+ * the time allowed here.
25458
+ */
25459
+ runCodexRuntimeSwitch(instanceName, model, effort) {
25460
+ const ipc = this.instanceIpcClients.get(instanceName), line = codexModelCommand(model, effort);
25461
+ if (!ipc || !line)
25462
+ return Promise.resolve({ outcome: "not_sent" });
25463
+ const id = `switch-${randomUUID()}`;
25464
+ return new Promise(resolve => {
25465
+ const timer = setTimeout(() => { this.runtimeSwitchWaiters.delete(id); resolve({ outcome: "not_confirmed" }); }, CODEX_RUNTIME_SWITCH_RESULT_MS);
25466
+ timer.unref?.();
25467
+ this.runtimeSwitchWaiters.set(id, result => { clearTimeout(timer); resolve(result); });
25468
+ const sent = ipc.send({ type: "raw_paste", content: line, runtime_switch: { id, kind: "model", requested: model ?? "", codex: { model, effort } } });
25469
+ if (!sent) {
25470
+ clearTimeout(timer);
25471
+ this.runtimeSwitchWaiters.delete(id);
25472
+ resolve({ outcome: "not_sent" });
25473
+ return;
25474
+ }
25475
+ this.logger.info({ instanceName, model, effort }, "Codex runtime switch sent");
25476
+ });
25477
+ }
25478
+ /**
25479
+ * M-3180: the in-session switch of a CLI in CLI_RUNTIME_SWITCH, one command at a time (the entry's steps), each typed by the
25480
+ * daemon only into an idle pane of a running binary at the entry's minimum for that step, and confirmed by what the CLI showed
25481
+ * after it. The first step that did not switch ends it, with that step. A model the CLI cannot vouch for is not typed.
25482
+ */
25483
+ async runCliRuntimeSwitch(instanceName, backend, want) {
25484
+ const entry = CLI_RUNTIME_SWITCH[backend];
25485
+ let last = { result: { outcome: "not_sent" }, step: want };
25486
+ for (const step of entry.steps(want)) {
25487
+ if (step.model !== null && entry.knownModel && entry.knownModel(step.model) !== true)
25488
+ return { result: { outcome: "not_sent", reason: "unknown_model" }, step };
25489
+ const line = entry.command(step), ipc = this.instanceIpcClients.get(instanceName);
25490
+ if (!line)
25491
+ return { result: { outcome: "not_sent", reason: "command" }, step };
25492
+ if (!ipc)
25493
+ return { result: { outcome: "not_sent" }, step };
25494
+ const id = `switch-${randomUUID()}`;
25495
+ const result = await new Promise(resolve => {
25496
+ const timer = setTimeout(() => { this.runtimeSwitchWaiters.delete(id); resolve({ outcome: "not_confirmed" }); }, CODEX_RUNTIME_SWITCH_RESULT_MS);
25497
+ timer.unref?.();
25498
+ this.runtimeSwitchWaiters.set(id, r => { clearTimeout(timer); resolve(r); });
25499
+ const sent = ipc.send({ type: "raw_paste", content: line, runtime_switch: { id, kind: "model", requested: step.model ?? "", cli: { backend, model: step.model, effort: step.effort } } });
25500
+ if (!sent) {
25501
+ clearTimeout(timer);
25502
+ this.runtimeSwitchWaiters.delete(id);
25503
+ resolve({ outcome: "not_sent" });
25504
+ return;
25505
+ }
25506
+ this.logger.info({ instanceName, backend, step }, "CLI runtime switch sent");
25507
+ });
25508
+ last = { result, step };
25509
+ if (result.outcome !== "switched")
25510
+ return last;
25511
+ }
25512
+ return last;
25513
+ }
25514
+ /** M-3180: why a CLI_RUNTIME_SWITCH switch fell back to a restart, in the reply's words. */
25515
+ cliSwitchFallbackReason(backend, { result, step }) {
25516
+ const cli = BACKEND_LABELS[backend] ?? backend, entry = CLI_RUNTIME_SWITCH[backend];
25517
+ if (result.outcome === "not_sent" && result.reason === "busy")
25518
+ return t("codex_switch.busy");
25519
+ if (result.outcome === "not_sent" && result.reason === "version") {
25520
+ return t("cli_switch.version", cli, result.version ?? t("codex_switch.version_unknown"), step.model !== null ? entry.minVersion.model : entry.minVersion.effort);
25521
+ }
25522
+ if (result.outcome === "not_sent" && result.reason === "unknown_model")
25523
+ return t("cli_switch.unknown_model", cli, step.model ?? "");
25524
+ if (result.outcome === "not_sent" && result.reason === "command")
25525
+ return t("cli_switch.not_one_command", cli, step.model ?? step.effort ?? "");
25526
+ if (result.outcome === "mismatch")
25527
+ return t("cli_switch.mismatch", cli, result.shown);
25528
+ return t("cli_switch.unconfirmed", cli);
25529
+ }
25530
+ /** M-3175: why a codex switch fell back to a restart, in the reply's words. */
25531
+ codexSwitchFallbackReason(result) {
25532
+ if (result.outcome === "not_sent" && result.reason === "busy")
25533
+ return t("codex_switch.busy");
25534
+ if (result.outcome === "not_sent" && result.reason === "version")
25535
+ return t("codex_switch.version", result.version ?? t("codex_switch.version_unknown"), CODEX_INLINE_MODEL_MIN);
25536
+ if (result.outcome === "mismatch")
25537
+ return t("codex_switch.mismatch", result.shown);
25538
+ return t("codex_switch.unconfirmed");
25539
+ }
25540
+ /**
25541
+ * M-3175: the effort a codex model switch carries — the one a restart would launch with (configured, and listed by that
25542
+ * model's catalog, as the launch flag is gated); null when there is none, and codex then takes the model's default, as a
25543
+ * launch without an effort does.
25544
+ */
25545
+ codexSwitchEffort(instanceName, model) {
25546
+ const effort = this.resolveInstanceEffort(instanceName).effort;
25547
+ if (!effort)
25548
+ return null;
25549
+ return this.instanceEffortMetadata(instanceName, model).levels.includes(effort) ? effort : null;
25550
+ }
25036
25551
  /**
25037
25552
  * #1690: the names claude-code is known to accept, for checking `/model <name>` BEFORE it is typed — claude itself
25038
25553
  * accepts any string ("Set model to opsu"), and its "Switch model?" then names the typo. Static aliases (with [1m]),
@@ -26282,12 +26797,40 @@ export class FleetManager {
26282
26797
  this.fleetConfig.instances[instanceName].effort = applied;
26283
26798
  this.saveFleetConfig();
26284
26799
  }
26800
+ // M-3180: a CLI with a verified in-session switch (CLI_RUNTIME_SWITCH) — typed when it can be, confirmed, else restarted.
26801
+ // The effort is already saved above, so a restart launches with it.
26802
+ if (Object.hasOwn(CLI_RUNTIME_SWITCH, backendName) && this.instanceIpcClients.get(instanceName)) {
26803
+ const done = await this.runCliRuntimeSwitch(instanceName, backendName, { model: null, effort: applied });
26804
+ if (opts?.current && !opts.current())
26805
+ return t("menu.instance_replaced", this.shownInstanceName(instanceName));
26806
+ if (done.result.outcome === "switched")
26807
+ return `${warn}${t("effort.codex_switched", instanceName, applied)}`;
26808
+ const why = this.cliSwitchFallbackReason(backendName, done);
26809
+ this.logger.info({ instanceName, backend: backendName, effort: applied, result: done.result }, "CLI runtime effort switch fell back to a restart");
26810
+ await this.restartSingleInstance(instanceName, { ownerCurrent: opts?.current });
26811
+ return `${warn}${t("effort.codex_restarted", instanceName, applied, why)}`;
26812
+ }
26285
26813
  if (strategy === "runtime") {
26286
26814
  if (!this.instanceIpcClients.get(instanceName))
26287
26815
  return `${warn}${t("effort.not_running", instanceName)}`;
26288
26816
  this.pasteRawToClassicInstance(instanceName, `/effort ${applied}`);
26289
26817
  return `${warn}${t("effort.runtime_success", instanceName, applied)}`;
26290
26818
  }
26819
+ // M-3175: codex 0.164+ takes the effort in the running session (`/model [MODEL] --reasoning=L`, its configured model named
26820
+ // when known); restarted when the switch was not typed or not confirmed. The effort is already saved above.
26821
+ if (backendName === "codex" && this.instanceIpcClients.get(instanceName)) {
26822
+ const resolved = this.resolveInstanceModel(instanceName);
26823
+ const model = resolved.source === "instance" || resolved.source === "fleet-default" ? resolved.model : null;
26824
+ const result = await this.runCodexRuntimeSwitch(instanceName, model, applied);
26825
+ if (opts?.current && !opts.current())
26826
+ return t("menu.instance_replaced", this.shownInstanceName(instanceName));
26827
+ if (result.outcome === "switched")
26828
+ return `${warn}${t("effort.codex_switched", instanceName, applied)}`;
26829
+ const why = this.codexSwitchFallbackReason(result);
26830
+ this.logger.info({ instanceName, effort: applied, result }, "Codex runtime effort switch fell back to a restart");
26831
+ await this.restartSingleInstance(instanceName, { ownerCurrent: opts?.current });
26832
+ return `${warn}${t("effort.codex_restarted", instanceName, applied, why)}`;
26833
+ }
26291
26834
  await this.restartSingleInstance(instanceName, { ownerCurrent: opts?.current });
26292
26835
  return `${warn}${t("effort.restart_success", instanceName, applied)}`;
26293
26836
  }
@@ -26349,6 +26892,40 @@ export class FleetManager {
26349
26892
  : t("model.switch_unconfirmed", instanceName, model, Math.round(RUNTIME_SWITCH_RESULT_MS / 1000));
26350
26893
  return `${warn}${head}${this.effortSuffix(instanceName)}`;
26351
26894
  }
26895
+ // M-3175: codex 0.164+ switches in the running session; saved first (a fallback restart launches from it), restarted when
26896
+ // the switch was not typed or not confirmed.
26897
+ if (backendName === "codex" && this.instanceIpcClients.get(instanceName)) {
26898
+ if (!this.persistInstanceModel(instanceName, model))
26899
+ return `${warn}${t("model.persist_failed", instanceName)}`;
26900
+ const effort = this.codexSwitchEffort(instanceName, model);
26901
+ const result = await this.runCodexRuntimeSwitch(instanceName, model, effort);
26902
+ if (opts?.current && !opts.current())
26903
+ return t("menu.instance_replaced", this.shownInstanceName(instanceName));
26904
+ if (result.outcome === "switched")
26905
+ return `${warn}${t("model.codex_switched", instanceName, model)}${this.effortSuffix(instanceName)}`;
26906
+ const why = this.codexSwitchFallbackReason(result);
26907
+ this.logger.info({ instanceName, model, result }, "Codex runtime model switch fell back to a restart");
26908
+ await this.restartSingleInstance(instanceName, { ownerCurrent: opts?.current });
26909
+ return `${warn}${t("model.codex_restarted", instanceName, model, why)}${this.effortSuffix(instanceName)}`;
26910
+ }
26911
+ // M-3180: the same for a CLI with a verified in-session switch (CLI_RUNTIME_SWITCH): saved first, switched in place when
26912
+ // it can be and confirmed, else restarted (as these CLIs always were).
26913
+ if (Object.hasOwn(CLI_RUNTIME_SWITCH, backendName) && this.instanceIpcClients.get(instanceName)) {
26914
+ if (!this.persistInstanceModel(instanceName, model))
26915
+ return `${warn}${t("model.persist_failed", instanceName)}`;
26916
+ const entry = CLI_RUNTIME_SWITCH[backendName];
26917
+ const effort = this.codexSwitchEffort(instanceName, model); // configured level, only when the target model supports it
26918
+ const want = entry.modelWant?.(model, effort) ?? { model, effort: null };
26919
+ const done = await this.runCliRuntimeSwitch(instanceName, backendName, want);
26920
+ if (opts?.current && !opts.current())
26921
+ return t("menu.instance_replaced", this.shownInstanceName(instanceName));
26922
+ if (done.result.outcome === "switched")
26923
+ return `${warn}${t("model.codex_switched", instanceName, model)}${this.effortSuffix(instanceName)}`;
26924
+ const why = this.cliSwitchFallbackReason(backendName, done);
26925
+ this.logger.info({ instanceName, backend: backendName, model, result: done.result }, "CLI runtime model switch fell back to a restart");
26926
+ await this.restartSingleInstance(instanceName, { ownerCurrent: opts?.current });
26927
+ return `${warn}${t("model.codex_restarted", instanceName, model, why)}${this.effortSuffix(instanceName)}`;
26928
+ }
26352
26929
  // Persist either way: a runtime switch must survive the next respawn too,
26353
26930
  // or the instance silently reverts to the CLI default after a fleet restart.
26354
26931
  if (!this.persistInstanceModel(instanceName, model))
@@ -27923,10 +28500,21 @@ export class FleetManager {
27923
28500
  if (!this.daemons.has(name)) {
27924
28501
  // New instance — startInstance already calls connectIpcToInstance. #2482: a paused one is not started (startInstance
27925
28502
  // returns at its pause); say so, quietly, instead of "starting" on every reload.
27926
- if (this.lifecycle.isPaused(name))
28503
+ if (this.lifecycle.isPaused(name)) {
27927
28504
  this.logger.debug({ name }, "Paused instance in config — not started");
27928
- else
27929
- this.logger.info({ name }, "New instance in config — starting");
28505
+ continue;
28506
+ }
28507
+ const previous = oldConfig?.instances[name];
28508
+ const change = previous ? classifyInstanceChange(previous, config) : "restart";
28509
+ // A Settings apply (observe set) of an unrelated fleet field must not start or list every
28510
+ // stopped agent whose instance block did not change (M-3165). SIGHUP still recovers missing ones.
28511
+ if (observe && change === "none")
28512
+ continue;
28513
+ this.logger.info({ name }, !previous
28514
+ ? "New instance in config — starting"
28515
+ : change === "none"
28516
+ ? "Instance not running — starting"
28517
+ : "Instance config changed — starting");
27930
28518
  observe?.(name, "restart", "running");
27931
28519
  await this.startInstanceUnattended(name, config, topicMode, "new instance");
27932
28520
  observe?.(name, "restart", "done");
@@ -29420,13 +30008,15 @@ export class FleetManager {
29420
30008
  const classicNames = new Set(this.classicChannels?.getAll().map(ch => ch.instanceName) ?? []);
29421
30009
  for (const [name, config] of Object.entries(next)) {
29422
30010
  const daemon = this.daemons.get(name);
29423
- if (!daemon) {
29424
- rows.push({ target: name, kind: "restart" });
30011
+ // Compare the live snapshot when we have one; otherwise the in-memory instance
30012
+ // (last load). "No daemon" is not itself a change — parked / other-team agents
30013
+ // whose YAML block is untouched must not appear as "restart this agent" (M-3165).
30014
+ const runtime = daemon?.getConfigSnapshot?.() ?? this.fleetConfig?.instances[name];
30015
+ if (!runtime) {
30016
+ if (!this.lifecycle.isPaused(name))
30017
+ rows.push({ target: name, kind: "restart" });
29425
30018
  continue;
29426
30019
  }
29427
- const runtime = daemon.getConfigSnapshot?.();
29428
- if (!runtime)
29429
- continue;
29430
30020
  const change = classifyInstanceChange(runtime, config);
29431
30021
  if (change !== "none")
29432
30022
  rows.push({ target: name, kind: change === "restart" ? "restart" : "hot" });
@@ -29802,6 +30392,7 @@ export class FleetManager {
29802
30392
  catch {
29803
30393
  this.recordUpdateCheck(currentVersion, null); /* silent — network issues */
29804
30394
  }
30395
+ await this.maybeNotifyHubRecommendation(); // M-3140: the 7-day reminder rides the daily check
29805
30396
  }
29806
30397
  // ── M-2738: updating from the web (src/web-update.ts) ───────────────
29807
30398
  /** The web's update routes (web-api.ts handleWebUpdate) read and start through this. */
@@ -29814,11 +30405,12 @@ export class FleetManager {
29814
30405
  }
29815
30406
  catch { /* unknown: the page compares nothing */ }
29816
30407
  const s = this.updateCheckState;
29817
- return { current, offer: s?.offer ?? null, checkedAt: s?.checkedAt ?? null, checkFailed: s?.failed ?? false };
30408
+ return { current, offer: s?.offer ?? null, hubRecommendation: this.hubRecommendedUpdate(), checkedAt: s?.checkedAt ?? null, checkFailed: s?.failed ?? false };
29818
30409
  },
29819
30410
  checkUpdateNow: () => this.checkUpdateNow(),
29820
30411
  updateProgress: () => webProgressOf(readUpdateProgress(this.dataDir)),
29821
- startWebUpdate: (key, person, stillAllowed) => this.startWebUpdateOnce(key, person, stillAllowed),
30412
+ startWebUpdate: (key, person, stillAllowed, pin) => this.startWebUpdateOnce(key, person, stillAllowed, pin),
30413
+ startHubRequestedUpdate: (key, person, stillAllowed, id) => this.startHubRequestedUpdateOnce(key, person, stillAllowed, id),
29822
30414
  updateLog: () => ({ text: readLogTail(updateLogPath(this.dataDir)), error: readUpdateProgress(this.dataDir)?.progress.error ?? null }),
29823
30415
  };
29824
30416
  }
@@ -29860,14 +30452,32 @@ export class FleetManager {
29860
30452
  * last check offers as installable; the update itself is chat `/update`'s (launchInstalledUpdate). Its progress marker
29861
30453
  * targets no chat message (WEB_UPDATE_ADAPTER); the page reads the stages the updater writes into it.
29862
30454
  */
29863
- async startWebUpdate(person, stillAllowed) {
30455
+ async startWebUpdate(person, stillAllowed, pin, hubRequestId) {
29864
30456
  if (this.shuttingDown)
29865
30457
  return { ok: false, status: 409, error: "stopping" };
29866
30458
  // Synchronous from here to the claim: a second start cannot slip in between on the event loop.
29867
30459
  if (this.webUpdateOwned || isUpdateInProgress(this.dataDir))
29868
30460
  return { ok: false, status: 409, error: "update_running" };
29869
- const offer = this.updateCheckState?.offer;
29870
- if (!offer?.installable)
30461
+ // M-3140: Update pinned to the Hub's recommendation. The page only names which advice it was shown; the version is
30462
+ // this Fleet's own verified view, re-read now (and again at the launch) — a page's word never chooses what installs.
30463
+ let pinned;
30464
+ const requestOwner = this.hubUpdates;
30465
+ if (hubRequestId) {
30466
+ const version = requestOwner?.manualCandidate(hubRequestId);
30467
+ if (!version || !this.semverGt(version, this.runningAgendVersion()))
30468
+ return { ok: false, status: 409, error: "request_changed" };
30469
+ pinned = version;
30470
+ }
30471
+ if (pin) {
30472
+ const advice = this.hubRecommendationFor(pin);
30473
+ if (!advice)
30474
+ return { ok: false, status: 409, error: "recommendation_changed" };
30475
+ pinned = advice.version;
30476
+ }
30477
+ const offer = pinned ? { version: pinned } : this.updateCheckState?.offer;
30478
+ if (!pinned && !this.updateCheckState?.offer?.installable)
30479
+ return { ok: false, status: 409, error: "nothing_to_install" };
30480
+ if (!offer)
29871
30481
  return { ok: false, status: 409, error: "nothing_to_install" };
29872
30482
  const startedAt = Date.now();
29873
30483
  const claim = { startedAt };
@@ -29883,7 +30493,8 @@ export class FleetManager {
29883
30493
  }
29884
30494
  const origin = `web update by ${person}`;
29885
30495
  // Prism #3505 P2-3: the asking session must still be current and an admin's when the updater is launched.
29886
- void this.launchInstalledUpdate(origin, () => !this.shuttingDown && stillAllowed()).then(child => {
30496
+ void this.launchInstalledUpdate(origin, () => !this.shuttingDown && stillAllowed() && (!pin || this.hubRecommendationFor(pin) !== null)
30497
+ && (!hubRequestId || this.hubUpdates === requestOwner && requestOwner?.manualCandidate(hubRequestId) === pinned), pinned).then(child => {
29887
30498
  if (!child) {
29888
30499
  release();
29889
30500
  return;
@@ -29898,17 +30509,44 @@ export class FleetManager {
29898
30509
  return { ok: true };
29899
30510
  }
29900
30511
  /** M-2738: a web start's answer for its key, the same on a retry (at most 32 kept). */
29901
- startWebUpdateOnce(key, person, stillAllowed) {
30512
+ startWebUpdateOnce(key, person, stillAllowed, pin) {
29902
30513
  // Prism #3505 P3: reserved before anything is awaited — a concurrent request with the same key shares this answer.
29903
30514
  const known = this.webUpdateStarts.get(key);
29904
30515
  if (known)
29905
30516
  return known;
29906
- const answer = this.startWebUpdate(person, stillAllowed);
30517
+ const answer = this.startWebUpdate(person, stillAllowed, pin);
29907
30518
  this.webUpdateStarts.set(key, answer);
29908
30519
  while (this.webUpdateStarts.size > 32)
29909
30520
  this.webUpdateStarts.delete(this.webUpdateStarts.keys().next().value);
29910
30521
  return answer;
29911
30522
  }
30523
+ startHubRequestedUpdateOnce(key, person, stillAllowed, id) {
30524
+ const cacheKey = JSON.stringify(["hub-request", person, id, key]);
30525
+ const known = this.webUpdateStarts.get(cacheKey);
30526
+ if (known)
30527
+ return known;
30528
+ const answer = (async () => {
30529
+ const owner = this.hubUpdates, request = owner?.view(id);
30530
+ if (!owner || !request || !owner.manualCandidate(id))
30531
+ return { ok: false, status: 404, error: "request_not_found" };
30532
+ const current = () => !this.shuttingDown && this.hubUpdates === owner && stillAllowed();
30533
+ if (!current())
30534
+ return { ok: false, status: 403, error: "not_authorized" };
30535
+ if (request.state === "waiting") {
30536
+ if (this.webUpdateOwned || isUpdateInProgress(this.dataDir))
30537
+ return { ok: false, status: 409, error: "update_running" };
30538
+ return await owner.updateNow(id, current) ? { ok: true } : { ok: false, status: 409, error: "update_not_started" };
30539
+ }
30540
+ // An expired request's button is a new, explicitly confirmed local update. Its old Hub result stays expired.
30541
+ if (request.state === "expired")
30542
+ return this.startWebUpdate(person, current, undefined, id);
30543
+ return { ok: false, status: 409, error: request.state === "updating" ? "update_running" : "request_changed" };
30544
+ })();
30545
+ this.webUpdateStarts.set(cacheKey, answer);
30546
+ while (this.webUpdateStarts.size > 32)
30547
+ this.webUpdateStarts.delete(this.webUpdateStarts.keys().next().value);
30548
+ return answer;
30549
+ }
29912
30550
  /**
29913
30551
  * Semver "a > b". Compares major.minor.patch numerically; a version without a
29914
30552
  * prerelease outranks the same core with one (2.0.8 > 2.0.8-beta.16); two