@cotal-ai/cli 0.100.2 → 0.101.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (618) hide show
  1. package/dist/chat/chat-view.d.ts.map +1 -1
  2. package/dist/chat/chat-view.js +5 -1
  3. package/dist/chat/chat-view.js.map +1 -1
  4. package/dist/chat/engine.d.ts +2 -1
  5. package/dist/chat/engine.d.ts.map +1 -1
  6. package/dist/chat/engine.js +2 -1
  7. package/dist/chat/engine.js.map +1 -1
  8. package/dist/chat/frontend.d.ts.map +1 -1
  9. package/dist/chat/frontend.js +13 -7
  10. package/dist/chat/frontend.js.map +1 -1
  11. package/dist/chat/native-session.d.ts +22 -3
  12. package/dist/chat/native-session.d.ts.map +1 -1
  13. package/dist/chat/native-session.js +91 -19
  14. package/dist/chat/native-session.js.map +1 -1
  15. package/dist/chat/open-session.d.ts +1 -0
  16. package/dist/chat/open-session.d.ts.map +1 -1
  17. package/dist/chat/open-session.js +1 -1
  18. package/dist/chat/open-session.js.map +1 -1
  19. package/dist/chat/picker.d.ts +5 -0
  20. package/dist/chat/picker.d.ts.map +1 -1
  21. package/dist/chat/picker.js +23 -10
  22. package/dist/chat/picker.js.map +1 -1
  23. package/dist/chat/plain.d.ts.map +1 -1
  24. package/dist/chat/plain.js +36 -10
  25. package/dist/chat/plain.js.map +1 -1
  26. package/dist/chat/session.d.ts +5 -0
  27. package/dist/chat/session.d.ts.map +1 -1
  28. package/dist/chat/static-session.d.ts +1 -0
  29. package/dist/chat/static-session.d.ts.map +1 -1
  30. package/dist/chat/static-session.js +24 -8
  31. package/dist/chat/static-session.js.map +1 -1
  32. package/dist/chat/stdio-io.d.ts +2 -0
  33. package/dist/chat/stdio-io.d.ts.map +1 -1
  34. package/dist/chat/stdio-io.js +6 -6
  35. package/dist/chat/stdio-io.js.map +1 -1
  36. package/dist/chat/stdio.d.ts +3 -2
  37. package/dist/chat/stdio.d.ts.map +1 -1
  38. package/dist/chat/stdio.js +26 -25
  39. package/dist/chat/stdio.js.map +1 -1
  40. package/dist/chat/user-session.d.ts +1 -0
  41. package/dist/chat/user-session.d.ts.map +1 -1
  42. package/dist/chat/user-session.js +1 -1
  43. package/dist/chat/user-session.js.map +1 -1
  44. package/dist/chat/view.d.ts +5 -4
  45. package/dist/chat/view.d.ts.map +1 -1
  46. package/dist/chat/view.js +10 -8
  47. package/dist/chat/view.js.map +1 -1
  48. package/dist/command.d.ts +5 -0
  49. package/dist/command.d.ts.map +1 -1
  50. package/dist/command.js +295 -82
  51. package/dist/command.js.map +1 -1
  52. package/dist/commands/agents.d.ts +29 -5
  53. package/dist/commands/agents.d.ts.map +1 -1
  54. package/dist/commands/agents.js +100 -35
  55. package/dist/commands/agents.js.map +1 -1
  56. package/dist/commands/backup-maintenance.d.ts.map +1 -1
  57. package/dist/commands/backup-maintenance.js +54 -21
  58. package/dist/commands/backup-maintenance.js.map +1 -1
  59. package/dist/commands/backup-read.d.ts.map +1 -1
  60. package/dist/commands/backup-read.js +12 -15
  61. package/dist/commands/backup-read.js.map +1 -1
  62. package/dist/commands/backup-restore.d.ts.map +1 -1
  63. package/dist/commands/backup-restore.js +20 -4
  64. package/dist/commands/backup-restore.js.map +1 -1
  65. package/dist/commands/backup.d.ts.map +1 -1
  66. package/dist/commands/backup.js +156 -28
  67. package/dist/commands/backup.js.map +1 -1
  68. package/dist/commands/channel-members.d.ts +1 -1
  69. package/dist/commands/channel-members.d.ts.map +1 -1
  70. package/dist/commands/channel-members.js +115 -29
  71. package/dist/commands/channel-members.js.map +1 -1
  72. package/dist/commands/channels.d.ts +11 -1
  73. package/dist/commands/channels.d.ts.map +1 -1
  74. package/dist/commands/channels.js +109 -20
  75. package/dist/commands/channels.js.map +1 -1
  76. package/dist/commands/chat.d.ts +11 -3
  77. package/dist/commands/chat.d.ts.map +1 -1
  78. package/dist/commands/chat.js +50 -22
  79. package/dist/commands/chat.js.map +1 -1
  80. package/dist/commands/clean.d.ts +10 -5
  81. package/dist/commands/clean.d.ts.map +1 -1
  82. package/dist/commands/clean.js +245 -42
  83. package/dist/commands/clean.js.map +1 -1
  84. package/dist/commands/completion.d.ts +15 -2
  85. package/dist/commands/completion.d.ts.map +1 -1
  86. package/dist/commands/completion.js +91 -26
  87. package/dist/commands/completion.js.map +1 -1
  88. package/dist/commands/config.d.ts +24 -1
  89. package/dist/commands/config.d.ts.map +1 -1
  90. package/dist/commands/config.js +65 -13
  91. package/dist/commands/config.js.map +1 -1
  92. package/dist/commands/console.d.ts.map +1 -1
  93. package/dist/commands/console.js +5 -4
  94. package/dist/commands/console.js.map +1 -1
  95. package/dist/commands/describe.d.ts +4 -2
  96. package/dist/commands/describe.d.ts.map +1 -1
  97. package/dist/commands/describe.js +4 -4
  98. package/dist/commands/describe.js.map +1 -1
  99. package/dist/commands/doctor.d.ts +1 -1
  100. package/dist/commands/doctor.d.ts.map +1 -1
  101. package/dist/commands/doctor.js +261 -34
  102. package/dist/commands/doctor.js.map +1 -1
  103. package/dist/commands/down-manifest.d.ts.map +1 -1
  104. package/dist/commands/down-manifest.js +9 -6
  105. package/dist/commands/down-manifest.js.map +1 -1
  106. package/dist/commands/down-services.d.ts +17 -16
  107. package/dist/commands/down-services.d.ts.map +1 -1
  108. package/dist/commands/down-services.js +29 -53
  109. package/dist/commands/down-services.js.map +1 -1
  110. package/dist/commands/down.d.ts +2 -2
  111. package/dist/commands/down.d.ts.map +1 -1
  112. package/dist/commands/down.js +96 -67
  113. package/dist/commands/down.js.map +1 -1
  114. package/dist/commands/endpoint-deregister.d.ts.map +1 -1
  115. package/dist/commands/endpoint-deregister.js +2 -2
  116. package/dist/commands/endpoint-deregister.js.map +1 -1
  117. package/dist/commands/endpoint.d.ts +2 -1
  118. package/dist/commands/endpoint.d.ts.map +1 -1
  119. package/dist/commands/endpoint.js +2 -2
  120. package/dist/commands/endpoint.js.map +1 -1
  121. package/dist/commands/endpoints.d.ts +1 -0
  122. package/dist/commands/endpoints.d.ts.map +1 -1
  123. package/dist/commands/endpoints.js +20 -5
  124. package/dist/commands/endpoints.js.map +1 -1
  125. package/dist/commands/feedback.d.ts.map +1 -1
  126. package/dist/commands/feedback.js +40 -2
  127. package/dist/commands/feedback.js.map +1 -1
  128. package/dist/commands/help.d.ts.map +1 -1
  129. package/dist/commands/help.js +2 -1
  130. package/dist/commands/help.js.map +1 -1
  131. package/dist/commands/history-clear.d.ts.map +1 -1
  132. package/dist/commands/history-clear.js +67 -51
  133. package/dist/commands/history-clear.js.map +1 -1
  134. package/dist/commands/history.d.ts +17 -2
  135. package/dist/commands/history.d.ts.map +1 -1
  136. package/dist/commands/history.js +221 -34
  137. package/dist/commands/history.js.map +1 -1
  138. package/dist/commands/join.d.ts +2 -0
  139. package/dist/commands/join.d.ts.map +1 -1
  140. package/dist/commands/join.js +132 -80
  141. package/dist/commands/join.js.map +1 -1
  142. package/dist/commands/meshes-add.d.ts +19 -4
  143. package/dist/commands/meshes-add.d.ts.map +1 -1
  144. package/dist/commands/meshes-add.js +114 -15
  145. package/dist/commands/meshes-add.js.map +1 -1
  146. package/dist/commands/meshes-wizard.d.ts +1 -0
  147. package/dist/commands/meshes-wizard.d.ts.map +1 -1
  148. package/dist/commands/meshes-wizard.js +45 -13
  149. package/dist/commands/meshes-wizard.js.map +1 -1
  150. package/dist/commands/meshes.d.ts +1 -1
  151. package/dist/commands/meshes.d.ts.map +1 -1
  152. package/dist/commands/meshes.js +76 -47
  153. package/dist/commands/meshes.js.map +1 -1
  154. package/dist/commands/mint.d.ts.map +1 -1
  155. package/dist/commands/mint.js +212 -19
  156. package/dist/commands/mint.js.map +1 -1
  157. package/dist/commands/models.d.ts +5 -1
  158. package/dist/commands/models.d.ts.map +1 -1
  159. package/dist/commands/models.js +21 -13
  160. package/dist/commands/models.js.map +1 -1
  161. package/dist/commands/persona-remote.d.ts.map +1 -1
  162. package/dist/commands/persona-remote.js +24 -13
  163. package/dist/commands/persona-remote.js.map +1 -1
  164. package/dist/commands/persona.d.ts +1 -1
  165. package/dist/commands/persona.d.ts.map +1 -1
  166. package/dist/commands/persona.js +92 -23
  167. package/dist/commands/persona.js.map +1 -1
  168. package/dist/commands/personas.d.ts.map +1 -1
  169. package/dist/commands/personas.js +59 -40
  170. package/dist/commands/personas.js.map +1 -1
  171. package/dist/commands/reset-space-apply.d.ts.map +1 -1
  172. package/dist/commands/reset-space-apply.js +69 -17
  173. package/dist/commands/reset-space-apply.js.map +1 -1
  174. package/dist/commands/reset-store-apply.d.ts +16 -0
  175. package/dist/commands/reset-store-apply.d.ts.map +1 -1
  176. package/dist/commands/reset-store-apply.js +122 -23
  177. package/dist/commands/reset-store-apply.js.map +1 -1
  178. package/dist/commands/reset.d.ts.map +1 -1
  179. package/dist/commands/reset.js +8 -7
  180. package/dist/commands/reset.js.map +1 -1
  181. package/dist/commands/revoke-credential.d.ts +5 -0
  182. package/dist/commands/revoke-credential.d.ts.map +1 -0
  183. package/dist/commands/revoke-credential.js +128 -0
  184. package/dist/commands/revoke-credential.js.map +1 -0
  185. package/dist/commands/send.d.ts +11 -3
  186. package/dist/commands/send.d.ts.map +1 -1
  187. package/dist/commands/send.js +284 -47
  188. package/dist/commands/send.js.map +1 -1
  189. package/dist/commands/service-actions.d.ts +2 -1
  190. package/dist/commands/service-actions.d.ts.map +1 -1
  191. package/dist/commands/service-actions.js +117 -21
  192. package/dist/commands/service-actions.js.map +1 -1
  193. package/dist/commands/service-log-follow.js +1 -1
  194. package/dist/commands/service-log-follow.js.map +1 -1
  195. package/dist/commands/service-registry.d.ts +1 -1
  196. package/dist/commands/service-registry.d.ts.map +1 -1
  197. package/dist/commands/service-registry.js +74 -30
  198. package/dist/commands/service-registry.js.map +1 -1
  199. package/dist/commands/service-set-stop.d.ts.map +1 -1
  200. package/dist/commands/service-set-stop.js +3 -2
  201. package/dist/commands/service-set-stop.js.map +1 -1
  202. package/dist/commands/setup-start.d.ts.map +1 -1
  203. package/dist/commands/setup-start.js +46 -5
  204. package/dist/commands/setup-start.js.map +1 -1
  205. package/dist/commands/setup.d.ts.map +1 -1
  206. package/dist/commands/setup.js +28 -13
  207. package/dist/commands/setup.js.map +1 -1
  208. package/dist/commands/space-delete.d.ts.map +1 -1
  209. package/dist/commands/space-delete.js +130 -41
  210. package/dist/commands/space-delete.js.map +1 -1
  211. package/dist/commands/space-registration.d.ts +13 -6
  212. package/dist/commands/space-registration.d.ts.map +1 -1
  213. package/dist/commands/space-registration.js +167 -46
  214. package/dist/commands/space-registration.js.map +1 -1
  215. package/dist/commands/space.d.ts +15 -1
  216. package/dist/commands/space.d.ts.map +1 -1
  217. package/dist/commands/space.js +66 -24
  218. package/dist/commands/space.js.map +1 -1
  219. package/dist/commands/spawn-preview.d.ts.map +1 -1
  220. package/dist/commands/spawn-preview.js +48 -10
  221. package/dist/commands/spawn-preview.js.map +1 -1
  222. package/dist/commands/spawn.d.ts +36 -13
  223. package/dist/commands/spawn.d.ts.map +1 -1
  224. package/dist/commands/spawn.js +263 -129
  225. package/dist/commands/spawn.js.map +1 -1
  226. package/dist/commands/stack-down.d.ts +9 -3
  227. package/dist/commands/stack-down.d.ts.map +1 -1
  228. package/dist/commands/stack-down.js +344 -64
  229. package/dist/commands/stack-down.js.map +1 -1
  230. package/dist/commands/stack-gone.d.ts +17 -0
  231. package/dist/commands/stack-gone.d.ts.map +1 -0
  232. package/dist/commands/stack-gone.js +218 -0
  233. package/dist/commands/stack-gone.js.map +1 -0
  234. package/dist/commands/stack-up.d.ts +64 -4
  235. package/dist/commands/stack-up.d.ts.map +1 -1
  236. package/dist/commands/stack-up.js +482 -55
  237. package/dist/commands/stack-up.js.map +1 -1
  238. package/dist/commands/status.d.ts +76 -2
  239. package/dist/commands/status.d.ts.map +1 -1
  240. package/dist/commands/status.js +550 -112
  241. package/dist/commands/status.js.map +1 -1
  242. package/dist/commands/team-agent-apply.d.ts.map +1 -1
  243. package/dist/commands/team-agent-apply.js +4 -3
  244. package/dist/commands/team-agent-apply.js.map +1 -1
  245. package/dist/commands/team-agent-remove.d.ts.map +1 -1
  246. package/dist/commands/team-agent-remove.js +4 -4
  247. package/dist/commands/team-agent-remove.js.map +1 -1
  248. package/dist/commands/team-boot-controller.d.ts.map +1 -1
  249. package/dist/commands/team-boot-controller.js +8 -2
  250. package/dist/commands/team-boot-controller.js.map +1 -1
  251. package/dist/commands/team-channel-remove.d.ts.map +1 -1
  252. package/dist/commands/team-channel-remove.js +26 -10
  253. package/dist/commands/team-channel-remove.js.map +1 -1
  254. package/dist/commands/team-deploy-apply.d.ts.map +1 -1
  255. package/dist/commands/team-deploy-apply.js +4 -3
  256. package/dist/commands/team-deploy-apply.js.map +1 -1
  257. package/dist/commands/team-mixed-remove.js +5 -5
  258. package/dist/commands/team-mixed-remove.js.map +1 -1
  259. package/dist/commands/team.d.ts.map +1 -1
  260. package/dist/commands/team.js +94 -32
  261. package/dist/commands/team.js.map +1 -1
  262. package/dist/commands/telemetry.d.ts.map +1 -1
  263. package/dist/commands/telemetry.js +3 -1
  264. package/dist/commands/telemetry.js.map +1 -1
  265. package/dist/commands/topology.d.ts.map +1 -1
  266. package/dist/commands/topology.js +11 -7
  267. package/dist/commands/topology.js.map +1 -1
  268. package/dist/commands/up.d.ts +6 -6
  269. package/dist/commands/up.d.ts.map +1 -1
  270. package/dist/commands/up.js +963 -240
  271. package/dist/commands/up.js.map +1 -1
  272. package/dist/commands/update.d.ts.map +1 -1
  273. package/dist/commands/update.js +9 -3
  274. package/dist/commands/update.js.map +1 -1
  275. package/dist/commands/use.d.ts +5 -1
  276. package/dist/commands/use.d.ts.map +1 -1
  277. package/dist/commands/use.js +55 -12
  278. package/dist/commands/use.js.map +1 -1
  279. package/dist/commands/watch.d.ts +4 -1
  280. package/dist/commands/watch.d.ts.map +1 -1
  281. package/dist/commands/watch.js +15 -3
  282. package/dist/commands/watch.js.map +1 -1
  283. package/dist/commands/who.d.ts +2 -0
  284. package/dist/commands/who.d.ts.map +1 -1
  285. package/dist/commands/who.js +18 -5
  286. package/dist/commands/who.js.map +1 -1
  287. package/dist/commands/whoami.d.ts +44 -5
  288. package/dist/commands/whoami.d.ts.map +1 -1
  289. package/dist/commands/whoami.js +168 -16
  290. package/dist/commands/whoami.js.map +1 -1
  291. package/dist/console/app.d.ts +1 -1
  292. package/dist/console/app.d.ts.map +1 -1
  293. package/dist/console/app.js +15 -9
  294. package/dist/console/app.js.map +1 -1
  295. package/dist/console/launch.d.ts +25 -0
  296. package/dist/console/launch.d.ts.map +1 -0
  297. package/dist/console/launch.js +56 -0
  298. package/dist/console/launch.js.map +1 -0
  299. package/dist/console/ui/CommandPalette.d.ts +5 -4
  300. package/dist/console/ui/CommandPalette.d.ts.map +1 -1
  301. package/dist/console/ui/CommandPalette.js +136 -45
  302. package/dist/console/ui/CommandPalette.js.map +1 -1
  303. package/dist/console/ui/Help.js +1 -1
  304. package/dist/console/ui/Help.js.map +1 -1
  305. package/dist/console/ui/Modal.d.ts +10 -0
  306. package/dist/console/ui/Modal.d.ts.map +1 -0
  307. package/dist/console/ui/Modal.js +8 -0
  308. package/dist/console/ui/Modal.js.map +1 -0
  309. package/dist/console/ui/NewAgent.d.ts +14 -0
  310. package/dist/console/ui/NewAgent.d.ts.map +1 -0
  311. package/dist/console/ui/NewAgent.js +114 -0
  312. package/dist/console/ui/NewAgent.js.map +1 -0
  313. package/dist/console/ui/StatusBar.d.ts +1 -2
  314. package/dist/console/ui/StatusBar.d.ts.map +1 -1
  315. package/dist/console/ui/StatusBar.js +6 -8
  316. package/dist/console/ui/StatusBar.js.map +1 -1
  317. package/dist/console/ui/topo/Map.d.ts.map +1 -1
  318. package/dist/console/ui/topo/Map.js +1 -2
  319. package/dist/console/ui/topo/Map.js.map +1 -1
  320. package/dist/console/ui/topo/Matrix.js +2 -2
  321. package/dist/console/ui/topo/Matrix.js.map +1 -1
  322. package/dist/console/ui/topo/Sequence.d.ts.map +1 -1
  323. package/dist/console/ui/topo/Sequence.js +5 -4
  324. package/dist/console/ui/topo/Sequence.js.map +1 -1
  325. package/dist/console/ui/topo/model.d.ts +2 -1
  326. package/dist/console/ui/topo/model.d.ts.map +1 -1
  327. package/dist/console/ui/topo/model.js +4 -3
  328. package/dist/console/ui/topo/model.js.map +1 -1
  329. package/dist/exec-endpoint/service-adapter.d.ts.map +1 -1
  330. package/dist/exec-endpoint/service-adapter.js +13 -3
  331. package/dist/exec-endpoint/service-adapter.js.map +1 -1
  332. package/dist/ext-loader.d.ts +4 -0
  333. package/dist/ext-loader.d.ts.map +1 -1
  334. package/dist/ext-loader.js +6 -0
  335. package/dist/ext-loader.js.map +1 -1
  336. package/dist/help.d.ts.map +1 -1
  337. package/dist/help.js +44 -23
  338. package/dist/help.js.map +1 -1
  339. package/dist/index.d.ts.map +1 -1
  340. package/dist/index.js +59 -54
  341. package/dist/index.js.map +1 -1
  342. package/dist/lib/agent-skills.d.ts.map +1 -1
  343. package/dist/lib/agent-skills.js +2 -1
  344. package/dist/lib/agent-skills.js.map +1 -1
  345. package/dist/lib/attach-client.js +2 -2
  346. package/dist/lib/attach-client.js.map +1 -1
  347. package/dist/lib/backup-artifact.d.ts +29 -8
  348. package/dist/lib/backup-artifact.d.ts.map +1 -1
  349. package/dist/lib/backup-artifact.js +147 -26
  350. package/dist/lib/backup-artifact.js.map +1 -1
  351. package/dist/lib/broker-service.d.ts +27 -3
  352. package/dist/lib/broker-service.d.ts.map +1 -1
  353. package/dist/lib/broker-service.js +135 -27
  354. package/dist/lib/broker-service.js.map +1 -1
  355. package/dist/lib/broker-store-health.d.ts +89 -0
  356. package/dist/lib/broker-store-health.d.ts.map +1 -0
  357. package/dist/lib/broker-store-health.js +171 -0
  358. package/dist/lib/broker-store-health.js.map +1 -0
  359. package/dist/lib/cancel.d.ts +4 -4
  360. package/dist/lib/cancel.d.ts.map +1 -1
  361. package/dist/lib/cancel.js +5 -5
  362. package/dist/lib/cancel.js.map +1 -1
  363. package/dist/lib/completion-install.d.ts +11 -2
  364. package/dist/lib/completion-install.d.ts.map +1 -1
  365. package/dist/lib/completion-install.js +79 -21
  366. package/dist/lib/completion-install.js.map +1 -1
  367. package/dist/lib/completion-scripts.d.ts.map +1 -1
  368. package/dist/lib/completion-scripts.js +2 -2
  369. package/dist/lib/completion-scripts.js.map +1 -1
  370. package/dist/lib/completion.d.ts +5 -1
  371. package/dist/lib/completion.d.ts.map +1 -1
  372. package/dist/lib/completion.js +10 -0
  373. package/dist/lib/completion.js.map +1 -1
  374. package/dist/lib/concrete-channel.d.ts +6 -0
  375. package/dist/lib/concrete-channel.d.ts.map +1 -0
  376. package/dist/lib/concrete-channel.js +17 -0
  377. package/dist/lib/concrete-channel.js.map +1 -0
  378. package/dist/lib/confirmation-required.d.ts +3 -12
  379. package/dist/lib/confirmation-required.d.ts.map +1 -1
  380. package/dist/lib/confirmation-required.js +9 -8
  381. package/dist/lib/confirmation-required.js.map +1 -1
  382. package/dist/lib/connect.d.ts +9 -0
  383. package/dist/lib/connect.d.ts.map +1 -1
  384. package/dist/lib/connect.js +27 -0
  385. package/dist/lib/connect.js.map +1 -1
  386. package/dist/lib/control.d.ts +42 -12
  387. package/dist/lib/control.d.ts.map +1 -1
  388. package/dist/lib/control.js +130 -31
  389. package/dist/lib/control.js.map +1 -1
  390. package/dist/lib/controller-restore.d.ts.map +1 -1
  391. package/dist/lib/controller-restore.js +12 -7
  392. package/dist/lib/controller-restore.js.map +1 -1
  393. package/dist/lib/credential-authority.d.ts.map +1 -1
  394. package/dist/lib/credential-authority.js +3 -0
  395. package/dist/lib/credential-authority.js.map +1 -1
  396. package/dist/lib/credential-exports.d.ts +17 -0
  397. package/dist/lib/credential-exports.d.ts.map +1 -0
  398. package/dist/lib/credential-exports.js +21 -0
  399. package/dist/lib/credential-exports.js.map +1 -0
  400. package/dist/lib/debug-flag.d.ts +4 -0
  401. package/dist/lib/debug-flag.d.ts.map +1 -0
  402. package/dist/lib/debug-flag.js +7 -0
  403. package/dist/lib/debug-flag.js.map +1 -0
  404. package/dist/lib/default-persona.d.ts +2 -0
  405. package/dist/lib/default-persona.d.ts.map +1 -1
  406. package/dist/lib/default-persona.js +2 -0
  407. package/dist/lib/default-persona.js.map +1 -1
  408. package/dist/lib/delivery-proc.d.ts +1 -1
  409. package/dist/lib/delivery-proc.d.ts.map +1 -1
  410. package/dist/lib/delivery-proc.js +5 -4
  411. package/dist/lib/delivery-proc.js.map +1 -1
  412. package/dist/lib/delivery-responder.d.ts +7 -3
  413. package/dist/lib/delivery-responder.d.ts.map +1 -1
  414. package/dist/lib/delivery-responder.js +8 -4
  415. package/dist/lib/delivery-responder.js.map +1 -1
  416. package/dist/lib/denied-write.d.ts +8 -0
  417. package/dist/lib/denied-write.d.ts.map +1 -0
  418. package/dist/lib/denied-write.js +24 -0
  419. package/dist/lib/denied-write.js.map +1 -0
  420. package/dist/lib/endpoint-capability-gates.js +2 -2
  421. package/dist/lib/endpoint-capability-gates.js.map +1 -1
  422. package/dist/lib/flag-value-refusal.d.ts +8 -0
  423. package/dist/lib/flag-value-refusal.d.ts.map +1 -0
  424. package/dist/lib/flag-value-refusal.js +10 -0
  425. package/dist/lib/flag-value-refusal.js.map +1 -0
  426. package/dist/lib/install-umask.d.ts +5 -0
  427. package/dist/lib/install-umask.d.ts.map +1 -1
  428. package/dist/lib/install-umask.js +25 -0
  429. package/dist/lib/install-umask.js.map +1 -1
  430. package/dist/lib/interrupt-notice.d.ts +23 -1
  431. package/dist/lib/interrupt-notice.d.ts.map +1 -1
  432. package/dist/lib/interrupt-notice.js +27 -6
  433. package/dist/lib/interrupt-notice.js.map +1 -1
  434. package/dist/lib/interrupt-report.d.ts +7 -0
  435. package/dist/lib/interrupt-report.d.ts.map +1 -0
  436. package/dist/lib/interrupt-report.js +24 -0
  437. package/dist/lib/interrupt-report.js.map +1 -0
  438. package/dist/lib/isolated-broker.d.ts +1 -1
  439. package/dist/lib/isolated-broker.d.ts.map +1 -1
  440. package/dist/lib/isolated-broker.js +17 -8
  441. package/dist/lib/isolated-broker.js.map +1 -1
  442. package/dist/lib/legacy-start.d.ts +8 -6
  443. package/dist/lib/legacy-start.d.ts.map +1 -1
  444. package/dist/lib/legacy-start.js +36 -36
  445. package/dist/lib/legacy-start.js.map +1 -1
  446. package/dist/lib/manager-choice.d.ts +45 -4
  447. package/dist/lib/manager-choice.d.ts.map +1 -1
  448. package/dist/lib/manager-choice.js +214 -24
  449. package/dist/lib/manager-choice.js.map +1 -1
  450. package/dist/lib/manager-proc.d.ts.map +1 -1
  451. package/dist/lib/manager-proc.js +7 -6
  452. package/dist/lib/manager-proc.js.map +1 -1
  453. package/dist/lib/manifest/index.d.ts +5 -1
  454. package/dist/lib/manifest/index.d.ts.map +1 -1
  455. package/dist/lib/manifest/index.js +50 -5
  456. package/dist/lib/manifest/index.js.map +1 -1
  457. package/dist/lib/manifest/preflight.d.ts +4 -0
  458. package/dist/lib/manifest/preflight.d.ts.map +1 -1
  459. package/dist/lib/manifest/preflight.js +18 -1
  460. package/dist/lib/manifest/preflight.js.map +1 -1
  461. package/dist/lib/manifest/resolve.d.ts +8 -0
  462. package/dist/lib/manifest/resolve.d.ts.map +1 -1
  463. package/dist/lib/manifest/resolve.js +104 -11
  464. package/dist/lib/manifest/resolve.js.map +1 -1
  465. package/dist/lib/missing-flags.js +1 -1
  466. package/dist/lib/missing-flags.js.map +1 -1
  467. package/dist/lib/nats-bin.d.ts +28 -5
  468. package/dist/lib/nats-bin.d.ts.map +1 -1
  469. package/dist/lib/nats-bin.js +85 -7
  470. package/dist/lib/nats-bin.js.map +1 -1
  471. package/dist/lib/nearest-word.d.ts +14 -0
  472. package/dist/lib/nearest-word.d.ts.map +1 -0
  473. package/dist/lib/nearest-word.js +76 -0
  474. package/dist/lib/nearest-word.js.map +1 -0
  475. package/dist/lib/no-expiry-record.d.ts +8 -0
  476. package/dist/lib/no-expiry-record.d.ts.map +1 -0
  477. package/dist/lib/no-expiry-record.js +27 -0
  478. package/dist/lib/no-expiry-record.js.map +1 -0
  479. package/dist/lib/paths.d.ts +31 -0
  480. package/dist/lib/paths.d.ts.map +1 -1
  481. package/dist/lib/paths.js +92 -2
  482. package/dist/lib/paths.js.map +1 -1
  483. package/dist/lib/persona-files.d.ts +29 -6
  484. package/dist/lib/persona-files.d.ts.map +1 -1
  485. package/dist/lib/persona-files.js +179 -36
  486. package/dist/lib/persona-files.js.map +1 -1
  487. package/dist/lib/personas.d.ts +18 -1
  488. package/dist/lib/personas.d.ts.map +1 -1
  489. package/dist/lib/personas.js +65 -6
  490. package/dist/lib/personas.js.map +1 -1
  491. package/dist/lib/prompts.d.ts +7 -1
  492. package/dist/lib/prompts.d.ts.map +1 -1
  493. package/dist/lib/prompts.js +43 -3
  494. package/dist/lib/prompts.js.map +1 -1
  495. package/dist/lib/registry-errors.d.ts +2 -1
  496. package/dist/lib/registry-errors.d.ts.map +1 -1
  497. package/dist/lib/registry-errors.js +6 -2
  498. package/dist/lib/registry-errors.js.map +1 -1
  499. package/dist/lib/reset-space-plan.d.ts +2 -0
  500. package/dist/lib/reset-space-plan.d.ts.map +1 -1
  501. package/dist/lib/reset-space-plan.js +1 -1
  502. package/dist/lib/reset-space-plan.js.map +1 -1
  503. package/dist/lib/restore.d.ts +45 -3
  504. package/dist/lib/restore.d.ts.map +1 -1
  505. package/dist/lib/restore.js +233 -39
  506. package/dist/lib/restore.js.map +1 -1
  507. package/dist/lib/rolled-back-runs.d.ts +36 -0
  508. package/dist/lib/rolled-back-runs.d.ts.map +1 -0
  509. package/dist/lib/rolled-back-runs.js +96 -0
  510. package/dist/lib/rolled-back-runs.js.map +1 -0
  511. package/dist/lib/service-definitions.d.ts +16 -3
  512. package/dist/lib/service-definitions.d.ts.map +1 -1
  513. package/dist/lib/service-definitions.js +99 -27
  514. package/dist/lib/service-definitions.js.map +1 -1
  515. package/dist/lib/service-instances.d.ts +13 -1
  516. package/dist/lib/service-instances.d.ts.map +1 -1
  517. package/dist/lib/service-instances.js +56 -12
  518. package/dist/lib/service-instances.js.map +1 -1
  519. package/dist/lib/service-presets.d.ts.map +1 -1
  520. package/dist/lib/service-presets.js +16 -0
  521. package/dist/lib/service-presets.js.map +1 -1
  522. package/dist/lib/service-process.d.ts +51 -8
  523. package/dist/lib/service-process.d.ts.map +1 -1
  524. package/dist/lib/service-process.js +385 -48
  525. package/dist/lib/service-process.js.map +1 -1
  526. package/dist/lib/space-streams.d.ts +18 -0
  527. package/dist/lib/space-streams.d.ts.map +1 -0
  528. package/dist/lib/space-streams.js +35 -0
  529. package/dist/lib/space-streams.js.map +1 -0
  530. package/dist/lib/spawn-defaults.d.ts +25 -1
  531. package/dist/lib/spawn-defaults.d.ts.map +1 -1
  532. package/dist/lib/spawn-defaults.js +37 -1
  533. package/dist/lib/spawn-defaults.js.map +1 -1
  534. package/dist/lib/stack-journal.d.ts +157 -14
  535. package/dist/lib/stack-journal.d.ts.map +1 -1
  536. package/dist/lib/stack-journal.js +406 -49
  537. package/dist/lib/stack-journal.js.map +1 -1
  538. package/dist/lib/stack-listeners.d.ts +17 -0
  539. package/dist/lib/stack-listeners.d.ts.map +1 -0
  540. package/dist/lib/stack-listeners.js +54 -0
  541. package/dist/lib/stack-listeners.js.map +1 -0
  542. package/dist/lib/stack-members.d.ts +13 -0
  543. package/dist/lib/stack-members.d.ts.map +1 -0
  544. package/dist/lib/stack-members.js +24 -0
  545. package/dist/lib/stack-members.js.map +1 -0
  546. package/dist/lib/stack-resume.d.ts.map +1 -1
  547. package/dist/lib/stack-resume.js +5 -2
  548. package/dist/lib/stack-resume.js.map +1 -1
  549. package/dist/lib/stack-runs.d.ts +34 -0
  550. package/dist/lib/stack-runs.d.ts.map +1 -0
  551. package/dist/lib/stack-runs.js +75 -0
  552. package/dist/lib/stack-runs.js.map +1 -0
  553. package/dist/lib/status.d.ts +11 -0
  554. package/dist/lib/status.d.ts.map +1 -1
  555. package/dist/lib/status.js +4 -5
  556. package/dist/lib/status.js.map +1 -1
  557. package/dist/lib/stdout-owner.d.ts +12 -3
  558. package/dist/lib/stdout-owner.d.ts.map +1 -1
  559. package/dist/lib/stdout-owner.js +33 -5
  560. package/dist/lib/stdout-owner.js.map +1 -1
  561. package/dist/lib/store-dir.d.ts +68 -4
  562. package/dist/lib/store-dir.d.ts.map +1 -1
  563. package/dist/lib/store-dir.js +253 -17
  564. package/dist/lib/store-dir.js.map +1 -1
  565. package/dist/lib/team-additive-attempt.d.ts +1 -1
  566. package/dist/lib/team-channel-removal.d.ts.map +1 -1
  567. package/dist/lib/team-channel-removal.js +4 -0
  568. package/dist/lib/team-channel-removal.js.map +1 -1
  569. package/dist/lib/team-deploy-inspection.d.ts +13 -0
  570. package/dist/lib/team-deploy-inspection.d.ts.map +1 -1
  571. package/dist/lib/team-deploy-inspection.js +12 -0
  572. package/dist/lib/team-deploy-inspection.js.map +1 -1
  573. package/dist/lib/team-text.d.ts +6 -0
  574. package/dist/lib/team-text.d.ts.map +1 -0
  575. package/dist/lib/team-text.js +36 -0
  576. package/dist/lib/team-text.js.map +1 -0
  577. package/dist/lib/transient.d.ts +14 -8
  578. package/dist/lib/transient.d.ts.map +1 -1
  579. package/dist/lib/transient.js +72 -11
  580. package/dist/lib/transient.js.map +1 -1
  581. package/dist/lib/unusable-file.d.ts +13 -0
  582. package/dist/lib/unusable-file.d.ts.map +1 -0
  583. package/dist/lib/unusable-file.js +12 -0
  584. package/dist/lib/unusable-file.js.map +1 -0
  585. package/dist/lib/up-report.d.ts +6 -0
  586. package/dist/lib/up-report.d.ts.map +1 -1
  587. package/dist/lib/up-report.js +13 -0
  588. package/dist/lib/up-report.js.map +1 -1
  589. package/dist/lib/verdict.d.ts +14 -0
  590. package/dist/lib/verdict.d.ts.map +1 -0
  591. package/dist/lib/verdict.js +15 -0
  592. package/dist/lib/verdict.js.map +1 -0
  593. package/dist/managed-handoff.d.ts +11 -6
  594. package/dist/managed-handoff.d.ts.map +1 -1
  595. package/dist/managed-handoff.js +27 -18
  596. package/dist/managed-handoff.js.map +1 -1
  597. package/dist/render.d.ts +5 -2
  598. package/dist/render.d.ts.map +1 -1
  599. package/dist/render.js +44 -10
  600. package/dist/render.js.map +1 -1
  601. package/dist/telemetry.d.ts +4 -3
  602. package/dist/telemetry.d.ts.map +1 -1
  603. package/dist/telemetry.js +14 -6
  604. package/dist/telemetry.js.map +1 -1
  605. package/dist/ui.d.ts +3 -2
  606. package/dist/ui.d.ts.map +1 -1
  607. package/dist/ui.js +6 -4
  608. package/dist/ui.js.map +1 -1
  609. package/dist/view/mesh-view.d.ts.map +1 -1
  610. package/dist/view/mesh-view.js +4 -1
  611. package/dist/view/mesh-view.js.map +1 -1
  612. package/dist/watch-data.d.ts +9 -1
  613. package/dist/watch-data.d.ts.map +1 -1
  614. package/dist/watch-data.js +17 -3
  615. package/dist/watch-data.js.map +1 -1
  616. package/dist/watch-json.js +4 -3
  617. package/dist/watch-json.js.map +1 -1
  618. package/package.json +5 -5
