@cotal-ai/cli 0.90.0 → 0.91.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 (759) 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 +19 -0
  6. package/dist/chat/controller.d.ts.map +1 -0
  7. package/dist/chat/controller.js +116 -0
  8. package/dist/chat/controller.js.map +1 -0
  9. package/dist/chat/engine.d.ts +108 -0
  10. package/dist/chat/engine.d.ts.map +1 -0
  11. package/dist/chat/engine.js +226 -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 +151 -0
  16. package/dist/chat/frontend.js.map +1 -0
  17. package/dist/chat/native-session.d.ts +71 -0
  18. package/dist/chat/native-session.d.ts.map +1 -0
  19. package/dist/chat/native-session.js +348 -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 +34 -0
  26. package/dist/chat/picker.d.ts.map +1 -0
  27. package/dist/chat/picker.js +97 -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 +242 -0
  32. package/dist/chat/plain.js.map +1 -0
  33. package/dist/chat/session.d.ts +217 -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 +34 -0
  42. package/dist/chat/stdio-io.d.ts.map +1 -0
  43. package/dist/chat/stdio-io.js +175 -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 +400 -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 +186 -0
  54. package/dist/chat/view.d.ts.map +1 -0
  55. package/dist/chat/view.js +386 -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 +392 -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 +501 -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 +92 -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 +27 -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 +81 -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 +102 -24
  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 +264 -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 +276 -115
  126. package/dist/commands/down.js.map +1 -1
  127. package/dist/commands/endpoint-authoring.d.ts +4 -0
  128. package/dist/commands/endpoint-authoring.d.ts.map +1 -0
  129. package/dist/commands/endpoint-authoring.js +125 -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 +73 -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 +443 -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 +140 -0
  198. package/dist/commands/reset-space-apply.js.map +1 -0
  199. package/dist/commands/reset-store-apply.d.ts +11 -0
  200. package/dist/commands/reset-store-apply.d.ts.map +1 -0
  201. package/dist/commands/reset-store-apply.js +154 -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 +143 -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 +405 -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 +106 -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 +161 -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 +341 -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 +388 -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 +78 -18
  263. package/dist/commands/spawn.d.ts.map +1 -1
  264. package/dist/commands/spawn.js +236 -96
  265. package/dist/commands/spawn.js.map +1 -1
  266. package/dist/commands/stack-down.d.ts +6 -0
  267. package/dist/commands/stack-down.d.ts.map +1 -0
  268. package/dist/commands/stack-down.js +206 -0
  269. package/dist/commands/stack-down.js.map +1 -0
  270. package/dist/commands/stack-up.d.ts +149 -0
  271. package/dist/commands/stack-up.d.ts.map +1 -0
  272. package/dist/commands/stack-up.js +459 -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 +232 -5
  279. package/dist/commands/status.d.ts.map +1 -1
  280. package/dist/commands/status.js +989 -406
  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 +727 -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 +144 -5
  319. package/dist/commands/up.d.ts.map +1 -1
  320. package/dist/commands/up.js +1015 -124
  321. package/dist/commands/up.js.map +1 -1
  322. package/dist/commands/update.d.ts +11 -0
  323. package/dist/commands/update.d.ts.map +1 -1
  324. package/dist/commands/update.js +72 -15
  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 +2 -0
  377. package/dist/index.d.ts.map +1 -1
  378. package/dist/index.js +444 -118
  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 +34 -1
  392. package/dist/lib/backup-artifact.d.ts.map +1 -1
  393. package/dist/lib/backup-artifact.js +67 -17
  394. package/dist/lib/backup-artifact.js.map +1 -1
  395. package/dist/lib/broker-service.d.ts +10 -0
  396. package/dist/lib/broker-service.d.ts.map +1 -0
  397. package/dist/lib/broker-service.js +329 -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/control.d.ts +65 -6
  421. package/dist/lib/control.d.ts.map +1 -1
  422. package/dist/lib/control.js +121 -27
  423. package/dist/lib/control.js.map +1 -1
  424. package/dist/lib/controller-preserve.d.ts +12 -0
  425. package/dist/lib/controller-preserve.d.ts.map +1 -0
  426. package/dist/lib/controller-preserve.js +373 -0
  427. package/dist/lib/controller-preserve.js.map +1 -0
  428. package/dist/lib/controller-restore.d.ts +38 -0
  429. package/dist/lib/controller-restore.d.ts.map +1 -0
  430. package/dist/lib/controller-restore.js +205 -0
  431. package/dist/lib/controller-restore.js.map +1 -0
  432. package/dist/lib/controller-resume.d.ts +92 -0
  433. package/dist/lib/controller-resume.d.ts.map +1 -0
  434. package/dist/lib/controller-resume.js +300 -0
  435. package/dist/lib/controller-resume.js.map +1 -0
  436. package/dist/lib/credential-authority.d.ts +17 -0
  437. package/dist/lib/credential-authority.d.ts.map +1 -0
  438. package/dist/lib/credential-authority.js +28 -0
  439. package/dist/lib/credential-authority.js.map +1 -0
  440. package/dist/lib/default-persona.d.ts +38 -0
  441. package/dist/lib/default-persona.d.ts.map +1 -0
  442. package/dist/lib/default-persona.js +85 -0
  443. package/dist/lib/default-persona.js.map +1 -0
  444. package/dist/lib/delivery-proc.d.ts +9 -9
  445. package/dist/lib/delivery-proc.d.ts.map +1 -1
  446. package/dist/lib/delivery-proc.js +9 -19
  447. package/dist/lib/delivery-proc.js.map +1 -1
  448. package/dist/lib/endpoint-capability-gates.d.ts +10 -0
  449. package/dist/lib/endpoint-capability-gates.d.ts.map +1 -0
  450. package/dist/lib/endpoint-capability-gates.js +70 -0
  451. package/dist/lib/endpoint-capability-gates.js.map +1 -0
  452. package/dist/lib/endpoint-client.d.ts +20 -0
  453. package/dist/lib/endpoint-client.d.ts.map +1 -0
  454. package/dist/lib/endpoint-client.js +42 -0
  455. package/dist/lib/endpoint-client.js.map +1 -0
  456. package/dist/lib/endpoint-errors.d.ts +11 -0
  457. package/dist/lib/endpoint-errors.d.ts.map +1 -0
  458. package/dist/lib/endpoint-errors.js +30 -0
  459. package/dist/lib/endpoint-errors.js.map +1 -0
  460. package/dist/lib/endpoint-goal.d.ts +19 -0
  461. package/dist/lib/endpoint-goal.d.ts.map +1 -0
  462. package/dist/lib/endpoint-goal.js +31 -0
  463. package/dist/lib/endpoint-goal.js.map +1 -0
  464. package/dist/lib/endpoint-inventory.d.ts +30 -0
  465. package/dist/lib/endpoint-inventory.d.ts.map +1 -0
  466. package/dist/lib/endpoint-inventory.js +79 -0
  467. package/dist/lib/endpoint-inventory.js.map +1 -0
  468. package/dist/lib/endpoint-references.d.ts +22 -0
  469. package/dist/lib/endpoint-references.d.ts.map +1 -0
  470. package/dist/lib/endpoint-references.js +44 -0
  471. package/dist/lib/endpoint-references.js.map +1 -0
  472. package/dist/lib/endpoint-scatter.d.ts +57 -0
  473. package/dist/lib/endpoint-scatter.d.ts.map +1 -0
  474. package/dist/lib/endpoint-scatter.js +75 -0
  475. package/dist/lib/endpoint-scatter.js.map +1 -0
  476. package/dist/lib/endpoint-selection.d.ts +35 -0
  477. package/dist/lib/endpoint-selection.d.ts.map +1 -0
  478. package/dist/lib/endpoint-selection.js +80 -0
  479. package/dist/lib/endpoint-selection.js.map +1 -0
  480. package/dist/lib/install-umask.d.ts +6 -0
  481. package/dist/lib/install-umask.d.ts.map +1 -0
  482. package/dist/lib/install-umask.js +15 -0
  483. package/dist/lib/install-umask.js.map +1 -0
  484. package/dist/lib/isolated-broker.d.ts.map +1 -1
  485. package/dist/lib/isolated-broker.js +9 -5
  486. package/dist/lib/isolated-broker.js.map +1 -1
  487. package/dist/lib/local-process-stop.d.ts.map +1 -1
  488. package/dist/lib/local-process-stop.js +7 -1
  489. package/dist/lib/local-process-stop.js.map +1 -1
  490. package/dist/lib/manager-proc.d.ts +11 -5
  491. package/dist/lib/manager-proc.d.ts.map +1 -1
  492. package/dist/lib/manager-proc.js +12 -17
  493. package/dist/lib/manager-proc.js.map +1 -1
  494. package/dist/lib/manifest/apply.d.ts +4 -1
  495. package/dist/lib/manifest/apply.d.ts.map +1 -1
  496. package/dist/lib/manifest/apply.js +1 -1
  497. package/dist/lib/manifest/apply.js.map +1 -1
  498. package/dist/lib/manifest/ledger.d.ts +3 -1
  499. package/dist/lib/manifest/ledger.d.ts.map +1 -1
  500. package/dist/lib/manifest/ledger.js +16 -3
  501. package/dist/lib/manifest/ledger.js.map +1 -1
  502. package/dist/lib/manifest/schema.d.ts +1 -117
  503. package/dist/lib/manifest/schema.d.ts.map +1 -1
  504. package/dist/lib/manifest/schema.js +1 -95
  505. package/dist/lib/manifest/schema.js.map +1 -1
  506. package/dist/lib/offline-recipient.d.ts +5 -0
  507. package/dist/lib/offline-recipient.d.ts.map +1 -0
  508. package/dist/lib/offline-recipient.js +7 -0
  509. package/dist/lib/offline-recipient.js.map +1 -0
  510. package/dist/lib/onboard.js +3 -3
  511. package/dist/lib/onboard.js.map +1 -1
  512. package/dist/lib/persona-files.d.ts +29 -0
  513. package/dist/lib/persona-files.d.ts.map +1 -0
  514. package/dist/lib/persona-files.js +154 -0
  515. package/dist/lib/persona-files.js.map +1 -0
  516. package/dist/lib/personas.d.ts +3 -0
  517. package/dist/lib/personas.d.ts.map +1 -1
  518. package/dist/lib/personas.js +14 -2
  519. package/dist/lib/personas.js.map +1 -1
  520. package/dist/lib/prompts.d.ts +16 -0
  521. package/dist/lib/prompts.d.ts.map +1 -0
  522. package/dist/lib/prompts.js +35 -0
  523. package/dist/lib/prompts.js.map +1 -0
  524. package/dist/lib/protected-records.d.ts +2 -0
  525. package/dist/lib/protected-records.d.ts.map +1 -0
  526. package/dist/lib/protected-records.js +3 -0
  527. package/dist/lib/protected-records.js.map +1 -0
  528. package/dist/lib/registry-errors.d.ts +4 -0
  529. package/dist/lib/registry-errors.d.ts.map +1 -0
  530. package/dist/lib/registry-errors.js +6 -0
  531. package/dist/lib/registry-errors.js.map +1 -0
  532. package/dist/lib/reset-space-plan.d.ts +36 -0
  533. package/dist/lib/reset-space-plan.d.ts.map +1 -0
  534. package/dist/lib/reset-space-plan.js +181 -0
  535. package/dist/lib/reset-space-plan.js.map +1 -0
  536. package/dist/lib/restore.d.ts +3 -1
  537. package/dist/lib/restore.d.ts.map +1 -1
  538. package/dist/lib/restore.js +38 -10
  539. package/dist/lib/restore.js.map +1 -1
  540. package/dist/lib/seat-resume.d.ts +4 -1
  541. package/dist/lib/seat-resume.d.ts.map +1 -1
  542. package/dist/lib/seat-resume.js +7 -4
  543. package/dist/lib/seat-resume.js.map +1 -1
  544. package/dist/lib/service-adapters.d.ts +32 -0
  545. package/dist/lib/service-adapters.d.ts.map +1 -0
  546. package/dist/lib/service-adapters.js +55 -0
  547. package/dist/lib/service-adapters.js.map +1 -0
  548. package/dist/lib/service-census.d.ts +73 -0
  549. package/dist/lib/service-census.d.ts.map +1 -0
  550. package/dist/lib/service-census.js +42 -0
  551. package/dist/lib/service-census.js.map +1 -0
  552. package/dist/lib/service-definitions.d.ts +49 -0
  553. package/dist/lib/service-definitions.d.ts.map +1 -0
  554. package/dist/lib/service-definitions.js +61 -0
  555. package/dist/lib/service-definitions.js.map +1 -0
  556. package/dist/lib/service-install-intent.d.ts +48 -0
  557. package/dist/lib/service-install-intent.d.ts.map +1 -0
  558. package/dist/lib/service-install-intent.js +95 -0
  559. package/dist/lib/service-install-intent.js.map +1 -0
  560. package/dist/lib/service-instances.d.ts +143 -0
  561. package/dist/lib/service-instances.d.ts.map +1 -0
  562. package/dist/lib/service-instances.js +193 -0
  563. package/dist/lib/service-instances.js.map +1 -0
  564. package/dist/lib/service-journal.d.ts +38 -0
  565. package/dist/lib/service-journal.d.ts.map +1 -0
  566. package/dist/lib/service-journal.js +210 -0
  567. package/dist/lib/service-journal.js.map +1 -0
  568. package/dist/lib/service-launchd-plan.d.ts +21 -0
  569. package/dist/lib/service-launchd-plan.d.ts.map +1 -0
  570. package/dist/lib/service-launchd-plan.js +69 -0
  571. package/dist/lib/service-launchd-plan.js.map +1 -0
  572. package/dist/lib/service-launchd-unit.d.ts +20 -0
  573. package/dist/lib/service-launchd-unit.d.ts.map +1 -0
  574. package/dist/lib/service-launchd-unit.js +66 -0
  575. package/dist/lib/service-launchd-unit.js.map +1 -0
  576. package/dist/lib/service-presets.d.ts +17 -0
  577. package/dist/lib/service-presets.d.ts.map +1 -0
  578. package/dist/lib/service-presets.js +138 -0
  579. package/dist/lib/service-presets.js.map +1 -0
  580. package/dist/lib/service-private-seed.d.ts +7 -0
  581. package/dist/lib/service-private-seed.d.ts.map +1 -0
  582. package/dist/lib/service-private-seed.js +64 -0
  583. package/dist/lib/service-private-seed.js.map +1 -0
  584. package/dist/lib/service-private-tree.d.ts +6 -0
  585. package/dist/lib/service-private-tree.d.ts.map +1 -0
  586. package/dist/lib/service-private-tree.js +100 -0
  587. package/dist/lib/service-private-tree.js.map +1 -0
  588. package/dist/lib/service-process.d.ts +121 -0
  589. package/dist/lib/service-process.d.ts.map +1 -0
  590. package/dist/lib/service-process.js +742 -0
  591. package/dist/lib/service-process.js.map +1 -0
  592. package/dist/lib/service-stopped-allocation.d.ts +6 -0
  593. package/dist/lib/service-stopped-allocation.d.ts.map +1 -0
  594. package/dist/lib/service-stopped-allocation.js +42 -0
  595. package/dist/lib/service-stopped-allocation.js.map +1 -0
  596. package/dist/lib/service-supervision.d.ts +59 -0
  597. package/dist/lib/service-supervision.d.ts.map +1 -0
  598. package/dist/lib/service-supervision.js +71 -0
  599. package/dist/lib/service-supervision.js.map +1 -0
  600. package/dist/lib/service-systemd-attempt-read.d.ts +40 -0
  601. package/dist/lib/service-systemd-attempt-read.d.ts.map +1 -0
  602. package/dist/lib/service-systemd-attempt-read.js +80 -0
  603. package/dist/lib/service-systemd-attempt-read.js.map +1 -0
  604. package/dist/lib/service-systemd-control.d.ts +38 -0
  605. package/dist/lib/service-systemd-control.d.ts.map +1 -0
  606. package/dist/lib/service-systemd-control.js +141 -0
  607. package/dist/lib/service-systemd-control.js.map +1 -0
  608. package/dist/lib/service-systemd-files.d.ts +8 -0
  609. package/dist/lib/service-systemd-files.d.ts.map +1 -0
  610. package/dist/lib/service-systemd-files.js +63 -0
  611. package/dist/lib/service-systemd-files.js.map +1 -0
  612. package/dist/lib/service-systemd-install.d.ts +17 -0
  613. package/dist/lib/service-systemd-install.d.ts.map +1 -0
  614. package/dist/lib/service-systemd-install.js +146 -0
  615. package/dist/lib/service-systemd-install.js.map +1 -0
  616. package/dist/lib/service-systemd-plan.d.ts +28 -0
  617. package/dist/lib/service-systemd-plan.d.ts.map +1 -0
  618. package/dist/lib/service-systemd-plan.js +56 -0
  619. package/dist/lib/service-systemd-plan.js.map +1 -0
  620. package/dist/lib/service-systemd-reseed.d.ts +16 -0
  621. package/dist/lib/service-systemd-reseed.d.ts.map +1 -0
  622. package/dist/lib/service-systemd-reseed.js +106 -0
  623. package/dist/lib/service-systemd-reseed.js.map +1 -0
  624. package/dist/lib/service-systemd-uninstall-plan.d.ts +29 -0
  625. package/dist/lib/service-systemd-uninstall-plan.d.ts.map +1 -0
  626. package/dist/lib/service-systemd-uninstall-plan.js +56 -0
  627. package/dist/lib/service-systemd-uninstall-plan.js.map +1 -0
  628. package/dist/lib/service-systemd-uninstall.d.ts +17 -0
  629. package/dist/lib/service-systemd-uninstall.d.ts.map +1 -0
  630. package/dist/lib/service-systemd-uninstall.js +106 -0
  631. package/dist/lib/service-systemd-uninstall.js.map +1 -0
  632. package/dist/lib/service-systemd-unit.d.ts +28 -0
  633. package/dist/lib/service-systemd-unit.d.ts.map +1 -0
  634. package/dist/lib/service-systemd-unit.js +73 -0
  635. package/dist/lib/service-systemd-unit.js.map +1 -0
  636. package/dist/lib/service-systemd.d.ts +49 -0
  637. package/dist/lib/service-systemd.d.ts.map +1 -0
  638. package/dist/lib/service-systemd.js +134 -0
  639. package/dist/lib/service-systemd.js.map +1 -0
  640. package/dist/lib/service-uninstall-intent.d.ts +38 -0
  641. package/dist/lib/service-uninstall-intent.d.ts.map +1 -0
  642. package/dist/lib/service-uninstall-intent.js +74 -0
  643. package/dist/lib/service-uninstall-intent.js.map +1 -0
  644. package/dist/lib/service-unit-action.d.ts +24 -0
  645. package/dist/lib/service-unit-action.d.ts.map +1 -0
  646. package/dist/lib/service-unit-action.js +61 -0
  647. package/dist/lib/service-unit-action.js.map +1 -0
  648. package/dist/lib/setup-log.d.ts +5 -4
  649. package/dist/lib/setup-log.d.ts.map +1 -1
  650. package/dist/lib/setup-log.js +18 -9
  651. package/dist/lib/setup-log.js.map +1 -1
  652. package/dist/lib/space-schema-inspection.d.ts +73 -0
  653. package/dist/lib/space-schema-inspection.d.ts.map +1 -0
  654. package/dist/lib/space-schema-inspection.js +118 -0
  655. package/dist/lib/space-schema-inspection.js.map +1 -0
  656. package/dist/lib/space-schema-report.d.ts +82 -0
  657. package/dist/lib/space-schema-report.d.ts.map +1 -0
  658. package/dist/lib/space-schema-report.js +109 -0
  659. package/dist/lib/space-schema-report.js.map +1 -0
  660. package/dist/lib/spawn-defaults.d.ts +14 -0
  661. package/dist/lib/spawn-defaults.d.ts.map +1 -0
  662. package/dist/lib/spawn-defaults.js +20 -0
  663. package/dist/lib/spawn-defaults.js.map +1 -0
  664. package/dist/lib/stack-journal.d.ts +92 -0
  665. package/dist/lib/stack-journal.d.ts.map +1 -0
  666. package/dist/lib/stack-journal.js +199 -0
  667. package/dist/lib/stack-journal.js.map +1 -0
  668. package/dist/lib/stack-resume.d.ts +35 -0
  669. package/dist/lib/stack-resume.d.ts.map +1 -0
  670. package/dist/lib/stack-resume.js +123 -0
  671. package/dist/lib/stack-resume.js.map +1 -0
  672. package/dist/lib/status.d.ts +19 -20
  673. package/dist/lib/status.d.ts.map +1 -1
  674. package/dist/lib/status.js +41 -40
  675. package/dist/lib/status.js.map +1 -1
  676. package/dist/lib/steps.d.ts.map +1 -1
  677. package/dist/lib/steps.js +3 -2
  678. package/dist/lib/steps.js.map +1 -1
  679. package/dist/lib/systemd-supervision.d.ts +11 -4
  680. package/dist/lib/systemd-supervision.d.ts.map +1 -1
  681. package/dist/lib/systemd-supervision.js +19 -8
  682. package/dist/lib/systemd-supervision.js.map +1 -1
  683. package/dist/lib/team-additive-attempt.d.ts +286 -0
  684. package/dist/lib/team-additive-attempt.d.ts.map +1 -0
  685. package/dist/lib/team-additive-attempt.js +387 -0
  686. package/dist/lib/team-additive-attempt.js.map +1 -0
  687. package/dist/lib/team-additive-native.d.ts +17 -0
  688. package/dist/lib/team-additive-native.d.ts.map +1 -0
  689. package/dist/lib/team-additive-native.js +29 -0
  690. package/dist/lib/team-additive-native.js.map +1 -0
  691. package/dist/lib/team-agent-removal.d.ts +104 -0
  692. package/dist/lib/team-agent-removal.d.ts.map +1 -0
  693. package/dist/lib/team-agent-removal.js +121 -0
  694. package/dist/lib/team-agent-removal.js.map +1 -0
  695. package/dist/lib/team-channel-removal.d.ts +220 -0
  696. package/dist/lib/team-channel-removal.d.ts.map +1 -0
  697. package/dist/lib/team-channel-removal.js +258 -0
  698. package/dist/lib/team-channel-removal.js.map +1 -0
  699. package/dist/lib/team-deploy-inspection.d.ts +59 -0
  700. package/dist/lib/team-deploy-inspection.d.ts.map +1 -0
  701. package/dist/lib/team-deploy-inspection.js +177 -0
  702. package/dist/lib/team-deploy-inspection.js.map +1 -0
  703. package/dist/lib/team-fresh.d.ts +73 -0
  704. package/dist/lib/team-fresh.d.ts.map +1 -0
  705. package/dist/lib/team-fresh.js +207 -0
  706. package/dist/lib/team-fresh.js.map +1 -0
  707. package/dist/lib/team-removal-reconcile.d.ts +118 -0
  708. package/dist/lib/team-removal-reconcile.d.ts.map +1 -0
  709. package/dist/lib/team-removal-reconcile.js +90 -0
  710. package/dist/lib/team-removal-reconcile.js.map +1 -0
  711. package/dist/lib/team-removal-record.d.ts +7 -0
  712. package/dist/lib/team-removal-record.d.ts.map +1 -0
  713. package/dist/lib/team-removal-record.js +46 -0
  714. package/dist/lib/team-removal-record.js.map +1 -0
  715. package/dist/lib/team-retained.d.ts +33 -0
  716. package/dist/lib/team-retained.d.ts.map +1 -0
  717. package/dist/lib/team-retained.js +55 -0
  718. package/dist/lib/team-retained.js.map +1 -0
  719. package/dist/lib/theme.d.ts.map +1 -1
  720. package/dist/lib/theme.js +9 -8
  721. package/dist/lib/theme.js.map +1 -1
  722. package/dist/lib/transient.d.ts +14 -9
  723. package/dist/lib/transient.d.ts.map +1 -1
  724. package/dist/lib/transient.js +25 -18
  725. package/dist/lib/transient.js.map +1 -1
  726. package/dist/lib/up-report.d.ts +1 -0
  727. package/dist/lib/up-report.d.ts.map +1 -1
  728. package/dist/lib/up-report.js +2 -1
  729. package/dist/lib/up-report.js.map +1 -1
  730. package/dist/lib/version.d.ts +8 -2
  731. package/dist/lib/version.d.ts.map +1 -1
  732. package/dist/lib/version.js +16 -9
  733. package/dist/lib/version.js.map +1 -1
  734. package/dist/seed/paths.d.ts +1 -1
  735. package/dist/seed/paths.js +1 -1
  736. package/dist/seed/reconcile.d.ts.map +1 -1
  737. package/dist/seed/reconcile.js +19 -3
  738. package/dist/seed/reconcile.js.map +1 -1
  739. package/dist/ui.d.ts +6 -0
  740. package/dist/ui.d.ts.map +1 -1
  741. package/dist/ui.js +12 -1
  742. package/dist/ui.js.map +1 -1
  743. package/dist/watch-data.d.ts +15 -0
  744. package/dist/watch-data.d.ts.map +1 -0
  745. package/dist/watch-data.js +66 -0
  746. package/dist/watch-data.js.map +1 -0
  747. package/dist/watch-json.d.ts +5 -0
  748. package/dist/watch-json.d.ts.map +1 -0
  749. package/dist/watch-json.js +131 -0
  750. package/dist/watch-json.js.map +1 -0
  751. package/dist/watch-view.d.ts +8 -0
  752. package/dist/watch-view.d.ts.map +1 -0
  753. package/dist/watch-view.js +65 -0
  754. package/dist/watch-view.js.map +1 -0
  755. package/package.json +8 -5
  756. package/dist/commands/service.d.ts +0 -17
  757. package/dist/commands/service.d.ts.map +0 -1
  758. package/dist/commands/service.js +0 -589
  759. package/dist/commands/service.js.map +0 -1
