@cotal-ai/cli 0.100.2 → 0.101.1

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 (626) hide show
  1. package/dist/chat/chat-view.d.ts.map +1 -1
  2. package/dist/chat/chat-view.js +5 -1
  3. package/dist/chat/chat-view.js.map +1 -1
  4. package/dist/chat/engine.d.ts +2 -1
  5. package/dist/chat/engine.d.ts.map +1 -1
  6. package/dist/chat/engine.js +2 -1
  7. package/dist/chat/engine.js.map +1 -1
  8. package/dist/chat/frontend.d.ts.map +1 -1
  9. package/dist/chat/frontend.js +13 -7
  10. package/dist/chat/frontend.js.map +1 -1
  11. package/dist/chat/native-session.d.ts +22 -3
  12. package/dist/chat/native-session.d.ts.map +1 -1
  13. package/dist/chat/native-session.js +91 -19
  14. package/dist/chat/native-session.js.map +1 -1
  15. package/dist/chat/open-session.d.ts +1 -0
  16. package/dist/chat/open-session.d.ts.map +1 -1
  17. package/dist/chat/open-session.js +1 -1
  18. package/dist/chat/open-session.js.map +1 -1
  19. package/dist/chat/picker.d.ts +5 -0
  20. package/dist/chat/picker.d.ts.map +1 -1
  21. package/dist/chat/picker.js +23 -10
  22. package/dist/chat/picker.js.map +1 -1
  23. package/dist/chat/plain.d.ts.map +1 -1
  24. package/dist/chat/plain.js +36 -10
  25. package/dist/chat/plain.js.map +1 -1
  26. package/dist/chat/session.d.ts +5 -0
  27. package/dist/chat/session.d.ts.map +1 -1
  28. package/dist/chat/static-session.d.ts +1 -0
  29. package/dist/chat/static-session.d.ts.map +1 -1
  30. package/dist/chat/static-session.js +24 -8
  31. package/dist/chat/static-session.js.map +1 -1
  32. package/dist/chat/stdio-io.d.ts +2 -0
  33. package/dist/chat/stdio-io.d.ts.map +1 -1
  34. package/dist/chat/stdio-io.js +6 -6
  35. package/dist/chat/stdio-io.js.map +1 -1
  36. package/dist/chat/stdio.d.ts +3 -2
  37. package/dist/chat/stdio.d.ts.map +1 -1
  38. package/dist/chat/stdio.js +26 -25
  39. package/dist/chat/stdio.js.map +1 -1
  40. package/dist/chat/user-session.d.ts +1 -0
  41. package/dist/chat/user-session.d.ts.map +1 -1
  42. package/dist/chat/user-session.js +1 -1
  43. package/dist/chat/user-session.js.map +1 -1
  44. package/dist/chat/view.d.ts +5 -4
  45. package/dist/chat/view.d.ts.map +1 -1
  46. package/dist/chat/view.js +10 -8
  47. package/dist/chat/view.js.map +1 -1
  48. package/dist/command.d.ts +5 -0
  49. package/dist/command.d.ts.map +1 -1
  50. package/dist/command.js +295 -82
  51. package/dist/command.js.map +1 -1
  52. package/dist/commands/agents.d.ts +29 -5
  53. package/dist/commands/agents.d.ts.map +1 -1
  54. package/dist/commands/agents.js +100 -35
  55. package/dist/commands/agents.js.map +1 -1
  56. package/dist/commands/backup-maintenance.d.ts.map +1 -1
  57. package/dist/commands/backup-maintenance.js +54 -21
  58. package/dist/commands/backup-maintenance.js.map +1 -1
  59. package/dist/commands/backup-read.d.ts.map +1 -1
  60. package/dist/commands/backup-read.js +12 -15
  61. package/dist/commands/backup-read.js.map +1 -1
  62. package/dist/commands/backup-restore.d.ts.map +1 -1
  63. package/dist/commands/backup-restore.js +20 -4
  64. package/dist/commands/backup-restore.js.map +1 -1
  65. package/dist/commands/backup.d.ts.map +1 -1
  66. package/dist/commands/backup.js +156 -28
  67. package/dist/commands/backup.js.map +1 -1
  68. package/dist/commands/channel-members.d.ts +1 -1
  69. package/dist/commands/channel-members.d.ts.map +1 -1
  70. package/dist/commands/channel-members.js +115 -29
  71. package/dist/commands/channel-members.js.map +1 -1
  72. package/dist/commands/channels.d.ts +11 -1
  73. package/dist/commands/channels.d.ts.map +1 -1
  74. package/dist/commands/channels.js +109 -20
  75. package/dist/commands/channels.js.map +1 -1
  76. package/dist/commands/chat.d.ts +11 -3
  77. package/dist/commands/chat.d.ts.map +1 -1
  78. package/dist/commands/chat.js +50 -22
  79. package/dist/commands/chat.js.map +1 -1
  80. package/dist/commands/clean.d.ts +10 -5
  81. package/dist/commands/clean.d.ts.map +1 -1
  82. package/dist/commands/clean.js +245 -42
  83. package/dist/commands/clean.js.map +1 -1
  84. package/dist/commands/completion.d.ts +15 -2
  85. package/dist/commands/completion.d.ts.map +1 -1
  86. package/dist/commands/completion.js +91 -26
  87. package/dist/commands/completion.js.map +1 -1
  88. package/dist/commands/config.d.ts +24 -1
  89. package/dist/commands/config.d.ts.map +1 -1
  90. package/dist/commands/config.js +65 -13
  91. package/dist/commands/config.js.map +1 -1
  92. package/dist/commands/console.d.ts.map +1 -1
  93. package/dist/commands/console.js +5 -4
  94. package/dist/commands/console.js.map +1 -1
  95. package/dist/commands/describe.d.ts +4 -2
  96. package/dist/commands/describe.d.ts.map +1 -1
  97. package/dist/commands/describe.js +4 -4
  98. package/dist/commands/describe.js.map +1 -1
  99. package/dist/commands/doctor.d.ts +1 -1
  100. package/dist/commands/doctor.d.ts.map +1 -1
  101. package/dist/commands/doctor.js +261 -34
  102. package/dist/commands/doctor.js.map +1 -1
  103. package/dist/commands/down-manifest.d.ts.map +1 -1
  104. package/dist/commands/down-manifest.js +9 -6
  105. package/dist/commands/down-manifest.js.map +1 -1
  106. package/dist/commands/down-services.d.ts +17 -16
  107. package/dist/commands/down-services.d.ts.map +1 -1
  108. package/dist/commands/down-services.js +29 -53
  109. package/dist/commands/down-services.js.map +1 -1
  110. package/dist/commands/down.d.ts +2 -2
  111. package/dist/commands/down.d.ts.map +1 -1
  112. package/dist/commands/down.js +96 -67
  113. package/dist/commands/down.js.map +1 -1
  114. package/dist/commands/endpoint-deregister.d.ts.map +1 -1
  115. package/dist/commands/endpoint-deregister.js +2 -2
  116. package/dist/commands/endpoint-deregister.js.map +1 -1
  117. package/dist/commands/endpoint.d.ts +2 -1
  118. package/dist/commands/endpoint.d.ts.map +1 -1
  119. package/dist/commands/endpoint.js +2 -2
  120. package/dist/commands/endpoint.js.map +1 -1
  121. package/dist/commands/endpoints.d.ts +1 -0
  122. package/dist/commands/endpoints.d.ts.map +1 -1
  123. package/dist/commands/endpoints.js +20 -5
  124. package/dist/commands/endpoints.js.map +1 -1
  125. package/dist/commands/feedback.d.ts.map +1 -1
  126. package/dist/commands/feedback.js +40 -2
  127. package/dist/commands/feedback.js.map +1 -1
  128. package/dist/commands/help.d.ts.map +1 -1
  129. package/dist/commands/help.js +2 -1
  130. package/dist/commands/help.js.map +1 -1
  131. package/dist/commands/history-clear.d.ts.map +1 -1
  132. package/dist/commands/history-clear.js +67 -51
  133. package/dist/commands/history-clear.js.map +1 -1
  134. package/dist/commands/history.d.ts +17 -2
  135. package/dist/commands/history.d.ts.map +1 -1
  136. package/dist/commands/history.js +221 -34
  137. package/dist/commands/history.js.map +1 -1
  138. package/dist/commands/join.d.ts +2 -0
  139. package/dist/commands/join.d.ts.map +1 -1
  140. package/dist/commands/join.js +132 -80
  141. package/dist/commands/join.js.map +1 -1
  142. package/dist/commands/meshes-add.d.ts +19 -4
  143. package/dist/commands/meshes-add.d.ts.map +1 -1
  144. package/dist/commands/meshes-add.js +114 -15
  145. package/dist/commands/meshes-add.js.map +1 -1
  146. package/dist/commands/meshes-wizard.d.ts +1 -0
  147. package/dist/commands/meshes-wizard.d.ts.map +1 -1
  148. package/dist/commands/meshes-wizard.js +45 -13
  149. package/dist/commands/meshes-wizard.js.map +1 -1
  150. package/dist/commands/meshes.d.ts +1 -1
  151. package/dist/commands/meshes.d.ts.map +1 -1
  152. package/dist/commands/meshes.js +76 -47
  153. package/dist/commands/meshes.js.map +1 -1
  154. package/dist/commands/mint.d.ts.map +1 -1
  155. package/dist/commands/mint.js +212 -19
  156. package/dist/commands/mint.js.map +1 -1
  157. package/dist/commands/models.d.ts +5 -1
  158. package/dist/commands/models.d.ts.map +1 -1
  159. package/dist/commands/models.js +21 -13
  160. package/dist/commands/models.js.map +1 -1
  161. package/dist/commands/persona-remote.d.ts.map +1 -1
  162. package/dist/commands/persona-remote.js +24 -13
  163. package/dist/commands/persona-remote.js.map +1 -1
  164. package/dist/commands/persona.d.ts +1 -1
  165. package/dist/commands/persona.d.ts.map +1 -1
  166. package/dist/commands/persona.js +92 -23
  167. package/dist/commands/persona.js.map +1 -1
  168. package/dist/commands/personas.d.ts.map +1 -1
  169. package/dist/commands/personas.js +59 -40
  170. package/dist/commands/personas.js.map +1 -1
  171. package/dist/commands/reset-space-apply.d.ts.map +1 -1
  172. package/dist/commands/reset-space-apply.js +69 -17
  173. package/dist/commands/reset-space-apply.js.map +1 -1
  174. package/dist/commands/reset-store-apply.d.ts +16 -0
  175. package/dist/commands/reset-store-apply.d.ts.map +1 -1
  176. package/dist/commands/reset-store-apply.js +122 -23
  177. package/dist/commands/reset-store-apply.js.map +1 -1
  178. package/dist/commands/reset.d.ts.map +1 -1
  179. package/dist/commands/reset.js +8 -7
  180. package/dist/commands/reset.js.map +1 -1
  181. package/dist/commands/revoke-credential.d.ts +5 -0
  182. package/dist/commands/revoke-credential.d.ts.map +1 -0
  183. package/dist/commands/revoke-credential.js +128 -0
  184. package/dist/commands/revoke-credential.js.map +1 -0
  185. package/dist/commands/send.d.ts +11 -3
  186. package/dist/commands/send.d.ts.map +1 -1
  187. package/dist/commands/send.js +284 -47
  188. package/dist/commands/send.js.map +1 -1
  189. package/dist/commands/service-actions.d.ts +2 -1
  190. package/dist/commands/service-actions.d.ts.map +1 -1
  191. package/dist/commands/service-actions.js +117 -21
  192. package/dist/commands/service-actions.js.map +1 -1
  193. package/dist/commands/service-log-follow.js +1 -1
  194. package/dist/commands/service-log-follow.js.map +1 -1
  195. package/dist/commands/service-registry.d.ts +1 -1
  196. package/dist/commands/service-registry.d.ts.map +1 -1
  197. package/dist/commands/service-registry.js +74 -30
  198. package/dist/commands/service-registry.js.map +1 -1
  199. package/dist/commands/service-set-stop.d.ts.map +1 -1
  200. package/dist/commands/service-set-stop.js +3 -2
  201. package/dist/commands/service-set-stop.js.map +1 -1
  202. package/dist/commands/setup-start.d.ts.map +1 -1
  203. package/dist/commands/setup-start.js +46 -5
  204. package/dist/commands/setup-start.js.map +1 -1
  205. package/dist/commands/setup.d.ts.map +1 -1
  206. package/dist/commands/setup.js +28 -13
  207. package/dist/commands/setup.js.map +1 -1
  208. package/dist/commands/space-delete.d.ts.map +1 -1
  209. package/dist/commands/space-delete.js +130 -41
  210. package/dist/commands/space-delete.js.map +1 -1
  211. package/dist/commands/space-registration.d.ts +13 -6
  212. package/dist/commands/space-registration.d.ts.map +1 -1
  213. package/dist/commands/space-registration.js +167 -46
  214. package/dist/commands/space-registration.js.map +1 -1
  215. package/dist/commands/space.d.ts +15 -1
  216. package/dist/commands/space.d.ts.map +1 -1
  217. package/dist/commands/space.js +66 -24
  218. package/dist/commands/space.js.map +1 -1
  219. package/dist/commands/spawn-preview.d.ts.map +1 -1
  220. package/dist/commands/spawn-preview.js +48 -10
  221. package/dist/commands/spawn-preview.js.map +1 -1
  222. package/dist/commands/spawn.d.ts +36 -13
  223. package/dist/commands/spawn.d.ts.map +1 -1
  224. package/dist/commands/spawn.js +306 -130
  225. package/dist/commands/spawn.js.map +1 -1
  226. package/dist/commands/stack-down.d.ts +9 -3
  227. package/dist/commands/stack-down.d.ts.map +1 -1
  228. package/dist/commands/stack-down.js +348 -64
  229. package/dist/commands/stack-down.js.map +1 -1
  230. package/dist/commands/stack-gone.d.ts +17 -0
  231. package/dist/commands/stack-gone.d.ts.map +1 -0
  232. package/dist/commands/stack-gone.js +218 -0
  233. package/dist/commands/stack-gone.js.map +1 -0
  234. package/dist/commands/stack-up.d.ts +64 -4
  235. package/dist/commands/stack-up.d.ts.map +1 -1
  236. package/dist/commands/stack-up.js +482 -55
  237. package/dist/commands/stack-up.js.map +1 -1
  238. package/dist/commands/status.d.ts +76 -2
  239. package/dist/commands/status.d.ts.map +1 -1
  240. package/dist/commands/status.js +550 -112
  241. package/dist/commands/status.js.map +1 -1
  242. package/dist/commands/team-agent-apply.d.ts.map +1 -1
  243. package/dist/commands/team-agent-apply.js +4 -3
  244. package/dist/commands/team-agent-apply.js.map +1 -1
  245. package/dist/commands/team-agent-remove.d.ts.map +1 -1
  246. package/dist/commands/team-agent-remove.js +4 -4
  247. package/dist/commands/team-agent-remove.js.map +1 -1
  248. package/dist/commands/team-boot-controller.d.ts.map +1 -1
  249. package/dist/commands/team-boot-controller.js +8 -2
  250. package/dist/commands/team-boot-controller.js.map +1 -1
  251. package/dist/commands/team-channel-remove.d.ts.map +1 -1
  252. package/dist/commands/team-channel-remove.js +26 -10
  253. package/dist/commands/team-channel-remove.js.map +1 -1
  254. package/dist/commands/team-deploy-apply.d.ts.map +1 -1
  255. package/dist/commands/team-deploy-apply.js +4 -3
  256. package/dist/commands/team-deploy-apply.js.map +1 -1
  257. package/dist/commands/team-mixed-remove.js +5 -5
  258. package/dist/commands/team-mixed-remove.js.map +1 -1
  259. package/dist/commands/team.d.ts.map +1 -1
  260. package/dist/commands/team.js +94 -32
  261. package/dist/commands/team.js.map +1 -1
  262. package/dist/commands/telemetry.d.ts.map +1 -1
  263. package/dist/commands/telemetry.js +3 -1
  264. package/dist/commands/telemetry.js.map +1 -1
  265. package/dist/commands/topology.d.ts.map +1 -1
  266. package/dist/commands/topology.js +11 -7
  267. package/dist/commands/topology.js.map +1 -1
  268. package/dist/commands/up.d.ts +6 -6
  269. package/dist/commands/up.d.ts.map +1 -1
  270. package/dist/commands/up.js +963 -240
  271. package/dist/commands/up.js.map +1 -1
  272. package/dist/commands/update.d.ts.map +1 -1
  273. package/dist/commands/update.js +9 -3
  274. package/dist/commands/update.js.map +1 -1
  275. package/dist/commands/use.d.ts +5 -1
  276. package/dist/commands/use.d.ts.map +1 -1
  277. package/dist/commands/use.js +55 -12
  278. package/dist/commands/use.js.map +1 -1
  279. package/dist/commands/watch.d.ts +4 -1
  280. package/dist/commands/watch.d.ts.map +1 -1
  281. package/dist/commands/watch.js +15 -3
  282. package/dist/commands/watch.js.map +1 -1
  283. package/dist/commands/who.d.ts +2 -0
  284. package/dist/commands/who.d.ts.map +1 -1
  285. package/dist/commands/who.js +18 -5
  286. package/dist/commands/who.js.map +1 -1
  287. package/dist/commands/whoami.d.ts +44 -5
  288. package/dist/commands/whoami.d.ts.map +1 -1
  289. package/dist/commands/whoami.js +168 -16
  290. package/dist/commands/whoami.js.map +1 -1
  291. package/dist/console/app.d.ts +1 -1
  292. package/dist/console/app.d.ts.map +1 -1
  293. package/dist/console/app.js +15 -9
  294. package/dist/console/app.js.map +1 -1
  295. package/dist/console/launch.d.ts +25 -0
  296. package/dist/console/launch.d.ts.map +1 -0
  297. package/dist/console/launch.js +56 -0
  298. package/dist/console/launch.js.map +1 -0
  299. package/dist/console/ui/CommandPalette.d.ts +5 -4
  300. package/dist/console/ui/CommandPalette.d.ts.map +1 -1
  301. package/dist/console/ui/CommandPalette.js +136 -45
  302. package/dist/console/ui/CommandPalette.js.map +1 -1
  303. package/dist/console/ui/Help.js +1 -1
  304. package/dist/console/ui/Help.js.map +1 -1
  305. package/dist/console/ui/Modal.d.ts +10 -0
  306. package/dist/console/ui/Modal.d.ts.map +1 -0
  307. package/dist/console/ui/Modal.js +8 -0
  308. package/dist/console/ui/Modal.js.map +1 -0
  309. package/dist/console/ui/NewAgent.d.ts +14 -0
  310. package/dist/console/ui/NewAgent.d.ts.map +1 -0
  311. package/dist/console/ui/NewAgent.js +114 -0
  312. package/dist/console/ui/NewAgent.js.map +1 -0
  313. package/dist/console/ui/StatusBar.d.ts +1 -2
  314. package/dist/console/ui/StatusBar.d.ts.map +1 -1
  315. package/dist/console/ui/StatusBar.js +6 -8
  316. package/dist/console/ui/StatusBar.js.map +1 -1
  317. package/dist/console/ui/topo/Map.d.ts.map +1 -1
  318. package/dist/console/ui/topo/Map.js +1 -2
  319. package/dist/console/ui/topo/Map.js.map +1 -1
  320. package/dist/console/ui/topo/Matrix.js +2 -2
  321. package/dist/console/ui/topo/Matrix.js.map +1 -1
  322. package/dist/console/ui/topo/Sequence.d.ts.map +1 -1
  323. package/dist/console/ui/topo/Sequence.js +5 -4
  324. package/dist/console/ui/topo/Sequence.js.map +1 -1
  325. package/dist/console/ui/topo/model.d.ts +2 -1
  326. package/dist/console/ui/topo/model.d.ts.map +1 -1
  327. package/dist/console/ui/topo/model.js +4 -3
  328. package/dist/console/ui/topo/model.js.map +1 -1
  329. package/dist/exec-endpoint/service-adapter.d.ts.map +1 -1
  330. package/dist/exec-endpoint/service-adapter.js +13 -3
  331. package/dist/exec-endpoint/service-adapter.js.map +1 -1
  332. package/dist/ext-loader.d.ts +4 -0
  333. package/dist/ext-loader.d.ts.map +1 -1
  334. package/dist/ext-loader.js +6 -0
  335. package/dist/ext-loader.js.map +1 -1
  336. package/dist/help.d.ts.map +1 -1
  337. package/dist/help.js +44 -23
  338. package/dist/help.js.map +1 -1
  339. package/dist/index.d.ts.map +1 -1
  340. package/dist/index.js +59 -54
  341. package/dist/index.js.map +1 -1
  342. package/dist/lib/agent-skills.d.ts.map +1 -1
  343. package/dist/lib/agent-skills.js +2 -1
  344. package/dist/lib/agent-skills.js.map +1 -1
  345. package/dist/lib/attach-client.js +2 -2
  346. package/dist/lib/attach-client.js.map +1 -1
  347. package/dist/lib/backup-artifact.d.ts +29 -8
  348. package/dist/lib/backup-artifact.d.ts.map +1 -1
  349. package/dist/lib/backup-artifact.js +147 -26
  350. package/dist/lib/backup-artifact.js.map +1 -1
  351. package/dist/lib/broker-service.d.ts +27 -3
  352. package/dist/lib/broker-service.d.ts.map +1 -1
  353. package/dist/lib/broker-service.js +142 -29
  354. package/dist/lib/broker-service.js.map +1 -1
  355. package/dist/lib/broker-store-health.d.ts +89 -0
  356. package/dist/lib/broker-store-health.d.ts.map +1 -0
  357. package/dist/lib/broker-store-health.js +171 -0
  358. package/dist/lib/broker-store-health.js.map +1 -0
  359. package/dist/lib/cancel.d.ts +4 -4
  360. package/dist/lib/cancel.d.ts.map +1 -1
  361. package/dist/lib/cancel.js +5 -5
  362. package/dist/lib/cancel.js.map +1 -1
  363. package/dist/lib/completion-install.d.ts +11 -2
  364. package/dist/lib/completion-install.d.ts.map +1 -1
  365. package/dist/lib/completion-install.js +79 -21
  366. package/dist/lib/completion-install.js.map +1 -1
  367. package/dist/lib/completion-scripts.d.ts.map +1 -1
  368. package/dist/lib/completion-scripts.js +2 -2
  369. package/dist/lib/completion-scripts.js.map +1 -1
  370. package/dist/lib/completion.d.ts +5 -1
  371. package/dist/lib/completion.d.ts.map +1 -1
  372. package/dist/lib/completion.js +10 -0
  373. package/dist/lib/completion.js.map +1 -1
  374. package/dist/lib/concrete-channel.d.ts +6 -0
  375. package/dist/lib/concrete-channel.d.ts.map +1 -0
  376. package/dist/lib/concrete-channel.js +17 -0
  377. package/dist/lib/concrete-channel.js.map +1 -0
  378. package/dist/lib/confirmation-required.d.ts +3 -12
  379. package/dist/lib/confirmation-required.d.ts.map +1 -1
  380. package/dist/lib/confirmation-required.js +9 -8
  381. package/dist/lib/confirmation-required.js.map +1 -1
  382. package/dist/lib/connect.d.ts +9 -0
  383. package/dist/lib/connect.d.ts.map +1 -1
  384. package/dist/lib/connect.js +27 -0
  385. package/dist/lib/connect.js.map +1 -1
  386. package/dist/lib/control.d.ts +42 -12
  387. package/dist/lib/control.d.ts.map +1 -1
  388. package/dist/lib/control.js +148 -34
  389. package/dist/lib/control.js.map +1 -1
  390. package/dist/lib/controller-restore.d.ts.map +1 -1
  391. package/dist/lib/controller-restore.js +12 -7
  392. package/dist/lib/controller-restore.js.map +1 -1
  393. package/dist/lib/credential-authority.d.ts.map +1 -1
  394. package/dist/lib/credential-authority.js +3 -0
  395. package/dist/lib/credential-authority.js.map +1 -1
  396. package/dist/lib/credential-exports.d.ts +17 -0
  397. package/dist/lib/credential-exports.d.ts.map +1 -0
  398. package/dist/lib/credential-exports.js +21 -0
  399. package/dist/lib/credential-exports.js.map +1 -0
  400. package/dist/lib/debug-flag.d.ts +4 -0
  401. package/dist/lib/debug-flag.d.ts.map +1 -0
  402. package/dist/lib/debug-flag.js +7 -0
  403. package/dist/lib/debug-flag.js.map +1 -0
  404. package/dist/lib/default-persona.d.ts +2 -0
  405. package/dist/lib/default-persona.d.ts.map +1 -1
  406. package/dist/lib/default-persona.js +2 -0
  407. package/dist/lib/default-persona.js.map +1 -1
  408. package/dist/lib/delivery-proc.d.ts +1 -1
  409. package/dist/lib/delivery-proc.d.ts.map +1 -1
  410. package/dist/lib/delivery-proc.js +5 -4
  411. package/dist/lib/delivery-proc.js.map +1 -1
  412. package/dist/lib/delivery-responder.d.ts +7 -3
  413. package/dist/lib/delivery-responder.d.ts.map +1 -1
  414. package/dist/lib/delivery-responder.js +8 -4
  415. package/dist/lib/delivery-responder.js.map +1 -1
  416. package/dist/lib/denied-write.d.ts +8 -0
  417. package/dist/lib/denied-write.d.ts.map +1 -0
  418. package/dist/lib/denied-write.js +24 -0
  419. package/dist/lib/denied-write.js.map +1 -0
  420. package/dist/lib/endpoint-capability-gates.js +2 -2
  421. package/dist/lib/endpoint-capability-gates.js.map +1 -1
  422. package/dist/lib/flag-value-refusal.d.ts +8 -0
  423. package/dist/lib/flag-value-refusal.d.ts.map +1 -0
  424. package/dist/lib/flag-value-refusal.js +10 -0
  425. package/dist/lib/flag-value-refusal.js.map +1 -0
  426. package/dist/lib/install-umask.d.ts +5 -0
  427. package/dist/lib/install-umask.d.ts.map +1 -1
  428. package/dist/lib/install-umask.js +25 -0
  429. package/dist/lib/install-umask.js.map +1 -1
  430. package/dist/lib/interrupt-notice.d.ts +23 -1
  431. package/dist/lib/interrupt-notice.d.ts.map +1 -1
  432. package/dist/lib/interrupt-notice.js +27 -6
  433. package/dist/lib/interrupt-notice.js.map +1 -1
  434. package/dist/lib/interrupt-report.d.ts +7 -0
  435. package/dist/lib/interrupt-report.d.ts.map +1 -0
  436. package/dist/lib/interrupt-report.js +24 -0
  437. package/dist/lib/interrupt-report.js.map +1 -0
  438. package/dist/lib/isolated-broker.d.ts +1 -1
  439. package/dist/lib/isolated-broker.d.ts.map +1 -1
  440. package/dist/lib/isolated-broker.js +17 -8
  441. package/dist/lib/isolated-broker.js.map +1 -1
  442. package/dist/lib/legacy-start.d.ts +8 -6
  443. package/dist/lib/legacy-start.d.ts.map +1 -1
  444. package/dist/lib/legacy-start.js +36 -36
  445. package/dist/lib/legacy-start.js.map +1 -1
  446. package/dist/lib/manager-choice.d.ts +92 -4
  447. package/dist/lib/manager-choice.d.ts.map +1 -1
  448. package/dist/lib/manager-choice.js +338 -23
  449. package/dist/lib/manager-choice.js.map +1 -1
  450. package/dist/lib/manager-proc.d.ts.map +1 -1
  451. package/dist/lib/manager-proc.js +7 -6
  452. package/dist/lib/manager-proc.js.map +1 -1
  453. package/dist/lib/manifest/index.d.ts +5 -1
  454. package/dist/lib/manifest/index.d.ts.map +1 -1
  455. package/dist/lib/manifest/index.js +50 -5
  456. package/dist/lib/manifest/index.js.map +1 -1
  457. package/dist/lib/manifest/preflight.d.ts +4 -0
  458. package/dist/lib/manifest/preflight.d.ts.map +1 -1
  459. package/dist/lib/manifest/preflight.js +18 -1
  460. package/dist/lib/manifest/preflight.js.map +1 -1
  461. package/dist/lib/manifest/resolve.d.ts +8 -0
  462. package/dist/lib/manifest/resolve.d.ts.map +1 -1
  463. package/dist/lib/manifest/resolve.js +104 -11
  464. package/dist/lib/manifest/resolve.js.map +1 -1
  465. package/dist/lib/missing-flags.js +1 -1
  466. package/dist/lib/missing-flags.js.map +1 -1
  467. package/dist/lib/nats-bin.d.ts +28 -5
  468. package/dist/lib/nats-bin.d.ts.map +1 -1
  469. package/dist/lib/nats-bin.js +85 -7
  470. package/dist/lib/nats-bin.js.map +1 -1
  471. package/dist/lib/nearest-word.d.ts +14 -0
  472. package/dist/lib/nearest-word.d.ts.map +1 -0
  473. package/dist/lib/nearest-word.js +76 -0
  474. package/dist/lib/nearest-word.js.map +1 -0
  475. package/dist/lib/no-expiry-record.d.ts +8 -0
  476. package/dist/lib/no-expiry-record.d.ts.map +1 -0
  477. package/dist/lib/no-expiry-record.js +27 -0
  478. package/dist/lib/no-expiry-record.js.map +1 -0
  479. package/dist/lib/paths.d.ts +31 -0
  480. package/dist/lib/paths.d.ts.map +1 -1
  481. package/dist/lib/paths.js +92 -2
  482. package/dist/lib/paths.js.map +1 -1
  483. package/dist/lib/persona-files.d.ts +29 -6
  484. package/dist/lib/persona-files.d.ts.map +1 -1
  485. package/dist/lib/persona-files.js +179 -36
  486. package/dist/lib/persona-files.js.map +1 -1
  487. package/dist/lib/personas.d.ts +18 -1
  488. package/dist/lib/personas.d.ts.map +1 -1
  489. package/dist/lib/personas.js +65 -6
  490. package/dist/lib/personas.js.map +1 -1
  491. package/dist/lib/prompts.d.ts +7 -1
  492. package/dist/lib/prompts.d.ts.map +1 -1
  493. package/dist/lib/prompts.js +43 -3
  494. package/dist/lib/prompts.js.map +1 -1
  495. package/dist/lib/registry-errors.d.ts +2 -1
  496. package/dist/lib/registry-errors.d.ts.map +1 -1
  497. package/dist/lib/registry-errors.js +6 -2
  498. package/dist/lib/registry-errors.js.map +1 -1
  499. package/dist/lib/reset-space-plan.d.ts +2 -0
  500. package/dist/lib/reset-space-plan.d.ts.map +1 -1
  501. package/dist/lib/reset-space-plan.js +1 -1
  502. package/dist/lib/reset-space-plan.js.map +1 -1
  503. package/dist/lib/restore.d.ts +45 -3
  504. package/dist/lib/restore.d.ts.map +1 -1
  505. package/dist/lib/restore.js +233 -39
  506. package/dist/lib/restore.js.map +1 -1
  507. package/dist/lib/rolled-back-runs.d.ts +36 -0
  508. package/dist/lib/rolled-back-runs.d.ts.map +1 -0
  509. package/dist/lib/rolled-back-runs.js +96 -0
  510. package/dist/lib/rolled-back-runs.js.map +1 -0
  511. package/dist/lib/service-custody-win32.d.ts +25 -0
  512. package/dist/lib/service-custody-win32.d.ts.map +1 -0
  513. package/dist/lib/service-custody-win32.js +67 -0
  514. package/dist/lib/service-custody-win32.js.map +1 -0
  515. package/dist/lib/service-definitions.d.ts +16 -3
  516. package/dist/lib/service-definitions.d.ts.map +1 -1
  517. package/dist/lib/service-definitions.js +99 -27
  518. package/dist/lib/service-definitions.js.map +1 -1
  519. package/dist/lib/service-instances.d.ts +46 -5
  520. package/dist/lib/service-instances.d.ts.map +1 -1
  521. package/dist/lib/service-instances.js +112 -18
  522. package/dist/lib/service-instances.js.map +1 -1
  523. package/dist/lib/service-journal.js +1 -1
  524. package/dist/lib/service-journal.js.map +1 -1
  525. package/dist/lib/service-presets.d.ts.map +1 -1
  526. package/dist/lib/service-presets.js +16 -0
  527. package/dist/lib/service-presets.js.map +1 -1
  528. package/dist/lib/service-process.d.ts +53 -15
  529. package/dist/lib/service-process.d.ts.map +1 -1
  530. package/dist/lib/service-process.js +533 -86
  531. package/dist/lib/service-process.js.map +1 -1
  532. package/dist/lib/service-systemd-install.js +1 -1
  533. package/dist/lib/service-systemd-install.js.map +1 -1
  534. package/dist/lib/space-streams.d.ts +18 -0
  535. package/dist/lib/space-streams.d.ts.map +1 -0
  536. package/dist/lib/space-streams.js +35 -0
  537. package/dist/lib/space-streams.js.map +1 -0
  538. package/dist/lib/spawn-defaults.d.ts +25 -1
  539. package/dist/lib/spawn-defaults.d.ts.map +1 -1
  540. package/dist/lib/spawn-defaults.js +37 -1
  541. package/dist/lib/spawn-defaults.js.map +1 -1
  542. package/dist/lib/stack-journal.d.ts +157 -14
  543. package/dist/lib/stack-journal.d.ts.map +1 -1
  544. package/dist/lib/stack-journal.js +406 -49
  545. package/dist/lib/stack-journal.js.map +1 -1
  546. package/dist/lib/stack-listeners.d.ts +17 -0
  547. package/dist/lib/stack-listeners.d.ts.map +1 -0
  548. package/dist/lib/stack-listeners.js +54 -0
  549. package/dist/lib/stack-listeners.js.map +1 -0
  550. package/dist/lib/stack-members.d.ts +13 -0
  551. package/dist/lib/stack-members.d.ts.map +1 -0
  552. package/dist/lib/stack-members.js +24 -0
  553. package/dist/lib/stack-members.js.map +1 -0
  554. package/dist/lib/stack-resume.d.ts.map +1 -1
  555. package/dist/lib/stack-resume.js +5 -2
  556. package/dist/lib/stack-resume.js.map +1 -1
  557. package/dist/lib/stack-runs.d.ts +34 -0
  558. package/dist/lib/stack-runs.d.ts.map +1 -0
  559. package/dist/lib/stack-runs.js +75 -0
  560. package/dist/lib/stack-runs.js.map +1 -0
  561. package/dist/lib/status.d.ts +11 -0
  562. package/dist/lib/status.d.ts.map +1 -1
  563. package/dist/lib/status.js +4 -5
  564. package/dist/lib/status.js.map +1 -1
  565. package/dist/lib/stdout-owner.d.ts +12 -3
  566. package/dist/lib/stdout-owner.d.ts.map +1 -1
  567. package/dist/lib/stdout-owner.js +33 -5
  568. package/dist/lib/stdout-owner.js.map +1 -1
  569. package/dist/lib/store-dir.d.ts +68 -4
  570. package/dist/lib/store-dir.d.ts.map +1 -1
  571. package/dist/lib/store-dir.js +253 -17
  572. package/dist/lib/store-dir.js.map +1 -1
  573. package/dist/lib/team-additive-attempt.d.ts +1 -1
  574. package/dist/lib/team-channel-removal.d.ts.map +1 -1
  575. package/dist/lib/team-channel-removal.js +4 -0
  576. package/dist/lib/team-channel-removal.js.map +1 -1
  577. package/dist/lib/team-deploy-inspection.d.ts +13 -0
  578. package/dist/lib/team-deploy-inspection.d.ts.map +1 -1
  579. package/dist/lib/team-deploy-inspection.js +12 -0
  580. package/dist/lib/team-deploy-inspection.js.map +1 -1
  581. package/dist/lib/team-text.d.ts +6 -0
  582. package/dist/lib/team-text.d.ts.map +1 -0
  583. package/dist/lib/team-text.js +36 -0
  584. package/dist/lib/team-text.js.map +1 -0
  585. package/dist/lib/transient.d.ts +14 -8
  586. package/dist/lib/transient.d.ts.map +1 -1
  587. package/dist/lib/transient.js +72 -11
  588. package/dist/lib/transient.js.map +1 -1
  589. package/dist/lib/unusable-file.d.ts +13 -0
  590. package/dist/lib/unusable-file.d.ts.map +1 -0
  591. package/dist/lib/unusable-file.js +12 -0
  592. package/dist/lib/unusable-file.js.map +1 -0
  593. package/dist/lib/up-report.d.ts +6 -0
  594. package/dist/lib/up-report.d.ts.map +1 -1
  595. package/dist/lib/up-report.js +13 -0
  596. package/dist/lib/up-report.js.map +1 -1
  597. package/dist/lib/verdict.d.ts +14 -0
  598. package/dist/lib/verdict.d.ts.map +1 -0
  599. package/dist/lib/verdict.js +15 -0
  600. package/dist/lib/verdict.js.map +1 -0
  601. package/dist/managed-handoff.d.ts +11 -6
  602. package/dist/managed-handoff.d.ts.map +1 -1
  603. package/dist/managed-handoff.js +27 -18
  604. package/dist/managed-handoff.js.map +1 -1
  605. package/dist/render.d.ts +5 -2
  606. package/dist/render.d.ts.map +1 -1
  607. package/dist/render.js +44 -10
  608. package/dist/render.js.map +1 -1
  609. package/dist/telemetry.d.ts +4 -3
  610. package/dist/telemetry.d.ts.map +1 -1
  611. package/dist/telemetry.js +14 -6
  612. package/dist/telemetry.js.map +1 -1
  613. package/dist/ui.d.ts +3 -2
  614. package/dist/ui.d.ts.map +1 -1
  615. package/dist/ui.js +6 -4
  616. package/dist/ui.js.map +1 -1
  617. package/dist/view/mesh-view.d.ts.map +1 -1
  618. package/dist/view/mesh-view.js +4 -1
  619. package/dist/view/mesh-view.js.map +1 -1
  620. package/dist/watch-data.d.ts +9 -1
  621. package/dist/watch-data.d.ts.map +1 -1
  622. package/dist/watch-data.js +17 -3
  623. package/dist/watch-data.js.map +1 -1
  624. package/dist/watch-json.js +4 -3
  625. package/dist/watch-json.js.map +1 -1
  626. package/package.json +5 -5