@@ -4,13 +4,17 @@ import { hostname } from "node:os";
4
4
  import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
5
5
  import { jetstreamManager } from "@nats-io/jetstream";
6
6
  import { Kvm } from "@nats-io/kv";
7
- import { canonicalBackupStreamConfig, consumerConfigFromCheckpoint, deliveryBucket, downloadStreamSnapshot, finalizeStreamRestore, hardenPrivate, initiateStreamRestore, LEASE_TTL_MS, managerBucket, MANAGER_LEASE_TTL_MS, membershipBucket, MEMBERSHIP_MAX_BYTES, PRESENCE_STORAGE, presenceBucket, recordsBucket, recreateConsumerCheckpoint, spaceBackupInventory, uploadStreamRestoreChunk, validateSpaceAuth, validateSpaceBackupInventory, validateBackupStreamState, validateCanonicalBackupStreamConfig, createEndpointStreams, ensureArtifactStore, hardenedAuthorityStreamNames, } from "@cotal-ai/core";
8
- import { CommandFailure, acquireMaintenanceLock, assessRestoreClaim, bindRestoreListener, bindRestoreTarget, cutController, getSpaceAuth, markRestoreActive, settleTokenHandoff, markRestoreDegraded, moveSamePathRestoreSource, prepareAlternateRestore, prepareMissingSourceRestore, prepareSamePathRestore, localProcessOwnerStatus, readMaintenanceJournal, readMaintenanceResumeDocument, recordRestoreAttemptResources, recordRestoreManagerCommit, replaceDeadRestoreListener, repairRestoreDegradedToActive, releaseMaintenanceLock, workspaceSecretStore, writeRestoreCommitIntent, readStoreIdentity, } from "@cotal-ai/workspace";
9
- import { ArtifactFileFault, readStagedCheckpoints, stageArtifact } from "./backup-artifact.js";
7
+ import { canonicalBackupStreamConfig, consumerConfigFromCheckpoint, deliveryBucket, downloadStreamSnapshot, finalizeStreamRestore, hardenPrivate, initiateStreamRestore, LEASE_TTL_MS, managerBucket, MANAGER_LEASE_TTL_MS, membershipBucket, MEMBERSHIP_MAX_BYTES, PRESENCE_STORAGE, presenceBucket, recordsBucket, recreateConsumerCheckpoint, spaceBackupInventory, uploadStreamRestoreChunk, validateSpaceAuth, validateSpaceBackupInventory, validateBackupStreamState, validateCanonicalBackupStreamConfig, createEndpointStreams, ensureArtifactStore, hardenedAuthorityStreamNames, wfjStreamName, } from "@cotal-ai/core";
8
+ import { CommandFailure, acquireMaintenanceLock, assessMaintenanceClaim, assessRestoreClaim, bindRestoreListener, bindRestoreTarget, cutController, getSpaceAuth, markRestoreActive, settleTokenHandoff, markRestoreDegraded, moveSamePathRestoreSource, prepareAlternateRestore, prepareMissingSourceRestore, prepareSamePathRestore, localProcessOwnerStatus, readMaintenanceJournal, restoreLeftOut, restoreReplacedNewerCut, restoreRolledBackRuns, readMaintenanceResumeDocument, recordRestoreAttemptResources, recordRestoreManagerCommit, replaceDeadRestoreListener, repairRestoreDegradedToActive, releaseMaintenanceLock, shellPath, workspaceSecretStore, writeRestoreCommitIntent, readStoreIdentity, } from "@cotal-ai/workspace";
9
+ import { ArtifactFileFault, artifactStreams, BACKUP_MANIFEST_FORMAT_V1, missingBackupPath, missingBackupPathText, notAnArtifactRefusal, readStagedCheckpoints, stageArtifact } from "./backup-artifact.js";
10
10
  import { authorityFingerprint } from "./maintenance-files.js";
