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
|
@@ -1,42 +1,430 @@
|
|
|
1
1
|
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
2
|
const require = __cjsRequire(import.meta.url);
|
|
3
3
|
import {
|
|
4
|
-
COPILOT_CLI_TOOL_NAME_MAP,
|
|
5
|
-
foldToolName,
|
|
6
|
-
readCopilotMcpTools
|
|
7
|
-
} from "./token-goat-chunk-EUSDXRXU.mjs";
|
|
8
|
-
import {
|
|
9
|
-
countRedactionPlaceholders,
|
|
10
4
|
recordStat,
|
|
11
5
|
savedTokensFromBytes
|
|
12
|
-
} from "./token-goat-chunk-
|
|
6
|
+
} from "./token-goat-chunk-U4WHMG6Y.mjs";
|
|
7
|
+
import {
|
|
8
|
+
estimateTokensFromLength
|
|
9
|
+
} from "./token-goat-chunk-BFCWY73P.mjs";
|
|
10
|
+
import {
|
|
11
|
+
countRedactionPlaceholders
|
|
12
|
+
} from "./token-goat-chunk-T5P5ACNQ.mjs";
|
|
13
13
|
import {
|
|
14
|
-
detectHarness,
|
|
15
14
|
loadConfig,
|
|
16
15
|
ownGet
|
|
17
|
-
} from "./token-goat-chunk-
|
|
16
|
+
} from "./token-goat-chunk-7EZTZOMC.mjs";
|
|
17
|
+
import {
|
|
18
|
+
detectHarness
|
|
19
|
+
} from "./token-goat-chunk-QYHO5CPH.mjs";
|
|
18
20
|
import {
|
|
19
21
|
registerReset
|
|
20
22
|
} from "./token-goat-chunk-YZAAZU2S.mjs";
|
|
21
23
|
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
isInsideRoot
|
|
25
|
-
} from "./token-goat-chunk-TCQANXYC.mjs";
|
|
24
|
+
echoedValue
|
|
25
|
+
} from "./token-goat-chunk-GGGG7RWB.mjs";
|
|
26
26
|
import {
|
|
27
27
|
displaySafeText,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} from "./token-goat-chunk-
|
|
28
|
+
neutralizeOutsideFences,
|
|
29
|
+
resolveToolPath
|
|
30
|
+
} from "./token-goat-chunk-FNFBKLRD.mjs";
|
|
31
31
|
import {
|
|
32
32
|
init_define_import_meta_env
|
|
33
33
|
} from "./token-goat-chunk-A37V4PBF.mjs";
|
|
34
34
|
|
|
35
|
+
// src/hooks_common.ts
|
|
36
|
+
init_define_import_meta_env();
|
|
37
|
+
function getToolName(event) {
|
|
38
|
+
return event.toolName;
|
|
39
|
+
}
|
|
40
|
+
function getToolInput(event) {
|
|
41
|
+
return event.toolInput;
|
|
42
|
+
}
|
|
43
|
+
function getFilePath(event) {
|
|
44
|
+
const value = event.toolInput["file_path"];
|
|
45
|
+
if (typeof value === "string" && value !== "") return resolveEventPath(event, value);
|
|
46
|
+
const notebookValue = event.toolInput["notebook_path"];
|
|
47
|
+
return typeof notebookValue === "string" && notebookValue !== "" ? resolveEventPath(event, notebookValue) : void 0;
|
|
48
|
+
}
|
|
49
|
+
function resolveEventPath(event, file) {
|
|
50
|
+
return resolveToolPath(file, getCwd(event));
|
|
51
|
+
}
|
|
52
|
+
function getFilePaths(event) {
|
|
53
|
+
const out = [];
|
|
54
|
+
const list = event.toolInput["file_paths"];
|
|
55
|
+
if (Array.isArray(list)) {
|
|
56
|
+
for (const entry of list) {
|
|
57
|
+
if (typeof entry !== "string" || entry === "") continue;
|
|
58
|
+
const resolved = resolveEventPath(event, entry);
|
|
59
|
+
if (!out.includes(resolved)) out.push(resolved);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const single = getFilePath(event);
|
|
63
|
+
if (single !== void 0 && !out.includes(single)) out.push(single);
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
function getCwd(event) {
|
|
67
|
+
const value = event.raw && typeof event.raw === "object" ? event.raw["cwd"] : void 0;
|
|
68
|
+
return typeof value === "string" && value !== "" ? value : void 0;
|
|
69
|
+
}
|
|
70
|
+
function getTranscriptPath(event) {
|
|
71
|
+
const value = event.raw && typeof event.raw === "object" ? event.raw["transcript_path"] : void 0;
|
|
72
|
+
return typeof value === "string" && value !== "" ? value : void 0;
|
|
73
|
+
}
|
|
74
|
+
function extractToolResponseField(raw, keys) {
|
|
75
|
+
const resp = raw["tool_response"];
|
|
76
|
+
if (typeof resp === "string") return resp;
|
|
77
|
+
if (resp !== null && typeof resp === "object") {
|
|
78
|
+
const r = resp;
|
|
79
|
+
const path3 = resolveToolResponseFieldPath(r, keys);
|
|
80
|
+
if (path3 !== null) return readAtPath(r, path3);
|
|
81
|
+
}
|
|
82
|
+
return "";
|
|
83
|
+
}
|
|
84
|
+
var NESTED_TOOL_RESPONSE_PATHS = [["file", "content"]];
|
|
85
|
+
function readAtPath(resp, path3) {
|
|
86
|
+
let cur = resp;
|
|
87
|
+
for (const seg of path3) {
|
|
88
|
+
if (cur === null || typeof cur !== "object") return "";
|
|
89
|
+
cur = cur[seg];
|
|
90
|
+
}
|
|
91
|
+
return typeof cur === "string" ? cur : "";
|
|
92
|
+
}
|
|
93
|
+
function resolveToolResponseFieldPath(resp, keys) {
|
|
94
|
+
for (const key of keys) {
|
|
95
|
+
if (typeof resp[key] === "string" && resp[key] !== "") return [key];
|
|
96
|
+
}
|
|
97
|
+
for (const path3 of NESTED_TOOL_RESPONSE_PATHS) {
|
|
98
|
+
if (readAtPath(resp, path3) !== "") return path3;
|
|
99
|
+
}
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
function replaceToolResponseField(resp, keys, newText) {
|
|
103
|
+
const path3 = resolveToolResponseFieldPath(resp, keys);
|
|
104
|
+
if (path3 === null) return null;
|
|
105
|
+
const root = { ...resp };
|
|
106
|
+
let cur = root;
|
|
107
|
+
for (let i = 0; i < path3.length - 1; i++) {
|
|
108
|
+
const seg = path3[i];
|
|
109
|
+
const child = cur[seg];
|
|
110
|
+
if (child === null || typeof child !== "object") return null;
|
|
111
|
+
const cloned = { ...child };
|
|
112
|
+
cur[seg] = cloned;
|
|
113
|
+
cur = cloned;
|
|
114
|
+
}
|
|
115
|
+
cur[path3[path3.length - 1]] = newText;
|
|
116
|
+
return root;
|
|
117
|
+
}
|
|
118
|
+
var OUTPUT_FIRST_TOOL_RESPONSE_KEYS = ["output", "content", "text", "body", "stdout", "stderr"];
|
|
119
|
+
var BODY_FIRST_TOOL_RESPONSE_KEYS = ["output", "body", "text", "content", "result"];
|
|
120
|
+
function isMcpErrorResponse(raw) {
|
|
121
|
+
const tr = raw["tool_response"];
|
|
122
|
+
if (!tr || typeof tr !== "object") return false;
|
|
123
|
+
return tr["isError"] === true;
|
|
124
|
+
}
|
|
125
|
+
var MCP_CONTENT_BLOCK_TYPES = /* @__PURE__ */ new Set(["text", "image", "audio", "resource", "resource_link"]);
|
|
126
|
+
function blocksToText(blocks) {
|
|
127
|
+
if (!Array.isArray(blocks)) return null;
|
|
128
|
+
const parts = [];
|
|
129
|
+
let recognised = false;
|
|
130
|
+
for (const block of blocks) {
|
|
131
|
+
if (!block || typeof block !== "object") continue;
|
|
132
|
+
const rec = block;
|
|
133
|
+
const type = rec["type"];
|
|
134
|
+
if (typeof type === "string" && MCP_CONTENT_BLOCK_TYPES.has(type)) recognised = true;
|
|
135
|
+
if (typeof rec["text"] === "string") {
|
|
136
|
+
parts.push(rec["text"]);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const resource = rec["resource"];
|
|
140
|
+
if (resource !== null && typeof resource === "object") {
|
|
141
|
+
const nested = resource["text"];
|
|
142
|
+
if (typeof nested === "string") parts.push(nested);
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (rec["type"] === "resource_link") {
|
|
146
|
+
const link = ["name", "uri", "description"].map((k) => rec[k]).filter((v) => typeof v === "string" && v !== "");
|
|
147
|
+
if (link.length > 0) parts.push(link.join(" "));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (parts.length > 0) return parts.join("\n");
|
|
151
|
+
return recognised ? "" : null;
|
|
152
|
+
}
|
|
153
|
+
function extractToolResultText(raw) {
|
|
154
|
+
const tr = raw["tool_response"];
|
|
155
|
+
if (typeof tr === "string") return tr;
|
|
156
|
+
if (!tr || typeof tr !== "object") return "";
|
|
157
|
+
const bare = blocksToText(tr);
|
|
158
|
+
if (bare !== null) return bare;
|
|
159
|
+
const resp = tr;
|
|
160
|
+
const content = resp["content"];
|
|
161
|
+
const joined = blocksToText(content);
|
|
162
|
+
if (joined !== null) return joined;
|
|
163
|
+
for (const key of ["output", "text", "body"]) {
|
|
164
|
+
if (typeof resp[key] === "string") return resp[key];
|
|
165
|
+
}
|
|
166
|
+
if (typeof content === "string") return content;
|
|
167
|
+
try {
|
|
168
|
+
return JSON.stringify(resp);
|
|
169
|
+
} catch {
|
|
170
|
+
return "";
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function asContentBlocks(value) {
|
|
174
|
+
if (!Array.isArray(value)) return null;
|
|
175
|
+
const blocks = value.filter((b) => b !== null && typeof b === "object");
|
|
176
|
+
const typed = blocks.some((b) => typeof b["type"] === "string" && MCP_CONTENT_BLOCK_TYPES.has(b["type"]));
|
|
177
|
+
return typed ? blocks : null;
|
|
178
|
+
}
|
|
179
|
+
function mcpContentBlocks(raw) {
|
|
180
|
+
const tr = raw["tool_response"];
|
|
181
|
+
if (tr === null || typeof tr !== "object") return null;
|
|
182
|
+
return asContentBlocks(tr) ?? asContentBlocks(tr["content"]);
|
|
183
|
+
}
|
|
184
|
+
function isTextualContentBlock(block) {
|
|
185
|
+
if (block === null || typeof block !== "object") return false;
|
|
186
|
+
const rec = block;
|
|
187
|
+
if (typeof rec["text"] === "string") return true;
|
|
188
|
+
if (rec["type"] === "resource_link") return true;
|
|
189
|
+
const resource = rec["resource"];
|
|
190
|
+
return resource !== null && typeof resource === "object" && typeof resource["text"] === "string";
|
|
191
|
+
}
|
|
192
|
+
function withPreservedBlocks(output, blocks) {
|
|
193
|
+
if (output.hookType !== "rewriteOutput" || blocks.length === 0) return output;
|
|
194
|
+
return { ...output, updatedBlocks: [{ type: "text", text: output.updatedOutput }, ...blocks] };
|
|
195
|
+
}
|
|
196
|
+
function dropsResultRewrite() {
|
|
197
|
+
return detectHarness() === "vscode";
|
|
198
|
+
}
|
|
199
|
+
function passOutput() {
|
|
200
|
+
return { hookType: "pass" };
|
|
201
|
+
}
|
|
202
|
+
function denyOutput(message) {
|
|
203
|
+
return { hookType: "deny", message: `[tg] ${neutralizeOutsideFences(message)}` };
|
|
204
|
+
}
|
|
205
|
+
function contextOutput(context, correlators) {
|
|
206
|
+
return correlators === void 0 ? { hookType: "context", context } : { hookType: "context", context, correlators };
|
|
207
|
+
}
|
|
208
|
+
function emitRewrite(updatedOutput, detail, savings, redaction = "count-here") {
|
|
209
|
+
if (dropsResultRewrite()) return passOutput();
|
|
210
|
+
if (redaction === "count-here") {
|
|
211
|
+
const count = countRedactionPlaceholders(updatedOutput);
|
|
212
|
+
if (count > 0) recordStat("secret_redacted", 0, count, void 0, detail);
|
|
213
|
+
}
|
|
214
|
+
if (savings !== void 0) {
|
|
215
|
+
const bytesSaved = savings.originalBytes - Buffer.byteLength(updatedOutput, "utf-8");
|
|
216
|
+
const credited = Math.max(0, bytesSaved);
|
|
217
|
+
recordStat(savings.kind, credited, savedTokensFromBytes(credited), void 0, savings.detail);
|
|
218
|
+
}
|
|
219
|
+
return { hookType: "rewriteOutput", updatedOutput };
|
|
220
|
+
}
|
|
221
|
+
function emitRewriteIfChanged(original, emitted, detail) {
|
|
222
|
+
if (emitted === original) return passOutput();
|
|
223
|
+
return emitRewrite(emitted, detail);
|
|
224
|
+
}
|
|
225
|
+
function emitRewriteWithContext(updatedOutput, context, detail, savings) {
|
|
226
|
+
const out = emitRewrite(updatedOutput, detail, { ...savings, originalBytes: savings.originalBytes - Buffer.byteLength(context, "utf-8") });
|
|
227
|
+
return out.hookType === "rewriteOutput" ? { ...out, context } : out;
|
|
228
|
+
}
|
|
229
|
+
function countNonEmptyLines(text) {
|
|
230
|
+
return text.split(/\r\n|\r|\n/).filter((line) => line.length > 0).length;
|
|
231
|
+
}
|
|
232
|
+
function estimateResultCount(text) {
|
|
233
|
+
const firstLine = text.split(/\r\n|\r|\n/).find((line) => line.trim().length > 0);
|
|
234
|
+
if (firstLine !== void 0) {
|
|
235
|
+
const trimmed = firstLine.trim();
|
|
236
|
+
if (/^No (?:files|matches) found\.?$/i.test(trimmed)) return 0;
|
|
237
|
+
const found = /^Found (\d+) (?:files?|matches?)\.?$/i.exec(trimmed);
|
|
238
|
+
if (found) return Number.parseInt(found[1], 10);
|
|
239
|
+
}
|
|
240
|
+
return countNonEmptyLines(text);
|
|
241
|
+
}
|
|
242
|
+
var RESULT_COUNT_KEYS = ["numFiles", "numLines", "numMatches"];
|
|
243
|
+
function structuredResultCount(raw) {
|
|
244
|
+
const response = raw["tool_response"];
|
|
245
|
+
if (response === null || typeof response !== "object") return null;
|
|
246
|
+
const counts = RESULT_COUNT_KEYS.map((k) => response[k]).filter((v) => typeof v === "number");
|
|
247
|
+
return counts.length > 0 ? Math.max(...counts) : null;
|
|
248
|
+
}
|
|
249
|
+
function makeDedupHintHandlers(opts) {
|
|
250
|
+
const post = (event) => {
|
|
251
|
+
try {
|
|
252
|
+
if (getToolName(event) !== opts.toolName) return passOutput();
|
|
253
|
+
const signature = opts.buildSignature(getToolInput(event));
|
|
254
|
+
if (signature === null) return passOutput();
|
|
255
|
+
opts.recordQuery(signature, structuredResultCount(event.raw) ?? estimateResultCount(extractToolResponseField(event.raw, OUTPUT_FIRST_TOOL_RESPONSE_KEYS)));
|
|
256
|
+
return passOutput();
|
|
257
|
+
} catch {
|
|
258
|
+
return passOutput();
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
const pre = (event) => {
|
|
262
|
+
try {
|
|
263
|
+
if (getToolName(event) !== opts.toolName) return passOutput();
|
|
264
|
+
const toolInput = getToolInput(event);
|
|
265
|
+
const signature = opts.buildSignature(toolInput);
|
|
266
|
+
if (signature === null) return passOutput();
|
|
267
|
+
const priorCount = opts.getMatchCount(signature);
|
|
268
|
+
if (priorCount === null) return passOutput();
|
|
269
|
+
if (priorCount < loadConfig().hints[opts.minMatchesConfigKey]) return passOutput();
|
|
270
|
+
recordStat(opts.statName, 0, 0);
|
|
271
|
+
const pattern = displaySafeText(typeof toolInput["pattern"] === "string" ? toolInput["pattern"] : "");
|
|
272
|
+
return contextOutput(
|
|
273
|
+
"Note: an identical " + opts.toolName + " for " + echoedValue(pattern) + " already ran this session and returned " + priorCount + (priorCount === 1 ? " match" : " matches") + ". If that result already answers this, you can skip re-running it."
|
|
274
|
+
);
|
|
275
|
+
} catch {
|
|
276
|
+
return passOutput();
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
return { post, pre };
|
|
280
|
+
}
|
|
281
|
+
|
|
35
282
|
// src/hooks_cli.ts
|
|
36
283
|
init_define_import_meta_env();
|
|
37
284
|
|
|
38
285
|
// src/copilot_mcp_names.ts
|
|
39
286
|
init_define_import_meta_env();
|
|
287
|
+
|
|
288
|
+
// src/copilot_mcp_tools.ts
|
|
289
|
+
init_define_import_meta_env();
|
|
290
|
+
import fs from "node:fs";
|
|
291
|
+
import path2 from "node:path";
|
|
292
|
+
|
|
293
|
+
// src/copilot_home.ts
|
|
294
|
+
init_define_import_meta_env();
|
|
295
|
+
import * as os from "node:os";
|
|
296
|
+
import * as path from "node:path";
|
|
297
|
+
function copilotCliUserRoot(homeDir = os.homedir()) {
|
|
298
|
+
const override = process.env["COPILOT_HOME"];
|
|
299
|
+
if (override !== void 0 && override.trim() !== "") return path.resolve(override);
|
|
300
|
+
return path.join(homeDir, ".copilot");
|
|
301
|
+
}
|
|
302
|
+
function copilotCliCacheRoot() {
|
|
303
|
+
const override = process.env["COPILOT_CACHE_HOME"];
|
|
304
|
+
if (override !== void 0 && override.trim() !== "") return path.resolve(override);
|
|
305
|
+
const home = os.homedir();
|
|
306
|
+
if (process.platform === "darwin") return path.join(home, "Library", "Caches", "copilot");
|
|
307
|
+
if (process.platform === "win32") {
|
|
308
|
+
const local = process.env["LOCALAPPDATA"];
|
|
309
|
+
const base2 = local !== void 0 && local.trim() !== "" ? local : path.join(home, ".cache");
|
|
310
|
+
return path.join(base2, "copilot");
|
|
311
|
+
}
|
|
312
|
+
const xdg = process.env["XDG_CACHE_HOME"];
|
|
313
|
+
const base = xdg !== void 0 && xdg.trim() !== "" ? xdg : path.join(home, ".cache");
|
|
314
|
+
return path.join(base, "copilot");
|
|
315
|
+
}
|
|
316
|
+
function copilotCliMcpToolsDir() {
|
|
317
|
+
return path.join(copilotCliCacheRoot(), "mcp-tools");
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// src/copilot_mcp_tools.ts
|
|
321
|
+
var COPILOT_BUILTIN_MCP_SERVERS = ["github-mcp-server"];
|
|
322
|
+
function readCopilotDisabledMcpServers(userRoot = copilotCliUserRoot()) {
|
|
323
|
+
const disabled = /* @__PURE__ */ new Set();
|
|
324
|
+
const settingsPath = path2.join(userRoot, "settings.json");
|
|
325
|
+
try {
|
|
326
|
+
if (!fs.existsSync(settingsPath)) return disabled;
|
|
327
|
+
const raw = fs.readFileSync(settingsPath, "utf8");
|
|
328
|
+
const parsed = JSON.parse(raw);
|
|
329
|
+
if (typeof parsed !== "object" || parsed === null) return disabled;
|
|
330
|
+
if (parsed["disableBuiltinMcps"] === true) {
|
|
331
|
+
for (const builtin of COPILOT_BUILTIN_MCP_SERVERS) {
|
|
332
|
+
disabled.add(builtin);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
const disabledList = parsed["disabledMcpServers"];
|
|
336
|
+
if (Array.isArray(disabledList)) {
|
|
337
|
+
for (const item of disabledList) {
|
|
338
|
+
if (typeof item === "string" && item.trim() !== "") {
|
|
339
|
+
disabled.add(item.trim());
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
const singleOrList = parsed["disableMcpServer"];
|
|
344
|
+
if (Array.isArray(singleOrList)) {
|
|
345
|
+
for (const item of singleOrList) {
|
|
346
|
+
if (typeof item === "string" && item.trim() !== "") {
|
|
347
|
+
disabled.add(item.trim());
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
} else if (typeof singleOrList === "string" && singleOrList.trim() !== "") {
|
|
351
|
+
disabled.add(singleOrList.trim());
|
|
352
|
+
}
|
|
353
|
+
} catch {
|
|
354
|
+
}
|
|
355
|
+
return disabled;
|
|
356
|
+
}
|
|
357
|
+
function wireShapeLength(tools) {
|
|
358
|
+
const wire = tools.map((tool) => {
|
|
359
|
+
const out = {};
|
|
360
|
+
if (typeof tool.name === "string") out["name"] = tool.name;
|
|
361
|
+
if (typeof tool.description === "string") out["description"] = tool.description;
|
|
362
|
+
if (tool.inputSchema !== void 0) out["inputSchema"] = tool.inputSchema;
|
|
363
|
+
return out;
|
|
364
|
+
});
|
|
365
|
+
return JSON.stringify(wire).length;
|
|
366
|
+
}
|
|
367
|
+
function readCopilotMcpTools(dir = copilotCliMcpToolsDir(), userRoot = copilotCliUserRoot()) {
|
|
368
|
+
let entries;
|
|
369
|
+
try {
|
|
370
|
+
entries = fs.readdirSync(dir);
|
|
371
|
+
} catch {
|
|
372
|
+
return { cacheFound: false, servers: [], disabledServers: [], unreadable: 0 };
|
|
373
|
+
}
|
|
374
|
+
const disabledSet = readCopilotDisabledMcpServers(userRoot);
|
|
375
|
+
const newest = /* @__PURE__ */ new Map();
|
|
376
|
+
let unreadable = 0;
|
|
377
|
+
for (const entry of entries) {
|
|
378
|
+
if (!entry.toLowerCase().endsWith(".json")) continue;
|
|
379
|
+
let parsed;
|
|
380
|
+
try {
|
|
381
|
+
parsed = JSON.parse(fs.readFileSync(path2.join(dir, entry), "utf8"));
|
|
382
|
+
} catch {
|
|
383
|
+
unreadable += 1;
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
if (typeof parsed !== "object" || parsed === null) {
|
|
387
|
+
unreadable += 1;
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
const record = parsed;
|
|
391
|
+
const serverName = typeof record.serverName === "string" ? record.serverName.trim() : "";
|
|
392
|
+
if (serverName === "") {
|
|
393
|
+
unreadable += 1;
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
const tools = Array.isArray(record.tools) ? record.tools : [];
|
|
397
|
+
const updatedAt = typeof record.updatedAt === "string" ? record.updatedAt : "";
|
|
398
|
+
const definitionBytes = wireShapeLength(tools);
|
|
399
|
+
const candidate = {
|
|
400
|
+
serverName,
|
|
401
|
+
toolCount: tools.length,
|
|
402
|
+
definitionBytes,
|
|
403
|
+
estimatedTokens: estimateTokensFromLength(definitionBytes),
|
|
404
|
+
updatedAt,
|
|
405
|
+
// `tools` is an unchecked cast off a JSON array, so every element is treated as untrusted here rather than trusted to match CachedTool.
|
|
406
|
+
toolNames: tools.map((t) => t?.name).filter((n) => typeof n === "string" && n !== "")
|
|
407
|
+
};
|
|
408
|
+
const existing = newest.get(serverName);
|
|
409
|
+
if (existing === void 0 || candidate.updatedAt > existing.updatedAt) newest.set(serverName, candidate);
|
|
410
|
+
}
|
|
411
|
+
const activeCandidates = [];
|
|
412
|
+
const disabledServers = [];
|
|
413
|
+
for (const [name, candidate] of newest.entries()) {
|
|
414
|
+
if (disabledSet.has(name)) {
|
|
415
|
+
disabledServers.push(name);
|
|
416
|
+
} else {
|
|
417
|
+
activeCandidates.push(candidate);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
disabledServers.sort();
|
|
421
|
+
const servers = activeCandidates.sort(
|
|
422
|
+
(a, b) => b.definitionBytes - a.definitionBytes || a.serverName.localeCompare(b.serverName)
|
|
423
|
+
);
|
|
424
|
+
return { cacheFound: true, servers, disabledServers, unreadable };
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
// src/copilot_mcp_names.ts
|
|
40
428
|
var _cached = null;
|
|
41
429
|
function copilotMcpToolNameMap() {
|
|
42
430
|
if (_cached) return _cached;
|
|
@@ -60,6 +448,30 @@ function resetCopilotMcpToolNameCache() {
|
|
|
60
448
|
}
|
|
61
449
|
registerReset(resetCopilotMcpToolNameCache, { perRequest: true });
|
|
62
450
|
|
|
451
|
+
// src/copilot_tool_names.ts
|
|
452
|
+
init_define_import_meta_env();
|
|
453
|
+
var COPILOT_CLI_TOOL_NAME_MAP = {
|
|
454
|
+
bash: "Bash",
|
|
455
|
+
powershell: "Bash",
|
|
456
|
+
read_bash: "BashOutput",
|
|
457
|
+
read_powershell: "BashOutput",
|
|
458
|
+
view: "Read",
|
|
459
|
+
create: "Write",
|
|
460
|
+
edit: "Edit",
|
|
461
|
+
web_fetch: "WebFetch",
|
|
462
|
+
web_search: "WebSearch",
|
|
463
|
+
grep: "Grep",
|
|
464
|
+
glob: "Glob",
|
|
465
|
+
skill: "Skill",
|
|
466
|
+
exit_plan_mode: "ExitPlanMode"
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
// src/tool_name_fold.ts
|
|
470
|
+
init_define_import_meta_env();
|
|
471
|
+
function foldToolName(name) {
|
|
472
|
+
return typeof name === "string" ? name.toLowerCase().replace(/[_-]/g, "") : "";
|
|
473
|
+
}
|
|
474
|
+
|
|
63
475
|
// src/hooks_cli.ts
|
|
64
476
|
var _LOG = {
|
|
65
477
|
warn: (msg, ...args) => console.warn(`[hooks_cli] ${msg}`, ...args),
|
|
@@ -118,7 +530,8 @@ function normalizeToolNameWithMap(toolName, nameMap) {
|
|
|
118
530
|
}
|
|
119
531
|
var COPILOT_CLI_INPUT_KEY_MAP = {
|
|
120
532
|
Read: { path: "file_path" },
|
|
121
|
-
|
|
533
|
+
// CAPTURE: the real Copilot CLI `create` arguments {path, file_text} in a session log (events.jsonl, tool.execution_start, toolName "create"); the `edit` entry below is FORMAT-DERIVED from the tool description in a Copilot CLI 1.0.88 session log.
|
|
534
|
+
Write: { path: "file_path", file_text: "content" },
|
|
122
535
|
Edit: { path: "file_path", old_str: "old_string", new_str: "new_string" },
|
|
123
536
|
BashOutput: { shellId: "bash_id" }
|
|
124
537
|
};
|
|
@@ -151,14 +564,12 @@ var GEMINI_TOOL_NAME_MAP = {
|
|
|
151
564
|
grep_search: "Grep",
|
|
152
565
|
// 'search_file_content' was GREP_TOOL_NAME's value before gemini-cli renamed it to 'grep_search' (confirmed against gemini-cli's current base-declarations.ts, which now defines GREP_TOOL_NAME = 'grep_search'; some of gemini-cli's own docs pages still lag the rename). Kept as a backward-compat entry for older installed gemini-cli versions that still emit the pre-rename name -- not dead/hallucinated, just legacy.
|
|
153
566
|
search_file_content: "Grep",
|
|
154
|
-
// Gemini's real web-search tool is registered as 'google_web_search' (WEB_SEARCH_TOOL_NAME in gemini-cli's tool-names.ts) -- 'web_search' is not a tool name Gemini CLI ever emits, so the old entry here silently never matched a real invocation.
|
|
155
|
-
// Previously mapped to 'WebFetch' as a workaround for GEMINI_PRE_TOOLS/POST_TOOLS (gemini_install.ts) excluding 'WebSearch' -- that made the hook fire under the installer's matcher, but hooks_fetch.ts's preFetchHandler/postFetchHandler require a `url` tool-input key, which a search call never sends (it sends `query`), so every google_web_search call silently no-op'd through WebFetch's handler: no URL policy check ever applied to it (it has no URL to check) and no search-result dedup ever ran. Now mapped to the dedicated 'WebSearch' handler (hooks_websearch.ts), which reads `query` directly; the installer gate above was extended to include 'WebSearch' so the hook stays wired.
|
|
567
|
+
// Gemini's real web-search tool is registered as 'google_web_search' (WEB_SEARCH_TOOL_NAME in gemini-cli's tool-names.ts) -- 'web_search' is not a tool name Gemini CLI ever emits, so the old entry here silently never matched a real invocation. Previously mapped to 'WebFetch' as a workaround for GEMINI_PRE_TOOLS/POST_TOOLS (gemini_install.ts) excluding 'WebSearch' -- that made the hook fire under the installer's matcher, but hooks_fetch.ts's preFetchHandler/postFetchHandler require a `url` tool-input key, which a search call never sends (it sends `query`), so every google_web_search call silently no-op'd through WebFetch's handler: no URL policy check ever applied to it (it has no URL to check) and no search-result dedup ever ran. Now mapped to the dedicated 'WebSearch' handler (hooks_websearch.ts), which reads `query` directly; the installer gate above was extended to include 'WebSearch' so the hook stays wired.
|
|
156
568
|
google_web_search: "WebSearch",
|
|
157
569
|
web_fetch: "WebFetch"
|
|
158
570
|
};
|
|
159
571
|
var GEMINI_INPUT_KEY_MAP = {
|
|
160
|
-
// Gemini's real write_file/replace tool schemas already use 'file_path' (and replace's 'old_string'/'new_string') verbatim -- identical to token-goat's own canonical keys (see getFilePath() in hooks_common.ts, which reads event.toolInput['file_path']) -- confirmed against gemini-cli's own EditToolParams/WriteFileToolParams interfaces. No remap is needed for Write/Edit; the previous entries here actively renamed a key that was already correct (file_path -> path), which would have silently corrupted the path argument on every real Gemini Write/Edit call.
|
|
161
|
-
// 'Read' covers THREE distinct raw Gemini tools (see GEMINI_TOOL_NAME_MAP above), and they do NOT share one schema: read_file already uses 'file_path' verbatim, no remap needed; list_directory uses 'dir_path' (confirmed against gemini-cli's LSToolParams) -- remapped to 'file_path' below, exactly mirroring Grep's existing dir_path->path fix; read_many_files uses 'include' (confirmed against gemini-cli's ReadManyFilesParams), an ARRAY of glob patterns, not a single file path -- there is no single string to remap it to, so it is deliberately left unmapped. getFilePath() (hooks_common.ts) will return undefined for this call, and preReadHandler/postReadHandler already fall back to passOutput() on an undefined path (see preReadHandler's `if (filePath === undefined) return passOutput()`), so a real read_many_files call still succeeds normally; it just doesn't get session-dedup tracking or read-count hints. Accepted limitation, not a bug to force-fit.
|
|
572
|
+
// Gemini's real write_file/replace tool schemas already use 'file_path' (and replace's 'old_string'/'new_string') verbatim -- identical to token-goat's own canonical keys (see getFilePath() in hooks_common.ts, which reads event.toolInput['file_path']) -- confirmed against gemini-cli's own EditToolParams/WriteFileToolParams interfaces. No remap is needed for Write/Edit; the previous entries here actively renamed a key that was already correct (file_path -> path), which would have silently corrupted the path argument on every real Gemini Write/Edit call. 'Read' covers THREE distinct raw Gemini tools (see GEMINI_TOOL_NAME_MAP above), and they do NOT share one schema: read_file already uses 'file_path' verbatim, no remap needed; list_directory uses 'dir_path' (confirmed against gemini-cli's LSToolParams) -- remapped to 'file_path' below, exactly mirroring Grep's existing dir_path->path fix; read_many_files uses 'include' (confirmed against gemini-cli's ReadManyFilesParams), an ARRAY of glob patterns, not a single file path -- there is no single string to remap it to, so it is deliberately left unmapped. getFilePath() (hooks_common.ts) will return undefined for this call, and preReadHandler/postReadHandler already fall back to passOutput() on an undefined path (see preReadHandler's `if (filePath === undefined) return passOutput()`), so a real read_many_files call still succeeds normally; it just doesn't get session-dedup tracking or read-count hints. Accepted limitation, not a bug to force-fit.
|
|
162
573
|
Read: { dir_path: "file_path" },
|
|
163
574
|
// Grep's real tool (grep_search) calls its target-directory argument 'dir_path', which preReadHandler's Grep fallback (event.toolInput['path']) doesn't recognize, so that one remains remapped.
|
|
164
575
|
Grep: { dir_path: "path" }
|
|
@@ -226,7 +637,12 @@ var VSCODE_TOOL_NAME_MAP = {
|
|
|
226
637
|
replace_string_in_file: "Edit",
|
|
227
638
|
insert_edit_into_file: "Edit",
|
|
228
639
|
edit_notebook_file: "NotebookEdit",
|
|
229
|
-
run_in_terminal: "Bash"
|
|
640
|
+
run_in_terminal: "Bash",
|
|
641
|
+
multi_replace_string_in_file: "MultiEdit",
|
|
642
|
+
apply_patch: "Edit",
|
|
643
|
+
fetch_webpage: "WebFetch",
|
|
644
|
+
runSubagent: "Task",
|
|
645
|
+
get_terminal_output: "BashOutput"
|
|
230
646
|
};
|
|
231
647
|
var VSCODE_INPUT_KEY_MAP = {
|
|
232
648
|
read_file: { filePath: "file_path" },
|
|
@@ -238,7 +654,52 @@ var VSCODE_INPUT_KEY_MAP = {
|
|
|
238
654
|
replace_string_in_file: { filePath: "file_path", oldString: "old_string", newString: "new_string" },
|
|
239
655
|
insert_edit_into_file: { filePath: "file_path" },
|
|
240
656
|
edit_notebook_file: { filePath: "notebook_path" },
|
|
241
|
-
run_in_terminal: {}
|
|
657
|
+
run_in_terminal: {},
|
|
658
|
+
multi_replace_string_in_file: {},
|
|
659
|
+
apply_patch: {},
|
|
660
|
+
fetch_webpage: {},
|
|
661
|
+
runSubagent: {},
|
|
662
|
+
get_terminal_output: { id: "bash_id" }
|
|
663
|
+
};
|
|
664
|
+
function derivedPaths(paths) {
|
|
665
|
+
const unique = [...new Set(paths)];
|
|
666
|
+
if (unique.length === 0) return {};
|
|
667
|
+
return unique.length === 1 ? { file_paths: unique, file_path: unique[0] } : { file_paths: unique };
|
|
668
|
+
}
|
|
669
|
+
var PATCH_PATH_HEADERS = ["*** Add File: ", "*** Delete File: ", "*** Update File: ", "*** Move to: "];
|
|
670
|
+
function patchFilePaths(patch) {
|
|
671
|
+
const paths = [];
|
|
672
|
+
for (const line of patch.split(/\r?\n/)) {
|
|
673
|
+
const header = PATCH_PATH_HEADERS.find((h) => line.startsWith(h));
|
|
674
|
+
if (header === void 0) continue;
|
|
675
|
+
const target = line.slice(header.length).trim();
|
|
676
|
+
if (target !== "") paths.push(target);
|
|
677
|
+
}
|
|
678
|
+
return paths;
|
|
679
|
+
}
|
|
680
|
+
var VSCODE_DERIVED_INPUT = {
|
|
681
|
+
multi_replace_string_in_file: (input) => {
|
|
682
|
+
const replacements = Array.isArray(input["replacements"]) ? input["replacements"] : [];
|
|
683
|
+
const paths = [];
|
|
684
|
+
for (const r of replacements) {
|
|
685
|
+
const filePath = r !== null && typeof r === "object" ? r["filePath"] : void 0;
|
|
686
|
+
if (typeof filePath === "string" && filePath !== "") paths.push(filePath);
|
|
687
|
+
}
|
|
688
|
+
return derivedPaths(paths);
|
|
689
|
+
},
|
|
690
|
+
apply_patch: (input) => typeof input["input"] === "string" ? derivedPaths(patchFilePaths(input["input"])) : {},
|
|
691
|
+
fetch_webpage: (input) => {
|
|
692
|
+
const out = {};
|
|
693
|
+
const urls = Array.isArray(input["urls"]) ? input["urls"] : [];
|
|
694
|
+
if (urls.length === 1 && typeof urls[0] === "string" && urls[0] !== "") out["url"] = urls[0];
|
|
695
|
+
if (typeof input["query"] === "string") out["prompt"] = input["query"];
|
|
696
|
+
return out;
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
var VSCODE_DERIVED_KEYS = {
|
|
700
|
+
multi_replace_string_in_file: ["file_paths", "file_path"],
|
|
701
|
+
apply_patch: ["file_paths", "file_path"],
|
|
702
|
+
fetch_webpage: ["url", "prompt"]
|
|
242
703
|
};
|
|
243
704
|
var VSCODE_TOOL_NAME_KEY = "_tg_vscode_tool_name";
|
|
244
705
|
function vscodeNativeToolInput(vscodeToolName, canonicalInput) {
|
|
@@ -246,8 +707,63 @@ function vscodeNativeToolInput(vscodeToolName, canonicalInput) {
|
|
|
246
707
|
for (const [nativeKey, canonicalKey] of Object.entries(ownGet(VSCODE_INPUT_KEY_MAP, vscodeToolName) ?? {})) {
|
|
247
708
|
inverse[canonicalKey] = nativeKey;
|
|
248
709
|
}
|
|
710
|
+
const native = remapInputKeys(canonicalInput, inverse);
|
|
711
|
+
for (const key of ownGet(VSCODE_DERIVED_KEYS, vscodeToolName) ?? []) delete native[key];
|
|
712
|
+
return native;
|
|
713
|
+
}
|
|
714
|
+
var ANTIGRAVITY_TOOL_NAME_MAP = {
|
|
715
|
+
view_file: "Read",
|
|
716
|
+
list_dir: "Read",
|
|
717
|
+
list_directory: "Read",
|
|
718
|
+
run_command: "Bash",
|
|
719
|
+
grep_search: "Grep",
|
|
720
|
+
find_by_name: "Glob",
|
|
721
|
+
find: "Glob",
|
|
722
|
+
replace_file_content: "Edit",
|
|
723
|
+
multi_replace_file_content: "Edit",
|
|
724
|
+
file_change: "Edit",
|
|
725
|
+
write_to_file: "Write",
|
|
726
|
+
search_web: "WebSearch"
|
|
727
|
+
};
|
|
728
|
+
var AGY_EDIT_KEYS = { TargetFile: "file_path", TargetContent: "old_string", ReplacementContent: "new_string" };
|
|
729
|
+
var ANTIGRAVITY_INPUT_KEY_MAP = {
|
|
730
|
+
view_file: { AbsolutePath: "file_path", StartLine: "startLine", EndLine: "endLine" },
|
|
731
|
+
list_dir: { DirectoryPath: "file_path" },
|
|
732
|
+
list_directory: { DirectoryPath: "file_path" },
|
|
733
|
+
run_command: { CommandLine: "command" },
|
|
734
|
+
grep_search: { Query: "pattern", SearchPath: "path" },
|
|
735
|
+
find_by_name: { Pattern: "pattern", SearchDirectory: "path" },
|
|
736
|
+
find: { Pattern: "pattern", SearchDirectory: "path" },
|
|
737
|
+
replace_file_content: AGY_EDIT_KEYS,
|
|
738
|
+
multi_replace_file_content: AGY_EDIT_KEYS,
|
|
739
|
+
file_change: AGY_EDIT_KEYS,
|
|
740
|
+
write_to_file: { TargetFile: "file_path", CodeContent: "content" },
|
|
741
|
+
search_web: {}
|
|
742
|
+
};
|
|
743
|
+
var ANTIGRAVITY_TOOL_NAME_KEY = "_tg_antigravity_tool_name";
|
|
744
|
+
function antigravityNativeToolInput(agyToolName, canonicalInput) {
|
|
745
|
+
const inverse = {};
|
|
746
|
+
for (const [nativeKey, canonicalKey] of Object.entries(ownGet(ANTIGRAVITY_INPUT_KEY_MAP, agyToolName) ?? {})) {
|
|
747
|
+
inverse[canonicalKey] = nativeKey;
|
|
748
|
+
}
|
|
249
749
|
return remapInputKeys(canonicalInput, inverse);
|
|
250
750
|
}
|
|
751
|
+
function antigravityToCanonicalWire(obj) {
|
|
752
|
+
const wire = { ...obj };
|
|
753
|
+
const call = wire["toolCall"];
|
|
754
|
+
if (call !== null && typeof call === "object" && !Array.isArray(call)) {
|
|
755
|
+
const { name, args } = call;
|
|
756
|
+
if (typeof name === "string" && wire["tool_name"] === void 0) wire["tool_name"] = name;
|
|
757
|
+
if (args !== null && typeof args === "object" && !Array.isArray(args) && wire["tool_input"] === void 0) wire["tool_input"] = args;
|
|
758
|
+
}
|
|
759
|
+
if (typeof wire["conversationId"] === "string" && wire["session_id"] === void 0) wire["session_id"] = wire["conversationId"];
|
|
760
|
+
const workspaces = wire["workspacePaths"];
|
|
761
|
+
if (wire["cwd"] === void 0 && Array.isArray(workspaces) && typeof workspaces[0] === "string" && workspaces[0] !== "") wire["cwd"] = workspaces[0];
|
|
762
|
+
if (wire["tool_response"] === void 0 && typeof wire["result"] === "string") {
|
|
763
|
+
wire["tool_response"] = typeof wire["error"] === "string" && wire["error"] !== "" ? { output: wire["result"], error: wire["error"] } : { output: wire["result"] };
|
|
764
|
+
}
|
|
765
|
+
return wire;
|
|
766
|
+
}
|
|
251
767
|
function remapInputKeys(input, keyMap) {
|
|
252
768
|
const newInput = {};
|
|
253
769
|
for (const [k, v] of Object.entries(input)) {
|
|
@@ -305,7 +821,7 @@ function normalizePayload(payload, harness = "claude") {
|
|
|
305
821
|
return {};
|
|
306
822
|
}
|
|
307
823
|
const rawObj = payload;
|
|
308
|
-
const obj = harness === "grok" ? grokToCanonicalWire(rawObj) : rawObj;
|
|
824
|
+
const obj = harness === "grok" ? grokToCanonicalWire(rawObj) : harness === "antigravity" ? antigravityToCanonicalWire(rawObj) : rawObj;
|
|
309
825
|
const toolName = obj["tool_name"];
|
|
310
826
|
if (typeof toolName !== "string" || !toolName.trim()) {
|
|
311
827
|
_LOG.debug("normalizePayload: tool_name missing or invalid; received %s", toolName);
|
|
@@ -322,6 +838,11 @@ function normalizePayload(payload, harness = "claude") {
|
|
|
322
838
|
if (mapped) {
|
|
323
839
|
result2["tool_name"] = mapped;
|
|
324
840
|
}
|
|
841
|
+
const rawInput = obj["tool_input"];
|
|
842
|
+
const patch = toolName === "apply_patch" && typeof rawInput === "object" && rawInput !== null && !Array.isArray(rawInput) ? rawInput["command"] : void 0;
|
|
843
|
+
if (typeof patch === "string") {
|
|
844
|
+
result2["tool_input"] = { ...rawInput, ...derivedPaths(patchFilePaths(patch)) };
|
|
845
|
+
}
|
|
325
846
|
result2["_tg_harness"] = harness;
|
|
326
847
|
return result2;
|
|
327
848
|
}
|
|
@@ -338,12 +859,27 @@ function normalizePayload(payload, harness = "claude") {
|
|
|
338
859
|
const keyMap = ownGet(VSCODE_INPUT_KEY_MAP, toolName) ?? ownGet(VSCODE_INPUT_KEY_MAP, mapped);
|
|
339
860
|
const rawInput = obj["tool_input"];
|
|
340
861
|
if (keyMap && typeof rawInput === "object" && rawInput !== null && !Array.isArray(rawInput)) {
|
|
341
|
-
|
|
862
|
+
const renamed = remapInputKeys(rawInput, keyMap);
|
|
863
|
+
const derive = ownGet(VSCODE_DERIVED_INPUT, toolName);
|
|
864
|
+
result2["tool_input"] = derive === void 0 ? renamed : { ...renamed, ...derive(rawInput) };
|
|
342
865
|
}
|
|
343
866
|
result2[VSCODE_TOOL_NAME_KEY] = toolName;
|
|
344
867
|
result2["_tg_harness"] = harness;
|
|
345
868
|
return result2;
|
|
346
869
|
}
|
|
870
|
+
if (harness === "antigravity") {
|
|
871
|
+
const mapped = normalizeToolNameWithMap(toolName, ANTIGRAVITY_TOOL_NAME_MAP);
|
|
872
|
+
const result2 = { ...obj };
|
|
873
|
+
result2["tool_name"] = mapped;
|
|
874
|
+
const keyMap = ownGet(ANTIGRAVITY_INPUT_KEY_MAP, toolName);
|
|
875
|
+
const rawInput = obj["tool_input"];
|
|
876
|
+
if (keyMap && typeof rawInput === "object" && rawInput !== null && !Array.isArray(rawInput)) {
|
|
877
|
+
result2["tool_input"] = remapInputKeys(rawInput, keyMap);
|
|
878
|
+
}
|
|
879
|
+
result2[ANTIGRAVITY_TOOL_NAME_KEY] = toolName;
|
|
880
|
+
result2["_tg_harness"] = harness;
|
|
881
|
+
return result2;
|
|
882
|
+
}
|
|
347
883
|
if (harness === "kimi") {
|
|
348
884
|
const result2 = remapToolName(obj, toolName, KIMI_TOOL_NAME_MAP, KIMI_INPUT_KEY_MAP);
|
|
349
885
|
result2["_tg_harness"] = harness;
|
|
@@ -374,321 +910,17 @@ function normalizePayload(payload, harness = "claude") {
|
|
|
374
910
|
return result;
|
|
375
911
|
}
|
|
376
912
|
|
|
377
|
-
// src/hint_suggestion_guard.ts
|
|
378
|
-
init_define_import_meta_env();
|
|
379
|
-
function looksLikeSuggestion(slice) {
|
|
380
|
-
return slice.includes('"');
|
|
381
|
-
}
|
|
382
|
-
var SAFE_OUTSIDE_QUOTES = /^[A-Za-z0-9 \t_./=:,@+-]*$/;
|
|
383
|
-
var CONTROL_OR_BIDI = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F\u200E\u200F\u202A-\u202E\u2066-\u2069\u061C\u200B-\u200D\u2028\u2029\uFE00-\uFE0F]|[\u{E0000}-\u{E007F}]/u;
|
|
384
|
-
function suggestionIsUnsafe(slice) {
|
|
385
|
-
if (slice.includes("$") || slice.includes("\n") || slice.includes("\r") || slice.includes("`")) return true;
|
|
386
|
-
if (CONTROL_OR_BIDI.test(slice)) return true;
|
|
387
|
-
const regions = slice.split('"');
|
|
388
|
-
if (regions.length % 2 === 0) return true;
|
|
389
|
-
for (let i = 2; i < regions.length; i += 2) {
|
|
390
|
-
if (!SAFE_OUTSIDE_QUOTES.test(regions[i] ?? "")) return true;
|
|
391
|
-
}
|
|
392
|
-
return false;
|
|
393
|
-
}
|
|
394
|
-
var OMITTED = "token-goat (command omitted: the path contains shell metacharacters)";
|
|
395
|
-
function stripUnsafeSuggestions(text) {
|
|
396
|
-
if (!text.includes("token-goat ")) return text;
|
|
397
|
-
let out = "";
|
|
398
|
-
let at = 0;
|
|
399
|
-
for (; ; ) {
|
|
400
|
-
const start = text.indexOf("token-goat ", at);
|
|
401
|
-
if (start === -1) return out + text.slice(at);
|
|
402
|
-
const lineBreak = text.slice(start).search(/[\r\n]/);
|
|
403
|
-
const line = lineBreak === -1 ? text.slice(start) : text.slice(start, start + lineBreak);
|
|
404
|
-
const firstTick = line.indexOf("`");
|
|
405
|
-
const narrow = firstTick === -1 ? line : line.slice(0, firstTick);
|
|
406
|
-
out += text.slice(at, start);
|
|
407
|
-
if (!looksLikeSuggestion(narrow) || !suggestionIsUnsafe(narrow)) {
|
|
408
|
-
out += narrow;
|
|
409
|
-
at = start + narrow.length;
|
|
410
|
-
continue;
|
|
411
|
-
}
|
|
412
|
-
const lastTick = line.lastIndexOf("`");
|
|
413
|
-
const wide = lastTick === -1 ? line : line.slice(0, lastTick);
|
|
414
|
-
out += OMITTED;
|
|
415
|
-
at = start + wide.length;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
function leadWithCommand(command, purpose = "", reason = "") {
|
|
419
|
-
const tail = reason.trim();
|
|
420
|
-
return "Run `" + command + "`" + (purpose === "" ? "" : " " + purpose) + "." + (tail === "" ? "" : (tail.includes("`") ? "\n" : " ") + tail);
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
// src/hooks_common.ts
|
|
424
|
-
init_define_import_meta_env();
|
|
425
|
-
function getToolName(event) {
|
|
426
|
-
return event.toolName;
|
|
427
|
-
}
|
|
428
|
-
function getToolInput(event) {
|
|
429
|
-
return event.toolInput;
|
|
430
|
-
}
|
|
431
|
-
function getFilePath(event) {
|
|
432
|
-
const value = event.toolInput["file_path"];
|
|
433
|
-
if (typeof value === "string" && value !== "") return value;
|
|
434
|
-
const notebookValue = event.toolInput["notebook_path"];
|
|
435
|
-
return typeof notebookValue === "string" && notebookValue !== "" ? notebookValue : void 0;
|
|
436
|
-
}
|
|
437
|
-
function getCwd(event) {
|
|
438
|
-
const value = event.raw && typeof event.raw === "object" ? event.raw["cwd"] : void 0;
|
|
439
|
-
return typeof value === "string" && value !== "" ? value : void 0;
|
|
440
|
-
}
|
|
441
|
-
function getTranscriptPath(event) {
|
|
442
|
-
const value = event.raw && typeof event.raw === "object" ? event.raw["transcript_path"] : void 0;
|
|
443
|
-
return typeof value === "string" && value !== "" ? value : void 0;
|
|
444
|
-
}
|
|
445
|
-
function extractToolResponseField(raw, keys) {
|
|
446
|
-
const resp = raw["tool_response"];
|
|
447
|
-
if (typeof resp === "string") return resp;
|
|
448
|
-
if (resp !== null && typeof resp === "object") {
|
|
449
|
-
const r = resp;
|
|
450
|
-
const path2 = resolveToolResponseFieldPath(r, keys);
|
|
451
|
-
if (path2 !== null) return readAtPath(r, path2);
|
|
452
|
-
}
|
|
453
|
-
return "";
|
|
454
|
-
}
|
|
455
|
-
var NESTED_TOOL_RESPONSE_PATHS = [["file", "content"]];
|
|
456
|
-
function readAtPath(resp, path2) {
|
|
457
|
-
let cur = resp;
|
|
458
|
-
for (const seg of path2) {
|
|
459
|
-
if (cur === null || typeof cur !== "object") return "";
|
|
460
|
-
cur = cur[seg];
|
|
461
|
-
}
|
|
462
|
-
return typeof cur === "string" ? cur : "";
|
|
463
|
-
}
|
|
464
|
-
function resolveToolResponseFieldPath(resp, keys) {
|
|
465
|
-
for (const key of keys) {
|
|
466
|
-
if (typeof resp[key] === "string" && resp[key] !== "") return [key];
|
|
467
|
-
}
|
|
468
|
-
for (const path2 of NESTED_TOOL_RESPONSE_PATHS) {
|
|
469
|
-
if (readAtPath(resp, path2) !== "") return path2;
|
|
470
|
-
}
|
|
471
|
-
return null;
|
|
472
|
-
}
|
|
473
|
-
function replaceToolResponseField(resp, keys, newText) {
|
|
474
|
-
const path2 = resolveToolResponseFieldPath(resp, keys);
|
|
475
|
-
if (path2 === null) return null;
|
|
476
|
-
const root = { ...resp };
|
|
477
|
-
let cur = root;
|
|
478
|
-
for (let i = 0; i < path2.length - 1; i++) {
|
|
479
|
-
const seg = path2[i];
|
|
480
|
-
const child = cur[seg];
|
|
481
|
-
if (child === null || typeof child !== "object") return null;
|
|
482
|
-
const cloned = { ...child };
|
|
483
|
-
cur[seg] = cloned;
|
|
484
|
-
cur = cloned;
|
|
485
|
-
}
|
|
486
|
-
cur[path2[path2.length - 1]] = newText;
|
|
487
|
-
return root;
|
|
488
|
-
}
|
|
489
|
-
var OUTPUT_FIRST_TOOL_RESPONSE_KEYS = ["output", "content", "text", "body", "stdout", "stderr"];
|
|
490
|
-
var BODY_FIRST_TOOL_RESPONSE_KEYS = ["output", "body", "text", "content", "result"];
|
|
491
|
-
function isMcpErrorResponse(raw) {
|
|
492
|
-
const tr = raw["tool_response"];
|
|
493
|
-
if (!tr || typeof tr !== "object") return false;
|
|
494
|
-
return tr["isError"] === true;
|
|
495
|
-
}
|
|
496
|
-
var MCP_CONTENT_BLOCK_TYPES = /* @__PURE__ */ new Set(["text", "image", "audio", "resource", "resource_link"]);
|
|
497
|
-
function blocksToText(blocks) {
|
|
498
|
-
if (!Array.isArray(blocks)) return null;
|
|
499
|
-
const parts = [];
|
|
500
|
-
let recognised = false;
|
|
501
|
-
for (const block of blocks) {
|
|
502
|
-
if (!block || typeof block !== "object") continue;
|
|
503
|
-
const rec = block;
|
|
504
|
-
const type = rec["type"];
|
|
505
|
-
if (typeof type === "string" && MCP_CONTENT_BLOCK_TYPES.has(type)) recognised = true;
|
|
506
|
-
if (typeof rec["text"] === "string") {
|
|
507
|
-
parts.push(rec["text"]);
|
|
508
|
-
continue;
|
|
509
|
-
}
|
|
510
|
-
const resource = rec["resource"];
|
|
511
|
-
if (resource !== null && typeof resource === "object") {
|
|
512
|
-
const nested = resource["text"];
|
|
513
|
-
if (typeof nested === "string") parts.push(nested);
|
|
514
|
-
continue;
|
|
515
|
-
}
|
|
516
|
-
if (rec["type"] === "resource_link") {
|
|
517
|
-
const link = ["name", "uri", "description"].map((k) => rec[k]).filter((v) => typeof v === "string" && v !== "");
|
|
518
|
-
if (link.length > 0) parts.push(link.join(" "));
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
if (parts.length > 0) return parts.join("\n");
|
|
522
|
-
return recognised ? "" : null;
|
|
523
|
-
}
|
|
524
|
-
function extractToolResultText(raw) {
|
|
525
|
-
const tr = raw["tool_response"];
|
|
526
|
-
if (typeof tr === "string") return tr;
|
|
527
|
-
if (!tr || typeof tr !== "object") return "";
|
|
528
|
-
const bare = blocksToText(tr);
|
|
529
|
-
if (bare !== null) return bare;
|
|
530
|
-
const resp = tr;
|
|
531
|
-
const content = resp["content"];
|
|
532
|
-
const joined = blocksToText(content);
|
|
533
|
-
if (joined !== null) return joined;
|
|
534
|
-
for (const key of ["output", "text", "body"]) {
|
|
535
|
-
if (typeof resp[key] === "string") return resp[key];
|
|
536
|
-
}
|
|
537
|
-
if (typeof content === "string") return content;
|
|
538
|
-
try {
|
|
539
|
-
return JSON.stringify(resp);
|
|
540
|
-
} catch {
|
|
541
|
-
return "";
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
function asContentBlocks(value) {
|
|
545
|
-
if (!Array.isArray(value)) return null;
|
|
546
|
-
const blocks = value.filter((b) => b !== null && typeof b === "object");
|
|
547
|
-
const typed = blocks.some((b) => typeof b["type"] === "string" && MCP_CONTENT_BLOCK_TYPES.has(b["type"]));
|
|
548
|
-
return typed ? blocks : null;
|
|
549
|
-
}
|
|
550
|
-
function mcpContentBlocks(raw) {
|
|
551
|
-
const tr = raw["tool_response"];
|
|
552
|
-
if (tr === null || typeof tr !== "object") return null;
|
|
553
|
-
return asContentBlocks(tr) ?? asContentBlocks(tr["content"]);
|
|
554
|
-
}
|
|
555
|
-
function isTextualContentBlock(block) {
|
|
556
|
-
if (block === null || typeof block !== "object") return false;
|
|
557
|
-
const rec = block;
|
|
558
|
-
if (typeof rec["text"] === "string") return true;
|
|
559
|
-
if (rec["type"] === "resource_link") return true;
|
|
560
|
-
const resource = rec["resource"];
|
|
561
|
-
return resource !== null && typeof resource === "object" && typeof resource["text"] === "string";
|
|
562
|
-
}
|
|
563
|
-
function withPreservedBlocks(output, blocks) {
|
|
564
|
-
if (output.hookType !== "rewriteOutput" || blocks.length === 0) return output;
|
|
565
|
-
return { ...output, updatedBlocks: [{ type: "text", text: output.updatedOutput }, ...blocks] };
|
|
566
|
-
}
|
|
567
|
-
function passOutput() {
|
|
568
|
-
return { hookType: "pass" };
|
|
569
|
-
}
|
|
570
|
-
function denyOutput(message) {
|
|
571
|
-
return { hookType: "deny", message: `[tg] ${neutralizeOutsideFences(message)}` };
|
|
572
|
-
}
|
|
573
|
-
function contextOutput(context, correlators) {
|
|
574
|
-
return correlators === void 0 ? { hookType: "context", context } : { hookType: "context", context, correlators };
|
|
575
|
-
}
|
|
576
|
-
function emitRewrite(updatedOutput, detail, savings, redaction = "count-here") {
|
|
577
|
-
if (detectHarness() === "vscode") return passOutput();
|
|
578
|
-
if (redaction === "count-here") {
|
|
579
|
-
const count = countRedactionPlaceholders(updatedOutput);
|
|
580
|
-
if (count > 0) recordStat("secret_redacted", 0, count, void 0, detail);
|
|
581
|
-
}
|
|
582
|
-
if (savings !== void 0) {
|
|
583
|
-
const bytesSaved = savings.originalBytes - Buffer.byteLength(updatedOutput, "utf-8");
|
|
584
|
-
const credited = Math.max(0, bytesSaved);
|
|
585
|
-
recordStat(savings.kind, credited, savedTokensFromBytes(credited), void 0, savings.detail);
|
|
586
|
-
}
|
|
587
|
-
return { hookType: "rewriteOutput", updatedOutput };
|
|
588
|
-
}
|
|
589
|
-
function emitRewriteIfChanged(original, emitted, detail) {
|
|
590
|
-
if (emitted === original) return passOutput();
|
|
591
|
-
return emitRewrite(emitted, detail);
|
|
592
|
-
}
|
|
593
|
-
function countNonEmptyLines(text) {
|
|
594
|
-
return text.split(/\r\n|\r|\n/).filter((line) => line.length > 0).length;
|
|
595
|
-
}
|
|
596
|
-
function estimateResultCount(text) {
|
|
597
|
-
const firstLine = text.split(/\r\n|\r|\n/).find((line) => line.trim().length > 0);
|
|
598
|
-
if (firstLine !== void 0) {
|
|
599
|
-
const trimmed = firstLine.trim();
|
|
600
|
-
if (/^No (?:files|matches) found\.?$/i.test(trimmed)) return 0;
|
|
601
|
-
const found = /^Found (\d+) (?:files?|matches?)\.?$/i.exec(trimmed);
|
|
602
|
-
if (found) return Number.parseInt(found[1], 10);
|
|
603
|
-
}
|
|
604
|
-
return countNonEmptyLines(text);
|
|
605
|
-
}
|
|
606
|
-
var RESULT_COUNT_KEYS = ["numFiles", "numLines", "numMatches"];
|
|
607
|
-
function structuredResultCount(raw) {
|
|
608
|
-
const response = raw["tool_response"];
|
|
609
|
-
if (response === null || typeof response !== "object") return null;
|
|
610
|
-
const counts = RESULT_COUNT_KEYS.map((k) => response[k]).filter((v) => typeof v === "number");
|
|
611
|
-
return counts.length > 0 ? Math.max(...counts) : null;
|
|
612
|
-
}
|
|
613
|
-
function makeDedupHintHandlers(opts) {
|
|
614
|
-
const post = (event) => {
|
|
615
|
-
try {
|
|
616
|
-
if (getToolName(event) !== opts.toolName) return passOutput();
|
|
617
|
-
const signature = opts.buildSignature(getToolInput(event));
|
|
618
|
-
if (signature === null) return passOutput();
|
|
619
|
-
opts.recordQuery(signature, structuredResultCount(event.raw) ?? estimateResultCount(extractToolResponseField(event.raw, OUTPUT_FIRST_TOOL_RESPONSE_KEYS)));
|
|
620
|
-
return passOutput();
|
|
621
|
-
} catch {
|
|
622
|
-
return passOutput();
|
|
623
|
-
}
|
|
624
|
-
};
|
|
625
|
-
const pre = (event) => {
|
|
626
|
-
try {
|
|
627
|
-
if (getToolName(event) !== opts.toolName) return passOutput();
|
|
628
|
-
const toolInput = getToolInput(event);
|
|
629
|
-
const signature = opts.buildSignature(toolInput);
|
|
630
|
-
if (signature === null) return passOutput();
|
|
631
|
-
const priorCount = opts.getMatchCount(signature);
|
|
632
|
-
if (priorCount === null) return passOutput();
|
|
633
|
-
if (priorCount < loadConfig().hints[opts.minMatchesConfigKey]) return passOutput();
|
|
634
|
-
recordStat(opts.statName, 0, 0);
|
|
635
|
-
const pattern = displaySafeText(typeof toolInput["pattern"] === "string" ? toolInput["pattern"] : "");
|
|
636
|
-
return contextOutput(
|
|
637
|
-
"Note: an identical " + opts.toolName + ' for "' + pattern + '" already ran this session and returned ' + priorCount + (priorCount === 1 ? " match" : " matches") + ". If that result already answers this, you can skip re-running it."
|
|
638
|
-
);
|
|
639
|
-
} catch {
|
|
640
|
-
return passOutput();
|
|
641
|
-
}
|
|
642
|
-
};
|
|
643
|
-
return { post, pre };
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
// src/vscode_path_gate.ts
|
|
647
|
-
init_define_import_meta_env();
|
|
648
|
-
import * as path from "node:path";
|
|
649
|
-
function resolvesToUncPath(target, cwd) {
|
|
650
|
-
try {
|
|
651
|
-
return isUncOrDevicePath(path.resolve(cwd ?? process.cwd(), target));
|
|
652
|
-
} catch {
|
|
653
|
-
return false;
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
function vscodePathAllowed(filePath, workspace) {
|
|
657
|
-
if (isUncOrDevicePath(filePath)) return false;
|
|
658
|
-
if (workspace === void 0 || isUncOrDevicePath(workspace)) return false;
|
|
659
|
-
const resolvedRoot = path.resolve(workspace);
|
|
660
|
-
const resolvedTarget = path.resolve(workspace, filePath);
|
|
661
|
-
const root = foldPathForContainment(resolvedRoot.replace(/\\/g, "/"));
|
|
662
|
-
const target = foldPathForContainment(resolvedTarget.replace(/\\/g, "/"));
|
|
663
|
-
if (target !== root && !target.startsWith(root.endsWith("/") ? root : root + "/")) return false;
|
|
664
|
-
return isInsideRoot(resolvedTarget, resolvedRoot);
|
|
665
|
-
}
|
|
666
|
-
function isVscodeEvent(event) {
|
|
667
|
-
return event.raw["_tg_harness"] === "vscode" || event.raw[VSCODE_TOOL_NAME_KEY] !== void 0;
|
|
668
|
-
}
|
|
669
|
-
function preToolPathDeclined(event, target) {
|
|
670
|
-
if (target === void 0) return false;
|
|
671
|
-
const cwd = getCwd(event);
|
|
672
|
-
if (isUncOrDevicePath(target) || resolvesToUncPath(target, cwd)) return true;
|
|
673
|
-
if (isVscodeEvent(event)) return !vscodePathAllowed(target, cwd);
|
|
674
|
-
return escapesOntoNetworkThroughLinks(target, cwd);
|
|
675
|
-
}
|
|
676
|
-
function commandPathIsTouchable(filePath, event) {
|
|
677
|
-
if (event === void 0) return !escapesOntoNetworkThroughLinks(filePath);
|
|
678
|
-
return !preToolPathDeclined(event, filePath);
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
// src/delivering_deny.ts
|
|
682
|
-
init_define_import_meta_env();
|
|
683
|
-
var DELIVERS_CONTENT_RE = /is inlined below instead of the full body|headings below instead of the full body|in place of the full file/;
|
|
684
|
-
|
|
685
913
|
export {
|
|
914
|
+
foldToolName,
|
|
686
915
|
getToolName,
|
|
687
916
|
getToolInput,
|
|
688
917
|
getFilePath,
|
|
918
|
+
resolveEventPath,
|
|
919
|
+
getFilePaths,
|
|
689
920
|
getCwd,
|
|
690
921
|
getTranscriptPath,
|
|
691
922
|
extractToolResponseField,
|
|
923
|
+
resolveToolResponseFieldPath,
|
|
692
924
|
replaceToolResponseField,
|
|
693
925
|
OUTPUT_FIRST_TOOL_RESPONSE_KEYS,
|
|
694
926
|
BODY_FIRST_TOOL_RESPONSE_KEYS,
|
|
@@ -697,22 +929,24 @@ export {
|
|
|
697
929
|
mcpContentBlocks,
|
|
698
930
|
isTextualContentBlock,
|
|
699
931
|
withPreservedBlocks,
|
|
932
|
+
dropsResultRewrite,
|
|
700
933
|
passOutput,
|
|
701
934
|
denyOutput,
|
|
702
935
|
contextOutput,
|
|
703
936
|
emitRewrite,
|
|
704
937
|
emitRewriteIfChanged,
|
|
938
|
+
emitRewriteWithContext,
|
|
705
939
|
estimateResultCount,
|
|
706
940
|
structuredResultCount,
|
|
707
941
|
makeDedupHintHandlers,
|
|
942
|
+
copilotCliUserRoot,
|
|
943
|
+
copilotCliMcpToolsDir,
|
|
944
|
+
readCopilotMcpTools,
|
|
945
|
+
COPILOT_CLI_TOOL_NAME_MAP,
|
|
708
946
|
GEMINI_TOOL_NAME_MAP,
|
|
709
947
|
VSCODE_TOOL_NAME_KEY,
|
|
710
948
|
vscodeNativeToolInput,
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
commandPathIsTouchable,
|
|
715
|
-
stripUnsafeSuggestions,
|
|
716
|
-
leadWithCommand,
|
|
717
|
-
DELIVERS_CONTENT_RE
|
|
949
|
+
ANTIGRAVITY_TOOL_NAME_KEY,
|
|
950
|
+
antigravityNativeToolInput,
|
|
951
|
+
normalizePayload
|
|
718
952
|
};
|