@cotal-ai/cli 0.100.1 → 0.101.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (619) hide show
  1. package/dist/chat/chat-view.d.ts.map +1 -1
  2. package/dist/chat/chat-view.js +5 -1
  3. package/dist/chat/chat-view.js.map +1 -1
  4. package/dist/chat/engine.d.ts +2 -1
  5. package/dist/chat/engine.d.ts.map +1 -1
  6. package/dist/chat/engine.js +2 -1
  7. package/dist/chat/engine.js.map +1 -1
  8. package/dist/chat/frontend.d.ts.map +1 -1
  9. package/dist/chat/frontend.js +13 -7
  10. package/dist/chat/frontend.js.map +1 -1
  11. package/dist/chat/native-session.d.ts +22 -3
  12. package/dist/chat/native-session.d.ts.map +1 -1
  13. package/dist/chat/native-session.js +91 -19
  14. package/dist/chat/native-session.js.map +1 -1
  15. package/dist/chat/open-session.d.ts +1 -0
  16. package/dist/chat/open-session.d.ts.map +1 -1
  17. package/dist/chat/open-session.js +1 -1
  18. package/dist/chat/open-session.js.map +1 -1
  19. package/dist/chat/picker.d.ts +5 -0
  20. package/dist/chat/picker.d.ts.map +1 -1
  21. package/dist/chat/picker.js +23 -10
  22. package/dist/chat/picker.js.map +1 -1
  23. package/dist/chat/plain.d.ts.map +1 -1
  24. package/dist/chat/plain.js +36 -10
  25. package/dist/chat/plain.js.map +1 -1
  26. package/dist/chat/session.d.ts +5 -0
  27. package/dist/chat/session.d.ts.map +1 -1
  28. package/dist/chat/static-session.d.ts +1 -0
  29. package/dist/chat/static-session.d.ts.map +1 -1
  30. package/dist/chat/static-session.js +24 -8
  31. package/dist/chat/static-session.js.map +1 -1
  32. package/dist/chat/stdio-io.d.ts +2 -0
  33. package/dist/chat/stdio-io.d.ts.map +1 -1
  34. package/dist/chat/stdio-io.js +6 -6
  35. package/dist/chat/stdio-io.js.map +1 -1
  36. package/dist/chat/stdio.d.ts +3 -2
  37. package/dist/chat/stdio.d.ts.map +1 -1
  38. package/dist/chat/stdio.js +26 -25
  39. package/dist/chat/stdio.js.map +1 -1
  40. package/dist/chat/user-session.d.ts +1 -0
  41. package/dist/chat/user-session.d.ts.map +1 -1
  42. package/dist/chat/user-session.js +1 -1
  43. package/dist/chat/user-session.js.map +1 -1
  44. package/dist/chat/view.d.ts +5 -4
  45. package/dist/chat/view.d.ts.map +1 -1
  46. package/dist/chat/view.js +10 -8
  47. package/dist/chat/view.js.map +1 -1
  48. package/dist/command.d.ts +5 -0
  49. package/dist/command.d.ts.map +1 -1
  50. package/dist/command.js +295 -82
  51. package/dist/command.js.map +1 -1
  52. package/dist/commands/agents.d.ts +29 -5
  53. package/dist/commands/agents.d.ts.map +1 -1
  54. package/dist/commands/agents.js +100 -35
  55. package/dist/commands/agents.js.map +1 -1
  56. package/dist/commands/backup-maintenance.d.ts.map +1 -1
  57. package/dist/commands/backup-maintenance.js +54 -21
  58. package/dist/commands/backup-maintenance.js.map +1 -1
  59. package/dist/commands/backup-read.d.ts.map +1 -1
  60. package/dist/commands/backup-read.js +13 -16
  61. package/dist/commands/backup-read.js.map +1 -1
  62. package/dist/commands/backup-restore.d.ts.map +1 -1
  63. package/dist/commands/backup-restore.js +20 -4
  64. package/dist/commands/backup-restore.js.map +1 -1
  65. package/dist/commands/backup.d.ts.map +1 -1
  66. package/dist/commands/backup.js +157 -29
  67. package/dist/commands/backup.js.map +1 -1
  68. package/dist/commands/channel-members.d.ts +1 -1
  69. package/dist/commands/channel-members.d.ts.map +1 -1
  70. package/dist/commands/channel-members.js +115 -29
  71. package/dist/commands/channel-members.js.map +1 -1
  72. package/dist/commands/channels.d.ts +11 -1
  73. package/dist/commands/channels.d.ts.map +1 -1
  74. package/dist/commands/channels.js +109 -20
  75. package/dist/commands/channels.js.map +1 -1
  76. package/dist/commands/chat.d.ts +11 -3
  77. package/dist/commands/chat.d.ts.map +1 -1
  78. package/dist/commands/chat.js +50 -22
  79. package/dist/commands/chat.js.map +1 -1
  80. package/dist/commands/clean.d.ts +10 -5
  81. package/dist/commands/clean.d.ts.map +1 -1
  82. package/dist/commands/clean.js +245 -42
  83. package/dist/commands/clean.js.map +1 -1
  84. package/dist/commands/completion.d.ts +15 -2
  85. package/dist/commands/completion.d.ts.map +1 -1
  86. package/dist/commands/completion.js +91 -26
  87. package/dist/commands/completion.js.map +1 -1
  88. package/dist/commands/config.d.ts +24 -1
  89. package/dist/commands/config.d.ts.map +1 -1
  90. package/dist/commands/config.js +91 -15
  91. package/dist/commands/config.js.map +1 -1
  92. package/dist/commands/console.d.ts.map +1 -1
  93. package/dist/commands/console.js +5 -4
  94. package/dist/commands/console.js.map +1 -1
  95. package/dist/commands/describe.d.ts +4 -2
  96. package/dist/commands/describe.d.ts.map +1 -1
  97. package/dist/commands/describe.js +4 -4
  98. package/dist/commands/describe.js.map +1 -1
  99. package/dist/commands/doctor.d.ts +1 -1
  100. package/dist/commands/doctor.d.ts.map +1 -1
  101. package/dist/commands/doctor.js +261 -34
  102. package/dist/commands/doctor.js.map +1 -1
  103. package/dist/commands/down-manifest.d.ts.map +1 -1
  104. package/dist/commands/down-manifest.js +9 -6
  105. package/dist/commands/down-manifest.js.map +1 -1
  106. package/dist/commands/down-services.d.ts +17 -16
  107. package/dist/commands/down-services.d.ts.map +1 -1
  108. package/dist/commands/down-services.js +29 -53
  109. package/dist/commands/down-services.js.map +1 -1
  110. package/dist/commands/down.d.ts +2 -2
  111. package/dist/commands/down.d.ts.map +1 -1
  112. package/dist/commands/down.js +96 -67
  113. package/dist/commands/down.js.map +1 -1
  114. package/dist/commands/endpoint-deregister.d.ts.map +1 -1
  115. package/dist/commands/endpoint-deregister.js +2 -2
  116. package/dist/commands/endpoint-deregister.js.map +1 -1
  117. package/dist/commands/endpoint.d.ts +2 -1
  118. package/dist/commands/endpoint.d.ts.map +1 -1
  119. package/dist/commands/endpoint.js +2 -2
  120. package/dist/commands/endpoint.js.map +1 -1
  121. package/dist/commands/endpoints.d.ts +1 -0
  122. package/dist/commands/endpoints.d.ts.map +1 -1
  123. package/dist/commands/endpoints.js +20 -5
  124. package/dist/commands/endpoints.js.map +1 -1
  125. package/dist/commands/feedback.d.ts.map +1 -1
  126. package/dist/commands/feedback.js +40 -2
  127. package/dist/commands/feedback.js.map +1 -1
  128. package/dist/commands/help.d.ts.map +1 -1
  129. package/dist/commands/help.js +2 -1
  130. package/dist/commands/help.js.map +1 -1
  131. package/dist/commands/history-clear.d.ts.map +1 -1
  132. package/dist/commands/history-clear.js +67 -51
  133. package/dist/commands/history-clear.js.map +1 -1
  134. package/dist/commands/history.d.ts +17 -2
  135. package/dist/commands/history.d.ts.map +1 -1
  136. package/dist/commands/history.js +221 -34
  137. package/dist/commands/history.js.map +1 -1
  138. package/dist/commands/join.d.ts +2 -0
  139. package/dist/commands/join.d.ts.map +1 -1
  140. package/dist/commands/join.js +132 -80
  141. package/dist/commands/join.js.map +1 -1
  142. package/dist/commands/meshes-add.d.ts +19 -4
  143. package/dist/commands/meshes-add.d.ts.map +1 -1
  144. package/dist/commands/meshes-add.js +114 -15
  145. package/dist/commands/meshes-add.js.map +1 -1
  146. package/dist/commands/meshes-wizard.d.ts +1 -0
  147. package/dist/commands/meshes-wizard.d.ts.map +1 -1
  148. package/dist/commands/meshes-wizard.js +45 -13
  149. package/dist/commands/meshes-wizard.js.map +1 -1
  150. package/dist/commands/meshes.d.ts +1 -1
  151. package/dist/commands/meshes.d.ts.map +1 -1
  152. package/dist/commands/meshes.js +76 -47
  153. package/dist/commands/meshes.js.map +1 -1
  154. package/dist/commands/mint.d.ts.map +1 -1
  155. package/dist/commands/mint.js +212 -19
  156. package/dist/commands/mint.js.map +1 -1
  157. package/dist/commands/models.d.ts +5 -1
  158. package/dist/commands/models.d.ts.map +1 -1
  159. package/dist/commands/models.js +21 -13
  160. package/dist/commands/models.js.map +1 -1
  161. package/dist/commands/persona-remote.d.ts.map +1 -1
  162. package/dist/commands/persona-remote.js +38 -19
  163. package/dist/commands/persona-remote.js.map +1 -1
  164. package/dist/commands/persona.d.ts +1 -1
  165. package/dist/commands/persona.d.ts.map +1 -1
  166. package/dist/commands/persona.js +92 -23
  167. package/dist/commands/persona.js.map +1 -1
  168. package/dist/commands/personas.d.ts.map +1 -1
  169. package/dist/commands/personas.js +59 -40
  170. package/dist/commands/personas.js.map +1 -1
  171. package/dist/commands/reset-space-apply.d.ts.map +1 -1
  172. package/dist/commands/reset-space-apply.js +69 -17
  173. package/dist/commands/reset-space-apply.js.map +1 -1
  174. package/dist/commands/reset-store-apply.d.ts +16 -0
  175. package/dist/commands/reset-store-apply.d.ts.map +1 -1
  176. package/dist/commands/reset-store-apply.js +122 -23
  177. package/dist/commands/reset-store-apply.js.map +1 -1
  178. package/dist/commands/reset.d.ts.map +1 -1
  179. package/dist/commands/reset.js +8 -7
  180. package/dist/commands/reset.js.map +1 -1
  181. package/dist/commands/revoke-credential.d.ts +5 -0
  182. package/dist/commands/revoke-credential.d.ts.map +1 -0
  183. package/dist/commands/revoke-credential.js +128 -0
  184. package/dist/commands/revoke-credential.js.map +1 -0
  185. package/dist/commands/send.d.ts +11 -3
  186. package/dist/commands/send.d.ts.map +1 -1
  187. package/dist/commands/send.js +284 -47
  188. package/dist/commands/send.js.map +1 -1
  189. package/dist/commands/service-actions.d.ts +2 -1
  190. package/dist/commands/service-actions.d.ts.map +1 -1
  191. package/dist/commands/service-actions.js +117 -21
  192. package/dist/commands/service-actions.js.map +1 -1
  193. package/dist/commands/service-log-follow.js +1 -1
  194. package/dist/commands/service-log-follow.js.map +1 -1
  195. package/dist/commands/service-registry.d.ts +1 -1
  196. package/dist/commands/service-registry.d.ts.map +1 -1
  197. package/dist/commands/service-registry.js +74 -30
  198. package/dist/commands/service-registry.js.map +1 -1
  199. package/dist/commands/service-set-stop.d.ts.map +1 -1
  200. package/dist/commands/service-set-stop.js +3 -2
  201. package/dist/commands/service-set-stop.js.map +1 -1
  202. package/dist/commands/setup-start.d.ts.map +1 -1
  203. package/dist/commands/setup-start.js +46 -5
  204. package/dist/commands/setup-start.js.map +1 -1
  205. package/dist/commands/setup.d.ts.map +1 -1
  206. package/dist/commands/setup.js +28 -13
  207. package/dist/commands/setup.js.map +1 -1
  208. package/dist/commands/space-delete.d.ts.map +1 -1
  209. package/dist/commands/space-delete.js +130 -41
  210. package/dist/commands/space-delete.js.map +1 -1
  211. package/dist/commands/space-registration.d.ts +13 -6
  212. package/dist/commands/space-registration.d.ts.map +1 -1
  213. package/dist/commands/space-registration.js +167 -46
  214. package/dist/commands/space-registration.js.map +1 -1
  215. package/dist/commands/space.d.ts +15 -1
  216. package/dist/commands/space.d.ts.map +1 -1
  217. package/dist/commands/space.js +66 -24
  218. package/dist/commands/space.js.map +1 -1
  219. package/dist/commands/spawn-preview.d.ts.map +1 -1
  220. package/dist/commands/spawn-preview.js +48 -10
  221. package/dist/commands/spawn-preview.js.map +1 -1
  222. package/dist/commands/spawn.d.ts +36 -13
  223. package/dist/commands/spawn.d.ts.map +1 -1
  224. package/dist/commands/spawn.js +263 -129
  225. package/dist/commands/spawn.js.map +1 -1
  226. package/dist/commands/stack-down.d.ts +9 -3
  227. package/dist/commands/stack-down.d.ts.map +1 -1
  228. package/dist/commands/stack-down.js +344 -64
  229. package/dist/commands/stack-down.js.map +1 -1
  230. package/dist/commands/stack-gone.d.ts +17 -0
  231. package/dist/commands/stack-gone.d.ts.map +1 -0
  232. package/dist/commands/stack-gone.js +218 -0
  233. package/dist/commands/stack-gone.js.map +1 -0
  234. package/dist/commands/stack-up.d.ts +64 -4
  235. package/dist/commands/stack-up.d.ts.map +1 -1
  236. package/dist/commands/stack-up.js +482 -55
  237. package/dist/commands/stack-up.js.map +1 -1
  238. package/dist/commands/status.d.ts +76 -2
  239. package/dist/commands/status.d.ts.map +1 -1
  240. package/dist/commands/status.js +550 -112
  241. package/dist/commands/status.js.map +1 -1
  242. package/dist/commands/team-agent-apply.d.ts.map +1 -1
  243. package/dist/commands/team-agent-apply.js +4 -3
  244. package/dist/commands/team-agent-apply.js.map +1 -1
  245. package/dist/commands/team-agent-remove.d.ts.map +1 -1
  246. package/dist/commands/team-agent-remove.js +4 -4
  247. package/dist/commands/team-agent-remove.js.map +1 -1
  248. package/dist/commands/team-boot-controller.d.ts.map +1 -1
  249. package/dist/commands/team-boot-controller.js +8 -2
  250. package/dist/commands/team-boot-controller.js.map +1 -1
  251. package/dist/commands/team-channel-remove.d.ts.map +1 -1
  252. package/dist/commands/team-channel-remove.js +26 -10
  253. package/dist/commands/team-channel-remove.js.map +1 -1
  254. package/dist/commands/team-deploy-apply.d.ts.map +1 -1
  255. package/dist/commands/team-deploy-apply.js +4 -3
  256. package/dist/commands/team-deploy-apply.js.map +1 -1
  257. package/dist/commands/team-mixed-remove.js +5 -5
  258. package/dist/commands/team-mixed-remove.js.map +1 -1
  259. package/dist/commands/team.d.ts.map +1 -1
  260. package/dist/commands/team.js +94 -32
  261. package/dist/commands/team.js.map +1 -1
  262. package/dist/commands/telemetry.d.ts +1 -1
  263. package/dist/commands/telemetry.d.ts.map +1 -1
  264. package/dist/commands/telemetry.js +5 -3
  265. package/dist/commands/telemetry.js.map +1 -1
  266. package/dist/commands/topology.d.ts.map +1 -1
  267. package/dist/commands/topology.js +11 -7
  268. package/dist/commands/topology.js.map +1 -1
  269. package/dist/commands/up.d.ts +6 -6
  270. package/dist/commands/up.d.ts.map +1 -1
  271. package/dist/commands/up.js +963 -240
  272. package/dist/commands/up.js.map +1 -1
  273. package/dist/commands/update.d.ts.map +1 -1
  274. package/dist/commands/update.js +9 -3
  275. package/dist/commands/update.js.map +1 -1
  276. package/dist/commands/use.d.ts +5 -1
  277. package/dist/commands/use.d.ts.map +1 -1
  278. package/dist/commands/use.js +55 -12
  279. package/dist/commands/use.js.map +1 -1
  280. package/dist/commands/watch.d.ts +4 -1
  281. package/dist/commands/watch.d.ts.map +1 -1
  282. package/dist/commands/watch.js +15 -3
  283. package/dist/commands/watch.js.map +1 -1
  284. package/dist/commands/who.d.ts +2 -0
  285. package/dist/commands/who.d.ts.map +1 -1
  286. package/dist/commands/who.js +18 -5
  287. package/dist/commands/who.js.map +1 -1
  288. package/dist/commands/whoami.d.ts +44 -5
  289. package/dist/commands/whoami.d.ts.map +1 -1
  290. package/dist/commands/whoami.js +168 -16
  291. package/dist/commands/whoami.js.map +1 -1
  292. package/dist/console/app.d.ts +1 -1
  293. package/dist/console/app.d.ts.map +1 -1
  294. package/dist/console/app.js +15 -9
  295. package/dist/console/app.js.map +1 -1
  296. package/dist/console/launch.d.ts +25 -0
  297. package/dist/console/launch.d.ts.map +1 -0
  298. package/dist/console/launch.js +56 -0
  299. package/dist/console/launch.js.map +1 -0
  300. package/dist/console/ui/CommandPalette.d.ts +5 -4
  301. package/dist/console/ui/CommandPalette.d.ts.map +1 -1
  302. package/dist/console/ui/CommandPalette.js +136 -45
  303. package/dist/console/ui/CommandPalette.js.map +1 -1
  304. package/dist/console/ui/Help.js +1 -1
  305. package/dist/console/ui/Help.js.map +1 -1
  306. package/dist/console/ui/Modal.d.ts +10 -0
  307. package/dist/console/ui/Modal.d.ts.map +1 -0
  308. package/dist/console/ui/Modal.js +8 -0
  309. package/dist/console/ui/Modal.js.map +1 -0
  310. package/dist/console/ui/NewAgent.d.ts +14 -0
  311. package/dist/console/ui/NewAgent.d.ts.map +1 -0
  312. package/dist/console/ui/NewAgent.js +114 -0
  313. package/dist/console/ui/NewAgent.js.map +1 -0
  314. package/dist/console/ui/StatusBar.d.ts +1 -2
  315. package/dist/console/ui/StatusBar.d.ts.map +1 -1
  316. package/dist/console/ui/StatusBar.js +6 -8
  317. package/dist/console/ui/StatusBar.js.map +1 -1
  318. package/dist/console/ui/topo/Map.d.ts.map +1 -1
  319. package/dist/console/ui/topo/Map.js +1 -2
  320. package/dist/console/ui/topo/Map.js.map +1 -1
  321. package/dist/console/ui/topo/Matrix.js +2 -2
  322. package/dist/console/ui/topo/Matrix.js.map +1 -1
  323. package/dist/console/ui/topo/Sequence.d.ts.map +1 -1
  324. package/dist/console/ui/topo/Sequence.js +5 -4
  325. package/dist/console/ui/topo/Sequence.js.map +1 -1
  326. package/dist/console/ui/topo/model.d.ts +2 -1
  327. package/dist/console/ui/topo/model.d.ts.map +1 -1
  328. package/dist/console/ui/topo/model.js +4 -3
  329. package/dist/console/ui/topo/model.js.map +1 -1
  330. package/dist/exec-endpoint/service-adapter.d.ts.map +1 -1
  331. package/dist/exec-endpoint/service-adapter.js +13 -3
  332. package/dist/exec-endpoint/service-adapter.js.map +1 -1
  333. package/dist/ext-loader.d.ts +4 -0
  334. package/dist/ext-loader.d.ts.map +1 -1
  335. package/dist/ext-loader.js +6 -0
  336. package/dist/ext-loader.js.map +1 -1
  337. package/dist/help.d.ts.map +1 -1
  338. package/dist/help.js +44 -23
  339. package/dist/help.js.map +1 -1
  340. package/dist/index.d.ts.map +1 -1
  341. package/dist/index.js +59 -54
  342. package/dist/index.js.map +1 -1
  343. package/dist/lib/agent-skills.d.ts.map +1 -1
  344. package/dist/lib/agent-skills.js +2 -1
  345. package/dist/lib/agent-skills.js.map +1 -1
  346. package/dist/lib/attach-client.js +2 -2
  347. package/dist/lib/attach-client.js.map +1 -1
  348. package/dist/lib/backup-artifact.d.ts +36 -8
  349. package/dist/lib/backup-artifact.d.ts.map +1 -1
  350. package/dist/lib/backup-artifact.js +156 -26
  351. package/dist/lib/backup-artifact.js.map +1 -1
  352. package/dist/lib/broker-service.d.ts +27 -3
  353. package/dist/lib/broker-service.d.ts.map +1 -1
  354. package/dist/lib/broker-service.js +135 -27
  355. package/dist/lib/broker-service.js.map +1 -1
  356. package/dist/lib/broker-store-health.d.ts +89 -0
  357. package/dist/lib/broker-store-health.d.ts.map +1 -0
  358. package/dist/lib/broker-store-health.js +171 -0
  359. package/dist/lib/broker-store-health.js.map +1 -0
  360. package/dist/lib/cancel.d.ts +4 -4
  361. package/dist/lib/cancel.d.ts.map +1 -1
  362. package/dist/lib/cancel.js +5 -5
  363. package/dist/lib/cancel.js.map +1 -1
  364. package/dist/lib/completion-install.d.ts +11 -2
  365. package/dist/lib/completion-install.d.ts.map +1 -1
  366. package/dist/lib/completion-install.js +79 -21
  367. package/dist/lib/completion-install.js.map +1 -1
  368. package/dist/lib/completion-scripts.d.ts.map +1 -1
  369. package/dist/lib/completion-scripts.js +2 -2
  370. package/dist/lib/completion-scripts.js.map +1 -1
  371. package/dist/lib/completion.d.ts +5 -1
  372. package/dist/lib/completion.d.ts.map +1 -1
  373. package/dist/lib/completion.js +10 -0
  374. package/dist/lib/completion.js.map +1 -1
  375. package/dist/lib/concrete-channel.d.ts +6 -0
  376. package/dist/lib/concrete-channel.d.ts.map +1 -0
  377. package/dist/lib/concrete-channel.js +17 -0
  378. package/dist/lib/concrete-channel.js.map +1 -0
  379. package/dist/lib/confirmation-required.d.ts +3 -12
  380. package/dist/lib/confirmation-required.d.ts.map +1 -1
  381. package/dist/lib/confirmation-required.js +9 -8
  382. package/dist/lib/confirmation-required.js.map +1 -1
  383. package/dist/lib/connect.d.ts +9 -0
  384. package/dist/lib/connect.d.ts.map +1 -1
  385. package/dist/lib/connect.js +27 -0
  386. package/dist/lib/connect.js.map +1 -1
  387. package/dist/lib/control.d.ts +42 -12
  388. package/dist/lib/control.d.ts.map +1 -1
  389. package/dist/lib/control.js +130 -31
  390. package/dist/lib/control.js.map +1 -1
  391. package/dist/lib/controller-restore.d.ts.map +1 -1
  392. package/dist/lib/controller-restore.js +12 -7
  393. package/dist/lib/controller-restore.js.map +1 -1
  394. package/dist/lib/credential-authority.d.ts.map +1 -1
  395. package/dist/lib/credential-authority.js +3 -0
  396. package/dist/lib/credential-authority.js.map +1 -1
  397. package/dist/lib/credential-exports.d.ts +17 -0
  398. package/dist/lib/credential-exports.d.ts.map +1 -0
  399. package/dist/lib/credential-exports.js +21 -0
  400. package/dist/lib/credential-exports.js.map +1 -0
  401. package/dist/lib/debug-flag.d.ts +4 -0
  402. package/dist/lib/debug-flag.d.ts.map +1 -0
  403. package/dist/lib/debug-flag.js +7 -0
  404. package/dist/lib/debug-flag.js.map +1 -0
  405. package/dist/lib/default-persona.d.ts +2 -0
  406. package/dist/lib/default-persona.d.ts.map +1 -1
  407. package/dist/lib/default-persona.js +2 -0
  408. package/dist/lib/default-persona.js.map +1 -1
  409. package/dist/lib/delivery-proc.d.ts +1 -1
  410. package/dist/lib/delivery-proc.d.ts.map +1 -1
  411. package/dist/lib/delivery-proc.js +5 -4
  412. package/dist/lib/delivery-proc.js.map +1 -1
  413. package/dist/lib/delivery-responder.d.ts +7 -3
  414. package/dist/lib/delivery-responder.d.ts.map +1 -1
  415. package/dist/lib/delivery-responder.js +8 -4
  416. package/dist/lib/delivery-responder.js.map +1 -1
  417. package/dist/lib/denied-write.d.ts +8 -0
  418. package/dist/lib/denied-write.d.ts.map +1 -0
  419. package/dist/lib/denied-write.js +24 -0
  420. package/dist/lib/denied-write.js.map +1 -0
  421. package/dist/lib/endpoint-capability-gates.js +2 -2
  422. package/dist/lib/endpoint-capability-gates.js.map +1 -1
  423. package/dist/lib/flag-value-refusal.d.ts +8 -0
  424. package/dist/lib/flag-value-refusal.d.ts.map +1 -0
  425. package/dist/lib/flag-value-refusal.js +10 -0
  426. package/dist/lib/flag-value-refusal.js.map +1 -0
  427. package/dist/lib/install-umask.d.ts +5 -0
  428. package/dist/lib/install-umask.d.ts.map +1 -1
  429. package/dist/lib/install-umask.js +25 -0
  430. package/dist/lib/install-umask.js.map +1 -1
  431. package/dist/lib/interrupt-notice.d.ts +23 -1
  432. package/dist/lib/interrupt-notice.d.ts.map +1 -1
  433. package/dist/lib/interrupt-notice.js +27 -6
  434. package/dist/lib/interrupt-notice.js.map +1 -1
  435. package/dist/lib/interrupt-report.d.ts +7 -0
  436. package/dist/lib/interrupt-report.d.ts.map +1 -0
  437. package/dist/lib/interrupt-report.js +24 -0
  438. package/dist/lib/interrupt-report.js.map +1 -0
  439. package/dist/lib/isolated-broker.d.ts +1 -1
  440. package/dist/lib/isolated-broker.d.ts.map +1 -1
  441. package/dist/lib/isolated-broker.js +17 -8
  442. package/dist/lib/isolated-broker.js.map +1 -1
  443. package/dist/lib/legacy-start.d.ts +8 -6
  444. package/dist/lib/legacy-start.d.ts.map +1 -1
  445. package/dist/lib/legacy-start.js +36 -36
  446. package/dist/lib/legacy-start.js.map +1 -1
  447. package/dist/lib/manager-choice.d.ts +45 -4
  448. package/dist/lib/manager-choice.d.ts.map +1 -1
  449. package/dist/lib/manager-choice.js +214 -24
  450. package/dist/lib/manager-choice.js.map +1 -1
  451. package/dist/lib/manager-proc.d.ts.map +1 -1
  452. package/dist/lib/manager-proc.js +7 -6
  453. package/dist/lib/manager-proc.js.map +1 -1
  454. package/dist/lib/manifest/index.d.ts +5 -1
  455. package/dist/lib/manifest/index.d.ts.map +1 -1
  456. package/dist/lib/manifest/index.js +50 -5
  457. package/dist/lib/manifest/index.js.map +1 -1
  458. package/dist/lib/manifest/preflight.d.ts +4 -0
  459. package/dist/lib/manifest/preflight.d.ts.map +1 -1
  460. package/dist/lib/manifest/preflight.js +18 -1
  461. package/dist/lib/manifest/preflight.js.map +1 -1
  462. package/dist/lib/manifest/resolve.d.ts +8 -0
  463. package/dist/lib/manifest/resolve.d.ts.map +1 -1
  464. package/dist/lib/manifest/resolve.js +104 -11
  465. package/dist/lib/manifest/resolve.js.map +1 -1
  466. package/dist/lib/missing-flags.js +1 -1
  467. package/dist/lib/missing-flags.js.map +1 -1
  468. package/dist/lib/nats-bin.d.ts +28 -5
  469. package/dist/lib/nats-bin.d.ts.map +1 -1
  470. package/dist/lib/nats-bin.js +85 -7
  471. package/dist/lib/nats-bin.js.map +1 -1
  472. package/dist/lib/nearest-word.d.ts +14 -0
  473. package/dist/lib/nearest-word.d.ts.map +1 -0
  474. package/dist/lib/nearest-word.js +76 -0
  475. package/dist/lib/nearest-word.js.map +1 -0
  476. package/dist/lib/no-expiry-record.d.ts +8 -0
  477. package/dist/lib/no-expiry-record.d.ts.map +1 -0
  478. package/dist/lib/no-expiry-record.js +27 -0
  479. package/dist/lib/no-expiry-record.js.map +1 -0
  480. package/dist/lib/paths.d.ts +31 -0
  481. package/dist/lib/paths.d.ts.map +1 -1
  482. package/dist/lib/paths.js +92 -2
  483. package/dist/lib/paths.js.map +1 -1
  484. package/dist/lib/persona-files.d.ts +29 -6
  485. package/dist/lib/persona-files.d.ts.map +1 -1
  486. package/dist/lib/persona-files.js +179 -36
  487. package/dist/lib/persona-files.js.map +1 -1
  488. package/dist/lib/personas.d.ts +18 -1
  489. package/dist/lib/personas.d.ts.map +1 -1
  490. package/dist/lib/personas.js +65 -6
  491. package/dist/lib/personas.js.map +1 -1
  492. package/dist/lib/prompts.d.ts +7 -1
  493. package/dist/lib/prompts.d.ts.map +1 -1
  494. package/dist/lib/prompts.js +43 -3
  495. package/dist/lib/prompts.js.map +1 -1
  496. package/dist/lib/registry-errors.d.ts +2 -1
  497. package/dist/lib/registry-errors.d.ts.map +1 -1
  498. package/dist/lib/registry-errors.js +6 -2
  499. package/dist/lib/registry-errors.js.map +1 -1
  500. package/dist/lib/reset-space-plan.d.ts +2 -0
  501. package/dist/lib/reset-space-plan.d.ts.map +1 -1
  502. package/dist/lib/reset-space-plan.js +1 -1
  503. package/dist/lib/reset-space-plan.js.map +1 -1
  504. package/dist/lib/restore.d.ts +45 -3
  505. package/dist/lib/restore.d.ts.map +1 -1
  506. package/dist/lib/restore.js +248 -35
  507. package/dist/lib/restore.js.map +1 -1
  508. package/dist/lib/rolled-back-runs.d.ts +36 -0
  509. package/dist/lib/rolled-back-runs.d.ts.map +1 -0
  510. package/dist/lib/rolled-back-runs.js +96 -0
  511. package/dist/lib/rolled-back-runs.js.map +1 -0
  512. package/dist/lib/service-definitions.d.ts +16 -3
  513. package/dist/lib/service-definitions.d.ts.map +1 -1
  514. package/dist/lib/service-definitions.js +99 -27
  515. package/dist/lib/service-definitions.js.map +1 -1
  516. package/dist/lib/service-instances.d.ts +13 -1
  517. package/dist/lib/service-instances.d.ts.map +1 -1
  518. package/dist/lib/service-instances.js +56 -12
  519. package/dist/lib/service-instances.js.map +1 -1
  520. package/dist/lib/service-presets.d.ts.map +1 -1
  521. package/dist/lib/service-presets.js +16 -0
  522. package/dist/lib/service-presets.js.map +1 -1
  523. package/dist/lib/service-process.d.ts +51 -8
  524. package/dist/lib/service-process.d.ts.map +1 -1
  525. package/dist/lib/service-process.js +385 -48
  526. package/dist/lib/service-process.js.map +1 -1
  527. package/dist/lib/space-streams.d.ts +18 -0
  528. package/dist/lib/space-streams.d.ts.map +1 -0
  529. package/dist/lib/space-streams.js +35 -0
  530. package/dist/lib/space-streams.js.map +1 -0
  531. package/dist/lib/spawn-defaults.d.ts +25 -1
  532. package/dist/lib/spawn-defaults.d.ts.map +1 -1
  533. package/dist/lib/spawn-defaults.js +37 -1
  534. package/dist/lib/spawn-defaults.js.map +1 -1
  535. package/dist/lib/stack-journal.d.ts +157 -14
  536. package/dist/lib/stack-journal.d.ts.map +1 -1
  537. package/dist/lib/stack-journal.js +406 -49
  538. package/dist/lib/stack-journal.js.map +1 -1
  539. package/dist/lib/stack-listeners.d.ts +17 -0
  540. package/dist/lib/stack-listeners.d.ts.map +1 -0
  541. package/dist/lib/stack-listeners.js +54 -0
  542. package/dist/lib/stack-listeners.js.map +1 -0
  543. package/dist/lib/stack-members.d.ts +13 -0
  544. package/dist/lib/stack-members.d.ts.map +1 -0
  545. package/dist/lib/stack-members.js +24 -0
  546. package/dist/lib/stack-members.js.map +1 -0
  547. package/dist/lib/stack-resume.d.ts.map +1 -1
  548. package/dist/lib/stack-resume.js +5 -2
  549. package/dist/lib/stack-resume.js.map +1 -1
  550. package/dist/lib/stack-runs.d.ts +34 -0
  551. package/dist/lib/stack-runs.d.ts.map +1 -0
  552. package/dist/lib/stack-runs.js +75 -0
  553. package/dist/lib/stack-runs.js.map +1 -0
  554. package/dist/lib/status.d.ts +11 -0
  555. package/dist/lib/status.d.ts.map +1 -1
  556. package/dist/lib/status.js +4 -5
  557. package/dist/lib/status.js.map +1 -1
  558. package/dist/lib/stdout-owner.d.ts +12 -3
  559. package/dist/lib/stdout-owner.d.ts.map +1 -1
  560. package/dist/lib/stdout-owner.js +33 -5
  561. package/dist/lib/stdout-owner.js.map +1 -1
  562. package/dist/lib/store-dir.d.ts +68 -4
  563. package/dist/lib/store-dir.d.ts.map +1 -1
  564. package/dist/lib/store-dir.js +253 -17
  565. package/dist/lib/store-dir.js.map +1 -1
  566. package/dist/lib/team-additive-attempt.d.ts +1 -1
  567. package/dist/lib/team-channel-removal.d.ts.map +1 -1
  568. package/dist/lib/team-channel-removal.js +4 -0
  569. package/dist/lib/team-channel-removal.js.map +1 -1
  570. package/dist/lib/team-deploy-inspection.d.ts +13 -0
  571. package/dist/lib/team-deploy-inspection.d.ts.map +1 -1
  572. package/dist/lib/team-deploy-inspection.js +12 -0
  573. package/dist/lib/team-deploy-inspection.js.map +1 -1
  574. package/dist/lib/team-text.d.ts +6 -0
  575. package/dist/lib/team-text.d.ts.map +1 -0
  576. package/dist/lib/team-text.js +36 -0
  577. package/dist/lib/team-text.js.map +1 -0
  578. package/dist/lib/transient.d.ts +14 -8
  579. package/dist/lib/transient.d.ts.map +1 -1
  580. package/dist/lib/transient.js +72 -11
  581. package/dist/lib/transient.js.map +1 -1
  582. package/dist/lib/unusable-file.d.ts +13 -0
  583. package/dist/lib/unusable-file.d.ts.map +1 -0
  584. package/dist/lib/unusable-file.js +12 -0
  585. package/dist/lib/unusable-file.js.map +1 -0
  586. package/dist/lib/up-report.d.ts +6 -0
  587. package/dist/lib/up-report.d.ts.map +1 -1
  588. package/dist/lib/up-report.js +13 -0
  589. package/dist/lib/up-report.js.map +1 -1
  590. package/dist/lib/verdict.d.ts +14 -0
  591. package/dist/lib/verdict.d.ts.map +1 -0
  592. package/dist/lib/verdict.js +15 -0
  593. package/dist/lib/verdict.js.map +1 -0
  594. package/dist/managed-handoff.d.ts +11 -6
  595. package/dist/managed-handoff.d.ts.map +1 -1
  596. package/dist/managed-handoff.js +27 -18
  597. package/dist/managed-handoff.js.map +1 -1
  598. package/dist/render.d.ts +5 -2
  599. package/dist/render.d.ts.map +1 -1
  600. package/dist/render.js +44 -10
  601. package/dist/render.js.map +1 -1
  602. package/dist/telemetry.d.ts +4 -3
  603. package/dist/telemetry.d.ts.map +1 -1
  604. package/dist/telemetry.js +14 -6
  605. package/dist/telemetry.js.map +1 -1
  606. package/dist/ui.d.ts +3 -2
  607. package/dist/ui.d.ts.map +1 -1
  608. package/dist/ui.js +6 -4
  609. package/dist/ui.js.map +1 -1
  610. package/dist/view/mesh-view.d.ts.map +1 -1
  611. package/dist/view/mesh-view.js +4 -1
  612. package/dist/view/mesh-view.js.map +1 -1
  613. package/dist/watch-data.d.ts +9 -1
  614. package/dist/watch-data.d.ts.map +1 -1
  615. package/dist/watch-data.js +17 -3
  616. package/dist/watch-data.js.map +1 -1
  617. package/dist/watch-json.js +4 -3
  618. package/dist/watch-json.js.map +1 -1
  619. package/package.json +5 -5