11
11
  import { attemptProcessesGone, connectIsolatedBroker, ensurePrivateAttemptsDir, startIsolatedBroker, sweepAttemptResidue } from "./isolated-broker.js";
12
+ import { readPreviousRunJournals, readRunJournals, rolledBackRuns } from "./rolled-back-runs.js";
12
13
  import { noticeOnInterrupt } from "./interrupt-notice.js";
14
+ import { displayCmd } from "./self-exec.js";
15
+ import { assertEndpointUnreachable } from "./endpoint-cut.js";
13
16
  import { acquireStackOperationLock } from "./stack-journal.js";
17
+ import { foreignEntriesRefusal, oldStoreForeignEntries } from "./store-dir.js";
14
18
  import { admitAndRestoreSeatCheckpoints } from "./seat-resume.js";
15
19
  import { assertControllerRestorable, reconfigureControllerBroker, rollbackRestoreWithBroker } from "./controller-restore.js";
16
20
  import { assertControllerCoupling, newControllerAttemptLaunch } from "./controller-resume.js";
@@ -60,6 +64,7 @@ export function rehydratePreparedRestore(root, journal) {
60
64
  runtime: launchString(journal.launch, "runtime"),
61
65
  detached: journal.launch.detached === true,
62
66
  selection: restoreOnly,
67
+ restoredStreams: journaledRestoredStreams(journal.launch, journal.space, journal.mode),
63
68
  inventory: resume.inventory,
64
69
  serverName,
65
70
  serverNonce,
@@ -164,11 +169,37 @@ function canonicalServerEndpoint(value) {
164
169
  throw new Error(`restore listener endpoint is not canonicalizable: ${value}`);
165
170
  return `${endpoint.protocol}//${endpoint.hostname.toLowerCase()}:${endpoint.port || "4222"}`;
166
171
  }
172
+ /** Whether `path` is a link that resolves to `target`. A dangling link resolves nowhere. */
173
+ function linksTo(path, target) {
174
+ if (!lstatSync(path, { throwIfNoEntry: false })?.isSymbolicLink())
175
+ return false;
176
+ try {
177
+ return realpathSync.native(path) === target;
178
+ }
179
+ catch {
180
+ return false;
181
+ }
182
+ }
167
183
  function contains(parent, child) {
168
184
  const path = relative(parent, child);
169
185
  const separator = process.platform === "win32" ? "\\" : "/";
170
186
  return path === "" || (path !== ".." && !path.startsWith(`..${separator}`) && !isAbsolute(path));
171
187
  }
188
+ /** The refusal for a restore artifact that is, holds or sits inside the store the restore replaces
189
+ * or this root's maintenance folder, where it stages its attempt, or `undefined` when it is clear
190
+ * of both. `artifact` and `store` are real paths. */
191
+ function artifactOverlapRefusal(root, artifact, store) {
192
+ for (const [path, what, why] of [
193
+ [store, "the preserved store", " it would replace"],
194
+ [realpathSync.native(join(root, ".cotal", "maintenance")), "this root's maintenance folder", ", where it stages its attempt"],
195
+ ]) {
196
+ if (!contains(path, artifact) && !contains(artifact, path))
197
+ continue;
198
+ const relation = artifact === path ? "is" : contains(path, artifact) ? "is inside" : "holds";
199
+ return new CommandFailure("refused", "USAGE_INVALID", `the restore artifact ${artifact} ${relation} ${what}${relation === "is" ? "" : ` ${path}`}${why}; nothing was restored`, { target: { root, directory: artifact, overlaps: path }, remedy: `name a backup artifact folder outside ${path}`, selfContained: true });
200
+ }
201
+ return undefined;
202
+ }
172
203
  /** An explicit `--store-dir` names the directory a restore creates and owns for its rollback, so it
173
204
  * must not exist yet and its parent must. Either mistake is a usage refusal before anything is
174
205
  * staged. The preserved source itself is the same-path restore. */
@@ -231,10 +262,10 @@ async function validateManifest(manifest, flags, ready, currentAuthority) {
231
262
  throw new Error("--open conflicts with the backup auth mode");
232
263
  if (flags["user-auth"] && manifest.mode !== "user")
233
264
  throw new Error("--user-auth conflicts with the backup auth mode");
234
- const inventory = spaceBackupInventory(manifest.space);
235
- const selected = flags["restore-only"] === "registry" ? inventory.registry : inventory[manifest.selection];
265
+ const held = artifactStreams(manifest);
266
+ const selected = flags["restore-only"] === "registry" ? spaceBackupInventory(manifest.space).registry : held;
236
267
  const actual = manifest.streams.map((entry) => entry.stream);
237
- if (new Set(actual).size !== actual.length || JSON.stringify([...actual].sort()) !== JSON.stringify([...inventory[manifest.selection]].sort()))
268
+ if (new Set(actual).size !== actual.length || JSON.stringify([...actual].sort()) !== JSON.stringify([...held].sort()))
238
269
  throw new Error("backup manifest stream inventory does not match its selection");
239
270
  for (const stream of selected) {
240
271
  const record = manifest.streams.find((entry) => entry.stream === stream);
@@ -253,13 +284,18 @@ async function validateManifest(manifest, flags, ready, currentAuthority) {
253
284
  // counting on during a disaster.
254
285
  // Checked before any transition, as the space is above: a refusal, not an unknown outcome.
255
286
  const sameAccount = manifest.authority?.account !== undefined && manifest.authority.account === currentAuthority.account;
287
+ // A registry restore does not check the trust state, so an artifact that holds the registry
288
+ // still restores that here, and the Next says how.
289
+ const registry = spaceBackupInventory(manifest.space).registry.every((stream) => held.includes(stream))
290
+ ? `; its channel registry still restores here with cotal backup restore ${shellPath(resolve(flags.restore))} --only registry, and chat and DM history and workflow runs then start empty`
291
+ : "";
256
292
  throw new CommandFailure("refused", "CONFLICT", sameAccount
257
293
  ? "backup authority fingerprint does not match current trust state: the data account is unchanged, so the OPERATOR/SYSTEM half of the trust chain moved - this artifact predates a system-account rotation (`cotal up --rotate-sys`) and is bound to the retired chain; the preserved cut was not changed"
258
294
  : "backup authority fingerprint does not match current trust state: this full artifact was taken under another trust state, such as another machine's or a reset root's; the preserved cut was not changed", {
259
295
  target: { space: ready.space },
260
- remedy: sameAccount
296
+ remedy: (sameAccount
261
297
  ? "restore it into a root holding that chain, or use a backup taken after the rotation"
262
- : "a full backup restores only into a root that still holds the trust state it was taken under: restore it there, or use a full backup taken on this root",
298
+ : "a full backup restores only into a root that still holds the trust state it was taken under: restore it there, or use a full backup taken on this root") + registry,
263
299
  });
264
300
  }
265
301
  }
@@ -398,10 +434,13 @@ async function recreateCheckpoint(broker, space, checkpoint) {
398
434
  await nc.drain().catch(() => { });
399
435
  }
400
436
  }
401
- async function createOmittedInfrastructure(broker, space, registryOnly) {
437
+ async function createOmittedInfrastructure(broker, space, restored) {
402
438
  const inventory = spaceBackupInventory(space);
403
- const create = registryOnly ? inventory.full.filter((name) => !inventory.registry.includes(name)) : [];
404
- const excluded = inventory.excluded.map((entry) => entry.name);
439
+ // The workflow stores are endpoint stores: createEndpointStreams below creates the ones the
440
+ // artifact did not hold and verifies the restored ones.
441
+ const workflow = inventory.backedUp.filter((entry) => entry.class === "workflow").map((entry) => entry.name);
442
+ const create = inventory.full.filter((name) => !restored.includes(name) && !workflow.includes(name));
443
+ const excluded = [...workflow, ...inventory.excluded.map((entry) => entry.name)];
405
444
  const login = await broker.addLogin({
406
445
  profile: "infrastructure",
407
446
  streams: [...create, ...excluded],
@@ -421,8 +460,9 @@ async function createOmittedInfrastructure(broker, space, registryOnly) {
421
460
  await kvm.create(membershipBucket(space), { history: 1, max_bytes: MEMBERSHIP_MAX_BYTES });
422
461
  await kvm.create(deliveryBucket(space), { ttl: LEASE_TTL_MS });
423
462
  await kvm.create(managerBucket(space), { ttl: MANAGER_LEASE_TTL_MS });
424
- // Endpoint journals and authority/session stores are nonportable control state. Recreate their
425
- // canonical empty infrastructure through the same production seam as ordinary space setup.
463
+ // The other endpoint stores are nonportable control state. Recreate them empty, with any workflow
464
+ // store the artifact did not hold, through the same production seam as ordinary space setup,
465
+ // which verifies the restored workflow stores.
426
466
  await createEndpointStreams(jsm, kvm, space);
427
467
  // The artifact Object Store is EXCLUDED from the backup artifact, which does not mean restore
428
468
  // ignores it: the assertion below covers `excluded` too, so a restored space must come back
@@ -459,13 +499,13 @@ async function createOmittedInfrastructure(broker, space, registryOnly) {
459
499
  }
460
500
  }
461
501
  async function restoreAndValidate(broker, space, staged, snapshotDir, pass, onlyRegistry, checkpoints, completeInfrastructure) {
462
- const wanted = onlyRegistry ? spaceBackupInventory(space).registry : spaceBackupInventory(space)[staged.manifest.selection];
502
+ const wanted = onlyRegistry ? spaceBackupInventory(space).registry : artifactStreams(staged.manifest);
463
503
  for (const name of wanted)
464
504
  await restoreStream(broker, space, snapshotDir, pass, staged.manifest.streams.find((entry) => entry.stream === name));
465
505
  for (const name of wanted)
466
506
  await validateRestoredStream(broker, space, staged.manifest.streams.find((entry) => entry.stream === name), 0);
467
507
  if (completeInfrastructure)
468
- await createOmittedInfrastructure(broker, space, onlyRegistry);
508
+ await createOmittedInfrastructure(broker, space, wanted);
469
509
  if (!onlyRegistry)
470
510
  for (const checkpoint of checkpoints)
471
511
  await recreateCheckpoint(broker, space, checkpoint);
@@ -514,15 +554,82 @@ export function preservedSourceState(root, source) {
514
554
  export function movedFolderRefusal(root, space, recordedStore, moved, then) {
515
555
  return new CommandFailure("refused", "CONFLICT", `this folder was moved from ${moved.recordedRoot} after its state was preserved: the maintenance journal records the preserved store at ${recordedStore}, and that store is now ${moved.store}`, { target: { root, space, recordedRoot: moved.recordedRoot, recordedStore, store: moved.store }, remedy: `move this folder back to ${moved.recordedRoot}, then ${then} there` });
516
556
  }
557
+ /** The streams a restore attempt restored, from its launch record. A record written before full
558
+ * backups held workflow runs names none, and those attempts restored a v1 artifact's streams. */
559
+ export function journaledRestoredStreams(launch, space, mode) {
560
+ const recorded = launch.restoredStreams;
561
+ const selection = launchString(launch, "restoreOnly") === "registry" ? "registry" : "full";
562
+ if (recorded === undefined)
563
+ return [...artifactStreams({ format: BACKUP_MANIFEST_FORMAT_V1, space, selection, mode })];
564
+ if (!Array.isArray(recorded) || recorded.some((name) => typeof name !== "string"))
565
+ throw new Error("restore launch record has an invalid restoredStreams");
566
+ return recorded;
567
+ }
568
+ const CLASS_WORDS = {
569
+ registry: "channel registry", messages: "messages", authorization: "channel ACLs and members", workflow: "workflow runs",
570
+ transient: "presence", derived: "membership", lease: "leases", control: "endpoint control stores", artifact: "artifact store",
571
+ };
572
+ /** What a restore brought back from the artifact and what it recreated empty, by stream, and the
573
+ * same in words. A full restore that brought back no workflow store carries a note that says why:
574
+ * a user-mode artifact holds none, and an older artifact was made before full backups held runs. */
575
+ export function restoreComposition(space, restored, mode) {
576
+ const inventory = spaceBackupInventory(space);
577
+ const all = [...inventory.backedUp, ...inventory.excluded];
578
+ const empty = all.filter((entry) => !restored.includes(entry.name));
579
+ const words = (entries) => [...new Set(entries.map((entry) => CLASS_WORDS[entry.class]))].join(", ") || "none";
580
+ const workflow = inventory.backedUp.filter((entry) => entry.class === "workflow").map((entry) => entry.name);
581
+ return {
582
+ restored: [...restored],
583
+ recreatedEmpty: empty.map((entry) => entry.name),
584
+ restoredWords: words(all.filter((entry) => restored.includes(entry.name))),
585
+ emptyWords: words(empty),
586
+ ...(restored.length > inventory.registry.length && !workflow.some((name) => restored.includes(name))
587
+ ? { note: mode === "user" ? USER_MODE_NO_RUNS : OLDER_FORMAT_NO_RUNS } : {}),
588
+ };
589
+ }
590
+ const USER_MODE_NO_RUNS = "A user-mode backup holds no workflow runs, because the records store's lifecycle heads name credential rows in the auth store, which a backup does not carry; the workflow run stores were recreated empty.";
591
+ const OLDER_FORMAT_NO_RUNS = "This backup was made before full backups held workflow runs, so it holds none; the workflow run stores were recreated empty.";
517
592
  /** The step that moves a full restore attempt on from `state`, for a refusal to name. A committed or
518
- * degraded attempt goes forward through bare `up`, which continues it. */
519
- export function restoreNextStep(state, attemptId) {
593
+ * degraded attempt goes forward through bare `up`, which continues it. `leftOut` is what the restore
594
+ * left only in its previous store ({@link restoreLeftOut}). */
595
+ export function restoreNextStep(state, attemptId, leftOut) {
520
596
  if (state === "restore-ready")
521
597
  return `roll the pre-commit attempt back with cotal backup recover ${attemptId} --yes; preview it first with --dry-run`;
598
+ // That restore's cleanup also deletes the store that holds the only copy of what it left out, so
599
+ // it runs only with --discard-history.
600
+ if (state === "active" && leftOut)
601
+ return `the restore completed: cotal backup cleanup-fallback ${attemptId} --yes --discard-history retires its journal and deletes the previous store, the only copy of the ${leftOut} it left out; preview it first with --dry-run`;
522
602
  if (state === "active")
523
603
  return `the restore completed: retire its journal with cotal backup cleanup-fallback ${attemptId} --yes; preview it first with --dry-run`;
524
604
  return `recover forward with bare cotal up from this root, which continues attempt ${attemptId}; fallback cleanup follows once it is active`;
525
605
  }
606
+ /** A ready journal's next step. Resume and backup use the store at its recorded path, so a folder
607
+ * moved after the cut is told to move back, and a missing store is named. */
608
+ function readyNextStep(root, source) {
609
+ const where = preservedSourceState(root, source);
610
+ if (where.state === "moved")
611
+ return `this folder was moved from ${where.recordedRoot} after its state was preserved: move it back there, then create a backup or resume with bare ${displayCmd()} up`;
612
+ if (where.state === "missing")
613
+ return `the preserved store recorded at ${source.path} is missing: if this folder was moved, move it back; if the store is lost, restore a backup with ${displayCmd()} backup restore <dir> --accept-missing-source`;
614
+ return `create a backup with ${displayCmd()} backup create <dir>, or resume with bare ${displayCmd()} up`;
615
+ }
616
+ /** The next step for a cut a backup create still claims: wait while it runs, or release it once it
617
+ * stopped before it finished. */
618
+ function claimedNextStep(root, claim) {
619
+ const recover = `${displayCmd()} backup recover ${claim.attemptId} --yes`;
620
+ if (assessMaintenanceClaim(claim, { unrecordedOwnersDead: attemptProcessesGone(root) }) === "stale")
621
+ return `backup attempt ${claim.attemptId} stopped before it finished: release it with ${recover}`;
622
+ return `backup attempt ${claim.attemptId} holds this root until ${claim.deadline} (process ${claim.coordinator.pid}); if it was stopped, run ${recover} once it has exited`;
623
+ }
624
+ /** The attempt a root's maintenance journal holds and the step that moves it on, as `cotal status`
625
+ * shows it and a command that refuses over that journal names it. */
626
+ export function maintenanceNextStep(root, journal) {
627
+ const attemptId = "restore" in journal ? journal.restore.attemptId : journal.state === "claimed" ? journal.claim.attemptId : journal.cut.attemptId;
628
+ const next = "restore" in journal ? restoreNextStep(journal.state, attemptId, restoreLeftOut(journal))
629
+ : journal.state === "ready" ? readyNextStep(root, journal.source)
630
+ : journal.state === "claimed" ? claimedNextStep(root, journal.claim) : null;
631
+ return { attemptId, next };
632
+ }
526
633
  /** The refusal while a restore's or backup's claim is not provably stale: what holds it, until
527
634
  * when, and when `backup recover` can release it. The refusing command changed nothing. */
528
635
  export function heldClaim(root, attemptId, claim, command, assessment) {
@@ -533,12 +640,57 @@ export function heldClaim(root, attemptId, claim, command, assessment) {
533
640
  const [holder, remedy] = assessment === "ambiguous"
534
641
  ? [`its processes on host ${coordinator.host} cannot be proven gone from this host`, `prove its ${kind} process and brokers on ${coordinator.host} have exited, then run ${recover}`]
535
642
  : coordinatorRuns
536
- ? [`its ${kind} process ${coordinator.pid} is still running`, `wait for that ${kind} to finish; if it was stopped, run ${recover} once process ${coordinator.pid} has exited`]
643
+ ? [`its ${kind} process ${coordinator.pid} is still running, started at ${coordinator.startedAt}`, `wait for that ${kind} to finish; if it was stopped, run ${recover} once process ${coordinator.pid} has exited`]
537
644
  : running.length
538
645
  ? [`its ${kind} process ${coordinator.pid} has exited, and its brokers (pid ${running.join(", ")}) are still stopping`, `run ${recover} again once they have exited`]
539
646
  : [`its ${kind} process ${coordinator.pid} has exited, but a broker it started cannot be proven gone`, `run ${recover} after ${deadline}`];
540
647
  return new CommandFailure("refused", "LIFECYCLE_BLOCKED", `${command} is refused: ${kind} attempt ${attemptId} holds this root until ${deadline}, and ${holder}; nothing was changed`, { target: { root, attemptId, deadline, holderPid: coordinator.pid }, remedy });
541
648
  }
649
+ /** What a restore attempt left only in the store it set aside ({@link restoreLeftOut}), whether that
650
+ * includes what was written after its artifact ({@link restoreReplacedNewerCut}), and that store, as
651
+ * the root's journal records them. Undefined when it left nothing out or the journal no longer names
652
+ * the attempt. */
653
+ export function restoreOnlyCopy(root, attemptId) {
654
+ try {
655
+ const journal = readMaintenanceJournal(root);
656
+ if (!journal || !("restore" in journal) || journal.restore.attemptId !== attemptId)
657
+ return undefined;
658
+ const leftOut = restoreLeftOut(journal);
659
+ return leftOut ? { leftOut, newer: restoreReplacedNewerCut(journal), rolledBack: restoreRolledBackRuns(journal), ...(journal.restore.previousSource ? { previousStore: journal.restore.previousSource.identity.path } : {}) } : undefined;
660
+ }
661
+ catch {
662
+ return undefined;
663
+ }
664
+ }
665
+ /** What a restore over a newer cut says about each run it rolled back ({@link restoreRolledBackRuns}):
666
+ * the steps settled after the artifact that are open again, and that the previous store holds the
667
+ * only copy of how they settled. Answering a reopened step again is allowed. */
668
+ export function rolledBackNotes(rolledBack) {
669
+ const lines = rolledBack.runs.map((row) => {
670
+ if (row.missing)
671
+ return `Run ${row.run} started after this backup, so the restore removed it; only the previous store holds it.`;
672
+ if (!row.reopened.length)
673
+ return `Run ${row.run} went back to where this backup left it; what it recorded after that is only in the previous store.`;
674
+ const one = row.reopened.length === 1;
675
+ const answered = row.reopened.every((key) => /^(checkpoint|ask)\b/.test(key.slice(key.lastIndexOf("/") + 1)));
676
+ const kept = answered ? (one ? "That answer is" : "Those answers are") : (one ? "Its outcome is" : "Their outcomes are");
677
+ return `Run ${row.run} went back to where this backup left it: ${row.reopened.join(", ")} ${one ? "was" : "were"} ${answered ? "answered" : "settled"} after that and ${one ? "is" : "are"} open again. ${kept} only in the previous store.`;
678
+ });
679
+ return rolledBack.more ? [...lines, `${rolledBack.more} more runs went back as well.`] : lines;
680
+ }
681
+ /** What a restore's receipt says about what it left out. A registry-only restore brings back channel
682
+ * settings only, and every other stream starts empty; a full restore of an artifact with no runs has
683
+ * a composition note that says why, and one of an artifact older than the state it replaced says
684
+ * that what was written after the artifact is not restored. The store it set aside holds the only
685
+ * copy, which cleanup-fallback deletes only with `--discard-history`. */
686
+ export function leftOutNotes(attemptId, selection, onlyCopy) {
687
+ if (!onlyCopy)
688
+ return [];
689
+ const kept = onlyCopy.previousStore ? `The previous store at ${onlyCopy.previousStore} holds the only copy of ${selection === "registry" ? "them" : `the ${onlyCopy.leftOut}`}. \`cotal backup cleanup-fallback ${attemptId}\` deletes it only with --discard-history.` : undefined;
690
+ if (selection !== "registry")
691
+ return [...(onlyCopy.newer ? ["This backup was made before the state it replaced was preserved, so the chat and DM history and workflow runs written after it are not restored.", ...rolledBackNotes(onlyCopy.rolledBack)] : []), ...(kept ? [kept] : [])];
692
+ return ["A registry-only restore brings back channel settings only, so chat and DM history and workflow runs start empty.", kept ?? "No previous store was retained."];
693
+ }
542
694
  /** The restore attempt the root's journal holds, with the step that moves it on, so a failure can
543
695
  * name the full attempt a recovery command needs. An unreadable journal names none. */
544
696
  export function heldRestoreAttempt(root) {
@@ -551,12 +703,12 @@ export function heldRestoreAttempt(root) {
551
703
  }
552
704
  if (!journal || !("restore" in journal))
553
705
  return undefined;
554
- return { attemptId: journal.restore.attemptId, journalState: journal.state, remedy: restoreNextStep(journal.state, journal.restore.attemptId) };
706
+ return { attemptId: journal.restore.attemptId, journalState: journal.state, remedy: restoreNextStep(journal.state, journal.restore.attemptId, restoreLeftOut(journal)) };
555
707
  }
556
708
  /** A root with no stopped preserved cut to restore into. Nothing was staged, moved or claimed. */
557
709
  function notRestorable(root, journal) {
558
710
  const remedy = !journal ? "restore needs the stopped preserved cut from `cotal down --preserve-state` on this root"
559
- : "restore" in journal ? restoreNextStep(journal.state, journal.restore.attemptId)
711
+ : "restore" in journal ? restoreNextStep(journal.state, journal.restore.attemptId, restoreLeftOut(journal))
560
712
  : "this root's maintenance attempt must finish first; check it with cotal status";
561
713
  return new CommandFailure("refused", "LIFECYCLE_BLOCKED", `restore requires stable ready maintenance state, found ${journal?.state ?? "none"}`, { target: { root, ...(journal ? { state: journal.state } : {}) }, remedy });
562
714
  }
@@ -572,9 +724,24 @@ export async function prepareRestore(root, flags, progress) {
572
724
  const deadline = new Date(Date.now() + RESTORE_TIMEOUT_MS);
573
725
  // With no journal there is no cut to restore into. Refuse before the lock creates the maintenance
574
726
  // directory, so a refused restore leaves the folder as it found it and `up` there sees no state.
575
- if (!readMaintenanceJournal(root))
727
+ const recorded = readMaintenanceJournal(root);
728
+ if (!recorded)
576
729
  throw notRestorable(root, undefined);
577
- let lock = acquireStackOperationLock(root);
730
+ // A path that names nothing is refused here too, saying whether its folder or the artifact is missing.
731
+ const named = resolve(flags.restore);
732
+ const missing = missingBackupPath(named);
733
+ if (missing)
734
+ throw new CommandFailure("refused", "TARGET_NOT_FOUND", `${missingBackupPathText(named, missing)}; nothing was restored`, { target: { root, directory: named, folder: dirname(named), missing }, remedy: "name an existing backup artifact folder; cotal backup verify <dir> checks one before a restore" });
735
+ // So is a path that cannot be an artifact, saying what it is: one that is, holds or sits inside
736
+ // the store the restore replaces or the folder it stages in, a file, or a folder no create wrote.
737
+ const namedPath = realpathSync.native(named);
738
+ const overlap = artifactOverlapRefusal(root, namedPath, recorded.source.path);
739
+ if (overlap)
740
+ throw overlap;
741
+ const notArtifact = notAnArtifactRefusal(root, namedPath, "nothing was restored", { root });
742
+ if (notArtifact)
743
+ throw notArtifact;
744
+ let lock = acquireStackOperationLock(root, "restore");
578
745
  let staged;
579
746
  let transitioned = false;
580
747
  let targetBound = false;
@@ -634,30 +801,37 @@ export async function prepareRestore(root, flags, progress) {
634
801
  const currentAuthority = await authorityFingerprint(root, journal.space, journal.mode);
635
802
  const stageParent = ensurePrivateAttemptsDir(root).path;
636
803
  const artifactPath = realpathSync.native(resolve(flags.restore));
637
- if (contains(journal.source.path, artifactPath) || contains(artifactPath, journal.source.path))
638
- throw new Error("restore artifact must not overlap the preserved source store");
639
- if (contains(stageParent, artifactPath) || contains(artifactPath, stageParent))
640
- throw new Error("restore artifact must not overlap the maintenance attempt directory");
641
- targetPath = resolve(flags["store-dir"] ?? (controller ? journal.source.path : join(root, ".cotal", "nats")));
804
+ // Again under the lock: a link in the path may name another folder now, and the journal is reread.
805
+ const lockedOverlap = artifactOverlapRefusal(root, artifactPath, journal.source.path);
806
+ if (lockedOverlap)
807
+ throw lockedOverlap;
808
+ // The cut records its source by real path, so a default .cotal/nats that links there is that
809
+ // source and is restored in place, not taken for an alternate target.
810
+ const defaultStore = join(root, ".cotal", "nats");
811
+ targetPath = resolve(flags["store-dir"] ?? (controller || linksTo(defaultStore, journal.source.path) ? journal.source.path : defaultStore));
642
812
  if (flags["store-dir"] !== undefined)
643
813
  assertNewStorePath(targetPath, journal.source.path);
644
814
  assertRestoreTargetPath(journal.source.path, artifactPath, stageParent, targetPath);
815
+ // A restore into the preserved store's own path moves that store aside whole, so a file in it that
816
+ // no Cotal store writes would move with it; it is refused before anything moves. A store restored
817
+ // elsewhere stays where it is, and its cleanup refuses instead.
818
+ if (targetPath === journal.source.path) {
819
+ const foreign = oldStoreForeignEntries(journal.source.path);
820
+ if (foreign.length)
821
+ throw foreignEntriesRefusal(journal.source.path, foreign, "the preserved store", "a restore into it moves that store aside whole, so nothing was restored", "the restore", { root, space: journal.space });
822
+ }
645
823
  // The journal is ready with no live claim, and the artifact/target are proven disjoint from
646
824
  // the attempts directory: any attempts-dir content is dead-attempt residue.
647
825
  sweepAttemptResidue(root);
648
- // Staging checks each artifact file before any transition, so a file fault leaves the preserved
649
- // cut unchanged: the same refusal `backup verify` gives for that file.
650
826
  let artifact;
827
+ // A faulty artifact is refused before anything moves, naming the file and fault verify names.
651
828
  try {
652
829
  artifact = stageArtifact(artifactPath, stageParent);
653
830
  }
654
831
  catch (error) {
655
832
  if (!(error instanceof ArtifactFileFault))
656
833
  throw error;
657
- throw new CommandFailure("refused", "SCHEMA_INVALID", `${error.message}; nothing was restored and the preserved cut was not changed`, {
658
- target: { directory: artifactPath, file: error.file, fault: error.fault },
659
- remedy: "this copy cannot be restored as it is: check another copy of the same artifact with cotal backup verify and restore that one, or restore a newer backup",
660
- });
834
+ throw new CommandFailure("refused", "SCHEMA_INVALID", `${error.message}; nothing was restored`, { target: { root, directory: artifactPath, file: error.file, fault: error.fault }, remedy: "this copy cannot be restored as it is: check it with cotal backup verify, or restore another copy of the same artifact; the preserved cut is unchanged" });
661
835
  }
662
836
  staged = artifact;
663
837
  await validateManifest(artifact.manifest, flags, journal, currentAuthority);
@@ -672,12 +846,14 @@ export async function prepareRestore(root, flags, progress) {
672
846
  // The partial selection is a property of the artifact, not only of the flag: a registry-only
673
847
  // artifact restored without --restore-only registry must still create omitted infrastructure.
674
848
  const onlyRegistry = flags["restore-only"] === "registry" || artifact.manifest.selection === "registry";
849
+ // Journaled, so cleanup-fallback knows the previous store holds the only copy of what was left out.
850
+ const selection = onlyRegistry ? "registry" : "full";
675
851
  // Retained agents relaunch under their preserved runtime; a contradicting override must fail
676
852
  // in preflight, before any mutation or listener exposure.
677
853
  if (!onlyRegistry && flags.runtime && inventoryRuntimes[0] && flags.runtime !== inventoryRuntimes[0])
678
854
  throw new Error(`--runtime ${flags.runtime} contradicts the preserved agent runtime ${inventoryRuntimes[0]}; omit it or restore registry-only`);
679
855
  const effectiveRuntime = flags.runtime ?? inventoryRuntimes[0] ?? "pty";
680
- const wanted = onlyRegistry ? spaceBackupInventory(journal.space).registry : spaceBackupInventory(journal.space)[artifact.manifest.selection];
856
+ const wanted = onlyRegistry ? spaceBackupInventory(journal.space).registry : artifactStreams(artifact.manifest);
681
857
  for (const checkpoint of onlyRegistry ? [] : checkpoints) {
682
858
  if (!wanted.includes(checkpoint.stream))
683
859
  throw new Error(`checkpoint ${checkpoint.stream}/${checkpoint.name} is outside the restored selection`);
@@ -697,6 +873,13 @@ export async function prepareRestore(root, flags, progress) {
697
873
  if (JSON.stringify(authorityBeforeMutation) !== JSON.stringify(currentAuthority))
698
874
  throw new Error("current trust state changed during restore validation");
699
875
  await validateManifest(artifact.manifest, flags, journal, authorityBeforeMutation);
876
+ const resumeLaunch = (resume.launch ?? {});
877
+ const effectiveServer = canonicalServerEndpoint(controller ? journal.cut.launch.server : flags.server ?? (typeof resumeLaunch.server === "string" ? resumeLaunch.server : "nats://127.0.0.1:4222"));
878
+ // The restored broker binds this address after commit intent, so another listener there would
879
+ // leave the attempt degraded. It is refused here, before anything moves, as backup create does.
880
+ await assertEndpointUnreachable(effectiveServer).catch((error) => {
881
+ throw new CommandFailure("refused", "CONFLICT", `${error.message}; the restored broker needs that address, so the preserved cut was not changed`, { target: { root, space: journal.space, server: effectiveServer }, remedy: `stop the process that listens on ${effectiveServer}, then run the restore again` });
882
+ });
700
883
  const sourceExists = (() => {
701
884
  try {
702
885
  lstatSync(journal.source.path);
@@ -720,15 +903,15 @@ export async function prepareRestore(root, flags, progress) {
720
903
  if (!sourceExists) {
721
904
  if (!flags["accept-missing-source"])
722
905
  throw new CommandFailure("refused", "TARGET_NOT_FOUND", `the preserved source ${journal.source.path} is missing; nothing was changed`, { target: { root, space: journal.space, source: journal.source.path }, remedy: "put the preserved store back at that path, or, once you have verified it is lost, repeat the restore with --accept-missing-source to rebuild it from this backup" });
723
- prepareMissingSourceRestore(lock, { attemptId, targetPath, claim });
906
+ prepareMissingSourceRestore(lock, { attemptId, targetPath, claim, selection });
724
907
  }
725
908
  else if (targetPath === journal.source.path) {
726
909
  const fallbackPath = join(dirname(targetPath), `.cotal-restore-fallback-${attemptId}`);
727
- prepareSamePathRestore(lock, { attemptId, targetPath, fallbackPath, claim });
910
+ prepareSamePathRestore(lock, { attemptId, targetPath, fallbackPath, claim, selection });
728
911
  moveSamePathRestoreSource(lock);
729
912
  }
730
913
  else {
731
- prepareAlternateRestore(lock, { attemptId, targetPath, claim });
914
+ prepareAlternateRestore(lock, { attemptId, targetPath, claim, selection });
732
915
  }
733
916
  transitioned = true;
734
917
  createOwnedDirectory(targetPath);
@@ -816,8 +999,17 @@ export async function prepareRestore(root, flags, progress) {
816
999
  releaseMaintenanceLock(lock);
817
1000
  lock = undefined;
818
1001
  await restoreAndValidate(broker, journal.space, artifact, sanitized.path, "target", onlyRegistry, checkpoints, true);
1002
+ // A cut preserved after this artifact was made holds history the artifact lacks, and the store
1003
+ // this restore sets aside keeps its only copy. The runs it rolled back are named from the step
1004
+ // journals of both stores: the restored one here, the set-aside one from a private clone.
1005
+ const previousCutNewer = sourceExists && Date.parse(journal.cut.intentAt) > Date.parse(artifact.manifest.createdAt);
1006
+ const restoredRuns = previousCutNewer && wanted.includes(wfjStreamName(journal.space)) ? await readRunJournals(broker, journal.space) : undefined;
819
1007
  await broker.stop();
820
1008
  broker = undefined;
1009
+ const previousStore = restoredRuns ? readMaintenanceJournal(root)?.restore.previousSource?.identity.path : undefined;
1010
+ const rolledBack = restoredRuns && previousStore
1011
+ ? rolledBackRuns(await readPreviousRunJournals({ root, previousStore, attemptId, space: journal.space, mode: journal.mode, ...(auth ? { auth } : {}), deadline, record: recordResources }), restoredRuns)
1012
+ : undefined;
821
1013
  // The seats this restore is about to resume owe the same admission and the same restore as an
822
1014
  // ordinary one: the retained inventory here is this root's own preserved cut, and the manager
823
1015
  // operation it ends in is the same `resumePreserved`. Run them after the store is restored and
@@ -834,8 +1026,6 @@ export async function prepareRestore(root, flags, progress) {
834
1026
  // intent, so a failure up to here still rolls the definition back first.
835
1027
  if (controller && sourceExists && targetPath !== journal.source.path)
836
1028
  reconfigureControllerBroker(lock);
837
- const resumeLaunch = (resume.launch ?? {});
838
- const effectiveServer = canonicalServerEndpoint(controller ? journal.cut.launch.server : flags.server ?? (typeof resumeLaunch.server === "string" ? resumeLaunch.server : "nats://127.0.0.1:4222"));
839
1029
  const effectiveHost = controller ? new URL(effectiveServer).hostname : flags.host ?? (() => {
840
1030
  try {
841
1031
  return new URL(effectiveServer).hostname;
@@ -857,7 +1047,10 @@ export async function prepareRestore(root, flags, progress) {
857
1047
  detached: Boolean(flags.detach),
858
1048
  restoreSource: resolve(flags.restore),
859
1049
  restoreOnly: flags["restore-only"] ?? artifact.manifest.selection,
1050
+ restoredStreams: [...wanted],
860
1051
  acceptMissingSource: Boolean(flags["accept-missing-source"]),
1052
+ ...(previousCutNewer ? { previousCutNewer: true } : {}),
1053
+ ...(rolledBack?.runs.length ? { rolledBackRuns: rolledBack.runs, ...(rolledBack.more ? { rolledBackRunsMore: rolledBack.more } : {}) } : {}),
861
1054
  serverName,
862
1055
  serverNonce,
863
1056
  // Durable evidence of consent, as the ordinary resume journals it: an operator asking later
@@ -883,6 +1076,7 @@ export async function prepareRestore(root, flags, progress) {
883
1076
  runtime: effectiveRuntime,
884
1077
  detached: Boolean(flags.detach),
885
1078
  selection: onlyRegistry ? "registry" : artifact.manifest.selection,
1079
+ restoredStreams: wanted,
886
1080
  inventory: resume.inventory,
887
1081
  serverName,
888
1082
  serverNonce,