@@ -6,27 +6,72 @@
6
6
  * recorded as such under its definition's lock and is not stopped again, so a repeated stop is a
7
7
  * no-op. Shared registry and credential cleanup follow only a complete confirmed stop. Nothing
8
8
  * outside the recorded members is touched. The whole apply holds the root's maintenance lock. */
9
+ import { accessSync, constants } from "node:fs";
10
+ import { dirname } from "node:path";
9
11
  import * as prompts from "../lib/prompts.js";
10
- import { DEFAULT_SPACE } from "@cotal-ai/core";
11
- import { CommandFailure, canonicalRoot, deliveryCredsKey, isCommandFailure, isConnectRefusal, oneLine, presentationOf, releaseMaintenanceLock, removeMeshesByRoot, recordPreparedSpace, renderReport, terminalWidth, workspaceSecretStore, writeResult, recordOperationSpace, } from "@cotal-ai/workspace";
12
- import { ConfirmationRequired } from "../lib/confirmation-required.js";
12
+ import { CotalEndpoint, DEFAULT_SPACE, deliveryLeaseHolderFor, mintCreds, newIdentity } from "@cotal-ai/core";
13
+ import { CommandFailure, ConfirmationRequired, canonicalRoot, deliveryCredsKey, findMesh, getSpaceAuth, homeCotalDir, isCommandFailure, isConnectRefusal, oneLine, presentationOf, processStopped, readBrokerPolicy, readNatsInfoGreeting, recordMesh, recordOperationSpace, recordPreparedSpace, releaseMaintenanceLock, removeMesh, removeMeshesByRoot, renderReport, resolveMeshTarget, stackHomeRemedy, stackRunsUnderOtherHome, terminalWidth, workspaceSecretStore, writeResult, } from "@cotal-ai/workspace";
14
+ import { brokerLaunchAt } from "../lib/broker-service.js";
15
+ import { fullStoreStopRefusal, jetStreamDisabled, jetStreamDisabledRefusal, readStoredBytes, recordedStore, storeFull, storeRefusedWrite } from "../lib/broker-store-health.js";
16
+ import { yesRequired } from "../lib/confirmation-required.js";
17
+ import { noticeOnInterrupt } from "../lib/interrupt-notice.js";
18
+ import { shellWord } from "../lib/endpoint-errors.js";
13
19
  import { canPrompt } from "./meshes-wizard.js";
