token-goat 2.9.30 → 2.9.31

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 (172) hide show
  1. package/README.md +24 -7
  2. package/SECURITY.md +10 -2
  3. package/THIRD_PARTY_NOTICES.md +1 -1
  4. package/dist/native/linux-arm64/tg-hook +0 -0
  5. package/dist/native/linux-x64/tg-hook +0 -0
  6. package/dist/native/win32-arm64/tg-hook.exe +0 -0
  7. package/dist/native/win32-x64/tg-hook.exe +0 -0
  8. package/dist/{token-goat-chunk-QSBRTGM2.mjs → token-goat-chunk-25TRAWET.mjs} +17 -7
  9. package/dist/token-goat-chunk-2KXO6V2B.mjs +203 -0
  10. package/dist/{token-goat-chunk-IVKIZWAB.mjs → token-goat-chunk-2M7E4PF7.mjs} +41 -12
  11. package/dist/{token-goat-chunk-SMVRN2HU.mjs → token-goat-chunk-2UPZGKKY.mjs} +2 -2
  12. package/dist/token-goat-chunk-2WLPWKHV.mjs +135 -0
  13. package/dist/token-goat-chunk-2XBMMDBD.mjs +126 -0
  14. package/dist/token-goat-chunk-32ZOY4N5.mjs +23 -0
  15. package/dist/token-goat-chunk-3EZRNKTK.mjs +188 -0
  16. package/dist/token-goat-chunk-4ADZHI7J.mjs +63 -0
  17. package/dist/token-goat-chunk-4GBVPH3D.mjs +242 -0
  18. package/dist/{token-goat-chunk-KWPNJBDH.mjs → token-goat-chunk-4GILLLWY.mjs} +7 -4
  19. package/dist/{token-goat-chunk-67TQJ76B.mjs → token-goat-chunk-4NAPX7BA.mjs} +36 -3
  20. package/dist/{token-goat-chunk-PU7V3FD6.mjs → token-goat-chunk-4SC7UJYV.mjs} +3354 -2553
  21. package/dist/token-goat-chunk-4SMRO4TO.mjs +366 -0
  22. package/dist/{token-goat-chunk-AFLYLHDH.mjs → token-goat-chunk-4ZBFWLXF.mjs} +283 -427
  23. package/dist/{token-goat-chunk-JDWCRD6M.mjs → token-goat-chunk-57BIAXJL.mjs} +73 -40
  24. package/dist/token-goat-chunk-5AC66HNP.mjs +115 -0
  25. package/dist/token-goat-chunk-5IMLKSOP.mjs +145 -0
  26. package/dist/token-goat-chunk-646E6U44.mjs +398 -0
  27. package/dist/token-goat-chunk-65N4RHP4.mjs +33 -0
  28. package/dist/{token-goat-chunk-JN4XMLSD.mjs → token-goat-chunk-6DG6HWP3.mjs} +8 -2
  29. package/dist/token-goat-chunk-6ENQSNRZ.mjs +573 -0
  30. package/dist/token-goat-chunk-6ZY4GNF2.mjs +91 -0
  31. package/dist/{token-goat-chunk-VPBBTSJR.mjs → token-goat-chunk-76FGDLRO.mjs} +262 -255
  32. package/dist/{token-goat-chunk-7IN2MKDS.mjs → token-goat-chunk-7EZTZOMC.mjs} +121 -289
  33. package/dist/{token-goat-chunk-OJBNYTJP.mjs → token-goat-chunk-7MAOA6X4.mjs} +640 -80
  34. package/dist/token-goat-chunk-7R2ZVVAX.mjs +218 -0
  35. package/dist/{token-goat-chunk-PD5VKH46.mjs → token-goat-chunk-AUNGYYQX.mjs} +2 -2
  36. package/dist/{token-goat-chunk-HG45AF2B.mjs → token-goat-chunk-AUQYRMMH.mjs} +794 -37
  37. package/dist/token-goat-chunk-B3PEKBYG.mjs +128 -0
  38. package/dist/{token-goat-chunk-A3CK6N5Z.mjs → token-goat-chunk-BA4HI6BW.mjs} +1309 -110
  39. package/dist/{token-goat-chunk-JB6QN6VF.mjs → token-goat-chunk-BFCWY73P.mjs} +59 -23
  40. package/dist/{token-goat-chunk-B45VMIIH.mjs → token-goat-chunk-BWGFUZZE.mjs} +7 -5
  41. package/dist/{token-goat-chunk-P4QMM4WK.mjs → token-goat-chunk-C75NA7PL.mjs} +50 -23
  42. package/dist/token-goat-chunk-CBIQ7WTD.mjs +87 -0
  43. package/dist/token-goat-chunk-CETM74KC.mjs +307 -0
  44. package/dist/{token-goat-chunk-H2PHHGM5.mjs → token-goat-chunk-CIMQ2BB3.mjs} +57 -12
  45. package/dist/{token-goat-chunk-N2NMER56.mjs → token-goat-chunk-CJLS3CDL.mjs} +46 -4
  46. package/dist/{token-goat-chunk-VES7EL7O.mjs → token-goat-chunk-CO3UYX6G.mjs} +1 -1
  47. package/dist/token-goat-chunk-COPNXRJM.mjs +154 -0
  48. package/dist/token-goat-chunk-CSJ5L3NL.mjs +479 -0
  49. package/dist/{token-goat-chunk-4LCCNRTG.mjs → token-goat-chunk-CVCEVUGK.mjs} +8 -6
  50. package/dist/{token-goat-chunk-B2RZZCSS.mjs → token-goat-chunk-CXHOFN7R.mjs} +37 -20
  51. package/dist/token-goat-chunk-D735C4QM.mjs +603 -0
  52. package/dist/{token-goat-chunk-APGZXSPS.mjs → token-goat-chunk-DGS2LVNA.mjs} +47 -30
  53. package/dist/{token-goat-chunk-54K3EUV3.mjs → token-goat-chunk-DOWRSMWO.mjs} +1 -1
  54. package/dist/token-goat-chunk-E45INMY3.mjs +71 -0
  55. package/dist/token-goat-chunk-EC5F37F4.mjs +244 -0
  56. package/dist/{token-goat-chunk-XTQAOTSO.mjs → token-goat-chunk-EDBDRVH5.mjs} +4 -1
  57. package/dist/{token-goat-chunk-5BCIJXMO.mjs → token-goat-chunk-EELTBKDM.mjs} +14 -10
  58. package/dist/{token-goat-chunk-W3QCJS6G.mjs → token-goat-chunk-F4HYL64R.mjs} +8 -6
  59. package/dist/token-goat-chunk-F6PAUIEK.mjs +624 -0
  60. package/dist/token-goat-chunk-FDSREWLX.mjs +692 -0
  61. package/dist/token-goat-chunk-GGGG7RWB.mjs +236 -0
  62. package/dist/{token-goat-chunk-C63JQV5K.mjs → token-goat-chunk-GL3ETKSC.mjs} +233 -15
  63. package/dist/token-goat-chunk-GVB2MUST.mjs +1298 -0
  64. package/dist/token-goat-chunk-GWFLAUMQ.mjs +307 -0
  65. package/dist/{token-goat-chunk-ZEJVMUQH.mjs → token-goat-chunk-HLPW63A7.mjs} +2 -2
  66. package/dist/{token-goat-chunk-GOLEOXZP.mjs → token-goat-chunk-HU4TORC5.mjs} +44 -26
  67. package/dist/{token-goat-chunk-Z57YODA2.mjs → token-goat-chunk-I7VKZZAW.mjs} +2 -2
  68. package/dist/{token-goat-chunk-NYKZLXMK.mjs → token-goat-chunk-IA6XSPE3.mjs} +6 -6
  69. package/dist/{token-goat-chunk-E3OQX2XT.mjs → token-goat-chunk-IAGXMHIK.mjs} +81 -42
  70. package/dist/{token-goat-chunk-HYBFA5X3.mjs → token-goat-chunk-IK2DRMFX.mjs} +24 -68
  71. package/dist/{token-goat-chunk-COBQGL5S.mjs → token-goat-chunk-INNPTRUX.mjs} +249 -299
  72. package/dist/{token-goat-chunk-7NADEDKJ.mjs → token-goat-chunk-JJ5BX4F4.mjs} +6 -1
  73. package/dist/{token-goat-chunk-PEPTHRFF.mjs → token-goat-chunk-JVFSHVFJ.mjs} +6 -6
  74. package/dist/token-goat-chunk-KGEFFSHD.mjs +50 -0
  75. package/dist/token-goat-chunk-KQBLRPBN.mjs +433 -0
  76. package/dist/{token-goat-chunk-Q5VTGRH7.mjs → token-goat-chunk-LCNQ2CNN.mjs} +55 -319
  77. package/dist/token-goat-chunk-M3LFJDPU.mjs +58 -0
  78. package/dist/token-goat-chunk-M52KPT3C.mjs +87 -0
  79. package/dist/token-goat-chunk-MBEG42H7.mjs +150 -0
  80. package/dist/{token-goat-chunk-EVC4TOLE.mjs → token-goat-chunk-METECDOH.mjs} +3 -12
  81. package/dist/{token-goat-chunk-T4FK7VOV.mjs → token-goat-chunk-MHX7XCC3.mjs} +2 -1
  82. package/dist/token-goat-chunk-N5LSOVSU.mjs +137 -0
  83. package/dist/{token-goat-chunk-LOBGHXPB.mjs → token-goat-chunk-N5MMR2IW.mjs} +1 -1
  84. package/dist/token-goat-chunk-N7B3JQ2C.mjs +160 -0
  85. package/dist/{token-goat-chunk-RHXKCZX3.mjs → token-goat-chunk-NISNMD7T.mjs} +2182 -2959
  86. package/dist/token-goat-chunk-NMD42SFQ.mjs +434 -0
  87. package/dist/token-goat-chunk-NOSS5VWY.mjs +174 -0
  88. package/dist/{token-goat-chunk-KQNZDCBD.mjs → token-goat-chunk-NSNSPPBG.mjs} +25 -3
  89. package/dist/token-goat-chunk-OBOFIHKN.mjs +38 -0
  90. package/dist/token-goat-chunk-OBRFJ5O5.mjs +76 -0
  91. package/dist/{token-goat-chunk-JTQQGXZH.mjs → token-goat-chunk-ODBT2USM.mjs} +124 -57
  92. package/dist/token-goat-chunk-OS5EM5PP.mjs +107 -0
  93. package/dist/token-goat-chunk-OUKDTVNU.mjs +1178 -0
  94. package/dist/token-goat-chunk-OXFMP75N.mjs +566 -0
  95. package/dist/{token-goat-chunk-DZX2YDPT.mjs → token-goat-chunk-OYIYKDDT.mjs} +2 -2
  96. package/dist/{token-goat-chunk-QCLDAQTS.mjs → token-goat-chunk-P6HQSWQ3.mjs} +50 -53
  97. package/dist/token-goat-chunk-P6VGNTQT.mjs +71 -0
  98. package/dist/{token-goat-chunk-7BXSNBY5.mjs → token-goat-chunk-PFWIMH2E.mjs} +23 -15
  99. package/dist/token-goat-chunk-PJZXIS3G.mjs +39 -0
  100. package/dist/token-goat-chunk-PUO5INXP.mjs +606 -0
  101. package/dist/{token-goat-chunk-GFBSN7BD.mjs → token-goat-chunk-PX5PQWTY.mjs} +22 -250
  102. package/dist/token-goat-chunk-Q5QDBC6O.mjs +111 -0
  103. package/dist/token-goat-chunk-QFNQXSDT.mjs +40 -0
  104. package/dist/{token-goat-chunk-FBNQNSJK.mjs → token-goat-chunk-QH7YVYOY.mjs} +2198 -2782
  105. package/dist/{token-goat-chunk-64FBPDTK.mjs → token-goat-chunk-QLMUHEPB.mjs} +12 -9
  106. package/dist/{token-goat-chunk-RZRTDST7.mjs → token-goat-chunk-QQOJIHL3.mjs} +37 -11
  107. package/dist/{token-goat-chunk-XKI4SEMX.mjs → token-goat-chunk-QQTWJY2O.mjs} +19 -0
  108. package/dist/{token-goat-chunk-U4N3BN2W.mjs → token-goat-chunk-QYHO5CPH.mjs} +3 -2
  109. package/dist/token-goat-chunk-RELAVWAD.mjs +27 -0
  110. package/dist/{token-goat-chunk-ETBHVDB6.mjs → token-goat-chunk-RSLPOBKQ.mjs} +22 -11
  111. package/dist/token-goat-chunk-SAMFDIS2.mjs +712 -0
  112. package/dist/token-goat-chunk-SDELXLDM.mjs +48 -0
  113. package/dist/{token-goat-chunk-4JJS54TR.mjs → token-goat-chunk-SOAFZNNZ.mjs} +161 -38
  114. package/dist/{token-goat-chunk-664RTTUV.mjs → token-goat-chunk-SRTHT7KV.mjs} +21 -16
  115. package/dist/{token-goat-chunk-4FVIAHSI.mjs → token-goat-chunk-T5P5ACNQ.mjs} +7 -6
  116. package/dist/token-goat-chunk-T5YGG4V3.mjs +45 -0
  117. package/dist/token-goat-chunk-TAUZ4OFS.mjs +110 -0
  118. package/dist/{token-goat-chunk-COTXZHTS.mjs → token-goat-chunk-TM6MC754.mjs} +4 -3
  119. package/dist/token-goat-chunk-TWUKBOMP.mjs +72 -0
  120. package/dist/{token-goat-chunk-3CHUNJ2O.mjs → token-goat-chunk-U2KSB4SG.mjs} +8 -5
  121. package/dist/{token-goat-chunk-3Z5S4KGM.mjs → token-goat-chunk-U4WHMG6Y.mjs} +29 -49
  122. package/dist/{token-goat-chunk-PY533T7F.mjs → token-goat-chunk-UGJHGR5A.mjs} +21 -15
  123. package/dist/{token-goat-chunk-CYCEYAEO.mjs → token-goat-chunk-UOUDVA5U.mjs} +1 -1
  124. package/dist/{token-goat-chunk-JDHE26RP.mjs → token-goat-chunk-URRJ33GR.mjs} +16 -5
  125. package/dist/{token-goat-chunk-56EIMS3E.mjs → token-goat-chunk-UZOROKIS.mjs} +23 -17
  126. package/dist/{token-goat-chunk-CZ3LUXYZ.mjs → token-goat-chunk-VIHGGGEI.mjs} +427 -308
  127. package/dist/token-goat-chunk-VTJLAA7P.mjs +21 -0
  128. package/dist/token-goat-chunk-VWDXLT4F.mjs +678 -0
  129. package/dist/{token-goat-chunk-YARZFCZS.mjs → token-goat-chunk-VWZA2H4P.mjs} +62 -53
  130. package/dist/{token-goat-chunk-SQSSNQPE.mjs → token-goat-chunk-VXEXMJDL.mjs} +3979 -4745
  131. package/dist/token-goat-chunk-WBA5SKT4.mjs +547 -0
  132. package/dist/{token-goat-chunk-SJHWVNDQ.mjs → token-goat-chunk-WDH44VAU.mjs} +7 -4
  133. package/dist/token-goat-chunk-X2SUP3EI.mjs +107 -0
  134. package/dist/token-goat-chunk-X3BELZSJ.mjs +125 -0
  135. package/dist/{token-goat-chunk-FZ3NEW5O.mjs → token-goat-chunk-XLRBNZCC.mjs} +13 -8
  136. package/dist/{token-goat-chunk-Z44YO3QZ.mjs → token-goat-chunk-XRKUX6CM.mjs} +1 -1
  137. package/dist/token-goat-chunk-XX6O25RN.mjs +82 -0
  138. package/dist/token-goat-chunk-XZSUHBVS.mjs +65 -0
  139. package/dist/{token-goat-chunk-WY3L4DVT.mjs → token-goat-chunk-Y2ZTQOCL.mjs} +13 -8
  140. package/dist/{token-goat-chunk-UQ5UK2T7.mjs → token-goat-chunk-YB4VMGK2.mjs} +1 -1
  141. package/dist/token-goat-chunk-YBIIY3HR.mjs +51 -0
  142. package/dist/{token-goat-chunk-ZQSJMO2R.mjs → token-goat-chunk-YHVDKQBR.mjs} +105 -105
  143. package/dist/{token-goat-chunk-H2K3QP6H.mjs → token-goat-chunk-YJB5XLWI.mjs} +8 -6
  144. package/dist/{token-goat-chunk-ZCDTCVIS.mjs → token-goat-chunk-YKB6AQG3.mjs} +5 -2
  145. package/dist/token-goat-chunk-YMTG2YA5.mjs +35 -0
  146. package/dist/token-goat-chunk-YPBZYQRV.mjs +40 -0
  147. package/dist/{token-goat-chunk-HOJLCGDP.mjs → token-goat-chunk-YY6AVUFL.mjs} +2033 -2251
  148. package/dist/token-goat-chunk-Z7N5OMMP.mjs +98 -0
  149. package/dist/token-goat-chunk-ZNMNUPAZ.mjs +938 -0
  150. package/dist/token-goat-hook-client.cjs +1 -1
  151. package/dist/token-goat-hook-client.mjs +3 -3
  152. package/dist/token-goat-hook.mjs +67 -38
  153. package/dist/token-goat.core.mjs +4 -4
  154. package/docs/C4_RUNTIME_ARCHITECTURE.md +1 -1
  155. package/docs/cli.md +40 -21
  156. package/docs/install.md +19 -9
  157. package/docs/security.md +5 -3
  158. package/package.json +2 -1
  159. package/dist/token-goat-chunk-5KDMCMF2.mjs +0 -362
  160. package/dist/token-goat-chunk-6QMAS7AB.mjs +0 -42
  161. package/dist/token-goat-chunk-7F2UBPD3.mjs +0 -397
  162. package/dist/token-goat-chunk-ARDNEC2U.mjs +0 -248
  163. package/dist/token-goat-chunk-ATCPY7EQ.mjs +0 -134
  164. package/dist/token-goat-chunk-EFHMMIGP.mjs +0 -68
  165. package/dist/token-goat-chunk-IVALLT3S.mjs +0 -48
  166. package/dist/token-goat-chunk-JDU3EXSU.mjs +0 -65
  167. package/dist/token-goat-chunk-MKPF4CL5.mjs +0 -37
  168. package/dist/token-goat-chunk-RC35RBUL.mjs +0 -312
  169. package/dist/token-goat-chunk-USILZ3T3.mjs +0 -53
  170. package/dist/token-goat-chunk-VL3YIFHZ.mjs +0 -2975
  171. package/dist/token-goat-chunk-XU4P6Z24.mjs +0 -133
  172. package/dist/token-goat-chunk-Y776AENC.mjs +0 -1597
