@cotal-ai/cli 0.182.0 → 0.183.0

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 (299) hide show
  1. package/dist/command.d.ts.map +1 -1
  2. package/dist/command.js +347 -179
  3. package/dist/command.js.map +1 -1
  4. package/dist/commands/agents.d.ts.map +1 -1
  5. package/dist/commands/agents.js +70 -14
  6. package/dist/commands/agents.js.map +1 -1
  7. package/dist/commands/app-identity.d.ts +1 -0
  8. package/dist/commands/app-identity.d.ts.map +1 -1
  9. package/dist/commands/app-identity.js +1 -1
  10. package/dist/commands/app-identity.js.map +1 -1
  11. package/dist/commands/backup-maintenance.d.ts.map +1 -1
  12. package/dist/commands/backup-maintenance.js +9 -7
  13. package/dist/commands/backup-maintenance.js.map +1 -1
  14. package/dist/commands/backup.d.ts.map +1 -1
  15. package/dist/commands/backup.js +51 -23
  16. package/dist/commands/backup.js.map +1 -1
  17. package/dist/commands/clean.d.ts.map +1 -1
  18. package/dist/commands/clean.js +8 -2
  19. package/dist/commands/clean.js.map +1 -1
  20. package/dist/commands/down.d.ts.map +1 -1
  21. package/dist/commands/down.js +12 -3
  22. package/dist/commands/down.js.map +1 -1
  23. package/dist/commands/ext.d.ts +4 -2
  24. package/dist/commands/ext.d.ts.map +1 -1
  25. package/dist/commands/ext.js +62 -15
  26. package/dist/commands/ext.js.map +1 -1
  27. package/dist/commands/help.js +1 -1
  28. package/dist/commands/help.js.map +1 -1
  29. package/dist/commands/history.d.ts.map +1 -1
  30. package/dist/commands/history.js +5 -1
  31. package/dist/commands/history.js.map +1 -1
  32. package/dist/commands/join.js +1 -1
  33. package/dist/commands/join.js.map +1 -1
  34. package/dist/commands/meshes.d.ts.map +1 -1
  35. package/dist/commands/meshes.js +2 -1
  36. package/dist/commands/meshes.js.map +1 -1
  37. package/dist/commands/mint.js +27 -26
  38. package/dist/commands/mint.js.map +1 -1
  39. package/dist/commands/persona.d.ts +2 -2
  40. package/dist/commands/persona.d.ts.map +1 -1
  41. package/dist/commands/persona.js +4 -3
  42. package/dist/commands/persona.js.map +1 -1
  43. package/dist/commands/send.d.ts.map +1 -1
  44. package/dist/commands/send.js +9 -7
  45. package/dist/commands/send.js.map +1 -1
  46. package/dist/commands/service-registry.d.ts +1 -1
  47. package/dist/commands/service-registry.js +1 -1
  48. package/dist/commands/service-registry.js.map +1 -1
  49. package/dist/commands/setup-current-connectors.d.ts +7 -0
  50. package/dist/commands/setup-current-connectors.d.ts.map +1 -0
  51. package/dist/commands/setup-current-connectors.js +31 -0
  52. package/dist/commands/setup-current-connectors.js.map +1 -0
  53. package/dist/commands/setup.d.ts +1 -0
  54. package/dist/commands/setup.d.ts.map +1 -1
  55. package/dist/commands/setup.js +43 -14
  56. package/dist/commands/setup.js.map +1 -1
  57. package/dist/commands/space-registration.d.ts.map +1 -1
  58. package/dist/commands/space-registration.js +6 -1
  59. package/dist/commands/space-registration.js.map +1 -1
  60. package/dist/commands/spawn-flags.d.ts +1 -1
  61. package/dist/commands/spawn-flags.d.ts.map +1 -1
  62. package/dist/commands/spawn-flags.js +11 -3
  63. package/dist/commands/spawn-flags.js.map +1 -1
  64. package/dist/commands/spawn-managed-launch.d.ts.map +1 -1
  65. package/dist/commands/spawn-managed-launch.js +3 -2
  66. package/dist/commands/spawn-managed-launch.js.map +1 -1
  67. package/dist/commands/spawn-preview.d.ts.map +1 -1
  68. package/dist/commands/spawn-preview.js +21 -4
  69. package/dist/commands/spawn-preview.js.map +1 -1
  70. package/dist/commands/spawn.d.ts +2 -15
  71. package/dist/commands/spawn.d.ts.map +1 -1
  72. package/dist/commands/spawn.js +117 -120
  73. package/dist/commands/spawn.js.map +1 -1
  74. package/dist/commands/stack-down.d.ts.map +1 -1
  75. package/dist/commands/stack-down.js +24 -12
  76. package/dist/commands/stack-down.js.map +1 -1
  77. package/dist/commands/stack-lost-records.d.ts +12 -0
  78. package/dist/commands/stack-lost-records.d.ts.map +1 -1
  79. package/dist/commands/stack-lost-records.js +31 -10
  80. package/dist/commands/stack-lost-records.js.map +1 -1
  81. package/dist/commands/stack-up.d.ts +1 -1
  82. package/dist/commands/stack-up.d.ts.map +1 -1
  83. package/dist/commands/stack-up.js +22 -10
  84. package/dist/commands/stack-up.js.map +1 -1
  85. package/dist/commands/stack-user-auth.d.ts +2 -2
  86. package/dist/commands/stack-user-auth.d.ts.map +1 -1
  87. package/dist/commands/stack-user-auth.js +6 -3
  88. package/dist/commands/stack-user-auth.js.map +1 -1
  89. package/dist/commands/status-health.d.ts +4 -1
  90. package/dist/commands/status-health.d.ts.map +1 -1
  91. package/dist/commands/status-health.js +4 -1
  92. package/dist/commands/status-health.js.map +1 -1
  93. package/dist/commands/status-meshes.d.ts +4 -1
  94. package/dist/commands/status-meshes.d.ts.map +1 -1
  95. package/dist/commands/status-meshes.js +8 -3
  96. package/dist/commands/status-meshes.js.map +1 -1
  97. package/dist/commands/status.d.ts.map +1 -1
  98. package/dist/commands/status.js +16 -11
  99. package/dist/commands/status.js.map +1 -1
  100. package/dist/commands/sync.d.ts.map +1 -1
  101. package/dist/commands/sync.js +2 -2
  102. package/dist/commands/sync.js.map +1 -1
  103. package/dist/commands/team-boot-controller.d.ts.map +1 -1
  104. package/dist/commands/team-boot-controller.js +2 -1
  105. package/dist/commands/team-boot-controller.js.map +1 -1
  106. package/dist/commands/team.js +6 -6
  107. package/dist/commands/team.js.map +1 -1
  108. package/dist/commands/topology.d.ts.map +1 -1
  109. package/dist/commands/topology.js +3 -2
  110. package/dist/commands/topology.js.map +1 -1
  111. package/dist/commands/trust.d.ts +27 -0
  112. package/dist/commands/trust.d.ts.map +1 -0
  113. package/dist/commands/trust.js +39 -0
  114. package/dist/commands/trust.js.map +1 -0
  115. package/dist/commands/up-detach.d.ts.map +1 -1
  116. package/dist/commands/up-detach.js +5 -1
  117. package/dist/commands/up-detach.js.map +1 -1
  118. package/dist/commands/up-foreground-listener.d.ts +20 -0
  119. package/dist/commands/up-foreground-listener.d.ts.map +1 -0
  120. package/dist/commands/up-foreground-listener.js +156 -0
  121. package/dist/commands/up-foreground-listener.js.map +1 -0
  122. package/dist/commands/up-manifest.d.ts.map +1 -1
  123. package/dist/commands/up-manifest.js +4 -5
  124. package/dist/commands/up-manifest.js.map +1 -1
  125. package/dist/commands/up-project-trust.d.ts +8 -0
  126. package/dist/commands/up-project-trust.d.ts.map +1 -0
  127. package/dist/commands/up-project-trust.js +35 -0
  128. package/dist/commands/up-project-trust.js.map +1 -0
  129. package/dist/commands/up-resume.d.ts +1 -1
  130. package/dist/commands/up-resume.d.ts.map +1 -1
  131. package/dist/commands/up-resume.js +12 -5
  132. package/dist/commands/up-resume.js.map +1 -1
  133. package/dist/commands/up.d.ts.map +1 -1
  134. package/dist/commands/up.js +30 -150
  135. package/dist/commands/up.js.map +1 -1
  136. package/dist/commands/update-continuity.d.ts +4 -0
  137. package/dist/commands/update-continuity.d.ts.map +1 -1
  138. package/dist/commands/update-continuity.js +54 -1
  139. package/dist/commands/update-continuity.js.map +1 -1
  140. package/dist/commands/update-offline.d.ts +4 -0
  141. package/dist/commands/update-offline.d.ts.map +1 -0
  142. package/dist/commands/update-offline.js +39 -0
  143. package/dist/commands/update-offline.js.map +1 -0
  144. package/dist/commands/update-process.d.ts.map +1 -1
  145. package/dist/commands/update-process.js +11 -8
  146. package/dist/commands/update-process.js.map +1 -1
  147. package/dist/commands/update.d.ts.map +1 -1
  148. package/dist/commands/update.js +24 -67
  149. package/dist/commands/update.js.map +1 -1
  150. package/dist/console/app.d.ts.map +1 -1
  151. package/dist/console/app.js +2 -1
  152. package/dist/console/app.js.map +1 -1
  153. package/dist/console/mesh.d.ts +1 -1
  154. package/dist/console/mesh.d.ts.map +1 -1
  155. package/dist/console/mesh.js +1 -1
  156. package/dist/console/mesh.js.map +1 -1
  157. package/dist/console/ui/CommandPalette.d.ts +2 -1
  158. package/dist/console/ui/CommandPalette.d.ts.map +1 -1
  159. package/dist/console/ui/CommandPalette.js +4 -4
  160. package/dist/console/ui/CommandPalette.js.map +1 -1
  161. package/dist/help.d.ts +1 -6
  162. package/dist/help.d.ts.map +1 -1
  163. package/dist/help.js +26 -4
  164. package/dist/help.js.map +1 -1
  165. package/dist/index.d.ts.map +1 -1
  166. package/dist/index.js +20 -4
  167. package/dist/index.js.map +1 -1
  168. package/dist/lib/app-user-identity.d.ts +10 -13
  169. package/dist/lib/app-user-identity.d.ts.map +1 -1
  170. package/dist/lib/app-user-identity.js +237 -59
  171. package/dist/lib/app-user-identity.js.map +1 -1
  172. package/dist/lib/choose-target.d.ts.map +1 -1
  173. package/dist/lib/choose-target.js +1 -0
  174. package/dist/lib/choose-target.js.map +1 -1
  175. package/dist/lib/command-path.d.ts +6 -0
  176. package/dist/lib/command-path.d.ts.map +1 -1
  177. package/dist/lib/command-path.js +3 -0
  178. package/dist/lib/command-path.js.map +1 -1
  179. package/dist/lib/completion-scripts.d.ts.map +1 -1
  180. package/dist/lib/completion-scripts.js +1 -1
  181. package/dist/lib/completion-scripts.js.map +1 -1
  182. package/dist/lib/conversation-identity.d.ts +2 -1
  183. package/dist/lib/conversation-identity.d.ts.map +1 -1
  184. package/dist/lib/conversation-identity.js +1 -1
  185. package/dist/lib/conversation-identity.js.map +1 -1
  186. package/dist/lib/conversation-resume.d.ts +30 -0
  187. package/dist/lib/conversation-resume.d.ts.map +1 -0
  188. package/dist/lib/conversation-resume.js +73 -0
  189. package/dist/lib/conversation-resume.js.map +1 -0
  190. package/dist/lib/endpoint-errors.d.ts.map +1 -1
  191. package/dist/lib/endpoint-errors.js +17 -2
  192. package/dist/lib/endpoint-errors.js.map +1 -1
  193. package/dist/lib/extension-core-peer.d.ts +2 -0
  194. package/dist/lib/extension-core-peer.d.ts.map +1 -0
  195. package/dist/lib/extension-core-peer.js +23 -0
  196. package/dist/lib/extension-core-peer.js.map +1 -0
  197. package/dist/lib/extension-stage.d.ts +1 -1
  198. package/dist/lib/extension-stage.d.ts.map +1 -1
  199. package/dist/lib/extension-stage.js +20 -8
  200. package/dist/lib/extension-stage.js.map +1 -1
  201. package/dist/lib/foreground-hold.d.ts +2 -2
  202. package/dist/lib/foreground-hold.d.ts.map +1 -1
  203. package/dist/lib/foreground-hold.js +31 -9
  204. package/dist/lib/foreground-hold.js.map +1 -1
  205. package/dist/lib/hermes-windows-host.d.ts +8 -0
  206. package/dist/lib/hermes-windows-host.d.ts.map +1 -0
  207. package/dist/lib/hermes-windows-host.js +85 -0
  208. package/dist/lib/hermes-windows-host.js.map +1 -0
  209. package/dist/lib/hermes-windows-preload.d.ts +2 -0
  210. package/dist/lib/hermes-windows-preload.d.ts.map +1 -0
  211. package/dist/lib/hermes-windows-preload.js +7 -0
  212. package/dist/lib/hermes-windows-preload.js.map +1 -0
  213. package/dist/lib/history-command.d.ts +2 -1
  214. package/dist/lib/history-command.d.ts.map +1 -1
  215. package/dist/lib/history-command.js +4 -2
  216. package/dist/lib/history-command.js.map +1 -1
  217. package/dist/lib/isolated-broker.d.ts.map +1 -1
  218. package/dist/lib/isolated-broker.js +80 -31
  219. package/dist/lib/isolated-broker.js.map +1 -1
  220. package/dist/lib/leading-flags.d.ts +1 -0
  221. package/dist/lib/leading-flags.d.ts.map +1 -1
  222. package/dist/lib/leading-flags.js +13 -2
  223. package/dist/lib/leading-flags.js.map +1 -1
  224. package/dist/lib/manifest/index.d.ts +1 -1
  225. package/dist/lib/manifest/index.d.ts.map +1 -1
  226. package/dist/lib/manifest/index.js +3 -3
  227. package/dist/lib/manifest/index.js.map +1 -1
  228. package/dist/lib/manifest/preflight.d.ts +1 -1
  229. package/dist/lib/manifest/preflight.d.ts.map +1 -1
  230. package/dist/lib/manifest/preflight.js +14 -4
  231. package/dist/lib/manifest/preflight.js.map +1 -1
  232. package/dist/lib/npm-invocation.d.ts +13 -9
  233. package/dist/lib/npm-invocation.d.ts.map +1 -1
  234. package/dist/lib/npm-invocation.js +66 -17
  235. package/dist/lib/npm-invocation.js.map +1 -1
  236. package/dist/lib/paths.d.ts +1 -1
  237. package/dist/lib/paths.d.ts.map +1 -1
  238. package/dist/lib/paths.js +3 -3
  239. package/dist/lib/paths.js.map +1 -1
  240. package/dist/lib/persona-files.d.ts.map +1 -1
  241. package/dist/lib/persona-files.js +17 -1
  242. package/dist/lib/persona-files.js.map +1 -1
  243. package/dist/lib/personas.d.ts +3 -4
  244. package/dist/lib/personas.d.ts.map +1 -1
  245. package/dist/lib/personas.js +6 -5
  246. package/dist/lib/personas.js.map +1 -1
  247. package/dist/lib/restore.d.ts +6 -2
  248. package/dist/lib/restore.d.ts.map +1 -1
  249. package/dist/lib/restore.js +29 -15
  250. package/dist/lib/restore.js.map +1 -1
  251. package/dist/lib/self-exec.d.ts +4 -2
  252. package/dist/lib/self-exec.d.ts.map +1 -1
  253. package/dist/lib/self-exec.js +9 -4
  254. package/dist/lib/self-exec.js.map +1 -1
  255. package/dist/lib/service-process.d.ts.map +1 -1
  256. package/dist/lib/service-process.js +12 -3
  257. package/dist/lib/service-process.js.map +1 -1
  258. package/dist/lib/service-start-options.d.ts +1 -0
  259. package/dist/lib/service-start-options.d.ts.map +1 -1
  260. package/dist/lib/service-start-options.js +3 -0
  261. package/dist/lib/service-start-options.js.map +1 -1
  262. package/dist/lib/stack-journal.d.ts +2 -2
  263. package/dist/lib/stack-journal.d.ts.map +1 -1
  264. package/dist/lib/stack-journal.js +22 -8
  265. package/dist/lib/stack-journal.js.map +1 -1
  266. package/dist/lib/stdout-owner.d.ts +5 -0
  267. package/dist/lib/stdout-owner.d.ts.map +1 -1
  268. package/dist/lib/stdout-owner.js +33 -1
  269. package/dist/lib/stdout-owner.js.map +1 -1
  270. package/dist/lib/team-deploy-inspection.js +1 -1
  271. package/dist/lib/team-deploy-inspection.js.map +1 -1
  272. package/dist/lib/update-connector-config.d.ts +4 -1
  273. package/dist/lib/update-connector-config.d.ts.map +1 -1
  274. package/dist/lib/update-connector-config.js +32 -4
  275. package/dist/lib/update-connector-config.js.map +1 -1
  276. package/dist/lib/update-manager-install-linux.d.ts +8 -0
  277. package/dist/lib/update-manager-install-linux.d.ts.map +1 -0
  278. package/dist/lib/update-manager-install-linux.js +128 -0
  279. package/dist/lib/update-manager-install-linux.js.map +1 -0
  280. package/dist/lib/update-managers.d.ts.map +1 -1
  281. package/dist/lib/update-managers.js +2 -1
  282. package/dist/lib/update-managers.js.map +1 -1
  283. package/dist/lib/update-pending.d.ts +1 -1
  284. package/dist/lib/update-pending.d.ts.map +1 -1
  285. package/dist/lib/update-pending.js +1 -1
  286. package/dist/lib/update-pending.js.map +1 -1
  287. package/dist/lib/version.js +3 -3
  288. package/dist/lib/version.js.map +1 -1
  289. package/dist/seed/reconcile.js +1 -1
  290. package/dist/seed/reconcile.js.map +1 -1
  291. package/dist/seed/store.d.ts +3 -7
  292. package/dist/seed/store.d.ts.map +1 -1
  293. package/dist/seed/store.js +83 -15
  294. package/dist/seed/store.js.map +1 -1
  295. package/dist/seed/verify.d.ts +2 -2
  296. package/dist/seed/verify.d.ts.map +1 -1
  297. package/dist/seed/verify.js +8 -4
  298. package/dist/seed/verify.js.map +1 -1
  299. package/package.json +5 -4