14
- import { kernelImpactView, nativeImpactView } from "./service-actions.js";
20
+ import { nativeImpactView } from "./service-actions.js";
15
21
  import { serviceDefinitionStore } from "../lib/service-definitions.js";
16
- import { instanceProjection, observeServiceProcess, serviceInstances, serviceInstanceStore } from "../lib/service-instances.js";
17
- import { abandonableSignalStop, assertNoServiceUnitAttempts, prepareKernelServiceStop, prepareNativeServiceStop, retainedStopRequest, settleExitedInstance, stopProcessService } from "../lib/service-process.js";
18
- import { abandonRemedy, abandonRetainedStackStop, acquireStackOperationLock, newStackOperation, previewStackSettlement, processGone, readStackJournal, recordedProcessLine, recordedProcessesUnder, refuseControllerCut, settleRetainedStackStops, settleStackOperation, stackMaintenanceFence, stackNeverStarted, stackOperationUnsettled, stackScopeRefusals, stackSettlementNotice, withSettledMembers, writeStackJournal } from "../lib/stack-journal.js";
22
+ import { instanceProjection, observeServiceProcess, serviceInstances, serviceInstanceStore, serviceRecordsWriteProblem } from "../lib/service-instances.js";
23
+ import { abandonableSignalStop, assertNoServiceUnitAttempts, prepareKernelServiceStop, prepareNativeServiceStop, readinessAddressSurvivors, resumableSignalStop, retainedStopRequest, settleExitedInstance, PROCESS_STOP_GRACE_MS, stopProcessService } from "../lib/service-process.js";
24
+ import { abandonLaunchRemedy, abandonRemedy, abandonRetainedStackStop, abandonUnresolvedStackLaunch, acquireStackOperationLock, interruptedUpLeftManagerOut, newStackOperation, localRecords, previewStackSettlement, processGone, readStackJournal, recordedProcessesUnder, recordedProcessLine, refuseControllerCut, removeStaleLocalRecords, RESUME_REMEDY, runningStackRoles, settleRetainedStackStops, STACK_DEFINITION, STACK_ROLES, settleStackOperation, stackJournalPath, stackMaintenanceFence, stackNeverStarted, stackOperationUnsettled, stackScopeRefusals, stackSettlementNotice, staleRecordNotice, withSettledMembers, writeStackJournal } from "../lib/stack-journal.js";
25
+ import { readStackRuns } from "../lib/stack-runs.js";
19
26
  const STOP_ORDER = ["manager", "delivery", "auth", "broker"];