package/dist/command.js CHANGED
@@ -1,20 +1,31 @@
1
1
  import { writeSync } from "node:fs";
2
+ import { parseArgs } from "node:util";
3
+ import { homedir } from "node:os";
4
+ import { isAbsolute, join, resolve } from "node:path";
2
5
  import { commandDeclarationProblems, findCommand, findSubcommand, parseCommandArgs } from "@cotal-ai/core";
3
- import { CommandFailure, commandFailureReport, cachedPreferences, disableColor, disableInput, envelopeLine, exitCode, failureEnvelope, globalFlagDeclarationProblems, hasMeshTargetFlags, inOperationSpace, isCommandFailure, isConnectRefusal, isSeededCommand, isWorkspaceTargetError, operationWarnings, outputDeclarationProblems, renderReport, renderWorkspaceError, runOperation, workspaceErrorParts, spaceRootTarget, targetErrorCode, terminalWidth, } from "@cotal-ai/workspace";
6
+ import { CommandFailure, commandFailureReport, cachedPreferences, cotalDirProblem, cotalHomeProblem, findCotalRoot, disableColor, disableInput, envelopeLine, exitCode, failureEnvelope, GLOBAL_FLAGS, globalConfigDirProblem, globalFlagDeclarationProblems, hasMeshTargetFlags, inOperationSpace, isCommandFailure, brokerUrlCredentialRefusal, brokerUrlHasUserinfo, isConnectRefusal, isMeshRegistryError, isSeededCommand, isWorkspaceTargetError, localeIsUtf8, operationWarnings, outputDeclarationProblems, oneLine, preferencesFolderWarning, recordOperationWarning, renderReport, renderWorkspaceError, runOperation, workspaceErrorParts, spaceRootTarget, targetErrorCode, terminalWidth, userCotalDir, } from "@cotal-ai/workspace";
4
7
  import { c, staleStoreHint, stderrLine } from "./ui.js";
