@cotal-ai/cli 0.100.2 → 0.101.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 (618) 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 +263 -129
  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 +344 -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 +135 -27
  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 +130 -31
  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 +45 -4
  447. package/dist/lib/manager-choice.d.ts.map +1 -1
  448. package/dist/lib/manager-choice.js +214 -24
  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-definitions.d.ts +16 -3
  512. package/dist/lib/service-definitions.d.ts.map +1 -1
  513. package/dist/lib/service-definitions.js +99 -27
  514. package/dist/lib/service-definitions.js.map +1 -1
  515. package/dist/lib/service-instances.d.ts +13 -1
  516. package/dist/lib/service-instances.d.ts.map +1 -1
  517. package/dist/lib/service-instances.js +56 -12
  518. package/dist/lib/service-instances.js.map +1 -1
  519. package/dist/lib/service-presets.d.ts.map +1 -1
  520. package/dist/lib/service-presets.js +16 -0
  521. package/dist/lib/service-presets.js.map +1 -1
  522. package/dist/lib/service-process.d.ts +51 -8
  523. package/dist/lib/service-process.d.ts.map +1 -1
  524. package/dist/lib/service-process.js +385 -48
  525. package/dist/lib/service-process.js.map +1 -1
  526. package/dist/lib/space-streams.d.ts +18 -0
  527. package/dist/lib/space-streams.d.ts.map +1 -0
  528. package/dist/lib/space-streams.js +35 -0
  529. package/dist/lib/space-streams.js.map +1 -0
  530. package/dist/lib/spawn-defaults.d.ts +25 -1
  531. package/dist/lib/spawn-defaults.d.ts.map +1 -1
  532. package/dist/lib/spawn-defaults.js +37 -1
  533. package/dist/lib/spawn-defaults.js.map +1 -1
  534. package/dist/lib/stack-journal.d.ts +157 -14
  535. package/dist/lib/stack-journal.d.ts.map +1 -1
  536. package/dist/lib/stack-journal.js +406 -49
  537. package/dist/lib/stack-journal.js.map +1 -1
  538. package/dist/lib/stack-listeners.d.ts +17 -0
  539. package/dist/lib/stack-listeners.d.ts.map +1 -0
  540. package/dist/lib/stack-listeners.js +54 -0
  541. package/dist/lib/stack-listeners.js.map +1 -0
  542. package/dist/lib/stack-members.d.ts +13 -0
  543. package/dist/lib/stack-members.d.ts.map +1 -0
  544. package/dist/lib/stack-members.js +24 -0
  545. package/dist/lib/stack-members.js.map +1 -0
  546. package/dist/lib/stack-resume.d.ts.map +1 -1
  547. package/dist/lib/stack-resume.js +5 -2
  548. package/dist/lib/stack-resume.js.map +1 -1
  549. package/dist/lib/stack-runs.d.ts +34 -0
  550. package/dist/lib/stack-runs.d.ts.map +1 -0
  551. package/dist/lib/stack-runs.js +75 -0
  552. package/dist/lib/stack-runs.js.map +1 -0
  553. package/dist/lib/status.d.ts +11 -0
  554. package/dist/lib/status.d.ts.map +1 -1
  555. package/dist/lib/status.js +4 -5
  556. package/dist/lib/status.js.map +1 -1
  557. package/dist/lib/stdout-owner.d.ts +12 -3
  558. package/dist/lib/stdout-owner.d.ts.map +1 -1
  559. package/dist/lib/stdout-owner.js +33 -5
  560. package/dist/lib/stdout-owner.js.map +1 -1
  561. package/dist/lib/store-dir.d.ts +68 -4
  562. package/dist/lib/store-dir.d.ts.map +1 -1
  563. package/dist/lib/store-dir.js +253 -17
  564. package/dist/lib/store-dir.js.map +1 -1
  565. package/dist/lib/team-additive-attempt.d.ts +1 -1
  566. package/dist/lib/team-channel-removal.d.ts.map +1 -1
  567. package/dist/lib/team-channel-removal.js +4 -0
  568. package/dist/lib/team-channel-removal.js.map +1 -1
  569. package/dist/lib/team-deploy-inspection.d.ts +13 -0
  570. package/dist/lib/team-deploy-inspection.d.ts.map +1 -1
  571. package/dist/lib/team-deploy-inspection.js +12 -0
  572. package/dist/lib/team-deploy-inspection.js.map +1 -1
  573. package/dist/lib/team-text.d.ts +6 -0
  574. package/dist/lib/team-text.d.ts.map +1 -0
  575. package/dist/lib/team-text.js +36 -0
  576. package/dist/lib/team-text.js.map +1 -0
  577. package/dist/lib/transient.d.ts +14 -8
  578. package/dist/lib/transient.d.ts.map +1 -1
  579. package/dist/lib/transient.js +72 -11
  580. package/dist/lib/transient.js.map +1 -1
  581. package/dist/lib/unusable-file.d.ts +13 -0
  582. package/dist/lib/unusable-file.d.ts.map +1 -0
  583. package/dist/lib/unusable-file.js +12 -0
  584. package/dist/lib/unusable-file.js.map +1 -0
  585. package/dist/lib/up-report.d.ts +6 -0
  586. package/dist/lib/up-report.d.ts.map +1 -1
  587. package/dist/lib/up-report.js +13 -0
  588. package/dist/lib/up-report.js.map +1 -1
  589. package/dist/lib/verdict.d.ts +14 -0
  590. package/dist/lib/verdict.d.ts.map +1 -0
  591. package/dist/lib/verdict.js +15 -0
  592. package/dist/lib/verdict.js.map +1 -0
  593. package/dist/managed-handoff.d.ts +11 -6
  594. package/dist/managed-handoff.d.ts.map +1 -1
  595. package/dist/managed-handoff.js +27 -18
  596. package/dist/managed-handoff.js.map +1 -1
  597. package/dist/render.d.ts +5 -2
  598. package/dist/render.d.ts.map +1 -1
  599. package/dist/render.js +44 -10
  600. package/dist/render.js.map +1 -1
  601. package/dist/telemetry.d.ts +4 -3
  602. package/dist/telemetry.d.ts.map +1 -1
  603. package/dist/telemetry.js +14 -6
  604. package/dist/telemetry.js.map +1 -1
  605. package/dist/ui.d.ts +3 -2
  606. package/dist/ui.d.ts.map +1 -1
  607. package/dist/ui.js +6 -4
  608. package/dist/ui.js.map +1 -1
  609. package/dist/view/mesh-view.d.ts.map +1 -1
  610. package/dist/view/mesh-view.js +4 -1
  611. package/dist/view/mesh-view.js.map +1 -1
  612. package/dist/watch-data.d.ts +9 -1
  613. package/dist/watch-data.d.ts.map +1 -1
  614. package/dist/watch-data.js +17 -3
  615. package/dist/watch-data.js.map +1 -1
  616. package/dist/watch-json.js +4 -3
  617. package/dist/watch-json.js.map +1 -1
  618. 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");