@@ -0,0 +1,307 @@
1
+ import { createRequire as __cjsRequire } from 'node:module';
2
+ const require = __cjsRequire(import.meta.url);
3
+ import {
4
+ evaluateVerification
5
+ } from "./token-goat-chunk-2WLPWKHV.mjs";
6
+ import {
7
+ claimsCommittedChange
8
+ } from "./token-goat-chunk-PUO5INXP.mjs";
9
+ import "./token-goat-chunk-2XBMMDBD.mjs";
10
+ import "./token-goat-chunk-PFWIMH2E.mjs";
11
+ import "./token-goat-chunk-GWFLAUMQ.mjs";
12
+ import "./token-goat-chunk-PJZXIS3G.mjs";
13
+ import "./token-goat-chunk-OBOFIHKN.mjs";
14
+ import "./token-goat-chunk-NOSS5VWY.mjs";
15
+ import "./token-goat-chunk-SAMFDIS2.mjs";
16
+ import {
17
+ sessionSidecarPath
18
+ } from "./token-goat-chunk-WBA5SKT4.mjs";
19
+ import "./token-goat-chunk-CIMQ2BB3.mjs";
20
+ import "./token-goat-chunk-WDH44VAU.mjs";
21
+ import "./token-goat-chunk-BPGCUMR7.mjs";
22
+ import "./token-goat-chunk-KQBLRPBN.mjs";
23
+ import "./token-goat-chunk-4ZBFWLXF.mjs";
24
+ import {
25
+ sessionStateKey
26
+ } from "./token-goat-chunk-C75NA7PL.mjs";
27
+ import {
28
+ contextOutput,
29
+ getCwd,
30
+ passOutput
31
+ } from "./token-goat-chunk-76FGDLRO.mjs";
32
+ import "./token-goat-chunk-GL3ETKSC.mjs";
33
+ import "./token-goat-chunk-NISNMD7T.mjs";
34
+ import "./token-goat-chunk-EVMZJ27Z.mjs";
35
+ import "./token-goat-chunk-IK2DRMFX.mjs";
36
+ import {
37
+ recordStat
38
+ } from "./token-goat-chunk-U4WHMG6Y.mjs";
39
+ import "./token-goat-chunk-GVB2MUST.mjs";
40
+ import "./token-goat-chunk-XB5KKOCG.mjs";
41
+ import "./token-goat-chunk-OUKDTVNU.mjs";
42
+ import "./token-goat-chunk-4GILLLWY.mjs";
43
+ import "./token-goat-chunk-BFCWY73P.mjs";
44
+ import "./token-goat-chunk-KGEFFSHD.mjs";
45
+ import "./token-goat-chunk-XX6O25RN.mjs";
46
+ import "./token-goat-chunk-HAVAOB3S.mjs";
47
+ import "./token-goat-chunk-F6PAUIEK.mjs";
48
+ import "./token-goat-chunk-65N4RHP4.mjs";
49
+ import "./token-goat-chunk-X2SUP3EI.mjs";
50
+ import {
51
+ redactSecrets
52
+ } from "./token-goat-chunk-T5P5ACNQ.mjs";
53
+ import {
54
+ loadConfig
55
+ } from "./token-goat-chunk-7EZTZOMC.mjs";
56
+ import {
57
+ getHarnessName
58
+ } from "./token-goat-chunk-QYHO5CPH.mjs";
59
+ import "./token-goat-chunk-4GBVPH3D.mjs";
60
+ import "./token-goat-chunk-YZAAZU2S.mjs";
61
+ import "./token-goat-chunk-IVE6U7KV.mjs";
62
+ import "./token-goat-chunk-Y4AFKTHK.mjs";
63
+ import {
64
+ atomicWriteText,
65
+ ensureDirSync,
66
+ isWithinQuietHours,
67
+ runGit,
68
+ withFileLock
69
+ } from "./token-goat-chunk-HU4TORC5.mjs";
70
+ import {
71
+ echoedCommand,
72
+ nameSubject
73
+ } from "./token-goat-chunk-GGGG7RWB.mjs";
74
+ import "./token-goat-chunk-AM5V6GSX.mjs";
75
+ import "./token-goat-chunk-FNFBKLRD.mjs";
76
+ import "./token-goat-chunk-CO3UYX6G.mjs";
77
+ import {
78
+ init_define_import_meta_env
79
+ } from "./token-goat-chunk-A37V4PBF.mjs";
80
+
81
+ // src/agent_receipt.ts
82
+ init_define_import_meta_env();
83
+ import { createHash } from "node:crypto";
84
+ import { existsSync, readFileSync } from "node:fs";
85
+ import { dirname } from "node:path";
86
+
87
+ // src/change_claim.ts
88
+ init_define_import_meta_env();
89
+ var CHANGE_VERBS = "fixed|implemented|added|created|wrote|written|refactored|updated|changed|edited|modified|deleted|removed|patched|resolved|replaced|improved|applied|renamed|rewrote|rewritten";
90
+ var OPENER_VERBS = "fixed|implemented|added|created|wrote|refactored|updated|changed|edited|modified|deleted|removed|patched|replaced|renamed|rewrote";
91
+ var NOT_AN_EDIT_OBJECT = "(?![ \\t]+(?:(?:the|a|an|my|our|this|these|some)[ \\t]+)?(?:summary|report|review|analysis|findings?|notes?|plan|mind|understanding|that|following[ \\t]+(?:findings?|notes?|observations?|points?|issues?[ \\t]+(?:I|we)[ \\t]+(?:found|noticed|saw)))\\b)";
92
+ var FENCED_BLOCK_RE = /```[\s\S]*?(?:```|$)|~~~[\s\S]*?(?:~~~|$)/g;
93
+ var QUOTED_LINE_RE = /^(?:[ \t]*>.*|(?: {4}|\t)(?![ \t]*(?:[-*•]|\d+[.)])[ \t]).*)$/gm;
94
+ var DIFF_EVIDENCE_RE = /^[ \t]*(?:@@|diff --git)|^[ \t]*\+[ \t].*\n[ \t]*[+-][ \t]|^[ \t]*-[ \t].*\n[ \t]*\+[ \t]/m;
95
+ var DIFF_LINE_RE = /^[ \t]*(?:[+-][ \t]|@@).*$/gm;
96
+ var FIRST_PERSON_CLAIM_RE = new RegExp(
97
+ `(?<!\\b(?:if|whether|when|unless|should|would|could)[ \\t]+)\\b(?:I|we)(?:['\u2019]ve|[ \\t]+have)?[ \\t]+(?:(?:also|then|just|now|already|both)[ \\t]+)*(?:(?:${CHANGE_VERBS})\\b(?![ \\t]+up\\b)(?![ \\t]*(?::[ \\t]*)?(?:nothing|none|anything|no|not|neither)\\b)${NOT_AN_EDIT_OBJECT}|made[ \\t]+(?:(?:the|some|several|a[ \\t]+few|these|those|following|minor|small)[ \\t]+)*(?:changes?|edits?|modifications?|fixes|updates?)\\b)`,
98
+ "i"
99
+ );
100
+ var OPENER_CLAIM_RE = new RegExp(`^[ \\t]{0,3}(?:${OPENER_VERBS})${NOT_AN_EDIT_OBJECT}[ \\t]+(?:(?:the|a|an|this|these|my|our)[ \\t]|\`[^\`\\n]+\`|[\\w./-]+\\.[A-Za-z]{1,5}\\b)`, "im");
101
+ var CHANGES_HEADER_RE = /(?:^|\n)[ \t]*(?:#{1,6}[ \t]*)?[*_]*(?:changes(?: made)?|what (?:I|we) (?:changed|did)|files (?:changed|modified|edited))[*_]*[ \t]*(?::[*_]*[ \t]*|(?=\n))([^\n]*(?:\n[ \t]*(?:[-*•]|\d+[.)])[ \t]+[^\n]*)*)/i;
102
+ var NEGATED_LIST_RE = /^[([]?\s*(?:none|nothing|n\/a|na|no|not|zero|0|[-–—]+)\b|^[-–—]+\s*$/i;
103
+ var NOT_A_REPORT_ITEM_RE = /^(?:recommend|suggest|propos|consider|could|should)|\b(?:only read|read[- ]only|no (?:changes|edits)|made no (?:changes|edits))\b/i;
104
+ function claimsOwnChange(report) {
105
+ const text = report.replace(FENCED_BLOCK_RE, "").replace(QUOTED_LINE_RE, "").replace(/\n[ \t]*(?=\n)/g, "");
106
+ const header = CHANGES_HEADER_RE.exec(text);
107
+ if (header !== null) {
108
+ const listed = (header[1] ?? "").trim().replace(/^(?:[-*•]|\d+[.)])[ \t]*/, "");
109
+ const firstItem = listed.split("\n")[0] ?? "";
110
+ if (listed !== "" && !NEGATED_LIST_RE.test(listed) && !NOT_A_REPORT_ITEM_RE.test(firstItem)) return true;
111
+ }
112
+ const prose = DIFF_EVIDENCE_RE.test(text) ? text.replace(DIFF_LINE_RE, "") : text;
113
+ return FIRST_PERSON_CLAIM_RE.test(prose) || OPENER_CLAIM_RE.test(prose);
114
+ }
115
+
116
+ // src/agent_receipt.ts
117
+ var RECEIPTS_SUFFIX = ".agent-receipts";
118
+ var MAX_RECEIPTS = 16;
119
+ var MAX_NAMED_FILES = 3;
120
+ var GIT_STATUS_TIMEOUT_MS = 5e3;
121
+ var LINE_PREFIX = "token-goat:";
122
+ var RECEIPT_TTL_MS = 30 * 60 * 1e3;
123
+ var RECEIPTS_LOCK_SUFFIX = ".agent-receipts.lock";
124
+ var RECEIPT_LOCK_WAIT_MS = 2e3;
125
+ function capReceipts(receipts) {
126
+ let excess = receipts.length - MAX_RECEIPTS;
127
+ if (excess <= 0) return receipts;
128
+ const dropped = /* @__PURE__ */ new Set();
129
+ for (const wantClean of [true, false]) {
130
+ for (const r of receipts) {
131
+ if (excess > 0 && r.text === "" === wantClean && !dropped.has(r)) {
132
+ dropped.add(r);
133
+ excess--;
134
+ }
135
+ }
136
+ }
137
+ return receipts.filter((r) => !dropped.has(r));
138
+ }
139
+ function reportHash(trimmedReport) {
140
+ return createHash("sha256").update(trimmedReport).digest("hex").slice(0, 16);
141
+ }
142
+ function receiptLines(state, claimsChangeWithoutEdit) {
143
+ const lines = [];
144
+ if (state.failingUnresolved && state.latestRun !== void 0) {
145
+ lines.push(`${LINE_PREFIX} this subagent's last check failed: ${echoedCommand(state.latestRun.command)} (exit ${state.latestRun.exitCode}).`);
146
+ }
147
+ if (state.editedSinceLastPass.length > 0) {
148
+ const named = state.editedSinceLastPass.slice(0, MAX_NAMED_FILES).map((name) => nameSubject("file", name)).join(", ");
149
+ const more = state.editedSinceLastPass.length - MAX_NAMED_FILES;
150
+ lines.push(`${LINE_PREFIX} this subagent edited after its last passing check: ${named}${more > 0 ? ` (+${more} more)` : ""}.`);
151
+ }
152
+ if (claimsChangeWithoutEdit) lines.push(`${LINE_PREFIX} the report claims a change, but this subagent recorded no edit and the working tree is clean.`);
153
+ return lines;
154
+ }
155
+ function claimsChangeTheTreeLacks(report, cwd) {
156
+ if (cwd === null || !claimsOwnChange(report) || claimsCommittedChange(report)) return false;
157
+ const result = runGit(["status", "--porcelain"], { cwd, timeoutMs: GIT_STATUS_TIMEOUT_MS });
158
+ return result.exitCode === 0 && result.stdout.trim() === "";
159
+ }
160
+ function receiptForStoppedAgent(event, redactedReport) {
161
+ const config = loadConfig().hints;
162
+ if (!config.agent_receipt || isWithinQuietHours(config.quiet_hours)) return null;
163
+ const state = evaluateVerification(sessionStateKey(event));
164
+ const claimsWithoutEdit = !state.editedAnyFile && claimsChangeTheTreeLacks(redactedReport, getCwd(event) || null);
165
+ const lines = receiptLines(state, claimsWithoutEdit);
166
+ return lines.length === 0 ? null : lines.join("\n");
167
+ }
168
+ function readReceipts(target) {
169
+ try {
170
+ const parsed = JSON.parse(readFileSync(target, "utf8"));
171
+ if (!Array.isArray(parsed)) return [];
172
+ const oldest = Date.now() - RECEIPT_TTL_MS;
173
+ return parsed.filter(
174
+ (r) => r !== null && typeof r === "object" && typeof r.hash === "string" && typeof r.length === "number" && typeof r.text === "string" && typeof r.at === "number" && r.at >= oldest
175
+ );
176
+ } catch {
177
+ return [];
178
+ }
179
+ }
180
+ function withReceipts(sessionId, create, work) {
181
+ const target = sessionSidecarPath(sessionId, RECEIPTS_SUFFIX);
182
+ const lockPath = sessionSidecarPath(sessionId, RECEIPTS_LOCK_SUFFIX);
183
+ if (target === null || lockPath === null) return null;
184
+ if (!create && (!existsSync(target) || readReceipts(target).length === 0)) return null;
185
+ try {
186
+ ensureDirSync(dirname(target));
187
+ const held = withFileLock(
188
+ lockPath,
189
+ () => {
190
+ const receipts = readReceipts(target);
191
+ const before = JSON.stringify(receipts);
192
+ const out = work(receipts);
193
+ const after = JSON.stringify(capReceipts(receipts));
194
+ if (after !== before) atomicWriteText(target, after);
195
+ return { out };
196
+ },
197
+ { waitMs: RECEIPT_LOCK_WAIT_MS }
198
+ );
199
+ return held === void 0 ? null : held.out;
200
+ } catch {
201
+ return null;
202
+ }
203
+ }
204
+ function parkAgentReceipt(sessionId, redactedReport, text, agentId) {
205
+ const trimmed = redactedReport.trim();
206
+ if (trimmed === "") return;
207
+ const entry = { hash: reportHash(trimmed), length: trimmed.length, text: redactSecrets(text).text, at: Date.now(), ...agentId ? { agentId } : {} };
208
+ withReceipts(sessionId, true, (receipts) => {
209
+ receipts.push(entry);
210
+ });
211
+ }
212
+ var AGENT_ID_TRAILER_RE = /\bagentId:\s*([A-Za-z0-9_-]{6,})/g;
213
+ function trailerAgentId(resultText) {
214
+ const matches = [...resultText.slice(-600).matchAll(AGENT_ID_TRAILER_RE)];
215
+ return matches.at(-1)?.[1];
216
+ }
217
+ function takeAgentReceipt(sessionId, resultText, agentId) {
218
+ const trimmed = resultText.trim();
219
+ const wantedId = agentId ?? trailerAgentId(trimmed);
220
+ const endsReport = (r) => r.length === trimmed.length || trimmed[r.length] === "\n" || trimmed[r.length] === "\r";
221
+ const sameText = (r) => r.length <= trimmed.length && endsReport(r) && reportHash(trimmed.slice(0, r.length)) === r.hash;
222
+ return withReceipts(sessionId, false, (receipts) => {
223
+ const byId = wantedId === void 0 ? -1 : receipts.findIndex((r) => r.agentId === wantedId);
224
+ if (byId >= 0 && (agentId !== void 0 || sameText(receipts[byId]))) return receipts.splice(byId, 1)[0]?.text || null;
225
+ if (agentId !== void 0) return null;
226
+ const candidates = receipts.map((r, i) => ({ r, i })).filter(({ r }) => sameText(r) && (wantedId === void 0 || r.agentId === void 0));
227
+ if (candidates.length === 0 || candidates.some(({ r }) => r.text !== candidates[0].r.text)) return null;
228
+ return receipts.splice(candidates[0].i, 1)[0]?.text || null;
229
+ });
230
+ }
231
+ function subagentReceiptHandler(event) {
232
+ try {
233
+ const raw = event.raw["last_assistant_message"];
234
+ if (getHarnessName() === "copilot_cli" || !event.sessionId || typeof raw !== "string" || raw === "" || event.raw["stop_hook_active"] === true) return passOutput();
235
+ const report = redactSecrets(raw).text;
236
+ const text = receiptForStoppedAgent(event, report);
237
+ if (text !== null || loadConfig().hints.agent_receipt) parkAgentReceipt(event.sessionId, report, text ?? "", event.agentId);
238
+ return passOutput();
239
+ } catch {
240
+ return passOutput();
241
+ }
242
+ }
243
+ function subagentStopHandler(event) {
244
+ try {
245
+ const cwd = getCwd(event);
246
+ if (!event.sessionId || !cwd) return passOutput();
247
+ const message = typeof event.raw["last_assistant_message"] === "string" ? event.raw["last_assistant_message"] : "";
248
+ if (!claimsOwnChange(message) || claimsCommittedChange(message)) return passOutput();
249
+ const result = runGit(["status", "--porcelain"], { cwd, timeoutMs: loadConfig().hints.git_hint_max_ms });
250
+ if (result.exitCode === 0 && result.stdout.trim() === "") {
251
+ console.warn(`subagent-stop: possible hallucination \u2014 session=${event.sessionId} but git status is clean`);
252
+ }
253
+ return passOutput();
254
+ } catch {
255
+ return passOutput();
256
+ }
257
+ }
258
+ function completedSubagents(toolResponse) {
259
+ let parsed = toolResponse;
260
+ if (typeof toolResponse === "string") {
261
+ try {
262
+ parsed = JSON.parse(toolResponse);
263
+ } catch {
264
+ return [];
265
+ }
266
+ }
267
+ const status = parsed !== null && typeof parsed === "object" ? parsed["status"] : void 0;
268
+ if (status === null || typeof status !== "object") return [];
269
+ const out = [];
270
+ for (const [agentId, value] of Object.entries(status)) {
271
+ const report = value !== null && typeof value === "object" ? value["completed"] : void 0;
272
+ if (typeof report === "string" && report !== "") out.push({ agentId, report });
273
+ }
274
+ return out;
275
+ }
276
+ function waitAgentReceipts(sessionId, toolResponse) {
277
+ const finished = completedSubagents(toolResponse);
278
+ const blocks = [];
279
+ for (const { agentId, report } of finished) {
280
+ const text = takeAgentReceipt(sessionId, redactSecrets(report).text, agentId);
281
+ if (text !== null) blocks.push(finished.length > 1 ? `${LINE_PREFIX} agent ${echoedCommand(agentId)}:
282
+ ${text}` : text);
283
+ }
284
+ return blocks;
285
+ }
286
+ function waitAgentHandler(event) {
287
+ try {
288
+ if (!event.sessionId) return passOutput();
289
+ const blocks = waitAgentReceipts(event.sessionId, event.raw["tool_response"]);
290
+ if (blocks.length === 0) return passOutput();
291
+ recordStat("agent_receipt", 0, 0, void 0, "agent");
292
+ return contextOutput(blocks.join("\n"));
293
+ } catch {
294
+ return passOutput();
295
+ }
296
+ }
297
+ export {
298
+ claimsChangeTheTreeLacks,
299
+ parkAgentReceipt,
300
+ receiptForStoppedAgent,
301
+ receiptLines,
302
+ subagentReceiptHandler,
303
+ subagentStopHandler,
304
+ takeAgentReceipt,
305
+ waitAgentHandler,
306
+ waitAgentReceipts
307
+ };
@@ -2,20 +2,20 @@ import { createRequire as __cjsRequire } from 'node:module';
2
2
  const require = __cjsRequire(import.meta.url);
3
3
  import {
4
4
  registerHook
5
- } from "./token-goat-chunk-P4QMM4WK.mjs";
6
- import {
7
- ensureWorkerAlive
8
- } from "./token-goat-chunk-5KDMCMF2.mjs";
5
+ } from "./token-goat-chunk-C75NA7PL.mjs";
9
6
  import {
10
7
  passOutput
11
- } from "./token-goat-chunk-VPBBTSJR.mjs";
8
+ } from "./token-goat-chunk-76FGDLRO.mjs";
9
+ import {
10
+ ensureWorkerAlive
11
+ } from "./token-goat-chunk-F6PAUIEK.mjs";
12
12
  import {
13
13
  isUnderSystemTemp
14
- } from "./token-goat-chunk-7IN2MKDS.mjs";
14
+ } from "./token-goat-chunk-4GBVPH3D.mjs";
15
15
  import {
16
16
  atomicWriteBytes,
17
17
  ensureDirSync
18
- } from "./token-goat-chunk-GOLEOXZP.mjs";
18
+ } from "./token-goat-chunk-HU4TORC5.mjs";
19
19
  import {
20
20
  foldPath
21
21
  } from "./token-goat-chunk-AM5V6GSX.mjs";
