@hawkeyexl/manni 4.15.0 → 4.17.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 (230) hide show
  1. package/README.md +11 -7
  2. package/dist/{batch-OMDKRGUE.js → batch-SAW4E46C.js} +14 -14
  3. package/dist/{build-YCY5MUHA.js → build-F6S3W77I.js} +15 -14
  4. package/dist/{calibrate-RN2NJ4FS.js → calibrate-3DW2VV7F.js} +15 -15
  5. package/dist/{capture-2WYROZKA.js → capture-PKEYY2VO.js} +14 -14
  6. package/dist/{check-LVUTWAGR.js → check-7PUIHLFM.js} +15 -15
  7. package/dist/{check-OIRJ6OBW.js → check-EZN7YNVF.js} +14 -15
  8. package/dist/{check-KRVWHF7E.js → check-LRX2YFDF.js} +13 -14
  9. package/dist/check-NW7GHSX6.js +47 -0
  10. package/dist/{cli-33E3B2FK.js → chunk-245W2Q7C.js} +133 -365
  11. package/dist/chunk-245W2Q7C.js.map +1 -0
  12. package/dist/{chunk-KN37BXVY.js → chunk-2A5OIZHT.js} +7 -7
  13. package/dist/{chunk-KCXQXKOL.js → chunk-2LCJNH73.js} +2 -2
  14. package/dist/{chunk-Q2VOXKAQ.js → chunk-2TLNAGVJ.js} +187 -159
  15. package/dist/chunk-2TLNAGVJ.js.map +1 -0
  16. package/dist/{chunk-AL4HRKSZ.js → chunk-3446DW4W.js} +2 -2
  17. package/dist/{chunk-UVLQRP6O.js → chunk-3UYSONT4.js} +7 -453
  18. package/dist/chunk-3UYSONT4.js.map +1 -0
  19. package/dist/{chunk-3CSEHHKB.js → chunk-4GGADKTU.js} +82 -238
  20. package/dist/chunk-4GGADKTU.js.map +1 -0
  21. package/dist/{chunk-RGRNAQG5.js → chunk-5QOTR53S.js} +7 -7
  22. package/dist/{chunk-GZHBMMDC.js → chunk-5VNFO2RT.js} +12 -38
  23. package/dist/chunk-5VNFO2RT.js.map +1 -0
  24. package/dist/{chunk-7EKXSSEO.js → chunk-64EDFJ5S.js} +5 -5
  25. package/dist/chunk-6J2ED4ED.js +545 -0
  26. package/dist/chunk-6J2ED4ED.js.map +1 -0
  27. package/dist/{chunk-FEEO7ET6.js → chunk-ABAFKOQF.js} +3 -3
  28. package/dist/{chunk-476DMDJ5.js → chunk-AIZBZYQM.js} +1311 -18
  29. package/dist/chunk-AIZBZYQM.js.map +1 -0
  30. package/dist/{chunk-NIQ2JSZO.js → chunk-B5R5BWMY.js} +14 -429
  31. package/dist/chunk-B5R5BWMY.js.map +1 -0
  32. package/dist/{chunk-6DYFWAZA.js → chunk-D3AO2PMV.js} +9 -9
  33. package/dist/{chunk-57DHX65T.js → chunk-DSJTYRI5.js} +3 -3
  34. package/dist/{chunk-T62SFCQY.js → chunk-DU6CXY5R.js} +47 -10
  35. package/dist/chunk-DU6CXY5R.js.map +1 -0
  36. package/dist/{chunk-OFOIBV5J.js → chunk-FAS3SRQB.js} +927 -99
  37. package/dist/chunk-FAS3SRQB.js.map +1 -0
  38. package/dist/{chunk-FYWQS35G.js → chunk-FEURGKJC.js} +2 -2
  39. package/dist/{chunk-46OWIAAX.js → chunk-FPPHEHPZ.js} +3 -3
  40. package/dist/chunk-HEVYEI6O.js +1338 -0
  41. package/dist/chunk-HEVYEI6O.js.map +1 -0
  42. package/dist/{chunk-C37OVJ35.js → chunk-IGE6CIKZ.js} +11 -2
  43. package/dist/chunk-IGE6CIKZ.js.map +1 -0
  44. package/dist/{chunk-4MYW2D2U.js → chunk-JK56UPNQ.js} +252 -425
  45. package/dist/chunk-JK56UPNQ.js.map +1 -0
  46. package/dist/{chunk-ZC2MZZR5.js → chunk-KAWS7H4C.js} +2385 -2061
  47. package/dist/chunk-KAWS7H4C.js.map +1 -0
  48. package/dist/{chunk-MAOX3524.js → chunk-KB4MNUKC.js} +2 -2
  49. package/dist/{chunk-Z6PZKXSP.js → chunk-KCNBM42T.js} +4 -4
  50. package/dist/chunk-KUXAHHDE.js +314 -0
  51. package/dist/chunk-KUXAHHDE.js.map +1 -0
  52. package/dist/{chunk-7SVFBJBE.js → chunk-LDIUA4ZG.js} +2 -2
  53. package/dist/{chunk-DN4LCWSA.js → chunk-M6DNOHJO.js} +3 -3
  54. package/dist/{chunk-TXZJESES.js → chunk-MBLVLQWI.js} +2 -2
  55. package/dist/{chunk-3EJVJDMX.js → chunk-MDXDTO7E.js} +6 -6
  56. package/dist/{chunk-WDENIUC7.js → chunk-MDZXRHIJ.js} +1 -1
  57. package/dist/chunk-MDZXRHIJ.js.map +1 -0
  58. package/dist/{chunk-IGRXQC3H.js → chunk-N25KDXOV.js} +2 -2
  59. package/dist/{chunk-DW22KCLN.js → chunk-NPZWOPOH.js} +3 -3
  60. package/dist/chunk-OZL5M764.js +443 -0
  61. package/dist/chunk-OZL5M764.js.map +1 -0
  62. package/dist/{chunk-Q62Q7CDI.js → chunk-PS4Y7EPP.js} +3 -3
  63. package/dist/{chunk-JTATFPWB.js → chunk-Q7E43SXN.js} +12 -7
  64. package/dist/{chunk-JTATFPWB.js.map → chunk-Q7E43SXN.js.map} +1 -1
  65. package/dist/{chunk-GUTAKJIF.js → chunk-QIKCIREY.js} +4 -4
  66. package/dist/{chunk-Y3GWQBJP.js → chunk-QIWSEKA6.js} +2 -2
  67. package/dist/{chunk-SVF3WCC7.js → chunk-TNYIXIYV.js} +6 -6
  68. package/dist/{chunk-SLGCRXHM.js → chunk-TUMR35B3.js} +4 -4
  69. package/dist/{chunk-7XHW5DZA.js → chunk-U5NSIZRS.js} +3 -3
  70. package/dist/chunk-UP6NBQ62.js +2 -0
  71. package/dist/{chunk-QEJ4GH25.js → chunk-VRMQSP7O.js} +3 -3
  72. package/dist/{chunk-URGALOZY.js → chunk-W7IEP7IG.js} +2 -2
  73. package/dist/{chunk-JHE3CYWS.js → chunk-W7XOMNYC.js} +2 -2
  74. package/dist/{chunk-CWGBRWP7.js → chunk-WBXVQW57.js} +6 -5
  75. package/dist/{chunk-CWGBRWP7.js.map → chunk-WBXVQW57.js.map} +1 -1
  76. package/dist/{chunk-JULE3EU3.js → chunk-WP5EKWTU.js} +7 -7
  77. package/dist/chunk-WRSWZEVU.js +580 -0
  78. package/dist/chunk-WRSWZEVU.js.map +1 -0
  79. package/dist/{chunk-JQPZKWIP.js → chunk-WZSL7KF2.js} +2 -2
  80. package/dist/{chunk-525KMBZS.js → chunk-XCEEJEVA.js} +4 -4
  81. package/dist/{chunk-3WQMMLIO.js → chunk-XPGK4ECA.js} +7 -7
  82. package/dist/{chunk-QDO5JFFV.js → chunk-XRWQQHBR.js} +2 -2
  83. package/dist/{chunk-IE5PXI6M.js → chunk-XWUIFSWK.js} +20 -6
  84. package/dist/chunk-XWUIFSWK.js.map +1 -0
  85. package/dist/{chunk-GLQCSDFS.js → chunk-YJHHXM5B.js} +2 -2
  86. package/dist/{chunk-QS3K57OJ.js → chunk-ZEYNLKOH.js} +4 -4
  87. package/dist/{chunk-YT5HKJWV.js → chunk-ZIXU7A4C.js} +21 -21
  88. package/dist/{cli-DDLLZHZW.js → cli-5ZQXVWWC.js} +18 -19
  89. package/dist/{cli-DDLLZHZW.js.map → cli-5ZQXVWWC.js.map} +1 -1
  90. package/dist/{cli-QEPVGLQ3.js → cli-D5WYQVUF.js} +18 -18
  91. package/dist/{cli-OKPRTVG6.js → cli-FCGGNZ5C.js} +2 -2
  92. package/dist/{cli-LIKI7WPR.js → cli-FNX4LXMI.js} +37 -37
  93. package/dist/{cli-VP6JTPFS.js → cli-LQRHK23G.js} +9 -9
  94. package/dist/{cli-MWUFAS2X.js → cli-LRKBCQRS.js} +9 -9
  95. package/dist/{cli-7JV4RM66.js → cli-NJC3H3CW.js} +15 -15
  96. package/dist/{cli-B4DTJ2KC.js → cli-OHKWCJIJ.js} +21 -21
  97. package/dist/{cli-EVACAD7K.js → cli-RKYIZ6KU.js} +634 -36
  98. package/dist/cli-RKYIZ6KU.js.map +1 -0
  99. package/dist/cli-TJDQ5GUW.js +379 -0
  100. package/dist/cli-TJDQ5GUW.js.map +1 -0
  101. package/dist/{cli-D4WXCDTS.js → cli-VC3BXCVR.js} +19 -19
  102. package/dist/cli.js +14 -14
  103. package/dist/docmeta.js +8 -8
  104. package/dist/{github-DV57TW5L.js → github-6PV2JTZ7.js} +13 -14
  105. package/dist/github-7ZT4KYQU.js +35 -0
  106. package/dist/graph/runtime.d.ts +633 -217
  107. package/dist/graph/runtime.js +1001 -370
  108. package/dist/graph/runtime.js.map +1 -1
  109. package/dist/index.d.ts +2617 -1945
  110. package/dist/index.js +108 -64
  111. package/dist/index.js.map +1 -1
  112. package/dist/{json-SHPUCD64.js → json-VWXLDTXR.js} +13 -14
  113. package/dist/{labels-3GCGYYV3.js → labels-ZJK27RL3.js} +12 -13
  114. package/dist/{labels-3GCGYYV3.js.map → labels-ZJK27RL3.js.map} +1 -1
  115. package/dist/{lint-RE4DMI6E.js → lint-5OERIERT.js} +13 -13
  116. package/dist/{list-ZR3KY556.js → list-MANBRF7Z.js} +13 -14
  117. package/dist/{list-F56MEJXR.js → list-SEEANTU6.js} +15 -15
  118. package/dist/{page-G7XSO4FD.js → page-O4M65KMJ.js} +13 -14
  119. package/dist/{prepare-WHMWP7BG.js → prepare-3WULLZER.js} +13 -13
  120. package/dist/{pretty-VTJVXWRK.js → pretty-5FRBLTXU.js} +13 -14
  121. package/dist/{pretty-YVRRWBWN.js → pretty-D3M366JD.js} +14 -15
  122. package/dist/{reporters-G5R4SURQ.js → reporters-4WWZRHKI.js} +4 -4
  123. package/dist/{reporters-FSXJ42EB.js → reporters-6TEJDXXO.js} +4 -4
  124. package/dist/{reporters-MHPY4HRA.js → reporters-GDCZ5P7C.js} +12 -12
  125. package/dist/{run-FSYOYEPR.js → run-TZDLG6EN.js} +16 -16
  126. package/dist/sarif-PUZAMEFQ.js +36 -0
  127. package/dist/{sarif-HBQIDY7T.js → sarif-SSSPOUCK.js} +11 -11
  128. package/dist/site/rehype.d.ts +33 -0
  129. package/dist/site/rehype.js +49 -0
  130. package/dist/site/rehype.js.map +1 -0
  131. package/dist/{term-ABHGACYE.js → term-DHWMUL5N.js} +18 -19
  132. package/dist/{term-ABHGACYE.js.map → term-DHWMUL5N.js.map} +1 -1
  133. package/dist/{types-VMOT7RAL.js → types-7N7ETP3W.js} +2 -2
  134. package/dist/{validate-DXYUUGUD.js → validate-4AW7KIIY.js} +5 -5
  135. package/package.json +10 -1
  136. package/plugin/manni/.claude-plugin/plugin.json +1 -1
  137. package/shapes/graph/shapes-1.2.0.ttl +1161 -0
  138. package/dist/check-MR7IG7IP.js +0 -36
  139. package/dist/chunk-3CSEHHKB.js.map +0 -1
  140. package/dist/chunk-476DMDJ5.js.map +0 -1
  141. package/dist/chunk-4MYW2D2U.js.map +0 -1
  142. package/dist/chunk-C37OVJ35.js.map +0 -1
  143. package/dist/chunk-GZHBMMDC.js.map +0 -1
  144. package/dist/chunk-IE5PXI6M.js.map +0 -1
  145. package/dist/chunk-IKEWBMCN.js +0 -98
  146. package/dist/chunk-IKEWBMCN.js.map +0 -1
  147. package/dist/chunk-NIQ2JSZO.js.map +0 -1
  148. package/dist/chunk-OFOIBV5J.js.map +0 -1
  149. package/dist/chunk-Q2VOXKAQ.js.map +0 -1
  150. package/dist/chunk-T62SFCQY.js.map +0 -1
  151. package/dist/chunk-UPUJJOKB.js +0 -236
  152. package/dist/chunk-UPUJJOKB.js.map +0 -1
  153. package/dist/chunk-UVLQRP6O.js.map +0 -1
  154. package/dist/chunk-WDENIUC7.js.map +0 -1
  155. package/dist/chunk-YUTVAMWW.js +0 -2
  156. package/dist/chunk-ZC2MZZR5.js.map +0 -1
  157. package/dist/cli-33E3B2FK.js.map +0 -1
  158. package/dist/cli-EVACAD7K.js.map +0 -1
  159. package/dist/github-SGX2EARO.js +0 -36
  160. package/dist/sarif-RRUFJZUL.js +0 -37
  161. /package/dist/{batch-OMDKRGUE.js.map → batch-SAW4E46C.js.map} +0 -0
  162. /package/dist/{build-YCY5MUHA.js.map → build-F6S3W77I.js.map} +0 -0
  163. /package/dist/{calibrate-RN2NJ4FS.js.map → calibrate-3DW2VV7F.js.map} +0 -0
  164. /package/dist/{capture-2WYROZKA.js.map → capture-PKEYY2VO.js.map} +0 -0
  165. /package/dist/{check-LVUTWAGR.js.map → check-7PUIHLFM.js.map} +0 -0
  166. /package/dist/{check-KRVWHF7E.js.map → check-EZN7YNVF.js.map} +0 -0
  167. /package/dist/{check-MR7IG7IP.js.map → check-LRX2YFDF.js.map} +0 -0
  168. /package/dist/{check-OIRJ6OBW.js.map → check-NW7GHSX6.js.map} +0 -0
  169. /package/dist/{chunk-KN37BXVY.js.map → chunk-2A5OIZHT.js.map} +0 -0
  170. /package/dist/{chunk-KCXQXKOL.js.map → chunk-2LCJNH73.js.map} +0 -0
  171. /package/dist/{chunk-AL4HRKSZ.js.map → chunk-3446DW4W.js.map} +0 -0
  172. /package/dist/{chunk-RGRNAQG5.js.map → chunk-5QOTR53S.js.map} +0 -0
  173. /package/dist/{chunk-7EKXSSEO.js.map → chunk-64EDFJ5S.js.map} +0 -0
  174. /package/dist/{chunk-FEEO7ET6.js.map → chunk-ABAFKOQF.js.map} +0 -0
  175. /package/dist/{chunk-6DYFWAZA.js.map → chunk-D3AO2PMV.js.map} +0 -0
  176. /package/dist/{chunk-57DHX65T.js.map → chunk-DSJTYRI5.js.map} +0 -0
  177. /package/dist/{chunk-FYWQS35G.js.map → chunk-FEURGKJC.js.map} +0 -0
  178. /package/dist/{chunk-46OWIAAX.js.map → chunk-FPPHEHPZ.js.map} +0 -0
  179. /package/dist/{chunk-MAOX3524.js.map → chunk-KB4MNUKC.js.map} +0 -0
  180. /package/dist/{chunk-Z6PZKXSP.js.map → chunk-KCNBM42T.js.map} +0 -0
  181. /package/dist/{chunk-7SVFBJBE.js.map → chunk-LDIUA4ZG.js.map} +0 -0
  182. /package/dist/{chunk-DN4LCWSA.js.map → chunk-M6DNOHJO.js.map} +0 -0
  183. /package/dist/{chunk-TXZJESES.js.map → chunk-MBLVLQWI.js.map} +0 -0
  184. /package/dist/{chunk-3EJVJDMX.js.map → chunk-MDXDTO7E.js.map} +0 -0
  185. /package/dist/{chunk-IGRXQC3H.js.map → chunk-N25KDXOV.js.map} +0 -0
  186. /package/dist/{chunk-DW22KCLN.js.map → chunk-NPZWOPOH.js.map} +0 -0
  187. /package/dist/{chunk-Q62Q7CDI.js.map → chunk-PS4Y7EPP.js.map} +0 -0
  188. /package/dist/{chunk-GUTAKJIF.js.map → chunk-QIKCIREY.js.map} +0 -0
  189. /package/dist/{chunk-Y3GWQBJP.js.map → chunk-QIWSEKA6.js.map} +0 -0
  190. /package/dist/{chunk-SVF3WCC7.js.map → chunk-TNYIXIYV.js.map} +0 -0
  191. /package/dist/{chunk-SLGCRXHM.js.map → chunk-TUMR35B3.js.map} +0 -0
  192. /package/dist/{chunk-7XHW5DZA.js.map → chunk-U5NSIZRS.js.map} +0 -0
  193. /package/dist/{chunk-YUTVAMWW.js.map → chunk-UP6NBQ62.js.map} +0 -0
  194. /package/dist/{chunk-QEJ4GH25.js.map → chunk-VRMQSP7O.js.map} +0 -0
  195. /package/dist/{chunk-URGALOZY.js.map → chunk-W7IEP7IG.js.map} +0 -0
  196. /package/dist/{chunk-JHE3CYWS.js.map → chunk-W7XOMNYC.js.map} +0 -0
  197. /package/dist/{chunk-JULE3EU3.js.map → chunk-WP5EKWTU.js.map} +0 -0
  198. /package/dist/{chunk-JQPZKWIP.js.map → chunk-WZSL7KF2.js.map} +0 -0
  199. /package/dist/{chunk-525KMBZS.js.map → chunk-XCEEJEVA.js.map} +0 -0
  200. /package/dist/{chunk-3WQMMLIO.js.map → chunk-XPGK4ECA.js.map} +0 -0
  201. /package/dist/{chunk-QDO5JFFV.js.map → chunk-XRWQQHBR.js.map} +0 -0
  202. /package/dist/{chunk-GLQCSDFS.js.map → chunk-YJHHXM5B.js.map} +0 -0
  203. /package/dist/{chunk-QS3K57OJ.js.map → chunk-ZEYNLKOH.js.map} +0 -0
  204. /package/dist/{chunk-YT5HKJWV.js.map → chunk-ZIXU7A4C.js.map} +0 -0
  205. /package/dist/{cli-QEPVGLQ3.js.map → cli-D5WYQVUF.js.map} +0 -0
  206. /package/dist/{cli-OKPRTVG6.js.map → cli-FCGGNZ5C.js.map} +0 -0
  207. /package/dist/{cli-LIKI7WPR.js.map → cli-FNX4LXMI.js.map} +0 -0
  208. /package/dist/{cli-VP6JTPFS.js.map → cli-LQRHK23G.js.map} +0 -0
  209. /package/dist/{cli-MWUFAS2X.js.map → cli-LRKBCQRS.js.map} +0 -0
  210. /package/dist/{cli-7JV4RM66.js.map → cli-NJC3H3CW.js.map} +0 -0
  211. /package/dist/{cli-B4DTJ2KC.js.map → cli-OHKWCJIJ.js.map} +0 -0
  212. /package/dist/{cli-D4WXCDTS.js.map → cli-VC3BXCVR.js.map} +0 -0
  213. /package/dist/{github-DV57TW5L.js.map → github-6PV2JTZ7.js.map} +0 -0
  214. /package/dist/{github-SGX2EARO.js.map → github-7ZT4KYQU.js.map} +0 -0
  215. /package/dist/{json-SHPUCD64.js.map → json-VWXLDTXR.js.map} +0 -0
  216. /package/dist/{lint-RE4DMI6E.js.map → lint-5OERIERT.js.map} +0 -0
  217. /package/dist/{list-F56MEJXR.js.map → list-MANBRF7Z.js.map} +0 -0
  218. /package/dist/{list-ZR3KY556.js.map → list-SEEANTU6.js.map} +0 -0
  219. /package/dist/{page-G7XSO4FD.js.map → page-O4M65KMJ.js.map} +0 -0
  220. /package/dist/{prepare-WHMWP7BG.js.map → prepare-3WULLZER.js.map} +0 -0
  221. /package/dist/{pretty-VTJVXWRK.js.map → pretty-5FRBLTXU.js.map} +0 -0
  222. /package/dist/{pretty-YVRRWBWN.js.map → pretty-D3M366JD.js.map} +0 -0
  223. /package/dist/{reporters-FSXJ42EB.js.map → reporters-4WWZRHKI.js.map} +0 -0
  224. /package/dist/{reporters-G5R4SURQ.js.map → reporters-6TEJDXXO.js.map} +0 -0
  225. /package/dist/{reporters-MHPY4HRA.js.map → reporters-GDCZ5P7C.js.map} +0 -0
  226. /package/dist/{run-FSYOYEPR.js.map → run-TZDLG6EN.js.map} +0 -0
  227. /package/dist/{sarif-HBQIDY7T.js.map → sarif-PUZAMEFQ.js.map} +0 -0
  228. /package/dist/{sarif-RRUFJZUL.js.map → sarif-SSSPOUCK.js.map} +0 -0
  229. /package/dist/{types-VMOT7RAL.js.map → types-7N7ETP3W.js.map} +0 -0
  230. /package/dist/{validate-DXYUUGUD.js.map → validate-4AW7KIIY.js.map} +0 -0
