@hawkeyexl/manni 4.14.0 → 4.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/README.md +11 -7
  2. package/dist/{batch-TKNIUBLK.js → batch-L5W4JS7A.js} +13 -13
  3. package/dist/{build-6G7PEAG4.js → build-GNZUVDZX.js} +13 -13
  4. package/dist/{calibrate-BDCXDZV5.js → calibrate-2LYIDN6U.js} +14 -14
  5. package/dist/{capture-NQJLZD66.js → capture-OEDMFU5Z.js} +13 -13
  6. package/dist/{check-QIZCTAIR.js → check-JR2TYL2Y.js} +14 -14
  7. package/dist/{check-552X5I2J.js → check-LVO4HZ3F.js} +14 -14
  8. package/dist/{check-5HMDJOFP.js → check-NLLFHNWG.js} +13 -13
  9. package/dist/{check-BSB4FF4L.js → check-Z5VGDSDT.js} +12 -12
  10. package/dist/{chunk-BA4TCCOO.js → chunk-2AUULNIJ.js} +3 -3
  11. package/dist/{chunk-AJYUJ37M.js → chunk-2XRET3ZG.js} +17 -10
  12. package/dist/chunk-2XRET3ZG.js.map +1 -0
  13. package/dist/{chunk-36FJWJSK.js → chunk-3GLDB7MZ.js} +2 -2
  14. package/dist/{chunk-4U3X7LYV.js → chunk-3WZQ2FR3.js} +4 -4
  15. package/dist/{chunk-Y36PNW6J.js → chunk-4HEEXPVX.js} +6 -6
  16. package/dist/{chunk-EXAZ7K25.js → chunk-4L3JBAW4.js} +2 -2
  17. package/dist/{chunk-V6OCE4ND.js → chunk-4LLYPDNG.js} +7 -7
  18. package/dist/{chunk-PCE7QHXJ.js → chunk-5D24C6WM.js} +6 -1
  19. package/dist/chunk-5D24C6WM.js.map +1 -0
  20. package/dist/{chunk-T3BBNLAT.js → chunk-5OOQ3HQ3.js} +2 -2
  21. package/dist/{chunk-T3BBNLAT.js.map → chunk-5OOQ3HQ3.js.map} +1 -1
  22. package/dist/{chunk-2A6XYSXO.js → chunk-5PO2BWZF.js} +2 -2
  23. package/dist/{chunk-GHZAOPGK.js → chunk-63GILHR5.js} +4 -4
  24. package/dist/{chunk-3MTZZJKH.js → chunk-6ANTGYNT.js} +2 -2
  25. package/dist/{chunk-3BMTCS4H.js → chunk-6NTNLKNQ.js} +3 -3
  26. package/dist/{chunk-7WVWGULD.js → chunk-6YFEV7CM.js} +5 -5
  27. package/dist/{chunk-QEZQ7MGH.js → chunk-7GB3KEEM.js} +4 -4
  28. package/dist/chunk-7GB3KEEM.js.map +1 -0
  29. package/dist/{chunk-VBBJGFME.js → chunk-7UC55CAU.js} +4 -4
  30. package/dist/{chunk-2HQSMZ4N.js → chunk-AWAXAJ6R.js} +2 -2
  31. package/dist/{chunk-STM3G7WJ.js → chunk-B3XXCDYW.js} +4 -4
  32. package/dist/{chunk-JWBS7YDI.js → chunk-BMYCLTFK.js} +3 -3
  33. package/dist/{chunk-USKTLEPZ.js → chunk-CSLJMML4.js} +3 -3
  34. package/dist/{chunk-D2TIZOMN.js → chunk-D4ANAOY7.js} +3 -3
  35. package/dist/{chunk-Y37VJFX2.js → chunk-DSTRT6YD.js} +3 -3
  36. package/dist/{chunk-ZPLIXZZ6.js → chunk-DTG6S2UG.js} +2 -2
  37. package/dist/{chunk-W5DO426O.js → chunk-DW22KCLN.js} +5 -6
  38. package/dist/chunk-DW22KCLN.js.map +1 -0
  39. package/dist/{chunk-742G2QCV.js → chunk-EA5KKIFG.js} +3 -3
  40. package/dist/{chunk-742G2QCV.js.map → chunk-EA5KKIFG.js.map} +1 -1
  41. package/dist/{chunk-LCRBR7KW.js → chunk-EOSQENQF.js} +2 -2
  42. package/dist/{chunk-ZRQUQS7P.js → chunk-EZCJPF72.js} +3 -3
  43. package/dist/{chunk-JTEWU4C6.js → chunk-F4GXZMEO.js} +7 -6
  44. package/dist/chunk-F4GXZMEO.js.map +1 -0
  45. package/dist/{chunk-WIPTWZVH.js → chunk-F6B2TNXU.js} +5 -5
  46. package/dist/{chunk-BAWKNF6U.js → chunk-FU3OCYYH.js} +2 -2
  47. package/dist/{chunk-6XFSZCLT.js → chunk-GC47NBGO.js} +4 -4
  48. package/dist/{chunk-56URKBXQ.js → chunk-GQQ2AX63.js} +23 -14
  49. package/dist/chunk-GQQ2AX63.js.map +1 -0
  50. package/dist/{chunk-HGU4FDRY.js → chunk-GR6QQ7GM.js} +4 -4
  51. package/dist/{chunk-W6B24IMO.js → chunk-IL62WATF.js} +2 -2
  52. package/dist/{chunk-MIGFQP5N.js → chunk-IM67NRUW.js} +2 -2
  53. package/dist/{chunk-7AXJY4FX.js → chunk-L3YGGYBG.js} +3 -3
  54. package/dist/{chunk-A7MNH4YI.js → chunk-LEOQO3S6.js} +7 -7
  55. package/dist/{chunk-M534DYAJ.js → chunk-LPBVWUKS.js} +2 -2
  56. package/dist/{chunk-6VT3Z352.js → chunk-NDBISART.js} +67 -4
  57. package/dist/chunk-NDBISART.js.map +1 -0
  58. package/dist/{chunk-7PENJOI6.js → chunk-NFJGIBES.js} +6 -6
  59. package/dist/{chunk-3CCY7M3R.js → chunk-NH6B6DDI.js} +4 -4
  60. package/dist/{chunk-CZJNYHK7.js → chunk-O6YTTBSN.js} +2 -2
  61. package/dist/{chunk-66MKBRTA.js → chunk-OJ7FEM2G.js} +6 -6
  62. package/dist/{chunk-M43NTWVH.js → chunk-PBZZUNDV.js} +5 -5
  63. package/dist/{chunk-B6GUSA53.js → chunk-PHNAQ4QX.js} +489 -15
  64. package/dist/chunk-PHNAQ4QX.js.map +1 -0
  65. package/dist/{chunk-BIRGZEWO.js → chunk-WD33LE5A.js} +2 -2
  66. package/dist/{chunk-7KOWE4F4.js → chunk-WT3AATHC.js} +8 -8
  67. package/dist/{chunk-YJ3EG2D5.js → chunk-YF6IZXAC.js} +3 -3
  68. package/dist/{chunk-IOYEPB27.js → chunk-ZJZQPOJO.js} +2 -2
  69. package/dist/{chunk-QF7EIRMU.js → chunk-ZT5NUSZA.js} +541 -343
  70. package/dist/chunk-ZT5NUSZA.js.map +1 -0
  71. package/dist/{cli-SOA2E26G.js → cli-2EKRURBU.js} +14 -14
  72. package/dist/{cli-X6IWTDFK.js → cli-2SDBEUER.js} +20 -20
  73. package/dist/{cli-7QHJW5GH.js → cli-4Y2XY52B.js} +2 -2
  74. package/dist/{cli-IKDX2I5X.js → cli-5QTSTGTX.js} +15 -15
  75. package/dist/{cli-5XKHMRZ5.js → cli-BXUZ3KEQ.js} +16 -16
  76. package/dist/{cli-LOND37OA.js → cli-DBMPGGOV.js} +36 -36
  77. package/dist/{cli-QTLOAVOY.js → cli-KAUXC7EZ.js} +9 -9
  78. package/dist/{cli-BUV3DRUH.js → cli-LZW6Z33F.js} +79 -19
  79. package/dist/cli-LZW6Z33F.js.map +1 -0
  80. package/dist/{cli-O6Y2KVWD.js → cli-RWRYV5FB.js} +9 -9
  81. package/dist/{cli-XAT673VB.js → cli-THEU2QG2.js} +2 -2
  82. package/dist/{cli-VQYB3663.js → cli-TZ2OHF3H.js} +18 -18
  83. package/dist/cli.js +14 -14
  84. package/dist/docmeta.js +8 -8
  85. package/dist/{github-IPBOTQBN.js → github-ICZ5UDGX.js} +14 -14
  86. package/dist/{github-XM36D7ZH.js → github-UR6LMUMW.js} +12 -12
  87. package/dist/index.d.ts +130 -25
  88. package/dist/index.js +38 -38
  89. package/dist/{json-7WV7KL6H.js → json-5EQCGVCV.js} +4 -2
  90. package/dist/{json-225TND7K.js → json-QTYN2JQB.js} +12 -12
  91. package/dist/{labels-CTLHIRC4.js → labels-UM2AFR5S.js} +11 -11
  92. package/dist/{lint-NP3PC3SO.js → lint-LOFNZZPR.js} +12 -12
  93. package/dist/{list-JJGNKO6S.js → list-EPMHOU7T.js} +12 -12
  94. package/dist/{list-Q457TIMA.js → list-GU7S6KEX.js} +12 -12
  95. package/dist/{page-FJW7J2EU.js → page-25CN3AFY.js} +11 -11
  96. package/dist/{prepare-RKJEKHAG.js → prepare-5GYMBF4P.js} +12 -12
  97. package/dist/{pretty-ECBO3EVT.js → pretty-52Z74O6F.js} +21 -15
  98. package/dist/{pretty-QFEN2SIA.js → pretty-QW6OSYRS.js} +12 -12
  99. package/dist/{reporters-IKKL5RHS.js → reporters-3FXX2W4X.js} +11 -11
  100. package/dist/{reporters-TDQDQHKE.js → reporters-FSXJ42EB.js} +2 -2
  101. package/dist/{reporters-WGLQKW2Y.js → reporters-WT53GD4P.js} +4 -4
  102. package/dist/{run-BTETGGLW.js → run-H7XJMUWK.js} +13 -13
  103. package/dist/{sarif-K4SMB563.js → sarif-C427U3NA.js} +10 -10
  104. package/dist/{sarif-ZHFK6PZY.js → sarif-UVAFWZKS.js} +15 -15
  105. package/dist/{term-2M7APX2A.js → term-VG65JRNR.js} +17 -17
  106. package/dist/{validate-GBM5STKS.js → validate-K36F54UB.js} +5 -5
  107. package/package.json +1 -1
  108. package/plugin/manni/.claude-plugin/plugin.json +1 -1
  109. package/dist/chunk-56URKBXQ.js.map +0 -1
  110. package/dist/chunk-6VT3Z352.js.map +0 -1
  111. package/dist/chunk-AJYUJ37M.js.map +0 -1
  112. package/dist/chunk-B6GUSA53.js.map +0 -1
  113. package/dist/chunk-JTEWU4C6.js.map +0 -1
  114. package/dist/chunk-PCE7QHXJ.js.map +0 -1
  115. package/dist/chunk-QEZQ7MGH.js.map +0 -1
  116. package/dist/chunk-QF7EIRMU.js.map +0 -1
  117. package/dist/chunk-W5DO426O.js.map +0 -1
  118. package/dist/cli-BUV3DRUH.js.map +0 -1
  119. /package/dist/{batch-TKNIUBLK.js.map → batch-L5W4JS7A.js.map} +0 -0
  120. /package/dist/{build-6G7PEAG4.js.map → build-GNZUVDZX.js.map} +0 -0
  121. /package/dist/{calibrate-BDCXDZV5.js.map → calibrate-2LYIDN6U.js.map} +0 -0
  122. /package/dist/{capture-NQJLZD66.js.map → capture-OEDMFU5Z.js.map} +0 -0
  123. /package/dist/{check-QIZCTAIR.js.map → check-JR2TYL2Y.js.map} +0 -0
  124. /package/dist/{check-552X5I2J.js.map → check-LVO4HZ3F.js.map} +0 -0
  125. /package/dist/{check-5HMDJOFP.js.map → check-NLLFHNWG.js.map} +0 -0
  126. /package/dist/{check-BSB4FF4L.js.map → check-Z5VGDSDT.js.map} +0 -0
  127. /package/dist/{chunk-BA4TCCOO.js.map → chunk-2AUULNIJ.js.map} +0 -0
  128. /package/dist/{chunk-36FJWJSK.js.map → chunk-3GLDB7MZ.js.map} +0 -0
  129. /package/dist/{chunk-4U3X7LYV.js.map → chunk-3WZQ2FR3.js.map} +0 -0
  130. /package/dist/{chunk-Y36PNW6J.js.map → chunk-4HEEXPVX.js.map} +0 -0
  131. /package/dist/{chunk-EXAZ7K25.js.map → chunk-4L3JBAW4.js.map} +0 -0
  132. /package/dist/{chunk-V6OCE4ND.js.map → chunk-4LLYPDNG.js.map} +0 -0
  133. /package/dist/{chunk-2A6XYSXO.js.map → chunk-5PO2BWZF.js.map} +0 -0
  134. /package/dist/{chunk-GHZAOPGK.js.map → chunk-63GILHR5.js.map} +0 -0
  135. /package/dist/{chunk-3MTZZJKH.js.map → chunk-6ANTGYNT.js.map} +0 -0
  136. /package/dist/{chunk-3BMTCS4H.js.map → chunk-6NTNLKNQ.js.map} +0 -0
  137. /package/dist/{chunk-7WVWGULD.js.map → chunk-6YFEV7CM.js.map} +0 -0
  138. /package/dist/{chunk-VBBJGFME.js.map → chunk-7UC55CAU.js.map} +0 -0
  139. /package/dist/{chunk-2HQSMZ4N.js.map → chunk-AWAXAJ6R.js.map} +0 -0
  140. /package/dist/{chunk-STM3G7WJ.js.map → chunk-B3XXCDYW.js.map} +0 -0
  141. /package/dist/{chunk-JWBS7YDI.js.map → chunk-BMYCLTFK.js.map} +0 -0
  142. /package/dist/{chunk-USKTLEPZ.js.map → chunk-CSLJMML4.js.map} +0 -0
  143. /package/dist/{chunk-D2TIZOMN.js.map → chunk-D4ANAOY7.js.map} +0 -0
  144. /package/dist/{chunk-Y37VJFX2.js.map → chunk-DSTRT6YD.js.map} +0 -0
  145. /package/dist/{chunk-ZPLIXZZ6.js.map → chunk-DTG6S2UG.js.map} +0 -0
  146. /package/dist/{chunk-LCRBR7KW.js.map → chunk-EOSQENQF.js.map} +0 -0
  147. /package/dist/{chunk-ZRQUQS7P.js.map → chunk-EZCJPF72.js.map} +0 -0
  148. /package/dist/{chunk-WIPTWZVH.js.map → chunk-F6B2TNXU.js.map} +0 -0
  149. /package/dist/{chunk-BAWKNF6U.js.map → chunk-FU3OCYYH.js.map} +0 -0
  150. /package/dist/{chunk-6XFSZCLT.js.map → chunk-GC47NBGO.js.map} +0 -0
  151. /package/dist/{chunk-HGU4FDRY.js.map → chunk-GR6QQ7GM.js.map} +0 -0
  152. /package/dist/{chunk-W6B24IMO.js.map → chunk-IL62WATF.js.map} +0 -0
  153. /package/dist/{chunk-MIGFQP5N.js.map → chunk-IM67NRUW.js.map} +0 -0
  154. /package/dist/{chunk-7AXJY4FX.js.map → chunk-L3YGGYBG.js.map} +0 -0
  155. /package/dist/{chunk-A7MNH4YI.js.map → chunk-LEOQO3S6.js.map} +0 -0
  156. /package/dist/{chunk-M534DYAJ.js.map → chunk-LPBVWUKS.js.map} +0 -0
  157. /package/dist/{chunk-7PENJOI6.js.map → chunk-NFJGIBES.js.map} +0 -0
  158. /package/dist/{chunk-3CCY7M3R.js.map → chunk-NH6B6DDI.js.map} +0 -0
  159. /package/dist/{chunk-CZJNYHK7.js.map → chunk-O6YTTBSN.js.map} +0 -0
  160. /package/dist/{chunk-66MKBRTA.js.map → chunk-OJ7FEM2G.js.map} +0 -0
  161. /package/dist/{chunk-M43NTWVH.js.map → chunk-PBZZUNDV.js.map} +0 -0
  162. /package/dist/{chunk-BIRGZEWO.js.map → chunk-WD33LE5A.js.map} +0 -0
  163. /package/dist/{chunk-7KOWE4F4.js.map → chunk-WT3AATHC.js.map} +0 -0
  164. /package/dist/{chunk-YJ3EG2D5.js.map → chunk-YF6IZXAC.js.map} +0 -0
  165. /package/dist/{chunk-IOYEPB27.js.map → chunk-ZJZQPOJO.js.map} +0 -0
  166. /package/dist/{cli-SOA2E26G.js.map → cli-2EKRURBU.js.map} +0 -0
  167. /package/dist/{cli-X6IWTDFK.js.map → cli-2SDBEUER.js.map} +0 -0
  168. /package/dist/{cli-7QHJW5GH.js.map → cli-4Y2XY52B.js.map} +0 -0
  169. /package/dist/{cli-IKDX2I5X.js.map → cli-5QTSTGTX.js.map} +0 -0
  170. /package/dist/{cli-5XKHMRZ5.js.map → cli-BXUZ3KEQ.js.map} +0 -0
  171. /package/dist/{cli-LOND37OA.js.map → cli-DBMPGGOV.js.map} +0 -0
  172. /package/dist/{cli-QTLOAVOY.js.map → cli-KAUXC7EZ.js.map} +0 -0
  173. /package/dist/{cli-O6Y2KVWD.js.map → cli-RWRYV5FB.js.map} +0 -0
  174. /package/dist/{cli-XAT673VB.js.map → cli-THEU2QG2.js.map} +0 -0
  175. /package/dist/{cli-VQYB3663.js.map → cli-TZ2OHF3H.js.map} +0 -0
  176. /package/dist/{github-IPBOTQBN.js.map → github-ICZ5UDGX.js.map} +0 -0
  177. /package/dist/{github-XM36D7ZH.js.map → github-UR6LMUMW.js.map} +0 -0
  178. /package/dist/{json-225TND7K.js.map → json-5EQCGVCV.js.map} +0 -0
  179. /package/dist/{json-7WV7KL6H.js.map → json-QTYN2JQB.js.map} +0 -0
  180. /package/dist/{labels-CTLHIRC4.js.map → labels-UM2AFR5S.js.map} +0 -0
  181. /package/dist/{lint-NP3PC3SO.js.map → lint-LOFNZZPR.js.map} +0 -0
  182. /package/dist/{list-JJGNKO6S.js.map → list-EPMHOU7T.js.map} +0 -0
  183. /package/dist/{list-Q457TIMA.js.map → list-GU7S6KEX.js.map} +0 -0
  184. /package/dist/{page-FJW7J2EU.js.map → page-25CN3AFY.js.map} +0 -0
  185. /package/dist/{prepare-RKJEKHAG.js.map → prepare-5GYMBF4P.js.map} +0 -0
  186. /package/dist/{pretty-ECBO3EVT.js.map → pretty-52Z74O6F.js.map} +0 -0
  187. /package/dist/{pretty-QFEN2SIA.js.map → pretty-QW6OSYRS.js.map} +0 -0
  188. /package/dist/{reporters-IKKL5RHS.js.map → reporters-3FXX2W4X.js.map} +0 -0
  189. /package/dist/{reporters-TDQDQHKE.js.map → reporters-FSXJ42EB.js.map} +0 -0
  190. /package/dist/{reporters-WGLQKW2Y.js.map → reporters-WT53GD4P.js.map} +0 -0
  191. /package/dist/{run-BTETGGLW.js.map → run-H7XJMUWK.js.map} +0 -0
  192. /package/dist/{sarif-K4SMB563.js.map → sarif-C427U3NA.js.map} +0 -0
  193. /package/dist/{sarif-ZHFK6PZY.js.map → sarif-UVAFWZKS.js.map} +0 -0
  194. /package/dist/{term-2M7APX2A.js.map → term-VG65JRNR.js.map} +0 -0
  195. /package/dist/{validate-GBM5STKS.js.map → validate-K36F54UB.js.map} +0 -0