8
+ import { debugFlag } from "./lib/debug-flag.js";
5
9
  import { isExtensionStub, materializeExtension, materializeExtensionCommand, overlayExtensions, setCommandSurface, setInstalledExtensionsEnabled, } from "./ext-loader.js";
6
10
  import { reconcileSeededConnectors } from "./seed/reconcile.js";
7
11
  import { isAuthenticSeedChild } from "./seed/lock.js";
8
12
  import { printCommandHelp, printHelpPath, printEntry } from "./help.js";
9
13
  import { CatalogPreparationError, prepareCatalogCommand } from "./commands/sync.js";
10
14
  import { servicePresetCommand } from "./lib/service-presets.js";
15
+ import { keepStartupNotice } from "./lib/interrupt-notice.js";
11
16
  import { metadataPositionals } from "./lib/command-path.js";
12
17
  import { chooseMeshTarget } from "./lib/choose-target.js";
13
- import { ConfirmationRequired } from "./lib/confirmation-required.js";
14
- import { MissingFlags } from "./lib/missing-flags.js";
18
+ import { registryFailure } from "./lib/registry-errors.js";
19
+ import { FlagValueRefusal } from "./lib/flag-value-refusal.js";
20
+ import { workingFolderRemoved } from "./lib/paths.js";
15
21
  import { reportLostOutput } from "./lib/stdout-owner.js";