@@ -0,0 +1,227 @@
1
+ /**
2
+ * `cotal chat [channel]`: one live session under its own admitted identity, in the terminal view,
3
+ * `--plain` lines, or the `--stdio` NDJSON protocol. The mesh is resolved once, and the session is
4
+ * admitted by that target's recorded auth mode only. Leaving ends the session; nothing outlives it.
5
+ */
6
+ import { randomBytes } from "node:crypto";
7
+ import { hostname, userInfo } from "node:os";
8
+ import { assertValidChannel, isConcreteChannel, oneLine, readChannelRegistry, } from "@cotal-ai/core";
9
+ import { CommandFailure, connectTargetOrThrow, credsFlag, isConnectRefusal, loadMeshes, plainFlag, preflightOrThrow, resolveTargetOrThrow, serverFlag, spaceFlag, } from "@cotal-ai/workspace";
10
+ import { completingFlagValue, positionalsForCompletion } from "../lib/completion.js";
11
+ import { listDeclaredChannels } from "../lib/personas.js";
12
+ import { declaredFrom } from "./send.js";
13
+ import { loadChatFrontEnd, selectFrontEnd } from "../chat/frontend.js";
14
+ import { openRoutingChatSession } from "../chat/open-session.js";
15
+ import { openStaticChatSession } from "../chat/static-session.js";
16
+ import { openUserChatSession } from "../chat/user-session.js";
17
+ import { closeSummary } from "../chat/view.js";
18
+ export const chatFlags = [
19
+ spaceFlag, serverFlag, { ...credsFlag, description: "an explicit credential file (not available for chat yet)" }, plainFlag,
20
+ { name: "stdio", type: "boolean", description: "exchange the NDJSON participant protocol on stdin and stdout instead of the terminal view" },
21
+ { name: "name", type: "string", value: "<n>", description: "the session's display label (default: <login>@<host> and a short suffix)" },
22
+ { name: "role", type: "string", value: "<r>", description: "a presence role (not available for chat yet)" },
23
+ { name: "kind", type: "string", value: "<k>", description: "the session's presence kind; only endpoint, the default, is accepted" },
24
+ { name: "link", type: "string", value: "<url>", description: "the space and auth from a join link (not available for chat yet)" },
25
+ { name: "token", type: "string", value: "<t>", description: "the space and auth from a join token (not available for chat yet)" },
26
+ { name: "lifecycle-uid", type: "string", value: "<uid>", description: "the lifecycle UID paired with --creds (not available for chat yet)" },
27
+ ];
28
+ /** Declared flags no admission supports yet, each with the reason it refuses. */
29
+ const NOT_YET = [
30
+ ["role", "a role puts the session on that role's work queue, the chat view cannot yet answer a task's sender, and the static and user-mode admissions take no role"],
31
+ ["link", "no admission opens a chat session from a join link; select the space with --space or cotal use"],
32
+ ["token", "no admission opens a chat session from a join token; select the space with --space or cotal use"],
33
+ ["creds", "a chat session gets its own identity from the space, and no admission accepts an explicit credential"],
34
+ ["lifecycle-uid", "it pairs with --creds, which no chat admission accepts"],
35
+ ];
36
+ /** A user-mode session asks for the auth service's whole lifetime cap, 8 hours, which it never
37
+ * extends. Each bearer within it still lasts at most 15 minutes. */
38
+ export const USER_CHAT_TTL_SEC = 8 * 60 * 60;
39
+ /** Check the grammar and choose the front end, before any target, connector or connection. */
40
+ export function chatArguments(args) {
41
+ const values = args.values;
42
+ if (args.positionals.length > 1)
43
+ throw new CommandFailure("refused", "USAGE_INVALID", "chat takes at most one channel", { remedy: "run cotal chat [<channel>]" });
44
+ const raw = args.positionals[0];
45
+ const channel = raw?.replace(/^#/, "");
46
+ if (channel !== undefined) {
47
+ try {
48
+ assertValidChannel(channel);
49
+ if (!isConcreteChannel(channel))
50
+ throw new Error("wildcard");
51
+ }
52
+ catch {
53
+ throw new CommandFailure("refused", "USAGE_INVALID", "name one concrete channel, without wildcards");
54
+ }
55
+ }
56
+ if (values.name !== undefined && (!values.name.trim() || values.name.length > 128 || /[\u0000-\u001f\u007f]/u.test(values.name)))
57
+ throw new CommandFailure("refused", "USAGE_INVALID", "--name takes a label of 1 to 128 characters without control characters");
58
+ // Every admission presents the session as an endpoint, so `--kind endpoint` changes nothing.
59
+ if (values.kind !== undefined && values.kind !== "endpoint")
60
+ throw new CommandFailure("refused", "USAGE_INVALID", values.kind === "agent" ? "--kind agent is refused because a chat session never presents as an agent" : "--kind accepts only endpoint", { remedy: "run cotal chat without --kind" });
61
+ for (const [flag, reason] of NOT_YET)
62
+ if (values[flag] !== undefined)
63
+ throw new CommandFailure("refused", "UNSUPPORTED", `--${flag} is not available for chat yet: ${reason}`, { remedy: `run cotal chat without --${flag}` });
64
+ const picked = selectFrontEnd({ stdio: values.stdio, plain: values.plain });
65
+ if (!picked.ok)
66
+ throw new CommandFailure("refused", "USAGE_INVALID", picked.message);
67
+ return { ...(channel === undefined ? {} : { channel }), ...(values.name === undefined ? {} : { label: values.name }), frontEnd: picked.frontEnd };
68
+ }
69
+ export function chatAdmission(mode, label, channel) {
70
+ const channels = channel === undefined ? [] : [channel];
71
+ if (mode === "open")
72
+ return { mode, label, channels };
73
+ if (mode === "auth")
74
+ return { mode, label, subscribe: channels, allowPublish: channels };
75
+ if (mode === "user")
76
+ return { mode, label, channels, read: channels, post: channels, ttlSec: USER_CHAT_TTL_SEC };
77
+ throw new CommandFailure("refused", "UNSUPPORTED", `chat has no admission for a mesh recorded in "${String(mode)}" mode; no other mode was tried`);
78
+ }
79
+ /** Admit through the one adapter the mode names. Each adapter refuses a target of another mode. */
80
+ function admit(target, admission) {
81
+ switch (admission.mode) {
82
+ case "open": return openRoutingChatSession(target, admission);
83
+ case "auth": return openStaticChatSession(target, admission);
84
+ case "user": return openUserChatSession(target, admission);
85
+ }
86
+ }
87
+ /** The exit code of a session that ended by leaving, end of input or expiry. Only a confirmed
88
+ * close is 0. Retirement asked for and not confirmed is 4. An unknown outcome, an unconfirmed
89
+ * connection close, or no close report is 3. */
90
+ export function closeExitCode(close) {
91
+ if (!close || close.retirement === "unknown" || close.connectionClosed !== "confirmed")
92
+ return 3;
93
+ return close.retirement === "requested" ? 4 : 0;
94
+ }
95
+ /** `<login>@<host>-<4 hex>`: readable, and distinct between two windows on one machine. A label is
96
+ * display only; the admitted principal is the session's authority. */
97
+ function defaultLabel() {
98
+ let login = "";
99
+ let host = "";
100
+ try {
101
+ login = userInfo().username.trim();
102
+ host = hostname().trim();
103
+ }
104
+ catch { /* refused below */ }
105
+ const label = `${login}@${host}-${randomBytes(2).toString("hex")}`;
106
+ if (!login || !host || label.length > 128 || /[/\\\u0000-\u001f\u007f]/u.test(label))
107
+ throw new CommandFailure("refused", "USAGE_INVALID", "chat cannot derive a label from the OS login and host", { remedy: "pass --name <n>" });
108
+ return label;
109
+ }
110
+ /** The exit status each terminating signal sets. */
111
+ const SIGNAL_EXIT = { SIGINT: 130, SIGTERM: 143, SIGHUP: 129 };
112
+ /** Hold SIGINT, SIGTERM and SIGHUP until a front end has installed its own handling, so no signal
113
+ * kills the process while a session is being admitted or is admitted. The first signal is kept and
114
+ * later ones are absorbed. */
115
+ export function holdSignals() {
116
+ let caught;
117
+ const held = Object.keys(SIGNAL_EXIT).map((sig) => {
118
+ const handler = () => { caught ??= SIGNAL_EXIT[sig]; };
119
+ process.on(sig, handler);
120
+ return () => { process.off(sig, handler); };
121
+ });
122
+ return { caught: () => caught, release: () => { for (const off of held)
123
+ off(); } };
124
+ }
125
+ /** The line that discloses a named channel before admission. `registered` is undefined when the
126
+ * registry could not be read. */
127
+ export function channelDisclosure(channel, registered) {
128
+ if (registered === undefined)
129
+ return `the registration of #${channel} could not be read; only the space's native policy decides whether a send is accepted`;
130
+ return registered ? `#${channel} is a registered channel` : `Unregistered channel #${channel}: sends follow the space's native policy, and nothing creates its registration`;
131
+ }
132
+ /** Read whether `channel` is registered, on the resolved target, through the one-shot `operator`
133
+ * connection and the registry read `cotal send` uses. The connection is also the reachability
134
+ * check. Nothing is written, and a read the broker refuses is disclosed as not read. */
135
+ async function discloseChannel(target, channel) {
136
+ const connection = await connectTargetOrThrow(target, "operator");
137
+ try {
138
+ const registry = await readChannelRegistry({ servers: connection.server, space: target.space, ...(connection.bearer ? { bearer: connection.bearer, sentinelCreds: connection.sentinelCreds } : { creds: connection.creds }) });
139
+ return channelDisclosure(channel, Object.hasOwn(registry.channels ?? {}, channel));
140
+ }
141
+ catch {
142
+ return channelDisclosure(channel, undefined);
143
+ }
144
+ }
145
+ /** Resolve the recorded mesh `--space`/`--server` select, once. Disclose the named channel, or
146
+ * check the target reachable when none is named. */
147
+ async function prepareChat(values, channel) {
148
+ try {
149
+ const target = await resolveTargetOrThrow({ space: values.space, server: values.server });
150
+ if (channel !== undefined)
151
+ return { target, notice: await discloseChannel(target, channel) };
152
+ await preflightOrThrow(target);
153
+ return { target };
154
+ }
155
+ catch (e) {
156
+ if (isConnectRefusal(e))
157
+ throw e.failure();
158
+ throw e;
159
+ }
160
+ }
161
+ export async function chat(args) {
162
+ const input = chatArguments(args);
163
+ const start = await loadChatFrontEnd(input.frontEnd);
164
+ const signals = holdSignals();
165
+ let target;
166
+ let notice;
167
+ let session;
168
+ try {
169
+ ({ target, notice } = await prepareChat(args.values, input.channel));
170
+ if (notice)
171
+ process.stderr.write(`cotal chat: ${notice}\n`);
172
+ const before = signals.caught();
173
+ if (before !== undefined) {
174
+ signals.release();
175
+ process.stderr.write("cotal chat: interrupted before admission; no session was opened\n");
176
+ process.exitCode = before;
177
+ return;
178
+ }
179
+ session = await admit(target, chatAdmission(target.mode, input.label ?? defaultLabel(), input.channel));
180
+ }
181
+ catch (e) {
182
+ signals.release();
183
+ throw e;
184
+ }
185
+ const during = signals.caught();
186
+ if (during !== undefined) {
187
+ // Interrupted while admitting: close what was admitted before a front end starts.
188
+ const ended = await session.close().catch(() => undefined);
189
+ signals.release();
190
+ process.stderr.write(`cotal chat: interrupted during admission; ${ended ? oneLine(closeSummary(session.identity(), ended)) : "the session's close was not observed"}\n`);
191
+ process.exitCode = during;
192
+ return;
193
+ }
194
+ const initialRecipient = input.channel === undefined ? undefined : { kind: "channel", channel: input.channel };
195
+ let close;
196
+ try {
197
+ // The front end installs its signal handling before it first yields, so releasing here leaves no gap.
198
+ const running = start({ session, initialRecipient, notice });
199
+ signals.release();
200
+ close = await running;
201
+ }
202
+ catch (e) {
203
+ // A front end that threw still ends the session it was given. Closing is idempotent.
204
+ const held = holdSignals();
205
+ signals.release();
206
+ const ended = await session.close().catch(() => undefined);
207
+ held.release();
208
+ const confirmed = closeExitCode(ended) === 0;
209
+ throw new CommandFailure(confirmed ? "failed" : "unknown", confirmed ? "OPERATION_FAILED" : "OPERATION_UNKNOWN", `the chat front end stopped with an error (${e instanceof Error ? e.message : String(e)}); ${ended ? ended.message : "the session's close was not observed"}`, { target: { space: target.space, principal: session.identity().principal }, native: { detail: { close: ended ?? null } } });
210
+ }
211
+ // The terminal view leaves its screen with nothing on it; `--plain` and `--stdio` report their own end.
212
+ if (input.frontEnd === "tui" && close)
213
+ console.log(oneLine(closeSummary(session.identity(), close)));
214
+ // A signal the front end handled already set 129, 130 or 143.
215
+ process.exitCode ??= closeExitCode(close);
216
+ }
217
+ /** Complete `--space` from the registry and the channel from the target mesh's persona catalog,
218
+ * offline. Other values have nothing to offer. */
219
+ export function chatComplete(argv) {
220
+ const flag = completingFlagValue(argv, chatFlags);
221
+ if (flag?.name === "space")
222
+ return { items: loadMeshes().map((mesh) => ({ value: mesh.space })), directive: "nofiles" };
223
+ if (!flag && positionalsForCompletion(argv, chatFlags).length === 1)
224
+ return { items: declaredFrom(argv, listDeclaredChannels).map((value) => ({ value })), directive: "nofiles" };
225
+ return { items: [], directive: "nofiles" };
226
+ }
227
+ //# sourceMappingURL=chat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat.js","sourceRoot":"","sources":["../../src/commands/chat.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;A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C7C,CAAC"}
@@ -1,4 +1,4 @@
1
- import { type CompletionResult, type ParsedArgs } from "@cotal-ai/core";
1
+ import { type AuthProvider, type CompletionResult, type ParsedArgs, type SecretStore } from "@cotal-ai/core";
2
2
  /** `cotal clean <history|store|all>` - one configurable cleanup verb.
3
3
  * - `history`: purge the retained message backlog on the RUNNING broker (CHAT, plus DMs with
4
4
  * `--dms`) via the least-privilege purger cred. `cotal history clear` is a thin alias.
@@ -37,6 +37,11 @@ export declare function liveMeshProcess(root: string, space?: string): string |
37
37
  * keeps "this mesh is running here, use `cotal down`" a true statement: found live against a real
38
38
  * registry, where a dashboard watching the remote optiplex mesh made `meshes rm` refuse and point
39
39
  * at a `cotal down` that would not have stopped that mesh at all.
40
+ *
41
+ * The controller stack this root recorded for the same space makes it the home too. `cotal up`
42
+ * starts that stack's members as service instances with no pidfile, and `cotal down` stops them
43
+ * together and drops the record. A member counts here while its process may still run. One proven
44
+ * gone without its stop receipt does not, and {@link unsettledStackMembers} names it.
40
45
  */
41
46
  export declare function liveMeshOwner(root: string, space?: string): string | undefined;
42
47
  /** `space` names the tenant whose pidfiles to look at. Pass it whenever the caller already knows
@@ -44,6 +49,25 @@ export declare function liveMeshOwner(root: string, space?: string): string | un
44
49
  * DIFFERENT tenant on a multi-space root, and the derivation throws outright on an unreadable or
45
50
  * ambiguous one — a caller asking a yes/no liveness question should not inherit that failure. */
46
51
  export declare function liveMeshProcesses(root: string, space?: string): string[];
52
+ /** The members of the controller stack recorded at this root for `space` whose process is proven
53
+ * gone with no stop receipt: they can no longer run, but nothing stopped them cleanly. */
54
+ export declare function unsettledStackMembers(root: string, space: string): string[];
55
+ /** Fixed filesystem targets shared by native identity cleanup and its read-only impact plan. */
56
+ export declare function localIdentityCleanupTargets(root: string, space: string): {
57
+ material: string;
58
+ renewal: string;
59
+ legacy: string[];
60
+ runtime: string[];
61
+ run: string;
62
+ auth: string;
63
+ };
64
+ export interface ReviewedIdentityCleanup {
65
+ store: SecretStore;
66
+ provider: AuthProvider | null;
67
+ agentKeys: readonly string[];
68
+ beforeRemove(path: string): void;
69
+ afterRemove(path: string): void;
70
+ }
47
71
  /** Delete the stopped mesh's local state and return what was removed (paths relative to the root).
48
72
  * `store`: the JetStream store directory. `all` adds the space identity (`.cotal/auth`), the
49
73
  * locally persisted creds/markers tied to it - all invalid once the identity regenerates, and
@@ -61,6 +85,24 @@ export declare function liveMeshProcesses(root: string, space?: string): string[
61
85
  export declare function removeLocalState(root: string, opts: {
62
86
  includeAuth: boolean;
63
87
  storeDir?: string;
88
+ space?: string;
89
+ expectedStore?: {
90
+ path: string;
91
+ identity?: {
92
+ dev: bigint;
93
+ ino: bigint;
94
+ };
95
+ };
96
+ onRemoved?: (label: string) => void;
97
+ identity?: ReviewedIdentityCleanup;
64
98
  }): Promise<string[]>;
99
+ /** Inspect the same pinned local store path that the existing guarded cleanup deletes. */
100
+ export declare function safeStoreCleanupPath(root: string, override: string | undefined): {
101
+ path: string;
102
+ identity?: {
103
+ dev: bigint;
104
+ ino: bigint;
105
+ };
106
+ };
65
107
  export declare function cleanComplete(argv: string[]): CompletionResult;
66
108
  //# sourceMappingURL=clean.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../src/commands/clean.ts"],"names":[],"mappings":"AAGA,OAAO,EAAoF,KAAK,gBAAgB,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAqC1J;;;;;;;;;;mEAUmE;AACnE,wBAAsB,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAoF3D;AAED;;;;mEAImE;AACnE,wBAAsB,YAAY,CAAC,MAAM,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAY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C;IAAC,QAAQ,CAAC,EAAE,uBAAuB,CAAA;CAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CA4I7R;AAQD,0FAA0F;AAC1F,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAsB1I;AAaD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,gBAAgB,CAG9D"}
@@ -2,12 +2,15 @@ import { randomUUID } from "node:crypto";
2
2
  import { existsSync, lstatSync, readdirSync, realpathSync, renameSync, rmSync } from "node:fs";
3
3
  import { dirname, isAbsolute, join, parse, relative, resolve } from "node:path";
4
4
  import { clearSpaceHistory, isReachable, registry, resolveAuthProvider } from "@cotal-ai/core";
5
- import { DELIVERY_CREDS_KIND, MEMBERSHIP_CONFIG_KIND, MEMBERSHIP_RW_CREDS_KIND, segmentedKey, spaceMaterialDir, spaceSegment, acquireMaintenanceLock, agentSecretKeysUnder, assertSingleSpaceBroker, authDir, cleanupRestoreFallback, deleteSpaceAuth, localProcessPath, localMeshesForRoot, readMaintenanceJournal, releaseMaintenanceLock, renewalRecordPath, removeMeshesByRoot, resolveRuntimeSpace, resolveSpace, rollbackRestore, SYSTEM_CREDS_FILES, workspaceSecretStore, } from "@cotal-ai/workspace";
5
+ import { CommandFailure, DELIVERY_CREDS_KIND, MEMBERSHIP_CONFIG_KIND, MEMBERSHIP_RW_CREDS_KIND, segmentedKey, spaceMaterialDir, spaceSegment, acquireMaintenanceLock, agentSecretKeysUnder, assertSingleSpaceBroker, authDir, cleanupRestoreFallback, deleteSpaceAuth, localProcessPath, localMeshesForRoot, readMaintenanceJournal, releaseMaintenanceLock, renewalRecordPath, removeMeshesByRoot, resolveRuntimeSpace, resolveSpace, SYSTEM_CREDS_FILES, workspaceSecretStore, } from "@cotal-ai/workspace";
6
6
  import { connectOrExit, userViewAuthOrExit } from "../lib/connect.js";
7
7
  import { c } from "../ui.js";
8
8
  import { cotalRoot } from "../lib/paths.js";
9
9
  import { pidfileState, pidfileTargets } from "./down.js";
10
10
  import { localProcessSurface } from "../ext-loader.js";
11
+ import { readStackJournal, STACK_DEFINITION } from "../lib/stack-journal.js";
12
+ import { rollbackRestoreWithBroker } from "../lib/controller-restore.js";
13
+ import { observeServiceProcess, serviceInstances } from "../lib/service-instances.js";
11
14
  const TARGETS = ["history", "store", "all", "restore-fallback", "restore-attempt"];
12
15
  /** `cotal clean <history|store|all>` - one configurable cleanup verb.
13
16
  * - `history`: purge the retained message backlog on the RUNNING broker (CHAT, plus DMs with
@@ -24,12 +27,9 @@ export async function clean(args) {
24
27
  const target = args.positionals[0];
25
28
  const values = args.values;
26
29
  if (!target || !TARGETS.includes(target))
27
- return usage();
28
- if (!values.force) {
29
- console.error(c.red(`refusing to clean ${target} without --force`));
30
- console.error(c.dim(`usage: ${USAGE}`));
31
- process.exit(1);
32
- }
30
+ throw new CommandFailure("refused", "USAGE_INVALID", target ? `clean has no target "${target}"; it takes ${TARGETS.join(", ")}` : `clean needs a target: ${TARGETS.join(", ")}`);
31
+ if (!values.force)
32
+ throw new CommandFailure("refused", "USAGE_INVALID", `clean ${target} deletes without prompting, so it requires --force`, { remedy: `cotal clean ${target} --force` });
33
33
  if (target === "history")
34
34
  return purgeHistory(values);
35
35
  // Everything below acts on the SHARED broker, never one space: `store`/`all` delete the single
@@ -50,7 +50,7 @@ export async function clean(args) {
50
50
  const journal = readMaintenanceJournal(root);
51
51
  if (!journal || journal.state !== "restore-ready" || journal.restore.attemptId !== values.attempt)
52
52
  throw new Error(`no pre-commit restore attempt ${values.attempt} is recorded${journal ? ` (maintenance state is ${journal.state}${"restore" in journal ? ` for attempt ${journal.restore.attemptId}` : ""})` : ""}`);
53
- rollbackRestore(lock);
53
+ rollbackRestoreWithBroker(lock);
54
54
  console.log(c.green(`✓ rolled back stale restore attempt ${values.attempt}`));
55
55
  console.log(c.dim(" the preserved source is back at ready; resume with `cotal up` or retry `cotal up --restore`"));
56
56
  }
@@ -145,6 +145,11 @@ export function liveMeshProcess(root, space) {
145
145
  * keeps "this mesh is running here, use `cotal down`" a true statement: found live against a real
146
146
  * registry, where a dashboard watching the remote optiplex mesh made `meshes rm` refuse and point
147
147
  * at a `cotal down` that would not have stopped that mesh at all.
148
+ *
149
+ * The controller stack this root recorded for the same space makes it the home too. `cotal up`
150
+ * starts that stack's members as service instances with no pidfile, and `cotal down` stops them
151
+ * together and drops the record. A member counts here while its process may still run. One proven
152
+ * gone without its stop receipt does not, and {@link unsettledStackMembers} names it.
148
153
  */
149
154
  export function liveMeshOwner(root, space) {
150
155
  const context = { root, space: space ?? resolveRuntimeSpace(root) };
@@ -155,7 +160,7 @@ export function liveMeshOwner(root, space) {
155
160
  if (running)
156
161
  return running;
157
162
  }
158
- return undefined;
163
+ return liveStackMembers(root, context.space, false)[0];
159
164
  }
160
165
  /** `space` names the tenant whose pidfiles to look at. Pass it whenever the caller already knows
161
166
  * which mesh it means (a registry entry does): re-deriving it from the root can resolve a
@@ -169,7 +174,36 @@ export function liveMeshProcesses(root, space) {
169
174
  if (record)
170
175
  running.push(record);
171
176
  }
172
- return running;
177
+ return [...running, ...liveStackMembers(root)];
178
+ }
179
+ /** The members of the controller stack recorded at this root that may still run. A member counts as
180
+ * live unless its process is gone and its record carries the stop receipt its role requires.
181
+ * Backup, reset store and reset space share this rule. With `unreceipted` false, a member whose
182
+ * process is proven gone does not count even without its receipt, as `space forget` asks. */
183
+ function liveStackMembers(root, space, unreceipted = true) {
184
+ return stackMembers(root, space).filter((row) => !row.gone || unreceipted && !row.receipted).map((row) => `${row.label}${row.gone ? ", no stop receipt" : ""}`);
185
+ }
186
+ /** The members of the controller stack recorded at this root for `space` whose process is proven
187
+ * gone with no stop receipt: they can no longer run, but nothing stopped them cleanly. */
188
+ export function unsettledStackMembers(root, space) {
189
+ return stackMembers(root, space).filter((row) => row.gone && !row.receipted).map((row) => row.label);
190
+ }
191
+ /** Each instance record of the controller stack recorded at this root. The members live under the
192
+ * stack's own recorded space. A space derived from the root's pidfiles or accounts can name another
193
+ * tenant, or the default, once the stack is stopped. `space` limits the answer to that space's
194
+ * stack. */
195
+ function stackMembers(root, space) {
196
+ const stack = readStackJournal(root);
197
+ if (!stack || space !== undefined && stack.journal.space !== space)
198
+ return [];
199
+ return Object.values(STACK_DEFINITION).flatMap((definition) => serviceInstances(stack.journal.space, definition).map((row) => {
200
+ const value = row.record.value;
201
+ return {
202
+ label: `${definition}, instance ${row.name}`,
203
+ gone: ["gone", "previous-boot"].includes(observeServiceProcess(value)),
204
+ receipted: value.state === "stopped" && Boolean(value.nativeStop ?? value.kernelStop ?? value.processStop),
205
+ };
206
+ }));
173
207
  }
174
208
  /** "label, pid N" for a record that may still front a process, with the probe's note when it is not
175
209
  * proven alive; undefined only for no record, an empty husk or a pid proven dead. Every caller
@@ -181,6 +215,16 @@ function possiblyRunning(component, context) {
181
215
  return undefined;
182
216
  return `${component.label}, ${[state.pid && `pid ${state.pid}`, state.note].filter(Boolean).join(", ")}`;
183
217
  }
218
+ /** Fixed filesystem targets shared by native identity cleanup and its read-only impact plan. */
219
+ export function localIdentityCleanupTargets(root, space) {
220
+ const control = join(root, ".cotal");
221
+ return {
222
+ material: spaceMaterialDir(root, space), renewal: renewalRecordPath(root, space),
223
+ legacy: [...SYSTEM_CREDS_FILES, MEMBERSHIP_CONFIG_KIND, "renewal.json"].map((name) => join(control, name)),
224
+ runtime: pidfileTargets(space, root).flatMap(([path]) => [path, `${path}.identity`]),
225
+ run: join(control, "run"), auth: authDir(root),
226
+ };
227
+ }
184
228
  /** Delete the stopped mesh's local state and return what was removed (paths relative to the root).
185
229
  * `store`: the JetStream store directory. `all` adds the space identity (`.cotal/auth`), the
186
230
  * locally persisted creds/markers tied to it - all invalid once the identity regenerates, and
@@ -197,23 +241,31 @@ function possiblyRunning(component, context) {
197
241
  * provider hook, never a KMS mode on this CLI). */
198
242
  export async function removeLocalState(root, opts) {
199
243
  const removed = [];
244
+ const recordRemoved = (label) => { removed.push(label); opts.onRemoved?.(label); };
200
245
  const rm = (path, label) => {
246
+ opts.identity?.beforeRemove(path);
201
247
  if (!existsSync(path))
202
248
  return;
203
249
  rmSync(path, { recursive: true, force: true });
204
- removed.push(label);
250
+ opts.identity?.afterRemove(path);
251
+ recordRemoved(label);
205
252
  };
206
- // The space must be read before `.cotal/auth` goes - it names the auth service's pidfile
207
- // and keys the provider's secret deprovision.
208
- const space = resolveSpace(root);
253
+ // Trust removal always derives its space from the root's local authority. A named
254
+ // store-only reset may supply the recorded open space, which has no auth record.
255
+ if (opts.includeAuth && opts.space !== undefined)
256
+ throw new Error("identity cleanup cannot take a caller-selected space");
257
+ const space = opts.space ?? resolveSpace(root);
209
258
  const store = safeStoreCleanupPath(root, opts.storeDir);
259
+ if (opts.expectedStore && (store.path !== opts.expectedStore.path || Boolean(store.identity) !== Boolean(opts.expectedStore.identity) || store.identity && (store.identity.dev !== opts.expectedStore.identity?.dev || store.identity.ino !== opts.expectedStore.identity?.ino)))
260
+ throw new Error("store path or pinned filesystem identity changed before cleanup; no directory was removed");
210
261
  if (store.identity) {
211
262
  removePinnedStoreDirectory(store.path, store.identity);
212
- removed.push(opts.storeDir ? store.path : ".cotal/nats (JetStream store)");
263
+ recordRemoved(opts.storeDir ? store.path : ".cotal/nats (JetStream store)");
213
264
  }
214
265
  if (opts.includeAuth) {
266
+ const targets = localIdentityCleanupTargets(root, space);
215
267
  // ---- the seam deletes, before ANY raw identity removal (see the doc above) ----
216
- const secrets = workspaceSecretStore(root);
268
+ const secrets = opts.identity?.store ?? workspaceSecretStore(root);
217
269
  const failures = [];
218
270
  // Both kinds are PER-SPACE as of P7 (§3.1's `(space) => key` shape), and both are swept at BOTH
219
271
  // spellings: the segmented key this space writes today, and the flat pre-P7 key, which a root
@@ -229,7 +281,7 @@ export async function removeLocalState(root, opts) {
229
281
  try {
230
282
  if ((await secrets.get(key)) !== undefined) {
231
283
  await secrets.delete(key);
232
- removed.push(`.cotal/${key}`);
284
+ recordRemoved(`.cotal/${key}`);
233
285
  }
234
286
  }
235
287
  catch (e) {
@@ -249,10 +301,10 @@ export async function removeLocalState(root, opts) {
249
301
  // sweep above is (never move material into the path you are about to delete), which is why it
250
302
  // reports both the segmented keys and the flat pre-P1 level rather than resolving through
251
303
  // `agentCredsDir`.
252
- for (const key of agentSecretKeysUnder(root)) {
304
+ for (const key of opts.identity?.agentKeys ?? agentSecretKeysUnder(root)) {
253
305
  try {
254
306
  await secrets.delete(key);
255
- removed.push(`.cotal/${key}`);
307
+ recordRemoved(`.cotal/${key}`);
256
308
  }
257
309
  catch (e) {
258
310
  failures.push(`${key}: ${e instanceof Error ? e.message : String(e)}`);
@@ -261,9 +313,10 @@ export async function removeLocalState(root, opts) {
261
313
  // Gate on registration: an open-mode composition may not register an auth provider, and a
262
314
  // reset there must not start failing. With one registered, its deprovision must SUCCEED
263
315
  // (absent keys are idempotent no-ops) before the identity goes.
264
- if (registry.all("auth-provider").length) {
316
+ const provider = opts.identity ? opts.identity.provider : registry.all("auth-provider").length ? resolveAuthProvider() : null;
317
+ if (provider) {
265
318
  try {
266
- await resolveAuthProvider().deprovisionSecrets({ store: secrets, space });
319
+ await provider.deprovisionSecrets({ store: secrets, space });
267
320
  }
268
321
  catch (e) {
269
322
  failures.push(e instanceof Error ? e.message : String(e));
@@ -286,30 +339,26 @@ export async function removeLocalState(root, opts) {
286
339
  // went through the store above; the seam deletes are authoritative and their failure already
287
340
  // threw, so by here the dir holds only what a raw rm owns. On a multi-space root this removes
288
341
  // ONLY this space's segment — the other tenants' material is not this reset's to touch.
289
- rm(spaceMaterialDir(root, space), `.cotal/${spaceSegment(space)} (this space's material)`);
342
+ rm(targets.material, `.cotal/${spaceSegment(space)} (this space's material)`);
290
343
  // This space's renewal record is per-space (#1850), removed with the rest of its material. The
291
344
  // LEGACY root-scoped `renewal.json` below stays in the list too: a pre-per-space build's copy
292
345
  // must not survive a full local reset either.
293
- rm(renewalRecordPath(root, space), `${relative(root, renewalRecordPath(root, space))} (renewal record)`);
294
- for (const f of [
346
+ rm(targets.renewal, `${relative(root, targets.renewal)} (renewal record)`);
347
+ for (const path of targets.legacy) {
295
348
  // The LEGACY FLAT copies of the raw P7 kinds: still present on a root no post-P7 `up` has
296
349
  // touched, and this surface must not leave old-operator $SYS material behind because the
297
350
  // migration had not run yet. The $SYS pair comes from its ONE named source, shared with the
298
351
  // rotation writer, so a file added to that class can never be minted-but-not-swept.
299
- ...SYSTEM_CREDS_FILES,
300
- MEMBERSHIP_CONFIG_KIND,
301
- "renewal.json",
302
- ])
303
- rm(join(root, ".cotal", f), `.cotal/${f}`);
352
+ rm(path, relative(root, path));
353
+ }
304
354
  // Crash residue: after a clean `down` none of this exists; after a crash the dead pidfiles and
305
355
  // transient launch artifacts are exactly the leftovers a "full local reset" must not keep.
306
356
  // Absolute paths, every spelling: the runtime records are `{space}` templates now, and the
307
357
  // delivery-aware marker rides along with them (it was a literal in the list above).
308
- for (const [path] of pidfileTargets(space, root)) {
309
- rm(path, `${relative(root, path)} (stale runtime record)`);
310
- rm(`${path}.identity`, `${relative(root, path)}.identity (stale identity pin)`); // #969 sibling of the record
358
+ for (const path of targets.runtime) {
359
+ rm(path, `${relative(root, path)} (${path.endsWith(".identity") ? "stale identity pin" : "stale runtime record"})`);
311
360
  }
312
- rm(join(root, ".cotal", "run"), ".cotal/run (launch artifacts)");
361
+ rm(targets.run, ".cotal/run (launch artifacts)");
313
362
  // The auth dir's NON-namer contents (callout, creds, server.conf, the user-auth state dir, any
314
363
  // stray) are removed BEFORE the trust records — a locked/immutable stray UNDER `.cotal/auth`
315
364
  // throws HERE, while the namer is still present, so a re-run still resolves THIS space. Removing
@@ -317,7 +366,7 @@ export async function removeLocalState(root, opts) {
317
366
  // a stray survived after the namer had already gone. The protected set is exactly what
318
367
  // `deleteSpaceAuth` owns: the account record (the space NAMER `resolveSpace` reads), the broker
319
368
  // record, and the legacy monolith.
320
- const authDirPath = join(root, ".cotal", "auth");
369
+ const authDirPath = targets.auth;
321
370
  const trustRecord = (entry) => entry === "auth.json" || entry === "broker.json" || (entry.startsWith("account.") && entry.endsWith(".json"));
322
371
  if (existsSync(authDirPath))
323
372
  for (const entry of readdirSync(authDirPath))
@@ -326,12 +375,13 @@ export async function removeLocalState(root, opts) {
326
375
  // The trust records — the space-NAMER last among them — die ABSOLUTELY LAST, as a single
327
376
  // authoritative op: the store delete is real for a non-FS store, and on the FS composition it
328
377
  // removes the same files.
329
- if (existsSync(authDirPath))
330
- for (const entry of readdirSync(authDirPath))
331
- if (trustRecord(entry))
332
- removed.push(`.cotal/auth/${entry} (space trust)`);
378
+ const trustPaths = existsSync(authDirPath) ? readdirSync(authDirPath).filter(trustRecord) : [];
333
379
  await deleteSpaceAuth(secrets, space);
380
+ for (const entry of trustPaths)
381
+ recordRemoved(`.cotal/auth/${entry} (space trust)`);
382
+ opts.identity?.beforeRemove(authDirPath);
334
383
  rmSync(authDirPath, { recursive: true, force: true }); // drop the now-empty auth dir (nothing lockable left)
384
+ opts.identity?.afterRemove(authDirPath);
335
385
  }
336
386
  return removed;
337
387
  }
@@ -340,7 +390,8 @@ function pathContains(parent, child) {
340
390
  const separator = process.platform === "win32" ? "\\" : "/";
341
391
  return path === "" || (path !== ".." && !path.startsWith(`..${separator}`) && !isAbsolute(path));
342
392
  }
343
- function safeStoreCleanupPath(root, override) {
393
+ /** Inspect the same pinned local store path that the existing guarded cleanup deletes. */
394
+ export function safeStoreCleanupPath(root, override) {
344
395
  const requested = resolve(override ?? join(root, ".cotal", "nats"));
345
396
  if (!existsSync(requested))
346
397
  return { path: requested };
@@ -376,14 +427,6 @@ function removePinnedStoreDirectory(path, identity) {
376
427
  }
377
428
  rmSync(tomb, { recursive: true });
378
429
  }
379
- const USAGE = "cotal clean <history|store|all> --force [--dms] [--space <s>] [--server <url>] [--creds <path>] [--store-dir <dir>] | cotal clean <restore-attempt|restore-fallback> --attempt <id> --force";
380
- function usage() {
381
- console.error(c.red(`usage: ${USAGE}`));
382
- console.error(c.dim(" history purge the message backlog on the running broker (--dms to include DMs)"));
383
- console.error(c.dim(" store delete the stopped mesh's JetStream store (.cotal/nats)"));
384
- console.error(c.dim(" all store + the space identity (.cotal/auth) - full local reset"));
385
- process.exit(1);
386
- }
387
430
  export function cleanComplete(argv) {
388
431
  if (argv.length <= 1)
389
432
  return { items: TARGETS.map((value) => ({ value })), directive: "nofiles" };