@hawkeyexl/manni 4.11.0 → 4.12.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 (238) hide show
  1. package/README.md +1 -1
  2. package/dist/{batch-UAULUMGH.js → batch-KMGZMIAQ.js} +20 -19
  3. package/dist/build-NO4AWCYG.js +36 -0
  4. package/dist/calibrate-XQUG5XAK.js +41 -0
  5. package/dist/capture-5XE3ZMXK.js +38 -0
  6. package/dist/{check-YEOYBFST.js → check-HTNPLWOV.js} +19 -18
  7. package/dist/check-RJ45IBA6.js +34 -0
  8. package/dist/{check-VELUQAUW.js → check-W24BQNCT.js} +35 -34
  9. package/dist/{check-VELUQAUW.js.map → check-W24BQNCT.js.map} +1 -1
  10. package/dist/check-WFXSXICD.js +30 -0
  11. package/dist/{chunk-IGSHYP74.js → chunk-23P7KMJM.js} +4 -4
  12. package/dist/{chunk-HA6MQMOY.js → chunk-24J7TYPU.js} +6 -6
  13. package/dist/{chunk-PCS4VJBV.js → chunk-37QJLVS3.js} +9 -9
  14. package/dist/{chunk-4CK6ZSOK.js → chunk-3P6KCU36.js} +3 -3
  15. package/dist/{chunk-54F74XR3.js → chunk-5JBVFWVP.js} +19 -19
  16. package/dist/{chunk-B7XYNRJQ.js → chunk-6KIYVVKL.js} +2 -2
  17. package/dist/{chunk-J6IDQGJL.js → chunk-6TVH4FI7.js} +469 -85
  18. package/dist/chunk-6TVH4FI7.js.map +1 -0
  19. package/dist/{chunk-GDVZ5VII.js → chunk-7A452BPZ.js} +4 -4
  20. package/dist/{chunk-M42DZCOU.js → chunk-7FCLXEAQ.js} +2 -2
  21. package/dist/{chunk-2MJ62AYQ.js → chunk-7MCQHTQ5.js} +4 -3
  22. package/dist/chunk-7MCQHTQ5.js.map +1 -0
  23. package/dist/{chunk-LBSCW232.js → chunk-7NXPQKSB.js} +7 -7
  24. package/dist/{chunk-OPXWPJDA.js → chunk-A3TEDWBZ.js} +14 -14
  25. package/dist/{chunk-BBT6AVUG.js → chunk-BHHXU2D2.js} +2 -2
  26. package/dist/{chunk-D4N2V43Z.js → chunk-CEI2J42X.js} +13 -7
  27. package/dist/chunk-CEI2J42X.js.map +1 -0
  28. package/dist/{chunk-FQXWVS6J.js → chunk-CMMBWHT2.js} +9 -9
  29. package/dist/{chunk-EIFCP6CZ.js → chunk-CO47QJKZ.js} +2 -2
  30. package/dist/{chunk-2DRHT73U.js → chunk-CVZMKWZ5.js} +913 -1398
  31. package/dist/chunk-CVZMKWZ5.js.map +1 -0
  32. package/dist/{chunk-ADMEPUBT.js → chunk-CXWTNT2O.js} +3 -3
  33. package/dist/{chunk-LKP7QDFN.js → chunk-DAQTRAP5.js} +4 -4
  34. package/dist/chunk-DSWKBZWW.js +16 -0
  35. package/dist/chunk-DSWKBZWW.js.map +1 -0
  36. package/dist/{chunk-PWBH7DCQ.js → chunk-EESH6COU.js} +4 -4
  37. package/dist/{chunk-JPQDNYXH.js → chunk-EM67O2ET.js} +8 -2
  38. package/dist/chunk-EM67O2ET.js.map +1 -0
  39. package/dist/{chunk-HQR2ZBHW.js → chunk-I2XQRRP7.js} +36 -7
  40. package/dist/chunk-I2XQRRP7.js.map +1 -0
  41. package/dist/{chunk-NCPWXHDO.js → chunk-JEUFYSFQ.js} +4 -4
  42. package/dist/{chunk-2IR4T5PO.js → chunk-JJ4RSDSY.js} +2 -2
  43. package/dist/chunk-KCB5JCK4.js +2272 -0
  44. package/dist/chunk-KCB5JCK4.js.map +1 -0
  45. package/dist/{chunk-VSEBFHAY.js → chunk-KFKL4VTL.js} +11369 -10218
  46. package/dist/chunk-KFKL4VTL.js.map +1 -0
  47. package/dist/{chunk-PCQ7ELJH.js → chunk-L2TD7DZB.js} +109 -5
  48. package/dist/chunk-L2TD7DZB.js.map +1 -0
  49. package/dist/{chunk-WDWXAYVH.js → chunk-L3RLGGRK.js} +4 -4
  50. package/dist/{chunk-T7JAOYE5.js → chunk-L75CAZG4.js} +6 -6
  51. package/dist/{chunk-U7CTFN2J.js → chunk-MYRPMSOX.js} +7 -7
  52. package/dist/{chunk-Y6DOMTQD.js → chunk-NCF5NQV5.js} +27 -27
  53. package/dist/chunk-NCF5NQV5.js.map +1 -0
  54. package/dist/{chunk-WQWKYAAK.js → chunk-NUQF5F5J.js} +2 -2
  55. package/dist/{chunk-FUCPZVRY.js → chunk-OEN6FBUW.js} +2 -2
  56. package/dist/{chunk-FBMZJEB3.js → chunk-OKMTUAWO.js} +4 -4
  57. package/dist/{chunk-QLWC7MKD.js → chunk-OTJOBZJ5.js} +135 -135
  58. package/dist/chunk-OTJOBZJ5.js.map +1 -0
  59. package/dist/{chunk-R4WXQIOZ.js → chunk-PCEM5FOZ.js} +3 -3
  60. package/dist/{chunk-4D5IZSXM.js → chunk-PXNCRGUL.js} +3 -3
  61. package/dist/chunk-Q2QC5AZB.js +1868 -0
  62. package/dist/chunk-Q2QC5AZB.js.map +1 -0
  63. package/dist/{chunk-ODRPL3WB.js → chunk-Q3ODX5PF.js} +2 -2
  64. package/dist/{chunk-KGEQJ5CC.js → chunk-RRFFUWDL.js} +8 -8
  65. package/dist/{chunk-NSBXVPZL.js → chunk-S3XUYW5K.js} +17 -17
  66. package/dist/{chunk-LPIF5LIE.js → chunk-SAU2WQFC.js} +2 -2
  67. package/dist/{chunk-MSRU4D4P.js → chunk-SFLICIQV.js} +2 -2
  68. package/dist/{chunk-NGTVREIH.js → chunk-U6IHLEWT.js} +2 -2
  69. package/dist/{chunk-QCHVR4ZM.js → chunk-VM7VAFJW.js} +33 -7
  70. package/dist/chunk-VM7VAFJW.js.map +1 -0
  71. package/dist/{chunk-6HWBRZIN.js → chunk-VQYGLU4C.js} +252 -193
  72. package/dist/chunk-VQYGLU4C.js.map +1 -0
  73. package/dist/{chunk-2IAZEB45.js → chunk-WGMFDG6U.js} +229 -821
  74. package/dist/chunk-WGMFDG6U.js.map +1 -0
  75. package/dist/{chunk-GV56WGL2.js → chunk-WO4JYWZK.js} +1036 -883
  76. package/dist/chunk-WO4JYWZK.js.map +1 -0
  77. package/dist/chunk-XYRUDFKS.js +685 -0
  78. package/dist/chunk-XYRUDFKS.js.map +1 -0
  79. package/dist/{chunk-VQK4VHLF.js → chunk-YQV75FIL.js} +2 -2
  80. package/dist/chunk-YUTVAMWW.js +2 -0
  81. package/dist/{chunk-RLT5SEML.js → chunk-Z5MZCCTT.js} +6 -6
  82. package/dist/{chunk-BKVHX6FU.js → chunk-ZIRBFXDW.js} +5 -10
  83. package/dist/chunk-ZIRBFXDW.js.map +1 -0
  84. package/dist/{cli-O4ABTN4Z.js → cli-236TGVJG.js} +31 -30
  85. package/dist/{cli-O4ABTN4Z.js.map → cli-236TGVJG.js.map} +1 -1
  86. package/dist/{cli-3BTCK4AB.js → cli-3FAPJBEY.js} +27 -26
  87. package/dist/{cli-3BTCK4AB.js.map → cli-3FAPJBEY.js.map} +1 -1
  88. package/dist/{cli-JJMOVIKS.js → cli-BS43EVCD.js} +14 -14
  89. package/dist/{cli-RORDPAPE.js → cli-CMR4FYF6.js} +59 -38
  90. package/dist/cli-CMR4FYF6.js.map +1 -0
  91. package/dist/{cli-ONTC5PKT.js → cli-FX53PBQ3.js} +9 -9
  92. package/dist/{cli-6KZTHWGP.js → cli-IQNJLKSN.js} +37 -36
  93. package/dist/{cli-6KZTHWGP.js.map → cli-IQNJLKSN.js.map} +1 -1
  94. package/dist/{cli-4MF37HAQ.js → cli-KOMXVPXX.js} +26 -25
  95. package/dist/{cli-4MF37HAQ.js.map → cli-KOMXVPXX.js.map} +1 -1
  96. package/dist/{cli-I62SRH3R.js → cli-NGL63E53.js} +14 -13
  97. package/dist/{cli-DRMZBZLB.js → cli-QPGS2MR5.js} +43 -42
  98. package/dist/{cli-DRMZBZLB.js.map → cli-QPGS2MR5.js.map} +1 -1
  99. package/dist/{cli-VID7PJS3.js → cli-RKQX4TI3.js} +23 -22
  100. package/dist/{cli-VID7PJS3.js.map → cli-RKQX4TI3.js.map} +1 -1
  101. package/dist/{cli-VUKMWSSF.js → cli-WNEI5L7P.js} +4 -4
  102. package/dist/cli.js +19 -13
  103. package/dist/cli.js.map +1 -1
  104. package/dist/{config-XDA42RJL.js → config-JJW75SBX.js} +5 -5
  105. package/dist/docmeta.js +13 -12
  106. package/dist/docmeta.js.map +1 -1
  107. package/dist/github-4UR67MEN.js +35 -0
  108. package/dist/github-UPGKMVVF.js +30 -0
  109. package/dist/graph/runtime.d.ts +4 -1
  110. package/dist/graph/runtime.js +20 -9
  111. package/dist/graph/runtime.js.map +1 -1
  112. package/dist/{host-6GURH5HE.js → host-YSTYO5DX.js} +3 -3
  113. package/dist/index.d.ts +192 -26
  114. package/dist/index.js +129 -124
  115. package/dist/index.js.map +1 -1
  116. package/dist/{json-BXY44ED7.js → json-DQIELR36.js} +18 -17
  117. package/dist/labels-XSTJJMSG.js +73 -0
  118. package/dist/labels-XSTJJMSG.js.map +1 -0
  119. package/dist/lint-BLBGGOYM.js +34 -0
  120. package/dist/list-B3RRRWFQ.js +32 -0
  121. package/dist/list-ZFRT3JQH.js +35 -0
  122. package/dist/{page-EV7OUBAU.js → page-5ISEVJR5.js} +18 -16
  123. package/dist/{prepare-JHJDJB6I.js → prepare-KFXXG2CJ.js} +22 -21
  124. package/dist/{prepare-JHJDJB6I.js.map → prepare-KFXXG2CJ.js.map} +1 -1
  125. package/dist/{pretty-Q5Y2PA64.js → pretty-Y7CGQLAF.js} +18 -17
  126. package/dist/{pretty-SCRK66M5.js → pretty-ZISH3Q4F.js} +18 -17
  127. package/dist/{provider-527CO4DM.js → provider-LBX4IXGX.js} +3 -3
  128. package/dist/{release-3D5PK6M7.js → release-VV3UTKE5.js} +3 -3
  129. package/dist/{reporters-M6LJ2IYU.js → reporters-26H3N2KW.js} +3 -3
  130. package/dist/{reporters-A5ADKDYR.js → reporters-4STXJJE2.js} +16 -15
  131. package/dist/{reporters-RBYTASMI.js → reporters-74B4U2GZ.js} +7 -7
  132. package/dist/run-DVGTKM52.js +37 -0
  133. package/dist/{term-CQAGNG3Q.js → term-PLJEYJQV.js} +981 -141
  134. package/dist/term-PLJEYJQV.js.map +1 -0
  135. package/dist/validate-CJNFQHMD.js +19 -0
  136. package/package.json +3 -2
  137. package/plugin/manni/.claude-plugin/plugin.json +1 -1
  138. package/shapes/graph/shapes-1.1.0.ttl +785 -0
  139. package/dist/build-QSPNK5AL.js +0 -35
  140. package/dist/calibrate-KXN4URPM.js +0 -40
  141. package/dist/capture-JHTSUPUC.js +0 -37
  142. package/dist/check-MDGXEUWL.js +0 -20
  143. package/dist/check-WOQRKNZK.js +0 -29
  144. package/dist/chunk-2DRHT73U.js.map +0 -1
  145. package/dist/chunk-2IAZEB45.js.map +0 -1
  146. package/dist/chunk-2MJ62AYQ.js.map +0 -1
  147. package/dist/chunk-4VBSTXN6.js +0 -392
  148. package/dist/chunk-4VBSTXN6.js.map +0 -1
  149. package/dist/chunk-6HWBRZIN.js.map +0 -1
  150. package/dist/chunk-BKVHX6FU.js.map +0 -1
  151. package/dist/chunk-D4N2V43Z.js.map +0 -1
  152. package/dist/chunk-EFW7CAG4.js +0 -387
  153. package/dist/chunk-EFW7CAG4.js.map +0 -1
  154. package/dist/chunk-GV56WGL2.js.map +0 -1
  155. package/dist/chunk-HQR2ZBHW.js.map +0 -1
  156. package/dist/chunk-J6IDQGJL.js.map +0 -1
  157. package/dist/chunk-JPQDNYXH.js.map +0 -1
  158. package/dist/chunk-JROBZ7JA.js +0 -818
  159. package/dist/chunk-JROBZ7JA.js.map +0 -1
  160. package/dist/chunk-PCQ7ELJH.js.map +0 -1
  161. package/dist/chunk-QCHVR4ZM.js.map +0 -1
  162. package/dist/chunk-QLWC7MKD.js.map +0 -1
  163. package/dist/chunk-TU2WUBVZ.js +0 -2
  164. package/dist/chunk-VSEBFHAY.js.map +0 -1
  165. package/dist/chunk-Y6DOMTQD.js.map +0 -1
  166. package/dist/cli-RORDPAPE.js.map +0 -1
  167. package/dist/github-RY3FRA6P.js +0 -29
  168. package/dist/github-YKQSH7FS.js +0 -34
  169. package/dist/lint-YJ2L22BW.js +0 -33
  170. package/dist/list-NSG24VVX.js +0 -31
  171. package/dist/list-V6EGCSHX.js +0 -34
  172. package/dist/run-BUE2DDXN.js +0 -36
  173. package/dist/term-CQAGNG3Q.js.map +0 -1
  174. package/dist/validate-ZBW44RHT.js +0 -18
  175. /package/dist/{batch-UAULUMGH.js.map → batch-KMGZMIAQ.js.map} +0 -0
  176. /package/dist/{build-QSPNK5AL.js.map → build-NO4AWCYG.js.map} +0 -0
  177. /package/dist/{calibrate-KXN4URPM.js.map → calibrate-XQUG5XAK.js.map} +0 -0
  178. /package/dist/{capture-JHTSUPUC.js.map → capture-5XE3ZMXK.js.map} +0 -0
  179. /package/dist/{check-MDGXEUWL.js.map → check-HTNPLWOV.js.map} +0 -0
  180. /package/dist/{check-WOQRKNZK.js.map → check-RJ45IBA6.js.map} +0 -0
  181. /package/dist/{check-YEOYBFST.js.map → check-WFXSXICD.js.map} +0 -0
  182. /package/dist/{chunk-IGSHYP74.js.map → chunk-23P7KMJM.js.map} +0 -0
  183. /package/dist/{chunk-HA6MQMOY.js.map → chunk-24J7TYPU.js.map} +0 -0
  184. /package/dist/{chunk-PCS4VJBV.js.map → chunk-37QJLVS3.js.map} +0 -0
  185. /package/dist/{chunk-4CK6ZSOK.js.map → chunk-3P6KCU36.js.map} +0 -0
  186. /package/dist/{chunk-54F74XR3.js.map → chunk-5JBVFWVP.js.map} +0 -0
  187. /package/dist/{chunk-B7XYNRJQ.js.map → chunk-6KIYVVKL.js.map} +0 -0
  188. /package/dist/{chunk-GDVZ5VII.js.map → chunk-7A452BPZ.js.map} +0 -0
  189. /package/dist/{chunk-M42DZCOU.js.map → chunk-7FCLXEAQ.js.map} +0 -0
  190. /package/dist/{chunk-LBSCW232.js.map → chunk-7NXPQKSB.js.map} +0 -0
  191. /package/dist/{chunk-OPXWPJDA.js.map → chunk-A3TEDWBZ.js.map} +0 -0
  192. /package/dist/{chunk-BBT6AVUG.js.map → chunk-BHHXU2D2.js.map} +0 -0
  193. /package/dist/{chunk-FQXWVS6J.js.map → chunk-CMMBWHT2.js.map} +0 -0
  194. /package/dist/{chunk-EIFCP6CZ.js.map → chunk-CO47QJKZ.js.map} +0 -0
  195. /package/dist/{chunk-ADMEPUBT.js.map → chunk-CXWTNT2O.js.map} +0 -0
  196. /package/dist/{chunk-LKP7QDFN.js.map → chunk-DAQTRAP5.js.map} +0 -0
  197. /package/dist/{chunk-PWBH7DCQ.js.map → chunk-EESH6COU.js.map} +0 -0
  198. /package/dist/{chunk-NCPWXHDO.js.map → chunk-JEUFYSFQ.js.map} +0 -0
  199. /package/dist/{chunk-2IR4T5PO.js.map → chunk-JJ4RSDSY.js.map} +0 -0
  200. /package/dist/{chunk-WDWXAYVH.js.map → chunk-L3RLGGRK.js.map} +0 -0
  201. /package/dist/{chunk-T7JAOYE5.js.map → chunk-L75CAZG4.js.map} +0 -0
  202. /package/dist/{chunk-U7CTFN2J.js.map → chunk-MYRPMSOX.js.map} +0 -0
  203. /package/dist/{chunk-WQWKYAAK.js.map → chunk-NUQF5F5J.js.map} +0 -0
  204. /package/dist/{chunk-FUCPZVRY.js.map → chunk-OEN6FBUW.js.map} +0 -0
  205. /package/dist/{chunk-FBMZJEB3.js.map → chunk-OKMTUAWO.js.map} +0 -0
  206. /package/dist/{chunk-R4WXQIOZ.js.map → chunk-PCEM5FOZ.js.map} +0 -0
  207. /package/dist/{chunk-4D5IZSXM.js.map → chunk-PXNCRGUL.js.map} +0 -0
  208. /package/dist/{chunk-ODRPL3WB.js.map → chunk-Q3ODX5PF.js.map} +0 -0
  209. /package/dist/{chunk-KGEQJ5CC.js.map → chunk-RRFFUWDL.js.map} +0 -0
  210. /package/dist/{chunk-NSBXVPZL.js.map → chunk-S3XUYW5K.js.map} +0 -0
  211. /package/dist/{chunk-LPIF5LIE.js.map → chunk-SAU2WQFC.js.map} +0 -0
  212. /package/dist/{chunk-MSRU4D4P.js.map → chunk-SFLICIQV.js.map} +0 -0
  213. /package/dist/{chunk-NGTVREIH.js.map → chunk-U6IHLEWT.js.map} +0 -0
  214. /package/dist/{chunk-VQK4VHLF.js.map → chunk-YQV75FIL.js.map} +0 -0
  215. /package/dist/{chunk-TU2WUBVZ.js.map → chunk-YUTVAMWW.js.map} +0 -0
  216. /package/dist/{chunk-RLT5SEML.js.map → chunk-Z5MZCCTT.js.map} +0 -0
  217. /package/dist/{cli-JJMOVIKS.js.map → cli-BS43EVCD.js.map} +0 -0
  218. /package/dist/{cli-ONTC5PKT.js.map → cli-FX53PBQ3.js.map} +0 -0
  219. /package/dist/{cli-I62SRH3R.js.map → cli-NGL63E53.js.map} +0 -0
  220. /package/dist/{cli-VUKMWSSF.js.map → cli-WNEI5L7P.js.map} +0 -0
  221. /package/dist/{config-XDA42RJL.js.map → config-JJW75SBX.js.map} +0 -0
  222. /package/dist/{github-RY3FRA6P.js.map → github-4UR67MEN.js.map} +0 -0
  223. /package/dist/{github-YKQSH7FS.js.map → github-UPGKMVVF.js.map} +0 -0
  224. /package/dist/{host-6GURH5HE.js.map → host-YSTYO5DX.js.map} +0 -0
  225. /package/dist/{json-BXY44ED7.js.map → json-DQIELR36.js.map} +0 -0
  226. /package/dist/{lint-YJ2L22BW.js.map → lint-BLBGGOYM.js.map} +0 -0
  227. /package/dist/{list-NSG24VVX.js.map → list-B3RRRWFQ.js.map} +0 -0
  228. /package/dist/{list-V6EGCSHX.js.map → list-ZFRT3JQH.js.map} +0 -0
  229. /package/dist/{page-EV7OUBAU.js.map → page-5ISEVJR5.js.map} +0 -0
  230. /package/dist/{pretty-Q5Y2PA64.js.map → pretty-Y7CGQLAF.js.map} +0 -0
  231. /package/dist/{pretty-SCRK66M5.js.map → pretty-ZISH3Q4F.js.map} +0 -0
  232. /package/dist/{provider-527CO4DM.js.map → provider-LBX4IXGX.js.map} +0 -0
  233. /package/dist/{release-3D5PK6M7.js.map → release-VV3UTKE5.js.map} +0 -0
  234. /package/dist/{reporters-A5ADKDYR.js.map → reporters-26H3N2KW.js.map} +0 -0
  235. /package/dist/{reporters-M6LJ2IYU.js.map → reporters-4STXJJE2.js.map} +0 -0
  236. /package/dist/{reporters-RBYTASMI.js.map → reporters-74B4U2GZ.js.map} +0 -0
  237. /package/dist/{run-BUE2DDXN.js.map → run-DVGTKM52.js.map} +0 -0
  238. /package/dist/{validate-ZBW44RHT.js.map → validate-CJNFQHMD.js.map} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/shared/cli-options.ts","../src/meta/core/external-metadata-fetch.ts","../src/shared/encryption-key.ts","../src/shared/write-file.ts","../src/meta/core/encrypted.ts","../src/meta/core/external-metadata.ts","../src/shared/manifest-cas.ts","../src/meta/core/location.ts","../src/meta/core/graph-output.ts","../src/meta/core/validator.ts","../src/meta/core/page-marks.ts","../src/meta/core/projection.ts","../src/meta/core/collections.ts","../src/meta/core/relocation.ts","../src/meta/core/external-metadata-write.ts","../src/shared/pin.ts","../src/meta/core/derive/provenance.ts"],"sourcesContent":["/**\n * Option plumbing every tool's commander wrapper needs.\n *\n * These are the pieces of `src/meta/cli.ts` that had nothing to do with\n * metadata: how a repeatable flag accumulates, how a comma list splits, how\n * stdin is drained, how `-c`/`--no-config` share one attribute, and how a\n * `--no-<thing>` flag is kept from clobbering a config value it never meant to\n * touch. A sibling tool that re-derived any of these would get one of them\n * subtly different, and \"commands must have parallel behaviors\" is the rule\n * that says it must not.\n */\nimport { basename, relative } from \"node:path\";\n\n/** Accumulate a repeatable option (`--exclude a --exclude b`). */\nexport function collect(value: string, prev: string[]): string[] {\n return prev.concat([value]);\n}\n\n/** Split a comma-separated option value, dropping blanks. */\nexport function splitList(value: string): string[] {\n return value\n .split(\",\")\n .map((s) => s.trim())\n .filter(Boolean);\n}\n\n/**\n * What a run that reads `-` without `--as` is told. Stdin has no file name to\n * pick a parser by, so the user names the format. One sentence for every tool\n * that reads stdin, so the refusal reads the same wherever it is hit.\n */\nexport const STDIN_REQUIRES_AS =\n \"Reading from stdin (`-`) requires --as <format> to choose an extractor.\";\n\n/** Drain stdin to a UTF-8 string. */\nexport async function readStdin(): Promise<string> {\n const chunks: Buffer[] = [];\n for await (const chunk of process.stdin) chunks.push(chunk as Buffer);\n return Buffer.concat(chunks).toString(\"utf8\");\n}\n\n/**\n * Split the one commander attribute that `-c, --config <path>` and\n * `--no-config` share. Verified by experiment: `opts.config` is `undefined`\n * with neither flag, the string with `-c`, and `false` with `--no-config`.\n */\nexport function configOption(value: unknown): {\n configPath?: string;\n noConfig?: boolean;\n} {\n if (value === false) return { noConfig: true };\n return typeof value === \"string\" ? { configPath: value } : {};\n}\n\n/**\n * A `--no-<thing>` flag for the core: only an explicit false travels.\n *\n * Commander gives `true` when the flag is absent, but that is its *default*,\n * not a choice the user made — passing it on would override the config's own\n * answer (`respectGitignore:`, say). Only the explicit `false` travels; absence\n * stays `undefined` so config still decides.\n */\nexport function explicitFalse(value: unknown): boolean | undefined {\n return value === false ? false : undefined;\n}\n\n/**\n * Say which config governed the run, and where it came from.\n *\n * Discovery walks up to the project boundary, so the answer is no longer\n * obvious from the working directory, and an unexpected ancestor config is the\n * difference between a five-minute diagnosis and an hour of confusion. Goes to\n * stderr for anything a machine reads, so structured output stays parseable.\n */\nexport function reportConfig(\n toStdout: boolean,\n cwd: string,\n): (info: { path: string; dir: string }) => void {\n return (info) => {\n const where = (relative(cwd, info.dir) || \".\").replace(/\\\\/g, \"/\");\n const line = `Using ${basename(info.path)} (${where})\\n`;\n (toStdout ? process.stdout : process.stderr).write(line);\n };\n}\n","/**\n * Fetch a remote manifest (proposal 0038).\n *\n * A manifest named by URL is fetched at the start of every run and never\n * cached: it is data that changes with every page, and a stale copy validates\n * the corpus against the wrong values. The bounds are the schema fetch's —\n * the same timeout, the same body cap, one narrow retry — because they exist\n * for the same reason there (0008 § stress test 4), and a manifest is\n * smaller than most schemas.\n *\n * The credential, when there is one, comes from the environment and is sent\n * as a bearer token to the origin the config named and nowhere else. It\n * never appears in a message: every error here names the URL and the status,\n * and the URL was checked at config time to carry no userinfo.\n */\nimport { DocmetaError } from \"../types.js\";\n\n/** Default network timeout, matching the schema fetch. */\nexport const EXTERNAL_METADATA_FETCH_TIMEOUT_MS = 10_000;\n\n/** Body cap, matching the schema fetch. */\nexport const EXTERNAL_METADATA_FETCH_MAX_BYTES = 5 * 1024 * 1024;\n\n/** Redirects followed before giving up. */\nconst MAX_REDIRECTS = 5;\n\n/** Backoff before the single retry. */\nconst RETRY_DELAY_MS = 500;\n\nexport interface ExternalMetadataFetchOptions {\n /** Environment variable holding a bearer token. Absent means an anonymous request. */\n tokenEnv?: string;\n timeoutMs?: number;\n maxBytes?: number;\n /** `--offline` / `offline:`: refuse rather than fetch. */\n offline?: boolean;\n /** For tests: the environment to read `tokenEnv` from. Defaults to `process.env`. */\n env?: Record<string, string | undefined>;\n}\n\n/** Fetch one remote manifest. Resolves to its text; throws `DocmetaError`. */\nexport async function fetchExternalMetadata(\n url: string,\n opts: ExternalMetadataFetchOptions = {},\n): Promise<string> {\n if (opts.offline) {\n throw new DocmetaError(\n `Manifest ${url} is remote and the run is offline. Vendor it to a path, or drop --offline.`,\n );\n }\n const timeoutMs = opts.timeoutMs ?? EXTERNAL_METADATA_FETCH_TIMEOUT_MS;\n const maxBytes = opts.maxBytes ?? EXTERNAL_METADATA_FETCH_MAX_BYTES;\n const env = opts.env ?? process.env;\n let token: string | undefined;\n if (opts.tokenEnv !== undefined) {\n token = env[opts.tokenEnv];\n if (token === undefined || token === \"\") {\n throw new DocmetaError(\n `Manifest ${url}: the environment variable ${opts.tokenEnv} named by \"tokenEnv\" is not set.`,\n );\n }\n }\n\n let res = await requestWithRedirects(url, token, timeoutMs);\n // One retry, on the failures that can heal: a network error or a 5xx. A\n // 4xx will not, and retrying it only doubles the time to the same answer.\n if (res instanceof Error || res.status >= 500) {\n await new Promise((r) => setTimeout(r, RETRY_DELAY_MS));\n res = await requestWithRedirects(url, token, timeoutMs);\n }\n if (res instanceof Error) {\n throw new DocmetaError(\n `Manifest ${url} could not be fetched: ${res.message}`,\n );\n }\n if (!res.ok) {\n const hint =\n res.status === 404 && token === undefined\n ? \" (a private file answers 404 without a token; set \\\"tokenEnv\\\")\"\n : res.status === 404\n ? \" (a private file answers 404 without a valid token)\"\n : \"\";\n throw new DocmetaError(\n `Manifest ${url} could not be fetched: HTTP ${res.status}${hint}.`,\n );\n }\n return readCapped(url, res, maxBytes);\n}\n\n/**\n * GET with manual redirect handling, so the bearer token follows only a\n * same-origin redirect. A cross-origin hop is followed without it, the way\n * browsers and curl behave; if the manifest lives where the token does not\n * reach, the 401 that results is reported rather than the token leaked.\n *\n * Resolves to the final `Response`, or to the `Error` a network failure or\n * timeout raised, so the caller can decide what to retry.\n */\nasync function requestWithRedirects(\n url: string,\n token: string | undefined,\n timeoutMs: number,\n): Promise<Response | Error> {\n const origin = new URL(url).origin;\n let current = url;\n for (let hop = 0; hop <= MAX_REDIRECTS; hop++) {\n const sameOrigin = new URL(current).origin === origin;\n const headers: Record<string, string> = { accept: \"text/plain, application/x-yaml, */*\" };\n if (token !== undefined && sameOrigin) headers.authorization = `Bearer ${token}`;\n let res: Response;\n try {\n res = await fetch(current, {\n headers,\n redirect: \"manual\",\n signal: AbortSignal.timeout(timeoutMs),\n });\n } catch (err) {\n const isAbort = err instanceof Error && err.name === \"TimeoutError\";\n return isAbort\n ? new Error(`timed out after ${timeoutMs}ms`)\n : new Error(err instanceof Error ? err.message : String(err));\n }\n if (res.status >= 300 && res.status < 400) {\n const location = res.headers.get(\"location\");\n if (location === null) return res;\n await res.body?.cancel();\n current = new URL(location, current).toString();\n continue;\n }\n return res;\n }\n return new Error(`more than ${MAX_REDIRECTS} redirects`);\n}\n\n/** Read a body, aborting once it exceeds `maxBytes`; content-length is advisory. */\nasync function readCapped(\n url: string,\n res: Response,\n maxBytes: number,\n): Promise<string> {\n const body = res.body;\n if (!body) return \"\";\n // `Response.body` is typed `ReadableStream<any>`; name the chunk type once\n // at the boundary, as the schema fetch does, so the cap is counted in\n // numbers rather than `any` arithmetic.\n const reader = body.getReader() as ReadableStreamDefaultReader<Uint8Array>;\n const chunks: Uint8Array[] = [];\n let total = 0;\n for (;;) {\n const { done, value }: { done: boolean; value?: Uint8Array } =\n await reader.read();\n if (done || value === undefined) break;\n total += value.byteLength;\n if (total > maxBytes) {\n await reader.cancel();\n throw new DocmetaError(\n `Manifest ${url} is too large: the response exceeds the ${maxBytes}-byte limit.`,\n );\n }\n chunks.push(value);\n }\n return Buffer.concat(chunks).toString(\"utf8\");\n}\n","/**\n * The family encryption key (proposal 0045): where a run finds it, where a\n * write puts it, and whether git would publish it.\n *\n * One key for the family, at the top of `manni.config.yaml` beside\n * `collections:`, read by every tool. `MANNI_ENCRYPTION_KEY` in the\n * environment wins over it, which is the right home for a shared repository:\n * a key committed with the pages decrypts every value on them.\n */\nimport { spawnSync } from \"node:child_process\";\nimport { readFile } from \"node:fs/promises\";\nimport { basename, dirname, join, relative, resolve } from \"node:path\";\nimport { isDeepStrictEqual } from \"node:util\";\nimport { isMap, parseDocument, parse as parseYaml, stringify } from \"yaml\";\nimport {\n ENCRYPTION_KEY_FIELD,\n ENCRYPTION_KEY_PREVIOUS_FIELD,\n FAMILY_CONFIG_NAMES,\n type ConfigFile,\n} from \"./config-file.js\";\nimport { isValidEncryptionKey } from \"./encryption.js\";\nimport { findGitRoot } from \"./git-root.js\";\nimport { writeTextAtomic } from \"./write-file.js\";\n\nexport {\n ENCRYPTION_KEY_FIELD,\n ENCRYPTION_KEY_PREVIOUS_FIELD,\n findFamilyConfigFile,\n readFamilyConfigFile,\n} from \"./config-file.js\";\n\n/** The environment variable that wins over the config's key. */\nexport const ENCRYPTION_KEY_ENV = \"MANNI_ENCRYPTION_KEY\";\n\nexport type KeySource = \"env\" | \"config\" | \"none\";\n\nexport interface ResolvedKey {\n key: string | undefined;\n source: KeySource;\n}\n\ntype ToError = (message: string) => Error;\n\n/**\n * The key a run uses: the environment's, else the config file's, else none.\n *\n * An empty `MANNI_ENCRYPTION_KEY` counts as unset, because that is what an\n * absent CI secret expands to (a fork's pull request, say), and refusing the\n * run there would fail every such build for a key it was never going to get.\n * A non-empty value of the wrong shape is refused, and never echoed.\n */\nexport function resolveEncryptionKey(opts: {\n env?: NodeJS.ProcessEnv;\n file: ConfigFile | null;\n toError: ToError;\n}): ResolvedKey {\n const env = opts.env ?? process.env;\n const fromEnv = env[ENCRYPTION_KEY_ENV];\n if (fromEnv !== undefined && fromEnv !== \"\") {\n if (!isValidEncryptionKey(fromEnv)) {\n throw opts.toError(\n `${ENCRYPTION_KEY_ENV} must be at least 32 hex or base64url characters.`,\n );\n }\n return { key: fromEnv, source: \"env\" };\n }\n const fromFile = opts.file?.encryptionKey;\n if (fromFile !== undefined) return { key: fromFile, source: \"config\" };\n return { key: undefined, source: \"none\" };\n}\n\ninterface Target {\n path: string;\n source: string;\n /** The file's current text, or `null` when the write creates it. */\n text: string | null;\n}\n\nfunction relativeSource(cwd: string, path: string): string {\n return relative(resolve(cwd), path).replace(/\\\\/g, \"/\");\n}\n\nfunction errorCode(err: unknown): string | undefined {\n return typeof err === \"object\" && err !== null && \"code\" in err\n ? String(err.code)\n : undefined;\n}\n\nasync function readIfPresent(path: string): Promise<string | null> {\n try {\n return await readFile(path, \"utf8\");\n } catch (err) {\n if (errorCode(err) === \"ENOENT\") return null;\n throw err;\n }\n}\n\nasync function fileTarget(file: ConfigFile, toError: ToError): Promise<Target> {\n // A single-tool file's whole document is one tool's section. A top-level\n // `encryptionKey:` would turn it into a family file on the next read, and\n // every key the tool had would stop being read.\n if (file.kind === \"legacy\" || !file.wrapped) {\n throw toError(\n `${file.source} is a single-tool config file, which cannot hold the family ${ENCRYPTION_KEY_FIELD}. Move its keys under the tool's section in ${FAMILY_CONFIG_NAMES[0] ?? \"manni.config.yaml\"}, or set ${ENCRYPTION_KEY_ENV}.`,\n );\n }\n // Re-read rather than trust `file.text`: the file may have changed since\n // discovery, and an edit made in between must not be written over.\n const text = await readIfPresent(file.path);\n return { path: file.path, source: file.source, text: text ?? file.text };\n}\n\n/**\n * With no config for the running tool, the key goes to the git root (else\n * `cwd`), where discovery from anywhere in the repository finds it. A family\n * file already there, one a sibling tool owns, is edited rather than\n * replaced.\n */\nasync function defaultTarget(cwd: string): Promise<Target> {\n const root = findGitRoot(cwd) ?? resolve(cwd);\n for (const name of FAMILY_CONFIG_NAMES) {\n const path = join(root, name);\n const text = await readIfPresent(path);\n if (text !== null) return { path, source: relativeSource(cwd, path), text };\n }\n const path = join(root, FAMILY_CONFIG_NAMES[0] ?? \"manni.config.yaml\");\n return { path, source: relativeSource(cwd, path), text: null };\n}\n\n/**\n * What a write does with `encryptionKeyPrevious:`: a string sets it, `null`\n * removes it, and `undefined` leaves whatever is there.\n */\ntype Previous = string | null | undefined;\n\n/** `text` with the top-level keys set, comments and key order kept. */\nfunction withKey(\n text: string,\n key: string,\n previous: Previous,\n source: string,\n toError: ToError,\n): string {\n const doc = parseDocument(text);\n const [first] = doc.errors;\n if (first !== undefined) {\n throw toError(`${source}: invalid YAML: ${first.message}`);\n }\n if (doc.contents !== null && !isMap(doc.contents)) {\n throw toError(`${source}: top level must be a mapping.`);\n }\n // Replaces an existing key in place, appends a new one, and turns an empty\n // or comment-only document into a one-key mapping.\n doc.set(ENCRYPTION_KEY_FIELD, key);\n if (typeof previous === \"string\") doc.set(ENCRYPTION_KEY_PREVIOUS_FIELD, previous);\n if (previous === null) doc.delete(ENCRYPTION_KEY_PREVIOUS_FIELD);\n return doc.toString();\n}\n\nfunction isMapping(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * Read back what is about to be written: the key, and every other top-level\n * value exactly as it was. A config the tools cannot read, or one that lost a\n * key on the way, is worse than a refused write.\n */\nfunction verify(\n before: string | null,\n after: string,\n key: string,\n previous: Previous,\n source: string,\n toError: ToError,\n): void {\n const old: unknown = before === null ? null : parseYaml(before);\n // Every old key as it was, the key set, and the previous key set, removed\n // or left alone as `previous` says.\n const expected = Object.fromEntries(\n Object.entries({\n ...(isMapping(old) ? old : {}),\n [ENCRYPTION_KEY_FIELD]: key,\n ...(typeof previous === \"string\" ? { [ENCRYPTION_KEY_PREVIOUS_FIELD]: previous } : {}),\n }).filter(([name]) => previous !== null || name !== ENCRYPTION_KEY_PREVIOUS_FIELD),\n );\n const reread: unknown = parseYaml(after);\n if (!isMapping(reread) || !isDeepStrictEqual(reread, expected)) {\n throw toError(\n `Could not write ${ENCRYPTION_KEY_FIELD} to ${source}; add the key by hand.`,\n );\n }\n}\n\n/**\n * Set the top-level `encryptionKey:` and write the file atomically.\n *\n * `file` is the config to write into: the running tool's discovered config,\n * or `findFamilyConfigFile`'s for `manni key`. With `null`, the key goes to\n * the family file at the git root (else `cwd`), created holding only the key\n * when there is none. A single-tool file (legacy, or an explicit `-c` file\n * read whole as one tool's section) is refused. `dryRun` does everything but\n * the write, so a caller can name the target before asking about it.\n *\n * `previous` is for `manni key rotate` alone: a string writes it as\n * `encryptionKeyPrevious:` in the same atomic write as the key, `null`\n * removes it, and omitted leaves the file's own. Never echoed either.\n */\nexport async function writeEncryptionKey(opts: {\n file: ConfigFile | null;\n key: string;\n cwd: string;\n toError: ToError;\n dryRun?: boolean;\n previous?: string | null;\n}): Promise<{ path: string; source: string; created: boolean }> {\n const { file, key, toError, previous } = opts;\n if (!isValidEncryptionKey(key)) {\n throw toError(\n `The ${ENCRYPTION_KEY_FIELD} must be at least 32 hex or base64url characters.`,\n );\n }\n if (typeof previous === \"string\" && !isValidEncryptionKey(previous)) {\n throw toError(\n `The ${ENCRYPTION_KEY_PREVIOUS_FIELD} must be at least 32 hex or base64url characters.`,\n );\n }\n const target =\n file === null ? await defaultTarget(opts.cwd) : await fileTarget(file, toError);\n const text =\n target.text === null\n ? stringify({\n [ENCRYPTION_KEY_FIELD]: key,\n ...(typeof previous === \"string\" ? { [ENCRYPTION_KEY_PREVIOUS_FIELD]: previous } : {}),\n })\n : withKey(target.text, key, previous, target.source, toError);\n verify(target.text, text, key, previous, target.source, toError);\n if (opts.dryRun !== true) await writeTextAtomic(target.path, text);\n return { path: target.path, source: target.source, created: target.text === null };\n}\n\n/**\n * Whether git ignores `path`, which need not exist yet: `git check-ignore -q`.\n * `undefined` when git is absent or the path is not inside a work tree. A\n * tracked file is not ignored, whatever `.gitignore` says, so it is `false`.\n */\nexport function isIgnoredByGit(path: string): boolean | undefined {\n const result = spawnSync(\"git\", [\"check-ignore\", \"-q\", \"--\", basename(path)], {\n cwd: dirname(path),\n stdio: \"ignore\",\n windowsHide: true,\n });\n if (result.error !== undefined) return undefined;\n if (result.status === 0) return true;\n if (result.status === 1) return false;\n return undefined;\n}\n\n/** The warning for a key about to land in a file git would publish. */\nexport const committedKeyWarning = (source: string): string =>\n `${source} is not ignored by git: once committed, anyone who can read the repository can decrypt every encrypted value. Prefer MANNI_ENCRYPTION_KEY for a shared repository.`;\n","/**\n * An atomic text write for the shared layer: a temp file in the target's own\n * directory, then `rename`, so the file holds its old contents or its new\n * ones, never half of each.\n *\n * The metadata tool has a fuller one (`src/meta/core/write-file.ts`: byte\n * payloads, and an in-place fallback when Windows keeps a target locked). The\n * shared layer does not import a tool's module, so this is the small subset\n * the family config writer needs. When a later change moves meta's writer\n * here, this file is what it replaces.\n */\nimport { chmod, rename, rm, stat, writeFile } from \"node:fs/promises\";\nimport { basename, dirname, join } from \"node:path\";\n\n/** Windows returns these while an editor or scanner holds the target open. */\nconst LOCKED = new Set([\"EPERM\", \"EBUSY\", \"EACCES\"]);\nconst RENAME_ATTEMPTS = 3;\n\nfunction errorCode(err: unknown): string | undefined {\n return typeof err === \"object\" && err !== null && \"code\" in err\n ? String(err.code)\n : undefined;\n}\n\nconst wait = (ms: number): Promise<void> =>\n new Promise((resolve) => {\n setTimeout(resolve, ms);\n });\n\n/** Write `text` (UTF-8) to `path`, replacing it atomically. */\nexport async function writeTextAtomic(path: string, text: string): Promise<void> {\n const tmp = join(\n dirname(path),\n `.${basename(path)}.manni-${process.pid}-${Math.random().toString(36).slice(2, 8)}.tmp`,\n );\n try {\n await writeFile(tmp, text, \"utf8\");\n // Keep the target's permissions; a missing target keeps the default mode.\n try {\n const { mode } = await stat(path);\n await chmod(tmp, mode);\n } catch {\n // Creating the file, or its mode is unreadable: keep the default.\n }\n for (let attempt = 1; ; attempt++) {\n try {\n await rename(tmp, path);\n return;\n } catch (err) {\n const code = errorCode(err);\n if (code === undefined || !LOCKED.has(code) || attempt >= RENAME_ATTEMPTS) {\n throw err;\n }\n await wait(attempt * 50);\n }\n }\n } finally {\n await rm(tmp, { force: true });\n }\n}\n","/**\n * `x-manni-encrypt` (proposal 0045): what meta does with a property whose\n * schema says the page must hold its value encrypted.\n *\n * The keyword itself is registered on every Ajv meta builds (validator.ts),\n * where it records the instance pointers it is evaluated at. Ajv's own\n * resolution is the walker, so a mark counts wherever the validator evaluates\n * it: through `$ref`, `allOf` and a referenced built-in, and inside `anyOf`,\n * `oneOf` and `if`/`then` branches Ajv actually takes. This module is what\n * happens next, and is the same for every command:\n *\n * - a marked value the page holds in plain text is a finding\n * (`encrypted:plain`), unless an external-metadata manifest supplied it;\n * - an encrypted one that decrypts under the key is validated as its\n * plaintext, on a copy, and no finding may print that plaintext;\n * - one that does not decrypt is a finding (`encrypted:unreadable`);\n * - with no key, findings at or under it are dropped and counted, and the run\n * says so once.\n *\n * The plaintext never leaves this module except as the copy validation reads\n * and the value a writer is about to encrypt.\n */\nimport type { DerivedField } from \"./derive/types.js\";\nimport type { ConfigFile } from \"../../shared/config-file.js\";\nimport { decryptValue, isEncryptedValue } from \"../../shared/encryption.js\";\nimport {\n ENCRYPTION_KEY_ENV,\n resolveEncryptionKey,\n} from \"../../shared/encryption-key.js\";\nimport { escapePointerSegment } from \"../extractors/pointer.js\";\nimport { DocmetaError, type FieldError } from \"../types.js\";\nimport type { SourceLocation } from \"./external-metadata.js\";\n\n/** The schema keyword. `true` marks a property; `false` or absent does not. */\nexport const ENCRYPT_KEYWORD = \"x-manni-encrypt\";\n\n/**\n * The `schema` of a finding for a plain value in a marked property. Shaped\n * like `external:owned` so `classifyRef` passes it through as a built-in id,\n * and so its rule id is `encrypted:plain/encrypted`.\n */\nexport const ENCRYPTED_PLAIN_SCHEMA = \"encrypted:plain\";\n\n/** The `schema` of a finding for a value that does not decrypt. */\nexport const ENCRYPTED_UNREADABLE_SCHEMA = \"encrypted:unreadable\";\n\n/** The `keyword` both findings carry: no Ajv keyword produced them. */\nexport const ENCRYPTED_KEYWORD = \"encrypted\";\n\n/** What every report prints in place of a value it must not show. */\nexport const ENCRYPTED_PLACEHOLDER = \"(encrypted)\";\n\n/** The encryption context of a metadata value. */\nexport const META_CONTEXT = \"meta\";\n\n/**\n * The refusals encryption adds to a run: a key that will not resolve, a join\n * that cannot be matched, a write with no key. A class of its own so a command\n * that files a document's own errors per file (`fill`) can tell these apart:\n * they are about the run, and exit 2.\n */\nexport class EncryptionRefusal extends DocmetaError {}\n\nexport const plainMessage = (pointer: string): string =>\n `${pointer} holds a plain value; its schema marks it ${ENCRYPT_KEYWORD}.`;\n\nexport const unreadableMessage = (pointer: string): string =>\n `${pointer} does not decrypt under the current key: encrypted under another key, or edited by hand.`;\n\n/** The one run-level warning for values a run could not verify. */\nexport function unverifiedWarning(count: number): string {\n const what =\n count === 1\n ? \"1 encrypted value was not verified\"\n : `${count} encrypted values were not verified`;\n return `${what}: no encryption key is available. Set ${ENCRYPTION_KEY_ENV}, or run \\`manni key set\\`.`;\n}\n\n/** The key a run reads with, or `undefined`; resolved on first use. */\nexport type KeyGetter = () => string | undefined;\n\n/**\n * The run's key, resolved once and only when something needs it: a malformed\n * `MANNI_ENCRYPTION_KEY` is refused by the first run that meets a ciphertext,\n * not by every run in a repository that encrypts nothing.\n */\nexport function lazyKey(\n file: ConfigFile | undefined,\n env: NodeJS.ProcessEnv | undefined,\n): KeyGetter {\n let resolved: { key: string | undefined } | undefined;\n return () => {\n resolved ??= {\n key: resolveEncryptionKey({\n ...(env === undefined ? {} : { env }),\n file: file ?? null,\n toError: (m) => new EncryptionRefusal(m),\n }).key,\n };\n return resolved.key;\n };\n}\n\n// ---------------------------------------------------------------------------\n// Pointers\n// ---------------------------------------------------------------------------\n\n/** The `/key` pointer of a top-level key. */\nexport function pointerOf(key: string): string {\n return `/${escapePointerSegment(key)}`;\n}\n\nfunction segments(pointer: string): string[] {\n if (pointer === \"\") return [];\n return pointer\n .slice(1)\n .split(\"/\")\n .map((s) => s.replace(/~1/g, \"/\").replace(/~0/g, \"~\"));\n}\n\n/** The top-level key a one-segment pointer names; `undefined` otherwise. */\nexport function topLevelKeyOf(pointer: string): string | undefined {\n const parts = segments(pointer);\n return parts.length === 1 ? parts[0] : undefined;\n}\n\n/** Whether `pointer` is `ancestor` or somewhere beneath it. */\nexport function isAtOrUnder(pointer: string, ancestor: string): boolean {\n return (\n pointer === ancestor || ancestor === \"\" || pointer.startsWith(`${ancestor}/`)\n );\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** The value at `pointer`, or `undefined` when there is none. */\nexport function valueAt(data: unknown, pointer: string): unknown {\n let node: unknown = data;\n for (const seg of segments(pointer)) {\n if (Array.isArray(node)) {\n const items: unknown[] = node;\n node = /^\\d+$/.test(seg) ? items[Number(seg)] : undefined;\n } else if (isRecord(node)) {\n node = Object.hasOwn(node, seg) ? node[seg] : undefined;\n } else {\n return undefined;\n }\n }\n return node;\n}\n\n/**\n * `root` with the value at `pointer` replaced, copying only the containers on\n * the way down: the page's own object is never mutated. A pointer that does\n * not resolve leaves `root` as it was.\n */\nexport function withValueAt<T>(root: T, pointer: string, value: unknown): T {\n const parts = segments(pointer);\n const set = (node: unknown, i: number): unknown => {\n const seg = parts[i];\n if (seg === undefined) return value;\n if (Array.isArray(node)) {\n const items: unknown[] = [...(node as unknown[])];\n if (!/^\\d+$/.test(seg) || Number(seg) >= items.length) return node;\n items[Number(seg)] = set(items[Number(seg)], i + 1);\n return items;\n }\n if (isRecord(node) && Object.hasOwn(node, seg)) {\n return { ...node, [seg]: set(node[seg], i + 1) };\n }\n return node;\n };\n return set(root, 0) as T;\n}\n\n// ---------------------------------------------------------------------------\n// The view a run validates\n// ---------------------------------------------------------------------------\n\n/** What a document's marks came to, for one schema set. */\nexport interface EncryptionView {\n /** The document's data with every readable encrypted value decrypted. A copy. */\n data: Record<string, unknown>;\n /** Every marked pointer that holds a value, shallowest first. */\n marked: string[];\n /** Marked pointers holding a plain value the page itself wrote. */\n plain: string[];\n /** Marked pointers whose ciphertext decrypted under the key. */\n decrypted: string[];\n /** Marked pointers whose ciphertext does not decrypt under the key. */\n unreadable: string[];\n /** Marked pointers holding a ciphertext, with no key to read it. */\n unverified: string[];\n}\n\n/** What the view needs from a validator: its marks, per data and schema set. */\nexport interface MarkSource {\n markedPointers(\n data: Record<string, unknown>,\n refs: string[],\n ): Promise<ReadonlySet<string>>;\n}\n\n/**\n * Settling a view can uncover marks: a decrypted value may take an `if`\n * branch the ciphertext did not. Each round decrypts what the last one\n * found, and a real schema settles in two; the bound is a guard, not a limit\n * anyone meets.\n */\nconst MAX_ROUNDS = 8;\n\n/**\n * Collect a document's marks and decrypt what it can. `locate` answers for a\n * value an external-metadata manifest supplied. That exempts it from\n * `encrypted:plain` and nothing else: a manifest is private by construction,\n * so a plain value in one is not a leak, but a ciphertext in one is read,\n * decrypted and reported under the same rules as one the page holds.\n */\nexport async function encryptionView(opts: {\n data: Record<string, unknown>;\n refs: string[];\n validator: MarkSource;\n key: KeyGetter;\n locate?: (pointer: string) => SourceLocation | undefined;\n}): Promise<EncryptionView> {\n const { data, refs, validator, key, locate } = opts;\n const view: EncryptionView = {\n data,\n marked: [],\n plain: [],\n decrypted: [],\n unreadable: [],\n unverified: [],\n };\n const seen = new Set<string>();\n const sealed: string[] = [];\n for (let round = 0; round < MAX_ROUNDS; round++) {\n const marks = await validator.markedPointers(view.data, refs);\n const fresh = [...marks]\n .filter((p) => !seen.has(p))\n .sort((a, b) => segments(a).length - segments(b).length);\n if (fresh.length === 0) break;\n for (const pointer of fresh) {\n seen.add(pointer);\n // Inside a ciphertext: the whole value is one token, so a mark on a\n // part of it is covered by the one on the whole.\n if (sealed.some((s) => isAtOrUnder(pointer, s))) continue;\n const value = valueAt(data, pointer);\n if (value === undefined) continue;\n view.marked.push(pointer);\n if (!isEncryptedValue(value)) {\n // A manifest is private by construction (0037), so a plain value it\n // supplied is not the leak `encrypted:plain` is about. That exemption\n // is about the *plain* case alone: a ciphertext a manifest supplied\n // is read, validated and reported exactly like one on the page.\n if (locate?.(pointer) === undefined) view.plain.push(pointer);\n continue;\n }\n sealed.push(pointer);\n const k = key();\n if (k === undefined) {\n view.unverified.push(pointer);\n continue;\n }\n const opened = decryptValue(value, k, META_CONTEXT);\n if (!opened.ok) {\n view.unreadable.push(pointer);\n continue;\n }\n view.decrypted.push(pointer);\n view.data = withValueAt(view.data, pointer, opened.value);\n }\n }\n return view;\n}\n\n/**\n * Keywords whose Ajv message or `params` name a part of the value itself — a\n * property name of an object — rather than something the schema says.\n */\nconst VALUE_NAMING = new Map<string, string>([\n [\"additionalProperties\", \"must NOT have additional properties\"],\n [\"unevaluatedProperties\", \"must NOT have unevaluated properties\"],\n [\"propertyNames\", \"property name must be valid\"],\n]);\n\ninterface Positions {\n lineFor(this: void, pointer: string): number | undefined;\n colFor?(this: void, pointer: string): number | undefined;\n}\n\n/** Where a merged value lives, when a manifest supplied it (0037). */\ntype Locator = (pointer: string) => SourceLocation | undefined;\n\n/**\n * The place a finding points at: the manifest entry's own line when a\n * manifest supplied the value, and the document's own position otherwise.\n * The same order `toFieldError` uses, so an encryption finding and a schema\n * finding on one pointer name the same place.\n */\nfunction at(\n pointer: string,\n pos: Positions,\n locate?: Locator,\n): { file?: string; line?: number; col?: number } {\n const located = locate?.(pointer);\n if (located) {\n return {\n file: located.file,\n ...(located.line != null ? { line: located.line } : {}),\n ...(located.col != null ? { col: located.col } : {}),\n };\n }\n const line = pos.lineFor(pointer);\n const col = pos.colFor?.(pointer);\n return { ...(line != null ? { line } : {}), ...(col != null ? { col } : {}) };\n}\n\n/**\n * Validation findings as a report may show them. Dropped at or under a value\n * that could not be read; at or under a decrypted value, moved to its pointer\n * and stripped of anything naming the plaintext, so neither the message, the\n * subject, nor the path of a nested key says more than the page did.\n */\nexport function settleFindings(\n errors: readonly FieldError[],\n view: EncryptionView,\n pos: Positions,\n locate?: Locator,\n): FieldError[] {\n const hidden = [...view.unreadable, ...view.unverified];\n const out: FieldError[] = [];\n for (const e of errors) {\n if (hidden.some((p) => isAtOrUnder(e.instancePath, p))) continue;\n const inside = view.decrypted.find((p) => isAtOrUnder(e.instancePath, p));\n const generic = VALUE_NAMING.get(e.keyword);\n if (inside === undefined || (e.instancePath === inside && generic === undefined)) {\n out.push(e);\n continue;\n }\n const { subject, file: _file, line: _line, col: _col, ...rest } = e;\n void _file;\n void _line;\n void _col;\n out.push({\n ...rest,\n instancePath: inside,\n message: generic ?? e.message,\n ...(generic === undefined && subject !== undefined ? { subject } : {}),\n ...at(inside, pos, locate),\n });\n }\n return out;\n}\n\n/** The findings encryption itself raises for a view, in pointer order. */\nexport function encryptionFindings(\n view: EncryptionView,\n pos: Positions,\n locate?: Locator,\n): FieldError[] {\n return [\n ...view.plain.map((p) => ({ p, schema: ENCRYPTED_PLAIN_SCHEMA, message: plainMessage(p) })),\n ...view.unreadable.map((p) => ({\n p,\n schema: ENCRYPTED_UNREADABLE_SCHEMA,\n message: unreadableMessage(p),\n })),\n ].map(({ p, schema, message }) => ({\n schema,\n keyword: ENCRYPTED_KEYWORD,\n instancePath: p,\n message,\n ...at(p, pos, locate),\n }));\n}\n\n/**\n * A copy of `data` fit to leave the machine: every marked pointer, and any\n * ciphertext anywhere, reads `(encrypted)`. What `fill` sends a model (0017's\n * egress rule): neither the plaintext nor the ciphertext of a marked field.\n */\nexport function redactForModel(\n data: Record<string, unknown>,\n marked: Iterable<string>,\n): Record<string, unknown> {\n let out = data;\n for (const pointer of marked) {\n if (valueAt(out, pointer) !== undefined) {\n out = withValueAt(out, pointer, ENCRYPTED_PLACEHOLDER);\n }\n }\n const scrub = (node: unknown): unknown => {\n if (isEncryptedValue(node)) return ENCRYPTED_PLACEHOLDER;\n if (Array.isArray(node)) return (node as unknown[]).map(scrub);\n if (isRecord(node)) {\n return Object.fromEntries(Object.entries(node).map(([k, v]) => [k, scrub(v)]));\n }\n return node;\n };\n return scrub(out) as Record<string, unknown>;\n}\n\n/**\n * A compared managed field as a report may show it when its schema marks it\n * `x-manni-encrypt` (proposals 0040 and 0045): both values as `(encrypted)`,\n * the status and the evidence as they were. `derive` and the derived\n * comparison in `validate` both report through it.\n */\nexport function redactedDerived(f: DerivedField): DerivedField {\n return {\n ...f,\n ...(f.asserted !== undefined ? { asserted: ENCRYPTED_PLACEHOLDER } : {}),\n ...(f.derived !== null ? { derived: ENCRYPTED_PLACEHOLDER } : {}),\n };\n}\n","/**\n * External metadata (proposal 0037): a private manifest joined to public\n * documents.\n *\n * A manifest is a YAML mapping from document to a mapping of owned keys. Its\n * values are merged into each named document's extracted metadata before\n * schema resolution, so every command sees one object. The manifest itself\n * is never a document: it registers no extractor, appears in no `docs` row,\n * and is what 0031 called a join table rather than the standalone data file\n * it rejected.\n *\n * Three rules decide everything else here:\n *\n * - **Keys are owned.** Each manifest declares the top-level keys it supplies,\n * ownership is disjoint across manifests (asserted by the config parser), and\n * a manifest entry supplying a key it does not own is an operational error.\n * A manifest that declares none (proposal 0068) owns, for each page, what\n * that page's schemas mark `x-manni-location: external`, less what its\n * siblings name. `ownsKey` decides it. A value such a manifest holds for a\n * key the page does not mark is the unowned-key refusal, raised at the\n * merge because ownership is per page. With the page's marks unknown, the\n * manifest owns nothing for it and nothing is judged.\n * Ownership is what gives a write to an absent key somewhere to go, and it\n * is what makes a document carrying a private key visible with or without\n * a manifest entry.\n * - **A document carrying an owned key is a collision, not a tiebreak.** 0020's\n * rule across files: neither channel wins, because the discarded value is\n * exactly the one nobody checked. The caller files the finding; the merge\n * keeps the document's value so the report shows what the public site\n * would publish.\n * - **A manifest names documents by exact path, or by one frontmatter field.**\n * No globs and no cascade (0004 rejected partial merges of config for the\n * reason that a silently merged result changes what the contract means).\n * A path is relative to the config's directory. A field join (0039)\n * matches the extracted value of that field, so a rename cannot orphan an\n * entry; what can is two pages sharing one value, which is a finding on\n * both.\n */\nimport { readFile } from \"node:fs/promises\";\nimport { isAbsolute, relative, resolve, sep } from \"node:path\";\nimport {\n LineCounter,\n isMap,\n isNode,\n isScalar,\n isSeq,\n parseDocument,\n type Node,\n} from \"yaml\";\nimport {\n externalMetadataOrigin,\n isMember,\n matchesCollectionPaths,\n neverOwned,\n ownsKey,\n type CollectionConfig,\n type ExternalMetadataConfig,\n} from \"../../shared/collections.js\";\nimport {\n PAGE_PLACEHOLDER,\n findPageManifests,\n hasPagePlaceholder,\n pageManifestPath,\n sameFile,\n} from \"../../shared/page-manifest.js\";\nimport { isMissing } from \"../../shared/manifest-cas.js\";\nimport { FILE_SCHEMA_KEY } from \"./resolve-schema.js\";\nimport { classifyRef } from \"./schema-registry.js\";\nimport { ManifestCache } from \"./manifest-cache.js\";\nimport { fetchExternalMetadata } from \"./external-metadata-fetch.js\";\nimport { STDIN_LABEL } from \"./load-files.js\";\nimport { escapePointerSegment, positionForFactory } from \"../extractors/pointer.js\";\nimport { DocmetaError, type ExtractedMetadata } from \"../types.js\";\nimport { decryptValue, isEncryptedValue } from \"../../shared/encryption.js\";\nimport { EncryptionRefusal, META_CONTEXT } from \"./encrypted.js\";\n\n/**\n * The `schema` ref a collision finding carries, and so its baseline and rule\n * identity: `external:owned/external`. Shaped like `check:<name>` so\n * `classifyRef` passes it through as a built-in id rather than resolving it\n * as a cwd-relative file path, and reserved in the registry for the same\n * reason `check` is.\n */\nexport const EXTERNAL_OWNED_SCHEMA = \"external:owned\";\n\n/**\n * The `schema` ref of a duplicate-join finding (0039): two documents carry\n * the same value of a join field, so one manifest entry matched both.\n */\nexport const EXTERNAL_DUPLICATE_SCHEMA = \"external:duplicate\";\n\n/**\n * The `keyword` every external-metadata finding carries: no Ajv keyword\n * produced it.\n */\nexport const EXTERNAL_KEYWORD = \"external\";\n\n/** The join that names documents by path, and the default. */\nexport const PATH_JOIN = \"path\";\n\n/** One value a manifest supplied, and where it was written. */\nexport interface ExternalMetadataValue {\n value: unknown;\n /** The collection whose manifest supplied it (proposal 0041). */\n collection: string;\n /** Manifest path as the run reports it: relative to the run's base, posix — or the URL. */\n file: string;\n /** 1-based line of the key in the manifest, when known. */\n line?: number;\n /**\n * 1-based manifest line of every node inside `value`, keyed by the JSON\n * Pointer relative to `value` (`/2/source/file`). A mapping member sits on\n * its key's line, and a list item on the line its node starts. Present only\n * when `value` is a mapping or a list with members; `line` answers for the\n * value itself.\n */\n lines?: ReadonlyMap<string, number>;\n}\n\n/** One manifest entry, for the orphan checks. */\nexport interface ExternalMetadataEntry {\n /** The collection whose manifest declared it (proposal 0041). */\n collection: string;\n /** `path`, or the frontmatter field this entry is keyed by. */\n join: string;\n /** Absolute document path, for a path entry. */\n abs?: string;\n /** The key exactly as written in the manifest. */\n spelled: string;\n /** Manifest path as the run reports it. */\n file: string;\n /** 1-based line of the entry in the manifest, when known. */\n line?: number;\n}\n\ntype Values = Map<string, ExternalMetadataValue>;\n\n/**\n * The same mapping as `Values`, as a cached parse hands it out. A caller that\n * holds one may read it and may copy it, and cannot write into the parse the\n * next command will be given.\n */\ntype ReadonlyValues = ReadonlyMap<string, ExternalMetadataValue>;\n\n/**\n * One manifest's parse, on its own: the values it supplies, indexed the way\n * its join indexes them, and the entries it declares. Isolated rather than\n * merged in place, because the same result is handed to the next command that\n * reads the same file.\n *\n * Readonly to the bottom of the maps, not just at the top. An outer\n * `ReadonlyMap` of mutable inner ones stops an add and a remove on the key set\n * and stops nothing else: anything holding an inner map could `set` a value\n * straight into the parse the next command is given. The copy-in below is\n * careful today, and the type is what keeps the change after it careful.\n */\ninterface ParsedManifest {\n readonly values: ReadonlyMap<string, ReadonlyValues>;\n readonly entries: readonly ExternalMetadataEntry[];\n}\n\n/**\n * Every manifest this process has parsed, by path, `mtimeMs` and size. A\n * manifest is data a whole run is judged against, so a stale parse would be a\n * wrong verdict rather than a slow one; `manifest-cache.ts` says what keeps it\n * fresh, and why a stat alone is not enough.\n */\nconst parsedManifests = new ManifestCache<ParsedManifest>();\n\n/**\n * A manifest with no `keys` (proposal 0068), as one index loaded it. What it\n * owns is decided per page, from the page's marks, so it is kept apart from\n * `owners`, which holds what the config alone decides.\n */\ninterface ImpliedOwner {\n /** The whole declared collection, for `ownsKey`. */\n collection: CollectionConfig;\n manifest: ExternalMetadataConfig;\n /** The manifest as a collision names it: its reported path, its URL, or its `{page}` pattern. */\n file: string;\n /** Every file its values carry, as the run reports them: one, or one per page. */\n files: Set<string>;\n}\n\n/**\n * The keyless manifests each index was loaded with. Kept beside the index, as\n * `perPageRules` is, so `ExternalMetadataIndex` keeps its shape.\n */\nconst impliedOwners = new WeakMap<ExternalMetadataIndex, readonly ImpliedOwner[]>();\n\n/** One `{page}` entry of a loaded index: what a stray walk needs to find its files. */\ninterface PerPageRule {\n collection: CollectionConfig;\n manifest: ExternalMetadataConfig;\n configDir: string;\n}\n\n/**\n * The `{page}` entries each index was loaded with (proposal 0058). Kept beside\n * the index rather than on it, so `ExternalMetadataIndex` keeps the shape\n * every caller already builds and reads, and `orphanEntries` keeps its\n * signature while it learns to report a stray file.\n */\nconst perPageRules = new WeakMap<ExternalMetadataIndex, readonly PerPageRule[]>();\n\n/**\n * The orphans `orphanEntries` found as stray files rather than as entries in\n * a file a run read, so `orphanError` tells the author to remove the file.\n */\nconst strayEntries = new WeakSet<ExternalMetadataEntry>();\n\n/** Every manifest of a run, loaded once and consulted per document. */\nexport interface ExternalMetadataIndex {\n /**\n * Owned key -> every collection that owns it, with the manifest that does.\n *\n * A list rather than one entry, because two collections may legitimately\n * each own the same key (0041 rule 5): `guides` and `blog` can both supply\n * `owner`. Ambiguity only exists for a file that is a member of both, which\n * is decided per file in `mergeExternalMetadata`.\n */\n owners: ReadonlyMap<string, readonly { collection: string; file: string }[]>;\n /** Path-joined manifests: absolute document path -> owned key -> value. */\n byPath: ReadonlyMap<string, ReadonlyMap<string, ExternalMetadataValue>>;\n /** Field-joined manifests: field -> value -> owned key -> value. */\n byField: ReadonlyMap<string, ReadonlyMap<string, ReadonlyMap<string, ExternalMetadataValue>>>;\n /** Every manifest entry, in manifest order. */\n entries: readonly ExternalMetadataEntry[];\n}\n\nexport interface LoadExternalMetadataOptions {\n /** Directory `externalMetadata[].file` and every manifest key resolve from. */\n configDir: string;\n /** Directory the run's file labels are relative to; manifests are reported the same way. */\n base: string;\n /** `--offline` / `offline:`: a URL manifest is refused rather than fetched (0038). */\n offline?: boolean;\n /** Network timeout for a URL manifest; the schema fetch's default otherwise. */\n timeoutMs?: number;\n /** For tests: the environment `tokenEnv` is read from. */\n env?: Record<string, string | undefined>;\n /**\n * The run's documents, as absolute paths (proposal 0058). An entry whose\n * `file` holds `{page}` names one manifest per page, so it is read for\n * exactly these pages, each that belongs to its collection, and for nothing\n * else. Absent, such an entry reads no file. An entry without the\n * placeholder ignores this and loads its one manifest as it always has.\n */\n pages?: readonly string[];\n}\n\n/** A place a merged value lives, for a finding that must name it. */\nexport interface SourceLocation {\n file: string;\n line?: number;\n col?: number;\n}\n\n/** A key the document carries that a manifest owns. */\nexport interface ExternalMetadataCollision {\n key: string;\n /** The owning manifest, as the run reports it. */\n file: string;\n /** The collection that manifest belongs to (proposal 0041). */\n collection: string;\n}\n\n/** A field-joined entry a document matched (0039). */\nexport interface ExternalMetadataJoin {\n field: string;\n /** The value matched: the field's plaintext, decrypted first when the page holds it encrypted. */\n value: string;\n /**\n * The field as the page holds it, when that differs from `value`: the\n * ciphertext of an encrypted join field (proposal 0045). A finding about\n * the join names this, never the plaintext.\n */\n pageValue?: string;\n /** The manifest, as the run reports it. */\n file: string;\n /** The collection that manifest belongs to (proposal 0041). */\n collection: string;\n}\n\n/** What `mergeExternalMetadata` hands back. */\nexport interface MergedMetadata {\n /** The document's metadata with every owned key the manifest supplied. */\n extracted: ExtractedMetadata;\n /**\n * Owned keys the document itself also carried, in document order, each\n * with the manifest that owns it — so the finding names it without a\n * second lookup, and without a fallback for an index that is not there.\n */\n collisions: ExternalMetadataCollision[];\n /** Field-joined entries this document matched, one per manifest at most. */\n joins: ExternalMetadataJoin[];\n /**\n * Where a merged pointer's value lives. Answers only for a value the\n * manifest supplied — a bare key or its `/key` pointer, and anything\n * beneath it — and `undefined` for everything the document owns, which is\n * what `lineFor` is for.\n *\n * The line is the deepest manifest node the pointer reaches, so\n * `/citations/2` is the third item's line and `/citations/2/source/file`\n * that member's. A pointer past what the manifest holds falls back to the\n * nearest ancestor that exists, and at worst to the owned key's line.\n */\n locate: (pointer: string) => SourceLocation | undefined;\n}\n\nconst posix = (p: string): string => p.split(sep).join(\"/\");\n\n/** How a run spells a manifest: relative to its base, like every file label. */\nexport function reportedPath(abs: string, base: string): string {\n const rel = relative(base, abs);\n return rel === \"\" ? \".\" : posix(rel);\n}\n\n/**\n * One value or entry of a cached parse, spelled the way this run reports its\n * manifest. Answers the original when the spelling already matches, which is\n * every run that parsed the manifest itself.\n */\nfunction reported<T extends { file: string }>(of: T, file: string): T {\n return of.file === file ? of : { ...of, file };\n}\n\n/** The join an external-metadata config asks for: `path` unless it names a field. */\nexport function externalMetadataJoin(\n manifest: Pick<ExternalMetadataConfig, \"join\">,\n): string {\n return manifest.join ?? PATH_JOIN;\n}\n\n/**\n * Load every manifest of every collection the run covers. Resolves to `null`\n * when none of them declares one, which is every setup that existed before\n * this feature.\n *\n * Every refusal is a `DocmetaError`: the manifest is a config-supplied input,\n * and one that is missing or misshapen is the run's problem, not a\n * document's (0014).\n */\nexport async function loadExternalMetadata(\n collections: readonly CollectionConfig[],\n opts: LoadExternalMetadataOptions,\n): Promise<ExternalMetadataIndex | null> {\n const configured = collections.flatMap((c) =>\n c.externalMetadata.map((m) => ({ collection: c.name, manifest: m })),\n );\n if (configured.length === 0) return null;\n\n const owners = new Map<string, { collection: string; file: string }[]>();\n const byPath = new Map<string, Values>();\n const byField = new Map<string, Map<string, Values>>();\n const entries: ExternalMetadataEntry[] = [];\n /** Every `{page}` manifest resolved so far, and the page that resolved it. */\n const resolvedBy = new Map<string, string>();\n const rules: PerPageRule[] = [];\n const implied: ImpliedOwner[] = [];\n\n for (const { collection, manifest } of configured) {\n // The whole collection, because a `{page}` entry is read per member page.\n const declared = collections.find(\n (c) => c.name === collection && c.externalMetadata.includes(manifest),\n );\n if (\n declared !== undefined &&\n classifyRef(manifest.file).kind !== \"url\" &&\n hasPagePlaceholder(manifest.file)\n ) {\n const owner = await loadPerPage(declared, manifest, opts, resolvedBy, { owners, byPath, byField, entries });\n if (owner !== undefined) implied.push(owner);\n rules.push({ collection: declared, manifest, configDir: opts.configDir });\n continue;\n }\n // A URL manifest (0038) is reported as the URL itself, and fetched every\n // run: it is data, and a stale copy would validate against the wrong\n // values. A path is reported relative to the run's base, like every\n // file label. Either way the manifest's *keys* resolve from the config\n // directory, so a remote manifest names documents the same way a local\n // one does.\n const join = externalMetadataJoin(manifest);\n let parsed: ParsedManifest;\n let file: string;\n if (classifyRef(manifest.file).kind === \"url\") {\n file = manifest.file;\n const text = await fetchExternalMetadata(manifest.file, {\n ...(manifest.tokenEnv !== undefined ? { tokenEnv: manifest.tokenEnv } : {}),\n ...(opts.offline !== undefined ? { offline: opts.offline } : {}),\n ...(opts.timeoutMs !== undefined ? { timeoutMs: opts.timeoutMs } : {}),\n ...(opts.env !== undefined ? { env: opts.env } : {}),\n });\n parsed = parseManifest(manifest, collection, text, file, opts.configDir, join, ownership(declared, manifest));\n } else {\n const abs = isAbsolute(manifest.file)\n ? manifest.file\n : resolve(opts.configDir, manifest.file);\n const label = reportedPath(abs, opts.base);\n file = label;\n // One parse per file, per declaration. A manifest unchanged since\n // another command in this process read it is not read again; a written\n // one was dropped by `writeFileAtomic`, and one edited from outside by\n // its `mtimeMs` and size.\n parsed = await parsedManifests.parse(\n abs,\n // `label` is deliberately not part of this. It is the manifest as this\n // run reports it, which is a function of the run's base rather than of\n // the bytes, so two runs over one corpus from two directories parse\n // identically and differ only in a string each value carries. Keying\n // on it would miss the cache for exactly the runs that share a\n // process, which is what a test suite is. The copy-in below writes\n // this run's spelling onto every value and entry instead.\n JSON.stringify([\n collection,\n join,\n opts.configDir,\n variantOf(declared, manifest),\n ]),\n async () =>\n parseManifest(\n manifest,\n collection,\n await readManifest(abs, label),\n label,\n opts.configDir,\n join,\n ownership(declared, manifest),\n ),\n );\n }\n if (manifest.keys === undefined && declared !== undefined) {\n implied.push({ collection: declared, manifest, file, files: new Set([file]) });\n }\n for (const key of manifest.keys ?? []) {\n const list = owners.get(key);\n if (list) list.push({ collection, file });\n else owners.set(key, [{ collection, file }]);\n }\n let target: Map<string, Values>;\n if (join === PATH_JOIN) {\n target = byPath;\n } else {\n const existing = byField.get(join);\n if (existing) target = existing;\n else {\n target = new Map<string, Values>();\n byField.set(join, target);\n }\n }\n // Copied in rather than handed over. The parse is shared with whatever\n // command reads this manifest next, so nothing downstream may hold a\n // reference into it.\n //\n // The copy is also where `file` is set, because the parse may have been\n // made by a run with another base and carries that run's spelling. The\n // walk happens either way, so rewriting costs one object per value.\n for (const [indexKey, values] of parsed.values) {\n const into = target.get(indexKey) ?? new Map<string, ExternalMetadataValue>();\n for (const [key, value] of values) into.set(key, reported(value, file));\n target.set(indexKey, into);\n }\n for (const entry of parsed.entries) entries.push(reported(entry, file));\n }\n const index: ExternalMetadataIndex = { owners, byPath, byField, entries };\n if (rules.length > 0) perPageRules.set(index, rules);\n if (implied.length > 0) impliedOwners.set(index, implied);\n return index;\n}\n\n/**\n * Which keys a manifest's entries may set, as the parse checks it. A manifest\n * with `keys` may set those. A keyless one (proposal 0068) may set any key\n * but the ones it can never own, because which of the rest it owns depends\n * on the page, and is settled at the merge.\n */\ninterface Ownership {\n may: (key: string) => boolean;\n /** Why an entry may not set `key`, as the tail of the refusal. */\n why: (key: string) => string;\n}\n\nfunction ownership(\n declared: CollectionConfig | undefined,\n manifest: ExternalMetadataConfig,\n): Ownership {\n if (manifest.keys !== undefined) {\n const owned = new Set(manifest.keys);\n return {\n may: (key) => owned.has(key),\n why: () => `which this manifest does not own. Add it to the manifest's \"keys\", or remove it from the entry.`,\n };\n }\n const never = neverOwned(declared ?? { externalMetadata: [manifest] }, manifest);\n return {\n may: (key) => !never.has(key),\n why: (key) =>\n key === manifest.join\n ? \"the field this manifest joins on, which the page carries. Remove it from the entry.\"\n : `which another manifest of this collection names in its \"keys\". Move it to that manifest, or remove it from the entry.`,\n };\n}\n\n/** What a parse depends on besides the bytes: the keys, or what a keyless manifest may never own. */\nfunction variantOf(\n declared: CollectionConfig | undefined,\n manifest: ExternalMetadataConfig,\n): unknown {\n // The keys are sorted because they reach the variant as an array, and two\n // declarations that own the same keys in a different order parse to the\n // same thing.\n if (manifest.keys !== undefined) return [...manifest.keys].sort();\n return { never: [...neverOwned(declared ?? { externalMetadata: [manifest] }, manifest)].sort() };\n}\n\n/** The index `loadExternalMetadata` is building, for a helper that adds to it. */\ninterface IndexUnderConstruction {\n owners: Map<string, { collection: string; file: string }[]>;\n byPath: Map<string, Values>;\n byField: Map<string, Map<string, Values>>;\n entries: ExternalMetadataEntry[];\n}\n\n/**\n * One `{page}` entry (proposal 0058): a rule rather than a file, so each of\n * the run's pages that belongs to the collection resolves its own manifest,\n * which is read, checked to be that page's, and indexed. A manifest that does\n * not exist is a page with nothing kept there, and reads as empty.\n *\n * Ownership is still the config's fact, so the entry owns its keys whether or\n * not any page resolved a file. The owner is recorded as the pattern as\n * written, because there is no one file to name.\n */\nasync function loadPerPage(\n declared: CollectionConfig,\n manifest: ExternalMetadataConfig,\n opts: LoadExternalMetadataOptions,\n resolvedBy: Map<string, string>,\n into: IndexUnderConstruction,\n): Promise<ImpliedOwner | undefined> {\n const collection = declared.name;\n const join = externalMetadataJoin(manifest);\n const implied: ImpliedOwner | undefined =\n manifest.keys === undefined\n ? { collection: declared, manifest, file: manifest.file, files: new Set() }\n : undefined;\n for (const key of manifest.keys ?? []) {\n const list = into.owners.get(key);\n if (list) list.push({ collection, file: manifest.file });\n else into.owners.set(key, [{ collection, file: manifest.file }]);\n }\n const target = indexFor(join, into);\n\n for (const pageAbs of opts.pages ?? []) {\n const resolved = pageManifestPath(manifest.file, opts.configDir, pageAbs);\n if (\"outside\" in resolved) {\n // A page above the config directory is a member of nothing, so it is\n // refused only when the collection's own paths claim it: the one case\n // where the placeholder was asked to resolve it and cannot.\n if (resolved.pageRel.startsWith(\"../\") && matchesCollectionPaths(declared, resolved.pageRel)) {\n throw new DocmetaError(outsideRefusal(manifest, collection, resolved.pageRel));\n }\n continue;\n }\n const rel = posix(relative(opts.configDir, pageAbs));\n if (!isMember(declared, rel)) continue;\n\n const earlier = resolvedBy.get(resolved.abs);\n if (earlier !== undefined && earlier !== pageAbs) {\n const [a, b] = [reportedPath(earlier, opts.base), reportedPath(pageAbs, opts.base)].sort();\n throw new DocmetaError(\n `${a ?? \"\"} and ${b ?? \"\"} both resolve ${PAGE_PLACEHOLDER} to ${reportedPath(resolved.abs, opts.base)}. A ${PAGE_PLACEHOLDER} manifest names one page, so rename one of them.`,\n );\n }\n resolvedBy.set(resolved.abs, pageAbs);\n\n const label = reportedPath(resolved.abs, opts.base);\n // The same cache, and the same variant, a concrete manifest parses under.\n // A missing file is never cached, because it cannot be stat'ed.\n const parsed = await parsedManifests.parse(\n resolved.abs,\n JSON.stringify([collection, join, opts.configDir, variantOf(declared, manifest)]),\n async () =>\n parseManifest(\n manifest,\n collection,\n await readPageManifest(resolved.abs, label),\n label,\n opts.configDir,\n join,\n ownership(declared, manifest),\n ),\n );\n implied?.files.add(label);\n\n // Every entry must be this page's own. Compared as files rather than as\n // text (0058 stress test 8): a spelling that differs only in case is one\n // page on a case-insensitive filesystem and two elsewhere, which is the\n // platform's call and not a string's.\n const pageLabel = reportedPath(pageAbs, opts.base);\n for (const entry of parsed.entries) {\n if (entry.abs === undefined || sameFile(entry.abs, pageAbs)) continue;\n const at = entry.line === undefined ? label : `${label}:${String(entry.line)}`;\n throw new DocmetaError(\n `Manifest ${at} names \"${entry.spelled}\", but ${PAGE_PLACEHOLDER} resolved this file for \"${pageLabel}\". A per-page manifest holds one entry, for its own page.`,\n );\n }\n\n // Indexed under the page's own path, which the check above proved every\n // path entry names, so a lookup by the run's spelling of the page finds it.\n for (const [indexKey, values] of parsed.values) {\n const key = join === PATH_JOIN ? pageAbs : indexKey;\n const merged = target.get(key) ?? new Map<string, ExternalMetadataValue>();\n for (const [owned, value] of values) merged.set(owned, reported(value, label));\n target.set(key, merged);\n }\n for (const entry of parsed.entries) {\n into.entries.push({\n ...reported(entry, label),\n ...(entry.abs === undefined ? {} : { abs: pageAbs }),\n });\n }\n }\n return implied;\n}\n\n/** The index a manifest with this join is merged into. */\nfunction indexFor(join: string, into: IndexUnderConstruction): Map<string, Values> {\n if (join === PATH_JOIN) return into.byPath;\n const existing = into.byField.get(join);\n if (existing) return existing;\n const created = new Map<string, Values>();\n into.byField.set(join, created);\n return created;\n}\n\n/**\n * The refusal for a page a `{page}` entry would resolve above the config\n * directory. Exported for the writers that resolve a page's manifest\n * themselves (`relocate`, `fill`, `derive`, `query`).\n */\nexport function outsideRefusal(\n manifest: ExternalMetadataConfig,\n collection: string,\n pageRel: string,\n): string {\n const tail = `for \"${pageRel}\". A ${PAGE_PLACEHOLDER} manifest stays under the config file.`;\n const origin = externalMetadataOrigin(manifest);\n if (origin === undefined) {\n return `externalMetadata file \"${manifest.file}\" of collection ${collection} resolves outside the config file's directory ${tail}`;\n }\n return `${origin.source}: ${origin.where}.file resolves outside ${origin.source}'s directory ${tail}`;\n}\n\n/**\n * A `{page}` manifest's text (0058 § 2): one that does not exist is a page\n * with nothing kept there, and reads as empty. Every other failure keeps\n * `readManifest`'s refusal, so a permission error is still reported.\n */\nasync function readPageManifest(abs: string, file: string): Promise<string> {\n try {\n return await readFile(abs, \"utf8\");\n } catch (err) {\n if (isMissing(err)) return \"\";\n throw unreadable(file, err);\n }\n}\n\nasync function readManifest(abs: string, file: string): Promise<string> {\n try {\n return await readFile(abs, \"utf8\");\n } catch (err) {\n throw unreadable(file, err);\n }\n}\n\n/** The refusal every manifest shares when it cannot be read. */\nfunction unreadable(file: string, err: unknown): DocmetaError {\n const reason = err instanceof Error ? err.message : String(err);\n return new DocmetaError(`Manifest ${file} could not be read: ${reason}`);\n}\n\n\nfunction parseManifest(\n manifest: ExternalMetadataConfig,\n collection: string,\n text: string,\n file: string,\n configDir: string,\n join: string,\n owns: Ownership,\n): ParsedManifest {\n const target = new Map<string, Values>();\n const entries: ExternalMetadataEntry[] = [];\n const lc = new LineCounter();\n // `uniqueKeys: false`, so a document named twice reaches the dedicated\n // check below and is reported by name and line, rather than as a generic\n // \"map keys must be unique\" parse error.\n const doc = parseDocument(text, { lineCounter: lc, uniqueKeys: false });\n const problem = doc.errors[0];\n if (problem) {\n throw new DocmetaError(\n `Manifest ${file} is not valid YAML: ${problem.message}`,\n );\n }\n const root = doc.contents;\n // An empty manifest is a mapping with no entries: legal, and merges nothing.\n if (root === null || (isScalar(root) && root.value === null))\n return { values: target, entries };\n if (!isMap(root)) {\n throw new DocmetaError(\n `Manifest ${file}: the manifest must be a mapping from document ${join === PATH_JOIN ? \"path\" : `\"${join}\"`} to owned keys.`,\n );\n }\n const lineAt = (node: unknown): number | undefined => {\n const range = isNode(node) ? node.range : undefined;\n return range ? lc.linePos(range[0]).line : undefined;\n };\n\n // A document named twice would otherwise resolve last-wins per key, with\n // both entries counted and no diagnostic: `yaml` files a duplicate mapping\n // key under `doc.warnings`, not `doc.errors`. It is almost always a typo,\n // and it is refused by name rather than merged.\n const seen = new Map<string, number | undefined>();\n for (const pair of root.items) {\n const spelled = isScalar(pair.key) ? String(pair.key.value) : String(pair.key);\n const entryLine = lineAt(pair.key);\n const where = entryLine === undefined ? file : `${file}:${entryLine}`;\n if (seen.has(spelled)) {\n const first = seen.get(spelled);\n throw new DocmetaError(\n `Manifest ${where}: \"${spelled}\" is named twice (first at line ${first ?? \"?\"}). Merge the two entries into one.`,\n );\n }\n seen.set(spelled, entryLine);\n if (!isMap(pair.value)) {\n throw new DocmetaError(\n `Manifest ${where}: \"${spelled}\" must be a mapping of owned keys to values.`,\n );\n }\n // A path entry is indexed by its absolute path; a field entry by the\n // spelled value, which a document's field is compared to as a string.\n const indexKey = join === PATH_JOIN ? resolve(configDir, spelled) : spelled;\n const values = target.get(indexKey) ?? new Map<string, ExternalMetadataValue>();\n for (const kv of pair.value.items) {\n const key = isScalar(kv.key) ? String(kv.key.value) : String(kv.key);\n if (key === FILE_SCHEMA_KEY) {\n throw new DocmetaError(\n `Manifest ${where}: \"${spelled}\" sets \"${FILE_SCHEMA_KEY}\" — a manifest never chooses the schema a document is judged by; use \"overrides\" in the config.`,\n );\n }\n if (!owns.may(key)) {\n throw new DocmetaError(`Manifest ${where}: \"${spelled}\" sets \"${key}\", ${owns.why(key)}`);\n }\n const value: unknown =\n kv.value === null\n ? null\n : (kv.value as Node).toJS(doc, { maxAliasCount: 100 });\n const line = lineAt(kv.key);\n const lines = nodeLines(kv.value, lineAt);\n values.set(key, {\n value,\n collection,\n file,\n ...(line === undefined ? {} : { line }),\n ...(lines.size === 0 ? {} : { lines }),\n });\n }\n target.set(indexKey, values);\n entries.push({\n collection,\n join,\n ...(join === PATH_JOIN ? { abs: indexKey } : {}),\n spelled,\n file,\n ...(entryLine === undefined ? {} : { line: entryLine }),\n });\n }\n return { values: target, entries };\n}\n\n/**\n * The line of every node inside one manifest value, keyed by the JSON Pointer\n * relative to that value, RFC 6901 escaped as Ajv's `instancePath` is.\n *\n * A mapping member is recorded at its key's line, the same rule the owned key\n * itself follows, and a list item at the line its node starts: for a block\n * item that is the `- ` line, for a flow item the line its `{` or scalar is\n * on. An alias is recorded where it is written and not followed, so a pointer\n * beneath it falls back to the alias's own line.\n */\nfunction nodeLines(\n node: unknown,\n lineAt: (node: unknown) => number | undefined,\n prefix = \"\",\n out = new Map<string, number>(),\n): Map<string, number> {\n if (isMap(node)) {\n for (const kv of node.items) {\n const seg = isScalar(kv.key) ? String(kv.key.value) : String(kv.key);\n const pointer = `${prefix}/${escapePointerSegment(seg)}`;\n const line = lineAt(kv.key) ?? lineAt(kv.value);\n if (line !== undefined) out.set(pointer, line);\n nodeLines(kv.value, lineAt, pointer, out);\n }\n } else if (isSeq(node)) {\n node.items.forEach((item, i) => {\n const pointer = `${prefix}/${String(i)}`;\n const line = lineAt(item);\n if (line !== undefined) out.set(pointer, line);\n nodeLines(item, lineAt, pointer, out);\n });\n }\n return out;\n}\n\n/** The string a document's join field compares as; undefined when it cannot. */\nfunction joinValue(raw: unknown): string | undefined {\n if (typeof raw === \"string\") return raw;\n if (typeof raw === \"number\" || typeof raw === \"bigint\") return String(raw);\n if (typeof raw === \"boolean\") return String(raw);\n return undefined;\n}\n\n/**\n * Merge the external metadata for one document into its extracted metadata.\n *\n * `label` is the document as the run spells it, relative to `base`; a path\n * entry matches on the resolved absolute path, never on the spelling, so a\n * positional run from a subdirectory finds the same entry a config-corpus\n * run does. A field entry matches on the document's own value of the join\n * field, wherever the document lives. Stdin never matches a path entry:\n * there is no file behind it.\n *\n * `memberOf` names the collections this document belongs to, and only their\n * manifests are consulted (0041 rule 4). It is the caller's `memberOf(...)`\n * result, computed once per file.\n *\n * `present`, `format` and the document's own positions are untouched. A\n * manifest key is not in the document, so `lineFor` keeps answering\n * `undefined` for it, and `locate` answers instead.\n *\n * A join field the page holds encrypted (proposal 0045) is decrypted with\n * `options.encryptionKey` before it is matched. With no key, and a manifest\n * of this document's collections joining on that field, the run cannot match\n * and refuses. A ciphertext that does not decrypt matches nothing.\n */\nexport function mergeExternalMetadata(\n label: string,\n extracted: ExtractedMetadata,\n index: ExternalMetadataIndex | null,\n memberOf: readonly string[],\n base: string,\n options: {\n encryptionKey?: () => string | undefined;\n /**\n * The top-level keys the document's schemas mark `x-manni-location:\n * external` (proposal 0068), which is what a manifest with no `keys`\n * owns. Absent, such a manifest owns nothing for this document.\n */\n marked?: ReadonlySet<string>;\n } = {},\n): MergedMetadata {\n return mergeWith(label, extracted, index, memberOf, base, options.encryptionKey, options.marked ?? UNKNOWN);\n}\n\n/**\n * No marks known: a keyless manifest owns nothing, and a value it holds is\n * skipped rather than refused. Compared by reference, because an explicit\n * empty set means something else: the marks are known and name nothing, so\n * every value a keyless manifest holds for the page is refused.\n */\nconst UNKNOWN: ReadonlySet<string> = new Set();\n\n/**\n * Every value a keyless manifest supplies counts as owned, so the merged data\n * is the probe a page's marks are read over (see `mergeWithMarks`). Nothing\n * is refused or filed in this mode.\n */\nconst PROBE = Symbol(\"probe\");\n\nfunction mergeWith(\n label: string,\n extracted: ExtractedMetadata,\n index: ExternalMetadataIndex | null,\n memberOf: readonly string[],\n base: string,\n encryptionKey: (() => string | undefined) | undefined,\n marked: ReadonlySet<string> | typeof PROBE,\n): MergedMetadata {\n const none = (): undefined => undefined;\n // A file that belongs to no collection gets nothing merged, and carries no\n // collision either: a key only counts as owned by a manifest that applies to\n // this file (0041 rule 4). A positional `README.md` is the case.\n if (!index || memberOf.length === 0) {\n return { extracted, collisions: [], joins: [], locate: none };\n }\n const mine = (collection: string): boolean => memberOf.includes(collection);\n const probing = marked === PROBE;\n\n // The keyless manifests of this file's collections (proposal 0068), and\n // whether one owns a key for this file.\n const implied = (impliedOwners.get(index) ?? []).filter((o) => mine(o.collection.name));\n const impliedOwns = (o: ImpliedOwner, key: string): boolean =>\n probing ? !neverOwned(o.collection, o.manifest).has(key) : ownsKey(o.collection, o.manifest, key, marked);\n /** Every manifest of this file's collections that owns `key` for it. Not asked while probing. */\n const ownersOf = (key: string): { collection: string; file: string }[] =>\n pageOwners(index, key, memberOf, probing ? undefined : marked);\n /** The keyless manifest a value came from, when one did. */\n const impliedFrom = (sv: ExternalMetadataValue): ImpliedOwner | undefined =>\n implied.find((o) => o.collection.name === sv.collection && o.files.has(sv.file));\n\n const collisions: ExternalMetadataCollision[] = [];\n if (!probing) {\n for (const key of Object.keys(extracted.data)) {\n for (const owner of ownersOf(key)) {\n collisions.push({ key, file: owner.file, collection: owner.collection });\n }\n }\n }\n\n const sources: ReadonlyMap<string, ExternalMetadataValue>[] = [];\n /** The manifest entry a source's values came from, for a refusal that names it. */\n const entryOf = new Map<ReadonlyMap<string, ExternalMetadataValue>, (sv: ExternalMetadataValue) => ExternalMetadataEntry | undefined>();\n const joins: ExternalMetadataJoin[] = [];\n if (label !== STDIN_LABEL) {\n const byPath = index.byPath.get(resolve(base, label));\n if (byPath) {\n sources.push(byPath);\n const abs = resolve(base, label);\n entryOf.set(byPath, (sv) => index.entries.find((e) => e.file === sv.file && e.abs === abs));\n }\n }\n for (const [field, byValue] of index.byField) {\n const raw = extracted.data[field];\n let value: string | undefined;\n let pageValue: string | undefined;\n if (isEncryptedValue(raw)) {\n const joinsHere = [...byValue.values()].some((supplied) =>\n [...supplied.values()].some((sv) => mine(sv.collection)),\n );\n if (!joinsHere) continue;\n const key = encryptionKey?.();\n if (key === undefined) {\n throw new EncryptionRefusal(\n `externalMetadata join field \"${field}\" is encrypted on these pages, and no encryption key is available to match them.`,\n );\n }\n const opened = decryptValue(raw, key, META_CONTEXT);\n if (!opened.ok) continue;\n value = joinValue(opened.value);\n pageValue = raw;\n } else {\n value = joinValue(raw);\n }\n if (value === undefined) continue;\n const hit = byValue.get(value);\n if (!hit) continue;\n sources.push(hit);\n const spelled = value;\n entryOf.set(hit, (sv) =>\n index.entries.find((e) => e.file === sv.file && e.join === field && e.spelled === spelled),\n );\n // Exactly one join per (field, value), whatever the collections behind it.\n // The duplicate-join finding (0039) counts *documents* per value, so a\n // second entry for one document would read as a second document.\n const first = [...hit.values()].find((sv) => mine(sv.collection));\n if (first) {\n joins.push({\n field,\n value,\n ...(pageValue === undefined ? {} : { pageValue }),\n file: first.file,\n collection: first.collection,\n });\n }\n }\n\n // Two of this file's collections owning one key the manifests actually\n // supply for it is an operational error, not a finding: there is nothing\n // about the document to fix, and picking a winner would be the tiebreak\n // 0020 and 0037 both refuse (0041 rule 5). The legitimate case — two\n // collections each owning `owner`, with no file in both — is untouched,\n // which is why this is decided per file rather than at parse time.\n for (const supplied of probing ? [] : sources) {\n for (const key of supplied.keys()) {\n const [a, b] = ownersOf(key);\n if (a && b) {\n throw new DocmetaError(\n `${label}: \"${key}\" is owned by manifests in two of its collections, ${a.collection} (${a.file}) and ${b.collection} (${b.file}); a key has one manifest per file. Narrow one collection's paths or exclude.`,\n );\n }\n }\n }\n\n if (sources.length === 0) {\n return { extracted, collisions, joins, locate: none };\n }\n\n const data: Record<string, unknown> = { ...extracted.data };\n const merged = new Map<string, ExternalMetadataValue>();\n for (const supplied of sources) {\n for (const [key, sv] of supplied) {\n // Only the manifests of collections this file belongs to.\n if (!mine(sv.collection)) continue;\n // A keyless manifest owns only what this file's schemas mark external\n // (0068 rule 5). An entry carrying anything else sets a key nothing\n // owns, which is the refusal a manifest with keys gives for one. With\n // the marks unknown (the schema set did not resolve, or the caller\n // passed none), nothing is owned and nothing is judged.\n const from = impliedFrom(sv);\n if (from !== undefined && !impliedOwns(from, key)) {\n if (probing || marked === UNKNOWN) continue;\n throw unmarkedRefusal(label, key, sv, entryOf.get(supplied)?.(sv));\n }\n // The document's value stays: the collision is filed by the caller,\n // and the report should show what the public site would publish.\n if (key in extracted.data) continue;\n data[key] = sv.value;\n merged.set(key, sv);\n }\n }\n const locate = (pointer: string): SourceLocation | undefined => {\n const split = splitTopLevel(pointer);\n if (split === undefined) return undefined;\n const sv = merged.get(split.key);\n if (!sv) return undefined;\n const line = manifestLine(sv, split.rest);\n return { file: sv.file, ...(line === undefined ? {} : { line }) };\n };\n return { extracted: { ...extracted, data }, collisions, joins, locate };\n}\n\n/**\n * The refusal for a keyless manifest's entry that sets a field the page's\n * schemas do not mark external (proposal 0068). It is the unowned-key refusal\n * a manifest with `keys` gives when it is read, said per page because what a\n * keyless manifest owns is.\n */\nfunction unmarkedRefusal(\n label: string,\n key: string,\n sv: ExternalMetadataValue,\n entry: ExternalMetadataEntry | undefined,\n): DocmetaError {\n const line = entry?.line ?? sv.line;\n const where = line === undefined ? sv.file : `${sv.file}:${String(line)}`;\n const spelled = entry?.spelled ?? label;\n return new DocmetaError(\n `Manifest ${where}: \"${spelled}\" sets \"${key}\", which this manifest does not own, because the page's schemas do not mark it x-manni-location: external. Mark it external in the page's schemas, or remove it from the entry.`,\n );\n}\n\n/**\n * The top-level keys one document's schemas mark `x-manni-location:\n * external`, read over `probe`: the document's metadata with everything its\n * keyless manifests supply for it (proposal 0068). `undefined` when the\n * document's schemas cannot be resolved or loaded, so the caller reports that\n * the way it always has and a keyless manifest owns nothing for it.\n */\nexport type PageMarks = (\n label: string,\n probe: Readonly<Record<string, unknown>>,\n memberOf: readonly string[],\n) => Promise<ReadonlySet<string> | undefined>;\n\n/** `mergeExternalMetadata`'s result, with the marks it was merged under. */\nexport interface MarkedMerge extends MergedMetadata {\n /** What the document's schemas mark external, when a keyless manifest needed asking. */\n marked?: ReadonlySet<string>;\n}\n\n/**\n * `mergeExternalMetadata`, with a keyless manifest's ownership settled first\n * (proposal 0068). Every command that merges goes through here, so what such\n * a manifest owns for a page is decided one way.\n *\n * The marks are read only when one of the document's collections declares a\n * manifest with no `keys`, which no config written before 0068 does, so\n * those runs never load a schema to merge. They are read over the document\n * with every value its keyless manifests supply, because a mark counts only\n * where Ajv evaluates it, and Ajv evaluates a property that is present.\n */\nexport async function mergeWithMarks(\n label: string,\n extracted: ExtractedMetadata,\n index: ExternalMetadataIndex | null,\n memberOf: readonly string[],\n base: string,\n options: { encryptionKey?: () => string | undefined; marks?: PageMarks },\n): Promise<MarkedMerge> {\n const { encryptionKey, marks } = options;\n if (marks === undefined || !hasImpliedOwner(index, memberOf)) {\n return mergeWith(label, extracted, index, memberOf, base, encryptionKey, UNKNOWN);\n }\n // First pass: include the keyless manifests' values, because a schema's\n // `x-manni-location` marks only fire on keys that are present.\n const probe = mergeWith(label, extracted, index, memberOf, base, encryptionKey, PROBE).extracted.data;\n const marked = await marks(label, probe, memberOf);\n // With the page's schema set unresolvable, the probe was spent for\n // nothing, and the merge below is the one a keyless-free collection gets.\n const merged = mergeWith(label, extracted, index, memberOf, base, encryptionKey, marked ?? UNKNOWN);\n return marked === undefined ? merged : { ...merged, marked };\n}\n\n/** Does one of these collections declare a manifest with no `keys` in this index? */\nexport function hasImpliedOwner(\n index: ExternalMetadataIndex | null,\n memberOf: readonly string[],\n): boolean {\n if (index === null) return false;\n return (impliedOwners.get(index) ?? []).some((o) => memberOf.includes(o.collection.name));\n}\n\n/**\n * The manifest line of `rest`, a pointer inside one supplied value: the\n * deepest node it reaches, else the nearest recorded ancestor, else the owned\n * key's own line. The same walk-up rule a document's `lineFor` follows.\n */\nfunction manifestLine(sv: ExternalMetadataValue, rest: string): number | undefined {\n if (rest === \"\" || sv.lines === undefined) return sv.line;\n return positionForFactory(sv.lines)(rest) ?? sv.line;\n}\n\n/**\n * The top-level key a pointer (or bare key) addresses, unescaped, and the\n * still-escaped pointer beneath it. Undefined for the root.\n */\nfunction splitTopLevel(pointer: string): { key: string; rest: string } | undefined {\n if (pointer === \"\") return undefined;\n if (!pointer.startsWith(\"/\")) return { key: pointer, rest: \"\" };\n const slash = pointer.indexOf(\"/\", 1);\n const seg = slash < 0 ? pointer.slice(1) : pointer.slice(1, slash);\n return {\n key: seg.replace(/~1/g, \"/\").replace(/~0/g, \"~\"),\n rest: slash < 0 ? \"\" : pointer.slice(slash),\n };\n}\n\n/** The `/key` pointer for an external-metadata finding, RFC 6901 escaped. */\nexport function externalMetadataPointer(key: string): string {\n return `/${escapePointerSegment(key)}`;\n}\n\n/**\n * Path entries naming no loaded document.\n *\n * `loaded` are the run's file labels, relative to `base`. Checked only when\n * the run is the config corpus (the same invariant corpus checks use): a\n * positional path means the operator chose to look at part of the corpus,\n * and an entry for the rest is expected, not orphaned.\n *\n * A `{page}` entry (proposal 0058) is never orphaned inside a file the run\n * read, because each file is named after its page. Its orphan is a stray\n * *file*, left behind by a `git mv` or a deletion, so on a run with no\n * `collections` narrowing the pattern's glob is walked and every manifest of\n * a page the run did not load is reported after the entries above. A\n * `--collection` run skips the walk: another collection's pages, which it\n * did not load, could share the pattern.\n */\nexport function orphanEntries(\n index: ExternalMetadataIndex | null,\n loaded: readonly string[],\n base: string,\n collections?: readonly string[],\n): ExternalMetadataEntry[] {\n if (!index) return [];\n const have = new Set(loaded.map((l) => resolve(base, l)));\n const orphans = index.entries.filter(\n (e) =>\n inCollections(e, collections) &&\n e.join === PATH_JOIN &&\n e.abs !== undefined &&\n !have.has(e.abs),\n );\n if (collections !== undefined) return orphans;\n return [...orphans, ...strayManifests(perPageRules.get(index) ?? [], have, base)];\n}\n\n/**\n * Manifests a `{page}` pattern names on disk for pages the run did not load\n * (0058 § 5), one orphan per entry. A file some loaded page resolves to was\n * read and checked by the loader, so it is not walked into again.\n */\nfunction strayManifests(\n rules: readonly PerPageRule[],\n loaded: ReadonlySet<string>,\n base: string,\n): ExternalMetadataEntry[] {\n const strays: ExternalMetadataEntry[] = [];\n for (const { collection, manifest, configDir } of rules) {\n const read = new Set<string>();\n for (const pageAbs of loaded) {\n const resolved = pageManifestPath(manifest.file, configDir, pageAbs);\n if (!(\"outside\" in resolved)) read.add(resolved.abs);\n }\n const found = findPageManifests(manifest.file, configDir, (rel) => isMember(collection, rel), read);\n for (const { abs, entries } of found) {\n const file = reportedPath(abs, base);\n for (const entry of entries) {\n if (loaded.has(entry.pageAbs)) continue;\n const stray: ExternalMetadataEntry = {\n collection: collection.name,\n join: PATH_JOIN,\n abs: entry.pageAbs,\n spelled: entry.spelled,\n file,\n ...(entry.line === undefined ? {} : { line: entry.line }),\n };\n strayEntries.add(stray);\n strays.push(stray);\n }\n }\n }\n return strays;\n}\n\n/**\n * Is this entry's collection one the run covers whole?\n *\n * `undefined` means every collection, which is a run with no `--collection`.\n * Naming collections makes each named one its own corpus (proposal 0041 rule\n * 6): the run loaded all of it, so an entry of that collection pointing at a\n * document that is not there is as orphaned as it would be in a full run. An\n * entry belonging to a collection nobody selected is not — the run never\n * claimed to cover it.\n */\nfunction inCollections(\n entry: ExternalMetadataEntry,\n collections: readonly string[] | undefined,\n): boolean {\n return collections === undefined || collections.includes(entry.collection);\n}\n\n/**\n * Field entries no loaded document matched (0039). `matched` is field -> the\n * values documents in the run carried, which the caller collects from each\n * document's `joins` — so this runs after the per-file loop, under the same\n * corpus invariant as `orphanEntries`.\n */\nexport function orphanJoins(\n index: ExternalMetadataIndex | null,\n matched: ReadonlyMap<string, ReadonlySet<string>>,\n collections?: readonly string[],\n): ExternalMetadataEntry[] {\n if (!index) return [];\n return index.entries.filter(\n (e) =>\n inCollections(e, collections) &&\n e.join !== PATH_JOIN &&\n !(matched.get(e.join)?.has(e.spelled) ?? false),\n );\n}\n\n/** The operational error an orphan check raises, naming the first entry. */\nexport function orphanError(orphans: readonly ExternalMetadataEntry[]): DocmetaError {\n const first = orphans[0];\n if (!first) throw new Error(\"orphanError called with no orphans\");\n const where = first.line === undefined ? first.file : `${first.file}:${first.line}`;\n const more = orphans.length > 1 ? ` (${orphans.length - 1} more)` : \"\";\n const what =\n first.join === PATH_JOIN\n ? `names \"${first.spelled}\", which this run did not load`\n : `names ${first.join} \"${first.spelled}\", which no loaded document carries`;\n // A stray per-page file holds its one page's entry, so the file goes with it.\n const remove = strayEntries.has(first) ? \"the file\" : \"it\";\n return new DocmetaError(\n `Manifest ${where} ${what}${more}. Fix the entry, or remove ${remove}.`,\n );\n}\n\n/**\n * Every manifest of `memberOf`'s collections that owns `key` for one page:\n * those whose `keys` name it, and a keyless one (proposal 0068) when `marked`,\n * the page's external marks, holds it. Empty when none does.\n */\nexport function pageOwners(\n index: ExternalMetadataIndex | null,\n key: string,\n memberOf: readonly string[],\n marked: ReadonlySet<string> | undefined,\n): { collection: string; file: string }[] {\n if (index === null) return [];\n return [\n ...(index.owners.get(key) ?? []).filter((o) => memberOf.includes(o.collection)),\n ...(impliedOwners.get(index) ?? [])\n .filter((o) => memberOf.includes(o.collection.name) && ownsKey(o.collection, o.manifest, key, marked))\n .map((o) => ({ collection: o.collection.name, file: o.file })),\n ];\n}\n","/**\n * Compare-and-swap for a manifest a command rewrites in memory.\n *\n * Every tool that writes external metadata does the same thing. It reads a\n * manifest once, splices the entries it owns into the text it read, and writes\n * the whole file back seconds later, after the minting or hashing or model\n * round trips that made the values. Two commands over one working copy overlap\n * inside that gap easily, and each writes bytes derived from a read that\n * predates the other, so the second write replaces the first's entries with\n * bytes that never had them. Nothing reports it: the loser's entries simply\n * are not there, and a manifest short of an entry reads as a file nobody\n * recorded anything about.\n *\n * So the write is a compare-and-swap. The run keeps, beside the text it is\n * building, the edits it made as plain descriptors and the value each entry's\n * key held when it first touched it. The write re-reads, writes when the bytes\n * are the ones it spliced from, and otherwise replays the descriptors onto the\n * newer bytes and looks again. A replay keeps the other run's entries, because\n * each edit replaces one range of the text it is given and leaves every other\n * byte alone. A key both runs wrote cannot be replayed, because the value this\n * run computed was derived from the other one's absence, so that is a refusal\n * rather than a silent merge.\n *\n * The conflict base is one entry's one key, not the whole entry. `meta fill`\n * writing `summary` and `meta derive` writing `updated` into one page's entry\n * are not in conflict, and a base keyed on the entry alone would refuse them\n * both.\n *\n * What this module cannot own is the splice itself. Reading and rewriting one\n * key of a manifest is the metadata tool's, and the shared layer does not\n * import a tool's module (`write-file.ts` states the rule), so the caller\n * hands in an `apply` and a `read` and this file owns only hold, re-read,\n * replay and refuse.\n *\n * This narrows the window rather than closing it: nothing stops a third write\n * landing between the re-read and the rename. The window goes from the length\n * of a whole command to the microseconds around one `rename`, which is what a\n * lock file would have to justify itself against.\n */\nimport { readFile } from \"node:fs/promises\";\nimport { posix } from \"node:path\";\n\n/** One entry's one key: what an edit rewrites, and what a conflict is about. */\nexport interface ManifestKey {\n /** The entry, as the manifest spells it. */\n entry: string;\n /** The key of that entry the edit rewrites. */\n key: string;\n /** How entry keys are compared; `path` normalizes separators. */\n join: string;\n}\n\n/** One edit a run made, replayable onto bytes read later. */\nexport interface ManifestOp extends ManifestKey {\n /** The manifest as the run names it in its own messages. */\n file: string;\n}\n\n/**\n * The two halves of a manifest this loop cannot own: applying one recorded\n * edit to whatever text it is handed, and reading one entry's key back out of\n * text the run has not seen before.\n */\nexport interface ManifestCodec<Op extends ManifestOp> {\n /** One recorded edit, against whatever text it is handed. */\n apply: (text: string, op: Op) => string;\n /** One entry's key as the given text holds it, or `undefined` when absent. */\n read: (text: string, at: ManifestKey) => unknown;\n}\n\n/** An entry's key this run rewrote, and what it held before the run did. */\ninterface KeyBase extends ManifestKey {\n /** The value as it was read, encoded so absence cannot collide. */\n value: string;\n}\n\n/** One manifest held for the length of a run: its text before, and now. */\nexport interface HeldManifest<Op extends ManifestOp> {\n /** Absolute path, the write target. */\n path: string;\n /** The manifest as the run reports it. */\n file: string;\n /** The bytes the run's edits were computed from. */\n before: string;\n /** The bytes as the run has rewritten them. */\n text: string;\n /** Every edit this run made, in order, for a replay onto newer bytes. */\n ops: Op[];\n /** Each entry key this run rewrote, and what it held first. */\n bases: Map<string, KeyBase>;\n /**\n * The file did not exist when it was held, so `before` is empty text\n * standing in for no file (proposal 0058). A distinct state from a file\n * that exists and is empty: a commit that still finds nothing creates the\n * file, and one that finds any bytes, empty ones included, rebases onto\n * them, since another writer created it in between.\n */\n absent: boolean;\n}\n\n/** How many times a write re-reads and replays before it refuses. */\nexport const COMMIT_ATTEMPTS = 5;\n\n/** The refusal when a manifest will not hold still long enough to be written. */\nexport function conflictRefusal(file: string): string {\n return `${file} changed under the command while it was being written. Nothing was written to it. Re-run the command.`;\n}\n\n/**\n * A manifest read, ready to be spliced and later settled. `absent` holds a\n * file that does not exist yet, with `before` as the empty text it stands in\n * for; only a per-page manifest (proposal 0058) is ever held that way.\n */\nexport function heldManifest<Op extends ManifestOp>(\n path: string,\n file: string,\n before: string,\n absent = false,\n): HeldManifest<Op> {\n return { path, file, before, text: before, ops: [], bases: new Map(), absent };\n}\n\n/**\n * A value as read, or the absence of one, as one comparable string.\n * `JSON.stringify` never answers a bare word, so `absent` cannot collide with\n * a value an entry actually holds.\n */\nfunction encodeValue(value: unknown): string {\n return value === undefined ? \"absent\" : JSON.stringify(value);\n}\n\n/** An entry and a key as one map key, spelled the way the manifest joins. */\nfunction baseKey(at: ManifestKey): string {\n const entry = at.join === \"path\" ? posix.normalize(at.entry) : at.entry;\n return `${entry}\\u0000${at.key}`;\n}\n\n/** Note what an entry's key held before this run first rewrote it. */\nexport function rebaseable<Op extends ManifestOp>(\n held: HeldManifest<Op>,\n op: Op,\n codec: ManifestCodec<Op>,\n): void {\n const at = baseKey(op);\n if (held.bases.has(at)) return;\n held.bases.set(at, {\n entry: op.entry,\n key: op.key,\n join: op.join,\n value: encodeValue(codec.read(held.before, op)),\n });\n}\n\n/**\n * Replay this run's edits onto the manifest as it now stands, or `undefined`\n * when a key this run rewrote has changed since it was read. Each edit\n * replaces one range of the text it is given, so every entry this run did not\n * touch survives the replay untouched.\n */\nexport function rebase<Op extends ManifestOp>(\n held: HeldManifest<Op>,\n current: string,\n codec: ManifestCodec<Op>,\n): string | undefined {\n for (const base of held.bases.values()) {\n if (encodeValue(codec.read(current, base)) !== base.value) return undefined;\n }\n let text = current;\n for (const op of held.ops) text = codec.apply(text, op);\n return text;\n}\n\n/**\n * Take the bytes just written as the new base, so a run that writes one\n * manifest more than once compares its next write against what it left on\n * disk. Without it the second write would replay against the pre-run text and\n * call this run's own first write somebody else's.\n */\nexport function rebaseline<Op extends ManifestOp>(held: HeldManifest<Op>): void {\n held.before = held.text;\n held.ops = [];\n held.bases.clear();\n held.absent = false;\n}\n\n/** What `settle` needs from the tool around it. */\nexport interface SettleIo<Op extends ManifestOp> {\n /** Applying and reading one edit; the metadata tool's, handed in. */\n codec: ManifestCodec<Op>;\n /** The byte writer; an atomic write unless a test says otherwise. */\n write: (path: string, text: string) => Promise<void>;\n /**\n * The compare-and-swap re-read, for a test counting the retries. It is that\n * loop's read alone: the first read of a manifest is the caller's.\n */\n read: (path: string) => Promise<string>;\n /** The calling tool's error class, so a refusal reads as that tool's. */\n toError: (message: string) => Error;\n}\n\n/**\n * Write one manifest, re-reading it first so the bytes being replaced are the\n * bytes this run spliced from. A run that loses the compare replays its edits\n * onto what it found and looks again; one that keeps losing refuses, having\n * written nothing.\n */\nexport async function settle<Op extends ManifestOp>(\n held: HeldManifest<Op>,\n io: SettleIo<Op>,\n): Promise<void> {\n for (let attempt = 1; attempt <= COMMIT_ATTEMPTS; attempt++) {\n let current: string;\n try {\n current = await io.read(held.path);\n } catch (error) {\n // Held absent and still missing: this run creates the file. A file that\n // was present when it was held and is gone now is a refusal, as it\n // always was, because something removed it on purpose.\n if (held.absent && isMissing(error)) {\n await io.write(held.path, held.text);\n held.absent = false;\n return;\n }\n const reason = error instanceof Error ? error.message : String(error);\n throw io.toError(`Manifest ${held.file} could not be read: ${reason}`);\n }\n // Bytes where the run held none are another writer's file, even empty\n // ones, so they are rebased onto rather than written over.\n if (!held.absent && current === held.before) {\n await io.write(held.path, held.text);\n return;\n }\n const replayed = rebase(held, current, io.codec);\n // A replay that cannot be made is a verdict about bytes just read, against\n // a base fixed when this run first touched the key. Neither side of that\n // comparison moves on a re-read, so the attempts are left for the case\n // they exist for, which is a file moving under replays that do succeed.\n if (replayed === undefined) throw io.toError(conflictRefusal(held.file));\n held.before = current;\n held.text = replayed;\n held.absent = false;\n }\n throw io.toError(conflictRefusal(held.file));\n}\n\n/** A read that failed because nothing is there. */\nexport function isMissing(error: unknown): boolean {\n return typeof error === \"object\" && error !== null && \"code\" in error && error.code === \"ENOENT\";\n}\n\n/**\n * A manifest's bytes, read just before a writer splices into them. A per-page\n * manifest (proposal 0058) that is not on disk yet is a page with nothing\n * recorded: it reads as empty text, and the write creates it. A missing\n * concrete manifest, or any other failure, is thrown for the caller to report\n * in its own error class.\n */\nexport async function readManifestOrEmpty(absPath: string, perPage: boolean): Promise<string> {\n try {\n return await readFile(absPath, \"utf8\");\n } catch (e) {\n if (perPage && isMissing(e)) return \"\";\n throw e;\n }\n}\n\n/** What a caller may substitute when it writes the manifests it held. */\nexport interface CommitIo<Change> {\n /** The byte writer; an atomic write unless a test says otherwise. */\n write?: (path: string, text: string) => Promise<void>;\n /** The compare-and-swap re-read, for a test counting the retries. */\n read?: (path: string) => Promise<string>;\n /** Called after each manifest lands, in write order. */\n after?: (change: Change) => void;\n /** Called when one manifest fails to land; must throw. */\n onError?: (change: Change, error: unknown) => Promise<never>;\n}\n","/**\n * `x-manni-location` (proposal 0047): where a schema would like a top-level\n * key's value stored, on the page or in external metadata.\n *\n * The keyword is registered on every Ajv meta builds (validator.ts), next to\n * `x-manni-encrypt`, and like it records where it was evaluated. Ajv's own\n * resolution is the walker, so a mark counts through `$ref`, `allOf` and a\n * referenced built-in, and inside the `anyOf`, `oneOf` and `if`/`then`\n * branches Ajv takes. Only top-level properties carry a preference; a nested\n * mark is accepted and ignored. `Validator.locationPreferences` is the one\n * question commands ask of it.\n *\n * One schema marking one key both ways is judged twice. Through `properties`,\n * `allOf` and local `$ref` alone, it is refused when the schema compiles.\n * Across conditional branches it is not an error: Ajv evaluates failing\n * branches too, so that schema gives the key no preference.\n */\n\n/** The schema keyword. */\nexport const LOCATION_KEYWORD = \"x-manni-location\";\n\n/** Where a top-level key prefers to live. */\nexport type FieldLocation = \"page\" | \"external\";\n\n/** A key's preferred location, and the schema ref whose mark decided it. */\nexport interface LocationPreference {\n location: FieldLocation;\n /** The ref, as given to `locationPreferences`, whose mark won. */\n schema: string;\n}\n\n/**\n * validate's two findings about a misplaced value, both warnings. Builtin-shaped\n * refs like `external:owned`, so the rule ids are `location:external/location`\n * and `location:page/location`.\n */\nexport const LOCATION_EXTERNAL_SCHEMA = \"location:external\";\nexport const LOCATION_PAGE_SCHEMA = \"location:page\";\n/** The `keyword` both findings carry. */\nexport const LOCATION_FINDING_KEYWORD = \"location\";\n\nexport function isFieldLocation(value: unknown): value is FieldLocation {\n return value === \"page\" || value === \"external\";\n}\n","/**\n * `x-manni-graph-output` (proposal 0051 §5): whether a top-level key belongs in a\n * published knowledge graph. graph harvests frontmatter into Turtle, JSON-LD,\n * iiRDS and a search index, all of which get published, and which fields belong\n * in that output is a property of the field rather than of the tool — so it is\n * recorded where the field is defined.\n *\n * The keyword is registered on every Ajv meta builds (validator.ts), next to\n * `x-manni-location`, and like it records where it was evaluated. Ajv's own\n * resolution is the walker, so a mark counts through `$ref`, `allOf` and a\n * referenced built-in, and inside the `anyOf`, `oneOf` and `if`/`then` branches\n * Ajv takes. Absent means `true`: every field is harvested unless a schema says\n * otherwise. Only a top-level property's mark counts; a mark nested inside `graph`\n * is accepted and ignored, as 0047 rule 2 ignores a nested `x-manni-location`.\n * `Validator.graphOutputPreferences` is the one question a tool asks of it.\n *\n * Why this is not `x-manni-location` (0051 stress test 3): the two answer\n * different questions. `x-manni-location` says where a field is *written* — in\n * the page or in a manifest — and says nothing about whether a delivered\n * artifact should carry it. A field can be `external` and still belong in the\n * graph (`authors` on a published page), or be page-local and not belong in it\n * at all. Overloading one mark would make `manni meta relocate` a publishing\n * decision.\n */\n\n/** The schema keyword. */\nexport const GRAPH_OUTPUT_KEYWORD = \"x-manni-graph-output\";\n","/**\n * JSON Schema validation engine. Compiles and caches an Ajv validator per\n * schema reference, validates extracted metadata against each schema in a set,\n * and maps every violation to a {schema, instancePath, line, col} FieldError.\n */\nimport * as AjvDraft07Ns from \"ajv\";\nimport * as Ajv2019Ns from \"ajv/dist/2019.js\";\nimport * as Ajv2020Ns from \"ajv/dist/2020.js\";\nimport * as AjvDraft04Ns from \"ajv-draft-04\";\nimport * as addFormatsNs from \"ajv-formats\";\nimport { createRequire } from \"node:module\";\nimport type {\n DefinedError,\n ErrorObject,\n ValidateFunction,\n} from \"ajv/dist/2020.js\";\nimport { DocmetaError, type FieldError } from \"../types.js\";\nimport type { SourceLocation } from \"./external-metadata.js\";\nimport { escapePointerSegment } from \"../extractors/pointer.js\";\n\n// ajv ships its meta-schema refs as JSON. A static JSON import survives\n// bundling as a bare ESM import without the required `type: json` attribute, so\n// load it through `require` instead (ajv is an external dep at runtime).\nconst draft06MetaSchema = createRequire(import.meta.url)(\n \"ajv/dist/refs/json-schema-draft-06.json\",\n) as Record<string, unknown>;\n\n// ajv and ajv-formats are CommonJS with a default export; under NodeNext the\n// callable/constructable value lives on `.default`. Cast through the named\n// default types so tsc sees a constructor / callable. The per-dialect builds\n// expose the same shape, so we treat them all as the 2020 constructor type.\ntype AjvCtor = typeof import(\"ajv/dist/2020.js\").default;\nconst AjvDraft07 = AjvDraft07Ns.default as unknown as AjvCtor;\nconst Ajv2019 = Ajv2019Ns.default as unknown as AjvCtor;\nconst Ajv2020 = Ajv2020Ns.default as unknown as AjvCtor;\nconst AjvDraft04 = AjvDraft04Ns.default as unknown as AjvCtor;\nconst addFormats =\n addFormatsNs.default as unknown as typeof import(\"ajv-formats\").default;\nimport {\n loadSchema,\n publishedBuiltins,\n type LoadSchemaOptions,\n type RegisteredSchemas,\n} from \"./schema-registry.js\";\nimport { FILE_SCHEMA_KEY } from \"./resolve-schema.js\";\nimport { ENCRYPT_KEYWORD } from \"./encrypted.js\";\nimport {\n LOCATION_KEYWORD,\n isFieldLocation,\n type FieldLocation,\n type LocationPreference,\n} from \"./location.js\";\nimport { GRAPH_OUTPUT_KEYWORD } from \"./graph-output.js\";\nimport { errorMessage } from \"../../shared/errors.js\";\n\ntype Dialect = \"2020\" | \"2019\" | \"draft7\" | \"draft4\";\n\n/**\n * Pick a JSON Schema dialect from a schema's own `$schema` meta-schema URI.\n * Remote schemas commonly target draft-07/draft-04, which the 2020 build can't\n * compile, so each dialect gets its own Ajv. A missing or unrecognized\n * `$schema` falls back to 2020 (the dialect of the built-ins).\n */\nfunction dialectOf(schema: Record<string, unknown>): Dialect {\n const meta = typeof schema.$schema === \"string\" ? schema.$schema : \"\";\n if (meta.includes(\"2019-09\")) return \"2019\";\n // draft-06 shares the draft-07 build (its meta-schema is registered there).\n if (\n meta.includes(\"draft-07\") ||\n meta.includes(\"draft/7\") ||\n meta.includes(\"draft-06\") ||\n meta.includes(\"draft/6\")\n ) {\n return \"draft7\";\n }\n if (meta.includes(\"draft-04\") || meta.includes(\"draft/4\")) return \"draft4\";\n return \"2020\";\n}\n\nfunction buildAjv(\n dialect: Dialect,\n coerceTypes: false | \"array\" = false,\n): InstanceType<AjvCtor> {\n // strict: false so user-supplied schemas with lax metadata still compile.\n const opts = { allErrors: true, strict: false, coerceTypes } as const;\n const ajv =\n dialect === \"2019\"\n ? new Ajv2019(opts)\n : dialect === \"draft7\"\n ? new AjvDraft07(opts)\n : dialect === \"draft4\"\n ? new AjvDraft04(opts)\n : new Ajv2020(opts);\n addFormats(ajv);\n // draft-06 shares the draft-07 build; register its meta-schema so draft-06\n // schemas compile too rather than erroring on an unknown `$schema`.\n if (dialect === \"draft7\") ajv.addMetaSchema(draft06MetaSchema);\n registerEncryptKeyword(ajv);\n registerLocationKeyword(ajv);\n registerGraphOutputKeyword(ajv);\n registerBuiltins(ajv, dialect);\n return ajv;\n}\n\n/**\n * Where `x-manni-encrypt: true` records the instance pointers it is evaluated\n * at, while `markedPointers` is running. `undefined` the rest of the time, so\n * an ordinary validation pays one comparison per marked property.\n *\n * Module state is safe here because a compiled validator is synchronous: the\n * recorder is set, the one call runs to completion, and it is cleared, all in\n * one tick. `fill`'s worker pool interleaves only at its awaits, and there is\n * none inside that window.\n */\nlet markRecorder: Set<string> | undefined;\n\n/**\n * `x-manni-encrypt` (proposal 0045), on every Ajv meta builds. It never fails\n * a value: validation of a marked property is the rest of its schema, run on\n * the decrypted copy. What it does is say where it was evaluated, so Ajv's\n * own resolution — `$ref`, `allOf`, a referenced built-in, the `anyOf`,\n * `oneOf` and `if` branches it takes — decides where a mark counts.\n *\n * The boolean meta-schema is what refuses `\"x-manni-encrypt\": \"yes\"` at\n * compile time; `compileUncached` turns Ajv's wording into the one message\n * the plan ships.\n */\nfunction registerEncryptKeyword(ajv: InstanceType<AjvCtor>): void {\n ajv.addKeyword({\n keyword: ENCRYPT_KEYWORD,\n metaSchema: { type: \"boolean\" },\n errors: false,\n validate: (\n schema: unknown,\n _data: unknown,\n _parent?: unknown,\n cxt?: { instancePath: string },\n ): boolean => {\n if (schema === true && markRecorder !== undefined) {\n markRecorder.add(cxt?.instancePath ?? \"\");\n }\n return true;\n },\n });\n}\n\n/** Ajv's compile error for a non-boolean mark names the keyword. */\nfunction isMarkShapeError(err: unknown): boolean {\n return err instanceof Error && err.message.includes(`\"${ENCRYPT_KEYWORD}\"`);\n}\n\n/**\n * Where `x-manni-location` records what it says for each top-level key it is\n * evaluated at, while `locationPreferences` is running: key name to the set of\n * values seen, so one schema saying both is detectable. `undefined` the rest\n * of the time, for the same reason and with the same safety as\n * `markRecorder`.\n */\nlet locationRecorder: Map<string, Set<FieldLocation>> | undefined;\n\n/** A depth-1 instance pointer (`/owner`), as its unescaped key; else undefined. */\nfunction topLevelKey(instancePath: string): string | undefined {\n if (!instancePath.startsWith(\"/\") || instancePath.indexOf(\"/\", 1) !== -1) {\n return undefined;\n }\n return instancePath.slice(1).replace(/~1/g, \"/\").replace(/~0/g, \"~\");\n}\n\n/**\n * `x-manni-location` (proposal 0047), on every Ajv meta builds. Like\n * `x-manni-encrypt`, it never fails a value; it says where it was evaluated,\n * so a mark counts wherever Ajv's resolution takes the validator. Only a mark\n * evaluated at a top-level property is recorded; a nested one is accepted and\n * ignored. The enum meta-schema refuses any other value at compile time, and\n * `compileUncached` turns Ajv's wording into the plan's message.\n */\nfunction registerLocationKeyword(ajv: InstanceType<AjvCtor>): void {\n ajv.addKeyword({\n keyword: LOCATION_KEYWORD,\n metaSchema: { type: \"string\", enum: [\"page\", \"external\"] },\n errors: false,\n validate: (\n schema: unknown,\n _data: unknown,\n _parent?: unknown,\n cxt?: { instancePath: string },\n ): boolean => {\n if (locationRecorder !== undefined && isFieldLocation(schema)) {\n const key = topLevelKey(cxt?.instancePath ?? \"\");\n if (key !== undefined) {\n const seen = locationRecorder.get(key);\n if (seen) seen.add(schema);\n else locationRecorder.set(key, new Set([schema]));\n }\n }\n return true;\n },\n });\n}\n\n/** Ajv's compile error for a mark outside the enum names the keyword. */\nfunction isLocationShapeError(err: unknown): boolean {\n return err instanceof Error && err.message.includes(`\"${LOCATION_KEYWORD}\"`);\n}\n\n/**\n * Where `x-manni-graph-output` records what it says for each top-level key it is\n * evaluated at, while `graphOutputPreferences` is running: key name to the set of\n * values seen, so one schema saying both is detectable. `undefined` the rest of\n * the time, for the same reason and with the same safety as `markRecorder`.\n */\nlet graphOutputRecorder: Map<string, Set<boolean>> | undefined;\n\n/**\n * `x-manni-graph-output` (proposal 0051 §5), on every Ajv meta builds. Like\n * `x-manni-location`, it never fails a value; it says where it was evaluated,\n * so a mark counts wherever Ajv's resolution takes the validator. Only a mark\n * evaluated at a top-level property is recorded; one nested inside `graph` is\n * accepted and ignored. The boolean meta-schema refuses any other value at\n * compile time, and `compileUncached` turns Ajv's wording into the plan's\n * message.\n */\nfunction registerGraphOutputKeyword(ajv: InstanceType<AjvCtor>): void {\n ajv.addKeyword({\n keyword: GRAPH_OUTPUT_KEYWORD,\n metaSchema: { type: \"boolean\" },\n errors: false,\n validate: (\n schema: unknown,\n _data: unknown,\n _parent?: unknown,\n cxt?: { instancePath: string },\n ): boolean => {\n if (graphOutputRecorder !== undefined && typeof schema === \"boolean\") {\n const key = topLevelKey(cxt?.instancePath ?? \"\");\n if (key !== undefined) {\n const seen = graphOutputRecorder.get(key);\n if (seen) seen.add(schema);\n else graphOutputRecorder.set(key, new Set([schema]));\n }\n }\n return true;\n },\n });\n}\n\n/** Ajv's compile error for a non-boolean mark names the keyword. */\nfunction isGraphOutputShapeError(err: unknown): boolean {\n return err instanceof Error && err.message.includes(`\"${GRAPH_OUTPUT_KEYWORD}\"`);\n}\n\n/** Does this schema mark its own top-level `$schema` property external? */\nfunction marksSchemaExternal(schema: Record<string, unknown>): boolean {\n const properties = schema[\"properties\"];\n if (typeof properties !== \"object\" || properties === null) return false;\n const own: unknown = (properties as Record<string, unknown>)[FILE_SCHEMA_KEY];\n if (typeof own !== \"object\" || own === null) return false;\n return (own as Record<string, unknown>)[LOCATION_KEYWORD] === \"external\";\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * The first top-level key this schema gives two different values of the mark\n * `keyword` on paths every document takes; else undefined. `isMark` says\n * which values count, so a malformed one is left to the keyword's own check.\n *\n * Unconditional means the schema's own `properties`, its `allOf` entries, and\n * a local `$ref` reached from those, applied again inside a property's\n * subschema. `anyOf`, `oneOf`, `if`/`then`/`else` and `not` are conditional,\n * so marks that differ across them are not a contradiction. A remote `$ref`\n * is not chased, and neither is a local one inside an embedded `$id`, whose\n * `#` names another resource.\n */\nfunction definiteMarkConflict(\n root: Record<string, unknown>,\n keyword: string,\n isMark: (value: unknown) => boolean,\n): string | undefined {\n const marks = new Map<string, Set<unknown>>();\n /** The target of a `#/...` pointer from the root, if it resolves. */\n const localRef = (node: Record<string, unknown>, embedded: boolean): unknown => {\n const ref = node[\"$ref\"];\n if (embedded || typeof ref !== \"string\" || !ref.startsWith(\"#\")) return undefined;\n const pointer = ref.slice(1);\n if (pointer === \"\") return root;\n if (!pointer.startsWith(\"/\")) return undefined;\n let at: unknown = root;\n for (const raw of pointer.slice(1).split(\"/\")) {\n let segment: string;\n try {\n segment = decodeURIComponent(raw).replace(/~1/g, \"/\").replace(/~0/g, \"~\");\n } catch {\n return undefined;\n }\n if (Array.isArray(at)) at = at[Number(segment)] as unknown;\n else if (isRecord(at)) at = at[segment];\n else return undefined;\n }\n return at;\n };\n const isEmbedded = (node: Record<string, unknown>, embedded: boolean): boolean =>\n embedded || (node !== root && typeof node[\"$id\"] === \"string\");\n const allOf = (node: Record<string, unknown>): unknown[] =>\n Array.isArray(node[\"allOf\"]) ? (node[\"allOf\"] as unknown[]) : [];\n\n const property = (key: string, node: unknown, embedded: boolean, visited: Set<unknown>): void => {\n if (!isRecord(node) || visited.has(node)) return;\n visited.add(node);\n const inner = isEmbedded(node, embedded);\n const mark = node[keyword];\n if (isMark(mark)) {\n const seen = marks.get(key);\n if (seen) seen.add(mark);\n else marks.set(key, new Set([mark]));\n }\n for (const entry of allOf(node)) property(key, entry, inner, visited);\n property(key, localRef(node, inner), inner, visited);\n };\n const object = (node: unknown, embedded: boolean, visited: Set<unknown>): void => {\n if (!isRecord(node) || visited.has(node)) return;\n visited.add(node);\n const inner = isEmbedded(node, embedded);\n const properties = node[\"properties\"];\n if (isRecord(properties)) {\n for (const [key, sub] of Object.entries(properties)) property(key, sub, inner, new Set());\n }\n for (const entry of allOf(node)) object(entry, inner, visited);\n object(localRef(node, inner), inner, visited);\n };\n object(root, false, new Set());\n for (const [key, seen] of marks) if (seen.size > 1) return key;\n return undefined;\n}\n\n/**\n * Make every built-in resolvable as a `$ref` target, under both of its names.\n *\n * Ajv is constructed with no `loadSchema`, so before this a user's schema could\n * not `$ref` a built-in by **any** route — not the published URL (nothing to\n * fetch it with) and not the docmeta id either, even though the schema was\n * bundled and would later be compiled into this very instance. Both failed with\n * \"can't resolve reference … from id #\", which reads like the published file is\n * broken. Proposal 0009 stress test 5.\n *\n * Three mechanics that are easy to get wrong:\n *\n * - **One call per built-in.** `addSchema(schema, url)` registers under the key\n * *and* under the schema's own `$id`, so the id form comes for free. Calling\n * it a second time under the id throws \"schema with key or id … already\n * exists\".\n * - **Meta-schema validation is off for these.** All the built-ins are\n * 2020-12, and the 2019/draft-07/draft-04 instances do not carry that\n * meta-schema — `addSchema` would throw `no schema with key or ref\n * \"https://json-schema.org/draft/2020-12/schema\"` and take out every Ajv but\n * one. These are docmeta's own files, covered by their own tests, so skipping\n * the check costs nothing. The flag is per call: a *user's* schema is still\n * validated normally.\n * - **All four dialects, not just 2020.** `dialectOf` picks the instance from\n * the *user's* `$schema`, so a draft-07 house schema extending OKF compiles in\n * the draft-07 Ajv and needs the built-ins registered there too.\n *\n * Registration is lazy — Ajv compiles a stored schema only when something\n * references it — so this costs a map insert per built-in, not fifteen compiles.\n *\n * Called from `buildAjv` rather than from `Validator`, deliberately:\n * `compileWithFormats` builds its own throwaway instance for `fill`'s proposal\n * envelope, which lifts subschemas out of the user's schemas and would\n * otherwise lose every `$ref` into a built-in.\n */\nfunction registerBuiltins(ajv: InstanceType<AjvCtor>, dialect: Dialect): void {\n for (const { id, url, legacyUrl, schema } of publishedBuiltins()) {\n ajv.addSchema(schema, url, undefined, false);\n // A user schema written before the rename `$ref`s the old URL. Same bytes,\n // same object; only the key differs.\n ajv.addSchema(schema, legacyUrl, undefined, false);\n // draft-04 predates `$id` — `ajv-draft-04` reads `id` instead — so the URL\n // key is the only registration the call above produces there, and the id\n // form has to be added explicitly. It does not throw as a duplicate for the\n // same reason: `$id` was never registered.\n if (dialect === \"draft4\") ajv.addSchema(schema, id, undefined, false);\n }\n}\n\n/**\n * Add a config's registered schemas (proposal 0070) to one Ajv, before\n * anything compiles there, as the built-ins are, so any schema can `$ref` one\n * by id. draft-04 reads `id` rather than `$id`, so there the id is the key.\n */\nfunction registerRegistered(\n ajv: InstanceType<AjvCtor>,\n dialect: Dialect,\n registered: RegisteredSchemas | undefined,\n): void {\n for (const { id, schema } of registered?.values() ?? []) {\n ajv.addSchema(schema, dialect === \"draft4\" ? id : undefined, undefined, false);\n }\n}\n\n/**\n * Compile an ad-hoc 2020-12 schema with docmeta's format support.\n *\n * `fill` needs this for the proposal envelope it builds around a document\n * schema's own property subschemas: those routinely carry `format: \"date-time\"`\n * / `\"uri\"`, and an Ajv without `ajv-formats` refuses to compile them outright.\n * A lifted subschema may `$ref` a registered schema, so the run's registered\n * schemas join this instance as they join the validator's.\n *\n * `coerce` turns on Ajv's `coerceTypes: \"array\"`, which rewrites a value of the\n * wrong JSON type into the declared one, in place, before any rule is judged:\n * `\"2\"` to `2`, `\"true\"` to `true`, a lone scalar to a one-item list. `fill`\n * checks each proposed value this way, on a copy. Off by default, because\n * everywhere else a value is judged as it stands.\n */\nexport function compileWithFormats(\n schema: Record<string, unknown>,\n registered?: RegisteredSchemas,\n options: { coerce?: boolean } = {},\n): ValidateFunction {\n const ajv = buildAjv(\"2020\", options.coerce === true ? \"array\" : false);\n registerRegistered(ajv, \"2020\", registered);\n return ajv.compile(schema);\n}\n\n/**\n * A bare Ajv carrying exactly the `addFormats` registration `buildAjv`\n * performs — the reference for what \"a format docmeta enforces\" means.\n * Shared by the two helpers below; built once, lazily.\n */\nlet formatRegistry: InstanceType<AjvCtor> | undefined;\nfunction formatsAjv(): InstanceType<AjvCtor> {\n if (!formatRegistry) {\n formatRegistry = new Ajv2020({ strict: false });\n addFormats(formatRegistry);\n }\n return formatRegistry;\n}\n\n/**\n * The format names docmeta's validators enforce on strings, derived from the\n * ajv-formats registration itself — never a hand-copied parallel list, so an\n * ajv-formats upgrade widens this set without anyone remembering it (proposal\n * 0028). Two exclusions, both because they do not constrain a string:\n * number-typed formats (`int32`, `float`, …) and always-pass placeholders\n * (`password`, `binary`, registered as `true`).\n */\nlet stringFormatsMemo: ReadonlySet<string> | undefined;\nexport function stringFormatNames(): ReadonlySet<string> {\n if (!stringFormatsMemo) {\n const names = new Set<string>();\n const registered: Record<string, unknown> = formatsAjv().formats;\n for (const [name, def] of Object.entries(registered)) {\n const enforcesStrings =\n def instanceof RegExp ||\n typeof def === \"function\" ||\n (typeof def === \"object\" &&\n def !== null &&\n ((def as { type?: string }).type === undefined ||\n (def as { type?: string }).type === \"string\"));\n if (enforcesStrings) names.add(name);\n }\n stringFormatsMemo = names;\n }\n return stringFormatsMemo;\n}\n\n/**\n * Does `value` satisfy the named format? Answered by compiling\n * `{type: \"string\", format: name}` in the same registry — the exact machinery\n * `validate` enforces the format with, so there is no second opinion about\n * what a `date` is (0028's DEFAULT guard).\n */\nconst formatCheckers = new Map<string, ValidateFunction>();\nexport function validatesFormat(name: string, value: string): boolean {\n let fn = formatCheckers.get(name);\n if (!fn) {\n fn = formatsAjv().compile({ type: \"string\", format: name });\n formatCheckers.set(name, fn);\n }\n return fn(value);\n}\n\nexport class Validator {\n /**\n * How this validator's schemas are loaded: the disk cache location, its TTL,\n * and `--offline`. Held per instance rather than read from module state, so\n * two differently-configured validations in one process each get their own\n * settings.\n *\n * That is not full isolation, and the difference matters to a library\n * caller: `schema-registry` keeps a process-wide memo of fetched schemas, so\n * one validator's successful fetch is visible to another. `offline` is\n * excluded from that sharing on purpose — an offline validator will not be\n * served something this process pulled over the network — but the memo is\n * still shared, so a URL fetched once is not re-fetched per instance.\n */\n constructor(private readonly schemaOptions: LoadSchemaOptions = {}) {}\n\n private ajvByDialect = new Map<Dialect, InstanceType<AjvCtor>>();\n /**\n * Keyed on the in-flight *promise*, not the resolved validator. Caching the\n * result made this a check-then-act race: `fill` walks files through a worker\n * pool, so every worker missed the cache while the first `loadSchema` was\n * still pending and they all then compiled the same schema into the one\n * shared per-dialect Ajv. Ajv registers a schema's `$id` on the first compile\n * and rejects the second with \"schema with key or id ... already exists\",\n * which took down any multi-file run against an $id-bearing schema. Storing\n * the promise before the first await lets the losers await the one compile.\n */\n private cache = new Map<string, Promise<ValidateFunction>>();\n\n private ajvFor(dialect: Dialect): InstanceType<AjvCtor> {\n let ajv = this.ajvByDialect.get(dialect);\n if (!ajv) {\n ajv = buildAjv(dialect);\n registerRegistered(ajv, dialect, this.schemaOptions.registered);\n this.ajvByDialect.set(dialect, ajv);\n }\n return ajv;\n }\n\n /**\n * Synchronous by design: the `cache.set` has to happen in the same tick as\n * the miss, or a second caller can slip in before the entry exists.\n */\n private compile(ref: string): Promise<ValidateFunction> {\n const cached = this.cache.get(ref);\n if (cached) return cached;\n const pending = this.compileUncached(ref);\n this.cache.set(ref, pending);\n // A failed load or compile is not cached — a transient fetch failure must\n // stay retryable rather than poisoning the ref for this Validator's life.\n // The extra `catch` keeps the eviction off the returned promise's chain, so\n // it does not convert the rejection into a handled one for the caller.\n pending.catch(() => {\n if (this.cache.get(ref) === pending) this.cache.delete(ref);\n });\n return pending;\n }\n\n private async compileUncached(ref: string): Promise<ValidateFunction> {\n const schema = await loadSchema(ref, this.schemaOptions);\n // `$schema` is how a page names its schema; external metadata is found\n // through that schema, so the directive cannot live there.\n if (marksSchemaExternal(schema)) {\n throw new DocmetaError(\n `${ref}: \"${FILE_SCHEMA_KEY}\" cannot be stored in external metadata.`,\n );\n }\n const contradicted = definiteMarkConflict(schema, LOCATION_KEYWORD, isFieldLocation);\n if (contradicted !== undefined) {\n throw new DocmetaError(\n `${ref}: \"${LOCATION_KEYWORD}\" says both \"page\" and \"external\" for \"${contradicted}\".`,\n );\n }\n const graphContradicted = definiteMarkConflict(\n schema,\n GRAPH_OUTPUT_KEYWORD,\n (value) => typeof value === \"boolean\",\n );\n if (graphContradicted !== undefined) {\n throw new DocmetaError(\n `${ref}: \"${GRAPH_OUTPUT_KEYWORD}\" says both true and false for \"${graphContradicted}\".`,\n );\n }\n try {\n const ajv = this.ajvFor(dialectOf(schema));\n // This cache is keyed on the ref string, but Ajv's registry is keyed on\n // `$id` — so one schema named two ways (a published URL in a document's\n // `$schema`, a local path on the command line) misses the cache twice and\n // Ajv rejects the second compile as a duplicate id. Reuse the existing\n // registration instead. `$id` is the schema's identity as far as Ajv is\n // concerned, so if two refs claim the same one, sharing a validator is\n // the only reading available — the alternative is the hard error this\n // replaces.\n //\n // Reused only when the registration really is *this* object. Sharing on\n // the id alone was tolerable while a registration could only come from an\n // earlier compile in the same run. It stopped being tolerable when\n // `registerBuiltins` began pre-loading every built-in into every\n // instance: an id collision is no longer a race whose outcome depends on\n // ordering, it is certain, and the built-in always wins.\n //\n // What that would silently override is a vendored built-in the user then\n // edited — the workflow proposal 0009 actively encourages. `schemas\n // vendor` writes a copy carrying `$id: google:okf:0.1`, so a house rule\n // added to that copy would simply not apply, while the report went on\n // naming the local path.\n //\n // A different schema claiming a taken id is compiled on its own merits,\n // with the id dropped from a shallow copy: Ajv refuses a second schema\n // under one id, and the id is not what identifies a schema here anyway —\n // the *ref* is what reports name, what baselines fingerprint, and what\n // this cache is keyed on.\n const id = typeof schema[\"$id\"] === \"string\" ? schema[\"$id\"] : undefined;\n const registered = id != null ? ajv.getSchema(id) : undefined;\n if (registered) {\n if (registered.schema === schema) return registered;\n const { $id: _taken, ...anonymous } = schema;\n return ajv.compile(anonymous);\n }\n return ajv.compile(schema);\n } catch (err) {\n if (isMarkShapeError(err)) {\n throw new DocmetaError(\n `${ref}: \"${ENCRYPT_KEYWORD}\" must be true or false.`,\n );\n }\n if (isLocationShapeError(err)) {\n throw new DocmetaError(\n `${ref}: \"${LOCATION_KEYWORD}\" must be \"page\" or \"external\".`,\n );\n }\n if (isGraphOutputShapeError(err)) {\n throw new DocmetaError(\n `${ref}: \"${GRAPH_OUTPUT_KEYWORD}\" must be true or false.`,\n );\n }\n throw new DocmetaError(\n `Schema \"${ref}\" failed to compile: ${errorMessage(err)}`,\n );\n }\n }\n\n /**\n * The instance pointers of `data` that carry `x-manni-encrypt: true` under\n * any schema in `refs`, in the order the validator evaluated them.\n *\n * A first pass with the recording keyword, so a mark counts exactly where\n * validation would evaluate it. Only present values are marked: Ajv applies\n * a property's subschema to a property that exists. A branch Ajv does not\n * take (`then` behind a failing `if`, an `anyOf` branch after a passing\n * one) contributes nothing; a branch it takes contributes its marks\n * whether or not the branch passes, because a ciphertext routinely fails\n * the rest of its own subschema until it is decrypted.\n */\n async markedPointers(\n data: Record<string, unknown>,\n refs: string[],\n ): Promise<Set<string>> {\n const { [FILE_SCHEMA_KEY]: _omit, ...subject } = data;\n void _omit;\n const marks = new Set<string>();\n for (const ref of refs) {\n const fn = await this.compile(ref);\n markRecorder = marks;\n try {\n fn(subject);\n } finally {\n markRecorder = undefined;\n }\n }\n return marks;\n }\n\n /**\n * The location each top-level key of `data` prefers under `refs`: `page` or\n * `external`, and the ref whose `x-manni-location` mark decided it. A key no\n * schema marks has no entry.\n *\n * A first pass with the recording keyword, as `markedPointers` runs, so a\n * mark counts exactly where validation would evaluate it, and a nested mark\n * is ignored. Only present values are marked: Ajv applies a property's\n * subschema to a property that exists. A caller asking where a key it is\n * about to write belongs passes `data` that already holds the candidate\n * value. `$schema` is stripped first, as validation does.\n *\n * Refs are evaluated in order and a later ref's mark wins. A ref that says\n * both values for one key unconditionally is refused when it compiles; one\n * whose evaluated branches say both gives that key no preference.\n */\n async locationPreferences(\n data: Record<string, unknown>,\n refs: string[],\n ): Promise<Map<string, LocationPreference>> {\n const { [FILE_SCHEMA_KEY]: _omit, ...subject } = data;\n void _omit;\n const preferences = new Map<string, LocationPreference>();\n for (const ref of refs) {\n const fn = await this.compile(ref);\n const seen = new Map<string, Set<FieldLocation>>();\n locationRecorder = seen;\n try {\n fn(subject);\n } finally {\n locationRecorder = undefined;\n }\n for (const [key, locations] of seen) {\n const [location, ...others] = [...locations];\n // Both values seen at evaluation can only come from conditional\n // branches: `compileUncached` refuses the unconditional kind. With\n // `allErrors`, Ajv evaluates failing branches too, so neither value\n // is this ref's answer, and an earlier ref's stands.\n if (location === undefined || others.length > 0) continue;\n preferences.set(key, { location, schema: ref });\n }\n }\n return preferences;\n }\n\n /**\n * The top-level property names the schemas in `refs` claim: the keys of\n * each schema's own `properties`, each once. What a page's schema set\n * claims decides which merge-safe fields a `derive:` block with no `fields`\n * manages on it (proposal 0069). A property reached only through `allOf`,\n * `$ref` or a conditional is not counted, so a schema that should manage a\n * field names it in its root `properties`. A schema that fails to load or\n * compile throws, as it would for `validate`.\n */\n async claimedProperties(refs: readonly string[]): Promise<Set<string>> {\n const claimed = new Set<string>();\n for (const ref of refs) {\n // Read from the compiled schema, which the cache already holds, so a\n // schema the run would refuse is refused here too and none loads twice.\n const schema: unknown = (await this.compile(ref)).schema;\n if (typeof schema !== \"object\" || schema === null) continue;\n const properties: unknown = (schema as Record<string, unknown>)[\"properties\"];\n if (typeof properties !== \"object\" || properties === null || Array.isArray(properties)) continue;\n for (const key of Object.keys(properties)) claimed.add(key);\n }\n return claimed;\n }\n\n /**\n * Whether each top-level key of `data` belongs in a published graph under\n * `refs`, as its `x-manni-graph-output` mark says. A key no schema marks has no\n * entry, which the caller reads as `true`: absent means harvested.\n *\n * A first pass with the recording keyword, as `locationPreferences` runs, so\n * a mark counts exactly where validation would evaluate it, and a mark nested\n * inside `graph` is ignored. Only present values are marked: Ajv applies a\n * property's subschema to a property that exists. `$schema` is stripped\n * first, as validation does.\n *\n * Refs are evaluated in order and a later ref's mark wins, so a house schema\n * listed after a vocabulary refines it. A schema that says both on paths\n * every document takes is refused when it compiles. A ref whose conditional\n * branches say both `true` and `false` gives that key no preference: with\n * `allErrors`, Ajv evaluates failing branches too, so neither value is that\n * ref's answer and an earlier ref's stands.\n */\n async graphOutputPreferences(\n data: Record<string, unknown>,\n refs: string[],\n ): Promise<Map<string, boolean>> {\n const { [FILE_SCHEMA_KEY]: _omit, ...subject } = data;\n void _omit;\n const preferences = new Map<string, boolean>();\n for (const ref of refs) {\n const fn = await this.compile(ref);\n const seen = new Map<string, Set<boolean>>();\n graphOutputRecorder = seen;\n try {\n fn(subject);\n } finally {\n graphOutputRecorder = undefined;\n }\n for (const [key, values] of seen) {\n const [value, ...others] = [...values];\n if (value === undefined || others.length > 0) continue;\n preferences.set(key, value);\n }\n }\n return preferences;\n }\n\n /**\n * Validate `data` against every schema in `refs`. Returns all violations,\n * each tagged with the schema that produced it and a source line via\n * `lineFor`.\n *\n * `colFor` is optional and additive: this signature is public, so a fourth\n * *required* parameter — or a widened third one — would be a consumer break.\n * Callers with an extractor that supplies no column pass nothing and get the\n * previous behavior exactly.\n */\n async validate(\n data: Record<string, unknown>,\n refs: string[],\n lineFor: (pointer: string) => number | undefined,\n colFor?: (pointer: string) => number | undefined,\n /**\n * Where a merged value lives when it is not in the document (proposal\n * 0037): a manifest's file and line. Consulted before `lineFor`,\n * and additive in the way `colFor` was.\n */\n locate?: (pointer: string) => SourceLocation | undefined,\n ): Promise<FieldError[]> {\n // `$schema` is a docmeta directive, not part of the document's metadata —\n // strip it so schemas with additionalProperties:false don't flag it.\n const { [FILE_SCHEMA_KEY]: _omit, ...subject } = data;\n void _omit;\n\n const errors: FieldError[] = [];\n for (const ref of refs) {\n const fn = await this.compile(ref);\n const ok = fn(subject);\n if (ok) continue;\n for (const e of fn.errors ?? []) {\n errors.push(toFieldError(ref, e, lineFor, colFor, locate));\n }\n }\n return errors;\n }\n}\n\n/**\n * The stable identifier inside a violation's `params`, when there is one.\n *\n * Only keywords whose parameter names a *thing* qualify. `pattern` carries the\n * regex source and `enum`/`minLength`/`minimum` carry schema-authored values:\n * including those would change a violation's identity every time the schema\n * author edited the rule, which is exactly what a baseline must survive.\n *\n * `DefinedError` is Ajv's own discriminated union over `keyword`, so each arm\n * below is type-checked against the real `params` shape rather than duck-typed.\n */\nfunction subjectOf(e: DefinedError): string | undefined {\n switch (e.keyword) {\n case \"required\":\n return e.params.missingProperty;\n case \"additionalProperties\":\n return e.params.additionalProperty;\n case \"format\":\n return e.params.format;\n case \"type\":\n // A union schema (`\"type\": [\"string\", \"null\"]`) yields the comma-joined\n // `\"string,null\"` rather than a single name. That is stable, so it\n // fingerprints correctly — but anyone matching on `subject` downstream\n // should not assume one type per value.\n return e.params.type;\n default:\n return undefined;\n }\n}\n\nfunction toFieldError(\n schema: string,\n e: ErrorObject,\n lineFor: (pointer: string) => number | undefined,\n colFor?: (pointer: string) => number | undefined,\n locate?: (pointer: string) => SourceLocation | undefined,\n): FieldError {\n // Ajv's documented way to narrow: every error it raises for a built-in\n // vocabulary is a member of `DefinedError`, but `ValidateFunction.errors` is\n // typed as the open `ErrorObject` to leave room for custom keywords.\n const defined = e as DefinedError;\n const instancePath = e.instancePath;\n const subject = subjectOf(defined);\n // Both of these point `instancePath` at the *parent* object and name the\n // property in the message, so neither gets a column.\n //\n // The parent exists, so `colFor` answers happily — with the parent's column,\n // which is a different token from the one the message is about. For\n // `required` the property is not in the file at all; for\n // `additionalProperties` it is, but somewhere else entirely, and the parent\n // of a document's root is the root, whose recorded position is 1:1. So a\n // stray key on line 40 was annotated at line 1 column 1, a caret on the first\n // character of the file.\n //\n // A `line` on the parent is a useful \"look around here\". A caret is a claim\n // about one character, and for these two keywords it would be the wrong one.\n let message = e.message ?? \"is invalid\";\n let wantsColumn = true;\n if (defined.keyword === \"required\") {\n message = `must have required property '${defined.params.missingProperty}'`;\n wantsColumn = false;\n } else if (defined.keyword === \"additionalProperties\") {\n message = `must NOT have additional property '${defined.params.additionalProperty}'`;\n wantsColumn = false;\n }\n // A value a manifest supplied is not in the document, so `lineFor` has no\n // answer for it; `locate` does, down to the line of the deepest node the\n // pointer reaches. `additionalProperties` is the one keyword whose offending\n // value sits at a *child* of `instancePath`, so the child is asked first.\n // Inside a manifest value that is the stray key's own line rather than its\n // parent's. At the root it is the manifest line of a private key a public\n // schema refused, which is exactly the case a reader needs pointed at.\n const located =\n defined.keyword === \"additionalProperties\"\n ? (locate?.(\n `${instancePath}/${escapePointerSegment(defined.params.additionalProperty)}`,\n ) ?? locate?.(instancePath))\n : locate?.(instancePath);\n if (located) {\n return {\n schema,\n instancePath,\n message,\n keyword: e.keyword,\n ...(subject != null ? { subject } : {}),\n file: located.file,\n ...(located.line != null ? { line: located.line } : {}),\n ...(wantsColumn && located.col != null ? { col: located.col } : {}),\n };\n }\n const line = lineFor(instancePath);\n const col = wantsColumn ? colFor?.(instancePath) : undefined;\n return {\n schema,\n instancePath,\n message,\n keyword: e.keyword,\n ...(subject != null ? { subject } : {}),\n ...(line != null ? { line } : {}),\n ...(col != null ? { col } : {}),\n };\n}\n","/**\n * What a page's schemas mark `x-manni-location: external`, for a manifest with\n * no `keys` (proposal 0068). Such a manifest owns those fields for that page,\n * so every command that merges one asks this first, through\n * `mergeWithMarks`.\n *\n * The page's schema set is resolved the way `validate` resolves it: by path,\n * collection and override, and by the page's own `$schema`, which a manifest\n * may never supply. So the set is known before anything is merged, and the\n * marks are read over the page with its keyless manifests' values in place.\n *\n * `pageClaims` reads the same set for what it claims rather than what it\n * marks: the top-level properties that decide which merge-safe fields a\n * `derive:` block with no `fields` manages on the page (proposal 0069).\n */\nimport { DocmetaError } from \"../types.js\";\nimport {\n loadConfig,\n schemaTrustRoot,\n type DocmetaConfig,\n type SchemaTrustRoot,\n} from \"./config.js\";\nimport type { PageMarks } from \"./external-metadata.js\";\nimport {\n collectSchemaPins,\n FILE_SCHEMA_KEY,\n rebaseConfigSchemaRefs,\n resolveSchemaSetWithSource,\n} from \"./resolve-schema.js\";\nimport { schemaLoadOptions } from \"./schema-registry.js\";\nimport { Validator } from \"./validator.js\";\n\nexport interface PageMarksOptions {\n /** The run's validator, or a way to build one on first use. */\n validator: Validator | (() => Validator);\n config: DocmetaConfig | null;\n /** The directory a page's own `$schema` is measured from. */\n cwd: string;\n trustRoot: SchemaTrustRoot;\n /** `-s/--schema`: the set every page is judged by, over config. */\n cliSchemas?: readonly string[];\n /**\n * The collections a page belongs to for its schema set, when the command\n * resolves sets over other collections than it merges manifests from.\n * Absent, the merge's own membership is used.\n */\n memberOf?: (label: string) => readonly string[];\n}\n\n/**\n * A `PageMarks` over the run's schemas. A page whose set cannot be resolved\n * or loaded gets `undefined`, so its keyless manifests own nothing for it\n * and the command reports the schema the way it always has.\n */\nexport function pageMarks(opts: PageMarksOptions): PageMarks {\n const validator = lazyValidator(opts);\n return async (label, probe, memberOf) => {\n const refs = pageRefs(opts, label, probe, memberOf);\n if (refs === undefined) return undefined;\n try {\n const preferences = await validator().locationPreferences({ ...probe }, refs);\n const marked = new Set<string>();\n for (const [key, p] of preferences) if (p.location === \"external\") marked.add(key);\n return marked;\n } catch (err) {\n if (err instanceof DocmetaError) return undefined;\n throw err;\n }\n };\n}\n\n/**\n * What a page's schemas claim, for the merge-safe default (proposal 0069):\n * the top-level property names of every schema in its set, resolved the way\n * `pageMarks` resolves it. `undefined` when the set cannot be resolved or\n * loaded, so the page claims nothing and the command reports the schema the\n * way it always has.\n */\nexport type PageClaims = (\n label: string,\n probe: Readonly<Record<string, unknown>>,\n memberOf: readonly string[],\n) => Promise<ReadonlySet<string> | undefined>;\n\nexport function pageClaims(opts: PageMarksOptions): PageClaims {\n const validator = lazyValidator(opts);\n return async (label, probe, memberOf) => {\n const refs = pageRefs(opts, label, probe, memberOf);\n if (refs === undefined) return undefined;\n try {\n return await validator().claimedProperties(refs);\n } catch (err) {\n if (err instanceof DocmetaError) return undefined;\n throw err;\n }\n };\n}\n\nfunction lazyValidator(opts: PageMarksOptions): () => Validator {\n let built: Validator | undefined;\n return () => (opts.validator instanceof Validator ? opts.validator : (built ??= opts.validator()));\n}\n\n/** The page's schema set, as `validate` resolves it. Throws when it cannot. */\nexport function pageSchemaSet(\n opts: PageMarksOptions,\n label: string,\n probe: Readonly<Record<string, unknown>>,\n memberOf: readonly string[],\n): string[] {\n return resolveSchemaSetWithSource({\n filePath: label,\n fileSchema: probe[FILE_SCHEMA_KEY],\n ...(opts.cliSchemas !== undefined ? { cliSchemas: [...opts.cliSchemas] } : {}),\n config: opts.config,\n memberOf: opts.memberOf?.(label) ?? memberOf,\n fileBase: opts.cwd,\n trustRoot: opts.trustRoot,\n }).schemas;\n}\n\n/** The page's schema set, or undefined when it cannot be resolved. */\nfunction pageRefs(\n opts: PageMarksOptions,\n label: string,\n probe: Readonly<Record<string, unknown>>,\n memberOf: readonly string[],\n): string[] | undefined {\n try {\n return pageSchemaSet(opts, label, probe, memberOf);\n } catch (err) {\n if (err instanceof DocmetaError) return undefined;\n throw err;\n }\n}\n\n/**\n * A validator for a command that validates nothing (`get`, `schemas`, `cite`),\n * built the way `validate` builds its own, for `pageMarks` to build on first\n * use.\n */\nexport function marksValidator(opts: {\n config: DocmetaConfig | null;\n cwd: string;\n configDir?: string;\n offline?: boolean;\n}): () => Validator {\n return () =>\n new Validator(\n schemaLoadOptions({\n root: opts.configDir ?? opts.cwd,\n fileBase: opts.cwd,\n ttlHours: opts.config?.schemaCache?.ttlHours,\n offline: opts.offline ?? opts.config?.offline,\n pins: collectSchemaPins(opts.config),\n registered: opts.config?.registered,\n }),\n );\n}\n\n/**\n * `pageMarks` for a sibling tool (`cite`, `key rotate`) that holds the family\n * file but not meta's config: meta's section is read from `configPath` and\n * rebased the way `resolveRunConfig` rebases it. `undefined` when the file has\n * none to read.\n */\nexport async function configMarks(configPath: string, cwd: string): Promise<PageMarks | undefined> {\n const loaded = await loadConfig(configPath, cwd);\n if (loaded === null) return undefined;\n const config = rebaseConfigSchemaRefs(loaded.config, loaded.dir, cwd);\n return pageMarks({\n validator: marksValidator({ config, cwd, configDir: loaded.dir }),\n config,\n cwd,\n trustRoot: schemaTrustRoot(cwd, loaded.dir),\n });\n}\n\n/**\n * Meta's section of a family file, rebased the way `resolveRunConfig` rebases\n * it, or `null` when the file has none. A sibling tool that writes a key meta\n * homes (`keyHome`) hands this to its `RelocationContext`, so the marks a\n * keyless manifest owns by are the ones `configMarks` reads.\n */\nexport async function metaSection(configPath: string, cwd: string): Promise<DocmetaConfig | null> {\n const loaded = await loadConfig(configPath, cwd);\n if (loaded === null) return null;\n return rebaseConfigSchemaRefs(loaded.config, loaded.dir, cwd);\n}\n\n/**\n * `configMarks` for a sibling tool that reads a family file every run (proposal\n * 0068), built once on first use. The page marks come from meta's section of\n * that file, or from meta's default set when the file has none for meta, or\n * when meta cannot read the file as its own. Without a file, the default set\n * decides.\n */\nexport function familyMarks(opts: {\n configPath: string | undefined;\n configDir: string;\n cwd: string;\n}): () => Promise<PageMarks> {\n let built: Promise<PageMarks> | undefined;\n const defaults = (): PageMarks =>\n pageMarks({\n validator: marksValidator({ config: null, cwd: opts.cwd, configDir: opts.configDir }),\n config: null,\n cwd: opts.cwd,\n trustRoot: schemaTrustRoot(opts.cwd, opts.configDir),\n });\n return () =>\n (built ??= (async () => {\n if (opts.configPath === undefined) return defaults();\n try {\n return (await configMarks(opts.configPath, opts.cwd)) ?? defaults();\n } catch (err) {\n if (err instanceof DocmetaError) return defaults();\n throw err;\n }\n })());\n}\n","/**\n * The SQL projection of a metadata corpus — the `docs` table both `query`\n * (proposal 0021) and the named corpus checks (proposal 0026) run over.\n *\n * One file, one row: the four system columns plus one column per top-level\n * metadata key across the corpus. `query` adds statement-specific columns and\n * effect-judging on top; checks read the same table and nothing else. The\n * table-building lives here so the two entry points cannot drift.\n */\nimport type { DatabaseSync } from \"node:sqlite\";\nimport { DocmetaError, type ExtractedMetadata } from \"../types.js\";\n\n/**\n * The columns every `docs` table carries, reserved so ordinary frontmatter can\n * never shadow them. A frontmatter key with exactly one of these names is not\n * lifted to a column and stays reachable as `_data ->> '$.<key>'`; any other\n * `_`-prefixed key lifts normally — the reservation is four names, not a\n * namespace grab (proposal 0021 § stress test 4).\n */\nexport const SYSTEM_COLUMNS = [\"_path\", \"_format\", \"_present\", \"_data\"] as const;\nexport const RESERVED: ReadonlySet<string> = new Set<string>(SYSTEM_COLUMNS);\n\n/** What `node:sqlite` accepts as a bound parameter. */\nexport type SqlValue = null | number | bigint | string;\n\n/** One loaded file, as the projection needs it: its label and its extraction. */\nexport interface ProjectionEntry {\n label: string;\n extracted: ExtractedMetadata;\n}\n\n/** Any key becomes a legal quoted identifier by doubling internal quotes. */\nexport function quoteIdent(name: string): string {\n return `\"${name.replaceAll('\"', '\"\"')}\"`;\n}\n\n/**\n * One frontmatter value, as SQLite stores it: booleans as 1/0 (`node:sqlite`\n * refuses to bind a boolean), arrays and objects as JSON text (which\n * `json_each` and `->>` then query directly), non-finite numbers as NULL\n * (SQLite has no NaN — it would store NULL anyway, this just does it without\n * an engine error).\n */\nexport function bindValue(value: unknown): SqlValue {\n if (value === undefined || value === null) return null;\n switch (typeof value) {\n case \"boolean\":\n return value ? 1 : 0;\n case \"number\":\n return Number.isFinite(value) ? value : null;\n case \"bigint\":\n case \"string\":\n return value;\n default:\n return JSON.stringify(value);\n }\n}\n\n/**\n * Data columns for a corpus: the union of top-level keys across `entries` —\n * the same scan boundary `schemas infer` chose — plus any `extraKeys` the\n * caller's statement names (a SET target no file has yet still deserves a\n * column). Sorted, so the column order (and any `SELECT *`) is deterministic\n * regardless of file order.\n */\nexport function corpusDataColumns(\n entries: readonly ProjectionEntry[],\n extraKeys: Iterable<string> = [],\n): string[] {\n const keys = new Set<string>();\n for (const { extracted } of entries) {\n for (const key of Object.keys(extracted.data)) {\n if (key !== \"\" && !RESERVED.has(key)) keys.add(key);\n }\n }\n for (const key of extraKeys) {\n if (key !== \"\" && !RESERVED.has(key)) keys.add(key);\n }\n return [...keys].sort();\n}\n\n/**\n * Create and load the `docs` table on an open database.\n *\n * Data columns get no type affinity, so SQLite stores exactly the value each\n * file had and never coerces one file's string into another's number. One\n * transaction for the bulk load: each bare run() would otherwise commit on its\n * own, which is where a large corpus spends its load time.\n */\nexport function createDocsTable(\n db: DatabaseSync,\n entries: readonly ProjectionEntry[],\n dataColumns: readonly string[],\n): void {\n db.exec(\n `CREATE TABLE docs (\"_path\" TEXT PRIMARY KEY, \"_format\" TEXT, \"_present\" INTEGER, \"_data\" TEXT${dataColumns\n .map((c) => `, ${quoteIdent(c)}`)\n .join(\"\")})`,\n );\n const insert = db.prepare(\n `INSERT INTO docs VALUES (${[\"?\", \"?\", \"?\", \"?\", ...dataColumns.map(() => \"?\")].join(\", \")})`,\n );\n db.exec(\"BEGIN\");\n // Committed or rolled back, never left open: a caller may keep using the\n // handle after a failed insert, and every later statement would otherwise\n // run inside the half-built transaction.\n let committed = false;\n try {\n for (const { label, extracted } of entries) {\n insert.run(\n label,\n extracted.format,\n extracted.present ? 1 : 0,\n JSON.stringify(extracted.data),\n ...dataColumns.map((c) => bindValue(extracted.data[c])),\n );\n }\n db.exec(\"COMMIT\");\n committed = true;\n } finally {\n if (!committed) db.exec(\"ROLLBACK\");\n }\n}\n\n/**\n * Register `lineFor(path, key)` as a SQL function on the run's database, so a\n * statement can name the source line a metadata key sits on (proposal 0026).\n *\n * Backed by each entry's `extracted.lineFor` — the contract every extractor\n * already fulfills for annotations — through the same `db.function` mechanism\n * that registers `explicit_null()`, plus `deterministic: true`: the answer\n * depends only on the arguments for the life of the statement, which lets\n * SQLite fold repeated calls. `NULL` for an unknown path, a key the extractor\n * cannot place, or a non-string argument.\n */\nexport function registerLineFor(\n db: DatabaseSync,\n entries: readonly ProjectionEntry[],\n): void {\n const byLabel = new Map(entries.map((e) => [e.label, e.extracted]));\n db.function(\"lineFor\", { deterministic: true }, (path, key) => {\n if (typeof path !== \"string\" || typeof key !== \"string\") return null;\n return byLabel.get(path)?.lineFor(key) ?? null;\n });\n}\n\n/**\n * Refuse a second statement instead of silently dropping it.\n *\n * `prepare()` compiles the first statement and ignores the rest, so\n * `SELECT 1; DROP TABLE docs` would run the SELECT and quietly skip the DROP —\n * a request half-honored with exit 0, the false-green shape 0016 exists to\n * keep out. The scan skips string literals, quoted identifiers, and both\n * comment forms; a trailing `;` (or several) is a terminator, not a chain.\n */\nexport function assertSingleStatement(sql: string): void {\n const cut = topLevelSemicolon(sql);\n if (cut === -1) return;\n if (!isTrivia(sql.slice(cut + 1))) {\n throw new DocmetaError(\n \"Run a single SQL statement per query; text after the first `;` would be silently ignored.\",\n );\n }\n}\n\n/**\n * The scanner primitives every SQL micro-lexer in the codebase is built on —\n * statement splitting and the parameter scan below, `query`'s SET/INSERT\n * target scans, and the 0028 catalog-CHECK parser. One implementation of\n * \"skip the region whose contents are data, not syntax\", so the consumers\n * cannot drift on what a string or a comment is.\n */\n\n/** Does `sql[i]` open a string literal or a quoted/bracketed identifier? */\nexport function startsStringOrIdent(sql: string, i: number): boolean {\n const ch = sql[i];\n return ch === \"'\" || ch === '\"' || ch === \"`\" || ch === \"[\";\n}\n\n/** Does a line comment (`--`) or block comment start at `i`? */\nexport function startsComment(sql: string, i: number): boolean {\n const ch = sql[i];\n return (\n (ch === \"-\" && sql[i + 1] === \"-\") || (ch === \"/\" && sql[i + 1] === \"*\")\n );\n}\n\n/**\n * Index just past a string literal or quoted/bracketed identifier opening at\n * `i` (`sql[i]` must satisfy `startsStringOrIdent`). The three quote forms\n * treat a doubled quote as an escape — `'a''b'` is one literal — and an\n * unterminated one consumes the rest of the input (returns `sql.length`).\n * A bracket identifier scans plainly to `]`: SQLite brackets have no `]]`\n * escape (unlike T-SQL), so no doubling branch — and an unterminated one\n * returns `sql.length + 1`, one past the close the terminated form counts,\n * which `readIdentifier`'s `end - 1` slicing relies on.\n */\nexport function skipStringOrIdent(sql: string, i: number): number {\n const quote = sql[i];\n if (quote === \"[\") {\n let j = i + 1;\n while (j < sql.length && sql[j] !== \"]\") j++;\n return j + 1;\n }\n let j = i + 1;\n while (j < sql.length) {\n if (sql[j] === quote) {\n if (sql[j + 1] === quote) {\n j += 2;\n continue;\n }\n return j + 1;\n }\n j++;\n }\n return j;\n}\n\n/**\n * Index just past a comment opening at `i` (`sql` must satisfy\n * `startsComment` there). A line comment ends past its newline, a block\n * comment past its closer; either unterminated consumes the rest of the\n * input. Consuming the line comment's newline is safe because every consumer\n * treats a bare newline as trivia.\n */\nexport function skipComment(sql: string, i: number): number {\n if (sql[i] === \"-\") {\n let j = i + 2;\n while (j < sql.length && sql[j] !== \"\\n\") j++;\n return j < sql.length ? j + 1 : j;\n }\n const end = sql.indexOf(\"*/\", i + 2);\n return end === -1 ? sql.length : end + 2;\n}\n\n/**\n * Index of the first `;` outside literals, identifiers, and comments.\n *\n * Parenthesis depth is deliberately not tracked: in valid SQLite, the only\n * semicolons outside strings are statement terminators — the grammar has no\n * parenthesized position where one may appear — so depth would be state with\n * nothing to distinguish. (Trigger bodies, the one construct with interior\n * semicolons, never reach here: the docs projection has no triggers.)\n */\nfunction topLevelSemicolon(sql: string): number {\n let i = 0;\n while (i < sql.length) {\n if (startsStringOrIdent(sql, i)) {\n i = skipStringOrIdent(sql, i);\n } else if (startsComment(sql, i)) {\n i = skipComment(sql, i);\n } else if (sql[i] === \";\") {\n return i;\n } else {\n i++;\n }\n }\n return -1;\n}\n\n/**\n * The one grammar for a named parameter's bare name. The scan below matches\n * it as a prefix; `isParamName` answers for a whole string — exported so the\n * CLI's `--param` validation cannot drift from what the scan recognizes.\n */\nconst PARAM_NAME_HEAD = /^[A-Za-z_][A-Za-z0-9_]*/;\nexport function isParamName(name: string): boolean {\n return PARAM_NAME_HEAD.exec(name)?.[0] === name;\n}\n\n/**\n * Named-parameter tokens (`$name`, `:name`, `@name`) the statement references\n * outside string literals, quoted identifiers, and comments — the same skip\n * rules as `topLevelSemicolon`, for the same reason: text inside a literal is\n * data, not syntax (proposal 0029).\n *\n * The tokens are returned as written, prefix included, first occurrence only.\n * The grammar is deliberately narrow: a prefix character must be followed\n * immediately by an identifier (`[A-Za-z_][A-Za-z0-9_]*`), so a bare `$`, a\n * spaced `:`, and a doubled `::` are all operators-or-noise, never parameters.\n *\n * One bare name under two prefixes (`$p` and `:p` in one statement) refuses\n * here: the engine rejects it anyway, but as a generic \"conflicting names\"\n * SQL error with neither spelling named.\n *\n * Why this exists: the engine throws on an *extra* bound parameter, but a\n * parameter the SQL references with nothing bound silently binds NULL — which\n * matches nothing, and a zero-row `--check` is a passing CI gate. The caller\n * uses this list to refuse that false green before the statement runs.\n */\nexport function collectNamedParameters(sql: string): string[] {\n const tokens: string[] = [];\n const seen = new Set<string>();\n const prefixOf = new Map<string, string>();\n let i = 0;\n while (i < sql.length) {\n const ch = sql[i];\n if (startsStringOrIdent(sql, i)) {\n i = skipStringOrIdent(sql, i);\n } else if (startsComment(sql, i)) {\n i = skipComment(sql, i);\n } else if (ch === \"$\" || ch === \":\" || ch === \"@\") {\n if (ch === \":\" && sql[i + 1] === \":\") {\n // `::` is no parameter; consume both so neither colon starts one.\n i += 2;\n continue;\n }\n const m = PARAM_NAME_HEAD.exec(sql.slice(i + 1));\n if (!m) {\n i++;\n continue;\n }\n const token = ch + m[0];\n const priorPrefix = prefixOf.get(m[0]);\n if (priorPrefix !== undefined && priorPrefix !== ch) {\n throw new DocmetaError(\n `The statement references both ${priorPrefix}${m[0]} and ${token} — one name under two prefixes, which the engine rejects as conflicting. Use one spelling throughout.`,\n );\n }\n prefixOf.set(m[0], ch);\n if (!seen.has(token)) {\n seen.add(token);\n tokens.push(token);\n }\n i += 1 + m[0].length;\n } else {\n i++;\n }\n }\n return tokens;\n}\n\n/**\n * The statement with leading whitespace and comments removed — the first real\n * token, for the callers that refuse a statement by name (`query`'s\n * ATTACH/VACUUM gate, and the checks' twin of it). Lived in query.ts until\n * the checks needed the identical scan.\n */\nexport function stripLeadingTrivia(sql: string): string {\n let i = 0;\n for (;;) {\n while (i < sql.length && /\\s/.test(sql[i] ?? \"\")) i++;\n if (startsComment(sql, i)) {\n i = skipComment(sql, i);\n continue;\n }\n return sql.slice(i);\n }\n}\n\n/** Only whitespace, comments, and bare `;` — legal after the terminator. */\nfunction isTrivia(text: string): boolean {\n let i = 0;\n while (i < text.length) {\n const ch = text[i];\n if (ch === undefined || /\\s/.test(ch) || ch === \";\") {\n i++;\n continue;\n }\n if (startsComment(text, i)) {\n i = skipComment(text, i);\n continue;\n }\n return false;\n }\n return true;\n}\n\n/**\n * `node:sqlite`, imported on first use only.\n *\n * Two reasons this is not a top-level import. A static import would load the\n * module for every docmeta invocation, `validate` runs included. And on the\n * Node 24 engines floor the module is a release candidate that announces\n * itself with an ExperimentalWarning on load — which would open every CI log\n * with a scare line — so exactly that one warning is filtered while the\n * import runs. Delete the filter when `node:sqlite` reaches Stable.\n */\nlet sqliteModule: Promise<typeof import(\"node:sqlite\")> | undefined;\nexport function loadSqlite(): Promise<typeof import(\"node:sqlite\")> {\n sqliteModule ??= (async () => {\n // Bound, so the capture is a standalone function twice over: callable\n // here without a `this` surprise, and safe to leave installed as the\n // restored property.\n const original = process.emitWarning.bind(process);\n const filtered: typeof process.emitWarning = (warning, ...rest) => {\n const text = typeof warning === \"string\" ? warning : warning.message;\n if (text.includes(\"SQLite is an experimental feature\")) return;\n Reflect.apply(original, process, [warning, ...rest]);\n };\n process.emitWarning = filtered;\n try {\n return await import(\"node:sqlite\");\n } finally {\n process.emitWarning = original;\n }\n })();\n return sqliteModule;\n}\n","/**\n * Collection views, and the membership adapter that decides what a collection\n * contains.\n *\n * `memberOf` is proposal 0041's rule 10: which collections a file belongs to,\n * as path arithmetic against the config file's directory. It is what external\n * metadata attaches to, what an `overrides[].collection` resolves through, and\n * — since 0041 rule 7 — what a SQL view holds.\n *\n * One meaning of \"collection\", everywhere. 0027 built each view from the files\n * an override *won schema resolution for*, so views were disjoint, only a\n * collection an override pointed at had a view at all, and a file whose own\n * `$schema` outranked the override was announced as not being in it. 0041\n * makes a view the set the config says it is: every declared collection is a\n * view, two views may overlap, and `FROM authors` reads as \"the files the\n * authors collection selects\".\n *\n * That restores 0021's founding rule, which 0027 had to bend: a plain read\n * resolves no schemas. Nothing in this module resolves anything, so there is\n * no trust refusal to demote a file over, no per-file walk to pay for, and no\n * notice to print. Resolution still honours `overrides[].collection` — it\n * matches through `memberOf` in `resolve-schema.ts`, which is untouched.\n *\n * Shared by both projection consumers — `query` and the corpus checks\n * `validate` runs — so the two cannot drift on what a collection contains.\n */\nimport type { DatabaseSync } from \"node:sqlite\";\nimport { isAbsolute, relative, resolve as resolvePath, sep } from \"node:path\";\nimport { isMember, type CollectionConfig } from \"../../shared/collections.js\";\nimport { STDIN_LABEL } from \"./load-files.js\";\nimport { quoteIdent, type ProjectionEntry } from \"./projection.js\";\n\n/**\n * Names of the collections this file belongs to, in declaration order.\n *\n * Where the two bases meet. A run labels files relative to `base` — the\n * working directory for positional paths, the config's directory otherwise —\n * while membership is decided relative to the config file's directory, because\n * that is where a collection's globs were written (0004). So the label is\n * resolved against `base` and then measured from `configDir`.\n *\n * Pure path arithmetic (0041 rule 10): no `stat`, nothing that can fail, and\n * nothing that costs per file. Stdin and anything outside `configDir` are\n * members of nothing — stdin because there is no file behind it, and `isMember`\n * refuses a `../` path on its own.\n */\nexport function memberOf(\n collections: readonly CollectionConfig[],\n configDir: string,\n base: string,\n label: string,\n): string[] {\n if (collections.length === 0) return [];\n if (label === STDIN_LABEL) return [];\n const rel = relative(configDir, resolvePath(base, label))\n .split(sep)\n .join(\"/\");\n // `relative` gives back an *absolute* path when the two sides share no root\n // — a different drive letter on Windows. That is as far outside the config\n // directory as a path can be, and it carries no `../` for `isMember` to\n // refuse, so it is refused here.\n if (isAbsolute(rel)) return [];\n return collections.filter((c) => isMember(c, rel)).map((c) => c.name);\n}\n\n/**\n * Narrow a walked file set to the files that belong to a selected collection\n * (proposal 0041 rule 9).\n *\n * The walk applies the family-wide ignores and `--exclude` only, because a\n * collection's `paths:` and `exclude:` are two halves of one statement and the\n * walk sees just the first half. Without this second pass a collection's\n * `exclude:` shaped its SQL view but not what a bare run read, so one config\n * gave two different answers about the same collection — the ambiguity 0041\n * exists to remove.\n *\n * Apply it **only** when the inputs came from the collections. A path someone\n * typed is theirs, and no collection's exclusions filter it (rule 3); the\n * caller decides, which is why this takes the already-walked list rather than\n * consulting `fromCollections` itself.\n */\nexport function retainMembers(\n files: readonly string[],\n membersFor: (label: string) => readonly string[],\n): string[] {\n return files.filter((label) => membersFor(label).length > 0);\n}\n\n/** One collection, with the loaded files that belong to it. */\nexport interface Collection {\n name: string;\n /** `_path` labels of the member files. May be empty — an empty view. */\n members: string[];\n}\n\n/**\n * The declared collection names, in declaration order — the one list every\n * \"is this a collection?\" consumer shares: the view builder below, and\n * `query`'s eager-build trigger and lazy-retry match. Callers that compare\n * case-insensitively use `String.prototype.toLowerCase`, whose Unicode fold\n * is looser than SQLite's ASCII-only fold — that mismatch can only\n * over-trigger a harmless eager build or rebuild, never miss a real match.\n */\nexport function collectionNames(\n collections: readonly CollectionConfig[] | undefined,\n): string[] {\n return (collections ?? []).map((c) => c.name);\n}\n\nexport interface CollectionParams {\n /**\n * Every collection the config **declares** — not just the ones `--collection`\n * selected, and not just the ones an override points at. Each one is a view\n * (0041 rule 11), so narrowing a run never turns `FROM blog` into a SQL\n * error; it turns it into a view holding whatever of `blog` the run loaded.\n * Optional so the checks' run context can be this very shape; absent, or\n * empty, means there are no collections and so no views.\n */\n collections?: readonly CollectionConfig[];\n /**\n * The config file's directory: what a collection's globs are measured from\n * (0004). Only read when there is a collection to build a view for, which is\n * only ever true when a config governs the run.\n */\n configDir?: string;\n /** Directory the run's file labels are relative to (`RunConfig.base`). */\n base?: string;\n}\n\n/**\n * Compute every declared collection's member list from the loaded entries.\n *\n * Membership is the config's own arithmetic — `memberOf`, the same function\n * external metadata and `overrides[].collection` go through — so a view holds\n * exactly the loaded files the collection selects, and a file in two\n * collections is in both views. Nothing here resolves a schema, opens a file,\n * or can fail.\n */\nexport function collectCollections(\n entries: readonly ProjectionEntry[],\n params: CollectionParams,\n): Collection[] {\n const declared = params.collections ?? [];\n if (declared.length === 0) return [];\n // A collection can only be declared by a config file, so both bases are set\n // whenever there is a view to build; the fallbacks keep the arithmetic total\n // rather than optional.\n const base = params.base ?? \".\";\n const configDir = params.configDir ?? base;\n\n const members = new Map<string, string[]>();\n for (const entry of entries) {\n for (const name of memberOf(declared, configDir, base, entry.label)) {\n const list = members.get(name);\n if (list) list.push(entry.label);\n else members.set(name, [entry.label]);\n }\n }\n return declared.map((c) => ({ name: c.name, members: members.get(c.name) ?? [] }));\n}\n\n/** One member path as a SQL string literal (doubling internal quotes). */\nfunction quoteSqlString(value: string): string {\n return `'${value.replaceAll(\"'\", \"''\")}'`;\n}\n\n/**\n * Create one view per collection on an open database that already holds the\n * `docs` table.\n *\n * Each view is built from the computed member list — literal paths, `WHERE 0`\n * for an empty collection — never from a SQL translation of the config glob:\n * picomatch and SQLite `GLOB` are different languages, and membership was\n * already decided by the code that owns the decision. The IN-list scales past\n * any real corpus (0027 § stress test 4: SQLite's SQL-length ceiling is\n * ~1 GB; ten thousand long-ish paths are under a megabyte).\n *\n * Views live in `sqlite_master`, outside the two snapshots effect judgment\n * diffs (`SELECT * FROM docs`, `PRAGMA table_info(docs)`), so the effect gate\n * never sees them — and a `--db` export carries them, which is a feature.\n */\nexport function createCollectionViews(\n db: DatabaseSync,\n collections: readonly Collection[],\n): void {\n for (const c of collections) {\n const where =\n c.members.length === 0\n ? \"0\"\n : `_path IN (${c.members.map(quoteSqlString).join(\", \")})`;\n db.exec(\n `CREATE VIEW ${quoteIdent(c.name)} AS SELECT * FROM docs WHERE ${where}`,\n );\n }\n}\n","/**\n * Relocation (proposal 0047): put a page's values where their schema's\n * `x-manni-location` mark and the config's manifests say they belong, and\n * give a value that prefers external metadata a manifest when it has none.\n *\n * `manni meta relocate` is this module with a CLI in front of it, and the\n * writers' and validate's offers run the same plan. Three steps, kept apart\n * so a caller can stop after any of them:\n *\n * - **Home selection** (`keyHome`, and inside `planRelocation`). A page in a\n * collection uses the first one it belongs to. With no collections, one\n * named `default` is created from the run's targets. With exactly one, the\n * target that names the page is appended to its `paths:`. With several and\n * the page in none, there is no home. The manifest is the collection's\n * first local `file:` entry, or `<collection>.metadata.yaml` beside the\n * config file. A URL manifest is never a home.\n * - **Planning** (`planRelocation`). Every move, every config edit and every\n * new file text is computed, and nothing is written. A change to a\n * manifest's `keys:` covers every member page of its collection, in both\n * directions, because a key a manifest owns and a page still carries is an\n * `external:owned` collision, and a key it stops owning is no longer read.\n * - **Applying** (`applyRelocation`). The texts are written, manifests first,\n * then the config, then the pages, and the caller's in-memory collections\n * are brought up to date, so a writer can put a value into the manifest the\n * plan just declared. A write that fails puts back the files already\n * written, so a run lands whole or not at all.\n *\n * A value never moves by being re-read. The page's own extraction and the\n * manifest's parsed value are what move, so an encrypted value goes as its\n * ciphertext, verbatim.\n */\nimport { isMissing } from \"../../shared/manifest-cas.js\";\nimport { access, readFile, stat, unlink } from \"node:fs/promises\";\nimport { basename, extname, isAbsolute, join, relative, resolve, sep } from \"node:path\";\nimport picomatch from \"picomatch\";\nimport {\n LineCounter,\n isMap,\n isNode,\n isScalar,\n isSeq,\n parse as parseYaml,\n parseDocument,\n type Document,\n} from \"yaml\";\nimport {\n isMember,\n ownsKey,\n parseCollections,\n type CollectionConfig,\n} from \"../../shared/collections.js\";\nimport { FAMILY_CONFIG_NAMES, type ConfigFile } from \"../../shared/config-file.js\";\nimport { findGitRoot } from \"../../shared/git-root.js\";\nimport { hasPagePlaceholder, pageManifestPath } from \"../../shared/page-manifest.js\";\nimport { errorMessage } from \"../../shared/errors.js\";\nimport { decryptValue, isEncryptedValue } from \"../../shared/encryption.js\";\nimport { DocmetaError, type MetadataExtractor, type MetadataPatch } from \"../types.js\";\nimport { schemaTrustRoot, type DocmetaConfig, type RunConfig } from \"./config.js\";\nimport { memberOf } from \"./collections.js\";\nimport { EncryptionRefusal, META_CONTEXT, lazyKey } from \"./encrypted.js\";\nimport {\n PATH_JOIN,\n externalMetadataJoin,\n loadExternalMetadata,\n mergeWithMarks,\n outsideRefusal as perPageOutsideRefusal,\n type ExternalMetadataIndex,\n type ExternalMetadataValue,\n} from \"./external-metadata.js\";\nimport { removeManifestKey, spliceManifestValue } from \"./external-metadata-write.js\";\nimport { gitignoreOptions, resolveTargetSet, STDIN_TOKEN } from \"./load-files.js\";\nimport { FILE_SCHEMA_KEY, resolveElements, resolveSchemaSetWithSource } from \"./resolve-schema.js\";\nimport { classifyRef } from \"./schema-registry.js\";\nimport type { Validator } from \"./validator.js\";\nimport { writeFileAtomic } from \"./write-file.js\";\nimport { extractorByName, extractorForExtension } from \"../extractors/index.js\";\nimport { deepEqual } from \"../extractors/patch-util.js\";\nimport type { FieldLocation } from \"./location.js\";\nimport { pageMarks } from \"./page-marks.js\";\n\n// ---------------------------------------------------------------------------\n// The result: what `manni meta relocate` reports.\n// ---------------------------------------------------------------------------\n\n/** Why a value was moved: its schema's mark, or a manifest that already owns the key. */\nexport type RelocateMoveReason = \"preferred\" | \"owned\";\n\n/** Why a value stayed on the side it is on. */\nexport type RelocateStayReason =\n | \"no-home\"\n | \"read-only-format\"\n | \"no-join-value\"\n | \"values-differ\"\n | \"url-manifest\"\n | \"unreadable\";\n\n/** One value that moved, or would under `dryRun`. */\nexport type RelocateMove =\n | { key: string; to: \"page\"; from: string; reason: RelocateMoveReason }\n | {\n key: string;\n to: \"manifest\";\n manifest: string;\n /** 1-based line of the key in the manifest afterwards. Absent under `dryRun`. */\n line?: number;\n reason: RelocateMoveReason;\n };\n\n/** One value that stayed on the wrong side. */\nexport interface RelocateStay {\n key: string;\n reason: RelocateStayReason;\n /** The sentence the pretty reporter prints after `stays: `. Not part of the JSON shape. */\n detail?: string;\n}\n\nexport interface RelocateFileResult {\n /** The page, as the run labels it. */\n file: string;\n moved: RelocateMove[];\n stayed: RelocateStay[];\n /** A member page outside the paths the run named, reached through a `keys:` or `paths:` change. */\n beyond: boolean;\n}\n\nexport interface RelocateManifestResult {\n /** The manifest as the run reports it: relative to the run's base, or the URL. */\n file: string;\n collection: string;\n /** Its index in the collection's `externalMetadata:` before the run. */\n index: number;\n created: boolean;\n keysAdded: string[];\n keysRemoved: string[];\n /** The keys it owns afterwards. */\n keys: string[];\n /** Whether its last key went, so the config no longer declares it (R3). */\n undeclared: boolean;\n /** Pages beyond the named paths whose values a `keys:` change moves, or leaves. */\n beyond: number;\n}\n\nexport interface RelocateConfigResult {\n /** The config file relative to the working directory, or null when there is none and none was needed. */\n file: string | null;\n created: boolean;\n collectionsCreated: { name: string; paths: string[] }[];\n pathsAdded: { collection: string; path: string }[];\n}\n\nexport interface RelocateSummary {\n /** Pages with a value moved or stayed. */\n files: number;\n moved: number;\n stayed: number;\n manifestsCreated: number;\n}\n\nexport interface RelocateResult {\n dryRun: boolean;\n config: RelocateConfigResult;\n /** Every manifest the run creates, changes the keys of, or moves a value into or out of. */\n manifests: RelocateManifestResult[];\n files: RelocateFileResult[];\n summary: RelocateSummary;\n}\n\n/** Whether a relocate run exits 1: at least one value stayed on the wrong side. */\nexport function relocateFailed(result: Pick<RelocateResult, \"summary\">): boolean {\n return result.summary.stayed > 0;\n}\n\n// ---------------------------------------------------------------------------\n// The context: what a run already settled, handed over once.\n// ---------------------------------------------------------------------------\n\nexport interface RelocationContext {\n cwd: string;\n /** The directory the run's file labels are relative to. */\n base: string;\n /** `--no-config`: nothing may be written to a config, so no value has a home. */\n noConfig: boolean;\n config: DocmetaConfig | null;\n /** Set by `applyRelocation` when it creates the config file. */\n configDir?: string;\n configPath?: string;\n configFile?: ConfigFile;\n /**\n * The run's selected collections. `applyRelocation` edits these objects in\n * place and appends a created collection, so a caller holding the array\n * sees the new manifests.\n */\n collections: CollectionConfig[];\n /** Every declared collection, the same objects as `collections`, edited the same way. */\n declaredCollections: CollectionConfig[];\n /**\n * The run's targets as typed (positional paths and globs). A created\n * collection's `paths:`, and a path appended to the only collection, come\n * from here. `-` is never one.\n */\n targets: readonly string[];\n /** `-s/--schema`: the schema set every page is judged by, over config. */\n cliSchemas?: readonly string[];\n validator: Validator;\n /** `--as`: the extractor every page is read with. */\n as?: string;\n /** `--no-gitignore` (false), for the walk of a collection's member pages. */\n respectGitignore?: boolean;\n env?: NodeJS.ProcessEnv;\n onNotice?: (message: string) => void;\n}\n\n/** A context from what `resolveRunConfig` returned, plus the rest a plan needs. */\nexport function relocationContext(\n run: RunConfig,\n extras: {\n cwd: string;\n targets: readonly string[];\n validator: Validator;\n noConfig?: boolean;\n cliSchemas?: readonly string[];\n as?: string;\n respectGitignore?: boolean;\n env?: NodeJS.ProcessEnv;\n onNotice?: (message: string) => void;\n },\n): RelocationContext {\n return {\n cwd: extras.cwd,\n base: run.base,\n noConfig: extras.noConfig ?? false,\n config: run.config,\n ...(run.configDir !== undefined ? { configDir: run.configDir } : {}),\n ...(run.configPath !== undefined ? { configPath: run.configPath } : {}),\n ...(run.configFile !== undefined ? { configFile: run.configFile } : {}),\n collections: run.collections,\n declaredCollections: run.declaredCollections,\n targets: extras.targets.filter((t) => t !== STDIN_TOKEN),\n ...(extras.cliSchemas !== undefined ? { cliSchemas: extras.cliSchemas } : {}),\n validator: extras.validator,\n ...(extras.as !== undefined ? { as: extras.as } : {}),\n ...(extras.respectGitignore !== undefined ? { respectGitignore: extras.respectGitignore } : {}),\n ...(extras.env !== undefined ? { env: extras.env } : {}),\n ...(extras.onNotice !== undefined ? { onNotice: extras.onNotice } : {}),\n };\n}\n\n// ---------------------------------------------------------------------------\n// The model: the collections as the plan would leave them.\n// ---------------------------------------------------------------------------\n\n/** One manifest of the model, declared or about to be. */\ninterface ManifestRef {\n collection: string;\n index: number;\n /** `file:` as the config writes it. */\n written: string;\n url: boolean;\n /** Undefined for a URL, and for a `{page}` manifest, which names no one file. */\n absPath: string | undefined;\n /**\n * As the run reports it. A `{page}` manifest (proposal 0058) names one file\n * per page, so this is the pattern as written, and `Model.fileFor` answers\n * the file one page's values live in.\n */\n file: string;\n join: string;\n /** `file:` holds `{page}`: each page keeps its values in a manifest of its own. */\n perPage: boolean;\n created: boolean;\n /**\n * The manifest names no `keys` (proposal 0068): it owns what each page's\n * schemas mark external, so the plan never adds or removes a key of its.\n */\n implied: boolean;\n keysBefore: string[];\n keysAdded: string[];\n keysRemoved: string[];\n}\n\nconst toPosix = (p: string): string => p.split(sep).join(\"/\");\n\nfunction reported(abs: string, base: string): string {\n const rel = relative(base, abs);\n return rel === \"\" ? \".\" : toPosix(rel);\n}\n\n/** The config file relative to the working directory, as every message names it. */\nfunction configSource(path: string, cwd: string): string {\n return toPosix(relative(cwd, path)) || basename(path);\n}\n\nfunction cloneCollection(c: CollectionConfig): CollectionConfig {\n return {\n ...c,\n paths: [...c.paths],\n exclude: [...c.exclude],\n externalMetadata: c.externalMetadata.map((m) => (m.keys === undefined ? { ...m } : { ...m, keys: [...m.keys] })),\n };\n}\n\n/** Where a page with no manifest for a key would get one. */\nexport type ProposedHome =\n | {\n kind: \"collection\";\n collection: string;\n /** The manifest the key would join, as the run reports it. */\n manifest: string;\n createsManifest: boolean;\n createsCollection: boolean;\n /** The run target appended to the collection's `paths:` (§3 case 3). */\n addsPath?: string;\n }\n | {\n kind: \"none\";\n /** `collections`: several are declared and the page is in none. `no-config`: `--no-config`. */\n reason: \"collections\" | \"no-config\";\n /** How many collections are declared. */\n collections: number;\n };\n\nclass Model {\n readonly collections: CollectionConfig[];\n readonly manifests: ManifestRef[] = [];\n readonly created: { name: string; paths: string[] }[] = [];\n readonly pathsAdded: { collection: string; path: string }[] = [];\n private targets: Promise<(string | undefined)[]> | undefined;\n\n constructor(\n private readonly ctx: RelocationContext,\n readonly configDir: string,\n ) {\n this.collections = ctx.declaredCollections.map(cloneCollection);\n for (const c of this.collections) {\n c.externalMetadata.forEach((m, index) => {\n const url = classifyRef(m.file).kind === \"url\";\n const perPage = !url && hasPagePlaceholder(m.file);\n const absPath =\n url || perPage ? undefined : isAbsolute(m.file) ? m.file : resolve(configDir, m.file);\n this.manifests.push({\n collection: c.name,\n index,\n written: m.file,\n url,\n absPath,\n file: absPath === undefined ? m.file : reported(absPath, ctx.base),\n join: externalMetadataJoin(m),\n perPage,\n created: false,\n implied: m.keys === undefined,\n keysBefore: [...(m.keys ?? [])],\n keysAdded: [],\n keysRemoved: [],\n });\n });\n }\n }\n\n members(label: string): string[] {\n return memberOf(this.collections, this.configDir, this.ctx.base, label);\n }\n\n /** The run's targets as `paths:` entries, in target order; resolved once, on first use. */\n private targetPaths(): Promise<(string | undefined)[]> {\n this.targets ??= Promise.all(this.ctx.targets.map((t) => collectionPath(t, this.ctx.cwd, this.configDir)));\n return this.targets;\n }\n\n manifestsOf(collection: string): ManifestRef[] {\n return this.manifests.filter((m) => m.collection === collection);\n }\n\n /**\n * The one file `m` keeps a page's values in, and how the run reports it:\n * the page's own for a `{page}` manifest (proposal 0058), the declared file\n * for any other. `abs` is undefined only for a URL manifest.\n */\n fileFor(m: ManifestRef, pageAbs: string): { abs: string | undefined; file: string } {\n if (!m.perPage) return { abs: m.absPath, file: m.file };\n const resolved = pageManifestPath(m.written, this.configDir, pageAbs);\n if (\"outside\" in resolved) {\n // The loader refuses such a page first, whenever the run names it.\n const declared = this.ctx.declaredCollections.find((c) => c.name === m.collection)?.externalMetadata[m.index];\n throw new DocmetaError(\n perPageOutsideRefusal(declared ?? { file: m.written }, m.collection, resolved.pageRel),\n );\n }\n return { abs: resolved.abs, file: reported(resolved.abs, this.ctx.base) };\n }\n\n /**\n * The manifest of one of `members` that owns `key`, in declaration order.\n * `marked` is what the page's schemas mark external, which is what a\n * manifest with no `keys` owns (proposal 0068).\n */\n ownerOf(key: string, members: readonly string[], marked?: ReadonlySet<string>): ManifestRef | undefined {\n return this.manifests.find(\n (m) =>\n members.includes(m.collection) &&\n (m.implied ? this.impliedOwns(m, key, marked) : m.keysBefore.includes(key) || m.keysAdded.includes(key)),\n );\n }\n\n /** Does a keyless manifest own `key` for a page whose schemas mark `marked`? */\n impliedOwns(m: ManifestRef, key: string, marked: ReadonlySet<string> | undefined): boolean {\n const collection = this.collections.find((c) => c.name === m.collection);\n const declared = collection?.externalMetadata[m.index];\n return collection !== undefined && declared !== undefined && ownsKey(collection, declared, key, marked);\n }\n\n /** Does one of `members` declare a manifest with no `keys`? */\n hasImplied(members: readonly string[]): boolean {\n return this.manifests.some((m) => m.implied && members.includes(m.collection));\n }\n\n /** The page's collection to home a new key in, first by the run's selection. */\n private pick(members: readonly string[]): string | undefined {\n const selected = new Set(this.ctx.collections.map((c) => c.name));\n return members.find((m) => selected.has(m)) ?? members[0];\n }\n\n /**\n * §3's four cases. `commit` makes the choice part of the model (a created\n * collection, an appended path, a new manifest), which planning wants and a\n * lookup does not.\n */\n async home(\n label: string,\n commit: boolean,\n owns: (m: ManifestRef) => boolean = () => false,\n ): Promise<{ manifest: ManifestRef; proposed: ProposedHome } | { proposed: ProposedHome }> {\n if (this.ctx.noConfig) {\n return { proposed: { kind: \"none\", reason: \"no-config\", collections: this.collections.length } };\n }\n const members = this.members(label);\n let collection = this.pick(members);\n let createsCollection = false;\n let addsPath: string | undefined;\n if (collection === undefined) {\n const rel = this.relative(label);\n if (this.collections.length === 0) {\n const paths = dedupe(\n (await this.targetPaths()).flatMap((p) => (p === undefined ? [] : [p])),\n );\n if (rel === undefined || !paths.some((p) => isMember(bare(p), rel))) {\n return { proposed: { kind: \"none\", reason: \"collections\", collections: 0 } };\n }\n collection = \"default\";\n createsCollection = true;\n if (commit) {\n this.collections.push({ name: collection, paths, exclude: [], externalMetadata: [] });\n this.created.push({ name: collection, paths: [...paths] });\n }\n } else if (this.collections.length === 1 && this.collections[0] !== undefined) {\n const only = this.collections[0];\n const target = (await this.targetPaths()).find(\n (p) => p !== undefined && rel !== undefined && isMember(bare(p), rel),\n );\n if (target === undefined) {\n return { proposed: { kind: \"none\", reason: \"collections\", collections: 1 } };\n }\n collection = only.name;\n addsPath = target;\n if (commit) {\n only.paths.push(target);\n this.pathsAdded.push({ collection: only.name, path: target });\n }\n } else {\n return { proposed: { kind: \"none\", reason: \"collections\", collections: this.collections.length } };\n }\n }\n const name = collection;\n // A keyless manifest (proposal 0068) is a home only for what it owns: a\n // key cannot be added to a list it does not have.\n const local = this.manifestsOf(name).find((m) => !m.url && (!m.implied || owns(m)));\n const proposedOf = (m: { file: string; created: boolean }): ProposedHome => ({\n kind: \"collection\",\n collection: name,\n manifest: m.file,\n createsManifest: m.created,\n createsCollection,\n ...(addsPath !== undefined ? { addsPath } : {}),\n });\n if (local !== undefined) return { manifest: local, proposed: proposedOf(local) };\n\n const fileName = `${name}.metadata.yaml`;\n const absPath = join(this.configDir, fileName);\n const file = reported(absPath, this.ctx.base);\n if (!commit) return { proposed: proposedOf({ file, created: true }) };\n if (await exists(absPath, file)) {\n throw new DocmetaError(\n `${file} already exists and is not a manifest of collection ${name}; declare it under externalMetadata, or move it.`,\n );\n }\n const owner = this.collections.find((c) => c.name === name);\n const ref: ManifestRef = {\n collection: name,\n index: owner?.externalMetadata.length ?? 0,\n written: `./${fileName}`,\n url: false,\n absPath,\n file,\n join: PATH_JOIN,\n perPage: false,\n created: true,\n implied: false,\n keysBefore: [],\n keysAdded: [],\n keysRemoved: [],\n };\n owner?.externalMetadata.push({ file: ref.written, keys: [] });\n this.manifests.push(ref);\n return { manifest: ref, proposed: proposedOf(ref) };\n }\n\n addKey(m: ManifestRef, key: string): void {\n if (m.implied || m.keysBefore.includes(key) || m.keysAdded.includes(key)) return;\n m.keysAdded.push(key);\n this.collections.find((c) => c.name === m.collection)?.externalMetadata[m.index]?.keys?.push(key);\n }\n\n removeKey(m: ManifestRef, key: string): void {\n if (!m.keysBefore.includes(key) || m.keysRemoved.includes(key)) return;\n m.keysRemoved.push(key);\n }\n\n /** The keys a manifest owns once the plan is applied. */\n finalKeys(m: ManifestRef): string[] {\n return [...m.keysBefore.filter((k) => !m.keysRemoved.includes(k)), ...m.keysAdded];\n }\n\n /** The collections as the config will declare them: removals applied, emptied manifests gone. */\n final(): CollectionConfig[] {\n return this.collections.map((c) => ({\n ...c,\n externalMetadata: c.externalMetadata.flatMap((em, index) => {\n const ref = this.manifests.find((m) => m.collection === c.name && m.index === index);\n // A keyless manifest (proposal 0068) is declared as it was.\n if (ref?.implied === true || (ref === undefined && em.keys === undefined)) return [em];\n const keys = ref === undefined ? (em.keys ?? []) : this.finalKeys(ref);\n return keys.length === 0 ? [] : [{ ...em, keys }];\n }),\n }));\n }\n\n /** A label relative to the config directory, posix; undefined outside it. */\n relative(label: string): string | undefined {\n if (label === \"<stdin>\") return undefined;\n const rel = toPosix(relative(this.configDir, resolve(this.ctx.base, label)));\n return isAbsolute(rel) || rel.startsWith(\"../\") ? undefined : rel;\n }\n}\n\nfunction dedupe<T>(xs: readonly T[]): T[] {\n return [...new Set(xs)];\n}\n\n/** A one-path collection, for asking whether a planned `paths:` entry covers a page. */\nfunction bare(path: string): CollectionConfig {\n return { name: \"\", paths: [path], exclude: [], externalMetadata: [] };\n}\n\n/**\n * A run target as a collection `paths:` entry, relative to the config\n * directory: `docs/` and a directory named without the slash become\n * `docs/**`, a glob and a file stay themselves. Undefined for stdin and for a\n * target outside the config directory, which no collection can hold.\n */\nasync function collectionPath(target: string, cwd: string, configDir: string): Promise<string | undefined> {\n if (target === STDIN_TOKEN) return undefined;\n const posix = target.replace(/\\\\/g, \"/\");\n const scanned = picomatch.scan(posix);\n if (scanned.isGlob) {\n // The glob's literal base resolves like a file target; the magic part rides along.\n const rel = toPosix(relative(configDir, resolve(cwd, scanned.base === \"\" ? \".\" : scanned.base)));\n if (isAbsolute(rel) || rel === \"..\" || rel.startsWith(\"../\")) return undefined;\n return rel === \"\" ? scanned.glob : `${rel}/${scanned.glob}`;\n }\n const abs = resolve(cwd, posix);\n const rel = toPosix(relative(configDir, abs));\n if (isAbsolute(rel) || rel.startsWith(\"..\")) return undefined;\n let directory = posix.endsWith(\"/\");\n if (!directory) {\n try {\n directory = (await stat(abs)).isDirectory();\n } catch {\n directory = false;\n }\n }\n if (!directory) return rel;\n return rel === \"\" ? \"**\" : `${rel}/**`;\n}\n\n/**\n * Whether `absPath` exists. Only a missing file is `false`: any other failure\n * to look is refused, rather than read as room to create the file.\n */\nasync function exists(absPath: string, file: string): Promise<boolean> {\n try {\n await access(absPath);\n return true;\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return false;\n throw new DocmetaError(`${file} could not be checked: ${errorMessage(err)}`);\n }\n}\n\n/** The directory a config is (or will be) in: the loaded one, else the git root, else cwd. */\nfunction plannedConfigDir(ctx: RelocationContext): string {\n return ctx.configDir ?? findGitRoot(ctx.cwd) ?? resolve(ctx.cwd);\n}\n\n// ---------------------------------------------------------------------------\n// Lookup: where a key lives, or where it would go.\n// ---------------------------------------------------------------------------\n\n/** Where key K of one page lives, or would. */\nexport type KeyHome =\n | {\n kind: \"manifest\";\n collection: string;\n /** As the run reports it. */\n file: string;\n absPath: string;\n /** `path`, or the page field the manifest joins on. */\n join: string;\n /** The page's entry: its path from the config directory, or its join value. Undefined when the page lacks the join field. */\n entry: string | undefined;\n /**\n * The manifest is the page's own, resolved from a `{page}` pattern\n * (proposal 0058). It may not exist yet: a writer holds it as empty\n * and creates it.\n */\n perPage: boolean;\n }\n | { kind: \"url\"; collection: string; file: string }\n | { kind: \"unowned\"; home: ProposedHome };\n\n/**\n * Where `key` of the page `label` lives in the context's current config: the\n * owning local manifest (with the page's entry in it), a URL manifest, or\n * nowhere, with the home §3 would choose. Reads no manifest and writes\n * nothing. `data` is the page's own metadata, for a field join; an encrypted\n * join value is decrypted with the run's key.\n */\nexport async function keyHome(\n ctx: RelocationContext,\n label: string,\n data: Readonly<Record<string, unknown>>,\n key: string,\n): Promise<KeyHome> {\n const model = new Model(ctx, plannedConfigDir(ctx));\n const members = model.members(label);\n // A keyless manifest (proposal 0068) owns the key when the page's schemas\n // mark it external, read with the key in place: Ajv evaluates a mark only\n // where the property is present.\n const marked = model.hasImplied(members)\n ? await marksOf(ctx)(\n label,\n Object.hasOwn(data, key) ? data : { ...data, [key]: null },\n memberOf(ctx.declaredCollections, ctx.configDir ?? ctx.cwd, ctx.base, label),\n )\n : undefined;\n const owner = model.ownerOf(key, members, marked);\n if (owner !== undefined) {\n // A `{page}` manifest (proposal 0058) resolves to the page's own file.\n const at = model.fileFor(owner, resolve(ctx.base, label));\n if (owner.url || at.abs === undefined) {\n return { kind: \"url\", collection: owner.collection, file: owner.file };\n }\n return {\n kind: \"manifest\",\n collection: owner.collection,\n file: at.file,\n absPath: at.abs,\n join: owner.join,\n entry: entryFor(owner, label, data, model.configDir, ctx.base, lazyKey(ctx.configFile, ctx.env)),\n perPage: owner.perPage,\n };\n }\n return { kind: \"unowned\", home: (await model.home(label, false)).proposed };\n}\n\n/** What a page's schemas mark external, over the context's schemas (proposal 0068). */\nfunction marksOf(ctx: RelocationContext): ReturnType<typeof pageMarks> {\n return pageMarks({\n validator: ctx.validator,\n config: ctx.config,\n cwd: ctx.cwd,\n trustRoot: schemaTrustRoot(ctx.cwd, ctx.configDir),\n ...(ctx.cliSchemas !== undefined ? { cliSchemas: ctx.cliSchemas } : {}),\n });\n}\n\n/** A page's entry in a manifest: its path from the config directory, or its join value. */\nfunction entryFor(\n m: ManifestRef,\n label: string,\n data: Readonly<Record<string, unknown>>,\n configDir: string,\n base: string,\n key: () => string | undefined,\n): string | undefined {\n if (m.join === PATH_JOIN) return toPosix(relative(configDir, resolve(base, label)));\n let raw = data[m.join];\n if (isEncryptedValue(raw)) {\n const k = key();\n if (k === undefined) {\n throw new EncryptionRefusal(\n `externalMetadata join field \"${m.join}\" is encrypted on these pages, and no encryption key is available to match them.`,\n );\n }\n const opened = decryptValue(raw, k, META_CONTEXT);\n if (!opened.ok) return undefined;\n raw = opened.value;\n }\n if (typeof raw === \"string\") return raw;\n if (typeof raw === \"number\" || typeof raw === \"boolean\") return String(raw);\n return undefined;\n}\n\n// ---------------------------------------------------------------------------\n// Planning.\n// ---------------------------------------------------------------------------\n\nexport interface RelocationRequest {\n /** The pages the run named, as labels relative to the context's base. */\n files: readonly string[];\n /** `--fields`: only these keys. Each must be marked, or manifest-owned, for some file. */\n fields?: readonly string[];\n /**\n * Keys a writer is about to set that need an external home for these\n * pages, whether or not the page holds them yet. Treated as preferring\n * external metadata; a key a manifest already owns needs nothing.\n */\n require?: ReadonlyMap<string, readonly string[]>;\n}\n\ntype Intent =\n | { kind: \"out\"; manifest: ManifestRef; reason: RelocateMoveReason; drop: boolean; entry: string }\n | { kind: \"in\"; manifest: ManifestRef; drop: boolean; entry: string; value: unknown }\n | {\n kind: \"stay\";\n reason: RelocateStayReason;\n detail: string;\n /** A manifest whose key removal this stay holds back. */\n blocks?: ManifestRef;\n /** The manifest the value was on its way out to. */\n toward?: ManifestRef;\n };\n\ninterface Page {\n label: string;\n absPath: string;\n format: string;\n content: string;\n elements: string[];\n extractor: MetadataExtractor;\n own: Record<string, unknown>;\n beyond: boolean;\n /** Why a page reached only beyond the named paths could not be read. Its `own` is empty. */\n unreadable?: string;\n intents: Map<string, Intent>;\n /** The page's text afterwards, when it changes. */\n text?: string;\n}\n\n/** One file the plan writes. */\nexport interface RelocationWrite {\n path: string;\n text: string;\n kind: \"manifest\" | \"config\" | \"page\";\n /**\n * The file's text on disk when the plan was made, or null when it did not\n * exist. Applying refuses a file that no longer matches, and a failed run\n * puts this text back.\n */\n before: string | null;\n}\n\n/** How `applyRelocation` changes the disk. Tests replace it; the default is atomic writes and `unlink`. */\nexport interface RelocationIo {\n write?: (path: string, text: string) => Promise<void>;\n remove?: (path: string) => Promise<void>;\n}\n\n/** A complete, validated plan: every text computed, nothing written. */\nexport interface RelocationPlan {\n /** The report, as a dry run shows it: no manifest lines. */\n result: RelocateResult;\n /** Every file to write, in write order. */\n writes: RelocationWrite[];\n /** Manifest lines per (file, key), for the applied report. */\n lines: ReadonlyMap<string, number>;\n /** The collections as the config declares them afterwards. */\n collections: CollectionConfig[];\n configDir: string;\n configPath: string;\n /** The per-collection offers the writers' and validate's prompts put. */\n offers: RelocationOffer[];\n /**\n * Pages whose external-preferring keys have no possible home, for the\n * writers' W2 line: several collections and the page in none, or\n * `--no-config`.\n */\n homeless: { file: string; keys: string[]; reason: \"collections\" | \"no-config\"; collections: number }[];\n}\n\n/**\n * The pages a `{page}` manifest (proposal 0058) is read for: the run's own,\n * and every member of a collection that declares one. A `keys:` change\n * reaches every member page, so a narrowed run still has to know what each\n * member's manifest holds. With no placeholder declared, nothing is walked.\n */\nasync function relocationPages(\n ctx: RelocationContext,\n request: RelocationRequest,\n): Promise<string[]> {\n const pages = new Set(request.files.map((label) => resolve(ctx.base, label)));\n const root = ctx.configDir ?? ctx.cwd;\n for (const collection of ctx.declaredCollections) {\n const perPage = collection.externalMetadata.some(\n (m) => classifyRef(m.file).kind !== \"url\" && hasPagePlaceholder(m.file),\n );\n if (!perPage) continue;\n const walked = await resolveTargetSet({\n inputs: [...collection.paths],\n cwd: root,\n allowEmpty: true,\n ...gitignoreOptions({\n ...(ctx.respectGitignore !== undefined ? { flag: ctx.respectGitignore } : {}),\n ...(ctx.config?.respectGitignore !== undefined ? { configured: ctx.config.respectGitignore } : {}),\n }),\n });\n for (const file of walked.files) pages.add(resolve(root, file));\n }\n return [...pages];\n}\n\n/**\n * Plan every move for `request.files` and the member pages a `keys:` change\n * reaches, with every new file text computed and read back. Writes nothing.\n *\n * Throws `DocmetaError` for a page that will not load, a schema that will not\n * resolve, a `--fields` name nothing marks or owns (U3), a manifest path that\n * exists undeclared (U6), a single-tool config file, and an edit that does\n * not read back as planned.\n */\nexport async function planRelocation(\n ctx: RelocationContext,\n request: RelocationRequest,\n): Promise<RelocationPlan> {\n const configDir = plannedConfigDir(ctx);\n const model = new Model(ctx, configDir);\n const encryptionKey = lazyKey(ctx.configFile, ctx.env);\n const marks = marksOf(ctx);\n const index = await loadExternalMetadata(ctx.declaredCollections, {\n configDir: ctx.configDir ?? ctx.cwd,\n base: ctx.base,\n offline: ctx.config?.offline ?? false,\n pages: await relocationPages(ctx, request),\n });\n const trustRoot = schemaTrustRoot(ctx.cwd, ctx.configDir);\n const forced = ctx.as !== undefined ? extractorByName(ctx.as) : undefined;\n const fields = request.fields === undefined ? undefined : new Set(request.fields);\n const wanted = (key: string): boolean => key !== FILE_SCHEMA_KEY && (fields === undefined || fields.has(key));\n const currentMembers = (label: string): string[] =>\n memberOf(ctx.declaredCollections, ctx.configDir ?? ctx.cwd, ctx.base, label);\n\n const pages = new Map<string, Page>();\n const runSet = new Set(request.files);\n const load = async (label: string, beyond: boolean): Promise<Page | undefined> => {\n const have = pages.get(label);\n if (have !== undefined) return have;\n // `--as` names how the run's own files are read; a sibling reached through a\n // keys: or paths: change is read by its extension, like any walk.\n const extractor = (beyond ? undefined : forced) ?? extractorForExtension(extname(label));\n if (extractor === undefined) {\n if (beyond) return undefined;\n throw new DocmetaError(`Unsupported file type \"${extname(label)}\" for \"${label}\". Use --as to override.`);\n }\n const absPath = resolve(ctx.base, label);\n const elements = resolveElements(label, ctx.config, currentMembers(label));\n let content = \"\";\n let own: Record<string, unknown> = {};\n let unreadable: string | undefined;\n // A named page that will not load refuses the run. A sibling is one page\n // among many the change reaches, so its values stay, with the reason.\n if (beyond) {\n try {\n content = await readFile(absPath, \"utf8\");\n own = extractor.extract(content, label, { elements }).data;\n } catch (err) {\n // The first line: a parser's excerpt of the source would break the report's one line per value.\n unreadable = (errorMessage(err).split(\"\\n\")[0] ?? \"\").replace(/:\\s*$/, \"\");\n }\n } else {\n content = await readFile(absPath, \"utf8\");\n try {\n own = extractor.extract(content, label, { elements }).data;\n } catch (err) {\n throw new DocmetaError(`${label}: ${errorMessage(err)}`);\n }\n }\n const page: Page = {\n label,\n absPath,\n format: extractor.name,\n content,\n elements,\n extractor,\n own,\n beyond,\n ...(unreadable !== undefined ? { unreadable } : {}),\n intents: new Map(),\n };\n pages.set(label, page);\n return page;\n };\n\n /** The value manifest `m` holds for `key` of `page` today. */\n const supplied = (m: ManifestRef, page: Page, key: string): ExternalMetadataValue | undefined => {\n if (m.created || index === null) return undefined;\n let sv: ExternalMetadataValue | undefined;\n if (m.join === PATH_JOIN) {\n sv = index.byPath.get(page.absPath)?.get(key);\n } else {\n const entry = entryFor(m, page.label, page.own, configDir, ctx.base, encryptionKey);\n sv = entry === undefined ? undefined : index.byField.get(m.join)?.get(entry)?.get(key);\n }\n // A `{page}` manifest's values carry the page's own file (proposal 0058).\n return sv !== undefined && sv.collection === m.collection && sv.file === model.fileFor(m, page.absPath).file\n ? sv\n : undefined;\n };\n\n const stay = (\n page: Page,\n key: string,\n reason: RelocateStayReason,\n detail: string,\n links: { blocks?: ManifestRef; toward?: ManifestRef } = {},\n ): void => {\n page.intents.set(key, { kind: \"stay\", reason, detail, ...links });\n };\n const urlDetail = (m: ManifestRef): string => `${m.file} is fetched and cannot be written`;\n const unreadableDetail = (page: Page): string => `this document could not be parsed: ${page.unreadable ?? \"\"}`;\n\n /** Out of the page, into `m`. */\n const planOut = (page: Page, m: ManifestRef, key: string, reason: RelocateMoveReason): void => {\n if (page.intents.has(key)) return;\n if (m.url) {\n stay(page, key, \"url-manifest\", urlDetail(m), { toward: m });\n return;\n }\n const entry = entryFor(m, page.label, page.own, configDir, ctx.base, encryptionKey);\n if (entry === undefined) {\n stay(page, key, \"no-join-value\", `this document has no ${m.join}, which ${m.file} joins on`, { toward: m });\n return;\n }\n const held = supplied(m, page, key);\n if (held !== undefined && !deepEqual(held.value, page.own[key])) {\n stay(page, key, \"values-differ\", `the page and ${held.file} hold different values`, { toward: m });\n return;\n }\n page.intents.set(key, { kind: \"out\", manifest: m, reason, drop: held !== undefined, entry });\n };\n\n /** Out of `m`, into the page. */\n const planIn = (page: Page, m: ManifestRef, key: string): void => {\n if (page.intents.has(key)) return;\n const held = supplied(m, page, key);\n if (held === undefined) return;\n const entry = entryFor(m, page.label, page.own, configDir, ctx.base, encryptionKey);\n /* c8 ignore next -- a supplied value was found through its entry. */\n if (entry === undefined) return;\n if (Object.hasOwn(page.own, key)) {\n if (!deepEqual(held.value, page.own[key])) {\n stay(page, key, \"values-differ\", `the page and ${held.file} hold different values`, { blocks: m });\n return;\n }\n page.intents.set(key, { kind: \"in\", manifest: m, drop: true, entry, value: held.value });\n return;\n }\n page.intents.set(key, { kind: \"in\", manifest: m, drop: false, entry, value: held.value });\n };\n\n // ---- The named pages: what their schemas and the config say ---------------\n const preferencesOf = new Map<string, Map<string, FieldLocation>>();\n const homeless = new Map<string, { keys: string[]; reason: \"collections\" | \"no-config\"; collections: number }>();\n const marked = new Set<string>();\n for (const label of request.files) {\n const page = await load(label, false);\n /* c8 ignore next -- a named page always has an extractor, or `load` threw. */\n if (page === undefined) continue;\n const members = currentMembers(label);\n const merged = await mergeWithMarks(\n label,\n { data: page.own, present: true, format: page.format, lineFor: () => undefined },\n index,\n members,\n ctx.base,\n { encryptionKey, marks },\n );\n const data = merged.extracted.data;\n const required = request.require?.get(label) ?? [];\n const resolved = resolveSchemaSetWithSource({\n filePath: label,\n fileSchema: data[FILE_SCHEMA_KEY],\n ...(ctx.cliSchemas !== undefined ? { cliSchemas: [...ctx.cliSchemas] } : {}),\n config: ctx.config,\n memberOf: members,\n fileBase: ctx.cwd,\n trustRoot,\n ...(ctx.onNotice !== undefined ? { onNotice: ctx.onNotice } : {}),\n });\n const probe: Record<string, unknown> = { ...data };\n for (const key of required) if (!(key in probe)) probe[key] = null;\n const prefs = new Map<string, FieldLocation>();\n /** What the schemas mark external, and so what a keyless manifest owns (0068). */\n const external = new Set<string>();\n for (const [key, p] of await ctx.validator.locationPreferences(probe, resolved.schemas)) {\n prefs.set(key, p.location);\n marked.add(key);\n if (p.location === \"external\") external.add(key);\n }\n for (const key of required) if (!prefs.has(key)) prefs.set(key, \"external\");\n preferencesOf.set(label, prefs);\n\n const planned = model.members(label);\n const joins = new Set(\n model.manifests.filter((m) => planned.includes(m.collection) && m.join !== PATH_JOIN).map((m) => m.join),\n );\n for (const m of model.manifests) {\n if (planned.includes(m.collection)) for (const k of [...m.keysBefore, ...m.keysAdded]) marked.add(k);\n }\n const keys = dedupe([...Object.keys(data), ...required]).filter(wanted);\n for (const key of keys) {\n if (joins.has(key)) continue;\n const pref = prefs.get(key);\n const inPage = Object.hasOwn(page.own, key);\n const owner = model.ownerOf(key, model.members(label), external);\n if (owner !== undefined) {\n if (pref === \"page\") {\n if (owner.url) {\n if (supplied(owner, page, key) !== undefined) stay(page, key, \"url-manifest\", urlDetail(owner));\n } else if (owner.keysBefore.includes(key)) {\n model.removeKey(owner, key);\n }\n } else if (inPage) {\n planOut(page, owner, key, pref === \"external\" ? \"preferred\" : \"owned\");\n }\n continue;\n }\n if (pref !== \"external\" || !(inPage || required.includes(key))) continue;\n const chosen = await model.home(label, true, (m) => model.impliedOwns(m, key, external));\n if (\"manifest\" in chosen) {\n // A keyless manifest owns the key already, so only this page's value moves.\n if (chosen.manifest.implied) {\n if (inPage) planOut(page, chosen.manifest, key, \"preferred\");\n continue;\n }\n model.addKey(chosen.manifest, key);\n continue;\n }\n if (chosen.proposed.kind !== \"none\") continue;\n if (inPage) {\n stay(\n page,\n key,\n \"no-home\",\n chosen.proposed.reason === \"no-config\"\n ? \"--no-config leaves this document no manifest\"\n : `this document is in none of the ${chosen.proposed.collections} collections, so it has no manifest`,\n );\n }\n const entry = homeless.get(label) ?? {\n keys: [],\n reason: chosen.proposed.reason,\n collections: chosen.proposed.collections,\n };\n entry.keys.push(key);\n homeless.set(label, entry);\n }\n }\n if (fields !== undefined) {\n for (const f of fields) {\n if (!marked.has(f) && !(request.require !== undefined && [...request.require.values()].some((ks) => ks.includes(f)))) {\n throw new DocmetaError(\n `\"${f}\" has no x-manni-location mark and no owning manifest for any file in this run.`,\n );\n }\n }\n }\n\n // ---- A key leaving keys: is headed for the page ---------------------------\n // A page planned before (or after) another page's mark removed the key would\n // otherwise send its copy to a manifest that no longer owns it. The move is\n // set aside, and put back if a page blocks the removal below.\n const suspended: { page: Page; manifest: ManifestRef; key: string; reason: RelocateMoveReason }[] = [];\n for (const page of pages.values()) {\n for (const [key, intent] of [...page.intents]) {\n const m = intent.kind === \"out\" ? intent.manifest : intent.kind === \"stay\" ? intent.toward : undefined;\n if (m === undefined || !m.keysRemoved.includes(key)) continue;\n page.intents.delete(key);\n const prefs = preferencesOf.get(page.label);\n suspended.push({\n page,\n manifest: m,\n key,\n reason: intent.kind === \"out\" ? intent.reason : prefs?.get(key) === \"external\" ? \"preferred\" : \"owned\",\n });\n }\n }\n\n // ---- A keys: or paths: change reaches every member page -------------------\n const grown = new Set(model.pathsAdded.map((p) => p.collection));\n const affected = new Set<string>(grown);\n for (const m of model.manifests) {\n if (m.keysAdded.length > 0 || m.keysRemoved.length > 0) affected.add(m.collection);\n }\n for (const name of affected) {\n const collection = model.collections.find((c) => c.name === name);\n /* c8 ignore next -- an affected collection is one of the model's. */\n if (collection === undefined) continue;\n const walked = await resolveTargetSet({\n inputs: [...collection.paths],\n cwd: configDir,\n allowEmpty: true,\n ...gitignoreOptions({\n ...(ctx.respectGitignore !== undefined ? { flag: ctx.respectGitignore } : {}),\n ...(ctx.config?.respectGitignore !== undefined ? { configured: ctx.config.respectGitignore } : {}),\n }),\n });\n const labels = dedupe([\n ...request.files,\n ...walked.files.map((f) => reported(resolve(configDir, f), ctx.base)),\n ]).filter((label) => model.members(label).includes(name));\n for (const label of labels) {\n const page = await load(label, !runSet.has(label));\n if (page === undefined) continue;\n const prefs = preferencesOf.get(label);\n // A page the paths: change brings in is covered for every key the\n // manifest owns, as a keys: change covers every page: --fields cannot\n // leave an owned key behind on it.\n const covered = grown.has(name) && !currentMembers(label).includes(name);\n for (const m of model.manifestsOf(name)) {\n const out = dedupe([\n ...m.keysAdded,\n ...(grown.has(name) ? m.keysBefore.filter((k) => !m.keysRemoved.includes(k)) : []),\n ]).filter((k) => (covered ? k !== FILE_SCHEMA_KEY : wanted(k)));\n if (page.unreadable !== undefined) {\n const detail = unreadableDetail(page);\n // The keys whose home this run changes for the page: added ones, and\n // every owned one when the page is newly covered.\n const changing = covered ? out : out.filter((k) => m.keysAdded.includes(k));\n for (const key of changing) if (!page.intents.has(key)) stay(page, key, \"unreadable\", detail);\n for (const key of m.keysRemoved) {\n // Whether the manifest sets the key for this page is known only\n // for a path join; a field join needs the page's own value.\n const held =\n m.join !== PATH_JOIN ||\n (!m.created && index?.byPath.get(page.absPath)?.get(key)?.file === model.fileFor(m, page.absPath).file);\n if (held && !page.intents.has(key)) stay(page, key, \"unreadable\", detail, { blocks: m });\n }\n continue;\n }\n for (const key of out) {\n if (!Object.hasOwn(page.own, key)) continue;\n const reason = m.keysAdded.includes(key) || prefs?.get(key) === \"external\" ? \"preferred\" : \"owned\";\n planOut(page, m, key, reason);\n }\n for (const key of m.keysRemoved) planIn(page, m, key);\n }\n }\n }\n\n // ---- Page texts, and removals a page blocks --------------------------------\n const orderedPages = (): Page[] => {\n const all = [...pages.values()];\n const run = all.filter((p) => !p.beyond).sort((a, b) => compare(a.label, b.label));\n const beyond = all.filter((p) => p.beyond).sort((a, b) => compare(a.label, b.label));\n return [...run, ...beyond];\n };\n // A worklist. Planning a page's text reads only that page's intents, so a\n // page whose intents did not change since its last planning would plan the\n // same text. The first pass plans every page; each later pass re-plans only\n // the pages the previous pass's unblocked removals touched, and looks among\n // them for new blocks. A block found earlier is settled: keysRemoved only\n // shrinks, so it cannot fire twice.\n let dirty = new Set<Page>(pages.values());\n while (dirty.size > 0) {\n // In the pages' own order, as every page was planned before.\n const pass = [...pages.values()].filter((p) => dirty.has(p));\n for (const page of pass) planPageText(page);\n const touched = new Set<Page>();\n for (const page of pass) {\n for (const [key, intent] of page.intents) {\n if (intent.kind !== \"stay\" || intent.blocks === undefined) continue;\n const m = intent.blocks;\n if (!m.keysRemoved.includes(key)) continue;\n m.keysRemoved.splice(m.keysRemoved.indexOf(key), 1);\n for (const other of pages.values()) {\n const i = other.intents.get(key);\n if (i?.kind === \"in\" && i.manifest === m) {\n other.intents.delete(key);\n touched.add(other);\n }\n }\n // The manifest keeps the key, so a copy set aside for the page goes to it after all.\n for (const s of suspended) {\n if (s.manifest === m && s.key === key) {\n planOut(s.page, m, key, s.reason);\n touched.add(s.page);\n }\n }\n }\n }\n dirty = touched;\n }\n\n // ---- Manifest texts --------------------------------------------------------\n const writes: RelocationWrite[] = [];\n const lines = new Map<string, number>();\n for (const m of model.manifests) {\n if (m.url) continue;\n const undeclared = !m.implied && model.finalKeys(m).length === 0 && !m.created;\n /**\n * The edits, by the file they land in. One file for a concrete manifest;\n * one per page for a `{page}` manifest (proposal 0058), so each page's\n * values go to, and come from, the page's own file.\n */\n type Edits = {\n file: string;\n outs: { page: string; entry: string; key: string; value: unknown; drop: boolean }[];\n ins: { entry: string; key: string }[];\n };\n const files = new Map<string, Edits>();\n const group = (at: { abs: string | undefined; file: string }): Edits | undefined => {\n /* c8 ignore next -- only a URL manifest has no path, and it was skipped. */\n if (at.abs === undefined) return undefined;\n const have = files.get(at.abs);\n if (have !== undefined) return have;\n const made: Edits = { file: at.file, outs: [], ins: [] };\n files.set(at.abs, made);\n return made;\n };\n // A created manifest is written even when nothing moves into it.\n if (m.created) group({ abs: m.absPath, file: m.file });\n for (const page of orderedPages()) {\n for (const [key, intent] of orderedIntents(page)) {\n if ((intent.kind === \"out\" || intent.kind === \"in\") && intent.manifest === m) {\n const into = group(model.fileFor(m, page.absPath));\n if (intent.kind === \"out\") {\n into?.outs.push({ page: page.label, entry: intent.entry, key, value: page.own[key], drop: intent.drop });\n } else {\n into?.ins.push({ entry: intent.entry, key });\n }\n }\n }\n }\n if (!undeclared) assertNoStrandedEntries(m, index, pages, configDir, (abs) => model.fileFor(m, abs).file);\n if (undeclared) continue;\n for (const [path, { file, outs, ins }] of files) {\n if (!m.created && outs.length === 0 && ins.length === 0) continue;\n // A created manifest's path does not exist: planning refuses one that\n // does (U6). A `{page}` manifest that does not exist yet reads as empty\n // and is created, `before: null`, like one.\n const disk = m.created ? null : await readManifestText(path, file, m.perPage);\n let text = disk ?? \"\";\n const before = text;\n const where = { join: m.join, file };\n for (const o of outs) {\n if (!o.drop) text = spliceManifestValue(text, { ...where, entry: o.entry, key: o.key, value: o.value }).text;\n }\n for (const i of ins) text = removeManifestKey(text, { ...where, entry: i.entry, key: i.key }).text;\n const found = keyLines(text, m.join);\n for (const o of outs) {\n const line = found.get(entryId(o.entry, m.join))?.get(o.key);\n if (line !== undefined) lines.set(lineId(o.page, file, o.key), line);\n }\n if (m.created || text !== before) {\n writes.push({ path, text, kind: \"manifest\", before: disk });\n }\n }\n }\n\n // ---- Config text ---------------------------------------------------------------\n const finalCollections = model.final();\n const needsConfig =\n model.created.length > 0 ||\n model.pathsAdded.length > 0 ||\n model.manifests.some((m) => m.created || m.keysAdded.length > 0 || m.keysRemoved.length > 0);\n const target = await configTarget(ctx, configDir);\n let configCreated = false;\n if (needsConfig) {\n if (ctx.configFile !== undefined && (ctx.configFile.kind === \"legacy\" || !ctx.configFile.wrapped)) {\n throw new DocmetaError(\n `${ctx.configFile.source} is a single-tool config file, which cannot hold collections:. Move its keys under meta: in ${FAMILY_CONFIG_NAMES[0] ?? \"manni.config.yaml\"}.`,\n );\n }\n const text = editConfig(target.text, model, configSource(target.path, ctx.cwd));\n verifyConfig(target.text, text, finalCollections, configSource(target.path, ctx.cwd));\n writes.push({ path: target.path, text, kind: \"config\", before: target.disk });\n configCreated = target.text === null;\n }\n\n for (const page of orderedPages()) {\n if (page.text !== undefined && page.text !== page.content) {\n writes.push({ path: page.absPath, text: page.text, kind: \"page\", before: page.content });\n }\n }\n\n const result = buildResult({\n model,\n pages: orderedPages(),\n dryRun: true,\n lines: new Map(),\n config: {\n file: needsConfig || ctx.configPath !== undefined ? configSource(target.path, ctx.cwd) : null,\n created: configCreated,\n collectionsCreated: model.created,\n pathsAdded: model.pathsAdded,\n },\n });\n return {\n result,\n writes,\n lines,\n collections: finalCollections,\n configDir,\n configPath: target.path,\n offers: buildOffers(model, orderedPages(), result, needsConfig ? configSource(target.path, ctx.cwd) : undefined),\n homeless: [...homeless].map(([file, h]) => ({ file, ...h })),\n };\n}\n\nconst compare = (a: string, b: string): number => (a < b ? -1 : a > b ? 1 : 0);\n\n/**\n * A page's intents in the page's own key order, then the rest (values coming\n * in from a manifest) as they were planned. Planning reaches a page's keys in\n * two passes, so insertion order alone would not follow the page.\n */\nfunction orderedIntents(page: Page): [string, Intent][] {\n const order = Object.keys(page.own);\n const rank = (key: string): number => {\n const i = order.indexOf(key);\n return i === -1 ? order.length : i;\n };\n return [...page.intents].sort(([a], [b]) => rank(a) - rank(b));\n}\n\n/**\n * The page's new text for its intents, read back. A format with no writer,\n * or a document its writer refuses, turns every intent that needs the page\n * written into a stay; one moving a value in blocks that key's removal.\n */\nfunction planPageText(page: Page): void {\n const patch: MetadataPatch = {};\n const deletions: string[] = [];\n for (const [key, intent] of page.intents) {\n if (intent.kind === \"out\") deletions.push(key);\n else if (intent.kind === \"in\" && !intent.drop) patch[key] = intent.value;\n }\n delete page.text;\n if (deletions.length === 0 && Object.keys(patch).length === 0) return;\n const refuse = (): void => {\n for (const [key, intent] of page.intents) {\n if (intent.kind === \"out\" || (intent.kind === \"in\" && !intent.drop)) {\n page.intents.set(key, {\n kind: \"stay\",\n reason: \"read-only-format\",\n detail: `the ${page.format} format cannot write this document's metadata`,\n ...(intent.kind === \"in\" ? { blocks: intent.manifest } : {}),\n });\n }\n }\n };\n const apply = page.extractor.apply;\n if (typeof apply !== \"function\") {\n refuse();\n return;\n }\n try {\n const next = apply(page.content, patch, {\n filePath: page.label,\n elements: page.elements,\n ...(deletions.length > 0 ? { deletions } : {}),\n });\n const after = page.extractor.extract(next, page.label, { elements: page.elements }).data;\n const wrote =\n deletions.every((k) => !Object.hasOwn(after, k)) &&\n Object.entries(patch).every(([k, v]) => deepEqual(after[k], v));\n if (!wrote) {\n refuse();\n return;\n }\n page.text = next;\n } catch (err) {\n if (!(err instanceof DocmetaError)) throw err;\n refuse();\n }\n}\n\n/**\n * A key leaving a manifest's `keys:` while an entry no member page matched\n * still sets it would make the manifest unloadable (\"sets a key it does not\n * own\"). Refused, naming the entry, rather than written.\n */\nfunction assertNoStrandedEntries(\n m: ManifestRef,\n index: ExternalMetadataIndex | null,\n pages: ReadonlyMap<string, Page>,\n configDir: string,\n /** The file `m` keeps one page's values in: the page's own for a `{page}` manifest. */\n fileOf: (pageAbs: string) => string,\n): void {\n if (index === null || m.keysRemoved.length === 0) return;\n for (const key of m.keysRemoved) {\n const moved = new Set<string>();\n for (const page of pages.values()) {\n const i = page.intents.get(key);\n if (i?.kind === \"in\" && i.manifest === m) moved.add(entryId(i.entry, m.join));\n }\n const stranded =\n m.join === PATH_JOIN\n ? [...index.byPath]\n .filter(([abs, values]) => {\n const sv = values.get(key);\n return sv !== undefined && sv.collection === m.collection && sv.file === fileOf(abs);\n })\n .map(([abs]) => toPosix(relative(configDir, abs)))\n : [...(index.byField.get(m.join) ?? new Map<string, ReadonlyMap<string, ExternalMetadataValue>>())]\n .filter(([, values]) => {\n const sv = values.get(key);\n return sv !== undefined && sv.file === m.file && sv.collection === m.collection;\n })\n .map(([value]) => value);\n const first = stranded.find((e) => !moved.has(entryId(e, m.join)));\n if (first !== undefined) {\n throw new DocmetaError(\n `Manifest ${m.file} names \"${first}\", which is not a page of collection ${m.collection}, so ${key} cannot leave its keys while that entry sets it. Fix the entry, or remove it.`,\n );\n }\n }\n}\n\n/**\n * A manifest's text, or null for a `{page}` manifest (proposal 0058) that\n * does not exist yet: a page with nothing kept there. A missing concrete\n * manifest is refused.\n */\nasync function readManifestText(path: string, file: string, perPage: boolean): Promise<string | null> {\n try {\n return await readFile(path, \"utf8\");\n } catch (err) {\n if (perPage && isMissing(err)) return null;\n throw new DocmetaError(`Manifest ${file} could not be read: ${errorMessage(err)}`);\n }\n}\n\n\nconst entryId = (entry: string, join: string): string =>\n join === PATH_JOIN ? toPosix(entry).replace(/^\\.\\//, \"\").replace(/\\/+/g, \"/\") : entry;\n/** A move's line, keyed by page label, manifest and key. */\n// NUL separates the parts, which assumes none of them holds a NUL. No supported OS allows one\n// in a page label or manifest path, and YAML frontmatter does not produce one in a key in practice.\nconst lineId = (page: string, manifest: string, key: string): string => `${page}\\0${manifest}\\0${key}`;\n\n/** Entry -> key -> 1-based line of the key, in a manifest's text. */\nfunction keyLines(text: string, join: string): Map<string, Map<string, number>> {\n const out = new Map<string, Map<string, number>>();\n const lc = new LineCounter();\n const doc = parseDocument(text, { lineCounter: lc, uniqueKeys: false });\n const root = doc.contents;\n if (!isMap(root)) return out;\n for (const pair of root.items) {\n const spelled = isScalar(pair.key) ? String(pair.key.value) : String(pair.key);\n if (!isMap(pair.value)) continue;\n const keys = new Map<string, number>();\n for (const kv of pair.value.items) {\n const name = isScalar(kv.key) ? String(kv.key.value) : String(kv.key);\n const range = isNode(kv.key) ? kv.key.range : undefined;\n if (range) keys.set(name, lc.linePos(range[0]).line);\n }\n out.set(entryId(spelled, join), keys);\n }\n return out;\n}\n\n/**\n * The config file a plan edits: the run's, else the family file at the git\n * root or cwd. `text` is what the edit starts from; `disk` is what the file\n * holds now, or null when there is no file.\n */\nasync function configTarget(\n ctx: RelocationContext,\n configDir: string,\n): Promise<{ path: string; text: string | null; disk: string | null }> {\n if (ctx.configPath !== undefined) {\n // Re-read rather than trust discovery's copy: an edit made since must not be written over.\n // Only a file removed since falls back to that copy; any other failure is refused.\n try {\n const text = await readFile(ctx.configPath, \"utf8\");\n return { path: ctx.configPath, text, disk: text };\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== \"ENOENT\") {\n throw new DocmetaError(\n `Config file ${configSource(ctx.configPath, ctx.cwd)} could not be read: ${errorMessage(err)}`,\n );\n }\n return { path: ctx.configPath, text: ctx.configFile?.text ?? null, disk: null };\n }\n }\n for (const name of FAMILY_CONFIG_NAMES) {\n const path = join(configDir, name);\n try {\n const text = await readFile(path, \"utf8\");\n return { path, text, disk: text };\n } catch {\n // Not this one.\n }\n }\n return { path: join(configDir, FAMILY_CONFIG_NAMES[0] ?? \"manni.config.yaml\"), text: null, disk: null };\n}\n\n/** The config text with the model's changes, comments and key order kept. */\nfunction editConfig(text: string | null, model: Model, source: string): string {\n const doc = parseDocument(text ?? \"\");\n const [problem] = doc.errors;\n if (problem !== undefined) throw new DocmetaError(`${source}: invalid YAML: ${problem.message}`);\n if (doc.contents !== null && !isMap(doc.contents)) {\n throw new DocmetaError(`${source}: top level must be a mapping.`);\n }\n const fail = (): never => {\n throw new DocmetaError(`Could not edit collections: in ${source}; make the change by hand.`);\n };\n const flowSeq = (node: unknown, quoted: boolean): void => {\n if (!isSeq(node)) return;\n node.flow = true;\n if (quoted) for (const item of node.items) if (isScalar(item)) item.type = \"QUOTE_DOUBLE\";\n };\n const manifestNode = (d: Document, file: string, keys: string[]): unknown => {\n const node = d.createNode({ file, keys });\n flowSeq(node.get(\"keys\", true), false);\n return node;\n };\n\n const declared = model.collections.length - model.created.length;\n const existing = doc.get(\"collections\", true);\n if (declared > 0 && !isSeq(existing)) fail();\n for (let i = 0; i < declared; i++) {\n const c = model.collections[i];\n const node = isSeq(existing) ? existing.items[i] : undefined;\n if (c === undefined || !isMap(node)) return fail();\n for (const added of model.pathsAdded.filter((p) => p.collection === c.name)) {\n const paths = node.get(\"paths\", true);\n if (!isSeq(paths)) return fail();\n const scalar = doc.createNode(added.path);\n const first = paths.items[0];\n if (isScalar(first) && first.type !== undefined) scalar.type = first.type;\n paths.add(scalar);\n }\n const refs = model.manifestsOf(c.name);\n for (const m of refs) {\n if (m.created) {\n let list = node.get(\"externalMetadata\", true);\n if (!isSeq(list)) {\n node.set(\"externalMetadata\", doc.createNode([]));\n list = node.get(\"externalMetadata\", true);\n }\n if (!isSeq(list)) return fail();\n list.add(manifestNode(doc, m.written, m.keysAdded));\n continue;\n }\n if (m.keysAdded.length === 0) continue;\n const entry = node.getIn([\"externalMetadata\", m.index], true);\n const keys = isMap(entry) ? entry.get(\"keys\", true) : undefined;\n if (!isSeq(keys)) return fail();\n for (const key of m.keysAdded) keys.add(doc.createNode(key));\n }\n // Removals last, highest index first, so earlier indices stay valid.\n const list = node.get(\"externalMetadata\", true);\n for (const m of [...refs].filter((r) => !r.created).sort((a, b) => b.index - a.index)) {\n if (m.keysRemoved.length === 0) continue;\n if (!isSeq(list)) return fail();\n const entry = list.items[m.index];\n const keys = isMap(entry) ? entry.get(\"keys\", true) : undefined;\n if (!isSeq(keys)) return fail();\n for (const key of m.keysRemoved) {\n const at = keys.items.findIndex((item) => (isScalar(item) ? String(item.value) : String(item)) === key);\n if (at >= 0) keys.delete(at);\n }\n if (keys.items.length === 0) list.delete(m.index);\n }\n if (isSeq(list) && list.items.length === 0) node.delete(\"externalMetadata\");\n }\n for (const created of model.created) {\n const c = model.collections.find((x) => x.name === created.name);\n /* c8 ignore next -- a created collection is in the model. */\n if (c === undefined) continue;\n const refs = model.manifestsOf(c.name).filter((m) => m.created);\n const node = doc.createNode({\n name: c.name,\n paths: c.paths,\n ...(refs.length > 0\n ? { externalMetadata: refs.map((m) => ({ file: m.written, keys: m.keysAdded })) }\n : {}),\n });\n flowSeq(node.get(\"paths\", true), true);\n const made = node.get(\"externalMetadata\", true);\n if (isSeq(made)) {\n for (const item of made.items) if (isMap(item)) flowSeq(item.get(\"keys\", true), false);\n }\n const seq = doc.get(\"collections\", true);\n if (isSeq(seq)) seq.add(node);\n else doc.set(\"collections\", doc.createNode([node]));\n }\n return doc.toString({ flowCollectionPadding: false });\n}\n\n/**\n * Read back the edited config the way discovery would: it parses, it\n * declares exactly the planned collections, and every other top-level key is\n * as it was. A config the tools cannot read is worse than a refused run.\n */\nfunction verifyConfig(\n before: string | null,\n after: string,\n expected: CollectionConfig[],\n source: string,\n): void {\n const fail = (why: string): never => {\n throw new DocmetaError(`Could not edit collections: in ${source}, so nothing was written. ${why}`);\n };\n let old: unknown;\n let now: unknown;\n try {\n old = before === null ? null : parseYaml(before);\n now = parseYaml(after);\n } catch (err) {\n return fail(errorMessage(err));\n }\n if (typeof now !== \"object\" || now === null || Array.isArray(now)) return fail(\"The result is not a mapping.\");\n const nowMap = now as Record<string, unknown>;\n const oldMap = typeof old === \"object\" && old !== null && !Array.isArray(old) ? (old as Record<string, unknown>) : {};\n const parsed = parseCollections(nowMap[\"collections\"], source, (m) => new DocmetaError(m));\n if (!deepEqual(parsed, expected)) return fail(\"The collections read back differently.\");\n const rest = (m: Record<string, unknown>): Record<string, unknown> =>\n Object.fromEntries(Object.entries(m).filter(([k]) => k !== \"collections\"));\n if (!deepEqual(rest(nowMap), rest(oldMap))) return fail(\"Another key would have changed.\");\n}\n\n// ---------------------------------------------------------------------------\n// The report.\n// ---------------------------------------------------------------------------\n\nfunction buildResult(input: {\n model: Model;\n pages: Page[];\n dryRun: boolean;\n lines: ReadonlyMap<string, number>;\n config: RelocateConfigResult;\n}): RelocateResult {\n const { model, pages, dryRun, lines } = input;\n const files: RelocateFileResult[] = [];\n for (const page of pages) {\n const moved: RelocateMove[] = [];\n const stayed: RelocateStay[] = [];\n const intents = orderedIntents(page);\n // A `{page}` manifest (proposal 0058) is named by the page's own file.\n const fileOf = (m: ManifestRef): string => model.fileFor(m, page.absPath).file;\n for (const [key, intent] of intents) {\n if (intent.kind === \"in\") moved.push({ key, to: \"page\", from: fileOf(intent.manifest), reason: \"preferred\" });\n }\n for (const [key, intent] of intents) {\n if (intent.kind !== \"out\") continue;\n const manifest = fileOf(intent.manifest);\n const line = dryRun ? undefined : lines.get(lineId(page.label, manifest, key));\n moved.push({\n key,\n to: \"manifest\",\n manifest,\n ...(line !== undefined ? { line } : {}),\n reason: intent.reason,\n });\n }\n for (const [key, intent] of intents) {\n if (intent.kind === \"stay\") stayed.push({ key, reason: intent.reason, detail: intent.detail });\n }\n if (moved.length > 0 || stayed.length > 0) files.push({ file: page.label, moved, stayed, beyond: page.beyond });\n }\n const touches = (m: ManifestRef, page: Page): boolean =>\n [...page.intents.values()].some((i) => (i.kind === \"in\" || i.kind === \"out\") && i.manifest === m);\n const manifests: RelocateManifestResult[] = model.manifests\n .filter(\n (m) =>\n m.created || m.keysAdded.length > 0 || m.keysRemoved.length > 0 || pages.some((p) => touches(m, p)),\n )\n .map((m) => {\n const keys = model.finalKeys(m);\n return {\n file: m.file,\n collection: m.collection,\n index: m.index,\n created: m.created,\n keysAdded: [...m.keysAdded],\n keysRemoved: [...m.keysRemoved],\n keys,\n undeclared: !m.implied && keys.length === 0 && !m.created,\n beyond: pages.filter(\n (p) =>\n p.beyond &&\n [...p.intents].some(\n ([k, i]) =>\n ((i.kind === \"in\" || i.kind === \"out\") && i.manifest === m) ||\n (i.kind === \"stay\" && (m.keysAdded.includes(k) || m.keysRemoved.includes(k))),\n ),\n ).length,\n };\n });\n return {\n dryRun,\n config: input.config,\n manifests,\n files,\n summary: {\n files: files.length,\n moved: files.reduce((n, f) => n + f.moved.length, 0),\n stayed: files.reduce((n, f) => n + f.stayed.length, 0),\n manifestsCreated: manifests.filter((m) => m.created).length,\n },\n };\n}\n\n// ---------------------------------------------------------------------------\n// Applying.\n// ---------------------------------------------------------------------------\n\n/**\n * Write a plan: manifests, then the config, then the pages, each atomically.\n * Afterwards the context's collections (the same objects the caller's run\n * holds) declare what the config now declares, a created collection is\n * appended to both lists, and a created config sets `configDir` and\n * `configPath`. Returns the report with each manifest line.\n *\n * The run is all or nothing, as far as the disk allows. A file that changed\n * since planning is refused before anything is written. A write that fails\n * puts every file already written back as planning found it, removing the\n * ones this run created, and the context is left untouched. Without that, a\n * value leaving a manifest could be in neither the manifest nor the page.\n *\n * Throws `DocmetaError` for a changed or unreadable file and for a failed\n * write, naming any file that could not be put back.\n */\nexport async function applyRelocation(\n ctx: RelocationContext,\n plan: RelocationPlan,\n io: RelocationIo = {},\n): Promise<RelocateResult> {\n // A per-page manifest (proposal 0058) may be the first file in its\n // directory. A page and the config already have theirs.\n const write = io.write ?? ((path: string, text: string) => writeFileAtomic(path, text, { createParents: true }));\n const remove = io.remove ?? ((path: string) => unlink(path));\n const label = (w: RelocationWrite): string =>\n w.kind === \"config\" ? configSource(w.path, ctx.cwd) : reported(w.path, ctx.base);\n\n for (const w of plan.writes) {\n let now: string | null;\n try {\n now = await readFile(w.path, \"utf8\");\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== \"ENOENT\") {\n throw new DocmetaError(`${label(w)} could not be read: ${errorMessage(err)}`);\n }\n now = null;\n }\n if (now !== w.before) {\n throw new DocmetaError(\n `${label(w)} changed after the relocation was planned, so nothing was written. Run the command again.`,\n );\n }\n }\n\n // Put back what `done` wrote, last first, and word the error the run throws.\n const rollBack = async (done: RelocationWrite[], head: string): Promise<DocmetaError> => {\n const failed: { file: string; reason: string }[] = [];\n for (const w of [...done].reverse()) {\n try {\n if (w.before === null) await remove(w.path);\n else await write(w.path, w.before);\n } catch (err) {\n failed.push({ file: label(w), reason: errorMessage(err) });\n }\n }\n const [first] = failed;\n if (first === undefined) {\n if (done.length === 0) return new DocmetaError(`${head} Nothing was changed.`);\n const files = done.length === 1 ? \"the file already written was\" : `the ${String(done.length)} files already written were`;\n return new DocmetaError(`${head} Nothing was changed: ${files} restored.`);\n }\n const one = failed.length === 1;\n return new DocmetaError(\n `${head} The run was rolled back, but ${list(failed.map((f) => f.file))} could not be restored: ${first.reason}. Restore ${one ? \"it\" : \"them\"} from version control.`,\n );\n };\n\n const written: RelocationWrite[] = [];\n for (const w of plan.writes) {\n try {\n await write(w.path, w.text);\n } catch (err) {\n throw await rollBack(written, `Could not write ${label(w)}: ${errorMessage(err)}.`);\n }\n written.push(w);\n }\n\n if (plan.writes.some((w) => w.kind === \"config\")) {\n const narrowed = ctx.collections.length < ctx.declaredCollections.length;\n for (const next of plan.collections) {\n const have = ctx.declaredCollections.find((c) => c.name === next.name);\n if (have !== undefined) {\n have.paths = next.paths;\n have.externalMetadata = next.externalMetadata;\n continue;\n }\n ctx.declaredCollections.push(next);\n if (!narrowed) ctx.collections.push(next);\n }\n ctx.configDir ??= plan.configDir;\n ctx.configPath ??= plan.configPath;\n }\n return {\n ...plan.result,\n dryRun: false,\n files: plan.result.files.map((f) => ({\n ...f,\n moved: f.moved.map((mv) => {\n if (mv.to !== \"manifest\") return mv;\n const line = plan.lines.get(lineId(f.file, mv.manifest, mv.key));\n return line === undefined ? mv : { ...mv, line };\n }),\n })),\n };\n}\n\n// ---------------------------------------------------------------------------\n// Offers: what the writers' (P1) and validate's (P2) prompts say.\n// ---------------------------------------------------------------------------\n\n/** One collection's share of a plan, as a prompt words it. */\nexport interface RelocationOffer {\n collection: string;\n /** The collection is created, with these paths (§3 case 2). */\n createsCollection?: { paths: string[] };\n /** Run targets appended to the collection's `paths:` (§3 case 3). */\n pathsAdded: string[];\n /** The config file the changes go to, as the run names it. */\n config: string | undefined;\n manifests: { file: string; created: boolean; keysAdded: string[]; keysRemoved: string[] }[];\n /** Keys leaving pages for a manifest, and how many values and pages that is. */\n keysOut: string[];\n valuesOut: number;\n pagesOut: number;\n /** Values leaving a manifest for pages, and which manifests give them up. */\n valuesIn: number;\n manifestsIn: string[];\n}\n\nfunction buildOffers(model: Model, pages: Page[], result: RelocateResult, config: string | undefined): RelocationOffer[] {\n const names = dedupe(result.manifests.map((m) => m.collection));\n return names.map((name) => {\n const manifests = result.manifests.filter((m) => m.collection === name);\n const outs = pages.flatMap((p) =>\n [...p.intents].filter(([, i]) => i.kind === \"out\" && i.manifest.collection === name).map(([k]) => ({ page: p.label, key: k })),\n );\n const ins = pages.flatMap((p) =>\n [...p.intents]\n .filter(([, i]) => i.kind === \"in\" && i.manifest.collection === name)\n .map(([, i]) => (i.kind === \"in\" ? i.manifest.file : \"\")),\n );\n const created = model.created.find((c) => c.name === name);\n return {\n collection: name,\n ...(created !== undefined ? { createsCollection: { paths: [...created.paths] } } : {}),\n pathsAdded: model.pathsAdded.filter((p) => p.collection === name).map((p) => p.path),\n config,\n manifests: manifests.map((m) => ({\n file: m.file,\n created: m.created,\n keysAdded: [...m.keysAdded],\n keysRemoved: [...m.keysRemoved],\n })),\n keysOut: dedupe(manifests.flatMap((m) => m.keysAdded)),\n valuesOut: outs.length,\n pagesOut: new Set(outs.map((o) => o.page)).size,\n valuesIn: ins.length,\n manifestsIn: dedupe(ins),\n };\n });\n}\n\nconst count = (n: number, noun: string): string => `${n} ${noun}${n === 1 ? \"\" : \"s\"}`;\nconst list = (xs: readonly string[]): string => xs.join(\", \");\n\n/**\n * The two lines a prompt puts for one offer: `notice` is a diagnostic (the\n * caller adds the `manni: ` prefix) and `question` goes to `Confirm`, which\n * appends `[y/N] `.\n *\n * `write` is P1, asked by `derive`, `fill` and `query` before a value that\n * prefers external metadata is written. `validate` is P2, asked after the\n * report.\n */\nexport function offerPrompt(offer: RelocationOffer, kind: \"write\" | \"validate\"): { notice: string; question: string } {\n const config = offer.config ?? FAMILY_CONFIG_NAMES[0] ?? \"manni.config.yaml\";\n if (kind === \"validate\") {\n const parts: string[] = [];\n if (offer.valuesOut > 0) {\n parts.push(\n `${count(offer.valuesOut, \"value\")} in ${count(offer.pagesOut, \"page\")} ${offer.valuesOut === 1 ? \"prefers\" : \"prefer\"} external metadata`,\n );\n }\n if (offer.valuesIn > 0) {\n parts.push(\n `${count(offer.valuesIn, \"value\")} in ${list(offer.manifestsIn)} ${offer.valuesIn === 1 ? \"prefers\" : \"prefer\"} the page`,\n );\n }\n const changes: string[] = [];\n if (offer.createsCollection !== undefined) {\n changes.push(`create collection ${offer.collection} (paths: ${list(offer.createsCollection.paths)})`);\n }\n for (const p of offer.pathsAdded) changes.push(`add ${p} to collection ${offer.collection}'s paths`);\n for (const m of offer.manifests) {\n if (m.created) changes.push(`create ${m.file}`);\n if (m.keysRemoved.length > 0) changes.push(`remove ${list(m.keysRemoved)} from ${m.file}'s keys`);\n if (!m.created && m.keysAdded.length > 0) changes.push(`add ${list(m.keysAdded)} to ${m.file}'s keys`);\n }\n return {\n notice: `in collection ${offer.collection}, ${parts.join(\" and \")}.`,\n question: changes.length === 0 ? \"Move them? \" : `Move them (${changes.join(\", \")})? `,\n };\n }\n const keys = list(offer.keysOut);\n const prefer = offer.keysOut.length === 1 ? \"which the schema prefers\" : \"which their schemas prefer\";\n const move = offer.pagesOut > 0 ? `move them out of ${count(offer.pagesOut, \"page\")}` : undefined;\n const tail = (steps: string[]): string => {\n const all = move === undefined ? steps : [...steps, move];\n if (all.length === 1) return `${capital(all[0] ?? \"\")}? `;\n if (all.length === 2) return `${capital(all[0] ?? \"\")} and ${all[1] ?? \"\"}? `;\n return `${capital(all.slice(0, -1).join(\", \"))}, and ${all.at(-1) ?? \"\"}? `;\n };\n const created = offer.manifests.find((m) => m.created);\n if (offer.createsCollection !== undefined) {\n const make = `Create collection ${offer.collection} (paths: ${list(offer.createsCollection.paths)}), with ${created?.file ?? `${offer.collection}.metadata.yaml`}, in ${config}`;\n return {\n notice: `no collection has a manifest for ${keys}, ${prefer} in external metadata.`,\n question: move === undefined ? `${make}? ` : `${make}, and ${move}? `,\n };\n }\n const steps: string[] = offer.pathsAdded.map((p) => `add ${p} to collection ${offer.collection}'s paths`);\n if (created !== undefined) steps.push(`create ${created.file}`, `add it to ${config}`);\n for (const m of offer.manifests) {\n if (!m.created && m.keysAdded.length > 0) steps.push(`add ${list(m.keysAdded)} to ${m.file}'s keys`);\n }\n return {\n notice: `collection ${offer.collection} has no manifest for ${keys}, ${prefer} in external metadata.`,\n question: tail(steps),\n };\n}\n\nfunction capital(s: string): string {\n return s.charAt(0).toUpperCase() + s.slice(1);\n}\n\n/** The plan's offers, one per collection whose manifests the plan changes. */\nexport function relocationOffers(plan: RelocationPlan): RelocationOffer[] {\n return plan.offers;\n}\n","/**\n * The manifest splice writer: rewrite one owned value for one document entry\n * of an external-metadata manifest (proposal 0037), and change no other byte.\n *\n * `manni cite` keeps a page's `citations` in a manifest and is the first\n * writer of one. Since proposal 0047, `meta query` routes a write to an\n * owned key here too, and `renameManifestEntry` follows a `_path` move. It is text in, text out: the caller reads and writes the\n * file.\n *\n * The design is the one `frontmatter-write.ts` uses for TOML. The document is\n * parsed once for its node ranges, and exactly one range of the original text\n * is replaced. So everything outside that range survives by construction\n * rather than by careful re-emission: comments, key order, quoting, blank\n * lines, and the line endings. The primitives live in `yaml-splice.ts`,\n * which the frontmatter writer shares. Three edits are possible:\n *\n * - **Replace.** The key is present in the entry. Its value's text is\n * replaced by the new value as block YAML at the key's indentation.\n * Comments inside the old value go with it, since they described it. A\n * comment on the key's own line stays.\n * - **Insert.** The entry is present and the key is not. The key is added\n * after the entry's last line, at the indentation of its other keys.\n * - **Append.** The entry is absent. It is added after the last entry, keyed\n * by path, or by the join value when the manifest joins on a field (0039),\n * and spaced from the one before it the way the others are.\n *\n * Every result is read back before it is returned, and the entry's key must\n * deep-equal the value while every other value is unchanged. A serializer\n * bug, or a value YAML cannot hold, is then a refusal rather than a damaged\n * manifest.\n */\nimport { posix } from \"node:path\";\nimport {\n LineCounter,\n isMap,\n isNode,\n isScalar,\n parseDocument,\n stringify,\n type Document,\n type Pair,\n type YAMLMap,\n} from \"yaml\";\nimport { DocmetaError } from \"../types.js\";\nimport { deepEqual } from \"../extractors/patch-util.js\";\nimport { FILE_SCHEMA_KEY } from \"./resolve-schema.js\";\nimport { PATH_JOIN } from \"./external-metadata.js\";\nimport {\n blockLines,\n colOf,\n colonEnd,\n contentEnd,\n detectEol,\n detectStyle,\n emptySource,\n insertKey,\n keyLines,\n keyString,\n lineEnd,\n rangeOf,\n replaceBlockValue,\n replaceFlowValue,\n type Edit,\n type Style,\n} from \"./yaml-splice.js\";\n\nexport interface SpliceManifestOptions {\n /**\n * The document entry: its path relative to the config's directory, or its\n * value of the join field when `join` names one. A path entry matches\n * however the manifest spells it (`./docs/a.md` is `docs/a.md`); a join\n * value matches exactly.\n */\n entry: string;\n /** The owned key to write. */\n key: string;\n /** The value to write. Mappings and lists are written in block style. */\n value: unknown;\n /** `path` (the default) or the frontmatter field the manifest joins on. */\n join?: string;\n /** The manifest as the run reports it, for error messages. */\n file?: string;\n}\n\nexport interface SplicedManifest {\n /** The whole manifest, with the one value rewritten. */\n text: string;\n /** 1-based line where the written value now starts. */\n line: number;\n}\n\n/**\n * Rewrite `options.key` of `options.entry` in the manifest `text` to\n * `options.value`, and return the new text and the line the value starts on.\n *\n * Throws `DocmetaError`, and never returns a partial result, when:\n * - the text is not valid YAML, or its top level is not a mapping;\n * - the entry is named twice, or is not a mapping;\n * - the key is set twice in the entry, or is `$schema`;\n * - the value is `undefined`;\n * - the key or entry is absent and would go into a flow mapping that has\n * members (`{ jira: A }`), which this writer does not add to;\n * - the key is written as an explicit `? key`;\n * - the result does not read back as written.\n */\nexport function spliceManifestValue(\n text: string,\n options: SpliceManifestOptions,\n): SplicedManifest {\n const { entry, key, value, file } = options;\n const join = options.join ?? PATH_JOIN;\n const at = (line?: number): string => {\n const name = file === undefined ? \"Manifest\" : `Manifest ${file}`;\n if (line === undefined) return name;\n return file === undefined ? `${name} line ${String(line)}` : `${name}:${String(line)}`;\n };\n\n if (key === FILE_SCHEMA_KEY) {\n throw new DocmetaError(\n `${at()}: refusing to write \"${FILE_SCHEMA_KEY}\" for \"${entry}\"; a manifest never chooses the schema a document is judged by. Use \"overrides\" in the config.`,\n );\n }\n if (value === undefined) {\n throw new DocmetaError(`${at()}: refusing to write \"${key}\" for \"${entry}\" with no value.`);\n }\n\n const eol = detectEol(text);\n const lc = new LineCounter();\n const doc = parseDocument(text, { lineCounter: lc, uniqueKeys: false });\n const problem = doc.errors[0];\n if (problem) {\n throw new DocmetaError(`${at()} is not valid YAML: ${problem.message}`);\n }\n const keyLine = (node: unknown): number | undefined => {\n const r = rangeOf(node);\n return r ? lc.linePos(r[0]).line : undefined;\n };\n const same =\n join === PATH_JOIN\n ? (a: string, b: string) => posix.normalize(a) === posix.normalize(b)\n : (a: string, b: string) => a === b;\n\n const root = doc.contents;\n let spelled = entry;\n let edit: Edit;\n if (root === null || (isScalar(root) && root.value === null && emptySource(text, root))) {\n edit = startManifest(text, entry, key, value, eol);\n } else if (!isMap(root)) {\n throw new DocmetaError(\n `${at()}: the manifest must be a mapping from document ${join === PATH_JOIN ? \"path\" : `\"${join}\"`} to owned keys.`,\n );\n } else {\n const style = detectStyle(text, root, eol);\n const matches = root.items.filter((p) => same(keyString(p.key), entry));\n const [first, second] = matches;\n if (first && second) {\n throw new DocmetaError(\n `${at(keyLine(second.key))}: \"${keyString(second.key)}\" is named twice (first at line ${String(keyLine(first.key) ?? \"?\")}). Merge the two entries into one.`,\n );\n }\n if (first === undefined) {\n if (root.flow === true && root.items.length > 0) {\n throw new DocmetaError(\n `${at()}: the manifest is a flow mapping ({ … }), which this writer does not add entries to. Rewrite it in block style.`,\n );\n }\n edit = appendEntry(text, root, entry, key, value, style);\n } else {\n spelled = keyString(first.key);\n const where = at(keyLine(first.key));\n const v = first.value;\n if (!isMap(v)) {\n throw new DocmetaError(`${where}: \"${spelled}\" must be a mapping of owned keys to values.`);\n }\n const hits = v.items.filter((kv) => keyString(kv.key) === key);\n const [hit, again] = hits;\n if (hit && again) {\n throw new DocmetaError(\n `${at(keyLine(again.key))}: \"${spelled}\" sets \"${key}\" twice (first at line ${String(keyLine(hit.key) ?? \"?\")}). Remove one.`,\n );\n }\n const flowRefusal = () =>\n new DocmetaError(\n `${where}: \"${spelled}\" is a flow mapping ({ … }), which this writer does not add keys to. Rewrite the entry in block style.`,\n );\n const formRefusal = () =>\n new DocmetaError(\n `${where}: \"${spelled}\" writes a key in a form this writer does not edit. Write it as \"${key}: …\".`,\n );\n // Each of these answers `undefined` for a shape it will not edit: a\n // flow mapping with members, or a key written as an explicit `? key`.\n let made: Edit | undefined;\n if (v.flow === true) {\n if (hit) made = replaceFlowValue(text, hit, value);\n else if (v.items.length === 0) made = fillEmptyEntry(text, first, key, value, style);\n else throw flowRefusal();\n if (!made) throw hit ? flowRefusal() : formRefusal();\n } else {\n made = hit\n ? replaceBlockValue(text, hit, value, style)\n : insertKey(text, v, key, value, style);\n if (!made) throw formRefusal();\n }\n edit = made;\n }\n }\n\n const out = text.slice(0, edit.start) + edit.insert + text.slice(edit.end);\n const line = readBack(doc, out, spelled, key, value, (why) =>\n new DocmetaError(\n `${at()}: writing \"${key}\" for \"${entry}\" did not read back as written, so nothing was written. ${why}`,\n ),\n );\n return { text: out, line };\n}\n\n/**\n * The value one document entry holds for one owned key, as the manifest text\n * stands. `undefined` when the entry or the key is absent, and for text that\n * is not a manifest at all.\n *\n * A writer that re-reads its target before replacing it needs this: it tells\n * the writer whether the entry it is about to rewrite is the one it read, or\n * one another process has changed since. Every refusal a malformed manifest\n * deserves is the splice's to raise, so this answers `undefined` rather than\n * throwing, and two `undefined`s compare equal.\n */\nexport function readManifestValue(\n text: string,\n options: { entry: string; key: string; join?: string },\n): unknown {\n const join = options.join ?? PATH_JOIN;\n const doc = parseDocument(text, { uniqueKeys: false });\n if (doc.errors.length > 0) return undefined;\n const root = doc.contents;\n if (!isMap(root)) return undefined;\n const same =\n join === PATH_JOIN\n ? (a: string, b: string) => posix.normalize(a) === posix.normalize(b)\n : (a: string, b: string) => a === b;\n const pair = root.items.find((p) => same(keyString(p.key), options.entry));\n const held = pair?.value;\n if (!isMap(held)) return undefined;\n const kv = held.items.find((p) => keyString(p.key) === options.key);\n const node = kv?.value;\n return isNode(node) ? (node.toJSON() as unknown) : undefined;\n}\n\n/**\n * Remove `options.key` from `options.entry` in the manifest `text`, and change\n * no other byte. An entry left with no keys goes too, since the loader refuses\n * an entry that is not a mapping, along with the blank line that spaced it.\n * A manifest, entry or key that is absent is left as it was.\n *\n * Throws `DocmetaError` where `spliceManifestValue` would: invalid YAML, a top\n * level or entry that is not a mapping, an entry named twice, a key set twice.\n * It also refuses a key in a flow mapping with other members, and a result\n * that does not read back with only that key gone.\n */\nexport function removeManifestKey(\n text: string,\n options: Omit<SpliceManifestOptions, \"value\">,\n): { text: string } {\n const { entry, key, file } = options;\n const join = options.join ?? PATH_JOIN;\n const at = (line?: number): string => {\n const name = file === undefined ? \"Manifest\" : `Manifest ${file}`;\n if (line === undefined) return name;\n return file === undefined ? `${name} line ${String(line)}` : `${name}:${String(line)}`;\n };\n\n const eol = detectEol(text);\n const lc = new LineCounter();\n const doc = parseDocument(text, { lineCounter: lc, uniqueKeys: false });\n const problem = doc.errors[0];\n if (problem) {\n throw new DocmetaError(`${at()} is not valid YAML: ${problem.message}`);\n }\n const keyLine = (node: unknown): number | undefined => {\n const r = rangeOf(node);\n return r ? lc.linePos(r[0]).line : undefined;\n };\n const root = doc.contents;\n if (root === null || (isScalar(root) && root.value === null)) return { text };\n if (!isMap(root)) {\n throw new DocmetaError(\n `${at()}: the manifest must be a mapping from document ${join === PATH_JOIN ? \"path\" : `\"${join}\"`} to owned keys.`,\n );\n }\n const same =\n join === PATH_JOIN\n ? (a: string, b: string) => posix.normalize(a) === posix.normalize(b)\n : (a: string, b: string) => a === b;\n const matches = root.items.filter((p) => same(keyString(p.key), entry));\n const [first, second] = matches;\n if (first && second) {\n throw new DocmetaError(\n `${at(keyLine(second.key))}: \"${keyString(second.key)}\" is named twice (first at line ${String(keyLine(first.key) ?? \"?\")}). Merge the two entries into one.`,\n );\n }\n if (first === undefined) return { text };\n const spelled = keyString(first.key);\n const where = at(keyLine(first.key));\n const v = first.value;\n if (!isMap(v)) {\n throw new DocmetaError(`${where}: \"${spelled}\" must be a mapping of owned keys to values.`);\n }\n const hits = v.items.filter((kv) => keyString(kv.key) === key);\n const [hit, again] = hits;\n if (hit && again) {\n throw new DocmetaError(\n `${at(keyLine(again.key))}: \"${spelled}\" sets \"${key}\" twice (first at line ${String(keyLine(hit.key) ?? \"?\")}). Remove one.`,\n );\n }\n if (hit === undefined) return { text };\n\n const whole = v.items.length === 1;\n if (!whole && v.flow === true) {\n throw new DocmetaError(\n `${where}: \"${spelled}\" is a flow mapping ({ … }), which this writer does not remove keys from. Rewrite the entry in block style.`,\n );\n }\n // The lines to cut: from the start of the key's line (the entry's, when\n // the entry goes) through the line break after the value's last line.\n const from = rangeOf(whole ? first.key : hit.key);\n const to = whole ? contentEnd(text, v) : (contentEnd(text, hit.value) ?? contentEnd(text, hit.key));\n if (!from || to === undefined) {\n throw new DocmetaError(\n `${where}: \"${spelled}\" writes a key in a form this writer does not edit. Write it as \"${key}: …\".`,\n );\n }\n let { start, end } = keyLines(text, from[0], to, eol);\n if (whole) {\n // The blank line that spaced the entry from the one before goes with it;\n // for a first entry, the one after it does.\n if (text.slice(start - 2 * eol.length, start) === eol + eol) start -= eol.length;\n else if (start === 0 && text.startsWith(eol, end)) end += eol.length;\n }\n const out = text.slice(0, start) + text.slice(end);\n\n const after = parseDocument(out, { uniqueKeys: false });\n const fail = (why: string) =>\n new DocmetaError(\n `${at()}: removing \"${key}\" for \"${entry}\" did not read back as removed, so nothing was written. ${why}`,\n );\n if (after.errors[0]) throw fail(`The result is not valid YAML: ${after.errors[0].message}`);\n const was: unknown = doc.toJS({ maxAliasCount: 100 });\n const wasRoot = isRecord(was) ? was : {};\n const wasEntry = wasRoot[spelled];\n const rest = Object.fromEntries(\n Object.entries(isRecord(wasEntry) ? wasEntry : {}).filter(([k]) => k !== key),\n );\n const kept = Object.entries(wasRoot).filter(([k]) => k !== spelled);\n if (Object.keys(rest).length > 0) kept.push([spelled, rest]);\n const now: unknown = after.toJS({ maxAliasCount: 100 });\n const expected = kept.length === 0 ? null : Object.fromEntries(kept);\n if (!deepEqual(now ?? null, expected)) throw fail(\"Another value in the manifest would have changed.\");\n return { text: out };\n}\n\n/**\n * Rename the document entry `options.entry` to `options.to` in the manifest\n * `text`, and change no other byte: only the entry's key is replaced, so its\n * values, comments and position stay. `meta query` uses it when a `_path`\n * move renames a document a path-joined manifest names (proposal 0047). A\n * manifest or entry that is absent is left as it was.\n *\n * Throws `DocmetaError` where `spliceManifestValue` would (invalid YAML, a top\n * level that is not a mapping, an entry named twice), when `to` already has\n * an entry, for a key written as an explicit `? key`, and for a result that\n * does not read back with only the entry's name changed.\n */\nexport function renameManifestEntry(\n text: string,\n options: { entry: string; to: string; join?: string; file?: string },\n): { text: string } {\n const { entry, to, file } = options;\n const join = options.join ?? PATH_JOIN;\n const at = (line?: number): string => {\n const name = file === undefined ? \"Manifest\" : `Manifest ${file}`;\n if (line === undefined) return name;\n return file === undefined ? `${name} line ${String(line)}` : `${name}:${String(line)}`;\n };\n const lc = new LineCounter();\n const doc = parseDocument(text, { lineCounter: lc, uniqueKeys: false });\n const problem = doc.errors[0];\n if (problem) {\n throw new DocmetaError(`${at()} is not valid YAML: ${problem.message}`);\n }\n const keyLine = (node: unknown): number | undefined => {\n const r = rangeOf(node);\n return r ? lc.linePos(r[0]).line : undefined;\n };\n const root = doc.contents;\n if (root === null || (isScalar(root) && root.value === null)) return { text };\n if (!isMap(root)) {\n throw new DocmetaError(\n `${at()}: the manifest must be a mapping from document ${join === PATH_JOIN ? \"path\" : `\"${join}\"`} to owned keys.`,\n );\n }\n const same =\n join === PATH_JOIN\n ? (a: string, b: string) => posix.normalize(a) === posix.normalize(b)\n : (a: string, b: string) => a === b;\n const [first, second] = root.items.filter((p) => same(keyString(p.key), entry));\n if (first && second) {\n throw new DocmetaError(\n `${at(keyLine(second.key))}: \"${keyString(second.key)}\" is named twice (first at line ${String(keyLine(first.key) ?? \"?\")}). Merge the two entries into one.`,\n );\n }\n if (first === undefined) return { text };\n const taken = root.items.find((p) => same(keyString(p.key), to));\n if (taken !== undefined) {\n throw new DocmetaError(\n `${at(keyLine(taken.key))}: \"${keyString(taken.key)}\" already has an entry, so \"${keyString(first.key)}\" cannot be renamed to it. Merge the two entries into one.`,\n );\n }\n const spelled = keyString(first.key);\n const r = rangeOf(first.key);\n const end = contentEnd(text, first.key);\n if (!r || end === undefined || colonEnd(text, first) === undefined) {\n throw new DocmetaError(\n `${at(keyLine(first.key))}: \"${spelled}\" is written in a form this writer does not edit. Write it as \"${spelled}: …\".`,\n );\n }\n const quoted = isScalar(first.key) && (first.key.type === \"QUOTE_DOUBLE\" || first.key.type === \"QUOTE_SINGLE\");\n const plain = stringify(to, { lineWidth: 0 }).replace(/\\n$/, \"\");\n const insert = quoted || plain.includes(\"\\n\") ? JSON.stringify(to) : plain;\n const out = text.slice(0, r[0]) + insert + text.slice(end);\n\n const after = parseDocument(out, { uniqueKeys: false });\n const fail = (why: string) =>\n new DocmetaError(\n `${at()}: renaming \"${spelled}\" to \"${to}\" did not read back as renamed, so nothing was written. ${why}`,\n );\n if (after.errors[0]) throw fail(`The result is not valid YAML: ${after.errors[0].message}`);\n const was: unknown = doc.toJS({ maxAliasCount: 100 });\n const wasRoot = isRecord(was) ? was : {};\n const expected = Object.fromEntries(\n Object.entries(wasRoot).map(([k, v]) => [k === spelled ? to : k, v]),\n );\n const now: unknown = after.toJS({ maxAliasCount: 100 });\n if (!deepEqual(now, expected)) throw fail(\"Another value in the manifest would have changed.\");\n return { text: out };\n}\n\n/** An empty manifest (no text, only comments, or a bare `---`): the first entry. */\nfunction startManifest(text: string, entry: string, key: string, value: unknown, eol: string): Edit {\n const style: Style = { step: 2, indentSeq: true, eol };\n const block = blockLines({ [entry]: { [key]: value } }, 0, style);\n let insert: string;\n if (text === \"\" || text.endsWith(\"\\n\")) insert = block + eol;\n else insert = eol + block;\n return { start: text.length, end: text.length, insert };\n}\n\n/** A new entry after the last one, or in place of an empty `{}` manifest. */\nfunction appendEntry(\n text: string,\n root: YAMLMap,\n entry: string,\n key: string,\n value: unknown,\n style: Style,\n): Edit {\n const body = { [entry]: { [key]: value } };\n if (root.flow === true) {\n // `{}` and nothing else: the refusal for a flow mapping with members ran first.\n const r = rangeOf(root);\n const start = r ? r[0] : text.length;\n const end = contentEnd(text, root) ?? start;\n return { start, end, insert: blockLines(body, colOf(text, start), style) };\n }\n const firstKey = rangeOf(root.items[0]?.key);\n const col = firstKey ? colOf(text, firstKey[0]) : 0;\n const pos = lineEnd(text, contentEnd(text, root) ?? text.length);\n const last = root.items.at(-1);\n const spaced =\n root.items.length > 1 && isNode(last?.key) && last.key.spaceBefore === true;\n return {\n start: pos,\n end: pos,\n insert: style.eol + (spaced ? style.eol : \"\") + blockLines(body, col, style),\n };\n}\n\n/** `docs/a.md: {}`: the empty flow mapping becomes a block one holding the key. */\nfunction fillEmptyEntry(\n text: string,\n entryPair: Pair,\n key: string,\n value: unknown,\n style: Style,\n): Edit | undefined {\n const start = colonEnd(text, entryPair);\n const keyRange = rangeOf(entryPair.key);\n const end = contentEnd(text, entryPair.value);\n if (start === undefined || !keyRange || end === undefined) return undefined;\n const col = colOf(text, keyRange[0]) + style.step;\n return { start, end, insert: style.eol + blockLines({ [key]: value }, col, style) };\n}\n\n/**\n * Re-parse `out` and check it says what was asked: the entry's key deep-equals\n * `value`, and every other value is what it was. Returns the value's line.\n */\nfunction readBack(\n before: Document,\n out: string,\n spelled: string,\n key: string,\n value: unknown,\n fail: (why: string) => DocmetaError,\n): number {\n const lc = new LineCounter();\n const after = parseDocument(out, { lineCounter: lc, uniqueKeys: false });\n const problem = after.errors[0];\n if (problem) throw fail(`The result is not valid YAML: ${problem.message}`);\n\n const was: unknown = before.toJS({ maxAliasCount: 100 });\n const now: unknown = after.toJS({ maxAliasCount: 100 });\n const wasRoot = isRecord(was) ? was : {};\n const wasEntry = wasRoot[spelled];\n const expected = {\n ...wasRoot,\n [spelled]: { ...(isRecord(wasEntry) ? wasEntry : {}), [key]: value },\n };\n const nowEntry = isRecord(now) ? now[spelled] : undefined;\n if (!isRecord(nowEntry) || !deepEqual(nowEntry[key], value)) {\n throw fail(\n \"The value reads back differently. A Date, an undefined member, or another value YAML cannot hold does not survive the trip.\",\n );\n }\n if (!deepEqual(now, expected)) {\n throw fail(\"Another value in the manifest would have changed.\");\n }\n\n const root = after.contents;\n const pair = isMap(root) ? root.items.find((p) => keyString(p.key) === spelled) : undefined;\n const entryMap = pair?.value;\n const kv = isMap(entryMap) ? entryMap.items.find((p) => keyString(p.key) === key) : undefined;\n const r = rangeOf(kv?.value) ?? rangeOf(kv?.key);\n if (!r) throw fail(\"The written value could not be found again.\");\n return lc.linePos(r[0]).line;\n}\n\nfunction isRecord(x: unknown): x is Record<string, unknown> {\n return typeof x === \"object\" && x !== null && !Array.isArray(x);\n}\n","/**\n * The pin engine: refer to content by its lines and a hash of them, and find\n * those lines again when they move. cite pins a citation's two ends with it,\n * and meta pins the fields a document derives; neither owns it.\n *\n * The hashing rule, stated once (proposal 0044 § The vocabulary):\n * UTF-8; strip one leading BOM; CRLF → LF; split on LF; drop the empty element\n * a trailing LF leaves; take lines L1..L2 inclusive (1-based); join with LF; no\n * trailing LF; trailing whitespace kept. Plain: `sha256-` and sha256(text).\n * Keyed (an encrypted value): `hmac-sha256-` and the family's keyed pin,\n * HMAC-SHA256 under a key derived from the encryption key (proposal 0045).\n */\n// Straight to the module rather than meta's barrel: shared code sits under\n// every tool, and `integrity.ts` depends on nothing but node:crypto.\nimport { integrityOf } from \"../meta/core/integrity.js\";\nimport { KEYED_PIN_PREFIX, keyedPin } from \"./encryption.js\";\nimport { ToolError } from \"./errors.js\";\nimport { STDIN_LINES_MARKER } from \"./run.js\";\n\n/**\n * A line range that runs past the end of the text, or ends before it starts.\n * Each tool rethrows it as its own error where its callers match on that.\n */\nexport class LineRangeError extends ToolError {\n constructor(message: string) {\n super(message);\n this.name = \"LineRangeError\";\n }\n}\n\n/** Lines as an entry writes them: an integer for one line, `\"L1-L2\"` for several. */\nexport type LineSpec = number | string;\n\n/** Page lines as an editor numbers them, 1-based and inclusive. */\nexport interface PageLines {\n start: number;\n end: number;\n}\n\n/** A 1-based inclusive range, either end optional: no `start` is the whole text, no `end` one line. */\nexport interface LineRange {\n start?: number;\n end?: number;\n}\n\n/** BOM stripped, CRLF folded to LF. */\nexport function normalizeText(text: string): string {\n const body = text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;\n return body.replace(/\\r\\n/g, \"\\n\");\n}\n\n/** The normalized lines, without the empty element a trailing LF leaves. */\nexport function splitLines(text: string): string[] {\n const parts = normalizeText(text).split(\"\\n\");\n if (parts.length > 0 && parts[parts.length - 1] === \"\") parts.pop();\n return parts;\n}\n\n/**\n * The lines of a range joined by LF. Throws `LineRangeError` when the range\n * runs past the end of the text (`<label> has N lines; line M is out of range.`).\n */\nexport function sliceLines(lines: readonly string[], range?: LineRange, label?: string): string {\n const start = range?.start;\n if (start === undefined) return lines.join(\"\\n\");\n const end = range?.end ?? start;\n if (end < start) {\n // Both bounds can be in range, so without this a reversed range sliced\n // nothing and hashed as the pin of an empty span.\n throw new LineRangeError(`${label ?? \"the source\"} range ${String(start)}-${String(end)} ends before it starts.`);\n }\n if (start > lines.length || end > lines.length) {\n const first = start > lines.length ? start : end;\n throw new LineRangeError(`${label ?? \"the source\"} has ${lines.length} lines; line ${first} is out of range.`);\n }\n return lines.slice(start - 1, end).join(\"\\n\");\n}\n\n/** The pin of a range of `text`: plain, or the keyed pin under `key` when one is given. */\nexport function hashRange(text: string, range?: LineRange, key?: string): string {\n return hashLines(sliceLines(splitLines(text), range), key);\n}\n\n/**\n * The pin of already-joined lines: `sha256-<hex>`, or with `key` the\n * `hmac-sha256-<hex>` keyed pin an encrypted value carries. A plain pin\n * passes `undefined`.\n */\nexport function hashLines(joined: string, key?: string): string {\n return key === undefined ? integrityOf(Buffer.from(joined, \"utf8\")) : keyedPin(joined, key);\n}\n\n/** Whether a pin is keyed (`hmac-sha256-`), the form an encrypted value carries. */\nexport function isKeyedPin(pin: string): boolean {\n return pin.startsWith(KEYED_PIN_PREFIX);\n}\n\n/** The plain pin of a range of lines; undefined when the range falls outside them or ends before it starts. */\nexport function pinOfLines(lines: readonly string[], range: PageLines): string | undefined {\n if (range.start < 1 || range.end > lines.length || range.end < range.start) return undefined;\n return hashLines(lines.slice(range.start - 1, range.end).join(\"\\n\"));\n}\n\n/** Half-width of the band around the original position the blind move search tries first. */\nexport const MOVE_WINDOW_LINES = 2000;\n/** Default hashing budget for the blind move search, in bytes. */\nexport const MOVE_BUDGET_BYTES = 64 * 1024 * 1024;\n/** The widest range an entry may name, at either end: a wider one is refused. */\nexport const MAX_RANGE_LINES = 5000;\n\n/**\n * Bytes left to spend on settling one pin. Every search that classifies the\n * same end shares one of these, so the cap is the cost of settling that pin\n * rather than the cost of each search in turn (proposal 0055 § the budget).\n */\nexport interface SearchBudget {\n left: number;\n}\n\nexport interface FindWindowsOptions {\n /** The 1-based start line the range was pinned at: the blind search begins around it. */\n around?: number;\n /** The pinned lines as they were, when known: enables the first-line filter. */\n original?: readonly string[];\n /** Hashing budget for the blind search, in bytes. Default `MOVE_BUDGET_BYTES`. */\n budget?: number;\n /** A budget shared with the other searches settling this pin. Wins over `budget`. */\n counter?: SearchBudget;\n}\n\n/**\n * Pure move search over normalized lines: the 1-based start lines where a\n * window of `length` lines hashes to `pin`. `original` (the pinned lines as\n * they were, when known) enables the first-line filter. `key` keys the hash\n * for a keyed pin and is `undefined` for a plain one.\n */\nexport function findWindows(\n lines: readonly string[],\n length: number,\n pin: string,\n key: string | undefined,\n opts?: FindWindowsOptions,\n): { starts: number[]; truncated: boolean } {\n const starts: number[] = [];\n const lastStart = lines.length - length + 1;\n if (length < 1 || lastStart < 1) return { starts, truncated: false };\n\n const joined = (start: number): string => lines.slice(start - 1, start - 1 + length).join(\"\\n\");\n\n const original = opts?.original;\n if (original !== undefined) {\n const first = original[0];\n for (let start = 1; start <= lastStart; start++) {\n if (lines[start - 1] !== first) continue;\n let same = true;\n for (let i = 1; i < length; i++) {\n if (lines[start - 1 + i] !== original[i]) {\n same = false;\n break;\n }\n }\n if (same && hashLines(joined(start), key) === pin) starts.push(start);\n }\n return { starts, truncated: false };\n }\n\n // Blind: the band around the original position first, then the rest, so the\n // common small shift is found before the budget is anywhere near spent.\n const counter = opts?.counter;\n const budget = counter?.left ?? opts?.budget ?? MOVE_BUDGET_BYTES;\n const around = opts?.around ?? 1;\n const bandStart = Math.max(1, around - MOVE_WINDOW_LINES);\n const bandEnd = Math.min(lastStart, around + MOVE_WINDOW_LINES);\n const order: number[] = [];\n for (let start = bandStart; start <= bandEnd; start++) order.push(start);\n for (let start = 1; start < bandStart; start++) order.push(start);\n for (let start = bandEnd + 1; start <= lastStart; start++) order.push(start);\n\n let spent = 0;\n for (const start of order) {\n const text = joined(start);\n const bytes = Buffer.byteLength(text, \"utf8\");\n if (spent + bytes > budget) {\n if (counter !== undefined) counter.left = budget - spent;\n return { starts, truncated: true };\n }\n spent += bytes;\n if (hashLines(text, key) === pin) starts.push(start);\n }\n if (counter !== undefined) counter.left = budget - spent;\n return { starts, truncated: false };\n}\n\n/**\n * `\"L1-L2\"`, the only string form an entry may write, and `\"L\"`, which no\n * entry writes but every report spells (`spellLines`), so a spelling reads\n * back as the lines it names.\n */\nconst RANGE_SPEC = /^([1-9][0-9]*)(?:-([1-9][0-9]*))?$/;\n\n/**\n * The lines a `LineSpec` names. Undefined for a value that is neither a\n * positive integer nor `\"L1-L2\"` with `L1 <= L2`.\n */\nexport function parseLines(spec: LineSpec): PageLines | undefined {\n if (typeof spec === \"number\") {\n return Number.isInteger(spec) && spec >= 1 ? { start: spec, end: spec } : undefined;\n }\n const m = RANGE_SPEC.exec(spec);\n const startText = m?.[1];\n if (startText === undefined) return undefined;\n const start = Number(startText);\n const endText = m?.[2];\n const end = endText === undefined ? start : Number(endText);\n return end < start ? undefined : { start, end };\n}\n\n/** Lines as an entry writes them: the integer for one line, `\"L1-L2\"` otherwise. */\nexport function lineSpec(lines: PageLines): LineSpec {\n return lines.start === lines.end ? lines.start : `${String(lines.start)}-${String(lines.end)}`;\n}\n\n/** Lines as a report spells them: `\"9\"` or `\"9-12\"`. */\nexport function spellLines(lines: PageLines): string {\n return String(lineSpec(lines));\n}\n\n/** Body lines as file lines: body line 1 is the file line `bodyLine`, the first after the frontmatter. */\nexport function toFileLines(lines: PageLines, bodyLine: number): PageLines {\n return { start: bodyLine + lines.start - 1, end: bodyLine + lines.end - 1 };\n}\n\n/** File lines as body lines. */\nexport function toBodyLines(lines: PageLines, bodyLine: number): PageLines {\n return { start: lines.start - bodyLine + 1, end: lines.end - bodyLine + 1 };\n}\n\n/**\n * Split `docs/limits.md:9` or `docs/limits.md:14-18` into the page and its\n * lines. Only a trailing `:L` or `:L1-L2` is read as lines, so a path that\n * carries a colon keeps it, and `-:9` still reads the page from stdin. Throws\n * `LineRangeError` for an end line before the start.\n */\nexport function splitPageArgument(arg: string): { page: string; lines?: PageLines } {\n // `-:9` reaches commander as an operand only after the bin rewrites its\n // leading `-` to the marker (`run.ts`); both spellings name stdin, `-`, and\n // the same lines.\n const text = arg.startsWith(STDIN_LINES_MARKER) ? `-${arg.slice(STDIN_LINES_MARKER.length)}` : arg;\n const m = /:([1-9][0-9]*)(?:-([1-9][0-9]*))?$/.exec(text);\n const head = m === null ? text : text.slice(0, m.index);\n if (m === null || head === \"\") return { page: arg };\n const start = Number(m[1]);\n const end = m[2] === undefined ? start : Number(m[2]);\n if (end < start) {\n throw new LineRangeError(`Invalid range \"${arg}\": end line ${end} is before start line ${start}.`);\n }\n return { page: head, lines: { start, end } };\n}\n","/**\n * `provenance`, derived (proposal 0046 § The derivation contract): which body\n * lines a machine wrote, read from `git blame --line-porcelain` and the\n * commits it names, compared with the pins a page already carries.\n *\n * Pure functions over parsed inputs. Running blame, reading commit messages\n * and reading blobs at a commit is the git source's job (`git.ts`); nothing\n * here spawns a process or touches the filesystem.\n *\n * The reference implementation is `docs/proposals/0046/ladders/blame-examples.cjs`.\n * Every rule its `RESOLVED` notes decide is carried here, and the test suite\n * runs the ladder beside this module so the two cannot drift apart.\n *\n * Two numberings meet here. Entries store BODY lines, counted from the first\n * line after the frontmatter, so writing the stamp never moves its own pins.\n * Everything a person reads — a range on the command line, a report, a\n * finding — is FILE lines, and the conversion happens at that edge.\n */\nimport picomatch from \"picomatch\";\nimport { extractFrontmatter, locateFrontmatter } from \"../../extractors/frontmatter.js\";\nimport { DocmetaError, type FieldError } from \"../../types.js\";\nimport {\n LineRangeError,\n findWindows,\n lineSpec,\n parseLines,\n pinOfLines,\n spellLines,\n splitLines,\n splitPageArgument,\n toBodyLines,\n toFileLines,\n type LineSpec,\n type PageLines,\n} from \"../../../shared/pin.js\";\nimport { DERIVED_KEYWORD, DERIVED_STALE_SCHEMA } from \"./types.js\";\n\n/**\n * The sha blame reports for a line that is not committed yet, in a SHA-1\n * repository. A SHA-256 repository reports 64 zeros; `parseLinePorcelain`\n * reads any all-zero sha as uncommitted.\n */\nexport const ZERO_SHA = \"0000000000000000000000000000000000000000\";\n\n/** `derive.machines` when the config does not set it: 0040's `[bot]` suffix. */\nexport const DEFAULT_MACHINES: readonly string[] = [\"*[bot]\"];\n\n/** The instance path every provenance finding carries. */\nconst PROVENANCE_POINTER = \"/provenance\";\n\n/**\n * Whether a line is blank: empty, or whitespace only. A blank line carries no\n * authorship (proposal 0071). It has no evidence, never starts or ends a\n * range, and never splits one: blank lines between two lines of one machine\n * sit inside its range, and its pin covers them.\n */\nexport function isBlankLine(line: string | undefined): boolean {\n return (line ?? \"\").trim() === \"\";\n}\n\n/** A span with its blank edge lines trimmed, or undefined when every line is blank. */\nfunction trimBlank(body: readonly string[], span: PageLines): PageLines | undefined {\n let { start, end } = span;\n while (start <= end && isBlankLine(body[start - 1])) start++;\n while (end >= start && isBlankLine(body[end - 1])) end--;\n return start > end ? undefined : { start, end };\n}\n\n/** Why a span is not a well-formed range: it holds only blank lines, or its first line, its last, or both are blank. */\nexport type BlankEdges = \"only\" | \"start\" | \"end\" | \"both\";\n\nfunction blankEdges(body: readonly string[], span: PageLines): BlankEdges | undefined {\n const first = isBlankLine(body[span.start - 1]);\n const last = isBlankLine(body[span.end - 1]);\n if (!first && !last) return undefined;\n if (trimBlank(body, span) === undefined) return \"only\";\n return first && last ? \"both\" : first ? \"start\" : \"end\";\n}\n\n// ---------------------------------------------------------------------------\n// Entries and pages\n// ---------------------------------------------------------------------------\n\n/** One `provenance` entry as stored: body lines, and the pin over them. */\nexport interface ProvenanceEntry {\n \"generated-by\": string;\n lines: LineSpec;\n integrity: string;\n}\n\nconst PLAIN_PIN = /^sha256-[0-9a-f]{64}$/;\n\n/**\n * The well-formed entries of a `provenance` value, in order. An entry the\n * schema would reject for its three keys (no machine, unreadable lines, a pin\n * that is not `sha256-`) is neither evidence nor compared: the schema finding\n * speaks for it. A key outside the closed set does not make an entry\n * unreadable. The schema reports that key, and the entry keeps it, so a write\n * that keeps the entry does not delete it silently.\n */\nexport function provenanceEntries(value: unknown): ProvenanceEntry[] {\n if (!Array.isArray(value)) return [];\n const out: ProvenanceEntry[] = [];\n for (const item of value as unknown[]) {\n if (typeof item !== \"object\" || item === null || Array.isArray(item)) continue;\n const record = item as Record<string, unknown>;\n const machine = record[\"generated-by\"];\n const lines = record.lines;\n const integrity = record.integrity;\n if (typeof machine !== \"string\" || machine === \"\") continue;\n if (typeof lines !== \"string\" && typeof lines !== \"number\") continue;\n if (parseLines(lines) === undefined) continue;\n if (typeof integrity !== \"string\" || !PLAIN_PIN.test(integrity)) continue;\n out.push({ ...record, \"generated-by\": machine, lines, integrity });\n }\n return out;\n}\n\n/** A page read for provenance. */\nexport interface ProvenancePage {\n /** Every normalized line of the file. */\n lines: string[];\n /** The file line body line 1 sits on. */\n bodyLine: number;\n /** The body's lines: `lines` from `bodyLine` on. */\n body: string[];\n /** The well-formed `provenance` entries the frontmatter carries. */\n stamp: ProvenanceEntry[];\n}\n\nexport interface ReadPageOptions {\n /**\n * Whether the page's metadata is a leading fenced block. Default true. A\n * page whose metadata is part of the body (html, xml, dita) has body line 1\n * at file line 1 and carries no stamp of its own; its record lives in a\n * manifest.\n */\n fenced?: boolean;\n}\n\n/**\n * Split a page into its body and its stamp. The frontmatter is the block\n * `validate` reads; one that does not parse carries no stamp, and its body\n * still starts after it.\n */\nexport function readProvenancePage(content: string, opts?: ReadPageOptions): ProvenancePage {\n const lines = splitLines(content);\n const loc = opts?.fenced === false ? null : locateFrontmatter(content);\n if (loc === null) return { lines, bodyLine: 1, body: lines, stamp: [] };\n const head = content.slice(0, loc.closeEnd);\n const newlines = head.split(\"\\n\").length - 1;\n // The body starts on the line after the block, and one line further when\n // the file ends at the closing fence with no newline after it.\n const bodyLine = newlines + (head.endsWith(\"\\n\") ? 1 : 2);\n let stamp: ProvenanceEntry[] = [];\n try {\n stamp = provenanceEntries(extractFrontmatter(content, \"markdown\").data.provenance);\n } catch {\n stamp = [];\n }\n return { lines, bodyLine, body: lines.slice(bodyLine - 1), stamp };\n}\n\n// ---------------------------------------------------------------------------\n// git blame --line-porcelain\n// ---------------------------------------------------------------------------\n\n/** One final line of `git blame --line-porcelain`. */\nexport interface BlameLine {\n sha: string;\n /** The line's number in the commit that last changed it. */\n origLine: number;\n /** The line's number in the working file. */\n finalLine: number;\n /** Lines in this group; blame writes it on a group's first line only. */\n groupCount?: number;\n author: string;\n /** `author-mail` without its angle brackets. */\n authorMail: string;\n filename: string;\n /** `previous <sha> <filename>`, when blame reports one. */\n previous?: { sha: string; filename: string };\n /** The commit is a boundary of the blamed history (a root, or a `--since` edge). */\n boundary: boolean;\n /** The zero sha: a line not committed yet. */\n uncommitted: boolean;\n /** The line as the working file holds it, a CR included. */\n content: string;\n}\n\n/** A SHA-1 sha is 40 hex digits, and a SHA-256 repository's (`objectFormat=sha256`) is 64. */\nconst HEADER = /^([0-9a-f]{40}(?:[0-9a-f]{24})?) ([1-9][0-9]*) ([1-9][0-9]*)(?: ([1-9][0-9]*))?$/;\nconst ALL_ZERO = /^0+$/;\n\n/**\n * Parse `git blame --line-porcelain`. Throws a plain `Error` on anything\n * else, plain `--porcelain` included: that form writes a group's header once,\n * and a line without its header cannot be attributed. Both are the caller's\n * bug, never the user's.\n */\nexport function parseLinePorcelain(text: string): BlameLine[] {\n const rows = text.split(\"\\n\");\n if (rows.length > 0 && rows[rows.length - 1] === \"\") rows.pop();\n const out: BlameLine[] = [];\n let i = 0;\n while (i < rows.length) {\n const headerRow = rows[i] ?? \"\";\n const m = HEADER.exec(headerRow);\n const sha = m?.[1];\n const orig = m?.[2];\n const final = m?.[3];\n if (sha === undefined || orig === undefined || final === undefined) {\n throw new Error(`porcelain: expected a header at row ${i + 1}, got ${JSON.stringify(headerRow)}`);\n }\n const finalLine = Number(final);\n const count = m?.[4];\n const fields = new Map<string, string | true>();\n i++;\n for (let row = rows[i]; row !== undefined && !row.startsWith(\"\\t\"); row = rows[i]) {\n const space = row.indexOf(\" \");\n if (space === -1) fields.set(row, true);\n else fields.set(row.slice(0, space), row.slice(space + 1));\n i++;\n }\n const contentRow = rows[i];\n if (contentRow === undefined) throw new Error(`porcelain: line ${finalLine} has no content row`);\n const author = fields.get(\"author\");\n const filename = fields.get(\"filename\");\n if (typeof author !== \"string\" || typeof filename !== \"string\") {\n throw new Error(`porcelain: line ${finalLine} has no full header; run blame with --line-porcelain`);\n }\n const mail = fields.get(\"author-mail\");\n const previous = fields.get(\"previous\");\n const space = typeof previous === \"string\" ? previous.indexOf(\" \") : -1;\n out.push({\n sha,\n origLine: Number(orig),\n finalLine,\n ...(count !== undefined ? { groupCount: Number(count) } : {}),\n author,\n authorMail: typeof mail === \"string\" ? mail.replace(/^<(.*)>$/, \"$1\") : \"\",\n filename,\n ...(typeof previous === \"string\" && space !== -1\n ? { previous: { sha: previous.slice(0, space), filename: previous.slice(space + 1) } }\n : {}),\n boundary: fields.get(\"boundary\") === true,\n uncommitted: ALL_ZERO.test(sha),\n content: contentRow.slice(1),\n });\n i++;\n }\n return out;\n}\n\n// ---------------------------------------------------------------------------\n// Evidence, per body line\n// ---------------------------------------------------------------------------\n\n/** What one commit offers as evidence. */\nexport interface CommitEvidence {\n sha: string;\n /** Trailer values by kind, in message order. `collectTrailers` builds it from key/value pairs. */\n trailers: { generatedBy: string[]; coAuthoredBy: string[] };\n /** The page's full text at this commit; rule 2 is skipped without it. */\n blob?: string;\n /**\n * The `provenance` entries recorded at this commit, when the record lives\n * in a manifest (read from the manifest's blob at this commit, under the\n * page's path). Absent means the page's own frontmatter in `blob`.\n */\n stamp?: readonly ProvenanceEntry[];\n}\n\n/**\n * Trailer pairs sorted into the two kinds evidence reads. Keys compare\n * without case, as git's own trailer parsing does; values are trimmed and\n * keep message order.\n */\nexport function collectTrailers(pairs: readonly (readonly [string, string])[]): CommitEvidence[\"trailers\"] {\n const trailers: CommitEvidence[\"trailers\"] = { generatedBy: [], coAuthoredBy: [] };\n for (const [key, value] of pairs) {\n const k = key.toLowerCase();\n if (k === \"generated-by\") trailers.generatedBy.push(value.trim());\n else if (k === \"co-authored-by\") trailers.coAuthoredBy.push(value.trim());\n }\n return trailers;\n}\n\n/** Which of 0046's five evidence rules answered for a line. */\nexport type EvidenceRule = 1 | 2 | 3 | 4 | 5;\n\n/** A line's evidence: the machine, or none under rule 5, and the blamed sha. */\nexport interface LineEvidence {\n machine?: string;\n rule: EvidenceRule;\n sha: string;\n}\n\nconst IDENTITY_GLOB = { literalBrackets: true, dot: true, bash: true } as const;\n\n/**\n * The machine a `Name <email>` trailer value names, when its name or its\n * email matches a `derive.machines` glob; undefined for a person. Globs are\n * picomatch's, case-sensitive, with literal brackets, so `*[bot]` is a name\n * ending in `[bot]` and not \"anything ending in b, o or t\" (stress test 16).\n * An identity is not a path: `dot` and `bash` let `*` cross a `/` and match a\n * leading `.`, so `ci/deploy[bot]` and `.hidden[bot]` are machines, as\n * `endsWith(\"[bot]\")` had them. The machine is the name as written, and the\n * email only when the name is empty.\n */\nexport function machineIdentity(value: string, machines: readonly string[]): string | undefined {\n const m = /^(.*?)\\s*<([^>]*)>\\s*$/.exec(value);\n const name = m === null ? value.trim() : (m[1] ?? \"\");\n const email = m === null ? \"\" : (m[2] ?? \"\");\n const match = (s: string): boolean =>\n s !== \"\" && machines.some((glob) => picomatch.isMatch(s, glob, IDENTITY_GLOB));\n if (!match(name) && !match(email)) return undefined;\n return name !== \"\" ? name : email;\n}\n\n/** What evidence resolution holds constant across a page. */\nexport interface EvidenceContext {\n commits: ReadonlyMap<string, CommitEvidence>;\n machines: readonly string[];\n /** `--generated-by`, or `MANNI_GENERATED_BY`; empty counts as unset. */\n generatedBy?: string;\n /** Whether the page's metadata is fenced, for reading commit blobs. Default true. */\n fenced?: boolean;\n}\n\n/**\n * Rule 2: the machine a verified stamp at the commit names for the line's\n * number there. The orig line is converted to that blob's own body\n * numbering, since the commit's frontmatter need not be today's. A stamp is\n * checked only at its recorded lines, so the same text elsewhere in the blob\n * does not count, and the first covering entry that verifies wins.\n */\nfunction stampEvidence(commit: CommitEvidence, origLine: number, fenced: boolean | undefined): string | undefined {\n const stamps = verifiedStamps(commit, fenced);\n if (stamps === undefined) return undefined;\n const body = origLine - stamps.bodyLine + 1;\n if (body < 1) return undefined;\n return stamps.entries.find((entry) => body >= entry.start && body <= entry.end)?.generatedBy;\n}\n\n/**\n * Whether a commit carries the page's provenance stamp (proposal 0069, rule\n * 3): at least one entry of its stamp verifies against the page at that\n * commit. Such a commit is the whole account of the lines it last touched.\n */\nfunction carriesStamp(commit: CommitEvidence, fenced: boolean | undefined): boolean {\n return (verifiedStamps(commit, fenced)?.entries.length ?? 0) > 0;\n}\n\n/** The stamp entries that verify against the page at one commit, in stamp order. */\ninterface VerifiedStamps {\n /** The file line body line 1 sits on, in the commit's blob. */\n bodyLine: number;\n entries: { start: number; end: number; generatedBy: string }[];\n}\n\n/**\n * A commit's stamp, read and verified once. Every line a commit last touched\n * asks it, and reading means parsing the blob's frontmatter and hashing each\n * stamped range, so asking per line re-did both for every line.\n */\nfunction verifiedStamps(commit: CommitEvidence, fenced: boolean | undefined): VerifiedStamps | undefined {\n if (commit.blob === undefined) return undefined;\n const memo = fenced === false ? stampsUnfenced : stampsFenced;\n const known = memo.get(commit);\n if (known !== undefined) return known;\n const page = readProvenancePage(commit.blob, fenced === undefined ? undefined : { fenced });\n const entries: VerifiedStamps[\"entries\"] = [];\n for (const entry of commit.stamp === undefined ? page.stamp : provenanceEntries(commit.stamp)) {\n const span = parseLines(entry.lines);\n if (span !== undefined && pinOfLines(page.body, span) === entry.integrity) {\n entries.push({ start: span.start, end: span.end, generatedBy: entry[\"generated-by\"] });\n }\n }\n const stamps = { bodyLine: page.bodyLine, entries };\n memo.set(commit, stamps);\n return stamps;\n}\n\n/**\n * `verifiedStamps` per commit. Keyed by identity: a run builds its\n * CommitEvidence objects fresh, so an entry never outlives the evidence it\n * describes. A pool of reused objects would need this cleared between runs.\n * One map per fenced setting, since the answer reads the commit's blob as\n * fenced or not: a commit shared by a Markdown page and an HTML page is\n * judged once for each.\n */\nconst stampsFenced = new WeakMap<CommitEvidence, VerifiedStamps>();\nconst stampsUnfenced = new WeakMap<CommitEvidence, VerifiedStamps>();\n\n/**\n * Rules 2 to 4 for one line. An uncommitted line has no commit, so none of\n * them applies to it; in particular the working tree's own stamp is never\n * evidence for itself. A stamp outranks its own commit's trailers, because\n * the stamp names lines and a trailer names a commit. And a commit that\n * carries a verified stamp is the whole account of its lines (proposal 0069,\n * rule 3): a line outside every stamped range has no evidence, so a trailer\n * a squash appended cannot turn a line the branch left unstamped into a\n * machine's.\n */\nfunction recordedEvidence(line: BlameLine, ctx: EvidenceContext): LineEvidence {\n if (line.uncommitted) return { rule: 5, sha: line.sha };\n const commit = ctx.commits.get(line.sha);\n if (commit === undefined) throw new Error(`no commit ${line.sha}`);\n const stamped = stampEvidence(commit, line.origLine, ctx.fenced);\n if (stamped !== undefined) return { machine: stamped, rule: 2, sha: line.sha };\n if (carriesStamp(commit, ctx.fenced)) return { rule: 5, sha: line.sha };\n const generated = commit.trailers.generatedBy.map((v) => v.trim()).find((v) => v !== \"\");\n if (generated !== undefined) return { machine: generated, rule: 3, sha: line.sha };\n for (const value of commit.trailers.coAuthoredBy) {\n const machine = machineIdentity(value.trim(), ctx.machines);\n if (machine !== undefined) return { machine, rule: 4, sha: line.sha };\n }\n return { rule: 5, sha: line.sha };\n}\n\n/** All five evidence rules for one blamed line, first match wins. */\nexport function resolveLineEvidence(line: BlameLine, ctx: EvidenceContext): LineEvidence {\n if (line.uncommitted && ctx.generatedBy !== undefined && ctx.generatedBy !== \"\") {\n return { machine: ctx.generatedBy, rule: 1, sha: line.sha };\n }\n return recordedEvidence(line, ctx);\n}\n\n// ---------------------------------------------------------------------------\n// Derivation\n// ---------------------------------------------------------------------------\n\n/** One derived range: its entry, its body lines, and its first line's evidence. */\nexport interface DerivedRange {\n entry: ProvenanceEntry;\n span: PageLines;\n evidence: LineEvidence;\n}\n\n/** A page's derivation: the page, each body line's evidence, and the ranges. */\nexport interface ProvenanceDerivation {\n page: ProvenancePage;\n evidenceByLine: ReadonlyMap<number, LineEvidence>;\n derived: DerivedRange[];\n}\n\nexport interface DeriveProvenanceInput {\n /** The page's working text. */\n content: string;\n blame: readonly BlameLine[];\n commits: ReadonlyMap<string, CommitEvidence>;\n /** `derive.machines`; `DEFAULT_MACHINES` when absent. */\n machines?: readonly string[];\n generatedBy?: string;\n fenced?: boolean;\n}\n\n/** The pin of a span known to lie inside `lines`. */\nfunction pinOf(lines: readonly string[], span: PageLines): string {\n const pin = pinOfLines(lines, span);\n if (pin === undefined) throw new Error(`provenance: lines ${spellLines(span)} fall outside the body`);\n return pin;\n}\n\nfunction contextOf(input: Omit<DeriveProvenanceInput, \"content\" | \"blame\">): EvidenceContext {\n return {\n commits: input.commits,\n machines: input.machines ?? DEFAULT_MACHINES,\n ...(input.generatedBy !== undefined ? { generatedBy: input.generatedBy } : {}),\n ...(input.fenced !== undefined ? { fenced: input.fenced } : {}),\n };\n}\n\nfunction readOptions(fenced: boolean | undefined): ReadPageOptions | undefined {\n return fenced === undefined ? undefined : { fenced };\n}\n\n/**\n * Derive a page's `provenance`: resolve every non-blank body line, then group\n * the lines resolved to one machine into one entry, pinned over the current\n * body. A blank line has no evidence and neither opens nor closes a group, so\n * a range starts and ends on a non-blank line and spans the blank lines\n * between two of its machine's lines (proposal 0071).\n */\nexport function deriveProvenance(input: DeriveProvenanceInput): ProvenanceDerivation {\n const page = readProvenancePage(input.content, readOptions(input.fenced));\n const ctx = contextOf(input);\n const evidenceByLine = new Map<number, LineEvidence>();\n for (const line of input.blame) {\n const body = line.finalLine - page.bodyLine + 1;\n if (body < 1) continue; // a frontmatter line\n if (isBlankLine(page.body[body - 1])) continue;\n evidenceByLine.set(body, resolveLineEvidence(line, ctx));\n }\n const groups: { machine: string; start: number; end: number; first: LineEvidence }[] = [];\n let open: (typeof groups)[number] | undefined;\n for (let n = 1; n <= page.body.length; n++) {\n if (isBlankLine(page.body[n - 1])) continue;\n const evidence = evidenceByLine.get(n);\n const machine = evidence?.machine;\n // Only blank lines lie between the open group's end and n: any other\n // line would have closed it.\n if (open !== undefined && machine !== undefined && machine === open.machine) {\n open.end = n;\n continue;\n }\n if (open !== undefined) groups.push(open);\n open = machine === undefined || evidence === undefined ? undefined : { machine, start: n, end: n, first: evidence };\n }\n if (open !== undefined) groups.push(open);\n return {\n page,\n evidenceByLine,\n derived: groups.map((g) => {\n const span = { start: g.start, end: g.end };\n return {\n entry: { \"generated-by\": g.machine, lines: lineSpec(span), integrity: pinOf(page.body, span) },\n span,\n evidence: g.first,\n };\n }),\n };\n}\n\n// ---------------------------------------------------------------------------\n// Comparison\n// ---------------------------------------------------------------------------\n\n/** 0046's comparison verdicts. */\nexport type ProvenanceStatus = \"current\" | \"moved\" | \"changed\" | \"stale\" | \"unset\";\n\n/**\n * One range's verdict. `entry` is the stamped entry, or the derived one for\n * `unset`. `span` is where its text is now in body lines, and the recorded\n * lines for `changed`. `evidence` is the contradicting line's for `stale` and\n * the range's first line's for `unset`. `noEvidence` marks a current or moved\n * range no line of which names a machine. `blank` marks a stale entry whose\n * text holds, at `span`, but starts or ends on a blank line (proposal 0071).\n */\nexport interface ProvenanceComparison {\n status: ProvenanceStatus;\n entry: ProvenanceEntry;\n span: PageLines;\n evidence?: LineEvidence;\n noEvidence?: true;\n blank?: BlankEdges;\n}\n\n/**\n * The candidate nearest the recorded lines (stress test 12): distance is\n * between start lines, and an equal distance goes to the earlier candidate.\n */\nfunction nearest<T extends { span: PageLines }>(candidates: readonly T[], recorded: PageLines): T | undefined {\n let best: { c: T; d: number } | undefined;\n for (const c of candidates) {\n const d = Math.abs(c.span.start - recorded.start);\n if (best === undefined || d < best.d || (d === best.d && c.span.start < best.c.span.start)) best = { c, d };\n }\n return best?.c;\n}\n\nconst sameSpan = (a: PageLines, b: PageLines): boolean => a.start === b.start && a.end === b.end;\n\n/**\n * What the evidence over a span says about a stamp's machine: the first line\n * that names a different machine, and whether any line names a machine.\n */\nfunction scanEvidence(\n evidenceByLine: ReadonlyMap<number, LineEvidence>,\n span: PageLines,\n machine: string,\n): { contradiction?: LineEvidence; anyMachine: boolean } {\n let anyMachine = false;\n for (let n = span.start; n <= span.end; n++) {\n const evidence = evidenceByLine.get(n);\n if (evidence?.machine === undefined) continue;\n anyMachine = true;\n if (evidence.machine !== machine) return { contradiction: evidence, anyMachine };\n }\n return { anyMachine };\n}\n\n/**\n * Compare a page's stamped entries with a fresh derivation: one result per\n * well-formed stamped entry, in order, then one `unset` per derived range\n * nothing covers.\n *\n * The recorded lines first: when the pin holds there and no line there names\n * a different machine, the entry is current, and it claims only a derived\n * range over exactly those lines. The same text elsewhere, even another\n * machine's, is not this entry's.\n *\n * Otherwise by integrity: an unclaimed derived range with the stamp's pin,\n * nearest by lines. The same machine is current at the recorded lines and\n * moved elsewhere; another machine is stale. Each derived range is taken once.\n *\n * Otherwise the pin is searched for across the whole body, nearest window\n * first. Found nowhere, it is changed. Found, it is stale when a line of the\n * window names a different machine, and current or moved otherwise: lines\n * that name the stamp's machine or no machine are not a contradiction.\n *\n * An entry whose text holds but starts or ends on a blank line, a blank-only\n * one included, is not a well-formed range (proposal 0071): it is stale where\n * its text is, and `blank` says why.\n *\n * A derived range is unset when some non-blank line of it lies outside every\n * span a result above holds, which for a changed entry is its recorded lines.\n * A person's edit inside an agent's range is therefore one changed finding,\n * not a changed finding and two unset ones. A blank line is never unset, so\n * entries a derived range spans across a blank line leave it covered.\n */\nexport function compareProvenance(\n stamped: readonly ProvenanceEntry[],\n derivation: ProvenanceDerivation,\n): ProvenanceComparison[] {\n const { page, evidenceByLine, derived } = derivation;\n const claimed = new Set<DerivedRange>();\n const results: ProvenanceComparison[] = [];\n for (const entry of provenanceEntries(stamped)) {\n const recorded = parseLines(entry.lines);\n if (recorded === undefined) continue; // unreachable: provenanceEntries checked it\n const machine = entry[\"generated-by\"];\n\n const takenHere = [...claimed].some((d) => sameSpan(d.span, recorded));\n if (!takenHere && pinOfLines(page.body, recorded) === entry.integrity) {\n const here = scanEvidence(evidenceByLine, recorded, machine);\n const blank = blankEdges(page.body, recorded);\n if (here.contradiction === undefined && blank !== undefined) {\n results.push({ status: \"stale\", entry, span: recorded, blank });\n continue;\n }\n if (here.contradiction === undefined) {\n const exact = derived.find(\n (d) => !claimed.has(d) && sameSpan(d.span, recorded) && d.entry.integrity === entry.integrity,\n );\n if (exact !== undefined) claimed.add(exact);\n results.push({ status: \"current\", entry, span: recorded, ...(here.anyMachine ? {} : { noEvidence: true as const }) });\n continue;\n }\n }\n\n const pool = derived.filter((d) => !claimed.has(d) && d.entry.integrity === entry.integrity);\n const hit = nearest(pool, recorded);\n if (hit !== undefined) {\n claimed.add(hit);\n if (hit.entry[\"generated-by\"] !== machine) {\n results.push({ status: \"stale\", entry, span: hit.span, evidence: hit.evidence });\n } else {\n results.push({ status: sameSpan(hit.span, recorded) ? \"current\" : \"moved\", entry, span: hit.span });\n }\n continue;\n }\n\n const width = recorded.end - recorded.start + 1;\n const claimedSpans = [...claimed].map((d) => d.span);\n // No budget: a truncated search would call an intact range changed, and\n // the band-first order keeps the common small shift fast.\n const windows = findWindows(page.body, width, entry.integrity, undefined, { around: recorded.start, budget: Infinity })\n .starts.map((start) => ({ span: { start, end: start + width - 1 } }))\n .filter((w) => !claimedSpans.some((s) => sameSpan(s, w.span)));\n const found = nearest(windows, recorded);\n if (found === undefined) {\n results.push({ status: \"changed\", entry, span: recorded });\n continue;\n }\n const { contradiction, anyMachine } = scanEvidence(evidenceByLine, found.span, machine);\n if (contradiction !== undefined) {\n results.push({ status: \"stale\", entry, span: found.span, evidence: contradiction });\n continue;\n }\n const blank = blankEdges(page.body, found.span);\n if (blank !== undefined) {\n results.push({ status: \"stale\", entry, span: found.span, blank });\n continue;\n }\n results.push({\n status: sameSpan(found.span, recorded) ? \"current\" : \"moved\",\n entry,\n span: found.span,\n ...(anyMachine ? {} : { noEvidence: true as const }),\n });\n }\n\n const covering = results.map((r) => r.span);\n for (const d of derived) {\n if (claimed.has(d)) continue;\n let uncovered = false;\n for (let n = d.span.start; n <= d.span.end && !uncovered; n++) {\n if (isBlankLine(page.body[n - 1])) continue;\n uncovered = !covering.some((s) => n >= s.start && n <= s.end);\n }\n if (uncovered) results.push({ status: \"unset\", entry: d.entry, span: d.span, evidence: d.evidence });\n }\n return results;\n}\n\n/**\n * The `provenance` value `derive` writes. Current entries stay as they are,\n * moved entries stay with `lines` rewritten, and every derived range not\n * already kept is added, which re-derives changed and stale entries and adds\n * unset ones. A changed entry no machine now answers for is dropped (stress\n * test 11: the bytes are gone); an entry nothing contradicts never is. An\n * entry stale for its blank lines is kept trimmed to its first and last\n * non-blank line and pinned over those, or dropped when it holds only blank\n * lines (proposal 0071). A derived range not already kept is the newer\n * account of its lines, of any machine: a kept entry within it is dropped,\n * and one it partly overlaps keeps only the lines outside it, split in two\n * when the range sits in its middle. Each piece is trimmed of blank edges and\n * pinned over its own lines, or dropped when only blank lines are left. A\n * kept entry keeps any key outside the closed set. Ordered by start line,\n * stably.\n */\nexport function planProvenanceWrite(\n comparisons: readonly ProvenanceComparison[],\n derivation: ProvenanceDerivation,\n): ProvenanceEntry[] {\n const { body } = derivation.page;\n const same = (a: ProvenanceEntry, b: ProvenanceEntry): boolean =>\n a[\"generated-by\"] === b[\"generated-by\"] && String(a.lines) === String(b.lines) && a.integrity === b.integrity;\n const kept: Written[] = [];\n // An entry identical to one already kept is written once: a blank-edged\n // entry trimmed can land on the lines of another entry the stamp holds.\n const keep = (entry: ProvenanceEntry, span: PageLines): void => {\n if (!kept.some((k) => same(k.entry, entry))) kept.push({ entry, span });\n };\n for (const r of comparisons) {\n if (r.status === \"current\") keep(r.entry, r.span);\n else if (r.status === \"moved\") keep({ ...r.entry, lines: lineSpec(r.span) }, r.span);\n else if (r.status === \"stale\" && r.blank !== undefined) {\n const span = trimBlank(body, r.span);\n if (span !== undefined) keep({ ...r.entry, lines: lineSpec(span), integrity: pinOf(body, span) }, span);\n }\n }\n /**\n * What is left of a kept entry beside a derived range: the pieces outside\n * it, each trimmed of blank edges, pinned over its own lines, and dropped\n * when only blank lines are left.\n */\n const outside = (k: Written, d: PageLines): Written[] => {\n if (k.span.end < d.start || k.span.start > d.end) return [k];\n const pieces: PageLines[] = [];\n if (k.span.start < d.start) pieces.push({ start: k.span.start, end: d.start - 1 });\n if (k.span.end > d.end) pieces.push({ start: d.end + 1, end: k.span.end });\n return pieces.flatMap((piece) => {\n const span = trimBlank(body, piece);\n if (span === undefined) return [];\n return [{ entry: { ...k.entry, lines: lineSpec(span), integrity: pinOf(body, span) }, span }];\n });\n };\n let out: Written[] = [...kept];\n const derived = new Set<Written>();\n for (const d of derivation.derived) {\n if (kept.some((k) => same(k.entry, d.entry))) continue;\n out = out.flatMap((k) => (derived.has(k) ? [k] : outside(k, d.span)));\n const written = { entry: d.entry, span: d.span };\n derived.add(written);\n out.push(written);\n }\n const unique: Written[] = [];\n for (const k of out) if (!unique.some((u) => same(u.entry, k.entry))) unique.push(k);\n return unique.sort((a, b) => a.span.start - b.span.start).map((k) => k.entry);\n}\n\n/** An entry a write plans, with the body lines it covers. */\ninterface Written {\n entry: ProvenanceEntry;\n span: PageLines;\n}\n\n// ---------------------------------------------------------------------------\n// Output: the JSON ranges, findings, and get's value\n// ---------------------------------------------------------------------------\n\n/** One range of `DerivedField.ranges`, in file lines. */\nexport interface RangeResult {\n lines: string;\n \"generated-by\": string;\n integrity: string;\n status: ProvenanceStatus;\n /** `uncommitted`, `blame <sha7>`, or `pin` when only the pin speaks for the range. */\n evidence: string;\n /** What the record said before: on `moved` and `stale` only. */\n from?: { lines: string; \"generated-by\": string };\n /** Whether `derive` wrote this range; always false until it does. */\n written: boolean;\n}\n\nconst short = (sha: string): string => sha.slice(0, 7);\n\n/** File lines as a report spells them. */\nfunction fileSpelling(span: PageLines, bodyLine: number): string {\n return spellLines(toFileLines(span, bodyLine));\n}\n\nfunction evidenceText(evidence: LineEvidence | undefined): string {\n if (evidence?.machine === undefined) return \"pin\";\n return evidence.rule === 1 ? \"uncommitted\" : `blame ${short(evidence.sha)}`;\n}\n\n/** Where a finding says the evidence came from: the short sha, or `uncommitted`. */\nfunction evidenceRef(evidence: LineEvidence | undefined): string {\n if (evidence === undefined) return \"no evidence\";\n return evidence.rule === 1 ? \"uncommitted\" : short(evidence.sha);\n}\n\n/** The comparisons as `DerivedField.ranges` reports them. `bodyLine` is the page's. */\nexport function rangeResults(comparisons: readonly ProvenanceComparison[], bodyLine: number): RangeResult[] {\n return comparisons.map((r) => {\n const lines = fileSpelling(r.span, bodyLine);\n const recorded = parseLines(r.entry.lines);\n const from = recorded === undefined ? undefined : fileSpelling(recorded, bodyLine);\n const machine = r.entry[\"generated-by\"];\n switch (r.status) {\n case \"stale\":\n return {\n lines,\n \"generated-by\": r.evidence?.machine ?? machine,\n integrity: r.entry.integrity,\n status: r.status,\n evidence: evidenceText(r.evidence),\n ...(from !== undefined ? { from: { lines: from, \"generated-by\": machine } } : {}),\n written: false,\n };\n case \"moved\":\n return {\n lines,\n \"generated-by\": machine,\n integrity: r.entry.integrity,\n status: r.status,\n evidence: \"pin\",\n ...(from !== undefined ? { from: { lines: from, \"generated-by\": machine } } : {}),\n written: false,\n };\n case \"unset\":\n return { lines, \"generated-by\": machine, integrity: r.entry.integrity, status: r.status, evidence: evidenceText(r.evidence), written: false };\n case \"current\":\n case \"changed\":\n return { lines, \"generated-by\": machine, integrity: r.entry.integrity, status: r.status, evidence: \"pin\", written: false };\n }\n });\n}\n\n/** How a finding says an entry's blank lines make it malformed. */\nconst BLANK_WORDS: Record<BlankEdges, string> = {\n only: \"hold only blank lines\",\n start: \"start on a blank line\",\n end: \"end on a blank line\",\n both: \"start and end on blank lines\",\n};\n\n/**\n * The findings `validate` and `derive --check` file for a page's provenance:\n * one per changed, stale or unset range, in 0046's words. `line` is the\n * range's file line on the page, and `subject` carries the pin (the recorded\n * one for changed and stale, the derived one for unset), so a baseline that\n * forgives one range does not forgive the rest.\n */\nexport function provenanceFindings(comparisons: readonly ProvenanceComparison[], bodyLine: number): FieldError[] {\n const findings: FieldError[] = [];\n for (const r of comparisons) {\n const machine = r.entry[\"generated-by\"];\n const lines = fileSpelling(r.span, bodyLine);\n let message: string;\n switch (r.status) {\n case \"changed\":\n message = `provenance lines ${lines} changed since ${machine} wrote them`;\n break;\n case \"stale\":\n message =\n r.blank !== undefined\n ? `provenance lines ${lines} say ${machine} but ${BLANK_WORDS[r.blank]}`\n : `provenance lines ${lines} say ${machine}; blame says ${r.evidence?.machine ?? \"another machine\"} (${evidenceRef(r.evidence)})`;\n break;\n case \"unset\":\n message = `provenance is unset for lines ${lines}; blame says ${machine} (${evidenceRef(r.evidence)})`;\n break;\n case \"current\":\n case \"moved\":\n continue;\n }\n findings.push({\n schema: DERIVED_STALE_SCHEMA,\n keyword: DERIVED_KEYWORD,\n subject: `provenance ${r.entry.integrity}`,\n instancePath: PROVENANCE_POINTER,\n message: `${message} — run manni meta derive`,\n line: toFileLines(r.span, bodyLine).start,\n });\n }\n return findings;\n}\n\n/** `get`'s value: `lines 12-31 claude-fable-5; lines 44 claude-sonnet-5`, in file lines. */\nexport function renderProvenanceValue(entries: readonly ProvenanceEntry[], bodyLine: number): string {\n return entries\n .map((e) => {\n const span = parseLines(e.lines);\n const lines = span === undefined ? String(e.lines) : fileSpelling(span, bodyLine);\n return `lines ${lines} ${e[\"generated-by\"]}`;\n })\n .join(\"; \");\n}\n\n// ---------------------------------------------------------------------------\n// Ranged attribution: `manni meta derive <path>:L1-L2 --generated-by <name>`\n// ---------------------------------------------------------------------------\n\n/**\n * Split `<path>:L` or `<path>:L1-L2` as `cite add` splits a page argument:\n * the last `:L` suffix, so a drive letter is not a range. A range that ends\n * before it starts is refused in 0046's words.\n */\nexport function parseProvenanceTarget(arg: string): { page: string; lines?: PageLines } {\n try {\n return splitPageArgument(arg);\n } catch (err) {\n if (err instanceof LineRangeError) throw new DocmetaError(`${arg} ends before it starts.`);\n throw err;\n }\n}\n\nexport interface AttributeRangeInput {\n /** The positional as typed, `<path>:L` or `<path>:L1-L2`, in file lines. */\n target: string;\n content: string;\n blame: readonly BlameLine[];\n commits: ReadonlyMap<string, CommitEvidence>;\n machines?: readonly string[];\n generatedBy: string;\n fenced?: boolean;\n /**\n * The page as `readProvenancePage` reads `content`, when the caller has it.\n * Several ranges on one file then share one read instead of one each.\n */\n page?: ProvenancePage;\n}\n\n/**\n * The entry a named range writes. Committed or not, its lines go to\n * `generatedBy`, unless rules 2 to 4 name a different machine for any of\n * them: the first such line in file order is named in the refusal. Evidence\n * that names the same machine, or none, lets the range through. Every\n * refusal is a `DocmetaError` (exit 2) in 0046's words.\n *\n * A blank line carries no authorship (proposal 0071): its evidence is never\n * a refusal, the entry is trimmed to the range's first and last non-blank\n * line, and a range of only blank lines writes nothing.\n */\nexport function attributeRange(input: AttributeRangeInput): ProvenanceEntry | undefined {\n const { target } = input;\n const { page: path, lines: range } = parseProvenanceTarget(target);\n if (range === undefined) throw new Error(`provenance: ${target} names no lines`);\n const page = input.page ?? readProvenancePage(input.content, readOptions(input.fenced));\n if (range.end > page.lines.length) {\n throw new DocmetaError(\n `${path} has no lines ${spellLines(range)}: the file ends at line ${page.lines.length}.`,\n );\n }\n if (range.start < page.bodyLine) {\n throw new DocmetaError(\n `${target} reaches into the frontmatter; provenance pins body lines, which start at line ${page.bodyLine}.`,\n );\n }\n const ctx = contextOf(input);\n for (const line of input.blame) {\n if (line.finalLine < range.start || line.finalLine > range.end) continue;\n if (isBlankLine(page.lines[line.finalLine - 1])) continue;\n const evidence = recordedEvidence(line, ctx);\n if (evidence.machine !== undefined && evidence.machine !== input.generatedBy) {\n throw new DocmetaError(\n `${target}: blame attributes these lines to ${evidence.machine} (${short(evidence.sha)}); --generated-by cannot overrule a recorded machine.`,\n );\n }\n }\n const span = trimBlank(page.body, toBodyLines(range, page.bodyLine));\n if (span === undefined) return undefined;\n return { \"generated-by\": input.generatedBy, lines: lineSpec(span), integrity: pinOf(page.body, span) };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,SAAS,UAAU,gBAAgB;A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,KAAK,YAAY,CAAC,CAAC,EAAG;AACjD,UAAM,WAAW,iBAAiB,MAAM,GAAG;AAC3C,QAAI,SAAS,YAAY,UAAa,SAAS,YAAY,MAAM,aAAa;AAC5E,YAAM,IAAI;AAAA,QACR,GAAG,MAAM,qCAAqC,SAAS,OAAO,KAAK,MAAM,SAAS,GAAG,CAAC;AAAA,MACxF;AAAA,IACF;AAAA,EACF;AACA,QAAM,OAAO,UAAU,KAAK,MAAM,YAAY,OAAO,KAAK,QAAQ,CAAC;AACnE,MAAI,SAAS,OAAW,QAAO;AAC/B,SAAO,EAAE,gBAAgB,MAAM,aAAa,OAAO,SAAS,IAAI,GAAG,WAAW,MAAM,KAAK,MAAM,IAAI,EAAE;AACvG;","names":["basename","dirname","join","relative","basename","resolve","relative","errorCode","path","join","basename","dirname","count","readFile","relative","resolve","isMap","parseDocument","readFile","at","posix","relative","join","resolve","list","at","readFile","parseDocument","isMap","memberOf","isRecord","at","memberOf","j","isAbsolute","relative","sep","relative","sep","isAbsolute","list","readFile","stat","basename","isAbsolute","join","relative","resolve","sep","LineCounter","isMap","isNode","isScalar","isSeq","parseYaml","parseDocument","posix","LineCounter","isMap","isNode","isScalar","parseDocument","stringify","join","at","line","LineCounter","parseDocument","posix","isScalar","isMap","isNode","isRecord","r","stringify","sep","reported","relative","basename","isAbsolute","resolve","join","posix","rel","stat","at","unreadable","readFile","keyLines","LineCounter","parseDocument","isMap","isScalar","isNode","isSeq","list","parseYaml","steps","picomatch","count","space","picomatch","blank"]}