@@ -1,15 +1,14 @@
1
1
  import { noManagerCredentialWarning } from "../lib/daemon-credential-warning.js";
2
2
  import { openBrokerLog, prepareForegroundBrokerLog } from "../lib/broker-log.js";
3
3
  import { spawnBroker } from "../lib/broker-spawn.js";
4
- import { foregroundBrokerStopped } from "../lib/foreground-broker-stop.js";
5
4
  import { randomUUID } from "node:crypto";
6
5
  import { homedir } from "node:os";
7
6
  import { mkdirSync, existsSync, lstatSync, realpathSync, readdirSync, rmdirSync, } from "node:fs";
8
7
  import { join, resolve } from "node:path";
9
8
  import { isReachable, DEFAULT_SERVER, CONTRACT_ARTIFACT_MAX_BYTES, MANAGER_START_PAYLOAD_FLOOR, mintCreds, newIdentity, reconcileSpaceMemoryBuckets, LEASE_TTL_MS, } from "@cotal-ai/core";
10
- import { assertManagerName, processStopped, readManagerName, readManagerSeatCap, DEFAULT_SEAT_CAP, parseSeatCapFlag, seatCapText, CommandFailure, codeSpan, failureEnvelope, writeEnvelope, isCommandFailure, protectedLocalDirectory, jsonFlag, plainFlag, renderReport, assertSingleSpaceBroker, authDir, getSpaceAuth, brokerAddressKey, canonicalRoot, clearCurrent, findMesh, legacyStackOtherHome, stackHomeRemedy, getCurrent, loadMeshes, localMeshesForRoot, keepsRegistration, presentationOf, parsePositiveIntegerFlag, retainedLegacyBroker, removeMesh, userAuthStateDir, workspaceSecretStore, acquireMaintenanceLock, assertStoreIdentity, assessMaintenanceClaim, assessRestoreClaim, beginOrdinaryResume, consumeRetiredMaintenance, markOrdinaryResumeDegraded, replaceDeadOrdinaryResumeListener, localProcessOwnerStatus, readMaintenanceJournal, readMaintenanceResumeDocument, readStoreIdentity, releaseMaintenanceLock, sameStoreIdentity, cutController, readBrokerPolicy, removePidPair, verifyIdentityPin, processesNaming, recordOperationSpace, recordOperationWarning, NATS_PIDFILE, exitCode, terminalWidth, } from "@cotal-ai/workspace";
9
+ import { assertManagerName, processStopped, readManagerName, readManagerSeatCap, DEFAULT_SEAT_CAP, parseSeatCapFlag, seatCapText, CommandFailure, codeSpan, failureEnvelope, writeEnvelope, isCommandFailure, protectedLocalDirectory, jsonFlag, plainFlag, renderReport, assertSingleSpaceBroker, authDir, getSpaceAuth, brokerAddressKey, canonicalRoot, legacyStackOtherHome, stackHomeRemedy, loadMeshes, localMeshesForRoot, keepsRegistration, presentationOf, parsePositiveIntegerFlag, retainedLegacyBroker, userAuthStateDir, workspaceSecretStore, acquireMaintenanceLock, assertStoreIdentity, assessMaintenanceClaim, assessRestoreClaim, beginOrdinaryResume, consumeRetiredMaintenance, markOrdinaryResumeDegraded, replaceDeadOrdinaryResumeListener, localProcessOwnerStatus, readMaintenanceJournal, readMaintenanceResumeDocument, readStoreIdentity, releaseMaintenanceLock, sameStoreIdentity, cutController, readBrokerPolicy, verifyIdentityPin, processesNaming, recordOperationSpace, recordOperationWarning, NATS_PIDFILE, terminalWidth, } from "@cotal-ai/workspace";
11
10
  import { FlagValueRefusal } from "../lib/flag-value-refusal.js";
