@songsid/agend 2.3.5-alpha.8 → 2.3.5-alpha.9

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 (266) hide show
  1. package/dist/accounts-profiles.d.ts +6 -0
  2. package/dist/accounts-profiles.js +16 -0
  3. package/dist/accounts-profiles.js.map +1 -1
  4. package/dist/agent-cli-instructions.md +1 -1
  5. package/dist/agent-cli.js +5 -2
  6. package/dist/agent-cli.js.map +1 -1
  7. package/dist/agent-whats-new.js +5 -0
  8. package/dist/agent-whats-new.js.map +1 -1
  9. package/dist/authority/company-join.d.ts +16 -0
  10. package/dist/authority/company-join.js +37 -0
  11. package/dist/authority/company-join.js.map +1 -0
  12. package/dist/authority/hub-initialization.d.ts +13 -0
  13. package/dist/authority/hub-initialization.js +30 -0
  14. package/dist/authority/hub-initialization.js.map +1 -0
  15. package/dist/backend/claude-code.d.ts +1 -0
  16. package/dist/backend/claude-code.js +13 -0
  17. package/dist/backend/claude-code.js.map +1 -1
  18. package/dist/backend/types.d.ts +4 -0
  19. package/dist/backend/types.js.map +1 -1
  20. package/dist/build-provenance.json +1 -1
  21. package/dist/channel/mcp-tools.js +2 -2
  22. package/dist/channel/mcp-tools.js.map +1 -1
  23. package/dist/claude-model-minimum.d.ts +7 -0
  24. package/dist/claude-model-minimum.js +16 -0
  25. package/dist/claude-model-minimum.js.map +1 -0
  26. package/dist/daemon.d.ts +43 -1
  27. package/dist/daemon.js +176 -27
  28. package/dist/daemon.js.map +1 -1
  29. package/dist/decision-list.d.ts +2 -0
  30. package/dist/decision-list.js +1 -1
  31. package/dist/decision-list.js.map +1 -1
  32. package/dist/fleet-manager.d.ts +50 -1
  33. package/dist/fleet-manager.js +306 -32
  34. package/dist/fleet-manager.js.map +1 -1
  35. package/dist/general-knowledge/skills/concepts/SKILL.md +14 -3
  36. package/dist/general-knowledge/skills/delegation-playbook/SKILL.md +4 -1
  37. package/dist/hub/client.js +2 -0
  38. package/dist/hub/client.js.map +1 -1
  39. package/dist/hub/compose/member.js +1 -1
  40. package/dist/hub/compose/member.js.map +1 -1
  41. package/dist/hub/compose/server.d.ts +48 -1
  42. package/dist/hub/compose/server.js +30 -5
  43. package/dist/hub/compose/server.js.map +1 -1
  44. package/dist/hub/directory/directory.d.ts +2 -0
  45. package/dist/hub/directory/directory.js +49 -4
  46. package/dist/hub/directory/directory.js.map +1 -1
  47. package/dist/hub/directory/types.d.ts +2 -0
  48. package/dist/hub/directory/types.js.map +1 -1
  49. package/dist/hub/enrollment-budget.d.ts +6 -0
  50. package/dist/hub/enrollment-budget.js +24 -0
  51. package/dist/hub/enrollment-budget.js.map +1 -0
  52. package/dist/hub/group-policy/authorization.d.ts +5 -0
  53. package/dist/hub/group-policy/authorization.js +24 -1
  54. package/dist/hub/group-policy/authorization.js.map +1 -1
  55. package/dist/hub/http/compose.js +62 -8
  56. package/dist/hub/http/compose.js.map +1 -1
  57. package/dist/hub/http/core.d.ts +2 -0
  58. package/dist/hub/http/core.js +10 -1
  59. package/dist/hub/http/core.js.map +1 -1
  60. package/dist/hub/http/deps.d.ts +3 -0
  61. package/dist/hub/http/schema.js +4 -0
  62. package/dist/hub/http/schema.js.map +1 -1
  63. package/dist/hub/init/browser-certificate.d.ts +6 -1
  64. package/dist/hub/init/browser-certificate.js +22 -1
  65. package/dist/hub/init/browser-certificate.js.map +1 -1
  66. package/dist/hub/init/initializer.d.ts +11 -1
  67. package/dist/hub/init/initializer.js +202 -83
  68. package/dist/hub/init/initializer.js.map +1 -1
  69. package/dist/hub/init/layout.js +1 -1
  70. package/dist/hub/init/layout.js.map +1 -1
  71. package/dist/hub/init/text.js +2 -2
  72. package/dist/hub/init/text.js.map +1 -1
  73. package/dist/hub/init/types.d.ts +32 -4
  74. package/dist/hub/init/types.js.map +1 -1
  75. package/dist/hub/init/web-audit-import.d.ts +12 -0
  76. package/dist/hub/init/web-audit-import.js +39 -0
  77. package/dist/hub/init/web-audit-import.js.map +1 -0
  78. package/dist/hub/init/web-audit.d.ts +30 -0
  79. package/dist/hub/init/web-audit.js +42 -0
  80. package/dist/hub/init/web-audit.js.map +1 -0
  81. package/dist/hub/init/web-error.d.ts +6 -0
  82. package/dist/hub/init/web-error.js +8 -0
  83. package/dist/hub/init/web-error.js.map +1 -0
  84. package/dist/hub/init/web-http.d.ts +9 -0
  85. package/dist/hub/init/web-http.js +103 -0
  86. package/dist/hub/init/web-http.js.map +1 -0
  87. package/dist/hub/init/web.d.ts +118 -0
  88. package/dist/hub/init/web.js +428 -0
  89. package/dist/hub/init/web.js.map +1 -0
  90. package/dist/hub/init/wizard.js +1 -3
  91. package/dist/hub/init/wizard.js.map +1 -1
  92. package/dist/hub/join/client.d.ts +35 -0
  93. package/dist/hub/join/client.js +112 -0
  94. package/dist/hub/join/client.js.map +1 -0
  95. package/dist/hub/join/descriptor.d.ts +45 -0
  96. package/dist/hub/join/descriptor.js +52 -0
  97. package/dist/hub/join/descriptor.js.map +1 -0
  98. package/dist/hub/join/fleet-authority.d.ts +2 -0
  99. package/dist/hub/join/fleet-authority.js +3 -0
  100. package/dist/hub/join/fleet-authority.js.map +1 -0
  101. package/dist/hub/join/http.d.ts +8 -0
  102. package/dist/hub/join/http.js +112 -0
  103. package/dist/hub/join/http.js.map +1 -0
  104. package/dist/hub/join/invitation.d.ts +28 -0
  105. package/dist/hub/join/invitation.js +28 -0
  106. package/dist/hub/join/invitation.js.map +1 -0
  107. package/dist/hub/join/local-journal.d.ts +84 -0
  108. package/dist/hub/join/local-journal.js +65 -0
  109. package/dist/hub/join/local-journal.js.map +1 -0
  110. package/dist/hub/join/local.d.ts +116 -0
  111. package/dist/hub/join/local.js +419 -0
  112. package/dist/hub/join/local.js.map +1 -0
  113. package/dist/hub/join/private.d.ts +3 -0
  114. package/dist/hub/join/private.js +46 -0
  115. package/dist/hub/join/private.js.map +1 -0
  116. package/dist/hub/join/protocol.d.ts +69 -0
  117. package/dist/hub/join/protocol.js +96 -0
  118. package/dist/hub/join/protocol.js.map +1 -0
  119. package/dist/hub/join/receipt.d.ts +42 -0
  120. package/dist/hub/join/receipt.js +75 -0
  121. package/dist/hub/join/receipt.js.map +1 -0
  122. package/dist/hub/join/service.d.ts +177 -0
  123. package/dist/hub/join/service.js +564 -0
  124. package/dist/hub/join/service.js.map +1 -0
  125. package/dist/hub/join/store.d.ts +97 -0
  126. package/dist/hub/join/store.js +87 -0
  127. package/dist/hub/join/store.js.map +1 -0
  128. package/dist/hub/join/trust.d.ts +13 -0
  129. package/dist/hub/join/trust.js +68 -0
  130. package/dist/hub/join/trust.js.map +1 -0
  131. package/dist/hub/member/pairing-api.js +6 -1
  132. package/dist/hub/member/pairing-api.js.map +1 -1
  133. package/dist/hub/member/pairing-notices.js +6 -4
  134. package/dist/hub/member/pairing-notices.js.map +1 -1
  135. package/dist/hub/pairing-notices.d.ts +3 -3
  136. package/dist/hub/pairing-notices.js +13 -8
  137. package/dist/hub/pairing-notices.js.map +1 -1
  138. package/dist/hub/pairing.d.ts +6 -0
  139. package/dist/hub/pairing.js +6 -6
  140. package/dist/hub/pairing.js.map +1 -1
  141. package/dist/hub/protocol.d.ts +29 -0
  142. package/dist/hub/protocol.js +3 -1
  143. package/dist/hub/protocol.js.map +1 -1
  144. package/dist/hub/room-read-pacer.d.ts +14 -0
  145. package/dist/hub/room-read-pacer.js +51 -0
  146. package/dist/hub/room-read-pacer.js.map +1 -0
  147. package/dist/hub/rooms.d.ts +7 -1
  148. package/dist/hub/rooms.js +25 -13
  149. package/dist/hub/rooms.js.map +1 -1
  150. package/dist/hub/runtime.d.ts +4 -0
  151. package/dist/hub/runtime.js +2 -0
  152. package/dist/hub/runtime.js.map +1 -1
  153. package/dist/hub/server.d.ts +3 -0
  154. package/dist/hub/server.js +14 -0
  155. package/dist/hub/server.js.map +1 -1
  156. package/dist/hub/session-directory-transition.d.ts +48 -0
  157. package/dist/hub/session-directory-transition.js +118 -0
  158. package/dist/hub/session-directory-transition.js.map +1 -0
  159. package/dist/hub/session-epoch.d.ts +16 -0
  160. package/dist/hub/session-epoch.js +50 -0
  161. package/dist/hub/session-epoch.js.map +1 -0
  162. package/dist/hub/sessions.d.ts +13 -0
  163. package/dist/hub/sessions.js +36 -16
  164. package/dist/hub/sessions.js.map +1 -1
  165. package/dist/hub/settings-api.d.ts +50 -0
  166. package/dist/hub/settings-api.js +92 -0
  167. package/dist/hub/settings-api.js.map +1 -0
  168. package/dist/hub/settings-commit.d.ts +95 -0
  169. package/dist/hub/settings-commit.js +490 -0
  170. package/dist/hub/settings-commit.js.map +1 -0
  171. package/dist/hub/settings-directory-decision.d.ts +433 -0
  172. package/dist/hub/settings-directory-decision.js +236 -0
  173. package/dist/hub/settings-directory-decision.js.map +1 -0
  174. package/dist/hub/settings-directory-proof.d.ts +77 -0
  175. package/dist/hub/settings-directory-proof.js +303 -0
  176. package/dist/hub/settings-directory-proof.js.map +1 -0
  177. package/dist/hub/store.d.ts +2 -1
  178. package/dist/hub/store.js +2 -1
  179. package/dist/hub/store.js.map +1 -1
  180. package/dist/hub/types.d.ts +4 -2
  181. package/dist/hub-host-settings.d.ts +48 -0
  182. package/dist/hub-host-settings.js +85 -0
  183. package/dist/hub-host-settings.js.map +1 -0
  184. package/dist/instance-lifecycle.d.ts +3 -0
  185. package/dist/instance-lifecycle.js +4 -0
  186. package/dist/instance-lifecycle.js.map +1 -1
  187. package/dist/locale.js +32 -14
  188. package/dist/locale.js.map +1 -1
  189. package/dist/outbound-schemas.d.ts +2 -0
  190. package/dist/outbound-schemas.js +4 -2
  191. package/dist/outbound-schemas.js.map +1 -1
  192. package/dist/pane-port.d.ts +1 -1
  193. package/dist/profile-signins.d.ts +107 -0
  194. package/dist/profile-signins.js +249 -0
  195. package/dist/profile-signins.js.map +1 -0
  196. package/dist/scheduler/db.d.ts +10 -0
  197. package/dist/scheduler/db.js +38 -11
  198. package/dist/scheduler/db.js.map +1 -1
  199. package/dist/scheduler/types.d.ts +6 -1
  200. package/dist/settings-api.d.ts +7 -0
  201. package/dist/settings-api.js +197 -2
  202. package/dist/settings-api.js.map +1 -1
  203. package/dist/settings-confirmation.d.ts +1 -1
  204. package/dist/settings-confirmation.js +1 -1
  205. package/dist/settings-confirmation.js.map +1 -1
  206. package/dist/settings-effect.js +58 -0
  207. package/dist/settings-effect.js.map +1 -1
  208. package/dist/settings-http-confirmation.d.ts +3 -0
  209. package/dist/settings-http-confirmation.js +8 -5
  210. package/dist/settings-http-confirmation.js.map +1 -1
  211. package/dist/settings-request-capability.d.ts +5 -0
  212. package/dist/settings-request-capability.js +6 -1
  213. package/dist/settings-request-capability.js.map +1 -1
  214. package/dist/structured-signin-transport.d.ts +20 -2
  215. package/dist/structured-signin-transport.js +57 -6
  216. package/dist/structured-signin-transport.js.map +1 -1
  217. package/dist/team-membership.d.ts +7 -0
  218. package/dist/team-membership.js +10 -0
  219. package/dist/team-membership.js.map +1 -0
  220. package/dist/tmux-manager.d.ts +1 -1
  221. package/dist/tmux-manager.js +4 -1
  222. package/dist/tmux-manager.js.map +1 -1
  223. package/dist/topic-commands.js +1 -1
  224. package/dist/topic-commands.js.map +1 -1
  225. package/dist/ui/backend-signin.js +51 -15
  226. package/dist/ui/hub-attachments.js +3 -3
  227. package/dist/ui/hub-chat-strings.js +2 -0
  228. package/dist/ui/hub-client.js +9 -3
  229. package/dist/ui/hub-company-join-strings.js +74 -0
  230. package/dist/ui/hub-company-join.js +119 -0
  231. package/dist/ui/hub-group-policy.js +7 -2
  232. package/dist/ui/hub-owner-strings.js +8 -8
  233. package/dist/ui/hub-quick-pairing.js +15 -8
  234. package/dist/ui/hub-quick-strings.js +3 -3
  235. package/dist/ui/hub-this-hub.js +112 -0
  236. package/dist/ui/hub-welcome.js +8 -5
  237. package/dist/ui/panel-hub.js +178 -26
  238. package/dist/ui/panel-needs.js +1 -1
  239. package/dist/ui/settings-hub-company-join.js +90 -0
  240. package/dist/ui/settings-hub-membership.js +2 -1
  241. package/dist/ui/settings-hub-preview.js +74 -0
  242. package/dist/ui/settings-hub-run.js +60 -0
  243. package/dist/ui/settings-hub-section.js +4 -2
  244. package/dist/ui/settings-registry.js +2 -0
  245. package/dist/ui/shared/app-i18n.js +1 -1
  246. package/dist/ui/shared/app-shell.js +21 -17
  247. package/dist/ui/shared/app.css +9 -8
  248. package/dist/ui/shared/chat-strings.js +13 -13
  249. package/dist/ui/shared/hub-chat.css +12 -0
  250. package/dist/ui/shared/hub-groups.css +2 -0
  251. package/dist/ui/shared/hub-owner.css +19 -1
  252. package/dist/ui/shared/hub.css +7 -1
  253. package/dist/ui/structured-signin.js +24 -6
  254. package/dist/update-dispatch.d.ts +32 -4
  255. package/dist/update-dispatch.js +146 -16
  256. package/dist/update-dispatch.js.map +1 -1
  257. package/dist/update-launch.d.ts +1 -1
  258. package/dist/update-launch.js +2 -2
  259. package/dist/update-launch.js.map +1 -1
  260. package/dist/view-api.d.ts +2 -8
  261. package/dist/view-api.js +3 -9
  262. package/dist/view-api.js.map +1 -1
  263. package/dist/web-api.d.ts +2 -0
  264. package/dist/web-api.js +66 -9
  265. package/dist/web-api.js.map +1 -1
  266. package/package.json +1 -1