@@ -57,12 +108,12 @@ function readMembers(journal) {
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}`;
59
110
  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 });
111
+ 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
112
  const retained = retainedStopRequest(instance.record.value);
62
113
  if (instance.record.value.state === "stopping" || retained)
63
114
  throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", retained?.publication === "unknown"
64
115
  ? "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 });
116
+ : "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
117
  assertNoServiceUnitAttempts(journal.space, row.definition);
67
118
  members.push({ role: row.role, definition, instance, live: state === "running" });
68
119
  }
@@ -70,26 +121,59 @@ function readMembers(journal) {
70
121
  }
71
122
  /** A live manager's agent impact is read through the broker on an authenticated stack. When the
72
123
  * 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. */
124
+ * the broker back while keeping the live manager. A broker whose process runs but sends no
125
+ * greeting, as a suspended one does, is named with its pid; the broker stops last, so it is not
126
+ * signalled here. */
74
127
  async function managerImpact(journal, members, manager, withAgents) {
75
128
  try {
76
129
  return await prepareNativeServiceStop(manager.definition, manager.instance, withAgents);
77
130
  }
78
131
  catch (caught) {
132
+ if (storeRefusedWrite(caught)) {
133
+ let store;
134
+ try {
135
+ store = recordedStore(journal.root, journal.space);
136
+ }
137
+ catch {
138
+ store = undefined;
139
+ }
140
+ throw fullStoreStop(journal, manager, store);
141
+ }
142
+ // Nothing was submitted: the stop's credential could not be recorded on a broker without JetStream.
143
+ const disabled = jetStreamDisabled(journal.root, journal.space);
144
+ if (disabled && !(isCommandFailure(caught) && caught.outcome !== "unknown"))
145
+ throw disabledJetStreamStop(journal, manager, disabled);
79
146
  // The read connects through the broker, so a gone broker surfaces as the connect refusal.
80
147
  const error = isConnectRefusal(caught) ? caught.failure() : caught;
81
- if (members.some((member) => member.role === "broker" && member.live) || !isCommandFailure(error))
148
+ const broker = members.find((member) => member.role === "broker" && member.live);
149
+ const pid = broker?.instance.record.value.process?.pid;
150
+ if (pid !== undefined && isCommandFailure(error) && !await readNatsInfoGreeting(journal.server, 2000)) {
151
+ 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` });
152
+ }
153
+ if (broker || !isCommandFailure(error))
82
154
  throw caught;