12
- import { resolveAuthProvider, stopAuthService } from "../lib/auth-proc.js";
11
+ import { resolveAuthProvider } from "../lib/auth-proc.js";
13
12
  import { c, hang, stderrLine } from "../ui.js";
14
13
  import { admitAndRestoreSeatCheckpoints } from "../lib/seat-resume.js";
15
14
  import { NATS_DEFAULT_MAX_PAYLOAD, natsServerLabel, resolveNatsServer, unreadVersion } from "../lib/nats-bin.js";
@@ -20,16 +19,16 @@ import { seedBeforeLaunch, seedMoveNote } from "../seed/launch.js";
20
19
  import { seedDir } from "../seed/paths.js";
21
20
  import { seedStoreMoved } from "../seed/reconcile.js";
22
21
  import { upSystemdSupervisionWarning } from "../lib/systemd-supervision.js";
23
- import { deliveryStoppedByDown, deliveryUp, ensureDelivery, stopDelivery } from "../lib/delivery-proc.js";
22
+ import { deliveryStoppedByDown, deliveryUp, ensureDelivery } from "../lib/delivery-proc.js";
24
23
  import { displayCmd } from "../lib/self-exec.js";
25
24
  import { shellWord } from "../lib/endpoint-errors.js";
26
- import { clearManagerArtifacts, liveManagerWouldApplyMaxSessions, managerHasDeliveryMarker, managerRecordState, stopManager } from "../lib/manager-proc.js";
25
+ import { liveManagerWouldApplyMaxSessions, managerHasDeliveryMarker, managerRecordState } from "../lib/manager-proc.js";
27
26
  import { loadManifest } from "../lib/manifest/index.js";