@@ -14,7 +14,7 @@ import {
14
14
  toValidationResult,
15
15
  unitText,
16
16
  withRemedy
17
- } from "./chunk-AJYUJ37M.js";
17
+ } from "./chunk-2XRET3ZG.js";
18
18
  import {
19
19
  ANY_FENCE,
20
20
  CITE_RULES,
@@ -34,7 +34,7 @@ import {
34
34
  sliceLines,
35
35
  sourceRange,
36
36
  spellSource
37
- } from "./chunk-QEZQ7MGH.js";
37
+ } from "./chunk-7GB3KEEM.js";
38
38
  import {
39
39
  MAX_RANGE_LINES,
40
40
  MOVE_BUDGET_BYTES,
@@ -57,7 +57,7 @@ import {
57
57
  spellLines,
58
58
  splitLines,
59
59
  toBodyLines
60
- } from "./chunk-36FJWJSK.js";
60
+ } from "./chunk-3GLDB7MZ.js";
61
61
  import {
62
62
  STDIN_LABEL,
63
63
  STDIN_TOKEN,
@@ -71,7 +71,7 @@ import {
71
71
  resolveTargetSet,
72
72
  settleBaseline,
73
73
  supportedExtensions
74
- } from "./chunk-BIRGZEWO.js";
74
+ } from "./chunk-WD33LE5A.js";
75
75
  import {
76
76
  SEVERITIES
77
77
  } from "./chunk-77AINBYM.js";