@@ -25,7 +25,7 @@ import {
25
25
  } from "./token-goat-chunk-FNFBKLRD.mjs";
26
26
  import {
27
27
  dataDir
28
- } from "./token-goat-chunk-VES7EL7O.mjs";
28
+ } from "./token-goat-chunk-CO3UYX6G.mjs";
29
29
  import {
30
30
  init_define_import_meta_env
31
31
  } from "./token-goat-chunk-A37V4PBF.mjs";
@@ -113,19 +113,47 @@ function appendDirtyQueueFile(filePath, absPaths) {
113
113
  }
114
114
  function appendDirtyQueuePaths(dir, absPaths) {
115
115
  if (absPaths.length === 0) return true;
116
- const queuePath = dirtyQueuePathFor(dir);
116
+ return appendToClaimableFile(dirtyQueuePathFor(dir), renderDirtyQueueLines(absPaths));
117
+ }
118
+ function appendToClaimableFile(queuePath, body) {
117
119
  const queueDir = path.dirname(queuePath);
118
120
  try {
119
121
  ensureDirSync(queueDir);
120
122
  } catch (e) {
121
123
  if (e.code !== "EEXIST" || !fs.existsSync(queueDir)) throw e;
122
124
  }
123
- const body = renderDirtyQueueLines(absPaths);
124
125
  for (let attempt = 0; attempt < 3; attempt++) {
125
126
  if (appendToLiveQueue(queuePath, `${dirtyQueueLeadingNewline(queuePath)}${body}`)) return true;
126
127
  }
127
128
  return false;
128
129
  }