28
27
  import { checkNewUpSpace, preparedUpRoot, restoreUpCwd } from "./up-target.js";
29
28
  import { cleanedManifestStart, interruptedStartBroker } from "../lib/legacy-start.js";
30
29
  import { canonicalServer } from "../lib/broker-service.js";
31
30
  import { controllerStackApplies, requestedStackMode, refuseForegroundStackHolder, stackUp, stackUpInterrupted, } from "./stack-up.js";
32
- import { exitInterrupted, handOverStartupNotice, noticeOnInterrupt, releaseStartupNotice } from "../lib/interrupt-notice.js";
31
+ import { handOverStartupNotice, noticeOnInterrupt, releaseStartupNotice } from "../lib/interrupt-notice.js";
33
32
  import { claimForegroundHold, foregroundHolder, foregroundStackEnd, foregroundStopLauncher, hangupForegroundStack, releaseForegroundHold } from "../lib/foreground-hold.js";
34
33
  import { settleInterruptedLaunches } from "../lib/service-process.js";
35
34
  import { assertUserStackTransport, preflightUserStack } from "./stack-user-auth.js";
@@ -39,7 +38,7 @@ import { warnForeignStoreEntries } from "../lib/store-dir.js";
39
38
  import { extensionNames, preflightRuntime } from "../ext-loader.js";