16
- import { managerChoiceFailure, rosterOf } from "./lib/manager-choice.js";
22
+ import { shellWord } from "./lib/endpoint-errors.js";
23
+ import { managerChoiceFailure, pickManager, rosterOf } from "./lib/manager-choice.js";
24
+ import { goneStackRefusal } from "./commands/stack-gone.js";
25
+ import { canPrompt } from "./commands/meshes-wizard.js";
17
26
  import { takeManagedHandoffCustody } from "./managed-handoff.js";
27
+ import { didYouMean, unknownCommandMessage, unknownSubcommandMessage } from "./lib/nearest-word.js";
28
+ import { UnusableFile } from "./lib/unusable-file.js";
18
29
  import { armTelemetry, recordTelemetryError, recordTelemetryFailure } from "./telemetry.js";
19
30
  /** Whether `args` ask for help: `--help` or `-h` before any `--`, after which every word is text. */
20
31
  function asksForHelp(args) {
@@ -32,10 +43,27 @@ function takeGlobalFlag(word) {
32
43
  return false;
33
44
  return true;
34
45
  }
35
- /** `words` without the global flags before any `--`, each applied. */
36
- function stripGlobalFlags(words) {
46
+ /** Node's unknown-option error, trimmed to its first sentence, with the nearest of `cmd`'s flags. */
47
+ function parseErrorMessage(cmd, e) {
48
+ const message = e.message.split(".")[0];
49
+ const option = e.code === "ERR_PARSE_ARGS_UNKNOWN_OPTION" ? /^Unknown option '(--[^']+)'/.exec(message)?.[1] : undefined;
50
+ const hint = option ? didYouMean(option, [...(cmd.flags ?? []).map((flag) => `--${flag.name}`), "--no-color", "--no-input", "--help"]) : "";
51
+ return hint ? `${message} - ${hint}` : message;
52
+ }
53
+ /** `words` without the global flags before any `--`, each applied. A global flag is given once, as
54
+ * any flag is: one already in `words` or in `leading`, those taken before the command word, is the
55
+ * usage error a repeated flag of `cmd` is. */
56
+ function stripGlobalFlags(words, leading = new Set(), cmd) {
37
57
  const end = words.indexOf("--");
38
- const head = (end === -1 ? words : words.slice(0, end)).filter((word) => !takeGlobalFlag(word));
58
+ const taken = new Set(leading);
59
+ const head = (end === -1 ? words : words.slice(0, end)).filter((word) => {
60
+ if (taken.has(word))
61
+ usageExit(`Option '${word}' cannot be repeated`, cmd, cmd !== undefined && asksForJson(cmd, words), words.includes("--plain"));
62
+ if (!takeGlobalFlag(word))
63
+ return true;
64
+ taken.add(word);
65
+ return false;
66
+ });
39
67
  return end === -1 ? head : [...head, ...words.slice(end)];
40
68
  }
