@cotal-ai/cli 0.100.2 → 0.101.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (626) hide show
  1. package/dist/chat/chat-view.d.ts.map +1 -1
  2. package/dist/chat/chat-view.js +5 -1
  3. package/dist/chat/chat-view.js.map +1 -1
  4. package/dist/chat/engine.d.ts +2 -1
  5. package/dist/chat/engine.d.ts.map +1 -1
  6. package/dist/chat/engine.js +2 -1
  7. package/dist/chat/engine.js.map +1 -1
  8. package/dist/chat/frontend.d.ts.map +1 -1
  9. package/dist/chat/frontend.js +13 -7
  10. package/dist/chat/frontend.js.map +1 -1
  11. package/dist/chat/native-session.d.ts +22 -3
  12. package/dist/chat/native-session.d.ts.map +1 -1
  13. package/dist/chat/native-session.js +91 -19
  14. package/dist/chat/native-session.js.map +1 -1
  15. package/dist/chat/open-session.d.ts +1 -0
  16. package/dist/chat/open-session.d.ts.map +1 -1
  17. package/dist/chat/open-session.js +1 -1
  18. package/dist/chat/open-session.js.map +1 -1
  19. package/dist/chat/picker.d.ts +5 -0
  20. package/dist/chat/picker.d.ts.map +1 -1
  21. package/dist/chat/picker.js +23 -10
  22. package/dist/chat/picker.js.map +1 -1
  23. package/dist/chat/plain.d.ts.map +1 -1
  24. package/dist/chat/plain.js +36 -10
  25. package/dist/chat/plain.js.map +1 -1
  26. package/dist/chat/session.d.ts +5 -0
  27. package/dist/chat/session.d.ts.map +1 -1
  28. package/dist/chat/static-session.d.ts +1 -0
  29. package/dist/chat/static-session.d.ts.map +1 -1
  30. package/dist/chat/static-session.js +24 -8
  31. package/dist/chat/static-session.js.map +1 -1
  32. package/dist/chat/stdio-io.d.ts +2 -0
  33. package/dist/chat/stdio-io.d.ts.map +1 -1
  34. package/dist/chat/stdio-io.js +6 -6
  35. package/dist/chat/stdio-io.js.map +1 -1
  36. package/dist/chat/stdio.d.ts +3 -2
  37. package/dist/chat/stdio.d.ts.map +1 -1
  38. package/dist/chat/stdio.js +26 -25
  39. package/dist/chat/stdio.js.map +1 -1
  40. package/dist/chat/user-session.d.ts +1 -0
  41. package/dist/chat/user-session.d.ts.map +1 -1
  42. package/dist/chat/user-session.js +1 -1
  43. package/dist/chat/user-session.js.map +1 -1
  44. package/dist/chat/view.d.ts +5 -4
  45. package/dist/chat/view.d.ts.map +1 -1
  46. package/dist/chat/view.js +10 -8
  47. package/dist/chat/view.js.map +1 -1
  48. package/dist/command.d.ts +5 -0
  49. package/dist/command.d.ts.map +1 -1
  50. package/dist/command.js +295 -82
  51. package/dist/command.js.map +1 -1
  52. package/dist/commands/agents.d.ts +29 -5
  53. package/dist/commands/agents.d.ts.map +1 -1
  54. package/dist/commands/agents.js +100 -35
  55. package/dist/commands/agents.js.map +1 -1
  56. package/dist/commands/backup-maintenance.d.ts.map +1 -1
  57. package/dist/commands/backup-maintenance.js +54 -21
  58. package/dist/commands/backup-maintenance.js.map +1 -1
  59. package/dist/commands/backup-read.d.ts.map +1 -1
  60. package/dist/commands/backup-read.js +12 -15
  61. package/dist/commands/backup-read.js.map +1 -1
  62. package/dist/commands/backup-restore.d.ts.map +1 -1
  63. package/dist/commands/backup-restore.js +20 -4
  64. package/dist/commands/backup-restore.js.map +1 -1
  65. package/dist/commands/backup.d.ts.map +1 -1
  66. package/dist/commands/backup.js +156 -28
  67. package/dist/commands/backup.js.map +1 -1
  68. package/dist/commands/channel-members.d.ts +1 -1
  69. package/dist/commands/channel-members.d.ts.map +1 -1
  70. package/dist/commands/channel-members.js +115 -29
  71. package/dist/commands/channel-members.js.map +1 -1
  72. package/dist/commands/channels.d.ts +11 -1
  73. package/dist/commands/channels.d.ts.map +1 -1
  74. package/dist/commands/channels.js +109 -20
  75. package/dist/commands/channels.js.map +1 -1
  76. package/dist/commands/chat.d.ts +11 -3
  77. package/dist/commands/chat.d.ts.map +1 -1
  78. package/dist/commands/chat.js +50 -22
  79. package/dist/commands/chat.js.map +1 -1
  80. package/dist/commands/clean.d.ts +10 -5
  81. package/dist/commands/clean.d.ts.map +1 -1
  82. package/dist/commands/clean.js +245 -42
  83. package/dist/commands/clean.js.map +1 -1
  84. package/dist/commands/completion.d.ts +15 -2
  85. package/dist/commands/completion.d.ts.map +1 -1
  86. package/dist/commands/completion.js +91 -26
  87. package/dist/commands/completion.js.map +1 -1
  88. package/dist/commands/config.d.ts +24 -1
  89. package/dist/commands/config.d.ts.map +1 -1
  90. package/dist/commands/config.js +65 -13
  91. package/dist/commands/config.js.map +1 -1
  92. package/dist/commands/console.d.ts.map +1 -1
  93. package/dist/commands/console.js +5 -4
  94. package/dist/commands/console.js.map +1 -1
  95. package/dist/commands/describe.d.ts +4 -2
  96. package/dist/commands/describe.d.ts.map +1 -1
  97. package/dist/commands/describe.js +4 -4
  98. package/dist/commands/describe.js.map +1 -1
  99. package/dist/commands/doctor.d.ts +1 -1
  100. package/dist/commands/doctor.d.ts.map +1 -1
  101. package/dist/commands/doctor.js +261 -34
  102. package/dist/commands/doctor.js.map +1 -1
  103. package/dist/commands/down-manifest.d.ts.map +1 -1
  104. package/dist/commands/down-manifest.js +9 -6
  105. package/dist/commands/down-manifest.js.map +1 -1
  106. package/dist/commands/down-services.d.ts +17 -16
  107. package/dist/commands/down-services.d.ts.map +1 -1
  108. package/dist/commands/down-services.js +29 -53
  109. package/dist/commands/down-services.js.map +1 -1
  110. package/dist/commands/down.d.ts +2 -2
  111. package/dist/commands/down.d.ts.map +1 -1
  112. package/dist/commands/down.js +96 -67
  113. package/dist/commands/down.js.map +1 -1
  114. package/dist/commands/endpoint-deregister.d.ts.map +1 -1
  115. package/dist/commands/endpoint-deregister.js +2 -2
  116. package/dist/commands/endpoint-deregister.js.map +1 -1
  117. package/dist/commands/endpoint.d.ts +2 -1
  118. package/dist/commands/endpoint.d.ts.map +1 -1
  119. package/dist/commands/endpoint.js +2 -2
  120. package/dist/commands/endpoint.js.map +1 -1
  121. package/dist/commands/endpoints.d.ts +1 -0
  122. package/dist/commands/endpoints.d.ts.map +1 -1
  123. package/dist/commands/endpoints.js +20 -5
  124. package/dist/commands/endpoints.js.map +1 -1
  125. package/dist/commands/feedback.d.ts.map +1 -1
  126. package/dist/commands/feedback.js +40 -2
  127. package/dist/commands/feedback.js.map +1 -1
  128. package/dist/commands/help.d.ts.map +1 -1
  129. package/dist/commands/help.js +2 -1
  130. package/dist/commands/help.js.map +1 -1
  131. package/dist/commands/history-clear.d.ts.map +1 -1
  132. package/dist/commands/history-clear.js +67 -51
  133. package/dist/commands/history-clear.js.map +1 -1
  134. package/dist/commands/history.d.ts +17 -2
  135. package/dist/commands/history.d.ts.map +1 -1
  136. package/dist/commands/history.js +221 -34
  137. package/dist/commands/history.js.map +1 -1
  138. package/dist/commands/join.d.ts +2 -0
  139. package/dist/commands/join.d.ts.map +1 -1
  140. package/dist/commands/join.js +132 -80
  141. package/dist/commands/join.js.map +1 -1
  142. package/dist/commands/meshes-add.d.ts +19 -4
  143. package/dist/commands/meshes-add.d.ts.map +1 -1
  144. package/dist/commands/meshes-add.js +114 -15
  145. package/dist/commands/meshes-add.js.map +1 -1
  146. package/dist/commands/meshes-wizard.d.ts +1 -0
  147. package/dist/commands/meshes-wizard.d.ts.map +1 -1
  148. package/dist/commands/meshes-wizard.js +45 -13
  149. package/dist/commands/meshes-wizard.js.map +1 -1
  150. package/dist/commands/meshes.d.ts +1 -1
  151. package/dist/commands/meshes.d.ts.map +1 -1
  152. package/dist/commands/meshes.js +76 -47
  153. package/dist/commands/meshes.js.map +1 -1
  154. package/dist/commands/mint.d.ts.map +1 -1
  155. package/dist/commands/mint.js +212 -19
  156. package/dist/commands/mint.js.map +1 -1
  157. package/dist/commands/models.d.ts +5 -1
  158. package/dist/commands/models.d.ts.map +1 -1
  159. package/dist/commands/models.js +21 -13
  160. package/dist/commands/models.js.map +1 -1
  161. package/dist/commands/persona-remote.d.ts.map +1 -1
  162. package/dist/commands/persona-remote.js +24 -13
  163. package/dist/commands/persona-remote.js.map +1 -1
  164. package/dist/commands/persona.d.ts +1 -1
  165. package/dist/commands/persona.d.ts.map +1 -1
  166. package/dist/commands/persona.js +92 -23
  167. package/dist/commands/persona.js.map +1 -1
  168. package/dist/commands/personas.d.ts.map +1 -1
  169. package/dist/commands/personas.js +59 -40
  170. package/dist/commands/personas.js.map +1 -1
  171. package/dist/commands/reset-space-apply.d.ts.map +1 -1
  172. package/dist/commands/reset-space-apply.js +69 -17
  173. package/dist/commands/reset-space-apply.js.map +1 -1
  174. package/dist/commands/reset-store-apply.d.ts +16 -0
  175. package/dist/commands/reset-store-apply.d.ts.map +1 -1
  176. package/dist/commands/reset-store-apply.js +122 -23
  177. package/dist/commands/reset-store-apply.js.map +1 -1
  178. package/dist/commands/reset.d.ts.map +1 -1
  179. package/dist/commands/reset.js +8 -7
  180. package/dist/commands/reset.js.map +1 -1
  181. package/dist/commands/revoke-credential.d.ts +5 -0
  182. package/dist/commands/revoke-credential.d.ts.map +1 -0
  183. package/dist/commands/revoke-credential.js +128 -0
  184. package/dist/commands/revoke-credential.js.map +1 -0
  185. package/dist/commands/send.d.ts +11 -3
  186. package/dist/commands/send.d.ts.map +1 -1
  187. package/dist/commands/send.js +284 -47
  188. package/dist/commands/send.js.map +1 -1
  189. package/dist/commands/service-actions.d.ts +2 -1
  190. package/dist/commands/service-actions.d.ts.map +1 -1
  191. package/dist/commands/service-actions.js +117 -21
  192. package/dist/commands/service-actions.js.map +1 -1
  193. package/dist/commands/service-log-follow.js +1 -1
  194. package/dist/commands/service-log-follow.js.map +1 -1
  195. package/dist/commands/service-registry.d.ts +1 -1
  196. package/dist/commands/service-registry.d.ts.map +1 -1
  197. package/dist/commands/service-registry.js +74 -30
  198. package/dist/commands/service-registry.js.map +1 -1
  199. package/dist/commands/service-set-stop.d.ts.map +1 -1
  200. package/dist/commands/service-set-stop.js +3 -2
  201. package/dist/commands/service-set-stop.js.map +1 -1
  202. package/dist/commands/setup-start.d.ts.map +1 -1
  203. package/dist/commands/setup-start.js +46 -5
  204. package/dist/commands/setup-start.js.map +1 -1
  205. package/dist/commands/setup.d.ts.map +1 -1
  206. package/dist/commands/setup.js +28 -13
  207. package/dist/commands/setup.js.map +1 -1
  208. package/dist/commands/space-delete.d.ts.map +1 -1
  209. package/dist/commands/space-delete.js +130 -41
  210. package/dist/commands/space-delete.js.map +1 -1
  211. package/dist/commands/space-registration.d.ts +13 -6
  212. package/dist/commands/space-registration.d.ts.map +1 -1
  213. package/dist/commands/space-registration.js +167 -46
  214. package/dist/commands/space-registration.js.map +1 -1
  215. package/dist/commands/space.d.ts +15 -1
  216. package/dist/commands/space.d.ts.map +1 -1
  217. package/dist/commands/space.js +66 -24
  218. package/dist/commands/space.js.map +1 -1
  219. package/dist/commands/spawn-preview.d.ts.map +1 -1
  220. package/dist/commands/spawn-preview.js +48 -10
  221. package/dist/commands/spawn-preview.js.map +1 -1
  222. package/dist/commands/spawn.d.ts +36 -13
  223. package/dist/commands/spawn.d.ts.map +1 -1
  224. package/dist/commands/spawn.js +306 -130
  225. package/dist/commands/spawn.js.map +1 -1
  226. package/dist/commands/stack-down.d.ts +9 -3
  227. package/dist/commands/stack-down.d.ts.map +1 -1
  228. package/dist/commands/stack-down.js +348 -64
  229. package/dist/commands/stack-down.js.map +1 -1
  230. package/dist/commands/stack-gone.d.ts +17 -0
  231. package/dist/commands/stack-gone.d.ts.map +1 -0
  232. package/dist/commands/stack-gone.js +218 -0
  233. package/dist/commands/stack-gone.js.map +1 -0
  234. package/dist/commands/stack-up.d.ts +64 -4
  235. package/dist/commands/stack-up.d.ts.map +1 -1
  236. package/dist/commands/stack-up.js +482 -55
  237. package/dist/commands/stack-up.js.map +1 -1
  238. package/dist/commands/status.d.ts +76 -2
  239. package/dist/commands/status.d.ts.map +1 -1
  240. package/dist/commands/status.js +550 -112
  241. package/dist/commands/status.js.map +1 -1
  242. package/dist/commands/team-agent-apply.d.ts.map +1 -1
  243. package/dist/commands/team-agent-apply.js +4 -3
  244. package/dist/commands/team-agent-apply.js.map +1 -1
  245. package/dist/commands/team-agent-remove.d.ts.map +1 -1
  246. package/dist/commands/team-agent-remove.js +4 -4
  247. package/dist/commands/team-agent-remove.js.map +1 -1
  248. package/dist/commands/team-boot-controller.d.ts.map +1 -1
  249. package/dist/commands/team-boot-controller.js +8 -2
  250. package/dist/commands/team-boot-controller.js.map +1 -1
  251. package/dist/commands/team-channel-remove.d.ts.map +1 -1
  252. package/dist/commands/team-channel-remove.js +26 -10
  253. package/dist/commands/team-channel-remove.js.map +1 -1
  254. package/dist/commands/team-deploy-apply.d.ts.map +1 -1
  255. package/dist/commands/team-deploy-apply.js +4 -3
  256. package/dist/commands/team-deploy-apply.js.map +1 -1
  257. package/dist/commands/team-mixed-remove.js +5 -5
  258. package/dist/commands/team-mixed-remove.js.map +1 -1
  259. package/dist/commands/team.d.ts.map +1 -1
  260. package/dist/commands/team.js +94 -32
  261. package/dist/commands/team.js.map +1 -1
  262. package/dist/commands/telemetry.d.ts.map +1 -1
  263. package/dist/commands/telemetry.js +3 -1
  264. package/dist/commands/telemetry.js.map +1 -1
  265. package/dist/commands/topology.d.ts.map +1 -1
  266. package/dist/commands/topology.js +11 -7
  267. package/dist/commands/topology.js.map +1 -1
  268. package/dist/commands/up.d.ts +6 -6
  269. package/dist/commands/up.d.ts.map +1 -1
  270. package/dist/commands/up.js +963 -240
  271. package/dist/commands/up.js.map +1 -1
  272. package/dist/commands/update.d.ts.map +1 -1
  273. package/dist/commands/update.js +9 -3
  274. package/dist/commands/update.js.map +1 -1
  275. package/dist/commands/use.d.ts +5 -1
  276. package/dist/commands/use.d.ts.map +1 -1
  277. package/dist/commands/use.js +55 -12
  278. package/dist/commands/use.js.map +1 -1
  279. package/dist/commands/watch.d.ts +4 -1
  280. package/dist/commands/watch.d.ts.map +1 -1
  281. package/dist/commands/watch.js +15 -3
  282. package/dist/commands/watch.js.map +1 -1
  283. package/dist/commands/who.d.ts +2 -0
  284. package/dist/commands/who.d.ts.map +1 -1
  285. package/dist/commands/who.js +18 -5
  286. package/dist/commands/who.js.map +1 -1
  287. package/dist/commands/whoami.d.ts +44 -5
  288. package/dist/commands/whoami.d.ts.map +1 -1
  289. package/dist/commands/whoami.js +168 -16
  290. package/dist/commands/whoami.js.map +1 -1
  291. package/dist/console/app.d.ts +1 -1
  292. package/dist/console/app.d.ts.map +1 -1
  293. package/dist/console/app.js +15 -9
  294. package/dist/console/app.js.map +1 -1
  295. package/dist/console/launch.d.ts +25 -0
  296. package/dist/console/launch.d.ts.map +1 -0
  297. package/dist/console/launch.js +56 -0
  298. package/dist/console/launch.js.map +1 -0
  299. package/dist/console/ui/CommandPalette.d.ts +5 -4
  300. package/dist/console/ui/CommandPalette.d.ts.map +1 -1
  301. package/dist/console/ui/CommandPalette.js +136 -45
  302. package/dist/console/ui/CommandPalette.js.map +1 -1
  303. package/dist/console/ui/Help.js +1 -1
  304. package/dist/console/ui/Help.js.map +1 -1
  305. package/dist/console/ui/Modal.d.ts +10 -0
  306. package/dist/console/ui/Modal.d.ts.map +1 -0
  307. package/dist/console/ui/Modal.js +8 -0
  308. package/dist/console/ui/Modal.js.map +1 -0
  309. package/dist/console/ui/NewAgent.d.ts +14 -0
  310. package/dist/console/ui/NewAgent.d.ts.map +1 -0
  311. package/dist/console/ui/NewAgent.js +114 -0
  312. package/dist/console/ui/NewAgent.js.map +1 -0
  313. package/dist/console/ui/StatusBar.d.ts +1 -2
  314. package/dist/console/ui/StatusBar.d.ts.map +1 -1
  315. package/dist/console/ui/StatusBar.js +6 -8
  316. package/dist/console/ui/StatusBar.js.map +1 -1
  317. package/dist/console/ui/topo/Map.d.ts.map +1 -1
  318. package/dist/console/ui/topo/Map.js +1 -2
  319. package/dist/console/ui/topo/Map.js.map +1 -1
  320. package/dist/console/ui/topo/Matrix.js +2 -2
  321. package/dist/console/ui/topo/Matrix.js.map +1 -1
  322. package/dist/console/ui/topo/Sequence.d.ts.map +1 -1
  323. package/dist/console/ui/topo/Sequence.js +5 -4
  324. package/dist/console/ui/topo/Sequence.js.map +1 -1
  325. package/dist/console/ui/topo/model.d.ts +2 -1
  326. package/dist/console/ui/topo/model.d.ts.map +1 -1
  327. package/dist/console/ui/topo/model.js +4 -3
  328. package/dist/console/ui/topo/model.js.map +1 -1
  329. package/dist/exec-endpoint/service-adapter.d.ts.map +1 -1
  330. package/dist/exec-endpoint/service-adapter.js +13 -3
  331. package/dist/exec-endpoint/service-adapter.js.map +1 -1
  332. package/dist/ext-loader.d.ts +4 -0
  333. package/dist/ext-loader.d.ts.map +1 -1
  334. package/dist/ext-loader.js +6 -0
  335. package/dist/ext-loader.js.map +1 -1
  336. package/dist/help.d.ts.map +1 -1
  337. package/dist/help.js +44 -23
  338. package/dist/help.js.map +1 -1
  339. package/dist/index.d.ts.map +1 -1
  340. package/dist/index.js +59 -54
  341. package/dist/index.js.map +1 -1
  342. package/dist/lib/agent-skills.d.ts.map +1 -1
  343. package/dist/lib/agent-skills.js +2 -1
  344. package/dist/lib/agent-skills.js.map +1 -1
  345. package/dist/lib/attach-client.js +2 -2
  346. package/dist/lib/attach-client.js.map +1 -1
  347. package/dist/lib/backup-artifact.d.ts +29 -8
  348. package/dist/lib/backup-artifact.d.ts.map +1 -1
  349. package/dist/lib/backup-artifact.js +147 -26
  350. package/dist/lib/backup-artifact.js.map +1 -1
  351. package/dist/lib/broker-service.d.ts +27 -3
  352. package/dist/lib/broker-service.d.ts.map +1 -1
  353. package/dist/lib/broker-service.js +142 -29
  354. package/dist/lib/broker-service.js.map +1 -1
  355. package/dist/lib/broker-store-health.d.ts +89 -0
  356. package/dist/lib/broker-store-health.d.ts.map +1 -0
  357. package/dist/lib/broker-store-health.js +171 -0
  358. package/dist/lib/broker-store-health.js.map +1 -0
  359. package/dist/lib/cancel.d.ts +4 -4
  360. package/dist/lib/cancel.d.ts.map +1 -1
  361. package/dist/lib/cancel.js +5 -5
  362. package/dist/lib/cancel.js.map +1 -1
  363. package/dist/lib/completion-install.d.ts +11 -2
  364. package/dist/lib/completion-install.d.ts.map +1 -1
  365. package/dist/lib/completion-install.js +79 -21
  366. package/dist/lib/completion-install.js.map +1 -1
  367. package/dist/lib/completion-scripts.d.ts.map +1 -1
  368. package/dist/lib/completion-scripts.js +2 -2
  369. package/dist/lib/completion-scripts.js.map +1 -1
  370. package/dist/lib/completion.d.ts +5 -1
  371. package/dist/lib/completion.d.ts.map +1 -1
  372. package/dist/lib/completion.js +10 -0
  373. package/dist/lib/completion.js.map +1 -1
  374. package/dist/lib/concrete-channel.d.ts +6 -0
  375. package/dist/lib/concrete-channel.d.ts.map +1 -0
  376. package/dist/lib/concrete-channel.js +17 -0
  377. package/dist/lib/concrete-channel.js.map +1 -0
  378. package/dist/lib/confirmation-required.d.ts +3 -12
  379. package/dist/lib/confirmation-required.d.ts.map +1 -1
  380. package/dist/lib/confirmation-required.js +9 -8
  381. package/dist/lib/confirmation-required.js.map +1 -1
  382. package/dist/lib/connect.d.ts +9 -0
  383. package/dist/lib/connect.d.ts.map +1 -1
  384. package/dist/lib/connect.js +27 -0
  385. package/dist/lib/connect.js.map +1 -1
  386. package/dist/lib/control.d.ts +42 -12
  387. package/dist/lib/control.d.ts.map +1 -1
  388. package/dist/lib/control.js +148 -34
  389. package/dist/lib/control.js.map +1 -1
  390. package/dist/lib/controller-restore.d.ts.map +1 -1
  391. package/dist/lib/controller-restore.js +12 -7
  392. package/dist/lib/controller-restore.js.map +1 -1
  393. package/dist/lib/credential-authority.d.ts.map +1 -1
  394. package/dist/lib/credential-authority.js +3 -0
  395. package/dist/lib/credential-authority.js.map +1 -1
  396. package/dist/lib/credential-exports.d.ts +17 -0
  397. package/dist/lib/credential-exports.d.ts.map +1 -0
  398. package/dist/lib/credential-exports.js +21 -0
  399. package/dist/lib/credential-exports.js.map +1 -0
  400. package/dist/lib/debug-flag.d.ts +4 -0
  401. package/dist/lib/debug-flag.d.ts.map +1 -0
  402. package/dist/lib/debug-flag.js +7 -0
  403. package/dist/lib/debug-flag.js.map +1 -0
  404. package/dist/lib/default-persona.d.ts +2 -0
  405. package/dist/lib/default-persona.d.ts.map +1 -1
  406. package/dist/lib/default-persona.js +2 -0
  407. package/dist/lib/default-persona.js.map +1 -1
  408. package/dist/lib/delivery-proc.d.ts +1 -1
  409. package/dist/lib/delivery-proc.d.ts.map +1 -1
  410. package/dist/lib/delivery-proc.js +5 -4
  411. package/dist/lib/delivery-proc.js.map +1 -1
  412. package/dist/lib/delivery-responder.d.ts +7 -3
  413. package/dist/lib/delivery-responder.d.ts.map +1 -1
  414. package/dist/lib/delivery-responder.js +8 -4
  415. package/dist/lib/delivery-responder.js.map +1 -1
  416. package/dist/lib/denied-write.d.ts +8 -0
  417. package/dist/lib/denied-write.d.ts.map +1 -0
  418. package/dist/lib/denied-write.js +24 -0
  419. package/dist/lib/denied-write.js.map +1 -0
  420. package/dist/lib/endpoint-capability-gates.js +2 -2
  421. package/dist/lib/endpoint-capability-gates.js.map +1 -1
  422. package/dist/lib/flag-value-refusal.d.ts +8 -0
  423. package/dist/lib/flag-value-refusal.d.ts.map +1 -0
  424. package/dist/lib/flag-value-refusal.js +10 -0
  425. package/dist/lib/flag-value-refusal.js.map +1 -0
  426. package/dist/lib/install-umask.d.ts +5 -0
  427. package/dist/lib/install-umask.d.ts.map +1 -1
  428. package/dist/lib/install-umask.js +25 -0
  429. package/dist/lib/install-umask.js.map +1 -1
  430. package/dist/lib/interrupt-notice.d.ts +23 -1
  431. package/dist/lib/interrupt-notice.d.ts.map +1 -1
  432. package/dist/lib/interrupt-notice.js +27 -6
  433. package/dist/lib/interrupt-notice.js.map +1 -1
  434. package/dist/lib/interrupt-report.d.ts +7 -0
  435. package/dist/lib/interrupt-report.d.ts.map +1 -0
  436. package/dist/lib/interrupt-report.js +24 -0
  437. package/dist/lib/interrupt-report.js.map +1 -0
  438. package/dist/lib/isolated-broker.d.ts +1 -1
  439. package/dist/lib/isolated-broker.d.ts.map +1 -1
  440. package/dist/lib/isolated-broker.js +17 -8
  441. package/dist/lib/isolated-broker.js.map +1 -1
  442. package/dist/lib/legacy-start.d.ts +8 -6
  443. package/dist/lib/legacy-start.d.ts.map +1 -1
  444. package/dist/lib/legacy-start.js +36 -36
  445. package/dist/lib/legacy-start.js.map +1 -1
  446. package/dist/lib/manager-choice.d.ts +92 -4
  447. package/dist/lib/manager-choice.d.ts.map +1 -1
  448. package/dist/lib/manager-choice.js +338 -23
  449. package/dist/lib/manager-choice.js.map +1 -1
  450. package/dist/lib/manager-proc.d.ts.map +1 -1
  451. package/dist/lib/manager-proc.js +7 -6
  452. package/dist/lib/manager-proc.js.map +1 -1
  453. package/dist/lib/manifest/index.d.ts +5 -1
  454. package/dist/lib/manifest/index.d.ts.map +1 -1
  455. package/dist/lib/manifest/index.js +50 -5
  456. package/dist/lib/manifest/index.js.map +1 -1
  457. package/dist/lib/manifest/preflight.d.ts +4 -0
  458. package/dist/lib/manifest/preflight.d.ts.map +1 -1
  459. package/dist/lib/manifest/preflight.js +18 -1
  460. package/dist/lib/manifest/preflight.js.map +1 -1
  461. package/dist/lib/manifest/resolve.d.ts +8 -0
  462. package/dist/lib/manifest/resolve.d.ts.map +1 -1
  463. package/dist/lib/manifest/resolve.js +104 -11
  464. package/dist/lib/manifest/resolve.js.map +1 -1
  465. package/dist/lib/missing-flags.js +1 -1
  466. package/dist/lib/missing-flags.js.map +1 -1
  467. package/dist/lib/nats-bin.d.ts +28 -5
  468. package/dist/lib/nats-bin.d.ts.map +1 -1
  469. package/dist/lib/nats-bin.js +85 -7
  470. package/dist/lib/nats-bin.js.map +1 -1
  471. package/dist/lib/nearest-word.d.ts +14 -0
  472. package/dist/lib/nearest-word.d.ts.map +1 -0
  473. package/dist/lib/nearest-word.js +76 -0
  474. package/dist/lib/nearest-word.js.map +1 -0
  475. package/dist/lib/no-expiry-record.d.ts +8 -0
  476. package/dist/lib/no-expiry-record.d.ts.map +1 -0
  477. package/dist/lib/no-expiry-record.js +27 -0
  478. package/dist/lib/no-expiry-record.js.map +1 -0
  479. package/dist/lib/paths.d.ts +31 -0
  480. package/dist/lib/paths.d.ts.map +1 -1
  481. package/dist/lib/paths.js +92 -2
  482. package/dist/lib/paths.js.map +1 -1
  483. package/dist/lib/persona-files.d.ts +29 -6
  484. package/dist/lib/persona-files.d.ts.map +1 -1
  485. package/dist/lib/persona-files.js +179 -36
  486. package/dist/lib/persona-files.js.map +1 -1
  487. package/dist/lib/personas.d.ts +18 -1
  488. package/dist/lib/personas.d.ts.map +1 -1
  489. package/dist/lib/personas.js +65 -6
  490. package/dist/lib/personas.js.map +1 -1
  491. package/dist/lib/prompts.d.ts +7 -1
  492. package/dist/lib/prompts.d.ts.map +1 -1
  493. package/dist/lib/prompts.js +43 -3
  494. package/dist/lib/prompts.js.map +1 -1
  495. package/dist/lib/registry-errors.d.ts +2 -1
  496. package/dist/lib/registry-errors.d.ts.map +1 -1
  497. package/dist/lib/registry-errors.js +6 -2
  498. package/dist/lib/registry-errors.js.map +1 -1
  499. package/dist/lib/reset-space-plan.d.ts +2 -0
  500. package/dist/lib/reset-space-plan.d.ts.map +1 -1
  501. package/dist/lib/reset-space-plan.js +1 -1
  502. package/dist/lib/reset-space-plan.js.map +1 -1
  503. package/dist/lib/restore.d.ts +45 -3
  504. package/dist/lib/restore.d.ts.map +1 -1
  505. package/dist/lib/restore.js +233 -39
  506. package/dist/lib/restore.js.map +1 -1
  507. package/dist/lib/rolled-back-runs.d.ts +36 -0
  508. package/dist/lib/rolled-back-runs.d.ts.map +1 -0
  509. package/dist/lib/rolled-back-runs.js +96 -0
  510. package/dist/lib/rolled-back-runs.js.map +1 -0
  511. package/dist/lib/service-custody-win32.d.ts +25 -0
  512. package/dist/lib/service-custody-win32.d.ts.map +1 -0
  513. package/dist/lib/service-custody-win32.js +67 -0
  514. package/dist/lib/service-custody-win32.js.map +1 -0
  515. package/dist/lib/service-definitions.d.ts +16 -3
  516. package/dist/lib/service-definitions.d.ts.map +1 -1
  517. package/dist/lib/service-definitions.js +99 -27
  518. package/dist/lib/service-definitions.js.map +1 -1
  519. package/dist/lib/service-instances.d.ts +46 -5
  520. package/dist/lib/service-instances.d.ts.map +1 -1
  521. package/dist/lib/service-instances.js +112 -18
  522. package/dist/lib/service-instances.js.map +1 -1
  523. package/dist/lib/service-journal.js +1 -1
  524. package/dist/lib/service-journal.js.map +1 -1
  525. package/dist/lib/service-presets.d.ts.map +1 -1
  526. package/dist/lib/service-presets.js +16 -0
  527. package/dist/lib/service-presets.js.map +1 -1
  528. package/dist/lib/service-process.d.ts +53 -15
  529. package/dist/lib/service-process.d.ts.map +1 -1
  530. package/dist/lib/service-process.js +533 -86
  531. package/dist/lib/service-process.js.map +1 -1
  532. package/dist/lib/service-systemd-install.js +1 -1
  533. package/dist/lib/service-systemd-install.js.map +1 -1
  534. package/dist/lib/space-streams.d.ts +18 -0
  535. package/dist/lib/space-streams.d.ts.map +1 -0
  536. package/dist/lib/space-streams.js +35 -0
  537. package/dist/lib/space-streams.js.map +1 -0
  538. package/dist/lib/spawn-defaults.d.ts +25 -1
  539. package/dist/lib/spawn-defaults.d.ts.map +1 -1
  540. package/dist/lib/spawn-defaults.js +37 -1
  541. package/dist/lib/spawn-defaults.js.map +1 -1
  542. package/dist/lib/stack-journal.d.ts +157 -14
  543. package/dist/lib/stack-journal.d.ts.map +1 -1
  544. package/dist/lib/stack-journal.js +406 -49
  545. package/dist/lib/stack-journal.js.map +1 -1
  546. package/dist/lib/stack-listeners.d.ts +17 -0
  547. package/dist/lib/stack-listeners.d.ts.map +1 -0
  548. package/dist/lib/stack-listeners.js +54 -0
  549. package/dist/lib/stack-listeners.js.map +1 -0
  550. package/dist/lib/stack-members.d.ts +13 -0
  551. package/dist/lib/stack-members.d.ts.map +1 -0
  552. package/dist/lib/stack-members.js +24 -0
  553. package/dist/lib/stack-members.js.map +1 -0
  554. package/dist/lib/stack-resume.d.ts.map +1 -1
  555. package/dist/lib/stack-resume.js +5 -2
  556. package/dist/lib/stack-resume.js.map +1 -1
  557. package/dist/lib/stack-runs.d.ts +34 -0
  558. package/dist/lib/stack-runs.d.ts.map +1 -0
  559. package/dist/lib/stack-runs.js +75 -0
  560. package/dist/lib/stack-runs.js.map +1 -0
  561. package/dist/lib/status.d.ts +11 -0
  562. package/dist/lib/status.d.ts.map +1 -1
  563. package/dist/lib/status.js +4 -5
  564. package/dist/lib/status.js.map +1 -1
  565. package/dist/lib/stdout-owner.d.ts +12 -3
  566. package/dist/lib/stdout-owner.d.ts.map +1 -1
  567. package/dist/lib/stdout-owner.js +33 -5
  568. package/dist/lib/stdout-owner.js.map +1 -1
  569. package/dist/lib/store-dir.d.ts +68 -4
  570. package/dist/lib/store-dir.d.ts.map +1 -1
  571. package/dist/lib/store-dir.js +253 -17
  572. package/dist/lib/store-dir.js.map +1 -1
  573. package/dist/lib/team-additive-attempt.d.ts +1 -1
  574. package/dist/lib/team-channel-removal.d.ts.map +1 -1
  575. package/dist/lib/team-channel-removal.js +4 -0
  576. package/dist/lib/team-channel-removal.js.map +1 -1
  577. package/dist/lib/team-deploy-inspection.d.ts +13 -0
  578. package/dist/lib/team-deploy-inspection.d.ts.map +1 -1
  579. package/dist/lib/team-deploy-inspection.js +12 -0
  580. package/dist/lib/team-deploy-inspection.js.map +1 -1
  581. package/dist/lib/team-text.d.ts +6 -0
  582. package/dist/lib/team-text.d.ts.map +1 -0
  583. package/dist/lib/team-text.js +36 -0
  584. package/dist/lib/team-text.js.map +1 -0
  585. package/dist/lib/transient.d.ts +14 -8
  586. package/dist/lib/transient.d.ts.map +1 -1
  587. package/dist/lib/transient.js +72 -11
  588. package/dist/lib/transient.js.map +1 -1
  589. package/dist/lib/unusable-file.d.ts +13 -0
  590. package/dist/lib/unusable-file.d.ts.map +1 -0
  591. package/dist/lib/unusable-file.js +12 -0
  592. package/dist/lib/unusable-file.js.map +1 -0
  593. package/dist/lib/up-report.d.ts +6 -0
  594. package/dist/lib/up-report.d.ts.map +1 -1
  595. package/dist/lib/up-report.js +13 -0
  596. package/dist/lib/up-report.js.map +1 -1
  597. package/dist/lib/verdict.d.ts +14 -0
  598. package/dist/lib/verdict.d.ts.map +1 -0
  599. package/dist/lib/verdict.js +15 -0
  600. package/dist/lib/verdict.js.map +1 -0
  601. package/dist/managed-handoff.d.ts +11 -6
  602. package/dist/managed-handoff.d.ts.map +1 -1
  603. package/dist/managed-handoff.js +27 -18
  604. package/dist/managed-handoff.js.map +1 -1
  605. package/dist/render.d.ts +5 -2
  606. package/dist/render.d.ts.map +1 -1
  607. package/dist/render.js +44 -10
  608. package/dist/render.js.map +1 -1
  609. package/dist/telemetry.d.ts +4 -3
  610. package/dist/telemetry.d.ts.map +1 -1
  611. package/dist/telemetry.js +14 -6
  612. package/dist/telemetry.js.map +1 -1
  613. package/dist/ui.d.ts +3 -2
  614. package/dist/ui.d.ts.map +1 -1
  615. package/dist/ui.js +6 -4
  616. package/dist/ui.js.map +1 -1
  617. package/dist/view/mesh-view.d.ts.map +1 -1
  618. package/dist/view/mesh-view.js +4 -1
  619. package/dist/view/mesh-view.js.map +1 -1
  620. package/dist/watch-data.d.ts +9 -1
  621. package/dist/watch-data.d.ts.map +1 -1
  622. package/dist/watch-data.js +17 -3
  623. package/dist/watch-data.js.map +1 -1
  624. package/dist/watch-json.js +4 -3
  625. package/dist/watch-json.js.map +1 -1
  626. package/package.json +5 -5
