@dreamlake/dreamlake-cli 0.88.1 → 0.89.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 (535) hide show
  1. package/dist/api/access.d.ts +83 -0
  2. package/dist/api/access.js +77 -0
  3. package/dist/api/agent.d.ts +156 -0
  4. package/dist/api/agent.js +111 -0
  5. package/dist/api/browser.d.ts +90 -0
  6. package/dist/api/browser.js +102 -0
  7. package/dist/api/client.d.ts +53 -0
  8. package/dist/api/client.js +102 -0
  9. package/dist/api/common.d.ts +28 -0
  10. package/dist/api/common.js +16 -0
  11. package/dist/api/content.d.ts +195 -0
  12. package/dist/api/content.js +147 -0
  13. package/dist/api/execution.d.ts +84 -0
  14. package/dist/api/execution.js +73 -0
  15. package/dist/api/http.d.ts +19 -0
  16. package/dist/api/http.js +66 -0
  17. package/dist/api/index.d.ts +2330 -0
  18. package/dist/api/index.js +114 -0
  19. package/dist/api/infra.d.ts +2 -0
  20. package/dist/api/infra.js +2 -0
  21. package/dist/api/jobs.d.ts +2 -0
  22. package/dist/api/jobs.js +2 -0
  23. package/dist/api/layout.d.ts +2 -0
  24. package/dist/api/layout.js +2 -0
  25. package/dist/api/library-edit.d.ts +3 -0
  26. package/dist/api/library-edit.js +3 -0
  27. package/dist/api/library-manifest.d.ts +2 -0
  28. package/dist/api/library-manifest.js +2 -0
  29. package/dist/api/note-character-plan.d.ts +2 -0
  30. package/dist/api/note-character-plan.js +2 -0
  31. package/dist/api/note-editing.d.ts +2 -0
  32. package/dist/api/note-editing.js +2 -0
  33. package/dist/api/note-edits.d.ts +21 -0
  34. package/dist/api/note-edits.js +10 -0
  35. package/dist/api/note-events.d.ts +5 -0
  36. package/dist/api/note-events.js +11 -0
  37. package/dist/api/note-files.d.ts +75 -0
  38. package/dist/api/note-files.js +65 -0
  39. package/dist/api/note-html-read.d.ts +2 -0
  40. package/dist/api/note-html-read.js +2 -0
  41. package/dist/api/note-html.d.ts +2 -0
  42. package/dist/api/note-html.js +2 -0
  43. package/dist/api/note-toc.d.ts +2 -0
  44. package/dist/api/note-toc.js +2 -0
  45. package/dist/api/notes.d.ts +304 -0
  46. package/dist/api/notes.js +181 -0
  47. package/dist/api/open-resources.d.ts +27 -0
  48. package/dist/api/open-resources.js +102 -0
  49. package/dist/api/ownership.d.ts +12 -0
  50. package/dist/api/ownership.js +24 -0
  51. package/dist/api/platform.d.ts +83 -0
  52. package/dist/api/platform.js +56 -0
  53. package/dist/api/presigned-transfer.d.ts +2 -0
  54. package/dist/api/presigned-transfer.js +2 -0
  55. package/dist/api/registered-runs.d.ts +48 -0
  56. package/dist/api/registered-runs.js +33 -0
  57. package/dist/api/sessions.d.ts +299 -0
  58. package/dist/api/sessions.js +105 -0
  59. package/dist/api/storage.d.ts +46 -0
  60. package/dist/api/storage.js +34 -0
  61. package/dist/api/streams.d.ts +18 -0
  62. package/dist/api/streams.js +70 -0
  63. package/dist/api/vault.d.ts +93 -0
  64. package/dist/api/vault.js +79 -0
  65. package/dist/api/workspace.d.ts +180 -0
  66. package/dist/api/workspace.js +146 -0
  67. package/dist/cli/agent-identity.d.ts +4 -0
  68. package/dist/cli/agent-identity.js +21 -0
  69. package/dist/cli/agents/identity.d.ts +50 -0
  70. package/dist/cli/agents/identity.js +105 -0
  71. package/dist/cli/agents/index.d.ts +31 -0
  72. package/dist/cli/agents/index.js +580 -0
  73. package/dist/cli/agents/manage.d.ts +43 -0
  74. package/dist/cli/agents/manage.js +376 -0
  75. package/dist/cli/agents/spec.d.ts +104 -0
  76. package/dist/cli/agents/spec.js +280 -0
  77. package/dist/cli/agents/web.d.ts +7 -0
  78. package/dist/cli/agents/web.js +109 -0
  79. package/dist/cli/artifact/incremental.d.ts +21 -0
  80. package/dist/cli/artifact/incremental.js +80 -0
  81. package/dist/cli/artifact/index.d.ts +52 -0
  82. package/dist/cli/artifact/index.js +405 -0
  83. package/dist/cli/artifact/meta.d.ts +69 -0
  84. package/dist/cli/artifact/meta.js +189 -0
  85. package/dist/cli/auth/commands.d.ts +29 -0
  86. package/dist/cli/auth/commands.js +327 -0
  87. package/dist/cli/auth/constants.d.ts +13 -0
  88. package/dist/cli/auth/constants.js +18 -0
  89. package/dist/cli/auth/credentials.d.ts +37 -0
  90. package/dist/cli/auth/credentials.js +155 -0
  91. package/dist/cli/auth/device-flow.d.ts +32 -0
  92. package/dist/cli/auth/device-flow.js +154 -0
  93. package/dist/cli/auth/device-secret.d.ts +6 -0
  94. package/dist/cli/auth/device-secret.js +26 -0
  95. package/dist/cli/auth/machine.d.ts +15 -0
  96. package/dist/cli/auth/machine.js +126 -0
  97. package/dist/cli/auth/materialized.d.ts +32 -0
  98. package/dist/cli/auth/materialized.js +102 -0
  99. package/dist/cli/auth/migrate.d.ts +10 -0
  100. package/dist/cli/auth/migrate.js +75 -0
  101. package/dist/cli/client.d.ts +102 -0
  102. package/dist/cli/client.js +206 -0
  103. package/dist/cli/collection-list.d.ts +3 -0
  104. package/dist/cli/collection-list.js +25 -0
  105. package/dist/cli/compat/ctx.d.ts +26 -0
  106. package/dist/cli/compat/ctx.js +76 -0
  107. package/dist/cli/compat/dreamdb-wasm-embedded.d.ts +2 -0
  108. package/dist/cli/compat/dreamdb-wasm-embedded.js +8 -0
  109. package/dist/cli/compat/dreamdb-wasm.d.ts +1 -0
  110. package/dist/cli/compat/dreamdb-wasm.js +26 -0
  111. package/dist/cli/compat/dreamdb.d.ts +112 -0
  112. package/dist/cli/compat/dreamdb.js +219 -0
  113. package/dist/cli/compat/flags.d.ts +2 -0
  114. package/dist/cli/compat/flags.js +13 -0
  115. package/dist/cli/compat/http.d.ts +23 -0
  116. package/dist/cli/compat/http.js +137 -0
  117. package/dist/cli/compat/presignedTransfer.d.ts +139 -0
  118. package/dist/cli/compat/presignedTransfer.js +580 -0
  119. package/dist/cli/compat/s3-backend.d.ts +73 -0
  120. package/dist/cli/compat/s3-backend.js +132 -0
  121. package/dist/cli/config.d.ts +22 -0
  122. package/dist/cli/config.js +96 -0
  123. package/dist/cli/connection/dto.d.ts +159 -0
  124. package/dist/cli/connection/dto.js +497 -0
  125. package/dist/cli/connection/index.d.ts +50 -0
  126. package/dist/cli/connection/index.js +413 -0
  127. package/dist/cli/connection/oauth.d.ts +23 -0
  128. package/dist/cli/connection/oauth.js +290 -0
  129. package/dist/cli/connection/write.d.ts +47 -0
  130. package/dist/cli/connection/write.js +573 -0
  131. package/dist/cli/create/index.d.ts +19 -0
  132. package/dist/cli/create/index.js +209 -0
  133. package/dist/cli/declare/index.d.ts +29 -0
  134. package/dist/cli/declare/index.js +304 -0
  135. package/dist/cli/delete/index.d.ts +18 -0
  136. package/dist/cli/delete/index.js +232 -0
  137. package/dist/cli/download/index.d.ts +9 -0
  138. package/dist/cli/download/index.js +128 -0
  139. package/dist/cli/env/compose.d.ts +88 -0
  140. package/dist/cli/env/compose.js +402 -0
  141. package/dist/cli/env/index.d.ts +176 -0
  142. package/dist/cli/env/index.js +1011 -0
  143. package/dist/cli/experiments/index.d.ts +11 -0
  144. package/dist/cli/experiments/index.js +168 -0
  145. package/dist/cli/glob.d.ts +1 -0
  146. package/dist/cli/glob.js +45 -0
  147. package/dist/cli/graphql-helpers.d.ts +23 -0
  148. package/dist/cli/graphql-helpers.js +42 -0
  149. package/dist/cli/graphql.d.ts +10 -0
  150. package/dist/cli/graphql.js +47 -0
  151. package/dist/cli/help-examples.generated.d.ts +1 -0
  152. package/dist/cli/help-examples.generated.js +192 -0
  153. package/dist/cli/helpers.d.ts +8 -0
  154. package/dist/cli/helpers.js +106 -0
  155. package/dist/cli/hosts/api.d.ts +29 -0
  156. package/dist/cli/hosts/api.js +54 -0
  157. package/dist/cli/hosts/bootstrap-source.d.ts +1 -0
  158. package/dist/cli/hosts/bootstrap-source.js +2 -0
  159. package/dist/cli/hosts/catalog.d.ts +26 -0
  160. package/dist/cli/hosts/catalog.js +55 -0
  161. package/dist/cli/hosts/config.d.ts +45 -0
  162. package/dist/cli/hosts/config.js +179 -0
  163. package/dist/cli/hosts/credentials.d.ts +19 -0
  164. package/dist/cli/hosts/credentials.js +173 -0
  165. package/dist/cli/hosts/enroll.d.ts +17 -0
  166. package/dist/cli/hosts/enroll.js +109 -0
  167. package/dist/cli/hosts/enrollments.d.ts +25 -0
  168. package/dist/cli/hosts/enrollments.js +54 -0
  169. package/dist/cli/hosts/index.d.ts +6 -0
  170. package/dist/cli/hosts/index.js +279 -0
  171. package/dist/cli/hosts/inventory.d.ts +40 -0
  172. package/dist/cli/hosts/inventory.js +91 -0
  173. package/dist/cli/hosts/lifecycle.d.ts +15 -0
  174. package/dist/cli/hosts/lifecycle.js +108 -0
  175. package/dist/cli/hosts/metrics-source.d.ts +12 -0
  176. package/dist/cli/hosts/metrics-source.js +89 -0
  177. package/dist/cli/hosts/observations.d.ts +39 -0
  178. package/dist/cli/hosts/observations.js +102 -0
  179. package/dist/cli/hosts/remote.d.ts +5 -0
  180. package/dist/cli/hosts/remote.js +66 -0
  181. package/dist/cli/hosts/ssh.d.ts +63 -0
  182. package/dist/cli/hosts/ssh.js +276 -0
  183. package/dist/cli/index.d.ts +1 -0
  184. package/dist/cli/index.js +288 -0
  185. package/dist/cli/infra/api.d.ts +95 -0
  186. package/dist/cli/infra/api.js +291 -0
  187. package/dist/cli/infra/index.d.ts +5 -0
  188. package/dist/cli/infra/index.js +102 -0
  189. package/dist/cli/infra/move.d.ts +15 -0
  190. package/dist/cli/infra/move.js +123 -0
  191. package/dist/cli/infra/transfer.d.ts +15 -0
  192. package/dist/cli/infra/transfer.js +280 -0
  193. package/dist/cli/jobs/api.d.ts +69 -0
  194. package/dist/cli/jobs/api.js +121 -0
  195. package/dist/cli/jobs/index.d.ts +5 -0
  196. package/dist/cli/jobs/index.js +140 -0
  197. package/dist/cli/lakeshore/index.d.ts +98 -0
  198. package/dist/cli/lakeshore/index.js +502 -0
  199. package/dist/cli/launch/index.d.ts +43 -0
  200. package/dist/cli/launch/index.js +270 -0
  201. package/dist/cli/layout/index.d.ts +2 -0
  202. package/dist/cli/layout/index.js +44 -0
  203. package/dist/cli/layout/transport.d.ts +12 -0
  204. package/dist/cli/layout/transport.js +70 -0
  205. package/dist/cli/library/add.d.ts +60 -0
  206. package/dist/cli/library/add.js +348 -0
  207. package/dist/cli/library/cache.d.ts +26 -0
  208. package/dist/cli/library/cache.js +88 -0
  209. package/dist/cli/library/config.d.ts +75 -0
  210. package/dist/cli/library/config.js +198 -0
  211. package/dist/cli/library/digest.d.ts +5 -0
  212. package/dist/cli/library/digest.js +19 -0
  213. package/dist/cli/library/discover.d.ts +87 -0
  214. package/dist/cli/library/discover.js +534 -0
  215. package/dist/cli/library/freshness.d.ts +35 -0
  216. package/dist/cli/library/freshness.js +109 -0
  217. package/dist/cli/library/generation.d.ts +35 -0
  218. package/dist/cli/library/generation.js +211 -0
  219. package/dist/cli/library/index.d.ts +2 -0
  220. package/dist/cli/library/index.js +36 -0
  221. package/dist/cli/library/info.d.ts +69 -0
  222. package/dist/cli/library/info.js +311 -0
  223. package/dist/cli/library/list.d.ts +33 -0
  224. package/dist/cli/library/list.js +86 -0
  225. package/dist/cli/library/manifest.d.ts +81 -0
  226. package/dist/cli/library/manifest.js +200 -0
  227. package/dist/cli/library/manifestCache.d.ts +45 -0
  228. package/dist/cli/library/manifestCache.js +169 -0
  229. package/dist/cli/library/pull.d.ts +30 -0
  230. package/dist/cli/library/pull.js +438 -0
  231. package/dist/cli/library/push.d.ts +72 -0
  232. package/dist/cli/library/push.js +642 -0
  233. package/dist/cli/library/rm.d.ts +31 -0
  234. package/dist/cli/library/rm.js +200 -0
  235. package/dist/cli/library/search.d.ts +18 -0
  236. package/dist/cli/library/search.js +181 -0
  237. package/dist/cli/library/stat.d.ts +15 -0
  238. package/dist/cli/library/stat.js +127 -0
  239. package/dist/cli/library/tools.d.ts +104 -0
  240. package/dist/cli/library/tools.js +163 -0
  241. package/dist/cli/library/wire.d.ts +47 -0
  242. package/dist/cli/library/wire.js +120 -0
  243. package/dist/cli/list/index.d.ts +26 -0
  244. package/dist/cli/list/index.js +256 -0
  245. package/dist/cli/notes/character-plan.d.ts +22 -0
  246. package/dist/cli/notes/character-plan.js +232 -0
  247. package/dist/cli/notes/document.d.ts +73 -0
  248. package/dist/cli/notes/document.js +306 -0
  249. package/dist/cli/notes/edit-commands.d.ts +106 -0
  250. package/dist/cli/notes/edit-commands.js +623 -0
  251. package/dist/cli/notes/editing.d.ts +81 -0
  252. package/dist/cli/notes/editing.js +305 -0
  253. package/dist/cli/notes/events.d.ts +36 -0
  254. package/dist/cli/notes/events.js +54 -0
  255. package/dist/cli/notes/files-commands.d.ts +120 -0
  256. package/dist/cli/notes/files-commands.js +554 -0
  257. package/dist/cli/notes/html-read.d.ts +9 -0
  258. package/dist/cli/notes/html-read.js +90 -0
  259. package/dist/cli/notes/html.d.ts +73 -0
  260. package/dist/cli/notes/html.js +381 -0
  261. package/dist/cli/notes/index.d.ts +123 -0
  262. package/dist/cli/notes/index.js +1303 -0
  263. package/dist/cli/notes/linger.d.ts +59 -0
  264. package/dist/cli/notes/linger.js +339 -0
  265. package/dist/cli/notes/media-commands.d.ts +5 -0
  266. package/dist/cli/notes/media-commands.js +51 -0
  267. package/dist/cli/notes/move-command.d.ts +83 -0
  268. package/dist/cli/notes/move-command.js +259 -0
  269. package/dist/cli/notes/rm-command.d.ts +22 -0
  270. package/dist/cli/notes/rm-command.js +110 -0
  271. package/dist/cli/notes/select-command.d.ts +12 -0
  272. package/dist/cli/notes/select-command.js +84 -0
  273. package/dist/cli/notes/suggest-diff.d.ts +56 -0
  274. package/dist/cli/notes/suggest-diff.js +311 -0
  275. package/dist/cli/notes/toc.d.ts +38 -0
  276. package/dist/cli/notes/toc.js +144 -0
  277. package/dist/cli/notes/transfer-command.d.ts +6 -0
  278. package/dist/cli/notes/transfer-command.js +9 -0
  279. package/dist/cli/notes/version-commands.d.ts +19 -0
  280. package/dist/cli/notes/version-commands.js +178 -0
  281. package/dist/cli/nymph/index.d.ts +74 -0
  282. package/dist/cli/nymph/index.js +349 -0
  283. package/dist/cli/org/index.d.ts +34 -0
  284. package/dist/cli/org/index.js +341 -0
  285. package/dist/cli/ownership/index.d.ts +12 -0
  286. package/dist/cli/ownership/index.js +122 -0
  287. package/dist/cli/ownership/metadata-transfer.d.ts +20 -0
  288. package/dist/cli/ownership/metadata-transfer.js +159 -0
  289. package/dist/cli/page/index.d.ts +58 -0
  290. package/dist/cli/page/index.js +387 -0
  291. package/dist/cli/pipeline/index.d.ts +69 -0
  292. package/dist/cli/pipeline/index.js +604 -0
  293. package/dist/cli/progress.d.ts +60 -0
  294. package/dist/cli/progress.js +276 -0
  295. package/dist/cli/project/attachments.d.ts +10 -0
  296. package/dist/cli/project/attachments.js +39 -0
  297. package/dist/cli/project/grants.d.ts +10 -0
  298. package/dist/cli/project/grants.js +39 -0
  299. package/dist/cli/project/index.d.ts +8 -0
  300. package/dist/cli/project/index.js +92 -0
  301. package/dist/cli/project/move.d.ts +57 -0
  302. package/dist/cli/project/move.js +242 -0
  303. package/dist/cli/project/output.d.ts +2 -0
  304. package/dist/cli/project/output.js +29 -0
  305. package/dist/cli/project/stream.d.ts +55 -0
  306. package/dist/cli/project/stream.js +207 -0
  307. package/dist/cli/project/transfer-preview.d.ts +8 -0
  308. package/dist/cli/project/transfer-preview.js +10 -0
  309. package/dist/cli/prompt.d.ts +1 -0
  310. package/dist/cli/prompt.js +17 -0
  311. package/dist/cli/provider/dreamdir.d.ts +52 -0
  312. package/dist/cli/provider/dreamdir.js +138 -0
  313. package/dist/cli/provider/index.d.ts +4 -0
  314. package/dist/cli/provider/index.js +419 -0
  315. package/dist/cli/provider/jump-worker.d.ts +9 -0
  316. package/dist/cli/provider/jump-worker.js +141 -0
  317. package/dist/cli/provider/lifecycle.d.ts +149 -0
  318. package/dist/cli/provider/lifecycle.js +1390 -0
  319. package/dist/cli/provider/machine.d.ts +17 -0
  320. package/dist/cli/provider/machine.js +116 -0
  321. package/dist/cli/provider/ssh.d.ts +105 -0
  322. package/dist/cli/provider/ssh.js +305 -0
  323. package/dist/cli/provider/terraform.d.ts +140 -0
  324. package/dist/cli/provider/terraform.js +288 -0
  325. package/dist/cli/providers/index.d.ts +18 -0
  326. package/dist/cli/providers/index.js +422 -0
  327. package/dist/cli/python.d.ts +61 -0
  328. package/dist/cli/python.js +255 -0
  329. package/dist/cli/queues/index.d.ts +33 -0
  330. package/dist/cli/queues/index.js +248 -0
  331. package/dist/cli/queues/slurm.d.ts +10 -0
  332. package/dist/cli/queues/slurm.js +134 -0
  333. package/dist/cli/resources.d.ts +72 -0
  334. package/dist/cli/resources.js +137 -0
  335. package/dist/cli/run/index.d.ts +15 -0
  336. package/dist/cli/run/index.js +163 -0
  337. package/dist/cli/run/input.d.ts +34 -0
  338. package/dist/cli/run/input.js +135 -0
  339. package/dist/cli/run/recovery.d.ts +2 -0
  340. package/dist/cli/run/recovery.js +18 -0
  341. package/dist/cli/run/setup.d.ts +3 -0
  342. package/dist/cli/run/setup.js +62 -0
  343. package/dist/cli/runconfig/index.d.ts +12 -0
  344. package/dist/cli/runconfig/index.js +130 -0
  345. package/dist/cli/runnable/index.d.ts +35 -0
  346. package/dist/cli/runnable/index.js +575 -0
  347. package/dist/cli/runnable/path.d.ts +115 -0
  348. package/dist/cli/runnable/path.js +288 -0
  349. package/dist/cli/runnable/run.d.ts +91 -0
  350. package/dist/cli/runnable/run.js +239 -0
  351. package/dist/cli/runnable/upload.d.ts +43 -0
  352. package/dist/cli/runnable/upload.js +342 -0
  353. package/dist/cli/runnable/worker.d.ts +1 -0
  354. package/dist/cli/runnable/worker.js +44 -0
  355. package/dist/cli/schemas/workflow-spec.schema.json +335 -0
  356. package/dist/cli/self-update/index.d.ts +5 -0
  357. package/dist/cli/self-update/index.js +107 -0
  358. package/dist/cli/self-update/install.d.ts +60 -0
  359. package/dist/cli/self-update/install.js +428 -0
  360. package/dist/cli/self-update/paths.d.ts +40 -0
  361. package/dist/cli/self-update/paths.js +87 -0
  362. package/dist/cli/self-update/releases.d.ts +41 -0
  363. package/dist/cli/self-update/releases.js +153 -0
  364. package/dist/cli/self-update/settings.d.ts +16 -0
  365. package/dist/cli/self-update/settings.js +68 -0
  366. package/dist/cli/self-update/update.d.ts +18 -0
  367. package/dist/cli/self-update/update.js +241 -0
  368. package/dist/cli/service-accounts/index.d.ts +3 -0
  369. package/dist/cli/service-accounts/index.js +149 -0
  370. package/dist/cli/session-affiliation.d.ts +26 -0
  371. package/dist/cli/session-affiliation.js +135 -0
  372. package/dist/cli/sessions/affiliation.d.ts +8 -0
  373. package/dist/cli/sessions/affiliation.js +66 -0
  374. package/dist/cli/sessions/api.d.ts +55 -0
  375. package/dist/cli/sessions/api.js +88 -0
  376. package/dist/cli/sessions/control.d.ts +6 -0
  377. package/dist/cli/sessions/control.js +159 -0
  378. package/dist/cli/sessions/conversation.d.ts +15 -0
  379. package/dist/cli/sessions/conversation.js +118 -0
  380. package/dist/cli/sessions/index.d.ts +2 -0
  381. package/dist/cli/sessions/index.js +209 -0
  382. package/dist/cli/sessions/managed.d.ts +39 -0
  383. package/dist/cli/sessions/managed.js +63 -0
  384. package/dist/cli/sessions/redaction.d.ts +2 -0
  385. package/dist/cli/sessions/redaction.js +11 -0
  386. package/dist/cli/sessions/runner/exec.d.ts +108 -0
  387. package/dist/cli/sessions/runner/exec.js +335 -0
  388. package/dist/cli/sessions/runner/journal.d.ts +26 -0
  389. package/dist/cli/sessions/runner/journal.js +49 -0
  390. package/dist/cli/sessions/runner/native.d.ts +48 -0
  391. package/dist/cli/sessions/runner/native.js +170 -0
  392. package/dist/cli/sessions/runner/pod.d.ts +30 -0
  393. package/dist/cli/sessions/runner/pod.js +129 -0
  394. package/dist/cli/sessions/runner/serve.d.ts +85 -0
  395. package/dist/cli/sessions/runner/serve.js +558 -0
  396. package/dist/cli/sessions/sync.d.ts +47 -0
  397. package/dist/cli/sessions/sync.js +80 -0
  398. package/dist/cli/sessions/transport.d.ts +14 -0
  399. package/dist/cli/sessions/transport.js +116 -0
  400. package/dist/cli/share.d.ts +15 -0
  401. package/dist/cli/share.js +139 -0
  402. package/dist/cli/skill/catalog.d.ts +141 -0
  403. package/dist/cli/skill/catalog.js +442 -0
  404. package/dist/cli/skill/files.d.ts +89 -0
  405. package/dist/cli/skill/files.js +264 -0
  406. package/dist/cli/skill/index.d.ts +268 -0
  407. package/dist/cli/skill/index.js +1216 -0
  408. package/dist/cli/skill/manifest.d.ts +30 -0
  409. package/dist/cli/skill/manifest.js +101 -0
  410. package/dist/cli/skill/prefs.d.ts +9 -0
  411. package/dist/cli/skill/prefs.js +32 -0
  412. package/dist/cli/skill/reminders.d.ts +15 -0
  413. package/dist/cli/skill/reminders.js +105 -0
  414. package/dist/cli/skill/tar.d.ts +17 -0
  415. package/dist/cli/skill/tar.js +195 -0
  416. package/dist/cli/snapshot/index.d.ts +24 -0
  417. package/dist/cli/snapshot/index.js +146 -0
  418. package/dist/cli/source/access.d.ts +45 -0
  419. package/dist/cli/source/access.js +563 -0
  420. package/dist/cli/source/control.d.ts +103 -0
  421. package/dist/cli/source/control.js +546 -0
  422. package/dist/cli/source/delete.d.ts +89 -0
  423. package/dist/cli/source/delete.js +463 -0
  424. package/dist/cli/source/index.d.ts +288 -0
  425. package/dist/cli/source/index.js +1348 -0
  426. package/dist/cli/source/share.d.ts +65 -0
  427. package/dist/cli/source/share.js +530 -0
  428. package/dist/cli/source/upload.d.ts +62 -0
  429. package/dist/cli/source/upload.js +258 -0
  430. package/dist/cli/source/write.d.ts +77 -0
  431. package/dist/cli/source/write.js +335 -0
  432. package/dist/cli/spawn.d.ts +28 -0
  433. package/dist/cli/spawn.js +81 -0
  434. package/dist/cli/target.d.ts +22 -0
  435. package/dist/cli/target.js +85 -0
  436. package/dist/cli/tasks/index.d.ts +38 -0
  437. package/dist/cli/tasks/index.js +365 -0
  438. package/dist/cli/team/index.d.ts +37 -0
  439. package/dist/cli/team/index.js +407 -0
  440. package/dist/cli/telemetry.d.ts +23 -0
  441. package/dist/cli/telemetry.js +262 -0
  442. package/dist/cli/telemetryJournal.d.ts +26 -0
  443. package/dist/cli/telemetryJournal.js +104 -0
  444. package/dist/cli/update/index.d.ts +21 -0
  445. package/dist/cli/update/index.js +284 -0
  446. package/dist/cli/upload/index.d.ts +11 -0
  447. package/dist/cli/upload/index.js +261 -0
  448. package/dist/cli/upload/kinds.d.ts +10 -0
  449. package/dist/cli/upload/kinds.js +85 -0
  450. package/dist/cli/upload/multipart.d.ts +21 -0
  451. package/dist/cli/upload/multipart.js +248 -0
  452. package/dist/cli/vault/affected-preview.d.ts +15 -0
  453. package/dist/cli/vault/affected-preview.js +38 -0
  454. package/dist/cli/vault/cloud.d.ts +55 -0
  455. package/dist/cli/vault/cloud.js +287 -0
  456. package/dist/cli/vault/format.d.ts +18 -0
  457. package/dist/cli/vault/format.js +104 -0
  458. package/dist/cli/vault/hostCredentials.d.ts +21 -0
  459. package/dist/cli/vault/hostCredentials.js +71 -0
  460. package/dist/cli/vault/hostSupersessions.d.ts +18 -0
  461. package/dist/cli/vault/hostSupersessions.js +68 -0
  462. package/dist/cli/vault/import.d.ts +3 -0
  463. package/dist/cli/vault/import.js +79 -0
  464. package/dist/cli/vault/index.d.ts +14 -0
  465. package/dist/cli/vault/index.js +225 -0
  466. package/dist/cli/vault/keys.d.ts +5 -0
  467. package/dist/cli/vault/keys.js +165 -0
  468. package/dist/cli/vault/kms.d.ts +6 -0
  469. package/dist/cli/vault/kms.js +169 -0
  470. package/dist/cli/vault/list.d.ts +13 -0
  471. package/dist/cli/vault/list.js +60 -0
  472. package/dist/cli/vault/listView.d.ts +21 -0
  473. package/dist/cli/vault/listView.js +123 -0
  474. package/dist/cli/vault/managementMetadata.d.ts +2 -0
  475. package/dist/cli/vault/managementMetadata.js +23 -0
  476. package/dist/cli/vault/mutations.d.ts +8 -0
  477. package/dist/cli/vault/mutations.js +151 -0
  478. package/dist/cli/vault/otp.d.ts +6 -0
  479. package/dist/cli/vault/otp.js +62 -0
  480. package/dist/cli/vault/otpIntent.d.ts +23 -0
  481. package/dist/cli/vault/otpIntent.js +76 -0
  482. package/dist/cli/vault/passImport.d.ts +25 -0
  483. package/dist/cli/vault/passImport.js +129 -0
  484. package/dist/cli/vault/passOtp.d.ts +51 -0
  485. package/dist/cli/vault/passOtp.js +101 -0
  486. package/dist/cli/vault/passStore.d.ts +26 -0
  487. package/dist/cli/vault/passStore.js +134 -0
  488. package/dist/cli/vault/passwordCommand.d.ts +39 -0
  489. package/dist/cli/vault/passwordCommand.js +101 -0
  490. package/dist/cli/vault/passwordProbe.d.ts +27 -0
  491. package/dist/cli/vault/passwordProbe.js +282 -0
  492. package/dist/cli/vault/passwordRotation.d.ts +9 -0
  493. package/dist/cli/vault/passwordRotation.js +273 -0
  494. package/dist/cli/vault/rotationApi.d.ts +13 -0
  495. package/dist/cli/vault/rotationApi.js +58 -0
  496. package/dist/cli/vault/rotationCommand.d.ts +2 -0
  497. package/dist/cli/vault/rotationCommand.js +75 -0
  498. package/dist/cli/vault/rotationEngine.d.ts +19 -0
  499. package/dist/cli/vault/rotationEngine.js +65 -0
  500. package/dist/cli/vault/rotationHelperSource.d.ts +2 -0
  501. package/dist/cli/vault/rotationHelperSource.js +3 -0
  502. package/dist/cli/vault/rotationInput.d.ts +11 -0
  503. package/dist/cli/vault/rotationInput.js +48 -0
  504. package/dist/cli/vault/rotationJournal.d.ts +16 -0
  505. package/dist/cli/vault/rotationJournal.js +183 -0
  506. package/dist/cli/vault/rotationKeys.d.ts +4 -0
  507. package/dist/cli/vault/rotationKeys.js +48 -0
  508. package/dist/cli/vault/rotationPrepare.d.ts +17 -0
  509. package/dist/cli/vault/rotationPrepare.js +108 -0
  510. package/dist/cli/vault/rotationRemote.d.ts +33 -0
  511. package/dist/cli/vault/rotationRemote.js +156 -0
  512. package/dist/cli/vault/rotationState.d.ts +42 -0
  513. package/dist/cli/vault/rotationState.js +115 -0
  514. package/dist/cli/vault/rotationTransport.d.ts +18 -0
  515. package/dist/cli/vault/rotationTransport.js +71 -0
  516. package/dist/cli/vault/sshSource.d.ts +18 -0
  517. package/dist/cli/vault/sshSource.js +196 -0
  518. package/dist/cli/vault/sshSync.d.ts +17 -0
  519. package/dist/cli/vault/sshSync.js +224 -0
  520. package/dist/cli/vault/sshTransfer.d.ts +22 -0
  521. package/dist/cli/vault/sshTransfer.js +140 -0
  522. package/dist/cli/vault/terraformState.d.ts +66 -0
  523. package/dist/cli/vault/terraformState.js +252 -0
  524. package/dist/cli/vault/terraformStateCommand.d.ts +2 -0
  525. package/dist/cli/vault/terraformStateCommand.js +61 -0
  526. package/dist/cli/vault/tree.d.ts +43 -0
  527. package/dist/cli/vault/tree.js +292 -0
  528. package/dist/cli/version.d.ts +1 -0
  529. package/dist/cli/version.js +9 -0
  530. package/dist/cli/workflow/index.d.ts +76 -0
  531. package/dist/cli/workflow/index.js +826 -0
  532. package/dist/cli/workflow/validate.d.ts +19 -0
  533. package/dist/cli/workflow/validate.js +353 -0
  534. package/dist/package.json +1 -0
  535. package/package.json +28 -10