41
69
  /** Whether `cmd` takes its words raw: it declares so, or it is an internal command, whose words are
@@ -45,8 +73,8 @@ function takesWordsRaw(cmd) {
45
73
  }
46
74
  /** The words `cmd` parses: the global flags are the kernel's, except for a command that takes its
47
75
  * words raw. */
48
- function ownWords(cmd, words) {
49
- return takesWordsRaw(cmd) ? [...words] : stripGlobalFlags(words);
76
+ function ownWords(cmd, words, leading) {
77
+ return takesWordsRaw(cmd) ? [...words] : stripGlobalFlags(words, leading, cmd);
50
78
  }
51
79
  /** Whether the invoked mode declares a structured output, so it reports every outcome by the 0 to 5
52
80
  * table: the subcommand `first` selects, else the command's bare form. */
@@ -66,7 +94,7 @@ function asksForJson(cmd, args) {
66
94
  }
67
95
  /** Under COTAL_DEBUG, print the failure's stack and the stack of each error that caused it. */
68
96
  function debugStacks(failure) {
69
- if (!process.env.COTAL_DEBUG)
97
+ if (!debugFlag("COTAL_DEBUG"))
70
98
  return;
71
99
  let error = failure;
72
100
  for (let depth = 0; error instanceof Error && depth < 8; error = error.cause, depth++)
@@ -76,40 +104,51 @@ function debugStacks(failure) {
76
104
  /** A classified failure: its line and remedy on stderr, its envelope on stdout when one was asked
77
105
  * for, and the exit code its outcome sets. The envelope is written synchronously, because stdout
78
106
  * to a pipe is asynchronous on some platforms and `exit` would cut it short. */
79
- function failureExit(cmd, failure, json, plain = false, warnings = operationWarnings()) {
107
+ function failureExit(cmd, failure, json, plain = false, scope) {
108
+ const warnings = scope ? scope.warnings ?? [] : operationWarnings();
80
109
  recordTelemetryFailure(failure.outcome, failure.code, failure);
81
110
  // A command's own usage refusal reads as the parser's: the error, its remedy, then the help. A
82
- // missing --yes or a missing scripted input is not a grammar mistake, and its remedy says the
83
- // whole fix.
84
- if (failure.code === "USAGE_INVALID" && !json) {
85
- stderrLine("✗ ", failure.message, c.red);
86
- if (failure.remedy)
87
- stderrLine(" ", failure.remedy, c.dim);
88
- if (!(failure instanceof ConfirmationRequired) && !(failure instanceof MissingFlags))
89
- printCommandHelp(cmd, undefined, (line) => console.error(line), terminalWidth(process.stderr));
111
+ // missing --yes, a missing scripted input or a removed working folder is not a grammar mistake,
112
+ // and its remedy says the whole fix. A file the command cannot use is reported like one that does
113
+ // not exist, and a refused flag value names its corrected value, so it gets the classified report.
114
+ if (failure.code === "USAGE_INVALID" && !json && !(failure instanceof UnusableFile) && !(failure instanceof FlagValueRefusal)) {
115
+ usageRefusal(failure, plain, failure.selfContained ? undefined : cmd);
90
116
  debugStacks(failure);
91
117
  process.exit(1);
92
118
  }
93
- writeSync(2, `${renderReport(commandFailureReport(failure), plain ? "plain" : "rich", terminalWidth(process.stderr))}
119
+ // Rendered in the run's scope, so the `Mesh:` heading keeps the note on how the run chose its space.
120
+ const report = () => renderReport(commandFailureReport(failure), plain ? "plain" : "rich", terminalWidth(process.stderr));
121
+ const writeReport = () => writeSync(2, `${scope ? runOperation(scope, report) : report()}
94
122
  `);
95
- // The refusal is on stderr and its exit status below stands whether or not the envelope lands.
96
- if (json)
123
+ // Under --json the envelope alone reports the failure. Its text report goes to stderr only when the
124
+ // envelope cannot be written, and the exit status below stands either way.
125
+ if (!json)
126
+ writeReport();
127
+ else
97
128
  try {
98
129
  writeSync(1, envelopeLine(failureEnvelope(cmd.name, failure, warnings)));
99
130
  }
100
131
  catch (error) {
101
132
  reportLostOutput(error);
133
+ try {
134
+ writeReport();
135
+ }
136
+ catch { /* stderr failed too; the exit status still says so */ }
102
137
  }
103
138
  debugStacks(failure);
104
139
  process.exit(exitCode(failure.outcome, failure.code));
105
140
  }
141
+ /** The refusal of a command that would read or write a config folder that is a file. */
142
+ function configFolderRefusal(problem) {
143
+ return new CommandFailure("refused", "SCHEMA_INVALID", `${problem.message}; Cotal keeps your preferences, config and extensions there, so the command did not run`, { remedy: problem.remedy });
144
+ }
106
145
  /**
107
146
  * `ext seed [--repair|--reset|--force]`, dispatched before the manifest overlay so repair survives a
108
147
  * corrupt manifest. Returns `true` iff `argv` was that command (or its help), so the caller returns.
109
148
  * The overlay cannot list the command yet, so the built-in `ext` is found through the registry,
110
149
  * which resolves its alias too.
111
150
  */
112
- async function extSeedGate(registry, argv) {
151
+ async function extSeedGate(registry, argv, configFolder, leading) {
113
152
  const [word, sub] = argv;
114
153
  const extCmd = word === undefined || !registry.has("command", word) ? undefined : registry.resolve("command", word);
115
154
  if (extCmd?.name !== "ext" || sub !== "seed")
@@ -120,7 +159,9 @@ async function extSeedGate(registry, argv) {
120
159
  printCommandHelp(extCmd);
121
160
  return true;
122
161
  }
123
- await extCmd.run(parseCommandArgs(extCmd, stripGlobalFlags(argv.slice(1))));
162
+ if (configFolder)
163
+ failureExit(extCmd, configFolderRefusal(configFolder), false);
164
+ await extCmd.run(parseCommandArgs(extCmd, stripGlobalFlags(argv.slice(1), leading, extCmd)));
124
165
  return true;
125
166
  }
126
167
  /**
@@ -199,6 +240,28 @@ function isArgError(e) {
199
240
  const code = e?.code;
200
241
  return typeof code === "string" && code.startsWith("ERR_PARSE_ARGS");
201
242
  }
243
+ /** The managed verbs whose unpinned manager selection is asked on a terminal: each is refused
244
+ * before any effect when several of your managers are live. */
245
+ const PICKS_MANAGER = new Set(["spawn", "ps", "stop", "attach", "input", "models", "persona", "status"]);
246
+ /** Whether `e` refused the unpinned manager selection of a command in {@link PICKS_MANAGER} and
247
+ * this terminal then picked a manager, which `parsed` now pins with `--on`. A script, `--json`,
248
+ * `--no-input` or `COTAL_NO_PROMPT=1` is not asked and keeps the refusal. A cancelled question exits 0, having
249
+ * done nothing. */
250
+ async function pinPickedManager(e, cmd, parsed, argv) {
251
+ if (!PICKS_MANAGER.has(cmd.name) || parsed.values.on !== undefined || !canPrompt())
252
+ return false;
253
+ const failure = isCommandFailure(e) ? e : isConnectRefusal(e) ? e.failure() : undefined;
254
+ if (!failure)
255
+ return false;
256
+ const target = { space: typeof parsed.values.space === "string" ? parsed.values.space : undefined, server: typeof parsed.values.server === "string" ? parsed.values.server : undefined };
257
+ const picked = await pickManager(failure, () => rosterOf(target), argv);
258
+ if (picked === null)
259
+ process.exit(0);
260
+ if (picked === undefined)
261
+ return false;
262
+ parsed.values.on = picked.instanceId;
263
+ return true;
264
+ }
202
265
  /** One dispatcher-owned catalog gate for every command that uses the shared mesh target grammar,
203
266
  * including commands self-registered by other packages. Registry-local `meshes add/rm` stay
204
267
  * offline. `use` takes its target positionally, and status keeps stale bytes diagnostic-only.
@@ -234,42 +297,121 @@ async function prepareCatalogForCommand(cmd, args) {
234
297
  await chooseMeshTarget(args);
235
298
  }
236
299
  }
237
- /** A usage error, rendered as one red line plus the command's help when there is one. Exit 1. */
238
- function usageExit(message, cmd, json = false) {
300
+ /** A usage refusal on stderr, then `cmd`'s help when one is given. Plain output and a locale without
301
+ * UTF-8 have no refusal mark, so there the refusal is the classified report, which names its outcome
302
+ * in words. Either way the words it quotes are escaped, as the report escapes every text. */
303
+ function usageRefusal(failure, plain, cmd) {
304
+ const report = plain || !localeIsUtf8();
305
+ if (report)
306
+ writeSync(2, `${renderReport(commandFailureReport(failure), plain ? "plain" : "rich", terminalWidth(process.stderr))}\n`);
307
+ else {
308
+ stderrLine("✗ ", oneLine(failure.message), c.red);
309
+ if (failure.remedy)
310
+ stderrLine(" ", oneLine(failure.remedy), c.dim);
311
+ }
312
+ if (!cmd)
313
+ return;
314
+ if (report)
315
+ console.error("");
316
+ printCommandHelp(cmd, undefined, (line) => console.error(line), terminalWidth(process.stderr));
317
+ }
318
+ /** A usage error, written by {@link usageRefusal} with the command's help when there is one, and
319
+ * with `remedy` under the message when the parser can name one. Exit 1. */
320
+ function usageExit(message, cmd, json = false, plain = false, remedy) {
239
321
  // A JSON caller gets the refusal as an envelope, so stdout stays one document and the help text
240
322
  // the remedy names stays out of it.
241
323
  if (cmd && json)
242
- failureExit(cmd, new CommandFailure("refused", "USAGE_INVALID", message, { remedy: `run \`cotal help ${cmd.name}\`` }), true);
324
+ failureExit(cmd, new CommandFailure("refused", "USAGE_INVALID", message, { remedy: remedy ?? `run \`cotal help ${cmd.name}\`` }), true);
243
325
  recordTelemetryFailure("refused", "USAGE_INVALID", message);
244
326
  // The help goes to stderr with the reason, so a refused run leaves stdout empty and a script that
245
327
  // sources or parses it gets nothing.
246
- stderrLine("✗ ", message, c.red);
247
- if (cmd)
248
- printCommandHelp(cmd, undefined, (line) => console.error(line), terminalWidth(process.stderr));
328
+ usageRefusal(new CommandFailure("refused", "USAGE_INVALID", message, remedy === undefined ? undefined : { remedy }), plain, cmd);
249
329
  process.exit(1);
250
330
  }
251
- /** `rest` parsed against `cmd`'s declared flags, positionals and subcommands, or a usage exit. Node's
252
- * parse error is trimmed to its first sentence: the verbose "To specify a positional argument
253
- * starting with a '-' …" tail is dropped. */
331
+ /** An option the parser would misread without an error: a short option written `-c=value`, which
332
+ * takes `=value` as its value, or a declared option typed with a typographic dash pasted from typeset
333
+ * text, which is read as a positional. */
334
+ function misspelledOption(cmd, rest) {
335
+ const names = new Set([...(cmd.flags ?? []).map((flag) => flag.name), ...GLOBAL_FLAGS]);
336
+ const shorts = new Set((cmd.flags ?? []).flatMap((flag) => (flag.short ? [flag.short] : [])));
337
+ for (const [index, word] of rest.entries()) {
338
+ if (word === "--")
339
+ return undefined;
340
+ const previous = rest[index - 1];
341
+ if (previous !== undefined && cmd.flags?.some((flag) => flag.type === "string" && (previous === `--${flag.name}` || previous === `-${flag.short}`)))
342
+ continue;
343
+ const short = /^-([^-=])=(.*)$/su.exec(word);
344
+ const flag = short && cmd.flags?.find((item) => item.short === short[1] && item.type === "string");
345
+ if (short && flag)
346
+ return { message: `${word} gives -${short[1]} the value "=${short[2]}"`, remedy: `write -${short[1]} ${short[2]} or --${flag.name}=${short[2]}` };
347
+ const typed = /^[\u2010-\u2015\u2212][-\u2010-\u2015\u2212]*([^=]+)/u.exec(word);
348
+ if (typed && (names.has(typed[1]) || shorts.has(typed[1])))
349
+ return { message: `${word} starts with a typographic dash, so it is not an option`, remedy: `type the option with hyphens: ${names.has(typed[1]) ? "--" : "-"}${typed[1]}` };
350
+ }
351
+ return undefined;
352
+ }
353
+ /** A parse error as a refusal. Node's message is trimmed to its first sentence, and the hint its tail
354
+ * carries is given as the remedy in this CLI's words: a word that starts with `-` goes after `--`,
355
+ * an option value that starts with `-` is written `--name=value`, and an option given with no value,
356
+ * last or before another of the command's options, is named with its placeholder. */
357
+ function parseRefusal(error, cmd, rest) {
358
+ const message = parseErrorMessage(cmd, error);
359
+ if (error.code === "ERR_PARSE_ARGS_UNKNOWN_OPTION" && cmd.positionals !== undefined)
360
+ return { message, remedy: "to pass a word that starts with \"-\", put -- before it" };
361
+ const missingValue = (flag) => ({ message: `--${flag.name} needs a value`, remedy: `write --${flag.name} ${flag.value ?? "<value>"}` });
362
+ const bare = /^Option '(?:-[^,']+, )?--([^ ']+) <value>' argument missing/.exec(error.message)?.[1];
363
+ const last = bare === undefined ? undefined : cmd.flags?.find((item) => item.name === bare);
364
+ if (error.code === "ERR_PARSE_ARGS_INVALID_OPTION_VALUE" && last)
365
+ return missingValue(last);
366
+ const long = /use '--([^=']+)=-XYZ'/.exec(error.message)?.[1];
367
+ const flag = long === undefined ? undefined : cmd.flags?.find((item) => item.name === long);
368
+ if (error.code === "ERR_PARSE_ARGS_INVALID_OPTION_VALUE" && flag) {
369
+ const at = rest.findIndex((word) => word === `--${flag.name}` || (flag.short !== undefined && word === `-${flag.short}`));
370
+ const value = at < 0 ? undefined : rest[at + 1];
371
+ if (value !== undefined && cmd.flags?.some((item) => value === `--${item.name}` || value.startsWith(`--${item.name}=`) || (item.short !== undefined && value === `-${item.short}`)))
372
+ return missingValue(flag);
373
+ if (value?.startsWith("-"))
374
+ return { message: `the value of --${flag.name} starts with "-", so it reads as an option`, remedy: `write it as --${flag.name}=${value}` };
375
+ }
376
+ return { message };
377
+ }
378
+ /** `rest` parsed against `cmd`'s declared flags, positionals and subcommands, or a usage exit. */
254
379
  function parseOrExit(cmd, rest) {
255
380
  const json = asksForJson(cmd, rest);
381
+ const plain = rest.includes("--plain");
382
+ const misspelled = cmd.rawArgs ? undefined : misspelledOption(cmd, rest);
383
+ if (misspelled)
384
+ usageExit(misspelled.message, cmd, json, plain, misspelled.remedy);
256
385
  let parsed;
257
386
  try {
258
387
  parsed = parseCommandArgs(cmd, rest);
259
388
  }
260
389
  catch (e) {
261
- if (isArgError(e))
262
- usageExit(e.message.split(".")[0], cmd, json);
390
+ if (isArgError(e)) {
391
+ const refusal = parseRefusal(e, cmd, rest);
392
+ usageExit(refusal.message, cmd, json, plain, refusal.remedy);
393
+ }
263
394
  throw e;
264
395
  }
265
396
  const first = parsed.positionals[0];
266
397
  // History also accepts a root channel positional; only its reserved clear token is a mode.
267
398
  if (cmd.subcommands?.length && first !== undefined && cmd.name !== "history" && !findSubcommand(cmd, first))
268
- usageExit(`cotal ${cmd.name} has no subcommand "${first}" - run \`cotal help ${cmd.name}\``, cmd, json);
399
+ usageExit(unknownSubcommandMessage(cmd.name, cmd, first), cmd, json, plain);
400
+ // Target resolution reads an empty space as no space and falls back to the selected one, so a script
401
+ // whose variable is unset would act on whichever space is selected.
402
+ const spaceFlag = cmd.flags?.find((flag) => flag.name === "space");
403
+ if (spaceFlag && typeof parsed.values.space === "string" && !parsed.values.space.trim())
404
+ failureExit(cmd, new CommandFailure("refused", "USAGE_INVALID", `--space${spaceFlag.short ? `/-${spaceFlag.short}` : ""} is empty; name one space`, { remedy: "name the space; `cotal space` lists the spaces this machine knows" }), json, parsed.values.plain === true);
405
+ // An empty --store-dir reads as no value and opens the default store, and a ~ no shell expanded
406
+ // names a folder called ~ in the working folder.
407
+ const storeDir = parsed.values["store-dir"];
408
+ if (typeof storeDir === "string" && (!storeDir.trim() || storeDir.startsWith("~")))
409
+ failureExit(cmd, storeDirRefusal(storeDir), json, parsed.values.plain === true);
269
410
  // `--json` implies `--no-input`: a script reading one document cannot answer a prompt.
270
411
  if (structured(cmd, first) && parsed.values.json === true)
271
412
  disableInput();
272
413
  const canonical = canonicalSubcommand(cmd, parsed);
414
+ refuseRemovedFolder(cmd, canonical);
273
415
  try {
274
416
  cmd.validate?.(canonical);
275
417
  }
@@ -277,11 +419,33 @@ function parseOrExit(cmd, rest) {
277
419
  if (isCommandFailure(error))
278
420
  failureExit(cmd, error, json, canonical.values.plain === true);
279
421
  if (isArgError(error))
280
- usageExit(error.message.split(".")[0], cmd, json);
422
+ usageExit(error.message.split(".")[0], cmd, json, plain);
281
423
  throw error;
282
424
  }
425
+ // The NATS client keeps only the host and port of a broker URL, so a user and password in it were
426
+ // dropped in silence and the command connected with whatever credential it resolved instead. A
427
+ // command whose own check names this, such as `up`'s, has refused above. The value is never repeated.
428
+ if (cmd.flags?.some((flag) => flag.name === "server") && typeof canonical.values.server === "string" && brokerUrlHasUserinfo(canonical.values.server))
429
+ failureExit(cmd, brokerUrlCredentialRefusal("--server"), json, canonical.values.plain === true);
283
430
  return canonical;
284
431
  }
432
+ /** The refusal of a `--store-dir` that is empty, or that starts with a `~` no shell expanded. */
433
+ function storeDirRefusal(value) {
434
+ if (!value.trim())
435
+ return new CommandFailure("refused", "USAGE_INVALID", "--store-dir is empty; the command did not run", { remedy: "name the store directory, or omit --store-dir to use the default store", selfContained: true });
436
+ const home = value === "~" || value.startsWith("~/") ? join(homedir(), value.slice(2)) : undefined;
437
+ return new CommandFailure("refused", "USAGE_INVALID", `--store-dir ${JSON.stringify(value)} starts with ~, which no shell expanded, so it names a folder called ${value.split("/")[0]} in ${process.cwd()}; the command did not run`, { target: { storeDir: value }, remedy: home ? `name the absolute path: --store-dir ${shellWord(home)}` : "name the store directory by its absolute path", selfContained: true });
438
+ }
439
+ /** The commands that never read the working folder, so they run from one that was removed. */
440
+ const FOLDERLESS = new Set(["help", "version", "completion", "docs", "telemetry"]);
441
+ /** A working folder removed before this process read it fails every cwd read the command makes, and
442
+ * Node caches the first read that succeeds. One read refuses that case before the command's own
443
+ * checks, such as `up`'s, or any effect, unless the command never reads the folder. */
444
+ function refuseRemovedFolder(cmd, parsed) {
445
+ if (cmd.name.startsWith("__") || FOLDERLESS.has(cmd.name) || !workingFolderRemoved())
446
+ return;
447
+ failureExit(cmd, new CommandFailure("refused", "USAGE_INVALID", "this folder no longer exists", { remedy: "cd to an existing folder and run the command again", selfContained: true }), structured(cmd, parsed.positionals[0]) && parsed.values.json === true, parsed.values.plain === true);
448
+ }
285
449
  /** The parsed args with a subcommand alias in the first positional replaced by its name, so `run`
286
450
  * only ever sees canonical subcommands. */
287
451
  function canonicalSubcommand(cmd, parsed) {
@@ -308,6 +472,10 @@ function printHelpFor(cmd, rest) {
308
472
  const path = [];
309
473
  for (const word of words) {
310
474
  const sub = findSubcommand(surface, word);
475
+ // A word where a subcommand belongs that names none refuses as `cotal help` does, so a mistyped
476
+ // subcommand never gets its group's help. History's own first word may be a channel.
477
+ if (!sub && surface.subcommands?.length && !(surface === cmd && cmd.name === "history"))
478
+ return printHelpPath(cmd, [...path, word]);
311
479
  if (!sub || sub.hidden)
312
480
  break;
313
481
  path.push(sub.name);
@@ -335,12 +503,17 @@ export async function runCli(registry, argv, opts = {}) {
335
503
  // the leading flags. A command that takes its words raw has no flags to read them as, so it
336
504
  // refuses them there. The built-in surface decides that before any extension overlay is read.
337
505
  const output = [];
506
+ const leadingGlobals = new Set();
338
507
  let lead = 0;
339
508
  for (; lead < argv.length; lead++) {
340
509
  const word = argv[lead];
341
510
  if (word === "--json" || word === "-j" || word === "--plain")
342
511
  output.push(word);
343
- else if (!takeGlobalFlag(word))
512
+ else if (leadingGlobals.has(word))
513
+ usageExit(`Option '${word}' cannot be repeated`);
514
+ else if (takeGlobalFlag(word))
515
+ leadingGlobals.add(word);
516
+ else
344
517
  break;
345
518
  }
346
519
  if (argv[lead] === "--")
@@ -367,9 +540,9 @@ export async function runCli(registry, argv, opts = {}) {
367
540
  }
368
541
  return;
369
542
  }
370
- // Before any ordinary dispatch outcome can exit, take the spawn handoff and ensure no child
371
- // inherits its variable. The unit entry refuses such a handoff without consuming its file.
372
- takeManagedHandoffCustody(process.env);
543
+ // Before any ordinary dispatch outcome can exit, a spawn takes its handoff, and no command lets a
544
+ // child inherit the variable. The unit entry refuses such a handoff without consuming its file.
545
+ takeManagedHandoffCustody(process.env, findCommand(registry.all("command"), argv[0])?.name === "spawn");
373
546
  setInstalledExtensionsEnabled(Boolean(opts.extensions));
374
547
  // The global spellings of help and version are the `help` and `version` commands.
375
548
  if (argv[0] === "-v")
@@ -378,9 +551,10 @@ export async function runCli(registry, argv, opts = {}) {
378
551
  argv = ["version", ...argv.slice(1)];
379
552
  else if (argv[0] === "--help" || argv[0] === "-h")
380
553
  argv = ["help", ...argv.slice(1)];
554
+ const configFolder = globalConfigDirProblem();
381
555
  if (opts.extensions) {
382
556
  try {
383
- if (await extSeedGate(registry, argv))
557
+ if (await extSeedGate(registry, argv, configFolder, leadingGlobals))
384
558
  return;
385
559
  }
386
560
  catch (e) {
@@ -417,7 +591,7 @@ export async function runCli(registry, argv, opts = {}) {
417
591
  if (word === undefined)
418
592
  return printEntry(commands);
419
593
  let cmd = findCommand(commands, word);
420
- let rest = ownWords(cmd, words);
594
+ let rest = ownWords(cmd, words, leadingGlobals);
421
595
  const wantsHelp = asksForHelp(rest);
422
596
  if (cmd?.name === "service") {
423
597
  try {
@@ -448,7 +622,7 @@ export async function runCli(registry, argv, opts = {}) {
448
622
  // unknown word is a usage error.
449
623
  const awaitingSeed = !cmd && opts.extensions === true && isSeededCommand(word) && !wantsHelp && !skipsSeed(word, rest[0], rest);
450
624
  if (!cmd && !awaitingSeed)
451
- usageExit(`unknown command: ${word} - run \`cotal help\` to list commands`);
625
+ usageExit(unknownCommandMessage(commands, word));
452
626
  // `cotal <cmd> --help` / `-h` → that command's help, never run it. This intercept also covers
453
627
  // rawArgs commands and extension STUBS (cached specs are exactly the display surface) — only
454
628
  // `__`-internal ones are exempt, because __complete's argv is ANOTHER command's half-typed
@@ -457,6 +631,11 @@ export async function runCli(registry, argv, opts = {}) {
457
631
  return printHelpFor(cmd, rest);
458
632
  let parsed = cmd && !isExtensionStub(cmd) ? parseOrExit(cmd, rest) : undefined;
459
633
  // ---- Effects: only a validated invocation reaches this line. ----
634
+ // A config folder that is a file fails every read and write of the preferences, the config file and
635
+ // the extensions, so a command that could use them stops here, before the seed would write there.
636
+ // Help, shell completion, version and docs use none of them.
637
+ if (configFolder && cmd && parsed && !cmd.name.startsWith("__") && !["help", "completion", "version", "docs"].includes(cmd.name))
638
+ failureExit(cmd, configFolderRefusal(configFolder), structured(cmd, parsed.positionals[0]) && parsed.values.json === true, parsed.values.plain === true);
460
639
  // The seed can install or upgrade an extension package, so the surface is read again after it and
461
640
  // an extension stub resolves against the manifest the seed left.
462
641
  const controlOnlyManager = parsed?.values.execution === "none" && (cmd?.name === "supervise" || cmd?.name === "__daemon-manager");
@@ -471,8 +650,8 @@ export async function runCli(registry, argv, opts = {}) {
471
650
  commands = surface();
472
651
  cmd = findCommand(commands, word);
473
652
  if (!cmd)
474
- usageExit(`unknown command: ${word} - run \`cotal help\` to list commands`);
475
- rest = ownWords(cmd, words);
653
+ usageExit(unknownCommandMessage(commands, word));
654
+ rest = ownWords(cmd, words, leadingGlobals);
476
655
  arm();
477
656
  }
478
657
  // An extension stub materializes before parsing: verify the version pin, import the package
@@ -489,73 +668,107 @@ export async function runCli(registry, argv, opts = {}) {
489
668
  }
490
669
  if (!cmd || !parsed)
491
670
  throw new Error("internal error: dispatch reached its effects without a parsed command");
492
- // A working folder removed before this process read it fails every cwd read the command makes, and
493
- // Node caches the first read that succeeds. One read here refuses that case before any effect.
494
- // Help, version and completion never read the folder.
495
- if (!cmd.name.startsWith("__") && !["help", "version", "completion"].includes(cmd.name)) {
496
- try {
497
- process.cwd();
498
- }
499
- catch (e) {
500
- if (e.code !== "ENOENT")
501
- throw e;
502
- failureExit(cmd, new CommandFailure("refused", "USAGE_INVALID", "this folder no longer exists", { remedy: "cd to an existing folder and run the command again" }), structured(cmd, parsed.positionals[0]) && parsed.values.json === true, parsed.values.plain === true);
503
- }
504
- }
505
- // A preferences file that does not validate stops every command except help and shell completion,
506
- // as a broken config file does, so nothing runs on a default the person did not mean. `--help` on a
507
- // command has already returned above.
671
+ // A preferences file that does not validate stops every command that could act on a default, as a
672
+ // broken config file does, so nothing runs on a default the person did not mean. Help, shell
673
+ // completion, version and docs use no preference, and status reports the file as a warning, so they
674
+ // still run. `--help` on a command has already returned above.
508
675
  if (!cmd.name.startsWith("__") && cmd.name !== "help" && cmd.name !== "completion") {
509
- try {
510
- cachedPreferences();
511
- }
512
- catch (e) {
513
- if (!isCommandFailure(e))
514
- throw e;
515
- failureExit(cmd, e, structured(cmd, parsed.positionals[0]) && parsed.values.json === true, parsed.values.plain === true);
676
+ // A relative COTAL_HOME would name another home in each folder a command runs in, and a
677
+ // COTAL_HOME that cannot be a directory can hold no record: both stop them before any command
678
+ // reads it.
679
+ const home = process.env.COTAL_HOME;
680
+ if (home && !isAbsolute(home))
681
+ failureExit(cmd, new CommandFailure("refused", "USAGE_INVALID", `COTAL_HOME ${JSON.stringify(home)} is a relative path, so each folder a command runs in would have its own Cotal home; the command did not run`, { remedy: `set COTAL_HOME to an absolute path, or unset it to use ${userCotalDir()}` }), structured(cmd, parsed.positionals[0]) && parsed.values.json === true, parsed.values.plain === true);
682
+ const homeProblem = cotalHomeProblem();
683
+ if (homeProblem)
684
+ failureExit(cmd, new CommandFailure("refused", "SCHEMA_INVALID", `${homeProblem}; the command did not run`, { remedy: `point COTAL_HOME at a directory, or unset it to use ${userCotalDir()}` }), structured(cmd, parsed.positionals[0]) && parsed.values.json === true, parsed.values.plain === true);
685
+ // A `.cotal` that is a file in the folder the command uses, such as someone's notes, holds no
686
+ // records, and every reader would otherwise report a different wrong cause.
687
+ const dirProblem = cmd.name === "version" || workingFolderRemoved() ? undefined : cotalDirProblem(typeof parsed.values.root === "string" ? resolve(parsed.values.root) : findCotalRoot());
688
+ if (dirProblem)
689
+ failureExit(cmd, new CommandFailure("refused", "CONFLICT", `${dirProblem}; the command did not run`, { remedy: "rename or move that file, then run the command again" }), structured(cmd, parsed.positionals[0]) && parsed.values.json === true, parsed.values.plain === true);
690
+ if (!["version", "docs", "status"].includes(cmd.name)) {
691
+ try {
692
+ cachedPreferences();
693
+ }
694
+ catch (e) {
695
+ if (!isCommandFailure(e))
696
+ throw e;
697
+ failureExit(cmd, e, structured(cmd, parsed.positionals[0]) && parsed.values.json === true, parsed.values.plain === true);
698
+ }
516
699
  }
517
700
  }
518
- // A failure raised after the command recorded the space it resolved is reported in that space.
519
- const scope = {};
520
- try {
701
+ // A failure raised after the command recorded the space it resolved is reported in that space. A
702
+ // completion writes its warnings, as its errors, only under COTAL_COMPLETE_DEBUG.
703
+ const scope = cmd.name === "__complete" && !debugFlag("COTAL_COMPLETE_DEBUG") ? { quiet: true } : {};
704
+ const execute = async () => {
521
705
  if (opts.extensions && cmd.requiredExtensions) {
522
706
  for (const ref of cmd.requiredExtensions(parsed))
523
707
  await materializeExtension(ref);
524
708
  }
525
709
  await prepareCatalogForCommand(cmd, parsed);
526
710
  await runOperation(scope, async () => {
711
+ // Preferences that another local account could change still apply, so each command that uses
712
+ // them says so, with the change that protects their folder.
713
+ if (!cmd.name.startsWith("__") && !["help", "completion", "version", "docs"].includes(cmd.name)) {
714
+ const folder = preferencesFolderWarning();
715
+ if (folder)
716
+ recordOperationWarning(folder.warning);
717
+ }
527
718
  if (cmd.prepare)
528
719
  await cmd.prepare(parsed);
529
720
  await cmd.run(parsed);
530
721
  });
722
+ };
723
+ if (opts.startupNotice && cmd.keepsStartupNotice)
724
+ keepStartupNotice(opts.startupNotice);
725
+ else
726
+ await opts.startupNotice?.release();
727
+ try {
728
+ await execute();
531
729
  }
532
730
  catch (e) {
731
+ // On a terminal, a refused unpinned manager selection among several live managers is asked
732
+ // once, and the command runs again on the manager picked, as the refusal's Next would rerun it.
733
+ if (await pinPickedManager(e, cmd, parsed, argv)) {
734
+ try {
735
+ await execute();
736
+ return;
737
+ }
738
+ catch (again) {
739
+ e = again;
740
+ }
741
+ }
533
742
  recordTelemetryError(e);
534
743
  const mode = parsed.positionals[0];
535
744
  const json = structured(cmd, mode) && parsed.values.json === true;
536
745
  // A usage error a command raises from its own checks prints the command's help, not a stack trace.
537
746
  if (isArgError(e))
538
- usageExit(e.message.split(".")[0], cmd, json);
747
+ usageExit(e.message.split(".")[0], cmd, json, parsed.values.plain === true);
539
748
  // A refused manager selection among several live managers becomes the choice: each manager
540
- // and the command again with `--on` for it.
749
+ // and the command again with `--on` for it. A space whose stack folder is gone names its stop.
541
750
  const target = { space: typeof parsed.values.space === "string" ? parsed.values.space : undefined, server: typeof parsed.values.server === "string" ? parsed.values.server : undefined };
542
- const choice = async (failure) => (await managerChoiceFailure(failure, () => rosterOf(target), argv)) ?? failure;
751
+ const choice = async (failure) => (await managerChoiceFailure(failure, () => rosterOf(target), argv)) ?? goneStackRefusal(failure);
543
752
  if (isCommandFailure(e))
544
- failureExit(cmd, inOperationSpace(await choice(e), scope.space), json, parsed.values.plain === true, scope.warnings);
753
+ failureExit(cmd, inOperationSpace(await choice(e), scope.space), json, parsed.values.plain === true, scope);
545
754
  // A command that declares a structured output reports by the outcome table. A target it could
546
755
  // not resolve or connect to is refused before any request, under the refusal's own code; a
547
756
  // failure it did not classify is unknown: it may have had effects that cannot be attributed.
548
757
  if (structured(cmd, mode)) {
549
758
  if (isConnectRefusal(e))
550
- failureExit(cmd, inOperationSpace(await choice(e.failure()), scope.space), json, parsed.values.plain === true, scope.warnings);
759
+ failureExit(cmd, inOperationSpace(await choice(e.failure()), scope.space), json, parsed.values.plain === true, scope);
551
760
  if (isWorkspaceTargetError(e)) {
552
761
  const { message, remedy } = workspaceErrorParts({ kind: "target", error: e });
553
762
  const target = spaceRootTarget(e.details);
554
- failureExit(cmd, inOperationSpace(new CommandFailure("refused", targetErrorCode(e.code), message, { ...(remedy ? { remedy } : {}), ...(target ? { target } : {}) }), scope.space), json, parsed.values.plain === true, scope.warnings);
763
+ failureExit(cmd, inOperationSpace(new CommandFailure("refused", targetErrorCode(e.code), message, { ...(remedy ? { remedy } : {}), ...(target ? { target } : {}) }), scope.space), json, parsed.values.plain === true, scope);
555
764
  }
765
+ // A registry record or directory it could not read is refused by its file, as `space` reports
766
+ // it, and as a target it could not resolve is refused above.
767
+ if (isMeshRegistryError(e))
768
+ failureExit(cmd, inOperationSpace(registryFailure(e), scope.space), json, parsed.values.plain === true, scope);
556
769
  if (e instanceof CatalogPreparationError)
557
- failureExit(cmd, new CommandFailure("refused", e.code, e.message), json, parsed.values.plain === true, scope.warnings);
558
- failureExit(cmd, inOperationSpace(new CommandFailure("unknown", "OPERATION_UNKNOWN", e instanceof Error ? e.message : String(e), { cause: e }), scope.space), json, parsed.values.plain === true, scope.warnings);
770
+ failureExit(cmd, new CommandFailure("refused", e.code, e.message), json, parsed.values.plain === true, scope);
771
+ failureExit(cmd, inOperationSpace(new CommandFailure("unknown", "OPERATION_UNKNOWN", e instanceof Error ? e.message : String(e), { cause: e }), scope.space), json, parsed.values.plain === true, scope);
559
772
  }
560
773
  // A workspace TARGET error carries structured recovery — which entry, whether it was removed,
561
774
  // what to run next — and has its own renderer. Its raw `.message` is deliberately dev-safe
@@ -565,7 +778,7 @@ export async function runCli(registry, argv, opts = {}) {
565
778
  // `…OrExit` helper.
566
779
  if (isWorkspaceTargetError(e)) {
567
780
  console.error(c.red(renderWorkspaceError({ kind: "target", error: e })));
568
- if (process.env.COTAL_DEBUG && e instanceof Error && e.stack)
781
+ if (debugFlag("COTAL_DEBUG") && e instanceof Error && e.stack)
569
782
  console.error(c.dim(e.stack));
570
783
  process.exit(1);
571
784
  }
@@ -586,7 +799,7 @@ export async function runCli(registry, argv, opts = {}) {
586
799
  const hint = staleStoreHint(msg);
587
800
  if (hint)
588
801
  stderrLine(" ↳ ", hint, c.dim);
589
- if (process.env.COTAL_DEBUG && e instanceof Error && e.stack)
802
+ if (debugFlag("COTAL_DEBUG") && e instanceof Error && e.stack)
590
803
  console.error(c.dim(e.stack));
591
804
  process.exit(1);
592
805
  }