@seasb/metafab 0.0.1 → 2.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (414) hide show
  1. package/README.md +46 -1
  2. package/dist/cli.d.ts +11 -0
  3. package/dist/cli.js +419 -0
  4. package/dist/cli.js.map +1 -0
  5. package/dist/commands/build.d.ts +31 -0
  6. package/dist/commands/build.js +156 -0
  7. package/dist/commands/build.js.map +1 -0
  8. package/dist/commands/check.d.ts +2 -0
  9. package/dist/commands/check.js +52 -0
  10. package/dist/commands/check.js.map +1 -0
  11. package/dist/commands/create.d.ts +2 -0
  12. package/dist/commands/create.js +75 -0
  13. package/dist/commands/create.js.map +1 -0
  14. package/dist/commands/detach.d.ts +2 -0
  15. package/dist/commands/detach.js +24 -0
  16. package/dist/commands/detach.js.map +1 -0
  17. package/dist/commands/diff.d.ts +2 -0
  18. package/dist/commands/diff.js +35 -0
  19. package/dist/commands/diff.js.map +1 -0
  20. package/dist/commands/env.d.ts +4 -0
  21. package/dist/commands/env.js +362 -0
  22. package/dist/commands/env.js.map +1 -0
  23. package/dist/commands/import.d.ts +2 -0
  24. package/dist/commands/import.js +107 -0
  25. package/dist/commands/import.js.map +1 -0
  26. package/dist/commands/init.d.ts +2 -0
  27. package/dist/commands/init.js +77 -0
  28. package/dist/commands/init.js.map +1 -0
  29. package/dist/commands/map.d.ts +2 -0
  30. package/dist/commands/map.js +42 -0
  31. package/dist/commands/map.js.map +1 -0
  32. package/dist/commands/pipeline-add.d.ts +2 -0
  33. package/dist/commands/pipeline-add.js +68 -0
  34. package/dist/commands/pipeline-add.js.map +1 -0
  35. package/dist/commands/pipeline-remove.d.ts +2 -0
  36. package/dist/commands/pipeline-remove.js +45 -0
  37. package/dist/commands/pipeline-remove.js.map +1 -0
  38. package/dist/commands/publish.d.ts +2 -0
  39. package/dist/commands/publish.js +153 -0
  40. package/dist/commands/publish.js.map +1 -0
  41. package/dist/commands/types.d.ts +45 -0
  42. package/dist/commands/types.js +2 -0
  43. package/dist/commands/types.js.map +1 -0
  44. package/dist/commands/update.d.ts +2 -0
  45. package/dist/commands/update.js +97 -0
  46. package/dist/commands/update.js.map +1 -0
  47. package/dist/core/adopt.d.ts +53 -0
  48. package/dist/core/adopt.js +676 -0
  49. package/dist/core/adopt.js.map +1 -0
  50. package/dist/core/build/agents.d.ts +26 -0
  51. package/dist/core/build/agents.js +67 -0
  52. package/dist/core/build/agents.js.map +1 -0
  53. package/dist/core/build/index.d.ts +5 -0
  54. package/dist/core/build/index.js +6 -0
  55. package/dist/core/build/index.js.map +1 -0
  56. package/dist/core/build/markers.d.ts +34 -0
  57. package/dist/core/build/markers.js +97 -0
  58. package/dist/core/build/markers.js.map +1 -0
  59. package/dist/core/build/plan.d.ts +82 -0
  60. package/dist/core/build/plan.js +912 -0
  61. package/dist/core/build/plan.js.map +1 -0
  62. package/dist/core/build/preview.d.ts +39 -0
  63. package/dist/core/build/preview.js +344 -0
  64. package/dist/core/build/preview.js.map +1 -0
  65. package/dist/core/build/skill.d.ts +99 -0
  66. package/dist/core/build/skill.js +354 -0
  67. package/dist/core/build/skill.js.map +1 -0
  68. package/dist/core/check/drift.d.ts +13 -0
  69. package/dist/core/check/drift.js +205 -0
  70. package/dist/core/check/drift.js.map +1 -0
  71. package/dist/core/check/index.d.ts +16 -0
  72. package/dist/core/check/index.js +84 -0
  73. package/dist/core/check/index.js.map +1 -0
  74. package/dist/core/check/markers.d.ts +9 -0
  75. package/dist/core/check/markers.js +220 -0
  76. package/dist/core/check/markers.js.map +1 -0
  77. package/dist/core/config/destinations.d.ts +5 -0
  78. package/dist/core/config/destinations.js +20 -0
  79. package/dist/core/config/destinations.js.map +1 -0
  80. package/dist/core/config/load.d.ts +4 -0
  81. package/dist/core/config/load.js +41 -0
  82. package/dist/core/config/load.js.map +1 -0
  83. package/dist/core/config/parse.d.ts +8 -0
  84. package/dist/core/config/parse.js +201 -0
  85. package/dist/core/config/parse.js.map +1 -0
  86. package/dist/core/config/source.d.ts +25 -0
  87. package/dist/core/config/source.js +67 -0
  88. package/dist/core/config/source.js.map +1 -0
  89. package/dist/core/config/types.d.ts +48 -0
  90. package/dist/core/config/types.js +2 -0
  91. package/dist/core/config/types.js.map +1 -0
  92. package/dist/core/config/validate.d.ts +11 -0
  93. package/dist/core/config/validate.js +389 -0
  94. package/dist/core/config/validate.js.map +1 -0
  95. package/dist/core/config/writers.d.ts +14 -0
  96. package/dist/core/config/writers.js +269 -0
  97. package/dist/core/config/writers.js.map +1 -0
  98. package/dist/core/config.d.ts +7 -0
  99. package/dist/core/config.js +8 -0
  100. package/dist/core/config.js.map +1 -0
  101. package/dist/core/discovery.d.ts +34 -0
  102. package/dist/core/discovery.js +272 -0
  103. package/dist/core/discovery.js.map +1 -0
  104. package/dist/core/edit/create.d.ts +18 -0
  105. package/dist/core/edit/create.js +190 -0
  106. package/dist/core/edit/create.js.map +1 -0
  107. package/dist/core/edit/document.d.ts +4 -0
  108. package/dist/core/edit/document.js +16 -0
  109. package/dist/core/edit/document.js.map +1 -0
  110. package/dist/core/edit/factory-yaml.d.ts +17 -0
  111. package/dist/core/edit/factory-yaml.js +213 -0
  112. package/dist/core/edit/factory-yaml.js.map +1 -0
  113. package/dist/core/edit/files.d.ts +6 -0
  114. package/dist/core/edit/files.js +47 -0
  115. package/dist/core/edit/files.js.map +1 -0
  116. package/dist/core/edit/index.d.ts +9 -0
  117. package/dist/core/edit/index.js +10 -0
  118. package/dist/core/edit/index.js.map +1 -0
  119. package/dist/core/edit/map.d.ts +24 -0
  120. package/dist/core/edit/map.js +82 -0
  121. package/dist/core/edit/map.js.map +1 -0
  122. package/dist/core/edit/names.d.ts +2 -0
  123. package/dist/core/edit/names.js +17 -0
  124. package/dist/core/edit/names.js.map +1 -0
  125. package/dist/core/edit/paths.d.ts +8 -0
  126. package/dist/core/edit/paths.js +81 -0
  127. package/dist/core/edit/paths.js.map +1 -0
  128. package/dist/core/edit/pipeline.d.ts +19 -0
  129. package/dist/core/edit/pipeline.js +152 -0
  130. package/dist/core/edit/pipeline.js.map +1 -0
  131. package/dist/core/edit/skill.d.ts +1 -0
  132. package/dist/core/edit/skill.js +10 -0
  133. package/dist/core/edit/skill.js.map +1 -0
  134. package/dist/core/env/condition.d.ts +40 -0
  135. package/dist/core/env/condition.js +283 -0
  136. package/dist/core/env/condition.js.map +1 -0
  137. package/dist/core/env/declarations.d.ts +16 -0
  138. package/dist/core/env/declarations.js +328 -0
  139. package/dist/core/env/declarations.js.map +1 -0
  140. package/dist/core/env/directives.d.ts +75 -0
  141. package/dist/core/env/directives.js +429 -0
  142. package/dist/core/env/directives.js.map +1 -0
  143. package/dist/core/env/git-config.d.ts +15 -0
  144. package/dist/core/env/git-config.js +110 -0
  145. package/dist/core/env/git-config.js.map +1 -0
  146. package/dist/core/env/imports.d.ts +60 -0
  147. package/dist/core/env/imports.js +217 -0
  148. package/dist/core/env/imports.js.map +1 -0
  149. package/dist/core/env/index.d.ts +6 -0
  150. package/dist/core/env/index.js +7 -0
  151. package/dist/core/env/index.js.map +1 -0
  152. package/dist/core/env/markdown.d.ts +22 -0
  153. package/dist/core/env/markdown.js +33 -0
  154. package/dist/core/env/markdown.js.map +1 -0
  155. package/dist/core/env/render.d.ts +13 -0
  156. package/dist/core/env/render.js +65 -0
  157. package/dist/core/env/render.js.map +1 -0
  158. package/dist/core/env/report.d.ts +29 -0
  159. package/dist/core/env/report.js +39 -0
  160. package/dist/core/env/report.js.map +1 -0
  161. package/dist/core/env/scenarios.d.ts +40 -0
  162. package/dist/core/env/scenarios.js +124 -0
  163. package/dist/core/env/scenarios.js.map +1 -0
  164. package/dist/core/env/select.d.ts +30 -0
  165. package/dist/core/env/select.js +191 -0
  166. package/dist/core/env/select.js.map +1 -0
  167. package/dist/core/env/types.d.ts +38 -0
  168. package/dist/core/env/types.js +2 -0
  169. package/dist/core/env/types.js.map +1 -0
  170. package/dist/core/env/validate.d.ts +25 -0
  171. package/dist/core/env/validate.js +212 -0
  172. package/dist/core/env/validate.js.map +1 -0
  173. package/dist/core/factory/discovery.d.ts +9 -0
  174. package/dist/core/factory/discovery.js +139 -0
  175. package/dist/core/factory/discovery.js.map +1 -0
  176. package/dist/core/factory/factory-yaml.d.ts +29 -0
  177. package/dist/core/factory/factory-yaml.js +538 -0
  178. package/dist/core/factory/factory-yaml.js.map +1 -0
  179. package/dist/core/factory/index.d.ts +5 -0
  180. package/dist/core/factory/index.js +6 -0
  181. package/dist/core/factory/index.js.map +1 -0
  182. package/dist/core/factory/lines.d.ts +8 -0
  183. package/dist/core/factory/lines.js +11 -0
  184. package/dist/core/factory/lines.js.map +1 -0
  185. package/dist/core/factory/load.d.ts +4 -0
  186. package/dist/core/factory/load.js +83 -0
  187. package/dist/core/factory/load.js.map +1 -0
  188. package/dist/core/factory/requires.d.ts +9 -0
  189. package/dist/core/factory/requires.js +123 -0
  190. package/dist/core/factory/requires.js.map +1 -0
  191. package/dist/core/factory/types.d.ts +58 -0
  192. package/dist/core/factory/types.js +2 -0
  193. package/dist/core/factory/types.js.map +1 -0
  194. package/dist/core/factory/validate.d.ts +44 -0
  195. package/dist/core/factory/validate.js +460 -0
  196. package/dist/core/factory/validate.js.map +1 -0
  197. package/dist/core/hooks/index.d.ts +8 -0
  198. package/dist/core/hooks/index.js +15 -0
  199. package/dist/core/hooks/index.js.map +1 -0
  200. package/dist/core/hooks/script.d.ts +21 -0
  201. package/dist/core/hooks/script.js +34 -0
  202. package/dist/core/hooks/script.js.map +1 -0
  203. package/dist/core/hooks/sync.d.ts +17 -0
  204. package/dist/core/hooks/sync.js +262 -0
  205. package/dist/core/hooks/sync.js.map +1 -0
  206. package/dist/core/import/conflicts.d.ts +82 -0
  207. package/dist/core/import/conflicts.js +256 -0
  208. package/dist/core/import/conflicts.js.map +1 -0
  209. package/dist/core/import/copy.d.ts +10 -0
  210. package/dist/core/import/copy.js +76 -0
  211. package/dist/core/import/copy.js.map +1 -0
  212. package/dist/core/import/file-tree.d.ts +43 -0
  213. package/dist/core/import/file-tree.js +107 -0
  214. package/dist/core/import/file-tree.js.map +1 -0
  215. package/dist/core/import/index.d.ts +5 -0
  216. package/dist/core/import/index.js +6 -0
  217. package/dist/core/import/index.js.map +1 -0
  218. package/dist/core/import/pipeline-changes.d.ts +8 -0
  219. package/dist/core/import/pipeline-changes.js +89 -0
  220. package/dist/core/import/pipeline-changes.js.map +1 -0
  221. package/dist/core/import/run.d.ts +76 -0
  222. package/dist/core/import/run.js +275 -0
  223. package/dist/core/import/run.js.map +1 -0
  224. package/dist/core/init/gitattributes.d.ts +20 -0
  225. package/dist/core/init/gitattributes.js +89 -0
  226. package/dist/core/init/gitattributes.js.map +1 -0
  227. package/dist/core/init/index.d.ts +4 -0
  228. package/dist/core/init/index.js +5 -0
  229. package/dist/core/init/index.js.map +1 -0
  230. package/dist/core/init/name.d.ts +1 -0
  231. package/dist/core/init/name.js +4 -0
  232. package/dist/core/init/name.js.map +1 -0
  233. package/dist/core/init/run.d.ts +51 -0
  234. package/dist/core/init/run.js +261 -0
  235. package/dist/core/init/run.js.map +1 -0
  236. package/dist/core/init/targets.d.ts +17 -0
  237. package/dist/core/init/targets.js +87 -0
  238. package/dist/core/init/targets.js.map +1 -0
  239. package/dist/core/merge.d.ts +88 -0
  240. package/dist/core/merge.js +239 -0
  241. package/dist/core/merge.js.map +1 -0
  242. package/dist/core/publish/exclude.d.ts +9 -0
  243. package/dist/core/publish/exclude.js +32 -0
  244. package/dist/core/publish/exclude.js.map +1 -0
  245. package/dist/core/publish/git-target.d.ts +32 -0
  246. package/dist/core/publish/git-target.js +460 -0
  247. package/dist/core/publish/git-target.js.map +1 -0
  248. package/dist/core/publish/index.d.ts +10 -0
  249. package/dist/core/publish/index.js +11 -0
  250. package/dist/core/publish/index.js.map +1 -0
  251. package/dist/core/publish/npm-target.d.ts +15 -0
  252. package/dist/core/publish/npm-target.js +177 -0
  253. package/dist/core/publish/npm-target.js.map +1 -0
  254. package/dist/core/publish/package-json.d.ts +31 -0
  255. package/dist/core/publish/package-json.js +74 -0
  256. package/dist/core/publish/package-json.js.map +1 -0
  257. package/dist/core/publish/prepare.d.ts +35 -0
  258. package/dist/core/publish/prepare.js +102 -0
  259. package/dist/core/publish/prepare.js.map +1 -0
  260. package/dist/core/publish/provenance.d.ts +1 -0
  261. package/dist/core/publish/provenance.js +20 -0
  262. package/dist/core/publish/provenance.js.map +1 -0
  263. package/dist/core/publish/publish.d.ts +13 -0
  264. package/dist/core/publish/publish.js +143 -0
  265. package/dist/core/publish/publish.js.map +1 -0
  266. package/dist/core/publish/readme.d.ts +22 -0
  267. package/dist/core/publish/readme.js +109 -0
  268. package/dist/core/publish/readme.js.map +1 -0
  269. package/dist/core/publish/stage.d.ts +19 -0
  270. package/dist/core/publish/stage.js +333 -0
  271. package/dist/core/publish/stage.js.map +1 -0
  272. package/dist/core/publish/types.d.ts +71 -0
  273. package/dist/core/publish/types.js +2 -0
  274. package/dist/core/publish/types.js.map +1 -0
  275. package/dist/core/requires/check.d.ts +15 -0
  276. package/dist/core/requires/check.js +83 -0
  277. package/dist/core/requires/check.js.map +1 -0
  278. package/dist/core/requires/index.d.ts +4 -0
  279. package/dist/core/requires/index.js +5 -0
  280. package/dist/core/requires/index.js.map +1 -0
  281. package/dist/core/requires/inspect.d.ts +44 -0
  282. package/dist/core/requires/inspect.js +114 -0
  283. package/dist/core/requires/inspect.js.map +1 -0
  284. package/dist/core/requires/paths.d.ts +29 -0
  285. package/dist/core/requires/paths.js +83 -0
  286. package/dist/core/requires/paths.js.map +1 -0
  287. package/dist/core/requires/setup.d.ts +37 -0
  288. package/dist/core/requires/setup.js +147 -0
  289. package/dist/core/requires/setup.js.map +1 -0
  290. package/dist/core/setup.d.ts +27 -0
  291. package/dist/core/setup.js +84 -0
  292. package/dist/core/setup.js.map +1 -0
  293. package/dist/core/sources/cache.d.ts +38 -0
  294. package/dist/core/sources/cache.js +264 -0
  295. package/dist/core/sources/cache.js.map +1 -0
  296. package/dist/core/sources/containment.d.ts +21 -0
  297. package/dist/core/sources/containment.js +50 -0
  298. package/dist/core/sources/containment.js.map +1 -0
  299. package/dist/core/sources/env.d.ts +12 -0
  300. package/dist/core/sources/env.js +28 -0
  301. package/dist/core/sources/env.js.map +1 -0
  302. package/dist/core/sources/extract.d.ts +25 -0
  303. package/dist/core/sources/extract.js +639 -0
  304. package/dist/core/sources/extract.js.map +1 -0
  305. package/dist/core/sources/git-process.d.ts +26 -0
  306. package/dist/core/sources/git-process.js +51 -0
  307. package/dist/core/sources/git-process.js.map +1 -0
  308. package/dist/core/sources/git.d.ts +41 -0
  309. package/dist/core/sources/git.js +525 -0
  310. package/dist/core/sources/git.js.map +1 -0
  311. package/dist/core/sources/https.d.ts +21 -0
  312. package/dist/core/sources/https.js +218 -0
  313. package/dist/core/sources/https.js.map +1 -0
  314. package/dist/core/sources/index.d.ts +13 -0
  315. package/dist/core/sources/index.js +14 -0
  316. package/dist/core/sources/index.js.map +1 -0
  317. package/dist/core/sources/npm-cli.d.ts +19 -0
  318. package/dist/core/sources/npm-cli.js +51 -0
  319. package/dist/core/sources/npm-cli.js.map +1 -0
  320. package/dist/core/sources/npm.d.ts +29 -0
  321. package/dist/core/sources/npm.js +411 -0
  322. package/dist/core/sources/npm.js.map +1 -0
  323. package/dist/core/sources/parse.d.ts +46 -0
  324. package/dist/core/sources/parse.js +446 -0
  325. package/dist/core/sources/parse.js.map +1 -0
  326. package/dist/core/sources/path.d.ts +10 -0
  327. package/dist/core/sources/path.js +331 -0
  328. package/dist/core/sources/path.js.map +1 -0
  329. package/dist/core/sources/problems.d.ts +29 -0
  330. package/dist/core/sources/problems.js +36 -0
  331. package/dist/core/sources/problems.js.map +1 -0
  332. package/dist/core/sources/redact.d.ts +2 -0
  333. package/dist/core/sources/redact.js +70 -0
  334. package/dist/core/sources/redact.js.map +1 -0
  335. package/dist/core/sources/resolve.d.ts +9 -0
  336. package/dist/core/sources/resolve.js +29 -0
  337. package/dist/core/sources/resolve.js.map +1 -0
  338. package/dist/core/sources/types.d.ts +86 -0
  339. package/dist/core/sources/types.js +2 -0
  340. package/dist/core/sources/types.js.map +1 -0
  341. package/dist/core/sources/validate.d.ts +9 -0
  342. package/dist/core/sources/validate.js +116 -0
  343. package/dist/core/sources/validate.js.map +1 -0
  344. package/dist/core/summary.d.ts +79 -0
  345. package/dist/core/summary.js +411 -0
  346. package/dist/core/summary.js.map +1 -0
  347. package/dist/core/update/clashes.d.ts +63 -0
  348. package/dist/core/update/clashes.js +192 -0
  349. package/dist/core/update/clashes.js.map +1 -0
  350. package/dist/core/update/detach.d.ts +21 -0
  351. package/dist/core/update/detach.js +38 -0
  352. package/dist/core/update/detach.js.map +1 -0
  353. package/dist/core/update/diff.d.ts +58 -0
  354. package/dist/core/update/diff.js +180 -0
  355. package/dist/core/update/diff.js.map +1 -0
  356. package/dist/core/update/fetch.d.ts +34 -0
  357. package/dist/core/update/fetch.js +73 -0
  358. package/dist/core/update/fetch.js.map +1 -0
  359. package/dist/core/update/index.d.ts +6 -0
  360. package/dist/core/update/index.js +7 -0
  361. package/dist/core/update/index.js.map +1 -0
  362. package/dist/core/update/restore.d.ts +20 -0
  363. package/dist/core/update/restore.js +195 -0
  364. package/dist/core/update/restore.js.map +1 -0
  365. package/dist/core/update/run.d.ts +113 -0
  366. package/dist/core/update/run.js +1135 -0
  367. package/dist/core/update/run.js.map +1 -0
  368. package/dist/core/update/select.d.ts +39 -0
  369. package/dist/core/update/select.js +157 -0
  370. package/dist/core/update/select.js.map +1 -0
  371. package/dist/core/update/spelling.d.ts +51 -0
  372. package/dist/core/update/spelling.js +185 -0
  373. package/dist/core/update/spelling.js.map +1 -0
  374. package/dist/core/update/trees.d.ts +24 -0
  375. package/dist/core/update/trees.js +72 -0
  376. package/dist/core/update/trees.js.map +1 -0
  377. package/dist/errors.d.ts +39 -0
  378. package/dist/errors.js +24 -0
  379. package/dist/errors.js.map +1 -0
  380. package/dist/help.d.ts +51 -0
  381. package/dist/help.js +117 -0
  382. package/dist/help.js.map +1 -0
  383. package/dist/input.d.ts +25 -0
  384. package/dist/input.js +174 -0
  385. package/dist/input.js.map +1 -0
  386. package/dist/output.d.ts +21 -0
  387. package/dist/output.js +37 -0
  388. package/dist/output.js.map +1 -0
  389. package/dist/util/frontmatter.d.ts +12 -0
  390. package/dist/util/frontmatter.js +58 -0
  391. package/dist/util/frontmatter.js.map +1 -0
  392. package/dist/util/fs.d.ts +38 -0
  393. package/dist/util/fs.js +135 -0
  394. package/dist/util/fs.js.map +1 -0
  395. package/dist/util/git-names.d.ts +8 -0
  396. package/dist/util/git-names.js +25 -0
  397. package/dist/util/git-names.js.map +1 -0
  398. package/dist/util/git.d.ts +12 -0
  399. package/dist/util/git.js +33 -0
  400. package/dist/util/git.js.map +1 -0
  401. package/dist/util/suggest.d.ts +6 -0
  402. package/dist/util/suggest.js +48 -0
  403. package/dist/util/suggest.js.map +1 -0
  404. package/dist/util/text.d.ts +8 -0
  405. package/dist/util/text.js +19 -0
  406. package/dist/util/text.js.map +1 -0
  407. package/dist/util/version.d.ts +7 -0
  408. package/dist/util/version.js +13 -0
  409. package/dist/util/version.js.map +1 -0
  410. package/dist/util/yaml.d.ts +30 -0
  411. package/dist/util/yaml.js +201 -0
  412. package/dist/util/yaml.js.map +1 -0
  413. package/package.json +51 -3
  414. package/resources/metafab-skill/SKILL.md +173 -0