@@ -0,0 +1,1390 @@
1
+ // The provider lifecycle — `create` / `plan` / `apply` / `connect` /
2
+ // `disconnect` / `status`.
3
+ //
4
+ // THE INVERSION THIS FILE EXISTS FOR. Ge: *"instead of making dreamlake the ai
5
+ // agent, think of how an ai agent can use it."* So there is NO MODEL HERE. No
6
+ // chat endpoint, no LLM call, no agent framework. Every function below does as
7
+ // much as it can without guessing, then STOPS and reports two things — where it
8
+ // is (`status`) and what happens next (`nextAction`). Something else performs
9
+ // that action and re-runs the command. That loop is the whole interface:
10
+ //
11
+ // run → read nextAction → act → --continue → run …
12
+ //
13
+ // THREE RULES FOLLOW, AND EACH IS LOAD-BEARING:
14
+ //
15
+ // 1. IT NEVER BLOCKS ON A TTY. An agent has no terminal. This file imports
16
+ // nothing from `@inquirer/prompts` and calls `confirm()` zero times — there
17
+ // is a test that reads this module's own source and asserts the word
18
+ // `inquirer` does not appear in it. "needs input" is an EXIT STATE carrying
19
+ // a next action, never a question asked of a terminal that is not there.
20
+ //
21
+ // 2. `needs_input` EXITS 0. It is not a failure: the tool did exactly its job,
22
+ // which is to find out what it cannot decide and say so. An agent driving
23
+ // under `set -e`, or a Makefile, must not die because the tool successfully
24
+ // reported a question. This is not new — `provider delete` without `--yes`
25
+ // on a non-TTY already cancels and returns 0 (lakeshore/index.ts:604).
26
+ // Exit 1 is reserved for "the tool could not do its job": bad flags, no
27
+ // binary, an unwritable directory, a terraform error, a refused ssh.
28
+ // An agent branches on `status` / `nextAction`, NEVER on the exit code.
29
+ //
30
+ // 3. `create` NEVER APPLIES. Applying spends money and is its own verb behind
31
+ // its own `--yes`. A test asserts that across a whole
32
+ // create → edit → create --continue → plan run, the recorded argv contains
33
+ // no `apply` and no `destroy`.
34
+ //
35
+ // NO PHASE IS EVER PERSISTED. It is derived on every invocation from four
36
+ // observations, in this order: the directory and its `provider.json`; the
37
+ // offline decision scan; terraform's own state and lock files; and the live
38
+ // workers claiming the name. Derived state cannot go stale and cannot lie about
39
+ // a `terraform apply` somebody ran by hand in that directory.
40
+ import { existsSync, readFileSync, statSync } from "node:fs";
41
+ import path from "node:path";
42
+ import { fileURLToPath } from "node:url";
43
+ import { JUMP_WORKER_VENDOR, jumpWorkerBackend, scanJumpWorker, checkJumpWorkerPaths, writeJumpWorkerFiles } from "./jump-worker.js";
44
+ import { requestJson } from "../client.js";
45
+ import { emitJson, fail, ok, warn } from "../helpers.js";
46
+ import { resolveCpNamespace, resolveServer } from "../python.js";
47
+ import { gitignoreWrite, invalidNameMessage, providerDir, readProviderRecord, relative, resolveDreamRoot, rootNote, writeFiles, } from "./dreamdir.js";
48
+ import { LOCK_FILE, PLUGIN_DIR, STATE_FILE, failureDetail, isVariableProblem, parsePlanStream, parseValidate, resolveTerraform, runTerraform, TIMEOUTS, } from "./terraform.js";
49
+ import { detectSupervisor, nymphCommand, probeHost, startNymph, stopCommand, stopLabel, stopNymph, supervisorLabel, unreachableMessage, } from "./ssh.js";
50
+ // ─── the printed commands ────────────────────────────────────────────────────
51
+ const cmdContinue = (n) => `dreamlake provider create -n ${n} --continue`;
52
+ const cmdPlan = (n) => `dreamlake provider plan -n ${n}`;
53
+ const cmdApply = (n) => `dreamlake provider apply -n ${n} --yes`;
54
+ const cmdConnect = (n) => `dreamlake provider connect -n ${n}`;
55
+ const cmdDisconnect = (n) => `dreamlake provider disconnect -n ${n}`;
56
+ const cmdStatus = (n) => `dreamlake provider status -n ${n}`;
57
+ const cmdCreate = (n, vendor) => `dreamlake provider create -n ${n} --provider ${vendor}`;
58
+ /**
59
+ * The next action for ANY terraform failure — init, validate, plan or apply.
60
+ *
61
+ * Every one of them is a config problem until proven otherwise, and the way out
62
+ * of all four is the same: open the terraform directory, fix what the
63
+ * diagnostic named, and re-PLAN. Never re-apply: plan reads and costs nothing,
64
+ * and a clean plan's own nextAction is the apply, so the money step stays a
65
+ * deliberate second command instead of something an agent retries in a loop.
66
+ *
67
+ * `nextAction: null` on these was the dead end — an agent hits the one state
68
+ * where it most needs a next step and is told the run is over.
69
+ */
70
+ const replanAfterFailure = (tfDir, n) => ({
71
+ kind: "edit_then_continue",
72
+ file: tfDir,
73
+ command: cmdPlan(n),
74
+ });
75
+ // ─── templates ───────────────────────────────────────────────────────────────
76
+ //
77
+ // `new URL("./templates/", import.meta.url)` rather than a path relative to
78
+ // cwd, so the SAME line resolves under `tsx src/cli/…` and under
79
+ // `node dist/cli/…`. The build copies the directory across
80
+ // (scripts/copy-templates.mjs) because `tsc` does not carry `.tf` files and a
81
+ // published CLI that scaffolds an empty directory is the trap this avoids.
82
+ export const VENDORS = ["kube", "ec2", "docker", "ssh", "slurm", "aws-jump-worker"];
83
+ function templateText(vendor, relativePath) {
84
+ if (typeof DREAMLAKE_EMBEDDED_PROVIDER_TEMPLATES !== "undefined") {
85
+ return DREAMLAKE_EMBEDDED_PROVIDER_TEMPLATES[`${vendor}/${relativePath}`] ?? null;
86
+ }
87
+ const file = path.join(templateDir(vendor), relativePath);
88
+ return existsSync(file) ? readFileSync(file, "utf8") : null;
89
+ }
90
+ export function templatesRoot() {
91
+ return fileURLToPath(new URL("./templates/", import.meta.url));
92
+ }
93
+ export function templateDir(vendor) {
94
+ return path.join(templatesRoot(), vendor);
95
+ }
96
+ export function loadTemplate(vendor) {
97
+ const manifestText = templateText(vendor, "TEMPLATE.json");
98
+ if (manifestText === null)
99
+ return null;
100
+ try {
101
+ const parsed = JSON.parse(manifestText);
102
+ if (!parsed || !Array.isArray(parsed.files))
103
+ return null;
104
+ return {
105
+ ...parsed,
106
+ decisions: Array.isArray(parsed.decisions) ? parsed.decisions : [],
107
+ };
108
+ }
109
+ catch {
110
+ return null;
111
+ }
112
+ }
113
+ function unknownVendorMessage(vendor) {
114
+ return (`no template for vendor '${vendor}' — known vendors are ${VENDORS.join(", ")}. ` +
115
+ `A vendor names a starting point, not a default: it is adapted to your ` +
116
+ `account, never applied as shipped.`);
117
+ }
118
+ /**
119
+ * `key = value` out of a tfvars file. Deliberately not an HCL parser: the scan
120
+ * only has to answer "is there a real value here", and a template ships its
121
+ * account-specific keys COMMENTED OUT so the answer is usually "no, and here is
122
+ * the line to type on".
123
+ *
124
+ * An uncommented assignment always beats a commented one for the same key.
125
+ */
126
+ export function parseTfvars(text) {
127
+ const found = new Map();
128
+ const lines = text.split(/\r?\n/);
129
+ for (let i = 0; i < lines.length; i++) {
130
+ const m = /^(\s*)(#+\s*)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)$/.exec(lines[i]);
131
+ if (!m)
132
+ continue;
133
+ const key = m[3];
134
+ const entry = {
135
+ value: m[4] ?? "",
136
+ line: i + 1,
137
+ commented: Boolean(m[2]),
138
+ };
139
+ const prev = found.get(key);
140
+ if (prev && !prev.commented && entry.commented)
141
+ continue;
142
+ found.set(key, entry);
143
+ }
144
+ return found;
145
+ }
146
+ /** The same question against a JSON file — `adopt.json` for the ssh vendor. */
147
+ export function parseJsonAssignments(text) {
148
+ const found = new Map();
149
+ let parsed;
150
+ try {
151
+ parsed = JSON.parse(text);
152
+ }
153
+ catch {
154
+ return found;
155
+ }
156
+ if (!parsed || typeof parsed !== "object")
157
+ return found;
158
+ const lines = text.split(/\r?\n/);
159
+ for (const [key, value] of Object.entries(parsed)) {
160
+ const line = lines.findIndex((l) => l.includes(`"${key}"`));
161
+ found.set(key, {
162
+ value: typeof value === "string" ? JSON.stringify(value) : JSON.stringify(value ?? ""),
163
+ line: line >= 0 ? line + 1 : 1,
164
+ commented: false,
165
+ });
166
+ }
167
+ return found;
168
+ }
169
+ const PLACEHOLDER = /CHANGE_?ME|REPLACE_?ME|<[^>]*>/i;
170
+ /** Empty, or still the thing the template shipped for you to replace. */
171
+ export function isPlaceholder(raw) {
172
+ const noComment = raw.replace(/\s+#.*$/, "").trim();
173
+ if (noComment === "")
174
+ return true;
175
+ const unquoted = /^"(.*)"$/.exec(noComment)?.[1] ?? noComment;
176
+ if (unquoted.trim() === "")
177
+ return true;
178
+ if (unquoted === "[]" || unquoted === "{}" || unquoted === "null")
179
+ return true;
180
+ return PLACEHOLDER.test(unquoted);
181
+ }
182
+ export function scanDecisions(dir, manifest) {
183
+ if (manifest.vendor === JUMP_WORKER_VENDOR)
184
+ return scanJumpWorker(dir, name => templateText(manifest.vendor, name));
185
+ const blocking = [];
186
+ const cache = new Map();
187
+ for (const decision of manifest.decisions) {
188
+ const abs = path.join(dir, decision.file);
189
+ let table = cache.get(abs);
190
+ if (!table) {
191
+ let text = "";
192
+ try {
193
+ text = readFileSync(abs, "utf8");
194
+ }
195
+ catch {
196
+ text = "";
197
+ }
198
+ table = abs.endsWith(".json") ? parseJsonAssignments(text) : parseTfvars(text);
199
+ cache.set(abs, table);
200
+ }
201
+ const entry = table.get(decision.var);
202
+ const base = { key: decision.key, file: abs, why: decision.why };
203
+ if (!entry || entry.commented) {
204
+ blocking.push({ ...base, reason: "unset", line: entry?.line });
205
+ continue;
206
+ }
207
+ if (isPlaceholder(entry.value)) {
208
+ blocking.push({ ...base, reason: "placeholder", line: entry.line });
209
+ continue;
210
+ }
211
+ if (decision.pattern) {
212
+ let re = null;
213
+ try {
214
+ re = new RegExp(decision.pattern);
215
+ }
216
+ catch {
217
+ re = null;
218
+ }
219
+ const unquoted = /^"(.*)"$/.exec(entry.value.trim())?.[1] ?? entry.value.trim();
220
+ if (re && !re.test(unquoted)) {
221
+ blocking.push({ ...base, reason: "invalid", line: entry.line });
222
+ }
223
+ }
224
+ }
225
+ return blocking;
226
+ }
227
+ /** The file an agent is told to open — the first blocking entry's, else the
228
+ * template's own primary decision file. */
229
+ function decisionFile(dir, manifest, blocking) {
230
+ const first = blocking.find((b) => b.file);
231
+ if (first?.file)
232
+ return first.file;
233
+ const decl = manifest.decisions[0]?.file;
234
+ return path.join(dir, decl ?? "terraform/terraform.tfvars");
235
+ }
236
+ /**
237
+ * Live workers whose `providerName` is this provider.
238
+ *
239
+ * `?state=live` because the SERVER owns the liveness predicate — that filter
240
+ * landed for exactly this question, and reimplementing "what counts as dead"
241
+ * here would be a second opinion that drifts. `gone` is therefore 0 by
242
+ * construction on this path; the UI, which needs both counts to be mutually
243
+ * consistent in one render, fetches unfiltered and partitions client-side
244
+ * instead. Different consumers, different right answer.
245
+ *
246
+ * A control plane that is absent or unreachable is DEGRADED, never fatal:
247
+ * "zero bridges for a provider is a normal state, not an error", and neither is
248
+ * "I could not ask".
249
+ */
250
+ async function fetchClaim(server, namespace, provider) {
251
+ if (!server)
252
+ return null;
253
+ try {
254
+ const res = await requestJson(server, `/v1/namespaces/${encodeURIComponent(namespace)}/workers`, { query: { state: "live" }, token: process.env.LAKESHORE_TOKEN ?? null, timeoutMs: 15_000 });
255
+ const all = Array.isArray(res) ? res : (res?.workers ?? []);
256
+ const mine = all.filter((w) => w.providerName === provider);
257
+ return {
258
+ live: mine.length,
259
+ gone: 0,
260
+ // For a launched worker the machineId IS the cloud instance id, which is
261
+ // the whole reason this list is interesting and not just a worker list.
262
+ instances: mine.map((w) => w.instanceId || w.machineId || "(unnamed)"),
263
+ rows: mine.map((w) => ({
264
+ id: w.instanceId || w.machineId || "(unnamed)",
265
+ state: w.state ?? "unknown",
266
+ queues: Array.isArray(w.queues) ? w.queues : [],
267
+ lastSeenAt: w.lastSeenAt,
268
+ })),
269
+ };
270
+ }
271
+ catch {
272
+ return null;
273
+ }
274
+ }
275
+ // ─── prose helpers ───────────────────────────────────────────────────────────
276
+ //
277
+ // The house column, unchanged from launch/index.ts:184-192 and
278
+ // snapshot/index.ts:131-153: a bare verb line, then ` key:` padded to column
279
+ // 14, then ✓/⚠ result lines, then indented copy-pasteable next commands.
280
+ function field(key, value) {
281
+ return ` ${`${key}:`.padEnd(12)}${value}\n`;
282
+ }
283
+ function reasonText(b) {
284
+ const base = b.reason === "unset"
285
+ ? "not set"
286
+ : b.reason === "placeholder"
287
+ ? "still the template placeholder"
288
+ : b.reason === "conflict"
289
+ ? "conflicts with a value already in the account"
290
+ : "rejected by the template's own validation";
291
+ if (b.observed && b.observed.length > 0) {
292
+ return `${base}. account has resources in ${b.observed.join(", ")}`;
293
+ }
294
+ return base;
295
+ }
296
+ function printBlocking(blocking, file, command) {
297
+ warn("needs decisions before it can apply:");
298
+ for (const b of blocking) {
299
+ // Pad to column 14, but never let a long key collide with the dash.
300
+ const label = b.key.length >= 14 ? `${b.key} ` : b.key.padEnd(14);
301
+ process.stdout.write(` · ${label}— ${reasonText(b)}\n`);
302
+ }
303
+ process.stdout.write("\n");
304
+ process.stdout.write(` next: edit ${file}, then\n`);
305
+ process.stdout.write(` ${command}\n`);
306
+ }
307
+ function printNext(action) {
308
+ if (!action) {
309
+ process.stdout.write("\n next: (none)\n");
310
+ return;
311
+ }
312
+ if (action.kind === "edit_then_continue") {
313
+ process.stdout.write("\n");
314
+ process.stdout.write(` next: edit ${action.file}, then\n`);
315
+ process.stdout.write(` ${action.command}\n`);
316
+ return;
317
+ }
318
+ process.stdout.write("\n");
319
+ process.stdout.write(` next: ${action.command}\n`);
320
+ }
321
+ function scopeResult(opts, result) {
322
+ if (result.vendor !== JUMP_WORKER_VENDOR || !result.nextAction?.command.startsWith("dreamlake provider "))
323
+ return result;
324
+ const quote = (value) => "'" + value.replace(/'/g, "'\"'\"'") + "'";
325
+ const dreamDir = result.dir ? path.dirname(path.dirname(result.dir)) : opts.dreamDir;
326
+ return { ...result, nextAction: { ...result.nextAction,
327
+ command: result.nextAction.command + (dreamDir ? ` --dream-dir ${quote(dreamDir)}` : "") + (opts.json ? " --json" : ""),
328
+ } };
329
+ }
330
+ function printFiles(files) {
331
+ for (const f of files.slice(0, 2))
332
+ process.stdout.write(` wrote ${f}\n`);
333
+ if (files.length > 2)
334
+ process.stdout.write(` … ${files.length - 2} more\n`);
335
+ }
336
+ function reject(opts, message, where, extra = {}) {
337
+ if (where.vendor === JUMP_WORKER_VENDOR && (extra.kind?.startsWith("Terraform") || extra.kind === "NoTerraformBinary")) {
338
+ message = `${extra.kind} failed; raw provider diagnostics are suppressed because they may contain state secrets. Review locally in the protected Terraform directory.`;
339
+ }
340
+ if (opts.json) {
341
+ const result = {
342
+ status: "error",
343
+ provider: where.provider,
344
+ vendor: where.vendor,
345
+ server: where.server,
346
+ namespace: where.namespace,
347
+ dir: where.dir,
348
+ error: message,
349
+ kind: extra.kind,
350
+ nextAction: extra.nextAction ?? null,
351
+ };
352
+ emitJson(scopeResult(opts, result));
353
+ }
354
+ else {
355
+ fail(message);
356
+ const action = extra.nextAction;
357
+ if (action?.kind === "edit_then_continue") {
358
+ process.stdout.write(` next: edit ${action.file}, then\n`);
359
+ process.stdout.write(` ${action.command}\n`);
360
+ }
361
+ else if (action) {
362
+ process.stdout.write(` next: ${action.command}\n`);
363
+ }
364
+ }
365
+ return 1;
366
+ }
367
+ function open(opts) {
368
+ const namespace = resolveCpNamespace(opts.namespace);
369
+ const server = resolveServer(opts.server);
370
+ const name = (opts.name ?? "").trim();
371
+ const bad = invalidNameMessage(name);
372
+ if (bad) {
373
+ return { error: bad, where: { provider: name, server: server ?? "", namespace } };
374
+ }
375
+ const dream = resolveDreamRoot(opts.dreamDir);
376
+ const dir = providerDir(dream, name);
377
+ return {
378
+ name,
379
+ dream,
380
+ dir,
381
+ server,
382
+ namespace,
383
+ where: { provider: name, server: server ?? "", namespace, dir },
384
+ };
385
+ }
386
+ function isError(c) {
387
+ return typeof c.error === "string";
388
+ }
389
+ /**
390
+ * The header, printed BEFORE anything is written or spawned. Same rule as
391
+ * lakeshore/index.ts:287-296: if the operator is about to write into the wrong
392
+ * tree or point at the wrong control plane, the line that tells them comes
393
+ * first.
394
+ */
395
+ function header(verb, c, vendor) {
396
+ process.stdout.write(`provider ${verb} ${c.name}\n`);
397
+ process.stdout.write(field("root", `${c.dream.root} ${rootNote(c.dream)}`));
398
+ process.stdout.write(field("dir", relative(c.dream, c.dir)));
399
+ if (vendor)
400
+ process.stdout.write(field("vendor", vendor));
401
+ process.stdout.write(field("server", c.server ?? "(none — set LAKESHORE_URL to see claims)"));
402
+ process.stdout.write(field("namespace", c.namespace));
403
+ }
404
+ /** Enrollment is a separate authenticated operation, never an inferred name claim. */
405
+ function enrollmentHandoff(opts, c) {
406
+ const file = path.join(c.dir, "terraform", "ENROLLMENT.md");
407
+ const result = {
408
+ ...c.where, vendor: JUMP_WORKER_VENDOR, status: "needs_input", files: [],
409
+ blocking: [{ key: "owned-enrollment-evidence", reason: "unset", file,
410
+ why: "Follow the explicit enrollment and mapper handoff; external mode reuses the existing controller enrollment. Infrastructure IDs and hostnames are not Host, Enrollment or Worker authority. Generic connect/disconnect does not manage this setup." }],
411
+ nextAction: { kind: "edit_then_continue", file, command: `dreamlake hosts enroll --help` },
412
+ };
413
+ if (opts.json)
414
+ emitJson(scopeResult(opts, result));
415
+ else
416
+ printBlocking(result.blocking, file, result.nextAction.command);
417
+ return 0;
418
+ }
419
+ // ─── create ──────────────────────────────────────────────────────────────────
420
+ export async function runProviderCreate(opts, deps = {}) {
421
+ void deps; // create is offline by construction — it spawns nothing at all.
422
+ const c = open(opts);
423
+ if (isError(c))
424
+ return reject(opts, c.error, c.where);
425
+ const existing = readProviderRecord(c.dir);
426
+ const dirExists = existsSync(c.dir);
427
+ const requested = (opts.provider ?? "").trim();
428
+ // ── vendor resolution, entirely local ──
429
+ if (dirExists && !existing) {
430
+ return reject(opts, `${c.dir} exists but has no readable provider.json — refusing to touch it. ` +
431
+ `Delete the directory or pick another name.`, c.where, { kind: "UnknownDirectory" });
432
+ }
433
+ if (existing && requested && requested !== existing.vendor) {
434
+ // Never merges, never overwrites. Idempotence property 2.
435
+ return reject(opts, `'${c.name}' was scaffolded from vendor '${existing.vendor}'. Refusing to ` +
436
+ `overwrite it with '${requested}' — delete the directory or pick another name.`, { ...c.where, vendor: existing.vendor }, { kind: "VendorMismatch" });
437
+ }
438
+ const vendor = existing?.vendor ?? requested;
439
+ if (!vendor) {
440
+ return reject(opts, `no vendor — pass --provider <${VENDORS.join("|")}>. A provider is created ` +
441
+ `by hand, once, with a name and a vendor a person chose.`, c.where);
442
+ }
443
+ const manifest = loadTemplate(vendor);
444
+ if (!manifest) {
445
+ return reject(opts, unknownVendorMessage(vendor), { ...c.where, vendor });
446
+ }
447
+ if (vendor === JUMP_WORKER_VENDOR) {
448
+ try {
449
+ checkJumpWorkerPaths([path.join(c.dir, "provider.json"), ...manifest.files.map(file => path.join(c.dir, file))]);
450
+ }
451
+ catch {
452
+ return reject(opts, "Scaffold paths must not contain symlinks or non-directory parents; nothing was written.", { ...c.where, vendor }, { kind: "UnsafeScaffold" });
453
+ }
454
+ }
455
+ // ── the header, before the first byte is written ──
456
+ if (!opts.json)
457
+ header("create", c, vendor);
458
+ // ── the write, or the deliberate absence of one ──
459
+ const writes = dirExists ? missingFiles(c, manifest, vendor) : allFiles(c, manifest, vendor);
460
+ let written = [];
461
+ if (writes.length > 0) {
462
+ const outcome = vendor === JUMP_WORKER_VENDOR ? writeJumpWorkerFiles(c.dir, writes) : writeFiles(c.dir, writes);
463
+ if (!outcome.ok) {
464
+ return reject(opts, outcome.message, { ...c.where, vendor }, { kind: "WriteFailed" });
465
+ }
466
+ written = outcome.files;
467
+ }
468
+ const blocking = scanDecisions(c.dir, manifest);
469
+ const editFile = decisionFile(c.dir, manifest, blocking);
470
+ // A BARE RE-RUN on a complete directory is `exists` with `files: []` — the
471
+ // EMPTY WRITE LIST IS THE PROOF it was a no-op, and it is what a test
472
+ // asserts. Modelled on `--if-exists ok` (lakeshore/index.ts:318-322).
473
+ // `--continue` says the directory is expected, so it reports the real state
474
+ // instead; that is the only difference between the two, and it is why
475
+ // `--continue` is sugar rather than a second code path.
476
+ const noop = dirExists && written.length === 0 && !opts.continue;
477
+ const nextAction = blocking.length > 0
478
+ ? { kind: "edit_then_continue", file: editFile, command: cmdContinue(c.name) }
479
+ : {
480
+ kind: "run",
481
+ command: manifest.terraform === false ? cmdConnect(c.name) : cmdPlan(c.name),
482
+ };
483
+ const result = {
484
+ status: noop ? "exists" : blocking.length > 0 ? "needs_input" : "scaffolded",
485
+ provider: c.name,
486
+ vendor,
487
+ server: c.server ?? "",
488
+ namespace: c.namespace,
489
+ dir: c.dir,
490
+ files: written,
491
+ blocking,
492
+ degraded: ["no-probe"],
493
+ nextAction,
494
+ };
495
+ if (opts.json) {
496
+ emitJson(scopeResult(opts, result));
497
+ return 0;
498
+ }
499
+ if (noop) {
500
+ warn(`${relative(c.dream, c.dir)}/ already exists from vendor '${vendor}' — nothing was overwritten`);
501
+ }
502
+ else {
503
+ const shown = manifest.terraform === false
504
+ ? `${relative(c.dream, c.dir)}/`
505
+ : `${relative(c.dream, c.dir)}/terraform/`;
506
+ ok(`scaffolded ${shown}`);
507
+ printFiles(written);
508
+ }
509
+ if (blocking.length > 0) {
510
+ printBlocking(blocking, editFile, cmdContinue(c.name));
511
+ }
512
+ else {
513
+ process.stdout.write(" every decision in this template has a value.\n");
514
+ printNext(nextAction);
515
+ }
516
+ return 0;
517
+ }
518
+ /** provider.json + every allowlisted template file + `.dream/.gitignore`. */
519
+ function allFiles(c, manifest, vendor) {
520
+ const writes = [];
521
+ const record = {
522
+ name: c.name,
523
+ kind: manifest.kind,
524
+ vendor,
525
+ template: `${vendor} v${manifest.version}`,
526
+ templateVersion: manifest.version,
527
+ createdAt: new Date().toISOString(),
528
+ };
529
+ writes.push({
530
+ path: path.join(c.dir, "provider.json"),
531
+ content: JSON.stringify(record, null, 2) + "\n",
532
+ });
533
+ // COPY BY THE ALLOWLIST, NEVER `cp -r`. `TEMPLATE.json.files` is that
534
+ // allowlist, and it is not a convenience: the setups these were derived from
535
+ // have a real `terraform.tfstate` sitting beside the `.tf` files, and a
536
+ // recursive copy would ship somebody's account with the template.
537
+ for (const rel of manifest.files) {
538
+ const content = templateText(vendor, rel);
539
+ if (content === null)
540
+ throw new Error(`Missing provider template file ${vendor}/${rel}`);
541
+ writes.push({ path: path.join(c.dir, rel), content });
542
+ }
543
+ // Last, so the first `wrote` lines are the ones the operator came for.
544
+ const gi = gitignoreWrite(c.dream);
545
+ if (gi)
546
+ writes.push(gi);
547
+ return writes;
548
+ }
549
+ /**
550
+ * Repair, not overwrite: only files the allowlist names AND that are missing.
551
+ * A file the operator edited is never touched, which is what makes a re-run
552
+ * safe enough to be the resume.
553
+ */
554
+ function missingFiles(c, manifest, vendor) {
555
+ return allFiles(c, manifest, vendor).filter((w) => !existsSync(w.path));
556
+ }
557
+ // ─── plan ────────────────────────────────────────────────────────────────────
558
+ export async function runProviderPlan(opts, deps = {}) {
559
+ const c = open(opts);
560
+ if (isError(c))
561
+ return reject(opts, c.error, c.where);
562
+ const existing = readProviderRecord(c.dir);
563
+ if (!existing) {
564
+ return reject(opts, notScaffolded(c.name, c.dir), c.where, {
565
+ kind: "NotScaffolded",
566
+ nextAction: { kind: "run", command: cmdCreate(c.name, "kube") },
567
+ });
568
+ }
569
+ const manifest = loadTemplate(existing.vendor);
570
+ if (!manifest) {
571
+ return reject(opts, unknownVendorMessage(existing.vendor), {
572
+ ...c.where,
573
+ vendor: existing.vendor,
574
+ });
575
+ }
576
+ const where = { ...c.where, vendor: existing.vendor };
577
+ if (manifest.terraform === false) {
578
+ return reject(opts, `vendor '${existing.vendor}' has no terraform — this provider is adopted, ` +
579
+ `not provisioned. There is nothing to plan.`, where, { kind: "NoTerraform", nextAction: { kind: "run", command: cmdConnect(c.name) } });
580
+ }
581
+ const tfDir = path.join(c.dir, "terraform");
582
+ if (!opts.json)
583
+ header("plan", c, existing.vendor);
584
+ // ── the decision scan is offline and comes FIRST: a missing variable must
585
+ // not cost a terraform init and a provider plugin download. ──
586
+ const offline = scanDecisions(c.dir, manifest);
587
+ if (offline.length > 0) {
588
+ const editFile = decisionFile(c.dir, manifest, offline);
589
+ const nextAction = {
590
+ kind: "edit_then_continue",
591
+ file: editFile,
592
+ command: cmdContinue(c.name),
593
+ };
594
+ const result = {
595
+ status: "needs_input",
596
+ provider: c.name,
597
+ vendor: existing.vendor,
598
+ server: c.server ?? "",
599
+ namespace: c.namespace,
600
+ dir: c.dir,
601
+ blocking: offline,
602
+ degraded: ["no-probe"],
603
+ nextAction,
604
+ };
605
+ if (opts.json) {
606
+ emitJson(scopeResult(opts, result));
607
+ return 0;
608
+ }
609
+ printBlocking(offline, editFile, cmdContinue(c.name));
610
+ return 0;
611
+ }
612
+ const tf = resolveTerraform({ spawn: deps.spawn, quiet: opts.json || existing.vendor === JUMP_WORKER_VENDOR });
613
+ if (!tf.ok) {
614
+ return reject(opts, tf.message, where, { kind: "NoTerraformBinary" });
615
+ }
616
+ const trun = { spawn: deps.spawn, quiet: opts.json || existing.vendor === JUMP_WORKER_VENDOR };
617
+ // Legacy templates reuse their plugin cache. The pair always rechecks its
618
+ // explicitly selected backend; changed backend settings fail without an
619
+ // automatic migration or reconfiguration.
620
+ if (existing.vendor === JUMP_WORKER_VENDOR || !existsSync(path.join(tfDir, PLUGIN_DIR))) {
621
+ const initArgs = ["init", "-input=false", ...(existing.vendor === JUMP_WORKER_VENDOR ? [`-backend-config=${jumpWorkerBackend(c.dir)}`] : [])];
622
+ const init = runTerraform(tf.bin, tfDir, initArgs, TIMEOUTS.init, trun);
623
+ if (init.spawnError || init.status !== 0) {
624
+ return reject(opts, `terraform init failed\n${failureDetail(init)}`, where, {
625
+ kind: "TerraformInit",
626
+ nextAction: replanAfterFailure(tfDir, c.name),
627
+ });
628
+ }
629
+ }
630
+ const validate = runTerraform(tf.bin, tfDir, ["validate", "-json"], TIMEOUTS.validate, trun);
631
+ if (validate.spawnError) {
632
+ return reject(opts, failureDetail(validate), where, {
633
+ kind: "TerraformValidate",
634
+ nextAction: replanAfterFailure(tfDir, c.name),
635
+ });
636
+ }
637
+ // TERRAFORM'S OWN EXIT CODE IS AUTHORITATIVE; the parsed body only enriches
638
+ // it. Deciding this the other way round is how a pretty-printed `valid: true`
639
+ // that we failed to parse became "validate failed" — the exit code was 0 the
640
+ // whole time and would have said so.
641
+ const validated = parseValidate(validate.stdout);
642
+ const validateFailed = validate.status !== 0 || validated.diagnostics.some((d) => d.severity === "error");
643
+ if (validateFailed) {
644
+ const errs = validated.diagnostics.filter((d) => d.severity === "error");
645
+ const decision = classify(errs);
646
+ if (decision === "needs_input") {
647
+ return emitDiagnosticBlocking(opts, c, existing.vendor, errs, manifest);
648
+ }
649
+ return reject(opts, `terraform validate failed\n${diagnosticLines(errs) || failureDetail(validate)}`, where, { kind: "TerraformValidate", nextAction: replanAfterFailure(tfDir, c.name) });
650
+ }
651
+ const planned = runTerraform(tf.bin, tfDir, ["plan", "-input=false", "-json", "-detailed-exitcode"], TIMEOUTS.plan, trun);
652
+ // A plan failure is the one error an agent can almost always fix in place, so
653
+ // it must not dead-end: route back to the terraform dir and re-plan.
654
+ const replan = replanAfterFailure(tfDir, c.name);
655
+ if (planned.spawnError) {
656
+ return reject(opts, failureDetail(planned), where, {
657
+ kind: "TerraformPlan",
658
+ nextAction: replan,
659
+ });
660
+ }
661
+ // THE `-json` TRAP: plan emits a STREAM, so lastNonEmptyLine is wrong here.
662
+ const stream = parsePlanStream(planned.stdout);
663
+ const errs = stream.diagnostics.filter((d) => d.severity === "error");
664
+ // `-detailed-exitcode` makes 2 mean "there are changes", which is the normal
665
+ // answer for a plan that has never been applied. Only 1 is a failure.
666
+ if ((existing.vendor === JUMP_WORKER_VENDOR ? ![0, 2].includes(planned.status ?? -1) : planned.status === 1) || errs.length > 0) {
667
+ if (classify(errs) === "needs_input") {
668
+ return emitDiagnosticBlocking(opts, c, existing.vendor, errs, manifest);
669
+ }
670
+ return reject(opts, `terraform plan failed\n${diagnosticLines(errs) || failureDetail(planned)}`, where, { kind: "TerraformPlan", nextAction: replan });
671
+ }
672
+ const changes = stream.changes ?? { add: 0, change: 0, destroy: 0 };
673
+ const nextAction = { kind: "run", command: cmdApply(c.name) };
674
+ const result = {
675
+ status: "ready",
676
+ provider: c.name,
677
+ vendor: existing.vendor,
678
+ server: c.server ?? "",
679
+ namespace: c.namespace,
680
+ dir: c.dir,
681
+ files: [],
682
+ blocking: [],
683
+ plan: changes,
684
+ nextAction,
685
+ };
686
+ if (opts.json) {
687
+ emitJson(scopeResult(opts, result));
688
+ return 0;
689
+ }
690
+ ok(`plan is clean — ${changes.add} to add, ${changes.change} to change, ` +
691
+ `${changes.destroy} to destroy`);
692
+ process.stdout.write(" nothing has been applied. The next command spends money.\n");
693
+ printNext(nextAction);
694
+ return 0;
695
+ }
696
+ function notScaffolded(name, dir) {
697
+ return (`no provider scaffold at ${dir} — nothing to work with. ` +
698
+ `Create it first, deliberately, with a vendor: ` +
699
+ `dreamlake provider create -n ${name} --provider <${VENDORS.join("|")}>`);
700
+ }
701
+ /** Missing / invalid variable → a question (rc 0). Anything else → an error. */
702
+ function classify(errs) {
703
+ return errs.length > 0 && errs.every(isVariableProblem) ? "needs_input" : "error";
704
+ }
705
+ function diagnosticLines(errs) {
706
+ return errs
707
+ .map((d) => ` ${d.summary}${d.detail ? `: ${d.detail}` : ""}`)
708
+ .join("\n");
709
+ }
710
+ /** terraform's own diagnostics, turned into `blocking[]` with reason "invalid". */
711
+ function emitDiagnosticBlocking(opts, c, vendor, errs, manifest) {
712
+ const blocking = vendor === JUMP_WORKER_VENDOR ? [{
713
+ key: "terraform-inputs", reason: "invalid", file: path.join(c.dir, "terraform", "terraform.tfvars.json"),
714
+ why: "Terraform rejected the reviewed inputs; raw diagnostics are suppressed because they may include state secrets. Review the schema and validate locally in the protected directory.",
715
+ }] : errs.map((d) => ({
716
+ key: variableName(d) ?? d.summary,
717
+ reason: "invalid",
718
+ file: d.file ? path.join(c.dir, "terraform", path.basename(d.file)) : undefined,
719
+ line: d.line,
720
+ why: d.detail ?? d.summary,
721
+ }));
722
+ const editFile = decisionFile(c.dir, manifest, blocking);
723
+ const nextAction = {
724
+ kind: "edit_then_continue",
725
+ file: editFile,
726
+ command: cmdContinue(c.name),
727
+ };
728
+ const result = {
729
+ status: "needs_input",
730
+ provider: c.name,
731
+ vendor,
732
+ server: c.server ?? "",
733
+ namespace: c.namespace,
734
+ dir: c.dir,
735
+ blocking,
736
+ nextAction,
737
+ };
738
+ if (opts.json) {
739
+ emitJson(scopeResult(opts, result));
740
+ return 0;
741
+ }
742
+ printBlocking(blocking, editFile, cmdContinue(c.name));
743
+ return 0;
744
+ }
745
+ /** `No value for required variable` names it in the detail; pull it out. */
746
+ function variableName(d) {
747
+ const m = /variable\s+"([^"]+)"/i.exec(`${d.summary} ${d.detail ?? ""}`);
748
+ return m?.[1] ?? null;
749
+ }
750
+ // ─── apply ───────────────────────────────────────────────────────────────────
751
+ export async function runProviderApply(opts, deps = {}) {
752
+ const c = open(opts);
753
+ if (isError(c))
754
+ return reject(opts, c.error, c.where);
755
+ const existing = readProviderRecord(c.dir);
756
+ if (!existing) {
757
+ return reject(opts, notScaffolded(c.name, c.dir), c.where, { kind: "NotScaffolded" });
758
+ }
759
+ const manifest = loadTemplate(existing.vendor);
760
+ if (!manifest) {
761
+ return reject(opts, unknownVendorMessage(existing.vendor), {
762
+ ...c.where,
763
+ vendor: existing.vendor,
764
+ });
765
+ }
766
+ const where = { ...c.where, vendor: existing.vendor };
767
+ if (manifest.terraform === false) {
768
+ return reject(opts, `vendor '${existing.vendor}' has no terraform — there is nothing to apply.`, where, { kind: "NoTerraform", nextAction: { kind: "run", command: cmdConnect(c.name) } });
769
+ }
770
+ const tfDir = path.join(c.dir, "terraform");
771
+ if (!opts.json)
772
+ header("apply", c, existing.vendor);
773
+ // ── the lock check comes before --yes: an apply that is already in flight is
774
+ // not a question about consent, it is a fact about the world. ──
775
+ const lock = path.join(tfDir, LOCK_FILE);
776
+ if (existsSync(lock)) {
777
+ const held = heldFor(lock);
778
+ const nextAction = { kind: "run", command: cmdApply(c.name) };
779
+ const result = {
780
+ status: "applying",
781
+ provider: c.name,
782
+ vendor: existing.vendor,
783
+ server: c.server ?? "",
784
+ namespace: c.namespace,
785
+ dir: c.dir,
786
+ nextAction,
787
+ };
788
+ if (opts.json) {
789
+ emitJson(scopeResult(opts, result));
790
+ return 0;
791
+ }
792
+ warn("an apply is in progress or was interrupted");
793
+ process.stdout.write(` terraform holds a state lock (${lock}${held ? `, held ${held}` : ""})\n`);
794
+ process.stdout.write("\n");
795
+ process.stdout.write(` next: ${nextAction.command} # re-run; terraform resumes\n`);
796
+ return 0;
797
+ }
798
+ // ── consent. NOT a prompt: an agent has no terminal, so the guard is that
799
+ // you have to type a DIFFERENT command than the one you just ran. ──
800
+ if (!opts.yes) {
801
+ const nextAction = { kind: "run", command: cmdApply(c.name) };
802
+ const result = {
803
+ status: "needs_input",
804
+ provider: c.name,
805
+ vendor: existing.vendor,
806
+ server: c.server ?? "",
807
+ namespace: c.namespace,
808
+ dir: c.dir,
809
+ blocking: [
810
+ {
811
+ key: "confirm",
812
+ reason: "unset",
813
+ why: "apply creates real infrastructure and spends real money. There is no " +
814
+ "confirmation prompt anywhere on this path; --yes is the confirmation.",
815
+ },
816
+ ],
817
+ nextAction,
818
+ };
819
+ if (opts.json) {
820
+ emitJson(scopeResult(opts, result));
821
+ return 0;
822
+ }
823
+ warn("apply needs --yes — it creates real infrastructure and spends real money");
824
+ printNext(nextAction);
825
+ return 0;
826
+ }
827
+ if (existing.vendor === JUMP_WORKER_VENDOR) {
828
+ const blocking = scanDecisions(c.dir, manifest);
829
+ if (blocking.length) {
830
+ const file = decisionFile(c.dir, manifest, blocking);
831
+ const result = { ...where, status: "needs_input", blocking,
832
+ nextAction: { kind: "edit_then_continue", file, command: cmdContinue(c.name) } };
833
+ if (opts.json)
834
+ emitJson(scopeResult(opts, result));
835
+ else
836
+ printBlocking(blocking, file, cmdContinue(c.name));
837
+ return 0;
838
+ }
839
+ }
840
+ const tf = resolveTerraform({ spawn: deps.spawn, quiet: opts.json || existing.vendor === JUMP_WORKER_VENDOR });
841
+ if (!tf.ok)
842
+ return reject(opts, tf.message, where, { kind: "NoTerraformBinary" });
843
+ const trun = { spawn: deps.spawn, quiet: opts.json || existing.vendor === JUMP_WORKER_VENDOR };
844
+ if (existing.vendor === JUMP_WORKER_VENDOR || !existsSync(path.join(tfDir, PLUGIN_DIR))) {
845
+ const initArgs = ["init", "-input=false", ...(existing.vendor === JUMP_WORKER_VENDOR ? [`-backend-config=${jumpWorkerBackend(c.dir)}`] : [])];
846
+ const init = runTerraform(tf.bin, tfDir, initArgs, TIMEOUTS.init, trun);
847
+ if (init.spawnError || init.status !== 0) {
848
+ return reject(opts, `terraform init failed\n${failureDetail(init)}`, where, {
849
+ kind: "TerraformInit",
850
+ nextAction: replanAfterFailure(tfDir, c.name),
851
+ });
852
+ }
853
+ }
854
+ // NO TIMEOUT. Twenty minutes is a normal EKS cluster.
855
+ const applied = runTerraform(tf.bin, tfDir, ["apply", "-input=false", "-auto-approve", "-json"], TIMEOUTS.apply, trun);
856
+ const stream = parsePlanStream(applied.stdout);
857
+ if (applied.spawnError || applied.status !== 0) {
858
+ // A failed apply that left a lock or a partial state is RESUMABLE, and
859
+ // terraform owns that recovery — we detect it and say so rather than
860
+ // reimplementing it.
861
+ if (existsSync(lock)) {
862
+ const result = {
863
+ status: "applying",
864
+ provider: c.name,
865
+ vendor: existing.vendor,
866
+ server: c.server ?? "",
867
+ namespace: c.namespace,
868
+ dir: c.dir,
869
+ nextAction: { kind: "run", command: cmdApply(c.name) },
870
+ };
871
+ if (opts.json) {
872
+ emitJson(scopeResult(opts, result));
873
+ return 0;
874
+ }
875
+ warn("the apply was interrupted and terraform still holds the state lock");
876
+ process.stdout.write(`\n next: ${cmdApply(c.name)} # re-run; terraform resumes\n`);
877
+ return 0;
878
+ }
879
+ // NOT `apply` again. A failed apply usually left partial state, and the way
880
+ // to find out what survived is the read-only command: plan re-derives the
881
+ // remaining diff, and its own nextAction is the apply if there is nothing
882
+ // to fix. Handing an agent `apply --yes` here is how a broken config
883
+ // becomes a retry loop that spends money on every turn.
884
+ return reject(opts, `terraform apply failed\n${diagnosticLines(stream.diagnostics) || failureDetail(applied)}`, where, { kind: "TerraformApply", nextAction: replanAfterFailure(tfDir, c.name) });
885
+ }
886
+ const changes = stream.changes ?? { add: 0, change: 0, destroy: 0 };
887
+ const claim = existing.vendor === JUMP_WORKER_VENDOR ? null : await fetchClaim(c.server, c.namespace, c.name);
888
+ const nextAction = existing.vendor === JUMP_WORKER_VENDOR
889
+ ? { kind: "edit_then_continue", file: path.join(c.dir, "terraform", "ENROLLMENT.md"), command: "dreamlake hosts enroll --help" }
890
+ : claim && claim.live > 0 ? null : { kind: "run", command: cmdConnect(c.name) };
891
+ const result = {
892
+ status: "applied",
893
+ provider: c.name,
894
+ vendor: existing.vendor,
895
+ server: c.server ?? "",
896
+ namespace: c.namespace,
897
+ dir: c.dir,
898
+ plan: changes,
899
+ claim: claim ?? undefined,
900
+ degraded: existing.vendor === JUMP_WORKER_VENDOR ? ["enrollment-not-verified"] : claim ? undefined : ["no-lakeshore"],
901
+ nextAction,
902
+ };
903
+ if (opts.json) {
904
+ emitJson(scopeResult(opts, result));
905
+ return 0;
906
+ }
907
+ ok(`applied — ${changes.add} added, ${changes.change} changed, ${changes.destroy} destroyed`);
908
+ if (existing.vendor === JUMP_WORKER_VENDOR) {
909
+ process.stdout.write(" infrastructure only; follow the chosen controller mode’s enrollment handoff.\n");
910
+ }
911
+ else if (!claim || claim.live === 0) {
912
+ process.stdout.write(" nothing is claiming this provider yet.\n");
913
+ }
914
+ printNext(nextAction);
915
+ return 0;
916
+ }
917
+ /** `held 00:04:12`, from the lock file's mtime. Best effort. */
918
+ function heldFor(lock) {
919
+ try {
920
+ const ms = Date.now() - statSync(lock).mtimeMs;
921
+ if (ms < 0)
922
+ return null;
923
+ const s = Math.floor(ms / 1000);
924
+ const pad = (n) => String(n).padStart(2, "0");
925
+ return `${pad(Math.floor(s / 3600))}:${pad(Math.floor((s % 3600) / 60))}:${pad(s % 60)}`;
926
+ }
927
+ catch {
928
+ return null;
929
+ }
930
+ }
931
+ // ─── connect ─────────────────────────────────────────────────────────────────
932
+ export async function runProviderConnect(opts, deps = {}) {
933
+ const c = open(opts);
934
+ if (isError(c))
935
+ return reject(opts, c.error, c.where);
936
+ const existing = readProviderRecord(c.dir);
937
+ const vendor = existing?.vendor;
938
+ if (vendor === JUMP_WORKER_VENDOR)
939
+ return enrollmentHandoff(opts, c);
940
+ const where = { ...c.where, vendor };
941
+ if (!opts.json)
942
+ header("connect", c, vendor);
943
+ // ── 1. THE CLAIM CHECK COMES FIRST. Idempotence before action: if something
944
+ // is already claiming this provider, connect spawns ZERO ssh
945
+ // subprocesses. A test asserts the recorded argv list is empty. ──
946
+ const claim = await fetchClaim(c.server, c.namespace, c.name);
947
+ if (claim && claim.live > 0) {
948
+ const result = {
949
+ status: "exists",
950
+ provider: c.name,
951
+ vendor,
952
+ server: c.server ?? "",
953
+ namespace: c.namespace,
954
+ dir: existing ? c.dir : undefined,
955
+ files: [],
956
+ claim,
957
+ nextAction: null,
958
+ };
959
+ if (opts.json) {
960
+ emitJson(scopeResult(opts, result));
961
+ return 0;
962
+ }
963
+ warn(`${claim.live} live worker${claim.live === 1 ? "" : "s"} already claiming ` +
964
+ `'${c.name}' — nothing was started`);
965
+ printClaimRows(claim);
966
+ printNext(null);
967
+ return 0;
968
+ }
969
+ // ── 2. the host ──
970
+ const host = resolveHost(opts, c.dir);
971
+ if (!host) {
972
+ const nextAction = {
973
+ kind: "edit_then_continue",
974
+ file: path.join(c.dir, "adopt.json"),
975
+ command: `dreamlake provider connect -n ${c.name} --host user@host.example`,
976
+ };
977
+ const result = {
978
+ status: "needs_input",
979
+ provider: c.name,
980
+ vendor,
981
+ server: c.server ?? "",
982
+ namespace: c.namespace,
983
+ dir: existing ? c.dir : undefined,
984
+ blocking: [
985
+ {
986
+ key: "host",
987
+ reason: "unset",
988
+ file: existing ? path.join(c.dir, "adopt.json") : undefined,
989
+ why: "connect needs a machine to reach. Pass --host user@hostname, or put " +
990
+ "`host` in adopt.json. Nothing is derivable from terraform outputs here.",
991
+ },
992
+ ],
993
+ degraded: claim ? undefined : ["no-lakeshore"],
994
+ nextAction,
995
+ };
996
+ if (opts.json) {
997
+ emitJson(scopeResult(opts, result));
998
+ return 0;
999
+ }
1000
+ printBlocking(result.blocking, nextAction.file, nextAction.command);
1001
+ return 0;
1002
+ }
1003
+ let command;
1004
+ try {
1005
+ command = nymphCommand({
1006
+ command: opts.nymphCommand,
1007
+ server: c.server ?? undefined,
1008
+ queue: opts.queue,
1009
+ });
1010
+ }
1011
+ catch (err) {
1012
+ return reject(opts, err.message, where, { kind: "MissingServer" });
1013
+ }
1014
+ const sdeps = { spawn: deps.spawn, quiet: opts.json };
1015
+ // ── 3. the probe. BatchMode=yes means this can never sit at a password
1016
+ // prompt: a refused key fails here, with the command that fixes it. ──
1017
+ const probed = probeHost(host, sdeps);
1018
+ if (probed.spawnError || probed.status !== 0) {
1019
+ return reject(opts, unreachableMessage(host, probed), where, {
1020
+ kind: "SshUnreachable",
1021
+ nextAction: { kind: "shell", command: `ssh-copy-id ${host}`, host },
1022
+ });
1023
+ }
1024
+ // ── 4. the supervisor ladder, checked on the HOST rather than assumed ──
1025
+ const { supervisor } = detectSupervisor(host, sdeps);
1026
+ if (supervisor === "none") {
1027
+ return reject(opts, `no supervisor on ${host} — install tmux, or enable systemd --user, then re-run`, where, { kind: "NoSupervisor", nextAction: { kind: "shell", command: "sudo apt-get install -y tmux", host } });
1028
+ }
1029
+ const started = startNymph(host, c.name, supervisor, command, sdeps);
1030
+ if (started.spawnError || started.status !== 0) {
1031
+ return reject(opts, `could not start the nymph on ${host}\n${failureDetail({
1032
+ status: started.status,
1033
+ stdout: started.stdout,
1034
+ stderr: started.stderr,
1035
+ spawnError: started.spawnError,
1036
+ })}`, where, { kind: "NymphStartFailed" });
1037
+ }
1038
+ // ── 5. did it claim? Asked once, not waited on: connect holds no socket and
1039
+ // is not the supervisor. `status` is how you watch. ──
1040
+ const after = await fetchClaim(c.server, c.namespace, c.name);
1041
+ const connected = Boolean(after && after.live > 0);
1042
+ const degraded = [];
1043
+ if (!after)
1044
+ degraded.push("no-lakeshore");
1045
+ if (supervisor === "tmux")
1046
+ degraded.push("no-supervisor");
1047
+ const nextAction = connected
1048
+ ? null
1049
+ : { kind: "run", command: cmdStatus(c.name) };
1050
+ const result = {
1051
+ status: connected ? "connected" : "connecting",
1052
+ provider: c.name,
1053
+ vendor,
1054
+ server: c.server ?? "",
1055
+ namespace: c.namespace,
1056
+ dir: existing ? c.dir : undefined,
1057
+ claim: after ?? undefined,
1058
+ degraded: degraded.length > 0 ? degraded : undefined,
1059
+ nextAction,
1060
+ };
1061
+ if (opts.json) {
1062
+ emitJson(scopeResult(opts, result));
1063
+ return 0;
1064
+ }
1065
+ ok(`nymph started on ${host} under ${supervisorLabel(supervisor, c.name)}`);
1066
+ if (supervisor === "tmux") {
1067
+ // tmux is for ATTACHING, not for supervising, and the prose says so
1068
+ // plainly rather than implying otherwise.
1069
+ warn(`no supervisor on this host — nymph is running under tmux (session nymph-${c.name})`);
1070
+ process.stdout.write(" tmux keeps it alive after your ssh session ends. It does NOT restart it.\n");
1071
+ process.stdout.write(" If this nymph dies, nothing brings it back:\n");
1072
+ process.stdout.write(` ${cmdConnect(c.name)} # re-run to restart\n`);
1073
+ }
1074
+ if (connected && after) {
1075
+ ok(`connected — ${after.live} live worker${after.live === 1 ? "" : "s"} claiming '${c.name}'`);
1076
+ printClaimRows(after);
1077
+ }
1078
+ else {
1079
+ warn("not claiming yet — a claim usually appears within ~10s");
1080
+ }
1081
+ printNext(nextAction);
1082
+ return 0;
1083
+ }
1084
+ /** `--host` → `adopt.json`'s `host` key. Terraform outputs are slice 4. */
1085
+ function resolveHost(opts, dir) {
1086
+ if (opts.host && opts.host.trim())
1087
+ return opts.host.trim();
1088
+ const adopt = path.join(dir, "adopt.json");
1089
+ if (!existsSync(adopt))
1090
+ return null;
1091
+ try {
1092
+ const parsed = JSON.parse(readFileSync(adopt, "utf8"));
1093
+ const host = typeof parsed.host === "string" ? parsed.host.trim() : "";
1094
+ return host && !isPlaceholder(JSON.stringify(host)) ? host : null;
1095
+ }
1096
+ catch {
1097
+ return null;
1098
+ }
1099
+ }
1100
+ function printClaimRows(claim) {
1101
+ for (const row of claim.rows.slice(0, 5)) {
1102
+ const queues = row.queues.length > 0 ? ` queues: ${row.queues.join(", ")}` : "";
1103
+ process.stdout.write(` ${row.id.padEnd(22)}${row.state.padEnd(10)}${queues}\n`);
1104
+ }
1105
+ if (claim.rows.length > 5) {
1106
+ process.stdout.write(` … ${claim.rows.length - 5} more\n`);
1107
+ }
1108
+ }
1109
+ // ─── disconnect ──────────────────────────────────────────────────────────────
1110
+ //
1111
+ // THE BUG THIS CLOSES. `provider delete` removes the database row and nothing
1112
+ // else, so a deleted provider whose nymph is still running keeps polling the
1113
+ // control plane forever, claiming a name that no longer exists. Until now the
1114
+ // only cure was the manual `ssh <host> systemctl --user stop …` the docs page
1115
+ // lists as a workaround.
1116
+ //
1117
+ // DISCONNECT IS NOT DELETE, and it is not a soft version of it either. The
1118
+ // Provider row is untouched — this stops a process on a machine, which is the
1119
+ // half `delete` never did. Deleting the row is still `provider delete`, and the
1120
+ // honest order is disconnect first, delete second.
1121
+ //
1122
+ // IT CLIMBS THE SAME LADDER `connect` CLIMBED, on the same host, in the same
1123
+ // one round trip. The stop action is not chosen from a config file or assumed
1124
+ // from the vendor: it is whatever `detectSupervisor` reports NOW, because that
1125
+ // is the only thing that agrees with how the nymph was actually started.
1126
+ //
1127
+ // IDEMPOTENT, ON PURPOSE. Stopping something that is already stopped exits 0
1128
+ // and says which of the two nothings it found — no unit at all, or a unit that
1129
+ // was already down. The same rule as `needs_input`: "I deliberately did not do
1130
+ // the thing, because it was already done" is a success.
1131
+ export async function runProviderDisconnect(opts, deps = {}) {
1132
+ const c = open(opts);
1133
+ if (isError(c))
1134
+ return reject(opts, c.error, c.where);
1135
+ const existing = readProviderRecord(c.dir);
1136
+ const vendor = existing?.vendor;
1137
+ if (vendor === JUMP_WORKER_VENDOR)
1138
+ return enrollmentHandoff(opts, c);
1139
+ const where = { ...c.where, vendor };
1140
+ if (!opts.json)
1141
+ header("disconnect", c, vendor);
1142
+ // ── 1. the host, resolved exactly the way connect resolves it ──
1143
+ //
1144
+ // NO CLAIM CHECK FIRST, and that is the deliberate difference from `connect`.
1145
+ // For connect a live claim means "already done" and is a reason to spawn
1146
+ // nothing. Here it means the opposite — there IS something to stop — and its
1147
+ // ABSENCE proves nothing at all: a nymph that is running but not claiming, or
1148
+ // a control plane we cannot reach, both look like zero.
1149
+ const host = resolveHost(opts, c.dir);
1150
+ if (!host) {
1151
+ const nextAction = {
1152
+ kind: "edit_then_continue",
1153
+ file: path.join(c.dir, "adopt.json"),
1154
+ command: `${cmdDisconnect(c.name)} --host user@host.example`,
1155
+ };
1156
+ const result = {
1157
+ status: "needs_input",
1158
+ provider: c.name,
1159
+ vendor,
1160
+ server: c.server ?? "",
1161
+ namespace: c.namespace,
1162
+ dir: existing ? c.dir : undefined,
1163
+ blocking: [
1164
+ {
1165
+ key: "host",
1166
+ reason: "unset",
1167
+ file: existing ? path.join(c.dir, "adopt.json") : undefined,
1168
+ why: "disconnect needs the machine the nymph is running on. Pass --host " +
1169
+ "user@hostname, or put `host` in adopt.json. Nothing was stopped.",
1170
+ },
1171
+ ],
1172
+ nextAction,
1173
+ };
1174
+ if (opts.json) {
1175
+ emitJson(scopeResult(opts, result));
1176
+ return 0;
1177
+ }
1178
+ printBlocking(result.blocking, nextAction.file, nextAction.command);
1179
+ return 0;
1180
+ }
1181
+ const sdeps = { spawn: deps.spawn, quiet: opts.json };
1182
+ // ── 2. the probe. Same BatchMode rule: a refused key fails here rather than
1183
+ // hanging, and it must NOT read as "the nymph is stopped". ──
1184
+ const probed = probeHost(host, sdeps);
1185
+ if (probed.spawnError || probed.status !== 0) {
1186
+ return reject(opts, unreachableMessage(host, probed), where, {
1187
+ kind: "SshUnreachable",
1188
+ nextAction: { kind: "shell", command: `ssh-copy-id ${host}`, host },
1189
+ });
1190
+ }
1191
+ // ── 3. the ladder — REUSED, not reimplemented. ──
1192
+ const { supervisor } = detectSupervisor(host, sdeps);
1193
+ if (supervisor === "none") {
1194
+ // SAY SO RATHER THAN PRETEND. There is no supervisor here, which means
1195
+ // nothing on this host was started by `connect` and nothing here knows what
1196
+ // to stop. Reporting a cheerful "disconnected" would be a lie that leaves a
1197
+ // nymph polling.
1198
+ return reject(opts, `no supervisor on ${host} — NOTHING WAS STOPPED. There is no systemd and no ` +
1199
+ `tmux here, so nothing on this host was started by \`dreamlake provider ` +
1200
+ `connect\` and this command has nothing it knows how to stop.`, where, {
1201
+ kind: "NoSupervisor",
1202
+ nextAction: { kind: "shell", command: `ssh ${host} 'pgrep -af nymph'`, host },
1203
+ });
1204
+ }
1205
+ // ── 4. the stop itself, one round trip, check-then-act on the host ──
1206
+ const { outcome, result } = stopNymph(host, c.name, supervisor, sdeps);
1207
+ if (outcome.spawnError || outcome.status !== 0 || result === null) {
1208
+ return reject(opts, `could not stop the nymph on ${host}\n${failureDetail({
1209
+ status: outcome.status,
1210
+ stdout: outcome.stdout,
1211
+ stderr: outcome.stderr,
1212
+ spawnError: outcome.spawnError,
1213
+ })}`, where, {
1214
+ kind: "NymphStopFailed",
1215
+ nextAction: {
1216
+ kind: "shell",
1217
+ command: `ssh ${host} '${stopCommand(supervisor, c.name)}'`,
1218
+ host,
1219
+ },
1220
+ });
1221
+ }
1222
+ // ── 5. did the claim drop? Asked once, not waited on — the control plane
1223
+ // notices a missing handshake on its own schedule, not ours. ──
1224
+ const after = await fetchClaim(c.server, c.namespace, c.name);
1225
+ const nextAction = after && after.live === 0 ? null : { kind: "run", command: cmdStatus(c.name) };
1226
+ const res = {
1227
+ // `stopped` is the only one that CHANGED anything; the other two are the
1228
+ // idempotent no-op, which this CLI has always spelled `exists`.
1229
+ status: result === "stopped" ? "disconnected" : "exists",
1230
+ provider: c.name,
1231
+ vendor,
1232
+ server: c.server ?? "",
1233
+ namespace: c.namespace,
1234
+ dir: existing ? c.dir : undefined,
1235
+ files: [],
1236
+ claim: after ?? undefined,
1237
+ degraded: after ? undefined : ["no-lakeshore"],
1238
+ nextAction,
1239
+ };
1240
+ if (opts.json) {
1241
+ emitJson(res);
1242
+ return 0;
1243
+ }
1244
+ if (result === "stopped") {
1245
+ ok(`nymph stopped on ${host} — ${stopLabel(supervisor, c.name)}`);
1246
+ }
1247
+ else if (result === "inactive") {
1248
+ warn(`nymph-${c.name} on ${host} was already stopped — nothing to do`);
1249
+ process.stdout.write(" already stopped is a success, not a failure.\n");
1250
+ }
1251
+ else {
1252
+ warn(`no nymph-${c.name} on ${host} — there was nothing running to stop`);
1253
+ process.stdout.write(" already stopped is a success, not a failure.\n");
1254
+ }
1255
+ // The line the docs page's "Kill" section exists because nobody could say.
1256
+ process.stdout.write(` the provider row is untouched — disconnect is not delete.\n` +
1257
+ ` to remove the row as well: dreamlake provider delete ${c.name} --yes\n`);
1258
+ if (after && after.live > 0) {
1259
+ warn(`${after.live} worker${after.live === 1 ? "" : "s"} still claiming '${c.name}' — ` +
1260
+ `the control plane has not noticed the missing handshake yet`);
1261
+ printClaimRows(after);
1262
+ }
1263
+ else if (!after) {
1264
+ process.stdout.write(" no control plane connected, so the claim is unknown.\n");
1265
+ }
1266
+ printNext(nextAction);
1267
+ return 0;
1268
+ }
1269
+ // ─── status ──────────────────────────────────────────────────────────────────
1270
+ //
1271
+ // The phase, RECOMPUTED. Nothing below reads a stored status, because there is
1272
+ // not one to read.
1273
+ export async function runProviderStatus(opts, deps = {}) {
1274
+ void deps; // status observes; it never spawns.
1275
+ const c = open(opts);
1276
+ if (isError(c))
1277
+ return reject(opts, c.error, c.where);
1278
+ const existing = readProviderRecord(c.dir);
1279
+ const claim = existing?.vendor === JUMP_WORKER_VENDOR ? null : await fetchClaim(c.server, c.namespace, c.name);
1280
+ if (!existing && (!claim || claim.live === 0)) {
1281
+ return reject(opts, notScaffolded(c.name, c.dir), c.where, {
1282
+ kind: "NotScaffolded",
1283
+ nextAction: { kind: "run", command: cmdCreate(c.name, "kube") },
1284
+ });
1285
+ }
1286
+ const manifest = existing ? loadTemplate(existing.vendor) : null;
1287
+ const blocking = existing && manifest ? scanDecisions(c.dir, manifest) : [];
1288
+ const tfDir = path.join(c.dir, "terraform");
1289
+ const locked = existsSync(path.join(tfDir, LOCK_FILE));
1290
+ const applied = existing?.vendor !== JUMP_WORKER_VENDOR && hasResources(path.join(tfDir, STATE_FILE));
1291
+ if (!opts.json)
1292
+ header("status", c, existing?.vendor);
1293
+ // Order matters, and it is "the world beats the file": an observed claim is
1294
+ // the terminal state whatever the tfvars say.
1295
+ let status;
1296
+ let nextAction;
1297
+ if (claim && claim.live > 0) {
1298
+ status = "connected";
1299
+ nextAction = null;
1300
+ }
1301
+ else if (blocking.length > 0) {
1302
+ status = "needs_input";
1303
+ nextAction = {
1304
+ kind: "edit_then_continue",
1305
+ file: decisionFile(c.dir, manifest, blocking),
1306
+ command: cmdContinue(c.name),
1307
+ };
1308
+ }
1309
+ else if (locked) {
1310
+ status = "applying";
1311
+ nextAction = { kind: "run", command: cmdApply(c.name) };
1312
+ }
1313
+ else if (applied) {
1314
+ status = "unclaimed";
1315
+ nextAction = { kind: "run", command: cmdConnect(c.name) };
1316
+ }
1317
+ else if (manifest?.terraform === false) {
1318
+ status = "scaffolded";
1319
+ nextAction = { kind: "run", command: cmdConnect(c.name) };
1320
+ }
1321
+ else {
1322
+ status = "scaffolded";
1323
+ nextAction = { kind: "run", command: cmdPlan(c.name) };
1324
+ }
1325
+ const degraded = [];
1326
+ if (existing?.vendor === JUMP_WORKER_VENDOR)
1327
+ degraded.push("remote-state-not-probed", "enrollment-not-verified");
1328
+ else if (!claim)
1329
+ degraded.push("no-lakeshore");
1330
+ if (blocking.length > 0)
1331
+ degraded.push("no-probe");
1332
+ const result = {
1333
+ status,
1334
+ provider: c.name,
1335
+ vendor: existing?.vendor,
1336
+ server: c.server ?? "",
1337
+ namespace: c.namespace,
1338
+ dir: existing ? c.dir : undefined,
1339
+ files: [],
1340
+ blocking,
1341
+ claim: claim ?? undefined,
1342
+ degraded: degraded.length > 0 ? degraded : undefined,
1343
+ nextAction,
1344
+ };
1345
+ if (opts.json) {
1346
+ emitJson(scopeResult(opts, result));
1347
+ return 0;
1348
+ }
1349
+ if (existing) {
1350
+ process.stdout.write(field("template", existing.template));
1351
+ }
1352
+ switch (status) {
1353
+ case "connected":
1354
+ ok(`connected — ${claim.live} live worker${claim.live === 1 ? "" : "s"} claiming '${c.name}'`);
1355
+ printClaimRows(claim);
1356
+ break;
1357
+ case "needs_input":
1358
+ printBlocking(blocking, decisionFile(c.dir, manifest, blocking), cmdContinue(c.name));
1359
+ return 0;
1360
+ case "applying":
1361
+ warn("an apply is in progress or was interrupted");
1362
+ break;
1363
+ case "unclaimed":
1364
+ // A normal state, not a fault. It must never read as an error.
1365
+ warn(`unclaimed — no bridge is claiming '${c.name}'`);
1366
+ process.stdout.write(" this is a normal state, not a fault: it means nothing can launch into this\n" +
1367
+ " account right now.\n");
1368
+ break;
1369
+ default:
1370
+ ok(`scaffolded — ${relative(c.dream, c.dir)}/`);
1371
+ if (!claim) {
1372
+ process.stdout.write(existing?.vendor === JUMP_WORKER_VENDOR ? " remote state and enrollment are not probed; plan verifies infrastructure.\n" : " no control plane connected, so the claim is unknown.\n");
1373
+ }
1374
+ break;
1375
+ }
1376
+ printNext(nextAction);
1377
+ return 0;
1378
+ }
1379
+ /** Is there a state file with anything in it? */
1380
+ function hasResources(statePath) {
1381
+ if (!existsSync(statePath))
1382
+ return false;
1383
+ try {
1384
+ const parsed = JSON.parse(readFileSync(statePath, "utf8"));
1385
+ return Array.isArray(parsed.resources) && parsed.resources.length > 0;
1386
+ }
1387
+ catch {
1388
+ return false;
1389
+ }
1390
+ }