83
155
  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
156
  }
85
157
  }
158
+ /** The full-store refusal of a stack's manager stop, before any member is stopped. Making room
159
+ * purges the space's channel history; a plain SIGTERM to the manager's own process needs no
160
+ * credential, so it stops the stack without that loss. */
161
+ function fullStoreStop(journal, manager, store) {
162
+ const pid = manager.instance.record.value.process?.pid;
163
+ 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` : ""}`);
164
+ }
165
+ /** The refusal of a stack's manager stop while its broker has JetStream disabled, before any member
166
+ * is stopped. */
167
+ function disabledJetStreamStop(journal, manager, write) {
168
+ 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);
169
+ }
86
170
  /** Everything outside the recorded members that would be cut off refuses before the first signal.
87
171
  * Returns a settled active restore of this stack that was admitted, for the result to name. */
88
172
  function scopeRefusals(journal) {
89
173
  const maintenance = stackMaintenanceFence(journal.root, journal);
90
174
  if (maintenance.fenced)
91
175
  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");
176
+ stackScopeRefusals(journal, "bare `cotal down`");
93
177
  return maintenance.admittedRestore;
94
178
  }
95
179
  /** A stack its own down stopped completely, with no recorded member and no other service instance of
@@ -110,9 +194,10 @@ function alreadyStopped(journal, members) {
110
194
  * record and its pid in the message and the remedy, because no command shows another space's
111
195
  * records; nothing is stopped, adopted or removed. A real --with-agents refuses too, because no
112
196
  * 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 = []) {
197
+ * --with-agents, or the root never started a stack. Its `preview` shows the no-op and warns with that
198
+ * refusal. The legacy route answers the same way. `warnings` report what this command changed before
199
+ * it found nothing running. */
200
+ export function nothingRunning(presentation, target, withAgents, warnings = [], preview = false) {
116
201
  // A root that names no space resolves to the default one, as `resolveSpace` answers.
117
202
  const remaining = recordedProcessesUnder(target.root, [target.space ?? DEFAULT_SPACE]);
118
203
  if (remaining.length) {
@@ -123,13 +208,52 @@ export function nothingRunning(presentation, target, withAgents, warnings = [])
123
208
  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
209
  });
125
210
  }
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: [
211
+ 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;
212
+ if (agents && !preview)
213
+ throw agents;
214
+ const shown = agents ? [...warnings, { code: agents.code, target, message: `the real stop would refuse: ${agents.message}; ${agents.remedy}` }] : warnings;
215
+ writeResult(presentation, { command: "down", target, result: { kind: "stack-not-running", ...target }, noOp: true, ...(shown.length ? { warnings: shown } : {}) }, () => ({ sections: [
129
216
  { title: `The stack in ${target.root} is not running`, blocks: [{ kind: "lines", lines: ["Nothing was stopped."] }] },
130
217
  { title: "Next", blocks: [{ kind: "commands", items: [{ command: "cotal up", description: "Start it" }] }] },
131
218
  ] }));
132
219
  }