40
39
  import { completingFlagValue } from "../lib/completion.js";
41
40
  import { metadataPositionals } from "../lib/command-path.js";
42
- import { isManagerCommittedRestore, markPreparedRestoreDegraded, heldRestoreAttempt, heldClaim, movedFolderRefusal, prepareRestore, restoreArtifactPath, restoreLaunch, preservedSourceState, rehydratePreparedRestore, journaledMaxFileStore, rearmUnboundRestore, replacePreparedDeadRestoreListener, restoreInterruptNotice, } from "../lib/restore.js";
41
+ import { isManagerCommittedRestore, markPreparedRestoreDegraded, heldRestoreAttempt, heldClaim, movedFolderRefusal, prepareRestore, restoreArtifactPath, restoreLaunch, preservedSourceState, rehydratePreparedRestore, journaledMaxFileStore, rearmUnboundRestore, replacePreparedDeadRestoreListener, } from "../lib/restore.js";
43
42
  import { attemptProcessesGone } from "../lib/isolated-broker.js";
44
43
  import { assertEndpointUnreachable } from "../lib/endpoint-cut.js";
45
44
  import { freshStackServer, legacyUpRetry, retryStackAddress, serverWithFreePort } from "../lib/up-broker-address.js";
@@ -49,7 +48,9 @@ import { reconcileHostAndServer } from "./up-host.js";
49
48
  import { registeredAddressHolder, refuseRegisteredAddress, membershipConversionRefusal, fileMembershipStore, } from "./up-stores.js";
50
49
  import { brokerVersion, writeOpenBrokerConf, authSetup, provisionWebCreds } from "./up-broker-auth.js";
51
50
  import { validateUpArguments, freshFolderRoot, folderNamedSpace, recordsNameNoSpace, inheritedMachineHomeRoot, assertFreshTeamBootOwnership, publicExchangeArgs, serviceEndpointsArgs, folderSpace, assertSelectionNotMoved, } from "./up-args.js";
52
- import { failedListeners, startUserAuthService, startDeliveryWithBroker, reportDegradedControlPlane, recordSpawnedListener, awaitSpawnedListener, listenerExitRemedy, serveReadyListener, startMeshDetached, assertBrokerAddressFree, refuseStartOverUserState, ensureRootForSpace, unnamedDefault, claimSpace, attachHostFor, maxSessionsFor, recordOurMesh, seedPersonaAfterUp, belowPresenceSafeBroker, } from "./up-detach.js";
51
+ import { startUserAuthService, startDeliveryWithBroker, reportDegradedControlPlane, recordSpawnedListener, awaitSpawnedListener, serveReadyListener, startMeshDetached, assertBrokerAddressFree, refuseStartOverUserState, ensureRootForSpace, unnamedDefault, claimSpace, attachHostFor, maxSessionsFor, recordOurMesh, seedPersonaAfterUp, belowPresenceSafeBroker, } from "./up-detach.js";
52
+ import { holdForegroundListener } from "./up-foreground-listener.js";
53
+ import { createUpControlDirectory, withUpProjectTrust } from "./up-project-trust.js";
53
54
  import { controllerStackNative, manifestFileRefusal, upManifest } from "./up-manifest.js";
