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
@@ -59,8 +59,13 @@ import {
59
59
  truncateMiddle,
60
60
  truncateMiddleSmart,
61
61
  truncateTableRows
62
- } from "./token-goat-chunk-KWPNJBDH.mjs";
62
+ } from "./token-goat-chunk-4GILLLWY.mjs";
63
63
  import "./token-goat-chunk-HAVAOB3S.mjs";
64
+ import "./token-goat-chunk-HU4TORC5.mjs";
65
+ import "./token-goat-chunk-GGGG7RWB.mjs";
66
+ import "./token-goat-chunk-AM5V6GSX.mjs";
67
+ import "./token-goat-chunk-FNFBKLRD.mjs";
68
+ import "./token-goat-chunk-CO3UYX6G.mjs";
64
69
  import "./token-goat-chunk-A37V4PBF.mjs";
65
70
  export {
66
71
  DEFAULT_MAX_BYTES,
@@ -1,15 +1,15 @@
1
1
  import { createRequire as __cjsRequire } from 'node:module';
2
2
  const require = __cjsRequire(import.meta.url);
3
- import {
4
- DELIVERS_CONTENT_RE
5
- } from "./token-goat-chunk-MNWKPRAL.mjs";
6
3
  import {
7
4
  splitShellSegments,
8
5
  stripLeadingAssignments
9
- } from "./token-goat-chunk-APGZXSPS.mjs";
6
+ } from "./token-goat-chunk-DGS2LVNA.mjs";
7
+ import {
8
+ DELIVERS_CONTENT_RE
9
+ } from "./token-goat-chunk-MNWKPRAL.mjs";
10
10
  import {
11
11
  safeSlice
12
- } from "./token-goat-chunk-GOLEOXZP.mjs";
12
+ } from "./token-goat-chunk-HU4TORC5.mjs";
13
13
  import {
14
14
  init_define_import_meta_env
15
15
  } from "./token-goat-chunk-A37V4PBF.mjs";