220
+ /** The registration `cotal up` wrote for this stack is how its members' stops reach it. An older
221
+ * `meshes rm --force` dropped it, and an older `meshes add --force` replaced it with one added by
222
+ * hand. When it is missing, or a hand-added one names this same root and broker, the stop rebuilds
223
+ * it from the journal, but only while the stack's broker is the exact launch the journal records
224
+ * there. A hand-added registration of another address or folder is not replaced: removing it takes
225
+ * an act that names it. One another stack started, or a catalog lists, resolves as before. */
226
+ function strandedRegistration(journal, members) {
227
+ const registered = findMesh(journal.space);
228
+ if (registered && registered.origin !== "manual" || !members.some((member) => member.live))
229
+ return undefined;
230
+ const target = { root: journal.root, space: journal.space, server: journal.server };
231
+ if (registered && (registered.server !== journal.server || canonicalRoot(registered.root) !== journal.root))
232
+ 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` });
233
+ const what = registered ? "is registered by hand" : "has no registration";
234
+ if (journal.mode === "user")
235
+ 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}\`` });
236
+ const broker = members.find((member) => member.role === "broker");
237
+ if (!broker?.live || !brokerLaunchAt(journal.space, broker.instance.name, broker.instance.record.value.launchRequestId, journal.root, journal.server))
238
+ 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}\`` });
239
+ const tlsRequired = readBrokerPolicy(journal.root)?.transport.kind === "tls-required";
240
+ return { previous: registered, entry: {
241
+ space: journal.space, server: journal.server, root: journal.root, mode: journal.mode, origin: "up", ts: new Date().toISOString(),
242
+ ...(tlsRequired ? { tlsRequired: true } : {}),
243
+ ...(journal.broker ? { storeDir: journal.broker.storeDir, ...(journal.broker.maxFileStore !== undefined ? { maxFileStore: journal.broker.maxFileStore } : {}), ...(journal.broker.host !== undefined ? { attachHost: journal.broker.host } : {}) } : {}),
244
+ } };
245
+ }
246
+ /** A stale process record a complete stop removed, or for a preview, one it would remove. */
247
+ function staleWarning(root, row, preview = false) {
248
+ return { code: "STALE_PROCESS_RECORD", target: { root, path: row.path, pid: row.pid, state: row.state }, message: staleRecordNotice(row, preview) };
249
+ }
250
+ /** What a stop that rebuilt the registration says it did, or for a preview, what it would do. */
251
+ function strandedNotice(journal, previous, preview = false) {
252
+ const used = preview ? "the stop would use" : "the stop used";
253
+ return { code: "REGISTRATION_REBUILT", target: { root: journal.root, space: journal.space, server: journal.server }, message: previous
254
+ ? `"${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`
255
+ : `"${journal.space}" ${preview ? "has" : "had"} no registration; ${used} the one \`cotal up\` writes for this stack, rebuilt from its journal` };
256
+ }
133
257
  /** What an abandoned member stop leaves unconfirmed. */
