token-goat 2.9.29 → 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.
- package/README.md +53 -42
- package/SECURITY.md +37 -11
- package/THIRD_PARTY_NOTICES.md +41 -4
- package/dist/native/linux-arm64/tg-hook +0 -0
- package/dist/native/linux-x64/tg-hook +0 -0
- package/dist/native/win32-arm64/tg-hook.exe +0 -0
- package/dist/native/win32-x64/tg-hook.exe +0 -0
- package/dist/ort-wasm-simd-threaded.mjs +59 -0
- package/dist/{token-goat-chunk-SE6E4BKJ.mjs → token-goat-chunk-25TRAWET.mjs} +23 -6
- package/dist/token-goat-chunk-2KXO6V2B.mjs +203 -0
- package/dist/{token-goat-chunk-UXSXQQIY.mjs → token-goat-chunk-2M7E4PF7.mjs} +43 -14
- package/dist/token-goat-chunk-2UPZGKKY.mjs +188 -0
- package/dist/token-goat-chunk-2WLPWKHV.mjs +135 -0
- package/dist/token-goat-chunk-2XBMMDBD.mjs +126 -0
- package/dist/token-goat-chunk-32ZOY4N5.mjs +23 -0
- package/dist/token-goat-chunk-3EZRNKTK.mjs +188 -0
- package/dist/token-goat-chunk-4ADZHI7J.mjs +63 -0
- package/dist/token-goat-chunk-4GBVPH3D.mjs +242 -0
- package/dist/{token-goat-chunk-2WOUYWLM.mjs → token-goat-chunk-4GILLLWY.mjs} +34 -7
- package/dist/token-goat-chunk-4NAPX7BA.mjs +90 -0
- package/dist/{token-goat-chunk-NMBWLRHW.mjs → token-goat-chunk-4SC7UJYV.mjs} +9981 -11563
- package/dist/token-goat-chunk-4SMRO4TO.mjs +366 -0
- package/dist/{token-goat-chunk-O6I2XU4P.mjs → token-goat-chunk-4ZBFWLXF.mjs} +310 -441
- package/dist/token-goat-chunk-57BIAXJL.mjs +286 -0
- package/dist/token-goat-chunk-5AC66HNP.mjs +115 -0
- package/dist/token-goat-chunk-5IMLKSOP.mjs +145 -0
- package/dist/token-goat-chunk-5RG5SBL6.mjs +221 -0
- package/dist/{token-goat-chunk-RRNZMM3A.mjs → token-goat-chunk-5Y6ZYL6U.mjs} +21 -2
- package/dist/token-goat-chunk-646E6U44.mjs +398 -0
- package/dist/token-goat-chunk-65N4RHP4.mjs +33 -0
- package/dist/{token-goat-chunk-6AK46ZT7.mjs → token-goat-chunk-6DG6HWP3.mjs} +13 -3
- package/dist/token-goat-chunk-6ENQSNRZ.mjs +573 -0
- package/dist/token-goat-chunk-6ZY4GNF2.mjs +91 -0
- package/dist/{token-goat-chunk-E5TK5DNO.mjs → token-goat-chunk-76FGDLRO.mjs} +574 -340
- package/dist/{token-goat-chunk-TGOXNAHW.mjs → token-goat-chunk-7EZTZOMC.mjs} +780 -767
- package/dist/token-goat-chunk-7MAOA6X4.mjs +3647 -0
- package/dist/token-goat-chunk-7R2ZVVAX.mjs +218 -0
- package/dist/{token-goat-chunk-TCQANXYC.mjs → token-goat-chunk-AM5V6GSX.mjs} +18 -2
- package/dist/token-goat-chunk-AUNGYYQX.mjs +184 -0
- package/dist/token-goat-chunk-AUQYRMMH.mjs +2985 -0
- package/dist/token-goat-chunk-B3PEKBYG.mjs +128 -0
- package/dist/{token-goat-chunk-KOPIR3KZ.mjs → token-goat-chunk-BA4HI6BW.mjs} +1910 -165
- package/dist/{token-goat-chunk-52NSDWYY.mjs → token-goat-chunk-BFCWY73P.mjs} +58 -20
- package/dist/token-goat-chunk-BPGCUMR7.mjs +30 -0
- package/dist/token-goat-chunk-BWGFUZZE.mjs +25 -0
- package/dist/token-goat-chunk-C75NA7PL.mjs +322 -0
- package/dist/token-goat-chunk-CBIQ7WTD.mjs +87 -0
- package/dist/token-goat-chunk-CETM74KC.mjs +307 -0
- package/dist/token-goat-chunk-CIMQ2BB3.mjs +233 -0
- package/dist/{token-goat-chunk-DNSPXQXQ.mjs → token-goat-chunk-CJLS3CDL.mjs} +70 -18
- package/dist/{token-goat-chunk-MELOKFDJ.mjs → token-goat-chunk-CO3UYX6G.mjs} +7 -1
- package/dist/token-goat-chunk-COPNXRJM.mjs +154 -0
- package/dist/token-goat-chunk-CSJ5L3NL.mjs +479 -0
- package/dist/token-goat-chunk-CVCEVUGK.mjs +315 -0
- package/dist/token-goat-chunk-CXHOFN7R.mjs +371 -0
- package/dist/token-goat-chunk-D735C4QM.mjs +603 -0
- package/dist/{token-goat-chunk-E4ZOJIZK.mjs → token-goat-chunk-DGS2LVNA.mjs} +70 -160
- package/dist/{token-goat-chunk-L7H3U27L.mjs → token-goat-chunk-DOWRSMWO.mjs} +1 -1
- package/dist/token-goat-chunk-E45INMY3.mjs +71 -0
- package/dist/token-goat-chunk-EC5F37F4.mjs +244 -0
- package/dist/{token-goat-chunk-XTQAOTSO.mjs → token-goat-chunk-EDBDRVH5.mjs} +4 -1
- package/dist/token-goat-chunk-EELTBKDM.mjs +613 -0
- package/dist/token-goat-chunk-EVMZJ27Z.mjs +147 -0
- package/dist/token-goat-chunk-EXKGNHEG.mjs +2096 -0
- package/dist/{token-goat-chunk-YOOVFPTP.mjs → token-goat-chunk-F4HYL64R.mjs} +12 -2
- package/dist/token-goat-chunk-F6PAUIEK.mjs +624 -0
- package/dist/token-goat-chunk-FDSREWLX.mjs +692 -0
- package/dist/{token-goat-chunk-NMTKNYGF.mjs → token-goat-chunk-FNFBKLRD.mjs} +74 -9
- package/dist/token-goat-chunk-G5PJ7AGM.mjs +36 -0
- package/dist/token-goat-chunk-GGGG7RWB.mjs +236 -0
- package/dist/{token-goat-chunk-TDUT2CL6.mjs → token-goat-chunk-GL3ETKSC.mjs} +276 -19
- package/dist/{token-goat-chunk-7CPMDFGB.mjs → token-goat-chunk-GVB2MUST.mjs} +265 -1567
- package/dist/token-goat-chunk-GWFLAUMQ.mjs +307 -0
- package/dist/token-goat-chunk-HAVAOB3S.mjs +87 -0
- package/dist/token-goat-chunk-HLPW63A7.mjs +48 -0
- package/dist/token-goat-chunk-HU4TORC5.mjs +1377 -0
- package/dist/token-goat-chunk-I7VKZZAW.mjs +35 -0
- package/dist/token-goat-chunk-IA6XSPE3.mjs +218 -0
- package/dist/token-goat-chunk-IAGXMHIK.mjs +863 -0
- package/dist/{token-goat-chunk-435UQTKD.mjs → token-goat-chunk-IK2DRMFX.mjs} +129 -74
- package/dist/{token-goat-chunk-ZER6EAXZ.mjs → token-goat-chunk-INNPTRUX.mjs} +2954 -2783
- package/dist/token-goat-chunk-JJ5BX4F4.mjs +129 -0
- package/dist/token-goat-chunk-JVFSHVFJ.mjs +129 -0
- package/dist/token-goat-chunk-KGEFFSHD.mjs +50 -0
- package/dist/token-goat-chunk-KKUFXAPD.mjs +25 -0
- package/dist/token-goat-chunk-KQBLRPBN.mjs +433 -0
- package/dist/token-goat-chunk-LCNQ2CNN.mjs +497 -0
- package/dist/token-goat-chunk-M3LFJDPU.mjs +58 -0
- package/dist/token-goat-chunk-M52KPT3C.mjs +87 -0
- package/dist/token-goat-chunk-MBEG42H7.mjs +150 -0
- package/dist/{token-goat-chunk-EVC4TOLE.mjs → token-goat-chunk-METECDOH.mjs} +3 -12
- package/dist/{token-goat-chunk-2AWQ2R5X.mjs → token-goat-chunk-MHX7XCC3.mjs} +3 -2
- package/dist/token-goat-chunk-MNWKPRAL.mjs +13 -0
- package/dist/token-goat-chunk-N5LSOVSU.mjs +137 -0
- package/dist/{token-goat-chunk-DPNLUJWB.mjs → token-goat-chunk-N5MMR2IW.mjs} +30 -8
- package/dist/token-goat-chunk-N7B3JQ2C.mjs +160 -0
- package/dist/{token-goat-chunk-VMFWNHGR.mjs → token-goat-chunk-NISNMD7T.mjs} +2545 -2953
- package/dist/token-goat-chunk-NMD42SFQ.mjs +434 -0
- package/dist/token-goat-chunk-NOSS5VWY.mjs +174 -0
- package/dist/token-goat-chunk-NSNSPPBG.mjs +69 -0
- package/dist/token-goat-chunk-OBOFIHKN.mjs +38 -0
- package/dist/token-goat-chunk-OBRFJ5O5.mjs +76 -0
- package/dist/token-goat-chunk-ODBT2USM.mjs +800 -0
- package/dist/token-goat-chunk-OS5EM5PP.mjs +107 -0
- package/dist/token-goat-chunk-OUKDTVNU.mjs +1178 -0
- package/dist/token-goat-chunk-OXFMP75N.mjs +566 -0
- package/dist/{token-goat-chunk-ASLWOQ3I.mjs → token-goat-chunk-OYIYKDDT.mjs} +2 -1
- package/dist/{token-goat-chunk-67BNIKKO.mjs → token-goat-chunk-P6HQSWQ3.mjs} +55 -47
- package/dist/token-goat-chunk-P6VGNTQT.mjs +71 -0
- package/dist/token-goat-chunk-PFWIMH2E.mjs +261 -0
- package/dist/token-goat-chunk-PJZXIS3G.mjs +39 -0
- package/dist/token-goat-chunk-PUO5INXP.mjs +606 -0
- package/dist/token-goat-chunk-PX5PQWTY.mjs +462 -0
- package/dist/token-goat-chunk-Q5QDBC6O.mjs +111 -0
- package/dist/token-goat-chunk-QFNQXSDT.mjs +40 -0
- package/dist/token-goat-chunk-QH7YVYOY.mjs +3957 -0
- package/dist/token-goat-chunk-QLMUHEPB.mjs +43 -0
- package/dist/{token-goat-chunk-PYSUADX4.mjs → token-goat-chunk-QQOJIHL3.mjs} +50 -14
- package/dist/token-goat-chunk-QQTWJY2O.mjs +85 -0
- package/dist/token-goat-chunk-QYHO5CPH.mjs +93 -0
- package/dist/token-goat-chunk-RELAVWAD.mjs +27 -0
- package/dist/token-goat-chunk-RSLPOBKQ.mjs +339 -0
- package/dist/token-goat-chunk-SAMFDIS2.mjs +712 -0
- package/dist/token-goat-chunk-SDELXLDM.mjs +48 -0
- package/dist/{token-goat-chunk-PGTH2U4C.mjs → token-goat-chunk-SOAFZNNZ.mjs} +164 -40
- package/dist/{token-goat-chunk-G23DWHV4.mjs → token-goat-chunk-SRTHT7KV.mjs} +33 -15
- package/dist/token-goat-chunk-T5P5ACNQ.mjs +212 -0
- package/dist/token-goat-chunk-T5YGG4V3.mjs +45 -0
- package/dist/token-goat-chunk-TAUZ4OFS.mjs +110 -0
- package/dist/token-goat-chunk-TM6MC754.mjs +40 -0
- package/dist/token-goat-chunk-TWUKBOMP.mjs +72 -0
- package/dist/token-goat-chunk-U2KSB4SG.mjs +56 -0
- package/dist/token-goat-chunk-U4WHMG6Y.mjs +898 -0
- package/dist/token-goat-chunk-UA5V6P3P.mjs +122 -0
- package/dist/token-goat-chunk-UGJHGR5A.mjs +52 -0
- package/dist/{token-goat-chunk-RQGGMPCR.mjs → token-goat-chunk-UOUDVA5U.mjs} +76 -16
- package/dist/{token-goat-chunk-HNFZZHFW.mjs → token-goat-chunk-URRJ33GR.mjs} +22 -4
- package/dist/token-goat-chunk-UZOROKIS.mjs +165 -0
- package/dist/token-goat-chunk-VIHGGGEI.mjs +4234 -0
- package/dist/token-goat-chunk-VTJLAA7P.mjs +21 -0
- package/dist/token-goat-chunk-VWDXLT4F.mjs +678 -0
- package/dist/token-goat-chunk-VWZA2H4P.mjs +368 -0
- package/dist/{token-goat-chunk-QO3LXVVR.mjs → token-goat-chunk-VXEXMJDL.mjs} +2964 -3153
- package/dist/token-goat-chunk-WBA5SKT4.mjs +547 -0
- package/dist/{token-goat-chunk-ONXH6NZ5.mjs → token-goat-chunk-WDH44VAU.mjs} +19 -22
- package/dist/token-goat-chunk-X2SUP3EI.mjs +107 -0
- package/dist/token-goat-chunk-X3BELZSJ.mjs +125 -0
- package/dist/{token-goat-chunk-RLP6J7WR.mjs → token-goat-chunk-XLRBNZCC.mjs} +40 -21
- package/dist/{token-goat-chunk-S4VSXURL.mjs → token-goat-chunk-XRKUX6CM.mjs} +4 -0
- package/dist/token-goat-chunk-XX6O25RN.mjs +82 -0
- package/dist/token-goat-chunk-XZSUHBVS.mjs +65 -0
- package/dist/token-goat-chunk-Y2ZTQOCL.mjs +35 -0
- package/dist/{token-goat-chunk-UA5BKWWQ.mjs → token-goat-chunk-YB4VMGK2.mjs} +15 -4
- package/dist/token-goat-chunk-YBIIY3HR.mjs +51 -0
- package/dist/{token-goat-chunk-PKRWMHVP.mjs → token-goat-chunk-YHVDKQBR.mjs} +389 -221
- package/dist/token-goat-chunk-YJB5XLWI.mjs +26 -0
- package/dist/{token-goat-chunk-PQ53BSCF.mjs → token-goat-chunk-YKB6AQG3.mjs} +53 -31
- package/dist/token-goat-chunk-YMTG2YA5.mjs +35 -0
- package/dist/token-goat-chunk-YPBZYQRV.mjs +40 -0
- package/dist/{token-goat-chunk-HUYUHODZ.mjs → token-goat-chunk-YY6AVUFL.mjs} +13246 -12247
- package/dist/token-goat-chunk-Z7N5OMMP.mjs +98 -0
- package/dist/{token-goat-chunk-BGHSSJUA.mjs → token-goat-chunk-ZFOBKUWH.mjs} +1 -1
- package/dist/token-goat-chunk-ZMBL6UVV.mjs +110 -0
- package/dist/token-goat-chunk-ZNMNUPAZ.mjs +938 -0
- package/dist/token-goat-hook-client.cjs +87 -23
- package/dist/token-goat-hook-client.mjs +3 -3
- package/dist/token-goat-hook.mjs +76 -31
- package/dist/token-goat.core.mjs +6 -6
- package/docs/C4_RUNTIME_ARCHITECTURE.md +2 -2
- package/docs/cli.md +113 -60
- package/docs/install.md +63 -20
- package/docs/security.md +10 -8
- package/package.json +18 -7
- package/scripts/verify-native-dist.mjs +386 -0
- package/dist/token-goat-chunk-2NNUA2LR.mjs +0 -143
- package/dist/token-goat-chunk-44BM7DDQ.mjs +0 -294
- package/dist/token-goat-chunk-BGYOZ6DO.mjs +0 -24
- package/dist/token-goat-chunk-C5YPNZKQ.mjs +0 -318
- package/dist/token-goat-chunk-CIQ2FTY3.mjs +0 -1990
- package/dist/token-goat-chunk-D4ETHJD6.mjs +0 -246
- package/dist/token-goat-chunk-DNRPXHYH.mjs +0 -1062
- package/dist/token-goat-chunk-EUSDXRXU.mjs +0 -1429
- package/dist/token-goat-chunk-FTP4U4QA.mjs +0 -64
- package/dist/token-goat-chunk-G7IWXCFF.mjs +0 -456
- package/dist/token-goat-chunk-GLXRTTLE.mjs +0 -36
- package/dist/token-goat-chunk-H5J3C56Q.mjs +0 -1511
- package/dist/token-goat-chunk-IVWI2OCK.mjs +0 -368
- package/dist/token-goat-chunk-JTKCQMQA.mjs +0 -418
- package/dist/token-goat-chunk-LZNBQTDK.mjs +0 -26
- package/dist/token-goat-chunk-ORNFMIER.mjs +0 -295
- package/dist/token-goat-chunk-RTMVLHWX.mjs +0 -7113
- package/dist/token-goat-chunk-VQ6F6T7X.mjs +0 -36
- package/dist/token-goat-chunk-VZQEWRVH.mjs +0 -312
- package/dist/token-goat-chunk-XYWPOSCN.mjs +0 -807
- package/dist/token-goat-chunk-YAGLESS3.mjs +0 -23
- package/dist/token-goat-chunk-YKSRAWUU.mjs +0 -33
- package/dist/token-goat-chunk-Z6KBMOBI.mjs +0 -53
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
|
+
const require = __cjsRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
AGENT_SALT_MARKER,
|
|
5
|
+
readSessionStateFile,
|
|
6
|
+
sessionFileStem
|
|
7
|
+
} from "./token-goat-chunk-WBA5SKT4.mjs";
|
|
8
|
+
import {
|
|
9
|
+
readTranscriptTail
|
|
10
|
+
} from "./token-goat-chunk-WDH44VAU.mjs";
|
|
11
|
+
import {
|
|
12
|
+
isAutoTriggerMultiplierExplicit,
|
|
13
|
+
loadConfig
|
|
14
|
+
} from "./token-goat-chunk-7EZTZOMC.mjs";
|
|
15
|
+
import {
|
|
16
|
+
detectHarness
|
|
17
|
+
} from "./token-goat-chunk-QYHO5CPH.mjs";
|
|
18
|
+
import {
|
|
19
|
+
atomicWriteText,
|
|
20
|
+
ensureDirSync,
|
|
21
|
+
normalizePathForwardSlash
|
|
22
|
+
} from "./token-goat-chunk-HU4TORC5.mjs";
|
|
23
|
+
import {
|
|
24
|
+
dataDir,
|
|
25
|
+
tokenGoatHome
|
|
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/compact.ts
|
|
32
|
+
init_define_import_meta_env();
|
|
33
|
+
import * as fs from "node:fs";
|
|
34
|
+
import * as path from "node:path";
|
|
35
|
+
var CONTEXT_AUTOCOMPACT_TOKENS = 66e4;
|
|
36
|
+
var CATALOG_TOKENS = 10800;
|
|
37
|
+
var CONTEXT_TIER_WARM = 0.5;
|
|
38
|
+
var CONTEXT_TIER_HOT = 0.7;
|
|
39
|
+
var CONTEXT_TIER_CRITICAL = 0.85;
|
|
40
|
+
var NOISE_EXTS = /* @__PURE__ */ new Set([
|
|
41
|
+
".pyc",
|
|
42
|
+
".pyo",
|
|
43
|
+
".pyd",
|
|
44
|
+
".class",
|
|
45
|
+
".o",
|
|
46
|
+
".obj",
|
|
47
|
+
".a",
|
|
48
|
+
".lib",
|
|
49
|
+
".dll",
|
|
50
|
+
".so",
|
|
51
|
+
".dylib",
|
|
52
|
+
".log",
|
|
53
|
+
".jsonl",
|
|
54
|
+
".tmp",
|
|
55
|
+
".temp",
|
|
56
|
+
".swp",
|
|
57
|
+
".swo",
|
|
58
|
+
".bak",
|
|
59
|
+
".pid",
|
|
60
|
+
".lock",
|
|
61
|
+
".map",
|
|
62
|
+
".wasm",
|
|
63
|
+
".gz",
|
|
64
|
+
".zip",
|
|
65
|
+
".tar",
|
|
66
|
+
".tgz",
|
|
67
|
+
".db",
|
|
68
|
+
".sqlite",
|
|
69
|
+
".sqlite3",
|
|
70
|
+
".db3",
|
|
71
|
+
".d.ts",
|
|
72
|
+
".snap",
|
|
73
|
+
".eot",
|
|
74
|
+
".ttf",
|
|
75
|
+
".woff",
|
|
76
|
+
".woff2",
|
|
77
|
+
".ico",
|
|
78
|
+
".pdb",
|
|
79
|
+
".exe",
|
|
80
|
+
".bin"
|
|
81
|
+
]);
|
|
82
|
+
var NOISE_BASENAMES = /* @__PURE__ */ new Set([
|
|
83
|
+
".ds_store",
|
|
84
|
+
"thumbs.db",
|
|
85
|
+
"desktop.ini",
|
|
86
|
+
"package-lock.json",
|
|
87
|
+
"yarn.lock",
|
|
88
|
+
"pnpm-lock.yaml",
|
|
89
|
+
"poetry.lock",
|
|
90
|
+
"uv.lock",
|
|
91
|
+
"pdm.lock",
|
|
92
|
+
"cargo.lock",
|
|
93
|
+
"composer.lock",
|
|
94
|
+
"gemfile.lock",
|
|
95
|
+
"coverage.xml",
|
|
96
|
+
".coverage",
|
|
97
|
+
"lcov.info"
|
|
98
|
+
]);
|
|
99
|
+
var NOISE_SEGMENTS = [
|
|
100
|
+
"/__pycache__/",
|
|
101
|
+
"/.git/",
|
|
102
|
+
"/node_modules/",
|
|
103
|
+
"/.venv/",
|
|
104
|
+
"/venv/",
|
|
105
|
+
"/dist/",
|
|
106
|
+
"/build/",
|
|
107
|
+
"/.mypy_cache/",
|
|
108
|
+
"/.pytest_cache/",
|
|
109
|
+
"/.ruff_cache/",
|
|
110
|
+
"/appdata/local/temp/",
|
|
111
|
+
"/appdata/roaming/",
|
|
112
|
+
"/tmp/",
|
|
113
|
+
"/.next/",
|
|
114
|
+
"/.nuxt/",
|
|
115
|
+
"/.svelte-kit/",
|
|
116
|
+
"/.turbo/",
|
|
117
|
+
"/.parcel-cache/",
|
|
118
|
+
"/.cache/",
|
|
119
|
+
"/.tox/",
|
|
120
|
+
"/coverage/",
|
|
121
|
+
"/.nyc_output/",
|
|
122
|
+
"/site-packages/",
|
|
123
|
+
".egg-info/",
|
|
124
|
+
"/target/",
|
|
125
|
+
"/__snapshots__/"
|
|
126
|
+
];
|
|
127
|
+
var HARNESS_MULTIPLIER_DEFAULTS = {
|
|
128
|
+
claudecode: 2,
|
|
129
|
+
codex: 1.5,
|
|
130
|
+
opencode: 2.5,
|
|
131
|
+
gemini: 3,
|
|
132
|
+
openclaw: 1,
|
|
133
|
+
pi: 1,
|
|
134
|
+
hermes: 1,
|
|
135
|
+
generic: 1
|
|
136
|
+
};
|
|
137
|
+
function tierForFraction(fill) {
|
|
138
|
+
if (fill >= CONTEXT_TIER_CRITICAL) return "critical";
|
|
139
|
+
if (fill >= CONTEXT_TIER_HOT) return "hot";
|
|
140
|
+
if (fill >= CONTEXT_TIER_WARM) return "warm";
|
|
141
|
+
return "cool";
|
|
142
|
+
}
|
|
143
|
+
function pressureRawTotal(cache) {
|
|
144
|
+
const skillTokens = cache.loadedSkillTotalTokens ?? 0;
|
|
145
|
+
const bashCount = (cache.bashOutputs ?? []).length;
|
|
146
|
+
const webCount = (cache.webFetches ?? []).length;
|
|
147
|
+
const files = cache.files ?? [];
|
|
148
|
+
const readCount = files.length;
|
|
149
|
+
return skillTokens + CATALOG_TOKENS + bashCount * 500 + webCount * 1e3 + readCount * 200;
|
|
150
|
+
}
|
|
151
|
+
var PROMPT_MEASURE_TAIL_BYTES = 1048576;
|
|
152
|
+
function extractUsageTotal(record) {
|
|
153
|
+
if (record === null || typeof record !== "object") return null;
|
|
154
|
+
if (record["type"] !== "assistant") return null;
|
|
155
|
+
const message = record["message"];
|
|
156
|
+
if (message === null || typeof message !== "object") return null;
|
|
157
|
+
const usage = message["usage"];
|
|
158
|
+
if (usage === null || typeof usage !== "object") return null;
|
|
159
|
+
const u = usage;
|
|
160
|
+
const input = u["input_tokens"];
|
|
161
|
+
const cacheCreation = u["cache_creation_input_tokens"];
|
|
162
|
+
const cacheRead = u["cache_read_input_tokens"];
|
|
163
|
+
const output = u["output_tokens"];
|
|
164
|
+
if (typeof input !== "number" || typeof cacheCreation !== "number" || typeof cacheRead !== "number" || typeof output !== "number") {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
return input + cacheCreation + cacheRead + output;
|
|
168
|
+
}
|
|
169
|
+
function measurePromptTokens(transcriptPath) {
|
|
170
|
+
try {
|
|
171
|
+
const lines = readTranscriptTail(transcriptPath, PROMPT_MEASURE_TAIL_BYTES);
|
|
172
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
173
|
+
const line = lines[i];
|
|
174
|
+
if (line === void 0) continue;
|
|
175
|
+
const trimmed = line.trim();
|
|
176
|
+
if (trimmed === "") continue;
|
|
177
|
+
let parsed;
|
|
178
|
+
try {
|
|
179
|
+
parsed = JSON.parse(trimmed);
|
|
180
|
+
} catch {
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
const total = extractUsageTotal(parsed);
|
|
184
|
+
if (total !== null) return total;
|
|
185
|
+
}
|
|
186
|
+
return null;
|
|
187
|
+
} catch {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
function getEffectiveAutoTriggerWindow() {
|
|
192
|
+
const ca = loadConfig().compact_assist;
|
|
193
|
+
const isConfigDefault = !isAutoTriggerMultiplierExplicit();
|
|
194
|
+
const multiplier = getAutoTriggerMultiplier(
|
|
195
|
+
ca.harness === "auto" ? { configExplicitMultiplier: ca.auto_trigger_multiplier, isConfigDefault } : { configExplicitMultiplier: ca.auto_trigger_multiplier, harness: ca.harness, isConfigDefault }
|
|
196
|
+
);
|
|
197
|
+
return CONTEXT_AUTOCOMPACT_TOKENS * multiplier;
|
|
198
|
+
}
|
|
199
|
+
function getContextPressure(cache, transcriptPath) {
|
|
200
|
+
try {
|
|
201
|
+
const window = getEffectiveAutoTriggerWindow();
|
|
202
|
+
if (transcriptPath) {
|
|
203
|
+
const measured = measurePromptTokens(transcriptPath);
|
|
204
|
+
if (measured !== null) {
|
|
205
|
+
const fill2 = measured / window;
|
|
206
|
+
return { fillFraction: fill2, tier: tierForFraction(fill2) };
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (!cache) {
|
|
210
|
+
return { fillFraction: 0, tier: "cool" };
|
|
211
|
+
}
|
|
212
|
+
const total = pressureRawTotal(cache);
|
|
213
|
+
const fill = total / window;
|
|
214
|
+
return {
|
|
215
|
+
fillFraction: fill,
|
|
216
|
+
tier: tierForFraction(fill)
|
|
217
|
+
};
|
|
218
|
+
} catch {
|
|
219
|
+
return { fillFraction: 0, tier: "cool" };
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function getAutoTriggerMultiplier(opts) {
|
|
223
|
+
const config = opts?.configExplicitMultiplier ?? 2;
|
|
224
|
+
let isDefault = opts?.isConfigDefault;
|
|
225
|
+
if (isDefault === void 0) {
|
|
226
|
+
isDefault = config === 2;
|
|
227
|
+
}
|
|
228
|
+
if (!isDefault && opts?.configExplicitMultiplier !== void 0) {
|
|
229
|
+
return Math.max(1, Math.min(10, opts.configExplicitMultiplier));
|
|
230
|
+
}
|
|
231
|
+
const harness = opts?.harness ?? detectHarness();
|
|
232
|
+
return Math.max(1, Math.min(10, HARNESS_MULTIPLIER_DEFAULTS[harness] ?? 1));
|
|
233
|
+
}
|
|
234
|
+
function isNoisePath(inputPath) {
|
|
235
|
+
if (!inputPath) {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
const p = normalizePathForwardSlash(inputPath, true);
|
|
239
|
+
for (const segment of NOISE_SEGMENTS) {
|
|
240
|
+
if (p.includes(segment)) {
|
|
241
|
+
return true;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const slashIdx = p.lastIndexOf("/");
|
|
245
|
+
const basename = slashIdx >= 0 ? p.slice(slashIdx + 1) : p;
|
|
246
|
+
if (NOISE_BASENAMES.has(basename)) {
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
if (basename.startsWith(".improve-state-") || basename.startsWith("improve_commit_msg_")) {
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
const dotIdx = basename.lastIndexOf(".");
|
|
253
|
+
if (dotIdx >= 0) {
|
|
254
|
+
const ext = basename.slice(dotIdx);
|
|
255
|
+
if (NOISE_EXTS.has(ext)) {
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
for (const ext of NOISE_EXTS) {
|
|
260
|
+
if (ext.includes(".") && ext.split(".").length > 2) {
|
|
261
|
+
if (basename.endsWith(ext)) {
|
|
262
|
+
return true;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
function findLatestSessionId() {
|
|
269
|
+
try {
|
|
270
|
+
const sessionsDir = path.join(tokenGoatHome(), "sessions");
|
|
271
|
+
if (!fs.existsSync(sessionsDir)) {
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
const files = fs.readdirSync(sessionsDir);
|
|
275
|
+
const jsonFiles = files.filter((f) => f.endsWith(".json") && !f.includes(AGENT_SALT_MARKER));
|
|
276
|
+
if (jsonFiles.length === 0) {
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
const firstFile = jsonFiles[0];
|
|
280
|
+
if (!firstFile) {
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
let latestFile = firstFile;
|
|
284
|
+
let latestMtime = fs.statSync(path.join(sessionsDir, firstFile)).mtimeMs;
|
|
285
|
+
for (const file of jsonFiles) {
|
|
286
|
+
const mtime = fs.statSync(path.join(sessionsDir, file)).mtimeMs;
|
|
287
|
+
if (mtime > latestMtime) {
|
|
288
|
+
latestFile = file;
|
|
289
|
+
latestMtime = mtime;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return latestFile.replace(/\.json$/, "");
|
|
293
|
+
} catch {
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
function eventCount(cache) {
|
|
298
|
+
const files = cache.files ?? [];
|
|
299
|
+
const editedCount = files.filter((f) => f.wasEdited).length;
|
|
300
|
+
const bashCount = (cache.bashOutputs ?? []).length;
|
|
301
|
+
const webCount = (cache.webFetches ?? []).length;
|
|
302
|
+
const skillHistory = cache.skillHistory ?? {};
|
|
303
|
+
return files.length + editedCount + bashCount + webCount + Object.keys(skillHistory).length;
|
|
304
|
+
}
|
|
305
|
+
function writeSessionManifest(projectHash, sessionId, manifestJson) {
|
|
306
|
+
const safeSessionId = sessionFileStem(sessionId);
|
|
307
|
+
if (!safeSessionId) return;
|
|
308
|
+
const sessionsDir = path.join(dataDir(), "projects", projectHash, "sessions");
|
|
309
|
+
if (!fs.existsSync(sessionsDir)) {
|
|
310
|
+
ensureDirSync(sessionsDir);
|
|
311
|
+
}
|
|
312
|
+
const dest = path.join(sessionsDir, `${safeSessionId}.json`);
|
|
313
|
+
atomicWriteText(dest, JSON.stringify(manifestJson));
|
|
314
|
+
}
|
|
315
|
+
function readAllSessionManifests(projectHash, maxAgeSecs = 3600) {
|
|
316
|
+
const sessionsDir = path.join(dataDir(), "projects", projectHash, "sessions");
|
|
317
|
+
if (!fs.existsSync(sessionsDir)) {
|
|
318
|
+
return [];
|
|
319
|
+
}
|
|
320
|
+
const now = Date.now() / 1e3;
|
|
321
|
+
const results = [];
|
|
322
|
+
try {
|
|
323
|
+
const files = fs.readdirSync(sessionsDir);
|
|
324
|
+
for (const file of files) {
|
|
325
|
+
if (!file.endsWith(".json")) {
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
try {
|
|
329
|
+
const fullPath = path.join(sessionsDir, file);
|
|
330
|
+
const stat = fs.statSync(fullPath);
|
|
331
|
+
if (now - stat.mtimeMs / 1e3 > maxAgeSecs) {
|
|
332
|
+
try {
|
|
333
|
+
fs.unlinkSync(fullPath);
|
|
334
|
+
} catch {
|
|
335
|
+
}
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
const text = fs.readFileSync(fullPath, "utf8");
|
|
339
|
+
const data = JSON.parse(text);
|
|
340
|
+
if (typeof data === "object" && data !== null && "files" in data) {
|
|
341
|
+
results.push(data);
|
|
342
|
+
}
|
|
343
|
+
} catch {
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
} catch {
|
|
347
|
+
}
|
|
348
|
+
return results;
|
|
349
|
+
}
|
|
350
|
+
function _editedFileCount(cache) {
|
|
351
|
+
return (cache.files ?? []).filter((f) => f.wasEdited).length;
|
|
352
|
+
}
|
|
353
|
+
function _computeActivityMultiplier(ageSecs, editedCount) {
|
|
354
|
+
const TEN_MIN_SECS = 600;
|
|
355
|
+
const SIXTY_MIN_SECS = 3600;
|
|
356
|
+
const EDITS_PER_MIN_DENSITY_THRESHOLD = 0.3;
|
|
357
|
+
let tier;
|
|
358
|
+
if (ageSecs < TEN_MIN_SECS) {
|
|
359
|
+
tier = "young";
|
|
360
|
+
} else if (ageSecs < SIXTY_MIN_SECS) {
|
|
361
|
+
tier = "active";
|
|
362
|
+
} else {
|
|
363
|
+
tier = "mature";
|
|
364
|
+
}
|
|
365
|
+
const baseFactor = {
|
|
366
|
+
young: 0.6,
|
|
367
|
+
active: 1,
|
|
368
|
+
mature: 1.4
|
|
369
|
+
};
|
|
370
|
+
let factor = baseFactor[tier];
|
|
371
|
+
if (ageSecs >= TEN_MIN_SECS) {
|
|
372
|
+
const editsPerMin = ageSecs > 0 ? editedCount / (ageSecs / 60) : 0;
|
|
373
|
+
if (editsPerMin < EDITS_PER_MIN_DENSITY_THRESHOLD) {
|
|
374
|
+
factor = Math.min(factor, 1);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return factor;
|
|
378
|
+
}
|
|
379
|
+
function loadSessionCache(sessionId) {
|
|
380
|
+
const disk = readSessionStateFile(sessionId);
|
|
381
|
+
if (!disk) {
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
return {
|
|
385
|
+
files: disk.files,
|
|
386
|
+
webFetches: disk.webFetches,
|
|
387
|
+
bashOutputs: disk.bashOutputs,
|
|
388
|
+
...disk.created_ts !== void 0 ? { created_ts: disk.created_ts } : {}
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
function computeAdaptiveBudget(cache, ageSecs = 0, opts) {
|
|
392
|
+
const base = 200;
|
|
393
|
+
const maxTotal = 800;
|
|
394
|
+
const minTotal = 200;
|
|
395
|
+
const editedCount = _editedFileCount(cache);
|
|
396
|
+
const editedBonus = Math.min(200, editedCount * 50);
|
|
397
|
+
const files = cache.files ?? [];
|
|
398
|
+
const symbolFiles = files.filter((f) => {
|
|
399
|
+
const entry = f;
|
|
400
|
+
return (entry["symbols_read"] ?? []).length > 0;
|
|
401
|
+
}).length;
|
|
402
|
+
const symbolsBonus = Math.min(150, symbolFiles * 30);
|
|
403
|
+
const bashCount = (cache.bashOutputs ?? []).length;
|
|
404
|
+
const bashBonus = bashCount > 0 ? Math.min(100, Math.max(20, bashCount * 5)) : 0;
|
|
405
|
+
const webBonus = (cache.webFetches ?? []).length > 0 ? 15 : 0;
|
|
406
|
+
const diffBonus = opts?.hasPendingDiff ? 50 : 0;
|
|
407
|
+
const uncommittedBonus = opts?.hasUncommittedChanges ? 10 : 0;
|
|
408
|
+
const staleFrac = Math.max(0, Math.min(1, opts?.staleCompactFraction ?? 0));
|
|
409
|
+
const staleBonus = Math.min(60, Math.round(staleFrac * 60));
|
|
410
|
+
const rawTotal = base + editedBonus + symbolsBonus + bashBonus + webBonus + diffBonus + uncommittedBonus + staleBonus;
|
|
411
|
+
const factor = _computeActivityMultiplier(ageSecs, editedCount);
|
|
412
|
+
const total = Math.round(rawTotal * factor);
|
|
413
|
+
let capMax = maxTotal;
|
|
414
|
+
if (opts?.contextPressure) {
|
|
415
|
+
if (opts.contextPressure.tier === "critical") {
|
|
416
|
+
capMax = Math.min(capMax, 300);
|
|
417
|
+
} else if (opts.contextPressure.tier === "hot") {
|
|
418
|
+
capMax = Math.min(capMax, 500);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
return Math.max(minTotal, Math.min(capMax, total));
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
export {
|
|
425
|
+
CONTEXT_AUTOCOMPACT_TOKENS,
|
|
426
|
+
getContextPressure,
|
|
427
|
+
isNoisePath,
|
|
428
|
+
findLatestSessionId,
|
|
429
|
+
eventCount,
|
|
430
|
+
writeSessionManifest,
|
|
431
|
+
readAllSessionManifests,
|
|
432
|
+
loadSessionCache,
|
|
433
|
+
computeAdaptiveBudget
|
|
434
|
+
};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
|
+
const require = __cjsRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
embedTexts,
|
|
5
|
+
isAvailable
|
|
6
|
+
} from "./token-goat-chunk-NISNMD7T.mjs";
|
|
7
|
+
import {
|
|
8
|
+
redactIfDotenv
|
|
9
|
+
} from "./token-goat-chunk-GVB2MUST.mjs";
|
|
10
|
+
import {
|
|
11
|
+
redactSecrets
|
|
12
|
+
} from "./token-goat-chunk-T5P5ACNQ.mjs";
|
|
13
|
+
import {
|
|
14
|
+
decodeSource,
|
|
15
|
+
ensureDirSync,
|
|
16
|
+
statSize
|
|
17
|
+
} from "./token-goat-chunk-HU4TORC5.mjs";
|
|
18
|
+
import {
|
|
19
|
+
displaySafePath,
|
|
20
|
+
hostPathOfIndexKey,
|
|
21
|
+
normalizePath
|
|
22
|
+
} from "./token-goat-chunk-FNFBKLRD.mjs";
|
|
23
|
+
import {
|
|
24
|
+
dataDir
|
|
25
|
+
} from "./token-goat-chunk-CO3UYX6G.mjs";
|
|
26
|
+
import {
|
|
27
|
+
init_define_import_meta_env
|
|
28
|
+
} from "./token-goat-chunk-A37V4PBF.mjs";
|
|
29
|
+
|
|
30
|
+
// src/evidence_cache.ts
|
|
31
|
+
init_define_import_meta_env();
|
|
32
|
+
import crypto from "node:crypto";
|
|
33
|
+
import fs from "node:fs";
|
|
34
|
+
import path from "node:path";
|
|
35
|
+
var MAX_ENTRIES = 500;
|
|
36
|
+
var MAX_TEXT_BYTES = 128 * 1024;
|
|
37
|
+
var MAX_FILE_BYTES = 4 * MAX_TEXT_BYTES + 7;
|
|
38
|
+
var CACHE_FILE = "workspace-evidence.json";
|
|
39
|
+
function cachePath() {
|
|
40
|
+
return path.join(dataDir(), CACHE_FILE);
|
|
41
|
+
}
|
|
42
|
+
function hash(text) {
|
|
43
|
+
return crypto.createHash("sha256").update(text).digest("hex");
|
|
44
|
+
}
|
|
45
|
+
function load() {
|
|
46
|
+
try {
|
|
47
|
+
const parsed = JSON.parse(fs.readFileSync(cachePath(), "utf8"));
|
|
48
|
+
if (!Array.isArray(parsed)) return [];
|
|
49
|
+
return parsed.filter(
|
|
50
|
+
(entry) => typeof entry === "object" && entry !== null && typeof entry.id === "string" && typeof entry.projectRoot === "string" && typeof entry.source === "string" && (entry.representation === "file" || entry.representation === "tool-output") && typeof entry.contentHash === "string" && typeof entry.text === "string" && typeof entry.createdAt === "number" && (entry.embedding === void 0 || typeof entry.embedding === "string")
|
|
51
|
+
);
|
|
52
|
+
} catch {
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function save(entries) {
|
|
57
|
+
try {
|
|
58
|
+
ensureDirSync(dataDir());
|
|
59
|
+
fs.writeFileSync(cachePath(), JSON.stringify(entries.slice(0, MAX_ENTRIES)), "utf8");
|
|
60
|
+
} catch {
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function readEvidenceFileText(filePath) {
|
|
64
|
+
const onDisk = hostPathOfIndexKey(filePath);
|
|
65
|
+
const size = statSize(onDisk);
|
|
66
|
+
if (size === null || size > MAX_FILE_BYTES) return null;
|
|
67
|
+
const text = decodeSource(fs.readFileSync(onDisk));
|
|
68
|
+
return Buffer.byteLength(text, "utf8") > MAX_TEXT_BYTES ? null : text;
|
|
69
|
+
}
|
|
70
|
+
function recordEvidence(input) {
|
|
71
|
+
if (Buffer.byteLength(input.text, "utf8") > MAX_TEXT_BYTES) return null;
|
|
72
|
+
const contentHash = hash(input.text);
|
|
73
|
+
const text = redactSecrets(redactIfDotenv(input.source, input.text)).text;
|
|
74
|
+
const projectRoot = normalizePath(input.projectRoot);
|
|
75
|
+
const source = input.representation === "file" ? normalizePath(input.source) : input.source;
|
|
76
|
+
const id = hash(`${projectRoot}\0${source}\0${input.representation}\0${contentHash}`).slice(0, 24);
|
|
77
|
+
const entry = {
|
|
78
|
+
id,
|
|
79
|
+
projectRoot,
|
|
80
|
+
source,
|
|
81
|
+
representation: input.representation,
|
|
82
|
+
contentHash,
|
|
83
|
+
text,
|
|
84
|
+
createdAt: Date.now()
|
|
85
|
+
};
|
|
86
|
+
const entries = load().filter(
|
|
87
|
+
(candidate) => candidate.projectRoot !== projectRoot || candidate.source !== source || candidate.representation !== input.representation
|
|
88
|
+
);
|
|
89
|
+
entries.unshift(entry);
|
|
90
|
+
save(entries);
|
|
91
|
+
return entry;
|
|
92
|
+
}
|
|
93
|
+
function findVerifiedFileEvidence(projectRoot, source, currentText) {
|
|
94
|
+
const normalizedRoot = normalizePath(projectRoot);
|
|
95
|
+
const normalizedSource = normalizePath(source);
|
|
96
|
+
const currentHash = hash(currentText);
|
|
97
|
+
return load().find(
|
|
98
|
+
(entry) => entry.projectRoot === normalizedRoot && entry.source === normalizedSource && entry.representation === "file" && entry.contentHash === currentHash
|
|
99
|
+
) ?? null;
|
|
100
|
+
}
|
|
101
|
+
function decodeEmbedding(encoded) {
|
|
102
|
+
if (encoded === void 0) return null;
|
|
103
|
+
try {
|
|
104
|
+
const bytes = Buffer.from(encoded, "base64");
|
|
105
|
+
if (bytes.length === 0 || bytes.length % Float32Array.BYTES_PER_ELEMENT !== 0) return null;
|
|
106
|
+
return new Float32Array(bytes.buffer, bytes.byteOffset, bytes.length / Float32Array.BYTES_PER_ELEMENT);
|
|
107
|
+
} catch {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function encodeEmbedding(vector) {
|
|
112
|
+
const values = Float32Array.from(vector);
|
|
113
|
+
return Buffer.from(values.buffer, values.byteOffset, values.byteLength).toString("base64");
|
|
114
|
+
}
|
|
115
|
+
function cosineSimilarity(left, right) {
|
|
116
|
+
if (left.length !== right.length) return Number.NEGATIVE_INFINITY;
|
|
117
|
+
let dot = 0;
|
|
118
|
+
let leftMagnitude = 0;
|
|
119
|
+
let rightMagnitude = 0;
|
|
120
|
+
for (let index = 0; index < left.length; index += 1) {
|
|
121
|
+
const a = left[index] ?? 0;
|
|
122
|
+
const b = right[index] ?? 0;
|
|
123
|
+
dot += a * b;
|
|
124
|
+
leftMagnitude += a * a;
|
|
125
|
+
rightMagnitude += b * b;
|
|
126
|
+
}
|
|
127
|
+
return leftMagnitude === 0 || rightMagnitude === 0 ? Number.NEGATIVE_INFINITY : dot / Math.sqrt(leftMagnitude * rightMagnitude);
|
|
128
|
+
}
|
|
129
|
+
async function searchEvidenceSemantically(projectRoot, query, limit = 10) {
|
|
130
|
+
if (query.trim() === "" || !isAvailable()) return [];
|
|
131
|
+
const root = normalizePath(projectRoot);
|
|
132
|
+
const entries = load().filter((entry) => entry.projectRoot === root);
|
|
133
|
+
if (entries.length === 0) return [];
|
|
134
|
+
try {
|
|
135
|
+
const missing = entries.filter((entry) => decodeEmbedding(entry.embedding) === null);
|
|
136
|
+
const vectors = await embedTexts([query, ...missing.map((entry) => entry.text)]);
|
|
137
|
+
const queryVector = vectors[0];
|
|
138
|
+
if (queryVector === void 0) return [];
|
|
139
|
+
for (let index = 0; index < missing.length; index += 1) {
|
|
140
|
+
const vector = vectors[index + 1];
|
|
141
|
+
if (vector !== void 0) missing[index].embedding = encodeEmbedding(vector);
|
|
142
|
+
}
|
|
143
|
+
if (missing.length > 0) {
|
|
144
|
+
const updated = new Map(entries.map((entry) => [entry.id, entry]));
|
|
145
|
+
save(load().map((entry) => updated.get(entry.id) ?? entry));
|
|
146
|
+
}
|
|
147
|
+
const queryValues = Float32Array.from(queryVector);
|
|
148
|
+
return entries.map((entry) => ({ entry, score: cosineSimilarity(queryValues, decodeEmbedding(entry.embedding) ?? new Float32Array()) })).filter(({ score }) => Number.isFinite(score)).sort((left, right) => right.score - left.score || right.entry.createdAt - left.entry.createdAt).slice(0, limit).map(({ entry }) => entry);
|
|
149
|
+
} catch {
|
|
150
|
+
return [];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function buildDeltaCapsule(projectRoot, limit = 8) {
|
|
154
|
+
const root = normalizePath(projectRoot);
|
|
155
|
+
const changed = load().filter((entry) => entry.projectRoot === root && entry.representation === "file").filter((entry) => {
|
|
156
|
+
try {
|
|
157
|
+
const current = readEvidenceFileText(entry.source);
|
|
158
|
+
return current === null || hash(current) !== entry.contentHash;
|
|
159
|
+
} catch {
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
}).slice(0, limit);
|
|
163
|
+
if (changed.length === 0) return null;
|
|
164
|
+
return `Cross-session evidence changed since it was cached:
|
|
165
|
+
${changed.map((entry) => `- ${displaySafePath(entry.source)} (use a fresh surgical read)`).join("\n")}`;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export {
|
|
169
|
+
readEvidenceFileText,
|
|
170
|
+
recordEvidence,
|
|
171
|
+
findVerifiedFileEvidence,
|
|
172
|
+
searchEvidenceSemantically,
|
|
173
|
+
buildDeltaCapsule
|
|
174
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
|
+
const require = __cjsRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
WORKER_STARTUP_GRACE_MS,
|
|
5
|
+
WorkerAlreadyRunningError,
|
|
6
|
+
WorkerDataDirUnwritableError,
|
|
7
|
+
appendWorkerErrorLog,
|
|
8
|
+
claimCurrentWorker,
|
|
9
|
+
claimWorkerPidFile,
|
|
10
|
+
currentDaemonStamp,
|
|
11
|
+
daemonEntryScript,
|
|
12
|
+
dataDirWriteRefusal,
|
|
13
|
+
displacedWorkerPath,
|
|
14
|
+
drainHeartbeatPathFor,
|
|
15
|
+
ensureWorkerAlive,
|
|
16
|
+
isWorkerRunning,
|
|
17
|
+
oneLogLine,
|
|
18
|
+
pidAlive,
|
|
19
|
+
readDisplacedPids,
|
|
20
|
+
readPidFile,
|
|
21
|
+
resolvePollIntervalMs,
|
|
22
|
+
retireDisplacedWorker,
|
|
23
|
+
startDetachedWorker,
|
|
24
|
+
stopWorker,
|
|
25
|
+
workerErrorLogPath,
|
|
26
|
+
workerPidPath,
|
|
27
|
+
workerStampPath,
|
|
28
|
+
writeDrainHeartbeat
|
|
29
|
+
} from "./token-goat-chunk-F6PAUIEK.mjs";
|
|
30
|
+
import "./token-goat-chunk-65N4RHP4.mjs";
|
|
31
|
+
import "./token-goat-chunk-X2SUP3EI.mjs";
|
|
32
|
+
import "./token-goat-chunk-7EZTZOMC.mjs";
|
|
33
|
+
import "./token-goat-chunk-QYHO5CPH.mjs";
|
|
34
|
+
import "./token-goat-chunk-4GBVPH3D.mjs";
|
|
35
|
+
import "./token-goat-chunk-YZAAZU2S.mjs";
|
|
36
|
+
import "./token-goat-chunk-IVE6U7KV.mjs";
|
|
37
|
+
import "./token-goat-chunk-HU4TORC5.mjs";
|
|
38
|
+
import "./token-goat-chunk-GGGG7RWB.mjs";
|
|
39
|
+
import "./token-goat-chunk-AM5V6GSX.mjs";
|
|
40
|
+
import "./token-goat-chunk-FNFBKLRD.mjs";
|
|
41
|
+
import "./token-goat-chunk-CO3UYX6G.mjs";
|
|
42
|
+
import "./token-goat-chunk-A37V4PBF.mjs";
|
|
43
|
+
export {
|
|
44
|
+
WORKER_STARTUP_GRACE_MS,
|
|
45
|
+
WorkerAlreadyRunningError,
|
|
46
|
+
WorkerDataDirUnwritableError,
|
|
47
|
+
appendWorkerErrorLog,
|
|
48
|
+
claimCurrentWorker,
|
|
49
|
+
claimWorkerPidFile,
|
|
50
|
+
currentDaemonStamp,
|
|
51
|
+
daemonEntryScript,
|
|
52
|
+
dataDirWriteRefusal,
|
|
53
|
+
displacedWorkerPath,
|
|
54
|
+
drainHeartbeatPathFor,
|
|
55
|
+
ensureWorkerAlive,
|
|
56
|
+
isWorkerRunning,
|
|
57
|
+
oneLogLine,
|
|
58
|
+
pidAlive,
|
|
59
|
+
readDisplacedPids,
|
|
60
|
+
readPidFile,
|
|
61
|
+
resolvePollIntervalMs,
|
|
62
|
+
retireDisplacedWorker,
|
|
63
|
+
startDetachedWorker,
|
|
64
|
+
stopWorker,
|
|
65
|
+
workerErrorLogPath,
|
|
66
|
+
workerPidPath,
|
|
67
|
+
workerStampPath,
|
|
68
|
+
writeDrainHeartbeat
|
|
69
|
+
};
|