130
+ function reconcileRequestPathFor(dir) {
131
+ return path.join(dir, "queue", "reconcile.txt");
132
+ }
133
+ function appendReconcileRequest(dir, projectDir) {
134
+ return appendToClaimableFile(reconcileRequestPathFor(dir), `${JSON.stringify(projectDir)}
135
+ `);
136
+ }
137
+ function parseReconcileRequests(raw) {
138
+ const seen = /* @__PURE__ */ new Set();
139
+ const out = [];
140
+ for (const line of raw.split("\n")) {
141
+ const trimmed = line.trim();
142
+ if (trimmed === "") continue;
143
+ let dir;
144
+ try {
145
+ dir = JSON.parse(trimmed);
146
+ } catch {
147
+ continue;
148
+ }
149
+ if (typeof dir !== "string" || dir === "") continue;
150
+ const key = foldPath(normalizePath(dir));
151
+ if (seen.has(key)) continue;
152
+ seen.add(key);
153
+ out.push(dir);
154
+ }
155
+ return out;
156
+ }
129
157
 
130
158
  // src/hooks_index.ts
131
159
  init_define_import_meta_env();
@@ -148,7 +176,8 @@ function enqueueDirtyPathsSafe(filePaths, opts) {
148
176
  resolved.push(r);
149
177
  }