134
258
  function abandonNotice(role, abandonment) {
135
259
  const receipts = abandonment.receipts.length ? `only ${abandonment.receipts.join(" and ")} receipts` : "no receipt";
@@ -164,15 +288,42 @@ export async function stackDown(rootInput, values) {
164
288
  // The preview reads without the lock and writes nothing. The real stop holds the root's
165
289
  // maintenance lock from its first read to its last write, so no other whole-stack operation runs.
166
290
  if (values["dry-run"] === true)
167
- return previewStackStop(root, values, presentation, withAgents);
168
- const lock = acquireStackOperationLock(root);
291
+ return await previewStackStop(root, values, presentation, withAgents);
292
+ // A signal ends the stop where it is, and the notice names the members that still run. It is
293
+ // installed before the lock, so no moment of the stop exits without it.
294
+ const release = noticeOnInterrupt(() => stackStopInterruptNotice(root));
169
295
  try {
170
- await applyStackStop(root, values, presentation, interactive, withAgents, lock);
296
+ // A busy root's refusal names the recorded space, as every refusal after the lock does.
297
+ const recorded = readStackJournal(root)?.journal.space;
298
+ if (recorded !== undefined)
299
+ recordOperationSpace(recorded);
300
+ const lock = acquireStackOperationLock(root);
301
+ try {
302
+ await applyStackStop(root, values, presentation, interactive, withAgents, lock);
303
+ }
304
+ finally {
305
+ releaseMaintenanceLock(lock);
306
+ }
171
307
  }
172
308
  finally {
173
- releaseMaintenanceLock(lock);
309
+ release();
174
310
  }
175
311
  }
312
+ /** What an interrupted bare down left: the members still running, and the down that finishes it. A
313
+ * member it left `stopping` under a signal is stopped again by that down while it runs, and once it
314
+ * has exited only `--abandon-stop` settles it, so the notice names both. */
315
+ function stackStopInterruptNotice(root) {
316
+ const space = readStackJournal(root)?.journal.space;
317
+ const running = space === undefined ? [] : runningStackRoles(space);
318
+ const signalled = space === undefined ? undefined : STACK_ROLES.flatMap((role) => serviceInstances(space, STACK_DEFINITION[role])
319
+ .filter(({ record: { value } }) => !value.nativeStopRequired && value.state === "stopping").map(({ record: { value } }) => ({ role, requestId: value.requestId })))[0];
320
+ const left = running.length ? `${running.join(", ")} ${running.length === 1 ? "is" : "are"} still running` : "no member is running";
321
+ if (signalled)
322
+ 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.`;
323
+ return running.length
324
+ ? `Interrupted while stopping the stack in ${root}; ${left}. Run cotal down --yes to finish the stop.`
325
+ : `Interrupted while stopping the stack in ${root}; no member is running. Run cotal down --yes to finish its cleanup.`;
326
+ }
176
327
  /** The recorded stack this stop targets, with every refusal that needs no lock or write. An earlier
177
328
  * preserve or resume with no outcome is decided by its own maintenance attempt; an earlier up or
178
329
  * down with none is classified read-only from its members, and refuses if any is unresolved. */
@@ -181,9 +332,17 @@ function stopTarget(root, values) {
181
332
  if (!previous)
182
333
  throw new CommandFailure("refused", "TARGET_NOT_FOUND", "this root has no controller stack journal", { target: { root } });
183
334
  const journal0 = previous.journal;
335
+ if (values.space !== undefined && values.space !== journal0.space) {
336
+ const space = String(values.space), elsewhere = stackRootElsewhere(space, root);
337
+ recordOperationSpace(space);
338
+ 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`, {
339
+ target: { root, space, recordedSpace: journal0.space, ...(elsewhere ? { stackRoot: elsewhere } : {}) },
340
+ 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`,
341
+ });
342
+ }
184
343
  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 } });
344
+ if (stackRunsUnderOtherHome(root, journal0))
345
+ 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
346
  if (stackOperationUnsettled(journal0) && journal0.operation.kind !== "up" && journal0.operation.kind !== "down")
188
347
  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
348
  const settlement = previewStackSettlement(journal0);
@@ -193,28 +352,82 @@ function stopTarget(root, values) {
193
352
  const members = readMembers(scoped);
194
353
  return { previous, journal0: scoped, settlement, members, target: { root, space: journal0.space, server: journal0.server } };
195
354
  }
196
- function previewStackStop(root, values, presentation, withAgents) {
355
+ async function previewStackStop(root, values, presentation, withAgents) {
197
356
  const { journal0, settlement, members, target } = stopTarget(root, values);
198
- if (alreadyStopped(journal0, members) || stackNeverStarted(journal0))
199
- return nothingRunning(presentation, target, false);
357
+ // As the real stop does, a stack its own down stopped refuses --with-agents unless that down took it.
358
+ const stopped = alreadyStopped(journal0, members);
359
+ if (stopped || stackNeverStarted(journal0))
360
+ return nothingRunning(presentation, target, stopped && withAgents && !journal0.operation.withAgents, [], true);
200
361
  // A preview reports what would refuse the real stop instead of refusing itself.
201
- let blocked, restore;
362
+ let blocked, restore, stranded;
202
363
  try {
203
364
  restore = scopeRefusals(journal0);
365
+ stranded = strandedRegistration(journal0, members);
366
+ assertJournalWritable(root, values);
367
+ assertServiceRecordsWritable(root, journal0.space, values);
204
368
  }
205
369
  catch (error) {
206
370
  if (!isCommandFailure(error))
207
371
  throw error;
208
372
  blocked = error;
209
373
  }
210
- const warnings = blocked ? [{ code: blocked.code, target: blocked.target, message: `the real stop would refuse: ${blocked.message}${blocked.remedy ? `; ${blocked.remedy}` : ""}` }] : [];
374
+ // A live manager's stop needs room in the store, so the preview reads how much the space holds.
375
+ const manager = members.find((member) => member.role === "manager" && member.live);
376
+ const brokerPid = members.find((member) => member.role === "broker" && member.live)?.instance.record.value.process?.pid;
377
+ if (!blocked && manager && brokerPid !== undefined && !processStopped(brokerPid)) {
378
+ // A broker that disabled JetStream answers no read of the store, so its own log decides first.
379
+ const disabled = jetStreamDisabled(root, journal0.space);
380
+ let used;
381
+ if (!disabled)
382
+ try {
383
+ used = await readStoredBytes(resolveMeshTarget(root, { space: journal0.space, readOnly: true }), "down-preview");
384
+ }
385
+ catch {
386
+ used = undefined;
387
+ }
388
+ const full = used === undefined ? undefined : storeFull(root, journal0.space, used);
389
+ if (disabled)
390
+ blocked = disabledJetStreamStop(journal0, manager, disabled);
391
+ else if (full)
392
+ blocked = fullStoreStop(journal0, manager, full);
393
+ }
394
+ const warnings = blocked ? [{ code: blocked.code, target: blocked.target, message: `the real stop would refuse: ${blocked.message}${blocked.remedy ? `; ${blocked.remedy}` : ""}` }]
395
+ : [...stranded ? [strandedNotice(journal0, stranded.previous, true)] : [], ...localRecords(root, journal0.space).filter((row) => row.state !== "live").map((row) => staleWarning(root, row, true))];
211
396
  // A preview that changes nothing succeeds. It is partial only in what it read: no provider and
212
397
  // no manager impact, which the real stop reads and confirms before any signal.
213
398
  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
399
  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."] }] }] };
400
+ 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
401
  });
217
402
  }
403
+ /** Whether shard 0 of the delivery lease still names the daemon this root's stored credential gave,
404
+ * read over an observer credential after the daemon's stop while the broker still runs. A daemon
405
+ * that was killed, or whose release write the broker refused, as a full store refuses it, leaves its
406
+ * row until the lease expires. The holder is the one that credential gives, never a name or pid.
407
+ * "unread" when the row could not be read. */
408
+ async function deliveryLeaseAfterStop(root, space, server) {
409
+ const store = workspaceSecretStore(root);
410
+ let ep;
411
+ try {
412
+ const creds = await store.get(deliveryCredsKey(space, { injected: false, root }));
413
+ if (creds === undefined)
414
+ return "released";
415
+ const auth = await getSpaceAuth(store, space);
416
+ if (!auth)
417
+ return "unread";
418
+ const id = newIdentity();
419
+ 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" } });
420
+ ep.on("error", () => { });
421
+ await ep.start();
422
+ return (await ep.readDeliveryLease(0))?.holder === deliveryLeaseHolderFor(creds) ? "held" : "released";
423
+ }
424
+ catch {
425
+ return "unread";
426
+ }
427
+ finally {
428
+ await ep?.stop().catch(() => { });
429
+ }
430
+ }
218
431
  async function applyStackStop(root, values, presentation, interactive, withAgents, lock) {
219
432
  // A member stop an earlier down could not confirm in time is settled from its own receipt first.
220
433
  const recorded = readStackJournal(root)?.journal;
@@ -223,43 +436,80 @@ async function applyStackStop(root, values, presentation, interactive, withAgent
223
436
  await settleRetainedStackStops(ours);
224
437
  // A stop no receipt can settle is abandoned only when the operator names its request.
225
438
  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) }] : [];
439
+ // So is a launch whose record names no process, when the operator names its instance.
440
+ const launch = ours && typeof values["abandon-launch"] === "string" ? abandonUnresolvedStackLaunch(ours, values["abandon-launch"]) : undefined;
441
+ const abandonWarnings = [
442
+ ...(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
+ ...(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` }] : []),
444
+ ];
227
445
  const { previous, journal0, settlement, members, target } = stopTarget(root, values);