@@ -57,7 +57,7 @@ var EXPECTED_PATTERNS = [
57
57
  // 16: the file changed on disk after the last read.
58
58
  { reason: "file_modified_since_read", tools: ["Edit", "MultiEdit", "Write"], re: /^File has been modified since read/ },
59
59
  // 643 (578 Bash, 53 Read, 11 Grep, 1 Edit): a path that does not exist, in each tool's own wording.
60
- { reason: "path_not_found", re: /No such file or directory|^File does not exist\.|^Path does not exist:/ },
60
+ { reason: "path_not_found", re: /No such file or directory|^File does not exist\.|^Path does not exist(?:[:.]|[ \t]*(?:\r?\n|$))/ },
61
61
  // 1,171: an interpreter raising: a Python traceback header, the `Node.js vN.N.N` line Node prints under every uncaught error, or a named error line (`SyntaxError: ...`). After path_not_found, so a missing file stays a missing file whichever language reported it.
62
62
  { reason: "script_exception", tools: ["Bash"], re: /^(?:Traceback \(most recent call last\):|Node\.js v\d+\.\d+\.\d+\b|[A-Z]\w*(?:Error|Exception)(?: \[\w+\])?: )/m },
63
63
  // 14: a Read over the harness's size ceiling.
@@ -0,0 +1,50 @@
1
+ import { createRequire as __cjsRequire } from 'node:module';
2
+ const require = __cjsRequire(import.meta.url);
3
+ import {
4
+ init_define_import_meta_env
5
+ } from "./token-goat-chunk-A37V4PBF.mjs";
6
+
7
+ // src/mcp_client_text.ts
8
+ init_define_import_meta_env();
9
+ import { AsyncLocalStorage } from "node:async_hooks";
10
+ var mcpToolCall = new AsyncLocalStorage();
11
+ var TOKEN_GOAT_RETRY_RE = /token-goat (\w[\w-]*) (?:"([^"]+)"|'([^']+)')/g;
12
+ var RETRY_PARAM_BY_COMMAND = {
13
+ read: "spec",
14
+ section: "spec",
15
+ symbol: "name",
16
+ skeleton: "file",
17
+ outline: "file",
18
+ semantic: "query"
19
+ };
20
+ function answeringMcpToolCall(fn, listed) {
21
+ return mcpToolCall.run({ listed }, fn);
22
+ }
23
+ function mcpToolListed(name) {
24
+ const store = mcpToolCall.getStore();
25
+ return store?.listed === void 0 || store.listed.has(name);
26
+ }
27
+ function forClient(note) {
28
+ return mcpToolCall.getStore() !== void 0 ? mcpFriendlyText(note) : note;
29
+ }
30
+ function mcpFriendlyText(text) {
31
+ let out = text.replace(TOKEN_GOAT_RETRY_RE, (_match, cmd, doubleQuoted, singleQuoted) => {
32
+ if (!mcpToolListed(cmd)) return "a narrower request";
33
+ const param = RETRY_PARAM_BY_COMMAND[cmd] ?? "parameter";
34
+ const value = doubleQuoted ?? singleQuoted ?? "";
35
+ const example = /["`]/.test(value) ? "" : ` (e.g. "${value}")`;
36
+ return `the "${cmd}" tool again with a more specific ${param}${example}`;
37
+ });
38
+ out = out.replace(/--json\b/g, "the json parameter");
39
+ out = out.replace(/--limit\b/g, "the limit parameter");
40
+ out = out.replace(/--top\b/g, "the top parameter");
41
+ out = out.replace(/--grep PATTERN, --section HEADING, or --tail N/g, "a narrower query");
42
+ return out;
43
+ }
44
+
45
+ export {
46
+ answeringMcpToolCall,
47
+ mcpToolListed,
48
+ forClient,
49
+ mcpFriendlyText
50
+ };
@@ -0,0 +1,433 @@
1
+ import { createRequire as __cjsRequire } from 'node:module';
2
+ const require = __cjsRequire(import.meta.url);
3
+ import {
4
+ indexRecallEntry,
5
+ isBlobStale,
6
+ isBuildCommand,
7
+ isDevServerCommand,
8
+ isTestRunnerCommand,
9
+ loadBlob,
10
+ parsePorcelainZ,
11
+ storeBlob
12
+ } from "./token-goat-chunk-4ZBFWLXF.mjs";
13
+ import {
14
+ redactSecrets
15
+ } from "./token-goat-chunk-T5P5ACNQ.mjs";
16
+ import {
17
+ shortFingerprint
18
+ } from "./token-goat-chunk-4GBVPH3D.mjs";
19
+ import {
20
+ registerReset
21
+ } from "./token-goat-chunk-YZAAZU2S.mjs";
22
+ import {
23
+ runGit
24
+ } from "./token-goat-chunk-HU4TORC5.mjs";
25
+ import {
26
+ normalizePath
27
+ } from "./token-goat-chunk-FNFBKLRD.mjs";
28
+ import {
29
+ init_define_import_meta_env
30
+ } from "./token-goat-chunk-A37V4PBF.mjs";
31
+
32
+ // src/bash_output_cache.ts
33
+ init_define_import_meta_env();
34
+ import { readdirSync, readFileSync, statSync } from "fs";
35
+ import { resolve } from "path";
36
+ var BASH_OUTPUT_SUBDIR = "bash_outputs";
37
+ var _byId = /* @__PURE__ */ new Map();
38
+ var COMMAND_PATTERNS = {
39
+ gitMutable: /^\s*git\s+(diff|status)\b/i,
40
+ gitImmutable: /^\s*git\s+show\s+[0-9a-f]{40}\b/i,
41
+ gitDiffScoped: /\s--\s+\S/,
42
+ dirListing: /^\s*(?:ls|eza|exa|dir|Get-ChildItem|gci)\b/i,
43
+ depList: /^\s*(?:npm\s+(?:--?[a-zA-Z0-9_-]+(?:\s+|=))*(?:ls|list)\b|pip\s+(?:--?[a-zA-Z0-9_-]+(?:\s+|=))*(?:list|freeze)\b|uv\s+pip\s+(?:--?[a-zA-Z0-9_-]+(?:\s+|=))*(?:list|freeze)\b|pnpm\s+(?:--?[a-zA-Z0-9_-]+(?:\s+|=))*(?:list|ls)\b|yarn\s+(?:--?[a-zA-Z0-9_-]+(?:\s+|=))*(?:list)\b|cargo\s+(?:--?[a-zA-Z0-9_-]+(?:\s+|=))*tree\b|bundle\s+(?:--?[a-zA-Z0-9_-]+(?:\s+|=))*(?:list|show)\b|composer\s+(?:--?[a-zA-Z0-9_-]+(?:\s+|=))*show\b)/i,
44
+ npmInstall: /^\s*npm\s+(?:--?[a-zA-Z0-9_-]+(?:\s+|=))*(?:install|ci)\b/i,
45
+ npmAudit: /^\s*npm\s+(?:--?[a-zA-Z0-9_-]+(?:\s+|=))*audit\b(?!.*(?:--fix|fix)\b)/i,
46
+ npmOutdated: /^\s*npm\s+(?:--?[a-zA-Z0-9_-]+(?:\s+|=))*outdated\b/i,
47
+ envProbe: /^\s*(?:node\s+(?:-v|--version)|npm\s+(?:-v|--version)|python3?\s+(?:(?:-V)\b|--?version)|git\s+--version|uv\s+--version|go\s+version|rustc\s+--version|cargo\s+--version|java\s+--version|ruby\s+--version|gem\s+--version|php\s+--version|which\b|where\b)/i,
48
+ npx: /^(?!.*\b(?:install|add|remove|uninstall|i|rm|update|upgrade|set|get|publish|link|ci|audit|shrinkwrap|dedupe|prune|rebuild)\b)\s*npx\s+(?:--?yes\s+)?/i,
49
+ gitPush: /^\s*git\s+push\b/i,
50
+ lintCommand: /^\s*(?:(?:npx\s+)?eslint|(?:uv\s+run\s+)?ruff)\b/i,
51
+ npmRunScript: /^\s*npm\s+run(?:-script)?\b/i,
52
+ catCommand: /^\s*cat\b/i
53
+ };
54
+ var DEP_LOCKFILES = {
55
+ npm: ["package-lock.json", "yarn.lock"],
56
+ pip: ["requirements.txt"],
57
+ uv: ["uv.lock", "requirements.txt"],
58
+ pnpm: ["pnpm-lock.yaml"],
59
+ yarn: ["yarn.lock"],
60
+ cargo: ["Cargo.lock"],
61
+ bundle: ["Gemfile.lock"],
62
+ composer: ["composer.lock"]
63
+ };
64
+ function isCommandOfType(cmd, type) {
65
+ const pattern = COMMAND_PATTERNS[type];
66
+ return pattern?.test(cmd) ?? false;
67
+ }
68
+ var isGitMutableCommand = (cmd) => isCommandOfType(cmd, "gitMutable");
69
+ var isDirListingCommand = (cmd) => isCommandOfType(cmd, "dirListing");
70
+ var isDepListCommand = (cmd) => isCommandOfType(cmd, "depList");
71
+ var isNpmInstallCommand = (cmd) => isCommandOfType(cmd, "npmInstall");
72
+ var isNpmAuditCommand = (cmd) => isCommandOfType(cmd, "npmAudit");
73
+ var isNpmOutdatedCommand = (cmd) => isCommandOfType(cmd, "npmOutdated");
74
+ var isGitPushCommand = (cmd) => isCommandOfType(cmd, "gitPush");
75
+ var isLintCommand = (cmd) => isCommandOfType(cmd, "lintCommand");
76
+ var isNpmRunScriptCommand = (cmd) => isCommandOfType(cmd, "npmRunScript");
77
+ var isCatCommand = (cmd) => isCommandOfType(cmd, "catCommand");
78
+ function isScopedGitStatusOrDiffStatCommand(cmd) {
79
+ if (!isCommandOfType(cmd, "gitMutable")) return false;
80
+ if (!isCommandOfType(cmd, "gitDiffScoped")) return false;
81
+ if (/^\s*git\s+diff\b/i.test(cmd) && !/--stat\b/.test(cmd)) return false;
82
+ return true;
83
+ }
84
+ var STATUS_STAT_CAP = 2e3;
85
+ function statusPathStats(root, porcelainZ) {
86
+ const out = [];
87
+ for (const { path: rel } of parsePorcelainZ(porcelainZ).slice(0, STATUS_STAT_CAP)) {
88
+ const st = statSync(resolve(root, rel), { throwIfNoEntry: false });
89
+ out.push(st ? `${rel}:${st.mtimeMs}:${st.size}` : `${rel}:-`);
90
+ }
91
+ return out.join("\0");
92
+ }
93
+ function gitStateFingerprintSync(cwd) {
94
+ try {
95
+ const headResult = runGit(["rev-parse", "--show-toplevel", "HEAD"], { cwd });
96
+ if (headResult.exitCode !== 0) return null;
97
+ const [root = "", headSha = ""] = headResult.stdout.trim().split(/\r?\n/);
98
+ let statusHash = "";
99
+ const statusResult = runGit(["status", "--porcelain", "-z", "--untracked-files=all"], { cwd });
100
+ if (statusResult.exitCode === 0) {
101
+ statusHash = shortFingerprint(`${statusResult.stdout}\0${statusPathStats(root, statusResult.stdout)}`);
102
+ }
103
+ const key = `${headSha}\0${statusHash}`;
104
+ return shortFingerprint(key);
105
+ } catch {
106
+ return null;
107
+ }
108
+ }
109
+ var DIR_FINGERPRINT_LISTING_CAP_ENTRIES = 1e4;
110
+ function dirStateFingerprintSync(path) {
111
+ try {
112
+ const stat = statSync(path);
113
+ if (!stat.isDirectory()) return null;
114
+ const entries = readdirSync(path);
115
+ if (entries.length <= DIR_FINGERPRINT_LISTING_CAP_ENTRIES) {
116
+ return shortFingerprint(entries.slice().sort().join("\0"));
117
+ }
118
+ return shortFingerprint(stat.mtimeMs.toString());
119
+ } catch {
120
+ return null;
121
+ }
122
+ }
123
+ var FILE_FINGERPRINT_CONTENT_CAP_BYTES = 2 * 1024 * 1024;
124
+ function fileStateFingerprintSync(path) {
125
+ try {
126
+ const stat = statSync(path);
127
+ if (!stat.isFile()) return null;
128
+ if (stat.size <= FILE_FINGERPRINT_CONTENT_CAP_BYTES) {
129
+ return shortFingerprint(readFileSync(path));
130
+ }
131
+ return shortFingerprint(`${stat.mtimeMs}\0${stat.size}`);
132
+ } catch {
133
+ return null;
134
+ }
135
+ }
136
+ function depLockfileFingerprintSync(cmd, cwd) {
137
+ if (!cwd) return null;
138
+ const stripped = cmd.trim();
139
+ const firstToken = stripped.split(/\s+/)[0]?.toLowerCase() || "";
140
+ if (!firstToken) return null;
141
+ const candidates = firstToken === "uv" ? DEP_LOCKFILES["uv"] : DEP_LOCKFILES[firstToken];
142
+ if (!candidates) return null;
143
+ for (const lockfile of candidates) {
144
+ try {
145
+ const content = readFileSync(resolve(cwd, lockfile));
146
+ return shortFingerprint(content);
147
+ } catch {
148
+ continue;
149
+ }
150
+ }
151
+ return null;
152
+ }
153
+ function normalizeCommandForCacheKey(cmd) {
154
+ const trimmed = cmd.trim();
155
+ const tokens = [];
156
+ let current = "";
157
+ let quoteChar = null;
158
+ const flush = () => {
159
+ if (current.length > 0) {
160
+ tokens.push(current);
161
+ current = "";
162
+ }
163
+ };
164
+ for (let i = 0; i < trimmed.length; i++) {
165
+ const ch = trimmed[i];
166
+ if (quoteChar !== null) {
167
+ current += ch;
168
+ if (ch === quoteChar) quoteChar = null;
169
+ continue;
170
+ }
171
+ if (ch === '"' || ch === "'") {
172
+ quoteChar = ch;
173
+ current += ch;
174
+ continue;
175
+ }
176
+ if (/\s/.test(ch)) {
177
+ flush();
178
+ continue;
179
+ }
180
+ current += ch === "\\" ? "/" : ch;
181
+ }
182
+ flush();
183
+ const normalized_tokens = tokens.map((token) => {
184
+ if (token.startsWith("-") || ["&&", "||", "|", ">", ">>", ";", "&"].includes(token)) {
185
+ return token;
186
+ }
187
+ if (token.startsWith("./") && !token.startsWith("../")) {
188
+ token = token.slice(2);
189
+ }
190
+ if (token.endsWith("/") && token !== "/") {
191
+ token = token.slice(0, -1);
192
+ }
193
+ return token || ".";
194
+ });
195
+ return normalized_tokens.join(" ");
196
+ }
197
+ function commandHashSync(command, cwd = null, gitState = () => cwd ? gitStateFingerprintSync(cwd) : null) {
198
+ const normalized = normalizeCommandForCacheKey(command);
199
+ let key = cwd ? `${normalizePath(cwd)}\0${normalized}` : normalized;
200
+ if (cwd && isGitMutableCommand(command)) {
201
+ const fp = gitState();
202
+ if (fp) key = `${key}\0git:${fp}`;
203
+ }
204
+ if (cwd && isDirListingCommand(command)) {
205
+ const target = extractFirstPathArg(command, cwd, cwd);
206
+ if (target) {
207
+ const fp = dirStateFingerprintSync(target);
208
+ if (fp) key = `${key}\0dir:${fp}`;
209
+ }
210
+ }
211
+ if (isDepListCommand(command)) {
212
+ const fp = depLockfileFingerprintSync(command, cwd);
213
+ if (fp) key = `${key}\0lockfile:${fp}`;
214
+ }
215
+ if (cwd && (isNpmInstallCommand(command) || isNpmAuditCommand(command) || isNpmOutdatedCommand(command))) {
216
+ const fp = depLockfileFingerprintSync(command, cwd);
217
+ if (fp) key = `${key}\0npm-install:${fp}`;
218
+ }
219
+ return shortFingerprint(key);
220
+ }
221
+ function commandHash(command, cwd = null) {
222
+ return Promise.resolve(commandHashSync(command, cwd));
223
+ }
224
+ function bashOutputIdSync(command, output, cwd = null) {
225
+ return outputIdFromCommandHash(commandHashSync(command, cwd), output);
226
+ }
227
+ function outputIdFromCommandHash(commandKey, output) {
228
+ return shortFingerprint(`${commandKey}\0${output}`);
229
+ }
230
+ function computeBashFingerprints(command, cwd, gitState = () => cwd ? gitStateFingerprintSync(cwd) : null) {
231
+ const fingerprints = {};
232
+ if (cwd && (isGitMutableCommand(command) || isGitPushCommand(command) || isTestRunnerCommand(command) || isLintCommand(command) || isBuildCommand(command) || isDevServerCommand(command) || isNpmRunScriptCommand(command))) {
233
+ const fp = gitState();
234
+ if (fp) fingerprints.git = fp;
235
+ }
236
+ if (cwd && isDirListingCommand(command)) {
237
+ const target = extractFirstPathArg(command, cwd, cwd);
238
+ if (target) {
239
+ const fp = dirStateFingerprintSync(target);
240
+ if (fp) fingerprints.dir = fp;
241
+ }
242
+ }
243
+ if (isDepListCommand(command) || cwd && (isNpmInstallCommand(command) || isNpmAuditCommand(command) || isNpmOutdatedCommand(command))) {
244
+ const fp = depLockfileFingerprintSync(command, cwd);
245
+ if (fp) fingerprints.lockfile = fp;
246
+ }
247
+ if (cwd && isCatCommand(command)) {
248
+ const target = extractFirstPathArg(command, cwd, null);
249
+ if (target) {
250
+ const fp = fileStateFingerprintSync(target);
251
+ if (fp) fingerprints.file = fp;
252
+ }
253
+ }
254
+ return Object.keys(fingerprints).length > 0 ? fingerprints : void 0;
255
+ }
256
+ function isBashEntryStale(entry, command, cwd) {
257
+ const stored = entry.fingerprints;
258
+ if (!stored) return false;
259
+ const current = computeBashFingerprints(command, cwd);
260
+ if (stored.git !== void 0 && stored.git !== current?.git) return true;
261
+ if (stored.dir !== void 0 && stored.dir !== current?.dir) return true;
262
+ if (stored.lockfile !== void 0 && stored.lockfile !== current?.lockfile) return true;
263
+ if (stored.file !== void 0 && stored.file !== current?.file) return true;
264
+ return false;
265
+ }
266
+ function tokenizeShellArgs(cmd) {
267
+ const trimmed = cmd.trim();
268
+ const tokens = [];
269
+ let current = "";
270
+ let quoteChar = null;
271
+ let hasToken = false;
272
+ for (let i = 0; i < trimmed.length; i++) {
273
+ const ch = trimmed[i];
274
+ if (quoteChar !== null) {
275
+ if (ch === quoteChar) {
276
+ quoteChar = null;
277
+ } else {
278
+ current += ch;
279
+ }
280
+ continue;
281
+ }
282
+ if (ch === '"' || ch === "'") {
283
+ quoteChar = ch;
284
+ hasToken = true;
285
+ continue;
286
+ }
287
+ if (/\s/.test(ch)) {
288
+ if (hasToken) {
289
+ tokens.push(current);
290
+ current = "";
291
+ hasToken = false;
292
+ }
293
+ continue;
294
+ }
295
+ current += ch;
296
+ hasToken = true;
297
+ }
298
+ if (hasToken) tokens.push(current);
299
+ return tokens;
300
+ }
301
+ function extractFirstPathArg(cmd, cwd, fallback) {
302
+ const tokens = tokenizeShellArgs(cmd);
303
+ for (let i = 1; i < tokens.length; i++) {
304
+ const token = tokens[i];
305
+ if (!token.startsWith("-")) {
306
+ if (!token.startsWith("/")) {
307
+ return resolve(cwd, token);
308
+ }
309
+ return token;
310
+ }
311
+ }
312
+ return fallback;
313
+ }
314
+ var ISSUE_LINE_PATTERN = /\b(?:error|fail(?:ed|ure)?|warning)\b/i;
315
+ function summarizeOutputDelta(oldOutput, newOutput) {
316
+ if (oldOutput === newOutput) return null;
317
+ const oldLines = oldOutput.split("\n");
318
+ const newLines = newOutput.split("\n");
319
+ const oldIssueLines = oldLines.filter((l) => ISSUE_LINE_PATTERN.test(l));
320
+ if (oldIssueLines.length > 0) {
321
+ const newIssueLines = newLines.filter((l) => ISSUE_LINE_PATTERN.test(l));
322
+ const priorTotal = oldIssueLines.length;
323
+ const availableCounts = /* @__PURE__ */ new Map();
324
+ for (const l of newIssueLines) availableCounts.set(l, (availableCounts.get(l) ?? 0) + 1);
325
+ let resolved = 0;
326
+ for (const l of oldIssueLines) {
327
+ const avail = availableCounts.get(l) ?? 0;
328
+ if (avail > 0) {
329
+ availableCounts.set(l, avail - 1);
330
+ } else {
331
+ resolved++;
332
+ }
333
+ }
334
+ const remaining = newIssueLines.length;
335
+ return `[token-goat: delta] ${resolved} of ${priorTotal} prior issues resolved; remaining: ${remaining}`;
336
+ }
337
+ return `[token-goat: delta] output changed: ${oldLines.length} -> ${newLines.length} lines`;
338
+ }
339
+ function storeBashOutputSync(command, output, exitCode, cwd = null) {
340
+ let gitState = null;
341
+ const gitStateOnce = () => (gitState ??= { value: cwd ? gitStateFingerprintSync(cwd) : null }).value;
342
+ const commandKey = commandHashSync(command, cwd, gitStateOnce);
343
+ const id = outputIdFromCommandHash(commandKey, output);
344
+ const fingerprints = computeBashFingerprints(command, cwd, gitStateOnce);
345
+ const redactedOutput = redactSecrets(output).text;
346
+ const redactedCommand = redactSecrets(command).text;
347
+ const entry = {
348
+ id,
349
+ command: redactedCommand,
350
+ output: redactedOutput,
351
+ exitCode,
352
+ storedAt: Date.now(),
353
+ sizeBytes: Buffer.byteLength(redactedOutput, "utf-8"),
354
+ ...fingerprints ? { fingerprints } : {}
355
+ };
356
+ _byId.set(id, entry);
357
+ _byId.set(commandKey, entry);
358
+ storeBlob(BASH_OUTPUT_SUBDIR, id, entry);
359
+ if (commandKey !== id) storeBlob(BASH_OUTPUT_SUBDIR, commandKey, { latestId: id });
360
+ indexRecallEntry("bash", id, redactedCommand, `${redactedCommand}
361
+ ${redactedOutput}`, entry.storedAt);
362
+ return id;
363
+ }
364
+ function coerceBashRedirect(raw) {
365
+ if (raw === null || typeof raw !== "object") return null;
366
+ const latest = raw["latestId"];
367
+ return typeof latest === "string" && latest.length > 0 ? latest : null;
368
+ }
369
+ function storeBashOutput(command, output, exitCode, cwd = null) {
370
+ return Promise.resolve(storeBashOutputSync(command, output, exitCode, cwd));
371
+ }
372
+ function coerceBashEntry(raw) {
373
+ if (raw === null || typeof raw !== "object") return null;
374
+ const o = raw;
375
+ if (typeof o["id"] !== "string" || typeof o["command"] !== "string" || typeof o["output"] !== "string" || typeof o["exitCode"] !== "number" || typeof o["storedAt"] !== "number" || typeof o["sizeBytes"] !== "number") {
376
+ return null;
377
+ }
378
+ const entry = {
379
+ id: o["id"],
380
+ command: o["command"],
381
+ output: o["output"],
382
+ exitCode: o["exitCode"],
383
+ storedAt: o["storedAt"],
384
+ sizeBytes: o["sizeBytes"]
385
+ };
386
+ const rawFingerprints = o["fingerprints"];
387
+ if (rawFingerprints !== null && typeof rawFingerprints === "object") {
388
+ const f = rawFingerprints;
389
+ const fingerprints = {};
390
+ if (typeof f["git"] === "string") fingerprints.git = f["git"];
391
+ if (typeof f["dir"] === "string") fingerprints.dir = f["dir"];
392
+ if (typeof f["lockfile"] === "string") fingerprints.lockfile = f["lockfile"];
393
+ if (typeof f["file"] === "string") fingerprints.file = f["file"];
394
+ if (Object.keys(fingerprints).length > 0) return { ...entry, fingerprints };
395
+ }
396
+ return entry;
397
+ }
398
+ function getBashOutput(id) {
399
+ const hit = _byId.get(id);
400
+ if (hit !== void 0) return hit;
401
+ if (isBlobStale(BASH_OUTPUT_SUBDIR, id)) return null;
402
+ const raw = loadBlob(BASH_OUTPUT_SUBDIR, id);
403
+ const target = coerceBashRedirect(raw);
404
+ if (target !== null) {
405
+ if (isBlobStale(BASH_OUTPUT_SUBDIR, target)) return null;
406
+ const latest = coerceBashEntry(loadBlob(BASH_OUTPUT_SUBDIR, target));
407
+ if (latest === null) return null;
408
+ _byId.set(target, latest);
409
+ _byId.set(id, latest);
410
+ return latest;
411
+ }
412
+ const entry = coerceBashEntry(raw);
413
+ if (entry === null) return null;
414
+ _byId.set(id, entry);
415
+ return entry;
416
+ }
417
+ registerReset(() => {
418
+ _byId = /* @__PURE__ */ new Map();
419
+ }, { perRequest: true });
420
+
421
+ export {
422
+ BASH_OUTPUT_SUBDIR,
423
+ isLintCommand,
424
+ isScopedGitStatusOrDiffStatCommand,
425
+ normalizeCommandForCacheKey,
426
+ commandHash,
427
+ bashOutputIdSync,
428
+ isBashEntryStale,
429
+ summarizeOutputDelta,
430
+ storeBashOutputSync,
431
+ storeBashOutput,
432
+ getBashOutput
433
+ };