54
55
  import { printRestoreReceipt, unrecordedStackServer, restoredBrokerRuns, assertOrdinaryUpAllowed, markPendingResumeDegraded, bindSpawnedRestoreListener, provePreparedRestoreListener, resumeControllerStack, commitTokenHandoff, bindSpawnedOrdinaryResumeListener, proveOrdinaryResumeListener, verifySpawnedOrdinaryListener, adoptProvenListener, completeResumeActivation, } from "./up-resume.js";
55
56
  export { prepareFreshTeamBoot, prepareResumeTeamBoot, recordedBrokerTransport, recheckFreshTeamBoot, controllerStackNative } from "./up-manifest.js";
@@ -268,9 +269,8 @@ function seedMovedFailure(error) {
268
269
  /** `inheritedLock` is the root maintenance lock a recovery re-entry hands down (see the re-entry
269
270
  * below). Ownership transfers with it: this call releases it at its own release point. */
270
271
  export async function up(args, inheritedLock, freshTeamBoot = false, restoreSink) {
271
- // One `up`, its re-entries included, reads each channels file once (see `channelsReads`).
272
272
  if (!channelsReads.getStore())
273
- return channelsReads.run(new Map(), () => up(args, inheritedLock, freshTeamBoot, restoreSink));
273
+ return withUpProjectTrust(() => channelsReads.run(new Map(), () => up(args, inheritedLock, freshTeamBoot, restoreSink)));
274
274
  // A --server is recorded and compared in one spelling, the scheme in lower case with no bare
275
275
  // trailing slash. A manifest boot checks its own override against broker.servers.
276
276
  if (typeof args.values.server === "string" && !args.values.file)
@@ -293,7 +293,7 @@ export async function up(args, inheritedLock, freshTeamBoot = false, restoreSink
293
293
  // A fresh folder under the machine home gets its own `.cotal` before anything resolves the root, so
294
294
  // every later step uses this folder. A run that stops before writing there removes it again.
295
295
  if (fresh) {
296
- mkdirSync(join(fresh, ".cotal"), { mode: 0o700 });
296
+ createUpControlDirectory(fresh);
297
297
  for (const line of hang("", `made ${join(fresh, ".cotal")} for this folder's records; the machine's home .cotal was not used`, terminalWidth(process.stderr), c.dim))
298
298
  console.error(line);
299
299
  }
@@ -921,7 +921,7 @@ async function runUp(args, invokedFrom, inheritedLock, onAdopt, freshTeamBoot =
921
921
  if (managerName !== undefined) {
922
922
  const named = { root: cotalRoot(), space: values.space ?? folderSpace() };
923
923
  if (readManagerName(named) !== managerName && managerRecordState(named.space, named.root).state === "alive")
924
- throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", `a manager already runs for space ${named.space}, and it keeps the name it started with`, { target: { root: named.root, space: named.space }, remedy: `stop it with \`cotal down\`, then run ${codeSpan(`cotal up --manager-name ${shellWord(managerName)}`)}` });
924
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", `a manager already runs for space ${named.space}, and it keeps the name it started with`, { target: { root: named.root, space: named.space }, remedy: `run ${codeSpan(`${values.json ? "cotal" : displayCmd()} down`)} from ${codeSpan(shellWord(named.root))}, then retry the original startup command unchanged from its original folder` });
925
925
  }
926
926
  // The manager records this cap once it serves. A running manager keeps the cap it started with.
927
927
  const managerSeatCap = parseSeatCapFlag("--seat-cap", values["seat-cap"]);
@@ -998,7 +998,7 @@ async function runUp(args, invokedFrom, inheritedLock, onAdopt, freshTeamBoot =
998
998
  const presentation = presentationOf(values);
999
999
  const holder = values.foreground ? foregroundHolder(meshRoot) : undefined;
1000
1000
  if (holder !== undefined)
1001
- refuseForegroundStackHolder(meshRoot, stackSpace, holder, noManager, maxPayload);
1001
+ refuseForegroundStackHolder(meshRoot, stackSpace, holder, noManager, maxPayload, maxFileStore, maxSessions);
1002
1002
  // A signal ends a detached start where it is, after it records a launch it had not yet pinned to
1003
1003
  // its child, and the notice names what it left running. It is installed before the lock, so no
1004
1004
  // moment of the start exits without it.
@@ -1057,7 +1057,7 @@ async function runUp(args, invokedFrom, inheritedLock, onAdopt, freshTeamBoot =
1057
1057
  // Structured and plain manifest refusals report file errors before checking startup support.
1058
1058
  if (values.json || values.plain) {
1059
1059
  try {
1060
- loadManifest(path, logFile);
1060
+ loadManifest(path, logFile, "preview");
1061
1061
  }
1062
1062
  catch (e) {
1063
1063
  throw manifestFileRefusal(e, path);
@@ -1819,137 +1819,12 @@ async function runUp(args, invokedFrom, inheritedLock, onAdopt, freshTeamBoot =
1819
1819
  const listenerStartedAt = new Date().toISOString();
1820
1820
  // Keep the POSIX broker out of the terminal's process group for manager-first teardown on Ctrl-C.
1821
1821
  const child = spawnBroker(bin, natsArgs, { cwd: cotalRoot(), stdio: "inherit", detached: process.platform !== "win32", windowsHide: false });
1822
- let listenerReady = false;
1823
- let activationFinished = !resumeAttempt;
1824
1822
  await recordSpawnedListener(child, listenerStartedAt, boundListener);
1825
- const foregroundPin = process.platform === "win32" ? verifyIdentityPin(cotalPath(NATS_PIDFILE)) : undefined;
1826
- child.on("error", (err) => {
1827
- console.error(c.red(`Failed to start nats-server: ${err.message}`));
1828
- if (!resumeAttempt)
1829
- process.exit(1);
1830
- });
1831
- // Stop the detached manager, delivery daemon and space's user-auth service before their broker,
1832
- // so none outlives it. The auth service's process record is space-scoped.
1833
- // The manager goes first, in `cotal down`'s order, through the stop `cotal down` runs (#1307): it
1834
- // holds the stop reservation, asserts the exact manager can spare its seats before any signal,
1835
- // reports the seats left behind, and escalates a wedged manager to SIGKILL. When that stop throws
1836
- // the manager may still be serving, so NOTHING else is signalled — no delivery, no auth, no broker:
1837
- // the refusal is printed with the reap route and the latch is released, so the stack keeps running
1838
- // in the foreground; the operator ends it with `cotal down --with-agents` from another terminal,
1839
- // and the broker-exit handler below already ends `up` when the broker goes.
1840
- // stopDelivery and stopAuthService are the stops bare `cotal down` performs for those daemons
1841
- // (reservation, SIGKILL escalation); the rest of the teardown must run even if one fails —
1842
- // the failure is logged, never swallowed silently. Teardown is AWAITED before the broker is
1843
- // signalled, so it never races a broker that is already going away.
1844
- let stopping = false;
1845
- // The operator's signal sets the command's exit status, not the broker's SIGTERM.
1846
- let stopSignal;
1847
- let stoppedListener = false;
1848
- let teardown;
1849
- const stop = (signal) => {
1850
- if (stopping)
1851
- return; // a second Ctrl-C during teardown must not start a second teardown
1852
- stopping = true;
1853
- stopSignal = signal;
1854
- // Once the broker has exited, its handler below is already running this teardown and reads
1855
- // `stopping` when it is done.
1856
- if (child.exitCode !== null || child.signalCode !== null)
1857
- return;
1858
- teardown = (async () => {
1859
- try {
1860
- await stopManager(space);
1861
- clearManagerArtifacts(space);
1862
- }
1863
- catch (e) {
1864
- console.error(c.red(`! teardown: ${e.message}`));
1865
- console.error(c.red(`the stack is still running; to take managed agents with it, run: \`cotal down --with-agents\``));
1866
- stopping = false;
1867
- return;
1868
- }
1869
- await stopDelivery(space).catch((e) => console.error(`! delivery teardown: ${e.message}`));
1870
- await stopAuthService(space).catch((e) => console.error(`! auth teardown: ${e.message}`));
1871
- stoppedListener = child.kill("SIGTERM");
1872
- })();
1873
- };
1874
- process.on("SIGINT", () => stop("SIGINT"));
1875
- process.on("SIGTERM", () => stop("SIGTERM"));
1876
- restored?.releaseInterruptNotice?.();
1877
- child.on("exit", async (code, signal) => {
1878
- if (failedListeners.has(child))
1879
- return;
1880
- const pidPath = cotalPath(NATS_PIDFILE), stoppedByDown = await foregroundBrokerStopped(pidPath, foregroundPin?.kind === "match" && foregroundPin.record.pid === child.pid ? foregroundPin.record : undefined, code);
1881
- if (!stoppedByDown)
1882
- removePidPair(pidPath, String(child.pid));
1883
- // One teardown at a time: a stop started while another is in flight is refused the reservation
1884
- // that one holds, so wait for a Ctrl-C teardown already running instead of racing it.
1885
- await teardown;
1886
- await stopDelivery(space).catch((e) => console.error(`! delivery teardown: ${e.message}`));
1887
- await stopManager(space).then(() => clearManagerArtifacts(space)).catch((e) => console.error(`! manager teardown: ${e.message}`));
1888
- await stopAuthService(space).catch((e) => console.error(`! auth teardown: ${e.message}`));
1889
- // Only the shutdown that `stop()` drives (Ctrl-C, SIGTERM) can unrecord here.
1890
- // External `down` owns its own registry cleanup.
1891
- if (stopping) {
1892
- // Only unrecord if the registry still points at THIS broker. A newer broker for the same space
1893
- // (a concurrent `up`, or a different-port re-up that recorded after us) may have replaced our
1894
- // record — removing by name would clobber the live winner and hide it from the registry.
1895
- // …and only if it is still OUR kind of record. A concurrent `cotal meshes add --force` can
1896
- // replace it with a hand-registered one carrying the same server + root; that record outlives
1897
- // this broker by design (it is the operator's, and only they remove it), so unrecording it on
1898
- // our exit would delete a registration this process never owned.
1899
- const mine = findMesh(space);
1900
- if (mine && mine.origin !== "manual" && mine.server === server && mine.root === cotalRoot() && !keepsRegistration(mine)) {
1901
- removeMesh(space);
1902
- if (getCurrent() === space)
1903
- clearCurrent();
1904
- }
1905
- if (activationFinished)
1906
- process.exit(stopSignal === "SIGTERM" ? 143 : 130);
1907
- }
1908
- else if (code === 0 || stoppedByDown) {
1909
- // Before readiness, the startup check reports that the listener never answered.
1910
- // After readiness, do not race external `down` with a claim about its registry cleanup.
1911
- if (listenerReady && activationFinished)
1912
- process.exit(0);
1913
- }
1914
- else {
1915
- // The record is kept ON PURPOSE: it still names the store this broker opened, so a repair
1916
- // `up` reopens that SAME store instead of falling back to the root's default, and a
1917
- // supervising unit's restart takes the refresh path against the recorded store rather than
1918
- // racing a second broker into existence. NATS logs to this terminal unless a native log was
1919
- // requested, so there is no `.cotal/nats.log` to name here.
1920
- const detail = signal ? `signal ${signal}` : `code ${code}`;
1921
- const repair = `log: see ${brokerOutput}; repair: ${codeSpan(`cotal up --server ${shellWord(server)} --space ${shellWord(space)}`)}`;
1922
- // Retention is read from the registry, not assumed: a broker that exits before it first
1923
- // answers was never recorded, and running the same `up` again only repeats that exit, so its
1924
- // step is the one a detached start gives. A registry that cannot be read is not claimed
1925
- // either way, and the read cannot throw past this handler, which still has to exit.
1926
- let outcome;
1927
- try {
1928
- const mine = findMesh(space);
1929
- outcome = mine && mine.server === server && mine.root === cotalRoot()
1930
- ? `; the mesh "${space}" stays recorded (\`cotal meshes\` lists it offline); ${repair}`
1931
- : ` before the mesh "${space}" was recorded; next: ${listenerExitRemedy(natsServer, brokerOutput)}`;
1932
- }
1933
- catch {
1934
- outcome = `; whether the mesh "${space}" stays recorded could not be read; ${repair}`;
1935
- }
1936
- stderrLine("✗ ", `nats-server exited unexpectedly (${detail})${outcome}`, c.red);
1937
- // A foreground broker under `Restart=on-failure` must exit non-zero on a crash so the unit
1938
- // restarts it; exiting 0 here (as an unconditional `code ?? 0` used to) looked like a clean
1939
- // stop and left the unit sitting dead. An abnormal exit is a failed run, 5, not the broker's
1940
- // own code, which the exit table would read as a usage error (1) or a refusal (2).
1941
- if (activationFinished)
1942
- process.exit(exitCode("failed", "OPERATION_FAILED"));
1943
- }
1944
- });
1945
- await awaitSpawnedListener({ child, executable: natsServer, server, space, creds: setup?.creds, tls: transport.kind === "tls-required", log: brokerOutput, boundListener }).catch((error) => {
1946
- if (!restored || !stoppedListener || !stopSignal || (child.exitCode === null && child.signalCode === null))
1947
- throw error;
1948
- releaseStartupLock();
1949
- exitInterrupted(stopSignal, restoreInterruptNotice(restored.root, restored.attemptId));
1950
- });
1951
- listenerReady = true;
1952
- {
1823
+ const foreground = holdForegroundListener({ child, server, space, executable: natsServer, log: brokerOutput, resuming: resumeAttempt !== undefined, restored, releaseStartupLock });
1824
+ try {
1825
+ await awaitSpawnedListener({ child, executable: natsServer, server, space, creds: setup?.creds, tls: transport.kind === "tls-required", log: brokerOutput, boundListener });
1826
+ foreground.listenerReady();
1827
+ await foreground.waitForRestoreStop();
1953
1828
  // A DAEMON THAT DIES UNDER THIS RUNNING BROKER IS RESTARTED HERE (#2469). It exits on its own once
1954
1829
  // it cannot reach the broker, and a starved host makes a running broker look unreachable, so it can
1955
1830
  // end while this broker serves on. Nothing else brings it back, and every static retirement then
@@ -1960,7 +1835,7 @@ async function runUp(args, invokedFrom, inheritedLock, onAdopt, freshTeamBoot =
1960
1835
  // stop. A failed attempt waits out the lease TTL, the longest a dead holder's lease blocks its
1961
1836
  // replacement. No daemon is alive during that wait for `down` to signal, so a stop there shows only as
1962
1837
  // the dead daemon's record going away. Recovery is announced only once the responder is bound.
1963
- const meshServing = () => !stopping && child.exitCode === null && child.signalCode === null;
1838
+ const meshServing = () => !foreground.isStopping() && child.exitCode === null && child.signalCode === null;
1964
1839
  let restartingDelivery = false;
1965
1840
  let deliveryStopped = false;
1966
1841
  const onDeliveryExit = (code, signal) => {
@@ -2000,7 +1875,7 @@ async function runUp(args, invokedFrom, inheritedLock, onAdopt, freshTeamBoot =
2000
1875
  restartingDelivery = false;
2001
1876
  })();
2002
1877
  };
2003
- const { authService, controlPlane } = await serveReadyListener({
1878
+ const { authService, controlPlane } = await foreground.publishControlPlane(() => serveReadyListener({
2004
1879
  child, server, space, storeDir, setup, seedFile: !resumeAttempt || values.channels ? seedFile : undefined, transport, maxPayload: brokerMaxPayload,
2005
1880
  ...(values["recreate-issued-stores"] !== undefined ? { recreateIssuedStores: resolve(values["recreate-issued-stores"]) } : {}),
2006
1881
  ...(values["recreate-membership-store"] ? { recreateMembershipStore: true } : {}),
@@ -2015,17 +1890,22 @@ async function runUp(args, invokedFrom, inheritedLock, onAdopt, freshTeamBoot =
2015
1890
  runtime: values.runtime,
2016
1891
  noManager,
2017
1892
  onDeliveryExit,
2018
- isStopping: () => stopping,
2019
- });
1893
+ isStopping: foreground.isStopping,
1894
+ }));
1895
+ await foreground.waitForRestoreStop();
2020
1896
  if (noManager && setup && controlPlane)
2021
1897
  recordOperationWarning(await noManagerCredentialWarning(cotalRoot(), space));
2022
1898
  if (restored && process.env.COTAL_SMOKE_FAIL_AFTER_RESTORE_LISTENER_READY === "1")
2023
1899
  throw new Error("smoke-injected failure after restore listener readiness");
2024
- await completeResumeActivation(resumeAttempt, controlPlane !== undefined && authService, !authService ? "normal listener started but the user-auth service is unavailable" : "normal listener started but the control plane is degraded", server, startupLock);
2025
- activationFinished = true;
1900
+ await completeResumeActivation(resumeAttempt, controlPlane !== undefined && authService, !authService ? "normal listener started but the user-auth service is unavailable" : "normal listener started but the control plane is degraded", server, startupLock, undefined, foreground.waitForRestoreStop);
1901
+ foreground.activationFinished();
2026
1902
  if (restored && !quietRestore)
2027
1903
  printRestoreReceipt(restored, values.__invokedRoot);
2028
1904
  }
1905
+ catch (error) {
1906
+ await foreground.waitForRestoreStop();
1907
+ throw error;
1908
+ }
2029
1909
  releaseStartupLock();
2030
1910
  await new Promise(() => { });
2031
1911
  }