@cotal-ai/cli 0.90.1 → 0.92.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (775) hide show
  1. package/dist/chat/chat-view.d.ts +17 -0
  2. package/dist/chat/chat-view.d.ts.map +1 -0
  3. package/dist/chat/chat-view.js +179 -0
  4. package/dist/chat/chat-view.js.map +1 -0
  5. package/dist/chat/controller.d.ts +20 -0
  6. package/dist/chat/controller.d.ts.map +1 -0
  7. package/dist/chat/controller.js +132 -0
  8. package/dist/chat/controller.js.map +1 -0
  9. package/dist/chat/engine.d.ts +110 -0
  10. package/dist/chat/engine.d.ts.map +1 -0
  11. package/dist/chat/engine.js +224 -0
  12. package/dist/chat/engine.js.map +1 -0
  13. package/dist/chat/frontend.d.ts +35 -0
  14. package/dist/chat/frontend.d.ts.map +1 -0
  15. package/dist/chat/frontend.js +166 -0
  16. package/dist/chat/frontend.js.map +1 -0
  17. package/dist/chat/native-session.d.ts +93 -0
  18. package/dist/chat/native-session.d.ts.map +1 -0
  19. package/dist/chat/native-session.js +389 -0
  20. package/dist/chat/native-session.js.map +1 -0
  21. package/dist/chat/open-session.d.ts +8 -0
  22. package/dist/chat/open-session.d.ts.map +1 -0
  23. package/dist/chat/open-session.js +120 -0
  24. package/dist/chat/open-session.js.map +1 -0
  25. package/dist/chat/picker.d.ts +35 -0
  26. package/dist/chat/picker.d.ts.map +1 -0
  27. package/dist/chat/picker.js +99 -0
  28. package/dist/chat/picker.js.map +1 -0
  29. package/dist/chat/plain.d.ts +15 -0
  30. package/dist/chat/plain.d.ts.map +1 -0
  31. package/dist/chat/plain.js +249 -0
  32. package/dist/chat/plain.js.map +1 -0
  33. package/dist/chat/session.d.ts +222 -0
  34. package/dist/chat/session.d.ts.map +1 -0
  35. package/dist/chat/session.js +2 -0
  36. package/dist/chat/session.js.map +1 -0
  37. package/dist/chat/static-session.d.ts +61 -0
  38. package/dist/chat/static-session.d.ts.map +1 -0
  39. package/dist/chat/static-session.js +212 -0
  40. package/dist/chat/static-session.js.map +1 -0
  41. package/dist/chat/stdio-io.d.ts +35 -0
  42. package/dist/chat/stdio-io.d.ts.map +1 -0
  43. package/dist/chat/stdio-io.js +176 -0
  44. package/dist/chat/stdio-io.js.map +1 -0
  45. package/dist/chat/stdio.d.ts +173 -0
  46. package/dist/chat/stdio.d.ts.map +1 -0
  47. package/dist/chat/stdio.js +401 -0
  48. package/dist/chat/stdio.js.map +1 -0
  49. package/dist/chat/user-session.d.ts +21 -0
  50. package/dist/chat/user-session.d.ts.map +1 -0
  51. package/dist/chat/user-session.js +180 -0
  52. package/dist/chat/user-session.js.map +1 -0
  53. package/dist/chat/view.d.ts +217 -0
  54. package/dist/chat/view.d.ts.map +1 -0
  55. package/dist/chat/view.js +433 -0
  56. package/dist/chat/view.js.map +1 -0
  57. package/dist/command.d.ts +11 -3
  58. package/dist/command.d.ts.map +1 -1
  59. package/dist/command.js +395 -147
  60. package/dist/command.js.map +1 -1
  61. package/dist/commands/agents.d.ts +103 -11
  62. package/dist/commands/agents.d.ts.map +1 -1
  63. package/dist/commands/agents.js +506 -251
  64. package/dist/commands/agents.js.map +1 -1
  65. package/dist/commands/app-identity.d.ts.map +1 -1
  66. package/dist/commands/app-identity.js +10 -1
  67. package/dist/commands/app-identity.js.map +1 -1
  68. package/dist/commands/backup-maintenance.d.ts +4 -0
  69. package/dist/commands/backup-maintenance.d.ts.map +1 -0
  70. package/dist/commands/backup-maintenance.js +93 -0
  71. package/dist/commands/backup-maintenance.js.map +1 -0
  72. package/dist/commands/backup-read.d.ts +4 -0
  73. package/dist/commands/backup-read.d.ts.map +1 -0
  74. package/dist/commands/backup-read.js +30 -0
  75. package/dist/commands/backup-read.js.map +1 -0
  76. package/dist/commands/backup-restore.d.ts +7 -0
  77. package/dist/commands/backup-restore.d.ts.map +1 -0
  78. package/dist/commands/backup-restore.js +78 -0
  79. package/dist/commands/backup-restore.js.map +1 -0
  80. package/dist/commands/backup.d.ts +2 -1
  81. package/dist/commands/backup.d.ts.map +1 -1
  82. package/dist/commands/backup.js +123 -32
  83. package/dist/commands/backup.js.map +1 -1
  84. package/dist/commands/channel-members.d.ts +8 -0
  85. package/dist/commands/channel-members.d.ts.map +1 -0
  86. package/dist/commands/channel-members.js +144 -0
  87. package/dist/commands/channel-members.js.map +1 -0
  88. package/dist/commands/channels.d.ts +75 -22
  89. package/dist/commands/channels.d.ts.map +1 -1
  90. package/dist/commands/channels.js +181 -100
  91. package/dist/commands/channels.js.map +1 -1
  92. package/dist/commands/chat.d.ts +109 -0
  93. package/dist/commands/chat.d.ts.map +1 -0
  94. package/dist/commands/chat.js +227 -0
  95. package/dist/commands/chat.js.map +1 -0
  96. package/dist/commands/clean.d.ts +43 -1
  97. package/dist/commands/clean.d.ts.map +1 -1
  98. package/dist/commands/clean.js +90 -47
  99. package/dist/commands/clean.js.map +1 -1
  100. package/dist/commands/completion.d.ts +39 -1
  101. package/dist/commands/completion.d.ts.map +1 -1
  102. package/dist/commands/completion.js +211 -87
  103. package/dist/commands/completion.js.map +1 -1
  104. package/dist/commands/config.d.ts +33 -0
  105. package/dist/commands/config.d.ts.map +1 -0
  106. package/dist/commands/config.js +159 -0
  107. package/dist/commands/config.js.map +1 -0
  108. package/dist/commands/console.d.ts.map +1 -1
  109. package/dist/commands/console.js +25 -7
  110. package/dist/commands/console.js.map +1 -1
  111. package/dist/commands/describe.d.ts +63 -31
  112. package/dist/commands/describe.d.ts.map +1 -1
  113. package/dist/commands/describe.js +270 -136
  114. package/dist/commands/describe.js.map +1 -1
  115. package/dist/commands/doctor.d.ts +11 -6
  116. package/dist/commands/doctor.d.ts.map +1 -1
  117. package/dist/commands/doctor.js +195 -288
  118. package/dist/commands/doctor.js.map +1 -1
  119. package/dist/commands/down-services.d.ts +29 -0
  120. package/dist/commands/down-services.d.ts.map +1 -0
  121. package/dist/commands/down-services.js +129 -0
  122. package/dist/commands/down-services.js.map +1 -0
  123. package/dist/commands/down.d.ts +37 -11
  124. package/dist/commands/down.d.ts.map +1 -1
  125. package/dist/commands/down.js +384 -117
  126. package/dist/commands/down.js.map +1 -1
  127. package/dist/commands/endpoint-authoring.d.ts +6 -0
  128. package/dist/commands/endpoint-authoring.d.ts.map +1 -0
  129. package/dist/commands/endpoint-authoring.js +130 -0
  130. package/dist/commands/endpoint-authoring.js.map +1 -0
  131. package/dist/commands/endpoint-deregister.d.ts +5 -0
  132. package/dist/commands/endpoint-deregister.d.ts.map +1 -0
  133. package/dist/commands/endpoint-deregister.js +70 -0
  134. package/dist/commands/endpoint-deregister.js.map +1 -0
  135. package/dist/commands/endpoint.d.ts +118 -0
  136. package/dist/commands/endpoint.d.ts.map +1 -0
  137. package/dist/commands/endpoint.js +177 -0
  138. package/dist/commands/endpoint.js.map +1 -0
  139. package/dist/commands/endpoints.d.ts +27 -1
  140. package/dist/commands/endpoints.d.ts.map +1 -1
  141. package/dist/commands/endpoints.js +42 -30
  142. package/dist/commands/endpoints.js.map +1 -1
  143. package/dist/commands/ext.d.ts +38 -1
  144. package/dist/commands/ext.d.ts.map +1 -1
  145. package/dist/commands/ext.js +84 -49
  146. package/dist/commands/ext.js.map +1 -1
  147. package/dist/commands/feedback.d.ts +58 -1
  148. package/dist/commands/feedback.d.ts.map +1 -1
  149. package/dist/commands/feedback.js +119 -47
  150. package/dist/commands/feedback.js.map +1 -1
  151. package/dist/commands/help.d.ts +20 -0
  152. package/dist/commands/help.d.ts.map +1 -0
  153. package/dist/commands/help.js +52 -0
  154. package/dist/commands/help.js.map +1 -0
  155. package/dist/commands/history-clear.d.ts +14 -0
  156. package/dist/commands/history-clear.d.ts.map +1 -0
  157. package/dist/commands/history-clear.js +74 -0
  158. package/dist/commands/history-clear.js.map +1 -0
  159. package/dist/commands/history.d.ts +146 -4
  160. package/dist/commands/history.d.ts.map +1 -1
  161. package/dist/commands/history.js +437 -19
  162. package/dist/commands/history.js.map +1 -1
  163. package/dist/commands/join.d.ts.map +1 -1
  164. package/dist/commands/join.js +7 -3
  165. package/dist/commands/join.js.map +1 -1
  166. package/dist/commands/meshes-add.d.ts +3 -0
  167. package/dist/commands/meshes-add.d.ts.map +1 -1
  168. package/dist/commands/meshes-add.js +41 -34
  169. package/dist/commands/meshes-add.js.map +1 -1
  170. package/dist/commands/meshes-wizard.js +3 -3
  171. package/dist/commands/meshes-wizard.js.map +1 -1
  172. package/dist/commands/mint-endpoint-caller.d.ts +5 -0
  173. package/dist/commands/mint-endpoint-caller.d.ts.map +1 -0
  174. package/dist/commands/mint-endpoint-caller.js +130 -0
  175. package/dist/commands/mint-endpoint-caller.js.map +1 -0
  176. package/dist/commands/mint.d.ts +2 -37
  177. package/dist/commands/mint.d.ts.map +1 -1
  178. package/dist/commands/mint.js +142 -325
  179. package/dist/commands/mint.js.map +1 -1
  180. package/dist/commands/models.d.ts +30 -8
  181. package/dist/commands/models.d.ts.map +1 -1
  182. package/dist/commands/models.js +72 -41
  183. package/dist/commands/models.js.map +1 -1
  184. package/dist/commands/persona-remote.d.ts +5 -0
  185. package/dist/commands/persona-remote.d.ts.map +1 -0
  186. package/dist/commands/persona-remote.js +237 -0
  187. package/dist/commands/persona-remote.js.map +1 -0
  188. package/dist/commands/persona.d.ts +91 -0
  189. package/dist/commands/persona.d.ts.map +1 -0
  190. package/dist/commands/persona.js +200 -0
  191. package/dist/commands/persona.js.map +1 -0
  192. package/dist/commands/personas.d.ts.map +1 -1
  193. package/dist/commands/personas.js +16 -59
  194. package/dist/commands/personas.js.map +1 -1
  195. package/dist/commands/reset-space-apply.d.ts +5 -0
  196. package/dist/commands/reset-space-apply.d.ts.map +1 -0
  197. package/dist/commands/reset-space-apply.js +127 -0
  198. package/dist/commands/reset-space-apply.js.map +1 -0
  199. package/dist/commands/reset-store-apply.d.ts +35 -0
  200. package/dist/commands/reset-store-apply.d.ts.map +1 -0
  201. package/dist/commands/reset-store-apply.js +216 -0
  202. package/dist/commands/reset-store-apply.js.map +1 -0
  203. package/dist/commands/reset.d.ts +26 -0
  204. package/dist/commands/reset.d.ts.map +1 -0
  205. package/dist/commands/reset.js +155 -0
  206. package/dist/commands/reset.js.map +1 -0
  207. package/dist/commands/runtimes.d.ts +26 -1
  208. package/dist/commands/runtimes.d.ts.map +1 -1
  209. package/dist/commands/runtimes.js +68 -32
  210. package/dist/commands/runtimes.js.map +1 -1
  211. package/dist/commands/send.d.ts +91 -6
  212. package/dist/commands/send.d.ts.map +1 -1
  213. package/dist/commands/send.js +180 -106
  214. package/dist/commands/send.js.map +1 -1
  215. package/dist/commands/service-actions.d.ts +6 -0
  216. package/dist/commands/service-actions.d.ts.map +1 -0
  217. package/dist/commands/service-actions.js +413 -0
  218. package/dist/commands/service-actions.js.map +1 -0
  219. package/dist/commands/service-log-follow.d.ts +5 -0
  220. package/dist/commands/service-log-follow.d.ts.map +1 -0
  221. package/dist/commands/service-log-follow.js +107 -0
  222. package/dist/commands/service-log-follow.js.map +1 -0
  223. package/dist/commands/service-registry.d.ts +67 -0
  224. package/dist/commands/service-registry.d.ts.map +1 -0
  225. package/dist/commands/service-registry.js +275 -0
  226. package/dist/commands/service-registry.js.map +1 -0
  227. package/dist/commands/service-set-stop.d.ts +6 -0
  228. package/dist/commands/service-set-stop.d.ts.map +1 -0
  229. package/dist/commands/service-set-stop.js +164 -0
  230. package/dist/commands/service-set-stop.js.map +1 -0
  231. package/dist/commands/service-unit-entry.d.ts +5 -0
  232. package/dist/commands/service-unit-entry.d.ts.map +1 -0
  233. package/dist/commands/service-unit-entry.js +113 -0
  234. package/dist/commands/service-unit-entry.js.map +1 -0
  235. package/dist/commands/setup-start.d.ts +21 -0
  236. package/dist/commands/setup-start.d.ts.map +1 -0
  237. package/dist/commands/setup-start.js +95 -0
  238. package/dist/commands/setup-start.js.map +1 -0
  239. package/dist/commands/setup.d.ts +86 -100
  240. package/dist/commands/setup.d.ts.map +1 -1
  241. package/dist/commands/setup.js +766 -487
  242. package/dist/commands/setup.js.map +1 -1
  243. package/dist/commands/space-delete.d.ts +3 -0
  244. package/dist/commands/space-delete.d.ts.map +1 -0
  245. package/dist/commands/space-delete.js +386 -0
  246. package/dist/commands/space-delete.js.map +1 -0
  247. package/dist/commands/space-registration.d.ts +92 -0
  248. package/dist/commands/space-registration.d.ts.map +1 -0
  249. package/dist/commands/space-registration.js +394 -0
  250. package/dist/commands/space-registration.js.map +1 -0
  251. package/dist/commands/space.d.ts +128 -0
  252. package/dist/commands/space.d.ts.map +1 -0
  253. package/dist/commands/space.js +230 -0
  254. package/dist/commands/space.js.map +1 -0
  255. package/dist/commands/spawn-manifest.d.ts.map +1 -1
  256. package/dist/commands/spawn-manifest.js +2 -2
  257. package/dist/commands/spawn-manifest.js.map +1 -1
  258. package/dist/commands/spawn-preview.d.ts +9 -0
  259. package/dist/commands/spawn-preview.d.ts.map +1 -0
  260. package/dist/commands/spawn-preview.js +68 -0
  261. package/dist/commands/spawn-preview.js.map +1 -0
  262. package/dist/commands/spawn.d.ts +81 -21
  263. package/dist/commands/spawn.d.ts.map +1 -1
  264. package/dist/commands/spawn.js +254 -107
  265. package/dist/commands/spawn.js.map +1 -1
  266. package/dist/commands/stack-down.d.ts +20 -0
  267. package/dist/commands/stack-down.d.ts.map +1 -0
  268. package/dist/commands/stack-down.js +313 -0
  269. package/dist/commands/stack-down.js.map +1 -0
  270. package/dist/commands/stack-up.d.ts +154 -0
  271. package/dist/commands/stack-up.d.ts.map +1 -0
  272. package/dist/commands/stack-up.js +498 -0
  273. package/dist/commands/stack-up.js.map +1 -0
  274. package/dist/commands/stack-user-auth.d.ts +52 -0
  275. package/dist/commands/stack-user-auth.d.ts.map +1 -0
  276. package/dist/commands/stack-user-auth.js +128 -0
  277. package/dist/commands/stack-user-auth.js.map +1 -0
  278. package/dist/commands/status.d.ts +244 -5
  279. package/dist/commands/status.d.ts.map +1 -1
  280. package/dist/commands/status.js +1044 -407
  281. package/dist/commands/status.js.map +1 -1
  282. package/dist/commands/sync.d.ts +23 -0
  283. package/dist/commands/sync.d.ts.map +1 -1
  284. package/dist/commands/sync.js +69 -17
  285. package/dist/commands/sync.js.map +1 -1
  286. package/dist/commands/team-agent-apply.d.ts +5 -0
  287. package/dist/commands/team-agent-apply.d.ts.map +1 -0
  288. package/dist/commands/team-agent-apply.js +204 -0
  289. package/dist/commands/team-agent-apply.js.map +1 -0
  290. package/dist/commands/team-agent-remove.d.ts +87 -0
  291. package/dist/commands/team-agent-remove.d.ts.map +1 -0
  292. package/dist/commands/team-agent-remove.js +348 -0
  293. package/dist/commands/team-agent-remove.js.map +1 -0
  294. package/dist/commands/team-boot-controller.d.ts +11 -0
  295. package/dist/commands/team-boot-controller.d.ts.map +1 -0
  296. package/dist/commands/team-boot-controller.js +176 -0
  297. package/dist/commands/team-boot-controller.js.map +1 -0
  298. package/dist/commands/team-channel-remove.d.ts +167 -0
  299. package/dist/commands/team-channel-remove.d.ts.map +1 -0
  300. package/dist/commands/team-channel-remove.js +486 -0
  301. package/dist/commands/team-channel-remove.js.map +1 -0
  302. package/dist/commands/team-deploy-apply.d.ts +11 -0
  303. package/dist/commands/team-deploy-apply.d.ts.map +1 -0
  304. package/dist/commands/team-deploy-apply.js +320 -0
  305. package/dist/commands/team-deploy-apply.js.map +1 -0
  306. package/dist/commands/team-mixed-remove.d.ts +8 -0
  307. package/dist/commands/team-mixed-remove.d.ts.map +1 -0
  308. package/dist/commands/team-mixed-remove.js +207 -0
  309. package/dist/commands/team-mixed-remove.js.map +1 -0
  310. package/dist/commands/team.d.ts +51 -0
  311. package/dist/commands/team.d.ts.map +1 -0
  312. package/dist/commands/team.js +728 -0
  313. package/dist/commands/team.js.map +1 -0
  314. package/dist/commands/topology.d.ts +4 -0
  315. package/dist/commands/topology.d.ts.map +1 -1
  316. package/dist/commands/topology.js +8 -0
  317. package/dist/commands/topology.js.map +1 -1
  318. package/dist/commands/up.d.ts +146 -6
  319. package/dist/commands/up.d.ts.map +1 -1
  320. package/dist/commands/up.js +1123 -131
  321. package/dist/commands/up.js.map +1 -1
  322. package/dist/commands/update.d.ts +13 -0
  323. package/dist/commands/update.d.ts.map +1 -1
  324. package/dist/commands/update.js +90 -22
  325. package/dist/commands/update.js.map +1 -1
  326. package/dist/commands/use.d.ts +16 -3
  327. package/dist/commands/use.d.ts.map +1 -1
  328. package/dist/commands/use.js +45 -19
  329. package/dist/commands/use.js.map +1 -1
  330. package/dist/commands/watch.d.ts +37 -0
  331. package/dist/commands/watch.d.ts.map +1 -0
  332. package/dist/commands/watch.js +106 -0
  333. package/dist/commands/watch.js.map +1 -0
  334. package/dist/commands/who.d.ts +79 -0
  335. package/dist/commands/who.d.ts.map +1 -0
  336. package/dist/commands/who.js +193 -0
  337. package/dist/commands/who.js.map +1 -0
  338. package/dist/commands/whoami.d.ts +56 -0
  339. package/dist/commands/whoami.d.ts.map +1 -0
  340. package/dist/commands/whoami.js +106 -0
  341. package/dist/commands/whoami.js.map +1 -0
  342. package/dist/console/app.d.ts.map +1 -1
  343. package/dist/console/app.js +8 -4
  344. package/dist/console/app.js.map +1 -1
  345. package/dist/console/commands.d.ts.map +1 -1
  346. package/dist/console/commands.js +12 -6
  347. package/dist/console/commands.js.map +1 -1
  348. package/dist/exec-endpoint/definition.d.ts +15 -0
  349. package/dist/exec-endpoint/definition.d.ts.map +1 -0
  350. package/dist/exec-endpoint/definition.js +56 -0
  351. package/dist/exec-endpoint/definition.js.map +1 -0
  352. package/dist/exec-endpoint/handler.d.ts +13 -0
  353. package/dist/exec-endpoint/handler.d.ts.map +1 -0
  354. package/dist/exec-endpoint/handler.js +155 -0
  355. package/dist/exec-endpoint/handler.js.map +1 -0
  356. package/dist/exec-endpoint/registration.d.ts +34 -0
  357. package/dist/exec-endpoint/registration.d.ts.map +1 -0
  358. package/dist/exec-endpoint/registration.js +148 -0
  359. package/dist/exec-endpoint/registration.js.map +1 -0
  360. package/dist/exec-endpoint/serve.d.ts +8 -0
  361. package/dist/exec-endpoint/serve.d.ts.map +1 -0
  362. package/dist/exec-endpoint/serve.js +159 -0
  363. package/dist/exec-endpoint/serve.js.map +1 -0
  364. package/dist/exec-endpoint/service-adapter.d.ts +6 -0
  365. package/dist/exec-endpoint/service-adapter.d.ts.map +1 -0
  366. package/dist/exec-endpoint/service-adapter.js +110 -0
  367. package/dist/exec-endpoint/service-adapter.js.map +1 -0
  368. package/dist/ext-loader.d.ts +10 -0
  369. package/dist/ext-loader.d.ts.map +1 -1
  370. package/dist/ext-loader.js +61 -13
  371. package/dist/ext-loader.js.map +1 -1
  372. package/dist/help.d.ts +18 -0
  373. package/dist/help.d.ts.map +1 -0
  374. package/dist/help.js +256 -0
  375. package/dist/help.js.map +1 -0
  376. package/dist/index.d.ts +3 -0
  377. package/dist/index.d.ts.map +1 -1
  378. package/dist/index.js +446 -119
  379. package/dist/index.js.map +1 -1
  380. package/dist/lib/assist.d.ts.map +1 -1
  381. package/dist/lib/assist.js +3 -2
  382. package/dist/lib/assist.js.map +1 -1
  383. package/dist/lib/attach-client.d.ts +7 -6
  384. package/dist/lib/attach-client.d.ts.map +1 -1
  385. package/dist/lib/attach-client.js +14 -15
  386. package/dist/lib/attach-client.js.map +1 -1
  387. package/dist/lib/auth-proc.d.ts +3 -3
  388. package/dist/lib/auth-proc.d.ts.map +1 -1
  389. package/dist/lib/auth-proc.js +8 -8
  390. package/dist/lib/auth-proc.js.map +1 -1
  391. package/dist/lib/backup-artifact.d.ts +41 -1
  392. package/dist/lib/backup-artifact.d.ts.map +1 -1
  393. package/dist/lib/backup-artifact.js +96 -22
  394. package/dist/lib/backup-artifact.js.map +1 -1
  395. package/dist/lib/broker-service.d.ts +19 -0
  396. package/dist/lib/broker-service.d.ts.map +1 -0
  397. package/dist/lib/broker-service.js +369 -0
  398. package/dist/lib/broker-service.js.map +1 -0
  399. package/dist/lib/cancel.js +1 -1
  400. package/dist/lib/cancel.js.map +1 -1
  401. package/dist/lib/choose-target.d.ts +10 -0
  402. package/dist/lib/choose-target.d.ts.map +1 -0
  403. package/dist/lib/choose-target.js +42 -0
  404. package/dist/lib/choose-target.js.map +1 -0
  405. package/dist/lib/command-path.d.ts +13 -0
  406. package/dist/lib/command-path.d.ts.map +1 -0
  407. package/dist/lib/command-path.js +40 -0
  408. package/dist/lib/command-path.js.map +1 -0
  409. package/dist/lib/completion-install.d.ts +29 -0
  410. package/dist/lib/completion-install.d.ts.map +1 -0
  411. package/dist/lib/completion-install.js +369 -0
  412. package/dist/lib/completion-install.js.map +1 -0
  413. package/dist/lib/completion-scripts.d.ts +4 -0
  414. package/dist/lib/completion-scripts.d.ts.map +1 -0
  415. package/dist/lib/completion-scripts.js +15 -0
  416. package/dist/lib/completion-scripts.js.map +1 -0
  417. package/dist/lib/completion.d.ts.map +1 -1
  418. package/dist/lib/completion.js +4 -1
  419. package/dist/lib/completion.js.map +1 -1
  420. package/dist/lib/confirmation-required.d.ts +13 -0
  421. package/dist/lib/confirmation-required.d.ts.map +1 -0
  422. package/dist/lib/confirmation-required.js +10 -0
  423. package/dist/lib/confirmation-required.js.map +1 -0
  424. package/dist/lib/control.d.ts +65 -6
  425. package/dist/lib/control.d.ts.map +1 -1
  426. package/dist/lib/control.js +121 -27
  427. package/dist/lib/control.js.map +1 -1
  428. package/dist/lib/controller-preserve.d.ts +12 -0
  429. package/dist/lib/controller-preserve.d.ts.map +1 -0
  430. package/dist/lib/controller-preserve.js +373 -0
  431. package/dist/lib/controller-preserve.js.map +1 -0
  432. package/dist/lib/controller-restore.d.ts +38 -0
  433. package/dist/lib/controller-restore.d.ts.map +1 -0
  434. package/dist/lib/controller-restore.js +205 -0
  435. package/dist/lib/controller-restore.js.map +1 -0
  436. package/dist/lib/controller-resume.d.ts +92 -0
  437. package/dist/lib/controller-resume.d.ts.map +1 -0
  438. package/dist/lib/controller-resume.js +300 -0
  439. package/dist/lib/controller-resume.js.map +1 -0
  440. package/dist/lib/credential-authority.d.ts +17 -0
  441. package/dist/lib/credential-authority.d.ts.map +1 -0
  442. package/dist/lib/credential-authority.js +29 -0
  443. package/dist/lib/credential-authority.js.map +1 -0
  444. package/dist/lib/default-persona.d.ts +38 -0
  445. package/dist/lib/default-persona.d.ts.map +1 -0
  446. package/dist/lib/default-persona.js +85 -0
  447. package/dist/lib/default-persona.js.map +1 -0
  448. package/dist/lib/delivery-proc.d.ts +9 -9
  449. package/dist/lib/delivery-proc.d.ts.map +1 -1
  450. package/dist/lib/delivery-proc.js +44 -23
  451. package/dist/lib/delivery-proc.js.map +1 -1
  452. package/dist/lib/endpoint-capability-gates.d.ts +10 -0
  453. package/dist/lib/endpoint-capability-gates.d.ts.map +1 -0
  454. package/dist/lib/endpoint-capability-gates.js +70 -0
  455. package/dist/lib/endpoint-capability-gates.js.map +1 -0
  456. package/dist/lib/endpoint-client.d.ts +23 -0
  457. package/dist/lib/endpoint-client.d.ts.map +1 -0
  458. package/dist/lib/endpoint-client.js +46 -0
  459. package/dist/lib/endpoint-client.js.map +1 -0
  460. package/dist/lib/endpoint-errors.d.ts +20 -0
  461. package/dist/lib/endpoint-errors.d.ts.map +1 -0
  462. package/dist/lib/endpoint-errors.js +46 -0
  463. package/dist/lib/endpoint-errors.js.map +1 -0
  464. package/dist/lib/endpoint-goal.d.ts +19 -0
  465. package/dist/lib/endpoint-goal.d.ts.map +1 -0
  466. package/dist/lib/endpoint-goal.js +31 -0
  467. package/dist/lib/endpoint-goal.js.map +1 -0
  468. package/dist/lib/endpoint-inventory.d.ts +30 -0
  469. package/dist/lib/endpoint-inventory.d.ts.map +1 -0
  470. package/dist/lib/endpoint-inventory.js +79 -0
  471. package/dist/lib/endpoint-inventory.js.map +1 -0
  472. package/dist/lib/endpoint-references.d.ts +22 -0
  473. package/dist/lib/endpoint-references.d.ts.map +1 -0
  474. package/dist/lib/endpoint-references.js +44 -0
  475. package/dist/lib/endpoint-references.js.map +1 -0
  476. package/dist/lib/endpoint-scatter.d.ts +57 -0
  477. package/dist/lib/endpoint-scatter.d.ts.map +1 -0
  478. package/dist/lib/endpoint-scatter.js +75 -0
  479. package/dist/lib/endpoint-scatter.js.map +1 -0
  480. package/dist/lib/endpoint-selection.d.ts +35 -0
  481. package/dist/lib/endpoint-selection.d.ts.map +1 -0
  482. package/dist/lib/endpoint-selection.js +80 -0
  483. package/dist/lib/endpoint-selection.js.map +1 -0
  484. package/dist/lib/install-umask.d.ts +6 -0
  485. package/dist/lib/install-umask.d.ts.map +1 -0
  486. package/dist/lib/install-umask.js +15 -0
  487. package/dist/lib/install-umask.js.map +1 -0
  488. package/dist/lib/isolated-broker.d.ts.map +1 -1
  489. package/dist/lib/isolated-broker.js +9 -5
  490. package/dist/lib/isolated-broker.js.map +1 -1
  491. package/dist/lib/local-process-stop.d.ts.map +1 -1
  492. package/dist/lib/local-process-stop.js +7 -1
  493. package/dist/lib/local-process-stop.js.map +1 -1
  494. package/dist/lib/manager-proc.d.ts +11 -5
  495. package/dist/lib/manager-proc.d.ts.map +1 -1
  496. package/dist/lib/manager-proc.js +12 -17
  497. package/dist/lib/manager-proc.js.map +1 -1
  498. package/dist/lib/manifest/apply.d.ts +4 -1
  499. package/dist/lib/manifest/apply.d.ts.map +1 -1
  500. package/dist/lib/manifest/apply.js +1 -1
  501. package/dist/lib/manifest/apply.js.map +1 -1
  502. package/dist/lib/manifest/ledger.d.ts +3 -1
  503. package/dist/lib/manifest/ledger.d.ts.map +1 -1
  504. package/dist/lib/manifest/ledger.js +16 -3
  505. package/dist/lib/manifest/ledger.js.map +1 -1
  506. package/dist/lib/manifest/schema.d.ts +1 -117
  507. package/dist/lib/manifest/schema.d.ts.map +1 -1
  508. package/dist/lib/manifest/schema.js +1 -95
  509. package/dist/lib/manifest/schema.js.map +1 -1
  510. package/dist/lib/offline-recipient.d.ts +5 -0
  511. package/dist/lib/offline-recipient.d.ts.map +1 -0
  512. package/dist/lib/offline-recipient.js +7 -0
  513. package/dist/lib/offline-recipient.js.map +1 -0
  514. package/dist/lib/onboard.js +3 -3
  515. package/dist/lib/onboard.js.map +1 -1
  516. package/dist/lib/persona-files.d.ts +29 -0
  517. package/dist/lib/persona-files.d.ts.map +1 -0
  518. package/dist/lib/persona-files.js +154 -0
  519. package/dist/lib/persona-files.js.map +1 -0
  520. package/dist/lib/personas.d.ts +3 -0
  521. package/dist/lib/personas.d.ts.map +1 -1
  522. package/dist/lib/personas.js +14 -2
  523. package/dist/lib/personas.js.map +1 -1
  524. package/dist/lib/prompts.d.ts +16 -0
  525. package/dist/lib/prompts.d.ts.map +1 -0
  526. package/dist/lib/prompts.js +35 -0
  527. package/dist/lib/prompts.js.map +1 -0
  528. package/dist/lib/protected-records.d.ts +2 -0
  529. package/dist/lib/protected-records.d.ts.map +1 -0
  530. package/dist/lib/protected-records.js +3 -0
  531. package/dist/lib/protected-records.js.map +1 -0
  532. package/dist/lib/registry-errors.d.ts +4 -0
  533. package/dist/lib/registry-errors.d.ts.map +1 -0
  534. package/dist/lib/registry-errors.js +6 -0
  535. package/dist/lib/registry-errors.js.map +1 -0
  536. package/dist/lib/reset-space-plan.d.ts +36 -0
  537. package/dist/lib/reset-space-plan.d.ts.map +1 -0
  538. package/dist/lib/reset-space-plan.js +202 -0
  539. package/dist/lib/reset-space-plan.js.map +1 -0
  540. package/dist/lib/restore.d.ts +13 -1
  541. package/dist/lib/restore.d.ts.map +1 -1
  542. package/dist/lib/restore.js +73 -11
  543. package/dist/lib/restore.js.map +1 -1
  544. package/dist/lib/seat-resume.d.ts +4 -1
  545. package/dist/lib/seat-resume.d.ts.map +1 -1
  546. package/dist/lib/seat-resume.js +7 -4
  547. package/dist/lib/seat-resume.js.map +1 -1
  548. package/dist/lib/service-adapters.d.ts +32 -0
  549. package/dist/lib/service-adapters.d.ts.map +1 -0
  550. package/dist/lib/service-adapters.js +55 -0
  551. package/dist/lib/service-adapters.js.map +1 -0
  552. package/dist/lib/service-census.d.ts +73 -0
  553. package/dist/lib/service-census.d.ts.map +1 -0
  554. package/dist/lib/service-census.js +42 -0
  555. package/dist/lib/service-census.js.map +1 -0
  556. package/dist/lib/service-definitions.d.ts +49 -0
  557. package/dist/lib/service-definitions.d.ts.map +1 -0
  558. package/dist/lib/service-definitions.js +61 -0
  559. package/dist/lib/service-definitions.js.map +1 -0
  560. package/dist/lib/service-install-intent.d.ts +48 -0
  561. package/dist/lib/service-install-intent.d.ts.map +1 -0
  562. package/dist/lib/service-install-intent.js +95 -0
  563. package/dist/lib/service-install-intent.js.map +1 -0
  564. package/dist/lib/service-instances.d.ts +143 -0
  565. package/dist/lib/service-instances.d.ts.map +1 -0
  566. package/dist/lib/service-instances.js +193 -0
  567. package/dist/lib/service-instances.js.map +1 -0
  568. package/dist/lib/service-journal.d.ts +38 -0
  569. package/dist/lib/service-journal.d.ts.map +1 -0
  570. package/dist/lib/service-journal.js +210 -0
  571. package/dist/lib/service-journal.js.map +1 -0
  572. package/dist/lib/service-launchd-plan.d.ts +21 -0
  573. package/dist/lib/service-launchd-plan.d.ts.map +1 -0
  574. package/dist/lib/service-launchd-plan.js +69 -0
  575. package/dist/lib/service-launchd-plan.js.map +1 -0
  576. package/dist/lib/service-launchd-unit.d.ts +20 -0
  577. package/dist/lib/service-launchd-unit.d.ts.map +1 -0
  578. package/dist/lib/service-launchd-unit.js +66 -0
  579. package/dist/lib/service-launchd-unit.js.map +1 -0
  580. package/dist/lib/service-presets.d.ts +17 -0
  581. package/dist/lib/service-presets.d.ts.map +1 -0
  582. package/dist/lib/service-presets.js +139 -0
  583. package/dist/lib/service-presets.js.map +1 -0
  584. package/dist/lib/service-private-seed.d.ts +7 -0
  585. package/dist/lib/service-private-seed.d.ts.map +1 -0
  586. package/dist/lib/service-private-seed.js +64 -0
  587. package/dist/lib/service-private-seed.js.map +1 -0
  588. package/dist/lib/service-private-tree.d.ts +6 -0
  589. package/dist/lib/service-private-tree.d.ts.map +1 -0
  590. package/dist/lib/service-private-tree.js +100 -0
  591. package/dist/lib/service-private-tree.js.map +1 -0
  592. package/dist/lib/service-process.d.ts +146 -0
  593. package/dist/lib/service-process.d.ts.map +1 -0
  594. package/dist/lib/service-process.js +862 -0
  595. package/dist/lib/service-process.js.map +1 -0
  596. package/dist/lib/service-stopped-allocation.d.ts +6 -0
  597. package/dist/lib/service-stopped-allocation.d.ts.map +1 -0
  598. package/dist/lib/service-stopped-allocation.js +42 -0
  599. package/dist/lib/service-stopped-allocation.js.map +1 -0
  600. package/dist/lib/service-supervision.d.ts +59 -0
  601. package/dist/lib/service-supervision.d.ts.map +1 -0
  602. package/dist/lib/service-supervision.js +71 -0
  603. package/dist/lib/service-supervision.js.map +1 -0
  604. package/dist/lib/service-systemd-attempt-read.d.ts +40 -0
  605. package/dist/lib/service-systemd-attempt-read.d.ts.map +1 -0
  606. package/dist/lib/service-systemd-attempt-read.js +80 -0
  607. package/dist/lib/service-systemd-attempt-read.js.map +1 -0
  608. package/dist/lib/service-systemd-control.d.ts +38 -0
  609. package/dist/lib/service-systemd-control.d.ts.map +1 -0
  610. package/dist/lib/service-systemd-control.js +141 -0
  611. package/dist/lib/service-systemd-control.js.map +1 -0
  612. package/dist/lib/service-systemd-files.d.ts +8 -0
  613. package/dist/lib/service-systemd-files.d.ts.map +1 -0
  614. package/dist/lib/service-systemd-files.js +63 -0
  615. package/dist/lib/service-systemd-files.js.map +1 -0
  616. package/dist/lib/service-systemd-install.d.ts +17 -0
  617. package/dist/lib/service-systemd-install.d.ts.map +1 -0
  618. package/dist/lib/service-systemd-install.js +146 -0
  619. package/dist/lib/service-systemd-install.js.map +1 -0
  620. package/dist/lib/service-systemd-plan.d.ts +28 -0
  621. package/dist/lib/service-systemd-plan.d.ts.map +1 -0
  622. package/dist/lib/service-systemd-plan.js +56 -0
  623. package/dist/lib/service-systemd-plan.js.map +1 -0
  624. package/dist/lib/service-systemd-reseed.d.ts +16 -0
  625. package/dist/lib/service-systemd-reseed.d.ts.map +1 -0
  626. package/dist/lib/service-systemd-reseed.js +106 -0
  627. package/dist/lib/service-systemd-reseed.js.map +1 -0
  628. package/dist/lib/service-systemd-uninstall-plan.d.ts +29 -0
  629. package/dist/lib/service-systemd-uninstall-plan.d.ts.map +1 -0
  630. package/dist/lib/service-systemd-uninstall-plan.js +56 -0
  631. package/dist/lib/service-systemd-uninstall-plan.js.map +1 -0
  632. package/dist/lib/service-systemd-uninstall.d.ts +17 -0
  633. package/dist/lib/service-systemd-uninstall.d.ts.map +1 -0
  634. package/dist/lib/service-systemd-uninstall.js +106 -0
  635. package/dist/lib/service-systemd-uninstall.js.map +1 -0
  636. package/dist/lib/service-systemd-unit.d.ts +28 -0
  637. package/dist/lib/service-systemd-unit.d.ts.map +1 -0
  638. package/dist/lib/service-systemd-unit.js +73 -0
  639. package/dist/lib/service-systemd-unit.js.map +1 -0
  640. package/dist/lib/service-systemd.d.ts +49 -0
  641. package/dist/lib/service-systemd.d.ts.map +1 -0
  642. package/dist/lib/service-systemd.js +134 -0
  643. package/dist/lib/service-systemd.js.map +1 -0
  644. package/dist/lib/service-uninstall-intent.d.ts +38 -0
  645. package/dist/lib/service-uninstall-intent.d.ts.map +1 -0
  646. package/dist/lib/service-uninstall-intent.js +74 -0
  647. package/dist/lib/service-uninstall-intent.js.map +1 -0
  648. package/dist/lib/service-unit-action.d.ts +24 -0
  649. package/dist/lib/service-unit-action.d.ts.map +1 -0
  650. package/dist/lib/service-unit-action.js +61 -0
  651. package/dist/lib/service-unit-action.js.map +1 -0
  652. package/dist/lib/setup-log.d.ts +5 -4
  653. package/dist/lib/setup-log.d.ts.map +1 -1
  654. package/dist/lib/setup-log.js +18 -9
  655. package/dist/lib/setup-log.js.map +1 -1
  656. package/dist/lib/shown-time.d.ts +5 -0
  657. package/dist/lib/shown-time.d.ts.map +1 -0
  658. package/dist/lib/shown-time.js +9 -0
  659. package/dist/lib/shown-time.js.map +1 -0
  660. package/dist/lib/space-schema-inspection.d.ts +73 -0
  661. package/dist/lib/space-schema-inspection.d.ts.map +1 -0
  662. package/dist/lib/space-schema-inspection.js +118 -0
  663. package/dist/lib/space-schema-inspection.js.map +1 -0
  664. package/dist/lib/space-schema-report.d.ts +82 -0
  665. package/dist/lib/space-schema-report.d.ts.map +1 -0
  666. package/dist/lib/space-schema-report.js +109 -0
  667. package/dist/lib/space-schema-report.js.map +1 -0
  668. package/dist/lib/spawn-defaults.d.ts +14 -0
  669. package/dist/lib/spawn-defaults.d.ts.map +1 -0
  670. package/dist/lib/spawn-defaults.js +20 -0
  671. package/dist/lib/spawn-defaults.js.map +1 -0
  672. package/dist/lib/stack-journal.d.ts +166 -0
  673. package/dist/lib/stack-journal.d.ts.map +1 -0
  674. package/dist/lib/stack-journal.js +421 -0
  675. package/dist/lib/stack-journal.js.map +1 -0
  676. package/dist/lib/stack-resume.d.ts +35 -0
  677. package/dist/lib/stack-resume.d.ts.map +1 -0
  678. package/dist/lib/stack-resume.js +123 -0
  679. package/dist/lib/stack-resume.js.map +1 -0
  680. package/dist/lib/status.d.ts +19 -20
  681. package/dist/lib/status.d.ts.map +1 -1
  682. package/dist/lib/status.js +41 -40
  683. package/dist/lib/status.js.map +1 -1
  684. package/dist/lib/stdout-owner.d.ts +17 -0
  685. package/dist/lib/stdout-owner.d.ts.map +1 -0
  686. package/dist/lib/stdout-owner.js +44 -0
  687. package/dist/lib/stdout-owner.js.map +1 -0
  688. package/dist/lib/steps.d.ts.map +1 -1
  689. package/dist/lib/steps.js +3 -2
  690. package/dist/lib/steps.js.map +1 -1
  691. package/dist/lib/systemd-supervision.d.ts +11 -4
  692. package/dist/lib/systemd-supervision.d.ts.map +1 -1
  693. package/dist/lib/systemd-supervision.js +19 -8
  694. package/dist/lib/systemd-supervision.js.map +1 -1
  695. package/dist/lib/team-additive-attempt.d.ts +286 -0
  696. package/dist/lib/team-additive-attempt.d.ts.map +1 -0
  697. package/dist/lib/team-additive-attempt.js +387 -0
  698. package/dist/lib/team-additive-attempt.js.map +1 -0
  699. package/dist/lib/team-additive-native.d.ts +17 -0
  700. package/dist/lib/team-additive-native.d.ts.map +1 -0
  701. package/dist/lib/team-additive-native.js +29 -0
  702. package/dist/lib/team-additive-native.js.map +1 -0
  703. package/dist/lib/team-agent-removal.d.ts +104 -0
  704. package/dist/lib/team-agent-removal.d.ts.map +1 -0
  705. package/dist/lib/team-agent-removal.js +121 -0
  706. package/dist/lib/team-agent-removal.js.map +1 -0
  707. package/dist/lib/team-channel-removal.d.ts +220 -0
  708. package/dist/lib/team-channel-removal.d.ts.map +1 -0
  709. package/dist/lib/team-channel-removal.js +258 -0
  710. package/dist/lib/team-channel-removal.js.map +1 -0
  711. package/dist/lib/team-deploy-inspection.d.ts +59 -0
  712. package/dist/lib/team-deploy-inspection.d.ts.map +1 -0
  713. package/dist/lib/team-deploy-inspection.js +177 -0
  714. package/dist/lib/team-deploy-inspection.js.map +1 -0
  715. package/dist/lib/team-fresh.d.ts +73 -0
  716. package/dist/lib/team-fresh.d.ts.map +1 -0
  717. package/dist/lib/team-fresh.js +207 -0
  718. package/dist/lib/team-fresh.js.map +1 -0
  719. package/dist/lib/team-removal-reconcile.d.ts +118 -0
  720. package/dist/lib/team-removal-reconcile.d.ts.map +1 -0
  721. package/dist/lib/team-removal-reconcile.js +90 -0
  722. package/dist/lib/team-removal-reconcile.js.map +1 -0
  723. package/dist/lib/team-removal-record.d.ts +7 -0
  724. package/dist/lib/team-removal-record.d.ts.map +1 -0
  725. package/dist/lib/team-removal-record.js +46 -0
  726. package/dist/lib/team-removal-record.js.map +1 -0
  727. package/dist/lib/team-retained.d.ts +33 -0
  728. package/dist/lib/team-retained.d.ts.map +1 -0
  729. package/dist/lib/team-retained.js +55 -0
  730. package/dist/lib/team-retained.js.map +1 -0
  731. package/dist/lib/theme.d.ts.map +1 -1
  732. package/dist/lib/theme.js +9 -8
  733. package/dist/lib/theme.js.map +1 -1
  734. package/dist/lib/transient.d.ts +14 -9
  735. package/dist/lib/transient.d.ts.map +1 -1
  736. package/dist/lib/transient.js +25 -18
  737. package/dist/lib/transient.js.map +1 -1
  738. package/dist/lib/up-report.d.ts +3 -0
  739. package/dist/lib/up-report.d.ts.map +1 -1
  740. package/dist/lib/up-report.js +4 -1
  741. package/dist/lib/up-report.js.map +1 -1
  742. package/dist/lib/version.d.ts +8 -2
  743. package/dist/lib/version.d.ts.map +1 -1
  744. package/dist/lib/version.js +16 -9
  745. package/dist/lib/version.js.map +1 -1
  746. package/dist/managed-handoff.d.ts +3 -0
  747. package/dist/managed-handoff.d.ts.map +1 -1
  748. package/dist/managed-handoff.js +5 -0
  749. package/dist/managed-handoff.js.map +1 -1
  750. package/dist/seed/paths.d.ts +1 -1
  751. package/dist/seed/paths.js +1 -1
  752. package/dist/seed/reconcile.d.ts.map +1 -1
  753. package/dist/seed/reconcile.js +19 -3
  754. package/dist/seed/reconcile.js.map +1 -1
  755. package/dist/ui.d.ts +10 -2
  756. package/dist/ui.d.ts.map +1 -1
  757. package/dist/ui.js +28 -6
  758. package/dist/ui.js.map +1 -1
  759. package/dist/watch-data.d.ts +15 -0
  760. package/dist/watch-data.d.ts.map +1 -0
  761. package/dist/watch-data.js +66 -0
  762. package/dist/watch-data.js.map +1 -0
  763. package/dist/watch-json.d.ts +5 -0
  764. package/dist/watch-json.d.ts.map +1 -0
  765. package/dist/watch-json.js +132 -0
  766. package/dist/watch-json.js.map +1 -0
  767. package/dist/watch-view.d.ts +8 -0
  768. package/dist/watch-view.d.ts.map +1 -0
  769. package/dist/watch-view.js +65 -0
  770. package/dist/watch-view.js.map +1 -0
  771. package/package.json +8 -5
  772. package/dist/commands/service.d.ts +0 -17
  773. package/dist/commands/service.d.ts.map +0 -1
  774. package/dist/commands/service.js +0 -589
  775. package/dist/commands/service.js.map +0 -1