@@ -59,7 +59,7 @@ import { withinBudget } from "./monotonic-budget.js";
59
59
  import { measureSyncWork } from "./sync-work-attribution.js";
60
60
  import { RuntimeCpuProfiler, ProfileBusyError, profileDuration } from "./runtime-cpu-profile.js";
61
61
  import { ProfileControlServer } from "./profile-control.js";
62
- import { existsSync, readFileSync, mkdirSync, writeFileSync, unlinkSync, rmSync, readdirSync, renameSync, copyFileSync, chmodSync, statSync, realpathSync, lstatSync, closeSync } from "node:fs";
62
+ import { existsSync, readFileSync, mkdirSync, writeFileSync, unlinkSync, rmSync, readdirSync, renameSync, copyFileSync, chmodSync, statSync, realpathSync, lstatSync, constants as fsConstants, openSync, closeSync, fsyncSync } from "node:fs";
63
63
  import { atomicWriteFileSync } from "./atomic-write.js";
64
64
  import { createHash, randomBytes, randomUUID } from "node:crypto";
65
65
  import { freemem, totalmem, homedir, hostname } from "node:os";
@@ -342,6 +342,8 @@ import { SessionAuthorizationRequests } from "./web-session-authorization.js";
342
342
  import { GuestLoginCodes, WebLoginCodes, LOGIN_CODE_TTL_MS } from "./web-login.js";