20
27
  /** The controller route applies whenever the root has a stack journal. */
21
28
  export function controllerStackRecorded(root) {
22
29
  return readStackJournal(canonicalRoot(root)) !== undefined;
23
30
  }
31
+ /** The root of the controller stack this machine started for `space` in a folder other than `root`,
32
+ * or undefined. `cotal down` stops only the stack of the folder it runs in, so a refusal names it. */
33
+ export function stackRootElsewhere(space, root) {
34
+ try {
35
+ const mesh = findMesh(space);
36
+ return mesh && mesh.origin === "up" && canonicalRoot(mesh.root) !== canonicalRoot(root) && controllerStackRecorded(mesh.root) ? mesh.root : undefined;
37
+ }
38
+ catch {
39
+ return undefined;
40
+ }
41
+ }
42
+ /** The same `down`, without `--space`, for a refusal that names the folder to run it from. */
43
+ export const sameDown = (values) => ["cotal down", ...["dry-run", "with-agents", "preserve-state", "yes"].filter((flag) => values[flag] === true).map((flag) => `--${flag}`)].join(" ");
44
+ /** A stop records each member's stop under the space's service instance records, so a folder there this
45
+ * account cannot write refuses before the plan, naming it, rather than leaving every member running
46
+ * after an unknown first stop. */
47
+ function assertServiceRecordsWritable(root, space, values) {
48
+ const dir = serviceRecordsWriteProblem(space, ["instances"]);
49
+ if (dir)
50
+ throw new CommandFailure("refused", "PERMISSION_DENIED", `this account cannot write ${dir}, where down records each member's stop; no member was stopped`, {
51
+ target: { root, space, path: dir },
52
+ remedy: `make it writable with chmod u+w ${dir}, then run \`${sameDown({ ...values, "dry-run": undefined, yes: true })}\``,
53
+ });
54
+ }
55
+ /** A stop records each step in the stack journal in the root's `.cotal`, so a folder this account
56
+ * cannot write refuses before the plan, naming it, rather than after the plan at the first write. */
57
+ function assertJournalWritable(root, values) {
58
+ const dir = dirname(stackJournalPath(root));
59
+ try {
60
+ accessSync(dir, constants.W_OK | constants.X_OK);
61
+ }
62
+ catch {
63
+ throw new CommandFailure("refused", "PERMISSION_DENIED", `this account cannot write ${dir}, where down records each step of the stop in the stack journal; no member was stopped`, {
64
+ target: { root, path: dir },
65
+ remedy: `make it writable with chmod u+w ${shellWord(dir)}, then run \`${sameDown({ ...values, "dry-run": undefined, yes: true })}\``,
66
+ });
67
+ }
68
+ }
24
69
  export function validateStackDownArguments(root, values) {
25
70
  const preserve = values["preserve-state"] === true;
26
- const allowed = new Set(preserve ? ["space", "yes", "json", "plain", "preserve-state", "store-dir", "session-store"] : ["space", "yes", "dry-run", "json", "plain", "with-agents", "abandon-stop"]);
71
+ const allowed = new Set(preserve ? ["space", "yes", "json", "plain", "preserve-state", "store-dir", "session-store"] : ["space", "yes", "dry-run", "json", "plain", "with-agents", "abandon-stop", "abandon-launch"]);
27
72
  const unsupported = Object.keys(values).filter((name) => !allowed.has(name) && values[name] !== undefined && !(Array.isArray(values[name]) && values[name].length === 0));
28
73
  if (unsupported.length)
29
- throw new CommandFailure("refused", "USAGE_INVALID", preserve ? "a controller stack's preserve accepts only --space, --store-dir, --session-store, --yes and presentation flags; it is exclusive with --with-agents and --dry-run" : "a controller stack's bare down accepts only --space, --with-agents, --abandon-stop, --yes, --dry-run and presentation flags; no other option was ignored", { target: { options: unsupported } });
74
+ throw new CommandFailure("refused", "USAGE_INVALID", preserve ? "a controller stack's preserve accepts only --space, --store-dir, --session-store, --yes and presentation flags; it is exclusive with --with-agents and --dry-run" : "a controller stack's bare down accepts only --space, --with-agents, --abandon-stop, --abandon-launch, --yes, --dry-run and presentation flags; no other option was ignored", { target: { options: unsupported } });
30
75
  if (values["dry-run"] === true && values.yes === true)
31
76
  throw new CommandFailure("refused", "USAGE_INVALID", "--yes acknowledges a guarded apply, not a read-only stack preview");
32
77
  if (values["abandon-stop"] !== undefined) {
@@ -35,7 +80,13 @@ export function validateStackDownArguments(root, values) {
35
80
  if (values["with-agents"] === true)
36
81
  throw new CommandFailure("refused", "USAGE_INVALID", "--abandon-stop cannot be combined with --with-agents: the abandoned stop's manager has exited, so no manager can stop the agents");
37
82
  if (values.yes !== true)
38
- throw new CommandFailure("refused", "USAGE_INVALID", "--abandon-stop needs --yes, because it gives up the only record of what that stop did");
83
+ throw new ConfirmationRequired("--abandon-stop needs --yes, because it gives up the only record of what that stop did", { remedy: `run cotal down --abandon-stop ${values["abandon-stop"]} --yes to give it up` });
84
+ }
85
+ if (values["abandon-launch"] !== undefined) {
86
+ if (values["dry-run"] === true)
87
+ throw new CommandFailure("refused", "USAGE_INVALID", "--abandon-launch records a member launch failed, so a read-only preview cannot take it");
88
+ if (values.yes !== true)
89
+ throw new CommandFailure("refused", "USAGE_INVALID", "--abandon-launch needs --yes, because a process that launch started without recording it is not excluded");
39
90
  }
40
91
  if (preserve)
41
92
  refuseControllerCut(root, "down --preserve-state");
@@ -56,13 +107,17 @@ function readMembers(journal) {
56
107
  throw new CommandFailure("refused", "TARGET_NOT_FOUND", "a recorded stack member's exact instance record is missing or belongs to another definition; no member was stopped", { target: { space: journal.space, definition: row.definition, instanceId: row.instanceId } });
57
108
  const state = observeServiceProcess(instance.record.value);
58
109
  const inspect = `inspect it with cotal service status ${row.definition} --instance ${row.instanceId} --space ${journal.space}`;
110
+ // Windows: the member's program exited on its own while its job still holds processes. Its own
111
+ // stop ends that job; a whole-stack down does not treat it as running or as gone.
112
+ if (state === "members-running")
113
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "a recorded stack member's program exited while its job still runs other processes; no member was stopped", { target: instanceProjection(instance), remedy: `end that job with cotal service stop ${row.definition} --instance ${row.instanceId} --space ${journal.space}${row.role === "manager" ? " --with-agents" : ""} --yes, then run cotal down again` });
59
114
  if (!processGone(state) && state !== "running")
60
- throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "a recorded stack member is foreign, unreadable or has an unresolved launch; no member was stopped", { target: instanceProjection(instance), remedy: inspect });
115
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "a recorded stack member is foreign, unreadable or has an unresolved launch; no member was stopped", { target: instanceProjection(instance), remedy: state === "unresolved-launch" ? `${inspect}; ${abandonLaunchRemedy(row.instanceId)}` : inspect });
61
116
  const retained = retainedStopRequest(instance.record.value);
