@songsid/agend 2.3.5-alpha.5 → 2.3.5-alpha.6

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 (326) hide show
  1. package/THIRD_PARTY_NOTICES.md +0 -1
  2. package/dist/accounts-profiles.d.ts +96 -0
  3. package/dist/accounts-profiles.js +178 -0
  4. package/dist/accounts-profiles.js.map +1 -0
  5. package/dist/accounts-signout.d.ts +59 -0
  6. package/dist/accounts-signout.js +184 -0
  7. package/dist/accounts-signout.js.map +1 -0
  8. package/dist/accounts-view.d.ts +54 -0
  9. package/dist/accounts-view.js +55 -11
  10. package/dist/accounts-view.js.map +1 -1
  11. package/dist/agent-workspace.d.ts +11 -0
  12. package/dist/agent-workspace.js +28 -0
  13. package/dist/agent-workspace.js.map +1 -1
  14. package/dist/auth-api.js +27 -5
  15. package/dist/auth-api.js.map +1 -1
  16. package/dist/authority/session-authorizations.d.ts +2 -0
  17. package/dist/authority/session-authorizations.js +7 -1
  18. package/dist/authority/session-authorizations.js.map +1 -1
  19. package/dist/backend/codex.js +1 -0
  20. package/dist/backend/codex.js.map +1 -1
  21. package/dist/backend/types.d.ts +2 -0
  22. package/dist/backend/types.js.map +1 -1
  23. package/dist/build-provenance.json +1 -1
  24. package/dist/bundled-tmux-guard.d.ts +19 -0
  25. package/dist/bundled-tmux-guard.js +83 -0
  26. package/dist/bundled-tmux-guard.js.map +1 -0
  27. package/dist/classic-bindings.d.ts +13 -0
  28. package/dist/classic-bindings.js +28 -2
  29. package/dist/classic-bindings.js.map +1 -1
  30. package/dist/classic-channel-manager.d.ts +2 -0
  31. package/dist/classic-channel-manager.js +5 -1
  32. package/dist/classic-channel-manager.js.map +1 -1
  33. package/dist/cli.js +116 -11
  34. package/dist/cli.js.map +1 -1
  35. package/dist/config-validator.js +11 -0
  36. package/dist/config-validator.js.map +1 -1
  37. package/dist/config.js +3 -1
  38. package/dist/config.js.map +1 -1
  39. package/dist/daemon.d.ts +27 -2
  40. package/dist/daemon.js +107 -6
  41. package/dist/daemon.js.map +1 -1
  42. package/dist/doctor.js +3 -4
  43. package/dist/doctor.js.map +1 -1
  44. package/dist/e2e-isolation.js +5 -2
  45. package/dist/e2e-isolation.js.map +1 -1
  46. package/dist/fleet-control-audit.d.ts +1 -1
  47. package/dist/fleet-manager.d.ts +129 -0
  48. package/dist/fleet-manager.js +725 -53
  49. package/dist/fleet-manager.js.map +1 -1
  50. package/dist/general-knowledge/skills/credential-profiles/SKILL.md +10 -0
  51. package/dist/hub/compose/server.js +1 -0
  52. package/dist/hub/compose/server.js.map +1 -1
  53. package/dist/hub/directory/directory.d.ts +1 -1
  54. package/dist/hub/directory/directory.js +115 -3
  55. package/dist/hub/directory/directory.js.map +1 -1
  56. package/dist/hub/directory/groups.d.ts +29 -0
  57. package/dist/hub/directory/groups.js +29 -0
  58. package/dist/hub/directory/groups.js.map +1 -0
  59. package/dist/hub/directory/index.d.ts +1 -0
  60. package/dist/hub/directory/types.d.ts +4 -0
  61. package/dist/hub/directory/types.js.map +1 -1
  62. package/dist/hub/group-policy/model.d.ts +56 -0
  63. package/dist/hub/group-policy/model.js +46 -0
  64. package/dist/hub/group-policy/model.js.map +1 -0
  65. package/dist/hub/group-policy/resources.d.ts +52 -0
  66. package/dist/hub/group-policy/resources.js +166 -0
  67. package/dist/hub/group-policy/resources.js.map +1 -0
  68. package/dist/hub/group-policy/store.d.ts +52 -0
  69. package/dist/hub/group-policy/store.js +149 -0
  70. package/dist/hub/group-policy/store.js.map +1 -0
  71. package/dist/hub/http/compose.js +4 -3
  72. package/dist/hub/http/compose.js.map +1 -1
  73. package/dist/hub/pairing.d.ts +3 -1
  74. package/dist/hub/pairing.js +6 -3
  75. package/dist/hub/pairing.js.map +1 -1
  76. package/dist/hub/server.d.ts +2 -0
  77. package/dist/hub/server.js +12 -2
  78. package/dist/hub/server.js.map +1 -1
  79. package/dist/instance-config-impact.js +4 -3
  80. package/dist/instance-config-impact.js.map +1 -1
  81. package/dist/instance-lifecycle.d.ts +17 -0
  82. package/dist/instance-lifecycle.js +38 -1
  83. package/dist/instance-lifecycle.js.map +1 -1
  84. package/dist/locale.js +21 -0
  85. package/dist/locale.js.map +1 -1
  86. package/dist/login-controller.d.ts +5 -0
  87. package/dist/login-controller.js +11 -0
  88. package/dist/login-controller.js.map +1 -1
  89. package/dist/login-window-lock.d.ts +2 -1
  90. package/dist/login-window-lock.js.map +1 -1
  91. package/dist/ls-rows.d.ts +1 -1
  92. package/dist/ls-rows.js +1 -1
  93. package/dist/ls-rows.js.map +1 -1
  94. package/dist/machine-accounts.d.ts +110 -0
  95. package/dist/machine-accounts.js +229 -0
  96. package/dist/machine-accounts.js.map +1 -0
  97. package/dist/machine-signins.d.ts +89 -0
  98. package/dist/machine-signins.js +182 -0
  99. package/dist/machine-signins.js.map +1 -0
  100. package/dist/muse-usage-relay.d.ts +2 -0
  101. package/dist/muse-usage-relay.js +5 -3
  102. package/dist/muse-usage-relay.js.map +1 -1
  103. package/dist/needs-you-hub.d.ts +3 -0
  104. package/dist/needs-you-hub.js +13 -3
  105. package/dist/needs-you-hub.js.map +1 -1
  106. package/dist/needs-you.d.ts +35 -2
  107. package/dist/needs-you.js +19 -0
  108. package/dist/needs-you.js.map +1 -1
  109. package/dist/quickstart.js +7 -18
  110. package/dist/quickstart.js.map +1 -1
  111. package/dist/quiet-run.d.ts +31 -0
  112. package/dist/quiet-run.js +50 -0
  113. package/dist/quiet-run.js.map +1 -0
  114. package/dist/quota-notice-config.d.ts +22 -0
  115. package/dist/quota-notice-config.js +41 -0
  116. package/dist/quota-notice-config.js.map +1 -0
  117. package/dist/runtime-api.d.ts +13 -0
  118. package/dist/runtime-api.js +125 -1
  119. package/dist/runtime-api.js.map +1 -1
  120. package/dist/runtime-build-info.d.ts +2 -1
  121. package/dist/runtime-build-info.js +7 -3
  122. package/dist/runtime-build-info.js.map +1 -1
  123. package/dist/runtime-cli-install.d.ts +153 -0
  124. package/dist/runtime-cli-install.js +675 -0
  125. package/dist/runtime-cli-install.js.map +1 -0
  126. package/dist/runtime-cli.js +157 -12
  127. package/dist/runtime-cli.js.map +1 -1
  128. package/dist/runtime-client.d.ts +64 -2
  129. package/dist/runtime-client.js +277 -20
  130. package/dist/runtime-client.js.map +1 -1
  131. package/dist/runtime-coordinator.d.ts +10 -1
  132. package/dist/runtime-coordinator.js +93 -2
  133. package/dist/runtime-coordinator.js.map +1 -1
  134. package/dist/runtime-credential-profiles.d.ts +11 -2
  135. package/dist/runtime-credential-profiles.js +28 -4
  136. package/dist/runtime-credential-profiles.js.map +1 -1
  137. package/dist/runtime-install.js +9 -6
  138. package/dist/runtime-install.js.map +1 -1
  139. package/dist/runtime-pane-link.js +2 -1
  140. package/dist/runtime-pane-link.js.map +1 -1
  141. package/dist/runtime-pane-service.js +2 -2
  142. package/dist/runtime-pane-service.js.map +1 -1
  143. package/dist/runtime-pane-store.d.ts +10 -0
  144. package/dist/runtime-pane-store.js +13 -1
  145. package/dist/runtime-pane-store.js.map +1 -1
  146. package/dist/runtime-profile-ownership.d.ts +66 -0
  147. package/dist/runtime-profile-ownership.js +391 -0
  148. package/dist/runtime-profile-ownership.js.map +1 -0
  149. package/dist/runtime-protocol.d.ts +88 -2
  150. package/dist/runtime-protocol.js +40 -0
  151. package/dist/runtime-protocol.js.map +1 -1
  152. package/dist/runtime-remote-accounts.d.ts +197 -0
  153. package/dist/runtime-remote-accounts.js +663 -0
  154. package/dist/runtime-remote-accounts.js.map +1 -0
  155. package/dist/runtime-remote-setup.d.ts +105 -0
  156. package/dist/runtime-remote-setup.js +529 -0
  157. package/dist/runtime-remote-setup.js.map +1 -0
  158. package/dist/runtime-signin-transport.d.ts +39 -0
  159. package/dist/runtime-signin-transport.js +110 -0
  160. package/dist/runtime-signin-transport.js.map +1 -0
  161. package/dist/runtime-signin.d.ts +132 -0
  162. package/dist/runtime-signin.js +289 -0
  163. package/dist/runtime-signin.js.map +1 -0
  164. package/dist/runtime-update-attention.d.ts +4 -0
  165. package/dist/runtime-update-attention.js +11 -0
  166. package/dist/runtime-update-attention.js.map +1 -0
  167. package/dist/runtime-update-controller.d.ts +75 -0
  168. package/dist/runtime-update-controller.js +691 -0
  169. package/dist/runtime-update-controller.js.map +1 -0
  170. package/dist/runtime-update-ipc.d.ts +42 -0
  171. package/dist/runtime-update-ipc.js +144 -0
  172. package/dist/runtime-update-ipc.js.map +1 -0
  173. package/dist/runtime-update-journal.d.ts +5 -0
  174. package/dist/runtime-update-journal.js +7 -0
  175. package/dist/runtime-update-journal.js.map +1 -1
  176. package/dist/runtime-update-lock.js +17 -2
  177. package/dist/runtime-update-lock.js.map +1 -1
  178. package/dist/runtime-update-status.d.ts +30 -0
  179. package/dist/runtime-update-status.js +31 -0
  180. package/dist/runtime-update-status.js.map +1 -0
  181. package/dist/settings-api.js +3 -0
  182. package/dist/settings-api.js.map +1 -1
  183. package/dist/settings-change.js +8 -0
  184. package/dist/settings-change.js.map +1 -1
  185. package/dist/settings-instance-patch.js +1 -1
  186. package/dist/settings-instance-patch.js.map +1 -1
  187. package/dist/setup-wizard.js +3 -5
  188. package/dist/setup-wizard.js.map +1 -1
  189. package/dist/signin-keepalive.d.ts +203 -0
  190. package/dist/signin-keepalive.js +652 -0
  191. package/dist/signin-keepalive.js.map +1 -0
  192. package/dist/structured-signin-transport.js +4 -0
  193. package/dist/structured-signin-transport.js.map +1 -1
  194. package/dist/structured-signin.d.ts +7 -0
  195. package/dist/structured-signin.js +1 -1
  196. package/dist/structured-signin.js.map +1 -1
  197. package/dist/tmux-binary.d.ts +23 -23
  198. package/dist/tmux-binary.js +35 -46
  199. package/dist/tmux-binary.js.map +1 -1
  200. package/dist/tmux-exec-helper.js +3 -3
  201. package/dist/tmux-exec-helper.js.map +1 -1
  202. package/dist/tmux-legacy.d.ts +94 -0
  203. package/dist/tmux-legacy.js +309 -0
  204. package/dist/tmux-legacy.js.map +1 -0
  205. package/dist/tmux-manager.d.ts +7 -1
  206. package/dist/tmux-manager.js +21 -11
  207. package/dist/tmux-manager.js.map +1 -1
  208. package/dist/tmux-rollback.d.ts +31 -0
  209. package/dist/tmux-rollback.js +72 -0
  210. package/dist/tmux-rollback.js.map +1 -0
  211. package/dist/tmux-server.d.ts +102 -0
  212. package/dist/tmux-server.js +248 -0
  213. package/dist/tmux-server.js.map +1 -0
  214. package/dist/transcript-monitor.js +43 -5
  215. package/dist/transcript-monitor.js.map +1 -1
  216. package/dist/transcript-records.d.ts +2 -1
  217. package/dist/transcript-records.js +3 -0
  218. package/dist/transcript-records.js.map +1 -1
  219. package/dist/transcript-sources.js +3 -0
  220. package/dist/transcript-sources.js.map +1 -1
  221. package/dist/types.d.ts +3 -0
  222. package/dist/ui/accounts-keepalive.js +112 -0
  223. package/dist/ui/accounts-manage.js +237 -0
  224. package/dist/ui/accounts-view.js +175 -31
  225. package/dist/ui/agent-runtime-settings.js +2 -1
  226. package/dist/ui/app.html +8 -1
  227. package/dist/ui/hub-attachments.js +90 -0
  228. package/dist/ui/hub-chat-store.js +9 -4
  229. package/dist/ui/hub-client.js +20 -1
  230. package/dist/ui/hub-preview.js +101 -0
  231. package/dist/ui/machine-signin.js +56 -0
  232. package/dist/ui/panel-fleet.js +1 -1
  233. package/dist/ui/panel-hub.js +126 -31
  234. package/dist/ui/panel-needs.js +14 -8
  235. package/dist/ui/panel-notices.js +4 -3
  236. package/dist/ui/panel-runtimes.js +19 -6
  237. package/dist/ui/panel-settings.js +12 -6
  238. package/dist/ui/panel-windows-agent.js +2 -1
  239. package/dist/ui/preview-pages.js +3 -41
  240. package/dist/ui/preview-panel-actions.js +3 -161
  241. package/dist/ui/preview-panel.js +10 -557
  242. package/dist/ui/preview-versions.js +3 -155
  243. package/dist/ui/runtime-cli-install.js +114 -0
  244. package/dist/ui/runtime-update-commands.d.ts +2 -0
  245. package/dist/ui/runtime-update-commands.js +11 -0
  246. package/dist/ui/runtime-update-status.js +53 -0
  247. package/dist/ui/search-dialog.js +3 -2
  248. package/dist/ui/settings-guests.js +3 -2
  249. package/dist/ui/settings-hub-browser-certificate.js +2 -0
  250. package/dist/ui/settings-hub-membership.js +12 -6
  251. package/dist/ui/settings-hub-retention.js +2 -0
  252. package/dist/ui/settings-hub.js +11 -3
  253. package/dist/ui/settings-quota-notice.js +100 -0
  254. package/dist/ui/settings-registry.js +1 -0
  255. package/dist/ui/settings-strings.js +2 -2
  256. package/dist/ui/settings-web-authority.js +2 -1
  257. package/dist/ui/shared/accounts-keepalive.css +7 -0
  258. package/dist/ui/shared/accounts.css +13 -0
  259. package/dist/ui/shared/app-route.js +1 -1
  260. package/dist/ui/shared/app-shell.js +9 -3
  261. package/dist/ui/shared/app-store.js +2 -2
  262. package/dist/ui/shared/app.css +13 -0
  263. package/dist/ui/shared/app.js +2 -1
  264. package/dist/ui/shared/hub-chat.css +1 -0
  265. package/dist/ui/shared/hub-owner.css +1 -1
  266. package/dist/ui/shared/loading.css +37 -0
  267. package/dist/ui/shared/preview-pages.js +41 -0
  268. package/dist/ui/shared/preview-panel-actions.js +168 -0
  269. package/dist/ui/shared/preview-panel.js +565 -0
  270. package/dist/ui/shared/preview-versions.js +155 -0
  271. package/dist/ui/shared/runtime-install.css +4 -0
  272. package/dist/ui/shared/signin.js +68 -6
  273. package/dist/ui/shared/ui-states.js +14 -3
  274. package/dist/ui/shared/workspace-follow.css +19 -0
  275. package/dist/ui/signin.html +7 -3
  276. package/dist/ui/structured-signin.js +31 -7
  277. package/dist/ui/workspace-follow-strings.js +28 -0
  278. package/dist/ui/workspace-panel.js +225 -36
  279. package/dist/update-install.d.ts +7 -0
  280. package/dist/update-install.js +23 -0
  281. package/dist/update-install.js.map +1 -1
  282. package/dist/usage/providers.d.ts +5 -0
  283. package/dist/usage/providers.js +5 -0
  284. package/dist/usage/providers.js.map +1 -1
  285. package/dist/usage/quota-notices.d.ts +38 -0
  286. package/dist/usage/quota-notices.js +160 -0
  287. package/dist/usage/quota-notices.js.map +1 -0
  288. package/dist/usage/usage-api.d.ts +1 -0
  289. package/dist/usage/usage-api.js +16 -0
  290. package/dist/usage/usage-api.js.map +1 -1
  291. package/dist/web-api.d.ts +33 -0
  292. package/dist/web-api.js +342 -8
  293. package/dist/web-api.js.map +1 -1
  294. package/dist/web-login.d.ts +35 -1
  295. package/dist/web-login.js +51 -5
  296. package/dist/web-login.js.map +1 -1
  297. package/dist/web-session.d.ts +11 -0
  298. package/dist/web-session.js +38 -1
  299. package/dist/web-session.js.map +1 -1
  300. package/dist/web-shell-routes.d.ts +1 -1
  301. package/dist/web-shell-routes.js +1 -1
  302. package/dist/web-shell-routes.js.map +1 -1
  303. package/dist/web-signin-link.d.ts +42 -0
  304. package/dist/web-signin-link.js +110 -0
  305. package/dist/web-signin-link.js.map +1 -0
  306. package/dist/windows-cli-api.d.ts +6 -0
  307. package/dist/windows-cli-api.js +11 -0
  308. package/dist/windows-cli-api.js.map +1 -1
  309. package/dist/windows-cli-worker.d.ts +3 -1
  310. package/dist/windows-cli-worker.js +18 -3
  311. package/dist/windows-cli-worker.js.map +1 -1
  312. package/dist/workspace-follow-parse.d.ts +36 -0
  313. package/dist/workspace-follow-parse.js +208 -0
  314. package/dist/workspace-follow-parse.js.map +1 -0
  315. package/dist/workspace-follow-records.d.ts +17 -0
  316. package/dist/workspace-follow-records.js +88 -0
  317. package/dist/workspace-follow-records.js.map +1 -0
  318. package/dist/workspace-follow.d.ts +41 -0
  319. package/dist/workspace-follow.js +143 -0
  320. package/dist/workspace-follow.js.map +1 -0
  321. package/dist/wsl-detect.d.ts +1 -0
  322. package/dist/wsl-detect.js +20 -0
  323. package/dist/wsl-detect.js.map +1 -0
  324. package/launcher/tmux-bundle.cjs +26 -10
  325. package/package.json +6 -2
  326. package/templates/runtime-install/install.ps1 +154 -13