@@ -389,6 +389,10 @@ var SOFTWARE_SUBJECT_IRIS = {
389
389
  var DCTERMS_TITLE = `${NS.dcterms}title`;
390
390
  var DCTERMS_REFERENCES = `${NS.dcterms}references`;
391
391
  var DCTERMS_LANGUAGE = `${NS.dcterms}language`;
392
+ var STATEMENT_DATA = /* @__PURE__ */ new Set([`${NS.graph}Block`, `${NS.graph}Verification`]);
393
+ function isStatementData(graph, iri) {
394
+ return graph.types(iri).some((t) => STATEMENT_DATA.has(t));
395
+ }
392
396
  function documentOf(iri) {
393
397
  const hash = iri.indexOf("#");
394
398
  return hash === -1 ? iri : iri.slice(0, hash);
@@ -485,6 +489,7 @@ function traverse(graph, options) {
485
489
  )) {
486
490
  if (allowed && !allowed.has(predicate)) continue;
487
491
  if (!followTypes && predicate === RDF_TYPE) continue;
492
+ if (isStatementData(graph, target)) continue;
488
493
  trace.hops.push({ from, predicate, to: target, depth, direction: dir });
489
494
  if (seen.has(target)) continue;
490
495
  seen.add(target);
@@ -543,6 +548,7 @@ var DCTERMS_TITLE2 = `${NS.dcterms}title`;
543
548
  var DCTERMS_HAS_PART = `${NS.dcterms}hasPart`;
544
549
  var GRAPH_LEVEL = `${NS.graph}level`;
545
550
  var GRAPH_ORDER = `${NS.graph}order`;
551
+ var GRAPH_BLOCK = `${NS.graph}Block`;
546
552
  function splitFragment(iri) {
547
553
  const hash = iri.indexOf("#");
548
554
  return hash < 0 ? { doc: iri } : { doc: iri.slice(0, hash), fragment: iri.slice(hash + 1) };
@@ -655,7 +661,7 @@ function stripInline(raw) {
655
661
  function documentSectionOrder(graph, docIri) {
656
662
  const ordered = [];
657
663
  const seen = /* @__PURE__ */ new Set();
658
- const childrenOf = (iri) => graph.out(iri, DCTERMS_HAS_PART).map((e) => e.target).sort((a, b) => {
664
+ const childrenOf = (iri) => graph.out(iri, DCTERMS_HAS_PART).map((e) => e.target).filter((target) => !graph.types(target).includes(GRAPH_BLOCK)).sort((a, b) => {
659
665
  const oa = Number.parseInt(graph.literal(a, GRAPH_ORDER) ?? "", 10);
660
666
  const ob = Number.parseInt(graph.literal(b, GRAPH_ORDER) ?? "", 10);
661
667
  if (Number.isNaN(oa) || Number.isNaN(ob) || oa === ob) {
@@ -806,7 +812,7 @@ function createFetchResolver(graph, options = {}) {
806
812
  // src/graph/runtime/assemble.ts
807
813
  async function assemble(resolver, nodes, options = {}) {
808
814
  const trace = options.trace ?? createTrace();
809
- const budget = options.maxChars ?? Infinity;
815
+ const budget2 = options.maxChars ?? Infinity;
810
816
  if (nodes.length === 0) {
811
817
  return {
812
818
  ...options.entry ? { entry: options.entry } : {},
@@ -828,7 +834,7 @@ async function assemble(resolver, nodes, options = {}) {
828
834
  const resolved = await resolver.resolve(node.iri);
829
835
  if (!resolved) continue;
830
836
  resolvedAny = true;
831
- if (used + resolved.text.length > budget) {
837
+ if (used + resolved.text.length > budget2) {
832
838
  truncated = true;
833
839
  continue;
834
840
  }
@@ -867,182 +873,341 @@ async function assemble(resolver, nodes, options = {}) {
867
873
  };
868
874
  }
869
875
 
870
- // src/graph/runtime/rdfjs.ts
871
- var XSD_STRING2 = "http://www.w3.org/2001/XMLSchema#string";
872
- var RDF_LANG_STRING = "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString";
873
- function namedNode(value) {
874
- return {
875
- termType: "NamedNode",
876
- value,
877
- equals(other) {
878
- return !!other && other.termType === "NamedNode" && other.value === value;
879
- }
880
- };
881
- }
882
- function defaultGraph() {
883
- return {
884
- termType: "DefaultGraph",
885
- value: "",
886
- equals(other) {
887
- return !!other && other.termType === "DefaultGraph";
888
- }
889
- };
890
- }
891
- function literal(value, datatype, language) {
892
- const lang = language ?? "";
893
- const dt = namedNode(lang ? RDF_LANG_STRING : datatype ?? XSD_STRING2);
894
- return {
895
- termType: "Literal",
896
- value,
897
- language: lang,
898
- datatype: dt,
899
- equals(other) {
900
- return !!other && other.termType === "Literal" && other.value === value && (other.language ?? "") === lang && !!other.datatype && other.datatype.value === dt.value;
901
- }
902
- };
903
- }
904
- function toTerm(v) {
905
- return v.kind === "iri" ? namedNode(v.value) : literal(v.value, v.datatype, v.language);
876
+ // src/graph/core/vector-index.ts
877
+ var MAGIC = new Uint8Array([77, 71, 82, 86]);
878
+ var FORMAT_VERSION = 2;
879
+ var HEADER_OFFSET = 12;
880
+ var VectorIndexError = class extends Error {
881
+ constructor(message) {
882
+ super(message);
883
+ this.name = "VectorIndexError";
884
+ }
885
+ };
886
+ function normalize(vector) {
887
+ let sum = 0;
888
+ for (const value of vector) sum += value * value;
889
+ if (sum === 0) return vector;
890
+ const inv = 1 / Math.sqrt(sum);
891
+ vector.set(vector.map((value) => value * inv));
892
+ return vector;
906
893
  }
907
- function makeQuad(s, p, o) {
908
- const subject = namedNode(s);
909
- const predicate = namedNode(p);
910
- const object = toTerm(o);
911
- const graph = defaultGraph();
912
- return {
913
- termType: "Quad",
914
- subject,
915
- predicate,
916
- object,
917
- graph,
918
- equals(other) {
919
- return !!other && subject.equals(other.subject) && predicate.equals(other.predicate) && object.equals(other.object);
894
+ function encodeVectorIndex(entries, meta) {
895
+ const sorted = [...entries].sort((a, b) => byCodeUnit(a.id, b.id));
896
+ const dims = sorted[0]?.vector.length ?? 0;
897
+ for (const entry of sorted) {
898
+ if (entry.vector.length !== dims) {
899
+ throw new VectorIndexError(
900
+ `Inconsistent vector dimensions: ${entry.id} has ${entry.vector.length}, expected ${dims}.`
901
+ );
920
902
  }
903
+ }
904
+ const header = {
905
+ model: meta.model,
906
+ dtype: meta.dtype,
907
+ dims,
908
+ count: sorted.length,
909
+ ids: sorted.map((e) => e.id),
910
+ source: meta.source,
911
+ language: meta.language
921
912
  };
922
- }
923
- function rdfjsQuads(graph) {
924
- const quads = [];
925
- for (const s of graph.ids()) {
926
- const node = graph.node(s);
927
- if (!node) continue;
928
- for (const p of [...node.props.keys()].sort(byCodeUnit)) {
929
- for (const v of node.props.get(p) ?? []) quads.push(makeQuad(s, p, v));
913
+ const headerBytes = new TextEncoder().encode(JSON.stringify(header));
914
+ const payloadBytes = sorted.length * dims * 4;
915
+ const out = new Uint8Array(HEADER_OFFSET + headerBytes.length + payloadBytes);
916
+ const view = new DataView(out.buffer);
917
+ out.set(MAGIC, 0);
918
+ view.setUint32(4, FORMAT_VERSION, true);
919
+ view.setUint32(8, headerBytes.length, true);
920
+ out.set(headerBytes, HEADER_OFFSET);
921
+ let offset = HEADER_OFFSET + headerBytes.length;
922
+ for (const entry of sorted) {
923
+ const vector = normalize(Float32Array.from(entry.vector));
924
+ for (const value of vector) {
925
+ view.setFloat32(offset, value, true);
926
+ offset += 4;
930
927
  }
931
928
  }
932
- return quads;
929
+ return out;
933
930
  }
934
- function matchQuads(graph, subject, predicate, object) {
935
- const quads = [];
936
- const subjects = subject ? [subject] : graph.ids();
937
- for (const s of subjects) {
938
- const node = graph.node(s);
939
- if (!node) continue;
940
- const predicates = predicate ? [predicate] : [...node.props.keys()].sort(byCodeUnit);
941
- for (const p of predicates) {
942
- for (const v of node.props.get(p) ?? []) {
943
- if (object !== void 0 && object !== null && v.value !== object) {
944
- continue;
945
- }
946
- quads.push(makeQuad(s, p, v));
947
- }
948
- }
931
+ function decodeVectorIndex(bytes) {
932
+ if (bytes.length < HEADER_OFFSET) {
933
+ throw new VectorIndexError("Not a manni graph vector index: file is too short.");
949
934
  }
950
- return quads;
951
- }
952
-
953
- // node_modules/minisearch/dist/es/index.js
954
- var ENTRIES = "ENTRIES";
955
- var KEYS = "KEYS";
956
- var VALUES = "VALUES";
957
- var LEAF = "";
958
- var TreeIterator = class {
959
- constructor(set, type) {
960
- const node = set._tree;
961
- const keys = Array.from(node.keys());
962
- this.set = set;
963
- this._type = type;
964
- this._path = keys.length > 0 ? [{ node, keys }] : [];
935
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
936
+ if (!MAGIC.every((byte, i) => bytes[i] === byte)) {
937
+ throw new VectorIndexError(
938
+ "Not a manni graph vector index: bad magic \u2014 is this the right file?"
939
+ );
965
940
  }
966
- next() {
967
- const value = this.dive();
968
- this.backtrack();
969
- return value;
941
+ const version = view.getUint32(4, true);
942
+ if (version !== FORMAT_VERSION) {
943
+ throw new VectorIndexError(
944
+ `Unsupported vector index version ${version} (this build reads ${FORMAT_VERSION}) \u2014 re-run \`manni graph embed\`.`
945
+ );
970
946
  }
971
- dive() {
972
- if (this._path.length === 0) {
973
- return { done: true, value: void 0 };
974
- }
975
- const { node, keys } = last$1(this._path);
976
- if (last$1(keys) === LEAF) {
977
- return { done: false, value: this.result() };
978
- }
979
- const child = node.get(last$1(keys));
980
- this._path.push({ node: child, keys: Array.from(child.keys()) });
981
- return this.dive();
947
+ const headerLength = view.getUint32(8, true);
948
+ if (HEADER_OFFSET + headerLength > bytes.length) {
949
+ throw new VectorIndexError("Vector index is truncated: header overruns.");
982
950
  }
983
- backtrack() {
984
- if (this._path.length === 0) {
985
- return;
986
- }
987
- const keys = last$1(this._path).keys;
988
- keys.pop();
989
- if (keys.length > 0) {
990
- return;
991
- }
992
- this._path.pop();
993
- this.backtrack();
951
+ let header;
952
+ try {
953
+ header = JSON.parse(
954
+ new TextDecoder().decode(
955
+ bytes.subarray(HEADER_OFFSET, HEADER_OFFSET + headerLength)
956
+ )
957
+ );
958
+ } catch {
959
+ throw new VectorIndexError("Vector index header is not valid JSON.");
994
960
  }
995
- key() {
996
- return this.set._prefix + this._path.map(({ keys }) => last$1(keys)).filter((key) => key !== LEAF).join("");
961
+ if (!Array.isArray(header.ids) || typeof header.dims !== "number" || header.ids.length !== header.count) {
962
+ throw new VectorIndexError("Vector index header is malformed.");
997
963
  }
998
- value() {
999
- return last$1(this._path).node.get(LEAF);
964
+ const start = HEADER_OFFSET + headerLength;
965
+ const expected = header.count * header.dims * 4;
966
+ if (bytes.length - start !== expected) {
967
+ throw new VectorIndexError(
968
+ `Vector index is truncated: expected ${expected} payload bytes, found ${bytes.length - start}.`
969
+ );
1000
970
  }
1001
- result() {
1002
- switch (this._type) {
1003
- case VALUES:
1004
- return this.value();
1005
- case KEYS:
1006
- return this.key();
1007
- default:
1008
- return [this.key(), this.value()];
1009
- }
971
+ const vectors = new Float32Array(header.count * header.dims);
972
+ for (let i = 0; i < vectors.length; i++) {
973
+ vectors[i] = view.getFloat32(start + i * 4, true);
1010
974
  }
1011
- [Symbol.iterator]() {
1012
- return this;
975
+ return { header, vectors };
976
+ }
977
+
978
+ // src/graph/runtime/vector.ts
979
+ var VectorMismatchError = class extends Error {
980
+ reason;
981
+ constructor(mismatch) {
982
+ super(mismatch.detail);
983
+ this.name = "VectorMismatchError";
984
+ this.reason = mismatch.reason;
1013
985
  }
1014
986
  };
1015
- var last$1 = (array) => {
1016
- return array[array.length - 1];
1017
- };
1018
- var fuzzySearch = (node, query, maxDistance) => {
1019
- const results = /* @__PURE__ */ new Map();
1020
- if (query === void 0)
1021
- return results;
1022
- const n = query.length + 1;
1023
- const m = n + maxDistance;
1024
- const matrix = new Uint8Array(m * n).fill(maxDistance + 1);
1025
- for (let j = 0; j < n; ++j)
1026
- matrix[j] = j;
1027
- for (let i = 1; i < m; ++i)
1028
- matrix[i * n] = i;
1029
- recurse(node, query, maxDistance, results, matrix, 1, n, "");
1030
- return results;
1031
- };
1032
- var recurse = (node, query, maxDistance, results, matrix, m, n, prefix) => {
1033
- const offset = m * n;
1034
- key: for (const key of node.keys()) {
1035
- if (key === LEAF) {
1036
- const distance = matrix[offset - 1];
1037
- if (distance <= maxDistance) {
1038
- results.set(prefix, [node.get(key), distance]);
1039
- }
1040
- } else {
1041
- let i = m;
1042
- for (let pos = 0; pos < key.length; ++pos, ++i) {
1043
- const char = key[pos];
1044
- const thisRowOffset = n * i;
1045
- const prevRowOffset = thisRowOffset - n;
987
+ async function searchIndexDigest(raw) {
988
+ const webCrypto = globalThis.crypto;
989
+ const subtle = webCrypto?.subtle;
990
+ if (!subtle) {
991
+ throw new Error(
992
+ "searchIndexDigest needs Web Crypto (globalThis.crypto.subtle), which is unavailable here \u2014 a page served over plain HTTP does not get it."
993
+ );
994
+ }
995
+ const digest = await subtle.digest("SHA-256", new TextEncoder().encode(raw));
996
+ const hex = [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("");
997
+ return `sha256:${hex}`;
998
+ }
999
+ function createVectorIndex(bytes) {
1000
+ const { header, vectors } = decodeVectorIndex(bytes);
1001
+ const { dims, ids } = header;
1002
+ return {
1003
+ model: header.model,
1004
+ dtype: header.dtype,
1005
+ dims,
1006
+ source: header.source,
1007
+ size: () => ids.length,
1008
+ idAt: (row) => ids[row],
1009
+ check(expected) {
1010
+ if (expected.model !== void 0 && expected.model !== header.model) {
1011
+ return {
1012
+ reason: "model",
1013
+ detail: `Vector index was built with ${header.model}, but the embedder is ${expected.model}. Re-run \`manni graph embed\`.`
1014
+ };
1015
+ }
1016
+ if (expected.dtype !== void 0 && expected.dtype !== header.dtype) {
1017
+ return {
1018
+ reason: "dtype",
1019
+ detail: `Vector index was built at dtype ${header.dtype}, but the embedder is at ${expected.dtype} \u2014 different weights are a different function. Re-run \`manni graph embed\`.`
1020
+ };
1021
+ }
1022
+ if (expected.dims !== void 0 && expected.dims !== dims) {
1023
+ return {
1024
+ reason: "dims",
1025
+ detail: `Vector index has ${dims} dimensions, but the embedder produces ${expected.dims}.`
1026
+ };
1027
+ }
1028
+ if (expected.source !== void 0 && expected.source !== header.source) {
1029
+ return {
1030
+ reason: "stale-source",
1031
+ detail: "Vector index was built from a different search index \u2014 the corpus changed. Re-run `manni graph embed`."
1032
+ };
1033
+ }
1034
+ return void 0;
1035
+ },
1036
+ search(query, options = {}) {
1037
+ if (dims === 0 || ids.length === 0) return [];
1038
+ if (query.length !== dims) {
1039
+ throw new VectorMismatchError({
1040
+ reason: "dims",
1041
+ detail: `Query vector has ${query.length} dimensions, but the index has ${dims}.`
1042
+ });
1043
+ }
1044
+ const limit = normalizeLimit(options.limit);
1045
+ if (limit === 0) return [];
1046
+ const minScore = options.minScore ?? 0;
1047
+ const q = normalize(Float32Array.from(query));
1048
+ const scored = [];
1049
+ for (const [row, iri] of ids.entries()) {
1050
+ const stored = vectors.subarray(row * dims, (row + 1) * dims);
1051
+ let score = 0;
1052
+ for (const [i, value] of q.entries()) score += value * (stored[i] ?? 0);
1053
+ if (score >= minScore) {
1054
+ scored.push({ iri, score, via: "vector" });
1055
+ }
1056
+ }
1057
+ scored.sort(
1058
+ (a, b) => a.score === b.score ? byCodeUnit(a.iri, b.iri) : b.score - a.score
1059
+ );
1060
+ return scored.slice(0, limit);
1061
+ }
1062
+ };
1063
+ }
1064
+ function normalizeLimit(limit) {
1065
+ return typeof limit === "number" && Number.isInteger(limit) && limit >= 0 ? limit : 10;
1066
+ }
1067
+
1068
+ // src/graph/runtime/entry.ts
1069
+ function rrfMerge(rankings, k = 60) {
1070
+ const fused = /* @__PURE__ */ new Map();
1071
+ for (const ranking of rankings) {
1072
+ ranking.forEach((candidate, i) => {
1073
+ const current = fused.get(candidate.iri) ?? {
1074
+ score: 0,
1075
+ vias: /* @__PURE__ */ new Set()
1076
+ };
1077
+ current.score += 1 / (k + i + 1);
1078
+ current.vias.add(candidate.via);
1079
+ fused.set(candidate.iri, current);
1080
+ });
1081
+ }
1082
+ return [...fused.entries()].map(([iri, { score, vias }]) => {
1083
+ const [only] = vias;
1084
+ return {
1085
+ iri,
1086
+ score,
1087
+ via: vias.size === 1 && only !== void 0 ? only : "hybrid"
1088
+ };
1089
+ }).sort(
1090
+ (a, b) => a.score === b.score ? byCodeUnit(a.iri, b.iri) : b.score - a.score
1091
+ );
1092
+ }
1093
+ async function findEntry(query, options) {
1094
+ const trace = options.trace ?? createTrace();
1095
+ const limit = typeof options.limit === "number" && Number.isInteger(options.limit) && options.limit >= 0 ? options.limit : 10;
1096
+ const lexical = options.lexical.search(query, { limit });
1097
+ const embedder = options.embedder;
1098
+ const embed = embedder ? (q) => embedder.embed(q) : options.embedQuery;
1099
+ let vector = [];
1100
+ if (options.vectors && embed && query.trim() !== "") {
1101
+ const mismatch = options.vectors.check({
1102
+ ...options.embedder ? { model: options.embedder.model, dtype: options.embedder.dtype } : {},
1103
+ // Staleness is checked whichever way the query is embedded — it is a
1104
+ // property of the corpus, not of the embedder, so even the unverified
1105
+ // `embedQuery` path gets it when the caller supplies a digest.
1106
+ ...options.source === void 0 ? {} : { source: options.source }
1107
+ });
1108
+ if (mismatch) throw new VectorMismatchError(mismatch);
1109
+ const queryVector = await embed(query);
1110
+ vector = options.vectors.search(queryVector, { limit });
1111
+ }
1112
+ const rankings = vector.length > 0 ? [lexical, vector] : [lexical];
1113
+ const candidates = rrfMerge(rankings).slice(0, limit);
1114
+ for (const candidate of candidates) trace.entry.push(candidate);
1115
+ return { candidates, lexical, vector, trace };
1116
+ }
1117
+
1118
+ // node_modules/minisearch/dist/es/index.js
1119
+ var ENTRIES = "ENTRIES";
1120
+ var KEYS = "KEYS";
1121
+ var VALUES = "VALUES";
1122
+ var LEAF = "";
1123
+ var TreeIterator = class {
1124
+ constructor(set, type) {
1125
+ const node = set._tree;
1126
+ const keys = Array.from(node.keys());
1127
+ this.set = set;
1128
+ this._type = type;
1129
+ this._path = keys.length > 0 ? [{ node, keys }] : [];
1130
+ }
1131
+ next() {
1132
+ const value = this.dive();
1133
+ this.backtrack();
1134
+ return value;
1135
+ }
1136
+ dive() {
1137
+ if (this._path.length === 0) {
1138
+ return { done: true, value: void 0 };
1139
+ }
1140
+ const { node, keys } = last$1(this._path);
1141
+ if (last$1(keys) === LEAF) {
1142
+ return { done: false, value: this.result() };
1143
+ }
1144
+ const child = node.get(last$1(keys));
1145
+ this._path.push({ node: child, keys: Array.from(child.keys()) });
1146
+ return this.dive();
1147
+ }
1148
+ backtrack() {
1149
+ if (this._path.length === 0) {
1150
+ return;
1151
+ }
1152
+ const keys = last$1(this._path).keys;
1153
+ keys.pop();
1154
+ if (keys.length > 0) {
1155
+ return;
1156
+ }
1157
+ this._path.pop();
1158
+ this.backtrack();
1159
+ }
1160
+ key() {
1161
+ return this.set._prefix + this._path.map(({ keys }) => last$1(keys)).filter((key) => key !== LEAF).join("");
1162
+ }
1163
+ value() {
1164
+ return last$1(this._path).node.get(LEAF);
1165
+ }
1166
+ result() {
1167
+ switch (this._type) {
1168
+ case VALUES:
1169
+ return this.value();
1170
+ case KEYS:
1171
+ return this.key();
1172
+ default:
1173
+ return [this.key(), this.value()];
1174
+ }
1175
+ }
1176
+ [Symbol.iterator]() {
1177
+ return this;
1178
+ }
1179
+ };
1180
+ var last$1 = (array) => {
1181
+ return array[array.length - 1];
1182
+ };
1183
+ var fuzzySearch = (node, query, maxDistance) => {
1184
+ const results = /* @__PURE__ */ new Map();
1185
+ if (query === void 0)
1186
+ return results;
1187
+ const n = query.length + 1;
1188
+ const m = n + maxDistance;
1189
+ const matrix = new Uint8Array(m * n).fill(maxDistance + 1);
1190
+ for (let j = 0; j < n; ++j)
1191
+ matrix[j] = j;
1192
+ for (let i = 1; i < m; ++i)
1193
+ matrix[i * n] = i;
1194
+ recurse(node, query, maxDistance, results, matrix, 1, n, "");
1195
+ return results;
1196
+ };
1197
+ var recurse = (node, query, maxDistance, results, matrix, m, n, prefix) => {
1198
+ const offset = m * n;
1199
+ key: for (const key of node.keys()) {
1200
+ if (key === LEAF) {
1201
+ const distance = matrix[offset - 1];
1202
+ if (distance <= maxDistance) {
1203
+ results.set(prefix, [node.get(key), distance]);
1204
+ }
1205
+ } else {
1206
+ let i = m;
1207
+ for (let pos = 0; pos < key.length; ++pos, ++i) {
1208
+ const char = key[pos];
1209
+ const thisRowOffset = n * i;
1210
+ const prevRowOffset = thisRowOffset - n;
1046
1211
  let minDistance = matrix[thisRowOffset];
1047
1212
  const jmin = Math.max(0, i - maxDistance - 1);
1048
1213
  const jmax = Math.min(n - 1, i + maxDistance);
@@ -2793,256 +2958,718 @@ function createLexicalIndex(input) {
2793
2958
  };
2794
2959
  }
2795
2960
 
2796
- // src/graph/core/vector-index.ts
2797
- var MAGIC = new Uint8Array([77, 71, 82, 86]);
2798
- var FORMAT_VERSION = 2;
2799
- var HEADER_OFFSET = 12;
2800
- var VectorIndexError = class extends Error {
2801
- constructor(message) {
2802
- super(message);
2803
- this.name = "VectorIndexError";
2961
+ // src/graph/runtime/retrieve.ts
2962
+ var StaleArtifactError = class extends Error {
2963
+ constructor(manifestGraph, found, file = "graph.jsonld") {
2964
+ super(`chunks.json was built from graph ${manifestGraph}, and ${file} is ${found}; publish again.`);
2965
+ this.name = "StaleArtifactError";
2804
2966
  }
2805
2967
  };
2806
- function normalize(vector) {
2807
- let sum = 0;
2808
- for (const value of vector) sum += value * value;
2809
- if (sum === 0) return vector;
2810
- const inv = 1 / Math.sqrt(sum);
2811
- vector.set(vector.map((value) => value * inv));
2812
- return vector;
2968
+ var ModelMismatchError = class extends Error {
2969
+ expected;
2970
+ actual;
2971
+ constructor(expected, actual) {
2972
+ super(`chunks.json was embedded with ${expected}, and the embedder loads ${actual}.`);
2973
+ this.name = "ModelMismatchError";
2974
+ this.expected = expected;
2975
+ this.actual = actual;
2976
+ }
2977
+ };
2978
+ var IMPACT_DEPTH = 3;
2979
+ var ENTRY_POOL = 50;
2980
+ function withholds(record, reason) {
2981
+ if (reason === "drifted") return record.pins.error > 0;
2982
+ return record.evals !== null && record.evals.current && record.evals.fail + record.evals.error > 0;
2813
2983
  }
2814
- function encodeVectorIndex(entries, meta) {
2815
- const sorted = [...entries].sort((a, b) => byCodeUnit(a.id, b.id));
2816
- const dims = sorted[0]?.vector.length ?? 0;
2817
- for (const entry of sorted) {
2818
- if (entry.vector.length !== dims) {
2819
- throw new VectorIndexError(
2820
- `Inconsistent vector dimensions: ${entry.id} has ${entry.vector.length}, expected ${dims}.`
2821
- );
2822
- }
2984
+ function failedField(row, where) {
2985
+ for (const { field, value } of where) {
2986
+ const held = row.metadata[field];
2987
+ const values = Array.isArray(held) ? held : [held];
2988
+ if (!values.some((v) => v !== void 0 && v !== null && scalarText(v) === value)) return field;
2823
2989
  }
2824
- const header = {
2825
- model: meta.model,
2826
- dtype: meta.dtype,
2827
- dims,
2828
- count: sorted.length,
2829
- ids: sorted.map((e) => e.id),
2830
- source: meta.source,
2831
- language: meta.language
2832
- };
2833
- const headerBytes = new TextEncoder().encode(JSON.stringify(header));
2834
- const payloadBytes = sorted.length * dims * 4;
2835
- const out = new Uint8Array(HEADER_OFFSET + headerBytes.length + payloadBytes);
2836
- const view = new DataView(out.buffer);
2837
- out.set(MAGIC, 0);
2838
- view.setUint32(4, FORMAT_VERSION, true);
2839
- view.setUint32(8, headerBytes.length, true);
2840
- out.set(headerBytes, HEADER_OFFSET);
2841
- let offset = HEADER_OFFSET + headerBytes.length;
2842
- for (const entry of sorted) {
2843
- const vector = normalize(Float32Array.from(entry.vector));
2844
- for (const value of vector) {
2845
- view.setFloat32(offset, value, true);
2846
- offset += 4;
2990
+ return void 0;
2991
+ }
2992
+ function scalarText(v) {
2993
+ return typeof v === "string" ? v : JSON.stringify(v);
2994
+ }
2995
+ function modelOf(manifest, language) {
2996
+ return manifest.languages[language]?.model ?? null;
2997
+ }
2998
+ async function rank(ctx, question, language, mode, where) {
2999
+ const model = modelOf(ctx.manifest, language);
3000
+ const wantVector = mode === "vector" || mode === "hybrid" || mode === void 0 && model !== null;
3001
+ let vector = [];
3002
+ const storeRows = /* @__PURE__ */ new Map();
3003
+ let fallback = mode === void 0 && model === null && Object.values(ctx.manifest.languages).some((l) => l.model !== null);
3004
+ if (wantVector && question.trim() !== "") {
3005
+ let queryVector = null;
3006
+ const embedder = model === null ? null : await ctx.embedder(model);
3007
+ if (model !== null && embedder !== null) {
3008
+ if (embedder.model !== model.id) throw new ModelMismatchError(model.id, embedder.model);
3009
+ queryVector = Array.from(await embedder.embed(question));
3010
+ }
3011
+ const found = await ctx.store.query({ text: question, vector: queryVector, k: ENTRY_POOL, language, where });
3012
+ for (const m of found) if (m.row !== void 0) storeRows.set(m.id, m.row);
3013
+ vector = found.map((m) => ({ iri: m.id, score: m.score, via: "vector" })).sort((a, b) => a.score === b.score ? byCodeUnit(a.iri, b.iri) : b.score - a.score);
3014
+ fallback = queryVector === null && vector.length === 0;
3015
+ }
3016
+ let lexical = [];
3017
+ if (mode !== "vector" || fallback) {
3018
+ const index = await ctx.lexical(language);
3019
+ lexical = index?.search(question, { limit: ENTRY_POOL }) ?? [];
3020
+ }
3021
+ const lexicalScore = new Map(lexical.map((c) => [c.iri, c.score]));
3022
+ const vectorScore = new Map(vector.map((c) => [c.iri, c.score]));
3023
+ const ranked = rrfMerge([lexical, vector].filter((leg) => leg.length > 0)).map((c) => {
3024
+ const row = storeRows.get(c.iri);
3025
+ return {
3026
+ iri: c.iri,
3027
+ via: c.via,
3028
+ fused: c.score,
3029
+ lexical: lexicalScore.get(c.iri) ?? null,
3030
+ vector: vectorScore.get(c.iri) ?? null,
3031
+ ...row === void 0 ? {} : { row }
3032
+ };
3033
+ });
3034
+ const best = lexical[0]?.score ?? vector[0]?.score;
3035
+ return { ranked, fallback, best };
3036
+ }
3037
+ async function rowsFor(ctx, ids, language) {
3038
+ const out = /* @__PURE__ */ new Map();
3039
+ if (ids.length === 0) return out;
3040
+ for (const row of await ctx.chunks.get([...ids], language)) {
3041
+ if (row.graph !== ctx.manifest.graph) {
3042
+ throw new StaleArtifactError(ctx.manifest.graph, row.graph, ctx.manifest.languages[row.language]?.file ?? "a chunk row");
2847
3043
  }
3044
+ out.set(row.id, row);
2848
3045
  }
2849
3046
  return out;
2850
3047
  }
2851
- function decodeVectorIndex(bytes) {
2852
- if (bytes.length < HEADER_OFFSET) {
2853
- throw new VectorIndexError("Not a manni graph vector index: file is too short.");
3048
+ function chunkFile(ctx, language) {
3049
+ return language === null ? "" : ctx.manifest.languages[language]?.file ?? "";
3050
+ }
3051
+ function admit(ctx, iri, row, language, floor, trace) {
3052
+ const exported = floor.exported.get(iri);
3053
+ if (exported !== void 0) {
3054
+ trace.withheld.push({ node: iri, because: exported, at: "export" });
3055
+ return { kind: "withheld" };
3056
+ }
3057
+ const sourceUrl = row === void 0 ? chunkFile(ctx, language) : chunkFile(ctx, row.language);
3058
+ if (row === void 0) {
3059
+ trace.resolutions.push({ iri, sourceUrl, ok: false, error: "no chunk row" });
3060
+ return { kind: "skipped" };
3061
+ }
3062
+ const field = failedField(row, floor.where);
3063
+ if (field !== void 0) {
3064
+ trace.filtered.push({ node: iri, field });
3065
+ return { kind: "skipped" };
3066
+ }
3067
+ const because = floor.withhold.filter((reason) => withholds(row.provenance, reason));
3068
+ if (because.length > 0) {
3069
+ trace.withheld.push({ node: iri, because, at: "query" });
3070
+ return { kind: "withheld" };
3071
+ }
3072
+ trace.resolutions.push({ iri, sourceUrl, ok: true });
3073
+ return { kind: "row", row };
3074
+ }
3075
+ function floorOf(ctx, withhold, where) {
3076
+ return {
3077
+ withhold: withhold ?? [],
3078
+ where: where ?? [],
3079
+ exported: new Map(ctx.manifest.withheld.map((w) => [w.id, w.because]))
3080
+ };
3081
+ }
3082
+ function emptyTrace() {
3083
+ return { entry: { candidates: [] }, hops: [], exclusions: [], resolutions: [], withheld: [], filtered: [] };
3084
+ }
3085
+ async function selectMatches(ctx, entry, language, seeds, floor, trace) {
3086
+ const rows = await rowsFor(
3087
+ ctx,
3088
+ entry.ranked.filter((r) => r.row === void 0).map((r) => r.iri),
3089
+ language
3090
+ );
3091
+ const kept = [];
3092
+ let withheld = 0;
3093
+ for (const ranked of entry.ranked) {
3094
+ if (kept.length + withheld >= seeds) break;
3095
+ const row = ranked.row ?? rows.get(ranked.iri);
3096
+ if (row !== void 0 && row.graph !== ctx.manifest.graph) {
3097
+ throw new StaleArtifactError(ctx.manifest.graph, row.graph, chunkFile(ctx, language) || "a chunk row");
3098
+ }
3099
+ const admitted = admit(ctx, ranked.iri, row, language, floor, trace);
3100
+ if (admitted.kind === "skipped") continue;
3101
+ trace.entry.candidates.push({ iri: ranked.iri, score: ranked.fused, via: ranked.via });
3102
+ if (admitted.kind === "withheld") withheld += 1;
3103
+ else kept.push({ ranked, row: admitted.row, rank: kept.length + withheld + 1 });
3104
+ }
3105
+ return { kept, withheld };
3106
+ }
3107
+ function absorb(trace, walked) {
3108
+ trace.hops.push(...walked.hops);
3109
+ trace.exclusions.push(...walked.exclusions);
3110
+ }
3111
+ async function passagesOf(ctx, nodes, language, floor, trace) {
3112
+ const rows = await rowsFor(ctx, nodes.map((n) => n.iri), language);
3113
+ const out = [];
3114
+ for (const n of nodes) {
3115
+ const admitted = admit(ctx, n.iri, rows.get(n.iri), language, floor, trace);
3116
+ if (admitted.kind === "row") out.push({ iri: n.iri, depth: n.depth, row: admitted.row });
2854
3117
  }
2855
- const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
2856
- if (!MAGIC.every((byte, i) => bytes[i] === byte)) {
2857
- throw new VectorIndexError(
2858
- "Not a manni graph vector index: bad magic \u2014 is this the right file?"
2859
- );
3118
+ return out;
3119
+ }
3120
+ function edgeOf(graph, hop) {
3121
+ const predicate = graph.compact(hop.predicate);
3122
+ return hop.direction === "out" ? { from: hop.from, predicate, to: hop.to } : { from: hop.to, predicate, to: hop.from };
3123
+ }
3124
+ function languagesOf(manifest) {
3125
+ return Object.keys(manifest.languages).sort(byCodeUnit);
3126
+ }
3127
+ function languageNamed(manifest, tag) {
3128
+ const wanted = canonicalLanguageTag(tag);
3129
+ return languagesOf(manifest).find((l) => canonicalLanguageTag(l) === wanted);
3130
+ }
3131
+ function refusal(reason, detail) {
3132
+ return { reason, detail };
3133
+ }
3134
+ function scopeRefusal(ctx, scope) {
3135
+ if (scope.variant !== void 0 && resolveVariant(ctx.graph, scope.variant) === void 0) {
3136
+ return refusal("unknown-scope", `No product variant matches ${scope.variant}.`);
2860
3137
  }
2861
- const version = view.getUint32(4, true);
2862
- if (version !== FORMAT_VERSION) {
2863
- throw new VectorIndexError(
2864
- `Unsupported vector index version ${version} (this build reads ${FORMAT_VERSION}) \u2014 re-run \`manni graph embed\`.`
2865
- );
3138
+ if (scope.softwareSubject !== void 0 && resolveSubject(ctx.graph, scope.softwareSubject) === void 0) {
3139
+ return refusal("unknown-scope", `No software subject matches ${scope.softwareSubject}.`);
2866
3140
  }
2867
- const headerLength = view.getUint32(8, true);
2868
- if (HEADER_OFFSET + headerLength > bytes.length) {
2869
- throw new VectorIndexError("Vector index is truncated: header overruns.");
3141
+ if (scope.lang !== void 0 && languageNamed(ctx.manifest, scope.lang) === void 0) {
3142
+ const have = languagesOf(ctx.manifest).join(", ") || "none";
3143
+ return refusal("unknown-scope", `No localization ${scope.lang}; this corpus has ${have}.`);
2870
3144
  }
2871
- let header;
2872
- try {
2873
- header = JSON.parse(
2874
- new TextDecoder().decode(
2875
- bytes.subarray(HEADER_OFFSET, HEADER_OFFSET + headerLength)
2876
- )
2877
- );
2878
- } catch {
2879
- throw new VectorIndexError("Vector index header is not valid JSON.");
3145
+ return void 0;
3146
+ }
3147
+ function pagesOf(manifest, pages) {
3148
+ const out = {};
3149
+ for (const page of [...new Set(pages)].sort(byCodeUnit)) {
3150
+ out[page] = { metadata: manifest.pages[page]?.metadata ?? {} };
2880
3151
  }
2881
- if (!Array.isArray(header.ids) || typeof header.dims !== "number" || header.ids.length !== header.count) {
2882
- throw new VectorIndexError("Vector index header is malformed.");
3152
+ return out;
3153
+ }
3154
+ function bundleOf(ctx, head, language, items, maxChars, trace, empty) {
3155
+ const base = { ...head, language, trace };
3156
+ if (items.length === 0) {
3157
+ return { ...base, context: [], citations: [], pages: {}, truncated: false, refusal: empty };
2883
3158
  }
2884
- const start = HEADER_OFFSET + headerLength;
2885
- const expected = header.count * header.dims * 4;
2886
- if (bytes.length - start !== expected) {
2887
- throw new VectorIndexError(
2888
- `Vector index is truncated: expected ${expected} payload bytes, found ${bytes.length - start}.`
2889
- );
3159
+ const context = [];
3160
+ let used = 0;
3161
+ let truncated = false;
3162
+ for (const { row, depth, role } of items) {
3163
+ if (used + row.text.length > maxChars) {
3164
+ truncated = true;
3165
+ continue;
3166
+ }
3167
+ used += row.text.length;
3168
+ context.push({
3169
+ iri: row.id,
3170
+ title: row.title,
3171
+ text: row.text,
3172
+ sourceUrl: row.page,
3173
+ depth,
3174
+ page: row.page,
3175
+ provenance: row.provenance,
3176
+ role
3177
+ });
2890
3178
  }
2891
- const vectors = new Float32Array(header.count * header.dims);
2892
- for (let i = 0; i < vectors.length; i++) {
2893
- vectors[i] = view.getFloat32(start + i * 4, true);
3179
+ if (context.length === 0) {
3180
+ return {
3181
+ ...base,
3182
+ context: [],
3183
+ citations: [],
3184
+ pages: {},
3185
+ truncated,
3186
+ refusal: refusal("no-content", "Every matching passage exceeded the character budget.")
3187
+ };
2894
3188
  }
2895
- return { header, vectors };
3189
+ return {
3190
+ ...base,
3191
+ context,
3192
+ citations: context.map((b) => ({ iri: b.iri, title: b.title, sourceUrl: b.sourceUrl })),
3193
+ pages: pagesOf(ctx.manifest, context.map((b) => b.page)),
3194
+ truncated
3195
+ };
2896
3196
  }
2897
-
2898
- // src/graph/runtime/vector.ts
2899
- var VectorMismatchError = class extends Error {
2900
- reason;
2901
- constructor(mismatch) {
2902
- super(mismatch.detail);
2903
- this.name = "VectorMismatchError";
2904
- this.reason = mismatch.reason;
3197
+ function budget(passages, maxChars) {
3198
+ let used = 0;
3199
+ let cut = false;
3200
+ for (const p of passages) {
3201
+ const n = p.text?.length ?? 0;
3202
+ if (used + n > maxChars) {
3203
+ p.text = null;
3204
+ p.truncated = true;
3205
+ cut = true;
3206
+ } else {
3207
+ used += n;
3208
+ }
2905
3209
  }
2906
- };
2907
- async function searchIndexDigest(raw) {
2908
- const webCrypto = globalThis.crypto;
2909
- const subtle = webCrypto?.subtle;
2910
- if (!subtle) {
2911
- throw new Error(
2912
- "searchIndexDigest needs Web Crypto (globalThis.crypto.subtle), which is unavailable here \u2014 a page served over plain HTTP does not get it."
3210
+ return cut;
3211
+ }
3212
+ function passageOf(row) {
3213
+ return {
3214
+ iri: row.id,
3215
+ title: row.title,
3216
+ page: row.page,
3217
+ lines: row.lines,
3218
+ text: row.text,
3219
+ truncated: false,
3220
+ provenance: row.provenance
3221
+ };
3222
+ }
3223
+ async function retrieve(input) {
3224
+ const ctx = input;
3225
+ const trace = emptyTrace();
3226
+ const settings = ctx.manifest.retrieve;
3227
+ const seeds = input.seeds ?? settings.seeds;
3228
+ const depth = input.depth ?? settings.depth;
3229
+ const maxChars = input.maxChars ?? settings.maxChars;
3230
+ const head = { question: input.question };
3231
+ const refuse = (r, language2) => bundleOf(ctx, head, language2, [], maxChars, trace, r);
3232
+ const scope = scopeRefusal(ctx, input);
3233
+ if (scope !== void 0) return refuse(scope, null);
3234
+ const languages = languagesOf(ctx.manifest);
3235
+ const language = input.lang === void 0 ? languages[0] : languageNamed(ctx.manifest, input.lang);
3236
+ if (input.lang === void 0 && languages.length > 1) {
3237
+ return refuse(
3238
+ refusal("lang-required", `This corpus has more than one localization (${languages.join(", ")}); pass lang to choose one.`),
3239
+ null
2913
3240
  );
2914
3241
  }
2915
- const digest = await subtle.digest("SHA-256", new TextEncoder().encode(raw));
2916
- const hex = [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("");
2917
- return `sha256:${hex}`;
3242
+ if (language === void 0) return refuse(refusal("no-route", "This artifact holds no passages."), null);
3243
+ const where = input.where ?? [];
3244
+ const entry = await rank(ctx, input.question, language, input.mode, where);
3245
+ if (entry.fallback) trace.entry.fallback = "lexical";
3246
+ const floor = floorOf(ctx, input.withhold, where);
3247
+ const { kept, withheld } = await selectMatches(ctx, entry, language, seeds, floor, trace);
3248
+ if (kept.length === 0) {
3249
+ return refuse(
3250
+ withheld > 0 ? refusal("withheld", "Every match was withheld by the trust floor; trace.withheld names them.") : refusal("no-route", "No passage in the docs matches this question."),
3251
+ language
3252
+ );
3253
+ }
3254
+ const walked = createTrace();
3255
+ const { nodes } = traverse(ctx.graph, {
3256
+ seeds: kept.map((m) => m.row.id),
3257
+ depth,
3258
+ direction: "out",
3259
+ ...input.variant === void 0 ? {} : { variant: input.variant },
3260
+ ...input.softwareSubject === void 0 ? {} : { subject: input.softwareSubject },
3261
+ language,
3262
+ trace: walked
3263
+ });
3264
+ absorb(trace, walked);
3265
+ const inScope = new Set(nodes.filter((n) => n.depth === 0).map((n) => n.iri));
3266
+ const reached = await passagesOf(ctx, nodes.filter((n) => n.depth > 0), language, floor, trace);
3267
+ const items = [
3268
+ ...kept.filter((m) => inScope.has(m.row.id)).map((m) => ({ row: m.row, depth: 0, role: "match" })),
3269
+ ...reached.map((r) => ({ row: r.row, depth: r.depth, role: "context" }))
3270
+ ];
3271
+ return bundleOf(ctx, head, language, items, maxChars, trace, refusal("no-route", "Every match is outside the requested scope."));
2918
3272
  }
2919
- function createVectorIndex(bytes) {
2920
- const { header, vectors } = decodeVectorIndex(bytes);
2921
- const { dims, ids } = header;
3273
+ async function walkPassages(input) {
3274
+ const ctx = input;
3275
+ const trace = emptyTrace();
3276
+ const maxChars = input.maxChars ?? ctx.manifest.retrieve.maxChars;
3277
+ const node = ctx.graph.expand(input.node);
3278
+ const head = { node };
3279
+ const refuse = (r) => bundleOf(ctx, head, null, [], maxChars, trace, r);
3280
+ if (!ctx.graph.has(node)) return refuse(refusal("unknown-node", `No node ${input.node} in the graph.`));
3281
+ const scope = scopeRefusal(ctx, input);
3282
+ if (scope !== void 0) return refuse(scope);
3283
+ const language = input.lang === void 0 ? null : languageNamed(ctx.manifest, input.lang) ?? null;
3284
+ const walked = createTrace();
3285
+ const options = {
3286
+ ...input.depth === void 0 ? {} : { depth: input.depth },
3287
+ ...input.predicates === void 0 ? {} : { predicates: input.predicates },
3288
+ ...input.variant === void 0 ? {} : { variant: input.variant },
3289
+ ...input.softwareSubject === void 0 ? {} : { subject: input.softwareSubject },
3290
+ ...input.lang === void 0 ? {} : { language: input.lang },
3291
+ ...input.limit === void 0 ? {} : { limit: input.limit },
3292
+ trace: walked
3293
+ };
3294
+ const { nodes } = input.impact === true ? impact(ctx.graph, node, options) : traverse(ctx.graph, { ...options, seeds: [node], direction: input.reverse === true ? "in" : "out" });
3295
+ absorb(trace, walked);
3296
+ trace.entry.candidates.push({ iri: node, score: 1, via: "explicit" });
3297
+ const floor = floorOf(ctx, input.withhold, input.where);
3298
+ const start = await passagesOf(ctx, [{ iri: node, depth: 0 }], language, floor, trace);
3299
+ const reached = await passagesOf(ctx, nodes.filter((n) => n.iri !== node), language, floor, trace);
3300
+ const inward = input.impact === true || input.reverse === true;
3301
+ const items = [
3302
+ ...start.map((r) => ({ row: r.row, depth: 0, role: "match" })),
3303
+ ...reached.map((r) => ({ row: r.row, depth: r.depth, role: inward ? "dependent" : "context" }))
3304
+ ];
3305
+ const languageOut = language ?? start[0]?.row.language ?? null;
3306
+ return bundleOf(
3307
+ ctx,
3308
+ head,
3309
+ languageOut,
3310
+ items,
3311
+ maxChars,
3312
+ trace,
3313
+ refusal("no-route", "No passage was reachable from this node under the active scope filter.")
3314
+ );
3315
+ }
3316
+ async function lookup2(input) {
3317
+ const ctx = input;
3318
+ const trace = emptyTrace();
3319
+ const { seeds, depth, maxChars } = ctx.manifest.retrieve;
3320
+ const empty = (language2, r) => ({
3321
+ question: input.question,
3322
+ language: language2,
3323
+ matches: { passages: [], truncated: false },
3324
+ traversal: { passages: [], edges: [], truncated: false },
3325
+ impact: { passages: [], edges: [], truncated: false },
3326
+ pages: {},
3327
+ citations: [],
3328
+ trace,
3329
+ refusal: r
3330
+ });
3331
+ const choose = async (mode) => {
3332
+ const scores = {};
3333
+ let chosen;
3334
+ for (const language2 of languagesOf(ctx.manifest)) {
3335
+ const entry2 = await rank(ctx, input.question, language2, mode, []);
3336
+ if (entry2.best === void 0) continue;
3337
+ scores[language2] = entry2.best;
3338
+ if (chosen === void 0 || entry2.best > chosen.best) chosen = { language: language2, entry: entry2, best: entry2.best };
3339
+ }
3340
+ return { scores, chosen };
3341
+ };
3342
+ let picked = await choose("lexical");
3343
+ if (picked.chosen === void 0) picked = await choose(void 0);
3344
+ else picked.chosen.entry = await rank(ctx, input.question, picked.chosen.language, void 0, []);
3345
+ trace.entry.languages = picked.scores;
3346
+ if (picked.chosen === void 0) return empty(null, refusal("no-route", "No passage in the docs matches this question."));
3347
+ const { language, entry } = picked.chosen;
3348
+ trace.entry.chosen = language;
3349
+ if (entry.fallback) trace.entry.fallback = "lexical";
3350
+ const floor = floorOf(ctx, input.withhold, []);
3351
+ const { kept, withheld } = await selectMatches(ctx, entry, language, seeds, floor, trace);
3352
+ if (kept.length === 0) {
3353
+ return empty(
3354
+ language,
3355
+ withheld > 0 ? refusal("withheld", "Every match was withheld by the trust floor; trace.withheld names them.") : refusal("no-route", "No passage in the docs matches this question.")
3356
+ );
3357
+ }
3358
+ const seedIris = kept.map((m) => m.row.id);
3359
+ const walk = async (direction, reach) => {
3360
+ const walked = createTrace();
3361
+ const { nodes } = traverse(ctx.graph, { seeds: seedIris, depth: reach, direction, language, trace: walked });
3362
+ absorb(trace, walked);
3363
+ const reached = await passagesOf(ctx, nodes.filter((n) => n.depth > 0), language, floor, trace);
3364
+ const passages = reached.map((r) => ({ ...passageOf(r.row), depth: r.depth }));
3365
+ return {
3366
+ passages,
3367
+ edges: walked.hops.map((h) => edgeOf(ctx.graph, h)),
3368
+ truncated: budget(passages, maxChars)
3369
+ };
3370
+ };
3371
+ const matches = kept.map(
3372
+ (m) => ({
3373
+ ...passageOf(m.row),
3374
+ rank: m.rank,
3375
+ score: { lexical: m.ranked.lexical, vector: m.ranked.vector, fused: m.ranked.fused }
3376
+ })
3377
+ );
3378
+ const matchesTruncated = budget(matches, maxChars);
3379
+ const traversal = await walk("out", depth);
3380
+ const impact2 = await walk("in", IMPACT_DEPTH);
3381
+ const served = [...matches, ...traversal.passages, ...impact2.passages];
3382
+ const citations = [];
3383
+ const cited = /* @__PURE__ */ new Set();
3384
+ for (const p of served) {
3385
+ if (p.text === null || cited.has(p.iri)) continue;
3386
+ cited.add(p.iri);
3387
+ citations.push({ iri: p.iri, title: p.title, sourceUrl: p.page });
3388
+ }
2922
3389
  return {
2923
- model: header.model,
2924
- dtype: header.dtype,
2925
- dims,
2926
- source: header.source,
2927
- size: () => ids.length,
2928
- idAt: (row) => ids[row],
2929
- check(expected) {
2930
- if (expected.model !== void 0 && expected.model !== header.model) {
2931
- return {
2932
- reason: "model",
2933
- detail: `Vector index was built with ${header.model}, but the embedder is ${expected.model}. Re-run \`manni graph embed\`.`
2934
- };
2935
- }
2936
- if (expected.dtype !== void 0 && expected.dtype !== header.dtype) {
2937
- return {
2938
- reason: "dtype",
2939
- detail: `Vector index was built at dtype ${header.dtype}, but the embedder is at ${expected.dtype} \u2014 different weights are a different function. Re-run \`manni graph embed\`.`
2940
- };
2941
- }
2942
- if (expected.dims !== void 0 && expected.dims !== dims) {
2943
- return {
2944
- reason: "dims",
2945
- detail: `Vector index has ${dims} dimensions, but the embedder produces ${expected.dims}.`
2946
- };
2947
- }
2948
- if (expected.source !== void 0 && expected.source !== header.source) {
2949
- return {
2950
- reason: "stale-source",
2951
- detail: "Vector index was built from a different search index \u2014 the corpus changed. Re-run `manni graph embed`."
2952
- };
2953
- }
2954
- return void 0;
2955
- },
2956
- search(query, options = {}) {
2957
- if (dims === 0 || ids.length === 0) return [];
2958
- if (query.length !== dims) {
2959
- throw new VectorMismatchError({
2960
- reason: "dims",
2961
- detail: `Query vector has ${query.length} dimensions, but the index has ${dims}.`
2962
- });
2963
- }
2964
- const limit = normalizeLimit(options.limit);
2965
- if (limit === 0) return [];
2966
- const minScore = options.minScore ?? 0;
2967
- const q = normalize(Float32Array.from(query));
3390
+ question: input.question,
3391
+ language,
3392
+ matches: { passages: matches, truncated: matchesTruncated },
3393
+ traversal,
3394
+ impact: impact2,
3395
+ pages: pagesOf(ctx.manifest, served.map((p) => p.page)),
3396
+ citations,
3397
+ trace
3398
+ };
3399
+ }
3400
+ function createStaticVectorStore(rows) {
3401
+ return {
3402
+ query(q) {
3403
+ if (q.vector === null) return Promise.resolve([]);
3404
+ const query = normalize(Float32Array.from(q.vector));
2968
3405
  const scored = [];
2969
- for (const [row, iri] of ids.entries()) {
2970
- const stored = vectors.subarray(row * dims, (row + 1) * dims);
3406
+ for (const row of rows) {
3407
+ if (row.vector === void 0 || row.vector.length !== query.length) continue;
3408
+ if (q.language !== null && row.language !== q.language) continue;
3409
+ if (failedField(row, q.where) !== void 0) continue;
3410
+ const stored = normalize(Float32Array.from(row.vector));
2971
3411
  let score = 0;
2972
- for (const [i, value] of q.entries()) score += value * (stored[i] ?? 0);
2973
- if (score >= minScore) {
2974
- scored.push({ iri, score, via: "vector" });
2975
- }
3412
+ for (const [i, value] of query.entries()) score += value * (stored[i] ?? 0);
3413
+ scored.push({ id: row.id, score, row });
2976
3414
  }
2977
- scored.sort(
2978
- (a, b) => a.score === b.score ? byCodeUnit(a.iri, b.iri) : b.score - a.score
2979
- );
2980
- return scored.slice(0, limit);
3415
+ scored.sort((a, b) => a.score === b.score ? byCodeUnit(a.id, b.id) : b.score - a.score);
3416
+ return Promise.resolve(scored.slice(0, q.k));
2981
3417
  }
2982
3418
  };
2983
3419
  }
2984
- function normalizeLimit(limit) {
2985
- return typeof limit === "number" && Number.isInteger(limit) && limit >= 0 ? limit : 10;
3420
+ function createHttpVectorStore(options) {
3421
+ const doFetch = options.fetch ?? defaultFetch;
3422
+ return {
3423
+ async query(q) {
3424
+ const response = await doFetch(options.url, {
3425
+ method: "POST",
3426
+ headers: { "content-type": "application/json" },
3427
+ body: JSON.stringify({ text: q.text, vector: q.vector, k: q.k, language: q.language, where: q.where })
3428
+ });
3429
+ if (!response.ok) throw new Error(`${options.url} answered HTTP ${String(response.status)}.`);
3430
+ const body = JSON.parse(await response.text());
3431
+ if (!Array.isArray(body.matches)) throw new Error(`${options.url} returned no matches array.`);
3432
+ return body.matches.filter(isMatch);
3433
+ }
3434
+ };
2986
3435
  }
2987
-
2988
- // src/graph/runtime/entry.ts
2989
- function rrfMerge(rankings, k = 60) {
2990
- const fused = /* @__PURE__ */ new Map();
2991
- for (const ranking of rankings) {
2992
- ranking.forEach((candidate, i) => {
2993
- const current = fused.get(candidate.iri) ?? {
2994
- score: 0,
2995
- vias: /* @__PURE__ */ new Set()
2996
- };
2997
- current.score += 1 / (k + i + 1);
2998
- current.vias.add(candidate.via);
2999
- fused.set(candidate.iri, current);
3000
- });
3436
+ function isMatch(m) {
3437
+ if (typeof m !== "object" || m === null) return false;
3438
+ const o = m;
3439
+ return typeof o.id === "string" && typeof o.score === "number";
3440
+ }
3441
+ function parseChunkRows(text) {
3442
+ const rows = [];
3443
+ for (const [i, line] of text.split(/\r?\n/).entries()) {
3444
+ if (line.trim() === "") continue;
3445
+ const row = JSON.parse(line);
3446
+ if (!isChunkRow(row)) throw new Error(`Line ${String(i + 1)} is not a chunk row.`);
3447
+ rows.push(row);
3448
+ }
3449
+ return rows;
3450
+ }
3451
+ function isRecord2(v) {
3452
+ return typeof v === "object" && v !== null && !Array.isArray(v);
3453
+ }
3454
+ function isChunkRow(v) {
3455
+ return isRecord2(v) && ["id", "graph", "page", "lines", "language", "title", "text"].every((k) => typeof v[k] === "string") && (v.vector === void 0 || Array.isArray(v.vector)) && isRecord2(v.metadata) && isRecord2(v.provenance);
3456
+ }
3457
+ function parseChunksManifest(input) {
3458
+ const doc = typeof input === "string" ? JSON.parse(input) : input;
3459
+ const valid = isRecord2(doc) && doc.format === "manni-graph-chunks" && doc.version === 1 && ["graph", "graphFile", "searchIndex"].every((k) => typeof doc[k] === "string") && !("model" in doc) && isRecord2(doc.retrieve) && isRecord2(doc.pages) && Array.isArray(doc.withheld) && isRecord2(doc.languages) && Object.values(doc.languages).every((l) => isRecord2(l) && typeof l.file === "string" && isModel(l.model));
3460
+ if (!valid) throw new Error('Not a manni graph chunk manifest: expected format "manni-graph-chunks", version 1.');
3461
+ return doc;
3462
+ }
3463
+ function isModel(v) {
3464
+ return v === null || isRecord2(v) && typeof v.id === "string" && typeof v.dimensions === "number";
3465
+ }
3466
+ function createChunkFileSource(textOrUrl, options = {}) {
3467
+ const isText = textOrUrl.trim() === "" || textOrUrl.trimStart().startsWith("{");
3468
+ let rows;
3469
+ const load = () => rows ??= isText ? Promise.resolve(parseChunkRows(textOrUrl)) : fetchText(options.fetch ?? defaultFetch, textOrUrl).then(parseChunkRows);
3470
+ return {
3471
+ async get(ids, language) {
3472
+ const want = new Set(ids);
3473
+ return (await load()).filter((r) => want.has(r.id) && (language === null || r.language === language));
3474
+ }
3475
+ };
3476
+ }
3477
+ function defaultFetch(url, init) {
3478
+ return globalThis.fetch(url, init);
3479
+ }
3480
+ async function fetchText(doFetch, url) {
3481
+ const response = await doFetch(url);
3482
+ if (!response.ok) throw new Error(`${url} answered HTTP ${String(response.status)}.`);
3483
+ return response.text();
3484
+ }
3485
+ function artifactContext(manifest, graph, read, seams) {
3486
+ const embedders = /* @__PURE__ */ new Map();
3487
+ const embedder = (model) => {
3488
+ let pending = embedders.get(model.id);
3489
+ if (pending === void 0) {
3490
+ pending = seams.embedder(model);
3491
+ embedders.set(model.id, pending);
3492
+ }
3493
+ return pending;
3494
+ };
3495
+ const loaded = /* @__PURE__ */ new Map();
3496
+ const rowsOf = (language) => {
3497
+ let pending = loaded.get(language);
3498
+ if (pending === void 0) {
3499
+ const entry = manifest.languages[language];
3500
+ pending = entry === void 0 ? Promise.resolve([]) : read(entry.file).then(parseChunkRows);
3501
+ loaded.set(language, pending);
3502
+ }
3503
+ return pending;
3504
+ };
3505
+ const allRows = async (language) => language === null ? (await Promise.all(languagesOf(manifest).map(rowsOf))).flat() : rowsOf(language);
3506
+ const chunks = seams.chunks ?? {
3507
+ async get(ids, language) {
3508
+ const want = new Set(ids);
3509
+ return (await allRows(language)).filter((r) => want.has(r.id));
3510
+ }
3511
+ };
3512
+ const store = seams.store ?? {
3513
+ async query(q) {
3514
+ return createStaticVectorStore(await allRows(q.language)).query(q);
3515
+ }
3516
+ };
3517
+ let localizations;
3518
+ const lexicons = /* @__PURE__ */ new Map();
3519
+ const lexical = (language) => {
3520
+ let pending = lexicons.get(language);
3521
+ if (pending === void 0) {
3522
+ pending = (async () => {
3523
+ localizations ??= read(manifest.searchIndex).then(parseLocalizations);
3524
+ const doc = await localizations;
3525
+ const wanted = canonicalLanguageTag(language);
3526
+ const entry = doc?.languages.find((l) => canonicalLanguageTag(l.language) === wanted);
3527
+ return entry === void 0 ? void 0 : createLexicalIndex(await read(entry.search.path));
3528
+ })();
3529
+ lexicons.set(language, pending);
3530
+ }
3531
+ return pending;
3532
+ };
3533
+ return { manifest, graph, lexical, store, chunks, embedder };
3534
+ }
3535
+ async function defaultEmbedder(model) {
3536
+ try {
3537
+ const specifier = "./embed.js";
3538
+ const embed = await import(
3539
+ /* @vite-ignore */
3540
+ specifier
3541
+ );
3542
+ return model.id === "mock" ? embed.createMockEmbedder({ dims: model.dimensions }) : await embed.createLocalEmbedder({ model: model.id, role: "query" });
3543
+ } catch {
3544
+ return null;
3001
3545
  }
3002
- return [...fused.entries()].map(([iri, { score, vias }]) => {
3003
- const [only] = vias;
3004
- return {
3005
- iri,
3006
- score,
3007
- via: vias.size === 1 && only !== void 0 ? only : "hybrid"
3008
- };
3009
- }).sort(
3010
- (a, b) => a.score === b.score ? byCodeUnit(a.iri, b.iri) : b.score - a.score
3546
+ }
3547
+ async function createRetriever(options) {
3548
+ const doFetch = options.fetch ?? defaultFetch;
3549
+ const fromUrl = typeof options.manifest === "string";
3550
+ const manifest = parseChunksManifest(
3551
+ typeof options.manifest === "string" ? await fetchText(doFetch, options.manifest) : options.manifest
3011
3552
  );
3553
+ const base = typeof options.manifest === "string" ? options.manifest.slice(0, options.manifest.lastIndexOf("/") + 1) : "";
3554
+ const resolvePath = (path) => fromUrl && !/^[a-z][a-z0-9+.-]*:/i.test(path) ? base + path : path;
3555
+ const read = (path) => fetchText(doFetch, resolvePath(path));
3556
+ const graphText = await read(manifest.graphFile);
3557
+ const digest = `sha256-${(await searchIndexDigest(graphText)).slice("sha256:".length)}`;
3558
+ if (digest !== manifest.graph) throw new StaleArtifactError(manifest.graph, digest);
3559
+ const graph = GraphIndex.fromJsonLd(graphText);
3560
+ const embed = options.embed;
3561
+ const embedder = embed === false ? () => Promise.resolve(null) : embed === void 0 ? defaultEmbedder : () => Promise.resolve(embed);
3562
+ const ctx = artifactContext(manifest, graph, read, {
3563
+ ...options.store === void 0 ? {} : { store: options.store },
3564
+ ...options.chunks === void 0 ? {} : { chunks: options.chunks },
3565
+ embedder
3566
+ });
3567
+ return {
3568
+ manifest,
3569
+ lookup: (question) => lookup2({ ...ctx, question }),
3570
+ retrieve: (question, o = {}) => retrieve({ ...ctx, ...o, question }),
3571
+ traverse: (node, o = {}) => walkPassages({ ...ctx, ...o, node }),
3572
+ impact: (node, o = {}) => walkPassages({ ...ctx, ...o, node, impact: true })
3573
+ };
3012
3574
  }
3013
- async function findEntry(query, options) {
3014
- const trace = options.trace ?? createTrace();
3015
- const limit = typeof options.limit === "number" && Number.isInteger(options.limit) && options.limit >= 0 ? options.limit : 10;
3016
- const lexical = options.lexical.search(query, { limit });
3017
- const embedder = options.embedder;
3018
- const embed = embedder ? (q) => embedder.embed(q) : options.embedQuery;
3019
- let vector = [];
3020
- if (options.vectors && embed && query.trim() !== "") {
3021
- const mismatch = options.vectors.check({
3022
- ...options.embedder ? { model: options.embedder.model, dtype: options.embedder.dtype } : {},
3023
- // Staleness is checked whichever way the query is embedded — it is a
3024
- // property of the corpus, not of the embedder, so even the unverified
3025
- // `embedQuery` path gets it when the caller supplies a digest.
3026
- ...options.source === void 0 ? {} : { source: options.source }
3027
- });
3028
- if (mismatch) throw new VectorMismatchError(mismatch);
3029
- const queryVector = await embed(query);
3030
- vector = options.vectors.search(queryVector, { limit });
3575
+
3576
+ // src/graph/runtime/rdfjs.ts
3577
+ var XSD_STRING2 = "http://www.w3.org/2001/XMLSchema#string";
3578
+ var RDF_LANG_STRING = "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString";
3579
+ function namedNode(value) {
3580
+ return {
3581
+ termType: "NamedNode",
3582
+ value,
3583
+ equals(other) {
3584
+ return !!other && other.termType === "NamedNode" && other.value === value;
3585
+ }
3586
+ };
3587
+ }
3588
+ function defaultGraph() {
3589
+ return {
3590
+ termType: "DefaultGraph",
3591
+ value: "",
3592
+ equals(other) {
3593
+ return !!other && other.termType === "DefaultGraph";
3594
+ }
3595
+ };
3596
+ }
3597
+ function literal(value, datatype, language) {
3598
+ const lang = language ?? "";
3599
+ const dt = namedNode(lang ? RDF_LANG_STRING : datatype ?? XSD_STRING2);
3600
+ return {
3601
+ termType: "Literal",
3602
+ value,
3603
+ language: lang,
3604
+ datatype: dt,
3605
+ equals(other) {
3606
+ return !!other && other.termType === "Literal" && other.value === value && (other.language ?? "") === lang && !!other.datatype && other.datatype.value === dt.value;
3607
+ }
3608
+ };
3609
+ }
3610
+ function toTerm(v) {
3611
+ return v.kind === "iri" ? namedNode(v.value) : literal(v.value, v.datatype, v.language);
3612
+ }
3613
+ function makeQuad(s, p, o) {
3614
+ const subject = namedNode(s);
3615
+ const predicate = namedNode(p);
3616
+ const object = toTerm(o);
3617
+ const graph = defaultGraph();
3618
+ return {
3619
+ termType: "Quad",
3620
+ subject,
3621
+ predicate,
3622
+ object,
3623
+ graph,
3624
+ equals(other) {
3625
+ return !!other && subject.equals(other.subject) && predicate.equals(other.predicate) && object.equals(other.object);
3626
+ }
3627
+ };
3628
+ }
3629
+ function rdfjsQuads(graph) {
3630
+ const quads = [];
3631
+ for (const s of graph.ids()) {
3632
+ const node = graph.node(s);
3633
+ if (!node) continue;
3634
+ for (const p of [...node.props.keys()].sort(byCodeUnit)) {
3635
+ for (const v of node.props.get(p) ?? []) quads.push(makeQuad(s, p, v));
3636
+ }
3031
3637
  }
3032
- const rankings = vector.length > 0 ? [lexical, vector] : [lexical];
3033
- const candidates = rrfMerge(rankings).slice(0, limit);
3034
- for (const candidate of candidates) trace.entry.push(candidate);
3035
- return { candidates, lexical, vector, trace };
3638
+ return quads;
3639
+ }
3640
+ function matchQuads(graph, subject, predicate, object) {
3641
+ const quads = [];
3642
+ const subjects = subject ? [subject] : graph.ids();
3643
+ for (const s of subjects) {
3644
+ const node = graph.node(s);
3645
+ if (!node) continue;
3646
+ const predicates = predicate ? [predicate] : [...node.props.keys()].sort(byCodeUnit);
3647
+ for (const p of predicates) {
3648
+ for (const v of node.props.get(p) ?? []) {
3649
+ if (object !== void 0 && object !== null && v.value !== object) {
3650
+ continue;
3651
+ }
3652
+ quads.push(makeQuad(s, p, v));
3653
+ }
3654
+ }
3655
+ }
3656
+ return quads;
3036
3657
  }
3037
3658
  export {
3038
3659
  GraphIndex,
3039
3660
  LOCALIZATIONS_FILENAME,
3661
+ ModelMismatchError,
3662
+ StaleArtifactError,
3040
3663
  UNDETERMINED,
3041
3664
  VectorIndexError,
3042
3665
  VectorMismatchError,
3043
3666
  assemble,
3667
+ createChunkFileSource,
3044
3668
  createFetchResolver,
3669
+ createHttpVectorStore,
3045
3670
  createLexicalIndex,
3671
+ createRetriever,
3672
+ createStaticVectorStore,
3046
3673
  createTrace,
3047
3674
  createVectorIndex,
3048
3675
  decodeVectorIndex,
@@ -3054,14 +3681,18 @@ export {
3054
3681
  findEntry,
3055
3682
  impact,
3056
3683
  literal,
3684
+ lookup2 as lookup,
3057
3685
  matchQuads,
3058
3686
  namedNode,
3059
3687
  normalize,
3688
+ parseChunkRows,
3689
+ parseChunksManifest,
3060
3690
  parseLocalizations,
3061
3691
  rdfjsQuads,
3062
3692
  reachedNodes,
3063
3693
  resolveSubject,
3064
3694
  resolveVariant,
3695
+ retrieve,
3065
3696
  reverseReferences,
3066
3697
  rrfMerge,
3067
3698
  scopeExclusion,