62
117
  if (instance.record.value.state === "stopping" || retained)
63
118
  throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", retained?.publication === "unknown"
64
119
  ? "a recorded stack member's stop request file does not read as its own, so whether a stop was published is unknown; nothing was resubmitted and no member was stopped"
65
- : "a recorded stack member retains an unconfirmed stop request; it was not resubmitted and no member was stopped", { target: { ...instanceProjection(instance), ...(retained ? { requestId: retained.requestId, stopPublication: retained.publication } : {}) }, remedy: retained?.publication === "published" ? `${inspect}; ${abandonRemedy(retained.requestId)}` : abandonableSignalStop(instance.record.value) ? `${inspect}; ${abandonRemedy(instance.record.value.requestId)}` : inspect });
120
+ : "a recorded stack member retains an unconfirmed stop request; it was not resubmitted and no member was stopped", { target: { ...instanceProjection(instance), ...(retained ? { requestId: retained.requestId, stopPublication: retained.publication } : {}) }, remedy: retained?.publication === "published" ? `${inspect}; ${abandonRemedy(retained.requestId)}` : abandonableSignalStop(instance.record.value) ? `${inspect}; ${abandonRemedy(instance.record.value.requestId)}` : resumableSignalStop(instance.record.value) ? `${inspect}; ${RESUME_REMEDY}` : inspect });
66
121
  assertNoServiceUnitAttempts(journal.space, row.definition);
67
122
  members.push({ role: row.role, definition, instance, live: state === "running" });
68
123
  }
@@ -70,26 +125,59 @@ function readMembers(journal) {
70
125
  }
71
126
  /** A live manager's agent impact is read through the broker on an authenticated stack. When the
72
127
  * stack's broker is gone that read cannot succeed, so the refusal names the command that brings
73
- * the broker back while keeping the live manager. */
128
+ * the broker back while keeping the live manager. A broker whose process runs but sends no
129
+ * greeting, as a suspended one does, is named with its pid; the broker stops last, so it is not
130
+ * signalled here. */
74
131
  async function managerImpact(journal, members, manager, withAgents) {
75
132
  try {
76
133
  return await prepareNativeServiceStop(manager.definition, manager.instance, withAgents);
77
134
  }
78
135
  catch (caught) {
136
+ if (storeRefusedWrite(caught)) {
137
+ let store;
138
+ try {
139
+ store = recordedStore(journal.root, journal.space);
140
+ }
141
+ catch {
142
+ store = undefined;
143
+ }
144
+ throw fullStoreStop(journal, manager, store);
145
+ }
146
+ // Nothing was submitted: the stop's credential could not be recorded on a broker without JetStream.
147
+ const disabled = jetStreamDisabled(journal.root, journal.space);
148
+ if (disabled && !(isCommandFailure(caught) && caught.outcome !== "unknown"))
149
+ throw disabledJetStreamStop(journal, manager, disabled);
79
150
  // The read connects through the broker, so a gone broker surfaces as the connect refusal.
80
151
  const error = isConnectRefusal(caught) ? caught.failure() : caught;
81
- if (members.some((member) => member.role === "broker" && member.live) || !isCommandFailure(error))
152
+ const broker = members.find((member) => member.role === "broker" && member.live);
153
+ const pid = broker?.instance.record.value.process?.pid;
154
+ if (pid !== undefined && isCommandFailure(error) && !await readNatsInfoGreeting(journal.server, 2000)) {
155
+ throw new CommandFailure("refused", "TARGET_UNAVAILABLE", `the stack's broker runs as pid ${pid} but does not answer at ${journal.server}, so the live manager's agent impact cannot be read; no member was stopped`, { target: { root: journal.root, space: journal.space, broker: broker.instance.name, pid, manager: manager.instance.name }, native: { code: error.code, outcome: error.outcome, detail: error.message }, remedy: `if pid ${pid} is suspended, resume it with kill -CONT ${pid} and run cotal down again; if it stays unresponsive, end it with kill -KILL ${pid}, then run cotal up --space ${journal.space} to restart the broker while the manager keeps running, then run cotal down` });
156
+ }
157
+ if (broker || !isCommandFailure(error))
82
158
  throw caught;
83
159
  throw new CommandFailure("refused", error.code, "the stack's broker is not running, so the live manager's agent impact cannot be read; no member was stopped", { target: { root: journal.root, space: journal.space, manager: manager.instance.name }, native: { code: error.code, outcome: error.outcome, detail: error.message }, remedy: `run cotal up --space ${journal.space} to restart the broker from its recorded inputs while the manager keeps running, then run cotal down` });
84
160
  }
85
161
  }
162
+ /** The full-store refusal of a stack's manager stop, before any member is stopped. Making room
163
+ * purges the space's channel history; a plain SIGTERM to the manager's own process needs no
164
+ * credential, so it stops the stack without that loss. */
165
+ function fullStoreStop(journal, manager, store) {
166
+ const pid = manager.instance.record.value.process?.pid;
167
+ return fullStoreStopRefusal("the manager", store, "no member was stopped", { root: journal.root, space: journal.space, manager: manager.instance.name }, `make room with cotal history clear --yes, which purges all of this space's channel history, then run cotal down${pid !== undefined ? `; to keep that history, end the manager on this host with kill -TERM ${pid}, which stops its agents by its default policy, then run cotal down, and cotal up --max-file-store <bytes> with a larger cap` : ""}`);
168
+ }
169
+ /** The refusal of a stack's manager stop while its broker has JetStream disabled, before any member
170
+ * is stopped. */
171
+ function disabledJetStreamStop(journal, manager, write) {
172
+ return jetStreamDisabledRefusal(write, journal.root, journal.space, "stopping the manager needs a credential whose issuance record the broker cannot store", "no member was stopped", { root: journal.root, space: journal.space, manager: manager.instance.name }, manager.instance.record.value.process?.pid);
173
+ }
86
174
  /** Everything outside the recorded members that would be cut off refuses before the first signal.
87
175
  * Returns a settled active restore of this stack that was admitted, for the result to name. */
88
176
  function scopeRefusals(journal) {
89
177
  const maintenance = stackMaintenanceFence(journal.root, journal);
90
178
  if (maintenance.fenced)
91
179
  throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "this root retains a maintenance attempt; the controller stack was not stopped under it", { target: { root: journal.root } });
92
- stackScopeRefusals(journal, "bare cotal down");
180
+ stackScopeRefusals(journal, "bare `cotal down`");
93
181
  return maintenance.admittedRestore;
94
182
  }
95
183
  /** A stack its own down stopped completely, with no recorded member and no other service instance of
@@ -110,9 +198,10 @@ function alreadyStopped(journal, members) {
110
198
  * record and its pid in the message and the remedy, because no command shows another space's
111
199
  * records; nothing is stopped, adopted or removed. A real --with-agents refuses too, because no
112
200
  * running manager can stop the agents, unless the caller knows none can remain: the last down took
113
- * --with-agents, or the root never started a stack. Its preview shows the no-op. The legacy route
114
- * answers the same way. `warnings` report what this command changed before it found nothing running. */
115
- export function nothingRunning(presentation, target, withAgents, warnings = []) {
201
+ * --with-agents, or the root never started a stack. Its `preview` shows the no-op and warns with that
202
+ * refusal. The legacy route answers the same way. `warnings` report what this command changed before
203
+ * it found nothing running. */
204
+ export function nothingRunning(presentation, target, withAgents, warnings = [], preview = false) {
116
205
  // A root that names no space resolves to the default one, as `resolveSpace` answers.
117
206
  const remaining = recordedProcessesUnder(target.root, [target.space ?? DEFAULT_SPACE]);
118
207
  if (remaining.length) {
@@ -123,13 +212,52 @@ export function nothingRunning(presentation, target, withAgents, warnings = [])
123
212
  remedy: `check ${checks.join(", ")}; stop each process where it was started, or remove a record whose process is gone, then run \`cotal down\` again`,
124
213
  });
125
214
  }