@@ -2,24 +2,27 @@ import { spawn as spawnProcess } from "node:child_process";
2
2
  import { createHash } from "node:crypto";
3
3
  import { readFileSync, rmSync, statSync } from "node:fs";
4
4
  import { hostname } from "node:os";
5
- import { join, resolve as resolvePath } from "node:path";
6
- import { assertValidRole, agentFilePath, AgentGrantConflictError, connectorServers, spawnEnvAllow, deprovisionAgent, discardLaunchArtifacts, firstFreeName, isReachable, reclaimWithChild, loadCotalConfig, modelPolicyRefusal, mintCreds, newIdentity, DEV_OWNER, parseShareSelection, principalKey, mintLifecycleUid, MANAGED_HANDOFF_FILE_ENV, parseManagedLifecycleHandoff, spawnNameError, provisionAgent, provisionAgentDurables, registry, resolveAuthProvider, resolveReadAcl, runAgentBearer, CotalEndpoint, acquireLock, inspectLock, localConsumerClaimPath, transferBucket, writeTransfer, peerLabel, } from "@cotal-ai/core";
7
- import { CommandFailure, loadLaunchPersonaFile, personaFileReference, PersonaSourceError, inputDisabledByFlag, jsonFlag, plainFlag, presentationOf, renderReport, terminalWidth, writeResult, agentActorTokenKey, agentCredsKey, agentSecretFilePaths, agentSentinelCredsKey, authDir, cachedPreferences, credsFlag, launchFlags, loadMeshes, findMesh, getSpaceAuth, materializeSecretToFile, mergeLaunchOptions, parseLaunchOptions, preflightOrThrow, provenance, resolveAgentType, resolveMeshTarget, resolvePreference, resolveTargetOrThrow, serverFlag, spaceAccountPath, spaceFlag, spaceKey, userAuthStateDir, workspaceSecretStore, refreshRegistrationPolicy, resolveSeatControlTarget, connectUserControlOrExit, userViewAuth, oneLine, recordOperationSpace, } from "@cotal-ai/workspace";
8
- import { c } from "../ui.js";
5
+ import { resolve as resolvePath } from "node:path";
6
+ import { assertValidRole, agentFilePath, AgentGrantConflictError, connectorServers, spawnEnvAllow, deprovisionAgent, discardLaunchArtifacts, firstFreeName, isReachable, reclaimWithChild, loadCotalConfig, modelPolicyRefusal, mintCreds, newIdentity, DEV_OWNER, parseShareSelection, principalKey, assertLifecycleToken, mintLifecycleUid, MANAGED_HANDOFF_FILE_ENV, parseManagedLifecycleHandoff, spawnNameError, provisionAgent, provisionAgentDurables, registry, resolveAuthProvider, resolveReadAcl, runAgentBearer, CotalEndpoint, acquireLock, inspectLock, localConsumerClaimPath, transferBucket, writeTransfer, peerLabel, } from "@cotal-ai/core";
7
+ import { CommandFailure, loadLaunchPersonaFile, personaFileReference, PersonaSourceError, inputDisabledByFlag, jsonFlag, plainFlag, presentationOf, recordOperationWarning, renderReport, terminalWidth, wrapWords, writeResult, agentActorTokenKey, agentCredsKey, agentSecretFilePaths, agentSentinelCredsKey, authDir, cachedPreferences, credsFlag, launchFlags, findMesh, getSpaceAuth, materializeSecretToFile, mergeLaunchOptions, parseLaunchOptions, preflightOrThrow, provenance, resolveAgentType, resolvePreference, resolveTargetOrThrow, serverFlag, spaceAccountPath, spaceFlag, spaceKey, userAuthStateDir, workspaceSecretStore, refreshRegistrationPolicy, resolveSeatControlTarget, connectUserControlOrExit, userViewAuth, oneLine, DEFAULT_CONNECTOR, hintedConnector, manifestExtensionNames, OFFICIAL_CONNECTORS, recordOperationSpace, } from "@cotal-ai/workspace";
8
+ import { c, stderrLine } from "../ui.js";
9
9
  import { liveMeshNames } from "../lib/live-names.js";