228
446
  // The completed down that stopped the stack also stopped its agents when it took --with-agents, so
229
447
  // a repeat has nothing left to stop. A stack that never started has no agents either.
230
448
  if (alreadyStopped(journal0, members))
231
- return nothingRunning(presentation, target, withAgents && !journal0.operation.withAgents, abandonWarnings);
449
+ return nothingRunning(presentation, target, withAgents && !journal0.operation.withAgents, [...abandonWarnings, ...await readinessAddressSurvivors(journal0.space)]);
232
450
  if (stackNeverStarted(journal0))
233
451
  return nothingRunning(presentation, target, false, abandonWarnings);
452
+ // A stopped broker takes connections and never answers, so every read through it would wait out
453
+ // its budget and the broker's own stop would wait on a signal it cannot act on.
454
+ const broker = members.find((member) => member.role === "broker" && member.live);
455
+ const brokerPid = broker?.instance.record.value.process?.pid;
456
+ if (brokerPid !== undefined && processStopped(brokerPid))
457
+ 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
458
  const admittedRestore = scopeRefusals(journal0);
459
+ assertJournalWritable(root, values);
460
+ assertServiceRecordsWritable(root, journal0.space, values);
235
461
  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" });
462
+ 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" });
463
+ // A missing or hand-added registration is rebuilt from the journal before anything resolves the
464
+ // members, and put back as it was when the stop ends before any member stops.
465
+ const stranded = strandedRegistration(journal0, members);
466
+ if (stranded)
467
+ recordMesh(stranded.entry);
468
+ const putBack = () => {
469
+ if (!stranded)
470
+ return;
471
+ if (stranded.previous)
472
+ recordMesh(stranded.previous);
473
+ else
474
+ removeMesh(journal0.space);
475
+ };
237
476
  // Complete native impact before confirmation. The broker's own kernel scope cannot be prepared