126
- if (withAgents)
127
- throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "--with-agents needs the stack's running manager, and this folder's stack is not running; nothing was stopped", { target, remedy: "start it with `cotal up`, then run `cotal down --with-agents`" });
128
- writeResult(presentation, { command: "down", target, result: { kind: "stack-not-running", ...target }, noOp: true, ...(warnings.length ? { warnings } : {}) }, () => ({ sections: [
215
+ const agents = withAgents ? new CommandFailure("refused", "LIFECYCLE_BLOCKED", "--with-agents needs the stack's running manager, and this folder's stack is not running; nothing was stopped", { target, remedy: "start it with `cotal up`, then run `cotal down --with-agents`" }) : undefined;
216
+ if (agents && !preview)
217
+ throw agents;
218
+ const shown = agents ? [...warnings, { code: agents.code, target, message: `the real stop would refuse: ${agents.message}; ${agents.remedy}` }] : warnings;
219
+ writeResult(presentation, { command: "down", target, result: { kind: "stack-not-running", ...target }, noOp: true, ...(shown.length ? { warnings: shown } : {}) }, () => ({ sections: [
129
220
  { title: `The stack in ${target.root} is not running`, blocks: [{ kind: "lines", lines: ["Nothing was stopped."] }] },
130
221
  { title: "Next", blocks: [{ kind: "commands", items: [{ command: "cotal up", description: "Start it" }] }] },
131
222
  ] }));
132
223
  }
224
+ /** The registration `cotal up` wrote for this stack is how its members' stops reach it. An older
225
+ * `meshes rm --force` dropped it, and an older `meshes add --force` replaced it with one added by
226
+ * hand. When it is missing, or a hand-added one names this same root and broker, the stop rebuilds
227
+ * it from the journal, but only while the stack's broker is the exact launch the journal records
228
+ * there. A hand-added registration of another address or folder is not replaced: removing it takes
229
+ * an act that names it. One another stack started, or a catalog lists, resolves as before. */
230
+ function strandedRegistration(journal, members) {
231
+ const registered = findMesh(journal.space);
232
+ if (registered && registered.origin !== "manual" || !members.some((member) => member.live))
233
+ return undefined;
234
+ const target = { root: journal.root, space: journal.space, server: journal.server };
235
+ if (registered && (registered.server !== journal.server || canonicalRoot(registered.root) !== journal.root))
236
+ throw new CommandFailure("refused", "CONFLICT", `"${journal.space}" is registered by hand at ${registered.server} for ${registered.root}, and this stack's broker is ${journal.server} in ${journal.root}; a registration added by hand is not replaced, so nothing was stopped`, { target, remedy: `if that registration names no other mesh you use, forget it with \`cotal space forget ${journal.space}\`, then run \`cotal down --yes\` here` });
237
+ const what = registered ? "is registered by hand" : "has no registration";
238
+ if (journal.mode === "user")
239
+ throw new CommandFailure("refused", "UNSUPPORTED", `"${journal.space}" ${what}, and a user-auth stack's registration holds sign-in settings its journal does not, so it was not rebuilt; nothing was stopped`, { target, remedy: `inspect the recorded members with \`cotal service --space ${journal.space}\`` });
240
+ const broker = members.find((member) => member.role === "broker");
241
+ if (!broker?.live || !brokerLaunchAt(journal.space, broker.instance.name, broker.instance.record.value.launchRequestId, journal.root, journal.server))
242
+ throw new CommandFailure("refused", "CONFLICT", `"${journal.space}" ${what}, and the stack's broker is not the launch its journal records at ${journal.server}, so its registration was not rebuilt; nothing was stopped`, { target, remedy: `inspect the recorded members with \`cotal service --space ${journal.space}\`` });
243
+ const tlsRequired = readBrokerPolicy(journal.root)?.transport.kind === "tls-required";
244
+ return { previous: registered, entry: {
245
+ space: journal.space, server: journal.server, root: journal.root, mode: journal.mode, origin: "up", ts: new Date().toISOString(),
246
+ ...(tlsRequired ? { tlsRequired: true } : {}),
247
+ ...(journal.broker ? { storeDir: journal.broker.storeDir, ...(journal.broker.maxFileStore !== undefined ? { maxFileStore: journal.broker.maxFileStore } : {}), ...(journal.broker.host !== undefined ? { attachHost: journal.broker.host } : {}) } : {}),
248
+ } };
249
+ }
250
+ /** A stale process record a complete stop removed, or for a preview, one it would remove. */
251
+ function staleWarning(root, row, preview = false) {
252
+ return { code: "STALE_PROCESS_RECORD", target: { root, path: row.path, pid: row.pid, state: row.state }, message: staleRecordNotice(row, preview) };
253
+ }
254
+ /** What a stop that rebuilt the registration says it did, or for a preview, what it would do. */
255
+ function strandedNotice(journal, previous, preview = false) {
256
+ const used = preview ? "the stop would use" : "the stop used";
257
+ return { code: "REGISTRATION_REBUILT", target: { root: journal.root, space: journal.space, server: journal.server }, message: previous
258
+ ? `"${journal.space}" ${preview ? "is" : "was"} registered by hand at this stack's own root and broker; ${used} the registration \`cotal up\` writes for this stack, rebuilt from its journal, in its place`
259
+ : `"${journal.space}" ${preview ? "has" : "had"} no registration; ${used} the one \`cotal up\` writes for this stack, rebuilt from its journal` };
260
+ }
133
261
  /** What an abandoned member stop leaves unconfirmed. */
134
262
  function abandonNotice(role, abandonment) {
135
263
  const receipts = abandonment.receipts.length ? `only ${abandonment.receipts.join(" and ")} receipts` : "no receipt";
@@ -164,15 +292,42 @@ export async function stackDown(rootInput, values) {
164
292
  // The preview reads without the lock and writes nothing. The real stop holds the root's
165
293
  // maintenance lock from its first read to its last write, so no other whole-stack operation runs.
166
294
  if (values["dry-run"] === true)
167
- return previewStackStop(root, values, presentation, withAgents);
168
- const lock = acquireStackOperationLock(root);
295
+ return await previewStackStop(root, values, presentation, withAgents);
296
+ // A signal ends the stop where it is, and the notice names the members that still run. It is
297
+ // installed before the lock, so no moment of the stop exits without it.
298
+ const release = noticeOnInterrupt(() => stackStopInterruptNotice(root));
169
299
  try {
170
- await applyStackStop(root, values, presentation, interactive, withAgents, lock);
300
+ // A busy root's refusal names the recorded space, as every refusal after the lock does.
301
+ const recorded = readStackJournal(root)?.journal.space;
302
+ if (recorded !== undefined)
303
+ recordOperationSpace(recorded);
304
+ const lock = acquireStackOperationLock(root);
305
+ try {
306
+ await applyStackStop(root, values, presentation, interactive, withAgents, lock);
307
+ }
308
+ finally {
309
+ releaseMaintenanceLock(lock);
310
+ }
171
311
  }
172
312
  finally {
173
- releaseMaintenanceLock(lock);
313
+ release();
174
314
  }
175
315
  }
316
+ /** What an interrupted bare down left: the members still running, and the down that finishes it. A
317
+ * member it left `stopping` under a signal is stopped again by that down while it runs, and once it
318
+ * has exited only `--abandon-stop` settles it, so the notice names both. */
319
+ function stackStopInterruptNotice(root) {
320
+ const space = readStackJournal(root)?.journal.space;
321
+ const running = space === undefined ? [] : runningStackRoles(space);
322
+ const signalled = space === undefined ? undefined : STACK_ROLES.flatMap((role) => serviceInstances(space, STACK_DEFINITION[role])
323
+ .filter(({ record: { value } }) => !value.nativeStopRequired && value.state === "stopping").map(({ record: { value } }) => ({ role, requestId: value.requestId })))[0];
324
+ const left = running.length ? `${running.join(", ")} ${running.length === 1 ? "is" : "are"} still running` : "no member is running";
325
+ if (signalled)
326
+ return `Interrupted while stopping the stack in ${root}; ${left}. The stop of ${signalled.role} is not confirmed: while it runs, cotal down --yes stops it again, and once it has exited, cotal down --abandon-stop ${signalled.requestId} --yes finishes the stop.`;
327
+ return running.length
328
+ ? `Interrupted while stopping the stack in ${root}; ${left}. Run cotal down --yes to finish the stop.`
329
+ : `Interrupted while stopping the stack in ${root}; no member is running. Run cotal down --yes to finish its cleanup.`;
330
+ }
176
331
  /** The recorded stack this stop targets, with every refusal that needs no lock or write. An earlier
177
332
  * preserve or resume with no outcome is decided by its own maintenance attempt; an earlier up or
178
333
  * down with none is classified read-only from its members, and refuses if any is unresolved. */
@@ -181,9 +336,17 @@ function stopTarget(root, values) {
181
336
  if (!previous)
182
337
  throw new CommandFailure("refused", "TARGET_NOT_FOUND", "this root has no controller stack journal", { target: { root } });
183
338
  const journal0 = previous.journal;
339
+ if (values.space !== undefined && values.space !== journal0.space) {
340
+ const space = String(values.space), elsewhere = stackRootElsewhere(space, root);
341
+ recordOperationSpace(space);
342
+ throw new CommandFailure("refused", "CONFLICT", `--space ${space} ${elsewhere ? `names a controller stack rooted at ${elsewhere}` : "is not this folder's stack"}, and \`cotal down\` stops only the stack of the folder it runs in; this folder's stack is ${journal0.space}, so no member was stopped`, {
343
+ target: { root, space, recordedSpace: journal0.space, ...(elsewhere ? { stackRoot: elsewhere } : {}) },
344
+ remedy: elsewhere ? `run \`${sameDown(values)}\` from ${elsewhere}` : `run \`${sameDown(values)}\` from the folder whose stack is ${space}, or drop --space to stop ${journal0.space} here`,
345
+ });
346
+ }
184
347
  recordOperationSpace(journal0.space);
185
- if (values.space !== undefined && values.space !== journal0.space)
186
- throw new CommandFailure("refused", "CONFLICT", "the selected space differs from this root's recorded controller stack; no member was stopped", { target: { root, selectedSpace: values.space, recordedSpace: journal0.space } });
348
+ if (stackRunsUnderOtherHome(root, journal0))
349
+ throw new CommandFailure("refused", "TARGET_UNAVAILABLE", "this root's controller stack runs under another Cotal home; this one holds no record of its members, so no member was stopped", { target: { root, space: journal0.space, cotalHome: homeCotalDir() }, remedy: stackHomeRemedy() });
187
350
  if (stackOperationUnsettled(journal0) && journal0.operation.kind !== "up" && journal0.operation.kind !== "down")
188
351
  throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "an earlier preserve or resume on this root has no settled outcome; it is decided by its own maintenance attempt and no member was stopped", { target: { root, operation: journal0.operation }, remedy: `inspect the root's maintenance attempt and the stack's members with cotal service --space ${journal0.space}` });
189
352
  const settlement = previewStackSettlement(journal0);
@@ -193,28 +356,82 @@ function stopTarget(root, values) {
193
356
  const members = readMembers(scoped);
194
357
  return { previous, journal0: scoped, settlement, members, target: { root, space: journal0.space, server: journal0.server } };
195
358
  }
196
- function previewStackStop(root, values, presentation, withAgents) {
359
+ async function previewStackStop(root, values, presentation, withAgents) {
197
360
  const { journal0, settlement, members, target } = stopTarget(root, values);
198
- if (alreadyStopped(journal0, members) || stackNeverStarted(journal0))
199
- return nothingRunning(presentation, target, false);
361
+ // As the real stop does, a stack its own down stopped refuses --with-agents unless that down took it.
362
+ const stopped = alreadyStopped(journal0, members);
363
+ if (stopped || stackNeverStarted(journal0))
364
+ return nothingRunning(presentation, target, stopped && withAgents && !journal0.operation.withAgents, [], true);
200
365
  // A preview reports what would refuse the real stop instead of refusing itself.
201
- let blocked, restore;
366
+ let blocked, restore, stranded;
202
367
  try {
203
368
  restore = scopeRefusals(journal0);
369
+ stranded = strandedRegistration(journal0, members);
370
+ assertJournalWritable(root, values);
371
+ assertServiceRecordsWritable(root, journal0.space, values);
204
372
  }
205
373
  catch (error) {
206
374
  if (!isCommandFailure(error))
207
375
  throw error;
208
376
  blocked = error;
209
377
  }
210
- const warnings = blocked ? [{ code: blocked.code, target: blocked.target, message: `the real stop would refuse: ${blocked.message}${blocked.remedy ? `; ${blocked.remedy}` : ""}` }] : [];
378
+ // A live manager's stop needs room in the store, so the preview reads how much the space holds.
379
+ const manager = members.find((member) => member.role === "manager" && member.live);
380
+ const brokerPid = members.find((member) => member.role === "broker" && member.live)?.instance.record.value.process?.pid;
381
+ if (!blocked && manager && brokerPid !== undefined && !processStopped(brokerPid)) {
382
+ // A broker that disabled JetStream answers no read of the store, so its own log decides first.
383
+ const disabled = jetStreamDisabled(root, journal0.space);
384
+ let used;
385
+ if (!disabled)
386
+ try {
387
+ used = await readStoredBytes(resolveMeshTarget(root, { space: journal0.space, readOnly: true }), "down-preview");
388
+ }
389
+ catch {
390
+ used = undefined;
391
+ }
392
+ const full = used === undefined ? undefined : storeFull(root, journal0.space, used);
393
+ if (disabled)
394
+ blocked = disabledJetStreamStop(journal0, manager, disabled);
395
+ else if (full)
396
+ blocked = fullStoreStop(journal0, manager, full);
397
+ }
398
+ const warnings = blocked ? [{ code: blocked.code, target: blocked.target, message: `the real stop would refuse: ${blocked.message}${blocked.remedy ? `; ${blocked.remedy}` : ""}` }]
399
+ : [...stranded ? [strandedNotice(journal0, stranded.previous, true)] : [], ...localRecords(root, journal0.space).filter((row) => row.state !== "live").map((row) => staleWarning(root, row, true))];
211
400
  // A preview that changes nothing succeeds. It is partial only in what it read: no provider and
212
401
  // no manager impact, which the real stop reads and confirms before any signal.
213
402
  writeResult(presentation, { command: "down", target, result: { kind: "controller-stack-stop-preview", ...target, withAgents, members: members.map((member) => ({ role: member.role, definition: member.definition.name, instanceId: member.instance.name, process: member.live ? "running" : "gone" })), settlesOperation: settlement ?? null, blockedBy: blocked?.detail() ?? null, nativeImpactChecked: false, dryRun: true, signalled: false, admittedRestore: restore ?? null }, completeness: "partial", warnings }, () => {
214
403
  const view = planView(journal0, members, withAgents, settlement);
215
- return { ...view, sections: [...view.sections, ...restoreNotice(restore), { title: "Preview", blocks: [{ kind: "lines", lines: ["Nothing was stopped or written. The preview reads recorded members only; it loads no provider and queries no manager impact. The real stop reads and confirms that impact before any signal."] }] }] };
404
+ return { ...view, sections: [...view.sections, ...restoreNotice(restore), { title: "Preview", blocks: [{ kind: "lines", lines: ["Nothing was stopped or written. The preview reads recorded members and, with a live manager, how much the space's store holds; it loads no provider and queries no manager impact. The real stop reads and confirms that impact before any signal."] }] }] };
216
405
  });
217
406
  }
407
+ /** Whether shard 0 of the delivery lease still names the daemon this root's stored credential gave,
408
+ * read over an observer credential after the daemon's stop while the broker still runs. A daemon
409
+ * that was killed, or whose release write the broker refused, as a full store refuses it, leaves its
410
+ * row until the lease expires. The holder is the one that credential gives, never a name or pid.
411
+ * "unread" when the row could not be read. */
412
+ async function deliveryLeaseAfterStop(root, space, server) {
413
+ const store = workspaceSecretStore(root);
414
+ let ep;
415
+ try {
416
+ const creds = await store.get(deliveryCredsKey(space, { injected: false, root }));
417
+ if (creds === undefined)
418
+ return "released";
419
+ const auth = await getSpaceAuth(store, space);
420
+ if (!auth)
421
+ return "unread";
422
+ const id = newIdentity();
423
+ ep = new CotalEndpoint({ space, servers: server, tls: readBrokerPolicy(root)?.transport.kind === "tls-required", creds: await mintCreds(auth, id, "observer"), channels: [], consume: false, registerPresence: false, watchPresence: false, watchChannels: false, card: { id: id.id, name: "down-delivery-lease", kind: "endpoint" } });
424
+ ep.on("error", () => { });
425
+ await ep.start();
426
+ return (await ep.readDeliveryLease(0))?.holder === deliveryLeaseHolderFor(creds) ? "held" : "released";
427
+ }
428
+ catch {
429
+ return "unread";
430
+ }
431
+ finally {
432
+ await ep?.stop().catch(() => { });
433
+ }
434
+ }
218
435
  async function applyStackStop(root, values, presentation, interactive, withAgents, lock) {
219
436
  // A member stop an earlier down could not confirm in time is settled from its own receipt first.
220
437
  const recorded = readStackJournal(root)?.journal;
@@ -223,43 +440,80 @@ async function applyStackStop(root, values, presentation, interactive, withAgent
223
440
  await settleRetainedStackStops(ours);
224
441
  // A stop no receipt can settle is abandoned only when the operator names its request.
225
442
  const abandoned = ours && typeof values["abandon-stop"] === "string" ? await abandonRetainedStackStop(ours, values["abandon-stop"]) : undefined;
226
- const abandonWarnings = abandoned ? [{ code: "STOP_ABANDONED", target: { ...instanceProjection(abandoned.row), role: abandoned.role, requestId: abandoned.abandonment.requestId, receipts: abandoned.abandonment.receipts }, message: abandonNotice(abandoned.role, abandoned.abandonment) }] : [];
443
+ // So is a launch whose record names no process, when the operator names its instance.
444
+ const launch = ours && typeof values["abandon-launch"] === "string" ? abandonUnresolvedStackLaunch(ours, values["abandon-launch"]) : undefined;
445
+ const abandonWarnings = [
446
+ ...(abandoned ? [{ code: "STOP_ABANDONED", target: { ...instanceProjection(abandoned.row), role: abandoned.role, requestId: abandoned.abandonment.requestId, receipts: abandoned.abandonment.receipts }, message: abandonNotice(abandoned.role, abandoned.abandonment) }] : []),
447
+ ...(launch ? [{ code: "LAUNCH_ABANDONED", target: { ...instanceProjection(launch.row), role: launch.role }, message: `the ${launch.role} launch ${launch.row.name} was recorded failed: the up that started it exited before it recorded a process. A process that launch started without recording it is not excluded, and this down does not stop it` }] : []),
448
+ ];
227
449
  const { previous, journal0, settlement, members, target } = stopTarget(root, values);
228
450
  // The completed down that stopped the stack also stopped its agents when it took --with-agents, so
229
451
  // a repeat has nothing left to stop. A stack that never started has no agents either.
230
452
  if (alreadyStopped(journal0, members))
231
- return nothingRunning(presentation, target, withAgents && !journal0.operation.withAgents, abandonWarnings);
453
+ return nothingRunning(presentation, target, withAgents && !journal0.operation.withAgents, [...abandonWarnings, ...await readinessAddressSurvivors(journal0.space)]);
232
454
  if (stackNeverStarted(journal0))
233
455
  return nothingRunning(presentation, target, false, abandonWarnings);
456
+ // A stopped broker takes connections and never answers, so every read through it would wait out
457
+ // its budget and the broker's own stop would wait on a signal it cannot act on.
458
+ const broker = members.find((member) => member.role === "broker" && member.live);
459
+ const brokerPid = broker?.instance.record.value.process?.pid;
460
+ if (brokerPid !== undefined && processStopped(brokerPid))
461
+ throw new CommandFailure("refused", "TARGET_UNAVAILABLE", `the stack's broker, pid ${brokerPid}, is stopped, so it accepts connections at ${journal0.server} and never answers; no member was stopped`, { target: { ...target, broker: broker.instance.name, pid: brokerPid }, remedy: `resume it with kill -CONT ${brokerPid} and run cotal down again` });
234
462
  const admittedRestore = scopeRefusals(journal0);
463
+ assertJournalWritable(root, values);
464
+ assertServiceRecordsWritable(root, journal0.space, values);
235
465
  if (!values.yes && !interactive)
236
- throw new ConfirmationRequired("stopping the whole controller stack requires --yes outside an interactive terminal", { target, remedy: "run `cotal down --yes` to stop it; `cotal down --dry-run` shows what it stops" });
466
+ throw new ConfirmationRequired(yesRequired("stopping the whole controller stack", presentation === "json"), { target, remedy: "run `cotal down --yes` to stop it; `cotal down --dry-run` shows what it stops" });
467
+ // A missing or hand-added registration is rebuilt from the journal before anything resolves the
468
+ // members, and put back as it was when the stop ends before any member stops.
469
+ const stranded = strandedRegistration(journal0, members);
470
+ if (stranded)
471
+ recordMesh(stranded.entry);
472
+ const putBack = () => {
473
+ if (!stranded)
474
+ return;
475
+ if (stranded.previous)
476
+ recordMesh(stranded.previous);
477
+ else
478
+ removeMesh(journal0.space);
479
+ };
237
480
  // Complete native impact before confirmation. The broker's own kernel scope cannot be prepared
238
481
  // while its dependants run; it is recomputed after they stop and refuses on any change then.
239
482
  const manager = members.find((member) => member.role === "manager" && member.live);
240
- if (manager) {
241
- manager.native = await managerImpact(journal0, members, manager, withAgents);
242
- if (!manager.native)
243
- throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "the manager's native agent impact could not be established; no member was stopped", { target: instanceProjection(manager.instance) });
244
- }
245
- else if (withAgents)
246
- throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "--with-agents needs the stack's live manager and its native impact; no member was stopped", { target });
247
- if (presentation !== "json") {
248
- console.log(renderReport(planView(journal0, members, withAgents, settlement), presentation, terminalWidth(process.stdout)));
249
- if (manager?.native)
250
- console.log(renderReport(nativeImpactView(manager.native), presentation, terminalWidth(process.stdout)));
251
- }
252
- if (!values.yes) {
253
- const answer = await prompts.confirm({ message: `Stop every displayed member of ${oneLine(journal0.space)}'s controller stack with only the displayed native impact?`, initialValue: false });
254
- if (prompts.isCancel(answer) || !answer) {
255
- writeResult(presentation, { command: "down", target, result: { kind: "controller-stack-stop", ...target, cancelled: true, members: journal0.members }, noOp: true, warnings: [{ code: "USER_CANCELLED", target, message: "no member was stopped" }] }, () => planView(journal0, members, withAgents, settlement));
256
- return;
483
+ try {
484
+ if (manager) {
485
+ manager.native = await managerImpact(journal0, members, manager, withAgents);
486
+ if (!manager.native)
487
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "the manager's native agent impact could not be established; no member was stopped", { target: instanceProjection(manager.instance) });
257
488
  }
489
+ else if (withAgents)
490
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "--with-agents needs the stack's live manager and its native impact; no member was stopped", { target });
491
+ if (!values.yes) {
492
+ // What the prompt asks to confirm. The receipt names the mesh, so the plan does not.
493
+ if (presentation !== "json") {
494
+ console.log(renderReport({ sections: planView(journal0, members, withAgents, settlement).sections }, presentation, terminalWidth(process.stdout)));
495
+ if (manager?.native)
496
+ console.log(renderReport(nativeImpactView(manager.native), presentation, terminalWidth(process.stdout)));
497
+ }
498
+ const answer = await prompts.confirm({ message: `Stop every displayed member of ${oneLine(journal0.space)}'s controller stack with only the displayed native impact?`, initialValue: false });
499
+ if (prompts.isCancel(answer) || !answer) {
500
+ putBack();
501
+ writeResult(presentation, { command: "down", target, result: { kind: "controller-stack-stop", ...target, cancelled: true, members: journal0.members }, noOp: true, warnings: [{ code: "USER_CANCELLED", target, message: "no member was stopped" }] }, () => planView(journal0, members, withAgents, settlement));
502
+ return;
503
+ }
504
+ }
505
+ }
506
+ catch (error) {
507
+ putBack();
508
+ throw error;
258
509
  }
510
+ // A store reset lists the runs it removes from this record, read while the manager still answers:
511
+ // the broker is the store's only reader and is stopped by then. A failed read never blocks the stop.
512
+ const runs = manager ? await readStackRuns(journal0.space) : { observedAt: new Date().toISOString(), read: false, reason: "the stack's manager was not running" };
259
513
  // An earlier operation with no outcome is recorded as failed from its members' evidence first.
260
514
  const { snapshot: settledSnapshot, settled } = settleStackOperation(lock, previous);
261
515
  // A replacement an earlier `up` journaled is resolved from its own record, as the stop planned it.
262
- let journal = { ...settledSnapshot.journal, operation: newStackOperation("down", withAgents), members: withSettledMembers(settledSnapshot.journal, undefined).members.map((row) => ({ ...row, state: row.instanceId === null ? "not-attempted" : "planned", code: undefined })), updatedAt: new Date().toISOString() };
516
+ let journal = { ...settledSnapshot.journal, operation: { ...newStackOperation("down", withAgents), runs }, members: withSettledMembers(settledSnapshot.journal, undefined).members.map((row) => ({ ...row, state: row.instanceId === null ? "not-attempted" : "planned", code: undefined })), updatedAt: new Date().toISOString() };
263
517
  let snapshot = writeStackJournal(root, settledSnapshot, journal);
264
518
  const mark = (role, change) => {
265
519
  journal = { ...journal, members: journal.members.map((row) => row.role === role ? { ...row, ...change } : row), updatedAt: new Date().toISOString() };
@@ -271,8 +525,11 @@ async function applyStackStop(root, values, presentation, interactive, withAgent
271
525
  };
272
526
  settle("applying");
273
527
  const changed = [];
528
+ // A member that outlived its SIGTERM grace was killed, which its record keeps; the receipt names it.
529
+ const killed = [];
274
530
  let failure;
275
531
  let deliveryCredentialKept = false;
532
+ let deliveryLease;
276
533
  for (const member of members) {
277
534
  const role = member.role;
278
535
  const holds = serviceDefinitionStore(journal.space).pin(member.definition);
@@ -294,13 +551,16 @@ async function applyStackStop(root, values, presentation, interactive, withAgent
294
551
  // Recheck the whole scope now that earlier members are confirmed stopped.
295
552
  scopeRefusals(journal);
296
553
  kernel = await prepareKernelServiceStop(member.definition, current);
297
- if (kernel && presentation !== "json")
298
- console.log(renderReport(kernelImpactView(kernel), presentation, terminalWidth(process.stdout)));
299
554
  }
300
555
  const stopped = await stopProcessService(member.definition, current, holds, { plan: role === "manager" ? member.native : undefined, withAgents: role === "manager" && withAgents }, { plan: kernel });
301
556
  mark(role, { state: stopped.noOp ? "already-stopped" : "stopped" });
302
557
  if (!stopped.noOp)
303
558
  changed.push(instanceProjection(stopped.instance));
559
+ const stop = stopped.instance.record.value.processStop;
560
+ if (!stopped.noOp && stop?.signal === "SIGKILL")
561
+ killed.push({ role, instanceId: stopped.instance.record.value.instanceId, pid: stop.process.pid });
562
+ if (role === "delivery" && !stopped.noOp)
563
+ deliveryLease = await deliveryLeaseAfterStop(journal.root, journal.space, journal.server);
304
564
  }
305
565
  catch (error) {
306
566
  const classified = isCommandFailure(error) ? error : undefined;
@@ -319,16 +579,19 @@ async function applyStackStop(root, values, presentation, interactive, withAgent
319
579
  catch { /* The reservation release is not confirmed; outcomes above stand. */ }
320
580
  }
321
581
  }
582
+ if (failure && !changed.length)
583
+ putBack();
322
584
  if (!failure) {
323
585
  // Shared cleanup only after the whole recorded set is confirmed stopped. An open stack never
324
586
  // had a delivery credential, so none is removed or claimed removed. Each step is idempotent.
325
- // A delivery daemon that was already gone never released shard 0, and its credential is how
326
- // the next up recognises that row as this folder's dead daemon's and waits it out, so it stays
327
- // until that up replaces it.
587
+ // A delivery daemon that was already gone never released shard 0, and one that was killed, or
588
+ // whose release a full store refused, left its row too. Its credential is how the next up
589
+ // recognises that row as this folder's stopped daemon's and waits it out, so it stays until that
590
+ // up replaces it, and it stays as well when the row could not be read.
328
591
  try {
329
592
  if (journal.mode !== "open") {
330
593
  const store = workspaceSecretStore(root), key = deliveryCredsKey(journal.space, { injected: false, root });
331
- if (journal.members.find((row) => row.role === "delivery")?.state === "already-stopped")
594
+ if (journal.members.find((row) => row.role === "delivery")?.state === "already-stopped" || deliveryLease === "held" || deliveryLease === "unread")
332
595
  deliveryCredentialKept = await store.get(key) !== undefined;
333
596
  else
334
597
  await store.delete(key);
@@ -343,10 +606,31 @@ async function applyStackStop(root, values, presentation, interactive, withAgent
343
606
  failure = new CommandFailure("partial", "OPERATION_PARTIAL", journal.mode === "open" ? "every member stopped, but the mesh registration cleanup did not confirm" : "every member stopped, but the delivery credential or mesh registration cleanup did not confirm", { target, changed, remedy: journal.mode === "open" ? "inspect the root's registry entry; nothing was retried" : "inspect the root's delivery credential and registry entry; nothing was retried" });
344
607
  }
345
608
  }
609
+ // A record whose process is gone, or whose pid now runs another start, fronts nothing, so a
610
+ // complete stop removes it, as a crashed member leaves its own.
611
+ let cleared = [];
612
+ if (!failure) {
613
+ try {
614
+ cleared = removeStaleLocalRecords(root, journal.space);
615
+ }
616
+ catch (error) {
617
+ failure = new CommandFailure("partial", "OPERATION_PARTIAL", `every member stopped, but a stale process record under the root was not removed (${error.message})`, { target, changed, remedy: "inspect the process records under the root's .cotal; nothing was retried" });
618
+ }
619
+ }
346
620
  settle(failure ? (failure.outcome === "unknown" ? "unknown" : failure.outcome === "partial" ? "partial" : failure.outcome === "failed" ? "failed" : "refused") : "completed");
347
- writeResult(presentation, { command: "down", target, result: { kind: "controller-stack-stop", ...target, operation: journal.operation, withAgents, members: journal.members, changed, managerImpact: manager?.native ?? null, atomic: false, cleanup: failure ? "not-confirmed" : journal.mode === "open" ? "registration-removed-no-delivery-credential" : deliveryCredentialKept ? "registration-removed-delivery-credential-kept" : "delivery-credential-and-registration-removed", admittedRestore: admittedRestore ?? null, settledOperation: settled ?? null }, ...(settled || abandoned ? { warnings: [...abandonWarnings, ...(settled ? [{ code: "OPERATION_SETTLED", target: { ...target, operation: settled.operation.id }, message: stackSettlementNotice(settled) }] : [])] } : {}), ...(failure ? { failure, completeness: "partial" } : changed.length ? {} : { noOp: true }) }, (result) => ({ sections: [...restoreNotice(admittedRestore), { title: failure ? "Controller stack stop incomplete" : changed.length ? "Controller stack stopped" : "Controller stack was not running; nothing was stopped", blocks: [
348
- { kind: "table", columns: [{ key: "role", label: "Member" }, { key: "instance", label: "Full instance" }, { key: "state", label: "Result" }], rows: result.members.filter((row) => row.instanceId !== null).map((row) => ({ role: row.role, instance: row.instanceId ?? "none", state: { text: row.state.replaceAll("-", " "), tone: ["stopped", "already-stopped"].includes(row.state) ? "ok" : ["refused", "failed"].includes(row.state) ? "failed" : "waiting" } })) },
349
- { kind: "lines", lines: ["A returned native manager stop and an observed broker exit are not proof of authority, lease, store or descendant cleanup. A member already gone was recorded without a signal. The stack journal and the saved definitions remain; the next bare cotal up reuses them."] },
350
- ] }] }));
621
+ const warnings = [
622
+ ...(settled || abandoned || stranded || cleared.length ? [
623
+ ...abandonWarnings,
624
+ ...(settled ? [{ code: "OPERATION_SETTLED", target: { ...target, operation: settled.operation.id }, message: stackSettlementNotice(settled) }] : []),
625
+ ...(stranded ? [strandedNotice(journal0, stranded.previous)] : []),
626
+ ...cleared.map((row) => staleWarning(root, row)),
627
+ ] : []),
628
+ ...killed.map(({ role, instanceId, pid }) => ({ code: "STOP_ESCALATED", target: { ...target, role, instanceId, pid }, message: `the ${role} member, pid ${pid}, did not exit within ${PROCESS_STOP_GRACE_MS / 1000} s of SIGTERM, so it was stopped with SIGKILL` })),
629
+ ...(deliveryLease === "unread" ? [{ code: "DELIVERY_LEASE_UNREAD", target, message: "the delivery lease could not be read after the delivery member stopped, so its credential was kept; the next up waits out a lease row that still names it" }] : []),
630
+ ...await readinessAddressSurvivors(journal.space),
631
+ ];
632
+ writeResult(presentation, { command: "down", target, result: { kind: "controller-stack-stop", ...target, operation: journal.operation, withAgents, members: journal.members, changed, managerImpact: manager?.native ?? null, atomic: false, cleanup: failure ? "not-confirmed" : journal.mode === "open" ? "registration-removed-no-delivery-credential" : deliveryCredentialKept ? "registration-removed-delivery-credential-kept" : "delivery-credential-and-registration-removed", admittedRestore: admittedRestore ?? null, settledOperation: settled ?? null }, ...(warnings.length ? { warnings } : {}), ...(failure ? { failure, completeness: "partial" } : changed.length ? {} : { noOp: true }) }, (result) => ({ sections: [...restoreNotice(admittedRestore), { title: failure ? "Controller stack stop incomplete" : changed.length ? "Controller stack stopped" : "Controller stack was not running; nothing was stopped", blocks: [
633
+ { kind: "table", columns: [{ key: "role", label: "Member" }, { key: "instance", label: "Full instance" }, { key: "state", label: "Result" }], rows: result.members.filter((row) => row.instanceId !== null).sort((a, b) => STOP_ORDER.indexOf(a.role) - STOP_ORDER.indexOf(b.role)).map((row) => ({ role: row.role, instance: row.instanceId ?? "none", state: { text: killed.some((k) => k.role === row.role) ? "stopped with SIGKILL" : row.state.replaceAll("-", " "), tone: ["stopped", "already-stopped"].includes(row.state) ? "ok" : ["refused", "failed"].includes(row.state) ? "failed" : "waiting" } })) },
634
+ ] }, ...(failure ? [] : [{ title: "Next", blocks: [{ kind: "commands", items: [{ command: `cotal up${interruptedUpLeftManagerOut(previous.journal) ? " --no-manager" : ""}`, description: "Start the stack again from its journal and saved definitions" }] }] }])] }));
351
635
  }
352
636
  //# sourceMappingURL=stack-down.js.map