10
10
  import { displayCmd } from "../lib/self-exec.js";
11
11
  import { entryScript } from "../seed/paths.js";
12
12
  import { completedFlagValue, completingFlagValue, hasCompletedFlagValue, positionalsForCompletion } from "../lib/completion.js";
13
13
  import { preflightOrExit, resolveTargetOrExit } from "../lib/connect.js";
14
- import { askManager, failIfNotOk, onInstance, onInstanceOrExit, resolveControlTarget, START_TIMEOUT_MS, withControlConnection } from "../lib/control.js";
15
- import { listDeclaredChannels, listDeclaredRoles, listPersonas } from "../lib/personas.js";
16
- import { callerHarness, spawnPersona } from "../lib/spawn-defaults.js";
17
- import { defaultPersonaFix } from "../lib/default-persona.js";
14
+ import { runningStackManagerPid, stackManagerAbsent, stackManagerStarting } from "../lib/stack-journal.js";
15
+ import { askManager, describeUnanswered, failIfNotOk, liveManagerIds, managerRailGone, onInstance, refuseUnregisteredManager, refuseWithoutLiveManager, resolveControlTarget, START_TIMEOUT_MS, withControlConnection } from "../lib/control.js";
16
+ import { askManagerFolder, askSpawnPlace, managerPin, managerSelection, managersWithPersona, rerunOn } from "../lib/manager-choice.js";
17
+ import { canPrompt } from "./meshes-wizard.js";
18
+ import { listDeclaredChannels, listDeclaredRoles, listPersonaNames } from "../lib/personas.js";
19
+ import { personaCatalog } from "../lib/persona-files.js";
20
+ import { callerHarness, missingPersona, spawnPersona, spawnUsesManager } from "../lib/spawn-defaults.js";
18
21
  import { spawnLaunchPreview } from "./spawn-preview.js";