343
343
  import { decisionListAnswer } from "./decision-list.js";
344
344
  import { CodeRequestLimiter, ReturningDevices } from "./web-returning-device.js";
345
+ import { hubInitializationSession } from "./authority/hub-initialization.js";
346
+ import { companyJoinSession } from "./authority/company-join.js";
345
347
  import { allowedHostNames, applyWebSecurityHeaders, hostnameOf, isHostAllowed, LOOPBACK_HOST_NAMES, WEB_HOST_REJECTED_MESSAGE } from "./web-host-guard.js";
346
348
  import { createPreviewListener, normalizeOrigin, previewAvailability, previewSettings } from "./web-preview.js";
347
349
  import { isCanvasWorkerTool, CANVAS_WORKER_EXPERIMENTAL_MESSAGE } from "./web-experimental.js";
@@ -360,10 +362,11 @@ import { CHAT_PROFILE_LOGIN_BACKENDS, credentialHomeSpec, credentialProfileHome,
360
362
  import { carryClaudeConversation } from "./backend/claude-carry.js";
361
363
  import { classicProfile, mergeBackendOptions, profileKey, profileName, profileOf, readClassicBindings, readClassicBindingsStrict } from "./classic-bindings.js";
362
364
  import { ACCOUNT_CLIS, PROFILE_CLIS, buildAccountsView, profilesOnDisk, shortUsage, weeklyUsage } from "./accounts-view.js";
363
- import { addAccountProfile, removeAccountProfile } from "./accounts-profiles.js";
365
+ import { accountFolderExists, addAccountProfile, removeAccountProfile } from "./accounts-profiles.js";
364
366
  import { signOutAccount } from "./accounts-signout.js";
365
367
  import { MachineAccounts, machineAgents } from "./machine-accounts.js";
366
368
  import { MachineSignIns } from "./machine-signins.js";
369
+ import { ProfileSignIns } from "./profile-signins.js";
367
370
  import { runQuiet } from "./quiet-run.js";
368
371
  const ACCOUNT_SIGN_OUT_DEPS = {
369
372
  platform: process.platform,
@@ -730,6 +733,7 @@ export class RestartSupersededError extends Error {
730
733
  }
731
734
  export class FleetManager {
732
735
  dataDir;
736
+ decisionSnapshot = [];
733
737
  static signalTarget = null;
734
738
  static sighupHandlerInstalled = false;
735
739
  /** Test seam: inject a spy to verify saveFleetConfig calls fsync. Default: fsyncSync. */
@@ -1320,7 +1324,98 @@ export class FleetManager {
1320
1324
  hubMemberExposureApi = null;
1321
1325
  hubMemberExposures() { return this.hubMemberExposureApi; }
1322
1326
  attachHubMemberExposures(api) { this.hubMemberExposureApi = api; }
1323
- /** S3c PR B: the member's pairing API, attached by S5's member composition (null: no Hub member here). */
1327
+ /** M-2687: local host-session setup; controller creation stays lazy while the Hub is off. */
1328
+ hubSetupController = null;
1329
+ hubSetupInit = null;
1330
+ hubSetupSession(req) {
1331
+ const token = this.webToken, sessions = this.webSessions, epoch = this.webAuthorityState().epoch;
1332
+ return hubInitializationSession(req, { token, sessions, config: this.fleetConfig, epoch, current: () => !this.shuttingDown
1333
+ && token === this.webToken && sessions === this.webSessions && epoch === this.webAuthorityState().epoch });
1334
+ }
1335
+ async hubSetup() {
1336
+ this.hubSetupInit ??= (async () => {
1337
+ const { createHubWebInitializer } = await import("./hub/init/web.js");
1338
+ if (this.shuttingDown)
1339
+ throw Error("Fleet is stopping");
1340
+ const controller = createHubWebInitializer({ home: this.dataDir, readConfig: () => this.getRawFleetConfig(),
1341
+ writeFleet: patches => this.saveFleetConfig(patches), committed: () => this.applyHubSwitches() });
1342
+ this.hubSetupController = controller;
1343
+ return controller;
1344
+ })();
1345
+ try {
1346
+ return await this.hubSetupInit;
1347
+ }
1348
+ catch (error) {
1349
+ this.hubSetupInit = null;
1350
+ throw error;
1351
+ }
1352
+ }
1353
+ /** The member's company sign-in controller; separate from host-owned Hub initialization. */
1354
+ companyJoinController = null;
1355
+ companyJoinInit = null;
1356
+ companyObservedMembership = null;
1357
+ companyMembershipWrite = false;
1358
+ hubCompanySession(req) {
1359
+ const epoch = this.webAuthorityState().epoch, token = this.webToken, sessions = this.webSessions, generation = this.settingsGeneration;
1360
+ return companyJoinSession(req, { token, sessions, config: this.fleetConfig, epoch, current: () => !this.shuttingDown
1361
+ && generation === this.settingsGeneration && token === this.webToken && sessions === this.webSessions && epoch === this.webAuthorityState().epoch });
1362
+ }
1363
+ async hubCompanyJoin() {
1364
+ const incarnation = this.settingsGeneration;
1365
+ const initialization = this.companyJoinInit ??= (async () => {
1366
+ const { CompanyJoinController } = await import("./hub/join/local.js");
1367
+ const { currentBinding } = await import("./hub/member/pairing-api.js");
1368
+ this.hubMemberBinding = currentBinding;
1369
+ if (this.shuttingDown || incarnation !== this.settingsGeneration)
1370
+ throw Error("Fleet is stopping");
1371
+ const controller = new CompanyJoinController({ home: this.dataDir,
1372
+ snapshot: () => {
1373
+ const state = join(this.dataDir, "hub-member/state.json");
1374
+ return { membership: this.rawFleetConfig?.hub_member?.enabled === true,
1375
+ binding: existsSync(state) ? createHash("sha256").update(readFileSync(state)).digest("hex") : null };
1376
+ },
1377
+ enableMembership: (current, accept) => {
1378
+ if (!current() || !this.configPath || !this.fleetConfig)
1379
+ throw Error("Join operation changed");
1380
+ this.companyMembershipWrite = true;
1381
+ try {
1382
+ this.saveFleetConfig([{ path: ["hub_member", "enabled"], value: true }]);
1383
+ // Strict durability for the joined profile+journal, including this internally enabled switch.
1384
+ const fd = openSync(this.configPath, fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW);
1385
+ try {
1386
+ fsyncSync(fd);
1387
+ }
1388
+ finally {
1389
+ closeSync(fd);
1390
+ }
1391
+ const parent = openSync(dirname(this.configPath), fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW);
1392
+ try {
1393
+ fsyncSync(parent);
1394
+ }
1395
+ finally {
1396
+ closeSync(parent);
1397
+ }
1398
+ accept();
1399
+ }
1400
+ finally {
1401
+ this.companyMembershipWrite = false;
1402
+ }
1403
+ },
1404
+ activate: () => { void this.applyHubSwitches().then(() => this.hubRuntime?.refresh()).catch(() => { }); },
1405
+ link: () => this.hubMemberLink === "online" ? "online" : "offline", });
1406
+ this.companyJoinController = controller;
1407
+ return controller;
1408
+ })();
1409
+ try {
1410
+ return await initialization;
1411
+ }
1412
+ catch (error) {
1413
+ if (this.companyJoinInit === initialization)
1414
+ this.companyJoinInit = null;
1415
+ throw error;
1416
+ }
1417
+ }
1418
+ invalidateHubCompanyJoin() { this.companyJoinController?.invalidate(); }
1324
1419
  hubMemberPairingApi = null;
1325
1420
  hubPairingNotices = null;
1326
1421
  hubMemberPairing() { return this.hubMemberPairingApi; }
@@ -1782,6 +1877,12 @@ export class FleetManager {
1782
1877
  */
1783
1878
  /** S-51: the Hub switches follow the configuration in force (load, save, reload rollback), like the runtime ones. */
1784
1879
  observeHubSwitches() {
1880
+ const enabled = this.rawFleetConfig?.hub_member?.enabled === true;
1881
+ if (this.companyObservedMembership !== null && enabled !== this.companyObservedMembership) {
1882
+ if (!this.companyMembershipWrite)
1883
+ this.companyJoinController?.invalidate();
1884
+ }
1885
+ this.companyObservedMembership = enabled;
1785
1886
  this.observeHubAgentIncarnations();
1786
1887
  if (!this.hubEffectsReady || this.hubEffectsScheduled || this.shuttingDown)
1787
1888
  return;
@@ -1801,6 +1902,16 @@ export class FleetManager {
1801
1902
  if (this.shuttingDown || !this.hubEffectsReady)
1802
1903
  return; // Stop owns it now (fenced in stopAll, closed in doStopAll)
1803
1904
  await this.observeHubMemberPairing(raw?.hub_member?.enabled === true);
1905
+ // M-2682: an interrupted sealed-settings commit is finished (or rolled back) before the Hub mounts its pair. A refusal
1906
+ // overwrites nothing; the mount then holds on the mismatch, visibly, until the files are put right.
1907
+ if (this.hubSettingsWriter?.pending()) {
1908
+ try {
1909
+ this.hubSettingsWriter.recover();
1910
+ }
1911
+ catch (err) {
1912
+ this.logger.warn({ err: err?.message ?? String(err) }, "Hub settings recovery refused");
1913
+ }
1914
+ }
1804
1915
  const current = this.rawFleetConfig;
1805
1916
  await runtime.apply({ hub: current?.hub, hub_member: current?.hub_member });
1806
1917
  }
@@ -1808,12 +1919,22 @@ export class FleetManager {
1808
1919
  this.logger.warn({ err: err?.message ?? String(err) }, "Hub switches could not be applied");
1809
1920
  }
1810
1921
  }
1922
+ /** M-2682: the one writer for sealed Hub settings, created with the Hub runtime. */
1923
+ hubSettingsWriter = null;
1811
1924
  /** Single flight: one import, one runtime, assigned once; every caller (and Stop) gets that same runtime. */
1812
1925
  hubRuntimeCreated() {
1813
1926
  this.hubRuntimeInit ??= (async () => {
1814
1927
  const { HubRuntime } = await import("./hub/runtime.js");
1928
+ // M-2682: the one writer for sealed Hub settings (a rename from Hub Administration). It saves hub.* through this
1929
+ // fleet's own synchronous writer, so nothing else here runs between its commit point and the new pair in force.
1930
+ const { createHubSettingsWriter } = await import("./hub/settings-commit.js");
1931
+ this.hubSettingsWriter ??= createHubSettingsWriter({ home: this.dataDir,
1932
+ readHub: () => this.rawFleetConfig?.hub,
1933
+ saveHub: patches => this.saveFleetConfig(patches) });
1815
1934
  const runtime = new HubRuntime({
1816
1935
  home: this.dataDir,
1936
+ settingsWriter: this.hubSettingsWriter,
1937
+ version: agendVersion(),
1817
1938
  log: (level, message, meta) => this.logger[level](meta ?? {}, message),
1818
1939
  onHoldsChanged: holds => { this.hubHolds = holds; this.needsYou?.poke(); },
1819
1940
  // S-51 PR 2b: the fleet's side of a Hub membership (pairing binding, local agents, attachment points).
@@ -2140,6 +2261,8 @@ export class FleetManager {
2140
2261
  }
2141
2262
  hubBrowserCertificate() { return this.hubRuntime?.browserCertificateSettings() ?? null; }
2142
2263
  hubRetention() { return this.hubRuntime?.retentionSettings() ?? null; }
2264
+ /** M-2682: an unfinished sealed-settings commit; Hub setting saves wait until recover() has run. */
2265
+ hubSettingsBusy() { return this.hubSettingsWriter?.pending() === true || this.hubSetupController?.pending() === true; }
2143
2266
  /** #3298 S-89: this fleet's own Hub offers group permissions (the page mark that shows Settings → Hub's Group permissions row). */
2144
2267
  hubGroupPermissions() { return this.hubRuntime?.groupPermissionsAvailable() ?? false; }
2145
2268
  observeRuntimeSwitches() {
@@ -3166,7 +3289,7 @@ export class FleetManager {
3166
3289
  if (auth.kind !== "ok" || !current())
3167
3290
  return null;
3168
3291
  const record = auth.session, sessions = this.webSessions, exposure = gatewayRequestContext(req);
3169
- return { id: record.idHash, label: record.label, source: exposure ? "public_link" : "web_session",
3292
+ return { localSession: this.hubCompanySession(req) ?? undefined, id: record.idHash, label: record.label, source: exposure ? "public_link" : "web_session",
3170
3293
  localAdmin: () => record.tier === "admin" && record.surface === "local" && !exposure,
3171
3294
  current: () => current() && sessions === this.webSessions && !!this.webToken
3172
3295
  && sessions.isCurrent(record, tokenEpoch(this.webToken)) && (!exposure || exposure.isCurrent()) };
@@ -3174,6 +3297,7 @@ export class FleetManager {
3174
3297
  selfConfirm: (req, id) => this.settingsSelfConfirmation(store, req, id),
3175
3298
  totp: { state: (req, id) => this.settingsTotpState(store, req, id), confirm: (req, id, code, digest) => this.settingsTotpConfirm(store, req, id, code, digest) },
3176
3299
  directAgentCreation: true,
3300
+ directCompanyJoin: true,
3177
3301
  job: async (id) => {
3178
3302
  const settlement = this.settingsJobSettlements.get(id);
3179
3303
  if (!settlement)
@@ -5699,7 +5823,7 @@ export class FleetManager {
5699
5823
  }
5700
5824
  const origin = `slash /update by ${adapterId}:${data.userId}`;
5701
5825
  recordInternalRequest(this.dataDir, "update", origin);
5702
- const launch = await resolveUpdateLaunch(installed.agend);
5826
+ const launch = await resolveUpdateLaunch(installed.agend, undefined, installed.npmDir);
5703
5827
  if (!launch.ok) {
5704
5828
  this.failUpdateProgress(`${t("update.failure.shell")} ${t("update.failure.independent", launch.reason)}`);
5705
5829
  return;
@@ -8366,6 +8490,22 @@ export class FleetManager {
8366
8490
  * Stopped/paused ClassicBot entries count too; their workspace is exactly
8367
8491
  * the one startClassicInstance builds, not this FleetManager's dataDir.
8368
8492
  */
8493
+ /** Take the startup snapshot of every active decision (text cut to 200 characters); see activeDecisions. */
8494
+ snapshotActiveDecisions() {
8495
+ try {
8496
+ const decisions = this.scheduler?.db.listAllActiveDecisions() ?? [];
8497
+ this.decisionSnapshot = decisions.map(d => ({ title: d.title, content: (d.content ?? "").slice(0, 200), scope: d.scope, project_root: d.project_root, ...(d.team ? { team: d.team } : {}) }));
8498
+ if (decisions.length > 0)
8499
+ this.logger.info({ count: decisions.length }, "Active decisions snapshotted for instance instructions");
8500
+ }
8501
+ catch (err) {
8502
+ this.logger.debug({ err }, "Decision injection skipped (no decisions db or query failed)");
8503
+ }
8504
+ }
8505
+ /** The startup snapshot of active decisions, for a daemon's Active Decisions (it selects and caps its own). */
8506
+ activeDecisions() {
8507
+ return this.decisionSnapshot;
8508
+ }
8369
8509
  kiroPeerWorkingDirectories(name) {
8370
8510
  if (!this.fleetConfig || !this.classicChannels)
8371
8511
  throw new Error("Kiro peer configuration is not loaded");
@@ -10851,20 +10991,12 @@ export class FleetManager {
10851
10991
  this.logger.warn({ err }, "Failed to send daily tip");
10852
10992
  }));
10853
10993
  this.dailyTipScheduler.start();
10854
- // Inject active decisions as env var for MCP instructions.
10855
- // Snapshotted at startup — new decisions via post_decision are available
10856
- // through list_decisions tool but not auto-injected until restart.
10857
- try {
10858
- const decisions = this.scheduler.db.listAllActiveDecisions();
10859
- if (decisions.length > 0) {
10860
- const capped = decisions.slice(0, 20).map(d => ({ title: d.title, content: (d.content ?? "").slice(0, 200), scope: d.scope, project_root: d.project_root }));
10861
- process.env.AGEND_DECISIONS = JSON.stringify(capped);
10862
- this.logger.info({ count: decisions.length, injected: capped.length }, "Injected active decisions into env");
10863
- }
10864
- }
10865
- catch (err) {
10866
- this.logger.debug({ err }, "Decision injection skipped (no decisions db or query failed)");
10867
- }
10994
+ // Active decisions for each instance's instructions, snapshotted at startup — new decisions via post_decision are
10995
+ // available through list_decisions but not auto-injected until restart. The whole active set is kept here (each
10996
+ // entry's text cut to 200 characters) and handed to each daemon at spawn (activeDecisions): the daemon selects
10997
+ // its own — fleet, its teams, its directory — and only then applies its caps, so other teams' or directories'
10998
+ // rows can never crowd an instance's own out (#3421 review). Nothing unbounded goes into process.env.
10999
+ this.snapshotActiveDecisions();
10868
11000
  }
10869
11001
  // Phase 1: Start general instances first and wait for them
10870
11002
  // M-2457: a held fleet starts no agent (the hold's Needs-you line says why and what to do).
@@ -14439,6 +14571,11 @@ export class FleetManager {
14439
14571
  let result;
14440
14572
  switch (msg.type) {
14441
14573
  case "fleet_decision_create": {
14574
+ const scoped = this.decisionScopeFor(instanceName, payload.scope, payload.team);
14575
+ if ("error" in scoped) {
14576
+ ipc.send({ type: "fleet_decision_response", fleetRequestId, error: scoped.error });
14577
+ return;
14578
+ }
14442
14579
  const supersedes = this.decisionSupersedes("ipc-typed", instanceName, payload.supersedes);
14443
14580
  if ("error" in supersedes) {
14444
14581
  ipc.send({ type: "fleet_decision_response", fleetRequestId, error: supersedes.error });
@@ -14448,7 +14585,9 @@ export class FleetManager {
14448
14585
  db.pruneExpiredDecisions();
14449
14586
  result = db.createDecision({
14450
14587
  project_root: projectRoot,
14451
- scope: payload.scope,
14588
+ scope: scoped.scope,
14589
+ team: scoped.team,
14590
+ poster_teams: scoped.teams,
14452
14591
  title: payload.title,
14453
14592
  content: payload.content,
14454
14593
  tags: payload.tags,
@@ -14464,10 +14603,16 @@ export class FleetManager {
14464
14603
  result = decisionListAnswer(db.listDecisions(projectRoot, {
14465
14604
  includeArchived: payload.include_archived,
14466
14605
  tags: payload.tags,
14606
+ teams: instanceTeams(this.fleetConfig?.teams, instanceName),
14467
14607
  }), { id: payload.id, full: payload.full });
14468
14608
  break;
14469
14609
  case "fleet_decision_update": {
14470
14610
  const id = payload.id;
14611
+ const hidden = this.decisionHiddenFrom(instanceName, id);
14612
+ if (hidden) {
14613
+ ipc.send({ type: "fleet_decision_response", fleetRequestId, error: hidden });
14614
+ return;
14615
+ }
14471
14616
  if (payload.archive) {
14472
14617
  db.archiveDecision(id);
14473
14618
  result = { archived: true, id };
@@ -14646,6 +14791,47 @@ export class FleetManager {
14646
14791
  return { error: `Superseding a decision needs update_decision. ${permitted.message}` };
14647
14792
  return { id: value };
14648
14793
  }
14794
+ /**
14795
+ * The scope (and team) a new decision gets. Team membership is read from fleet.yaml now. Omitted scope: the poster's
14796
+ * team when they are in exactly one, project (this exact directory) when they are in none; in several, they choose.
14797
+ * A team decision goes only to a team the poster is in.
14798
+ */
14799
+ decisionScopeFor(instance, scope, team) {
14800
+ const teams = instanceTeams(this.fleetConfig?.teams, instance);
14801
+ const named = typeof team === "string" && team.trim() ? team.trim() : undefined;
14802
+ if (scope !== undefined && scope !== null && scope !== "project" && scope !== "team" && scope !== "fleet") {
14803
+ return { error: `scope must be "project", "team" or "fleet"` };
14804
+ }
14805
+ if (scope === "project" || scope === "fleet") {
14806
+ return named ? { error: `team goes with scope "team", not "${scope}"` } : { scope, teams };
14807
+ }
14808
+ if (named) {
14809
+ if (!teams.includes(named)) {
14810
+ return { error: teams.length ? `You are not in team "${named}". Your teams: ${teams.join(", ")}` : `You are not in team "${named}" (you are in no team)` };
14811
+ }
14812
+ return { scope: "team", team: named, teams };
14813
+ }
14814
+ if (teams.length === 1)
14815
+ return { scope: "team", team: teams[0], teams };
14816
+ if (teams.length > 1)
14817
+ return { error: `You are in several teams (${teams.join(", ")}): name one with team, or use scope "project" or "fleet"` };
14818
+ if (scope === "team")
14819
+ return { error: `You are in no team: use scope "project" (this directory) or "fleet"` };
14820
+ return { scope: "project", teams };
14821
+ }
14822
+ /**
14823
+ * #3421 review: a team decision is only for its team's current members — reading it back through an update (even an
14824
+ * empty one) or archiving it is refused to anyone else, exactly as list/get and supersede are. The refusal names it
14825
+ * "not found", as for an id that does not exist, and changes nothing. Project and fleet decisions: as before.
14826
+ */
14827
+ decisionHiddenFrom(instance, id) {
14828
+ if (typeof id !== "string" || !this.scheduler)
14829
+ return null;
14830
+ const d = this.scheduler.db.getDecision(id);
14831
+ if (!d || d.scope !== "team")
14832
+ return null;
14833
+ return d.team && instanceTeams(this.fleetConfig?.teams, instance).includes(d.team) ? null : `Decision "${id}" not found`;
14834
+ }
14649
14835
  async handleDecisionCrudHttp(instance, op, args) {
14650
14836
  if (!this.scheduler)
14651
14837
  return { error: "Scheduler not available" };
@@ -14660,14 +14846,18 @@ export class FleetManager {
14660
14846
  const content = asStr(args.content);
14661
14847
  if (!title || !content)
14662
14848
  return { error: "title and content are required" };
14663
- const scope = args.scope === "fleet" ? "fleet" : "project";
14849
+ const scoped = this.decisionScopeFor(instance, args.scope, args.team);
14850
+ if ("error" in scoped)
14851
+ return { error: scoped.error };
14664
14852
  const supersedes = this.decisionSupersedes("agent-endpoint", instance, args.supersedes);
14665
14853
  if ("error" in supersedes)
14666
14854
  return { error: supersedes.error };
14667
14855
  try {
14668
14856
  return db.createDecision({
14669
14857
  project_root: projectRoot,
14670
- scope,
14858
+ scope: scoped.scope,
14859
+ team: scoped.team,
14860
+ poster_teams: scoped.teams,
14671
14861
  title,
14672
14862
  content,
14673
14863
  tags: asStrArr(args.tags),
@@ -14689,11 +14879,15 @@ export class FleetManager {
14689
14879
  return decisionListAnswer(db.listDecisions(projectRoot, {
14690
14880
  includeArchived: args.includeArchived === true || args.include_archived === true,
14691
14881
  tags: asStrArr(args.tags),
14882
+ teams: instanceTeams(this.fleetConfig?.teams, instance),
14692
14883
  }), { id: op === "get" ? asStr(args.id) ?? "" : args.id, full: args.full });
14693
14884
  case "update": {
14694
14885
  const id = asStr(args.id);
14695
14886
  if (!id)
14696
14887
  return { error: "id is required" };
14888
+ const hidden = this.decisionHiddenFrom(instance, id);
14889
+ if (hidden)
14890
+ return { error: hidden };
14697
14891
  return db.updateDecision(id, {
14698
14892
  content: asStr(args.content),
14699
14893
  tags: asStrArr(args.tags),
@@ -15338,6 +15532,9 @@ export class FleetManager {
15338
15532
  * non-identity instance leaves are canonicalized to inheritance afterward.
15339
15533
  */
15340
15534
  saveFleetConfig(explicitPatches = []) {
15535
+ if (!this.companyMembershipWrite && explicitPatches.some(p => p.path[0] === "hub_member"
15536
+ && (p.path[1] === "enabled" ? p.value !== true || p.remove : p.path.length === 1)))
15537
+ this.invalidateHubCompanyJoin();
15341
15538
  this.publicWebLink?.refresh();
15342
15539
  this.enforceGuestSwitch(); // #1920: a Settings save turning guests off ends their sessions
15343
15540
  this.observeWebAuthority(); // #2453 review: so is a web-authority switch (off is always seen)
@@ -20815,6 +21012,51 @@ export class FleetManager {
20815
21012
  },
20816
21013
  });
20817
21014
  }
21015
+ profileSignInsInstance = null;
21016
+ /**
21017
+ * #3212: a NAMED account's sign-in on this host from Settings → Accounts — #2599's StructuredSignIn (press Sign in, open the page, paste the code), pointed at
21018
+ * that profile's own folder (`CLAUDE_CONFIG_DIR`), under the host's login window like every other credential writer. Not the default account's checklist.
21019
+ */
21020
+ get profileSignIns() {
21021
+ return this.profileSignInsInstance ??= new ProfileSignIns({
21022
+ lock: this.loginWindow,
21023
+ current: owner => this.browserSignInOwnerCurrent(owner),
21024
+ installed: backend => this.isCliInstalledOffLoop(backend),
21025
+ known: (backend, profile) => accountFolderExists(this.dataDir, backend, profile) ? "exists" : this.configuredProfileNames(backend).has(profile) ? "configured" : "unknown",
21026
+ add: (backend, profile) => {
21027
+ const result = addAccountProfile(this.dataDir, backend, profile, this.configuredProfileNames(backend));
21028
+ if (result.ok)
21029
+ this.logger.info({ backend, profile }, "Credential profile added by the first sign-in of an account the configuration names");
21030
+ return result.ok;
21031
+ },
21032
+ checkAuth: (backend, profile) => {
21033
+ const env = credentialProfileEnv(this.dataDir, backend, profile);
21034
+ return env ? checkAuthStatus(LOGIN_FLOWS[backend].authCheck, env) : Promise.resolve("unknown");
21035
+ },
21036
+ transport: target => createStructuredSignInTransport({ backend: target.backend, dataDir: this.dataDir }),
21037
+ changed: (event, owner, launched) => {
21038
+ try {
21039
+ this.eventLog?.insert("login", "browser_profile_signin", event);
21040
+ }
21041
+ catch { /* safe metadata only */ }
21042
+ broadcastSseEvent(this.sseClients, "backend_login", {}, err => this.logger.debug({ err }, "backend_login event failed"));
21043
+ if (event.phase === "done") {
21044
+ this.forgetSignInIdentities(); // a sign-in may be a different account now
21045
+ this.keepAliveAfterSignIn(event.backend, event.profile);
21046
+ }
21047
+ this.needsYou?.poke();
21048
+ if (!this.browserSignInOwnerCurrent(owner))
21049
+ return;
21050
+ if (event.phase === "starting") {
21051
+ const record = owner;
21052
+ this.notifyFleetError(t("login.web_dashboard_notice", t("login.profile_label", event.backend, event.profile), record.label, record.handle.slice(0, 8)));
21053
+ }
21054
+ // A live CLI holds the old token in memory: the agents on THIS account (and no other) wake or restart, as after the other sign-in flows.
21055
+ if (event.phase === "done" && launched)
21056
+ void this.recoverBackendInstances(event.backend, undefined, event.profile).catch(() => this.logger.warn({ backend: event.backend, profile: event.profile }, "Post sign-in recovery failed"));
21057
+ },
21058
+ });
21059
+ }
20818
21060
  needsYouBackendSignIns() {
20819
21061
  const pending = readPendingBackendSignIns(this.dataDir).pending;
20820
21062
  for (const backend of this.pendingBackendSince?.keys() ?? [])
@@ -21164,7 +21406,7 @@ export class FleetManager {
21164
21406
  if (cli === backend && same(profileName(classicProfile(b.backend_options, defaults?.backend_options, cli))))
21165
21407
  return true;
21166
21408
  }
21167
- return this.loginController?.signingIn(backend, profile) ?? false;
21409
+ return (this.loginController?.signingIn(backend, profile) ?? false) || (profile !== null && (this.profileSignInsInstance?.signingIn(backend, profile) ?? false)); // #3212: the dashboard's structured sign-in of a named account counts too
21168
21410
  }
21169
21411
  /**
21170
21412
  * #3292 review: one keep-alive run's admission, decided synchronously: not in use, the shared login window taken, and the
@@ -21242,6 +21484,13 @@ export class FleetManager {
21242
21484
  // #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.
21243
21485
  if (machine)
21244
21486
  return this.machineAccounts.add(backend, name, machine.id, by);
21487
+ const result = addAccountProfile(this.dataDir, backend, name, this.configuredProfileNames(backend));
21488
+ if (result.ok)
21489
+ this.logger.info({ backend, profile: name, by }, "Credential profile added from Settings → Accounts");
21490
+ return result;
21491
+ }
21492
+ /** The profile names the configuration refers to for this backend — an agent, a ClassicBot room, the fleet default — whether or not their folders exist yet. */
21493
+ configuredProfileNames(backend) {
21245
21494
  const { agents, classic, fleetDefaults } = this.accountUses();
21246
21495
  const configured = new Set();
21247
21496
  for (const x of [...agents, ...classic])
@@ -21250,10 +21499,7 @@ export class FleetManager {
21250
21499
  const fd = fleetDefaults.get(backend);
21251
21500
  if (fd)
21252
21501
  configured.add(fd);
21253
- const result = addAccountProfile(this.dataDir, backend, name, configured);
21254
- if (result.ok)
21255
- this.logger.info({ backend, profile: name, by }, "Credential profile added from Settings → Accounts");
21256
- return result;
21502
+ return configured;
21257
21503
  }
21258
21504
  /**
21259
21505
  * #3212 PR 2: Settings → Accounts → Remove. Refused while anything uses it or a sign-in for it runs (the login controller,
@@ -21267,8 +21513,12 @@ export class FleetManager {
21267
21513
  const shown = validCredentialProfileName(name) ? name : "(invalid)";
21268
21514
  // #3321 review ("Cancel sign-in and remove"): the sign-in of exactly this account is ended first — no other account's, and a start whose profile is
21269
21515
  // not known yet is not guessed at — and every Remove check below is then made as usual: what is still signing in refuses (`signing_in`).
21270
- if (opts?.cancelSignIn && validCredentialProfileName(name) && await this.loginController?.cancelAccount(backend, name).catch(() => false)) {
21271
- this.logger.info({ backend, profile: shown, by }, "Sign-in cancelled for Remove");
21516
+ if (opts?.cancelSignIn && validCredentialProfileName(name)) {
21517
+ // The account's sign-in is either the dashboard's structured one (ProfileSignIns) or the chat/terminal one (the login controller); at most one runs on the host.
21518
+ const ended = (await this.profileSignInsInstance?.cancelAccount(backend, name).catch(() => false))
21519
+ || (await this.loginController?.cancelAccount(backend, name).catch(() => false));
21520
+ if (ended)
21521
+ this.logger.info({ backend, profile: shown, by }, "Sign-in cancelled for Remove");
21272
21522
  }
21273
21523
  const refused = (r) => { if (!r.ok)
21274
21524
  this.logger.info({ backend, profile: shown, by, refused: r.error }, "Credential profile removal refused"); return r; };
@@ -21356,8 +21606,8 @@ export class FleetManager {
21356
21606
  fleetDefault: same(fleetDefaults.get(backend)),
21357
21607
  };
21358
21608
  const held = this.loginWindow.current;
21359
- const signingIn = (this.loginController?.signingIn(backend, profile) ?? false)
21360
- || (!!held && held !== ownClaim && held.backend === backend && !this.loginController?.activeBackend);
21609
+ const signingIn = (this.loginController?.signingIn(backend, profile) ?? false) || (this.profileSignInsInstance?.signingIn(backend, profile) ?? false)
21610
+ || (!!held && held !== ownClaim && held.backend === backend && !this.loginController?.activeBackend && !this.profileSignInsInstance?.active); // a named account's sign-in holds the window too, and says WHICH account (above)
21361
21611
  return { backend, name, confirm, users, signingIn, usersUnknown: rooms.kind === "unknown" };
21362
21612
  }
21363
21613
  /**
@@ -21413,7 +21663,7 @@ export class FleetManager {
21413
21663
  const shown = named === null ? "(default)" : validCredentialProfileName(named) ? named : "(invalid)";
21414
21664
  // #3305 review P2-3: the logout holds the shared login window from before it runs until its cleanup is done — no
21415
21665
  // sign-in (chat, dashboard, install) and no other logout starts meanwhile; one already running refuses this.
21416
- const signingIn = this.loginController?.signingIn(backend, named) ?? false;
21666
+ const signingIn = (this.loginController?.signingIn(backend, named) ?? false) || (named !== null && (this.profileSignInsInstance?.signingIn(backend, named) ?? false));
21417
21667
  const claim = signingIn ? null : this.loginWindow.tryClaim("web", backend);
21418
21668
  let result;
21419
21669
  if (!claim)
@@ -21803,6 +22053,15 @@ export class FleetManager {
21803
22053
  else
21804
22054
  this.logger.error("A computer's account sign-in could not be confirmed ended; check that computer's Runtime window.");
21805
22055
  }), "machine-signins"),
22056
+ // #3212: a named account's sign-in on this host is ended too; one that could not be shown gone keeps sign-in admission closed, as the default account's.
22057
+ bounded(this.profileSignInsInstance?.close().then(confirmed => {
22058
+ if (confirmed)
22059
+ this.profileSignInsInstance = null;
22060
+ else {
22061
+ this.structuredLoginCleanupFailed = true;
22062
+ this.logger.error("A named account's structured login cleanup failed; sign-in admission remains closed until the host is restarted.");
22063
+ }
22064
+ }), "profile-signins"),
21806
22065
  bounded(this.loginController?.shutdown(), "web-login"),
21807
22066
  bounded(this.activeInstall?.session.cancel("cancelled"), "install"),
21808
22067
  // #3305 review P2-3: an account logout in flight (its CLI) — the closed window fences its cleanup; this waits for it.
@@ -21828,6 +22087,10 @@ export class FleetManager {
21828
22087
  this.browserBackendSignInsInstance = null;
21829
22088
  return confirmed ? t("login.cancelled", browserBackend) : t("login.browser_cleanup_failed");
21830
22089
  }
22090
+ // #3212: a named account's sign-in on this host ("Cancel sign-in and remove" and `/login cancel` end it as they end the others).
22091
+ const ended = await this.profileSignInsInstance?.cancelActive();
22092
+ if (ended)
22093
+ return ended.confirmed ? t("login.cancelled", t("login.profile_label", ended.target.backend, ended.target.profile)) : t("login.browser_cleanup_failed");
21831
22094
  if (this.loginController?.isActive())
21832
22095
  return this.loginController.cancel();
21833
22096
  return t("login.no_session");
@@ -25537,6 +25800,16 @@ export class FleetManager {
25537
25800
  clearInterval(this.updateProgressTimer);
25538
25801
  this.updateProgressTimer = null;
25539
25802
  }
25803
+ // close() fences setup synchronously; its physical drain joins the asynchronous phase below.
25804
+ // Awaiting even an absent controller here would yield before the remaining shutdown fences.
25805
+ const setupClosed = this.hubSetupController?.close().catch(() => {
25806
+ this.logger.warn("Hub setup scratch cleanup is unconfirmed; setup remains fenced");
25807
+ });
25808
+ this.hubSetupController = null;
25809
+ this.hubSetupInit = null;
25810
+ this.companyJoinController?.close();
25811
+ this.companyJoinController = null;
25812
+ this.companyJoinInit = null;
25540
25813
  this.settingsGeneration++;
25541
25814
  this.settingsConfirmation?.store.close();
25542
25815
  this.settingsConfirmation = null;
@@ -25601,6 +25874,7 @@ export class FleetManager {
25601
25874
  // timer and HTTP listener living in THIS process: without an explicit
25602
25875
  // shutdown it would outlive us as an owner-less login CLI (sol B3).
25603
25876
  await inboundStopped;
25877
+ await setupClosed;
25604
25878
  await publicStopped;
25605
25879
  await sharesStopped?.catch(() => { });
25606
25880
  await profileStopped;