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
@@ -1,397 +0,0 @@
1
- import { createRequire as __cjsRequire } from 'node:module';
2
- const require = __cjsRequire(import.meta.url);
3
- import {
4
- deliveredOutputBytes
5
- } from "./token-goat-chunk-54K3EUV3.mjs";
6
- import {
7
- PassthroughFilter,
8
- TOOL_FILTERS,
9
- compressedTokensSaved,
10
- deliverCompressed,
11
- dispatchArgv,
12
- filterByName,
13
- selectFilter
14
- } from "./token-goat-chunk-COBQGL5S.mjs";
15
- import {
16
- storeBashOutputSync
17
- } from "./token-goat-chunk-AFLYLHDH.mjs";
18
- import {
19
- recordStat
20
- } from "./token-goat-chunk-3Z5S4KGM.mjs";
21
- import {
22
- loadConfig
23
- } from "./token-goat-chunk-7IN2MKDS.mjs";
24
- import {
25
- displaySafeText
26
- } from "./token-goat-chunk-FNFBKLRD.mjs";
27
- import {
28
- capTokens,
29
- shlexSplit
30
- } from "./token-goat-chunk-KWPNJBDH.mjs";
31
- import {
32
- init_define_import_meta_env
33
- } from "./token-goat-chunk-A37V4PBF.mjs";
34
-
35
- // src/bash_runner.ts
36
- init_define_import_meta_env();
37
- import { spawn, spawnSync } from "node:child_process";
38
- import * as os from "node:os";
39
-
40
- // src/shell.ts
41
- init_define_import_meta_env();
42
- import * as fs from "node:fs";
43
- import * as path from "node:path";
44
- var WSL_LAUNCHER_SEGMENTS = /* @__PURE__ */ new Set(["system32", "syswow64", "windowsapps"]);
45
- function isExecutable(p) {
46
- try {
47
- return fs.statSync(p).isFile();
48
- } catch {
49
- return false;
50
- }
51
- }
52
- function isWslLauncherDir(dir) {
53
- return dir.toLowerCase().split(/[\\/]+/).some((seg) => WSL_LAUNCHER_SEGMENTS.has(seg));
54
- }
55
- function locateBashOnPath(pathValue, isExe = isExecutable) {
56
- for (const dir of (pathValue ?? "").split(path.delimiter)) {
57
- if (!dir || isWslLauncherDir(dir)) continue;
58
- const cand = path.join(dir, "bash.exe");
59
- if (isExe(cand)) return cand;
60
- }
61
- return null;
62
- }
63
- function knownGitBashPaths() {
64
- const localPrograms = process.env["LOCALAPPDATA"] ? path.join(process.env["LOCALAPPDATA"], "Programs") : void 0;
65
- const bases = [
66
- process.env["ProgramFiles"],
67
- process.env["ProgramFiles(x86)"],
68
- process.env["ProgramW6432"],
69
- localPrograms
70
- ];
71
- const out = [];
72
- for (const base of bases) {
73
- if (!base) continue;
74
- out.push(path.join(base, "Git", "bin", "bash.exe"));
75
- out.push(path.join(base, "Git", "usr", "bin", "bash.exe"));
76
- }
77
- return out;
78
- }
79
- function resolveWindowsBash() {
80
- if (process.platform !== "win32") return null;
81
- const override = process.env["TOKEN_GOAT_BASH"];
82
- if (override && isExecutable(override)) return override;
83
- const onPath = locateBashOnPath(process.env["PATH"]);
84
- if (onPath) return onPath;
85
- for (const cand of knownGitBashPaths()) {
86
- if (isExecutable(cand)) return cand;
87
- }
88
- return null;
89
- }
90
- function wrappedShell() {
91
- if (process.platform !== "win32") return true;
92
- return resolveWindowsBash() ?? true;
93
- }
94
- function canRunWrappedShell() {
95
- return process.platform !== "win32" || resolveWindowsBash() !== null;
96
- }
97
- function resolvePowerShell(env = process.env, isExe = isExecutable) {
98
- const override = env["TOKEN_GOAT_POWERSHELL"] || env["TOKEN_GOAT_PWSH"];
99
- if (override && isExe(override)) return override;
100
- if (process.platform === "win32") {
101
- for (const dir of (env["PATH"] ?? "").split(path.delimiter)) {
102
- if (!dir) continue;
103
- const cand = path.join(dir, "pwsh.exe");
104
- if (isExe(cand)) return cand;
105
- }
106
- const systemRoot = env["SystemRoot"] ?? env["windir"] ?? "C:\\Windows";
107
- const defaultPs = path.join(systemRoot, "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
108
- if (isExe(defaultPs)) return defaultPs;
109
- return "powershell.exe";
110
- }
111
- for (const dir of (env["PATH"] ?? "").split(path.delimiter)) {
112
- if (!dir) continue;
113
- const cand = path.join(dir, "pwsh");
114
- if (isExe(cand)) return cand;
115
- }
116
- for (const cand of ["/usr/bin/pwsh", "/usr/local/bin/pwsh", "/opt/microsoft/powershell/7/pwsh"]) {
117
- if (isExe(cand)) return cand;
118
- }
119
- return "pwsh";
120
- }
121
- function canRunPowerShell(env = process.env, isExe = isExecutable) {
122
- if (process.platform === "win32") return true;
123
- try {
124
- const ps = resolvePowerShell(env, isExe);
125
- return isExe(ps);
126
- } catch {
127
- return false;
128
- }
129
- }
130
-
131
- // src/bash_runner.ts
132
- var DEFAULT_TIMEOUT_SECONDS = 600;
133
- var MAX_CAPTURE_BYTES = 32 * 1024 * 1024;
134
- var MIN_RECORD_STAT_BYTES = 32;
135
- var DEFAULT_HEARTBEAT_INTERVAL_MS = 15e3;
136
- var CaptureSink = class {
137
- constructor(cap) {
138
- this.cap = cap;
139
- }
140
- cap;
141
- chunks = [];
142
- bytes = 0;
143
- overflowed = false;
144
- push(chunk) {
145
- if (this.overflowed) return;
146
- this.bytes += chunk.length;
147
- if (this.bytes > this.cap) {
148
- this.overflowed = true;
149
- return;
150
- }
151
- this.chunks.push(chunk);
152
- }
153
- text() {
154
- return decode(Buffer.concat(this.chunks));
155
- }
156
- };
157
- function scheduleHeartbeat(startTime, intervalMs, write) {
158
- let interval = intervalMs;
159
- let timer;
160
- const arm = () => {
161
- timer = setTimeout(() => {
162
- write(Math.round((Date.now() - startTime) / 1e3));
163
- interval *= 2;
164
- arm();
165
- }, interval);
166
- timer.unref();
167
- };
168
- arm();
169
- return {
170
- onOutput: () => {
171
- interval = intervalMs;
172
- if (timer !== void 0) clearTimeout(timer);
173
- arm();
174
- },
175
- stop: () => {
176
- if (timer !== void 0) clearTimeout(timer);
177
- }
178
- };
179
- }
180
- function resolveFilter(command, filterName, cwd) {
181
- const effectiveCwd = cwd ?? process.cwd();
182
- let split;
183
- try {
184
- split = shlexSplit(command);
185
- } catch {
186
- split = null;
187
- }
188
- const argv = split === null ? [command] : dispatchArgv(split, effectiveCwd).argv;
189
- if (filterName) {
190
- const named = filterByName(filterName);
191
- if (named !== null) return { filter: named, argv };
192
- const filter = split === null ? null : selectFilter(split, effectiveCwd);
193
- return { filter, argv, unknownFilter: filterName };
194
- }
195
- if (split === null) return { filter: null, argv };
196
- return { filter: selectFilter(split, effectiveCwd), argv };
197
- }
198
- function baseSpawnOptions(timeout, cwd) {
199
- return { timeout: timeout * 1e3, cwd };
200
- }
201
- function spawnTarget(command, nativeShell, shellType) {
202
- if (shellType === "pwsh" || shellType === "powershell") {
203
- const ps = resolvePowerShell();
204
- return {
205
- file: ps,
206
- args: [
207
- "-NoProfile",
208
- "-NonInteractive",
209
- "-Command",
210
- `$TgC = $env:TG_CMD; Remove-Item Env:TG_CMD -ErrorAction SilentlyContinue; $global:TgOk = $true; $TgN = [Environment]::NewLine; $TgK = 'if ($global:TgOk = $?) { }'; $TgT = $null; $TgE = $null; $TgA = [System.Management.Automation.Language.Parser]::ParseInput($TgC, [ref]$TgT, [ref]$TgE); $TgX = [System.Collections.Generic.List[object]]::new(); $TgL = [System.Collections.Generic.List[string]]::new(); $TgTop = { param($n) $p = $n.Parent; while ($p -isnot [System.Management.Automation.Language.ScriptBlockAst]) { $p = $p.Parent }; [object]::ReferenceEquals($p, $TgA) }; if ($TgE.Count -eq 0) { if ($TgA.EndBlock.Unnamed) { $TgX.Add([pscustomobject]@{ P = $TgC.Length; O = 0; L = 0; T = ($TgN + $TgK) }) }; foreach ($TgB in @($TgA.BeginBlock, $TgA.ProcessBlock, $TgA.EndBlock, $TgA.CleanBlock)) { if ($TgB -and -not $TgB.Unnamed) { $TgX.Add([pscustomobject]@{ P = ($TgB.Extent.EndOffset - 1); O = 0; L = 0; T = ($TgN + $TgK + $TgN) }) } }; foreach ($TgR in $TgA.FindAll({ param($n) $n -is [System.Management.Automation.Language.ReturnStatementAst] -and (& $TgTop $n) }, $true)) { if ($TgR.Pipeline -and $TgR.Pipeline.GetPureExpression()) { $TgX.Add([pscustomobject]@{ P = $TgR.Extent.StartOffset; O = 1; L = 6; T = '$TgW = (' }); $TgX.Add([pscustomobject]@{ P = $TgR.Extent.EndOffset; O = 1; L = 0; T = '), $?; $global:TgOk = $TgW[1]; return $TgW[0]' }) } else { $TgX.Add([pscustomobject]@{ P = $TgR.Extent.StartOffset; O = 1; L = 6; T = 'return $(' }); $TgX.Add([pscustomobject]@{ P = $TgR.Extent.EndOffset; O = 1; L = 0; T = $(if ($TgR.Pipeline) { '; ' + $TgK + ')' } else { $TgK + ')' }) }) } }; $TgD = @($TgA.FindAll({ param($n) $n -is [System.Management.Automation.Language.LabeledStatementAst] -and $n.Label }, $true) | ForEach-Object { $_.Label } | Select-Object -Unique); foreach ($TgR in $TgA.FindAll({ param($n) ($n -is [System.Management.Automation.Language.BreakStatementAst] -or $n -is [System.Management.Automation.Language.ContinueStatementAst]) -and (& $TgTop $n) }, $true)) { $TgX.Add([pscustomobject]@{ P = $TgR.Extent.StartOffset; O = 0; L = 0; T = ($TgK + '; ') }); if ($TgR.Label -is [System.Management.Automation.Language.StringConstantExpressionAst]) { if ($TgR.Label.Value -eq '') { } elseif ($TgD -contains $TgR.Label.Value) { $TgL.Add($TgR.Label.Value) } else { $TgX.Add([pscustomobject]@{ P = $TgR.Label.Extent.StartOffset; O = 1; L = $TgR.Label.Extent.Text.Length; T = 'TgEsc' }); $TgL.Add('TgEsc') } } elseif ($TgR.Label) { $TgX.Add([pscustomobject]@{ P = $TgR.Label.Extent.StartOffset; O = 1; L = $TgR.Label.Extent.Text.Length; T = ('$(if ((-not [string]($TgV = (' + $TgR.Label.Extent.Text + '))) -or (@(' + (($TgD | ForEach-Object { "'" + $_ + "'" }) -join ',') + ') -contains $TgV)) { $TgV } else { ''TgEsc'' }; if (-not $global:TgOk) { Microsoft.PowerShell.Utility\\Write-Error TgRestore -ErrorAction Ignore })') }); foreach ($TgI in $TgD) { $TgL.Add($TgI) }; $TgL.Add('TgEsc') } }; foreach ($TgR in $TgA.FindAll({ param($n) $n -is [System.Management.Automation.Language.TryStatementAst] -and $n.Finally -and $n.Finally.Statements.Count -gt 0 -and (& $TgTop $n) }, $true)) { $TgX.Add([pscustomobject]@{ P = ($TgR.Finally.Extent.EndOffset - 1); O = 0; L = 0; T = ($TgN + $TgK + $TgN) }) } } else { throw [System.Management.Automation.ParseException]::new($TgE) }; $TgS = $TgC; foreach ($TgI in ($TgX | Sort-Object -Property @{ Expression = 'P'; Descending = $true }, @{ Expression = 'O'; Descending = $false })) { $TgS = $TgS.Substring(0, $TgI.P) + $TgI.T + $TgS.Substring($TgI.P + $TgI.L) }; $TgO = $(if ($PSVersionTable.PSVersion.Major -lt 6) { 'do { @() | & ([scriptblock]::Create($TgS)) } while ($false)' } else { 'do { & ([scriptblock]::Create($TgS)) } while ($false)' }); foreach ($TgI in ($TgL | Select-Object -Unique)) { $TgO = ':' + $TgI + ' do { ' + $TgO + ' } while ($false)' }; . ([scriptblock]::Create($TgO)); if ($global:TgOk) { exit 0 } else { exit 1 }`
211
- ],
212
- shell: false,
213
- cmdEnv: { TG_CMD: command }
214
- };
215
- }
216
- const shell = nativeShell || shellType === "native" ? true : wrappedShell();
217
- if (typeof shell === "string") return { file: shell, args: ["-c", 'eval "$TG_CMD"'], shell: false, cmdEnv: { TG_CMD: command } };
218
- return { file: command, args: [], shell };
219
- }
220
- function mergeSpawnEnv(env, cmdEnv) {
221
- return cmdEnv ? { ...env ?? process.env, ...cmdEnv } : env;
222
- }
223
- function signalExitCode(signal) {
224
- const num = os.constants.signals[signal];
225
- return 128 + (num ?? 0);
226
- }
227
- function resolveProfile(explicit) {
228
- if (explicit) return explicit;
229
- try {
230
- const p = loadConfig().compression.profile;
231
- return p && p !== "auto" ? p : "balanced";
232
- } catch {
233
- return "balanced";
234
- }
235
- }
236
- function resolveCompressLimits() {
237
- try {
238
- const bc = loadConfig().bash_compress;
239
- return { maxLines: bc.max_lines, maxBytes: bc.max_bytes };
240
- } catch {
241
- return { maxLines: 1e3, maxBytes: 64 * 1024 };
242
- }
243
- }
244
- function unknownFilterNotice(name, fallback) {
245
- const typed = name.toLowerCase();
246
- const names = ["generic", "passthrough", ...new Set(TOOL_FILTERS.map((f) => f.name))];
247
- const near = names.filter((n) => n.split("-").some((word) => word.startsWith(typed)) || typed.startsWith(n)).slice(0, 5);
248
- const instead = fallback === null ? "running it uncompressed" : `auto-detected ${fallback.name}`;
249
- const hint = near.length > 0 ? `; did you mean ${near.join(", ")}?` : "";
250
- return `[token-goat: no filter named "${displaySafeText(name)}", ${instead}${hint}]
251
- `;
252
- }
253
- async function run(command, opts = {}) {
254
- const timeout = opts.timeout ?? DEFAULT_TIMEOUT_SECONDS;
255
- const { filter, argv, unknownFilter } = resolveFilter(command, opts.filterName, opts.cwd);
256
- if (unknownFilter !== void 0) (opts.writeStderr ?? ((s) => process.stderr.write(s)))(unknownFilterNotice(unknownFilter, filter));
257
- if (filter === null) {
258
- if ((opts.maxTokens ?? 0) > 0 || opts.quietSuccess) {
259
- return wrapAndCompress(command, argv, new PassthroughFilter(), timeout, resolveProfile(opts.compressionProfile), opts);
260
- }
261
- return passthrough(command, timeout, opts.cwd, opts.env, opts.nativeShell, opts.shellType);
262
- }
263
- return wrapAndCompress(command, argv, filter, timeout, resolveProfile(opts.compressionProfile), opts);
264
- }
265
- function runRaw(command, timeout = DEFAULT_TIMEOUT_SECONDS, nativeShell, shellType) {
266
- return passthrough(command, timeout, void 0, void 0, nativeShell, shellType);
267
- }
268
- function passthrough(command, timeout, cwd, env, nativeShell, shellType) {
269
- const { file, args, shell, cmdEnv } = spawnTarget(command, nativeShell, shellType);
270
- const result = spawnSync(file, args, {
271
- ...baseSpawnOptions(timeout, cwd),
272
- shell,
273
- env: mergeSpawnEnv(env, cmdEnv),
274
- stdio: "inherit"
275
- });
276
- if (isTimeout(result.error)) return 124;
277
- if (result.error) {
278
- process.stderr.write(`[token-goat: ${displaySafeText(result.error.message)}]
279
- `);
280
- return 127;
281
- }
282
- if (result.status !== null) return result.status;
283
- if (result.signal) return signalExitCode(result.signal);
284
- return 0;
285
- }
286
- function isTimeout(error) {
287
- return !!error && error.code === "ETIMEDOUT";
288
- }
289
- function decode(buf) {
290
- if (buf == null) return "";
291
- return typeof buf === "string" ? buf : buf.toString("utf8");
292
- }
293
- async function wrapAndCompress(command, argv, filter, timeout, profile, opts) {
294
- const writeStdout = opts.writeStdout ?? ((s) => process.stdout.write(s));
295
- const writeStderr = opts.writeStderr ?? ((s) => process.stderr.write(s));
296
- const startTime = Date.now();
297
- const { file, args, shell, cmdEnv } = spawnTarget(command, opts.nativeShell, opts.shellType);
298
- const stdoutSink = new CaptureSink(MAX_CAPTURE_BYTES);
299
- const stderrSink = new CaptureSink(MAX_CAPTURE_BYTES);
300
- let timedOut = false;
301
- let overflowed = false;
302
- const child = spawn(file, args, { cwd: opts.cwd, shell, env: mergeSpawnEnv(opts.env, cmdEnv), stdio: ["ignore", "pipe", "pipe"] });
303
- const heartbeat = scheduleHeartbeat(startTime, opts.heartbeatIntervalMs ?? DEFAULT_HEARTBEAT_INTERVAL_MS, (elapsed) => {
304
- writeStderr(`[token-goat compress] still running, ${elapsed}s elapsed
305
- `);
306
- });
307
- const timeoutHandle = setTimeout(() => {
308
- timedOut = true;
309
- child.kill();
310
- }, timeout * 1e3);
311
- const onData = (sink) => (chunk) => {
312
- heartbeat.onOutput();
313
- sink.push(chunk);
314
- if (sink.overflowed) {
315
- overflowed = true;
316
- child.kill();
317
- }
318
- };
319
- child.stdout?.on("data", onData(stdoutSink));
320
- child.stderr?.on("data", onData(stderrSink));
321
- let spawnError = null;
322
- const { code, signal } = await new Promise((resolve) => {
323
- child.on("error", (e) => {
324
- spawnError = e;
325
- resolve({ code: 127, signal: null });
326
- });
327
- child.on("close", (code2, signal2) => resolve({ code: code2, signal: signal2 }));
328
- });
329
- heartbeat.stop();
330
- clearTimeout(timeoutHandle);
331
- let stdoutText = stdoutSink.text();
332
- let stderrText = stderrSink.text();
333
- if (overflowed) {
334
- stdoutText += `
335
- [token-goat: capture capped at ${MAX_CAPTURE_BYTES / (1024 * 1024)} MiB]`;
336
- }
337
- if (spawnError !== null) stderrText = (stderrText ? stderrText + "\n" : "") + `[token-goat: ${displaySafeText(spawnError.message)}]`;
338
- let exitCode;
339
- if (timedOut) {
340
- exitCode = 124;
341
- stderrText = (stderrText ? stderrText + "\n" : "") + `[token-goat: command exceeded ${timeout}s timeout and was killed]`;
342
- } else if (code !== null) {
343
- exitCode = code;
344
- } else if (signal) {
345
- exitCode = signalExitCode(signal);
346
- } else {
347
- exitCode = 0;
348
- }
349
- if (opts.quietSuccess && exitCode === 0) {
350
- const duration = ((Date.now() - startTime) / 1e3).toFixed(1) + "s";
351
- const fullRaw = (stdoutText + (stderrText ? "\n" + stderrText : "")).trim();
352
- const id = storeBashOutputSync(command, fullRaw, 0, opts.cwd ?? null);
353
- const summary = `[tg: ok] ${command} (${duration}, recall: token-goat bash-output ${id})
354
- `;
355
- writeStdout(summary);
356
- return 0;
357
- }
358
- const limits = resolveCompressLimits();
359
- const { applied, marker, compressed, text: delivered } = deliverCompressed(filter, stdoutText, stderrText, exitCode, argv, {
360
- compressionProfile: profile,
361
- maxLines: limits.maxLines,
362
- maxBytes: limits.maxBytes
363
- });
364
- let text = delivered;
365
- const maxTokens = opts.maxTokens ?? 0;
366
- if (maxTokens > 0) text = capTokens(text, maxTokens);
367
- const capped = text !== delivered;
368
- let body = text + marker;
369
- if (applied || capped) {
370
- const fullRaw = (stdoutText + (stderrText ? "\n" + stderrText : "")).trim();
371
- const recallId = storeBashOutputSync(command, fullRaw, exitCode, opts.cwd ?? null);
372
- body += "\n[token-goat] full output: bash-output " + recallId + " --full";
373
- if (opts.capHint) body += "\n[token-goat] " + opts.capHint;
374
- }
375
- writeStdout(body.endsWith("\n") ? body : body + "\n");
376
- if (applied) recordSavings(compressed);
377
- return exitCode;
378
- }
379
- function recordSavings(result) {
380
- const delivered = deliveredOutputBytes(result.originalBytes);
381
- const bytesSaved = Math.max(0, delivered - result.compressedBytes);
382
- if (bytesSaved < MIN_RECORD_STAT_BYTES) return;
383
- recordStat(`bash_compress:${result.filterName}`, bytesSaved, compressedTokensSaved(bytesSaved));
384
- }
385
-
386
- export {
387
- canRunWrappedShell,
388
- canRunPowerShell,
389
- DEFAULT_TIMEOUT_SECONDS,
390
- MAX_CAPTURE_BYTES,
391
- DEFAULT_HEARTBEAT_INTERVAL_MS,
392
- resolveFilter,
393
- spawnTarget,
394
- unknownFilterNotice,
395
- run,
396
- runRaw
397
- };
@@ -1,248 +0,0 @@
1
- import { createRequire as __cjsRequire } from 'node:module';
2
- const require = __cjsRequire(import.meta.url);
3
- import {
4
- recordStat
5
- } from "./token-goat-chunk-3Z5S4KGM.mjs";
6
- import {
7
- redactSerializedJson
8
- } from "./token-goat-chunk-4FVIAHSI.mjs";
9
- import {
10
- loadConfig
11
- } from "./token-goat-chunk-7IN2MKDS.mjs";
12
- import {
13
- atomicWriteText,
14
- ensureDirSync,
15
- sanitizeIdForFilename
16
- } from "./token-goat-chunk-GOLEOXZP.mjs";
17
- import {
18
- tokenGoatHome
19
- } from "./token-goat-chunk-VES7EL7O.mjs";
20
- import {
21
- init_define_import_meta_env
22
- } from "./token-goat-chunk-A37V4PBF.mjs";
23
-
24
- // src/disk_cache.ts
25
- init_define_import_meta_env();
26
- import * as fs from "node:fs";
27
- import * as path from "node:path";
28
- var DEFAULT_MAX_COUNT = 200;
29
- var DEFAULT_MAX_AGE_MS = 24 * 3600 * 1e3;
30
- function sanitizeId(id) {
31
- return sanitizeIdForFilename(id, 64);
32
- }
33
- function blobDir(subdir) {
34
- return path.join(tokenGoatHome(), subdir);
35
- }
36
- function blobPath(subdir, id) {
37
- const safe = sanitizeId(id);
38
- if (!safe) return null;
39
- const dir = blobDir(subdir);
40
- const candidate = path.join(dir, `${safe}.json`);
41
- try {
42
- const rel = path.relative(dir, candidate);
43
- if (rel.startsWith("..")) return null;
44
- } catch {
45
- return null;
46
- }
47
- return candidate;
48
- }
49
- function isBlobStale(subdir, id) {
50
- const p = blobPath(subdir, id);
51
- if (p === null) return false;
52
- try {
53
- const stat = fs.statSync(p);
54
- return Date.now() - stat.mtimeMs > DEFAULT_MAX_AGE_MS;
55
- } catch {
56
- return false;
57
- }
58
- }
59
- function subdirCacheDefaults(subdir) {
60
- try {
61
- if (subdir === "bash_outputs") {
62
- const bc = loadConfig().bash_compress;
63
- return { maxCount: bc.cache_max_file_count, maxBytes: bc.cache_max_bytes, maxBytesPerItem: bc.cache_max_bytes_per_output };
64
- }
65
- if (subdir === "web_outputs") {
66
- const wf = loadConfig().webfetch;
67
- return { maxCount: wf.max_file_count, maxBytes: wf.max_bytes, maxBytesPerItem: Number.POSITIVE_INFINITY };
68
- }
69
- } catch {
70
- }
71
- return { maxCount: DEFAULT_MAX_COUNT, maxBytes: Number.POSITIVE_INFINITY, maxBytesPerItem: Number.POSITIVE_INFINITY };
72
- }
73
- function storeBlob(subdir, id, value, opts = {}) {
74
- const p = blobPath(subdir, id);
75
- if (!p) return false;
76
- const defaults = subdirCacheDefaults(subdir);
77
- const maxBytesPerItem = opts.maxBytesPerItem ?? defaults.maxBytesPerItem;
78
- let rawJson;
79
- try {
80
- rawJson = JSON.stringify(value);
81
- } catch {
82
- return false;
83
- }
84
- let json;
85
- try {
86
- const result = redactSerializedJson(rawJson);
87
- json = result.text;
88
- if (result.count > 0) recordStat("secret_redacted", 0, result.count, void 0, subdir);
89
- } catch {
90
- return false;
91
- }
92
- if (Number.isFinite(maxBytesPerItem) && Buffer.byteLength(json, "utf-8") > maxBytesPerItem) return false;
93
- try {
94
- const dir = path.dirname(p);
95
- if (!fs.existsSync(dir)) ensureDirSync(dir);
96
- atomicWriteText(p, json);
97
- } catch {
98
- return false;
99
- }
100
- pruneBlobs(
101
- subdir,
102
- opts.maxCount ?? defaults.maxCount,
103
- opts.maxAgeMs ?? DEFAULT_MAX_AGE_MS,
104
- opts.maxBytes ?? defaults.maxBytes,
105
- p
106
- );
107
- return true;
108
- }
109
- function loadBlob(subdir, id) {
110
- const p = blobPath(subdir, id);
111
- if (!p) return null;
112
- try {
113
- if (!fs.existsSync(p)) return null;
114
- return JSON.parse(fs.readFileSync(p, "utf8"));
115
- } catch {
116
- return null;
117
- }
118
- }
119
- function listBlobs(subdir) {
120
- const dir = blobDir(subdir);
121
- const out = [];
122
- try {
123
- if (!fs.existsSync(dir)) return out;
124
- for (const file of fs.readdirSync(dir)) {
125
- if (!file.endsWith(".json")) continue;
126
- const id = file.slice(0, -5);
127
- let mtime = 0;
128
- try {
129
- mtime = fs.statSync(path.join(dir, file)).mtimeMs;
130
- } catch {
131
- }
132
- const value = loadBlob(subdir, id);
133
- if (value !== null) out.push({ id, mtime, value });
134
- }
135
- } catch {
136
- return out;
137
- }
138
- return out;
139
- }
140
- function pruneBlobs(subdir, maxCount = DEFAULT_MAX_COUNT, maxAgeMs = DEFAULT_MAX_AGE_MS, maxBytes = Number.POSITIVE_INFINITY, protectedPath) {
141
- return pruneBlobDir(blobDir(subdir), maxCount, maxAgeMs, maxBytes, protectedPath);
142
- }
143
- function pruneBlobDir(dir, maxCount = DEFAULT_MAX_COUNT, maxAgeMs = DEFAULT_MAX_AGE_MS, maxBytes = Number.POSITIVE_INFINITY, protectedPath) {
144
- let removed = 0;
145
- try {
146
- if (!fs.existsSync(dir)) return 0;
147
- const cutoff = Date.now() - maxAgeMs;
148
- let kept = [];
149
- let protectedEntry;
150
- for (const file of fs.readdirSync(dir)) {
151
- const full = path.join(dir, file);
152
- let stat;
153
- try {
154
- stat = fs.statSync(full);
155
- } catch {
156
- continue;
157
- }
158
- if (!stat.isFile()) continue;
159
- if (protectedPath !== void 0 && full === protectedPath) {
160
- protectedEntry = [full, stat.mtimeMs, stat.size];
161
- continue;
162
- }
163
- if (stat.mtimeMs < cutoff) {
164
- try {
165
- fs.unlinkSync(full);
166
- removed++;
167
- } catch {
168
- continue;
169
- }
170
- } else if (file.endsWith(".json")) {
171
- kept.push([full, stat.mtimeMs, stat.size]);
172
- }
173
- }
174
- const countBudget = protectedEntry ? Math.max(0, maxCount - 1) : maxCount;
175
- if (kept.length > countBudget) {
176
- kept.sort((a, b) => a[1] - b[1]);
177
- const excess = kept.slice(0, kept.length - countBudget);
178
- kept = kept.slice(kept.length - countBudget);
179
- for (const [full] of excess) {
180
- try {
181
- fs.unlinkSync(full);
182
- removed++;
183
- } catch {
184
- continue;
185
- }
186
- }
187
- }
188
- if (Number.isFinite(maxBytes)) {
189
- kept.sort((a, b) => a[1] - b[1]);
190
- let total = kept.reduce((sum, [, , size]) => sum + size, 0) + (protectedEntry ? protectedEntry[2] : 0);
191
- while (total > maxBytes && kept.length > 0) {
192
- const oldest = kept.shift();
193
- if (!oldest) break;
194
- const [full, , size] = oldest;
195
- try {
196
- fs.unlinkSync(full);
197
- removed++;
198
- total -= size;
199
- } catch {
200
- break;
201
- }
202
- }
203
- }
204
- } catch {
205
- return removed;
206
- }
207
- return removed;
208
- }
209
- var SWEEPABLE_CACHE_SUBDIRS = [
210
- { subdir: "bash_outputs", countCapped: true },
211
- { subdir: "web_outputs", countCapped: true },
212
- { subdir: "mcp_outputs", countCapped: true },
213
- { subdir: "sessions", countCapped: false }
214
- ];
215
- function sweepCacheRoots(extraRoots = []) {
216
- let removed = 0;
217
- const roots = [tokenGoatHome(), ...extraRoots];
218
- const seen = /* @__PURE__ */ new Set();
219
- for (const root of roots) {
220
- if (!root || seen.has(root)) continue;
221
- seen.add(root);
222
- for (const { subdir, countCapped } of SWEEPABLE_CACHE_SUBDIRS) {
223
- try {
224
- const defaults = subdirCacheDefaults(subdir);
225
- removed += pruneBlobDir(
226
- path.join(root, subdir),
227
- countCapped ? defaults.maxCount : Number.POSITIVE_INFINITY,
228
- DEFAULT_MAX_AGE_MS,
229
- countCapped ? defaults.maxBytes : Number.POSITIVE_INFINITY
230
- );
231
- } catch {
232
- }
233
- }
234
- }
235
- return removed;
236
- }
237
-
238
- export {
239
- DEFAULT_MAX_COUNT,
240
- DEFAULT_MAX_AGE_MS,
241
- blobPath,
242
- isBlobStale,
243
- storeBlob,
244
- loadBlob,
245
- listBlobs,
246
- pruneBlobs,
247
- sweepCacheRoots
248
- };