19
22
  import { protectedCredentialReference, readLocalRecordSource } from "../lib/protected-records.js";
20
23
  import { attachSeat } from "./agents.js";
21
24
  import { extensionNames, materializeExtension } from "../ext-loader.js";
22
- import { claimManagedHandoff, holdsManagedHandoff } from "../managed-handoff.js";
25
+ import { claimManagedHandoff, holdsManagedHandoff, managedHandoffRefusal } from "../managed-handoff.js";
23
26
  import { checkDialPolicy, checkEnforcement, checkServer, checkUserBundle, persistRemoteUserEntry, probeEnforcement, tlsIntent, userExchangeIssuer, verifyUserExchange, } from "./meshes-add.js";
24
27
  const ENROLLMENT_URL_ENV = "COTAL_ENROLLMENT_URL";
25
28
  const ENROLLMENT_FILE_ENV = "COTAL_ENROLLMENT_FILE";
@@ -64,6 +67,14 @@ export function scrubEnrollmentEnv(env) {
64
67
  delete env[key];
65
68
  }
66
69
  }
70
+ /** Carry the launching manager's validated `COTAL_MANAGER_INSTANCE` onto a managed-handoff
71
+ * child's connector launch spec (`spawnProcess` passes `env: spec.env` only, and `launchEnv`
72
+ * does not forward `COTAL_MANAGER_INSTANCE` from `process.env`). */
73
+ export function applyHandoffManagerInstance(spec, handoffManagerInstanceId) {
74
+ if (handoffManagerInstanceId !== undefined) {
75
+ spec.env = { ...spec.env, COTAL_MANAGER_INSTANCE: handoffManagerInstanceId };
76
+ }
77
+ }
67
78
  export function checkEnrollmentBundle(raw, actor) {
68
79
  const material = checkRemoteAgentMaterial(raw, actor);
69
80
  if (!material.ok)
@@ -170,8 +181,6 @@ async function registerEnrollmentMesh(stock, root, refusals) {
170
181
  * personas, not the cwd's. */
171
182
  export function spawnComplete(argv) {
172
183
  const flag = completingFlagValue(argv, spawnFlags);
173
- if (flag?.name === "space")
174
- return { items: loadMeshes().map((m) => ({ value: m.space })), directive: "nofiles" };
175
184
  if (flag?.name === "agent" || flag?.name === "harness")
176
185
  return { items: registry.all("connector").map((c) => ({ value: c.name })), directive: "nofiles" };
177
186
  if (flag?.name === "role")
@@ -180,12 +189,7 @@ export function spawnComplete(argv) {
180
189
  const current = argv[argv.length - 1] ?? "";
181
190
  if (current.includes("/") || current.includes("\\") || current.endsWith(".md"))
182
191
  return { items: [], directive: "default" };
183
- try {
184
- return { items: personaItems(argv), directive: "nofiles" };
185
- }
186
- catch {
187
- return { items: [], directive: "nofiles" };
188
- }
192
+ return { items: personaItems(argv), directive: "nofiles" };
189
193
  }
190
194
  if (flag && ["subscribe", "allow-subscribe", "allow-publish"].includes(flag.name))
191
195
  return { items: declaredFrom(argv, listDeclaredChannels).map((value) => ({ value, description: "declared channel" })), directive: "nofiles" };
@@ -195,24 +199,28 @@ export function spawnComplete(argv) {
195
199
  return { items: ["pty", ...extensionNames("runtime")].filter((value, i, all) => all.indexOf(value) === i).map((value) => ({ value })), directive: "nofiles" };
196
200
  const positionals = positionalsForCompletion(argv, spawnFlags);
197
201
  // Only the first word after `spawn` is the persona positional; once it's typed, defer to the shell.
198
- if (positionals.length <= 1 && !hasCompletedFlagValue(argv, spawnFlags, "config") && !hasCompletedFlagValue(argv, spawnFlags, "file")) {
199
- try {
200
- return { items: personaItems(argv), directive: "nofiles" };
201
- }
202
- catch {
203
- // No single target (no mesh, or several with no `current`) — fail CLOSED: offer no personas
204
- // rather than throw. `cotal spawn --space <TAB>` still lists the running meshes.
205
- return { items: [], directive: "nofiles" };
206
- }
207
- }
202
+ if (positionals.length <= 1 && !hasCompletedFlagValue(argv, spawnFlags, "config") && !hasCompletedFlagValue(argv, spawnFlags, "file"))
203
+ return { items: personaItems(argv), directive: "nofiles" };
208
204
  return { items: [], directive: "nofiles" };
209
205
  }
206
+ /** The persona catalog root this spawn would read, resolved read-only as `persona show` resolves it,
207
+ * so a prepared space that is not started still lists its personas. */
208
+ const catalogRoot = (argv) => personaCatalog({
209
+ space: completedFlagValue(argv, spawnFlags, "space"),
210
+ server: completedFlagValue(argv, spawnFlags, "server"),
211
+ }).root;
212
+ /** The personas this spawn would launch from. With no single target (no mesh, or several with no
213
+ * `current`) it fails CLOSED and offers none; `cotal spawn --space <TAB>` still lists the running
214
+ * meshes. A catalog folder that cannot be read throws, so the completion fails and names it. */
210
215
  function personaItems(argv) {
211
- const target = resolveMeshTarget(process.cwd(), {
212
- space: completedFlagValue(argv, spawnFlags, "space"),
213
- server: completedFlagValue(argv, spawnFlags, "server"),
214
- });
215
- return listPersonas(target.root).map((p) => ({ value: p.name }));
216
+ let root;
217
+ try {
218
+ root = catalogRoot(argv);
219
+ }
220
+ catch {
221
+ return [];
222
+ }
223
+ return listPersonaNames(root).map((value) => ({ value }));
216
224
  }
217
225
  /** Channels/roles declared by the TARGET mesh's personas — the same root {@link personaItems}
218
226
  * uses, so `--role`/`--subscribe` complete from the personas this spawn would actually launch
@@ -221,10 +229,7 @@ function personaItems(argv) {
221
229
  * offer nothing rather than throw into the operator's shell. */
222
230
  function declaredFrom(argv, list) {
223
231
  try {
224
- return list(resolveMeshTarget(process.cwd(), {
225
- space: completedFlagValue(argv, spawnFlags, "space"),
226
- server: completedFlagValue(argv, spawnFlags, "server"),
227
- }).root);
232
+ return list(catalogRoot(argv));
228
233
  }
229
234
  catch {
230
235
  return [];
@@ -265,40 +270,43 @@ async function provisionFreshForeground(requested, autoName, provision) {
265
270
  }
266
271
  }
267
272
  }
268
- /** `cotal spawn`'s grammar: managed launch/attach by default, explicit native foreground,
269
- * and one positional persona or explicit persona file. Declared `as const` so the values cast
273
+ /** `cotal spawn`'s grammar: the application in this terminal by default, a manager's launch only
274
+ * with `--detach` or `--on`, and one positional persona or explicit persona file. Declared `as const` so the values cast
270
275
  * below is compile-checked against exactly these specs. Foreground and detached parse the SAME
271
276
  * flags — the old `spawn` vs `start` ability drift is structurally gone. */
272
277
  export const spawnFlags = [
273
278
  spaceFlag,
274
279
  serverFlag,
275
- { ...credsFlag, description: "control-caller creds for an off-registry manager (managed launch only, not --foreground)" },
280
+ { ...credsFlag, description: "control-caller creds for an off-registry manager (with --detach or --on)" },
276
281
  ...launchFlags,
277
282
  { name: "harness", short: "H", type: "string", value: "<connector>", description: "application connector; an explicit flag wins over persona and saved defaults" },
278
- { name: "foreground", type: "boolean", description: "run the native application directly; terminal exit may end it" },
279
- { name: "restarts", type: "string", value: "<n>", description: "maximum manager-supervised restarts in the selected restart window" },
283
+ { name: "foreground", type: "boolean", description: "run the application in this terminal, as a spawn without --detach or --on does; terminal exit may end it" },
284
+ { name: "restarts", type: "string", value: "<n>", description: "with --detach or --on: maximum manager-supervised restarts in the selected restart window" },
280
285
  { name: "restart-window", type: "string", value: "<ms>", description: "time window for --restarts; both flags are required together" },
281
286
  jsonFlag, plainFlag,
282
- { name: "detach", type: "boolean", short: "d", description: "launch through the manager, await readiness and return without attaching" },
287
+ { name: "detach", type: "boolean", short: "d", description: "launch through a manager, await readiness and return without attaching" },
283
288
  { name: "live-only", type: "boolean", description: "foreground only: skip the durable backstop (no read-ACL row; messages missed while disconnected are not replayed)" },
284
289
  { name: "file", type: "string", short: "f", value: "<persona-file>", description: "persona file on the execution host; never a manifest deploy or implicit upload" },
285
290
  { name: "dry-run", type: "boolean", description: "preview the launch without allocation, provisioning or starting an application" },
286
- { name: "enrollment-file", type: "string", value: "<private-file>", description: "with --foreground: protected file holding this one seat's enrollment URL; never print or forward it" },
291
+ { name: "enrollment-file", type: "string", value: "<private-file>", description: "foreground only: protected file holding this one seat's enrollment URL; never print or forward it" },
287
292
  { name: "allow-stale", type: "string", value: "<a,b>", description: "refused: a manifest deployment option; use cotal team deploy <file>" },
288
293
  { name: "runtime", type: "string", value: "<name>", description: "refused: a manifest deployment option; use cotal team deploy <file>" },
289
- { name: "on", type: "string", value: "<instance>", description: "managed launch only: launch through one manager instance, by the id `ps` prints, in a space with several managers; by default any one takes it" },
294
+ { name: "on", type: "string", value: "<instance>", description: "launch through this manager instance, by the id `ps` prints, and attach; with --detach, return once it joins" },
290
295
  { name: "expect-owner", type: "string", value: "<u_…>", description: `with ${MANAGED_HANDOFF_FILE_ENV}: the owner the managed handoff must carry` },
291
296
  { name: "expect-lifecycle-uid", type: "string", value: "<uid>", description: `with ${MANAGED_HANDOFF_FILE_ENV}: the lifecycle UID the managed handoff must carry` },
292
297
  ];
293
298
  /** Check the public mode and spelling before catalog preparation or identity allocation. */
294
299
  export function validateSpawnArguments(args) {
295
300
  const values = args.values;
301
+ const handoffRefusal = managedHandoffRefusal();
302
+ if (handoffRefusal)
303
+ throw handoffRefusal;
296
304
  presentationOf(values);
297
305
  // `runCli` has already taken the handoff into custody and deleted its variable.
298
306
  const internal = holdsManagedHandoff() || Boolean(process.env[ENROLLMENT_URL_ENV] || process.env[ENROLLMENT_FILE_ENV]);
299
307
  if (!holdsManagedHandoff() && (values["expect-owner"] !== undefined || values["expect-lifecycle-uid"] !== undefined))
300
308
  throw new CommandFailure("refused", "USAGE_INVALID", `--expect-owner and --expect-lifecycle-uid apply only with ${MANAGED_HANDOFF_FILE_ENV}`);
301
- const direct = values.foreground === true || internal;
309
+ const direct = values.foreground === true || internal || !spawnUsesManager(values);
302
310
  if (values.file !== undefined && (args.positionals.length || values.config !== undefined))
303
311
  throw new CommandFailure("refused", "USAGE_INVALID", "choose one positional persona or --file/-f, not multiple explicit persona sources");
304
312
  if (!internal && values.config !== undefined)
@@ -315,21 +323,21 @@ export function validateSpawnArguments(args) {
315
323
  throw new CommandFailure("refused", "USAGE_INVALID", "manifest deployment options belong to cotal team deploy <file>, not spawn");
316
324
  if (values["enrollment-file"] !== undefined && !values.space)
317
325
  throw new CommandFailure("refused", "USAGE_INVALID", "--enrollment-file requires an explicit --space");
318
- if (values["enrollment-file"] !== undefined && !values.foreground)
319
- throw new CommandFailure("refused", "UNSUPPORTED", "this native enrollment path runs one foreground seat; use --foreground explicitly. It does not substitute for managed enrollment authority");
326
+ if (values["enrollment-file"] !== undefined && !direct)
327
+ throw new CommandFailure("refused", "UNSUPPORTED", "this native enrollment path runs one foreground seat. It does not substitute for managed enrollment authority");
320
328
  if (values["enrollment-file"] !== undefined && (internal || values.detach || values.creds !== undefined || values.on !== undefined))
321
329
  throw new CommandFailure("refused", "USAGE_INVALID", "choose one foreground enrollment source without a manager pin, credential override or internal handoff");
322
330
  if (values.harness !== undefined && values.agent !== undefined)
323
331
  throw new CommandFailure("refused", "USAGE_INVALID", "choose --harness/-H or the legacy --agent spelling, not both");
324
332
  if (values.detach && direct)
325
333
  throw new CommandFailure("refused", "USAGE_INVALID", "--detach and direct foreground execution are different launch modes");
326
- if (values.foreground && ((!values["dry-run"] && (values.json || values.plain)) || values.creds !== undefined || values.on !== undefined))
327
- throw new CommandFailure("refused", "USAGE_INVALID", "direct --foreground execution takes no structured receipt, manager credential or manager pin");
334
+ if (direct && ((!values["dry-run"] && (values.json || values.plain)) || values.creds !== undefined || values.on !== undefined))
335
+ throw new CommandFailure("refused", "USAGE_INVALID", "a spawn in this terminal takes no structured receipt, manager credential or manager pin", { remedy: "add -d to launch it through a manager, which returns a receipt once the agent joins", selfContained: true });
328
336
  if ((values.restarts === undefined) !== (values["restart-window"] === undefined))
329
337
  throw new CommandFailure("refused", "USAGE_INVALID", "--restarts and --restart-window must be supplied together");
330
338
  if (values.restarts !== undefined) {
331
339
  if (direct)
332
- throw new CommandFailure("refused", "USAGE_INVALID", "restart supervision belongs to a managed launch, not direct foreground execution");
340
+ throw new CommandFailure("refused", "USAGE_INVALID", "restart supervision belongs to a managed launch, not a spawn in this terminal", { remedy: "add -d, or --on <instance>, to launch it through a manager" });
333
341
  for (const field of ["restarts", "restart-window"])
334
342
  if (!/^[1-9][0-9]*$/.test(values[field]) || !Number.isSafeInteger(Number(values[field])))
335
343
  throw new CommandFailure("refused", "USAGE_INVALID", `--${field} must be a positive safe integer`);
@@ -337,7 +345,7 @@ export function validateSpawnArguments(args) {
337
345
  if (values["live-only"] && !direct)
338
346
  throw new CommandFailure("refused", "USAGE_INVALID", "--live-only belongs to direct foreground execution");
339
347
  if (!values["dry-run"] && !direct && !values.detach && (values.json || values.plain || inputDisabledByFlag() || !process.stdin.isTTY || !process.stdout.isTTY))
340
- throw new CommandFailure("refused", "USAGE_INVALID", "managed attachment needs usable input and output terminals before an identity is allocated", { remedy: "use cotal spawn -d to wait for readiness without attaching, or --foreground for direct execution" });
348
+ throw new CommandFailure("refused", "USAGE_INVALID", "attaching to a manager's launch needs usable input and output terminals before an identity is allocated", { remedy: "add -d to wait for readiness without attaching, or drop --on to run it in this terminal", selfContained: true });
341
349
  for (const field of ["harness", "agent", "model", "variant", "name"])
342
350
  if (values[field] !== undefined && !values[field].trim())
343
351
  throw new CommandFailure("refused", "USAGE_INVALID", `--${field} cannot be empty`);
@@ -377,6 +385,22 @@ export function validateSpawnArguments(args) {
377
385
  export function spawnRequiredExtensions(_args) {
378
386
  return [];
379
387
  }
388
+ /** Whether the installed manifest lists a connector named `name`. An unreadable manifest answers
389
+ * true, so the import's own refusal reports it. */
390
+ function connectorListed(name) {
391
+ try {
392
+ return manifestExtensionNames("connector").includes(name);
393
+ }
394
+ catch {
395
+ return true;
396
+ }
397
+ }
398
+ /** The refusal for a harness with no installed connector, naming the package when it is official. */
399
+ function missingConnector(name, target) {
400
+ const pkg = OFFICIAL_CONNECTORS[name];
401
+ return new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", `no connector "${name}" is installed`, { target,
402
+ remedy: pkg ? `add it with \`cotal ext add ${pkg}\`` : "install its integration with `cotal ext add <npm-package>`, or check the name" });
403
+ }
380
404
  /** Comma-list flag → string[] (shared by both spawn modes). Only an absent flag is `undefined` and
381
405
  * defers to the persona; an empty value is the empty list, so `--subscribe ""` clears it. */
382
406
  const splitFlag = (v) => (v === undefined ? undefined : v.split(",").map((s) => s.trim()).filter(Boolean));
@@ -389,16 +413,29 @@ const splitFlag = (v) => (v === undefined ? undefined : v.split(",").map((s) =>
389
413
  function refuseUnmintableNameOrExit(name, userMode) {
390
414
  const refusal = spawnNameError(name, { userMode });
391
415
  if (refusal) {
392
- console.error(c.red(`✗ ${refusal}`));
416
+ stderrLine("✗ ", `${refusal}`, c.red);
393
417
  process.exit(1);
394
418
  }
395
419
  }
396
- function managedLaunchView(r) {
420
+ /** The manager's `acl` launch field: null when the manager sent none, undefined when it cannot be read. */
421
+ export function managedLaunchAcl(value) {
422
+ if (value === undefined)
423
+ return null;
424
+ const lists = (raw) => {
425
+ const { allowSubscribe, allowPublish } = (raw ?? {});
426
+ const channels = (list) => Array.isArray(list) && list.every((channel) => typeof channel === "string");
427
+ return channels(allowSubscribe) && channels(allowPublish) ? { allowSubscribe: [...allowSubscribe], allowPublish: [...allowPublish] } : undefined;
428
+ };
429
+ const requested = lists(value?.requested), effective = lists(value?.effective);
430
+ return requested && effective ? { requested, effective } : undefined;
431
+ }
432
+ const channelList = (channels) => channels.length ? channels.join(", ") : "none";
433
+ export function managedLaunchView(r) {
397
434
  const concrete = [r.name, r.space, r.managerInstanceId].every((value) => /^[A-Za-z0-9_-]+$/.test(value));
398
435
  const target = concrete ? `${r.name} --space ${r.space} --on ${r.managerInstanceId}` : "<name> --space <space> --on <manager-instance>";
399
436
  return { sections: [
400
437
  { title: "Agent joined", blocks: [
401
- { kind: "fields", rows: [["Agent", r.name], ["Identity", r.id], ["Lifecycle", r.lifecycleUid], ["Space", r.space], ["Manager receipt", r.managerInstanceId], ["Original request", r.intent?.requestId ?? r.request?.requestId ?? "not recorded"], ["Accepted goal", r.request?.goalId ?? "not reported"], ["Application", r.harness], ["Runtime", r.runtime], ["Role", r.role ?? "not recorded"], ["Model request", r.requestedModel ?? "persona/manager precedence; not inspected"], ["View", r.detached ? "not attached" : "attaching to the allocated incarnation"]] },
438
+ { kind: "fields", rows: [["Agent", r.name], ["Identity", r.id], ["Lifecycle", r.lifecycleUid], ["Space", r.space], ["Manager receipt", r.managerInstanceId], ["Original request", r.intent?.requestId ?? r.request?.requestId ?? "not recorded"], ["Accepted goal", r.request?.goalId ?? "not reported"], ["Application", r.harness], ["Runtime", r.runtime], ["Role", r.role ?? "not recorded"], ...(r.acl ? [["Granted", `read ${channelList(r.acl.effective.allowSubscribe)} · post ${channelList(r.acl.effective.allowPublish)}; asked for read ${channelList(r.acl.requested.allowSubscribe)} · post ${channelList(r.acl.requested.allowPublish)}`]] : []), ["Model request", r.requestedModel ?? "persona/manager precedence; not inspected"], ["View", r.detached ? "not attached" : "attaching to the allocated incarnation"]] },
402
439
  { kind: "lines", lines: [{ text: "The manager confirmed presence readiness. This is not proof that the kickoff task completed.", tone: "hint" }] },
403
440
  ] },
404
441
  ...(r.detached ? [{ title: "Next", blocks: [{ kind: "commands", items: [
@@ -414,7 +451,7 @@ export async function launchManagedPersona(values, positionals, events, launchOp
414
451
  // `COTAL_DEFAULT_PERSONA` > `default`). Identity is separate:
415
452
  // when `--name` is given it OVERRIDES the file's `name:` (foreground's `requested`), threaded
416
453
  // as the op's `identity` so it is never silently dropped in detached mode.
417
- const on = onInstance(values.on, "cotal spawn <persona>");
454
+ const on = await managerPin(values, "cotal spawn <persona>");
418
455
  // From a managed seat's own shell the launch is the SEAT's, as its `cotal_spawn` tool is: the
419
456
  // manager records the seat as the spawner, so the seat can stop the child it asked for (#718).
420
457
  // `--on` keeps the pin on that path too.
@@ -422,6 +459,20 @@ export async function launchManagedPersona(values, positionals, events, launchOp
422
459
  const seatIntent = Boolean(process.env.COTAL_NAME || process.env.COTAL_ID || process.env.COTAL_LIFECYCLE_UID || process.env.COTAL_ACCEPTED_TOKEN);
423
460
  if (seatIntent && values.creds !== undefined)
424
461
  throw new CommandFailure("refused", "USAGE_INVALID", "a managed seat's child launch uses that seat's own caller, not a --creds override");
462
+ // On a terminal, a pinned manager that is not known to run on this host is asked which of its
463
+ // folders the agent works in, unless -C names one. The question holds no manager credential: a
464
+ // typed folder is checked under a view of that manager acquired after it is answered, and the
465
+ // launch acquires its own below.
466
+ let cwd = values.cwd;
467
+ if (cwd === undefined && on !== undefined && !seatIntent && canPrompt()) {
468
+ const selection = await managerSelection(values, on);
469
+ if (selection.manager.host !== hostname()) {
470
+ const folder = await askManagerFolder(selection, process.argv.slice(2), (path) => checkFolder(flags, on, path));
471
+ if (folder === null)
472
+ process.exit(0);
473
+ cwd = folder;
474
+ }
475
+ }
425
476
  let seat;
426
477
  if (seatIntent) {
427
478
  try {
@@ -451,7 +502,11 @@ export async function launchManagedPersona(values, positionals, events, launchOp
451
502
  if (eventsRequired && events === false) {
452
503
  throw new CommandFailure("refused", "PERMISSION_DENIED", `space "${t.space}" requires the event plane by registration policy; no launch was submitted`);
453
504
  }
454
- provenance.read("mesh", `${t.space} (${t.server})`);
505
+ if (on === undefined && !t.auth.bearer)
506
+ await refuseWithoutLiveManager(t.space, t.server, t.auth, { space: t.space, managerInstanceId: null, managerEpoch: null }, "launch an agent");
507
+ // A pin the registry does not list is refused at once; only a registered manager is waited on.
508
+ if (on !== undefined && !t.auth.bearer)
509
+ await refuseUnregisteredManager(t.space, t.server, t.auth, on);
455
510
  const { ref, from: personaFrom } = spawnPersona(values.config, positionals, { space: t.space, preferences: cachedPreferences() });
456
511
  const managerConfigRef = values.config ?? (personaFrom !== undefined ? ref : undefined);
457
512
  const defaultAgent = callerHarness(t.space);
@@ -463,8 +518,11 @@ export async function launchManagedPersona(values, positionals, events, launchOp
463
518
  resumeAgent = values.agent ?? await launchAgentOrExit(t, on, { name: ref, config: managerConfigRef, defaultAgent });
464
519
  resumeClaim = await carryTranscriptOrExit(flags, on, values.resume, resumeAgent);
465
520
  }
466
- console.error(renderReport({ space: t.space, sections: [{ title: "Managed launch", blocks: [{ kind: "fields", rows: [["Space", t.space], ["Manager selector", on ?? t.auth.managerInstanceId ?? "native class selection"], ["Persona", ref], ["File source", managerConfigRef ? `${managerConfigRef} · manager execution host` : "selected manager's persona catalog"], ["File transfer", "none"]] }, { kind: "lines", lines: [{ text: "The accepting manager validates its own visible file before allocation. No local file is uploaded, and a pin never selects a replacement manager.", tone: "hint" }] }] }] }, presentationOf(values) === "plain" ? "plain" : "rich", terminalWidth(process.stderr)));
467
- console.error(c.dim("waiting for it to join the mesh (the manager replies on a real outcome - join, exit, or ~30s) …"));
521
+ // The report that answers names the mesh in its heading, so this block names it once, in a field.
522
+ const toStdout = !observer && presentationOf(values) !== "json";
523
+ (toStdout ? console.log : console.error)(renderReport({ sections: [{ title: "Managed launch", blocks: [{ kind: "fields", rows: [["Space", t.space], ["Manager selector", on ?? t.auth.managerInstanceId ?? "native class selection"], ["Persona", ref], ["File source", managerConfigRef ? `${managerConfigRef} · manager execution host` : "selected manager's persona catalog"], ["File transfer", "none"]] }, { kind: "lines", lines: [{ text: "The accepting manager validates its own visible file before allocation. No local file is uploaded, and a pin never selects a replacement manager.", tone: "hint" }] }] }] }, presentationOf(values) === "plain" ? "plain" : "rich", terminalWidth(toStdout ? process.stdout : process.stderr)));
524
+ for (const line of wrapWords("waiting for the manager: it answers when it refuses the launch, or when the agent joins or exits (at most about 30s) …", terminalWidth(process.stderr)))
525
+ console.error(c.dim(line));
468
526
  const reply = await askManager(t.space, t.server, "start", {
469
527
  name: ref,
470
528
  identity: values.name,
@@ -481,7 +539,7 @@ export async function launchManagedPersona(values, positionals, events, launchOp
481
539
  variant: values.variant,
482
540
  ...(values.restarts !== undefined ? { supervise: { restarts: Number(values.restarts), windowMs: Number(values["restart-window"]) } } : {}),
483
541
  launchOptions,
484
- cwd: values.cwd,
542
+ cwd,
485
543
  resume: values.resume, // host-local session id; the manager preflights connector resume support
486
544
  ...(resumeClaim !== undefined ? { resumeClaim, resumeAgent } : {}),
487
545
  prompt: values.prompt,
@@ -502,15 +560,42 @@ export async function launchManagedPersona(values, positionals, events, launchOp
502
560
  const refusal = { "permission-denied": "PERMISSION_DENIED", "unauthenticated": "AUTH_REQUIRED", "not-found": "TARGET_NOT_FOUND", "unavailable": "TARGET_UNAVAILABLE", "bad-request": "SCHEMA_INVALID", "failed-precondition": "LIFECYCLE_BLOCKED", "already-exists": "CONFLICT", "unimplemented": "UNSUPPORTED" };
503
561
  const code = reply.code === undefined ? undefined : refusal[reply.code];
504
562
  const native = { code: reply.code, outcome: reply.nativeOutcome, ...(reply.request || reply.intent ? { detail: { request: reply.request ?? null, intent: reply.intent ?? null, observation: reply.observationCause ?? null } } : {}) };
505
- if (reply.nativeOutcome === "not-executed" && code)
506
- throw new CommandFailure("refused", code, reply.error ? oneLine(reply.error) : "the manager refused the launch before execution", { target, native, remedy: "nothing was launched; fix what the manager reported, then run the spawn again" });
563
+ // The broker attested that no manager received an unpinned launch: none takes the class queue.
564
+ if (on === undefined && !t.auth.bearer && reply.unanswered && reply.nativeOutcome === "not-executed")
565
+ throw await unservedClassLaunch(seat ? undefined : flags, t, values.agent ?? defaultAgent, { target, native });
566
+ // A pinned describe that drew no answer means the launch was never sent, as ps and stop --on say.
567
+ if (on !== undefined && describeUnanswered(reply))
568
+ throw new CommandFailure("refused", "TARGET_UNAVAILABLE", `manager instance ${on} did not answer, so the launch was not sent and nothing was launched`, { target, native: { code: reply.code, ...(reply.error ? { detail: oneLine(reply.error) } : {}) }, remedy: "cotal ps shows which managers answer; rerun the spawn on one of them with --on <instance>" });
569
+ // So does an unpinned one: no manager answered, and the launch was never published.
570
+ if (on === undefined && describeUnanswered(reply))
571
+ throw unansweredClassLaunch(t, { target, native: { code: reply.code, ...(reply.error ? { detail: oneLine(reply.error) } : {}) } });
572
+ // A manager without the connector: it is added where that manager runs, not on this machine.
573
+ const absent = reply.nativeOutcome === "not-executed" && reply.error !== undefined ? hintedConnector(reply.error) : undefined;
574
+ if (absent !== undefined) {
575
+ const answered = reply.managerInstanceId ?? on;
576
+ throw new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", `no connector "${absent}" is installed on ${answered ? await managerNamed(seat ? undefined : flags, t, answered) : "the manager"}; nothing was launched`, { target, native,
577
+ remedy: `add it where that manager runs, such as ${extAddFor(absent)}, then restart that manager; it reads its agent applications when it starts` });
578
+ }
579
+ if (reply.nativeOutcome === "not-executed" && code) {
580
+ // A manager without the persona: it is created on that manager's host, or the spawn goes to
581
+ // another live manager whose catalog has it.
582
+ const missing = managerConfigRef === undefined && reply.error?.startsWith(`no persona "${ref}"`) === true;
583
+ const elsewhere = missing ? await managersWithPersona(flags, reply.managerInstanceId ?? on, ref).catch(() => []) : [];
584
+ throw new CommandFailure("refused", code, reply.error ? oneLine(reply.error) : "the manager refused the launch before execution", { target, native, remedy: elsewhere.length
585
+ ? `nothing was launched; ${elsewhere.length === 1 ? "this manager of yours has" : "these managers of yours have"} ${ref === "default" ? "a default persona" : `persona "${ref}"`}: ${elsewhere.map((selector) => rerunOn(process.argv.slice(2), selector)).join(" or ")}`
586
+ : missing ? "nothing was launched; create that file on the manager's host, then run the spawn again"
587
+ : "nothing was launched; fix what the manager reported, then run the spawn again" });
588
+ }
507
589
  const unknown = reply.nativeOutcome !== "executed" || reply.unanswered;
508
590
  throw new CommandFailure(unknown ? "unknown" : "failed", unknown ? "OPERATION_UNKNOWN" : "OPERATION_FAILED", reply.error ? oneLine(reply.error) : "the manager did not confirm launch readiness", { target, native, remedy: "inspect cotal ps and the selected manager before retrying; this launch was not submitted again" });
509
591
  }
510
592
  const d = reply.data;
511
593
  if (!d || typeof d.name !== "string" || typeof d.id !== "string" || typeof d.lifecycleUid !== "string" || typeof d.agent !== "string" || typeof d.mode !== "string" || !reply.managerInstanceId)
512
594
  throw new CommandFailure("partial", "OPERATION_PARTIAL", "the manager reported a successful launch but did not supply the identity and manager needed for a safe handoff", { target, changed: [{ kind: "managed-launch", readinessReported: true }], remedy: "inspect cotal ps before doing anything else; do not relaunch" });
513
- const result = { kind: "managed-launch", name: d.name, id: d.id, lifecycleUid: d.lifecycleUid, space: t.space, managerInstanceId: reply.managerInstanceId, harness: d.agent, runtime: d.mode, role: d.role ?? null, request: reply.request ?? null, intent: reply.intent ?? null, readiness: "joined", requestedModel: values.model ?? null, detached: values.detach === true };
595
+ const acl = managedLaunchAcl(d.acl);
596
+ if (acl === undefined)
597
+ throw new CommandFailure("partial", "OPERATION_PARTIAL", "the agent joined, but the manager's report of the channels its host granted could not be read; no replacement was launched", { target, changed: [{ kind: "managed-launch", readinessReported: true }], remedy: "inspect cotal ps before doing anything else; do not relaunch" });
598
+ const result = { kind: "managed-launch", name: d.name, id: d.id, lifecycleUid: d.lifecycleUid, space: t.space, managerInstanceId: reply.managerInstanceId, harness: d.agent, runtime: d.mode, role: d.role ?? null, request: reply.request ?? null, intent: reply.intent ?? null, readiness: "joined", requestedModel: values.model ?? null, detached: values.detach === true, acl };
514
599
  const presentation = presentationOf(values);
515
600
  const warnings = d.eventsNotice ? [{ code: "EVENT_PLANE_NOTICE", target, message: d.eventsNotice }] : [];
516
601
  if (observer) {
@@ -538,6 +623,93 @@ export async function launchManagedPersona(values, positionals, events, launchOp
538
623
  throw new CommandFailure("partial", "OPERATION_PARTIAL", "the agent joined, but its exact native terminal was unavailable before setup could open the view; no replacement was launched", { target, changed: [result], remedy: "inspect the original lifecycle and manager before another startup" });
539
624
  console.error(renderReport({ sections: [{ title: verdict.kind === "gone" ? "Attach target unavailable" : verdict.reason === "detached" ? "Detached" : "Attach session ended", blocks: [{ kind: "fields", rows: [["Agent", d.name], ["Identity", d.id], ["Manager", reply.managerInstanceId]] }, { kind: "lines", lines: [{ text: "Leaving the view sent no stop request. The original lifecycle was not replaced.", tone: "hint" }] }] }] }, "rich", terminalWidth(process.stderr)));
540
625
  }
626
+ /** Whether the manager `on` pins can launch an agent in `path`, answered by its `resolve-cwd` over
627
+ * a view of that manager acquired for this check alone. A path it cannot use is its refusal; a
628
+ * check it does not answer refuses the launch. */
629
+ async function checkFolder(flags, on, path) {
630
+ const t = await resolveControlTarget(flags, "control-caller-privileged", on, { onRefusal: "throw" });
631
+ const reply = await askManager(t.space, t.server, "resolveCwd", { cwd: path }, t.auth, "owner", undefined, { instanceId: on });
632
+ const cwd = reply.ok ? reply.data?.cwd : undefined;
633
+ if (typeof cwd === "string")
634
+ return { cwd };
635
+ if (!reply.ok && reply.code === "failed-precondition" && reply.error)
636
+ return { refusal: oneLine(reply.error) };
637
+ throw new CommandFailure("refused", "TARGET_UNAVAILABLE", `manager instance ${on} did not check the folder ${JSON.stringify(path)}${reply.error ? ` (${oneLine(reply.error)})` : ""}, so nothing was launched`, {
638
+ target: { space: t.space, managerInstanceId: on },
639
+ remedy: "cotal ps shows which managers answer; run the spawn again",
640
+ });
641
+ }
642
+ /** Why no manager received an unpinned launch. A manager whose boot inventory found no agent
643
+ * application leaves the class queue, so when every live one that answered reports that on its own
644
+ * instance rail the refusal names the application to add. A manager the broker affirms gone is
645
+ * skipped and named in a warning, so its registration costs no deadline and hides no reason. A seat
646
+ * (`flags` undefined) does not read the census as the operator. `agent` is the harness this caller
647
+ * would choose, for the install hint. */
648
+ async function unservedClassLaunch(flags, t, agent, at) {
649
+ const census = flags ? await classLaunchCensus(flags, t).catch(() => undefined) : undefined;
650
+ for (const instanceId of census?.gone ?? [])
651
+ recordOperationWarning({ code: "MANAGER_SILENT", target: { space: t.space, managerInstanceId: instanceId }, message: `manager ${instanceId} was skipped: its registration is stale (the broker reports nothing subscribed on its rail; its host is gone and never deregistered)` });
652
+ if (census?.noApplication) {
653
+ return new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", `no manager of yours takes unpinned launches: none ${census.gone.length ? "that answered " : ""}has an agent application installed${census.managers.length ? ` (${census.managers.join(", ")})` : ""}; nothing was launched`, { ...at,
654
+ remedy: `add one where ${census.managers.length > 1 ? "one of them" : "that manager"} runs, such as ${extAddFor(agent ?? DEFAULT_CONNECTOR)}, then restart that manager; it reads its agent applications when it starts` });
655
+ }
656
+ return new CommandFailure("refused", "TARGET_UNAVAILABLE", "no manager of yours received this unpinned launch; nothing was launched", { ...at, remedy: "run the spawn again, or pin one manager with --on <instance> from cotal ps" });
657
+ }
658
+ /** Why no manager answered an unpinned launch's describe, so the launch was never sent. This root's
659
+ * own stack says why when it records one, in the words `ps` uses for the same silence. */
660
+ function unansweredClassLaunch(t, at) {
661
+ const refused = (message, remedy) => new CommandFailure("refused", "TARGET_UNAVAILABLE", `${message}, so the launch was not sent and nothing was launched`, { ...at, remedy });
662
+ if (t.root !== undefined && stackManagerStarting(t.root, t.space))
663
+ return refused("the stack's manager is starting", "run the spawn again once cotal up reports the manager started");
664
+ if (t.root !== undefined && stackManagerAbsent(t.root, t.space))
665
+ return refused("no manager is running for this space", "start the stack's manager with bare cotal up; a stack started with --no-manager has none");
666
+ const pid = t.root === undefined ? undefined : runningStackManagerPid(t.root, t.space);
667
+ if (pid !== undefined)
668
+ return refused(`this space's stack manager (pid ${pid}) is running but did not answer`, `if it stays unresponsive, end that process with kill -KILL ${pid}; then bare cotal up starts the manager again`);
669
+ return refused("no manager answered", "cotal ps shows which managers answer; run the spawn again once one does");
670
+ }
671
+ /** What the registered managers say about unpinned launches. `noApplication` holds when one answered
672
+ * and each one that answered says it runs agents but takes no unpinned launch; `gone` lists the
673
+ * managers skipped because the broker affirms nothing subscribed on their rail. Status has no
674
+ * scatter route, so each is read pinned to its instance, racing the rail probe: whichever settles
675
+ * first stops the other, so neither a live manager nor a gone one is waited out. */
676
+ async function classLaunchCensus(flags, t) {
677
+ const gone = [];
678
+ const managers = [];
679
+ for (const instanceId of await liveManagerIds(t.space, t.server, t.auth)) {
680
+ const pinned = await resolveControlTarget(flags, "control-caller-privileged", instanceId, { onRefusal: "throw" });
681
+ const settled = new AbortController();
682
+ const status = await Promise.race([
683
+ managerRailGone(pinned.space, pinned.server, pinned.auth, instanceId, settled.signal).then((isGone) => isGone ? undefined : new Promise(() => { })),
684
+ askManager(pinned.space, pinned.server, "managerStatus", undefined, pinned.auth, "owner", 5_000, { instanceId, signal: settled.signal }),
685
+ ]).finally(() => settled.abort());
686
+ if (status === undefined) {
687
+ gone.push(instanceId);
688
+ continue;
689
+ }
690
+ const data = status.data;
691
+ if (!status.ok || data?.classSpawn !== false || data.execution === "none")
692
+ return { noApplication: false, gone, managers };
693
+ managers.push(managerAt(instanceId, data.host));
694
+ }
695
+ return { noApplication: managers.length > 0, gone, managers };
696
+ }
697
+ /** A manager as a refusal names it: its instance id, and the host its own status reports. */
698
+ const managerAt = (instanceId, host) => typeof host === "string" && host ? `manager ${instanceId} on host ${host}` : `manager ${instanceId}`;
699
+ /** {@link managerAt} for one manager, read pinned to it. A seat (`flags` undefined) reads with its
700
+ * own caller, and a status that cannot be read leaves the host out. */
701
+ async function managerNamed(flags, t, instanceId) {
702
+ try {
703
+ const pinned = flags ? await resolveControlTarget(flags, "control-caller-privileged", instanceId, { onRefusal: "throw" }) : t;
704
+ const status = await askManager(pinned.space, pinned.server, "managerStatus", undefined, pinned.auth, "owner", 5_000, { instanceId });
705
+ return managerAt(instanceId, status.ok ? status.data?.host : undefined);
706
+ }
707
+ catch {
708
+ return managerAt(instanceId, undefined);
709
+ }
710
+ }
711
+ /** The `cotal ext add` that installs connector `name`, quoted for a refusal. */
712
+ const extAddFor = (name) => OFFICIAL_CONNECTORS[name] ? `\`cotal ext add ${OFFICIAL_CONNECTORS[name]}\`` : `\`cotal ext add <npm-package>\` for "${name}"`;
541
713
  /** The harness the manager's `spawn` resolves for this persona, read with the same fields `start` sends. */
542
714
  async function launchAgentOrExit(t, on, fields) {
543
715
  const reply = await askManager(t.space, t.server, "resolveAgent", fields, t.auth, "owner", undefined, { instanceId: on });
@@ -558,13 +730,13 @@ async function carryTranscriptOrExit(flags, on, id, agent) {
558
730
  found = registry.resolve("connector", agent).resumeTranscript?.find(id, process.env);
559
731
  }
560
732
  catch (e) {
561
- console.error(c.red(`✗ resume: ${e.message}`));
733
+ stderrLine("✗ ", `resume: ${e.message}`, c.red);
562
734
  process.exit(1);
563
735
  }
564
736
  if (found === undefined)
565
737
  return undefined;
566
738
  if (on === undefined) {
567
- console.error(c.red(`✗ resume: session ${id} is held on this host, and carrying it needs one manager instance; pass --on <instance>`));
739
+ stderrLine("✗ ", `resume: session ${id} is held on this host, and carrying it needs one manager instance; pass --on <instance>`, c.red);
568
740
  process.exit(1);
569
741
  }
570
742
  const bytes = readFileSync(found.path);
@@ -604,20 +776,21 @@ async function transferWriterOrExit(flags, t, instanceId, hex) {
604
776
  return { bearer: view.bearer, sentinelCreds: view.sentinelCreds, tls: conn.tls };
605
777
  }
606
778
  catch (e) {
607
- console.error(c.red(`✗ resume: ${e.message}`));
779
+ stderrLine("✗ ", `resume: ${e.message}`, c.red);
608
780
  process.exit(1);
609
781
  }
610
782
  }
611
783
  if (t.mode !== "auth" || !t.spaceAuth) {
612
- console.error(c.red("✗ resume: carrying a session mints a transfer writer from this mesh's signing seed, and this host holds none for it (an off-registry connection)"));
784
+ stderrLine("✗ ", "resume: carrying a session mints a transfer writer from this mesh's signing seed, and this host holds none for it (an off-registry connection)", c.red);
613
785
  process.exit(1);
614
786
  }
615
787
  return { creds: await mintCreds(t.spaceAuth, newIdentity(), "transfer-writer", { transferWriter: { instanceId, hex } }), tls: t.auth.tls };
616
788
  }
617
789
  /**
618
- * `cotal spawn [<persona>] [--file <persona-file>]` launches through the manager and attaches
619
- * to its allocated incarnation. `--detach` returns after readiness; `--foreground` explicitly
620
- * runs the native application in this terminal. File validation belongs to that execution host.
790
+ * `cotal spawn [<persona>] [--file <persona-file>]` runs the native application in this terminal.
791
+ * `--detach` launches it through a manager and returns after readiness, and `--on <instance>`
792
+ * launches it through that manager and attaches to its allocated incarnation. File validation
793
+ * belongs to the execution host.
621
794
  *
622
795
  * The launch recipe is the connector's `buildLaunch` (the single source of truth,
623
796
  * shared with the manager); only *how the spec runs* differs — foreground exec
@@ -670,25 +843,28 @@ export async function spawn(args) {
670
843
  scrubEnrollmentEnv(process.env);
671
844
  }
672
845
  let redeemedEnrollment;
846
+ let handoffManagerInstanceId;
673
847
  if (handoffText !== undefined) {
674
848
  const refusal = enrollmentUrl ? `${MANAGED_HANDOFF_FILE_ENV} cannot be combined with ${ENROLLMENT_URL_ENV}/${ENROLLMENT_FILE_ENV}`
675
849
  : values.detach || values.file || values.creds ? `${MANAGED_HANDOFF_FILE_ENV} applies only to a foreground persona spawn without --creds`
676
850
  : !values.space || !values.name || !values["expect-owner"] || !values["expect-lifecycle-uid"]
677
851
  ? `${MANAGED_HANDOFF_FILE_ENV} requires --space, --name, --expect-owner and --expect-lifecycle-uid`
678
852
  : !values.config ? `${MANAGED_HANDOFF_FILE_ENV} requires --config <persona-file>`
679
- : undefined;
853
+ : !process.env.COTAL_MANAGER_INSTANCE?.trim() ? `${MANAGED_HANDOFF_FILE_ENV} requires COTAL_MANAGER_INSTANCE`
854
+ : undefined;
680
855
  if (refusal) {
681
- console.error(c.red(`✗ ${refusal}`));
856
+ stderrLine("✗ ", `${refusal}`, c.red);
682
857
  process.exit(1);
683
858
  }
684
859
  try {
685
860
  loadLaunchPersonaFile(resolvePath(values.config));
686
861
  }
687
862
  catch (e) {
688
- console.error(c.red(`✗ cannot load the managed handoff persona: ${e.message}`));
863
+ stderrLine("✗ ", `cannot load the managed handoff persona: ${e.message}`, c.red);
689
864
  process.exit(1);
690
865
  }
691
866
  try {
867
+ handoffManagerInstanceId = assertLifecycleToken(process.env.COTAL_MANAGER_INSTANCE.trim(), "COTAL_MANAGER_INSTANCE");
692
868
  const handoff = parseManagedLifecycleHandoff(handoffText, {
693
869
  space: values.space, owner: values["expect-owner"], actor: values.name, lifecycleUid: values["expect-lifecycle-uid"],
694
870
  });
@@ -711,37 +887,48 @@ export async function spawn(args) {
711
887
  await registerEnrollmentMesh(stock, resolvePath(values.config, ".."), HANDOFF_REFUSALS);
712
888
  }
713
889
  catch (e) {
714
- console.error(c.red(`✗ ${e.message}`));
890
+ stderrLine("✗ ", `${e.message}`, c.red);
715
891
  process.exit(1);
716
892
  }
717
893
  }
718
894
  if (enrollmentUrl && values.detach) {
719
- console.error(c.red(`✗ ${ENROLLMENT_URL_ENV}/${ENROLLMENT_FILE_ENV} apply only to a foreground persona spawn`));
895
+ stderrLine("✗ ", `${ENROLLMENT_URL_ENV}/${ENROLLMENT_FILE_ENV} apply only to a foreground persona spawn`, c.red);
720
896
  process.exit(1);
721
897
  }
722
898
  if (enrollmentUrl && !values.space) {
723
- console.error(c.red(`✗ ${ENROLLMENT_URL_ENV}/${ENROLLMENT_FILE_ENV} require --space <s>`));
899
+ stderrLine("✗ ", `${ENROLLMENT_URL_ENV}/${ENROLLMENT_FILE_ENV} require --space <s>`, c.red);
724
900
  process.exit(1);
725
901
  }
726
- const direct = values.foreground === true || handoffText !== undefined || enrollmentUrl !== undefined;
902
+ // On a terminal, a spawn that names no launch mode, persona file or terminal-only option asks
903
+ // where it runs when several of your managers are live. This terminal is the default; a manager
904
+ // launches it and attaches here, as --on does.
905
+ if (handoffText === undefined && enrollmentUrl === undefined && values.foreground !== true && !spawnUsesManager(values) && values.file === undefined
906
+ && values.config === undefined && !values["live-only"] && !values.json && !values.plain && canPrompt()) {
907
+ const place = await askSpawnPlace(values, process.argv.slice(2));
908
+ if (place === null)
909
+ process.exit(0);
910
+ if (place)
911
+ values.on = place.instanceId;
912
+ }
913
+ const direct = values.foreground === true || handoffText !== undefined || enrollmentUrl !== undefined || !spawnUsesManager(values);
727
914
  const enrollmentBootstrap = Boolean(enrollmentUrl && values.space && !findMesh(values.space));
728
915
  if (enrollmentBootstrap) {
729
916
  if (!values.config || (!values.config.includes("/") && !values.config.includes("\\") && !values.config.endsWith(".md"))) {
730
- console.error(c.red("✗ enrollment bootstrap needs --config <persona-file>; no remote persona catalog exists on this machine yet"));
917
+ stderrLine("✗ ", "enrollment bootstrap needs --config <persona-file>; no remote persona catalog exists on this machine yet", c.red);
731
918
  process.exit(1);
732
919
  }
733
920
  try {
734
921
  loadLaunchPersonaFile(resolvePath(values.config));
735
922
  }
736
923
  catch (e) {
737
- console.error(c.red(`✗ cannot load the enrollment bootstrap persona: ${e.message}`));
924
+ stderrLine("✗ ", `cannot load the enrollment bootstrap persona: ${e.message}`, c.red);
738
925
  process.exit(1);
739
926
  }
740
927
  }
741
928
  // Explicit files retain the execution host's path semantics. A manager pin is meaningful for
742
929
  // either managed persona spelling; direct execution has no manager placement to select.
743
930
  if (values.on !== undefined && direct) {
744
- console.error(c.red("✗ --on pins a managed imperative launch; direct --foreground does not take that manager selector"));
931
+ stderrLine("✗ ", "--on pins a managed imperative launch; a spawn in this terminal does not take that manager selector", c.red);
745
932
  process.exit(1);
746
933
  }
747
934
  // `--resume ""` / `--resume=` means the operator asked to resume but named no session — fail loud
@@ -773,7 +960,7 @@ export async function spawn(args) {
773
960
  // grants publish on the channel the connector names. Both are required, which is what stops a
774
961
  // hand-written grant from turning events on by itself.
775
962
  if (values.events && values["no-events"]) {
776
- console.error(c.red("✗ --events and --no-events are mutually exclusive"));
963
+ stderrLine("✗ ", "--events and --no-events are mutually exclusive", c.red);
777
964
  process.exit(1);
778
965
  }
779
966
  // #373: the detached path sends the bit ONLY when the operator chose it. `--events` gives
@@ -781,15 +968,14 @@ export async function spawn(args) {
781
968
  // an explicit true from a non-admin caller as operator reach and serves an omission unarmed
782
969
  // with a notice, so an unconditional default-true would be refused for an ordinary actor.
783
970
  const events = values.events ? true : values["no-events"] ? false : undefined;
784
- // Managed by default; the persona remains on the manager's execution host. Direct foreground
785
- // execution keeps its separate native custody path below.
971
+ // A manager runs it only with --detach or --on, and the persona then stays on the manager's
972
+ // execution host. Every other spawn keeps the native custody path below, in this terminal.
786
973
  if (!direct)
787
974
  return launchManagedPersona(values, positionals, events, cliLaunchOptions);
788
- console.error(renderReport({ sections: [{ title: "Direct application", blocks: [{ kind: "lines", lines: ["This is native foreground execution, not a detachable Cotal view.", { text: "Native exit, Ctrl-C or terminal loss may end this process. No crash or reboot survival is promised.", tone: "hint" }] }] }] }, "rich", terminalWidth(process.stderr)));
789
975
  // `--creds` names a CONTROL-CALLER credential (reach an off-registry manager) — meaningless for
790
976
  // a foreground launch, which provisions the agent's own creds. Fail loud, never ignore.
791
977
  if (values.creds) {
792
- console.error(c.red("✗ --creds is only valid with --detach (it authenticates the manager control call)"));
978
+ stderrLine("✗ ", "--creds is only valid with --detach (it authenticates the manager control call)", c.red);
793
979
  process.exit(1);
794
980
  }
795
981
  // An enrollment may bootstrap the stock remote user-mesh record before normal target resolution.
@@ -813,7 +999,7 @@ export async function spawn(args) {
813
999
  await registerEnrollmentMesh(redeemedEnrollment.stock, resolvePath(values.config, ".."));
814
1000
  }
815
1001
  catch (e) {
816
- console.error(c.red(`✗ ${e.message}`));
1002
+ stderrLine("✗ ", `${e.message}`, c.red);
817
1003
  process.exit(1);
818
1004
  }
819
1005
  }
@@ -824,11 +1010,11 @@ export async function spawn(args) {
824
1010
  const target = handoffText === undefined
825
1011
  ? await resolveTargetOrExit({ server: values.server, space: values.space })
826
1012
  : await resolveTargetOrThrow({ server: values.server, space: values.space }).catch(() => {
827
- console.error(c.red(`✗ ${HANDOFF_REFUSALS.target}`));
1013
+ stderrLine("✗ ", `${HANDOFF_REFUSALS.target}`, c.red);
828
1014
  process.exit(1);
829
1015
  });
830
1016
  if (handoffText !== undefined && !(target.mode === "user" && target.userAuth?.remote)) {
831
- console.error(c.red("✗ the managed handoff's space is registered here as a local mesh, so it cannot host a managed handoff"));
1017
+ stderrLine("✗ ", "the managed handoff's space is registered here as a local mesh, so it cannot host a managed handoff", c.red);
832
1018
  process.exit(1);
833
1019
  }
834
1020
  let policy;
@@ -836,14 +1022,14 @@ export async function spawn(args) {
836
1022
  policy = await refreshRegistrationPolicy(target);
837
1023
  }
838
1024
  catch (e) {
839
- console.error(c.red(`✗ ${handoffText === undefined ? e.message : HANDOFF_REFUSALS.policy}`));
1025
+ stderrLine("✗ ", `${handoffText === undefined ? e.message : HANDOFF_REFUSALS.policy}`, c.red);
840
1026
  process.exit(1);
841
1027
  }
842
1028
  const eventsRequired = policy?.events === "required";
843
1029
  // A handoff's space is a value from the document, so its policy refusals name the field instead.
844
1030
  const policySpace = handoffText === undefined ? `space "${target.space}"` : "the managed handoff's space";
845
1031
  if (eventsRequired && values["no-events"]) {
846
- console.error(c.red(`✗ ${policySpace} requires the event plane by registration policy; --no-events is not allowed`));
1032
+ stderrLine("✗ ", `${policySpace} requires the event plane by registration policy; --no-events is not allowed`, c.red);
847
1033
  process.exit(1);
848
1034
  }
849
1035
  // Foreground is the operator's own in-process launch (no typed door, no epAdminReach) and is
@@ -865,31 +1051,16 @@ export async function spawn(args) {
865
1051
  if (e instanceof PersonaSourceError)
866
1052
  throw new CommandFailure("refused", "SCHEMA_INVALID", e.message, { target: { space, path }, remedy: "use cotal team deploy <file> for a Mesh manifest; use a native persona file for spawn" });
867
1053
  const code = e.code;
868
- const fromEnv = personaFrom === undefined ? "" : ` from ${personaFrom}`;
869
1054
  // The not-found text names the mesh's space and server, which for a handoff are its values.
870
1055
  if (handoffText !== undefined) {
871
- console.error(c.red(`✗ cannot load the managed handoff persona: ${e.message}`));
872
- }
873
- else if (code === "ENOENT" && path !== join(target.personaRoot, `${ref}.md`)) {
874
- // A path reference opened that one file and never read the catalog, so name the file.
875
- console.error(c.red(`✗ no persona "${ref}"${fromEnv} - ${path} not found`));
1056
+ stderrLine("✗ ", `cannot load the managed handoff persona: ${e.message}`, c.red);
876
1057
  }
877
1058
  else if (code === "ENOENT") {
878
- // A refusal that names no root is why this bug cost an hour. The old text asserted an absence
879
- // ("no default persona yet") and prescribed a remedy (`cotal setup`) without saying WHERE it
880
- // had looked — so when setup seeded a cwd-derived root and spawn read the resolved mesh's,
881
- // the message survived running the exact command it named and pointed at nothing to check.
882
- // Name the absolute directory checked and the mesh that root came from: the two facts that
883
- // make the disagreement visible in one read.
884
- const where = `${target.personaRoot} (mesh "${target.space}" at ${target.server}${target.source === "current" ? ", your current mesh" : target.source === "registry" ? ", the only mesh running" : ""})`;
885
- const fix = defaultPersonaFix(target);
886
- const write = fix.cwd ? `run \`${fix.command}\` in ${fix.cwd} to write one` : `create one with \`${fix.command}\``;
887
- console.error(c.red(ref === "default" && personaFrom === undefined
888
- ? `✗ no default persona in ${where} - ${write}, or name a persona: \`cotal spawn <name>\``
889
- : `✗ no persona "${ref}"${fromEnv} in ${where} - pass a catalog name, or use \`--config <path>\` for a file elsewhere`));
1059
+ const missing = missingPersona(target, ref, personaFrom, path);
1060
+ throw new CommandFailure("refused", "TARGET_NOT_FOUND", missing.message, { target: { space, path }, remedy: missing.remedy });
890
1061
  }
891
1062
  else {
892
- console.error(c.red(`✗ ${e.message}`));
1063
+ stderrLine("✗ ", `${e.message}`, c.red);
893
1064
  }
894
1065
  process.exit(1);
895
1066
  }
@@ -907,7 +1078,7 @@ export async function spawn(args) {
907
1078
  // Opaque connector options: `--opt` flags win per key over the persona's `launchOptions:`.
908
1079
  const launchOptions = mergeLaunchOptions(def.launchOptions, cliLaunchOptions);
909
1080
  if (redeemedEnrollment && redeemedEnrollment.bundle.actor !== requested) {
910
- console.error(c.red(`✗ the enrollment is for actor "${redeemedEnrollment.bundle.actor}" but this spawn names "${requested}"`));
1081
+ stderrLine("✗ ", `the enrollment is for actor "${redeemedEnrollment.bundle.actor}" but this spawn names "${requested}"`, c.red);
911
1082
  process.exit(1);
912
1083
  }
913
1084
  // #867: same door as the detached path — the effective identity (flag or file) must be mintable
@@ -926,12 +1097,12 @@ export async function spawn(args) {
926
1097
  launchOptions,
927
1098
  });
928
1099
  if (refusal) {
929
- console.error(c.red(`✗ ${refusal}`));
1100
+ stderrLine("✗ ", `${refusal}`, c.red);
930
1101
  process.exit(1);
931
1102
  }
932
1103
  }
933
1104
  catch (e) {
934
- console.error(c.red(`✗ ${e.message}`));
1105
+ stderrLine("✗ ", `${e.message}`, c.red);
935
1106
  process.exit(1);
936
1107
  }
937
1108
  // Preflight: fail with one sentence if the mesh is down or won't take our creds, instead of
@@ -940,7 +1111,7 @@ export async function spawn(args) {
940
1111
  await preflightOrExit(target);
941
1112
  else
942
1113
  await preflightOrThrow(target).catch(() => {
943
- console.error(c.red(`✗ ${HANDOFF_REFUSALS.preflight}`));
1114
+ stderrLine("✗ ", `${HANDOFF_REFUSALS.preflight}`, c.red);
944
1115
  process.exit(1);
945
1116
  });
946
1117
  // User mode allocates during guarded provisioning below, without a static operator credential.
@@ -958,7 +1129,9 @@ export async function spawn(args) {
958
1129
  await materializeExtension({ kind: "connector", name: agentType });
959
1130
  }
960
1131
  catch (e) {
961
- console.error(c.red(`✗ ${e.message}`));
1132
+ if (!connectorListed(agentType))
1133
+ throw missingConnector(agentType, { space, path });
1134
+ stderrLine("✗ ", `${e.message}`, c.red);
962
1135
  process.exit(1);
963
1136
  }
964
1137
  let connector;
@@ -966,15 +1139,15 @@ export async function spawn(args) {
966
1139
  connector = registry.resolve("connector", agentType);
967
1140
  }
968
1141
  catch (e) {
969
- console.error(c.red(`✗ ${e.message}`));
1142
+ stderrLine("✗ ", `${e.message}`, c.red);
970
1143
  process.exit(1);
971
1144
  }
972
1145
  if (variant && !connector.supportsModelVariant) {
973
- console.error(c.red(`✗ ${agentType} connector does not support model variants (variant)`));
1146
+ stderrLine("✗ ", `${agentType} connector does not support model variants (variant)`, c.red);
974
1147
  process.exit(1);
975
1148
  }
976
1149
  if (values.prompt !== undefined && !connector.supportsPrompt) {
977
- console.error(c.red(`✗ ${agentType} connector does not support an initial prompt (prompt)`));
1150
+ stderrLine("✗ ", `${agentType} connector does not support an initial prompt (prompt)`, c.red);
978
1151
  process.exit(1);
979
1152
  }
980
1153
  // Which of the operator's personal MCP servers to share with this agent: declared in the cotal
@@ -1017,7 +1190,7 @@ export async function spawn(args) {
1017
1190
  allowSubscribe = resolveReadAcl(subscribe ?? [], splitFlag(values["allow-subscribe"]) ?? def.allowSubscribe);
1018
1191
  }
1019
1192
  catch (e) {
1020
- console.error(c.red(`✗ ${e.message}`));
1193
+ stderrLine("✗ ", `${e.message}`, c.red);
1021
1194
  process.exit(1);
1022
1195
  }
1023
1196
  let allowPublish = splitFlag(values["allow-publish"]) ?? def.allowPublish;
@@ -1040,10 +1213,12 @@ export async function spawn(args) {
1040
1213
  ? target.userAuth.endpoints?.agentProvisioningUrl
1041
1214
  : undefined;
1042
1215
  if (target.mode === "user" && target.userAuth?.remote && !remoteProvisioningUrl && !enrollmentUrl && !redeemedEnrollment) {
1043
- console.error(c.red(`✗ mesh "${target.space}" runs elsewhere and advertises no agent-provisioning endpoint, so agents cannot be provisioned from this machine`));
1044
- console.error(c.dim(` a user-mode agent's credentials are granted where the mesh's signer lives; ask the mesh operator to advertise one (\`cotal up --agent-provisioning-url …\`), or run the agent there`));
1216
+ stderrLine("✗ ", `mesh "${target.space}" runs elsewhere and advertises no agent-provisioning endpoint, so agents cannot be provisioned from this machine`, c.red);
1217
+ console.error(c.dim(` a user-mode agent's credentials are granted where the mesh's signer lives; ask the mesh operator to advertise one (\`cotal up --agent-provisioning-url …\`), run the agent there, or add -d to launch it through one of your managers`));
1045
1218
  process.exit(1);
1046
1219
  }
1220
+ // Said once every check above has passed, so a refusal is never read as a launch that started.
1221
+ console.error(renderReport({ sections: [{ title: "Direct application", blocks: [{ kind: "lines", lines: ["This is native foreground execution, not a detachable Cotal view.", { text: "Native exit, Ctrl-C or terminal loss may end this process. No crash or reboot survival is promised.", tone: "hint" }] }] }] }, "rich", terminalWidth(process.stderr)));
1047
1222
  // Auth mode provisions the identity + writes its creds to disk BEFORE the connector validates the
1048
1223
  // launch (e.g. `buildLaunch` throws on a rejected `--opt`) and before the child execs. The SAME
1049
1224
  // retirement serves a failed provisioning or launch (rollback) and the normal foreground
@@ -1068,7 +1243,7 @@ export async function spawn(args) {
1068
1243
  await attemptCleanup(failed, "broker teardown", () => mintCreds(auth, newIdentity(), "deprovisioner", { deprovisionTarget: { principal: targetId, lifecycleUid } })
1069
1244
  .then((dc) => deprovisionAgent({ servers: server, space, targetId, lifecycleUid, creds: dc })));
1070
1245
  if (failed.length)
1071
- console.error(c.red(`✗ cleaning up after ${name}: ${describeCleanupFailures(failed)}`));
1246
+ stderrLine("✗ ", `cleaning up after ${name}: ${describeCleanupFailures(failed)}`, c.red);
1072
1247
  else
1073
1248
  console.error(` ↩ retired creds for ${name} (${why})`);
1074
1249
  };
@@ -1076,7 +1251,7 @@ export async function spawn(args) {
1076
1251
  if (!redeemedEnrollment) {
1077
1252
  // The record alone decides this refusal, and the redemption below spends the enrollment.
1078
1253
  if (!target.userAuth.endpoints?.url) {
1079
- console.error(c.red(`✗ ${noExchangeEndpoint(space)}`));
1254
+ stderrLine("✗ ", `${noExchangeEndpoint(space)}`, c.red);
1080
1255
  process.exit(1);
1081
1256
  }
1082
1257
  try {
@@ -1087,21 +1262,21 @@ export async function spawn(args) {
1087
1262
  redeemedEnrollment = checkEnrollmentBundle(body, name);
1088
1263
  }
1089
1264
  catch (e) {
1090
- console.error(c.red(`✗ ${e.message}`));
1265
+ stderrLine("✗ ", `${e.message}`, c.red);
1091
1266
  process.exit(1);
1092
1267
  }
1093
1268
  }
1094
1269
  const enrolled = redeemedEnrollment.bundle;
1095
1270
  if (enrolled.space !== space) {
1096
- console.error(c.red(`✗ the enrollment is for space "${enrolled.space}" but this spawn targets "${space}"`));
1271
+ stderrLine("✗ ", `the enrollment is for space "${enrolled.space}" but this spawn targets "${space}"`, c.red);
1097
1272
  process.exit(1);
1098
1273
  }
1099
1274
  if (enrolled.idp.url !== target.userAuth.idp.url || enrolled.idp.issuer !== target.userAuth.idp.issuer || enrolled.idp.audience !== target.userAuth.idp.audience) {
1100
- console.error(c.red("✗ the enrollment's IdP pins do not match the registered mesh"));
1275
+ stderrLine("✗ ", "the enrollment's IdP pins do not match the registered mesh", c.red);
1101
1276
  process.exit(1);
1102
1277
  }
1103
1278
  if (target.userAuth.endpoints?.url !== enrolled.authServiceUrl) {
1104
- console.error(c.red("✗ the enrollment's authServiceUrl does not match the registered mesh exchange"));
1279
+ stderrLine("✗ ", "the enrollment's authServiceUrl does not match the registered mesh exchange", c.red);
1105
1280
  process.exit(1);
1106
1281
  }
1107
1282
  const remote = await provisionRemoteUserForeground(target, name, { body: enrolled, exchangeUrl: enrolled.authServiceUrl }, handoffText === undefined ? undefined : HANDOFF_REFUSALS);
@@ -1266,6 +1441,7 @@ export async function spawn(args) {
1266
1441
  // construction because its write-ahead log had nowhere to live that a later start would look.
1267
1442
  workspaceRoot: target.root,
1268
1443
  });
1444
+ applyHandoffManagerInstance(spec, handoffManagerInstanceId);
1269
1445
  artifacts = spec.artifacts;
1270
1446
  scrubEnrollmentEnv(spec.env);
1271
1447
  // What happens next belongs to the CONNECTOR: naming one harness's first-run gate for all of
@@ -1300,7 +1476,7 @@ export async function spawn(args) {
1300
1476
  // other's mode): revoke the user-mode actor grant AND roll back the static-auth creds + footprint,
1301
1477
  // before rethrowing, so no standing grant survives a spawn that never started.
1302
1478
  if (userCleanup)
1303
- await userCleanup().catch((err) => console.error(c.red(`✗ cleaning up after ${name}: ${err.message}`)));
1479
+ await userCleanup().catch((err) => stderrLine("✗ ", `cleaning up after ${name}: ${err.message}`, c.red));
1304
1480
  await retireProvision("launch build failed");
1305
1481
  // The launch's private files (core launch-artifacts) go too: no child will read them.
1306
1482
  discardLaunchArtifacts(artifacts);
@@ -1310,7 +1486,7 @@ export async function spawn(args) {
1310
1486
  child.on("error", (e) => {
1311
1487
  // The exec never started, so the just-provisioned static-auth identity is orphaned — roll it
1312
1488
  // back. (User-mode revoke runs unconditionally once this promise settles, below.)
1313
- console.error(`✗ failed to launch ${spec.command}: ${e.message}`);
1489
+ stderrLine("✗ ", `failed to launch ${spec.command}: ${e.message}`, (line) => line);
1314
1490
  void retireProvision("exec failed").finally(() => {
1315
1491
  process.exitCode = 1;
1316
1492
  resolve();
@@ -1331,7 +1507,7 @@ export async function spawn(args) {
1331
1507
  // (a SIGKILLed CLI can't run this; its retained grant needs operator recovery), loud
1332
1508
  // on failure, never blocking the exit code already set above.
1333
1509
  if (userCleanup)
1334
- await userCleanup().catch((e) => console.error(c.red(`✗ cleaning up after ${name}: ${e.message}`)));
1510
+ await userCleanup().catch((e) => stderrLine("✗ ", `cleaning up after ${name}: ${e.message}`, c.red));
1335
1511
  // The child has exited or never started, so nothing reads the launch's private files any more
1336
1512
  // (core launch-artifacts). A SIGKILLed CLI cannot run this; the child's watcher removes those.
1337
1513
  discardLaunchArtifacts(spec.artifacts);
@@ -1420,7 +1596,7 @@ async function provisionRemoteUserForeground(target, name, source, refusals) {
1420
1596
  const store = workspaceSecretStore(target.root);
1421
1597
  const composition = { injected: false, root: target.root };
1422
1598
  const fail = (msg) => {
1423
- console.error(c.red(`✗ ${msg}`));
1599
+ stderrLine("✗ ", `${msg}`, c.red);
1424
1600
  process.exit(1);
1425
1601
  };
1426
1602
  // Resolved first, as by every consumer of the space's local state: each resolution migrates a
@@ -1556,7 +1732,7 @@ async function provisionUserForeground(target, name, ref, opts) {
1556
1732
  const store = workspaceSecretStore(target.root);
1557
1733
  const composition = { injected: false, root: target.root };
1558
1734
  const fail = (msg) => {
1559
- console.error(c.red(`✗ ${msg}`));
1735
+ stderrLine("✗ ", `${msg}`, c.red);
1560
1736
  process.exit(1);
1561
1737
  };
1562
1738
  let provider;