150
178
  if (resolved.length === 0) return 0;
151
- appendDirtyPaths(resolved);
179
+ if (opts?.dir !== void 0) appendDirtyQueuePaths(opts.dir, resolved);
180
+ else appendDirtyPaths(resolved);
152
181
  } catch {
153
182
  return 0;
154
183
  }
@@ -158,6 +187,18 @@ function enqueueDirtyPathsSafe(filePaths, opts) {
158
187
  }
159
188
  return resolved.length;
160
189
  }
190
+ function requestReconcileSafe(projectDir) {
191
+ try {
192
+ if (!appendReconcileRequest(dataDir(), projectDir)) return false;
193
+ } catch {
194
+ return false;
195
+ }
196
+ try {
197
+ ensureWorkerAlive();
198
+ } catch {
199
+ }
200
+ return true;
201
+ }
161
202
  function getDirtyPaths() {
162
203
  return getDirtyPathsFor(dataDir());
163
204
  }
@@ -182,7 +223,11 @@ export {
182
223
  getDirtyPathsFor,
183
224
  appendDirtyQueueFile,
184
225
  appendDirtyQueuePaths,
226
+ reconcileRequestPathFor,
227
+ appendReconcileRequest,
228
+ parseReconcileRequests,
185
229
  appendDirtyPath,
186
230
  enqueueDirtyPathSafe,
187
- enqueueDirtyPathsSafe
231
+ enqueueDirtyPathsSafe,
232
+ requestReconcileSafe
188
233
  };
