@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,124 @@
1
+ import { conditionVariables, evaluate } from "./condition.js";
2
+ /**
3
+ * The most scenarios a block may span over the variables it and its enclosing
4
+ * conditions name. A document that needs more is an error, so rendering and the
5
+ * all-values root block stay cheap however many variables a factory declares.
6
+ */
7
+ export const MAX_COMBINATIONS = 1024;
8
+ /**
9
+ * Product of the declared value counts of `variables`: the all-values case,
10
+ * independent of the selection. A variable the factory does not declare has no
11
+ * declared values, so the product is 0.
12
+ */
13
+ export function combinations(variables, declared) {
14
+ const counts = new Map(declared.map((variable) => [variable.name, variable.values.length]));
15
+ let total = 1;
16
+ for (const name of variables) {
17
+ const count = counts.get(name);
18
+ if (count === undefined)
19
+ return 0;
20
+ total *= count;
21
+ if (total > Number.MAX_SAFE_INTEGER)
22
+ return Number.MAX_SAFE_INTEGER;
23
+ }
24
+ return total;
25
+ }
26
+ /**
27
+ * Every scenario over `variables`, in declaration order: the product of the
28
+ * selected values, with the first variable varying slowest. A variable the
29
+ * selection does not give a value for contributes none.
30
+ */
31
+ export function scenarios(selection, variables) {
32
+ let result = [new Map()];
33
+ for (const name of variables) {
34
+ const values = selection.get(name) ?? [];
35
+ const next = [];
36
+ for (const scenario of result) {
37
+ for (const value of values) {
38
+ const extended = new Map(scenario);
39
+ extended.set(name, value);
40
+ next.push(extended);
41
+ }
42
+ }
43
+ result = next;
44
+ }
45
+ return result;
46
+ }
47
+ /**
48
+ * Classifies a condition in the scenarios where its enclosing conditions are
49
+ * true: `all` when it holds in every one, `none` when it holds in none, else
50
+ * `some` with the label its kept text takes. No other variable is enumerated,
51
+ * because no other variable can change the result.
52
+ */
53
+ export function classify(condition, enclosing, selection, variables) {
54
+ const named = conditionVariables(condition);
55
+ for (const outer of enclosing) {
56
+ for (const name of conditionVariables(outer))
57
+ named.add(name);
58
+ }
59
+ const context = scenarios(selection, declarationOrder(named, variables)).filter((scenario) => enclosing.every((outer) => evaluate(outer, scenario)));
60
+ if (context.length === 0)
61
+ return { kind: "none" };
62
+ const kept = context.filter((scenario) => evaluate(condition, scenario));
63
+ if (kept.length === context.length)
64
+ return { kind: "all" };
65
+ if (kept.length === 0)
66
+ return { kind: "none" };
67
+ return { kind: "some", label: labelFor(condition, context, kept, variables) };
68
+ }
69
+ /** The selection with every declared value of every variable: the root `AGENTS.md` render. */
70
+ export function allValues(variables) {
71
+ return new Map(variables.map((variable) => [variable.name, variable.values.map((value) => value.name)]));
72
+ }
73
+ /** The declared variables a set of names names, in `env` order. */
74
+ function declarationOrder(named, variables) {
75
+ return variables.map((variable) => variable.name).filter((name) => named.has(name));
76
+ }
77
+ /**
78
+ * The label a partially matching block takes, as the spec's Rendering section
79
+ * builds it: each of the condition's variables that takes more than one value
80
+ * in the context and is not true for every one of them contributes the labels
81
+ * of the values it can be true for, joined with ` or `. When that names no
82
+ * variable, every combination of the condition's variables for which it is true
83
+ * is listed instead.
84
+ */
85
+ function labelFor(condition, context, kept, variables) {
86
+ const own = conditionVariables(condition);
87
+ const parts = [];
88
+ for (const variable of variables) {
89
+ if (!own.has(variable.name))
90
+ continue;
91
+ const possible = new Set(context.map((scenario) => scenario.get(variable.name)));
92
+ if (possible.size < 2)
93
+ continue;
94
+ const reachable = new Set(kept.map((scenario) => scenario.get(variable.name)));
95
+ if (reachable.size === possible.size)
96
+ continue;
97
+ const labels = variable.values
98
+ .filter((value) => reachable.has(value.name))
99
+ .map((value) => value.label);
100
+ if (labels.length > 0)
101
+ parts.push(labels.join(" or "));
102
+ }
103
+ if (parts.length > 0)
104
+ return parts.join(", and ");
105
+ const ownVariables = variables.filter((variable) => own.has(variable.name));
106
+ const seen = new Set();
107
+ const listed = [];
108
+ for (const scenario of kept) {
109
+ const names = ownVariables.map((variable) => scenario.get(variable.name) ?? "");
110
+ const key = names.join("\u0000");
111
+ if (seen.has(key))
112
+ continue;
113
+ seen.add(key);
114
+ listed.push(ownVariables
115
+ .map((variable, index) => {
116
+ const name = names[index] ?? "";
117
+ return (variable.values.find((value) => value.name === name)?.label ??
118
+ `When ${variable.name} is ${name}`);
119
+ })
120
+ .join(", and "));
121
+ }
122
+ return listed.join(" or ");
123
+ }
124
+ //# sourceMappingURL=scenarios.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scenarios.js","sourceRoot":"","sources":["../../../src/core/env/scenarios.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAI9D;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAQrC;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAC1B,SAA2B,EAC3B,QAAgC;IAEhC,MAAM,MAAM,GAAG,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AAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,KAAK;gBAC3D,QAAQ,QAAQ,CAAC,IAAI,OAAO,IAAI,EAAE,CACnC,CAAC;QACJ,CAAC,CAAC;aACD,IAAI,CAAC,QAAQ,CAAC,CAClB,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,30 @@
1
+ import type { EnvConfigReader } from "./git-config.js";
2
+ import type { EnvVariable, ResolvedSelection } from "./types.js";
3
+ /** `harness` → `FACTORY_ENV_HARNESS`; `target-os` → `FACTORY_ENV_TARGET_OS`. */
4
+ export declare function envVariableName(variable: string): string;
5
+ /** Comma-separated value names, trimmed, without empties or repeats. */
6
+ export declare function splitValues(text: string): string[];
7
+ /**
8
+ * The `--env` option's arguments: `parseArgs` gives one string, a list of them,
9
+ * or a boolean when the option is written with no value.
10
+ */
11
+ export declare function envOptions(value: unknown): string[];
12
+ export interface ResolveOptions {
13
+ root: string;
14
+ /** Raw `--env` arguments. */
15
+ options?: readonly string[];
16
+ /** Default `process.env`; tests inject one so no developer's variable leaks in. */
17
+ processEnv?: NodeJS.ProcessEnv;
18
+ /** Default `readEnvConfig`; tests inject a fake. */
19
+ readConfig?: EnvConfigReader;
20
+ }
21
+ /** The fix line for a variable or value a factory does not declare. */
22
+ export declare function declaredVariablesFix(names: readonly string[]): string;
23
+ /**
24
+ * Resolves every declared variable's values from `--env`, the process
25
+ * environment, Git config, the declared default and finally every value.
26
+ *
27
+ * A bad `--env` throws a `MetafabError` with exit 1; an undeclared value from
28
+ * any other source is a warning and the next source applies.
29
+ */
30
+ export declare function resolveSelection(variables: readonly EnvVariable[], options: ResolveOptions): Promise<ResolvedSelection>;
@@ -0,0 +1,191 @@
1
+ import { ExitCode, MetafabError } from "../../errors.js";
2
+ import { didYouMean } from "../../util/suggest.js";
3
+ import { readEnvConfig } from "./git-config.js";
4
+ /** A problem with the selection is a problem with the declaration that needs it. */
5
+ const FILE = ".factory/factory.yaml";
6
+ /** Git config scopes, highest priority first. */
7
+ const SCOPES = ["worktree", "local", "global", "system"];
8
+ /** `harness` → `FACTORY_ENV_HARNESS`; `target-os` → `FACTORY_ENV_TARGET_OS`. */
9
+ export function envVariableName(variable) {
10
+ return `FACTORY_ENV_${variable.toUpperCase().replaceAll("-", "_")}`;
11
+ }
12
+ /** Comma-separated value names, trimmed, without empties or repeats. */
13
+ export function splitValues(text) {
14
+ const values = [];
15
+ for (const part of text.split(",")) {
16
+ const value = part.trim();
17
+ if (value === "" || values.includes(value))
18
+ continue;
19
+ values.push(value);
20
+ }
21
+ return values;
22
+ }
23
+ /**
24
+ * The `--env` option's arguments: `parseArgs` gives one string, a list of them,
25
+ * or a boolean when the option is written with no value.
26
+ */
27
+ export function envOptions(value) {
28
+ if (typeof value === "string")
29
+ return [value];
30
+ if (Array.isArray(value)) {
31
+ return value.filter((item) => typeof item === "string");
32
+ }
33
+ return [];
34
+ }
35
+ /** The fix line for a variable or value a factory does not declare. */
36
+ export function declaredVariablesFix(names) {
37
+ return names.length === 0
38
+ ? "This factory declares no environment variables"
39
+ : `Declared variables: ${names.join(", ")}`;
40
+ }
41
+ /** Splits `--env <variable>=<values>`, reporting every bad argument at once. */
42
+ function parseOptions(variables, args) {
43
+ const byName = new Map(variables.map((variable) => [variable.name, variable]));
44
+ const declared = variables.map((variable) => variable.name);
45
+ const parsed = new Map();
46
+ const problems = [];
47
+ for (const arg of args) {
48
+ const equals = arg.indexOf("=");
49
+ if (equals === -1) {
50
+ problems.push({
51
+ level: "error",
52
+ file: FILE,
53
+ message: `--env needs <variable>=<values>: "${arg}"`,
54
+ fix: "Write --env <variable>=<values>, such as --env harness=opencode",
55
+ });
56
+ continue;
57
+ }
58
+ const name = arg.slice(0, equals);
59
+ const text = arg.slice(equals + 1);
60
+ const variable = byName.get(name);
61
+ if (variable === undefined) {
62
+ problems.push({
63
+ level: "error",
64
+ file: FILE,
65
+ message: `--env names unknown variable "${name}"`,
66
+ fix: didYouMean(name, declared) ?? declaredVariablesFix(declared),
67
+ });
68
+ continue;
69
+ }
70
+ if (parsed.has(name)) {
71
+ problems.push({
72
+ level: "error",
73
+ file: FILE,
74
+ line: variable.line,
75
+ message: `--env names "${name}" twice`,
76
+ fix: `Pass --env ${name}=<values> once`,
77
+ });
78
+ continue;
79
+ }
80
+ parsed.set(name, text);
81
+ }
82
+ if (problems.length > 0) {
83
+ throw new MetafabError("Invalid --env", {
84
+ exitCode: ExitCode.Failed,
85
+ code: "invalid-env",
86
+ problems,
87
+ });
88
+ }
89
+ return parsed;
90
+ }
91
+ /**
92
+ * Drops the values the variable does not declare, warning about each one, and
93
+ * returns what is left in declaration order so the order given never matters.
94
+ */
95
+ function keepDeclared(text, source, variable, declared, warnings) {
96
+ const kept = new Set();
97
+ for (const value of splitValues(text)) {
98
+ if (!declared.includes(value)) {
99
+ warnings.push({
100
+ level: "warning",
101
+ file: FILE,
102
+ line: variable.line,
103
+ message: `Ignored "${value}" from ${source}: ${variable.name} does not declare it`,
104
+ fix: `Declared values: ${declared.join(", ")}`,
105
+ });
106
+ continue;
107
+ }
108
+ kept.add(value);
109
+ }
110
+ return declared.filter((name) => kept.has(name));
111
+ }
112
+ /** The first source that yields a declared value wins, in the spec's order. */
113
+ function resolveVariable(variable, sources, warnings) {
114
+ const declared = variable.values.map((value) => value.name);
115
+ const name = variable.name;
116
+ const optionText = sources.optionValues.get(name);
117
+ if (optionText !== undefined) {
118
+ if (splitValues(optionText).length === 0) {
119
+ warnings.push({
120
+ level: "warning",
121
+ file: FILE,
122
+ line: variable.line,
123
+ message: `--env ${name}=${optionText} names no value`,
124
+ fix: `Write --env ${name}=<values>, such as --env ${name}=${declared[0] ?? "<value>"}`,
125
+ });
126
+ }
127
+ else {
128
+ const values = keepDeclared(optionText, `--env ${name}=${optionText}`, variable, declared, warnings);
129
+ if (values.length > 0)
130
+ return { variable: name, values, source: "option" };
131
+ }
132
+ }
133
+ const from = envVariableName(name);
134
+ const environmentText = sources.processEnv[from];
135
+ if (environmentText !== undefined) {
136
+ const values = keepDeclared(environmentText, from, variable, declared, warnings);
137
+ if (values.length > 0)
138
+ return { variable: name, values, source: "environment", from };
139
+ }
140
+ for (const scope of SCOPES) {
141
+ const scoped = sources.entries.filter((entry) => entry.variable === name && entry.scope === scope);
142
+ if (scoped.length === 0)
143
+ continue;
144
+ const source = `factory.env.${name} in ${scope} Git config`;
145
+ const kept = new Set();
146
+ for (const entry of scoped) {
147
+ for (const value of keepDeclared(entry.value, source, variable, declared, warnings)) {
148
+ kept.add(value);
149
+ }
150
+ }
151
+ const values = declared.filter((value) => kept.has(value));
152
+ // A scope that sets the key decides it, even when every value is ignored.
153
+ if (values.length > 0)
154
+ return { variable: name, values, source: "git", scope };
155
+ break;
156
+ }
157
+ const defaults = (variable.default ?? []).filter((value) => declared.includes(value));
158
+ if (defaults.length > 0) {
159
+ const values = declared.filter((value) => defaults.includes(value));
160
+ return { variable: name, values, source: "default" };
161
+ }
162
+ return { variable: name, values: [...declared], source: "all" };
163
+ }
164
+ /**
165
+ * Resolves every declared variable's values from `--env`, the process
166
+ * environment, Git config, the declared default and finally every value.
167
+ *
168
+ * A bad `--env` throws a `MetafabError` with exit 1; an undeclared value from
169
+ * any other source is a warning and the next source applies.
170
+ */
171
+ export async function resolveSelection(variables, options) {
172
+ const optionValues = parseOptions(variables, options.options ?? []);
173
+ const selection = new Map();
174
+ if (variables.length === 0)
175
+ return { variables: [], selection, warnings: [] };
176
+ const { entries, warnings: readWarnings } = await (options.readConfig ?? readEnvConfig)(options.root);
177
+ const sources = {
178
+ optionValues,
179
+ processEnv: options.processEnv ?? process.env,
180
+ entries,
181
+ };
182
+ const warnings = [...readWarnings];
183
+ const resolved = [];
184
+ for (const variable of variables) {
185
+ const result = resolveVariable(variable, sources, warnings);
186
+ resolved.push(result);
187
+ selection.set(variable.name, result.values);
188
+ }
189
+ return { variables: resolved, selection, warnings };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CAAC;IAC5D,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IAE9E,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,IAAI,aAAa,CAAC,CACrF,OAAO,CAAC,IAAI,CACb,CAAC;IACF,MAAM,OAAO,GAAoB;QAC/B,YAAY;QACZ,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,GAAG;QAC7C,OAAO;KACR,CAAC;IAEF,MAAM,QAAQ,GAAc,CAAC,GAAG,YAAY,CAAC,CAAC;IAC9C,MAAM,QAAQ,GAAuB,EAAE,CAAC;IACxC,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,MAAM,MAAM,GAAG,eAAe,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;QAC5D,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACtB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AACtD,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { Problem } from "../../errors.js";
2
+ export interface EnvValue {
3
+ name: string;
4
+ /** The declared label, or `When <variable> is <value>`. */
5
+ label: string;
6
+ line: number;
7
+ }
8
+ export interface EnvVariable {
9
+ name: string;
10
+ description?: string;
11
+ /** Declaration order, never empty after validation. */
12
+ values: EnvValue[];
13
+ /** Value names in declaration order, when the variable declares a default. */
14
+ default?: string[];
15
+ /** The variable's key line in `factory.yaml`. */
16
+ line: number;
17
+ }
18
+ /**
19
+ * Variable name → selected value names, in declaration order. Every declared
20
+ * variable has an entry.
21
+ */
22
+ export type EnvSelection = ReadonlyMap<string, readonly string[]>;
23
+ export type SelectionSource = "option" | "environment" | "git" | "default" | "all";
24
+ export type GitConfigScope = "worktree" | "local" | "global" | "system";
25
+ export interface ResolvedVariable {
26
+ variable: string;
27
+ values: string[];
28
+ source: SelectionSource;
29
+ /** The Git config scope the selection came from, for `git`. */
30
+ scope?: GitConfigScope;
31
+ /** The `FACTORY_ENV_<VAR>` variable that supplied the selection, for `environment`. */
32
+ from?: string;
33
+ }
34
+ export interface ResolvedSelection {
35
+ variables: ResolvedVariable[];
36
+ selection: EnvSelection;
37
+ warnings: Problem[];
38
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/env/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,25 @@
1
+ import type { Problem } from "../../errors.js";
2
+ import type { Factory } from "../factory/types.js";
3
+ import type { MarkdownDocument } from "./directives.js";
4
+ import type { EnvVariable } from "./types.js";
5
+ /**
6
+ * Rule 14 for a format 2 factory, and directives rule 5 for a format 1 one.
7
+ * Format 2 validates every directive, condition and switch in every branch of
8
+ * every file `build` renders, whatever the selection, and every `skills` entry.
9
+ * Format 1 copies directives as text, so each file that has one gets a single
10
+ * warning on its first directive line.
11
+ */
12
+ export declare function environmentProblems(factory: Factory): Promise<Problem[]>;
13
+ /**
14
+ * The combination limit across an import: a block inside an imported file is
15
+ * classified together with the conditions around the import line, so the two
16
+ * files' variables can span more scenarios than either file alone. Each file's
17
+ * own parse checks its blocks against its own enclosing conditions, so this
18
+ * reports only the blocks an import pushes over the limit, on the import
19
+ * directive's line in the importing file.
20
+ *
21
+ * Rendering classifies each block over its enclosing conditions, so a renderer
22
+ * must treat these as errors too: without them it would enumerate every
23
+ * scenario of a block this reports.
24
+ */
25
+ export declare function importCombinationProblems(document: MarkdownDocument, variables: readonly EnvVariable[]): Problem[];
@@ -0,0 +1,212 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { didYouMean } from "../../util/suggest.js";
4
+ import { toLF } from "../../util/text.js";
5
+ import { collectSkillFiles, textContent } from "../build/skill.js";
6
+ import { conditionVariables } from "./condition.js";
7
+ import { directiveLines, parseMarkdown } from "./directives.js";
8
+ import { createImportCache } from "./imports.js";
9
+ import { markdownParts } from "./markdown.js";
10
+ import { MAX_COMBINATIONS, combinations } from "./scenarios.js";
11
+ const FACTORY_FILE = ".factory/factory.yaml";
12
+ const AGENTS_FILE = ".factory/AGENTS.md";
13
+ const FRONTMATTER_MESSAGE = "Directives are not allowed in frontmatter";
14
+ const FRONTMATTER_FIX = "Move the directive below the closing ---; name and description stay the same in every environment";
15
+ const FORMAT_ONE_FIX = "Set format: 2 in .factory/factory.yaml, or remove the directives";
16
+ /** True for a file `build` renders: its extension, lowercased, is `.md`. */
17
+ function isRenderedMarkdown(relative) {
18
+ return path.extname(relative).toLowerCase() === ".md";
19
+ }
20
+ async function readMarkdown(target, file, problems) {
21
+ let data;
22
+ try {
23
+ data = await readFile(target);
24
+ }
25
+ catch {
26
+ problems.push({
27
+ level: "error",
28
+ file,
29
+ line: 1,
30
+ message: `Cannot read file ${file}`,
31
+ fix: "Check its permissions or restore the file",
32
+ });
33
+ return undefined;
34
+ }
35
+ const text = textContent(data);
36
+ return text === undefined ? undefined : toLF(text);
37
+ }
38
+ /**
39
+ * Rule 14 for a format 2 factory, and directives rule 5 for a format 1 one.
40
+ * Format 2 validates every directive, condition and switch in every branch of
41
+ * every file `build` renders, whatever the selection, and every `skills` entry.
42
+ * Format 1 copies directives as text, so each file that has one gets a single
43
+ * warning on its first directive line.
44
+ */
45
+ export async function environmentProblems(factory) {
46
+ const problems = [];
47
+ const yaml = factory.factoryYaml;
48
+ const format = yaml?.format ?? 1;
49
+ const variables = yaml?.env ?? [];
50
+ // One cache per run, so a partial imported by several files is read once and
51
+ // an edited partial is always reread by the next run.
52
+ const imports = createImportCache(factory.dir);
53
+ const checkFile = async (file, route, text, frontmatter) => {
54
+ if (format === 1) {
55
+ const lines = directiveLines(text);
56
+ if (lines.length > 0) {
57
+ problems.push({
58
+ level: "warning",
59
+ file,
60
+ line: lines[0],
61
+ message: `${file} has factory: directives, which need format: 2`,
62
+ fix: FORMAT_ONE_FIX,
63
+ });
64
+ }
65
+ return;
66
+ }
67
+ const parts = frontmatter ? markdownParts(text) : undefined;
68
+ if (parts?.frontmatter !== undefined) {
69
+ for (const line of directiveLines(parts.frontmatter, 2)) {
70
+ problems.push({
71
+ level: "error",
72
+ file,
73
+ line,
74
+ message: FRONTMATTER_MESSAGE,
75
+ fix: FRONTMATTER_FIX,
76
+ });
77
+ }
78
+ }
79
+ const document = await parseMarkdown(parts?.body ?? text, {
80
+ file,
81
+ firstLine: parts?.firstLine ?? 1,
82
+ variables,
83
+ imports,
84
+ route,
85
+ chain: [],
86
+ });
87
+ problems.push(...document.problems);
88
+ problems.push(...importCombinationProblems(document, variables));
89
+ };
90
+ for (const skill of factory.skills) {
91
+ const sourcePath = `.factory/${skill.relDir}`;
92
+ const collected = await collectSkillFiles({ dir: path.join(factory.dir, ...skill.relDir.split("/")), name: skill.name, sourcePath }, { factoryDir: factory.dir });
93
+ for (const file of collected.files) {
94
+ if (!isRenderedMarkdown(file.relative))
95
+ continue;
96
+ const displayPath = `${sourcePath}/${file.relative}`;
97
+ const text = await readMarkdown(file.target, displayPath, problems);
98
+ if (text === undefined)
99
+ continue;
100
+ await checkFile(displayPath, `${skill.relDir}/${file.relative}`, text, true);
101
+ }
102
+ }
103
+ // `.factory/AGENTS.md` is rendered whole, so it has no frontmatter to protect.
104
+ if (factory.agentsMd !== undefined) {
105
+ await checkFile(AGENTS_FILE, "AGENTS.md", factory.agentsMd, false);
106
+ }
107
+ if (format === 2)
108
+ problems.push(...conditionalSkillProblems(factory));
109
+ return dedupeProblems(problems);
110
+ }
111
+ /**
112
+ * The combination limit across an import: a block inside an imported file is
113
+ * classified together with the conditions around the import line, so the two
114
+ * files' variables can span more scenarios than either file alone. Each file's
115
+ * own parse checks its blocks against its own enclosing conditions, so this
116
+ * reports only the blocks an import pushes over the limit, on the import
117
+ * directive's line in the importing file.
118
+ *
119
+ * Rendering classifies each block over its enclosing conditions, so a renderer
120
+ * must treat these as errors too: without them it would enumerate every
121
+ * scenario of a block this reports.
122
+ */
123
+ export function importCombinationProblems(document, variables) {
124
+ const problems = [];
125
+ const walk = (nodes, state) => {
126
+ for (const node of nodes) {
127
+ if (node.kind === "text")
128
+ continue;
129
+ if (node.kind === "import") {
130
+ walk(node.children, {
131
+ file: node.file ?? state.file,
132
+ origin: { file: state.file, line: node.line },
133
+ foreign: new Set([...state.foreign, ...state.local]),
134
+ local: new Set(),
135
+ });
136
+ continue;
137
+ }
138
+ const own = node.kind === "when" ? conditionVariables(node.condition) : new Set([node.variable]);
139
+ const local = new Set([...state.local, ...own]);
140
+ const all = new Set([...state.foreign, ...local]);
141
+ if (state.origin !== undefined) {
142
+ const count = combinations(all, variables);
143
+ if (count > MAX_COMBINATIONS && combinations(local, variables) <= MAX_COMBINATIONS) {
144
+ problems.push({
145
+ level: "error",
146
+ file: state.origin.file,
147
+ line: state.origin.line,
148
+ message: `Condition on line ${node.line} of ${state.file} spans too many combinations here: ${count} over ${[...all].join(", ")}; the limit is ${MAX_COMBINATIONS}`,
149
+ fix: "Import it outside the enclosing blocks, or split the condition",
150
+ });
151
+ }
152
+ }
153
+ const children = node.kind === "when" ? node.children : node.branches.flatMap((branch) => branch.children);
154
+ walk(children, { ...state, local });
155
+ }
156
+ };
157
+ walk(document.nodes, { file: document.file, foreign: new Set(), local: new Set() });
158
+ return problems;
159
+ }
160
+ /**
161
+ * Keeps one problem per file, line and message, so a partial imported by several
162
+ * files reports each of its own problems once.
163
+ */
164
+ function dedupeProblems(problems) {
165
+ const seen = new Set();
166
+ return problems.filter((problem) => {
167
+ const key = `${problem.file}\u0000${problem.line ?? 0}\u0000${problem.message}`;
168
+ if (seen.has(key))
169
+ return false;
170
+ seen.add(key);
171
+ return true;
172
+ });
173
+ }
174
+ /**
175
+ * The `skills` checks that need the loaded factory: each entry names a skill,
176
+ * and no workflow the pipeline names carries one, because the pipeline is the
177
+ * same for every developer and must name installed workflows.
178
+ */
179
+ function conditionalSkillProblems(factory) {
180
+ const yaml = factory.factoryYaml;
181
+ if (yaml === undefined)
182
+ return [];
183
+ const problems = [];
184
+ const names = factory.skills.map((skill) => skill.name);
185
+ const pipeline = new Set(yaml.pipeline.map((entry) => entry.workflow));
186
+ for (const entry of yaml.skills) {
187
+ if (!names.includes(entry.name)) {
188
+ problems.push({
189
+ level: "error",
190
+ file: FACTORY_FILE,
191
+ line: entry.line,
192
+ message: `skills names unknown skill "${entry.name}"`,
193
+ fix: didYouMean(entry.name, names) ??
194
+ (names.length === 0
195
+ ? "Remove the entry, or add the skill under .factory/skills/"
196
+ : `Use one of: ${names.join(", ")}`),
197
+ });
198
+ continue;
199
+ }
200
+ if (pipeline.has(entry.name)) {
201
+ problems.push({
202
+ level: "error",
203
+ file: FACTORY_FILE,
204
+ line: entry.line,
205
+ message: `"${entry.name}" is in the pipeline, so it cannot have a skills entry`,
206
+ fix: "Remove the entry: the pipeline names installed workflows for everyone",
207
+ });
208
+ }
209
+ }
210
+ return problems;
211
+ }
212
+ //# sourceMappingURL=validate.js.map