@cotal-ai/cli 0.90.1 → 0.92.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 (775) hide show
  1. package/dist/chat/chat-view.d.ts +17 -0
  2. package/dist/chat/chat-view.d.ts.map +1 -0
  3. package/dist/chat/chat-view.js +179 -0
  4. package/dist/chat/chat-view.js.map +1 -0
  5. package/dist/chat/controller.d.ts +20 -0
  6. package/dist/chat/controller.d.ts.map +1 -0
  7. package/dist/chat/controller.js +132 -0
  8. package/dist/chat/controller.js.map +1 -0
  9. package/dist/chat/engine.d.ts +110 -0
  10. package/dist/chat/engine.d.ts.map +1 -0
  11. package/dist/chat/engine.js +224 -0
  12. package/dist/chat/engine.js.map +1 -0
  13. package/dist/chat/frontend.d.ts +35 -0
  14. package/dist/chat/frontend.d.ts.map +1 -0
  15. package/dist/chat/frontend.js +166 -0
  16. package/dist/chat/frontend.js.map +1 -0
  17. package/dist/chat/native-session.d.ts +93 -0
  18. package/dist/chat/native-session.d.ts.map +1 -0
  19. package/dist/chat/native-session.js +389 -0
  20. package/dist/chat/native-session.js.map +1 -0
  21. package/dist/chat/open-session.d.ts +8 -0
  22. package/dist/chat/open-session.d.ts.map +1 -0
  23. package/dist/chat/open-session.js +120 -0
  24. package/dist/chat/open-session.js.map +1 -0
  25. package/dist/chat/picker.d.ts +35 -0
  26. package/dist/chat/picker.d.ts.map +1 -0
  27. package/dist/chat/picker.js +99 -0
  28. package/dist/chat/picker.js.map +1 -0
  29. package/dist/chat/plain.d.ts +15 -0
  30. package/dist/chat/plain.d.ts.map +1 -0
  31. package/dist/chat/plain.js +249 -0
  32. package/dist/chat/plain.js.map +1 -0
  33. package/dist/chat/session.d.ts +222 -0
  34. package/dist/chat/session.d.ts.map +1 -0
  35. package/dist/chat/session.js +2 -0
  36. package/dist/chat/session.js.map +1 -0
  37. package/dist/chat/static-session.d.ts +61 -0
  38. package/dist/chat/static-session.d.ts.map +1 -0
  39. package/dist/chat/static-session.js +212 -0
  40. package/dist/chat/static-session.js.map +1 -0
  41. package/dist/chat/stdio-io.d.ts +35 -0
  42. package/dist/chat/stdio-io.d.ts.map +1 -0
  43. package/dist/chat/stdio-io.js +176 -0
  44. package/dist/chat/stdio-io.js.map +1 -0
  45. package/dist/chat/stdio.d.ts +173 -0
  46. package/dist/chat/stdio.d.ts.map +1 -0
  47. package/dist/chat/stdio.js +401 -0
  48. package/dist/chat/stdio.js.map +1 -0
  49. package/dist/chat/user-session.d.ts +21 -0
  50. package/dist/chat/user-session.d.ts.map +1 -0
  51. package/dist/chat/user-session.js +180 -0
  52. package/dist/chat/user-session.js.map +1 -0
  53. package/dist/chat/view.d.ts +217 -0
  54. package/dist/chat/view.d.ts.map +1 -0
  55. package/dist/chat/view.js +433 -0
  56. package/dist/chat/view.js.map +1 -0
  57. package/dist/command.d.ts +11 -3
  58. package/dist/command.d.ts.map +1 -1
  59. package/dist/command.js +395 -147
  60. package/dist/command.js.map +1 -1
  61. package/dist/commands/agents.d.ts +103 -11
  62. package/dist/commands/agents.d.ts.map +1 -1
  63. package/dist/commands/agents.js +506 -251
  64. package/dist/commands/agents.js.map +1 -1
  65. package/dist/commands/app-identity.d.ts.map +1 -1
  66. package/dist/commands/app-identity.js +10 -1
  67. package/dist/commands/app-identity.js.map +1 -1
  68. package/dist/commands/backup-maintenance.d.ts +4 -0
  69. package/dist/commands/backup-maintenance.d.ts.map +1 -0
  70. package/dist/commands/backup-maintenance.js +93 -0
  71. package/dist/commands/backup-maintenance.js.map +1 -0
  72. package/dist/commands/backup-read.d.ts +4 -0
  73. package/dist/commands/backup-read.d.ts.map +1 -0
  74. package/dist/commands/backup-read.js +30 -0
  75. package/dist/commands/backup-read.js.map +1 -0
  76. package/dist/commands/backup-restore.d.ts +7 -0
  77. package/dist/commands/backup-restore.d.ts.map +1 -0
  78. package/dist/commands/backup-restore.js +78 -0
  79. package/dist/commands/backup-restore.js.map +1 -0
  80. package/dist/commands/backup.d.ts +2 -1
  81. package/dist/commands/backup.d.ts.map +1 -1
  82. package/dist/commands/backup.js +123 -32
  83. package/dist/commands/backup.js.map +1 -1
  84. package/dist/commands/channel-members.d.ts +8 -0
  85. package/dist/commands/channel-members.d.ts.map +1 -0
  86. package/dist/commands/channel-members.js +144 -0
  87. package/dist/commands/channel-members.js.map +1 -0
  88. package/dist/commands/channels.d.ts +75 -22
  89. package/dist/commands/channels.d.ts.map +1 -1
  90. package/dist/commands/channels.js +181 -100
  91. package/dist/commands/channels.js.map +1 -1
  92. package/dist/commands/chat.d.ts +109 -0
  93. package/dist/commands/chat.d.ts.map +1 -0
  94. package/dist/commands/chat.js +227 -0
  95. package/dist/commands/chat.js.map +1 -0
  96. package/dist/commands/clean.d.ts +43 -1
  97. package/dist/commands/clean.d.ts.map +1 -1
  98. package/dist/commands/clean.js +90 -47
  99. package/dist/commands/clean.js.map +1 -1
  100. package/dist/commands/completion.d.ts +39 -1
  101. package/dist/commands/completion.d.ts.map +1 -1
  102. package/dist/commands/completion.js +211 -87
  103. package/dist/commands/completion.js.map +1 -1
  104. package/dist/commands/config.d.ts +33 -0
  105. package/dist/commands/config.d.ts.map +1 -0
  106. package/dist/commands/config.js +159 -0
  107. package/dist/commands/config.js.map +1 -0
  108. package/dist/commands/console.d.ts.map +1 -1
  109. package/dist/commands/console.js +25 -7
  110. package/dist/commands/console.js.map +1 -1
  111. package/dist/commands/describe.d.ts +63 -31
  112. package/dist/commands/describe.d.ts.map +1 -1
  113. package/dist/commands/describe.js +270 -136
  114. package/dist/commands/describe.js.map +1 -1
  115. package/dist/commands/doctor.d.ts +11 -6
  116. package/dist/commands/doctor.d.ts.map +1 -1
  117. package/dist/commands/doctor.js +195 -288
  118. package/dist/commands/doctor.js.map +1 -1
  119. package/dist/commands/down-services.d.ts +29 -0
  120. package/dist/commands/down-services.d.ts.map +1 -0
  121. package/dist/commands/down-services.js +129 -0
  122. package/dist/commands/down-services.js.map +1 -0
  123. package/dist/commands/down.d.ts +37 -11
  124. package/dist/commands/down.d.ts.map +1 -1
  125. package/dist/commands/down.js +384 -117
  126. package/dist/commands/down.js.map +1 -1
  127. package/dist/commands/endpoint-authoring.d.ts +6 -0
  128. package/dist/commands/endpoint-authoring.d.ts.map +1 -0
  129. package/dist/commands/endpoint-authoring.js +130 -0
  130. package/dist/commands/endpoint-authoring.js.map +1 -0
  131. package/dist/commands/endpoint-deregister.d.ts +5 -0
  132. package/dist/commands/endpoint-deregister.d.ts.map +1 -0
  133. package/dist/commands/endpoint-deregister.js +70 -0
  134. package/dist/commands/endpoint-deregister.js.map +1 -0
  135. package/dist/commands/endpoint.d.ts +118 -0
  136. package/dist/commands/endpoint.d.ts.map +1 -0
  137. package/dist/commands/endpoint.js +177 -0
  138. package/dist/commands/endpoint.js.map +1 -0
  139. package/dist/commands/endpoints.d.ts +27 -1
  140. package/dist/commands/endpoints.d.ts.map +1 -1
  141. package/dist/commands/endpoints.js +42 -30
  142. package/dist/commands/endpoints.js.map +1 -1
  143. package/dist/commands/ext.d.ts +38 -1
  144. package/dist/commands/ext.d.ts.map +1 -1
  145. package/dist/commands/ext.js +84 -49
  146. package/dist/commands/ext.js.map +1 -1
  147. package/dist/commands/feedback.d.ts +58 -1
  148. package/dist/commands/feedback.d.ts.map +1 -1
  149. package/dist/commands/feedback.js +119 -47
  150. package/dist/commands/feedback.js.map +1 -1
  151. package/dist/commands/help.d.ts +20 -0
  152. package/dist/commands/help.d.ts.map +1 -0
  153. package/dist/commands/help.js +52 -0
  154. package/dist/commands/help.js.map +1 -0
  155. package/dist/commands/history-clear.d.ts +14 -0
  156. package/dist/commands/history-clear.d.ts.map +1 -0
  157. package/dist/commands/history-clear.js +74 -0
  158. package/dist/commands/history-clear.js.map +1 -0
  159. package/dist/commands/history.d.ts +146 -4
  160. package/dist/commands/history.d.ts.map +1 -1
  161. package/dist/commands/history.js +437 -19
  162. package/dist/commands/history.js.map +1 -1
  163. package/dist/commands/join.d.ts.map +1 -1
  164. package/dist/commands/join.js +7 -3
  165. package/dist/commands/join.js.map +1 -1
  166. package/dist/commands/meshes-add.d.ts +3 -0
  167. package/dist/commands/meshes-add.d.ts.map +1 -1
  168. package/dist/commands/meshes-add.js +41 -34
  169. package/dist/commands/meshes-add.js.map +1 -1
  170. package/dist/commands/meshes-wizard.js +3 -3
  171. package/dist/commands/meshes-wizard.js.map +1 -1
  172. package/dist/commands/mint-endpoint-caller.d.ts +5 -0
  173. package/dist/commands/mint-endpoint-caller.d.ts.map +1 -0
  174. package/dist/commands/mint-endpoint-caller.js +130 -0
  175. package/dist/commands/mint-endpoint-caller.js.map +1 -0
  176. package/dist/commands/mint.d.ts +2 -37
  177. package/dist/commands/mint.d.ts.map +1 -1
  178. package/dist/commands/mint.js +142 -325
  179. package/dist/commands/mint.js.map +1 -1
  180. package/dist/commands/models.d.ts +30 -8
  181. package/dist/commands/models.d.ts.map +1 -1
  182. package/dist/commands/models.js +72 -41
  183. package/dist/commands/models.js.map +1 -1
  184. package/dist/commands/persona-remote.d.ts +5 -0
  185. package/dist/commands/persona-remote.d.ts.map +1 -0
  186. package/dist/commands/persona-remote.js +237 -0
  187. package/dist/commands/persona-remote.js.map +1 -0
  188. package/dist/commands/persona.d.ts +91 -0
  189. package/dist/commands/persona.d.ts.map +1 -0
  190. package/dist/commands/persona.js +200 -0
  191. package/dist/commands/persona.js.map +1 -0
  192. package/dist/commands/personas.d.ts.map +1 -1
  193. package/dist/commands/personas.js +16 -59
  194. package/dist/commands/personas.js.map +1 -1
  195. package/dist/commands/reset-space-apply.d.ts +5 -0
  196. package/dist/commands/reset-space-apply.d.ts.map +1 -0
  197. package/dist/commands/reset-space-apply.js +127 -0
  198. package/dist/commands/reset-space-apply.js.map +1 -0
  199. package/dist/commands/reset-store-apply.d.ts +35 -0
  200. package/dist/commands/reset-store-apply.d.ts.map +1 -0
  201. package/dist/commands/reset-store-apply.js +216 -0
  202. package/dist/commands/reset-store-apply.js.map +1 -0
  203. package/dist/commands/reset.d.ts +26 -0
  204. package/dist/commands/reset.d.ts.map +1 -0
  205. package/dist/commands/reset.js +155 -0
  206. package/dist/commands/reset.js.map +1 -0
  207. package/dist/commands/runtimes.d.ts +26 -1
  208. package/dist/commands/runtimes.d.ts.map +1 -1
  209. package/dist/commands/runtimes.js +68 -32
  210. package/dist/commands/runtimes.js.map +1 -1
  211. package/dist/commands/send.d.ts +91 -6
  212. package/dist/commands/send.d.ts.map +1 -1
  213. package/dist/commands/send.js +180 -106
  214. package/dist/commands/send.js.map +1 -1
  215. package/dist/commands/service-actions.d.ts +6 -0
  216. package/dist/commands/service-actions.d.ts.map +1 -0
  217. package/dist/commands/service-actions.js +413 -0
  218. package/dist/commands/service-actions.js.map +1 -0
  219. package/dist/commands/service-log-follow.d.ts +5 -0
  220. package/dist/commands/service-log-follow.d.ts.map +1 -0
  221. package/dist/commands/service-log-follow.js +107 -0
  222. package/dist/commands/service-log-follow.js.map +1 -0
  223. package/dist/commands/service-registry.d.ts +67 -0
  224. package/dist/commands/service-registry.d.ts.map +1 -0
  225. package/dist/commands/service-registry.js +275 -0
  226. package/dist/commands/service-registry.js.map +1 -0
  227. package/dist/commands/service-set-stop.d.ts +6 -0
  228. package/dist/commands/service-set-stop.d.ts.map +1 -0
  229. package/dist/commands/service-set-stop.js +164 -0
  230. package/dist/commands/service-set-stop.js.map +1 -0
  231. package/dist/commands/service-unit-entry.d.ts +5 -0
  232. package/dist/commands/service-unit-entry.d.ts.map +1 -0
  233. package/dist/commands/service-unit-entry.js +113 -0
  234. package/dist/commands/service-unit-entry.js.map +1 -0
  235. package/dist/commands/setup-start.d.ts +21 -0
  236. package/dist/commands/setup-start.d.ts.map +1 -0
  237. package/dist/commands/setup-start.js +95 -0
  238. package/dist/commands/setup-start.js.map +1 -0
  239. package/dist/commands/setup.d.ts +86 -100
  240. package/dist/commands/setup.d.ts.map +1 -1
  241. package/dist/commands/setup.js +766 -487
  242. package/dist/commands/setup.js.map +1 -1
  243. package/dist/commands/space-delete.d.ts +3 -0
  244. package/dist/commands/space-delete.d.ts.map +1 -0
  245. package/dist/commands/space-delete.js +386 -0
  246. package/dist/commands/space-delete.js.map +1 -0
  247. package/dist/commands/space-registration.d.ts +92 -0
  248. package/dist/commands/space-registration.d.ts.map +1 -0
  249. package/dist/commands/space-registration.js +394 -0
  250. package/dist/commands/space-registration.js.map +1 -0
  251. package/dist/commands/space.d.ts +128 -0
  252. package/dist/commands/space.d.ts.map +1 -0
  253. package/dist/commands/space.js +230 -0
  254. package/dist/commands/space.js.map +1 -0
  255. package/dist/commands/spawn-manifest.d.ts.map +1 -1
  256. package/dist/commands/spawn-manifest.js +2 -2
  257. package/dist/commands/spawn-manifest.js.map +1 -1
  258. package/dist/commands/spawn-preview.d.ts +9 -0
  259. package/dist/commands/spawn-preview.d.ts.map +1 -0
  260. package/dist/commands/spawn-preview.js +68 -0
  261. package/dist/commands/spawn-preview.js.map +1 -0
  262. package/dist/commands/spawn.d.ts +81 -21
  263. package/dist/commands/spawn.d.ts.map +1 -1
  264. package/dist/commands/spawn.js +254 -107
  265. package/dist/commands/spawn.js.map +1 -1
  266. package/dist/commands/stack-down.d.ts +20 -0
  267. package/dist/commands/stack-down.d.ts.map +1 -0
  268. package/dist/commands/stack-down.js +313 -0
  269. package/dist/commands/stack-down.js.map +1 -0
  270. package/dist/commands/stack-up.d.ts +154 -0
  271. package/dist/commands/stack-up.d.ts.map +1 -0
  272. package/dist/commands/stack-up.js +498 -0
  273. package/dist/commands/stack-up.js.map +1 -0
  274. package/dist/commands/stack-user-auth.d.ts +52 -0
  275. package/dist/commands/stack-user-auth.d.ts.map +1 -0
  276. package/dist/commands/stack-user-auth.js +128 -0
  277. package/dist/commands/stack-user-auth.js.map +1 -0
  278. package/dist/commands/status.d.ts +244 -5
  279. package/dist/commands/status.d.ts.map +1 -1
  280. package/dist/commands/status.js +1044 -407
  281. package/dist/commands/status.js.map +1 -1
  282. package/dist/commands/sync.d.ts +23 -0
  283. package/dist/commands/sync.d.ts.map +1 -1
  284. package/dist/commands/sync.js +69 -17
  285. package/dist/commands/sync.js.map +1 -1
  286. package/dist/commands/team-agent-apply.d.ts +5 -0
  287. package/dist/commands/team-agent-apply.d.ts.map +1 -0
  288. package/dist/commands/team-agent-apply.js +204 -0
  289. package/dist/commands/team-agent-apply.js.map +1 -0
  290. package/dist/commands/team-agent-remove.d.ts +87 -0
  291. package/dist/commands/team-agent-remove.d.ts.map +1 -0
  292. package/dist/commands/team-agent-remove.js +348 -0
  293. package/dist/commands/team-agent-remove.js.map +1 -0
  294. package/dist/commands/team-boot-controller.d.ts +11 -0
  295. package/dist/commands/team-boot-controller.d.ts.map +1 -0
  296. package/dist/commands/team-boot-controller.js +176 -0
  297. package/dist/commands/team-boot-controller.js.map +1 -0
  298. package/dist/commands/team-channel-remove.d.ts +167 -0
  299. package/dist/commands/team-channel-remove.d.ts.map +1 -0
  300. package/dist/commands/team-channel-remove.js +486 -0
  301. package/dist/commands/team-channel-remove.js.map +1 -0
  302. package/dist/commands/team-deploy-apply.d.ts +11 -0
  303. package/dist/commands/team-deploy-apply.d.ts.map +1 -0
  304. package/dist/commands/team-deploy-apply.js +320 -0
  305. package/dist/commands/team-deploy-apply.js.map +1 -0
  306. package/dist/commands/team-mixed-remove.d.ts +8 -0
  307. package/dist/commands/team-mixed-remove.d.ts.map +1 -0
  308. package/dist/commands/team-mixed-remove.js +207 -0
  309. package/dist/commands/team-mixed-remove.js.map +1 -0
  310. package/dist/commands/team.d.ts +51 -0
  311. package/dist/commands/team.d.ts.map +1 -0
  312. package/dist/commands/team.js +728 -0
  313. package/dist/commands/team.js.map +1 -0
  314. package/dist/commands/topology.d.ts +4 -0
  315. package/dist/commands/topology.d.ts.map +1 -1
  316. package/dist/commands/topology.js +8 -0
  317. package/dist/commands/topology.js.map +1 -1
  318. package/dist/commands/up.d.ts +146 -6
  319. package/dist/commands/up.d.ts.map +1 -1
  320. package/dist/commands/up.js +1123 -131
  321. package/dist/commands/up.js.map +1 -1
  322. package/dist/commands/update.d.ts +13 -0
  323. package/dist/commands/update.d.ts.map +1 -1
  324. package/dist/commands/update.js +90 -22
  325. package/dist/commands/update.js.map +1 -1
  326. package/dist/commands/use.d.ts +16 -3
  327. package/dist/commands/use.d.ts.map +1 -1
  328. package/dist/commands/use.js +45 -19
  329. package/dist/commands/use.js.map +1 -1
  330. package/dist/commands/watch.d.ts +37 -0
  331. package/dist/commands/watch.d.ts.map +1 -0
  332. package/dist/commands/watch.js +106 -0
  333. package/dist/commands/watch.js.map +1 -0
  334. package/dist/commands/who.d.ts +79 -0
  335. package/dist/commands/who.d.ts.map +1 -0
  336. package/dist/commands/who.js +193 -0
  337. package/dist/commands/who.js.map +1 -0
  338. package/dist/commands/whoami.d.ts +56 -0
  339. package/dist/commands/whoami.d.ts.map +1 -0
  340. package/dist/commands/whoami.js +106 -0
  341. package/dist/commands/whoami.js.map +1 -0
  342. package/dist/console/app.d.ts.map +1 -1
  343. package/dist/console/app.js +8 -4
  344. package/dist/console/app.js.map +1 -1
  345. package/dist/console/commands.d.ts.map +1 -1
  346. package/dist/console/commands.js +12 -6
  347. package/dist/console/commands.js.map +1 -1
  348. package/dist/exec-endpoint/definition.d.ts +15 -0
  349. package/dist/exec-endpoint/definition.d.ts.map +1 -0
  350. package/dist/exec-endpoint/definition.js +56 -0
  351. package/dist/exec-endpoint/definition.js.map +1 -0
  352. package/dist/exec-endpoint/handler.d.ts +13 -0
  353. package/dist/exec-endpoint/handler.d.ts.map +1 -0
  354. package/dist/exec-endpoint/handler.js +155 -0
  355. package/dist/exec-endpoint/handler.js.map +1 -0
  356. package/dist/exec-endpoint/registration.d.ts +34 -0
  357. package/dist/exec-endpoint/registration.d.ts.map +1 -0
  358. package/dist/exec-endpoint/registration.js +148 -0
  359. package/dist/exec-endpoint/registration.js.map +1 -0
  360. package/dist/exec-endpoint/serve.d.ts +8 -0
  361. package/dist/exec-endpoint/serve.d.ts.map +1 -0
  362. package/dist/exec-endpoint/serve.js +159 -0
  363. package/dist/exec-endpoint/serve.js.map +1 -0
  364. package/dist/exec-endpoint/service-adapter.d.ts +6 -0
  365. package/dist/exec-endpoint/service-adapter.d.ts.map +1 -0
  366. package/dist/exec-endpoint/service-adapter.js +110 -0
  367. package/dist/exec-endpoint/service-adapter.js.map +1 -0
  368. package/dist/ext-loader.d.ts +10 -0
  369. package/dist/ext-loader.d.ts.map +1 -1
  370. package/dist/ext-loader.js +61 -13
  371. package/dist/ext-loader.js.map +1 -1
  372. package/dist/help.d.ts +18 -0
  373. package/dist/help.d.ts.map +1 -0
  374. package/dist/help.js +256 -0
  375. package/dist/help.js.map +1 -0
  376. package/dist/index.d.ts +3 -0
  377. package/dist/index.d.ts.map +1 -1
  378. package/dist/index.js +446 -119
  379. package/dist/index.js.map +1 -1
  380. package/dist/lib/assist.d.ts.map +1 -1
  381. package/dist/lib/assist.js +3 -2
  382. package/dist/lib/assist.js.map +1 -1
  383. package/dist/lib/attach-client.d.ts +7 -6
  384. package/dist/lib/attach-client.d.ts.map +1 -1
  385. package/dist/lib/attach-client.js +14 -15
  386. package/dist/lib/attach-client.js.map +1 -1
  387. package/dist/lib/auth-proc.d.ts +3 -3
  388. package/dist/lib/auth-proc.d.ts.map +1 -1
  389. package/dist/lib/auth-proc.js +8 -8
  390. package/dist/lib/auth-proc.js.map +1 -1
  391. package/dist/lib/backup-artifact.d.ts +41 -1
  392. package/dist/lib/backup-artifact.d.ts.map +1 -1
  393. package/dist/lib/backup-artifact.js +96 -22
  394. package/dist/lib/backup-artifact.js.map +1 -1
  395. package/dist/lib/broker-service.d.ts +19 -0
  396. package/dist/lib/broker-service.d.ts.map +1 -0
  397. package/dist/lib/broker-service.js +369 -0
  398. package/dist/lib/broker-service.js.map +1 -0
  399. package/dist/lib/cancel.js +1 -1
  400. package/dist/lib/cancel.js.map +1 -1
  401. package/dist/lib/choose-target.d.ts +10 -0
  402. package/dist/lib/choose-target.d.ts.map +1 -0
  403. package/dist/lib/choose-target.js +42 -0
  404. package/dist/lib/choose-target.js.map +1 -0
  405. package/dist/lib/command-path.d.ts +13 -0
  406. package/dist/lib/command-path.d.ts.map +1 -0
  407. package/dist/lib/command-path.js +40 -0
  408. package/dist/lib/command-path.js.map +1 -0
  409. package/dist/lib/completion-install.d.ts +29 -0
  410. package/dist/lib/completion-install.d.ts.map +1 -0
  411. package/dist/lib/completion-install.js +369 -0
  412. package/dist/lib/completion-install.js.map +1 -0
  413. package/dist/lib/completion-scripts.d.ts +4 -0
  414. package/dist/lib/completion-scripts.d.ts.map +1 -0
  415. package/dist/lib/completion-scripts.js +15 -0
  416. package/dist/lib/completion-scripts.js.map +1 -0
  417. package/dist/lib/completion.d.ts.map +1 -1
  418. package/dist/lib/completion.js +4 -1
  419. package/dist/lib/completion.js.map +1 -1
  420. package/dist/lib/confirmation-required.d.ts +13 -0
  421. package/dist/lib/confirmation-required.d.ts.map +1 -0
  422. package/dist/lib/confirmation-required.js +10 -0
  423. package/dist/lib/confirmation-required.js.map +1 -0
  424. package/dist/lib/control.d.ts +65 -6
  425. package/dist/lib/control.d.ts.map +1 -1
  426. package/dist/lib/control.js +121 -27
  427. package/dist/lib/control.js.map +1 -1
  428. package/dist/lib/controller-preserve.d.ts +12 -0
  429. package/dist/lib/controller-preserve.d.ts.map +1 -0
  430. package/dist/lib/controller-preserve.js +373 -0
  431. package/dist/lib/controller-preserve.js.map +1 -0
  432. package/dist/lib/controller-restore.d.ts +38 -0
  433. package/dist/lib/controller-restore.d.ts.map +1 -0
  434. package/dist/lib/controller-restore.js +205 -0
  435. package/dist/lib/controller-restore.js.map +1 -0
  436. package/dist/lib/controller-resume.d.ts +92 -0
  437. package/dist/lib/controller-resume.d.ts.map +1 -0
  438. package/dist/lib/controller-resume.js +300 -0
  439. package/dist/lib/controller-resume.js.map +1 -0
  440. package/dist/lib/credential-authority.d.ts +17 -0
  441. package/dist/lib/credential-authority.d.ts.map +1 -0
  442. package/dist/lib/credential-authority.js +29 -0
  443. package/dist/lib/credential-authority.js.map +1 -0
  444. package/dist/lib/default-persona.d.ts +38 -0
  445. package/dist/lib/default-persona.d.ts.map +1 -0
  446. package/dist/lib/default-persona.js +85 -0
  447. package/dist/lib/default-persona.js.map +1 -0
  448. package/dist/lib/delivery-proc.d.ts +9 -9
  449. package/dist/lib/delivery-proc.d.ts.map +1 -1
  450. package/dist/lib/delivery-proc.js +44 -23
  451. package/dist/lib/delivery-proc.js.map +1 -1
  452. package/dist/lib/endpoint-capability-gates.d.ts +10 -0
  453. package/dist/lib/endpoint-capability-gates.d.ts.map +1 -0
  454. package/dist/lib/endpoint-capability-gates.js +70 -0
  455. package/dist/lib/endpoint-capability-gates.js.map +1 -0
  456. package/dist/lib/endpoint-client.d.ts +23 -0
  457. package/dist/lib/endpoint-client.d.ts.map +1 -0
  458. package/dist/lib/endpoint-client.js +46 -0
  459. package/dist/lib/endpoint-client.js.map +1 -0
  460. package/dist/lib/endpoint-errors.d.ts +20 -0
  461. package/dist/lib/endpoint-errors.d.ts.map +1 -0
  462. package/dist/lib/endpoint-errors.js +46 -0
  463. package/dist/lib/endpoint-errors.js.map +1 -0
  464. package/dist/lib/endpoint-goal.d.ts +19 -0
  465. package/dist/lib/endpoint-goal.d.ts.map +1 -0
  466. package/dist/lib/endpoint-goal.js +31 -0
  467. package/dist/lib/endpoint-goal.js.map +1 -0
  468. package/dist/lib/endpoint-inventory.d.ts +30 -0
  469. package/dist/lib/endpoint-inventory.d.ts.map +1 -0
  470. package/dist/lib/endpoint-inventory.js +79 -0
  471. package/dist/lib/endpoint-inventory.js.map +1 -0
  472. package/dist/lib/endpoint-references.d.ts +22 -0
  473. package/dist/lib/endpoint-references.d.ts.map +1 -0
  474. package/dist/lib/endpoint-references.js +44 -0
  475. package/dist/lib/endpoint-references.js.map +1 -0
  476. package/dist/lib/endpoint-scatter.d.ts +57 -0
  477. package/dist/lib/endpoint-scatter.d.ts.map +1 -0
  478. package/dist/lib/endpoint-scatter.js +75 -0
  479. package/dist/lib/endpoint-scatter.js.map +1 -0
  480. package/dist/lib/endpoint-selection.d.ts +35 -0
  481. package/dist/lib/endpoint-selection.d.ts.map +1 -0
  482. package/dist/lib/endpoint-selection.js +80 -0
  483. package/dist/lib/endpoint-selection.js.map +1 -0
  484. package/dist/lib/install-umask.d.ts +6 -0
  485. package/dist/lib/install-umask.d.ts.map +1 -0
  486. package/dist/lib/install-umask.js +15 -0
  487. package/dist/lib/install-umask.js.map +1 -0
  488. package/dist/lib/isolated-broker.d.ts.map +1 -1
  489. package/dist/lib/isolated-broker.js +9 -5
  490. package/dist/lib/isolated-broker.js.map +1 -1
  491. package/dist/lib/local-process-stop.d.ts.map +1 -1
  492. package/dist/lib/local-process-stop.js +7 -1
  493. package/dist/lib/local-process-stop.js.map +1 -1
  494. package/dist/lib/manager-proc.d.ts +11 -5
  495. package/dist/lib/manager-proc.d.ts.map +1 -1
  496. package/dist/lib/manager-proc.js +12 -17
  497. package/dist/lib/manager-proc.js.map +1 -1
  498. package/dist/lib/manifest/apply.d.ts +4 -1
  499. package/dist/lib/manifest/apply.d.ts.map +1 -1
  500. package/dist/lib/manifest/apply.js +1 -1
  501. package/dist/lib/manifest/apply.js.map +1 -1
  502. package/dist/lib/manifest/ledger.d.ts +3 -1
  503. package/dist/lib/manifest/ledger.d.ts.map +1 -1
  504. package/dist/lib/manifest/ledger.js +16 -3
  505. package/dist/lib/manifest/ledger.js.map +1 -1
  506. package/dist/lib/manifest/schema.d.ts +1 -117
  507. package/dist/lib/manifest/schema.d.ts.map +1 -1
  508. package/dist/lib/manifest/schema.js +1 -95
  509. package/dist/lib/manifest/schema.js.map +1 -1
  510. package/dist/lib/offline-recipient.d.ts +5 -0
  511. package/dist/lib/offline-recipient.d.ts.map +1 -0
  512. package/dist/lib/offline-recipient.js +7 -0
  513. package/dist/lib/offline-recipient.js.map +1 -0
  514. package/dist/lib/onboard.js +3 -3
  515. package/dist/lib/onboard.js.map +1 -1
  516. package/dist/lib/persona-files.d.ts +29 -0
  517. package/dist/lib/persona-files.d.ts.map +1 -0
  518. package/dist/lib/persona-files.js +154 -0
  519. package/dist/lib/persona-files.js.map +1 -0
  520. package/dist/lib/personas.d.ts +3 -0
  521. package/dist/lib/personas.d.ts.map +1 -1
  522. package/dist/lib/personas.js +14 -2
  523. package/dist/lib/personas.js.map +1 -1
  524. package/dist/lib/prompts.d.ts +16 -0
  525. package/dist/lib/prompts.d.ts.map +1 -0
  526. package/dist/lib/prompts.js +35 -0
  527. package/dist/lib/prompts.js.map +1 -0
  528. package/dist/lib/protected-records.d.ts +2 -0
  529. package/dist/lib/protected-records.d.ts.map +1 -0
  530. package/dist/lib/protected-records.js +3 -0
  531. package/dist/lib/protected-records.js.map +1 -0
  532. package/dist/lib/registry-errors.d.ts +4 -0
  533. package/dist/lib/registry-errors.d.ts.map +1 -0
  534. package/dist/lib/registry-errors.js +6 -0
  535. package/dist/lib/registry-errors.js.map +1 -0
  536. package/dist/lib/reset-space-plan.d.ts +36 -0
  537. package/dist/lib/reset-space-plan.d.ts.map +1 -0
  538. package/dist/lib/reset-space-plan.js +202 -0
  539. package/dist/lib/reset-space-plan.js.map +1 -0
  540. package/dist/lib/restore.d.ts +13 -1
  541. package/dist/lib/restore.d.ts.map +1 -1
  542. package/dist/lib/restore.js +73 -11
  543. package/dist/lib/restore.js.map +1 -1
  544. package/dist/lib/seat-resume.d.ts +4 -1
  545. package/dist/lib/seat-resume.d.ts.map +1 -1
  546. package/dist/lib/seat-resume.js +7 -4
  547. package/dist/lib/seat-resume.js.map +1 -1
  548. package/dist/lib/service-adapters.d.ts +32 -0
  549. package/dist/lib/service-adapters.d.ts.map +1 -0
  550. package/dist/lib/service-adapters.js +55 -0
  551. package/dist/lib/service-adapters.js.map +1 -0
  552. package/dist/lib/service-census.d.ts +73 -0
  553. package/dist/lib/service-census.d.ts.map +1 -0
  554. package/dist/lib/service-census.js +42 -0
  555. package/dist/lib/service-census.js.map +1 -0
  556. package/dist/lib/service-definitions.d.ts +49 -0
  557. package/dist/lib/service-definitions.d.ts.map +1 -0
  558. package/dist/lib/service-definitions.js +61 -0
  559. package/dist/lib/service-definitions.js.map +1 -0
  560. package/dist/lib/service-install-intent.d.ts +48 -0
  561. package/dist/lib/service-install-intent.d.ts.map +1 -0
  562. package/dist/lib/service-install-intent.js +95 -0
  563. package/dist/lib/service-install-intent.js.map +1 -0
  564. package/dist/lib/service-instances.d.ts +143 -0
  565. package/dist/lib/service-instances.d.ts.map +1 -0
  566. package/dist/lib/service-instances.js +193 -0
  567. package/dist/lib/service-instances.js.map +1 -0
  568. package/dist/lib/service-journal.d.ts +38 -0
  569. package/dist/lib/service-journal.d.ts.map +1 -0
  570. package/dist/lib/service-journal.js +210 -0
  571. package/dist/lib/service-journal.js.map +1 -0
  572. package/dist/lib/service-launchd-plan.d.ts +21 -0
  573. package/dist/lib/service-launchd-plan.d.ts.map +1 -0
  574. package/dist/lib/service-launchd-plan.js +69 -0
  575. package/dist/lib/service-launchd-plan.js.map +1 -0
  576. package/dist/lib/service-launchd-unit.d.ts +20 -0
  577. package/dist/lib/service-launchd-unit.d.ts.map +1 -0
  578. package/dist/lib/service-launchd-unit.js +66 -0
  579. package/dist/lib/service-launchd-unit.js.map +1 -0
  580. package/dist/lib/service-presets.d.ts +17 -0
  581. package/dist/lib/service-presets.d.ts.map +1 -0
  582. package/dist/lib/service-presets.js +139 -0
  583. package/dist/lib/service-presets.js.map +1 -0
  584. package/dist/lib/service-private-seed.d.ts +7 -0
  585. package/dist/lib/service-private-seed.d.ts.map +1 -0
  586. package/dist/lib/service-private-seed.js +64 -0
  587. package/dist/lib/service-private-seed.js.map +1 -0
  588. package/dist/lib/service-private-tree.d.ts +6 -0
  589. package/dist/lib/service-private-tree.d.ts.map +1 -0
  590. package/dist/lib/service-private-tree.js +100 -0
  591. package/dist/lib/service-private-tree.js.map +1 -0
  592. package/dist/lib/service-process.d.ts +146 -0
  593. package/dist/lib/service-process.d.ts.map +1 -0
  594. package/dist/lib/service-process.js +862 -0
  595. package/dist/lib/service-process.js.map +1 -0
  596. package/dist/lib/service-stopped-allocation.d.ts +6 -0
  597. package/dist/lib/service-stopped-allocation.d.ts.map +1 -0
  598. package/dist/lib/service-stopped-allocation.js +42 -0
  599. package/dist/lib/service-stopped-allocation.js.map +1 -0
  600. package/dist/lib/service-supervision.d.ts +59 -0
  601. package/dist/lib/service-supervision.d.ts.map +1 -0
  602. package/dist/lib/service-supervision.js +71 -0
  603. package/dist/lib/service-supervision.js.map +1 -0
  604. package/dist/lib/service-systemd-attempt-read.d.ts +40 -0
  605. package/dist/lib/service-systemd-attempt-read.d.ts.map +1 -0
  606. package/dist/lib/service-systemd-attempt-read.js +80 -0
  607. package/dist/lib/service-systemd-attempt-read.js.map +1 -0
  608. package/dist/lib/service-systemd-control.d.ts +38 -0
  609. package/dist/lib/service-systemd-control.d.ts.map +1 -0
  610. package/dist/lib/service-systemd-control.js +141 -0
  611. package/dist/lib/service-systemd-control.js.map +1 -0
  612. package/dist/lib/service-systemd-files.d.ts +8 -0
  613. package/dist/lib/service-systemd-files.d.ts.map +1 -0
  614. package/dist/lib/service-systemd-files.js +63 -0
  615. package/dist/lib/service-systemd-files.js.map +1 -0
  616. package/dist/lib/service-systemd-install.d.ts +17 -0
  617. package/dist/lib/service-systemd-install.d.ts.map +1 -0
  618. package/dist/lib/service-systemd-install.js +146 -0
  619. package/dist/lib/service-systemd-install.js.map +1 -0
  620. package/dist/lib/service-systemd-plan.d.ts +28 -0
  621. package/dist/lib/service-systemd-plan.d.ts.map +1 -0
  622. package/dist/lib/service-systemd-plan.js +56 -0
  623. package/dist/lib/service-systemd-plan.js.map +1 -0
  624. package/dist/lib/service-systemd-reseed.d.ts +16 -0
  625. package/dist/lib/service-systemd-reseed.d.ts.map +1 -0
  626. package/dist/lib/service-systemd-reseed.js +106 -0
  627. package/dist/lib/service-systemd-reseed.js.map +1 -0
  628. package/dist/lib/service-systemd-uninstall-plan.d.ts +29 -0
  629. package/dist/lib/service-systemd-uninstall-plan.d.ts.map +1 -0
  630. package/dist/lib/service-systemd-uninstall-plan.js +56 -0
  631. package/dist/lib/service-systemd-uninstall-plan.js.map +1 -0
  632. package/dist/lib/service-systemd-uninstall.d.ts +17 -0
  633. package/dist/lib/service-systemd-uninstall.d.ts.map +1 -0
  634. package/dist/lib/service-systemd-uninstall.js +106 -0
  635. package/dist/lib/service-systemd-uninstall.js.map +1 -0
  636. package/dist/lib/service-systemd-unit.d.ts +28 -0
  637. package/dist/lib/service-systemd-unit.d.ts.map +1 -0
  638. package/dist/lib/service-systemd-unit.js +73 -0
  639. package/dist/lib/service-systemd-unit.js.map +1 -0
  640. package/dist/lib/service-systemd.d.ts +49 -0
  641. package/dist/lib/service-systemd.d.ts.map +1 -0
  642. package/dist/lib/service-systemd.js +134 -0
  643. package/dist/lib/service-systemd.js.map +1 -0
  644. package/dist/lib/service-uninstall-intent.d.ts +38 -0
  645. package/dist/lib/service-uninstall-intent.d.ts.map +1 -0
  646. package/dist/lib/service-uninstall-intent.js +74 -0
  647. package/dist/lib/service-uninstall-intent.js.map +1 -0
  648. package/dist/lib/service-unit-action.d.ts +24 -0
  649. package/dist/lib/service-unit-action.d.ts.map +1 -0
  650. package/dist/lib/service-unit-action.js +61 -0
  651. package/dist/lib/service-unit-action.js.map +1 -0
  652. package/dist/lib/setup-log.d.ts +5 -4
  653. package/dist/lib/setup-log.d.ts.map +1 -1
  654. package/dist/lib/setup-log.js +18 -9
  655. package/dist/lib/setup-log.js.map +1 -1
  656. package/dist/lib/shown-time.d.ts +5 -0
  657. package/dist/lib/shown-time.d.ts.map +1 -0
  658. package/dist/lib/shown-time.js +9 -0
  659. package/dist/lib/shown-time.js.map +1 -0
  660. package/dist/lib/space-schema-inspection.d.ts +73 -0
  661. package/dist/lib/space-schema-inspection.d.ts.map +1 -0
  662. package/dist/lib/space-schema-inspection.js +118 -0
  663. package/dist/lib/space-schema-inspection.js.map +1 -0
  664. package/dist/lib/space-schema-report.d.ts +82 -0
  665. package/dist/lib/space-schema-report.d.ts.map +1 -0
  666. package/dist/lib/space-schema-report.js +109 -0
  667. package/dist/lib/space-schema-report.js.map +1 -0
  668. package/dist/lib/spawn-defaults.d.ts +14 -0
  669. package/dist/lib/spawn-defaults.d.ts.map +1 -0
  670. package/dist/lib/spawn-defaults.js +20 -0
  671. package/dist/lib/spawn-defaults.js.map +1 -0
  672. package/dist/lib/stack-journal.d.ts +166 -0
  673. package/dist/lib/stack-journal.d.ts.map +1 -0
  674. package/dist/lib/stack-journal.js +421 -0
  675. package/dist/lib/stack-journal.js.map +1 -0
  676. package/dist/lib/stack-resume.d.ts +35 -0
  677. package/dist/lib/stack-resume.d.ts.map +1 -0
  678. package/dist/lib/stack-resume.js +123 -0
  679. package/dist/lib/stack-resume.js.map +1 -0
  680. package/dist/lib/status.d.ts +19 -20
  681. package/dist/lib/status.d.ts.map +1 -1
  682. package/dist/lib/status.js +41 -40
  683. package/dist/lib/status.js.map +1 -1
  684. package/dist/lib/stdout-owner.d.ts +17 -0
  685. package/dist/lib/stdout-owner.d.ts.map +1 -0
  686. package/dist/lib/stdout-owner.js +44 -0
  687. package/dist/lib/stdout-owner.js.map +1 -0
  688. package/dist/lib/steps.d.ts.map +1 -1
  689. package/dist/lib/steps.js +3 -2
  690. package/dist/lib/steps.js.map +1 -1
  691. package/dist/lib/systemd-supervision.d.ts +11 -4
  692. package/dist/lib/systemd-supervision.d.ts.map +1 -1
  693. package/dist/lib/systemd-supervision.js +19 -8
  694. package/dist/lib/systemd-supervision.js.map +1 -1
  695. package/dist/lib/team-additive-attempt.d.ts +286 -0
  696. package/dist/lib/team-additive-attempt.d.ts.map +1 -0
  697. package/dist/lib/team-additive-attempt.js +387 -0
  698. package/dist/lib/team-additive-attempt.js.map +1 -0
  699. package/dist/lib/team-additive-native.d.ts +17 -0
  700. package/dist/lib/team-additive-native.d.ts.map +1 -0
  701. package/dist/lib/team-additive-native.js +29 -0
  702. package/dist/lib/team-additive-native.js.map +1 -0
  703. package/dist/lib/team-agent-removal.d.ts +104 -0
  704. package/dist/lib/team-agent-removal.d.ts.map +1 -0
  705. package/dist/lib/team-agent-removal.js +121 -0
  706. package/dist/lib/team-agent-removal.js.map +1 -0
  707. package/dist/lib/team-channel-removal.d.ts +220 -0
  708. package/dist/lib/team-channel-removal.d.ts.map +1 -0
  709. package/dist/lib/team-channel-removal.js +258 -0
  710. package/dist/lib/team-channel-removal.js.map +1 -0
  711. package/dist/lib/team-deploy-inspection.d.ts +59 -0
  712. package/dist/lib/team-deploy-inspection.d.ts.map +1 -0
  713. package/dist/lib/team-deploy-inspection.js +177 -0
  714. package/dist/lib/team-deploy-inspection.js.map +1 -0
  715. package/dist/lib/team-fresh.d.ts +73 -0
  716. package/dist/lib/team-fresh.d.ts.map +1 -0
  717. package/dist/lib/team-fresh.js +207 -0
  718. package/dist/lib/team-fresh.js.map +1 -0
  719. package/dist/lib/team-removal-reconcile.d.ts +118 -0
  720. package/dist/lib/team-removal-reconcile.d.ts.map +1 -0
  721. package/dist/lib/team-removal-reconcile.js +90 -0
  722. package/dist/lib/team-removal-reconcile.js.map +1 -0
  723. package/dist/lib/team-removal-record.d.ts +7 -0
  724. package/dist/lib/team-removal-record.d.ts.map +1 -0
  725. package/dist/lib/team-removal-record.js +46 -0
  726. package/dist/lib/team-removal-record.js.map +1 -0
  727. package/dist/lib/team-retained.d.ts +33 -0
  728. package/dist/lib/team-retained.d.ts.map +1 -0
  729. package/dist/lib/team-retained.js +55 -0
  730. package/dist/lib/team-retained.js.map +1 -0
  731. package/dist/lib/theme.d.ts.map +1 -1
  732. package/dist/lib/theme.js +9 -8
  733. package/dist/lib/theme.js.map +1 -1
  734. package/dist/lib/transient.d.ts +14 -9
  735. package/dist/lib/transient.d.ts.map +1 -1
  736. package/dist/lib/transient.js +25 -18
  737. package/dist/lib/transient.js.map +1 -1
  738. package/dist/lib/up-report.d.ts +3 -0
  739. package/dist/lib/up-report.d.ts.map +1 -1
  740. package/dist/lib/up-report.js +4 -1
  741. package/dist/lib/up-report.js.map +1 -1
  742. package/dist/lib/version.d.ts +8 -2
  743. package/dist/lib/version.d.ts.map +1 -1
  744. package/dist/lib/version.js +16 -9
  745. package/dist/lib/version.js.map +1 -1
  746. package/dist/managed-handoff.d.ts +3 -0
  747. package/dist/managed-handoff.d.ts.map +1 -1
  748. package/dist/managed-handoff.js +5 -0
  749. package/dist/managed-handoff.js.map +1 -1
  750. package/dist/seed/paths.d.ts +1 -1
  751. package/dist/seed/paths.js +1 -1
  752. package/dist/seed/reconcile.d.ts.map +1 -1
  753. package/dist/seed/reconcile.js +19 -3
  754. package/dist/seed/reconcile.js.map +1 -1
  755. package/dist/ui.d.ts +10 -2
  756. package/dist/ui.d.ts.map +1 -1
  757. package/dist/ui.js +28 -6
  758. package/dist/ui.js.map +1 -1
  759. package/dist/watch-data.d.ts +15 -0
  760. package/dist/watch-data.d.ts.map +1 -0
  761. package/dist/watch-data.js +66 -0
  762. package/dist/watch-data.js.map +1 -0
  763. package/dist/watch-json.d.ts +5 -0
  764. package/dist/watch-json.d.ts.map +1 -0
  765. package/dist/watch-json.js +132 -0
  766. package/dist/watch-json.js.map +1 -0
  767. package/dist/watch-view.d.ts +8 -0
  768. package/dist/watch-view.d.ts.map +1 -0
  769. package/dist/watch-view.js +65 -0
  770. package/dist/watch-view.js.map +1 -0
  771. package/package.json +8 -5
  772. package/dist/commands/service.d.ts +0 -17
  773. package/dist/commands/service.d.ts.map +0 -1
  774. package/dist/commands/service.js +0 -589
  775. package/dist/commands/service.js.map +0 -1