@@ -5,8 +5,11 @@ import {
5
5
  } from "./token-goat-chunk-3BTK54F3.mjs";
6
6
  import {
7
7
  compileGuardedRegexCached,
8
- filtersFilteredToEmptyNotice
9
- } from "./token-goat-chunk-GOLEOXZP.mjs";
8
+ countNoun
9
+ } from "./token-goat-chunk-HU4TORC5.mjs";
10
+ import {
11
+ echoedValue
12
+ } from "./token-goat-chunk-GGGG7RWB.mjs";
10
13
  import {
11
14
  displaySafeText
12
15
  } from "./token-goat-chunk-FNFBKLRD.mjs";
@@ -16,6 +19,39 @@ import {
16
19
 
17
20
  // src/csv_query.ts
18
21
  init_define_import_meta_env();
22
+
23
+ // src/query_notices.ts
24
+ init_define_import_meta_env();
25
+ function headElidedNotice(hidden, noun) {
26
+ return `...(${countNoun(hidden, `more ${noun}`)} elided; use --head to see more)`;
27
+ }
28
+ function traversalLimitNotice(matched) {
29
+ if (matched === 0) return "...(no matches: the search stopped at this tool's traversal limit before finding any, so the part of the document it did not reach may still hold some. Narrow the path to search less of the document.)";
30
+ return "...(the search stopped early at this tool's traversal limit; these are not necessarily all the matches. Narrow the path to search less of the document.)";
31
+ }
32
+
33
+ // src/filter_notice.ts
34
+ init_define_import_meta_env();
35
+ function allOfCount(count, singular, plural = `${singular}s`) {
36
+ return count === 1 ? `the only ${singular}` : `all ${count} ${plural}`;
37
+ }
38
+ function filteredSubject(count, singular, plural) {
39
+ const one = count === 1;
40
+ return { subject: `${allOfCount(count, singular, plural)} ${one ? "was" : "were"}`, pronoun: one ? "it" : "them" };
41
+ }
42
+ function grepFilteredToEmptyNotice(preFilterCount, grep, nounSingular, nounPlural) {
43
+ const { subject, pronoun } = filteredSubject(preFilterCount, nounSingular, nounPlural);
44
+ return ` (${subject} filtered out by --grep ${displaySafeText(grep)} -- widen or drop the filter to see ${pronoun})`;
45
+ }
46
+ function filtersFilteredToEmptyNotice(preFilterCount, activeFilters, nounSingular, nounPlural, reassurance) {
47
+ const { subject, pronoun } = filteredSubject(preFilterCount, nounSingular, nounPlural);
48
+ const cause = activeFilters.length === 0 ? "the active filter" : activeFilters.map(displaySafeText).join(" + ");
49
+ const knob = activeFilters.length > 1 ? "filters" : "filter";
50
+ const tail = reassurance === void 0 ? "" : `; ${reassurance}`;
51
+ return ` (${subject} filtered out by ${cause}${tail} -- widen or drop the ${knob} to see ${pronoun})`;
52
+ }
53
+
54
+ // src/csv_query.ts
19
55
  var DELIMITER_CANDIDATES = [",", " ", ";", "|"];
20
56
  var DELIMITER_SAMPLE_ROWS = 5;
21
57
  function detectDelimiter(content) {
@@ -80,7 +116,7 @@ function parseWhereSpecs(specs) {
80
116
  const op = m[2];
81
117
  const value = m[3];
82
118
  if ((op === ">" || op === "<" || op === ">=" || op === "<=") && value.trim() === "") {
83
- throw new Error(`invalid --where spec: ${spec} (missing comparison value after '${op}')`);
119
+ throw new Error(`invalid --where spec: ${spec} (missing comparison value after ${echoedValue(op)})`);
84
120
  }
85
121
  if (op === "~=") {
86
122
  const guarded = compileGuardedRegexCached(value);
@@ -174,7 +210,7 @@ function formatCsvTable(result, activeFilters = []) {
174
210
  ...result.rows.map((r) => r.map(quoteCsvCell).join(","))
175
211
  ];
176
212
  if (result.totalRows > result.rows.length) {
177
- lines.push(`...(${result.totalRows - result.rows.length} more rows elided; use --head to see more)`);
213
+ lines.push(headElidedNotice(result.totalRows - result.rows.length, "row"));
178
214
  }
179
215
  if (result.totalRows === 0 && result.preFilterRows > 0) {
180
216
  lines.push(filtersFilteredToEmptyNotice(result.preFilterRows, activeFilters, "data row", "data rows"));
@@ -229,6 +265,12 @@ function formatCsvProfile(profiles) {
229
265
  }
230
266
 
231
267
  export {
268
+ headElidedNotice,
269
+ traversalLimitNotice,
270
+ allOfCount,
271
+ filteredSubject,
272
+ grepFilteredToEmptyNotice,
273
+ filtersFilteredToEmptyNotice,
232
274
  parseWhereSpecs,
233
275
  queryCsv,
234
276
  quoteCsvCell,
@@ -8,7 +8,7 @@ import {
8
8
  init_define_import_meta_env();
9
9
  import { createRequire } from "node:module";
10
10
  function readManifest() {
11
- if (true) return JSON.parse('{"version":"2.9.30","name":"token-goat","bugs":{"url":"https://github.com/DFKHelper/token-goat/issues"}}');
11
+ if (true) return JSON.parse('{"version":"2.9.31","name":"token-goat","bugs":{"url":"https://github.com/DFKHelper/token-goat/issues"}}');
12
12
  try {
13
13
  return createRequire(import.meta.url)("../package.json");
14
14
  } catch {
@@ -0,0 +1,154 @@
1
+ import { createRequire as __cjsRequire } from 'node:module';
2
+ const require = __cjsRequire(import.meta.url);
3
+ import {
4
+ FIND_SCAN_LIMIT,
5
+ findParentName,
6
+ findSymbolCandidates
7
+ } from "./token-goat-chunk-4SC7UJYV.mjs";
8
+ import {
9
+ indexedSourceText
10
+ } from "./token-goat-chunk-QH7YVYOY.mjs";
11
+ import {
12
+ querySymbols
13
+ } from "./token-goat-chunk-IK2DRMFX.mjs";
14
+ import {
15
+ getDb,
16
+ pathEqClause
17
+ } from "./token-goat-chunk-GVB2MUST.mjs";
18
+ import {
19
+ fingerprintContent
20
+ } from "./token-goat-chunk-4GBVPH3D.mjs";
21
+ import {
22
+ foldPath
23
+ } from "./token-goat-chunk-AM5V6GSX.mjs";
24
+ import {
25
+ globalDbPath
26
+ } from "./token-goat-chunk-CO3UYX6G.mjs";
27
+ import {
28
+ init_define_import_meta_env
29
+ } from "./token-goat-chunk-A37V4PBF.mjs";
30
+
31
+ // src/notes.ts
32
+ init_define_import_meta_env();
33
+ import * as fs from "node:fs";
34
+ var WHOLE_FILE_NOTE_SYMBOL = "";
35
+ function toNoteRow(row) {
36
+ return {
37
+ id: row.id,
38
+ filePath: row.file_path,
39
+ symbol: row.symbol,
40
+ content: row.content,
41
+ fingerprint: row.fingerprint,
42
+ createdAt: row.created_at,
43
+ updatedAt: row.updated_at
44
+ };
45
+ }
46
+ function declarationGroups(rows, dbPath) {
47
+ const fileSymbols = /* @__PURE__ */ new Map();
48
+ const groups = /* @__PURE__ */ new Map();
49
+ for (const row of rows) {
50
+ let siblings = fileSymbols.get(row.filePath);
51
+ if (siblings === void 0) {
52
+ siblings = querySymbols({ filePath: row.filePath, limit: FIND_SCAN_LIMIT }, dbPath);
53
+ fileSymbols.set(row.filePath, siblings);
54
+ }
55
+ const parent = findParentName(row, siblings);
56
+ const key = JSON.stringify([row.filePath, parent]);
57
+ const group = groups.get(key);
58
+ if (group === void 0) groups.set(key, { parent, rows: [row] });
59
+ else group.rows.push(row);
60
+ }
61
+ return [...groups.values()];
62
+ }
63
+ function groupEntry(group) {
64
+ const rows = [...group].sort((x, y) => x.lineStart - y.lineStart);
65
+ const first = rows[0];
66
+ if (rows.length === 1 && first.body !== "") return first;
67
+ const body = rows.map((r) => r.body !== "" ? r.body : bodyFromSource(r)).join("\n");
68
+ return { ...first, lineEnd: Math.max(...rows.map((r) => r.lineEnd)), body };
69
+ }
70
+ function resolveSymbolMatch(filePath, symbolName, dbPath = globalDbPath()) {
71
+ const { candidates, displaySymbol } = findSymbolCandidates(filePath, filePath, symbolName, void 0, dbPath);
72
+ const seen = /* @__PURE__ */ new Set();
73
+ const distinct = candidates.filter((c) => {
74
+ const key = `${c.filePath}|${c.lineStart}|${c.lineEnd}`;
75
+ if (seen.has(key)) return false;
76
+ seen.add(key);
77
+ return true;
78
+ });
79
+ if (distinct.length === 0) return { kind: "none" };
80
+ if (distinct.length === 1) return { kind: "ok", entry: groupEntry(distinct) };
81
+ const groups = declarationGroups(distinct, dbPath);
82
+ if (groups.length === 1) return { kind: "ok", entry: groupEntry(groups[0].rows) };
83
+ const fileLevel = groups.find((g) => g.parent === null);
84
+ if (fileLevel !== void 0 && !symbolName.includes(".")) return { kind: "ok", entry: groupEntry(fileLevel.rows) };
85
+ const declarations = groups.map((g) => ({ entry: groupEntry(g.rows), qualifiedName: g.parent === null ? displaySymbol : `${g.parent}.${displaySymbol}` })).sort((x, y) => x.entry.lineStart - y.entry.lineStart);
86
+ return { kind: "ambiguous", symbol: displaySymbol, candidates: declarations };
87
+ }
88
+ function bodyFromSource(entry) {
89
+ try {
90
+ return indexedSourceText(entry.filePath, fs.readFileSync(entry.filePath, "utf8")).split(/\r?\n/).slice(Math.max(0, entry.lineStart - 1), entry.lineEnd).join("\n");
91
+ } catch {
92
+ return "";
93
+ }
94
+ }
95
+ function symbolNamesInFile(filePath, dbPath = globalDbPath()) {
96
+ const symbols = querySymbols({ filePath, limit: -1 }, dbPath);
97
+ return [...new Set(symbols.map((s) => s.name))].sort();
98
+ }
99
+ function computeFileFingerprint(filePath, dbPath = globalDbPath()) {
100
+ const symbols = querySymbols({ filePath, limit: -1 }, dbPath);
101
+ const manifest = symbols.map((s) => `${s.name}:${s.kind}:${s.lineStart}-${s.lineEnd}`).sort().join("\n");
102
+ return fingerprintContent(manifest);
103
+ }
104
+ function computeSymbolFingerprints(filePath, symbolName, dbPath = globalDbPath()) {
105
+ const match = resolveSymbolMatch(filePath, symbolName, dbPath);
106
+ if (match.kind === "none") return [];
107
+ return (match.kind === "ok" ? [match.entry] : match.candidates.map((c) => c.entry)).map((e) => fingerprintContent(e.body));
108
+ }
109
+ function upsertNote(filePath, symbol, content, fingerprint, dbPath = globalDbPath()) {
110
+ const db = getDb(dbPath);
111
+ const now = Date.now() / 1e3;
112
+ db.transaction(() => {
113
+ const updated = db.prepare(`UPDATE notes SET content = ?, fingerprint = ?, updated_at = ? WHERE ${pathEqClause("file_path")} AND symbol = ?`).run(content, fingerprint, now, foldPath(filePath), symbol);
114
+ if (updated.changes > 0) return;
115
+ db.prepare("INSERT INTO notes (file_path, symbol, content, fingerprint, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?)").run(
116
+ filePath,
117
+ symbol,
118
+ content,
119
+ fingerprint,
120
+ now,
121
+ now
122
+ );
123
+ }).immediate();
124
+ }
125
+ function getNote(filePath, symbol, dbPath = globalDbPath()) {
126
+ const db = getDb(dbPath);
127
+ const row = db.prepare(
128
+ `SELECT id, file_path, symbol, content, fingerprint, created_at, updated_at FROM notes WHERE ${pathEqClause("file_path")} AND symbol = ?`
129
+ ).get(foldPath(filePath), symbol);
130
+ return row === void 0 ? null : toNoteRow(row);
131
+ }
132
+ function listNotes(dbPath = globalDbPath()) {
133
+ const db = getDb(dbPath);
134
+ const rows = db.prepare(
135
+ "SELECT id, file_path, symbol, content, fingerprint, created_at, updated_at FROM notes ORDER BY file_path, symbol"
136
+ ).all();
137
+ return rows.map(toNoteRow);
138
+ }
139
+ function isNoteStale(note, dbPath = globalDbPath()) {
140
+ if (note.symbol !== WHOLE_FILE_NOTE_SYMBOL) return !computeSymbolFingerprints(note.filePath, note.symbol, dbPath).includes(note.fingerprint);
141
+ return computeFileFingerprint(note.filePath, dbPath) !== note.fingerprint;
142
+ }
143
+
144
+ export {
145
+ WHOLE_FILE_NOTE_SYMBOL,
146
+ resolveSymbolMatch,
147
+ symbolNamesInFile,
148
+ computeFileFingerprint,
149
+ computeSymbolFingerprints,
150
+ upsertNote,
151
+ getNote,
152
+ listNotes,
153
+ isNoteStale
154
+ };