token-goat 2.9.28 → 2.9.30
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 +36 -40
- package/SECURITY.md +28 -10
- package/THIRD_PARTY_NOTICES.md +40 -3
- package/dist/native/linux-arm64/tg-hook +0 -0
- package/dist/native/linux-x64/tg-hook +0 -0
- package/dist/ort-wasm-simd-threaded.mjs +59 -0
- package/dist/token-goat-chunk-3CHUNJ2O.mjs +53 -0
- package/dist/token-goat-chunk-3Z5S4KGM.mjs +918 -0
- package/dist/token-goat-chunk-4FVIAHSI.mjs +211 -0
- package/dist/{token-goat-chunk-66LODAUT.mjs → token-goat-chunk-4JJS54TR.mjs} +4 -3
- package/dist/token-goat-chunk-4LCCNRTG.mjs +313 -0
- package/dist/token-goat-chunk-54K3EUV3.mjs +35 -0
- package/dist/token-goat-chunk-56EIMS3E.mjs +159 -0
- package/dist/token-goat-chunk-5BCIJXMO.mjs +609 -0
- package/dist/token-goat-chunk-5KDMCMF2.mjs +362 -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-NILVK7XM.mjs → token-goat-chunk-64FBPDTK.mjs} +12 -6
- package/dist/{token-goat-chunk-LEG3JNJ6.mjs → token-goat-chunk-664RTTUV.mjs} +31 -15
- package/dist/token-goat-chunk-67TQJ76B.mjs +57 -0
- package/dist/token-goat-chunk-6QMAS7AB.mjs +42 -0
- package/dist/token-goat-chunk-7BXSNBY5.mjs +253 -0
- package/dist/{token-goat-chunk-F7QZRIWM.mjs → token-goat-chunk-7F2UBPD3.mjs} +42 -35
- package/dist/{token-goat-chunk-CC2PYJM7.mjs → token-goat-chunk-7IN2MKDS.mjs} +718 -595
- package/dist/token-goat-chunk-7NADEDKJ.mjs +124 -0
- package/dist/{token-goat-chunk-6SGLIPQB.mjs → token-goat-chunk-A3CK6N5Z.mjs} +621 -72
- package/dist/{token-goat-chunk-HXNAC4ZF.mjs → token-goat-chunk-AFLYLHDH.mjs} +48 -33
- package/dist/token-goat-chunk-AM5V6GSX.mjs +367 -0
- package/dist/{token-goat-chunk-I7CB3X4K.mjs → token-goat-chunk-APGZXSPS.mjs} +44 -148
- package/dist/{token-goat-chunk-BJBRGPBX.mjs → token-goat-chunk-ARDNEC2U.mjs} +11 -7
- package/dist/token-goat-chunk-ATCPY7EQ.mjs +134 -0
- package/dist/token-goat-chunk-B2RZZCSS.mjs +354 -0
- package/dist/{token-goat-chunk-QM76S6YS.mjs → token-goat-chunk-B45VMIIH.mjs} +6 -5
- package/dist/token-goat-chunk-BPGCUMR7.mjs +30 -0
- package/dist/{token-goat-chunk-GGLEE35R.mjs → token-goat-chunk-C63JQV5K.mjs} +49 -10
- package/dist/{token-goat-chunk-RJH64KQH.mjs → token-goat-chunk-COBQGL5S.mjs} +2661 -2440
- package/dist/token-goat-chunk-COTXZHTS.mjs +39 -0
- package/dist/token-goat-chunk-CYCEYAEO.mjs +265 -0
- package/dist/token-goat-chunk-CZ3LUXYZ.mjs +4115 -0
- package/dist/token-goat-chunk-DZX2YDPT.mjs +15 -0
- package/dist/token-goat-chunk-E3OQX2XT.mjs +824 -0
- package/dist/token-goat-chunk-EFHMMIGP.mjs +68 -0
- package/dist/token-goat-chunk-ETBHVDB6.mjs +328 -0
- package/dist/token-goat-chunk-EVMZJ27Z.mjs +147 -0
- package/dist/token-goat-chunk-EXKGNHEG.mjs +2096 -0
- package/dist/{token-goat-chunk-6Z5ULNE5.mjs → token-goat-chunk-FBNQNSJK.mjs} +2490 -4957
- package/dist/{token-goat-chunk-NMTKNYGF.mjs → token-goat-chunk-FNFBKLRD.mjs} +74 -9
- package/dist/{token-goat-chunk-XI2VFAV6.mjs → token-goat-chunk-FZ3NEW5O.mjs} +33 -19
- package/dist/token-goat-chunk-G5PJ7AGM.mjs +36 -0
- package/dist/{token-goat-chunk-VE27HPIF.mjs → token-goat-chunk-GFBSN7BD.mjs} +30 -398
- package/dist/{token-goat-chunk-L45ZQRT7.mjs → token-goat-chunk-GOLEOXZP.mjs} +780 -786
- package/dist/token-goat-chunk-H2K3QP6H.mjs +24 -0
- package/dist/token-goat-chunk-H2PHHGM5.mjs +188 -0
- package/dist/token-goat-chunk-HAVAOB3S.mjs +87 -0
- package/dist/token-goat-chunk-HG45AF2B.mjs +2228 -0
- package/dist/{token-goat-chunk-CBMY2FGI.mjs → token-goat-chunk-HOJLCGDP.mjs} +17113 -15554
- package/dist/{token-goat-chunk-HUDC5GS5.mjs → token-goat-chunk-HYBFA5X3.mjs} +120 -19
- package/dist/token-goat-chunk-IVALLT3S.mjs +48 -0
- package/dist/token-goat-chunk-IVE6U7KV.mjs +53 -0
- package/dist/{token-goat-chunk-UBUKHVYW.mjs → token-goat-chunk-IVKIZWAB.mjs} +3 -3
- package/dist/{token-goat-chunk-4JMWPWCS.mjs → token-goat-chunk-JB6QN6VF.mjs} +6 -4
- package/dist/{token-goat-chunk-Q4S3UQGO.mjs → token-goat-chunk-JDHE26RP.mjs} +10 -3
- package/dist/{token-goat-chunk-7R2XYKC5.mjs → token-goat-chunk-JDU3EXSU.mjs} +14 -10
- package/dist/token-goat-chunk-JDWCRD6M.mjs +253 -0
- package/dist/{token-goat-chunk-XBESNWEX.mjs → token-goat-chunk-JN4XMLSD.mjs} +7 -4
- package/dist/token-goat-chunk-JTQQGXZH.mjs +733 -0
- package/dist/token-goat-chunk-KKUFXAPD.mjs +25 -0
- package/dist/token-goat-chunk-KQNZDCBD.mjs +47 -0
- package/dist/{token-goat-chunk-4RN64ZND.mjs → token-goat-chunk-KWPNJBDH.mjs} +28 -3
- package/dist/token-goat-chunk-LOBGHXPB.mjs +242 -0
- package/dist/token-goat-chunk-MKPF4CL5.mjs +37 -0
- package/dist/token-goat-chunk-MNWKPRAL.mjs +13 -0
- package/dist/{token-goat-chunk-YWSP6IU7.mjs → token-goat-chunk-N2NMER56.mjs} +25 -15
- package/dist/token-goat-chunk-NYKZLXMK.mjs +218 -0
- package/dist/token-goat-chunk-OJBNYTJP.mjs +3087 -0
- package/dist/token-goat-chunk-P4QMM4WK.mjs +295 -0
- package/dist/token-goat-chunk-PD5VKH46.mjs +184 -0
- package/dist/token-goat-chunk-PEPTHRFF.mjs +129 -0
- package/dist/{token-goat-chunk-VWZKZPSR.mjs → token-goat-chunk-PU7V3FD6.mjs} +8752 -11098
- package/dist/token-goat-chunk-PY533T7F.mjs +46 -0
- package/dist/token-goat-chunk-Q5VTGRH7.mjs +761 -0
- package/dist/{token-goat-chunk-IHKZ3QNA.mjs → token-goat-chunk-QCLDAQTS.mjs} +33 -19
- package/dist/{token-goat-chunk-LKSXAMJB.mjs → token-goat-chunk-QSBRTGM2.mjs} +9 -2
- package/dist/{token-goat-chunk-4STDIGYC.mjs → token-goat-chunk-RC35RBUL.mjs} +7 -5
- package/dist/{token-goat-chunk-D5ICEPSB.mjs → token-goat-chunk-RHXKCZX3.mjs} +887 -507
- package/dist/{token-goat-chunk-RSS3TLXU.mjs → token-goat-chunk-RZRTDST7.mjs} +17 -7
- package/dist/{token-goat-chunk-MAMQPC43.mjs → token-goat-chunk-SJHWVNDQ.mjs} +15 -21
- package/dist/token-goat-chunk-SMVRN2HU.mjs +188 -0
- package/dist/{token-goat-chunk-EL7M26WP.mjs → token-goat-chunk-SQSSNQPE.mjs} +2100 -1442
- package/dist/{token-goat-chunk-OZRSREKR.mjs → token-goat-chunk-T4FK7VOV.mjs} +3 -3
- package/dist/token-goat-chunk-U4N3BN2W.mjs +92 -0
- package/dist/token-goat-chunk-UA5V6P3P.mjs +122 -0
- package/dist/{token-goat-chunk-XKY4VKJ4.mjs → token-goat-chunk-UQ5UK2T7.mjs} +15 -4
- package/dist/token-goat-chunk-USILZ3T3.mjs +53 -0
- package/dist/token-goat-chunk-VES7EL7O.mjs +205 -0
- package/dist/{token-goat-chunk-M56BWPBN.mjs → token-goat-chunk-VL3YIFHZ.mjs} +550 -49
- package/dist/{token-goat-chunk-IZXKVT4A.mjs → token-goat-chunk-VPBBTSJR.mjs} +362 -128
- package/dist/{token-goat-chunk-F2ARFHLJ.mjs → token-goat-chunk-W3QCJS6G.mjs} +10 -2
- package/dist/{token-goat-chunk-FSTWAOW6.mjs → token-goat-chunk-WY3L4DVT.mjs} +11 -5
- package/dist/{token-goat-chunk-OSUFN2FV.mjs → token-goat-chunk-XB5KKOCG.mjs} +5 -25
- package/dist/token-goat-chunk-XKI4SEMX.mjs +66 -0
- package/dist/token-goat-chunk-XU4P6Z24.mjs +133 -0
- package/dist/{token-goat-chunk-6CCQDAYY.mjs → token-goat-chunk-Y776AENC.mjs} +138 -33
- package/dist/token-goat-chunk-YARZFCZS.mjs +359 -0
- package/dist/{token-goat-chunk-EEIDFMEM.mjs → token-goat-chunk-YZAAZU2S.mjs} +12 -3
- package/dist/{token-goat-chunk-E3K3BTEQ.mjs → token-goat-chunk-Z44YO3QZ.mjs} +12 -6
- package/dist/token-goat-chunk-Z57YODA2.mjs +35 -0
- package/dist/{token-goat-chunk-DA43OE7L.mjs → token-goat-chunk-ZCDTCVIS.mjs} +49 -30
- package/dist/token-goat-chunk-ZEJVMUQH.mjs +48 -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-SJEKA7Y2.mjs → token-goat-chunk-ZQSJMO2R.mjs} +381 -201
- package/dist/token-goat-hook-client.cjs +539 -0
- package/dist/token-goat-hook-client.mjs +26 -0
- package/dist/token-goat-hook.mjs +48 -28
- package/dist/token-goat.core.mjs +10 -45
- package/docs/C4_RUNTIME_ARCHITECTURE.md +3 -3
- package/docs/cli.md +82 -47
- package/docs/install.md +58 -23
- package/docs/security.md +7 -7
- package/package.json +17 -7
- package/scripts/verify-native-dist.mjs +386 -0
- package/dist/token-goat-chunk-4JJBFT7V.mjs +0 -20
- package/dist/token-goat-chunk-5NNYIUGV.mjs +0 -143
- package/dist/token-goat-chunk-6DQNNFJ6.mjs +0 -294
- package/dist/token-goat-chunk-7MAFDRVR.mjs +0 -47
- package/dist/token-goat-chunk-BCN2YQC6.mjs +0 -32
- package/dist/token-goat-chunk-D7GHQKQD.mjs +0 -30
- package/dist/token-goat-chunk-GMOUBOX4.mjs +0 -386
- package/dist/token-goat-chunk-IFORDBGC.mjs +0 -192
- package/dist/token-goat-chunk-JXK2HQXS.mjs +0 -318
- package/dist/token-goat-chunk-L7SDVGBT.mjs +0 -430
- package/dist/token-goat-chunk-MMLMALWK.mjs +0 -1381
- package/dist/token-goat-chunk-MVSWBNMD.mjs +0 -1985
|
@@ -4,23 +4,30 @@ import {
|
|
|
4
4
|
CONTENT_DELIVERED_REASON,
|
|
5
5
|
classifyToolError,
|
|
6
6
|
errorPrefix
|
|
7
|
-
} from "./token-goat-chunk-
|
|
8
|
-
import "./token-goat-chunk-
|
|
9
|
-
import "./token-goat-chunk-
|
|
10
|
-
import "./token-goat-chunk-
|
|
11
|
-
import "./token-goat-chunk-
|
|
12
|
-
import "./token-goat-chunk-
|
|
13
|
-
import "./token-goat-chunk-
|
|
14
|
-
import "./token-goat-chunk-
|
|
15
|
-
import "./token-goat-chunk-
|
|
16
|
-
import "./token-goat-chunk-
|
|
17
|
-
import "./token-goat-chunk-
|
|
18
|
-
import "./token-goat-chunk-
|
|
19
|
-
import "./token-goat-chunk-
|
|
7
|
+
} from "./token-goat-chunk-PEPTHRFF.mjs";
|
|
8
|
+
import "./token-goat-chunk-MNWKPRAL.mjs";
|
|
9
|
+
import "./token-goat-chunk-APGZXSPS.mjs";
|
|
10
|
+
import "./token-goat-chunk-COBQGL5S.mjs";
|
|
11
|
+
import "./token-goat-chunk-ATCPY7EQ.mjs";
|
|
12
|
+
import "./token-goat-chunk-VPBBTSJR.mjs";
|
|
13
|
+
import "./token-goat-chunk-C63JQV5K.mjs";
|
|
14
|
+
import "./token-goat-chunk-JB6QN6VF.mjs";
|
|
15
|
+
import "./token-goat-chunk-3Z5S4KGM.mjs";
|
|
16
|
+
import "./token-goat-chunk-VL3YIFHZ.mjs";
|
|
17
|
+
import "./token-goat-chunk-XB5KKOCG.mjs";
|
|
18
|
+
import "./token-goat-chunk-4FVIAHSI.mjs";
|
|
19
|
+
import "./token-goat-chunk-7IN2MKDS.mjs";
|
|
20
|
+
import "./token-goat-chunk-U4N3BN2W.mjs";
|
|
21
|
+
import "./token-goat-chunk-YZAAZU2S.mjs";
|
|
22
|
+
import "./token-goat-chunk-IVE6U7KV.mjs";
|
|
23
|
+
import "./token-goat-chunk-GOLEOXZP.mjs";
|
|
24
|
+
import "./token-goat-chunk-AM5V6GSX.mjs";
|
|
20
25
|
import {
|
|
21
26
|
displaySafeText
|
|
22
|
-
} from "./token-goat-chunk-
|
|
23
|
-
import "./token-goat-chunk-
|
|
27
|
+
} from "./token-goat-chunk-FNFBKLRD.mjs";
|
|
28
|
+
import "./token-goat-chunk-VES7EL7O.mjs";
|
|
29
|
+
import "./token-goat-chunk-KWPNJBDH.mjs";
|
|
30
|
+
import "./token-goat-chunk-HAVAOB3S.mjs";
|
|
24
31
|
import {
|
|
25
32
|
init_define_import_meta_env
|
|
26
33
|
} from "./token-goat-chunk-A37V4PBF.mjs";
|
|
@@ -75,6 +82,15 @@ function newToolErrorAccumulator() {
|
|
|
75
82
|
finish() {
|
|
76
83
|
const topUnknown = [...unknownPrefixes.values()].sort((a, b) => b.count - a.count || byCodeUnit(a.tool, b.tool) || byCodeUnit(a.prefix, b.prefix)).slice(0, UNKNOWN_PREFIX_LIMIT);
|
|
77
84
|
return { byTool: sortTallies(tools), byModel: sortTallies(models), unknownPrefixes: topUnknown };
|
|
85
|
+
},
|
|
86
|
+
checkpoint() {
|
|
87
|
+
const saved = structuredClone([[...tools], [...models], [...unknownPrefixes]]);
|
|
88
|
+
return () => {
|
|
89
|
+
for (const [live, copy] of [[tools, saved[0]], [models, saved[1]], [unknownPrefixes, saved[2]]]) {
|
|
90
|
+
live.clear();
|
|
91
|
+
for (const [k, v] of copy) live.set(k, v);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
78
94
|
}
|
|
79
95
|
};
|
|
80
96
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
loadConfig
|
|
8
|
+
} from "./token-goat-chunk-7IN2MKDS.mjs";
|
|
9
|
+
import {
|
|
10
|
+
fenceUntrustedContent,
|
|
11
|
+
scanForInjectionPatterns
|
|
12
|
+
} from "./token-goat-chunk-FNFBKLRD.mjs";
|
|
13
|
+
import {
|
|
14
|
+
init_define_import_meta_env
|
|
15
|
+
} from "./token-goat-chunk-A37V4PBF.mjs";
|
|
16
|
+
|
|
17
|
+
// src/untrusted_fence.ts
|
|
18
|
+
init_define_import_meta_env();
|
|
19
|
+
function injectionFencingEnabled() {
|
|
20
|
+
try {
|
|
21
|
+
return loadConfig().injection.enabled;
|
|
22
|
+
} catch {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function fenceUntrusted(text, tag) {
|
|
27
|
+
if (!injectionFencingEnabled()) return text;
|
|
28
|
+
return fenceUntrustedContent(text, scanAndRecord(text), tag);
|
|
29
|
+
}
|
|
30
|
+
function fenceUntrustedSpans(spans, tag) {
|
|
31
|
+
const joined = spans.map((s) => s.text).join("");
|
|
32
|
+
if (!injectionFencingEnabled()) return joined;
|
|
33
|
+
return fenceUntrustedContent(spans, scanAndRecord(spans.filter((s) => s.own !== true).map((s) => s.text).join("")), tag);
|
|
34
|
+
}
|
|
35
|
+
function fenceWithMatches(text, matches, tag) {
|
|
36
|
+
if (!injectionFencingEnabled()) return text;
|
|
37
|
+
return tag === void 0 ? fenceUntrustedContent(text, matches) : fenceUntrustedContent(text, matches, tag);
|
|
38
|
+
}
|
|
39
|
+
function scanAndRecord(text) {
|
|
40
|
+
if (!injectionFencingEnabled()) return [];
|
|
41
|
+
let matches;
|
|
42
|
+
try {
|
|
43
|
+
matches = scanForInjectionPatterns(text);
|
|
44
|
+
} catch {
|
|
45
|
+
matches = [];
|
|
46
|
+
}
|
|
47
|
+
if (matches.length > 0) recordStat("injection_detected", 0, 0, void 0, matches.join(","));
|
|
48
|
+
return matches;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export {
|
|
52
|
+
injectionFencingEnabled,
|
|
53
|
+
fenceUntrusted,
|
|
54
|
+
fenceUntrustedSpans,
|
|
55
|
+
fenceWithMatches,
|
|
56
|
+
scanAndRecord
|
|
57
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
|
+
const require = __cjsRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
DEFAULT_HEARTBEAT_INTERVAL_MS,
|
|
5
|
+
DEFAULT_TIMEOUT_SECONDS,
|
|
6
|
+
MAX_CAPTURE_BYTES,
|
|
7
|
+
resolveFilter,
|
|
8
|
+
run,
|
|
9
|
+
runRaw,
|
|
10
|
+
spawnTarget,
|
|
11
|
+
unknownFilterNotice
|
|
12
|
+
} from "./token-goat-chunk-7F2UBPD3.mjs";
|
|
13
|
+
import "./token-goat-chunk-54K3EUV3.mjs";
|
|
14
|
+
import "./token-goat-chunk-COBQGL5S.mjs";
|
|
15
|
+
import "./token-goat-chunk-AFLYLHDH.mjs";
|
|
16
|
+
import "./token-goat-chunk-HYBFA5X3.mjs";
|
|
17
|
+
import "./token-goat-chunk-ARDNEC2U.mjs";
|
|
18
|
+
import "./token-goat-chunk-3Z5S4KGM.mjs";
|
|
19
|
+
import "./token-goat-chunk-VL3YIFHZ.mjs";
|
|
20
|
+
import "./token-goat-chunk-XB5KKOCG.mjs";
|
|
21
|
+
import "./token-goat-chunk-4FVIAHSI.mjs";
|
|
22
|
+
import "./token-goat-chunk-7IN2MKDS.mjs";
|
|
23
|
+
import "./token-goat-chunk-U4N3BN2W.mjs";
|
|
24
|
+
import "./token-goat-chunk-YZAAZU2S.mjs";
|
|
25
|
+
import "./token-goat-chunk-IVE6U7KV.mjs";
|
|
26
|
+
import "./token-goat-chunk-GOLEOXZP.mjs";
|
|
27
|
+
import "./token-goat-chunk-AM5V6GSX.mjs";
|
|
28
|
+
import "./token-goat-chunk-FNFBKLRD.mjs";
|
|
29
|
+
import "./token-goat-chunk-VES7EL7O.mjs";
|
|
30
|
+
import "./token-goat-chunk-KWPNJBDH.mjs";
|
|
31
|
+
import "./token-goat-chunk-HAVAOB3S.mjs";
|
|
32
|
+
import "./token-goat-chunk-A37V4PBF.mjs";
|
|
33
|
+
export {
|
|
34
|
+
DEFAULT_HEARTBEAT_INTERVAL_MS,
|
|
35
|
+
DEFAULT_TIMEOUT_SECONDS,
|
|
36
|
+
MAX_CAPTURE_BYTES,
|
|
37
|
+
resolveFilter,
|
|
38
|
+
run,
|
|
39
|
+
runRaw,
|
|
40
|
+
spawnTarget,
|
|
41
|
+
unknownFilterNotice
|
|
42
|
+
};
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
|
+
const require = __cjsRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
getTrackedFiles
|
|
5
|
+
} from "./token-goat-chunk-FBNQNSJK.mjs";
|
|
6
|
+
import {
|
|
7
|
+
enqueueDirtyPathsSafe
|
|
8
|
+
} from "./token-goat-chunk-H2PHHGM5.mjs";
|
|
9
|
+
import {
|
|
10
|
+
indexedPathSpellingIsStale,
|
|
11
|
+
parserFingerprintForLanguage
|
|
12
|
+
} from "./token-goat-chunk-RHXKCZX3.mjs";
|
|
13
|
+
import {
|
|
14
|
+
getProjectFileEntries,
|
|
15
|
+
projectScopeClause
|
|
16
|
+
} from "./token-goat-chunk-HYBFA5X3.mjs";
|
|
17
|
+
import {
|
|
18
|
+
getDb
|
|
19
|
+
} from "./token-goat-chunk-VL3YIFHZ.mjs";
|
|
20
|
+
import {
|
|
21
|
+
fingerprintFile,
|
|
22
|
+
getDisplayRoot,
|
|
23
|
+
indexedFileIsGone
|
|
24
|
+
} from "./token-goat-chunk-7IN2MKDS.mjs";
|
|
25
|
+
import {
|
|
26
|
+
countNoun
|
|
27
|
+
} from "./token-goat-chunk-GOLEOXZP.mjs";
|
|
28
|
+
import {
|
|
29
|
+
foldPath
|
|
30
|
+
} from "./token-goat-chunk-AM5V6GSX.mjs";
|
|
31
|
+
import {
|
|
32
|
+
displaySafeJson,
|
|
33
|
+
normalizePath,
|
|
34
|
+
resolveIndexPath,
|
|
35
|
+
toDisplayPath
|
|
36
|
+
} from "./token-goat-chunk-FNFBKLRD.mjs";
|
|
37
|
+
import {
|
|
38
|
+
globalDbPath
|
|
39
|
+
} from "./token-goat-chunk-VES7EL7O.mjs";
|
|
40
|
+
import {
|
|
41
|
+
init_define_import_meta_env
|
|
42
|
+
} from "./token-goat-chunk-A37V4PBF.mjs";
|
|
43
|
+
|
|
44
|
+
// src/reconcile.ts
|
|
45
|
+
init_define_import_meta_env();
|
|
46
|
+
import * as fs from "node:fs";
|
|
47
|
+
var DEFAULT_RECONCILE_BUDGET_MS = 1500;
|
|
48
|
+
function readReconcileCursor(dbPath, root) {
|
|
49
|
+
try {
|
|
50
|
+
const row = getDb(dbPath).prepare("SELECT last_scanned_path FROM reconcile_cursor WHERE root = ?").get(root);
|
|
51
|
+
return row?.last_scanned_path ?? null;
|
|
52
|
+
} catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function writeReconcileCursor(dbPath, root, lastScannedPath) {
|
|
57
|
+
try {
|
|
58
|
+
getDb(dbPath).prepare(
|
|
59
|
+
"INSERT INTO reconcile_cursor (root, last_scanned_path, updated_at) VALUES (?, ?, ?) ON CONFLICT(root) DO UPDATE SET last_scanned_path = excluded.last_scanned_path, updated_at = excluded.updated_at"
|
|
60
|
+
).run(root, lastScannedPath, Date.now());
|
|
61
|
+
} catch {
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function clearReconcileCursor(dbPath, root) {
|
|
65
|
+
try {
|
|
66
|
+
getDb(dbPath).prepare("DELETE FROM reconcile_cursor WHERE root = ?").run(root);
|
|
67
|
+
} catch {
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function runReconcile(opts = {}) {
|
|
71
|
+
const raw = reconcileProject(opts);
|
|
72
|
+
const root = getDisplayRoot(opts.cwd ?? process.cwd());
|
|
73
|
+
const display = (paths) => paths.map((p) => toDisplayPath(root, p)).sort();
|
|
74
|
+
const result = {
|
|
75
|
+
...raw,
|
|
76
|
+
changed: display(raw.changed),
|
|
77
|
+
added: display(raw.added),
|
|
78
|
+
removed: display(raw.removed)
|
|
79
|
+
};
|
|
80
|
+
if (opts.json === true) {
|
|
81
|
+
process.stdout.write(`${displaySafeJson(result)}
|
|
82
|
+
`);
|
|
83
|
+
return 0;
|
|
84
|
+
}
|
|
85
|
+
const unqueued = opts.dryRun === true ? 0 : result.changed.length + result.added.length + result.removed.length - result.enqueued;
|
|
86
|
+
const noneQueued = unqueued > 0 && result.enqueued === 0;
|
|
87
|
+
const lines = [];
|
|
88
|
+
if (isReconcileClean(result)) {
|
|
89
|
+
if (!result.trackedUnavailable) {
|
|
90
|
+
lines.push(`Index matches disk: ${countNoun(result.scanned, "file")} checked in ${result.elapsedMs}ms.`);
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
const verb = opts.dryRun === true ? "would reindex" : noneQueued ? "not queued" : "queued for reindexing";
|
|
94
|
+
const dropVerb = opts.dryRun === true ? "would drop from the index" : noneQueued ? "not queued" : "queued for removal";
|
|
95
|
+
if (result.changed.length > 0) lines.push(`${countNoun(result.changed.length, "file")} changed since indexing (${verb}):`);
|
|
96
|
+
for (const f of result.changed) lines.push(` ~ ${f}`);
|
|
97
|
+
if (result.added.length > 0) lines.push(`${countNoun(result.added.length, "file")} not in the index (${verb}):`);
|
|
98
|
+
for (const f of result.added) lines.push(` + ${f}`);
|
|
99
|
+
if (result.removed.length > 0) lines.push(`${countNoun(result.removed.length, "file")} indexed but gone from disk (${dropVerb}):`);
|
|
100
|
+
for (const f of result.removed) lines.push(` - ${f}`);
|
|
101
|
+
lines.push(`Checked ${countNoun(result.scanned, "file")} in ${result.elapsedMs}ms.`);
|
|
102
|
+
}
|
|
103
|
+
if (result.mtimeOnly > 0) {
|
|
104
|
+
lines.push(`${countNoun(result.mtimeOnly, "file")} had a newer timestamp but identical content, so ${result.mtimeOnly === 1 ? "it was" : "they were"} left alone.`);
|
|
105
|
+
}
|
|
106
|
+
if (result.parserStale > 0) {
|
|
107
|
+
const reparseVerb = opts.dryRun === true ? "would reparse" : noneQueued ? "not queued" : "queued for reparse";
|
|
108
|
+
lines.push(`${countNoun(result.parserStale, "file")} of the above ${result.parserStale === 1 ? "was" : "were"} unchanged on disk but indexed by an older parser (${reparseVerb}).`);
|
|
109
|
+
}
|
|
110
|
+
if (result.embedStale > 0) {
|
|
111
|
+
const reembedVerb = opts.dryRun === true ? "would re-embed" : noneQueued ? "not queued" : "queued for re-embedding";
|
|
112
|
+
lines.push(`${countNoun(result.embedStale, "file")} of the above ${result.embedStale === 1 ? "was" : "were"} unchanged on disk but held out-of-date embeddings (${reembedVerb}).`);
|
|
113
|
+
}
|
|
114
|
+
if (unqueued > 0) {
|
|
115
|
+
lines.push(`${countNoun(unqueued, "file")} of the above could not be queued for reindexing: the queue takes nothing under the OS temp dir, and nothing at all when it cannot be written. Run token-goat index here to bring the index up to date.`);
|
|
116
|
+
}
|
|
117
|
+
if (result.trackedUnavailable) {
|
|
118
|
+
lines.push("This project has an index but git listed no files in it, so nothing on disk was compared against it and changed or new files could not be found. Files gone from disk were still detected. Run token-goat inside the repository, or reindex with --walk if this directory is deliberately not under git.");
|
|
119
|
+
}
|
|
120
|
+
if (result.budgetExhausted) {
|
|
121
|
+
lines.push(`Stopped at the ${result.elapsedMs}ms budget with ${countNoun(result.unscanned, "file")} unchecked, so there may be more drift; deletions were not computed at all, because an unchecked file is indistinguishable from a deleted one. Raise --budget-ms for a complete sweep.`);
|
|
122
|
+
}
|
|
123
|
+
process.stdout.write(`${lines.join("\n")}
|
|
124
|
+
`);
|
|
125
|
+
return 0;
|
|
126
|
+
}
|
|
127
|
+
function isReconcileClean(r) {
|
|
128
|
+
return r.changed.length === 0 && r.added.length === 0 && r.removed.length === 0;
|
|
129
|
+
}
|
|
130
|
+
function reconcileProject(opts = {}) {
|
|
131
|
+
const cwd = opts.cwd ?? process.cwd();
|
|
132
|
+
const budgetMs = opts.budgetMs ?? DEFAULT_RECONCILE_BUDGET_MS;
|
|
133
|
+
const calledAt = Date.now();
|
|
134
|
+
const dbPath = opts.dbPath ?? globalDbPath();
|
|
135
|
+
const tracked = getTrackedFiles(cwd);
|
|
136
|
+
const projectRoot = resolveIndexPath(".", cwd);
|
|
137
|
+
const indexed = getProjectFileEntries(projectRoot, dbPath);
|
|
138
|
+
const chunkScope = projectScopeClause("file_path");
|
|
139
|
+
const chunked = new Set(
|
|
140
|
+
getDb(dbPath).prepare(`SELECT DISTINCT file_path FROM chunks WHERE ${chunkScope.clause}`).pluck().all(...chunkScope.params(projectRoot)).map((p) => foldPath(normalizePath(p)))
|
|
141
|
+
);
|
|
142
|
+
const startedAt = Date.now();
|
|
143
|
+
let scanOrder = tracked;
|
|
144
|
+
const cursorPath = tracked.length > 0 ? readReconcileCursor(dbPath, projectRoot) : null;
|
|
145
|
+
if (cursorPath !== null) {
|
|
146
|
+
const cursorFolded = foldPath(normalizePath(cursorPath));
|
|
147
|
+
const cursorIdx = tracked.findIndex((f) => foldPath(normalizePath(f)) === cursorFolded);
|
|
148
|
+
if (cursorIdx !== -1) {
|
|
149
|
+
scanOrder = [...tracked.slice(cursorIdx + 1), ...tracked.slice(0, cursorIdx + 1)];
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const changed = [];
|
|
153
|
+
const added = [];
|
|
154
|
+
const seenOnDisk = /* @__PURE__ */ new Set();
|
|
155
|
+
let mtimeOnly = 0;
|
|
156
|
+
let parserStale = 0;
|
|
157
|
+
let embedStale = 0;
|
|
158
|
+
let scanned = 0;
|
|
159
|
+
let budgetExhausted = false;
|
|
160
|
+
let lastScanned = null;
|
|
161
|
+
for (const file of scanOrder) {
|
|
162
|
+
if (Date.now() - startedAt >= budgetMs) {
|
|
163
|
+
budgetExhausted = true;
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
scanned++;
|
|
167
|
+
lastScanned = file;
|
|
168
|
+
const normalized = normalizePath(file);
|
|
169
|
+
const folded = foldPath(normalized);
|
|
170
|
+
seenOnDisk.add(folded);
|
|
171
|
+
const entry = indexed.get(folded);
|
|
172
|
+
if (entry === void 0) {
|
|
173
|
+
added.push(file);
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
if (entry.parserSha !== parserFingerprintForLanguage(entry.language)) {
|
|
177
|
+
changed.push(file);
|
|
178
|
+
parserStale++;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (entry.embedSha === "" && chunked.has(folded)) {
|
|
182
|
+
changed.push(file);
|
|
183
|
+
embedStale++;
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (normalizePath(entry.filePath).slice(projectRoot.length) !== normalized.slice(projectRoot.length) && indexedPathSpellingIsStale(entry.filePath, file)) {
|
|
187
|
+
changed.push(file);
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
let mtimeMs;
|
|
191
|
+
try {
|
|
192
|
+
mtimeMs = fs.statSync(file).mtimeMs;
|
|
193
|
+
} catch {
|
|
194
|
+
changed.push(file);
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (entry.mtime !== 0 && mtimeMs / 1e3 === entry.mtime) continue;
|
|
198
|
+
const diskSha = fingerprintFile(file);
|
|
199
|
+
if (diskSha === null) {
|
|
200
|
+
changed.push(file);
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (diskSha === entry.sha) {
|
|
204
|
+
mtimeOnly++;
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
changed.push(file);
|
|
208
|
+
}
|
|
209
|
+
const trackedUnavailable = tracked.length === 0 && indexed.size > 0;
|
|
210
|
+
const removed = [];
|
|
211
|
+
if (!budgetExhausted) {
|
|
212
|
+
for (const [folded, entry] of indexed) {
|
|
213
|
+
if (seenOnDisk.has(folded)) continue;
|
|
214
|
+
if (Date.now() - startedAt >= budgetMs) {
|
|
215
|
+
budgetExhausted = true;
|
|
216
|
+
removed.length = 0;
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
if (indexedFileIsGone(entry.filePath)) removed.push(entry.filePath);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
let enqueued = 0;
|
|
223
|
+
if (opts.dryRun !== true) {
|
|
224
|
+
const toEnqueue = [...changed, ...added, ...removed].map((p) => resolveIndexPath(p, cwd));
|
|
225
|
+
enqueued = enqueueDirtyPathsSafe(toEnqueue, { alreadyResolved: true });
|
|
226
|
+
if (budgetExhausted) {
|
|
227
|
+
if (lastScanned !== null) writeReconcileCursor(dbPath, projectRoot, lastScanned);
|
|
228
|
+
} else if (tracked.length > 0) {
|
|
229
|
+
clearReconcileCursor(dbPath, projectRoot);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
scanned,
|
|
234
|
+
changed,
|
|
235
|
+
added,
|
|
236
|
+
removed,
|
|
237
|
+
mtimeOnly,
|
|
238
|
+
parserStale,
|
|
239
|
+
embedStale,
|
|
240
|
+
budgetExhausted,
|
|
241
|
+
trackedUnavailable,
|
|
242
|
+
unscanned: Math.max(0, tracked.length - scanned),
|
|
243
|
+
enqueued,
|
|
244
|
+
elapsedMs: Date.now() - calledAt
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export {
|
|
249
|
+
DEFAULT_RECONCILE_BUDGET_MS,
|
|
250
|
+
runReconcile,
|
|
251
|
+
isReconcileClean,
|
|
252
|
+
reconcileProject
|
|
253
|
+
};
|
|
@@ -1,27 +1,33 @@
|
|
|
1
1
|
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
2
|
const require = __cjsRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
deliveredOutputBytes
|
|
5
|
+
} from "./token-goat-chunk-54K3EUV3.mjs";
|
|
3
6
|
import {
|
|
4
7
|
PassthroughFilter,
|
|
8
|
+
TOOL_FILTERS,
|
|
5
9
|
compressedTokensSaved,
|
|
6
10
|
deliverCompressed,
|
|
7
11
|
dispatchArgv,
|
|
8
12
|
filterByName,
|
|
9
13
|
selectFilter
|
|
10
|
-
} from "./token-goat-chunk-
|
|
14
|
+
} from "./token-goat-chunk-COBQGL5S.mjs";
|
|
11
15
|
import {
|
|
12
16
|
storeBashOutputSync
|
|
13
|
-
} from "./token-goat-chunk-
|
|
14
|
-
import {
|
|
15
|
-
capTokens,
|
|
16
|
-
shlexSplit
|
|
17
|
-
} from "./token-goat-chunk-4RN64ZND.mjs";
|
|
17
|
+
} from "./token-goat-chunk-AFLYLHDH.mjs";
|
|
18
18
|
import {
|
|
19
19
|
recordStat
|
|
20
|
-
} from "./token-goat-chunk-
|
|
20
|
+
} from "./token-goat-chunk-3Z5S4KGM.mjs";
|
|
21
21
|
import {
|
|
22
|
-
detectHarness,
|
|
23
22
|
loadConfig
|
|
24
|
-
} from "./token-goat-chunk-
|
|
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";
|
|
25
31
|
import {
|
|
26
32
|
init_define_import_meta_env
|
|
27
33
|
} from "./token-goat-chunk-A37V4PBF.mjs";
|
|
@@ -31,28 +37,6 @@ init_define_import_meta_env();
|
|
|
31
37
|
import { spawn, spawnSync } from "node:child_process";
|
|
32
38
|
import * as os from "node:os";
|
|
33
39
|
|
|
34
|
-
// src/delivery_cap.ts
|
|
35
|
-
init_define_import_meta_env();
|
|
36
|
-
var CLAUDE_CODE_BASH_OUTPUT_CAP_BYTES = 2e4;
|
|
37
|
-
var CLAUDE_CODE_PERSISTED_PREVIEW_BYTES = 2048;
|
|
38
|
-
function bashOutputCapBytes(harness = detectHarness()) {
|
|
39
|
-
return harness === "claudecode" ? CLAUDE_CODE_BASH_OUTPUT_CAP_BYTES : null;
|
|
40
|
-
}
|
|
41
|
-
function clipToDeliveryCap(text, reserveBytes) {
|
|
42
|
-
const cap = bashOutputCapBytes();
|
|
43
|
-
const room = cap === null ? null : cap - reserveBytes;
|
|
44
|
-
if (room === null || room <= 0 || Buffer.byteLength(text, "utf-8") <= room) return { text, clipped: false };
|
|
45
|
-
const sliced = Buffer.from(text, "utf-8").subarray(0, room).toString("utf-8");
|
|
46
|
-
const lastNewline = sliced.lastIndexOf("\n");
|
|
47
|
-
return { text: lastNewline > 0 ? sliced.slice(0, lastNewline) : sliced, clipped: true };
|
|
48
|
-
}
|
|
49
|
-
function deliveredOutputBytes(originalBytes, harness) {
|
|
50
|
-
const cap = bashOutputCapBytes(harness);
|
|
51
|
-
if (cap === null) return Math.max(0, originalBytes);
|
|
52
|
-
if (originalBytes <= cap) return Math.max(0, originalBytes);
|
|
53
|
-
return CLAUDE_CODE_PERSISTED_PREVIEW_BYTES;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
40
|
// src/shell.ts
|
|
57
41
|
init_define_import_meta_env();
|
|
58
42
|
import * as fs from "node:fs";
|
|
@@ -205,6 +189,8 @@ function resolveFilter(command, filterName, cwd) {
|
|
|
205
189
|
if (filterName) {
|
|
206
190
|
const named = filterByName(filterName);
|
|
207
191
|
if (named !== null) return { filter: named, argv };
|
|
192
|
+
const filter = split === null ? null : selectFilter(split, effectiveCwd);
|
|
193
|
+
return { filter, argv, unknownFilter: filterName };
|
|
208
194
|
}
|
|
209
195
|
if (split === null) return { filter: null, argv };
|
|
210
196
|
return { filter: selectFilter(split, effectiveCwd), argv };
|
|
@@ -221,7 +207,7 @@ function spawnTarget(command, nativeShell, shellType) {
|
|
|
221
207
|
"-NoProfile",
|
|
222
208
|
"-NonInteractive",
|
|
223
209
|
"-Command",
|
|
224
|
-
|
|
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 }`
|
|
225
211
|
],
|
|
226
212
|
shell: false,
|
|
227
213
|
cmdEnv: { TG_CMD: command }
|
|
@@ -255,9 +241,19 @@ function resolveCompressLimits() {
|
|
|
255
241
|
return { maxLines: 1e3, maxBytes: 64 * 1024 };
|
|
256
242
|
}
|
|
257
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
|
+
}
|
|
258
253
|
async function run(command, opts = {}) {
|
|
259
254
|
const timeout = opts.timeout ?? DEFAULT_TIMEOUT_SECONDS;
|
|
260
|
-
const { filter, argv } = resolveFilter(command, opts.filterName, opts.cwd);
|
|
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));
|
|
261
257
|
if (filter === null) {
|
|
262
258
|
if ((opts.maxTokens ?? 0) > 0 || opts.quietSuccess) {
|
|
263
259
|
return wrapAndCompress(command, argv, new PassthroughFilter(), timeout, resolveProfile(opts.compressionProfile), opts);
|
|
@@ -278,6 +274,11 @@ function passthrough(command, timeout, cwd, env, nativeShell, shellType) {
|
|
|
278
274
|
stdio: "inherit"
|
|
279
275
|
});
|
|
280
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
|
+
}
|
|
281
282
|
if (result.status !== null) return result.status;
|
|
282
283
|
if (result.signal) return signalExitCode(result.signal);
|
|
283
284
|
return 0;
|
|
@@ -317,7 +318,12 @@ async function wrapAndCompress(command, argv, filter, timeout, profile, opts) {
|
|
|
317
318
|
};
|
|
318
319
|
child.stdout?.on("data", onData(stdoutSink));
|
|
319
320
|
child.stderr?.on("data", onData(stderrSink));
|
|
321
|
+
let spawnError = null;
|
|
320
322
|
const { code, signal } = await new Promise((resolve) => {
|
|
323
|
+
child.on("error", (e) => {
|
|
324
|
+
spawnError = e;
|
|
325
|
+
resolve({ code: 127, signal: null });
|
|
326
|
+
});
|
|
321
327
|
child.on("close", (code2, signal2) => resolve({ code: code2, signal: signal2 }));
|
|
322
328
|
});
|
|
323
329
|
heartbeat.stop();
|
|
@@ -328,6 +334,7 @@ async function wrapAndCompress(command, argv, filter, timeout, profile, opts) {
|
|
|
328
334
|
stdoutText += `
|
|
329
335
|
[token-goat: capture capped at ${MAX_CAPTURE_BYTES / (1024 * 1024)} MiB]`;
|
|
330
336
|
}
|
|
337
|
+
if (spawnError !== null) stderrText = (stderrText ? stderrText + "\n" : "") + `[token-goat: ${displaySafeText(spawnError.message)}]`;
|
|
331
338
|
let exitCode;
|
|
332
339
|
if (timedOut) {
|
|
333
340
|
exitCode = 124;
|
|
@@ -377,14 +384,14 @@ function recordSavings(result) {
|
|
|
377
384
|
}
|
|
378
385
|
|
|
379
386
|
export {
|
|
380
|
-
clipToDeliveryCap,
|
|
381
|
-
deliveredOutputBytes,
|
|
382
387
|
canRunWrappedShell,
|
|
383
388
|
canRunPowerShell,
|
|
384
389
|
DEFAULT_TIMEOUT_SECONDS,
|
|
385
390
|
MAX_CAPTURE_BYTES,
|
|
386
391
|
DEFAULT_HEARTBEAT_INTERVAL_MS,
|
|
387
392
|
resolveFilter,
|
|
393
|
+
spawnTarget,
|
|
394
|
+
unknownFilterNotice,
|
|
388
395
|
run,
|
|
389
396
|
runRaw
|
|
390
397
|
};
|