@@ -0,0 +1,76 @@
1
+ import { lstat, mkdir, readlink, rm, symlink } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { copyFileWithMode, readdirTyped } from "../../util/fs.js";
4
+ /** Files the fab carries for its own repository, never for the receiver. */
5
+ export const FAB_ROOT_EXCLUDES = new Set(["metafab.yaml", "README.md"]);
6
+ async function lstatIfExists(target) {
7
+ try {
8
+ return await lstat(target);
9
+ }
10
+ catch (error) {
11
+ if (error.code === "ENOENT")
12
+ return undefined;
13
+ throw error;
14
+ }
15
+ }
16
+ async function ensureDirectory(target) {
17
+ const info = await lstatIfExists(target);
18
+ if (info !== undefined && !info.isDirectory()) {
19
+ await rm(target, { recursive: true, force: true });
20
+ }
21
+ await mkdir(target, { recursive: true });
22
+ }
23
+ /** Replaces whatever occupies `target` with a regular file copy. */
24
+ async function copyFile(source, target) {
25
+ const info = await lstatIfExists(target);
26
+ if (info !== undefined && !info.isFile()) {
27
+ await rm(target, { recursive: true, force: true });
28
+ }
29
+ await copyFileWithMode(source, target);
30
+ }
31
+ /** Replaces whatever occupies `target` with a symbolic link to `linkTarget`. */
32
+ async function copyLink(linkTarget, target) {
33
+ await rm(target, { recursive: true, force: true });
34
+ await symlink(linkTarget, target);
35
+ }
36
+ /**
37
+ * Copy a fetched fab's `.factory/` into the local `.factory/`, keeping modes.
38
+ *
39
+ * `metafab.yaml` and `.factory/README.md` belong to the fab's repository and are
40
+ * never copied. The source tree was validated by the fetch, so links point
41
+ * inside the factory and can be recreated as they are.
42
+ */
43
+ export async function copyFactoryTree(sourceDir, destinationDir) {
44
+ const copied = [];
45
+ async function walk(current, relative) {
46
+ const entries = await readdirTyped(current);
47
+ entries.sort((left, right) => (left.name < right.name ? -1 : left.name > right.name ? 1 : 0));
48
+ for (const entry of entries) {
49
+ if (relative === "" && FAB_ROOT_EXCLUDES.has(entry.name))
50
+ continue;
51
+ const source = path.join(current, entry.name);
52
+ const target = path.join(destinationDir, ...(relative === "" ? [entry.name] : [...relative.split("/"), entry.name]));
53
+ const childRelative = relative === "" ? entry.name : `${relative}/${entry.name}`;
54
+ if (entry.isSymbolicLink()) {
55
+ await ensureDirectory(path.dirname(target));
56
+ await copyLink(await readlink(source), target);
57
+ copied.push(childRelative);
58
+ continue;
59
+ }
60
+ if (entry.isDirectory()) {
61
+ await ensureDirectory(target);
62
+ await walk(source, childRelative);
63
+ continue;
64
+ }
65
+ if (!entry.isFile())
66
+ continue;
67
+ await ensureDirectory(path.dirname(target));
68
+ await copyFile(source, target);
69
+ copied.push(childRelative);
70
+ }
71
+ }
72
+ await ensureDirectory(destinationDir);
73
+ await walk(sourceDir, "");
74
+ return copied.sort();
75
+ }
76
+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@ -0,0 +1,43 @@
1
+ export interface FileEntry {
2
+ /** SHA-256 of the content: the LF-normalised bytes for text, the raw bytes for binary. */
3
+ hash: string;
4
+ /** Permission bits, so an executable bit counts as a change. */
5
+ mode: number;
6
+ binary: boolean;
7
+ /** Content when the file is text, with LF line endings. */
8
+ text?: string;
9
+ /** Content when the file is binary. */
10
+ data?: Uint8Array;
11
+ /** The target of a symbolic link, when the entry is a link rather than a file. */
12
+ link?: string;
13
+ /** True when the text uses CRLF on every line, so a write can keep it. */
14
+ crlf?: true;
15
+ /** The file's original bytes when they differ from the LF text, so a write can keep them. */
16
+ raw?: Buffer;
17
+ }
18
+ /** A snapshot of a factory directory: relative POSIX path to entry. */
19
+ export type FileTree = Readonly<Record<string, FileEntry>>;
20
+ export declare const LINK_HASH_PREFIX = "\0metafab-link\0";
21
+ /**
22
+ * Snapshot every file and symbolic link under `dir`, keyed by its POSIX path
23
+ * relative to `dir`.
24
+ *
25
+ * Text is stored with LF line endings and hashed that way, so a change of line
26
+ * endings alone is not a change. Content that is not valid UTF-8, and content
27
+ * with a NUL, are binary: stored and hashed as raw bytes. A link is stored with
28
+ * its target, so an added, removed, or repointed link is a change like any
29
+ * other.
30
+ */
31
+ export declare function snapshotTree(dir: string): Promise<FileTree>;
32
+ /** Snapshot the active factory, `.factory/` under `root`. */
33
+ export declare function snapshotFactory(root: string): Promise<FileTree>;
34
+ /**
35
+ * Every directory under `dir`, as POSIX paths relative to it, symbolic links
36
+ * not followed.
37
+ *
38
+ * A snapshot keeps no directories, so this is how a preflight finds a local
39
+ * directory that an incoming file or link would delete, empty or not.
40
+ */
41
+ export declare function snapshotDirectories(dir: string): Promise<string[]>;
42
+ /** A file tree with no entries: the state of a repository before its first import. */
43
+ export declare function emptyTree(): FileTree;
@@ -0,0 +1,107 @@
1
+ import { createHash } from "node:crypto";
2
+ import { lstat, readFile, readlink } from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { readdirTyped } from "../../util/fs.js";
5
+ import { toLF, usesCRLF } from "../../util/text.js";
6
+ import { textContent } from "../build/skill.js";
7
+ export const LINK_HASH_PREFIX = "\0metafab-link\0";
8
+ function hashOf(data) {
9
+ return createHash("sha256").update(data).digest("hex");
10
+ }
11
+ async function entryOf(target, link) {
12
+ if (link !== undefined) {
13
+ const info = await lstat(target);
14
+ // The prefix keeps a link's target from hashing like file content with the same bytes.
15
+ return {
16
+ hash: hashOf(`${LINK_HASH_PREFIX}${link}`),
17
+ mode: info.mode & 0o777,
18
+ binary: false,
19
+ link,
20
+ };
21
+ }
22
+ const [data, info] = await Promise.all([readFile(target), lstat(target)]);
23
+ const mode = info.mode & 0o777;
24
+ // Decoding keeps a valid UTF-8 file as text. Anything else stays raw bytes:
25
+ // re-encoding a lossy decode would corrupt the file, and two different invalid
26
+ // sequences would decode to the same replacement characters.
27
+ const decoded = textContent(data);
28
+ if (decoded === undefined) {
29
+ return { hash: hashOf(data), mode, binary: true, data };
30
+ }
31
+ const text = toLF(decoded);
32
+ const entry = { hash: hashOf(text), mode, binary: false, text };
33
+ // Keep the original bytes only when normalising changed them, which is a
34
+ // CRLF or mixed-ending file, so a write can reproduce the file as it was.
35
+ if (text !== decoded)
36
+ entry.raw = data;
37
+ if (usesCRLF(decoded))
38
+ entry.crlf = true;
39
+ return entry;
40
+ }
41
+ /**
42
+ * Snapshot every file and symbolic link under `dir`, keyed by its POSIX path
43
+ * relative to `dir`.
44
+ *
45
+ * Text is stored with LF line endings and hashed that way, so a change of line
46
+ * endings alone is not a change. Content that is not valid UTF-8, and content
47
+ * with a NUL, are binary: stored and hashed as raw bytes. A link is stored with
48
+ * its target, so an added, removed, or repointed link is a change like any
49
+ * other.
50
+ */
51
+ export async function snapshotTree(dir) {
52
+ const root = path.resolve(dir);
53
+ const entries = {};
54
+ async function walk(directory, prefix) {
55
+ const children = await readdirTyped(directory);
56
+ children.sort((left, right) => (left.name < right.name ? -1 : left.name > right.name ? 1 : 0));
57
+ for (const child of children) {
58
+ const relativePath = prefix === "" ? child.name : `${prefix}/${child.name}`;
59
+ const target = path.join(directory, child.name);
60
+ if (child.isSymbolicLink()) {
61
+ entries[relativePath] = await entryOf(target, await readlink(target));
62
+ }
63
+ else if (child.isDirectory()) {
64
+ await walk(target, relativePath);
65
+ }
66
+ else if (child.isFile()) {
67
+ entries[relativePath] = await entryOf(target, undefined);
68
+ }
69
+ }
70
+ }
71
+ await walk(root, "");
72
+ return entries;
73
+ }
74
+ /** Snapshot the active factory, `.factory/` under `root`. */
75
+ export async function snapshotFactory(root) {
76
+ return snapshotTree(path.join(path.resolve(root), ".factory"));
77
+ }
78
+ /**
79
+ * Every directory under `dir`, as POSIX paths relative to it, symbolic links
80
+ * not followed.
81
+ *
82
+ * A snapshot keeps no directories, so this is how a preflight finds a local
83
+ * directory that an incoming file or link would delete, empty or not.
84
+ */
85
+ export async function snapshotDirectories(dir) {
86
+ const root = path.resolve(dir);
87
+ const directories = [];
88
+ async function walk(directory, prefix) {
89
+ const children = await readdirTyped(directory);
90
+ children.sort((left, right) => (left.name < right.name ? -1 : left.name > right.name ? 1 : 0));
91
+ for (const child of children) {
92
+ // A symbolic link is not a directory here: the snapshot treats it as a link.
93
+ if (!child.isDirectory())
94
+ continue;
95
+ const relativePath = prefix === "" ? child.name : `${prefix}/${child.name}`;
96
+ directories.push(relativePath);
97
+ await walk(path.join(directory, child.name), relativePath);
98
+ }
99
+ }
100
+ await walk(root, "");
101
+ return directories;
102
+ }
103
+ /** A file tree with no entries: the state of a repository before its first import. */
104
+ export function emptyTree() {
105
+ return {};
106
+ }
107
+ //# sourceMappingURL=file-tree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-tree.js","sourceRoot":"","sources":["../../../src/core/import/file-tree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,IAAI,MAAM,WAAW,CA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AI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAE/F,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;YAC7B,6EAA6E;YAC7E,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE;gBAAE,SAAS;YACnC,MAAM,YAAY,GAAG,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;YAC5E,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YAC/B,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,YAAY,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;IAED,MAAM,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACrB,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,SAAS;IACvB,OAAO,EAAE,CAAC;AACZ,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from "./file-tree.js";
2
+ export * from "./pipeline-changes.js";
3
+ export * from "./copy.js";
4
+ export * from "./conflicts.js";
5
+ export * from "./run.js";
@@ -0,0 +1,6 @@
1
+ export * from "./file-tree.js";
2
+ export * from "./pipeline-changes.js";
3
+ export * from "./copy.js";
4
+ export * from "./conflicts.js";
5
+ export * from "./run.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/import/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Describe changes to the `pipeline` list of `factory.yaml` in words, such as
3
+ * `pipeline: finish-slice added after review-slice`.
4
+ *
5
+ * Returns no descriptions when either side cannot be parsed, or when the
6
+ * pipeline did not change; the caller then falls back to line counts.
7
+ */
8
+ export declare function describePipelineChanges(before: string | undefined, after: string | undefined): string[];
@@ -0,0 +1,89 @@
1
+ import { parseFactoryYaml } from "../factory/index.js";
2
+ function pipelineOf(text) {
3
+ if (text === undefined)
4
+ return { names: [], stops: new Map() };
5
+ const parsed = parseFactoryYaml(text, "factory.yaml");
6
+ if (parsed.problems.length > 0)
7
+ return undefined;
8
+ const snapshot = { names: [], stops: new Map() };
9
+ for (const entry of parsed.pipeline ?? []) {
10
+ snapshot.names.push(entry.workflow);
11
+ snapshot.stops.set(entry.workflow, entry.stop);
12
+ }
13
+ return snapshot;
14
+ }
15
+ function at(grid, row, column) {
16
+ return grid[row]?.[column] ?? 0;
17
+ }
18
+ /** Indices in `after` of one longest common subsequence of the two name lists. */
19
+ function lcsIndices(before, after) {
20
+ const rows = before.length;
21
+ const columns = after.length;
22
+ const grid = Array.from({ length: rows + 1 }, () => new Array(columns + 1).fill(0));
23
+ for (let row = rows - 1; row >= 0; row -= 1) {
24
+ for (let column = columns - 1; column >= 0; column -= 1) {
25
+ grid[row][column] =
26
+ before[row] === after[column]
27
+ ? at(grid, row + 1, column + 1) + 1
28
+ : Math.max(at(grid, row + 1, column), at(grid, row, column + 1));
29
+ }
30
+ }
31
+ const kept = new Set();
32
+ let row = 0;
33
+ let column = 0;
34
+ while (row < rows && column < columns) {
35
+ if (before[row] === after[column]) {
36
+ kept.add(column);
37
+ row += 1;
38
+ column += 1;
39
+ }
40
+ else if (at(grid, row + 1, column) >= at(grid, row, column + 1)) {
41
+ row += 1;
42
+ }
43
+ else {
44
+ column += 1;
45
+ }
46
+ }
47
+ return kept;
48
+ }
49
+ function positionIn(names, index) {
50
+ const previous = index === 0 ? undefined : names[index - 1];
51
+ return previous === undefined ? "at the start" : `after ${previous}`;
52
+ }
53
+ /**
54
+ * Describe changes to the `pipeline` list of `factory.yaml` in words, such as
55
+ * `pipeline: finish-slice added after review-slice`.
56
+ *
57
+ * Returns no descriptions when either side cannot be parsed, or when the
58
+ * pipeline did not change; the caller then falls back to line counts.
59
+ */
60
+ export function describePipelineChanges(before, after) {
61
+ const previous = pipelineOf(before);
62
+ const next = pipelineOf(after);
63
+ if (previous === undefined || next === undefined)
64
+ return [];
65
+ const beforeNames = new Set(previous.names);
66
+ const afterNames = new Set(next.names);
67
+ const kept = lcsIndices(previous.names, next.names);
68
+ const descriptions = [];
69
+ next.names.forEach((name, index) => {
70
+ const position = positionIn(next.names, index);
71
+ if (!beforeNames.has(name)) {
72
+ descriptions.push(`pipeline: ${name} added ${position}`);
73
+ return;
74
+ }
75
+ if (!kept.has(index)) {
76
+ descriptions.push(index === 0 ? `pipeline: ${name} moved to the start` : `pipeline: ${name} moved ${position}`);
77
+ return;
78
+ }
79
+ if (previous.stops.get(name) !== next.stops.get(name)) {
80
+ descriptions.push(`pipeline: ${name} stop changed`);
81
+ }
82
+ });
83
+ for (const name of previous.names) {
84
+ if (!afterNames.has(name))
85
+ descriptions.push(`pipeline: ${name} removed`);
86
+ }
87
+ return descriptions;
88
+ }
89
+ //# sourceMappingURL=pipeline-changes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipeline-changes.js","sourceRoot":"","sources":["../../../src/core/import/pipeline-changes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAOvD,SAAS,UAAU,CAAC,IAAwB;IAC1C,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC;IAC/D,MAAM,MAAM,GAAG,gBAAgB,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;IACtD,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC;IACjD,MAAM,QAAQ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C,IAAI,CAAC,aAAa,IAAI,eAAe,CAAC,CAAC;QACtD,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,KAAK,MAAM,IAAI,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC;QAClC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,YAAY,CAAC,IAAI,CAAC,aAAa,IAAI,UAAU,CAAC,CAAC;IAC5E,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC"}
@@ -0,0 +1,76 @@
1
+ import type { Problem } from "../../errors.js";
2
+ import type { InputIO } from "../../input.js";
3
+ import type { AdoptionMove } from "../adopt.js";
4
+ import type { BuildChange } from "../build/index.js";
5
+ import type { UpstreamEntry } from "../config/types.js";
6
+ import type { HookChange } from "../hooks/index.js";
7
+ import type { TargetPrompt } from "../init/targets.js";
8
+ import type { RequirementResult } from "../requires/inspect.js";
9
+ import type { SourceOptions } from "../sources/index.js";
10
+ import type { Summary } from "../summary.js";
11
+ export interface ImportOptions {
12
+ /** Directory that contains, or will contain, `.factory/`. */
13
+ root: string;
14
+ /** The source exactly as the user typed it. */
15
+ source: string;
16
+ /** Directory relative paths resolve against; the process cwd by default. */
17
+ cwd?: string;
18
+ /** Raw `--agents` value. */
19
+ agents?: string;
20
+ /** Replace differing local files instead of stopping. */
21
+ force?: boolean;
22
+ /** Consent to adopt existing repository skills without asking. */
23
+ adopt?: boolean;
24
+ /** Create the missing required files: `true` for `--setup`, `false` for `--no-setup`. */
25
+ setup?: boolean;
26
+ /** Injected input and output; production uses the process streams. */
27
+ io?: InputIO;
28
+ /** Injected agent-target prompt, so tests do not need a terminal. */
29
+ prompt?: TargetPrompt;
30
+ /** Let Git prompt for credentials; the command enables it for a TTY. */
31
+ interactive?: boolean;
32
+ /** Injected source settings, used by tests for a local registry or transport. */
33
+ sourceOptions?: SourceOptions;
34
+ /**
35
+ * @internal Test seam: runs after the setup consent and before the agreed
36
+ * files are created, so a test can make one appear in between.
37
+ */
38
+ beforeCreate?: () => Promise<void>;
39
+ }
40
+ export interface ImportReport {
41
+ root: string;
42
+ upstream: UpstreamEntry;
43
+ /** Files created before the copy, such as `metafab.yaml` and `.gitattributes`. */
44
+ created: string[];
45
+ /** Existing files changed before the copy. */
46
+ updated: string[];
47
+ /** `.gitattributes` lines added. */
48
+ gitattributes: string[];
49
+ /** Skills moved from a destination into `.factory/skills/`. */
50
+ moved: AdoptionMove[];
51
+ /** The repository files the factory requires, in `factory.yaml` order. */
52
+ requires: RequirementResult[];
53
+ /** Fab paths copied into `.factory/`. */
54
+ copied: string[];
55
+ /** Files created, updated, or removed by the closing build. */
56
+ changed: BuildChange[];
57
+ /** Git hooks created, updated, or removed by the closing build. */
58
+ hooks: HookChange[];
59
+ /** Build warnings. */
60
+ problems: Problem[];
61
+ /** The review summary, also rendered as the command's human output. */
62
+ review: Summary;
63
+ /** True when the adoption question was answered with no. */
64
+ declined: boolean;
65
+ }
66
+ /**
67
+ * Runs `metafab import`: resolve and fetch the source, check it against the
68
+ * repository without writing, collect adoption consent, then create the local
69
+ * configuration, adopt skills, copy the fab, record the upstream and build.
70
+ *
71
+ * Nothing is written before the preflight and consent are complete. A temporary
72
+ * fetch directory is removed whatever way the command ends.
73
+ */
74
+ export declare function runImport(options: ImportOptions): Promise<ImportReport>;
75
+ /** Human-readable report for `import`: the review summary, or the declined notice. */
76
+ export declare function describeImport(report: ImportReport): string;