238
477
  // while its dependants run; it is recomputed after they stop and refuses on any change then.
239
478
  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;
479
+ try {
480
+ if (manager) {
481
+ manager.native = await managerImpact(journal0, members, manager, withAgents);
482
+ if (!manager.native)
483
+ 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
484
  }
485
+ else if (withAgents)
486
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "--with-agents needs the stack's live manager and its native impact; no member was stopped", { target });
487
+ if (!values.yes) {
488
+ // What the prompt asks to confirm. The receipt names the mesh, so the plan does not.
489
+ if (presentation !== "json") {
490
+ console.log(renderReport({ sections: planView(journal0, members, withAgents, settlement).sections }, presentation, terminalWidth(process.stdout)));
491
+ if (manager?.native)
492
+ console.log(renderReport(nativeImpactView(manager.native), presentation, terminalWidth(process.stdout)));
493
+ }
494
+ 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 });
495
+ if (prompts.isCancel(answer) || !answer) {
496
+ putBack();
497
+ 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));
498
+ return;
499
+ }
500
+ }
501
+ }
502
+ catch (error) {
503
+ putBack();
504
+ throw error;
258
505
  }
506
+ // A store reset lists the runs it removes from this record, read while the manager still answers:
507
+ // the broker is the store's only reader and is stopped by then. A failed read never blocks the stop.
508
+ const runs = manager ? await readStackRuns(journal0.space) : { observedAt: new Date().toISOString(), read: false, reason: "the stack's manager was not running" };
259
509
  // An earlier operation with no outcome is recorded as failed from its members' evidence first.
260
510
  const { snapshot: settledSnapshot, settled } = settleStackOperation(lock, previous);
261
511
  // 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() };
512
+ 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
513
  let snapshot = writeStackJournal(root, settledSnapshot, journal);
