@seasb/metafab 0.0.0-stage → 1.0.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 (369) hide show
  1. package/README.md +47 -2
  2. package/dist/cli.d.ts +11 -0
  3. package/dist/cli.js +317 -0
  4. package/dist/cli.js.map +1 -0
  5. package/dist/commands/build.d.ts +2 -0
  6. package/dist/commands/build.js +70 -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 +41 -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 +74 -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/import.d.ts +2 -0
  21. package/dist/commands/import.js +107 -0
  22. package/dist/commands/import.js.map +1 -0
  23. package/dist/commands/init.d.ts +2 -0
  24. package/dist/commands/init.js +77 -0
  25. package/dist/commands/init.js.map +1 -0
  26. package/dist/commands/map.d.ts +2 -0
  27. package/dist/commands/map.js +43 -0
  28. package/dist/commands/map.js.map +1 -0
  29. package/dist/commands/not-implemented.d.ts +2 -0
  30. package/dist/commands/not-implemented.js +19 -0
  31. package/dist/commands/not-implemented.js.map +1 -0
  32. package/dist/commands/pipeline-add.d.ts +2 -0
  33. package/dist/commands/pipeline-add.js +67 -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 +44 -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 +147 -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 +23 -0
  51. package/dist/core/build/agents.js +60 -0
  52. package/dist/core/build/agents.js.map +1 -0
  53. package/dist/core/build/index.d.ts +4 -0
  54. package/dist/core/build/index.js +5 -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 +48 -0
  60. package/dist/core/build/plan.js +792 -0
  61. package/dist/core/build/plan.js.map +1 -0
  62. package/dist/core/build/skill.d.ts +60 -0
  63. package/dist/core/build/skill.js +275 -0
  64. package/dist/core/build/skill.js.map +1 -0
  65. package/dist/core/check/drift.d.ts +13 -0
  66. package/dist/core/check/drift.js +205 -0
  67. package/dist/core/check/drift.js.map +1 -0
  68. package/dist/core/check/index.d.ts +12 -0
  69. package/dist/core/check/index.js +78 -0
  70. package/dist/core/check/index.js.map +1 -0
  71. package/dist/core/check/markers.d.ts +9 -0
  72. package/dist/core/check/markers.js +220 -0
  73. package/dist/core/check/markers.js.map +1 -0
  74. package/dist/core/config/destinations.d.ts +5 -0
  75. package/dist/core/config/destinations.js +20 -0
  76. package/dist/core/config/destinations.js.map +1 -0
  77. package/dist/core/config/load.d.ts +4 -0
  78. package/dist/core/config/load.js +41 -0
  79. package/dist/core/config/load.js.map +1 -0
  80. package/dist/core/config/parse.d.ts +8 -0
  81. package/dist/core/config/parse.js +198 -0
  82. package/dist/core/config/parse.js.map +1 -0
  83. package/dist/core/config/source.d.ts +14 -0
  84. package/dist/core/config/source.js +44 -0
  85. package/dist/core/config/source.js.map +1 -0
  86. package/dist/core/config/types.d.ts +48 -0
  87. package/dist/core/config/types.js +2 -0
  88. package/dist/core/config/types.js.map +1 -0
  89. package/dist/core/config/validate.d.ts +11 -0
  90. package/dist/core/config/validate.js +351 -0
  91. package/dist/core/config/validate.js.map +1 -0
  92. package/dist/core/config/writers.d.ts +14 -0
  93. package/dist/core/config/writers.js +261 -0
  94. package/dist/core/config/writers.js.map +1 -0
  95. package/dist/core/config.d.ts +7 -0
  96. package/dist/core/config.js +8 -0
  97. package/dist/core/config.js.map +1 -0
  98. package/dist/core/discovery.d.ts +34 -0
  99. package/dist/core/discovery.js +272 -0
  100. package/dist/core/discovery.js.map +1 -0
  101. package/dist/core/edit/create.d.ts +18 -0
  102. package/dist/core/edit/create.js +190 -0
  103. package/dist/core/edit/create.js.map +1 -0
  104. package/dist/core/edit/document.d.ts +4 -0
  105. package/dist/core/edit/document.js +16 -0
  106. package/dist/core/edit/document.js.map +1 -0
  107. package/dist/core/edit/factory-yaml.d.ts +17 -0
  108. package/dist/core/edit/factory-yaml.js +211 -0
  109. package/dist/core/edit/factory-yaml.js.map +1 -0
  110. package/dist/core/edit/files.d.ts +6 -0
  111. package/dist/core/edit/files.js +47 -0
  112. package/dist/core/edit/files.js.map +1 -0
  113. package/dist/core/edit/index.d.ts +9 -0
  114. package/dist/core/edit/index.js +10 -0
  115. package/dist/core/edit/index.js.map +1 -0
  116. package/dist/core/edit/map.d.ts +24 -0
  117. package/dist/core/edit/map.js +82 -0
  118. package/dist/core/edit/map.js.map +1 -0
  119. package/dist/core/edit/names.d.ts +2 -0
  120. package/dist/core/edit/names.js +17 -0
  121. package/dist/core/edit/names.js.map +1 -0
  122. package/dist/core/edit/paths.d.ts +8 -0
  123. package/dist/core/edit/paths.js +76 -0
  124. package/dist/core/edit/paths.js.map +1 -0
  125. package/dist/core/edit/pipeline.d.ts +19 -0
  126. package/dist/core/edit/pipeline.js +146 -0
  127. package/dist/core/edit/pipeline.js.map +1 -0
  128. package/dist/core/edit/skill.d.ts +1 -0
  129. package/dist/core/edit/skill.js +10 -0
  130. package/dist/core/edit/skill.js.map +1 -0
  131. package/dist/core/factory/discovery.d.ts +9 -0
  132. package/dist/core/factory/discovery.js +139 -0
  133. package/dist/core/factory/discovery.js.map +1 -0
  134. package/dist/core/factory/factory-yaml.d.ts +16 -0
  135. package/dist/core/factory/factory-yaml.js +375 -0
  136. package/dist/core/factory/factory-yaml.js.map +1 -0
  137. package/dist/core/factory/index.d.ts +5 -0
  138. package/dist/core/factory/index.js +6 -0
  139. package/dist/core/factory/index.js.map +1 -0
  140. package/dist/core/factory/lines.d.ts +8 -0
  141. package/dist/core/factory/lines.js +11 -0
  142. package/dist/core/factory/lines.js.map +1 -0
  143. package/dist/core/factory/load.d.ts +4 -0
  144. package/dist/core/factory/load.js +81 -0
  145. package/dist/core/factory/load.js.map +1 -0
  146. package/dist/core/factory/requires.d.ts +9 -0
  147. package/dist/core/factory/requires.js +123 -0
  148. package/dist/core/factory/requires.js.map +1 -0
  149. package/dist/core/factory/types.d.ts +45 -0
  150. package/dist/core/factory/types.js +2 -0
  151. package/dist/core/factory/types.js.map +1 -0
  152. package/dist/core/factory/validate.d.ts +41 -0
  153. package/dist/core/factory/validate.js +441 -0
  154. package/dist/core/factory/validate.js.map +1 -0
  155. package/dist/core/hooks/index.d.ts +8 -0
  156. package/dist/core/hooks/index.js +15 -0
  157. package/dist/core/hooks/index.js.map +1 -0
  158. package/dist/core/hooks/script.d.ts +21 -0
  159. package/dist/core/hooks/script.js +34 -0
  160. package/dist/core/hooks/script.js.map +1 -0
  161. package/dist/core/hooks/sync.d.ts +17 -0
  162. package/dist/core/hooks/sync.js +262 -0
  163. package/dist/core/hooks/sync.js.map +1 -0
  164. package/dist/core/import/conflicts.d.ts +82 -0
  165. package/dist/core/import/conflicts.js +256 -0
  166. package/dist/core/import/conflicts.js.map +1 -0
  167. package/dist/core/import/copy.d.ts +10 -0
  168. package/dist/core/import/copy.js +76 -0
  169. package/dist/core/import/copy.js.map +1 -0
  170. package/dist/core/import/file-tree.d.ts +43 -0
  171. package/dist/core/import/file-tree.js +107 -0
  172. package/dist/core/import/file-tree.js.map +1 -0
  173. package/dist/core/import/index.d.ts +5 -0
  174. package/dist/core/import/index.js +6 -0
  175. package/dist/core/import/index.js.map +1 -0
  176. package/dist/core/import/pipeline-changes.d.ts +8 -0
  177. package/dist/core/import/pipeline-changes.js +89 -0
  178. package/dist/core/import/pipeline-changes.js.map +1 -0
  179. package/dist/core/import/run.d.ts +76 -0
  180. package/dist/core/import/run.js +258 -0
  181. package/dist/core/import/run.js.map +1 -0
  182. package/dist/core/init/gitattributes.d.ts +20 -0
  183. package/dist/core/init/gitattributes.js +89 -0
  184. package/dist/core/init/gitattributes.js.map +1 -0
  185. package/dist/core/init/index.d.ts +4 -0
  186. package/dist/core/init/index.js +5 -0
  187. package/dist/core/init/index.js.map +1 -0
  188. package/dist/core/init/name.d.ts +1 -0
  189. package/dist/core/init/name.js +4 -0
  190. package/dist/core/init/name.js.map +1 -0
  191. package/dist/core/init/run.d.ts +51 -0
  192. package/dist/core/init/run.js +261 -0
  193. package/dist/core/init/run.js.map +1 -0
  194. package/dist/core/init/targets.d.ts +17 -0
  195. package/dist/core/init/targets.js +87 -0
  196. package/dist/core/init/targets.js.map +1 -0
  197. package/dist/core/merge.d.ts +88 -0
  198. package/dist/core/merge.js +239 -0
  199. package/dist/core/merge.js.map +1 -0
  200. package/dist/core/publish/exclude.d.ts +9 -0
  201. package/dist/core/publish/exclude.js +32 -0
  202. package/dist/core/publish/exclude.js.map +1 -0
  203. package/dist/core/publish/git-target.d.ts +32 -0
  204. package/dist/core/publish/git-target.js +447 -0
  205. package/dist/core/publish/git-target.js.map +1 -0
  206. package/dist/core/publish/index.d.ts +10 -0
  207. package/dist/core/publish/index.js +11 -0
  208. package/dist/core/publish/index.js.map +1 -0
  209. package/dist/core/publish/npm-target.d.ts +15 -0
  210. package/dist/core/publish/npm-target.js +170 -0
  211. package/dist/core/publish/npm-target.js.map +1 -0
  212. package/dist/core/publish/package-json.d.ts +31 -0
  213. package/dist/core/publish/package-json.js +74 -0
  214. package/dist/core/publish/package-json.js.map +1 -0
  215. package/dist/core/publish/prepare.d.ts +24 -0
  216. package/dist/core/publish/prepare.js +93 -0
  217. package/dist/core/publish/prepare.js.map +1 -0
  218. package/dist/core/publish/provenance.d.ts +1 -0
  219. package/dist/core/publish/provenance.js +20 -0
  220. package/dist/core/publish/provenance.js.map +1 -0
  221. package/dist/core/publish/publish.d.ts +13 -0
  222. package/dist/core/publish/publish.js +130 -0
  223. package/dist/core/publish/publish.js.map +1 -0
  224. package/dist/core/publish/readme.d.ts +22 -0
  225. package/dist/core/publish/readme.js +112 -0
  226. package/dist/core/publish/readme.js.map +1 -0
  227. package/dist/core/publish/stage.d.ts +19 -0
  228. package/dist/core/publish/stage.js +333 -0
  229. package/dist/core/publish/stage.js.map +1 -0
  230. package/dist/core/publish/types.d.ts +71 -0
  231. package/dist/core/publish/types.js +2 -0
  232. package/dist/core/publish/types.js.map +1 -0
  233. package/dist/core/requires/check.d.ts +15 -0
  234. package/dist/core/requires/check.js +83 -0
  235. package/dist/core/requires/check.js.map +1 -0
  236. package/dist/core/requires/index.d.ts +4 -0
  237. package/dist/core/requires/index.js +5 -0
  238. package/dist/core/requires/index.js.map +1 -0
  239. package/dist/core/requires/inspect.d.ts +44 -0
  240. package/dist/core/requires/inspect.js +114 -0
  241. package/dist/core/requires/inspect.js.map +1 -0
  242. package/dist/core/requires/paths.d.ts +29 -0
  243. package/dist/core/requires/paths.js +83 -0
  244. package/dist/core/requires/paths.js.map +1 -0
  245. package/dist/core/requires/setup.d.ts +37 -0
  246. package/dist/core/requires/setup.js +147 -0
  247. package/dist/core/requires/setup.js.map +1 -0
  248. package/dist/core/setup.d.ts +27 -0
  249. package/dist/core/setup.js +84 -0
  250. package/dist/core/setup.js.map +1 -0
  251. package/dist/core/sources/cache.d.ts +38 -0
  252. package/dist/core/sources/cache.js +200 -0
  253. package/dist/core/sources/cache.js.map +1 -0
  254. package/dist/core/sources/containment.d.ts +21 -0
  255. package/dist/core/sources/containment.js +50 -0
  256. package/dist/core/sources/containment.js.map +1 -0
  257. package/dist/core/sources/env.d.ts +12 -0
  258. package/dist/core/sources/env.js +28 -0
  259. package/dist/core/sources/env.js.map +1 -0
  260. package/dist/core/sources/extract.d.ts +25 -0
  261. package/dist/core/sources/extract.js +676 -0
  262. package/dist/core/sources/extract.js.map +1 -0
  263. package/dist/core/sources/git-process.d.ts +26 -0
  264. package/dist/core/sources/git-process.js +51 -0
  265. package/dist/core/sources/git-process.js.map +1 -0
  266. package/dist/core/sources/git.d.ts +41 -0
  267. package/dist/core/sources/git.js +511 -0
  268. package/dist/core/sources/git.js.map +1 -0
  269. package/dist/core/sources/https.d.ts +21 -0
  270. package/dist/core/sources/https.js +208 -0
  271. package/dist/core/sources/https.js.map +1 -0
  272. package/dist/core/sources/index.d.ts +13 -0
  273. package/dist/core/sources/index.js +14 -0
  274. package/dist/core/sources/index.js.map +1 -0
  275. package/dist/core/sources/npm-cli.d.ts +19 -0
  276. package/dist/core/sources/npm-cli.js +43 -0
  277. package/dist/core/sources/npm-cli.js.map +1 -0
  278. package/dist/core/sources/npm.d.ts +29 -0
  279. package/dist/core/sources/npm.js +386 -0
  280. package/dist/core/sources/npm.js.map +1 -0
  281. package/dist/core/sources/parse.d.ts +32 -0
  282. package/dist/core/sources/parse.js +389 -0
  283. package/dist/core/sources/parse.js.map +1 -0
  284. package/dist/core/sources/path.d.ts +10 -0
  285. package/dist/core/sources/path.js +316 -0
  286. package/dist/core/sources/path.js.map +1 -0
  287. package/dist/core/sources/redact.d.ts +2 -0
  288. package/dist/core/sources/redact.js +70 -0
  289. package/dist/core/sources/redact.js.map +1 -0
  290. package/dist/core/sources/resolve.d.ts +9 -0
  291. package/dist/core/sources/resolve.js +29 -0
  292. package/dist/core/sources/resolve.js.map +1 -0
  293. package/dist/core/sources/types.d.ts +86 -0
  294. package/dist/core/sources/types.js +2 -0
  295. package/dist/core/sources/types.js.map +1 -0
  296. package/dist/core/sources/validate.d.ts +9 -0
  297. package/dist/core/sources/validate.js +111 -0
  298. package/dist/core/sources/validate.js.map +1 -0
  299. package/dist/core/summary.d.ts +77 -0
  300. package/dist/core/summary.js +405 -0
  301. package/dist/core/summary.js.map +1 -0
  302. package/dist/core/update/clashes.d.ts +63 -0
  303. package/dist/core/update/clashes.js +192 -0
  304. package/dist/core/update/clashes.js.map +1 -0
  305. package/dist/core/update/detach.d.ts +21 -0
  306. package/dist/core/update/detach.js +38 -0
  307. package/dist/core/update/detach.js.map +1 -0
  308. package/dist/core/update/diff.d.ts +58 -0
  309. package/dist/core/update/diff.js +180 -0
  310. package/dist/core/update/diff.js.map +1 -0
  311. package/dist/core/update/fetch.d.ts +34 -0
  312. package/dist/core/update/fetch.js +73 -0
  313. package/dist/core/update/fetch.js.map +1 -0
  314. package/dist/core/update/index.d.ts +6 -0
  315. package/dist/core/update/index.js +7 -0
  316. package/dist/core/update/index.js.map +1 -0
  317. package/dist/core/update/restore.d.ts +20 -0
  318. package/dist/core/update/restore.js +195 -0
  319. package/dist/core/update/restore.js.map +1 -0
  320. package/dist/core/update/run.d.ts +113 -0
  321. package/dist/core/update/run.js +1132 -0
  322. package/dist/core/update/run.js.map +1 -0
  323. package/dist/core/update/select.d.ts +39 -0
  324. package/dist/core/update/select.js +157 -0
  325. package/dist/core/update/select.js.map +1 -0
  326. package/dist/core/update/spelling.d.ts +51 -0
  327. package/dist/core/update/spelling.js +185 -0
  328. package/dist/core/update/spelling.js.map +1 -0
  329. package/dist/core/update/trees.d.ts +24 -0
  330. package/dist/core/update/trees.js +72 -0
  331. package/dist/core/update/trees.js.map +1 -0
  332. package/dist/errors.d.ts +29 -0
  333. package/dist/errors.js +24 -0
  334. package/dist/errors.js.map +1 -0
  335. package/dist/help.d.ts +46 -0
  336. package/dist/help.js +103 -0
  337. package/dist/help.js.map +1 -0
  338. package/dist/input.d.ts +25 -0
  339. package/dist/input.js +173 -0
  340. package/dist/input.js.map +1 -0
  341. package/dist/output.d.ts +21 -0
  342. package/dist/output.js +37 -0
  343. package/dist/output.js.map +1 -0
  344. package/dist/util/frontmatter.d.ts +12 -0
  345. package/dist/util/frontmatter.js +58 -0
  346. package/dist/util/frontmatter.js.map +1 -0
  347. package/dist/util/fs.d.ts +32 -0
  348. package/dist/util/fs.js +126 -0
  349. package/dist/util/fs.js.map +1 -0
  350. package/dist/util/git-names.d.ts +8 -0
  351. package/dist/util/git-names.js +25 -0
  352. package/dist/util/git-names.js.map +1 -0
  353. package/dist/util/git.d.ts +12 -0
  354. package/dist/util/git.js +33 -0
  355. package/dist/util/git.js.map +1 -0
  356. package/dist/util/suggest.d.ts +6 -0
  357. package/dist/util/suggest.js +48 -0
  358. package/dist/util/suggest.js.map +1 -0
  359. package/dist/util/text.d.ts +8 -0
  360. package/dist/util/text.js +19 -0
  361. package/dist/util/text.js.map +1 -0
  362. package/dist/util/version.d.ts +7 -0
  363. package/dist/util/version.js +13 -0
  364. package/dist/util/version.js.map +1 -0
  365. package/dist/util/yaml.d.ts +30 -0
  366. package/dist/util/yaml.js +201 -0
  367. package/dist/util/yaml.js.map +1 -0
  368. package/package.json +51 -4
  369. package/resources/metafab-skill/SKILL.md +99 -0