@@ -1,15 +1,23 @@
1
- import { readFileSync, rmSync, statSync } from "node:fs";
2
- import { join, resolve as resolvePath } from "node:path";
1
+ import { existsSync, lstatSync, readdirSync, readFileSync, rmSync, statSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { join, relative, resolve as resolvePath } from "node:path";
3
4
  import {} from "@cotal-ai/core";
4
- import { abortMaintenanceCut, acquireMaintenanceLock, assertSingleSpaceBroker, authDir, beginMaintenanceCut, clearPreservationCommitIntent, clearPreservationPrepareIntent, completeMaintenanceCut, loadMeshes, meshesForRoot, localProcessPath, localProcessPathCandidates, readMaintenanceJournal, readMaintenanceResumeDocument, readPreservationCommitIntent, readPreservationPrepareIntent, readStoreIdentity, recordPreservationManagerCommit, releaseMaintenanceLock, removeMeshesByRoot, resolveMeshTarget, sameStoreIdentity, writePreservationCommitIntent, writePreservationPrepareIntent, DELIVERY_PIDFILE, MANAGER_DELIVERY_AWARE_MARKER, MANAGER_PIDFILE, WEB_PIDFILE, MAINTENANCE_RESUME_DOCUMENT_VERSION, writeMaintenanceResumeDocument, loadSeatWriterGeneration, materializeFromManifest, seatCheckpointDir, } from "@cotal-ai/workspace";
5
+ import { CommandFailure, localRecordName, presentationOf, abortMaintenanceCut, acquireMaintenanceLock, assertSingleSpaceBroker, authDir, beginMaintenanceCut, clearPreservationCommitIntent, clearPreservationPrepareIntent, completeMaintenanceCut, loadMeshes, meshesForRoot, localProcessPath, localProcessPathCandidates, canonicalRoot, brokerAddressForDisplay, findMesh, localMeshesForRoot, preparedSpaceAt, soleSpaceOf, writeResult, readMaintenanceJournal, readContainedRecord, readMaintenanceResumeDocument, readPreservationCommitIntent, readPreservationPrepareIntent, readStoreIdentity, recordPreservationManagerCommit, releaseMaintenanceLock, removeMeshesByRoot, sameStoreIdentity, writePreservationCommitIntent, writePreservationPrepareIntent, DELIVERY_PIDFILE, MANAGER_DELIVERY_AWARE_MARKER, MANAGER_PIDFILE, WEB_PIDFILE, MAINTENANCE_RESUME_DOCUMENT_VERSION, writeMaintenanceResumeDocument, loadSeatWriterGeneration, materializeFromManifest, seatCheckpointDir, } from "@cotal-ai/workspace";
5
6
  import { jetstreamManager } from "@nats-io/jetstream";
6
- import { DEV_OWNER, dialerFor, isReachable, LEASE_TTL_MS, MANAGER_LEASE_KEY, MANAGER_LEASE_TTL_MS, deliveryBucket, managerBucket, presenceBucket, parsePrincipalKey, principalKey, standaloneConnectOpts, } from "@cotal-ai/core";
7
- import { extensionNames, localProcessSurface } from "../ext-loader.js";
7
+ import { DEV_OWNER, dialerFor, isReachable, realDirNoSymlink, LEASE_TTL_MS, MANAGER_LEASE_KEY, MANAGER_LEASE_TTL_MS, deliveryBucket, managerBucket, presenceBucket, parsePrincipalKey, principalKey, standaloneConnectOpts, } from "@cotal-ai/core";
8
+ import { localProcessSurface } from "../ext-loader.js";
8
9
  import { c } from "../ui.js";
9
10
  import { cotalRoot } from "../lib/paths.js";
10
11
  import { parsePid, probeLiveness, readPidfile } from "@cotal-ai/workspace";
11
12
  import { resolveRuntimeSpace } from "../lib/status.js";
12
13
  import { downManifest } from "./down-manifest.js";
14
+ import { listLedgerFiles } from "../lib/manifest/ledger.js";
15
+ import { freshTeamAttemptSettled, listFreshTeamAttempts, listFreshTeamSummaries } from "../lib/team-fresh.js";
16
+ import { additiveTeamRecordedState, listAdditiveTeamAttempts, retainedAdditiveTeamAttempts } from "../lib/team-additive-attempt.js";
17
+ import { service, serviceComplete, validateServiceArguments } from "./service-registry.js";
18
+ import { stopNamedServiceSet } from "./service-set-stop.js";
19
+ import { readLocalServiceCensus } from "../lib/service-census.js";
20
+ import { assertBareDownServicesVerified, bareDownServicesView, planBareDownServices, stopBareDownServices } from "./down-services.js";
13
21
  import { askManager, resolveControlTarget } from "../lib/control.js";
14
22
  import { connectOrExit, userViewAuthOrExit } from "../lib/connect.js";
15
23
  import { waitForEndpointUnreachable } from "../lib/endpoint-cut.js";
@@ -17,124 +25,367 @@ import { captureSeatCheckpoint } from "../lib/seat-capture.js";
17
25
  import { processRecorded, stopLocalProcess } from "../lib/local-process-stop.js";
18
26
  import { stopManager } from "../lib/manager-proc.js";
19
27
  import { removeDeliveryCredentials, stopDelivery } from "../lib/delivery-proc.js";
28
+ import { controllerStackRecorded, nothingRunning, stackDown, validateStackDownArguments } from "./stack-down.js";
29
+ import { recordedProcessLine } from "../lib/stack-journal.js";
20
30
  /** Complete selective component names without importing installed packages. */
21
31
  export function downComplete(argv) {
22
32
  if (argv.some((word) => word === "-f" || word === "--file" || word === "--run"))
23
33
  return { items: [], directive: "nofiles" };
24
34
  if ((argv[argv.length - 1] ?? "").startsWith("-"))
25
35
  return { items: [], directive: "nofiles" };
26
- const used = new Set(argv.slice(0, -1).filter((word) => !word.startsWith("-")));
27
- return {
28
- items: extensionNames("local-process").filter((name) => !used.has(name)).map((value) => ({ value })),
29
- directive: "nofiles",
30
- };
36
+ return serviceComplete(["stop", ...(argv.length ? argv : [""])]);
31
37
  }
32
- /** Stop the whole local stack by default, or only named self-registered process components. The
33
- * manifest forms remain ownership-scoped deploy teardown and cannot be mixed with components. */
38
+ function namedStopArguments(args) {
39
+ return { ...args, positionals: ["stop", args.positionals[0]] };
40
+ }
41
+ /** Named stops use only the owned-service controller. Multiple definitions require complete
42
+ * set selection, reservation and impact preflight. Legacy bare-stack integration stays separate. */
43
+ export function validateDownArguments(args) {
44
+ presentationOf(args.values);
45
+ if (args.positionals.length) {
46
+ for (const name of args.positionals)
47
+ localRecordName(name);
48
+ if (args.values["with-agents"] !== undefined)
49
+ throw new CommandFailure("refused", "USAGE_INVALID", "named down does not accept --with-agents; no flag was dropped", { remedy: "use cotal service stop <manager-name> --instance <full-id> --with-agents for the exact owned manager and its native impact review" });
50
+ if (args.values.instance !== undefined && args.positionals.length !== 1)
51
+ throw new CommandFailure("refused", "USAGE_INVALID", "--instance qualifies one service name, never a multi-service set");
52
+ const allowed = new Set(["space", "instance", "yes", "dry-run", "json", "plain"]);
53
+ if (Object.keys(args.values).some((name) => !allowed.has(name)))
54
+ throw new CommandFailure("refused", "USAGE_INVALID", "named down accepts only space, instance, confirmation, preview and presentation flags; no whole-stack or manifest option was ignored");
55
+ if (new Set(args.positionals).size !== args.positionals.length)
56
+ throw new CommandFailure("refused", "USAGE_INVALID", "name each service once; duplicate targets were not silently collapsed");
57
+ for (const name of args.positionals)
58
+ validateServiceArguments({ ...args, positionals: ["stop", name] });
59
+ return;
60
+ }
61
+ if (args.values.instance !== undefined)
62
+ throw new CommandFailure("refused", "USAGE_INVALID", "--instance needs one explicit service definition name");
63
+ if (controllerStackRecorded(cotalRoot()))
64
+ return validateStackDownArguments(cotalRoot(), args.values);
65
+ if (args.values["dry-run"] === true && args.values.yes === true)
66
+ throw new CommandFailure("refused", "USAGE_INVALID", "--yes acknowledges a guarded apply, not a read-only stack preview");
67
+ if ((args.values.json !== undefined || args.values.plain !== undefined) && args.values["dry-run"] === true && args.values.file === undefined && args.values.run === undefined && args.values["preserve-state"] === undefined && args.values["store-dir"] === undefined && args.values["session-store"] === undefined)
68
+ return;
69
+ if (args.values.yes !== undefined)
70
+ throw new CommandFailure("refused", "UNSUPPORTED", "--yes applies only to a controller stack, and this root has none; a bare stop here needs no --yes, and nothing was stopped", { remedy: "run `cotal down` from this root without --yes" });
71
+ if ((args.values.json !== undefined || args.values.plain !== undefined) && !(bareStop(args.values) && stoppedLegacyStack()))
72
+ throw new CommandFailure("refused", "UNSUPPORTED", "--json and --plain apply only to a controller stack, a --dry-run preview or a stack that is already stopped; a bare stop here prints its own lines, and nothing was stopped", { remedy: "run `cotal down` from this root without --json or --plain; `cotal down --dry-run --json` reads this root's stack" });
73
+ }
74
+ /** The one route that stops the stack `up` starts from the machine home. */
75
+ const MACHINE_HOME_STOP = "stop the machine-home stack with cotal down --preserve-state, which keeps its state for the next cotal up";
76
+ /** A bare stack preview is a local record census, never an effect plan or stop authority. */
77
+ function previewWholeStack(args) {
78
+ const root = canonicalRoot(cotalRoot());
79
+ const selectedSpace = args.values.space;
80
+ const target = { root, ...(selectedSpace ? { space: selectedSpace } : {}) };
81
+ if (root === canonicalRoot(homedir()))
82
+ throw new CommandFailure("refused", "CONFLICT", "the machine home is not an isolated project root for a whole-stack preview", { target, remedy: MACHINE_HOME_STOP });
83
+ let mesh;
84
+ let maintenance;
85
+ let components;
86
+ let services, serviceStops;
87
+ let additiveRecords, additiveAttempts;
88
+ let bootAttempts, bootSummaries;
89
+ let otherBrokerRegistrations;
90
+ // A root with no control directory, or with no stack registered at it, holds no stack. That is a
91
+ // plain miss, not records that could not be read.
92
+ const noStack = () => new CommandFailure("refused", "TARGET_NOT_FOUND", "there is no stack at this folder's root, so there is nothing to preview", { target, remedy: "run `cotal down --dry-run` from the folder where `cotal up` started the stack" });
93
+ try {
94
+ try {
95
+ lstatSync(join(root, ".cotal"));
96
+ }
97
+ catch (error) {
98
+ if (error.code === "ENOENT")
99
+ throw noStack();
100
+ throw error;
101
+ }
102
+ if (!realDirNoSymlink(root, ".cotal"))
103
+ throw new Error("missing project control directory");
104
+ const local = localMeshesForRoot(root), sole = local[0];
105
+ if (!local.length)
106
+ throw noStack();
107
+ if (local.length !== 1 || sole?.origin !== "up")
108
+ throw new Error("no unique locally started stack at this root");
109
+ const candidate = selectedSpace ? findMesh(selectedSpace) : sole;
110
+ if (!candidate || candidate.origin !== "up" || candidate.space !== sole.space || canonicalRoot(candidate.root) !== root)
111
+ throw new Error("space does not belong to the selected root");
112
+ mesh = candidate;
113
+ assertSingleSpaceBroker(authDir(root), "down preview");
114
+ otherBrokerRegistrations = loadMeshes().filter((row) => row.space !== mesh.space && row.server === mesh.server)
115
+ .map((row) => ({ space: row.space, root: row.root, origin: row.origin ?? "not recorded" }));
116
+ maintenance = readMaintenanceJournal(root);
117
+ const context = { root, space: mesh.space };
118
+ components = localProcessSurface().map((component) => {
119
+ const pidfile = localProcessPath(component.pidFile, context);
120
+ const state = pidfileState(pidfile);
121
+ return { name: component.name, label: component.label, pidfile, recorded: processRecorded(component, context), liveness: state.liveness, pid: state.pid ?? null, note: state.note ?? null };
122
+ });
123
+ services = readLocalServiceCensus(mesh.space);
124
+ serviceStops = planBareDownServices(mesh.space);
125
+ additiveRecords = listLedgerFiles(root, { requireReadable: true });
126
+ additiveAttempts = listAdditiveTeamAttempts(root);
127
+ bootAttempts = listFreshTeamAttempts(root);
128
+ bootSummaries = listFreshTeamSummaries(root);
129
+ }
130
+ catch (error) {
131
+ if (error instanceof CommandFailure)
132
+ throw error;
133
+ throw new CommandFailure("refused", "CONFLICT", "the local stack, process or service records, or maintenance state could not be inspected consistently; no stop target was inferred", { target });
134
+ }
135
+ const byBootId = new Map(bootSummaries.valid.map((summary) => [summary.deploymentId, summary]));
136
+ const unsettledBootAttempts = bootAttempts.valid.filter((attempt) => !freshTeamAttemptSettled(attempt, byBootId.get(attempt.deploymentId)));
137
+ const result = { kind: "whole-stack-local-preview", space: mesh.space, root, recordedBroker: brokerAddressForDisplay(mesh.server) ?? null,
138
+ maintenance: maintenance?.state ?? "none-recorded", withAgentsRequested: args.values["with-agents"] === true,
139
+ components, ...services, serviceStops, otherBrokerRegistrations,
140
+ additiveLedgers: additiveRecords.valid.map(({ ledger }) => ({ deploymentId: ledger.runId, space: ledger.space, agents: ledger.created.agents.length, channels: ledger.created.channels.length })),
141
+ unreadableAdditiveLedgers: additiveRecords.refused.map(({ path }) => path),
142
+ retainedAdditiveAttempts: additiveAttempts.valid.map((attempt) => ({ deploymentId: attempt.deploymentId, space: attempt.space, server: brokerAddressForDisplay(attempt.server) ?? "not displayable", createdAt: attempt.createdAt, recordedState: additiveTeamRecordedState(attempt, additiveAttempts) })),
143
+ unreadableAdditiveAttempts: additiveAttempts.refused.map(({ path }) => path),
144
+ unsettledBootAttempts: unsettledBootAttempts.map((attempt) => ({ deploymentId: attempt.deploymentId, space: attempt.space, server: brokerAddressForDisplay(attempt.server) ?? "not displayable", createdAt: attempt.createdAt })),
145
+ unreadableBootRecords: [...bootAttempts.refused, ...bootSummaries.refused].map(({ path }) => path),
146
+ brokerSharing: "exact recorded address matches only; aliases and live tenants not checked", agentImpact: "not-established", serviceInstanceScope: "selected-space workstation records only; root ownership and live state not established",
147
+ dryRun: true, effectAttempted: false, reserved: false };
148
+ writeResult(presentationOf(args.values), { command: "down", target: { root, space: mesh.space }, result,
149
+ completeness: "partial", partial: { message: "Pidfiles, additive ledgers, service records, supervisor receipts and retained attempts are not a complete owned stack or native agent-impact plan. No process identity, service root ownership, broker sharing or stop authority was established." } }, (data) => ({ sections: [
150
+ { title: "Whole-stack local inspection", blocks: [{ kind: "fields", rows: [["Space", data.space], ["Root", data.root], ["Maintenance", data.maintenance], ["Saved service definitions", String(data.serviceDefinitions.length)], ["Saved service instances", String(data.serviceRecords.length)], ["Supervisor receipts", String(data.supervisors.length)], ["Retained native attempts", String(data.nativeAttempts.length)], ["Other exact-address registrations", String(data.otherBrokerRegistrations.length)], ["Additive ledgers", String(data.additiveLedgers.length)], ["Unreadable additive ledgers", String(data.unreadableAdditiveLedgers.length)], ["Retained additive deployments", String(data.retainedAdditiveAttempts.length)], ["Unreadable additive attempts", String(data.unreadableAdditiveAttempts.length)], ["Unsettled fresh attempts", String(data.unsettledBootAttempts.length)], ["Unreadable fresh records", String(data.unreadableBootRecords.length)], ["Deprovision agents", data.withAgentsRequested ? "requested; impact unknown" : "not requested; process impact unknown"], ["Stop authority", "not established"]] }, { kind: "lines", lines: [{ text: "This is a read of local records, not a stop plan. Liveness does not prove identity, and service, broker-sharing and agent consequences are not checked. No process was signalled.", tone: "waiting" }] }] },
151
+ { title: "Recorded broker address matches", blocks: [data.otherBrokerRegistrations.length ? { kind: "table", columns: [{ key: "space", label: "Other space" }, { key: "root", label: "Recorded root" }, { key: "origin", label: "Registration" }], rows: data.otherBrokerRegistrations.slice(0, 100) } : { kind: "lines", lines: ["No other registration uses this exact broker address in the local workstation registry."] }, { kind: "lines", lines: [...(data.otherBrokerRegistrations.length > 100 ? ["Additional exact-address matches are in JSON."] : []), "An exact-address match is a sharing warning. No match is not proof of an exclusive broker: aliases, remote tenants and live attachments were not checked."] }] },
152
+ { title: "Recorded additive deployments", blocks: [data.additiveLedgers.length ? { kind: "table", columns: [{ key: "id", label: "Deployment" }, { key: "space", label: "Recorded space" }, { key: "agents", label: "Agent rows" }, { key: "channels", label: "Channel rows" }], rows: data.additiveLedgers.slice(0, 100).map((row) => ({ id: row.deploymentId, space: row.space, agents: String(row.agents), channels: String(row.channels) })) } : { kind: "lines", lines: ["No readable additive ledgers under this project root."] }, { kind: "lines", lines: [...(data.additiveLedgers.length > 100 ? ["Additional additive ledgers are in JSON."] : []), ...data.unreadableAdditiveLedgers.slice(0, 100).map((path) => `Unreadable ledger: ${path}`), ...(data.unreadableAdditiveLedgers.length > 100 ? ["Additional unreadable paths are in JSON."] : []), "An additive ledger is not whole-stack ownership. A recorded or unreadable one blocks the retained bare apply; this preview changes nothing."] }] },
153
+ { title: "Retained additive deployments", blocks: [data.retainedAdditiveAttempts.length ? { kind: "table", columns: [{ key: "id", label: "Deployment" }, { key: "space", label: "Space" }, { key: "state", label: "Recorded state" }, { key: "time", label: "Intent recorded" }], rows: data.retainedAdditiveAttempts.slice(0, 100).map((attempt) => ({ id: attempt.deploymentId, space: attempt.space, state: attempt.recordedState, time: attempt.createdAt })) } : { kind: "lines", lines: ["No readable additive attempts under this root."] }, { kind: "lines", lines: [...data.unreadableAdditiveAttempts.slice(0, 100).map((path) => `Unreadable additive attempt: ${path}`), ...(data.retainedAdditiveAttempts.length > 100 || data.unreadableAdditiveAttempts.length > 100 ? ["Additional attempts or paths are in JSON."] : []), "Unsettled or unremoved additive deployments block the legacy bare stop. A full matched static agent-retirement receipt releases only its original deployment's blocker; all other ownership and process guards remain."] }] },
154
+ { title: "Fresh boot attempts", blocks: [data.unsettledBootAttempts.length ? { kind: "table", columns: [{ key: "deploymentId", label: "Deployment" }, { key: "space", label: "Space" }, { key: "server", label: "Recorded broker" }, { key: "createdAt", label: "Intent recorded" }], rows: data.unsettledBootAttempts.slice(0, 100) } : { kind: "lines", lines: ["No unsettled readable fresh boot attempts under this root."] }, { kind: "lines", lines: [...data.unreadableBootRecords.slice(0, 100).map((path) => `Unreadable fresh record: ${path}`), ...(data.unsettledBootAttempts.length > 100 || data.unreadableBootRecords.length > 100 ? ["Additional attempts or unreadable paths are in JSON."] : []), "An unsettled fresh attempt or unreadable record blocks the retained bare apply; a missing summary does not prove the broker never started."] }] },
155
+ { title: "Local process records", blocks: [data.components.length ? { kind: "table", columns: [{ key: "name", label: "Component" }, { key: "state", label: "Pidfile probe" }, { key: "record", label: "Recorded" }, { key: "pid", label: "PID" }], rows: data.components.map((row) => ({ name: row.label, state: row.liveness, record: row.recorded ? "yes" : "no", pid: row.pid === null ? "not pinned" : String(row.pid) })) } : { kind: "lines", lines: ["No local process descriptors were found."] }] },
156
+ { title: "Selected-space service definitions", blocks: [data.serviceDefinitions.length ? { kind: "table", columns: [{ key: "name", label: "Definition" }, { key: "launch", label: "Launch type" }, { key: "instances", label: "Instance records" }], rows: data.serviceDefinitions.slice(0, 100).map((row) => ({ name: row.name, launch: row.launch, instances: String(row.instanceRecords) })) } : { kind: "lines", lines: ["No saved service definitions in this space's workstation store."] }, ...(data.serviceDefinitions.length > 100 ? [{ kind: "lines", lines: ["Additional definitions are in JSON."] }] : [])] },
157
+ { title: "Selected-space service instances", blocks: [data.serviceRecords.length ? { kind: "table", columns: [{ key: "definition", label: "Definition" }, { key: "instance", label: "Full instance" }, { key: "state", label: "Recorded state" }, { key: "host", label: "Recorded host" }], rows: data.serviceRecords.slice(0, 100).map((row) => ({ definition: row.definition, instance: row.instanceId, state: row.recordedState, host: row.host })) } : { kind: "lines", lines: ["No saved service instances in this space's workstation store."] }, { kind: "lines", lines: [...(data.serviceRecords.length > 100 ? ["Additional service records are in JSON."] : []), "These records are scoped by space, not proven owned by this project root. Their recorded state is not live process or supervisor status; the next section observes each process on this host."] }] },
158
+ ...(data.serviceStops.length ? bareDownServicesView(data.space, data.serviceStops).sections : [{ title: "Services bare down stops first", blocks: [{ kind: "lines", lines: ["No saved service instance in this space, so bare down stops no service first."] }] }]),
159
+ { title: "Recorded native supervisors", blocks: [data.supervisors.length ? { kind: "table", columns: [{ key: "definition", label: "Definition" }, { key: "instance", label: "Full instance" }, { key: "mechanism", label: "Mechanism" }, { key: "unit", label: "Recorded unit" }], rows: data.supervisors.slice(0, 100).map((row) => ({ definition: row.definition, instance: row.instanceId, mechanism: row.mechanism, unit: row.unit })) } : { kind: "lines", lines: ["No supervisor receipts in this space's workstation store."] }, { kind: "lines", lines: [...(data.supervisors.length > 100 ? ["Additional supervisor receipts are in JSON."] : []), "A receipt is not a live unit observation or authority to stop it. No native service status request was made."] }] },
160
+ { title: "Retained native attempts", blocks: [data.nativeAttempts.length ? { kind: "table", columns: [{ key: "kind", label: "Action" }, { key: "definition", label: "Definition" }, { key: "instance", label: "Full instance" }, { key: "step", label: "Step" }, { key: "position", label: "Position" }], rows: data.nativeAttempts.slice(0, 100).map((row) => ({ kind: row.kind, definition: row.definition, instance: row.instanceId, step: row.step, position: row.position })) } : { kind: "lines", lines: ["No retained install, uninstall or unit-action attempts in this space's workstation store."] }, { kind: "lines", lines: [...(data.nativeAttempts.length > 100 ? ["Additional attempts and their full IDs are in JSON."] : []), "A submitted or unknown step may already have changed native state. This preview neither reconciles nor retries it."] }] },
161
+ ] }));
162
+ }
163
+ /** A bare stop, its preview included: no flag beyond --dry-run, --with-agents and the presentation
164
+ * flags. */
165
+ function bareStop(values) {
166
+ return Object.entries(values).every(([name, value]) => ["dry-run", "with-agents", "json", "plain"].includes(name) || value === undefined || Array.isArray(value) && value.length === 0);
167
+ }
168
+ /** Whether any process record (`*.pid`) remains in `<root>/.cotal`. */
169
+ const pidRecordsUnder = (root) => readdirSync(join(root, ".cotal")).some((name) => name.endsWith(".pid"));
170
+ /** A legacy root whose stack is not running, told apart from a folder that never had one. No
171
+ * registration names the root, because its own down removed the last one, and no `*.pid` record
172
+ * remains at the top of its `.cotal`. The root still holds the broker configuration a start rendered
173
+ * there (`server-open.conf`, or `auth/server.conf` in auth mode) or a space prepared there. When the
174
+ * root names its space, none of that space's saved services runs either. Undefined when any of that
175
+ * is missing, so bare down refuses rather than guess. `nothingRunning` reads every other record a
176
+ * local-process descriptor names under the root, for any space, before it answers. */
177
+ function stoppedLegacyStack() {
178
+ const root = canonicalRoot(cotalRoot());
179
+ if (root === canonicalRoot(homedir()) || !realDirNoSymlink(root, ".cotal") || meshesForRoot(root).length || pidRecordsUnder(root))
180
+ return undefined;
181
+ let space;
182
+ try {
183
+ space = soleSpaceOf(authDir(root));
184
+ }
185
+ catch {
186
+ return undefined;
187
+ }
188
+ const prepared = preparedSpaceAt(root);
189
+ if (!prepared && !existsSync(join(root, ".cotal", "server-open.conf")) && !existsSync(join(authDir(root), "server.conf")))
190
+ return undefined;
191
+ space ??= prepared?.space;
192
+ if (space !== undefined && planBareDownServices(space).some((row) => row.action !== "already-stopped"))
193
+ return undefined;
194
+ return { root, ...(space === undefined ? {} : { space }) };
195
+ }
196
+ /** Why bare down found no stack of its own at this root, with the one step that moves it on. */
197
+ function noOwnedStack(root) {
198
+ const target = { root };
199
+ const absent = new CommandFailure("refused", "TARGET_NOT_FOUND", "there is no stack at this folder's root, so there is nothing to stop", { target, remedy: "run `cotal down` from the folder where `cotal up` started the stack" });
200
+ const unclassified = new CommandFailure("refused", "CONFLICT", "the local root has no unique owned stack registration and real control directory; no whole-stack stop target was inferred", { target, remedy: "run `cotal status` here to see what this folder records" });
201
+ if (!existsSync(join(root, ".cotal")))
202
+ return absent;
203
+ if (!realDirNoSymlink(root, ".cotal"))
204
+ return unclassified;
205
+ let local, registered;
206
+ try {
207
+ local = localMeshesForRoot(root);
208
+ registered = meshesForRoot(root).length;
209
+ }
210
+ catch {
211
+ return unclassified;
212
+ }
213
+ if (local.length > 1)
214
+ return new CommandFailure("refused", "CONFLICT", `${local.length} registrations name this root (${local.map((mesh) => `"${mesh.space}"`).join(", ")}); bare down did not pick one to stop`, {
215
+ target: { root, spaces: local.map((mesh) => mesh.space) },
216
+ remedy: "remove the one that does not run here with `cotal space forget <name>`",
217
+ });
218
+ // A registration of any kind, or a process record no registration explains, is a stack this
219
+ // cannot classify.
220
+ if (registered || pidRecordsUnder(root))
221
+ return unclassified;
222
+ return absent;
223
+ }
224
+ /** Keep the retained pidfile sweep from crossing an exact recorded broker-sharing boundary, and
225
+ * return the space's service instances it stops first, each one verified. This is not a complete
226
+ * live ownership or agent-impact proof. */
227
+ function guardLegacyBareDown() {
228
+ const root = canonicalRoot(cotalRoot());
229
+ const target = { root };
230
+ if (root === canonicalRoot(homedir()))
231
+ throw new CommandFailure("refused", "CONFLICT", "the machine home is not an isolated whole-stack stop root; no process was signalled", { target, remedy: MACHINE_HOME_STOP });
232
+ let mesh;
233
+ try {
234
+ if (!realDirNoSymlink(root, ".cotal"))
235
+ throw new Error("missing project control directory");
236
+ // A root that hosts several spaces refuses before the registration lookup, naming them.
237
+ try {
238
+ assertSingleSpaceBroker(authDir(root), "bare down");
239
+ }
240
+ catch (error) {
241
+ throw new CommandFailure("refused", "CONFLICT", error.message, { target });
242
+ }
243
+ const local = localMeshesForRoot(root), sole = local[0];
244
+ if (local.length !== 1 || sole?.origin !== "up")
245
+ throw new Error("no unique locally started stack at this root");
246
+ mesh = sole;
247
+ }
248
+ catch (error) {
249
+ if (error instanceof CommandFailure)
250
+ throw error;
251
+ throw noOwnedStack(root);
252
+ }
253
+ const scoped = { root, space: mesh.space };
254
+ const maintenance = readMaintenanceJournal(root);
255
+ // A validated active restore is complete, so its retained journal does not fence ordinary stop.
256
+ // Pending transitions and a journal naming another space still cannot authorize this sweep.
257
+ if (maintenance && (maintenance.state !== "active" || maintenance.space !== mesh.space))
258
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "this stack retains a maintenance transition; ordinary bare down did not bypass it", { target: { ...scoped, state: maintenance.state } });
259
+ let ledgers;
260
+ try {
261
+ ledgers = listLedgerFiles(root, { requireReadable: true });
262
+ }
263
+ catch {
264
+ throw new CommandFailure("refused", "TARGET_UNAVAILABLE", "the root's additive ledger directory could not be inspected; bare down did not infer that it owns every resource", { target: scoped });
265
+ }
266
+ if (ledgers.valid.length || ledgers.refused.length)
267
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "additive ownership ledgers or unreadable ledger records remain under this root; bare down did not adopt or stop their resources", { target: { ...scoped, deploymentIds: ledgers.valid.map(({ ledger }) => ledger.runId), unreadable: ledgers.refused.map(({ path }) => path) }, remedy: "finish each additive deployment's own lifecycle before a guarded whole-stack stop" });
268
+ let additiveAttempts;
269
+ try {
270
+ additiveAttempts = listAdditiveTeamAttempts(root);
271
+ }
272
+ catch {
273
+ throw new CommandFailure("refused", "TARGET_UNAVAILABLE", "the additive attempt inventory could not be read; bare down did not infer an empty resource set", { target: scoped });
274
+ }
275
+ if (retainedAdditiveTeamAttempts(additiveAttempts).length || additiveAttempts.refused.length)
276
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "an additive attempt or returned additive deployment remains under this root; legacy bare down did not adopt its resources", { target: { ...scoped, deploymentIds: retainedAdditiveTeamAttempts(additiveAttempts).map((attempt) => attempt.deploymentId), unreadable: additiveAttempts.refused.map(({ path }) => path) } });
277
+ let attempts, summaries;
278
+ try {
279
+ attempts = listFreshTeamAttempts(root);
280
+ summaries = listFreshTeamSummaries(root);
281
+ }
282
+ catch {
283
+ throw new CommandFailure("refused", "TARGET_UNAVAILABLE", "fresh boot attempt or summary records could not be read; bare down did not infer stop authority", { target: scoped });
284
+ }
285
+ const returned = new Map(summaries.valid.map((summary) => [summary.deploymentId, summary]));
286
+ const unsettled = attempts.valid.filter((attempt) => !freshTeamAttemptSettled(attempt, returned.get(attempt.deploymentId)));
287
+ if (unsettled.length || attempts.refused.length || summaries.refused.length)
288
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "a fresh boot attempt is unsettled or a boot record unreadable; legacy bare down did not stop a process whose original launch outcome is unknown", { target: { ...scoped, unsettledIds: unsettled.map((row) => row.deploymentId), unreadable: [...attempts.refused, ...summaries.refused].map(({ path }) => path) }, remedy: "inspect the original boot and process custody before any stop; the pidfile sweep is not recovery" });
289
+ const other = loadMeshes().filter((row) => row.space !== mesh.space && row.server === mesh.server);
290
+ if (other.length)
291
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "another registered space names this exact broker address; bare down did not stop its shared listener", { target: { ...scoped, otherSpaces: other.map((row) => row.space) }, remedy: "inspect both registrations and their native ownership; an exact-address match is a blocker, while no match does not prove exclusivity" });
292
+ const services = planBareDownServices(mesh.space);
293
+ assertBareDownServicesVerified(mesh.space, services);
294
+ return { space: mesh.space, services };
295
+ }
296
+ /** Bare down reads each process record it stops where the record lies, as the stopped-stack census
297
+ * does. A record that read leaves unread (a link on its path, a record that is not a regular file,
298
+ * is larger than a record, cannot be opened or changes while it is read) refuses before the first
299
+ * stop, naming where reading stopped: no process behind it is read, signalled or unrecorded. */
300
+ function refuseUncontainedRecords(components, context) {
301
+ const unread = new Map();
302
+ for (const component of components) {
303
+ const record = readContainedRecord(context.root, localProcessPath(component.pidFile, context));
304
+ if (record.state === "unread" && !unread.has(record.at))
305
+ unread.set(record.at, recordedProcessLine({ name: component.name, path: relative(context.root, record.at), note: record.why }));
306
+ }
307
+ if (!unread.size)
308
+ return;
309
+ const paths = [...unread.keys()].map((at) => relative(context.root, at));
310
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", `process records under this root cannot be read in place (${[...unread.values()].join("; ")}), so bare down stopped nothing; it does not read or signal through them`, {
311
+ target: { root: context.root, space: context.space, processes: [...unread.values()] },
312
+ remedy: `check ${paths.join(", ")}; stop each process where it was started, and replace a link with this stack's own record or remove it, then run \`cotal down\` again`,
313
+ });
314
+ }
315
+ /** One named service is a thin native-controller alias. The retained bare-stack and manifest
316
+ * paths below have not yet been replaced by the approved whole-stack controller. */
34
317
  export async function down(args) {
318
+ validateDownArguments(args);
319
+ if (args.positionals.length > 1)
320
+ return stopNamedServiceSet(args);
321
+ if (args.positionals.length)
322
+ return service(namedStopArguments(args), "down");
323
+ // A root whose stack the service controller owns stops only through its recorded members.
324
+ if (controllerStackRecorded(cotalRoot()))
325
+ return stackDown(cotalRoot(), args.values);
35
326
  const values = args.values;
36
- const requested = [...new Set(args.positionals)];
327
+ // A legacy root whose stack is already stopped: a bare down and its preview stop nothing.
328
+ if (bareStop(args.values)) {
329
+ const stopped = stoppedLegacyStack();
330
+ if (stopped)
331
+ return nothingRunning(presentationOf(args.values), stopped, values["with-agents"] === true && values["dry-run"] !== true);
332
+ }
333
+ if (values["dry-run"] && !values.file && !values.run && !values["preserve-state"] && !values["store-dir"] && !values["session-store"]?.length)
334
+ return previewWholeStack(args);
37
335
  if (values["preserve-state"] && values["with-agents"])
38
- throw new Error("--preserve-state cannot be combined with --with-agents");
39
- if (values["with-agents"] && (requested.length || values.file || values.run || values.space))
40
- throw new Error("--with-agents is bare-whole-stack only and cannot be combined with components, --space, --file, or --run");
336
+ throw new CommandFailure("refused", "USAGE_INVALID", "--preserve-state cannot be combined with --with-agents");
337
+ if (values["with-agents"] && (values.file || values.run || values.space))
338
+ throw new CommandFailure("refused", "USAGE_INVALID", "--with-agents is bare-whole-stack only and cannot be combined with components, --space, --file, or --run");
41
339
  if (values["preserve-state"]) {
42
- if (requested.length || values.file || values.run || values["dry-run"] || values.space)
43
- throw new Error("--preserve-state is bare-whole-stack only and cannot be combined with components, --space, --file, --run, or --dry-run");
340
+ if (values.file || values.run || values["dry-run"] || values.space)
341
+ throw new CommandFailure("refused", "USAGE_INVALID", "--preserve-state is bare-whole-stack only and cannot be combined with components, --space, --file, --run, or --dry-run");
44
342
  assertSingleSpaceBroker(authDir(cotalRoot()), "cotal down");
45
343
  await preserveStateDown(values["store-dir"], assertSessionStores(values["session-store"] ?? []));
46
344
  return;
47
345
  }
48
346
  if (values["store-dir"])
49
- throw new Error("--store-dir is only valid with down --preserve-state");
347
+ throw new CommandFailure("refused", "USAGE_INVALID", "--store-dir is only valid with down --preserve-state");
50
348
  if (values["session-store"]?.length)
51
- throw new Error("--session-store is only valid with down --preserve-state");
52
- if ((values.file || values.run) && (requested.length || values.space)) {
53
- throw new Error("component names and --space cannot be combined with --file or --run");
349
+ throw new CommandFailure("refused", "USAGE_INVALID", "--session-store is only valid with down --preserve-state");
350
+ if ((values.file || values.run) && values.space) {
351
+ throw new CommandFailure("refused", "USAGE_INVALID", "component names and --space cannot be combined with --file or --run");
54
352
  }
55
353
  if (values.file || values.run) {
56
354
  await downManifest(values.file ?? "<run>", { run: values.run, dryRun: Boolean(values["dry-run"]) });
57
355
  return;
58
356
  }
59
- if (values.space && !requested.length)
60
- throw new Error("--space only selects the mesh for target-addressed components - name them (e.g. `cotal down web --space <name>`); bare `cotal down` always stops this folder's stack");
61
- const all = localProcessSurface();
62
- const known = all.map((component) => component.name).sort();
63
- const unknown = requested.filter((name) => !known.includes(name));
64
- if (unknown.length)
65
- throw new Error(`unknown component${unknown.length > 1 ? "s" : ""} ${unknown.map((name) => JSON.stringify(name)).join(", ")} - known: ${known.join(", ")}`);
66
- const selected = (requested.length ? requested.map((name) => all.find((part) => part.name === name)) : all)
357
+ if (values.space)
358
+ throw new CommandFailure("refused", "USAGE_INVALID", "a bare stop takes no --space: `cotal down` stops the stack recorded at this folder's root", {
359
+ target: { root: cotalRoot(), space: values.space },
360
+ remedy: "run `cotal down` without --space from the stack's root; to stop one saved service, run `cotal service stop <service-name> --space <space>`",
361
+ });
362
+ const guarded = guardLegacyBareDown();
363
+ const selected = localProcessSurface()
67
364
  .sort((a, b) => Number(Boolean(a.stopLast)) - Number(Boolean(b.stopLast)) || (a.order ?? 50) - (b.order ?? 50));
68
- // A component whose START is target-resolved (`rootedAt: "target"` — the web dashboard) records
69
- // its pidfile under the TARGET mesh's root, so a selective stop resolves the SAME mesh the start
70
- // side did (registry current mesh first, `--space` to name one) instead of assuming this folder.
71
- // Bare `cotal down` stays a sweep of this folder's stack: its pidfiles live here, and reaching
72
- // into another mesh's root mid-sweep would stop a process the folder's broker does not own.
73
- const targetAddressed = (component) => requested.length > 0 && component.rootedAt === "target";
74
- if (values.space) {
75
- const folderRooted = selected.filter((component) => !targetAddressed(component));
76
- if (folderRooted.length)
77
- throw new Error(`--space only applies to target-addressed components - ${folderRooted.map((component) => component.name).join(", ")} always stop${folderRooted.length === 1 ? "s" : ""} under this folder's root`);
78
- }
79
365
  // A `down` that touches this folder's stack stops the shared broker and its per-space daemons;
80
366
  // none of them can address one space, so a multi-space root is refused up front rather than at
81
- // the space-blind pidfile lookup below. A purely target-addressed stop never reads this folder's
82
- // pidfiles, so it is exempt (its space comes from the resolved mesh target).
83
- if (selected.some((component) => !targetAddressed(component)))
84
- assertSingleSpaceBroker(authDir(cotalRoot()), "cotal down");
85
- // Both contexts resolve lazily: a purely target-addressed stop must not require a mesh root at
86
- // the cwd, and a folder sweep must not require a resolvable mesh target.
367
+ // the space-blind pidfile lookup below.
368
+ assertSingleSpaceBroker(authDir(cotalRoot()), "cotal down");
87
369
  let folderContext;
88
370
  const folderCtx = () => (folderContext ??= { root: cotalRoot(), space: resolveRuntimeSpace(process.cwd()) });
89
- let targetContext;
90
- const contextFor = (component) => {
91
- if (!targetAddressed(component))
92
- return folderCtx();
93
- if (!targetContext) {
94
- const target = resolveMeshTarget(process.cwd(), values.space ? { space: values.space } : {});
95
- targetContext = { root: target.root, space: target.space };
96
- }
97
- return targetContext;
98
- };
99
- if (selected.some((component) => component.stopLast)) {
100
- const selectedNames = new Set(selected.map((component) => component.name));
101
- // Fail CLOSED: an unselected dependant that MIGHT be running (including one behind an
102
- // unattributable/unknown pidfile) blocks a stop-last shutdown - stopping the broker out from
103
- // under a live dependant we could not confirm gone is exactly the signer-orphan the contract
104
- // forbids. `mayBeRunning`, not `processAlive` (which reads uncertainty as "not running").
105
- // Folder context: the question is what depends on THIS folder's broker, so a dependant is
106
- // judged by the record under this root regardless of how it would be addressed selectively.
107
- const dependants = all.filter((component) => !selectedNames.has(component.name) && mayBeRunning(component, folderCtx()));
108
- if (dependants.length) {
109
- throw new Error(`cannot stop ${selected.filter((component) => component.stopLast).map((component) => component.name).join(", ")} while ${dependants.map((component) => component.name).join(", ")} ${dependants.length === 1 ? "is" : "are"} still running (or its liveness cannot be confirmed) - name them too, or run bare \`cotal down\``);
110
- }
111
- }
112
- if (values["dry-run"]) {
113
- const recorded = selected.filter((component) => processRecorded(component, contextFor(component)));
114
- for (const component of recorded)
115
- console.log(c.dim(`would stop ${component.label}`));
116
- if (!recorded.length) {
117
- const target = requested.length ? requested.join(", ") : "the local stack";
118
- console.error(c.red(`Nothing running for ${target} (no recorded pidfiles).`));
119
- process.exit(1);
120
- }
121
- console.log(c.dim("Dry run - nothing was changed. Re-run without --dry-run to stop these components."));
122
- return;
123
- }
371
+ refuseUncontainedRecords(selected, folderCtx());
372
+ // Every dry run returned or was refused above, so from here on this is the whole-stack stop of
373
+ // this folder's root. Its services stop first, through the service controller.
374
+ await stopBareDownServices(guarded.space, guarded.services, { style: "rich", withAgents: values["with-agents"] === true });
124
375
  let any = false;
125
376
  let allStopped = true;
126
377
  for (const component of selected) {
127
- any = processRecorded(component, contextFor(component)) || any;
378
+ any = processRecorded(component, folderCtx()) || any;
128
379
  if (component.stopLast && !allStopped) {
129
380
  console.error(c.red(`✗ not stopping ${component.label} because an earlier component did not stop`));
130
381
  continue;
131
382
  }
132
383
  try {
133
- const context = contextFor(component);
384
+ const context = folderCtx();
134
385
  if (component.name === "manager")
135
386
  await stopManager(context.space, { withAgents: values["with-agents"] });
136
387
  else if (component.name === "delivery")
137
- await stopDelivery(context.space, { preserveCredentials: !requested.length });
388
+ await stopDelivery(context.space, { preserveCredentials: true });
138
389
  else
139
390
  await stopLocalProcess(component, context);
140
391
  }
@@ -148,11 +399,11 @@ export async function down(args) {
148
399
  process.exitCode = 1;
149
400
  return;
150
401
  }
151
- if (!requested.length && selected.some((component) => component.name === "delivery"))
402
+ if (selected.some((component) => component.name === "delivery"))
152
403
  await removeDeliveryCredentials(folderCtx().space);
153
404
  for (const component of selected) {
154
405
  for (const artifact of component.artifacts ?? [])
155
- rmSync(localProcessPath(artifact, contextFor(component)), { force: true });
406
+ rmSync(localProcessPath(artifact, folderCtx()), { force: true });
156
407
  }
157
408
  // Pidfiles are the only thing this stack owns. A registered broker that answers with no pidfile
158
409
  // is a different situation: something is running that `down` did not start and must not stop.
@@ -161,27 +412,24 @@ export async function down(args) {
161
412
  // Owned components (a detached web, a manager) do not change the question: stopping them is not
162
413
  // the same as this stack owning the broker. The probe runs on every bare down that holds no
163
414
  // nats pidfile, AFTER their owned artifacts cleared, so those components stop exactly as they
164
- // do with no broker present. Targeted stops and --dry-run stay pidfile-only.
165
- if (!requested.length && !values["dry-run"]) {
166
- const unowned = await liveUnownedBrokers(folderCtx());
167
- if (unowned.length) {
168
- for (const broker of unowned) {
169
- console.error(c.red(`Broker for "${broker.space}" is running at ${broker.server}, but no pidfile records it. ` +
170
- `cotal down will not stop a process it did not start. ` +
171
- `Stop that broker with the supervisor that started it, or remove the registration with \`cotal meshes rm ${broker.space}\`.`));
172
- }
173
- process.exit(1);
415
+ // do with no broker present.
416
+ const unowned = await liveUnownedBrokers(folderCtx());
417
+ if (unowned.length) {
418
+ for (const broker of unowned) {
419
+ console.error(c.red(`Broker for "${broker.space}" is running at ${broker.server}, but no pidfile records it. ` +
420
+ `cotal down will not stop a process it did not start. ` +
421
+ `Stop that broker with the supervisor that started it, or remove the registration with \`cotal meshes rm ${broker.space}\`.`));
174
422
  }
423
+ process.exit(1);
175
424
  }
176
- // The broker owns the mesh registry entry and transient whole-mesh launch material. Selective
177
- // control-plane shutdown leaves both intact so `cotal up` can heal only what was stopped.
425
+ // The broker owns the mesh registry entry and transient whole-mesh launch material, so they go
426
+ // with it.
178
427
  if (selected.some((component) => component.clearsMesh)) {
179
428
  rmSync(join(folderCtx().root, ".cotal", "run"), { recursive: true, force: true });
180
429
  removeMeshesByRoot(folderCtx().root);
181
430
  }
182
431
  if (!any) {
183
- const target = requested.length ? requested.join(", ") : "the local stack";
184
- console.error(c.red(`Nothing running for ${target} (no recorded pidfiles).`));
432
+ console.error(c.red("Nothing running for the local stack (no recorded pidfiles)."));
185
433
  process.exit(1);
186
434
  }
187
435
  }
@@ -212,14 +460,14 @@ export function processAlive(component, context) {
212
460
  const pid = parsePid(raw);
213
461
  return pid !== undefined && isAlive(pid);
214
462
  }
215
- /** Whether a component MIGHT still be running - the question the pre-stop `stopLast` guard must ask,
216
- * and it fails CLOSED on uncertainty. A component with NO pidfile, an EMPTY husk, or a valid pid
217
- * PROVEN dead (ESRCH) is not running. ANY other state - an unparsable/unattributable record, or a
218
- * valid pid that is alive or whose liveness cannot be confirmed (`unknown`) - MIGHT be running, so
219
- * it must BLOCK a stop-last (broker) shutdown. `processAlive` collapses unparsable and `unknown` to
220
- * "not alive", which is fine for "is it worth stopping" but WRONG for "is it safe to stop the broker
221
- * out from under this": that read would let `cotal down nats` orphan a live auth signer behind a
222
- * torn pidfile. Only an ESRCH-confirmed death (or no record) clears a dependant. */
463
+ /** Whether a component MIGHT still be running. It fails CLOSED on uncertainty. A component with NO
464
+ * pidfile, an EMPTY husk, or a valid pid PROVEN dead (ESRCH) is not running. ANY other state - an
465
+ * unparsable/unattributable record, or a valid pid that is alive or whose liveness cannot be
466
+ * confirmed (`unknown`) - MIGHT be running. `down --preserve-state` asks it to fence an uncertain
467
+ * delivery daemon, to treat an uncertain manager as alive, and to refuse to call a cut complete.
468
+ * `processAlive` collapses unparsable and `unknown` to "not alive", which is fine for "is it worth
469
+ * stopping" but WRONG for those questions: it would count a live auth signer behind a torn pidfile
470
+ * as stopped. Only an ESRCH-confirmed death (or no record) clears a component. */
223
471
  export function mayBeRunning(component, context) {
224
472
  const raw = readPidfile(localProcessPath(component.pidFile, context));
225
473
  if (!raw)
@@ -231,7 +479,7 @@ export function mayBeRunning(component, context) {
231
479
  }
232
480
  /** The principal keys of every retained agent in a preservation inventory — the dot-form ids that
233
481
  * appear in the presence roster, so a caller can tell which retained agents are still live. */
234
- function retainedPrincipalKeys(inventory) {
482
+ export function retainedPrincipalKeys(inventory) {
235
483
  const agents = (inventory.agents ?? []);
236
484
  return new Set(agents.map((agent) => {
237
485
  if (agent.identity?.mode === "user" && agent.identity.owner && agent.identity.actor)
@@ -258,10 +506,10 @@ function assertSessionStores(paths) {
258
506
  stat = statSync(resolved);
259
507
  }
260
508
  catch (error) {
261
- throw new Error(`--session-store ${resolved} cannot be read (${error.code ?? error.message}); name the harness transcript store directory for this host`);
509
+ throw new CommandFailure("refused", "USAGE_INVALID", `--session-store ${resolved} cannot be read (${error.code ?? error.message}); name the harness transcript store directory for this host`);
262
510
  }
263
511
  if (!stat.isDirectory())
264
- throw new Error(`--session-store ${resolved} is not a directory; name the harness transcript store directory for this host`);
512
+ throw new CommandFailure("refused", "USAGE_INVALID", `--session-store ${resolved} is not a directory; name the harness transcript store directory for this host`);
265
513
  return resolved;
266
514
  });
267
515
  }
@@ -269,13 +517,16 @@ async function preserveStateDown(storeOverride, sessionStores = []) {
269
517
  const root = cotalRoot();
270
518
  const matching = loadMeshes().filter((mesh) => mesh.root === root);
271
519
  if (matching.length !== 1)
272
- throw new Error(`down --preserve-state requires exactly one recorded mesh for this root; found ${matching.length}`);
520
+ throw new CommandFailure("refused", matching.length ? "TARGET_AMBIGUOUS" : "TARGET_NOT_FOUND", `down --preserve-state requires exactly one recorded mesh for this root; found ${matching.length}, and nothing was stopped`, { target: { root, spaces: matching.map((mesh) => mesh.space) } });
273
521
  const mesh = matching[0];
274
522
  const storeDir = storeOverride ? resolveStore(storeOverride) : join(root, ".cotal", "nats");
275
523
  // The store cap the broker was started with travels with the store, so the resume re-renders it.
276
524
  const cap = mesh.maxFileStore !== undefined ? { maxFileStore: mesh.maxFileStore } : {};
277
525
  const lock = acquireMaintenanceLock(root);
278
526
  try {
527
+ const additiveAttempts = listAdditiveTeamAttempts(root);
528
+ if (retainedAdditiveTeamAttempts(additiveAttempts).length || additiveAttempts.refused.length)
529
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "an additive attempt or returned additive deployment remains; preserve-state down did not fold its resources into the retained stack", { target: { root, space: mesh.space, deploymentIds: retainedAdditiveTeamAttempts(additiveAttempts).map((attempt) => attempt.deploymentId), unreadable: additiveAttempts.refused.map(({ path }) => path) } });
279
530
  const all = localProcessSurface();
280
531
  const context = { root, space: mesh.space };
281
532
  const existing = readMaintenanceJournal(root);
@@ -364,6 +615,14 @@ async function preserveStateDown(storeOverride, sessionStores = []) {
364
615
  }
365
616
  }
366
617
  else {
618
+ // The cut takes its agent inventory from the manager that serves the space. A stack with no
619
+ // manager, such as one started with --no-manager, refuses here, before the prepare intent, the
620
+ // delivery stop or any other effect.
621
+ if ((await readPresenceAndLease(mesh.space, mesh.server)).managerId === undefined)
622
+ throw new CommandFailure("refused", "TARGET_UNAVAILABLE", "no manager serves this space, so --preserve-state cannot take the agent inventory it preserves; nothing was stopped", {
623
+ target: { root, space: mesh.space, server: mesh.server },
624
+ remedy: "start this stack's manager with `cotal up`, then run `cotal down --preserve-state` again",
625
+ });
367
626
  // The attempt binding is durable BEFORE the manager is fenced: a crash between manager
368
627
  // preparation and the cut-intent journal retries with the exact attempt the manager holds.
369
628
  const intent = readPreservationPrepareIntent(root);
@@ -550,7 +809,7 @@ async function preserveStateDown(storeOverride, sessionStores = []) {
550
809
  * source`, and a checkpoint inherits that refusal rather than writing something that will not
551
810
  * reproduce the seat.
552
811
  */
553
- function assertSeatsCheckpointable(inventory) {
812
+ export function assertSeatsCheckpointable(inventory) {
554
813
  for (const entry of (inventory.agents ?? [])) {
555
814
  const keys = entry.launch?.unresolvedLaunchOptionKeys ?? [];
556
815
  if (keys.length)
@@ -560,7 +819,7 @@ function assertSeatsCheckpointable(inventory) {
560
819
  }
561
820
  }
562
821
  /** Capture one checkpoint per retained seat, after the cut has proven the whole stack down. */
563
- async function captureSeatCheckpoints(root, space, resume, destination, sessionStores) {
822
+ export async function captureSeatCheckpoints(root, space, resume, destination, sessionStores) {
564
823
  const document = readMaintenanceResumeDocument(root, resume);
565
824
  const inventory = document.inventory;
566
825
  const agents = inventory?.agents ?? [];
@@ -631,7 +890,7 @@ async function directKvValue(nc, stream, subject, allowEmpty = false) {
631
890
  * continuously, so the cut publishes `ready` only once BOTH lease buckets hold no live value —
632
891
  * a dead daemon's lease expires by TTL, a pidless live one keeps renewing and is refused here.
633
892
  * Pidfiles are hints; leases are proof. */
634
- async function assertControlPlaneQuiesced(space, server) {
893
+ export async function assertControlPlaneQuiesced(space, server) {
635
894
  const resolved = await connectOrExit({ space, server }, "deployer");
636
895
  const user = resolved.bearer ? await userViewAuthOrExit(resolved, "deployer") : undefined;
637
896
  const nc = await dialerFor(server)({
@@ -680,6 +939,14 @@ async function assertControlPlaneQuiesced(space, server) {
680
939
  * THIS function, not a transcription of it: a copy carries its own `allowEmpty` parameter, so it
681
940
  * stays green when the argument at the real call site is removed and proves nothing about the fix. */
682
941
  export async function readPresenceWithoutConsumer(space, server) {
942
+ const { roster, managerId } = await readPresenceAndLease(space, server);
943
+ if (managerId === undefined)
944
+ throw new Error("manager lease has no authoritative holder principal");
945
+ return { roster, managerId };
946
+ }
947
+ /** The roster and the principal holding the space's manager lease, or no holder when no manager
948
+ * serves the space. */
949
+ async function readPresenceAndLease(space, server) {
683
950
  const resolved = await connectOrExit({ space, server }, "deployer");
684
951
  const user = resolved.bearer ? await userViewAuthOrExit(resolved, "deployer") : undefined;
685
952
  const nc = await dialerFor(server)({
@@ -730,7 +997,7 @@ export async function readPresenceWithoutConsumer(space, server) {
730
997
  }
731
998
  }
732
999
  if (!lease?.holder)
733
- throw new Error("manager lease has no authoritative holder principal");
1000
+ return { roster };
734
1001
  return { roster, managerId: parsePrincipalKey(lease.holder) ? lease.holder : principalKey(DEV_OWNER, lease.holder).key };
735
1002
  }
736
1003
  finally {