@@ -0,0 +1,862 @@
1
+ import { spawn } from "node:child_process";
2
+ import { randomUUID } from "node:crypto";
3
+ import { closeSync, constants, fstatSync, openSync, readSync } from "node:fs";
4
+ import { isAbsolute, join, resolve } from "node:path";
5
+ import { CommandFailure, assertRecordIdentity, canonicalRoot, commandIsCotalSupervisor, isCommandFailure, maintenanceAdmitsStackWork, readMaintenanceJournal, readProcessCommand, readServiceStopRequest, resolveNativeServiceTarget, resolveOnPath, serviceAdapterReadiness, serviceMetadataDigest, spaceKey, serviceAdapterKernelStopPlan, serviceAdapterKernelStopResult, serviceAdapterStopPlan, serviceAdapterStopResult, isWorkspaceTargetError, targetErrorCode, workspaceErrorParts } from "@cotal-ai/workspace";
6
+ import { refuseRecordedSupervisor } from "./service-supervision.js";
7
+ import { serviceInstallIntents } from "./service-install-intent.js";
8
+ import { serviceUninstallIntents } from "./service-uninstall-intent.js";
9
+ import { serviceUnitActionStore } from "./service-unit-action.js";
10
+ import { selfArgv } from "./self-exec.js";
11
+ import { loadServiceAdapter, resolveServiceAdapter, sameServiceAdapterPin } from "./service-adapters.js";
12
+ import { serviceDefinitionStore, validateServiceDefinition } from "./service-definitions.js";
13
+ import { instanceProjection, observeServiceProcess, processServiceHost, requireProcessIdentity, serviceInstances, serviceInstanceStore } from "./service-instances.js";
14
+ import { maintenanceStackView } from "./stack-journal.js";
15
+ export const PROCESS_SERVICE_CAPABILITIES = Object.freeze({ multiInstance: true, foreground: true, logs: true, install: false });
16
+ const delay = (ms) => new Promise((done) => setTimeout(done, ms));
17
+ const gone = (state) => state === "gone" || state === "previous-boot" || state === "foreign-pid";
18
+ /** A record with no creation pin whose own state says no child exists: its launch failed before
19
+ * a process did. There is nothing to stop. */
20
+ const neverLaunched = (value) => !value.process && gone(observeServiceProcess(value));
21
+ /** The recorded states a crash or a failed start leaves behind. A retained `stopping` request is not
22
+ * one of them: its own stop evidence decides it. */
23
+ const UNSETTLED_RUN = ["starting", "running", "unknown"];
24
+ /** Record an instance as `failed` when its exact recorded process is proven gone (its PID is dead,
25
+ * names a later process, or belongs to an earlier boot) and no stop of ours explains the exit. A
26
+ * native record that retains a stop request (see {@link retainedStopRequest}) is recorded `stopping`
27
+ * under that request instead, since only that stop's own receipt can settle it. The caller holds
28
+ * the definition's writer lock, so no launch or stop of it is in flight. Nothing is signalled,
29
+ * relaunched or removed. Any other record is returned unchanged. */
30
+ export function settleExitedInstance(row) {
31
+ const value = row.record.value;
32
+ if (!value.process || !UNSETTLED_RUN.includes(value.state) || !gone(observeServiceProcess(value)))
33
+ return row;
34
+ const retained = retainedStopRequest(value);
35
+ return transition(row, retained ? { state: "stopping", requestId: retained.requestId, readiness: "not-checked" } : { state: "failed", readiness: "not-checked" });
36
+ }
37
+ /** A record settled by {@link settleExitedInstance} or by its own failed start: its exact process
38
+ * is gone and no stop receipt explains the exit. */
39
+ export function exitedWithoutStop(value) {
40
+ return value.state === "failed" && value.process !== undefined && gone(observeServiceProcess(value));
41
+ }
42
+ /** Nothing of this record runs and no stop of ours is retained: it never launched, or its exact
43
+ * process is gone and its record is settled or a crash a stop may settle. */
44
+ function goneWithoutStop(value) {
45
+ if (neverLaunched(value))
46
+ return true;
47
+ if (!gone(observeServiceProcess(value)))
48
+ return false;
49
+ return value.state === "failed" || value.process !== undefined && UNSETTLED_RUN.includes(value.state);
50
+ }
51
+ /** The native stop request this exact instance launch holds, or undefined when the launch has no
52
+ * request file. It is `published` when the file reads as this launch's own. A file or state
53
+ * directory that cannot be read cannot rule a publication out, so it answers with the request this
54
+ * record names and an `unknown` publication, never a verified one. */
55
+ function publishedNativeStop(value) {
56
+ try {
57
+ const stateDirectory = serviceInstanceStore(value.space).directory();
58
+ if (!stateDirectory)
59
+ return { requestId: value.requestId, publication: "unknown" };
60
+ const request = readServiceStopRequest({ space: value.space, instanceId: value.instanceId, launchRequestId: value.launchRequestId, stateDirectory });
61
+ return request && { requestId: request.requestId, publication: "published" };
62
+ }
63
+ catch {
64
+ return { requestId: value.requestId, publication: "unknown" };
65
+ }
66
+ }
67
+ /** The native stop this record retains, or undefined. A native record with a process retains one
68
+ * while it is `stopping`, or in a state a crash leaves behind, and its launch holds a stop request:
69
+ * an earlier build recorded such a stop `unknown`. Only the adapter's own request-bound receipt
70
+ * settles it; no start, stop, crash settlement or exit record replaces it. */
71
+ export function retainedStopRequest(value) {
72
+ if (!value.nativeStopRequired || !value.process || value.state !== "stopping" && !UNSETTLED_RUN.includes(value.state))
73
+ return undefined;
74
+ return publishedNativeStop(value);
75
+ }
76
+ /** The refusal for a retained native stop, made before any readiness probe, stop request or record
77
+ * write. This command has no effect, so it is refused; only the earlier stop's outcome is unknown. A
78
+ * request file that does not read as this launch's own is named an unknown publication. */
79
+ function retainedNativeStop(definition, row, retained) {
80
+ return new CommandFailure("refused", "LIFECYCLE_BLOCKED", retained.publication === "published"
81
+ ? "an earlier native stop request is retained without its terminal receipt, so its outcome is unknown; nothing was submitted or written and its exit was not settled as a crash"
82
+ : "this launch's native stop request file does not read as its own, so whether an earlier stop was published is unknown; nothing was submitted or written and its exit was not settled as a crash", { target: { ...instanceProjection(row), requestId: retained.requestId, stopPublication: retained.publication }, remedy: `inspect the original request with cotal service status ${definition.name} --instance ${row.name} --space ${row.record.value.space}` });
83
+ }
84
+ /** Settle every instance of one definition under its writer lock. */
85
+ export function settleExitedInstances(definition) {
86
+ const space = definition.record.value.space;
87
+ const hold = serviceDefinitionStore(space).pin(definition);
88
+ try {
89
+ for (const row of serviceInstances(space, definition.name))
90
+ settleExitedInstance(row);
91
+ }
92
+ finally {
93
+ hold.release();
94
+ }
95
+ }
96
+ export function selectServiceInstance(rows, id, allowMissing = false) {
97
+ if (id !== undefined) {
98
+ const found = rows.find((row) => row.name === id);
99
+ if (!found)
100
+ throw new CommandFailure("refused", "TARGET_NOT_FOUND", "the full instance ID does not belong to this selected definition and space");
101
+ return found;
102
+ }
103
+ if (!rows.length) {
104
+ if (allowMissing)
105
+ return undefined;
106
+ throw new CommandFailure("refused", "TARGET_NOT_FOUND", "no instance is recorded for this service definition");
107
+ }
108
+ if (rows.length !== 1)
109
+ throw new CommandFailure("refused", "TARGET_AMBIGUOUS", `this definition has several instance records; choose --instance with one full ID:\n${rows.map((row) => row.name).join("\n")}`, { target: { candidates: rows.map((row) => row.name) } });
110
+ return rows[0];
111
+ }
112
+ function sameIncarnation(before, after) {
113
+ return before.instanceId === after.instanceId && before.definitionRevision === after.definitionRevision && before.process?.pid === after.process?.pid && before.process?.token === after.process?.token;
114
+ }
115
+ function transition(row, change) {
116
+ const store = serviceInstanceStore(row.record.value.space);
117
+ const current = store.read(row.name);
118
+ if (!current || !sameIncarnation(row.record.value, current.record.value))
119
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the service incarnation changed while its operation was in flight; the successor was not overwritten", { target: { instanceId: row.name, requestId: row.record.value.requestId } });
120
+ store.commit(row.name, current, { ...current.record.value, ...change, ...(change.readiness === "not-checked" ? { adapterReadiness: undefined } : {}), updatedAt: new Date().toISOString() });
121
+ return store.read(row.name);
122
+ }
123
+ function executable(definition) {
124
+ if (definition.launch.type !== "process")
125
+ throw new CommandFailure("refused", "UNSUPPORTED", "this driver accepts process definitions, not adapter options");
126
+ const source = definition.launch.executable;
127
+ const found = isAbsolute(source) ? source : /[\\/]/.test(source) ? resolve(definition.launch.cwd, source) : resolveOnPath(source);
128
+ if (!found)
129
+ throw new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", "the declared executable is unavailable; no instance was allocated");
130
+ return found;
131
+ }
132
+ function environment(definition) {
133
+ const env = {};
134
+ for (const key of ["PATH", "HOME", "USER", "LOGNAME", "TMPDIR", "LANG", "LC_ALL", "TERM", "COLORTERM", "NO_COLOR", "FORCE_COLOR", "COTAL_HOME", "XDG_CONFIG_HOME", "XDG_DATA_HOME", "XDG_STATE_HOME", "XDG_CACHE_HOME", "XDG_RUNTIME_DIR"])
135
+ if (process.env[key] !== undefined)
136
+ env[key] = process.env[key];
137
+ for (const [destination, source] of Object.entries(definition.envRefs ?? {})) {
138
+ if (process.env[source] === undefined)
139
+ throw new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", "a selected host environment reference is unavailable; no environment value was printed and no process was launched");
140
+ env[destination] = process.env[source];
141
+ }
142
+ if (definition.credentialRef)
143
+ env.COTAL_CREDS = definition.credentialRef.path;
144
+ return env;
145
+ }
146
+ export function serviceLogPath(space, id, create = false) {
147
+ const dir = serviceInstanceStore(space).directory(create);
148
+ return dir ? join(dir, `${spaceKey(id)}.log`) : undefined;
149
+ }
150
+ /** Both absent, or the same attempt and inventory digest. */
151
+ function samePreserved(a, b) {
152
+ return a === undefined ? b === undefined : b !== undefined && a.attemptId === b.attemptId && a.inventorySha256 === b.inventorySha256;
153
+ }
154
+ function ownedMetadata(value) {
155
+ const freeze = (input) => {
156
+ if (input && typeof input === "object") {
157
+ for (const child of Object.values(input))
158
+ freeze(child);
159
+ Object.freeze(input);
160
+ }
161
+ };
162
+ const copy = structuredClone(value);
163
+ freeze(copy);
164
+ return copy;
165
+ }
166
+ function adapterContext(definition, instance, cliInvocation, attempt, stack) {
167
+ const value = definition.record.value;
168
+ if (value.launch.type !== "adapter")
169
+ throw new CommandFailure("refused", "UNSUPPORTED", "a process definition has no adapter context");
170
+ const options = ownedMetadata(value.launch.options);
171
+ const stateDirectory = serviceInstanceStore(value.space).directory();
172
+ if (!stateDirectory)
173
+ throw new CommandFailure("refused", "CONFLICT", "the reserved service state directory disappeared");
174
+ return Object.freeze({ space: value.space, definition: definition.name, definitionRevision: definition.record.revision, instanceId: instance.instanceId, launchRequestId: instance.launchRequestId, stateDirectory, ...(cliInvocation ? { cliInvocation: Object.freeze([...cliInvocation]) } : {}), options, ...(value.credentialRef ? { credentialRef: Object.freeze({ ...value.credentialRef }) } : {}), ...(value.envRefs ? { envRefs: ownedMetadata(value.envRefs) } : {}), ...(attempt ? { attempt: ownedMetadata(attempt) } : {}), ...(stack ? { stack: ownedMetadata(stack) } : {}) });
175
+ }
176
+ /** A deadline bounds our observation, not the provider's work. No timed-out hook is retried. */
177
+ async function adapterCall(call, timeoutMs) {
178
+ const controller = new AbortController();
179
+ let timer;
180
+ try {
181
+ return await Promise.race([
182
+ Promise.resolve().then(() => call(controller.signal)),
183
+ new Promise((_, reject) => { timer = setTimeout(() => { controller.abort(); reject(new CommandFailure("unknown", "OPERATION_UNKNOWN", "the adapter did not complete its bounded observation; it was not retried")); }, Math.max(1, timeoutMs)); }),
184
+ ]);
185
+ }
186
+ finally {
187
+ if (timer !== undefined)
188
+ clearTimeout(timer);
189
+ controller.abort();
190
+ }
191
+ }
192
+ export async function serviceReadiness(row, definition, adapter) {
193
+ const deadline = Date.now() + definition.readiness.timeoutMs;
194
+ do {
195
+ const state = observeServiceProcess(row.record.value);
196
+ if (gone(state))
197
+ throw new CommandFailure("failed", "OPERATION_FAILED", "the owned service process exited before readiness was established", { target: { instanceId: row.name, requestId: row.record.value.requestId } });
198
+ if (state !== "running")
199
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "service process ownership could not be re-established while observing readiness; no replacement was launched", { target: { instanceId: row.name, requestId: row.record.value.requestId } });
200
+ if (definition.readiness.type === "process")
201
+ return transition(row, { state: "running", readiness: "process-running" });
202
+ if (definition.readiness.type === "adapter") {
203
+ if (!adapter || !row.record.value.process || !sameServiceAdapterPin(row.record.value.adapter, adapter.provider.pin))
204
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the service readiness has no matching pinned adapter; no provider was substituted", { target: instanceProjection(row) });
205
+ const began = Date.now();
206
+ let observation;
207
+ try {
208
+ observation = serviceAdapterReadiness(await adapterCall((signal) => adapter.provider.readiness({ ...adapter.context, process: { ...row.record.value.process }, signal }), deadline - Date.now()));
209
+ if (observation.state === "ready") {
210
+ const process = row.record.value.process, observedAt = Date.parse(observation.observedAt);
211
+ if (observation.process.pid !== process.pid || observation.process.token !== process.token || observedAt < began - 1000 || observedAt > Date.now() + 1000 || (adapter.provider.declaration.readiness === "endpoint") !== (observation.native !== undefined) || (adapter.provider.declaration.readiness === "listener") !== (observation.listener !== undefined))
212
+ throw new Error("unattributed adapter observation");
213
+ if (observeServiceProcess(row.record.value) !== "running")
214
+ throw new Error("process changed during adapter observation");
215
+ return transition(row, { state: "running", readiness: observation.native ? "endpoint-serving" : observation.listener ? "broker-listener-reported" : "adapter-process-running", adapterReadiness: observation });
216
+ }
217
+ }
218
+ catch {
219
+ const uncertain = transition(row, { state: "unknown", readiness: "not-checked" });
220
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the adapter did not establish current readiness for the owned process before its deadline, or returned mismatched evidence; no hook or launch was retried", { target: instanceProjection(uncertain), remedy: "inspect the original full instance and its launch request before another start" });
221
+ }
222
+ await delay(Math.min(100, Math.max(0, deadline - Date.now())));
223
+ continue;
224
+ }
225
+ try {
226
+ const response = await fetch(definition.readiness.url, { redirect: "manual", credentials: "omit", signal: AbortSignal.timeout(Math.max(1, Math.min(1000, deadline - Date.now()))) });
227
+ await response.body?.cancel();
228
+ if (response.status === definition.readiness.expectedStatus && observeServiceProcess(row.record.value) === "running")
229
+ return transition(row, { state: "running", readiness: "http-reachable" });
230
+ }
231
+ catch { /* A failed bounded HTTP read is not proof of process death or listener ownership. */ }
232
+ await delay(Math.min(100, Math.max(0, deadline - Date.now())));
233
+ } while (Date.now() < deadline);
234
+ const uncertain = transition(row, { state: "unknown", readiness: "not-checked" });
235
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the owned process did not establish its declared readiness before the deadline; it was not relaunched or automatically killed", { target: instanceProjection(uncertain), remedy: "inspect service status/logs with the original full instance ID before another start" });
236
+ }
237
+ /** A target the adapter could not resolve, as the refusal its code and remedy name. */
238
+ function targetRefusal(error) {
239
+ const { message, remedy } = workspaceErrorParts({ kind: "target", error });
240
+ return new CommandFailure("refused", targetErrorCode(error.code), message, remedy ? { remedy } : {});
241
+ }
242
+ export function prepareProcessService(definition) {
243
+ processServiceHost();
244
+ validateServiceDefinition(definition.record.value, definition.record.value.space);
245
+ const launch = definition.record.value.launch;
246
+ const program = launch.type === "process" ? executable(definition.record.value) : undefined;
247
+ if (launch.type === "process" && commandIsCotalSupervisor([program, ...launch.args].join(" ")))
248
+ throw new CommandFailure("refused", "UNSUPPORTED", "a native manager needs its service adapter and agent-impact guards, not generic process control; no instance was allocated");
249
+ const adapter = launch.type === "adapter" ? resolveServiceAdapter(launch.adapter, launch.options) : undefined;
250
+ let cliInvocation;
251
+ if (adapter?.declaration.requiresCli) {
252
+ try {
253
+ cliInvocation = selfArgv();
254
+ }
255
+ catch {
256
+ throw new CommandFailure("refused", "UNSUPPORTED", "this native adapter requires the verified cotal binary entry; an arbitrary library entry was not re-executed");
257
+ }
258
+ }
259
+ return { program, adapter, cliInvocation, env: environment(definition.record.value), launcher: requireProcessIdentity(process.pid) };
260
+ }
261
+ /** A restart stops before it starts, and its start carries no maintenance attempt. Under a
262
+ * maintenance journal the broker and manager adapters admit such a start only through
263
+ * `maintenanceAdmitsStackWork`, so a restart either would refuse is refused here, before any stop
264
+ * is prepared or made. It only reads; a journal written after it can still refuse the start. */
265
+ export function assertRestartAdmitted(definition) {
266
+ const value = definition.record.value;
267
+ if (value.launch.type !== "adapter" || !["nats-broker", "manager-service"].includes(value.launch.adapter))
268
+ return;
269
+ const options = value.launch.options, root = canonicalRoot(String(options.root));
270
+ if (!readMaintenanceJournal(root))
271
+ return;
272
+ const server = value.launch.adapter === "nats-broker" ? String(options.server) : resolveNativeServiceTarget(root, value.space, options.server).server;
273
+ if (!maintenanceAdmitsStackWork(root, value.space, server, maintenanceStackView(root, value.space)))
274
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "this root retains a maintenance or recovery attempt, under which the replacement start would be refused; nothing was stopped", { target: { space: value.space, definition: definition.name } });
275
+ }
276
+ export async function startProcessService(definition, options, held) {
277
+ const value = definition.record.value;
278
+ if (options.attempt && (value.launch.type !== "adapter" || options.foreground))
279
+ throw new CommandFailure("refused", "UNSUPPORTED", "a maintenance attempt reaches only an adapter launch in the background; no launch was allocated");
280
+ // Only the broker and manager adapters read an attempt; every other adapter refuses it.
281
+ if (options.attempt && value.launch.type === "adapter" && !["nats-broker", "manager-service"].includes(value.launch.adapter))
282
+ throw new CommandFailure("refused", "UNSUPPORTED", "this adapter accepts no maintenance attempt; no launch was allocated");
283
+ // A controller attempt whose cut broker is retired starts the new broker
284
+ // instance its maintenance journal names, with the journal's own IDs. The broker adapter admits
285
+ // only that exact pair, and only while every other record of the definition is retired.
286
+ if (options.brokerInstance && (!options.attempt || value.launch.type !== "adapter" || value.launch.adapter !== "nats-broker" || options.newInstance || options.instance !== undefined))
287
+ throw new CommandFailure("refused", "UNSUPPORTED", "a journaled broker instance is started only by its own controller attempt; no launch was allocated");
288
+ // A stack redefinition starts the replacement its stack journal named before the old instance was
289
+ // retired, with the journal's own IDs, and only while the definition has no instance record.
290
+ if (options.replacement && (options.brokerInstance || options.newInstance || options.instance !== undefined))
291
+ throw new CommandFailure("refused", "UNSUPPORTED", "a journaled stack replacement is started only under its own IDs; no launch was allocated");
292
+ const { program, adapter: declaredAdapter, cliInvocation, env, launcher } = prepareProcessService(definition);
293
+ if (declaredAdapter && (options.newInstance && !declaredAdapter.declaration.capabilities.multiInstance || options.foreground && !declaredAdapter.declaration.capabilities.foreground))
294
+ throw new CommandFailure("refused", "UNSUPPORTED", "the selected adapter does not declare this multi-instance or foreground capability; no launch was allocated");
295
+ const hold = held ?? serviceDefinitionStore(value.space).pin(definition);
296
+ let child;
297
+ try {
298
+ assertNoServiceUnitAttempts(value.space, definition.name);
299
+ const rows = serviceInstances(value.space, definition.name);
300
+ if (options.brokerInstance) {
301
+ if (rows.some((row) => row.name === options.brokerInstance.instanceId))
302
+ throw new CommandFailure("refused", "CONFLICT", "the journaled broker instance already has a record; no second launch was allocated");
303
+ if (rows.some((row) => row.record.value.state !== "stopped" || !row.record.value.kernelStop || !gone(observeServiceProcess(row.record.value))))
304
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "another record of this broker definition is not a stopped one with its own kernel-exit receipt; no new broker instance was allocated");
305
+ }
306
+ if (options.replacement && rows.length)
307
+ throw new CommandFailure("refused", "CONFLICT", "the definition already has an instance record; the journaled replacement was not launched beside it", { target: { space: value.space, definition: definition.name, candidates: rows.map((row) => row.name) } });
308
+ const chosen = options.newInstance || options.brokerInstance || options.replacement ? undefined : selectServiceInstance(rows, options.instance, true);
309
+ // A retained native stop is decided only by its own receipt, so no start probes, reuses or
310
+ // replaces it, and its record is not written.
311
+ const retained = chosen && retainedStopRequest(chosen.record.value);
312
+ if (chosen && retained)
313
+ throw retainedNativeStop(definition, chosen, retained);
314
+ // A crash or failed start is settled from its own evidence before the relaunch checks below.
315
+ const selected = chosen && settleExitedInstance(chosen);
316
+ if (selected && selected.record.value.definitionRevision !== definition.record.revision)
317
+ throw new CommandFailure("refused", "CONFLICT", "this instance belongs to another definition revision; it was not adopted");
318
+ if (selected && !sameServiceAdapterPin(selected.record.value.adapter, declaredAdapter?.pin))
319
+ throw new CommandFailure("refused", "CONFLICT", "the recorded instance pins a different adapter declaration or package version; stop and explicitly remove its retained records before choosing a different provider", { target: instanceProjection(selected) });
320
+ if (selected) {
321
+ refuseRecordedSupervisor(selected.record.value, "start");
322
+ const state = observeServiceProcess(selected.record.value);
323
+ if (state === "running") {
324
+ if (options.foreground)
325
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "an existing live instance cannot be converted into this terminal's foreground process; stop it explicitly before a foreground start", { target: instanceProjection(selected) });
326
+ const adapter = declaredAdapter && value.launch.type === "adapter" ? { provider: await loadServiceAdapter(declaredAdapter, value.launch.options), context: adapterContext(definition, selected.record.value, cliInvocation) } : undefined;
327
+ return { instance: await serviceReadiness(selected, value, adapter), noOp: true, child: undefined, exit: undefined };
328
+ }
329
+ if (!gone(state))
330
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "an unresolved or foreign service incarnation is retained; no second launch was allocated", { target: instanceProjection(selected), remedy: "inspect the original full instance with service status/logs; do not discard an unresolved launch receipt" });
331
+ // A settled exit (`failed` with its gone process) is relaunched; a retained `stopping`
332
+ // request is still decided by its own stop evidence.
333
+ const settledExit = exitedWithoutStop(selected.record.value);
334
+ if (declaredAdapter?.declaration.stop === "native" && selected.record.value.process && !settledExit && !(selected.record.value.state === "stopped" && selected.record.value.nativeStop))
335
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the original native service disappeared during its retained stop request, without its recorded terminal stop; no replacement was launched", { target: instanceProjection(selected), remedy: `inspect the original request with cotal service status ${definition.name} --instance ${selected.name} --space ${value.space}` });
336
+ if (declaredAdapter?.declaration.stop === "kernel-exit" && selected.record.value.process && !settledExit && !(selected.record.value.state === "stopped" && selected.record.value.kernelStop))
337
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the original broker process disappeared during its retained stop request, without this controller's recorded exact-exit stop; no replacement listener was launched over its store", { target: instanceProjection(selected), remedy: `inspect the original request with cotal service status ${definition.name} --instance ${selected.name} --space ${value.space}` });
338
+ }
339
+ hold.check();
340
+ const now = new Date().toISOString(), id = options.brokerInstance?.instanceId ?? options.replacement?.instanceId ?? selected?.name ?? randomUUID(), launchRequestId = options.brokerInstance?.launchRequestId ?? options.replacement?.launchRequestId ?? randomUUID();
341
+ const instance = { schemaVersion: 1, instanceId: id, definition: definition.name, definitionRevision: definition.record.revision, space: value.space, host: processServiceHost(), requestId: launchRequestId, launchRequestId, state: "starting", launcher, readiness: "not-checked", supervisor: "none", ...(options.attempt ? { attempt: { attemptId: options.attempt.attemptId } } : {}), ...(declaredAdapter ? { adapter: declaredAdapter.pin, ...(declaredAdapter.declaration.stop === "native" ? { nativeStopRequired: true } : declaredAdapter.declaration.stop === "kernel-exit" ? { kernelStopRequired: true } : {}) } : {}), foreground: options.foreground === true, createdAt: selected?.record.value.createdAt ?? now, updatedAt: now };
342
+ const store = serviceInstanceStore(value.space);
343
+ store.commit(id, selected, instance);
344
+ let row = store.read(id);
345
+ let adapter;
346
+ let launch;
347
+ try {
348
+ if (value.launch.type === "process")
349
+ launch = { program: program, args: value.launch.args, cwd: value.launch.cwd };
350
+ else {
351
+ // The manager adapter reads no stack journal, so its launch carries the facts it admits a settled restore against.
352
+ const stack = value.launch.adapter === "manager-service" && typeof value.launch.options.root === "string" ? maintenanceStackView(value.launch.options.root, value.space) : undefined;
353
+ const context = adapterContext(definition, instance, cliInvocation, options.attempt, stack);
354
+ const provider = await loadServiceAdapter(declaredAdapter, value.launch.options);
355
+ hold.check();
356
+ const plan = await adapterCall(() => provider.build(context), Math.min(10000, value.readiness.timeoutMs));
357
+ const validated = validateServiceDefinition({ ...value, launch: { type: "process", ...plan }, readiness: { type: "process", timeoutMs: value.readiness.timeoutMs } }, value.space);
358
+ if (validated.launch.type !== "process")
359
+ throw new Error("invalid adapter launch plan");
360
+ const executablePath = executable(validated);
361
+ if (provider.declaration.stop !== "native" && commandIsCotalSupervisor([executablePath, ...validated.launch.args].join(" ")))
362
+ throw new CommandFailure("refused", "UNSUPPORTED", "the direct-process adapter ABI cannot bypass native manager agent-impact guards");
363
+ launch = { program: executablePath, args: validated.launch.args, cwd: validated.launch.cwd };
364
+ adapter = { provider, context };
365
+ }
366
+ hold.check();
367
+ }
368
+ catch (error) {
369
+ const failure = isCommandFailure(error) ? error : isWorkspaceTargetError(error) ? targetRefusal(error) : undefined;
370
+ // No child is spawned above this point, so this incarnation has no process: the record is
371
+ // failed either way. Only the provider's own work stays unattributed on an unknown error.
372
+ row = transition(row, { state: "failed", readiness: "not-checked" });
373
+ if (failure?.outcome === "refused")
374
+ throw new CommandFailure("refused", failure.code, `service preparation was refused before a child launch: ${failure.message}`, { target: instanceProjection(row), native: { code: failure.code, outcome: failure.outcome, detail: failure.message }, remedy: failure.remedy });
375
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "service preparation did not establish an accepted direct-child launch plan; no child was launched, and no provider or launch was retried", { target: instanceProjection(row) });
376
+ }
377
+ const path = serviceLogPath(value.space, id, true);
378
+ let log;
379
+ let exitCode = null, exitSignal = null;
380
+ let exited = false;
381
+ let done;
382
+ const exit = new Promise((resolve) => { done = resolve; });
383
+ try {
384
+ if (!options.foreground) {
385
+ log = openSync(path, constants.O_WRONLY | constants.O_CREAT | constants.O_APPEND | constants.O_NOFOLLOW | constants.O_NONBLOCK, 0o600);
386
+ const info = fstatSync(log);
387
+ if (!info.isFile() || info.uid !== process.getuid() || (info.mode & 0o077) !== 0)
388
+ throw new Error("unprotected log target");
389
+ }
390
+ child = spawn(launch.program, [...launch.args], { cwd: launch.cwd, env, shell: false, detached: !options.foreground, stdio: options.foreground ? "inherit" : ["ignore", log, log] });
391
+ if (!options.foreground)
392
+ child.unref();
393
+ child.once("exit", (code, signal) => { exited = true; exitCode = code; exitSignal = signal; done(); });
394
+ await new Promise((resolve, reject) => { child.once("spawn", resolve); child.once("error", reject); });
395
+ }
396
+ catch {
397
+ row = transition(row, { state: "failed", readiness: "not-checked" });
398
+ throw new CommandFailure("failed", "OPERATION_FAILED", "the native process launch failed before a service child was established; its instance receipt was retained", { target: instanceProjection(row) });
399
+ }
400
+ finally {
401
+ if (log !== undefined)
402
+ closeSync(log);
403
+ }
404
+ if (!child.pid)
405
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the launch has no confirmed process ID; its instance intent was retained and no retry was made", { target: instanceProjection(row) });
406
+ let identity;
407
+ try {
408
+ identity = requireProcessIdentity(child.pid);
409
+ }
410
+ catch {
411
+ if (!exited)
412
+ child.kill("SIGTERM");
413
+ await Promise.race([exit, delay(3000)]);
414
+ row = transition(row, { state: exited ? "failed" : "unknown", ...(exited ? { exit: { code: exitCode, signal: exitSignal } } : {}) });
415
+ throw new CommandFailure(exited ? "failed" : "unknown", exited ? "OPERATION_FAILED" : "OPERATION_UNKNOWN", "the child could not be creation-pinned; its native child handle was asked to exit, and no replacement was launched", { target: instanceProjection(row) });
416
+ }
417
+ row = transition(row, { process: identity });
418
+ let running;
419
+ try {
420
+ running = await serviceReadiness(row, value, adapter);
421
+ }
422
+ catch (error) {
423
+ // Only an exit of the pinned child itself is settled here, with the exit this parent observed.
424
+ if (!isCommandFailure(error) || error.code !== "OPERATION_FAILED")
425
+ throw error;
426
+ await Promise.race([exit, delay(1000)]);
427
+ const failed = transition(row, { state: "failed", readiness: "not-checked", ...(exited ? { exit: { code: exitCode, signal: exitSignal } } : {}) });
428
+ throw new CommandFailure("failed", "OPERATION_FAILED", `the owned service process exited before readiness was established${exited ? ` (exit code ${exitCode ?? "none"}, signal ${exitSignal ?? "none"})` : ""}; its log records the cause`, { target: instanceProjection(failed), remedy: `read its log with cotal service logs ${definition.name} --instance ${id} --space ${value.space}` });
429
+ }
430
+ return { instance: running, noOp: false, child, exit: { done: exit, observed: () => exited, result: () => ({ code: exitCode, signal: exitSignal }) } };
431
+ }
432
+ finally {
433
+ if (!held)
434
+ hold.release();
435
+ }
436
+ }
437
+ /** Native preview imports only the pinned provider and performs its caller-scoped read. No
438
+ * process signal, request publication or reservation is part of this pre-confirmation step. */
439
+ export async function prepareNativeServiceStop(definition, selected, withAgents = false, preserved) {
440
+ if (preserved && withAgents)
441
+ throw new CommandFailure("refused", "USAGE_INVALID", "a preserved-exit stop retains agents; --with-agents cannot be combined with it");
442
+ const value = definition.record.value;
443
+ const declared = value.launch.type === "adapter" ? resolveServiceAdapter(value.launch.adapter, value.launch.options) : undefined;
444
+ if (declared?.declaration.stop !== "native") {
445
+ if (withAgents)
446
+ throw new CommandFailure("refused", "UNSUPPORTED", "--with-agents requires a declared native stop policy; generic descendant signals were not substituted");
447
+ if (preserved)
448
+ throw new CommandFailure("refused", "UNSUPPORTED", "a preserved-exit stop requires a declared native stop policy");
449
+ return undefined;
450
+ }
451
+ if (!sameServiceAdapterPin(selected.record.value.adapter, declared.pin) || selected.record.value.definitionRevision !== definition.record.revision)
452
+ throw new CommandFailure("refused", "CONFLICT", "the selected native service pins another definition or adapter revision");
453
+ if (selected.record.value.state === "stopped" && selected.record.value.nativeStop && gone(observeServiceProcess(selected.record.value)))
454
+ return undefined;
455
+ const retained = retainedStopRequest(selected.record.value);
456
+ if (retained)
457
+ throw retainedNativeStop(definition, selected, retained);
458
+ // Nothing runs, so there is no impact to read; the stop records that exit under its lock.
459
+ if (goneWithoutStop(selected.record.value))
460
+ return undefined;
461
+ if (observeServiceProcess(selected.record.value) !== "running" || !selected.record.value.process)
462
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the native service has no live attributable process for an impact read; no completed stop was inferred from disappearance", { target: instanceProjection(selected) });
463
+ const provider = await loadServiceAdapter(declared, value.launch.type === "adapter" ? value.launch.options : {});
464
+ const began = Date.now();
465
+ const plan = ownedMetadata(serviceAdapterStopPlan(await adapterCall((signal) => provider.prepareStop({ ...adapterContext(definition, selected.record.value), process: { ...selected.record.value.process }, withAgents, ...(preserved ? { preserved: { ...preserved } } : {}), signal }), 15000), selected.record.value.process));
466
+ if (plan.withAgents !== withAgents || !samePreserved(plan.preserved, preserved) || Date.parse(plan.observedAt) < began - 1000 || Date.parse(plan.observedAt) > Date.now() + 1000)
467
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the native stop preview did not establish the requested current policy");
468
+ return plan;
469
+ }
470
+ /** Kernel-exit preview imports only the pinned provider and reads its exact binding and dependant
471
+ * guards. No signal, reservation or record write is part of this pre-confirmation step. */
472
+ export async function prepareKernelServiceStop(definition, selected) {
473
+ const value = definition.record.value;
474
+ const declared = value.launch.type === "adapter" ? resolveServiceAdapter(value.launch.adapter, value.launch.options) : undefined;
475
+ if (declared?.declaration.stop !== "kernel-exit")
476
+ return undefined;
477
+ if (!sameServiceAdapterPin(selected.record.value.adapter, declared.pin) || selected.record.value.definitionRevision !== definition.record.revision || selected.record.value.kernelStopRequired !== true)
478
+ throw new CommandFailure("refused", "CONFLICT", "the selected broker pins another definition, adapter revision or stop policy");
479
+ if (selected.record.value.state === "stopped" && selected.record.value.kernelStop && gone(observeServiceProcess(selected.record.value)))
480
+ return undefined;
481
+ if (goneWithoutStop(selected.record.value))
482
+ return undefined;
483
+ if (selected.record.value.state === "stopping")
484
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "an earlier broker stop request is retained without its exact-exit receipt; it was not resubmitted", { target: instanceProjection(selected) });
485
+ if (observeServiceProcess(selected.record.value) !== "running" || !selected.record.value.process)
486
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the broker has no live attributable process for a stop scope; disappearance was not treated as a completed stop", { target: instanceProjection(selected) });
487
+ const provider = await loadServiceAdapter(declared, value.launch.type === "adapter" ? value.launch.options : {});
488
+ const began = Date.now();
489
+ const plan = ownedMetadata(serviceAdapterKernelStopPlan(await adapterCall((signal) => provider.prepareKernelStop({ ...adapterContext(definition, selected.record.value), process: { ...selected.record.value.process }, signal }), 15000)));
490
+ if (Date.parse(plan.observedAt) < began - 1000 || Date.parse(plan.observedAt) > Date.now() + 1000)
491
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the broker stop scope was not observed now");
492
+ return plan;
493
+ }
494
+ /** Whole-set eligibility read before any member is stopped. The actual stop retains its own
495
+ * per-effect checks: a cooperative definition reservation does not freeze a live process. */
496
+ export function preflightProcessServiceStop(definition, selected) {
497
+ assertNoServiceUnitAttempts(selected.record.value.space, definition.name);
498
+ const current = serviceInstanceStore(selected.record.value.space).read(selected.name);
499
+ if (!current || current.record.revision !== selected.record.revision || current.hash !== selected.hash)
500
+ throw new CommandFailure("refused", "CONFLICT", "a selected service instance changed during set preflight; no service was stopped");
501
+ refuseRecordedSupervisor(current.record.value, "stop");
502
+ const value = current.record.value, state = observeServiceProcess(value), launch = definition.record.value.launch;
503
+ if (neverLaunched(value))
504
+ return;
505
+ const declared = launch.type === "adapter" ? resolveServiceAdapter(launch.adapter, launch.options) : undefined;
506
+ if (declared?.declaration.stop === "native") {
507
+ if (!sameServiceAdapterPin(value.adapter, declared.pin) || value.definitionRevision !== definition.record.revision)
508
+ throw new CommandFailure("refused", "CONFLICT", "a selected native incarnation pins another definition or adapter; no service was stopped");
509
+ if (gone(state) && value.state === "stopped" && value.nativeStop)
510
+ return;
511
+ if (state !== "running" || !value.process)
512
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "a selected native service has no attributable live process or retained returned stop; no new stop was submitted");
513
+ return;
514
+ }
515
+ if (value.nativeStopRequired)
516
+ throw new CommandFailure("refused", "UNSUPPORTED", "a selected instance requires its original native stop policy; a set stop cannot replace it with process signals");
517
+ if (value.kernelStopRequired || declared?.declaration.stop === "kernel-exit")
518
+ throw new CommandFailure("refused", "UNSUPPORTED", "a selected broker requires its exact kernel-exit stop and dependant scope; a named service set does not integrate that policy, so no service was stopped", { remedy: "stop the broker alone with cotal service stop <name> --instance <full-id> after its dependants are stopped" });
519
+ if (gone(state))
520
+ return;
521
+ if (state !== "running" || !value.process)
522
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "a selected service process is foreign, unreadable or unresolved; no service was stopped");
523
+ const command = readProcessCommand(value.process.pid);
524
+ if (command.kind !== "command" || commandIsCotalSupervisor(command.command))
525
+ throw new CommandFailure("refused", "UNSUPPORTED", "a selected process has an unreadable or manager-supervisor role; no generic set stop bypassed its native impact policy");
526
+ }
527
+ /** Only the stored creation-pinned process is signalled. Every escalation rechecks its identity. */
528
+ export async function stopProcessService(definition, selected, held, native, kernel) {
529
+ const hold = held ?? serviceDefinitionStore(definition.record.value.space).pin(definition);
530
+ try {
531
+ assertNoServiceUnitAttempts(selected.record.value.space, definition.name);
532
+ const store = serviceInstanceStore(selected.record.value.space), current = store.read(selected.name);
533
+ if (!current || current.record.revision !== selected.record.revision || current.hash !== selected.hash)
534
+ throw new CommandFailure("refused", "CONFLICT", "the selected instance changed before stop; no process was signalled");
535
+ let row = current;
536
+ refuseRecordedSupervisor(row.record.value, "stop");
537
+ const initial = observeServiceProcess(row.record.value);
538
+ const launch = definition.record.value.launch;
539
+ const declared = launch.type === "adapter" ? resolveServiceAdapter(launch.adapter, launch.options) : undefined;
540
+ if (declared?.declaration.stop === "native") {
541
+ if (!sameServiceAdapterPin(row.record.value.adapter, declared.pin) || row.record.value.definitionRevision !== definition.record.revision)
542
+ throw new CommandFailure("refused", "CONFLICT", "the native service incarnation pins another definition or adapter; it was not controlled");
543
+ if (gone(initial) && row.record.value.state === "stopped" && row.record.value.nativeStop)
544
+ return { instance: row, noOp: true, nativeStop: row.record.value.nativeStop };
545
+ const retained = retainedStopRequest(row.record.value);
546
+ if (retained)
547
+ throw retainedNativeStop(definition, row, retained);
548
+ // Already gone without a stop of ours: record that exit under this lock; nothing is signalled.
549
+ if (goneWithoutStop(row.record.value))
550
+ return { instance: settleExitedInstance(row), noOp: true };
551
+ if (initial !== "running" || !row.record.value.process)
552
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "native stop has no current attributable process or retained returned receipt; disappearance was not treated as completion", { target: instanceProjection(row) });
553
+ if (!native?.plan)
554
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "native service stop requires its current caller-scoped impact and explicit confirmation; generic signals were not used");
555
+ const plan = serviceAdapterStopPlan(native.plan, row.record.value.process);
556
+ if (plan.withAgents !== native.withAgents || !samePreserved(plan.preserved, native.preserved))
557
+ throw new CommandFailure("refused", "CONFLICT", "the confirmed native stop policy differs from the submitted policy");
558
+ const provider = await loadServiceAdapter(declared, launch.type === "adapter" ? launch.options : {});
559
+ hold.check();
560
+ // A preserved-exit caller journals its attempt first and passes that attempt's request ID.
561
+ if (native.preserved && !native.requestId)
562
+ throw new CommandFailure("refused", "USAGE_INVALID", "a preserved-exit stop needs its journaled attempt's request ID; no request was published");
563
+ const requestId = native.requestId ?? randomUUID(), target = { ...row.record.value.process }, began = Date.now();
564
+ row = transition(row, { state: "stopping", requestId });
565
+ let returned = false;
566
+ try {
567
+ const raw = await adapterCall((signal) => provider.stop({ ...adapterContext(definition, row.record.value), process: target, withAgents: native.withAgents, ...(native.preserved ? { preserved: { ...native.preserved } } : {}), requestId, plan, signal }), 45000);
568
+ returned = true;
569
+ const result = serviceAdapterStopResult(raw);
570
+ // The terminal kind must answer the submitted request: a preserved stop returns only
571
+ // `preserved-exit-returned`, an ordinary stop only `returned`.
572
+ if (result.nativeStop !== (native.preserved ? "preserved-exit-returned" : "returned") || result.requestId !== requestId || result.scopeSha256 !== plan.scopeSha256 || result.process.pid !== target.pid || result.process.token !== target.token || Date.parse(result.observedAt) < began - 1000 || Date.parse(result.observedAt) > Date.now() + 1000 || !gone(observeServiceProcess(row.record.value)))
573
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the native service did not confirm both its original returned stop and the exact process exit");
574
+ return { instance: transition(row, { state: "stopped", readiness: "not-checked", nativeStop: result }), noOp: false, nativeStop: result };
575
+ }
576
+ catch (error) {
577
+ const refused = !returned && isCommandFailure(error) && error.outcome === "refused";
578
+ // A published or unreadable request keeps the record `stopping` under that request, even after
579
+ // its process exits, so no crash settlement, record removal or relaunch can treat the exit as
580
+ // unstopped. Only a stop that published nothing returns to its observed state.
581
+ const published = publishedNativeStop(row.record.value);
582
+ row = transition(row, published ? { state: "stopping", requestId: published.requestId, readiness: "not-checked" } : { state: refused && observeServiceProcess(row.record.value) === "running" ? "running" : "unknown", readiness: "not-checked" });
583
+ if (isCommandFailure(error) && (!returned || error.outcome !== "refused"))
584
+ throw error;
585
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the native service stop did not confirm its original terminal receipt; no signal escalation or restart was attempted", { target: instanceProjection(row) });
586
+ }
587
+ }
588
+ if (declared?.declaration.stop === "kernel-exit")
589
+ return await stopKernelService(definition, row, hold, declared, initial, native, kernel);
590
+ if (row.record.value.nativeStopRequired)
591
+ throw new CommandFailure("refused", "UNSUPPORTED", "the retained instance requires its original native stop policy; no generic signal path was substituted");
592
+ if (row.record.value.kernelStopRequired)
593
+ throw new CommandFailure("refused", "UNSUPPORTED", "the retained instance requires its exact kernel-exit stop policy from its pinned adapter; no generic signal path was substituted");
594
+ if (native?.withAgents)
595
+ throw new CommandFailure("refused", "UNSUPPORTED", "generic process stop does not accept an agent-reap policy");
596
+ if (gone(initial))
597
+ return { instance: transition(row, { state: "stopped", readiness: "not-checked" }), noOp: true };
598
+ if (initial !== "running" || !row.record.value.process)
599
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "the selected process is foreign, unreadable or unresolved; it was not signalled", { target: instanceProjection(row) });
600
+ const command = readProcessCommand(row.record.value.process.pid);
601
+ if (command.kind !== "command" || commandIsCotalSupervisor(command.command))
602
+ throw new CommandFailure("refused", "UNSUPPORTED", "generic process stop cannot bypass manager agent-impact guards or an unreadable process role; use its supported service adapter. No signal was sent", { target: instanceProjection(row) });
603
+ row = transition(row, { state: "stopping", requestId: randomUUID() });
604
+ // The receipt names the last signal this call itself delivered to the pinned process. A process
605
+ // that was already gone before any delivery gets no receipt: absence is not a stop.
606
+ let delivered;
607
+ const signal = (name) => {
608
+ const state = observeServiceProcess(row.record.value);
609
+ if (gone(state))
610
+ return;
611
+ if (state !== "running")
612
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "service ownership became uncertain before signalling; its record was retained", { target: instanceProjection(row) });
613
+ const role = readProcessCommand(row.record.value.process.pid);
614
+ if (role.kind !== "command" || commandIsCotalSupervisor(role.command))
615
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the process role changed or became unreadable before signalling; manager impact guards were not bypassed", { target: instanceProjection(row) });
616
+ const identity = assertRecordIdentity(row.record.value.process);
617
+ if (identity.kind !== "match")
618
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the exact process incarnation changed before a signal; no successor was signalled", { target: instanceProjection(row) });
619
+ try {
620
+ process.kill(row.record.value.process.pid, name);
621
+ delivered = name;
622
+ }
623
+ catch (error) {
624
+ if (error.code !== "ESRCH")
625
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the exact process signal was not confirmed; its record was retained", { target: instanceProjection(row) });
626
+ }
627
+ };
628
+ signal("SIGTERM");
629
+ for (const [timeout, escalation] of [[15000, "SIGKILL"], [3000, undefined]]) {
630
+ const deadline = Date.now() + timeout;
631
+ while (Date.now() < deadline) {
632
+ const state = observeServiceProcess(row.record.value);
633
+ if (gone(state))
634
+ return { instance: transition(row, { state: "stopped", readiness: "not-checked", ...(delivered ? { processStop: { kind: "process-exit", requestId: row.record.value.requestId, process: { ...row.record.value.process }, signal: delivered, observedAt: new Date().toISOString() } } : {}) }), noOp: false };
635
+ if (state !== "running")
636
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the service exit could not be established; its identity and stop receipt were retained", { target: instanceProjection(row) });
637
+ await delay(100);
638
+ }
639
+ if (escalation)
640
+ signal(escalation);
641
+ }
642
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the selected service process did not confirm exit; its record was retained and no restart was attempted", { target: instanceProjection(row) });
643
+ }
644
+ finally {
645
+ if (!held)
646
+ hold.release();
647
+ }
648
+ }
649
+ /** The broker's exact kernel-exit stop. It signals only the creation-pinned child after the
650
+ * confirmed scope is recomputed unchanged, waits for that exact process to exit and records the
651
+ * observed exit. A retained `stopping` request, an exit this call did not cause, or an exit not
652
+ * observed before the deadline stays unknown: no SIGKILL, resubmission or restart follows. */
653
+ async function stopKernelService(definition, current, hold, declared, initial, native, kernel) {
654
+ let row = current;
655
+ const value = row.record.value, launch = definition.record.value.launch;
656
+ if (native?.withAgents)
657
+ throw new CommandFailure("refused", "UNSUPPORTED", "a broker kernel-exit stop has no agent policy; --with-agents belongs to the exact manager instance");
658
+ if (!sameServiceAdapterPin(value.adapter, declared.pin) || value.definitionRevision !== definition.record.revision || value.kernelStopRequired !== true)
659
+ throw new CommandFailure("refused", "CONFLICT", "the broker incarnation pins another definition, adapter or stop policy; it was not controlled", { target: instanceProjection(row) });
660
+ if (gone(initial) && value.state === "stopped" && value.kernelStop)
661
+ return { instance: row, noOp: true, kernelStop: value.kernelStop };
662
+ // Already gone without a stop of ours: record that exit under this lock. No exit is attributed
663
+ // to a signal, and no kernel-exit receipt is written.
664
+ if (goneWithoutStop(value))
665
+ return { instance: settleExitedInstance(row), noOp: true };
666
+ if (value.state === "stopping")
667
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "an earlier broker stop request is retained without its exact-exit receipt; it was not resubmitted", { target: instanceProjection(row) });
668
+ if (initial !== "running" || !value.process)
669
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the broker has no current attributable process or retained exact-exit receipt; disappearance was not treated as a completed stop", { target: instanceProjection(row) });
670
+ if (!kernel?.plan)
671
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "a broker stop requires its current exact scope and explicit confirmation; no signal was sent");
672
+ const confirmed = serviceAdapterKernelStopPlan(kernel.plan);
673
+ const provider = await loadServiceAdapter(declared, launch.type === "adapter" ? launch.options : {});
674
+ hold.check();
675
+ const target = { ...value.process };
676
+ const fresh = serviceAdapterKernelStopPlan(await adapterCall((signal) => provider.prepareKernelStop({ ...adapterContext(definition, value), process: target, signal }), 15000));
677
+ if (fresh.scopeSha256 !== confirmed.scopeSha256 || serviceMetadataDigest(fresh.binding) !== serviceMetadataDigest(confirmed.binding))
678
+ throw new CommandFailure("refused", "CONFLICT", "the broker binding or dependant scope changed after confirmation; no signal was sent", { target: instanceProjection(row) });
679
+ hold.check();
680
+ const role = readProcessCommand(target.pid);
681
+ if (role.kind !== "command" || commandIsCotalSupervisor(role.command) || assertRecordIdentity(target).kind !== "match")
682
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "the broker process identity or role could not be re-established immediately before the signal; no signal was sent", { target: instanceProjection(row) });
683
+ const requestId = randomUUID();
684
+ row = transition(row, { state: "stopping", requestId });
685
+ try {
686
+ if (assertRecordIdentity(target).kind !== "match")
687
+ throw new Error("identity changed");
688
+ process.kill(target.pid, "SIGTERM");
689
+ }
690
+ catch {
691
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the exact broker signal was not confirmed delivered to the pinned process; its stop request was retained and no exit was attributed to it", { target: instanceProjection(row) });
692
+ }
693
+ const deadline = Date.now() + 30000;
694
+ while (Date.now() < deadline) {
695
+ const state = observeServiceProcess(row.record.value);
696
+ if (gone(state)) {
697
+ let trace = "ports-file-retained";
698
+ try {
699
+ trace = provider.observeKernelStop({ ...adapterContext(definition, row.record.value), process: target });
700
+ }
701
+ catch { /* The observed exit stands; an unreadable trace is reported as retained, never removed. */ }
702
+ const kernelStop = serviceAdapterKernelStopResult({ kind: "kernel-exit", requestId, scopeSha256: confirmed.scopeSha256, process: target, observation: "exact-process-exit", brokerShutdownTrace: trace, cleanup: "not-checked", observedAt: new Date().toISOString() });
703
+ return { instance: transition(row, { state: "stopped", readiness: "not-checked", kernelStop }), noOp: false, kernelStop };
704
+ }
705
+ if (state !== "running")
706
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the broker exit could not be attributed; its stop request was retained", { target: instanceProjection(row) });
707
+ await delay(100);
708
+ }
709
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the broker did not exit within its stop window; the request was retained without force kill or restart", { target: instanceProjection(row), remedy: "inspect the exact broker instance before another action; a later stop of this instance is refused until it is reconciled" });
710
+ }
711
+ export function assertNoServiceUnitAttempts(space, name) {
712
+ const pending = [...serviceInstallIntents(space), ...serviceUninstallIntents(space)].filter((row) => row.record.value.definition === name);
713
+ const nativeActions = serviceUnitActionStore(space).list();
714
+ if (nativeActions.some((row) => row.name !== row.record.value.instanceId))
715
+ throw new CommandFailure("refused", "SCHEMA_INVALID", "a native action filename differs from its full instance ID; no process effect was submitted");
716
+ const actions = nativeActions.filter((row) => row.record.value.definition === name);
717
+ if (pending.length || actions.length)
718
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "a retained native installation, removal or unit action names this definition; no direct process effect was substituted", { target: { space, name, attempts: [...pending, ...actions].map((row) => ({ instanceId: row.name, attemptId: row.record.value.attemptId })) } });
719
+ }
720
+ export function removableServiceInstances(space, name) {
721
+ const pending = [...serviceInstallIntents(space), ...serviceUninstallIntents(space)].filter((row) => row.record.value.definition === name);
722
+ if (pending.length)
723
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "service remove cannot discard a definition while an installation or removal attempt may still own a unit, private store or enable link", { target: { space, name, attempts: pending.map((row) => ({ instanceId: row.name, attemptId: row.record.value.attemptId, step: row.record.value.step, position: row.record.value.position })) }, remedy: "inspect and reconcile every retained native unit attempt before removing this definition" });
724
+ const nativeActions = serviceUnitActionStore(space).list();
725
+ if (nativeActions.some((row) => row.name !== row.record.value.instanceId))
726
+ throw new CommandFailure("refused", "SCHEMA_INVALID", "a native action filename differs from its full instance ID; no definition was removed");
727
+ const actions = nativeActions.filter((row) => row.record.value.definition === name);
728
+ if (actions.length)
729
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "service remove cannot discard a definition while an exact native action is retained", { target: { space, name, attempts: actions.map((row) => ({ instanceId: row.name, attemptId: row.record.value.attemptId, operation: row.record.value.operation, position: row.record.value.position })) } });
730
+ const rows = serviceInstances(space, name);
731
+ for (const row of rows)
732
+ refuseRecordedSupervisor(row.record.value, "remove");
733
+ for (const row of rows)
734
+ if (!gone(observeServiceProcess(row.record.value)))
735
+ throw new CommandFailure("refused", "LIFECYCLE_BLOCKED", "service remove requires every recorded owned instance stopped and its supervisor uninstalled", { target: instanceProjection(row), remedy: `use cotal service stop ${name} --instance ${row.name} before removing its definition` });
736
+ // A settled exit is a record of evidence, not an unknown request. An unsettled one is settled by
737
+ // the named stop, which signals nothing when the process is already gone.
738
+ const settle = (row) => row.record.value.state === "stopping" || retainedStopRequest(row.record.value) ? { remedy: `inspect the original request with cotal service status ${name} --instance ${row.name} --space ${space}` }
739
+ : UNSETTLED_RUN.includes(row.record.value.state) ? { remedy: `record the exit with cotal service stop ${name} --instance ${row.name} --space ${space} --yes, then remove it` } : {};
740
+ for (const row of rows)
741
+ if (row.record.value.nativeStopRequired && row.record.value.process && !row.record.value.nativeStop && !exitedWithoutStop(row.record.value))
742
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the native service has no confirmed terminal stop; its launch and unknown request cannot be forgotten merely because the process disappeared", { target: instanceProjection(row), ...settle(row) });
743
+ for (const row of rows)
744
+ if (row.record.value.kernelStopRequired && row.record.value.process && !row.record.value.kernelStop && !exitedWithoutStop(row.record.value))
745
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the broker has no recorded exact-exit stop from this controller; its launch cannot be forgotten merely because the process disappeared", { target: instanceProjection(row), ...settle(row) });
746
+ return rows;
747
+ }
748
+ /** Called under the definition writer lock, after stopped/host/supervisor checks for every row. */
749
+ export function removeStoppedInstanceRecords(space, name) {
750
+ const rows = removableServiceInstances(space, name), removed = [];
751
+ try {
752
+ for (const row of rows) {
753
+ serviceInstanceStore(space).commit(row.name, row, undefined);
754
+ removed.push(row.name);
755
+ }
756
+ }
757
+ catch (error) {
758
+ if (!removed.length)
759
+ throw error;
760
+ throw new CommandFailure("partial", "OPERATION_PARTIAL", "some stopped instance records were removed, but the definition was kept after another record changed", { target: { space, name }, changed: removed.map((instanceId) => ({ kind: "stopped-instance-record", instanceId })), remedy: "inspect the remaining records before another removal; no process was signalled and logs were retained" });
761
+ }
762
+ }
763
+ /** Read only bounded regular-file bytes; log data is not promised to be secret-redacted. */
764
+ export function readServiceLog(space, id, tail) {
765
+ const path = serviceLogPath(space, id);
766
+ if (!path)
767
+ return { lines: [], omittedBytes: 0, path: null };
768
+ let fd;
769
+ try {
770
+ fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
771
+ }
772
+ catch (error) {
773
+ if (error.code === "ENOENT")
774
+ return { lines: [], omittedBytes: 0, path };
775
+ throw error;
776
+ }
777
+ try {
778
+ const info = fstatSync(fd);
779
+ if (![info.size, info.dev, info.ino].every((number) => Number.isSafeInteger(number) && number >= 0))
780
+ throw new CommandFailure("refused", "UNSUPPORTED", "this log's native file coordinates cannot be represented safely; no approximate byte offsets were reported");
781
+ if (!info.isFile() || info.uid !== process.getuid() || (info.mode & 0o077) !== 0)
782
+ throw new CommandFailure("refused", "PERMISSION_DENIED", "the service log is not an owned private regular file");
783
+ const length = Math.min(info.size, 1024 * 1024), start = info.size - length;
784
+ const buffer = Buffer.alloc(length);
785
+ let offset = 0;
786
+ while (offset < length) {
787
+ const count = readSync(fd, buffer, offset, length - offset, start + offset);
788
+ if (!count)
789
+ break;
790
+ offset += count;
791
+ }
792
+ let text = buffer.subarray(0, offset).toString("utf8");
793
+ if (start)
794
+ text = text.includes("\n") ? text.slice(text.indexOf("\n") + 1) : "";
795
+ const all = text.replace(/\n$/, "").split("\n");
796
+ return { lines: text ? all.slice(-tail) : [], omittedBytes: start, path };
797
+ }
798
+ finally {
799
+ closeSync(fd);
800
+ }
801
+ }
802
+ /** One bounded raw log slice. File identity and byte offsets are local file facts, not global sequences. */
803
+ export function serviceLogSlice(space, id, position, tail) {
804
+ const path = serviceLogPath(space, id);
805
+ if (!path)
806
+ return undefined;
807
+ let fd;
808
+ try {
809
+ fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
810
+ }
811
+ catch (error) {
812
+ if (error.code === "ENOENT")
813
+ return undefined;
814
+ throw error;
815
+ }
816
+ try {
817
+ const info = fstatSync(fd);
818
+ if (![info.size, info.dev, info.ino].every((number) => Number.isSafeInteger(number) && number >= 0))
819
+ throw new CommandFailure("refused", "UNSUPPORTED", "this log's native file coordinates cannot be represented safely; no approximate byte offsets were reported");
820
+ if (!info.isFile() || info.uid !== process.getuid() || (info.mode & 0o077) !== 0)
821
+ throw new CommandFailure("refused", "PERMISSION_DENIED", "the selected service log is not an owned private regular file");
822
+ const replaced = position !== undefined && (position.dev !== info.dev || position.ino !== info.ino);
823
+ const truncated = position !== undefined && !replaced && info.size < position.offset;
824
+ let offset = position && !replaced && !truncated ? position.offset : 0;
825
+ let omittedBytes = 0;
826
+ if (!position || replaced || truncated) {
827
+ const length = Math.min(info.size, 1024 * 1024), start = info.size - length;
828
+ const sample = Buffer.alloc(length);
829
+ let read = 0;
830
+ while (read < length) {
831
+ const count = readSync(fd, sample, read, length - read, start + read);
832
+ if (!count)
833
+ break;
834
+ read += count;
835
+ }
836
+ let cursor = read && sample[read - 1] === 10 ? read - 1 : read;
837
+ for (let count = 0; count < tail; count++) {
838
+ if (cursor <= 0) {
839
+ cursor = -1;
840
+ break;
841
+ }
842
+ cursor = sample.lastIndexOf(10, cursor - 1);
843
+ if (cursor < 0)
844
+ break;
845
+ }
846
+ offset = start + cursor + 1;
847
+ omittedBytes = offset;
848
+ }
849
+ else if (info.size - offset > 1024 * 1024) {
850
+ const next = info.size - 1024 * 1024;
851
+ omittedBytes = next - offset;
852
+ offset = next;
853
+ }
854
+ const buffer = Buffer.alloc(Math.min(16_384, Math.max(0, info.size - offset)));
855
+ const count = buffer.length ? readSync(fd, buffer, 0, buffer.length, offset) : 0;
856
+ return { file: { dev: info.dev, ino: info.ino }, fromOffset: offset, toOffset: offset + count, sizeAtRead: info.size, bytes: buffer.subarray(0, count), omittedBytes, replaced, truncated };
857
+ }
858
+ finally {
859
+ closeSync(fd);
860
+ }
861
+ }
862
+ //# sourceMappingURL=service-process.js.map