@@ -0,0 +1,83 @@
1
+ import { requirementTemplateProblems } from "../factory/requires.js";
2
+ import { inspectRequirement } from "./inspect.js";
3
+ import { requirementPathProblem } from "./paths.js";
4
+ /** The prefix of the required path that a case-variant clash stands in for. */
5
+ function expectedSpelling(requiredPath, clash) {
6
+ const segments = clash.split("/").length;
7
+ return requiredPath.split("/").slice(0, segments).join("/");
8
+ }
9
+ /**
10
+ * Whether renaming the clashing entry gives the required path what it needs: a
11
+ * directory at a parent can become the parent, and any entry that is not a
12
+ * directory at the path itself can become the file, because a link (even a
13
+ * dangling one), a socket and a FIFO count as present. Renaming anything else
14
+ * leaves the path blocked (a file at a parent, a directory at the path), so the
15
+ * fix says to move it.
16
+ */
17
+ function renameHelps(requiredPath, clash, kind) {
18
+ if (kind === undefined)
19
+ return false;
20
+ const atPath = clash.split("/").length === requiredPath.split("/").length;
21
+ return atPath ? kind !== "directory" : kind === "directory";
22
+ }
23
+ /**
24
+ * Warnings for the repository files a factory requires. A missing file is the
25
+ * person's to create, and an entry in the way is theirs to move, so neither is
26
+ * an error: the factory itself is valid, and a repository may choose not to
27
+ * create a file. A present file says nothing, with or without a template;
28
+ * whether it holds what the fab needs is the person's call.
29
+ *
30
+ * An entry that rule 12 or 13 already rejected is skipped: rule 12's path
31
+ * shape, rule 12's uniqueness and nesting (the later repeat or nested entry),
32
+ * and rule 13's template checks are errors with their own fix, and a warning
33
+ * telling the person to create the file would contradict them.
34
+ */
35
+ export async function requirementWarnings(factory) {
36
+ const problems = [];
37
+ const seen = [];
38
+ for (const requirement of factory.factoryYaml?.requires ?? []) {
39
+ const folded = requirement.path.toLowerCase();
40
+ const rejectedByUniqueness = seen.some((other) => folded === other || folded.startsWith(`${other}/`) || other.startsWith(`${folded}/`));
41
+ seen.push(folded);
42
+ if (requirementPathProblem(requirement.path) !== undefined)
43
+ continue;
44
+ if (rejectedByUniqueness)
45
+ continue;
46
+ if (requirement.template !== undefined) {
47
+ const templateProblems = await requirementTemplateProblems(factory, [requirement], ".factory/factory.yaml");
48
+ if (templateProblems.length > 0)
49
+ continue;
50
+ }
51
+ const result = await inspectRequirement(factory.root, requirement);
52
+ if (result.state === "missing") {
53
+ problems.push({
54
+ level: "warning",
55
+ file: ".factory/factory.yaml",
56
+ line: requirement.line,
57
+ message: `Required file ${requirement.path} is missing: ${requirement.description}`,
58
+ fix: requirement.template === undefined
59
+ ? `Create ${requirement.path}`
60
+ : `Copy ${requirement.template} to ${requirement.path}`,
61
+ });
62
+ continue;
63
+ }
64
+ if (result.state !== "blocked" || result.clash === undefined)
65
+ continue;
66
+ const reason = result.reason ?? "";
67
+ const caseVariant = reason.endsWith("differs only in letter case");
68
+ const canRename = caseVariant && renameHelps(requirement.path, result.clash, result.clashKind);
69
+ problems.push({
70
+ level: "warning",
71
+ file: ".factory/factory.yaml",
72
+ line: requirement.line,
73
+ message: `Required file ${requirement.path} cannot be created: ${reason}`,
74
+ fix: reason.startsWith("Cannot read ")
75
+ ? `Check the permissions of ${result.clash}, then run metafab check again`
76
+ : canRename
77
+ ? `Rename ${result.clash} to match ${expectedSpelling(requirement.path, result.clash)}, or move it away, then create ${requirement.path}`
78
+ : `Move ${result.clash} away, then create ${requirement.path}`,
79
+ });
80
+ }
81
+ return problems;
82
+ }
83
+ //# sourceMappingURL=check.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check.js","sourceRoot":"","sources":["../../../src/core/requires/check.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEpD,+EAA+E;AAC/E,SAAS,gBAAgB,CAAC,YAAoB,EAAE,KAAa;IAC3D,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,OAAO,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,WAAW,CAClB,YAAoB,EACpB,KAAa,EACb,IAAsC;IAEtC,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IACrC,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1E,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC;AAC9D,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* from "./inspect.js";
3
+ export * from "./setup.js";
4
+ export * from "./check.js";
@@ -0,0 +1,5 @@
1
+ export * from "./paths.js";
2
+ export * from "./inspect.js";
3
+ export * from "./setup.js";
4
+ export * from "./check.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/requires/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,44 @@
1
+ import type { Requirement } from "../factory/types.js";
2
+ export type RequirementState = "present" | "missing" | "blocked" | "created" | "declined" | "failed";
3
+ /** What kind of entry stands in the way of a required path. */
4
+ export type RequirementClashKind = "file" | "directory" | "link" | "other";
5
+ export interface RequirementResult {
6
+ path: string;
7
+ description: string;
8
+ template?: string;
9
+ state: RequirementState;
10
+ /** Why it is blocked or failed, as a phrase for the summary. */
11
+ reason?: string;
12
+ /**
13
+ * For `blocked`: the repository-relative path of the existing entry in the
14
+ * way (the directory at the path, the file or link parent, or the case
15
+ * variant). `check`'s fix line names it.
16
+ */
17
+ clash?: string;
18
+ /**
19
+ * For a `blocked` case variant: what kind of entry has the other spelling, so
20
+ * a fix line offers a rename only when renaming gives the required path what
21
+ * it needs (a directory at a parent, or any non-directory entry at the path
22
+ * itself, which inspection would then report as present).
23
+ */
24
+ clashKind?: RequirementClashKind;
25
+ }
26
+ /** What inspection needs of a requirement; a `Requirement` satisfies it. */
27
+ export type RequirementRef = Pick<Requirement, "path" | "description"> & {
28
+ template?: string;
29
+ };
30
+ /**
31
+ * What is at a required path in the repository, without writing anything:
32
+ *
33
+ * - `present`: a file, link (even a dangling one) or other entry that is not a
34
+ * directory.
35
+ * - `missing`: nothing is at the path, and no parent is in the way.
36
+ * - `blocked`: a directory is at the path, a parent is a file or link (or not a
37
+ * directory), the path or a parent differs only in letter case from an
38
+ * existing entry, or a parent cannot be read.
39
+ *
40
+ * Inspection never follows a link, so a linked parent cannot redirect a later
41
+ * write. Names are folded with `toLowerCase`, as `import` folds them, so a case
42
+ * variant is reported the same way on every filesystem.
43
+ */
44
+ export declare function inspectRequirement(root: string, requirement: RequirementRef): Promise<RequirementResult>;
@@ -0,0 +1,114 @@
1
+ import path from "node:path";
2
+ import { readdirTyped } from "../../util/fs.js";
3
+ function base(requirement) {
4
+ return {
5
+ path: requirement.path,
6
+ description: requirement.description,
7
+ ...(requirement.template === undefined ? {} : { template: requirement.template }),
8
+ };
9
+ }
10
+ function missing(requirement) {
11
+ return { ...base(requirement), state: "missing" };
12
+ }
13
+ function present(requirement) {
14
+ return { ...base(requirement), state: "present" };
15
+ }
16
+ function blocked(requirement, reason, clash, clashKind) {
17
+ return {
18
+ ...base(requirement),
19
+ state: "blocked",
20
+ reason,
21
+ clash,
22
+ ...(clashKind === undefined ? {} : { clashKind }),
23
+ };
24
+ }
25
+ /** What kind of entry a case variant is, from a listing that never follows links. */
26
+ function kindOf(entry) {
27
+ if (entry.isFile())
28
+ return "file";
29
+ if (entry.isDirectory())
30
+ return "directory";
31
+ if (entry.isSymbolicLink())
32
+ return "link";
33
+ return "other";
34
+ }
35
+ async function readDirectory(directory) {
36
+ try {
37
+ return { ok: true, entries: await readdirTyped(directory) };
38
+ }
39
+ catch (error) {
40
+ const code = error?.code;
41
+ return { ok: false, absent: code === "ENOENT" || code === "ENOTDIR" };
42
+ }
43
+ }
44
+ function label(relativePath) {
45
+ return relativePath === "" ? "." : relativePath;
46
+ }
47
+ /**
48
+ * What is at a required path in the repository, without writing anything:
49
+ *
50
+ * - `present`: a file, link (even a dangling one) or other entry that is not a
51
+ * directory.
52
+ * - `missing`: nothing is at the path, and no parent is in the way.
53
+ * - `blocked`: a directory is at the path, a parent is a file or link (or not a
54
+ * directory), the path or a parent differs only in letter case from an
55
+ * existing entry, or a parent cannot be read.
56
+ *
57
+ * Inspection never follows a link, so a linked parent cannot redirect a later
58
+ * write. Names are folded with `toLowerCase`, as `import` folds them, so a case
59
+ * variant is reported the same way on every filesystem.
60
+ */
61
+ export async function inspectRequirement(root, requirement) {
62
+ const segments = requirement.path.split("/");
63
+ const last = segments.pop() ?? "";
64
+ const parents = [];
65
+ let directory = root;
66
+ const unreadable = (parent) => blocked(requirement, `Cannot read ${label(parent)}`, label(parent));
67
+ for (const segment of segments) {
68
+ const listing = await readDirectory(directory);
69
+ if (!listing.ok) {
70
+ if (listing.absent)
71
+ return missing(requirement);
72
+ return unreadable(parents.join("/"));
73
+ }
74
+ const relativePath = [...parents, segment].join("/");
75
+ const exact = listing.entries.find((entry) => entry.name === segment);
76
+ if (exact !== undefined) {
77
+ if (exact.isDirectory()) {
78
+ parents.push(segment);
79
+ directory = path.join(directory, segment);
80
+ continue;
81
+ }
82
+ if (exact.isSymbolicLink())
83
+ return blocked(requirement, `${relativePath} is a symbolic link`, relativePath);
84
+ if (exact.isFile())
85
+ return blocked(requirement, `${relativePath} is a file`, relativePath);
86
+ return blocked(requirement, `${relativePath} is not a directory`, relativePath);
87
+ }
88
+ const folded = listing.entries.find((entry) => entry.name.toLowerCase() === segment.toLowerCase());
89
+ if (folded !== undefined) {
90
+ const clash = [...parents, folded.name].join("/");
91
+ return blocked(requirement, `${clash} differs only in letter case`, clash, kindOf(folded));
92
+ }
93
+ return missing(requirement);
94
+ }
95
+ const listing = await readDirectory(directory);
96
+ if (!listing.ok) {
97
+ if (listing.absent)
98
+ return missing(requirement);
99
+ return unreadable(parents.join("/"));
100
+ }
101
+ const exact = listing.entries.find((entry) => entry.name === last);
102
+ if (exact !== undefined) {
103
+ return exact.isDirectory()
104
+ ? blocked(requirement, `${requirement.path} is a directory`, requirement.path)
105
+ : present(requirement);
106
+ }
107
+ const folded = listing.entries.find((entry) => entry.name.toLowerCase() === last.toLowerCase());
108
+ if (folded !== undefined) {
109
+ const clash = [...parents, folded.name].join("/");
110
+ return blocked(requirement, `${clash} differs only in letter case`, clash, kindOf(folded));
111
+ }
112
+ return missing(requirement);
113
+ }
114
+ //# sourceMappingURL=inspect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inspect.js","sourceRoot":"","sources":["../../../src/core/requires/inspect.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAkChD,SAAS,IAAI,CAAC,WAA2B;IACvC,OAAO;QACL,IAAI,EAAE,WAAW,CAAC,IAAI;QACtB,WAAW,EAAE,WAAW,CAAC,WAAW;QACpC,GAAG,CAAC,WAAW,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,WAAW,CAAC,QAAQ,EAAE,CAAC;KAClF,CAAC;AACJ,CAAC;AAED,SAAS,OAAO,CAAC,WAA2B;IAC1C,OAAO,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AACpD,CAAC;AAED,SAAS,OAAO,CAAC,WAA2B;IAC1C,OAAO,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AACpD,CAAC;AAED,SAAS,OAAO,CACd,WAA2B,EAC3B,MAAc,EACd,KAAa,EACb,SAAgC;IAEhC,OAAO;QACL,GAAG,IAAI,CAAC,WAAW,CAAC;QACpB,KAAK,EAAE,SAAS;QAChB,MAAM;QACN,KAAK;QACL,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC;KAClD,CAAC;AACJ,CAAC;AAED,qFAAqF;AACrF,SAAS,MAAM,CAAC,KAAe;IAC7B,IAAI,KAAK,CAAC,MAAM,EAAE;QAAE,OAAO,MAAM,CAAC;IAClC,IAAI,KAAK,CAAC,WAAW,EAAE;QAAE,OAAO,WAAW,CAAC;IAC5C,IAAI,KAA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AC,MAAM,CAAC,CAAC,CAAC;IAC7F,CAAC;IAED,OAAO,OAAO,CAAC,WAAW,CAAC,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,29 @@
1
+ /** Every `requires` template is written as a repository-relative path under this prefix. */
2
+ export declare const FACTORY_TEMPLATES_PREFIX = ".factory/templates/";
3
+ /**
4
+ * Targets rule 12 refuses: Metafab's own tree, the skill trees `build` and
5
+ * `import` write, and the root files they own. The comparison ignores case, and
6
+ * a path below one of them is refused with it.
7
+ */
8
+ export declare const FORBIDDEN_REQUIREMENT_TARGETS: readonly [".factory", ".claude/skills", ".agents/skills", "agents.md", "claude.md", ".gitignore", ".gitattributes"];
9
+ /**
10
+ * Directories that hold a target of `FORBIDDEN_REQUIREMENT_TARGETS`, so the
11
+ * directory itself is refused: `build` needs it to stay a directory, and a
12
+ * requirement with a template there would create it as a file. A path below one
13
+ * is still allowed, such as `.claude/settings.json`.
14
+ */
15
+ export declare const FORBIDDEN_REQUIREMENT_DIRECTORIES: readonly [".claude", ".agents"];
16
+ /**
17
+ * A `template` written as a repository-relative path, as everything inside
18
+ * `.factory/` is: `Skill.relDir`, `FileTree` keys, conflict and change paths.
19
+ * Rule 13 guarantees the prefix; this only drops it.
20
+ */
21
+ export declare function factoryRelative(template: string): string;
22
+ /**
23
+ * The first rule a `requires` path breaks, as a phrase for
24
+ * `Required path "<path>" <phrase>`, or `undefined` when the path is safe.
25
+ * Rule 12 of the factory format: a repository-relative file path outside
26
+ * Metafab's own files, which Windows, Git and every case-insensitive
27
+ * filesystem can create.
28
+ */
29
+ export declare function requirementPathProblem(value: string): string | undefined;
@@ -0,0 +1,83 @@
1
+ import { isDotGitName } from "../../util/git-names.js";
2
+ /** Every `requires` template is written as a repository-relative path under this prefix. */
3
+ export const FACTORY_TEMPLATES_PREFIX = ".factory/templates/";
4
+ /**
5
+ * Targets rule 12 refuses: Metafab's own tree, the skill trees `build` and
6
+ * `import` write, and the root files they own. The comparison ignores case, and
7
+ * a path below one of them is refused with it.
8
+ */
9
+ export const FORBIDDEN_REQUIREMENT_TARGETS = [
10
+ ".factory",
11
+ ".claude/skills",
12
+ ".agents/skills",
13
+ "agents.md",
14
+ "claude.md",
15
+ ".gitignore",
16
+ ".gitattributes",
17
+ ];
18
+ /**
19
+ * Directories that hold a target of `FORBIDDEN_REQUIREMENT_TARGETS`, so the
20
+ * directory itself is refused: `build` needs it to stay a directory, and a
21
+ * requirement with a template there would create it as a file. A path below one
22
+ * is still allowed, such as `.claude/settings.json`.
23
+ */
24
+ export const FORBIDDEN_REQUIREMENT_DIRECTORIES = [".claude", ".agents"];
25
+ /** Characters no `requires` path may hold: Windows refuses them in a name. */
26
+ const FORBIDDEN_CHARACTER = /[\\:*?"<>|\u0000-\u001f\u007f]/;
27
+ /** A Windows device name, with or without an extension, in any letter case. */
28
+ const WINDOWS_DEVICE_NAME = /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\..*)?$/i;
29
+ /**
30
+ * A `template` written as a repository-relative path, as everything inside
31
+ * `.factory/` is: `Skill.relDir`, `FileTree` keys, conflict and change paths.
32
+ * Rule 13 guarantees the prefix; this only drops it.
33
+ */
34
+ export function factoryRelative(template) {
35
+ return template.slice(".factory/".length);
36
+ }
37
+ function isForbiddenTarget(folded) {
38
+ return FORBIDDEN_REQUIREMENT_TARGETS.some((target) => folded === target || folded.startsWith(`${target}/`));
39
+ }
40
+ /**
41
+ * The first rule a `requires` path breaks, as a phrase for
42
+ * `Required path "<path>" <phrase>`, or `undefined` when the path is safe.
43
+ * Rule 12 of the factory format: a repository-relative file path outside
44
+ * Metafab's own files, which Windows, Git and every case-insensitive
45
+ * filesystem can create.
46
+ */
47
+ export function requirementPathProblem(value) {
48
+ if (value === "")
49
+ return "is empty";
50
+ if (value.startsWith("/"))
51
+ return "leaves the repository";
52
+ if (value.includes("\\"))
53
+ return "uses a backslash";
54
+ if (value.endsWith("/"))
55
+ return "ends with a slash";
56
+ const segments = value.split("/");
57
+ if (segments.includes(""))
58
+ return "has an empty segment";
59
+ if (segments.includes(".."))
60
+ return "leaves the repository";
61
+ if (segments.includes("."))
62
+ return 'has a "." segment';
63
+ if (FORBIDDEN_CHARACTER.test(value))
64
+ return "contains a character Windows cannot use";
65
+ if (segments.some((segment) => segment.endsWith(".") || segment.endsWith(" "))) {
66
+ return "has a segment that ends in a dot or a space";
67
+ }
68
+ if (segments.some((segment) => WINDOWS_DEVICE_NAME.test(segment))) {
69
+ return "uses a Windows device name";
70
+ }
71
+ if (segments.some((segment) => isDotGitName(segment)))
72
+ return "is read by Git as .git";
73
+ const folded = value.toLowerCase();
74
+ if (folded === ".factory" || folded.startsWith(".factory/"))
75
+ return "is inside .factory/";
76
+ if (isForbiddenTarget(folded))
77
+ return "is a file Metafab writes";
78
+ if (FORBIDDEN_REQUIREMENT_DIRECTORIES.some((directory) => folded === directory)) {
79
+ return "is a directory that holds a file Metafab writes";
80
+ }
81
+ return undefined;
82
+ }
83
+ //# sourceMappingURL=paths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.js","sourceRoot":"","sources":["../../../src/core/requires/paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,4FAA4F;AAC5F,MAAM,CAAC,MAAM,wBAAwB,GAAG,qBAAqB,CAAC;AAE9D;;;;GAIG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG;IAC3C,UAAU;IACV,gBAAgB;IAChB,gBAAgB;IAChB,WAAW;IACX,WAAW;IACX,YAAY;IACZ,gBAAgB;CACR,CAAC;AAEX;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAU,CAAC;AAEjF,8EAA8E;AAC9E,MAAM,mBAAmB,GAAG,gCAAgC,CAAC;AAE7D,+EAA+E;AAC/E,MAAM,mBAAmB,GAAG,mDAAmD,CAAC;AAEhF;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,QAAgB;IA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AAC,OAAO,EAAE,EAAE,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;QAClE,OAAO,4BAA4B,CAAC;IACtC,CAAC;IACD,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAAE,OAAO,wBAAwB,CAAC;IAEvF,MAAM,MAAM,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;IACnC,IAAI,MAAM,KAAK,UAAU,IAAI,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC;QAAE,OAAO,qBAAqB,CAAC;IAC1F,IAAI,iBAAiB,CAAC,MAAM,CAAC;QAAE,OAAO,0BAA0B,CAAC;IACjE,IAAI,iCAAiC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,MAAM,KAAK,SAAS,CAAC,EAAE,CAAC;QAChF,OAAO,iDAAiD,CAAC;IAC3D,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,37 @@
1
+ import type { Problem } from "../../errors.js";
2
+ import type { InputIO, RequiredValue } from "../../input.js";
3
+ import type { RequirementResult } from "./inspect.js";
4
+ export declare const SETUP_QUESTION = "Create the missing files from the fab's templates? Existing files are never changed.";
5
+ /**
6
+ * The required value for the setup consent. The caller collects it with the
7
+ * adoption value, so one `NeedsInput` can name both.
8
+ */
9
+ export declare function setupRequired(results: RequirementResult[]): RequiredValue;
10
+ /**
11
+ * The list printed before the setup question: only the entries that can be
12
+ * created, in `factory.yaml` order. A present, blocked or template-less entry
13
+ * is not worth asking about; the review summary shows it after the import.
14
+ */
15
+ export declare function describeRequirementList(results: RequirementResult[]): string;
16
+ /**
17
+ * Whether to create the missing files: a flag wins, a terminal is asked with
18
+ * yes as the default, and no terminal means the caller must report `--setup`.
19
+ * The list goes to stderr, so `--json` output stays one JSON object.
20
+ */
21
+ export declare function decideSetup(results: RequirementResult[], choice: boolean | undefined, io: InputIO, tty: boolean): Promise<boolean | "needs-input">;
22
+ /**
23
+ * Marks each file the person chose not to create. A requirement without a
24
+ * template stays `missing`: nobody was asked about it, and `check` reports it.
25
+ */
26
+ export declare function declineRequirements(results: RequirementResult[]): RequirementResult[];
27
+ /**
28
+ * Creates each agreed file from its template. The template's bytes are copied
29
+ * unchanged, so CRLF, a BOM and binary content survive; the new file is 0755
30
+ * when the template has any executable bit and 0644 otherwise. Each path is
31
+ * inspected again first, and the file is created exclusively, so an entry that
32
+ * appeared since the preflight is `present` and never replaced.
33
+ *
34
+ * A failure is a warning and the import continues; one file never stops the
35
+ * rest. `problems` collects those warnings for the command's report.
36
+ */
37
+ export declare function createRequirements(root: string, results: RequirementResult[], problems?: Problem[]): Promise<RequirementResult[]>;
@@ -0,0 +1,147 @@
1
+ import { chmod, mkdir, readFile, realpath, stat, writeFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { confirm } from "../../input.js";
4
+ import { isInsideAbsolute } from "../sources/containment.js";
5
+ import { inspectRequirement } from "./inspect.js";
6
+ export const SETUP_QUESTION = "Create the missing files from the fab's templates? Existing files are never changed.";
7
+ function creatable(results) {
8
+ return results.filter((result) => result.state === "missing" && result.template !== undefined);
9
+ }
10
+ /**
11
+ * The required value for the setup consent. The caller collects it with the
12
+ * adoption value, so one `NeedsInput` can name both.
13
+ */
14
+ export function setupRequired(results) {
15
+ const paths = creatable(results).map((result) => result.path);
16
+ return {
17
+ name: "setup",
18
+ flag: "--setup",
19
+ description: `Create the missing repository files the factory needs: ${paths.join(", ")}. Pass --setup to create them or --no-setup to skip`,
20
+ };
21
+ }
22
+ /**
23
+ * The list printed before the setup question: only the entries that can be
24
+ * created, in `factory.yaml` order. A present, blocked or template-less entry
25
+ * is not worth asking about; the review summary shows it after the import.
26
+ */
27
+ export function describeRequirementList(results) {
28
+ const entries = creatable(results);
29
+ if (entries.length === 0)
30
+ return "";
31
+ const width = Math.max(...entries.map((entry) => entry.path.length));
32
+ const lines = ["The factory needs these files, which are missing:"];
33
+ for (const entry of entries) {
34
+ lines.push(` ${entry.path.padEnd(width)} ${entry.description}`);
35
+ }
36
+ return `${lines.join("\n")}\n`;
37
+ }
38
+ /**
39
+ * Whether to create the missing files: a flag wins, a terminal is asked with
40
+ * yes as the default, and no terminal means the caller must report `--setup`.
41
+ * The list goes to stderr, so `--json` output stays one JSON object.
42
+ */
43
+ export async function decideSetup(results, choice, io, tty) {
44
+ if (creatable(results).length === 0)
45
+ return false;
46
+ if (choice !== undefined)
47
+ return choice;
48
+ if (!tty)
49
+ return "needs-input";
50
+ const stderr = io.stderr ??
51
+ ((text) => {
52
+ process.stderr.write(text);
53
+ });
54
+ stderr(describeRequirementList(results));
55
+ return confirm({ name: "setup", flag: "--setup", description: SETUP_QUESTION }, { default: true }, { ...io, stderr, tty });
56
+ }
57
+ /**
58
+ * Marks each file the person chose not to create. A requirement without a
59
+ * template stays `missing`: nobody was asked about it, and `check` reports it.
60
+ */
61
+ export function declineRequirements(results) {
62
+ return results.map((result) => result.state === "missing" && result.template !== undefined
63
+ ? { ...result, state: "declined" }
64
+ : result);
65
+ }
66
+ /**
67
+ * Why a template cannot be copied, as a phrase, or `undefined` when it can.
68
+ * Reading follows a link in any parent directory, so a `.factory/templates/`
69
+ * entry that is a link to an outside directory would copy bytes from outside
70
+ * `.factory/`. Rule 13 refuses such a tree, but `update` copies from the merged
71
+ * tree before its build validates it, so creation checks too. Anything that is
72
+ * not a regular file is refused for the same reason: `readFile` on a directory
73
+ * fails with `EISDIR`, and on a FIFO or a socket it waits for a peer.
74
+ */
75
+ async function templateRefusal(root, template) {
76
+ const refusal = `its template ${template} is not a regular file inside .factory/`;
77
+ const factory = await realpath(path.join(root, ".factory")).catch(() => undefined);
78
+ const resolved = await realpath(path.join(root, ...template.split("/"))).catch(() => undefined);
79
+ if (factory === undefined || resolved === undefined || !isInsideAbsolute(factory, resolved)) {
80
+ return refusal;
81
+ }
82
+ const info = await stat(resolved).catch(() => undefined);
83
+ return info !== undefined && info.isFile() ? undefined : refusal;
84
+ }
85
+ /**
86
+ * Creates each agreed file from its template. The template's bytes are copied
87
+ * unchanged, so CRLF, a BOM and binary content survive; the new file is 0755
88
+ * when the template has any executable bit and 0644 otherwise. Each path is
89
+ * inspected again first, and the file is created exclusively, so an entry that
90
+ * appeared since the preflight is `present` and never replaced.
91
+ *
92
+ * A failure is a warning and the import continues; one file never stops the
93
+ * rest. `problems` collects those warnings for the command's report.
94
+ */
95
+ export async function createRequirements(root, results, problems = []) {
96
+ const updated = [];
97
+ for (const result of results) {
98
+ if (result.state !== "missing" || result.template === undefined) {
99
+ updated.push(result);
100
+ continue;
101
+ }
102
+ const current = await inspectRequirement(root, result);
103
+ if (current.state !== "missing") {
104
+ updated.push(current);
105
+ continue;
106
+ }
107
+ const template = result.template;
108
+ const templatePath = path.join(root, ...template.split("/"));
109
+ const target = path.join(root, ...result.path.split("/"));
110
+ const refusal = await templateRefusal(root, template);
111
+ if (refusal !== undefined) {
112
+ updated.push({ ...result, state: "failed", reason: refusal });
113
+ problems.push({
114
+ level: "warning",
115
+ file: result.path,
116
+ message: `Could not create ${result.path}: ${refusal}`,
117
+ fix: `Replace ${template} with a file inside .factory/templates/`,
118
+ });
119
+ continue;
120
+ }
121
+ try {
122
+ const info = await stat(templatePath);
123
+ const bytes = await readFile(templatePath);
124
+ const mode = (info.mode & 0o111) !== 0 ? 0o755 : 0o644;
125
+ await mkdir(path.dirname(target), { recursive: true });
126
+ await writeFile(target, bytes, { flag: "wx", mode });
127
+ await chmod(target, mode);
128
+ updated.push({ ...result, state: "created" });
129
+ }
130
+ catch (error) {
131
+ const code = error?.code ?? "EIO";
132
+ if (code === "EEXIST") {
133
+ updated.push({ ...result, state: "present" });
134
+ continue;
135
+ }
136
+ updated.push({ ...result, state: "failed", reason: code });
137
+ problems.push({
138
+ level: "warning",
139
+ file: result.path,
140
+ message: `Could not create ${result.path}: ${code}`,
141
+ fix: `Copy ${template} to ${result.path}`,
142
+ });
143
+ }
144
+ }
145
+ return updated;
146
+ }
147
+ //# sourceMappingURL=setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.js","sourceRoot":"","sources":["../../../src/core/requires/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACrF,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGlD,MAAM,CAAC,MAAM,cAAc,GACzB,sFAAsF,CAAC;AAEzF,SAAS,SAAS,CAAC,OAA4B;IAC7C,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC;AACjG,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,OAA4B;IACxD,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC9D,OAAO;QACL,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,0DAA0D,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,qDAAqD;KAC7I,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAA4B;IAClE,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;IACnC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAEpC,MAAM,KAAK,GAAG,IAAI,CAAC,G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AC;AACjB,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { MetafabError } from "../errors.js";
2
+ import type { AdoptionMove } from "./adopt.js";
3
+ import type { Config, Target } from "./config/types.js";
4
+ /** The command whose name fills the `then run metafab <command> again` fix lines. */
5
+ export type SetupCommand = "init" | "import";
6
+ export declare function selectedTargets(selection: "all" | Target[]): Target[];
7
+ export declare function unreadableFactory(file: string, message: string, fix: string): MetafabError;
8
+ /** Refuses a `.factory` entry that cannot hold a factory before anything reads it. */
9
+ export declare function assertFactoryDirectoryUsable(factoryDir: string, command: SetupCommand): Promise<void>;
10
+ /**
11
+ * The fix line for an unreadable configuration file. Only a permissions error
12
+ * is worth telling the reader to check permissions; every other code means the
13
+ * file is broken, a directory, a loop, or otherwise unreadable.
14
+ */
15
+ export declare function unreadableConfigFix(code: string, command: SetupCommand): string;
16
+ /** Loads `metafab.yaml`, refusing a file that exists but cannot be read. */
17
+ export declare function readConfig(factoryDir: string, command: SetupCommand): Promise<Config>;
18
+ /** True when `file` lies at or beneath one of the paths an adoption moves. */
19
+ export declare function isAdoptionSource(file: string, moves: readonly AdoptionMove[]): boolean;
20
+ /**
21
+ * The output conflicts `build` would refuse, checked before `init` or `import`
22
+ * writes anything. Validation errors that are already in the factory are left
23
+ * for the closing build to report, so the setup command still adds the missing
24
+ * entries the specification promises. Conflict problems inside a planned move
25
+ * are ignored: the move removes them.
26
+ */
27
+ export declare function preflightBuild(root: string, config: Config, selection: "all" | Target[], configExists: boolean, moves: readonly AdoptionMove[]): Promise<void>;