264
514
  const mark = (role, change) => {
265
515
  journal = { ...journal, members: journal.members.map((row) => row.role === role ? { ...row, ...change } : row), updatedAt: new Date().toISOString() };
@@ -271,8 +521,11 @@ async function applyStackStop(root, values, presentation, interactive, withAgent
271
521
  };
272
522
  settle("applying");
273
523
  const changed = [];
524
+ // A member that outlived its SIGTERM grace was killed, which its record keeps; the receipt names it.
525
+ const killed = [];
274
526
  let failure;
275
527
  let deliveryCredentialKept = false;
528
+ let deliveryLease;
276
529
  for (const member of members) {
277
530
  const role = member.role;
278
531
  const holds = serviceDefinitionStore(journal.space).pin(member.definition);
@@ -294,13 +547,16 @@ async function applyStackStop(root, values, presentation, interactive, withAgent
294
547
  // Recheck the whole scope now that earlier members are confirmed stopped.
295
548
  scopeRefusals(journal);
296
549
  kernel = await prepareKernelServiceStop(member.definition, current);
297
- if (kernel && presentation !== "json")
298
- console.log(renderReport(kernelImpactView(kernel), presentation, terminalWidth(process.stdout)));
299
550
  }
300
551
  const stopped = await stopProcessService(member.definition, current, holds, { plan: role === "manager" ? member.native : undefined, withAgents: role === "manager" && withAgents }, { plan: kernel });
301
552
  mark(role, { state: stopped.noOp ? "already-stopped" : "stopped" });
302
553
  if (!stopped.noOp)
303
554
  changed.push(instanceProjection(stopped.instance));
555
+ const stop = stopped.instance.record.value.processStop;
556
+ if (!stopped.noOp && stop?.signal === "SIGKILL")
557
+ killed.push({ role, instanceId: stopped.instance.record.value.instanceId, pid: stop.process.pid });
558
+ if (role === "delivery" && !stopped.noOp)
559
+ deliveryLease = await deliveryLeaseAfterStop(journal.root, journal.space, journal.server);
304
560
  }
305
561
  catch (error) {
306
562
  const classified = isCommandFailure(error) ? error : undefined;
@@ -319,16 +575,19 @@ async function applyStackStop(root, values, presentation, interactive, withAgent
319
575
  catch { /* The reservation release is not confirmed; outcomes above stand. */ }
320
576
  }
321
577
  }
578
+ if (failure && !changed.length)
579
+ putBack();
322
580
  if (!failure) {
323
581
  // Shared cleanup only after the whole recorded set is confirmed stopped. An open stack never
324
582
  // 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.
583
+ // A delivery daemon that was already gone never released shard 0, and one that was killed, or
584
+ // whose release a full store refused, left its row too. Its credential is how the next up
585
+ // recognises that row as this folder's stopped daemon's and waits it out, so it stays until that
586
+ // up replaces it, and it stays as well when the row could not be read.
328
587
  try {
329
588
  if (journal.mode !== "open") {
330
589
  const store = workspaceSecretStore(root), key = deliveryCredsKey(journal.space, { injected: false, root });
331
- if (journal.members.find((row) => row.role === "delivery")?.state === "already-stopped")
590
+ if (journal.members.find((row) => row.role === "delivery")?.state === "already-stopped" || deliveryLease === "held" || deliveryLease === "unread")
332
591
  deliveryCredentialKept = await store.get(key) !== undefined;
333
592
  else
334
593
  await store.delete(key);
@@ -343,10 +602,31 @@ async function applyStackStop(root, values, presentation, interactive, withAgent
343
602
  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
603
  }
345
604
  }
605
+ // A record whose process is gone, or whose pid now runs another start, fronts nothing, so a
606
+ // complete stop removes it, as a crashed member leaves its own.
607
+ let cleared = [];
608
+ if (!failure) {
609
+ try {
610
+ cleared = removeStaleLocalRecords(root, journal.space);
611
+ }
612
+ catch (error) {
613
+ 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" });
614
+ }
615
+ }
346
616
  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
- ] }] }));
617
+ const warnings = [
618
+ ...(settled || abandoned || stranded || cleared.length ? [
619
+ ...abandonWarnings,
620
+ ...(settled ? [{ code: "OPERATION_SETTLED", target: { ...target, operation: settled.operation.id }, message: stackSettlementNotice(settled) }] : []),
621
+ ...(stranded ? [strandedNotice(journal0, stranded.previous)] : []),
622
+ ...cleared.map((row) => staleWarning(root, row)),
623
+ ] : []),
624
+ ...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` })),
625
+ ...(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" }] : []),
626
+ ...await readinessAddressSurvivors(journal.space),
627
+ ];
628
+ 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: [
629
+ { 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" } })) },
630
+ ] }, ...(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
631
  }
352
632
  //# sourceMappingURL=stack-down.js.map