@@ -5,6 +5,9 @@ import { NativePaneRecoveryError } from "./native-pane-recovery.js";
5
5
  import { nativePaneToolAvailable, nativePaneToolRefusal } from "./native-pane-tools.js";
6
6
  import { windowsAgentsFor } from "./windows-agents.js";
7
7
  import { AgentRuntimeChanges } from "./agent-runtime-change.js";
8
+ import { QuotaNotices } from "./usage/quota-notices.js";
9
+ import { quotaNoticeRule } from "./quota-notice-config.js";
10
+ import { onUsageSnapshot } from "./usage/usage-api.js";
8
11
  import { supportsVerifiedKiroMigration, getCachedKiroCliCompatibility, kiroV1DbPath, kiroV2SessionsDir } from "./backend/kiro.js";
9
12
  import { listKiroV1Sessions, readKiroClassicLinks } from "./backend/kiro-identity.js";
10
13
  import { readKiroV1SavedModel } from "./backend/kiro-retired-model.js";
@@ -68,6 +71,7 @@ import { join, dirname, basename, delimiter, isAbsolute, relative, resolve as re
68
71
  import { fileURLToPath } from "node:url";
69
72
  import { isDeepStrictEqual } from "node:util";
70
73
  import { getAgendHome, ensureWorkspaceGit } from "./paths.js";
74
+ import { LegacyWindowHoldError } from "./tmux-legacy.js";
71
75
  import { planKiroReconciliation, applyKiroReconciliation, kiroReconciliationPrompt } from "./kiro-reconcile.js";
72
76
  import { applyKiroMigration, kiroMigrationPrompt, planKiroMigration } from "./kiro-migrate.js";
73
77
  import { fleetLabel } from "./fleet-label.js";
@@ -213,8 +217,9 @@ import { windowsCliEnabled, closeWindowsBridge, inventoryProbed, LOCAL_WINDOWS_C
213
217
  import { nativeCliVersionState } from "./runtime-pane-native.js";
214
218
  import { localWindowsCliEnabled, remoteRuntimeEnabled, setConfiguredRuntimeSwitches, maxAgentsPerMachine } from "./runtime-switches.js";
215
219
  import { RuntimeInstallService } from "./runtime-install.js";
216
- import { RUNTIME_CREDENTIAL_CAPABILITY } from "./runtime-credential-profiles.js";
220
+ import { RUNTIME_CREDENTIAL_CAPABILITY, validCredentialProfileName } from "./runtime-credential-profiles.js";
217
221
  import { RuntimeCoordinator } from "./runtime-coordinator.js";
222
+ import { runtimeUpdateAttention } from "./runtime-update-attention.js";
218
223
  import { RuntimeWindowsBridge } from "./runtime-windows-bridge.js";
219
224
  import { FleetWindowsRuntime } from "./fleet-windows-runtime.js";
220
225
  import { NativeMcpSessions } from "./native-mcp.js";
@@ -309,6 +314,8 @@ import { isSetupComplete, markSetupComplete } from "./setup-marker.js";
309
314
  import { manualCleanupMessage, reapStaleTunnel } from "./tunnel/lease.js";
310
315
  import { buildToolPermissionsNotice } from "./tool-permissions-notice.js";
311
316
  import { NeedsYouHub } from "./needs-you-hub.js";
317
+ import { SignInKeepAlive, isKeepAliveBackend } from "./signin-keepalive.js";
318
+ import { BACKEND_LABELS } from "./interaction-observation.js";
312
319
  import { GENERAL_NAME, GENERAL_PAUSE_ERROR, adoptGeneralByName, freeGeneralName, isGeneralInstance } from "./general-instance.js";
313
320
  import { buildOrgChart } from "./web-org.js";
314
321
  import { topMemoryHogs } from "./memory-hogs.js";
@@ -349,10 +356,22 @@ import { PROVIDER_SECRET_SPECS, PUBLIC_TUNNEL_SECRET_SPEC, providerSecretSpec, p
349
356
  const SELF_RESTART_DEADLINE_MS = 300_000;
350
357
  import { APPLY_FLEET_TARGET, ApplyJobStore, viewOf, } from "./apply-job.js";
351
358
  import { kiroHome } from "./backend/kiro-kas-store.js";
352
- import { CHAT_PROFILE_LOGIN_BACKENDS, credentialHomeSpec, credentialProfileHome, credentialProfileEnv, credentialProfileLogin, credentialProfileLoginCommand, credentialProfileStoreHome, credentialSwitchCarriesConversation, credentialSwitchStartsFresh, instanceCredentialProfile, listConfiguredProfiles } from "./backend/credential-profile.js";
359
+ import { CHAT_PROFILE_LOGIN_BACKENDS, credentialHomeSpec, credentialProfileHome, credentialProfileEnv, credentialProfileLogin, credentialProfileLoginCommand, credentialProfileStoreHome, credentialSwitchCarriesConversation, credentialSwitchStartsFresh, instanceCredentialProfile, listConfiguredProfiles, resolveCredentialProfile } from "./backend/credential-profile.js";
353
360
  import { carryClaudeConversation } from "./backend/claude-carry.js";
354
- import { classicProfile, mergeBackendOptions, profileKey, profileName, profileOf, readClassicBindings } from "./classic-bindings.js";
361
+ import { classicProfile, mergeBackendOptions, profileKey, profileName, profileOf, readClassicBindings, readClassicBindingsStrict } from "./classic-bindings.js";
355
362
  import { ACCOUNT_CLIS, PROFILE_CLIS, buildAccountsView, profilesOnDisk, weeklyUsage } from "./accounts-view.js";
363
+ import { addAccountProfile, removeAccountProfile } from "./accounts-profiles.js";
364
+ import { signOutAccount } from "./accounts-signout.js";
365
+ import { MachineAccounts, machineAgents } from "./machine-accounts.js";
366
+ import { MachineSignIns } from "./machine-signins.js";
367
+ import { runQuiet } from "./quiet-run.js";
368
+ const ACCOUNT_SIGN_OUT_DEPS = {
369
+ platform: process.platform,
370
+ run: (binary, args, env) => runQuiet(binary, args, env), // its `gone` is kept by withAccountWriter
371
+ // #3305 review P2-5: a deadline is a failure (runQuiet), for the Keychain query too; it only reads, so its child is not
372
+ // held as a credential writer (its answer is a failure until it exits 0 in time).
373
+ keychainHas: async (service) => (await runQuiet("security", ["find-generic-password", "-s", service], process.env, { timeoutMs: 15_000 })).code === 0,
374
+ };
356
375
  import { classifyInstanceChange, CLASSIC_HOT_CONFIG_KEYS, HOT_INSTANCE_CONFIG_KEYS, hotConfigUpdate, } from "./instance-config-impact.js";
357
376
  import { cleanupWatchVerdict, formatRestartProgressCompletion, RestartProgress, } from "./restart-progress.js";
358
377
  import { FleetStartup } from "./fleet-startup.js";
@@ -826,6 +845,8 @@ export class FleetManager {
826
845
  handlePaneMcp: async (machineId, body, current) => (await this.nativePanes()).handle(machineId, body, current),
827
846
  warn: (fields, message) => this.logger.warn(fields, message),
828
847
  changed: event => {
848
+ if (event?.type === "machine")
849
+ this.needsYou?.poke();
829
850
  if (event?.type === "machine" && this.runtimeHub?.machine(event.machineId)?.status !== "online") {
830
851
  for (const [name, config] of Object.entries(this.fleetConfig?.instances ?? {}))
831
852
  if (config.machine_id === event.machineId) {
@@ -835,7 +856,6 @@ export class FleetManager {
835
856
  this.holdGeneralOldDeliveries(name);
836
857
  }
837
858
  }
838
- this.needsYou?.poke();
839
859
  }
840
860
  if (this.runtimeStatusScheduled || this.shuttingDown)
841
861
  return;
@@ -2202,6 +2222,10 @@ export class FleetManager {
2202
2222
  hubEffectsReady = false;
2203
2223
  hubEffectsScheduled = false;
2204
2224
  hubHolds = [];
2225
+ /** M-2457 §6 rule 2: the fleet is held — an old tmux server is still on the socket and AgEnD can't prove it its own. */
2226
+ tmuxHold = null;
2227
+ /** M-2457 §6 rule 3: instances held by an old 2.3 window AgEnD could not prove its own. */
2228
+ legacyWindowHolds = new Map();
2205
2229
  rawFleetDocument = null;
2206
2230
  /** #2208: the paths a saveFleetConfig() wrote, for its check that nothing else changed. */
2207
2231
  fleetDocumentWrites = null;
@@ -2380,6 +2404,8 @@ export class FleetManager {
2380
2404
  kiroMigrationRuns = new Map();
2381
2405
  /** #1386 "Needs you": the list, its live chat messages and Acknowledge. Started with the fleet (finishStartup). */
2382
2406
  needsYou = null;
2407
+ /** #3292: "Keep sign-in alive" (signin-keepalive.ts); built at startup, stopped at shutdown. */
2408
+ signInKeepAlive = null;
2383
2409
  hubExecutionAttention = null;
2384
2410
  missedOfflineStore = null;
2385
2411
  configHistory = null;
@@ -5058,6 +5084,7 @@ export class FleetManager {
5058
5084
  finishStartup(bootUpdateMarker = null) {
5059
5085
  this.startupComplete = true;
5060
5086
  this.startNeedsYou();
5087
+ this.startSignInKeepAlive();
5061
5088
  // Resolve whatever a previous run — or a setup host that crashed — left
5062
5089
  // behind. A tunnel nobody is tracking is a public entrance nobody is
5063
5090
  // watching, and the fleet starting is the moment there is finally a process
@@ -7511,6 +7538,7 @@ export class FleetManager {
7511
7538
  }
7512
7539
  classicBehaviorUpdate(instanceName) {
7513
7540
  return {
7541
+ quota_notice: this.classicChannels?.getQuotaNoticeByInstance?.(instanceName) ?? null,
7514
7542
  reply_triggers: this.classicChannels?.getReplyTriggersByInstance(instanceName, this.fleetConfig?.defaults?.reply_triggers) ?? DEFAULT_REPLY_TRIGGERS,
7515
7543
  tool_progress: this.classicChannels?.getToolProgressByInstance(instanceName, this.fleetConfig?.defaults?.tool_progress) ?? "off",
7516
7544
  reply_completion_guard: this.classicChannels?.getReplyCompletionGuardByInstance(instanceName, this.fleetConfig?.defaults?.reply_completion_guard) ?? true,
@@ -7662,6 +7690,9 @@ export class FleetManager {
7662
7690
  resumePaused = false,
7663
7691
  /** Phase 2a: the caller's transition, for a start made from inside a restart or wake. */
7664
7692
  transition, execution, kiroMigration) {
7693
+ // M-2457 §6: no agent starts on a held tmux server (an old one AgEnD could not prove its own may still run it).
7694
+ if (this.tmuxHold)
7695
+ throw new Error(this.tmuxHold.detail);
7665
7696
  if (isNativeExecInstance(config)) {
7666
7697
  execution?.assert();
7667
7698
  if (!windowsCliEnabled())
@@ -7775,14 +7806,26 @@ export class FleetManager {
7775
7806
  }
7776
7807
  const receipt = execution ? this.classicSettingsOwners.get(execution) : undefined;
7777
7808
  const identity = { kind, backend, model: isWindowsInstance(config) ? config.model || "default" : this.resolveInstanceModel(name).display };
7778
- if (receipt) {
7779
- await this.lifecycle.start(name, config, topicMode, identity, transition, execution, daemon => {
7780
- // Only this transition's actual publication can acquire its replacement.
7781
- receipt.daemon = daemon;
7782
- });
7809
+ // M-2457 §6 rule 3: an old 2.3 window AgEnD can't prove its own holds only this instance (Needs-you says why).
7810
+ try {
7811
+ if (receipt) {
7812
+ await this.lifecycle.start(name, config, topicMode, identity, transition, execution, daemon => {
7813
+ // Only this transition's actual publication can acquire its replacement.
7814
+ receipt.daemon = daemon;
7815
+ });
7816
+ }
7817
+ else
7818
+ await this.lifecycle.start(name, config, topicMode, identity, transition, execution);
7783
7819
  }
7784
- else
7785
- await this.lifecycle.start(name, config, topicMode, identity, transition, execution);
7820
+ catch (err) {
7821
+ if (err instanceof LegacyWindowHoldError) {
7822
+ this.legacyWindowHolds.set(name, { key: `legacy:${Date.now()}`, detail: err.message, since: Date.now() });
7823
+ this.needsYou?.poke();
7824
+ }
7825
+ throw err;
7826
+ }
7827
+ if (this.legacyWindowHolds.delete(name))
7828
+ this.needsYou?.poke();
7786
7829
  execution?.assert();
7787
7830
  // Only clear a stale process status after a real start succeeded. Clearing
7788
7831
  // it before lifecycle.start() can turn a crash-loop daemon's dead pane into
@@ -10245,7 +10288,7 @@ export class FleetManager {
10245
10288
  }
10246
10289
  async startAllWithinDeadline(configPath, deadline) {
10247
10290
  if (!this.structuredLoginCleanupFailed)
10248
- this.loginWindow.reopen(); // a stopAll → startAll restart must accept login windows again
10291
+ this.reopenLoginWindow(); // a stopAll → startAll restart must accept login windows again
10249
10292
  this.loginController?.reopen();
10250
10293
  const startupStartedAt = Date.now();
10251
10294
  FleetManager.signalTarget = this;
@@ -10300,11 +10343,63 @@ export class FleetManager {
10300
10343
  // #2910: a web-only fleet's agents run in topic mode too (their cross-instance tools work; the dashboard is their place).
10301
10344
  const topicMode = daemonTopicMode(fleet);
10302
10345
  // Set tmux socket isolation for custom AGEND_HOME
10303
- // M-2457: the bundled tmux's socket while it is on; getTmuxSocketName() as before while off.
10304
- const { tmuxSocket } = await import("./tmux-binary.js");
10346
+ // M-2457: AgEnD's own tmux socket (`agend` for the real home).
10347
+ const { tmuxSocket, resolveTmux } = await import("./tmux-binary.js");
10305
10348
  TmuxManager.setSocketName(tmuxSocket());
10306
- await TmuxManager.ensureSession(getTmuxSession());
10307
- this.tmuxSessionEnsured = true;
10349
+ // M-2457 §6 rule 3: 2.3's window ids (untagged window-id files) move into the migration journal before anything —
10350
+ // a stop, a pane check, a restart — can read one as a window on AgEnD's own server.
10351
+ try {
10352
+ const { sweepLegacyWindowIds } = await import("./tmux-legacy.js");
10353
+ const moved = sweepLegacyWindowIds(getAgendHome(), Object.keys(fleet.instances ?? {}).map(name => ({ name, dir: this.getInstanceDir(name) })), tmuxSocket());
10354
+ if (moved.length)
10355
+ this.logger.info({ instances: moved }, "2.3 tmux window ids moved to the migration journal");
10356
+ }
10357
+ catch (err) {
10358
+ this.logger.warn({ err }, "Could not move 2.3 tmux window ids to the migration journal; each instance does it as it starts");
10359
+ }
10360
+ // M-2457 §6 rule 2: a server from another pin still on the socket is ended by its own recorded
10361
+ // client, positively, before ours starts; one AgEnD cannot prove its own holds the whole fleet (nothing is killed).
10362
+ const bundled = await (async () => {
10363
+ const srv = await import("./tmux-server.js");
10364
+ const binary = resolveTmux().binary;
10365
+ return { srv, socket: tmuxSocket(), current: { binary, sha256: srv.sha256File(binary) }, previous: srv.readServerRecord(getAgendHome()) };
10366
+ })();
10367
+ // M-2457 §5 (Fable #3312 N3): an upgraded home — agents ran here before (their output or session ids are on disk
10368
+ // from an earlier start) and no AgEnD tmux server was ever recorded — gets the one own-tmux notice. A cleanly stopped
10369
+ // 2.3 fleet leaves no window ids (no migration journal), so this, not the journal, is the evidence. Read before any
10370
+ // agent of this start writes its own.
10371
+ this.ownTmuxUpgradedHome = FleetManager.ownTmuxUpgraded(getAgendHome(), bundled.previous);
10372
+ this.tmuxHold = null;
10373
+ TmuxManager.setHold(null);
10374
+ if (bundled) {
10375
+ const reason = await bundled.srv.reconcileServer({ agendHome: getAgendHome(), socket: bundled.socket, current: bundled.current,
10376
+ log: (msg, data) => this.logger.info(data ?? {}, msg) });
10377
+ if (reason) {
10378
+ this.tmuxHold = { key: `server:${Date.now()}`, detail: reason, since: Date.now() };
10379
+ TmuxManager.setHold(reason); // every other way in (sign-in/install windows, a daemon) is refused too
10380
+ this.logger.error({ reason }, "Fleet held: AgEnD's previous tmux server can't be verified; no agent starts");
10381
+ }
10382
+ }
10383
+ if (!this.tmuxHold) {
10384
+ await TmuxManager.ensureSession(getTmuxSession());
10385
+ this.tmuxSessionEnsured = true;
10386
+ if (bundled) {
10387
+ await bundled.srv.recordServer({ agendHome: getAgendHome(), socket: bundled.socket, current: bundled.current, version: "",
10388
+ log: (msg, data) => this.logger.warn(data ?? {}, msg) });
10389
+ // A server AgEnD starts later (the session re-created after the server crashed) is recorded the same way, so
10390
+ // server.json always names the server that runs (leg M: an unrecorded server made `agend rollback` refuse).
10391
+ TmuxManager.onSessionCreated(async () => {
10392
+ const r = await bundled.srv.recordServer({ agendHome: getAgendHome(), socket: bundled.socket, current: bundled.current, version: "",
10393
+ log: (msg, data) => this.logger.warn(data ?? {}, msg) });
10394
+ if (r)
10395
+ this.logger.info({ serverPid: r.serverPid }, "tmux server recorded (session created)");
10396
+ });
10397
+ // The current copy and the one the previous server ran (kept for a handover/rollback); older ones go.
10398
+ const removed = bundled.srv.pruneCopies(getAgendHome(), [bundled.current.binary, ...(bundled.previous ? [bundled.previous.binary] : [])]);
10399
+ if (removed.length)
10400
+ this.logger.info({ removed }, "Pruned old bundled tmux copies");
10401
+ }
10402
+ }
10308
10403
  // #2072: what this host can run — probed in the background, published for every picker.
10309
10404
  this.startAvailabilityRefresh();
10310
10405
  // Pre-flight (advisory, fire-and-forget): warm the per-backend auth cache
@@ -10316,7 +10411,7 @@ export class FleetManager {
10316
10411
  return { backend, profile: credentialHomeSpec(backend) ? instanceCredentialProfile(config, fleet.defaults, backend) : null };
10317
10412
  }));
10318
10413
  // Start tmux control mode client for idle detection
10319
- if (!this.controlClient) {
10414
+ if (!this.controlClient && !this.tmuxHold) {
10320
10415
  this.controlClient = new TmuxControlClient(getTmuxSession(), 2000, this.logger);
10321
10416
  this.controlClient.start();
10322
10417
  }
@@ -10329,25 +10424,26 @@ export class FleetManager {
10329
10424
  // windows from deleted instances that are no longer in fleet.yaml.
10330
10425
  const agendNames = new Set(Object.keys(fleet.instances));
10331
10426
  agendNames.add("general");
10332
- try {
10333
- const existingWindows = await TmuxManager.listWindows(getTmuxSession());
10334
- for (const w of existingWindows) {
10335
- // Kill known instance windows (will be recreated)
10336
- // Also kill orphaned windows: any window with a topic ID suffix (name-tNNNNN)
10337
- // that isn't in the current config — these are leftovers from deleted instances
10338
- const isKnownInstance = agendNames.has(w.name);
10339
- const isOrphanedInstance = !isKnownInstance && isOrphanInstanceWindowName(w.name);
10340
- if (isKnownInstance || isOrphanedInstance) {
10341
- if (isOrphanedInstance)
10342
- this.logger.info({ window: w.name }, "Cleaning up orphaned tmux window");
10343
- const tm = new TmuxManager(getTmuxSession(), w.id);
10344
- await tm.killWindow();
10427
+ if (!this.tmuxHold)
10428
+ try {
10429
+ const existingWindows = await TmuxManager.listWindows(getTmuxSession());
10430
+ for (const w of existingWindows) {
10431
+ // Kill known instance windows (will be recreated)
10432
+ // Also kill orphaned windows: any window with a topic ID suffix (name-tNNNNN)
10433
+ // that isn't in the current config — these are leftovers from deleted instances
10434
+ const isKnownInstance = agendNames.has(w.name);
10435
+ const isOrphanedInstance = !isKnownInstance && isOrphanInstanceWindowName(w.name);
10436
+ if (isKnownInstance || isOrphanedInstance) {
10437
+ if (isOrphanedInstance)
10438
+ this.logger.info({ window: w.name }, "Cleaning up orphaned tmux window");
10439
+ const tm = new TmuxManager(getTmuxSession(), w.id);
10440
+ await tm.killWindow();
10441
+ }
10345
10442
  }
10346
10443
  }
10347
- }
10348
- catch (err) {
10349
- this.logger.debug({ err }, "Startup tmux window cleanup failed (best effort)");
10350
- }
10444
+ catch (err) {
10445
+ this.logger.debug({ err }, "Startup tmux window cleanup failed (best effort)");
10446
+ }
10351
10447
  const pidPath = join(this.dataDir, "fleet.pid");
10352
10448
  writeFileSync(pidPath, String(process.pid), "utf-8");
10353
10449
  this.eventLog = this.openEventLog();
@@ -10555,14 +10651,15 @@ export class FleetManager {
10555
10651
  }
10556
10652
  }
10557
10653
  // Phase 1: Start general instances first and wait for them
10558
- const allEntries = Object.entries(fleet.instances).filter(([, config]) => !isNativeExecInstance(config));
10654
+ // M-2457: a held fleet starts no agent (the hold's Needs-you line says why and what to do).
10655
+ const allEntries = this.tmuxHold ? [] : Object.entries(fleet.instances).filter(([, config]) => !isNativeExecInstance(config));
10559
10656
  const generals = allEntries.filter(([_, cfg]) => cfg.general_topic);
10560
10657
  const others = allEntries.filter(([_, cfg]) => !cfg.general_topic);
10561
- const startupProgress = new RestartProgress(this.runnableStartupCount(fleet, topicMode), pendingUpdateProgress?.startedAt ?? startupStartedAt, this.logger, { mode: pendingProgressOperation === "full-restart" ? "reload" : pendingUpdateProgress ? "update" : "restart" });
10658
+ const startupProgress = new RestartProgress(this.tmuxHold ? 0 : this.runnableStartupCount(fleet, topicMode), pendingUpdateProgress?.startedAt ?? startupStartedAt, this.logger, { mode: pendingProgressOperation === "full-restart" ? "reload" : pendingUpdateProgress ? "update" : "restart" });
10562
10659
  this.startupProgress = startupProgress;
10563
10660
  // Auth, restored chat, Classic roster and the task DB are ready. Listening is not service readiness:
10564
10661
  // the dashboard observes startup, while /health and READY retain their existing completion boundary.
10565
- this.startupDashboard = new FleetStartup(this.configuredStartupInstanceNames(fleet, topicMode)
10662
+ this.startupDashboard = new FleetStartup(this.tmuxHold ? [] : this.configuredStartupInstanceNames(fleet, topicMode)
10566
10663
  .filter(name => !this.lifecycle.isPaused(name)));
10567
10664
  await this.startHealthServer(fleet.health_port ?? 19280);
10568
10665
  if (this.shuttingDown)
@@ -10807,6 +10904,8 @@ export class FleetManager {
10807
10904
  // #1266: buttons that ended while AgEnD was down (expired, or chosen before a restart) are shown as ended now.
10808
10905
  // #1823: and polls: a deadline that passed meanwhile closes now (results once); an open one's countdown is redrawn.
10809
10906
  void this.replyButtons()?.sweep().catch(err => this.logger.warn({ err }, "Reply-button sweep failed"));
10907
+ // M-2457 §5: the first start on AgEnD's own tmux says so, once per home: `tmux attach` no longer shows the agents.
10908
+ this.announceOwnTmux();
10810
10909
  // Daily update check — first check after 1 hour, then every 24 hours
10811
10910
  this.updateCheckTimer = setTimeout(() => {
10812
10911
  this.checkForUpdates();
@@ -10856,7 +10955,47 @@ export class FleetManager {
10856
10955
  * Discord bot and while some account has a running agent, read every 30 min — the same cached read (its 5-minute TTL
10857
10956
  * still bounds the vendor calls), recorded like any other.
10858
10957
  */
10958
+ quotaNotices = null;
10959
+ stopQuotaObserver = null;
10960
+ quotaNoticePolicy() {
10961
+ const defaults = this.fleetConfig?.defaults.quota_notice;
10962
+ const wanted = defaults?.target ?? "general";
10963
+ const instances = this.fleetConfig?.instances ?? {};
10964
+ const target = wanted === "general"
10965
+ ? Object.entries(instances).find(([name, c]) => c.general_topic === true || name === "general")?.[0]
10966
+ : Object.hasOwn(instances, wanted) ? wanted : undefined;
10967
+ const webOnly = !!this.webOnlyPromptPlace();
10968
+ const config = target ? instances[target] : undefined;
10969
+ const adapterId = target ? this.getInstanceAdapterId(target) : undefined;
10970
+ const groupId = target ? this.getChannelConfig(adapterId)?.group_id : undefined;
10971
+ const ready = !!target && (webOnly || (config?.topic_id != null && !!groupId && !!(this.getAdapterForInstance(target) ?? this.adapter)));
10972
+ return {
10973
+ target: this.shuttingDown ? "" : ready ? target : !target && wanted === "general" && webOnly ? "/notices" : "",
10974
+ destinationBinding: JSON.stringify([webOnly, adapterId, groupId, config?.topic_id]),
10975
+ locale: this.fleetConfig?.defaults.locale ?? getLocale(),
10976
+ subscriptions: this.shuttingDown ? [] : this.activeBackendBindings().flatMap(([name, backend, profile]) => {
10977
+ // Local WSL usage cannot prove a Windows/paired machine's credential source.
10978
+ const instance = instances[name];
10979
+ if (instance?.runtime === "windows" || instance?.machine_id)
10980
+ return [];
10981
+ const provider = usageProviderIdForBackend(backend);
10982
+ if (!provider)
10983
+ return [];
10984
+ const providerId = profile ? `${provider}:${profile}` : provider;
10985
+ return [{ account: `${backend}:host:${profile ?? ""}`, providerId,
10986
+ rule: quotaNoticeRule(defaults, backend, instances[name]?.quota_notice ?? this.classicChannels?.getQuotaNoticeByInstance?.(name)) }];
10987
+ }),
10988
+ };
10989
+ }
10859
10990
  startQuotaBackgroundReads() {
10991
+ if (!this.quotaNotices) {
10992
+ this.quotaNotices = new QuotaNotices({
10993
+ file: join(this.dataDir, "quota-notices.json"), policy: () => this.quotaNoticePolicy(),
10994
+ send: (target, text) => target === "/notices" ? this.recordWebNotice("fleet", text) : this.notifyInstanceTopic(target, text),
10995
+ warn: err => this.logger.warn({ err }, "Optional quota reminders held: could not retain dispatch state"),
10996
+ });
10997
+ this.stopQuotaObserver = onUsageSnapshot(payload => { void this.quotaNotices?.observe(payload); });
10998
+ }
10860
10999
  if (this.quotaReadTimer)
10861
11000
  clearInterval(this.quotaReadTimer);
10862
11001
  this.quotaReadTimer = setInterval(() => { void this.backgroundQuotaRead(); }, FleetManager.QUOTA_BACKGROUND_READ_MS);
@@ -16829,6 +16968,46 @@ export class FleetManager {
16829
16968
  }
16830
16969
  return { chatId, opts: {} };
16831
16970
  }
16971
+ /**
16972
+ * M-2457 §5: one fleet notice, the first time an upgraded home's fleet runs on AgEnD's own tmux. Marked done only once it
16973
+ * was dispatched (General, the channel's notice target, or a web-only fleet's Notices), so a start with nowhere to
16974
+ * post it tries again next start.
16975
+ */
16976
+ /** Set at fleet start (before any agent starts): this home ran agents on an earlier AgEnD's system tmux. */
16977
+ ownTmuxUpgradedHome = false;
16978
+ /** An upgraded home: agent state from an earlier start, and no AgEnD tmux server ever recorded (`previous`). */
16979
+ static ownTmuxUpgraded(agendHome, previous) {
16980
+ return previous === null && FleetManager.priorAgentState(join(agendHome, "instances"));
16981
+ }
16982
+ /** Whether any instance directory holds state from an earlier start (its output log or a session id). */
16983
+ static priorAgentState(instancesDir) {
16984
+ let names = [];
16985
+ try {
16986
+ names = readdirSync(instancesDir);
16987
+ }
16988
+ catch {
16989
+ return false;
16990
+ }
16991
+ return names.some(n => ["output.log", "session-id"].some(f => existsSync(join(instancesDir, n, f))));
16992
+ }
16993
+ announceOwnTmux() {
16994
+ const marker = join(getAgendHome(), "tmux", "own-server-announced");
16995
+ if (existsSync(marker))
16996
+ return;
16997
+ // Only a home an earlier AgEnD ran its agents in (on the system tmux) has something to be told (Fable #3312 N3):
16998
+ // agent state from before this start and no recorded AgEnD tmux server (set at fleet start), or a migration journal
16999
+ // (2.3 window ids found). A fresh home is marked without a notice.
17000
+ const upgraded = this.ownTmuxUpgradedHome || existsSync(join(getAgendHome(), "tmux-migration.json"));
17001
+ if (upgraded && !this.notifyFleetError(t("tmux.own_server_notice"), { throttle: false }))
17002
+ return;
17003
+ try {
17004
+ mkdirSync(dirname(marker), { recursive: true });
17005
+ writeFileSync(marker, `${new Date().toISOString()}\n`);
17006
+ }
17007
+ catch (err) {
17008
+ this.logger.warn({ err }, "Could not record that the own-tmux notice was posted");
17009
+ }
17010
+ }
16832
17011
  /**
16833
17012
  * Post the daily summary where fleet-wide notices go.
16834
17013
  *
@@ -17745,12 +17924,16 @@ export class FleetManager {
17745
17924
  acknowledgeMissed: (id, by) => this.missedOfflineStore?.acknowledge(id, by) ?? false,
17746
17925
  tasks: () => this.needsYouTaskItems(),
17747
17926
  backendSignIns: () => this.needsYouBackendSignIns(),
17927
+ signInKeepAlive: () => this.keepAliveAttention(),
17748
17928
  hubExecution: () => this.hubExecutionAttention?.() ?? [],
17929
+ runtimeUpdates: () => remoteRuntimeEnabled() ? runtimeUpdateAttention(this.runtimeHub?.listMachines() ?? [], t, this.worlds.keys().next().value) : [],
17749
17930
  hubHolds: () => this.hubHolds.map(h => {
17750
17931
  // A provider hold carries a bounded setup reason; its guidance (S4b's copy) when present, else the code's text.
17751
17932
  const guidance = h.reason ? t(`hub.provider.${h.reason}`) : "";
17752
17933
  return { side: h.side, code: h.code, since: h.since, detail: guidance && guidance !== `hub.provider.${h.reason}` ? guidance : t(`hub.hold.${h.code}`) };
17753
17934
  }),
17935
+ tmuxHolds: () => [...(this.tmuxHold ? [{ instance: null, ...this.tmuxHold }] : []),
17936
+ ...[...this.legacyWindowHolds].map(([instance, h]) => ({ instance, ...h }))],
17754
17937
  configIssues: () => (this.configHistory?.currentIssues() ?? []).map(issue => ({
17755
17938
  ...issue, detail: configIssueText(issue, t), owner: this.worlds.keys().next().value,
17756
17939
  })),
@@ -20279,6 +20462,43 @@ export class FleetManager {
20279
20462
  }
20280
20463
  return this.loginController;
20281
20464
  }
20465
+ /**
20466
+ * #3190 Part 3c: dashboard sign-ins on a paired computer (machine-signins.ts): #3212's StructuredSignIn over a RuntimeSignInTransport, one computer and one
20467
+ * credential profile at a time. Its own coordinator, not the host's: it never touches the host's sign-in checklist or login window.
20468
+ */
20469
+ machineSignInsInstance = null;
20470
+ get machineSignIns() {
20471
+ return this.machineSignInsInstance ??= new MachineSignIns({
20472
+ call: (id, operation, payload, timeoutMs) => this.runtimeCoordinator().callAccount(id, operation, payload, timeoutMs),
20473
+ current: owner => this.browserSignInOwnerCurrent(owner),
20474
+ reported: (id, profile) => this.machineAccounts.profileState(id, profile),
20475
+ readiness: id => this.machineAccounts.readiness(id),
20476
+ actor: owner => { const handle = owner.handle; return typeof handle === "string" && /^[a-f0-9]{16}$/.test(handle) ? `admin:${handle}` : null; },
20477
+ changed: (event, owner) => {
20478
+ // Safe fields only: the computer, the profile name, a phase and a fixed reason. Never a URL, a code, output or an e-mail address.
20479
+ this.logger.info({ machine: event.machine, profile: event.profile, phase: event.phase, ...(event.reason ? { reason: event.reason } : {}), by: owner.label }, "Computer account sign-in from Settings → Accounts");
20480
+ broadcastSseEvent(this.sseClients, "backend_login", {}, err => this.logger.debug({ err }, "backend_login event failed"));
20481
+ this.needsYou?.poke();
20482
+ },
20483
+ });
20484
+ }
20485
+ machineAccountsInstance = null;
20486
+ /** #3190 Part 3c: a paired computer's accounts in Settings → Accounts (machine-accounts.ts). */
20487
+ get machineAccounts() {
20488
+ return this.machineAccountsInstance ??= new MachineAccounts({
20489
+ call: (id, operation, payload, timeoutMs) => this.runtimeCoordinator().callAccount(id, operation, payload, timeoutMs),
20490
+ machine: id => remoteRuntimeEnabled() ? this.runtimeCoordinator().machine(id) ?? undefined : undefined,
20491
+ machines: () => remoteRuntimeEnabled() ? this.runtimeCoordinator().listMachines() : [],
20492
+ agents: id => machineAgents(this.fleetConfig?.instances, id, name => { try {
20493
+ return nativeCredentialProfile(this.fleetConfig?.instances[name]) ?? null;
20494
+ }
20495
+ catch {
20496
+ return null;
20497
+ } }, this.fleetConfig?.defaults?.backend ?? "claude-code"),
20498
+ signingIn: (id, profile) => this.machineSignInsInstance?.signingIn(id, profile) ?? false,
20499
+ log: entry => this.logger.info(entry, entry.outcome === "ok" ? "Computer account changed from Settings → Accounts" : "Computer account change refused"),
20500
+ });
20501
+ }
20282
20502
  browserBackendSignInsInstance = null;
20283
20503
  structuredLoginCleanupFailed = false;
20284
20504
  pendingBackendSince = new Map();
@@ -20434,8 +20654,6 @@ export class FleetManager {
20434
20654
  * usage is the usage panel's cached read (never forced), given at most `usageWaitMs` before the view is sent without it.
20435
20655
  */
20436
20656
  async accountsView(usageWaitMs = 1500) {
20437
- const fleet = this.fleetConfig;
20438
- const defaultBackend = fleet?.defaults?.backend ?? "claude-code";
20439
20657
  this.refreshSignInIdentities();
20440
20658
  const targets = this.backendSignInTargets();
20441
20659
  const diskProfiles = new Map();
@@ -20455,19 +20673,7 @@ export class FleetManager {
20455
20673
  }
20456
20674
  diskProfiles.set(backend, rows);
20457
20675
  }
20458
- // Host agents only: an agent on a paired Windows computer runs on that computer's accounts (its own scope, later).
20459
- const agents = Object.keys(fleet?.instances ?? {}).filter(name => !isWindowsInstance(fleet.instances[name])).sort()
20460
- .map(name => { const backend = this.backendNameForInstance(name); return { name, backend, profile: this.credentialProfileOf(name, backend) }; });
20461
- const classic = readClassicBindings(this.dataDir).map(b => {
20462
- const backend = b.backend ?? defaultBackend;
20463
- return { key: b.key, backend, profile: profileName(classicProfile(b.backend_options, fleet?.defaults?.backend_options, backend)) };
20464
- });
20465
- const fleetDefaults = new Map();
20466
- for (const backend of PROFILE_CLIS) {
20467
- const p = profileName(profileOf(fleet?.defaults?.backend_options, backend));
20468
- if (p)
20469
- fleetDefaults.set(backend, p);
20470
- }
20676
+ const { agents, classic, fleetDefaults } = this.accountUses();
20471
20677
  // Weekly usage, from the usage panel's own (cached, never forced) read.
20472
20678
  const usage = new Map();
20473
20679
  const ids = new Map(); // provider id → backend\0profile
@@ -20489,7 +20695,437 @@ export class FleetManager {
20489
20695
  }
20490
20696
  }
20491
20697
  catch { /* the view without usage */ }
20492
- return buildAccountsView({ targets, diskProfiles, agents, classic, fleetDefaults, usage });
20698
+ // #3292: each Claude Code / Codex row's "Keep sign-in alive" part (the setting, its last run, the dates its file says).
20699
+ const keepAlive = new Map();
20700
+ const ka = this.keepAliveService();
20701
+ for (const backend of ACCOUNT_CLIS) {
20702
+ if (!isKeepAliveBackend(backend))
20703
+ continue;
20704
+ for (const profile of [null, ...new Set([...(diskProfiles.get(backend) ?? []).map(d => d.profile), ...targets.filter(t => t.backend === backend && t.profile).map(t => t.profile)])]) {
20705
+ const v = ka.view(backend, profile);
20706
+ if (v)
20707
+ keepAlive.set(`${backend}\0${profile ?? ""}`, v);
20708
+ }
20709
+ }
20710
+ // #3190 Part 3c: each paired computer's accounts, as rows under the `machine` scope. Read from what the computers reported; the view never waits long for one.
20711
+ // (Keep-alive is the host's: it is built from the host's profiles above and never given to a computer's rows.)
20712
+ let machines = [];
20713
+ if (remoteRuntimeEnabled()) {
20714
+ try {
20715
+ machines = await this.machineAccounts.list();
20716
+ }
20717
+ catch (err) {
20718
+ this.logger.debug({ err: err.message }, "Computer accounts not read");
20719
+ }
20720
+ }
20721
+ return buildAccountsView({ targets, diskProfiles, agents, classic, fleetDefaults, usage, keepAlive, machines });
20722
+ }
20723
+ /** #3292: the keep-alive service (built on first use, so the Accounts view can read settings before startup finishes). */
20724
+ keepAliveService() {
20725
+ return this.signInKeepAlive ??= new SignInKeepAlive({
20726
+ dataDir: this.dataDir,
20727
+ log: (level, msg, fields) => this.logger[level](fields, msg),
20728
+ homeOf: (backend, profile) => profile ? credentialProfileHome(this.dataDir, backend, profile) : credentialHomeSpec(backend)?.sharedRoot() ?? null,
20729
+ acquire: (backend, profile) => this.acquireKeepAliveRun(backend, profile),
20730
+ changed: () => {
20731
+ this.needsYou?.poke();
20732
+ // #3313 review P2-7: the Accounts view reads itself again on `backend_login` (no details: each page reads its own
20733
+ // view). That event, not a new one: a tab whose cached shell predates this still passes it on.
20734
+ broadcastSseEvent(this.sseClients, "backend_login", {}, err => this.logger.debug({ err }, "backend_login event failed"));
20735
+ },
20736
+ claudeKeychain: process.platform === "darwin",
20737
+ });
20738
+ }
20739
+ startSignInKeepAlive() { this.keepAliveService().start(); }
20740
+ /**
20741
+ * #3292 review: which sign-in each host agent is starting or running on, recorded at its start (InstanceLifecycle
20742
+ * admitCredentialUse) from the configuration it launched with — never re-resolved against today's defaults. An entry
20743
+ * whose start ended without a daemon, or whose daemon is gone, is dropped when next read.
20744
+ */
20745
+ credentialLeases = new Map();
20746
+ /** #3292 review: Keep sign-in alive runs in flight, by sign-in: a start on that sign-in waits for its end. */
20747
+ keepAliveRenewing = new Map();
20748
+ credentialKey(backend, profile) { return `${backend}\0${(profile ?? "").toLowerCase()}`; }
20749
+ /**
20750
+ * The sign-in a start launches on, from the instance's own (defaults-expanded at load) options — exactly what the
20751
+ * Daemon's clone of that config hands its CLI. Never today's defaults: an older config object keeps its own.
20752
+ */
20753
+ launchCredentialKey(config, backend) {
20754
+ let profile = null;
20755
+ try {
20756
+ profile = resolveCredentialProfile(config.backend_options?.[backend]);
20757
+ }
20758
+ catch {
20759
+ profile = null;
20760
+ }
20761
+ return this.credentialKey(backend, profile);
20762
+ }
20763
+ /**
20764
+ * #3313 review r2: failed starts whose CLI was not proven gone keep holding their sign-in (across a retry of the same
20765
+ * agent too) until a check finds it ended.
20766
+ */
20767
+ credentialOrphans = new Map();
20768
+ orphanCheck = null;
20769
+ recheckCredentialOrphans() {
20770
+ if (this.orphanCheck || !this.credentialOrphans.size)
20771
+ return;
20772
+ this.orphanCheck = (async () => {
20773
+ for (const [id, o] of [...this.credentialOrphans]) {
20774
+ let gone = false;
20775
+ try {
20776
+ gone = await o.ended();
20777
+ }
20778
+ catch {
20779
+ gone = false;
20780
+ }
20781
+ if (gone)
20782
+ this.credentialOrphans.delete(id);
20783
+ }
20784
+ })().finally(() => { this.orphanCheck = null; });
20785
+ }
20786
+ /**
20787
+ * LifecycleContext: hold the sign-in a start will launch on (waits while Keep sign-in alive renews it). The key is
20788
+ * read again after every wait; `current(config)` lets the start check, with no await before it builds its Daemon,
20789
+ * that the config still names that sign-in (a save may have changed it meanwhile: then it asks again).
20790
+ */
20791
+ async admitCredentialUse(name, config, backend, assertCurrent) {
20792
+ if (!isKeepAliveBackend(backend) || isWindowsInstance(config))
20793
+ return null;
20794
+ let key = this.launchCredentialKey(config, backend);
20795
+ for (let renewing = this.keepAliveRenewing.get(key); renewing; renewing = this.keepAliveRenewing.get(key)) {
20796
+ await renewing;
20797
+ assertCurrent();
20798
+ key = this.launchCredentialKey(config, backend);
20799
+ }
20800
+ const lease = { key, starting: true };
20801
+ this.credentialLeases.set(name, lease);
20802
+ const drop = () => { if (this.credentialLeases.get(name) === lease)
20803
+ this.credentialLeases.delete(name); };
20804
+ return {
20805
+ published: () => { lease.starting = false; },
20806
+ release: drop,
20807
+ current: c => this.launchCredentialKey(c, backend) === key,
20808
+ // A failed start whose CLI may still run: the sign-in stays held (by itself, not by the agent's name) until it is seen gone.
20809
+ unknownEnd: ended => { drop(); this.credentialOrphans.set(Symbol(name), { key, ended }); this.recheckCredentialOrphans(); },
20810
+ };
20811
+ }
20812
+ /**
20813
+ * #3292: a sign-in is in use when a host agent is starting or running on it (as launched), a ClassicBot room is bound
20814
+ * to it (or the rooms cannot be read — none when there is no classicBot.yaml), or a sign-in for it is running. Codex
20815
+ * refresh tokens are single-use: a refresh beside a live user could spend the one it holds; and use keeps it alive.
20816
+ */
20817
+ keepAliveInUse(backend, profile) {
20818
+ const key = this.credentialKey(backend, profile);
20819
+ for (const o of this.credentialOrphans.values())
20820
+ if (o.key === key) {
20821
+ this.recheckCredentialOrphans();
20822
+ return true;
20823
+ }
20824
+ for (const [name, lease] of [...this.credentialLeases]) {
20825
+ if (!lease.starting && !this.daemons?.has(name)) {
20826
+ this.credentialLeases.delete(name);
20827
+ continue;
20828
+ }
20829
+ if (lease.key === key)
20830
+ return true;
20831
+ }
20832
+ const same = (p) => profile === null ? !p : !!p && p.toLowerCase() === profile.toLowerCase();
20833
+ const defaults = this.fleetConfig?.defaults, defaultBackend = defaults?.backend ?? "claude-code";
20834
+ // A running agent with no record (started some other way): only its own setting is trusted; none names an account, so it may be on any.
20835
+ for (const [name, daemon] of this.daemons ?? []) {
20836
+ if (this.credentialLeases.has(name))
20837
+ continue;
20838
+ let snap;
20839
+ try {
20840
+ snap = daemon.getConfigSnapshot?.();
20841
+ }
20842
+ catch {
20843
+ snap = undefined;
20844
+ }
20845
+ if (snap && isWindowsInstance(snap))
20846
+ continue;
20847
+ if (!snap)
20848
+ return true;
20849
+ if ((snap.backend ?? defaultBackend) !== backend)
20850
+ continue;
20851
+ let own = null;
20852
+ try {
20853
+ own = resolveCredentialProfile(snap.backend_options?.[backend]);
20854
+ }
20855
+ catch {
20856
+ return true;
20857
+ }
20858
+ if (!own || same(own))
20859
+ return true;
20860
+ }
20861
+ const rooms = readClassicBindingsStrict(this.dataDir);
20862
+ if (rooms.kind === "unknown")
20863
+ return true;
20864
+ for (const b of rooms.kind === "ok" ? rooms.bindings : []) {
20865
+ const cli = b.backend ?? defaultBackend;
20866
+ if (cli === backend && same(profileName(classicProfile(b.backend_options, defaults?.backend_options, cli))))
20867
+ return true;
20868
+ }
20869
+ return this.loginController?.signingIn(backend, profile) ?? false;
20870
+ }
20871
+ /**
20872
+ * #3292 review: one keep-alive run's admission, decided synchronously: not in use, the shared login window taken, and the
20873
+ * sign-in marked as renewing (a start on it waits). The run's life is an account writer: a stop waits for it, and
20874
+ * sign-in admission reopens after a restart only once it has ended. `release()` only after its CLI has exited.
20875
+ */
20876
+ acquireKeepAliveRun(backend, profile) {
20877
+ if (this.keepAliveInUse(backend, profile))
20878
+ return "in_use";
20879
+ const claim = this.loginWindow.tryClaim("keepalive", backend);
20880
+ if (!claim)
20881
+ return "busy";
20882
+ const key = this.credentialKey(backend, profile);
20883
+ let finished;
20884
+ const life = new Promise(r => { finished = r; });
20885
+ this.keepAliveRenewing.set(key, life);
20886
+ this.accountWriters.add(life);
20887
+ let released = false;
20888
+ return {
20889
+ release: () => {
20890
+ if (released)
20891
+ return;
20892
+ released = true;
20893
+ this.loginWindow.release(claim);
20894
+ if (this.keepAliveRenewing.get(key) === life)
20895
+ this.keepAliveRenewing.delete(key);
20896
+ this.accountWriters.delete(life);
20897
+ finished();
20898
+ },
20899
+ };
20900
+ }
20901
+ /** #3292: Needs you's lines for kept sign-ins, in the fleet's language (posted in General's world, like config issues). */
20902
+ keepAliveAttention() {
20903
+ const ka = this.signInKeepAlive;
20904
+ if (!ka)
20905
+ return [];
20906
+ const day = (ms) => ms === undefined ? "?" : new Date(ms).toISOString().slice(0, 10);
20907
+ const owner = this.worlds.keys().next().value;
20908
+ return ka.attention().map(a => ({
20909
+ backend: a.backend, profile: a.profile, kind: a.kind, since: a.since, signIn: dashboardSignInSupported(a.backend, a.profile),
20910
+ ...(owner ? { owner } : {}),
20911
+ detail: t(`keepalive.${a.kind}`, BACKEND_LABELS[a.backend] ?? a.backend, a.profile ?? t("keepalive.default_name"), day(a.kind === "transient" ? a.failedSince ?? a.since : a.endsAt)),
20912
+ }));
20913
+ }
20914
+ /** #3292: Settings → Accounts → Keep sign-in alive (POST /ui/accounts/keep-alive). `by`: the session's label, for the fleet log. */
20915
+ setAccountKeepAlive(backend, profile, enabled, fallback, by) {
20916
+ const r = this.keepAliveService().set(backend, profile, enabled, fallback);
20917
+ if (r.ok)
20918
+ this.logger.info({ backend, profile: profile ?? "(default)", enabled, by }, "Keep sign-in alive changed from Settings → Accounts");
20919
+ return r;
20920
+ }
20921
+ /**
20922
+ * Who uses which account: host agents (an agent on a paired Windows computer runs on that computer's accounts — its
20923
+ * own scope), ClassicBot rooms and the fleet default per CLI, each with its effective profile (null: the default sign-in).
20924
+ */
20925
+ accountUses() {
20926
+ const fleet = this.fleetConfig;
20927
+ const defaultBackend = fleet?.defaults?.backend ?? "claude-code";
20928
+ const agents = Object.keys(fleet?.instances ?? {}).filter(name => !isWindowsInstance(fleet.instances[name])).sort()
20929
+ .map(name => { const backend = this.backendNameForInstance(name); return { name, backend, profile: this.credentialProfileOf(name, backend) }; });
20930
+ const classic = readClassicBindings(this.dataDir).map(b => {
20931
+ const backend = b.backend ?? defaultBackend;
20932
+ return { key: b.key, backend, profile: profileName(classicProfile(b.backend_options, fleet?.defaults?.backend_options, backend)) };
20933
+ });
20934
+ const fleetDefaults = new Map();
20935
+ for (const backend of PROFILE_CLIS) {
20936
+ const p = profileName(profileOf(fleet?.defaults?.backend_options, backend));
20937
+ if (p)
20938
+ fleetDefaults.set(backend, p);
20939
+ }
20940
+ return { agents, classic, fleetDefaults };
20941
+ }
20942
+ /** #3212 PR 2: Settings → Accounts → + Add account (accounts-profiles.ts). `by`: the session's label, for the fleet log. */
20943
+ addAccountProfile(backend, name, by, machine) {
20944
+ // #3190 Part 3c: on a paired computer the profile's folder is made by its Runtime when the first sign-in starts; this only checks what can be checked first.
20945
+ if (machine)
20946
+ return this.machineAccounts.add(backend, name, machine.id, by);
20947
+ const { agents, classic, fleetDefaults } = this.accountUses();
20948
+ const configured = new Set();
20949
+ for (const x of [...agents, ...classic])
20950
+ if (x.backend === backend && x.profile)
20951
+ configured.add(x.profile);
20952
+ const fd = fleetDefaults.get(backend);
20953
+ if (fd)
20954
+ configured.add(fd);
20955
+ const result = addAccountProfile(this.dataDir, backend, name, configured);
20956
+ if (result.ok)
20957
+ this.logger.info({ backend, profile: name, by }, "Credential profile added from Settings → Accounts");
20958
+ return result;
20959
+ }
20960
+ /**
20961
+ * #3212 PR 2: Settings → Accounts → Remove. Refused while anything uses it or a sign-in for it runs (the login controller,
20962
+ * or the login window held for this backend by a sign-in whose profile is not known yet); see accounts-profiles.ts.
20963
+ * The fleet log records who removed which backend's profile — never what was in it.
20964
+ */
20965
+ async removeAccountProfile(backend, name, confirm, by, machine) {
20966
+ if (machine)
20967
+ return this.machineAccounts.remove(backend, name, confirm, machine.id, machine, by); // #3190 Part 3c: that computer's Runtime deletes its own folder
20968
+ const profile = typeof name === "string" ? name : "";
20969
+ const shown = validCredentialProfileName(name) ? name : "(invalid)";
20970
+ const refused = (r) => { if (!r.ok)
20971
+ this.logger.info({ backend, profile: shown, by, refused: r.error }, "Credential profile removal refused"); return r; };
20972
+ // #3212 PR 3: on macOS, Claude Code keeps the account's token in the Keychain, outside the folder — its own logout
20973
+ // (run with the folder, once every Remove check has passed) removes that item first. AgEnD never deletes it itself.
20974
+ // #3305 review: the logout holds the shared login window (no sign-in or other logout starts meanwhile), and after it
20975
+ // every check is made again — who uses it, sign-ins, ClassicBot's settings — on the same folder (its identity).
20976
+ const signOutDeps = this.accountSignOutDeps ?? ACCOUNT_SIGN_OUT_DEPS;
20977
+ let keychainLeft = false;
20978
+ let removed;
20979
+ if (backend === "claude-code" && signOutDeps.platform === "darwin") {
20980
+ const dry = removeAccountProfile(this.dataDir, this.removalRequest(backend, name, confirm, null), undefined, { dryRun: true });
20981
+ if (!dry.ok)
20982
+ return refused(dry);
20983
+ const claim = this.loginWindow.tryClaim("web", backend);
20984
+ if (!claim)
20985
+ return refused({ ok: false, error: "signing_in" });
20986
+ const step = await this.withAccountWriter(claim, async (deps) => {
20987
+ const out = await signOutAccount(this.dataDir, { backend, profile, confirm: true, signingIn: false }, deps);
20988
+ if (!out.ok)
20989
+ return { ok: false, error: out.error === "unsafe" ? "unsafe" : "failed" };
20990
+ if (!this.loginWindow.isCurrent(claim))
20991
+ return { ok: false, error: "failed" }; // the fleet is stopping
20992
+ keychainLeft = out.keychainLeft === true;
20993
+ return removeAccountProfile(this.dataDir, this.removalRequest(backend, name, confirm, claim), undefined, { expect: dry.identity });
20994
+ });
20995
+ if (!step.ok)
20996
+ return refused(step);
20997
+ removed = step;
20998
+ }
20999
+ else
21000
+ removed = removeAccountProfile(this.dataDir, this.removalRequest(backend, name, confirm, null));
21001
+ if (!removed.ok)
21002
+ return refused(removed);
21003
+ this.logger.info({ backend, profile, by, ...(keychainLeft ? { keychainLeft } : {}) }, "Credential profile removed from Settings → Accounts");
21004
+ return keychainLeft ? { ok: true, keychainLeft: true } : { ok: true };
21005
+ }
21006
+ /**
21007
+ * Remove's whole safety proof, read now (#3291 review): who uses the account — configured agents and live daemons, the
21008
+ * fleet default, ClassicBot rooms read strictly — and whether a sign-in for it runs. `ownClaim`: the login window this
21009
+ * removal holds itself, which is not someone else's sign-in.
21010
+ */
21011
+ removalRequest(backend, name, confirm, ownClaim) {
21012
+ const profile = typeof name === "string" ? name : "";
21013
+ // #3291 review (Prism P2-3): one folder on a case-insensitive disk (Windows, default macOS) — `Work` and `work` are the
21014
+ // same account for every safety check here.
21015
+ const same = (p) => !!p && p.toLowerCase() === profile.toLowerCase();
21016
+ const { agents, fleetDefaults } = this.accountUses();
21017
+ const defaultBackend = this.fleetConfig?.defaults?.backend ?? "claude-code";
21018
+ // #3291 review (Prism P2-2): ClassicBot rooms read strictly — an unreadable or malformed classicBot.yaml is not "no rooms".
21019
+ const rooms = readClassicBindingsStrict(this.dataDir);
21020
+ const classic = rooms.kind === "ok" ? rooms.bindings.map(b => {
21021
+ const cli = b.backend ?? defaultBackend;
21022
+ return { key: b.key, backend: cli, profile: profileName(classicProfile(b.backend_options, this.fleetConfig?.defaults?.backend_options, cli)) };
21023
+ }) : [];
21024
+ // #3291 review (Prism P2-1): what a running CLI was launched with. An agent or room moved off this account keeps
21025
+ // running on it until its process stops (the configuration changes first): it is still a user until then.
21026
+ const live = [];
21027
+ for (const [instance, daemon] of this.daemons ?? []) {
21028
+ let snap;
21029
+ try {
21030
+ snap = daemon.getConfigSnapshot?.();
21031
+ }
21032
+ catch {
21033
+ snap = undefined;
21034
+ }
21035
+ if (!snap || isWindowsInstance(snap))
21036
+ continue;
21037
+ const cli = snap.backend ?? defaultBackend;
21038
+ if (cli !== backend)
21039
+ continue;
21040
+ let launched = null;
21041
+ try {
21042
+ launched = resolveCredentialProfile(snap.backend_options?.[cli]);
21043
+ }
21044
+ catch {
21045
+ launched = null;
21046
+ }
21047
+ if (same(launched))
21048
+ live.push(instance);
21049
+ }
21050
+ const users = {
21051
+ agents: [...new Set([...agents.filter(a => a.backend === backend && same(a.profile)).map(a => a.name), ...live])].sort(),
21052
+ classic: classic.filter(c => c.backend === backend && same(c.profile)).map(c => c.key),
21053
+ fleetDefault: same(fleetDefaults.get(backend)),
21054
+ };
21055
+ const held = this.loginWindow.current;
21056
+ const signingIn = (this.loginController?.signingIn(backend, profile) ?? false)
21057
+ || (!!held && held !== ownClaim && held.backend === backend && !this.loginController?.activeBackend);
21058
+ return { backend, name, confirm, users, signingIn, usersUnknown: rooms.kind === "unknown" };
21059
+ }
21060
+ /**
21061
+ * #3212 PR 3: Settings → Accounts → Sign out (accounts-signout.ts): the CLI's own logout for the default sign-in
21062
+ * (`profile` null) or a named account. Refused while a sign-in for it runs (case-insensitive, as Remove). The fleet
21063
+ * log records who signed out which backend's account; then every page reads the sign-ins again.
21064
+ */
21065
+ /** How a CLI's logout is run and the Keychain asked (a test's stand-in; the platform with it). */
21066
+ accountSignOutDeps = ACCOUNT_SIGN_OUT_DEPS;
21067
+ /** #3305 review: every account logout's whole life — its CLI children until positively gone (shutdown drains them). */
21068
+ accountWriters = new Set();
21069
+ /**
21070
+ * #3305 review P2-3/P2-5: run `work` as the owner of the credential writer (`claim`). Its CLIs run through a runner
21071
+ * that records each child's positive end; the work is told whether it still owns the writer (`stillOwner`) before it
21072
+ * cleans anything; and the claim is released only once every child it started is positively gone — a child whose end
21073
+ * is unknown keeps sign-in admission closed (logged). Shutdown waits for these (shutdownLoginWindows), and a restart
21074
+ * reopens admission only after they are gone.
21075
+ */
21076
+ async withAccountWriter(claim, work) {
21077
+ const base = this.accountSignOutDeps ?? ACCOUNT_SIGN_OUT_DEPS;
21078
+ const children = [];
21079
+ const watch = async (r) => { if (r.gone)
21080
+ children.push(r.gone); return r; };
21081
+ const deps = {
21082
+ platform: base.platform,
21083
+ run: async (b, a, e) => watch(await base.run(b, a, e)),
21084
+ keychainHas: base.keychainHas,
21085
+ stillOwner: () => this.loginWindow.isCurrent(claim),
21086
+ };
21087
+ let finished;
21088
+ const life = new Promise(r => { finished = r; });
21089
+ this.accountWriters.add(life);
21090
+ try {
21091
+ return await work(deps);
21092
+ }
21093
+ finally {
21094
+ const settle = () => { this.loginWindow.release(claim); this.accountWriters.delete(life); finished(); };
21095
+ if (!children.length)
21096
+ settle();
21097
+ else {
21098
+ let warned = false;
21099
+ const t = setTimeout(() => { warned = true; this.logger.error("An account logout's CLI has not ended: sign-in stays closed until it does"); }, 30_000);
21100
+ t.unref?.();
21101
+ void Promise.all(children).then(() => { clearTimeout(t); if (warned)
21102
+ this.logger.info("The account logout's CLI ended: sign-in is open again"); settle(); });
21103
+ }
21104
+ }
21105
+ }
21106
+ async signOutAccount(backend, profile, confirm, by, machine) {
21107
+ if (machine)
21108
+ return this.machineAccounts.signOut(backend, profile, confirm, machine.id, machine, by); // #3190 Part 3c: that computer's Runtime runs the CLI's own logout
21109
+ const named = typeof profile === "string" ? profile : null;
21110
+ const shown = named === null ? "(default)" : validCredentialProfileName(named) ? named : "(invalid)";
21111
+ // #3305 review P2-3: the logout holds the shared login window from before it runs until its cleanup is done — no
21112
+ // sign-in (chat, dashboard, install) and no other logout starts meanwhile; one already running refuses this.
21113
+ const signingIn = this.loginController?.signingIn(backend, named) ?? false;
21114
+ const claim = signingIn ? null : this.loginWindow.tryClaim("web", backend);
21115
+ let result;
21116
+ if (!claim)
21117
+ result = { ok: false, error: "signing_in" };
21118
+ else
21119
+ result = await this.withAccountWriter(claim, deps => signOutAccount(this.dataDir, { backend, profile: profile ?? null, confirm, signingIn: false }, deps));
21120
+ if (result.ok) {
21121
+ this.logger.info({ backend, profile: shown, by, ...(result.keychainLeft ? { keychainLeft: true } : {}) }, "Account signed out from Settings → Accounts");
21122
+ this.forgetSignInIdentities();
21123
+ void this.backendAvailability.refresh([backend], { force: true }).catch(() => { });
21124
+ broadcastSseEvent(this.sseClients, "backend_login", {}, err => this.logger.debug({ err }, "backend_login event failed"));
21125
+ }
21126
+ else
21127
+ this.logger.info({ backend, profile: shown, by, refused: result.error }, "Account sign-out refused");
21128
+ return result;
20493
21129
  }
20494
21130
  backendSignInTargets() {
20495
21131
  const out = [];
@@ -20795,11 +21431,32 @@ export class FleetManager {
20795
21431
  return this.webLogin.start(backendArg, chat, opts);
20796
21432
  }
20797
21433
  /** Fleet shutdown: end any web login or install window and wait for its confirmed teardown. */
21434
+ /**
21435
+ * #3305 review P2-3: reopen sign-in admission after a restart — only once no account logout's CLI from before is still
21436
+ * alive (a fresh sign-in must never overlap it). Each reopen supersedes a deferred one.
21437
+ */
21438
+ loginReopenGen = 0;
21439
+ reopenLoginWindow() {
21440
+ const gen = ++this.loginReopenGen;
21441
+ const pending = [...this.accountWriters];
21442
+ if (!pending.length) {
21443
+ this.loginWindow.reopen();
21444
+ return;
21445
+ }
21446
+ this.logger.warn({ pending: pending.length }, "Sign-in admission reopens once an account logout from before the restart has ended");
21447
+ void Promise.all(pending).then(() => { if (gen === this.loginReopenGen && !this.structuredLoginCleanupFailed)
21448
+ this.loginWindow.reopen(); });
21449
+ }
20798
21450
  async shutdownLoginWindows() {
21451
+ // #3305 review: a newer stop supersedes a reopen still waiting for an old account logout's CLI.
21452
+ this.loginReopenGen++;
20799
21453
  // Close the lock FIRST: in-flight starts parked in a pre-check or
20800
21454
  // ensureSession observe !isCurrent when they resume and stop; no new
20801
21455
  // window can be claimed while we stop.
20802
21456
  this.loginWindow.close();
21457
+ // #3292 review: Keep sign-in alive stops asking for runs and stops its CLI; its run's life is an account writer,
21458
+ // waited for below like an account logout.
21459
+ void this.signInKeepAlive?.stop();
20803
21460
  // Completion semantics live INSIDE the sessions: each awaits its own
20804
21461
  // confirmed cleanup, every tmux op on that path has a hard per-op bound
20805
21462
  // (web: abort ≤10 s + kill ≤31 s; legacy: create/list/kill ≤10 s each,
@@ -20836,8 +21493,17 @@ export class FleetManager {
20836
21493
  this.logger.error("Structured login cleanup failed; sign-in admission remains closed until the host is restarted.");
20837
21494
  }
20838
21495
  }), "browser-controls"),
21496
+ // #3190 Part 3c: a sign-in running on a paired computer is ended (its Runtime also ends it when the connection goes). One that could not be shown gone is logged.
21497
+ bounded(this.machineSignInsInstance?.close().then(confirmed => {
21498
+ if (confirmed)
21499
+ this.machineSignInsInstance = null;
21500
+ else
21501
+ this.logger.error("A computer's account sign-in could not be confirmed ended; check that computer's Runtime window.");
21502
+ }), "machine-signins"),
20839
21503
  bounded(this.loginController?.shutdown(), "web-login"),
20840
21504
  bounded(this.activeInstall?.session.cancel("cancelled"), "install"),
21505
+ // #3305 review P2-3: an account logout in flight (its CLI) — the closed window fences its cleanup; this waits for it.
21506
+ bounded(this.accountWriters.size ? Promise.all([...this.accountWriters]).then(() => undefined) : undefined, "account-logout"),
20841
21507
  ]);
20842
21508
  }
20843
21509
  /** `/login cancel` — abort the active session and remove its window. */
@@ -24356,6 +25022,7 @@ export class FleetManager {
24356
25022
  ...this.fleetConfig?.defaults,
24357
25023
  working_directory: workDir,
24358
25024
  lightweight: true,
25025
+ quota_notice: classicIdentity?.quotaNotice,
24359
25026
  tool_progress: toolProgress ?? "off",
24360
25027
  reply_completion_guard: replyCompletionGuard ?? true,
24361
25028
  ...(backend ? { backend } : {}),
@@ -24535,6 +25202,9 @@ export class FleetManager {
24535
25202
  // because we asked it to. Set synchronously — doStopAll runs to its first
24536
25203
  // await in the same tick as the signal handler, so no event can slip in.
24537
25204
  this.shuttingDown = true;
25205
+ this.stopQuotaObserver?.();
25206
+ this.stopQuotaObserver = null;
25207
+ const quotaNoticesStopped = this.quotaNotices?.stop();
24538
25208
  // Stop receive admission before the first await or any instance shutdown; outbound
24539
25209
  // adapters remain available below to retire notices and pending prompts.
24540
25210
  for (const state of this.adapterState.values()) {
@@ -24630,6 +25300,8 @@ export class FleetManager {
24630
25300
  await needsStopped;
24631
25301
  await settingsControlStopped;
24632
25302
  await cacheStopped;
25303
+ await quotaNoticesStopped;
25304
+ this.quotaNotices = null;
24633
25305
  await webChatStopped;
24634
25306
  await this.cpuProfileControl?.close();
24635
25307
  this.cpuProfileControl = null;