@@ -95,6 +95,301 @@ import { existsSync as existsSync2 } from "node:fs";
95
95
  import { readFile as readFile2 } from "node:fs/promises";
96
96
  import { resolve as resolve3 } from "node:path";
97
97
 
98
+ // src/cite/core/history.ts
99
+ var MAX_PAGE_COMMITS = 256;
100
+ function stripMarkers(lines, format) {
101
+ return lines.filter((line) => !isMarkerLine(line, format));
102
+ }
103
+ function claimWords(lines, format) {
104
+ return stripMarkers(lines, format).join(" ").replace(/\s+/g, " ").trim();
105
+ }
106
+ function sentencesOf(text) {
107
+ return text.split(/(?<=[.!?])\s+/).map((sentence) => sentence.replace(/\s+/g, " ").trim().toLowerCase()).filter((sentence) => sentence !== "");
108
+ }
109
+ function sharesSentence(a, b) {
110
+ const left = new Set(sentencesOf(a));
111
+ return sentencesOf(b).some((sentence) => left.has(sentence));
112
+ }
113
+ function wordSet(text) {
114
+ return new Set(
115
+ text.toLowerCase().split(/\s+/).filter((word) => word !== "")
116
+ );
117
+ }
118
+ function wordShare(was, now) {
119
+ const left = wordSet(was);
120
+ if (left.size === 0) return 1;
121
+ const right = wordSet(now);
122
+ let held = 0;
123
+ for (const word of left) if (right.has(word)) held++;
124
+ return held / left.size;
125
+ }
126
+ function holdsWords(outer, inner) {
127
+ if (inner === "") return true;
128
+ if (outer === inner) return true;
129
+ if (outer.startsWith(`${inner} `)) return true;
130
+ if (outer.endsWith(` ${inner}`)) return true;
131
+ return outer.includes(` ${inner} `);
132
+ }
133
+ function runsHolding(lines, format, bodyLine, inner) {
134
+ if (inner === "") return [];
135
+ let text = "";
136
+ const at = [];
137
+ for (let n = Math.max(bodyLine, 1); n <= lines.length; n++) {
138
+ const line = lines[n - 1] ?? "";
139
+ if (isMarkerLine(line, format)) continue;
140
+ const words = line.replace(/\s+/g, " ").trim();
141
+ if (words === "") continue;
142
+ if (text !== "") {
143
+ text += " ";
144
+ at.push(n);
145
+ }
146
+ for (let i = 0; i < words.length; i++) at.push(n);
147
+ text += words;
148
+ }
149
+ const out = [];
150
+ let from = 0;
151
+ for (; ; ) {
152
+ const found = text.indexOf(inner, from);
153
+ if (found === -1) break;
154
+ from = found + 1;
155
+ const before = found === 0 ? " " : text[found - 1];
156
+ const afterAt = found + inner.length;
157
+ const after = afterAt === text.length ? " " : text[afterAt];
158
+ if (before !== " " || after !== " ") continue;
159
+ const start = at[found];
160
+ const end = at[afterAt - 1];
161
+ if (start === void 0 || end === void 0) continue;
162
+ if (!out.some((span) => span.start === start && span.end === end)) out.push({ start, end });
163
+ }
164
+ return out.filter(
165
+ (span) => !out.some(
166
+ (other) => (other.start !== span.start || other.end !== span.end) && other.start >= span.start && other.end <= span.end
167
+ )
168
+ );
169
+ }
170
+ function bounds(line) {
171
+ return line === void 0 || line.trim() === "" || ANY_FENCE.test(line);
172
+ }
173
+ function pinOf(lines, span) {
174
+ if (span.start < 1 || span.end > lines.length || span.end < span.start) return void 0;
175
+ return hashLines(lines.slice(span.start - 1, span.end).join("\n"));
176
+ }
177
+ function readThen(input, text) {
178
+ const then = readPage(input.page.file, text, { format: input.page.format });
179
+ const lines = splitLines(then.content);
180
+ if (input.entry.citation.claim?.lines !== void 0) return { page: then, lines };
181
+ const id = input.entry.citation.id;
182
+ if (id === void 0) return void 0;
183
+ const marker = then.statements.find(
184
+ (statement) => statement.payload.kind === "ref" && statement.payload.ids.includes(id)
185
+ );
186
+ if (marker === void 0) return void 0;
187
+ return { page: then, lines, marker };
188
+ }
189
+ function anchorHeldAt(input, then) {
190
+ const pin = input.entry.citation.claim?.integrity;
191
+ if (pin === void 0) return { kind: "absent" };
192
+ const was = {
193
+ citation: input.entry.citation,
194
+ origin: input.entry.origin,
195
+ ...then.marker === void 0 ? {} : { marker: then.marker }
196
+ };
197
+ const split = then.marker === void 0 ? void 0 : misplacedMarkerAt(then.page, then.lines, then.marker.line, was);
198
+ const end = claimEnd(then.page, was, then.lines, split);
199
+ if (end === null || end.status !== "current" && end.status !== "moved") {
200
+ return { kind: "absent" };
201
+ }
202
+ for (const spec of [end.fileLines, end.newFileLines]) {
203
+ const span = spec === void 0 ? void 0 : parseLines(spec);
204
+ if (span !== void 0 && pinOf(then.lines, span) === pin) {
205
+ return { kind: "found", span, lines: then.lines.slice(span.start - 1, span.end) };
206
+ }
207
+ }
208
+ if (split !== void 0) {
209
+ const text = unitText(then.lines, split);
210
+ if (hashLines(text.join("\n")) === pin) {
211
+ return { kind: "found", span: movedUnit(split), lines: text };
212
+ }
213
+ }
214
+ return { kind: "absent" };
215
+ }
216
+ function windowHeldAt(input, then) {
217
+ const pin = input.entry.citation.claim?.integrity;
218
+ const marker = then.marker;
219
+ if (pin === void 0 || marker === void 0) return { kind: "absent" };
220
+ if (input.entry.citation.quote === true) return { kind: "absent" };
221
+ const lines = then.lines;
222
+ let stop = marker.line;
223
+ for (let n = marker.line + 1; n <= lines.length; n++) {
224
+ if (bounds(lines[n - 1])) break;
225
+ stop = n;
226
+ }
227
+ const starts = [marker.line];
228
+ for (let n = marker.line + 1; n <= stop; n++) {
229
+ const line = lines[n - 1] ?? "";
230
+ if (line.trim() === "" || isMarkerLine(line, then.page.format)) continue;
231
+ starts.push(n);
232
+ }
233
+ for (const start of starts) {
234
+ for (let end = start; end <= stop; end++) {
235
+ if (pinOf(lines, { start, end }) === pin) {
236
+ return { kind: "found", span: { start, end }, lines: lines.slice(start - 1, end) };
237
+ }
238
+ }
239
+ }
240
+ return { kind: "absent" };
241
+ }
242
+ async function stillWritten(input, commit, pageText) {
243
+ const pin = input.entry.citation.claim?.integrity;
244
+ if (pin === void 0) return { stop: true, born: true };
245
+ const manifest = input.manifest;
246
+ if (manifest !== void 0) {
247
+ const shown = await input.git.showFile(commit, manifest);
248
+ const held2 = "text" in shown && shown.text.includes(pin);
249
+ return { stop: !held2, born: !held2 };
250
+ }
251
+ const held = pageText.includes(pin);
252
+ return { stop: false, born: !held };
253
+ }
254
+ async function claimHistory(input) {
255
+ const { git, path } = input;
256
+ if (git.pageCommits === void 0) return { kind: "none" };
257
+ if (!await git.available()) return { kind: "none" };
258
+ const cap = input.cap ?? MAX_PAGE_COMMITS;
259
+ const history = await git.pageCommits(path, cap);
260
+ const { commits } = history;
261
+ if (commits.length === 0) return { kind: "none" };
262
+ const format = input.page.format;
263
+ const baselineAt = (index, then, found) => {
264
+ if (found.kind !== "found") return { kind: "none" };
265
+ const commit = commits[index];
266
+ if (commit === void 0) return { kind: "none" };
267
+ return {
268
+ kind: "baseline",
269
+ commit: commit.sha,
270
+ commitsSince: commits.slice(0, index).map((c) => c.subject),
271
+ words: claimWords(found.lines, format),
272
+ pageWords: claimWords(then.lines.slice(then.page.bodyLine - 1), format),
273
+ lines: found.lines,
274
+ at: spellLines(found.span)
275
+ };
276
+ };
277
+ const examined = [];
278
+ let ended = "cap";
279
+ let born = false;
280
+ for (let i = 0; i < commits.length; i++) {
281
+ const commit = commits[i];
282
+ if (commit === void 0) continue;
283
+ const shown = await git.showFile(commit.sha, path);
284
+ if (!("text" in shown)) {
285
+ ended = shown.missing === "commit" ? "unavailable" : "birth";
286
+ break;
287
+ }
288
+ const then = readThen(input, shown.text);
289
+ if (then === void 0) {
290
+ ended = "birth";
291
+ break;
292
+ }
293
+ examined.push(then);
294
+ const found = anchorHeldAt(input, then);
295
+ if (found.kind === "found") return baselineAt(i, then, found);
296
+ const written = await stillWritten(input, commit.sha, shown.text);
297
+ if (written.born) born = true;
298
+ if (written.stop) {
299
+ ended = "birth";
300
+ break;
301
+ }
302
+ }
303
+ for (const [i, then] of examined.entries()) {
304
+ const found = windowHeldAt(input, then);
305
+ if (found.kind === "found") return baselineAt(i, then, found);
306
+ }
307
+ if (ended === "birth" || born) return { kind: "none" };
308
+ if (ended === "unavailable") return { kind: "unavailable" };
309
+ return history.truncated || history.shallow ? { kind: "unavailable" } : { kind: "none" };
310
+ }
311
+ function claimDiff(input) {
312
+ const a = input.was.lines;
313
+ const b = input.now.lines;
314
+ let head = 0;
315
+ while (head < a.length && head < b.length && a[head] === b[head]) head++;
316
+ let tail = 0;
317
+ while (tail < a.length - head && tail < b.length - head && a[a.length - 1 - tail] === b[b.length - 1 - tail]) {
318
+ tail++;
319
+ }
320
+ const out = [
321
+ `--- ${input.file}@${shortCommit(input.commit)}:${input.was.at}`,
322
+ `+++ ${input.file}:${input.now.at}`
323
+ ];
324
+ for (const line of a.slice(0, head)) out.push(` ${line}`);
325
+ for (const line of a.slice(head, a.length - tail)) out.push(`-${line}`);
326
+ for (const line of b.slice(head, b.length - tail)) out.push(`+${line}`);
327
+ for (const line of a.slice(a.length - tail)) out.push(` ${line}`);
328
+ return out.join("\n");
329
+ }
330
+ function refineClaim(input) {
331
+ const { claim, history, entry, page, lines } = input;
332
+ if (history.kind === "unavailable") return { ...claim, historyAvailable: false };
333
+ if (history.kind === "none") return claim;
334
+ const format = page.format;
335
+ const base = {
336
+ ...claim,
337
+ commitSha: history.commit,
338
+ historyAvailable: true,
339
+ commitsSince: history.commitsSince,
340
+ baselineText: history.lines
341
+ };
342
+ const withDiff = (end, now2) => {
343
+ const diff = claimDiff({
344
+ file: page.file,
345
+ commit: history.commit,
346
+ was: { at: history.at, lines: history.lines },
347
+ now: now2
348
+ });
349
+ return { ...end, diff };
350
+ };
351
+ if (entry.citation.quote === true) {
352
+ const now2 = claim.text ?? [];
353
+ const same = stripMarkers(now2, format).join("\n") === stripMarkers(history.lines, format).join("\n");
354
+ const at = claim.fileLines ?? history.at;
355
+ return withDiff(same ? { ...base, status: "reanchored" } : base, { at, lines: now2 });
356
+ }
357
+ if (entry.citation.claim?.lines === void 0) {
358
+ const now2 = claim.text ?? [];
359
+ const w12 = claimWords(now2, format);
360
+ const at = claim.fileLines ?? history.at;
361
+ const held = holdsWords(w12, history.words) && holdsWords(history.pageWords, w12);
362
+ return withDiff(held ? { ...base, status: "reanchored" } : base, { at, lines: now2 });
363
+ }
364
+ const runs = runsHolding(lines, format, page.bodyLine, history.words);
365
+ const [only] = runs;
366
+ if (runs.length > 1) {
367
+ return {
368
+ ...claim,
369
+ status: "moved-ambiguous",
370
+ candidates: runs.map((span) => spellLines(toBodyLines(span, page.bodyLine))),
371
+ candidateFileLines: runs.map(spellLines)
372
+ };
373
+ }
374
+ if (only === void 0) {
375
+ return withDiff(base, { at: claim.fileLines ?? history.at, lines: claim.text ?? [] });
376
+ }
377
+ const now = lines.slice(only.start - 1, only.end);
378
+ const w1 = claimWords(now, format);
379
+ if (!holdsWords(history.pageWords, w1)) {
380
+ return withDiff(base, { at: claim.fileLines ?? history.at, lines: claim.text ?? [] });
381
+ }
382
+ return withDiff(
383
+ {
384
+ ...base,
385
+ status: "reanchored",
386
+ newLines: spellLines(toBodyLines(only, page.bodyLine)),
387
+ newFileLines: spellLines(only)
388
+ },
389
+ { at: spellLines(only), lines: now }
390
+ );
391
+ }
392
+
98
393
  // src/cite/core/sources.ts
99
394
  import fg from "fast-glob";
100
395
  import { lstat, readFile, realpath } from "node:fs/promises";
@@ -177,13 +472,13 @@ async function readSource(root, index, range, key, cache) {
177
472
  const resolvedPath = resolved.path;
178
473
  if (!index.has(resolvedPath)) return { kind: "missing", reason: "untracked" };
179
474
  if (cache === void 0) {
180
- const text = await readTracked(root, resolvedPath);
475
+ const text = await readIndexed(root, index, resolvedPath);
181
476
  return text === void 0 ? { kind: "missing", reason: "unreadable" } : { kind: "ok", resolvedPath, text };
182
477
  }
183
478
  const slot = JSON.stringify([root, resolvedPath]);
184
479
  let read = cache.get(slot);
185
480
  if (read === void 0) {
186
- read = readTracked(root, resolvedPath).then(
481
+ read = readIndexed(root, index, resolvedPath).then(
187
482
  (text) => text === void 0 ? void 0 : { text, lines: splitLines(text) }
188
483
  );
189
484
  cache.set(slot, read);
@@ -191,6 +486,9 @@ async function readSource(root, index, range, key, cache) {
191
486
  const file = await read;
192
487
  return file === void 0 ? { kind: "missing", reason: "unreadable" } : { kind: "ok", resolvedPath, text: file.text, lines: file.lines };
193
488
  }
489
+ function readIndexed(root, index, path) {
490
+ return index.read === void 0 ? readTracked(root, path) : index.read(path);
491
+ }
194
492
  async function readTracked(root, path) {
195
493
  try {
196
494
  return await readFile(join(root, path), "utf8");
@@ -227,6 +525,58 @@ async function historyOf(git, commit, path, range, pin, key, budget, counter) {
227
525
  }
228
526
  return found.truncated ? { kind: "unknown" } : { kind: "never-true" };
229
527
  }
528
+ async function sourceBaseline(git, recorded, path, range, pin, key, budget, counter) {
529
+ const at = (commit) => historyOf(git, commit, path, range, pin, key, budget, counter);
530
+ if (git.pageCommits === void 0) {
531
+ if (recorded === void 0) return { history: { kind: "none" } };
532
+ const history = await at(recorded);
533
+ return history.kind === "original" ? { history, commit: recorded } : { history };
534
+ }
535
+ if (recorded !== void 0 && await inHistory(git, recorded)) {
536
+ const history = await at(recorded);
537
+ if (history.kind === "original") return { history, commit: recorded };
538
+ }
539
+ const { commits, shallow, truncated } = await git.pageCommits(path, MAX_PAGE_COMMITS);
540
+ let unknown = false;
541
+ for (const [i, commit] of commits.entries()) {
542
+ const history = await at(commit.sha);
543
+ if (history.kind === "original") {
544
+ return {
545
+ history,
546
+ commit: commit.sha,
547
+ commitsSince: commits.slice(0, i).map((c) => c.subject)
548
+ };
549
+ }
550
+ if (history.kind === "unavailable") return { history };
551
+ if (history.kind === "unknown") unknown = true;
552
+ }
553
+ if (shallow || truncated) return { history: { kind: "unavailable" } };
554
+ return { history: unknown ? { kind: "unknown" } : { kind: "never-true" } };
555
+ }
556
+ async function inHistory(git, commit) {
557
+ if (git.isAncestor === void 0) return true;
558
+ const head = await git.head();
559
+ if (head === null) return true;
560
+ return git.isAncestor(commit, head);
561
+ }
562
+ async function arrivalOf(git, path, range, pin, key) {
563
+ if (git.pageCommits === void 0) return void 0;
564
+ const { commits } = await git.pageCommits(path, MAX_PAGE_COMMITS);
565
+ let arrived;
566
+ for (const commit of commits) {
567
+ const shown = await git.showFile(commit.sha, path);
568
+ if (!("text" in shown) || !holdsAt(shown.text, range, pin, key)) break;
569
+ arrived = commit.sha;
570
+ }
571
+ return arrived;
572
+ }
573
+ function holdsAt(text, range, pin, key) {
574
+ try {
575
+ return hashLines(sliceLines(splitLines(text), range), key) === pin;
576
+ } catch {
577
+ return false;
578
+ }
579
+ }
230
580
  async function followAcross(ask, counter) {
231
581
  const hits = [];
232
582
  const length = ask.original.length;
@@ -235,7 +585,7 @@ async function followAcross(ask, counter) {
235
585
  (path) => path !== ask.own && ask.index.has(path)
236
586
  );
237
587
  for (const path of candidates2) {
238
- const text = await readTracked(ask.root, path);
588
+ const text = await readIndexed(ask.root, ask.index, path);
239
589
  if (text === void 0) continue;
240
590
  const bytes = Buffer.byteLength(text, "utf8");
241
591
  if (bytes > counter.left) return { hits, truncated: true };
@@ -297,11 +647,14 @@ async function classifyCitation(entry, opts) {
297
647
  }
298
648
  }
299
649
  const counter = { left: opts.budget ?? MOVE_BUDGET_BYTES };
300
- let history = { kind: "none" };
301
- if (commit !== void 0 && await opts.git.available()) {
302
- history = await historyOf(opts.git, commit, path, range, pin, key, opts.budget, counter);
650
+ let derived = { history: { kind: "none" } };
651
+ if (await opts.git.available()) {
652
+ derived = await sourceBaseline(opts.git, commit, path, range, pin, key, opts.budget, counter);
303
653
  }
654
+ const history = derived.history;
655
+ const baseline = derived.commit;
304
656
  const original = history.kind === "original" ? history.lines : void 0;
657
+ if (baseline !== void 0) result.baselineSha = baseline;
305
658
  const spellAt = (at, start, end) => {
306
659
  const written = range.encrypted && opts.key !== void 0 ? encryptSourcePath(at, opts.key) : at;
307
660
  return formatSrc({ path: written, encrypted: range.encrypted, ...start === void 0 ? {} : { start, end } });
@@ -328,9 +681,9 @@ async function classifyCitation(entry, opts) {
328
681
  return result;
329
682
  }
330
683
  }
331
- if (commit !== void 0 && original !== void 0) {
684
+ if (baseline !== void 0 && original !== void 0) {
332
685
  const across = await followAcross(
333
- { git: opts.git, root: opts.root, index: opts.index, commit, own: path, pin, key, original },
686
+ { git: opts.git, root: opts.root, index: opts.index, commit: baseline, own: path, pin, key, original },
334
687
  counter
335
688
  );
336
689
  if (across.truncated) {
@@ -364,10 +717,10 @@ async function classifyCitation(entry, opts) {
364
717
  result.status = "changed";
365
718
  if (history.kind === "unavailable") result.historyAvailable = false;
366
719
  if (history.kind === "unknown") result.truncatedSearch = true;
367
- if (original !== void 0 && commit !== void 0) {
720
+ if (original !== void 0 && baseline !== void 0) {
368
721
  result.historyAvailable = true;
369
- result.commitsSince = await opts.git.subjectsSince(commit, path);
370
- result.diff = await opts.git.diffSince(commit, path);
722
+ result.commitsSince = derived.commitsSince ?? await opts.git.subjectsSince(baseline, path);
723
+ result.diff = await opts.git.diffSince(baseline, path);
371
724
  const span = range.start === void 0 ? void 0 : spanOf(lines, original);
372
725
  if (span !== void 0) result.newLines = String(lineSpec(span));
373
726
  }
@@ -375,16 +728,16 @@ async function classifyCitation(entry, opts) {
375
728
  }
376
729
 
377
730
  // src/cite/core/git.ts
378
- import { execFile } from "node:child_process";
731
+ import { execFile, spawn } from "node:child_process";
379
732
  var MAX_BUFFER = 32 * 1024 * 1024;
380
733
  var NO_COMMIT = /invalid object name|bad revision|unknown revision|bad object/i;
381
734
  var NO_PATH = /does not exist in|exists on disk, but not in|path .* does not exist/i;
382
- function run(root, args) {
735
+ function run(root, args, maxBuffer = MAX_BUFFER) {
383
736
  return new Promise((resolve4) => {
384
737
  execFile(
385
738
  "git",
386
739
  ["-c", "core.quotepath=false", ...args],
387
- { cwd: root, windowsHide: true, maxBuffer: MAX_BUFFER, encoding: "utf8" },
740
+ { cwd: root, windowsHide: true, maxBuffer, encoding: "utf8" },
388
741
  (error, stdout, stderr) => {
389
742
  if (error) {
390
743
  const failure = { ok: false, stderr, message: error.message };
@@ -395,7 +748,7 @@ function run(root, args) {
395
748
  );
396
749
  });
397
750
  }
398
- function gitClient(root) {
751
+ function gitClient(root, rev = "HEAD") {
399
752
  const memo = /* @__PURE__ */ new Map();
400
753
  const once = (key, compute) => {
401
754
  const held = memo.get(key);
@@ -433,7 +786,7 @@ function gitClient(root) {
433
786
  }),
434
787
  head: () => once("head", async () => {
435
788
  if (!await available()) return null;
436
- const out = await run(root, ["rev-parse", "HEAD"]);
789
+ const out = await run(root, ["rev-parse", "--verify", "--quiet", "--end-of-options", `${rev}^{commit}`]);
437
790
  return out.ok ? out.stdout.trim() : null;
438
791
  }),
439
792
  lsFiles: () => once("ls-files", async () => {
@@ -452,21 +805,23 @@ function gitClient(root) {
452
805
  throw failed("show", out);
453
806
  }),
454
807
  subjectsSince: (commit, path) => once(`log\0${commit}\0${path}`, async () => {
455
- const out = await run(root, ["log", "--format=%s", "--end-of-options", `${commit}..HEAD`, "--", path]);
808
+ const out = await run(root, ["log", "--format=%s", "--end-of-options", `${commit}..${rev}`, "--", path]);
456
809
  if (!out.ok) throw failed("log", out);
457
810
  return out.stdout.split(/\r?\n/).filter((line) => line !== "");
458
811
  }),
459
- // `HEAD` is written out: with no second revision git compares the commit
460
- // to the working tree, and this list is committed changes only, so a move
461
- // that is merely saved is never followed into a page (0055 stress test 8).
812
+ // The revision is written out, `HEAD` for a check: with no second revision
813
+ // git compares the commit to the working tree, and this list is committed
814
+ // changes only, so a move that is merely saved is never followed into a
815
+ // page (0055 stress test 8).
462
816
  changedSince: (commit) => once(`changed\0${commit}`, async () => {
463
817
  if (!await available()) return [];
464
- const out = await run(root, ["diff", "--name-only", "--end-of-options", commit, "HEAD"]);
818
+ const out = await run(root, ["diff", "--name-only", "--end-of-options", commit, rev]);
465
819
  if (!out.ok) throw failed("diff", out);
466
820
  return out.stdout.split(/\r?\n/).filter((line) => line !== "");
467
821
  }),
468
822
  diffSince: (commit, path) => once(`diff\0${commit}\0${path}`, async () => {
469
- const out = await run(root, ["diff", "--end-of-options", commit, "--", path]);
823
+ const against = rev === "HEAD" ? [commit] : [commit, rev];
824
+ const out = await run(root, ["diff", "--end-of-options", ...against, "--", path]);
470
825
  if (!out.ok) throw failed("diff", out);
471
826
  return out.stdout;
472
827
  }),
@@ -477,7 +832,8 @@ function gitClient(root) {
477
832
  `--format=%H${UNIT}%s`,
478
833
  "--topo-order",
479
834
  `-n${String(cap + 1)}`,
480
- "HEAD",
835
+ "--end-of-options",
836
+ rev,
481
837
  "--",
482
838
  path
483
839
  ]);
@@ -495,316 +851,151 @@ function gitClient(root) {
495
851
  };
496
852
  }
497
853
  var UNIT = "";
498
- var GIT_UNAVAILABLE_HISTORY = "git is not available here, so citations are checked without history: no never-true, no reanchored claims, no diffs, no commit subjects.";
499
- var PAGE_HISTORY_UNAVAILABLE = "the page history ends before the pin held; use fetch-depth: 0 to tell reanchored claims from changed ones";
500
- var SHALLOW_RECOMMIT = "this clone is shallow, so --recommit re-recorded only commits that do not contain their lines. Fetch full history to check the rest.";
501
- var GIT_UNAVAILABLE_COMMIT = "git is not available here, so the citation records no commit.";
502
- function noGit() {
503
- return {
504
- available: () => Promise.resolve(false),
505
- head: () => Promise.resolve(null),
506
- lsFiles: () => Promise.resolve([]),
507
- showFile: () => Promise.resolve({ missing: "commit" }),
508
- subjectsSince: () => Promise.resolve([]),
509
- diffSince: () => Promise.resolve(""),
510
- changedSince: () => Promise.resolve([]),
511
- pageCommits: () => Promise.resolve({ commits: [], shallow: false, truncated: false })
512
- };
513
- }
514
-
515
- // src/cite/core/history.ts
516
- var MAX_PAGE_COMMITS = 256;
517
- function stripMarkers(lines, format) {
518
- return lines.filter((line) => !isMarkerLine(line, format));
519
- }
520
- function claimWords(lines, format) {
521
- return stripMarkers(lines, format).join(" ").replace(/\s+/g, " ").trim();
522
- }
523
- function sentencesOf(text) {
524
- return text.split(/(?<=[.!?])\s+/).map((sentence) => sentence.replace(/\s+/g, " ").trim().toLowerCase()).filter((sentence) => sentence !== "");
525
- }
526
- function sharesSentence(a, b) {
527
- const left = new Set(sentencesOf(a));
528
- return sentencesOf(b).some((sentence) => left.has(sentence));
529
- }
530
- function wordSet(text) {
531
- return new Set(
532
- text.toLowerCase().split(/\s+/).filter((word) => word !== "")
533
- );
534
- }
535
- function wordShare(was, now) {
536
- const left = wordSet(was);
537
- if (left.size === 0) return 1;
538
- const right = wordSet(now);
539
- let held = 0;
540
- for (const word of left) if (right.has(word)) held++;
541
- return held / left.size;
542
- }
543
- function holdsWords(outer, inner) {
544
- if (inner === "") return true;
545
- if (outer === inner) return true;
546
- if (outer.startsWith(`${inner} `)) return true;
547
- if (outer.endsWith(` ${inner}`)) return true;
548
- return outer.includes(` ${inner} `);
549
- }
550
- function runsHolding(lines, format, bodyLine, inner) {
551
- if (inner === "") return [];
552
- let text = "";
553
- const at = [];
554
- for (let n = Math.max(bodyLine, 1); n <= lines.length; n++) {
555
- const line = lines[n - 1] ?? "";
556
- if (isMarkerLine(line, format)) continue;
557
- const words = line.replace(/\s+/g, " ").trim();
558
- if (words === "") continue;
559
- if (text !== "") {
560
- text += " ";
561
- at.push(n);
562
- }
563
- for (let i = 0; i < words.length; i++) at.push(n);
564
- text += words;
565
- }
566
- const out = [];
567
- let from = 0;
568
- for (; ; ) {
569
- const found = text.indexOf(inner, from);
570
- if (found === -1) break;
571
- from = found + 1;
572
- const before = found === 0 ? " " : text[found - 1];
573
- const afterAt = found + inner.length;
574
- const after = afterAt === text.length ? " " : text[afterAt];
575
- if (before !== " " || after !== " ") continue;
576
- const start = at[found];
577
- const end = at[afterAt - 1];
578
- if (start === void 0 || end === void 0) continue;
579
- if (!out.some((span) => span.start === start && span.end === end)) out.push({ start, end });
580
- }
581
- return out.filter(
582
- (span) => !out.some(
583
- (other) => (other.start !== span.start || other.end !== span.end) && other.start >= span.start && other.end <= span.end
584
- )
585
- );
586
- }
587
- function bounds(line) {
588
- return line === void 0 || line.trim() === "" || ANY_FENCE.test(line);
854
+ var GIT_UNAVAILABLE_HISTORY = "git is not available here, so citations are checked without history: no never-true, no reanchored claims, no diffs, no commit subjects.";
855
+ var PAGE_HISTORY_UNAVAILABLE = "the page history ends before the pin held; use fetch-depth: 0 to tell reanchored claims from changed ones";
856
+ var SOURCE_HISTORY_UNAVAILABLE = "the source history ends before the pin held; use fetch-depth: 0 to tell never-true from changed";
857
+ var SHALLOW_RECOMMIT = "this clone is shallow, so --recommit re-recorded only commits that do not contain their lines. Fetch full history to check the rest.";
858
+ var GIT_UNAVAILABLE_COMMIT = "git is not available here, so the citation records no commit.";
859
+ function noGit() {
860
+ return {
861
+ available: () => Promise.resolve(false),
862
+ head: () => Promise.resolve(null),
863
+ lsFiles: () => Promise.resolve([]),
864
+ showFile: () => Promise.resolve({ missing: "commit" }),
865
+ subjectsSince: () => Promise.resolve([]),
866
+ diffSince: () => Promise.resolve(""),
867
+ changedSince: () => Promise.resolve([]),
868
+ pageCommits: () => Promise.resolve({ commits: [], shallow: false, truncated: false })
869
+ };
589
870
  }
590
- function pinOf(lines, span) {
591
- if (span.start < 1 || span.end > lines.length || span.end < span.start) return void 0;
592
- return hashLines(lines.slice(span.start - 1, span.end).join("\n"));
871
+ var LOG_BUFFER = 1024 * 1024 * 1024;
872
+ var ZERO = /^0+$/;
873
+ function gitFailed(verb, outcome) {
874
+ return new CiteError(`git ${verb} failed: ${outcome.stderr.trim() || outcome.message}`);
593
875
  }
594
- function readThen(input, text) {
595
- const then = readPage(input.page.file, text, { format: input.page.format });
596
- const lines = splitLines(then.content);
597
- if (input.entry.citation.claim?.lines !== void 0) return { page: then, lines };
598
- const id = input.entry.citation.id;
599
- if (id === void 0) return void 0;
600
- const marker = then.statements.find(
601
- (statement) => statement.payload.kind === "ref" && statement.payload.ids.includes(id)
876
+ async function firstParentLog(root) {
877
+ const out = await run(
878
+ root,
879
+ [
880
+ "log",
881
+ "--first-parent",
882
+ "--diff-merges=first-parent",
883
+ "--root",
884
+ "-M",
885
+ "--raw",
886
+ "--no-abbrev",
887
+ "-z",
888
+ "--format=%x01%H%x02%ct%x02%s",
889
+ "HEAD"
890
+ ],
891
+ LOG_BUFFER
602
892
  );
603
- if (marker === void 0) return void 0;
604
- return { page: then, lines, marker };
605
- }
606
- function anchorHeldAt(input, then) {
607
- const pin = input.entry.citation.claim?.integrity;
608
- if (pin === void 0) return { kind: "absent" };
609
- const was = {
610
- citation: input.entry.citation,
611
- origin: input.entry.origin,
612
- ...then.marker === void 0 ? {} : { marker: then.marker }
613
- };
614
- const split = then.marker === void 0 ? void 0 : misplacedMarkerAt(then.page, then.lines, then.marker.line, was);
615
- const end = claimEnd(then.page, was, then.lines, split);
616
- if (end === null || end.status !== "current" && end.status !== "moved") {
617
- return { kind: "absent" };
618
- }
619
- for (const spec of [end.fileLines, end.newFileLines]) {
620
- const span = spec === void 0 ? void 0 : parseLines(spec);
621
- if (span !== void 0 && pinOf(then.lines, span) === pin) {
622
- return { kind: "found", span, lines: then.lines.slice(span.start - 1, span.end) };
623
- }
624
- }
625
- if (split !== void 0) {
626
- const text = unitText(then.lines, split);
627
- if (hashLines(text.join("\n")) === pin) {
628
- return { kind: "found", span: movedUnit(split), lines: text };
893
+ if (!out.ok) throw gitFailed("log", out);
894
+ const commits = [];
895
+ for (const record of out.stdout.split("")) {
896
+ if (record === "") continue;
897
+ const end = record.indexOf("\0");
898
+ const [sha, time, ...subject] = (end === -1 ? record : record.slice(0, end)).split("");
899
+ if (sha === void 0 || time === void 0) continue;
900
+ const tokens = end === -1 ? [] : record.slice(end + 1).replace(/^\n/, "").split("\0");
901
+ const changes = [];
902
+ for (let i = 0; i < tokens.length; i++) {
903
+ const meta = tokens[i];
904
+ if (meta === void 0 || !meta.startsWith(":")) continue;
905
+ const [, mode, , blob, status] = meta.slice(1).split(" ");
906
+ const path = tokens[++i];
907
+ if (path === void 0 || blob === void 0 || status === void 0) continue;
908
+ const added = ZERO.test(blob) ? { path } : { path, blob, ...mode === void 0 ? {} : { mode } };
909
+ if (status.startsWith("R") || status.startsWith("C")) {
910
+ const to = tokens[++i];
911
+ if (to === void 0) continue;
912
+ if (status.startsWith("R")) changes.push({ path });
913
+ changes.push({ ...added, path: to, ...status.startsWith("R") ? { from: path } : {} });
914
+ } else changes.push(added);
629
915
  }
916
+ commits.push({ sha, time: Number(time), subject: subject.join(""), changes });
630
917
  }
631
- return { kind: "absent" };
632
- }
633
- function windowHeldAt(input, then) {
634
- const pin = input.entry.citation.claim?.integrity;
635
- const marker = then.marker;
636
- if (pin === void 0 || marker === void 0) return { kind: "absent" };
637
- if (input.entry.citation.quote === true) return { kind: "absent" };
638
- const lines = then.lines;
639
- let stop = marker.line;
640
- for (let n = marker.line + 1; n <= lines.length; n++) {
641
- if (bounds(lines[n - 1])) break;
642
- stop = n;
918
+ return commits.reverse();
919
+ }
920
+ async function topLevel(root) {
921
+ const out = await run(root, ["rev-parse", "--show-toplevel"]);
922
+ return out.ok ? out.stdout.trim() : null;
923
+ }
924
+ async function commitGraph(root) {
925
+ const out = await run(root, ["log", "--format=%H %ct %P", "HEAD"], LOG_BUFFER);
926
+ if (!out.ok) throw gitFailed("log", out);
927
+ const graph = /* @__PURE__ */ new Map();
928
+ for (const line of out.stdout.split(/\r?\n/)) {
929
+ const [sha, time, ...parents] = line.trim().split(" ");
930
+ if (sha === void 0 || sha === "" || time === void 0) continue;
931
+ graph.set(sha, { time: Number(time), parents: parents.filter((p) => p !== "") });
643
932
  }
644
- const starts = [marker.line];
645
- for (let n = marker.line + 1; n <= stop; n++) {
646
- const line = lines[n - 1] ?? "";
647
- if (line.trim() === "" || isMarkerLine(line, then.page.format)) continue;
648
- starts.push(n);
933
+ return graph;
934
+ }
935
+ async function tagCommits(root) {
936
+ const out = await run(root, [
937
+ "for-each-ref",
938
+ "--format=%(refname:strip=2) %(objectname) %(*objectname)",
939
+ "refs/tags"
940
+ ]);
941
+ if (!out.ok) throw gitFailed("for-each-ref", out);
942
+ const tags = [];
943
+ for (const line of out.stdout.split(/\r?\n/)) {
944
+ const [name, object, peeled] = line.trim().split(" ");
945
+ if (name === void 0 || name === "" || object === void 0) continue;
946
+ tags.push({ name, commit: peeled !== void 0 && peeled !== "" ? peeled : object });
649
947
  }
650
- for (const start of starts) {
651
- for (let end = start; end <= stop; end++) {
652
- if (pinOf(lines, { start, end }) === pin) {
653
- return { kind: "found", span: { start, end }, lines: lines.slice(start - 1, end) };
948
+ return tags;
949
+ }
950
+ function blobReader(root) {
951
+ const child = spawn("git", ["cat-file", "--batch"], {
952
+ cwd: root,
953
+ windowsHide: true,
954
+ stdio: ["pipe", "pipe", "ignore"]
955
+ });
956
+ const waiting = [];
957
+ let buffer = Buffer.alloc(0);
958
+ const drain = () => {
959
+ for (; ; ) {
960
+ const next = waiting[0];
961
+ const nl = buffer.indexOf(10);
962
+ if (next === void 0 || nl === -1) return;
963
+ const header = buffer.subarray(0, nl).toString("utf8").split(" ");
964
+ const size = Number(header[2]);
965
+ if (header[1] === "missing" || !Number.isInteger(size)) {
966
+ buffer = buffer.subarray(nl + 1);
967
+ waiting.shift();
968
+ next.reject(new CiteError(`git cat-file failed: ${header.join(" ")}`));
969
+ continue;
654
970
  }
971
+ if (buffer.length < nl + 2 + size) return;
972
+ const text = buffer.subarray(nl + 1, nl + 1 + size).toString("utf8");
973
+ buffer = buffer.subarray(nl + 2 + size);
974
+ waiting.shift();
975
+ next.resolve(text);
655
976
  }
656
- }
657
- return { kind: "absent" };
658
- }
659
- async function stillWritten(input, commit, pageText) {
660
- const pin = input.entry.citation.claim?.integrity;
661
- if (pin === void 0) return { stop: true, born: true };
662
- const manifest = input.manifest;
663
- if (manifest !== void 0) {
664
- const shown = await input.git.showFile(commit, manifest);
665
- const held2 = "text" in shown && shown.text.includes(pin);
666
- return { stop: !held2, born: !held2 };
667
- }
668
- const held = pageText.includes(pin);
669
- return { stop: false, born: !held };
670
- }
671
- async function claimHistory(input) {
672
- const { git, path } = input;
673
- if (git.pageCommits === void 0) return { kind: "none" };
674
- if (!await git.available()) return { kind: "none" };
675
- const cap = input.cap ?? MAX_PAGE_COMMITS;
676
- const history = await git.pageCommits(path, cap);
677
- const { commits } = history;
678
- if (commits.length === 0) return { kind: "none" };
679
- const format = input.page.format;
680
- const baselineAt = (index, then, found) => {
681
- if (found.kind !== "found") return { kind: "none" };
682
- const commit = commits[index];
683
- if (commit === void 0) return { kind: "none" };
684
- return {
685
- kind: "baseline",
686
- commit: commit.sha,
687
- commitsSince: commits.slice(0, index).map((c) => c.subject),
688
- words: claimWords(found.lines, format),
689
- pageWords: claimWords(then.lines.slice(then.page.bodyLine - 1), format),
690
- lines: found.lines,
691
- at: spellLines(found.span)
692
- };
693
977
  };
694
- const examined = [];
695
- let ended = "cap";
696
- let born = false;
697
- for (let i = 0; i < commits.length; i++) {
698
- const commit = commits[i];
699
- if (commit === void 0) continue;
700
- const shown = await git.showFile(commit.sha, path);
701
- if (!("text" in shown)) {
702
- ended = shown.missing === "commit" ? "unavailable" : "birth";
703
- break;
704
- }
705
- const then = readThen(input, shown.text);
706
- if (then === void 0) {
707
- ended = "birth";
708
- break;
709
- }
710
- examined.push(then);
711
- const found = anchorHeldAt(input, then);
712
- if (found.kind === "found") return baselineAt(i, then, found);
713
- const written = await stillWritten(input, commit.sha, shown.text);
714
- if (written.born) born = true;
715
- if (written.stop) {
716
- ended = "birth";
717
- break;
718
- }
719
- }
720
- for (const [i, then] of examined.entries()) {
721
- const found = windowHeldAt(input, then);
722
- if (found.kind === "found") return baselineAt(i, then, found);
723
- }
724
- if (ended === "birth" || born) return { kind: "none" };
725
- if (ended === "unavailable") return { kind: "unavailable" };
726
- return history.truncated || history.shallow ? { kind: "unavailable" } : { kind: "none" };
727
- }
728
- function claimDiff(input) {
729
- const a = input.was.lines;
730
- const b = input.now.lines;
731
- let head = 0;
732
- while (head < a.length && head < b.length && a[head] === b[head]) head++;
733
- let tail = 0;
734
- while (tail < a.length - head && tail < b.length - head && a[a.length - 1 - tail] === b[b.length - 1 - tail]) {
735
- tail++;
736
- }
737
- const out = [
738
- `--- ${input.file}@${shortCommit(input.commit)}:${input.was.at}`,
739
- `+++ ${input.file}:${input.now.at}`
740
- ];
741
- for (const line of a.slice(0, head)) out.push(` ${line}`);
742
- for (const line of a.slice(head, a.length - tail)) out.push(`-${line}`);
743
- for (const line of b.slice(head, b.length - tail)) out.push(`+${line}`);
744
- for (const line of a.slice(a.length - tail)) out.push(` ${line}`);
745
- return out.join("\n");
746
- }
747
- function refineClaim(input) {
748
- const { claim, history, entry, page, lines } = input;
749
- if (history.kind === "unavailable") return { ...claim, historyAvailable: false };
750
- if (history.kind === "none") return claim;
751
- const format = page.format;
752
- const base = {
753
- ...claim,
754
- commitSha: history.commit,
755
- historyAvailable: true,
756
- commitsSince: history.commitsSince,
757
- baselineText: history.lines
978
+ const failAll = (error) => {
979
+ for (const next of waiting.splice(0)) next.reject(error);
758
980
  };
759
- const withDiff = (end, now2) => {
760
- const diff = claimDiff({
761
- file: page.file,
762
- commit: history.commit,
763
- was: { at: history.at, lines: history.lines },
764
- now: now2
765
- });
766
- return { ...end, diff };
981
+ child.stdout.on("data", (chunk) => {
982
+ buffer = Buffer.concat([buffer, chunk]);
983
+ drain();
984
+ });
985
+ child.on("error", failAll);
986
+ child.on("close", () => {
987
+ failAll(new CiteError("git cat-file ended early"));
988
+ });
989
+ return {
990
+ read: (blob) => new Promise((resolve4, reject) => {
991
+ waiting.push({ resolve: resolve4, reject });
992
+ child.stdin.write(`${blob}
993
+ `);
994
+ }),
995
+ close: () => {
996
+ child.stdin.end();
997
+ }
767
998
  };
768
- if (entry.citation.quote === true) {
769
- const now2 = claim.text ?? [];
770
- const same = stripMarkers(now2, format).join("\n") === stripMarkers(history.lines, format).join("\n");
771
- const at = claim.fileLines ?? history.at;
772
- return withDiff(same ? { ...base, status: "reanchored" } : base, { at, lines: now2 });
773
- }
774
- if (entry.citation.claim?.lines === void 0) {
775
- const now2 = claim.text ?? [];
776
- const w12 = claimWords(now2, format);
777
- const at = claim.fileLines ?? history.at;
778
- const held = holdsWords(w12, history.words) && holdsWords(history.pageWords, w12);
779
- return withDiff(held ? { ...base, status: "reanchored" } : base, { at, lines: now2 });
780
- }
781
- const runs = runsHolding(lines, format, page.bodyLine, history.words);
782
- const [only] = runs;
783
- if (runs.length > 1) {
784
- return {
785
- ...claim,
786
- status: "moved-ambiguous",
787
- candidates: runs.map((span) => spellLines(toBodyLines(span, page.bodyLine))),
788
- candidateFileLines: runs.map(spellLines)
789
- };
790
- }
791
- if (only === void 0) {
792
- return withDiff(base, { at: claim.fileLines ?? history.at, lines: claim.text ?? [] });
793
- }
794
- const now = lines.slice(only.start - 1, only.end);
795
- const w1 = claimWords(now, format);
796
- if (!holdsWords(history.pageWords, w1)) {
797
- return withDiff(base, { at: claim.fileLines ?? history.at, lines: claim.text ?? [] });
798
- }
799
- return withDiff(
800
- {
801
- ...base,
802
- status: "reanchored",
803
- newLines: spellLines(toBodyLines(only, page.bodyLine)),
804
- newFileLines: spellLines(only)
805
- },
806
- { at: spellLines(only), lines: now }
807
- );
808
999
  }
809
1000
 
810
1001
  // src/cite/core/check-page.ts
@@ -1008,7 +1199,7 @@ async function checkCitations(page, opts) {
1008
1199
  }
1009
1200
  findings.push(...findingsFor(results, severity));
1010
1201
  for (const finding of findings) finding.guidance = guidanceFor(finding.rule);
1011
- const wantsSourceHistory = checkSources && read.citations.some(({ citation }) => citation.source["commit-sha"] !== void 0);
1202
+ const wantsSourceHistory = checkSources && (read.citations.some(({ citation }) => citation.source["commit-sha"] !== void 0) || results.some((r) => r.source.status !== "current"));
1012
1203
  const wantsClaimHistory = results.some((r) => r.claim?.status === "changed");
1013
1204
  if (wantsSourceHistory && !await client.available()) notices.push(GIT_UNAVAILABLE_HISTORY);
1014
1205
  else if (wantsClaimHistory && !await pageGit.available()) {
@@ -1017,11 +1208,8 @@ async function checkCitations(page, opts) {
1017
1208
  if (results.some((r) => r.claim?.historyAvailable === false)) {
1018
1209
  notices.push(PAGE_HISTORY_UNAVAILABLE);
1019
1210
  }
1020
- const unavailable = results.find((r) => r.source.historyAvailable === false);
1021
- if (unavailable?.source.commitSha !== void 0) {
1022
- notices.push(
1023
- `commit ${unavailable.source.commitSha.slice(0, 7)} not found in history; use fetch-depth: 0 to enable never-true and diffs`
1024
- );
1211
+ if (results.some((r) => r.source.historyAvailable === false)) {
1212
+ notices.push(SOURCE_HISTORY_UNAVAILABLE);
1025
1213
  }
1026
1214
  const budget = String(MOVE_BUDGET_BYTES / (1024 * 1024));
1027
1215
  if (results.some((r) => r.source.truncatedSearch === true && r.source.truncatedAcross !== true)) {
@@ -1621,15 +1809,36 @@ export {
1621
1809
  gitClient,
1622
1810
  GIT_UNAVAILABLE_HISTORY,
1623
1811
  PAGE_HISTORY_UNAVAILABLE,
1812
+ SOURCE_HISTORY_UNAVAILABLE,
1624
1813
  SHALLOW_RECOMMIT,
1625
1814
  GIT_UNAVAILABLE_COMMIT,
1626
1815
  noGit,
1816
+ firstParentLog,
1817
+ topLevel,
1818
+ commitGraph,
1819
+ tagCommits,
1820
+ blobReader,
1821
+ MAX_PAGE_COMMITS,
1822
+ stripMarkers,
1823
+ claimWords,
1824
+ sentencesOf,
1825
+ sharesSentence,
1826
+ wordShare,
1827
+ holdsWords,
1828
+ runsHolding,
1829
+ claimHistory,
1830
+ claimDiff,
1831
+ refineClaim,
1627
1832
  encryptSourcePath,
1628
1833
  decryptSourcePath,
1629
1834
  buildSourceIndex,
1630
1835
  sourceIndexFor,
1836
+ resolveSourcePath,
1837
+ createSourceCache,
1631
1838
  readSource,
1632
1839
  historyOf,
1840
+ sourceBaseline,
1841
+ arrivalOf,
1633
1842
  classifyCitation,
1634
1843
  CITATIONS_KEY,
1635
1844
  urlManifestRefusal,
@@ -1638,17 +1847,6 @@ export {
1638
1847
  orphanRefusal,
1639
1848
  duplicateJoinRefusal,
1640
1849
  sidecarsFor,
1641
- MAX_PAGE_COMMITS,
1642
- stripMarkers,
1643
- claimWords,
1644
- sentencesOf,
1645
- sharesSentence,
1646
- wordShare,
1647
- holdsWords,
1648
- runsHolding,
1649
- claimHistory,
1650
- claimDiff,
1651
- refineClaim,
1652
1850
  checkCitations,
1653
1851
  joinHits,
1654
1852
  prepareRun,
@@ -1658,4 +1856,4 @@ export {
1658
1856
  sayNotices,
1659
1857
  runCheck
1660
1858
  };
1661
- //# sourceMappingURL=chunk-QF7EIRMU.js.map
1859
+ //# sourceMappingURL=chunk-ZT5NUSZA.js.map