token-goat 2.9.30 → 2.9.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -7
- package/SECURITY.md +10 -2
- package/THIRD_PARTY_NOTICES.md +1 -1
- 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/{token-goat-chunk-QSBRTGM2.mjs → token-goat-chunk-25TRAWET.mjs} +17 -7
- package/dist/token-goat-chunk-2KXO6V2B.mjs +203 -0
- package/dist/{token-goat-chunk-IVKIZWAB.mjs → token-goat-chunk-2M7E4PF7.mjs} +41 -12
- package/dist/{token-goat-chunk-SMVRN2HU.mjs → token-goat-chunk-2UPZGKKY.mjs} +2 -2
- 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-KWPNJBDH.mjs → token-goat-chunk-4GILLLWY.mjs} +7 -4
- package/dist/{token-goat-chunk-67TQJ76B.mjs → token-goat-chunk-4NAPX7BA.mjs} +36 -3
- package/dist/{token-goat-chunk-PU7V3FD6.mjs → token-goat-chunk-4SC7UJYV.mjs} +3354 -2553
- package/dist/token-goat-chunk-4SMRO4TO.mjs +366 -0
- package/dist/{token-goat-chunk-AFLYLHDH.mjs → token-goat-chunk-4ZBFWLXF.mjs} +283 -427
- package/dist/{token-goat-chunk-JDWCRD6M.mjs → token-goat-chunk-57BIAXJL.mjs} +73 -40
- package/dist/token-goat-chunk-5AC66HNP.mjs +115 -0
- package/dist/token-goat-chunk-5IMLKSOP.mjs +145 -0
- package/dist/token-goat-chunk-646E6U44.mjs +398 -0
- package/dist/token-goat-chunk-65N4RHP4.mjs +33 -0
- package/dist/{token-goat-chunk-JN4XMLSD.mjs → token-goat-chunk-6DG6HWP3.mjs} +8 -2
- package/dist/token-goat-chunk-6ENQSNRZ.mjs +573 -0
- package/dist/token-goat-chunk-6ZY4GNF2.mjs +91 -0
- package/dist/{token-goat-chunk-VPBBTSJR.mjs → token-goat-chunk-76FGDLRO.mjs} +262 -255
- package/dist/{token-goat-chunk-7IN2MKDS.mjs → token-goat-chunk-7EZTZOMC.mjs} +121 -289
- package/dist/{token-goat-chunk-OJBNYTJP.mjs → token-goat-chunk-7MAOA6X4.mjs} +640 -80
- package/dist/token-goat-chunk-7R2ZVVAX.mjs +218 -0
- package/dist/{token-goat-chunk-PD5VKH46.mjs → token-goat-chunk-AUNGYYQX.mjs} +2 -2
- package/dist/{token-goat-chunk-HG45AF2B.mjs → token-goat-chunk-AUQYRMMH.mjs} +794 -37
- package/dist/token-goat-chunk-B3PEKBYG.mjs +128 -0
- package/dist/{token-goat-chunk-A3CK6N5Z.mjs → token-goat-chunk-BA4HI6BW.mjs} +1309 -110
- package/dist/{token-goat-chunk-JB6QN6VF.mjs → token-goat-chunk-BFCWY73P.mjs} +59 -23
- package/dist/{token-goat-chunk-B45VMIIH.mjs → token-goat-chunk-BWGFUZZE.mjs} +7 -5
- package/dist/{token-goat-chunk-P4QMM4WK.mjs → token-goat-chunk-C75NA7PL.mjs} +50 -23
- package/dist/token-goat-chunk-CBIQ7WTD.mjs +87 -0
- package/dist/token-goat-chunk-CETM74KC.mjs +307 -0
- package/dist/{token-goat-chunk-H2PHHGM5.mjs → token-goat-chunk-CIMQ2BB3.mjs} +57 -12
- package/dist/{token-goat-chunk-N2NMER56.mjs → token-goat-chunk-CJLS3CDL.mjs} +46 -4
- package/dist/{token-goat-chunk-VES7EL7O.mjs → token-goat-chunk-CO3UYX6G.mjs} +1 -1
- package/dist/token-goat-chunk-COPNXRJM.mjs +154 -0
- package/dist/token-goat-chunk-CSJ5L3NL.mjs +479 -0
- package/dist/{token-goat-chunk-4LCCNRTG.mjs → token-goat-chunk-CVCEVUGK.mjs} +8 -6
- package/dist/{token-goat-chunk-B2RZZCSS.mjs → token-goat-chunk-CXHOFN7R.mjs} +37 -20
- package/dist/token-goat-chunk-D735C4QM.mjs +603 -0
- package/dist/{token-goat-chunk-APGZXSPS.mjs → token-goat-chunk-DGS2LVNA.mjs} +47 -30
- package/dist/{token-goat-chunk-54K3EUV3.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-5BCIJXMO.mjs → token-goat-chunk-EELTBKDM.mjs} +14 -10
- package/dist/{token-goat-chunk-W3QCJS6G.mjs → token-goat-chunk-F4HYL64R.mjs} +8 -6
- package/dist/token-goat-chunk-F6PAUIEK.mjs +624 -0
- package/dist/token-goat-chunk-FDSREWLX.mjs +692 -0
- package/dist/token-goat-chunk-GGGG7RWB.mjs +236 -0
- package/dist/{token-goat-chunk-C63JQV5K.mjs → token-goat-chunk-GL3ETKSC.mjs} +233 -15
- package/dist/token-goat-chunk-GVB2MUST.mjs +1298 -0
- package/dist/token-goat-chunk-GWFLAUMQ.mjs +307 -0
- package/dist/{token-goat-chunk-ZEJVMUQH.mjs → token-goat-chunk-HLPW63A7.mjs} +2 -2
- package/dist/{token-goat-chunk-GOLEOXZP.mjs → token-goat-chunk-HU4TORC5.mjs} +44 -26
- package/dist/{token-goat-chunk-Z57YODA2.mjs → token-goat-chunk-I7VKZZAW.mjs} +2 -2
- package/dist/{token-goat-chunk-NYKZLXMK.mjs → token-goat-chunk-IA6XSPE3.mjs} +6 -6
- package/dist/{token-goat-chunk-E3OQX2XT.mjs → token-goat-chunk-IAGXMHIK.mjs} +81 -42
- package/dist/{token-goat-chunk-HYBFA5X3.mjs → token-goat-chunk-IK2DRMFX.mjs} +24 -68
- package/dist/{token-goat-chunk-COBQGL5S.mjs → token-goat-chunk-INNPTRUX.mjs} +249 -299
- package/dist/{token-goat-chunk-7NADEDKJ.mjs → token-goat-chunk-JJ5BX4F4.mjs} +6 -1
- package/dist/{token-goat-chunk-PEPTHRFF.mjs → token-goat-chunk-JVFSHVFJ.mjs} +6 -6
- package/dist/token-goat-chunk-KGEFFSHD.mjs +50 -0
- package/dist/token-goat-chunk-KQBLRPBN.mjs +433 -0
- package/dist/{token-goat-chunk-Q5VTGRH7.mjs → token-goat-chunk-LCNQ2CNN.mjs} +55 -319
- 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-T4FK7VOV.mjs → token-goat-chunk-MHX7XCC3.mjs} +2 -1
- package/dist/token-goat-chunk-N5LSOVSU.mjs +137 -0
- package/dist/{token-goat-chunk-LOBGHXPB.mjs → token-goat-chunk-N5MMR2IW.mjs} +1 -1
- package/dist/token-goat-chunk-N7B3JQ2C.mjs +160 -0
- package/dist/{token-goat-chunk-RHXKCZX3.mjs → token-goat-chunk-NISNMD7T.mjs} +2182 -2959
- package/dist/token-goat-chunk-NMD42SFQ.mjs +434 -0
- package/dist/token-goat-chunk-NOSS5VWY.mjs +174 -0
- package/dist/{token-goat-chunk-KQNZDCBD.mjs → token-goat-chunk-NSNSPPBG.mjs} +25 -3
- package/dist/token-goat-chunk-OBOFIHKN.mjs +38 -0
- package/dist/token-goat-chunk-OBRFJ5O5.mjs +76 -0
- package/dist/{token-goat-chunk-JTQQGXZH.mjs → token-goat-chunk-ODBT2USM.mjs} +124 -57
- 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-DZX2YDPT.mjs → token-goat-chunk-OYIYKDDT.mjs} +2 -2
- package/dist/{token-goat-chunk-QCLDAQTS.mjs → token-goat-chunk-P6HQSWQ3.mjs} +50 -53
- package/dist/token-goat-chunk-P6VGNTQT.mjs +71 -0
- package/dist/{token-goat-chunk-7BXSNBY5.mjs → token-goat-chunk-PFWIMH2E.mjs} +23 -15
- package/dist/token-goat-chunk-PJZXIS3G.mjs +39 -0
- package/dist/token-goat-chunk-PUO5INXP.mjs +606 -0
- package/dist/{token-goat-chunk-GFBSN7BD.mjs → token-goat-chunk-PX5PQWTY.mjs} +22 -250
- package/dist/token-goat-chunk-Q5QDBC6O.mjs +111 -0
- package/dist/token-goat-chunk-QFNQXSDT.mjs +40 -0
- package/dist/{token-goat-chunk-FBNQNSJK.mjs → token-goat-chunk-QH7YVYOY.mjs} +2198 -2782
- package/dist/{token-goat-chunk-64FBPDTK.mjs → token-goat-chunk-QLMUHEPB.mjs} +12 -9
- package/dist/{token-goat-chunk-RZRTDST7.mjs → token-goat-chunk-QQOJIHL3.mjs} +37 -11
- package/dist/{token-goat-chunk-XKI4SEMX.mjs → token-goat-chunk-QQTWJY2O.mjs} +19 -0
- package/dist/{token-goat-chunk-U4N3BN2W.mjs → token-goat-chunk-QYHO5CPH.mjs} +3 -2
- package/dist/token-goat-chunk-RELAVWAD.mjs +27 -0
- package/dist/{token-goat-chunk-ETBHVDB6.mjs → token-goat-chunk-RSLPOBKQ.mjs} +22 -11
- package/dist/token-goat-chunk-SAMFDIS2.mjs +712 -0
- package/dist/token-goat-chunk-SDELXLDM.mjs +48 -0
- package/dist/{token-goat-chunk-4JJS54TR.mjs → token-goat-chunk-SOAFZNNZ.mjs} +161 -38
- package/dist/{token-goat-chunk-664RTTUV.mjs → token-goat-chunk-SRTHT7KV.mjs} +21 -16
- package/dist/{token-goat-chunk-4FVIAHSI.mjs → token-goat-chunk-T5P5ACNQ.mjs} +7 -6
- package/dist/token-goat-chunk-T5YGG4V3.mjs +45 -0
- package/dist/token-goat-chunk-TAUZ4OFS.mjs +110 -0
- package/dist/{token-goat-chunk-COTXZHTS.mjs → token-goat-chunk-TM6MC754.mjs} +4 -3
- package/dist/token-goat-chunk-TWUKBOMP.mjs +72 -0
- package/dist/{token-goat-chunk-3CHUNJ2O.mjs → token-goat-chunk-U2KSB4SG.mjs} +8 -5
- package/dist/{token-goat-chunk-3Z5S4KGM.mjs → token-goat-chunk-U4WHMG6Y.mjs} +29 -49
- package/dist/{token-goat-chunk-PY533T7F.mjs → token-goat-chunk-UGJHGR5A.mjs} +21 -15
- package/dist/{token-goat-chunk-CYCEYAEO.mjs → token-goat-chunk-UOUDVA5U.mjs} +1 -1
- package/dist/{token-goat-chunk-JDHE26RP.mjs → token-goat-chunk-URRJ33GR.mjs} +16 -5
- package/dist/{token-goat-chunk-56EIMS3E.mjs → token-goat-chunk-UZOROKIS.mjs} +23 -17
- package/dist/{token-goat-chunk-CZ3LUXYZ.mjs → token-goat-chunk-VIHGGGEI.mjs} +427 -308
- package/dist/token-goat-chunk-VTJLAA7P.mjs +21 -0
- package/dist/token-goat-chunk-VWDXLT4F.mjs +678 -0
- package/dist/{token-goat-chunk-YARZFCZS.mjs → token-goat-chunk-VWZA2H4P.mjs} +62 -53
- package/dist/{token-goat-chunk-SQSSNQPE.mjs → token-goat-chunk-VXEXMJDL.mjs} +3979 -4745
- package/dist/token-goat-chunk-WBA5SKT4.mjs +547 -0
- package/dist/{token-goat-chunk-SJHWVNDQ.mjs → token-goat-chunk-WDH44VAU.mjs} +7 -4
- package/dist/token-goat-chunk-X2SUP3EI.mjs +107 -0
- package/dist/token-goat-chunk-X3BELZSJ.mjs +125 -0
- package/dist/{token-goat-chunk-FZ3NEW5O.mjs → token-goat-chunk-XLRBNZCC.mjs} +13 -8
- package/dist/{token-goat-chunk-Z44YO3QZ.mjs → token-goat-chunk-XRKUX6CM.mjs} +1 -1
- package/dist/token-goat-chunk-XX6O25RN.mjs +82 -0
- package/dist/token-goat-chunk-XZSUHBVS.mjs +65 -0
- package/dist/{token-goat-chunk-WY3L4DVT.mjs → token-goat-chunk-Y2ZTQOCL.mjs} +13 -8
- package/dist/{token-goat-chunk-UQ5UK2T7.mjs → token-goat-chunk-YB4VMGK2.mjs} +1 -1
- package/dist/token-goat-chunk-YBIIY3HR.mjs +51 -0
- package/dist/{token-goat-chunk-ZQSJMO2R.mjs → token-goat-chunk-YHVDKQBR.mjs} +105 -105
- package/dist/{token-goat-chunk-H2K3QP6H.mjs → token-goat-chunk-YJB5XLWI.mjs} +8 -6
- package/dist/{token-goat-chunk-ZCDTCVIS.mjs → token-goat-chunk-YKB6AQG3.mjs} +5 -2
- package/dist/token-goat-chunk-YMTG2YA5.mjs +35 -0
- package/dist/token-goat-chunk-YPBZYQRV.mjs +40 -0
- package/dist/{token-goat-chunk-HOJLCGDP.mjs → token-goat-chunk-YY6AVUFL.mjs} +2033 -2251
- package/dist/token-goat-chunk-Z7N5OMMP.mjs +98 -0
- package/dist/token-goat-chunk-ZNMNUPAZ.mjs +938 -0
- package/dist/token-goat-hook-client.cjs +1 -1
- package/dist/token-goat-hook-client.mjs +3 -3
- package/dist/token-goat-hook.mjs +67 -38
- package/dist/token-goat.core.mjs +4 -4
- package/docs/C4_RUNTIME_ARCHITECTURE.md +1 -1
- package/docs/cli.md +40 -21
- package/docs/install.md +19 -9
- package/docs/security.md +5 -3
- package/package.json +2 -1
- package/dist/token-goat-chunk-5KDMCMF2.mjs +0 -362
- package/dist/token-goat-chunk-6QMAS7AB.mjs +0 -42
- package/dist/token-goat-chunk-7F2UBPD3.mjs +0 -397
- package/dist/token-goat-chunk-ARDNEC2U.mjs +0 -248
- package/dist/token-goat-chunk-ATCPY7EQ.mjs +0 -134
- package/dist/token-goat-chunk-EFHMMIGP.mjs +0 -68
- package/dist/token-goat-chunk-IVALLT3S.mjs +0 -48
- package/dist/token-goat-chunk-JDU3EXSU.mjs +0 -65
- package/dist/token-goat-chunk-MKPF4CL5.mjs +0 -37
- package/dist/token-goat-chunk-RC35RBUL.mjs +0 -312
- package/dist/token-goat-chunk-USILZ3T3.mjs +0 -53
- package/dist/token-goat-chunk-VL3YIFHZ.mjs +0 -2975
- package/dist/token-goat-chunk-XU4P6Z24.mjs +0 -133
- package/dist/token-goat-chunk-Y776AENC.mjs +0 -1597
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
|
-
const require = __cjsRequire(import.meta.url);
|
|
3
|
-
import {
|
|
4
|
-
VSCODE_TOOL_NAME_KEY,
|
|
5
|
-
getCwd
|
|
6
|
-
} from "./token-goat-chunk-VPBBTSJR.mjs";
|
|
7
|
-
import {
|
|
8
|
-
escapesOntoNetworkThroughLinks,
|
|
9
|
-
foldPathForContainment,
|
|
10
|
-
isInsideRoot
|
|
11
|
-
} from "./token-goat-chunk-AM5V6GSX.mjs";
|
|
12
|
-
import {
|
|
13
|
-
isUncOrDevicePath,
|
|
14
|
-
resolveIndexPath,
|
|
15
|
-
wslMountOfIndexKey
|
|
16
|
-
} from "./token-goat-chunk-FNFBKLRD.mjs";
|
|
17
|
-
import {
|
|
18
|
-
init_define_import_meta_env
|
|
19
|
-
} from "./token-goat-chunk-A37V4PBF.mjs";
|
|
20
|
-
|
|
21
|
-
// src/hint_suggestion_guard.ts
|
|
22
|
-
init_define_import_meta_env();
|
|
23
|
-
function looksLikeSuggestion(slice) {
|
|
24
|
-
return slice.includes('"');
|
|
25
|
-
}
|
|
26
|
-
var SAFE_OUTSIDE_QUOTES = /^[A-Za-z0-9 \t_./=:,@+-]*$/;
|
|
27
|
-
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;
|
|
28
|
-
function suggestionIsUnsafe(slice) {
|
|
29
|
-
if (slice.includes("$") || slice.includes("\n") || slice.includes("\r") || slice.includes("`")) return true;
|
|
30
|
-
if (CONTROL_OR_BIDI.test(slice)) return true;
|
|
31
|
-
const regions = slice.split('"');
|
|
32
|
-
if (regions.length % 2 === 0) return true;
|
|
33
|
-
for (let i = 2; i < regions.length; i += 2) {
|
|
34
|
-
if (!SAFE_OUTSIDE_QUOTES.test(regions[i] ?? "")) return true;
|
|
35
|
-
}
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
var OMITTED = "token-goat (command omitted: the path contains shell metacharacters)";
|
|
39
|
-
function stripUnsafeSuggestions(text) {
|
|
40
|
-
if (!text.includes("token-goat ")) return text;
|
|
41
|
-
let out = "";
|
|
42
|
-
let at = 0;
|
|
43
|
-
for (; ; ) {
|
|
44
|
-
const start = text.indexOf("token-goat ", at);
|
|
45
|
-
if (start === -1) return out + text.slice(at);
|
|
46
|
-
const lineBreak = text.slice(start).search(/[\r\n]/);
|
|
47
|
-
const line = lineBreak === -1 ? text.slice(start) : text.slice(start, start + lineBreak);
|
|
48
|
-
const firstTick = line.indexOf("`");
|
|
49
|
-
const narrow = firstTick === -1 ? line : line.slice(0, firstTick);
|
|
50
|
-
out += text.slice(at, start);
|
|
51
|
-
if (!looksLikeSuggestion(narrow) || !suggestionIsUnsafe(narrow)) {
|
|
52
|
-
out += narrow;
|
|
53
|
-
at = start + narrow.length;
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
const lastTick = line.lastIndexOf("`");
|
|
57
|
-
const wide = lastTick === -1 ? line : line.slice(0, lastTick);
|
|
58
|
-
out += OMITTED;
|
|
59
|
-
at = start + wide.length;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
function leadWithCommand(command, purpose = "", reason = "") {
|
|
63
|
-
const tail = reason.trim();
|
|
64
|
-
return "Run `" + command + "`" + (purpose === "" ? "" : " " + purpose) + "." + (tail === "" ? "" : (tail.includes("`") ? "\n" : " ") + tail);
|
|
65
|
-
}
|
|
66
|
-
function docNavigation(filePath) {
|
|
67
|
-
const ext = /\.(txt|rst)$/i.exec(filePath)?.[1]?.toLowerCase();
|
|
68
|
-
return { section: ext !== "txt", outline: ext === void 0 };
|
|
69
|
-
}
|
|
70
|
-
function grepLinesHint(pattern, shownPath, reason = "") {
|
|
71
|
-
return leadWithCommand('token-goat grep "' + pattern + '" "' + shownPath + '" -C 3', "to read the matching lines", reason);
|
|
72
|
-
}
|
|
73
|
-
function docSectionHint(shownPath, heading, reason = "") {
|
|
74
|
-
const nav = docNavigation(shownPath);
|
|
75
|
-
if (!nav.section) return grepLinesHint("<pattern>", shownPath, reason);
|
|
76
|
-
return leadWithCommand('token-goat section "' + shownPath + "::" + heading + '"', "to read one section" + (nav.outline ? ', or `token-goat outline "' + shownPath + '"` for every heading with line ranges' : ""), reason);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// src/vscode_path_gate.ts
|
|
80
|
-
init_define_import_meta_env();
|
|
81
|
-
import * as path from "node:path";
|
|
82
|
-
function resolvesToUncPath(target, cwd) {
|
|
83
|
-
try {
|
|
84
|
-
return isUncOrDevicePath(path.resolve(cwd ?? process.cwd(), target));
|
|
85
|
-
} catch {
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
function vscodePathAllowed(filePath, workspace) {
|
|
90
|
-
if (isUncOrDevicePath(filePath)) return false;
|
|
91
|
-
if (workspace === void 0 || isUncOrDevicePath(workspace)) return false;
|
|
92
|
-
const resolvedRoot = path.resolve(workspace);
|
|
93
|
-
const resolvedTarget = path.resolve(workspace, filePath);
|
|
94
|
-
const root = foldPathForContainment(resolvedRoot.replace(/\\/g, "/"));
|
|
95
|
-
const target = foldPathForContainment(resolvedTarget.replace(/\\/g, "/"));
|
|
96
|
-
if (target !== root && !target.startsWith(root.endsWith("/") ? root : root + "/")) return false;
|
|
97
|
-
return isInsideRoot(resolvedTarget, resolvedRoot);
|
|
98
|
-
}
|
|
99
|
-
function isVscodeEvent(event) {
|
|
100
|
-
return event.raw["_tg_harness"] === "vscode" || event.raw[VSCODE_TOOL_NAME_KEY] !== void 0;
|
|
101
|
-
}
|
|
102
|
-
function preToolPathDeclined(event, target) {
|
|
103
|
-
if (target === void 0) return false;
|
|
104
|
-
const cwd = getCwd(event);
|
|
105
|
-
if (spellingDeclined(event, target, cwd)) return true;
|
|
106
|
-
const mount = secondSpellingAtMount(target, cwd);
|
|
107
|
-
return mount !== null && spellingDeclined(event, mount, cwd);
|
|
108
|
-
}
|
|
109
|
-
function spellingDeclined(event, target, cwd) {
|
|
110
|
-
if (isUncOrDevicePath(target) || resolvesToUncPath(target, cwd)) return true;
|
|
111
|
-
if (isVscodeEvent(event)) return !vscodePathAllowed(target, cwd);
|
|
112
|
-
return escapesOntoNetworkThroughLinks(target, cwd);
|
|
113
|
-
}
|
|
114
|
-
function secondSpellingAtMount(target, cwd) {
|
|
115
|
-
if (process.platform === "win32") return null;
|
|
116
|
-
const base = cwd ?? "/";
|
|
117
|
-
const mount = wslMountOfIndexKey(resolveIndexPath(target, base));
|
|
118
|
-
return mount !== null && mount !== path.resolve(base, target) ? mount : null;
|
|
119
|
-
}
|
|
120
|
-
function commandPathIsTouchable(filePath, event) {
|
|
121
|
-
if (event === void 0) return !escapesOntoNetworkThroughLinks(filePath);
|
|
122
|
-
return !preToolPathDeclined(event, filePath);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export {
|
|
126
|
-
stripUnsafeSuggestions,
|
|
127
|
-
leadWithCommand,
|
|
128
|
-
docNavigation,
|
|
129
|
-
grepLinesHint,
|
|
130
|
-
docSectionHint,
|
|
131
|
-
vscodePathAllowed,
|
|
132
|
-
preToolPathDeclined,
|
|
133
|
-
commandPathIsTouchable
|
|
134
|
-
};
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
|
-
const require = __cjsRequire(import.meta.url);
|
|
3
|
-
import {
|
|
4
|
-
NATIVE_FALLBACK_ENV,
|
|
5
|
-
RELAY_QUEUE_WAIT_MS,
|
|
6
|
-
buildEvent,
|
|
7
|
-
nativeFallbackDetail,
|
|
8
|
-
relay,
|
|
9
|
-
relayInProcess
|
|
10
|
-
} from "./token-goat-chunk-SQSSNQPE.mjs";
|
|
11
|
-
import "./token-goat-chunk-ZEJVMUQH.mjs";
|
|
12
|
-
import "./token-goat-chunk-GFBSN7BD.mjs";
|
|
13
|
-
import "./token-goat-chunk-5RG5SBL6.mjs";
|
|
14
|
-
import "./token-goat-chunk-KKUFXAPD.mjs";
|
|
15
|
-
import "./token-goat-chunk-7F2UBPD3.mjs";
|
|
16
|
-
import "./token-goat-chunk-54K3EUV3.mjs";
|
|
17
|
-
import "./token-goat-chunk-7BXSNBY5.mjs";
|
|
18
|
-
import "./token-goat-chunk-G5PJ7AGM.mjs";
|
|
19
|
-
import "./token-goat-chunk-YARZFCZS.mjs";
|
|
20
|
-
import "./token-goat-chunk-FBNQNSJK.mjs";
|
|
21
|
-
import "./token-goat-chunk-PEPTHRFF.mjs";
|
|
22
|
-
import "./token-goat-chunk-MNWKPRAL.mjs";
|
|
23
|
-
import "./token-goat-chunk-JTQQGXZH.mjs";
|
|
24
|
-
import "./token-goat-chunk-67TQJ76B.mjs";
|
|
25
|
-
import "./token-goat-chunk-H2PHHGM5.mjs";
|
|
26
|
-
import "./token-goat-chunk-P4QMM4WK.mjs";
|
|
27
|
-
import "./token-goat-chunk-5KDMCMF2.mjs";
|
|
28
|
-
import "./token-goat-chunk-APGZXSPS.mjs";
|
|
29
|
-
import "./token-goat-chunk-COBQGL5S.mjs";
|
|
30
|
-
import "./token-goat-chunk-ATCPY7EQ.mjs";
|
|
31
|
-
import "./token-goat-chunk-VPBBTSJR.mjs";
|
|
32
|
-
import "./token-goat-chunk-Q5VTGRH7.mjs";
|
|
33
|
-
import "./token-goat-chunk-Y776AENC.mjs";
|
|
34
|
-
import "./token-goat-chunk-SJHWVNDQ.mjs";
|
|
35
|
-
import "./token-goat-chunk-AFLYLHDH.mjs";
|
|
36
|
-
import "./token-goat-chunk-BPGCUMR7.mjs";
|
|
37
|
-
import "./token-goat-chunk-C63JQV5K.mjs";
|
|
38
|
-
import "./token-goat-chunk-JB6QN6VF.mjs";
|
|
39
|
-
import "./token-goat-chunk-RHXKCZX3.mjs";
|
|
40
|
-
import "./token-goat-chunk-EVMZJ27Z.mjs";
|
|
41
|
-
import "./token-goat-chunk-HYBFA5X3.mjs";
|
|
42
|
-
import "./token-goat-chunk-5Y6ZYL6U.mjs";
|
|
43
|
-
import "./token-goat-chunk-ARDNEC2U.mjs";
|
|
44
|
-
import "./token-goat-chunk-3Z5S4KGM.mjs";
|
|
45
|
-
import "./token-goat-chunk-VL3YIFHZ.mjs";
|
|
46
|
-
import "./token-goat-chunk-XB5KKOCG.mjs";
|
|
47
|
-
import "./token-goat-chunk-3BTK54F3.mjs";
|
|
48
|
-
import "./token-goat-chunk-4FVIAHSI.mjs";
|
|
49
|
-
import "./token-goat-chunk-7IN2MKDS.mjs";
|
|
50
|
-
import "./token-goat-chunk-U4N3BN2W.mjs";
|
|
51
|
-
import "./token-goat-chunk-YZAAZU2S.mjs";
|
|
52
|
-
import "./token-goat-chunk-IVE6U7KV.mjs";
|
|
53
|
-
import "./token-goat-chunk-Y4AFKTHK.mjs";
|
|
54
|
-
import "./token-goat-chunk-GOLEOXZP.mjs";
|
|
55
|
-
import "./token-goat-chunk-AM5V6GSX.mjs";
|
|
56
|
-
import "./token-goat-chunk-FNFBKLRD.mjs";
|
|
57
|
-
import "./token-goat-chunk-VES7EL7O.mjs";
|
|
58
|
-
import "./token-goat-chunk-KWPNJBDH.mjs";
|
|
59
|
-
import "./token-goat-chunk-HAVAOB3S.mjs";
|
|
60
|
-
import "./token-goat-chunk-A37V4PBF.mjs";
|
|
61
|
-
export {
|
|
62
|
-
NATIVE_FALLBACK_ENV,
|
|
63
|
-
RELAY_QUEUE_WAIT_MS,
|
|
64
|
-
buildEvent,
|
|
65
|
-
nativeFallbackDetail,
|
|
66
|
-
relay,
|
|
67
|
-
relayInProcess
|
|
68
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
|
-
const require = __cjsRequire(import.meta.url);
|
|
3
|
-
import {
|
|
4
|
-
INSTALL_INDEX_ENV,
|
|
5
|
-
formatInstallIndexResult,
|
|
6
|
-
queueInstallIndex
|
|
7
|
-
} from "./token-goat-chunk-56EIMS3E.mjs";
|
|
8
|
-
import "./token-goat-chunk-7BXSNBY5.mjs";
|
|
9
|
-
import "./token-goat-chunk-FBNQNSJK.mjs";
|
|
10
|
-
import "./token-goat-chunk-MNWKPRAL.mjs";
|
|
11
|
-
import "./token-goat-chunk-H2PHHGM5.mjs";
|
|
12
|
-
import "./token-goat-chunk-P4QMM4WK.mjs";
|
|
13
|
-
import "./token-goat-chunk-5KDMCMF2.mjs";
|
|
14
|
-
import "./token-goat-chunk-ATCPY7EQ.mjs";
|
|
15
|
-
import "./token-goat-chunk-VPBBTSJR.mjs";
|
|
16
|
-
import "./token-goat-chunk-Y776AENC.mjs";
|
|
17
|
-
import "./token-goat-chunk-SJHWVNDQ.mjs";
|
|
18
|
-
import "./token-goat-chunk-AFLYLHDH.mjs";
|
|
19
|
-
import "./token-goat-chunk-BPGCUMR7.mjs";
|
|
20
|
-
import "./token-goat-chunk-C63JQV5K.mjs";
|
|
21
|
-
import "./token-goat-chunk-JB6QN6VF.mjs";
|
|
22
|
-
import "./token-goat-chunk-RHXKCZX3.mjs";
|
|
23
|
-
import "./token-goat-chunk-EVMZJ27Z.mjs";
|
|
24
|
-
import "./token-goat-chunk-HYBFA5X3.mjs";
|
|
25
|
-
import "./token-goat-chunk-5Y6ZYL6U.mjs";
|
|
26
|
-
import "./token-goat-chunk-ARDNEC2U.mjs";
|
|
27
|
-
import "./token-goat-chunk-3Z5S4KGM.mjs";
|
|
28
|
-
import "./token-goat-chunk-VL3YIFHZ.mjs";
|
|
29
|
-
import "./token-goat-chunk-XB5KKOCG.mjs";
|
|
30
|
-
import "./token-goat-chunk-3BTK54F3.mjs";
|
|
31
|
-
import "./token-goat-chunk-4FVIAHSI.mjs";
|
|
32
|
-
import "./token-goat-chunk-7IN2MKDS.mjs";
|
|
33
|
-
import "./token-goat-chunk-U4N3BN2W.mjs";
|
|
34
|
-
import "./token-goat-chunk-YZAAZU2S.mjs";
|
|
35
|
-
import "./token-goat-chunk-IVE6U7KV.mjs";
|
|
36
|
-
import "./token-goat-chunk-Y4AFKTHK.mjs";
|
|
37
|
-
import "./token-goat-chunk-GOLEOXZP.mjs";
|
|
38
|
-
import "./token-goat-chunk-AM5V6GSX.mjs";
|
|
39
|
-
import "./token-goat-chunk-FNFBKLRD.mjs";
|
|
40
|
-
import "./token-goat-chunk-VES7EL7O.mjs";
|
|
41
|
-
import "./token-goat-chunk-KWPNJBDH.mjs";
|
|
42
|
-
import "./token-goat-chunk-HAVAOB3S.mjs";
|
|
43
|
-
import "./token-goat-chunk-A37V4PBF.mjs";
|
|
44
|
-
export {
|
|
45
|
-
INSTALL_INDEX_ENV,
|
|
46
|
-
formatInstallIndexResult,
|
|
47
|
-
queueInstallIndex
|
|
48
|
-
};
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
|
-
const require = __cjsRequire(import.meta.url);
|
|
3
|
-
import {
|
|
4
|
-
OCR_LANG_FILE,
|
|
5
|
-
OCR_LANG_PATH,
|
|
6
|
-
OCR_LANG_SHA256,
|
|
7
|
-
SUPPORTED_OCR_LANGS,
|
|
8
|
-
buildChildScript,
|
|
9
|
-
formatOcrSummary,
|
|
10
|
-
getActiveOcrLangs,
|
|
11
|
-
getOcrLangSpec,
|
|
12
|
-
isOcrEngineAvailable,
|
|
13
|
-
isTextHeavy,
|
|
14
|
-
ocrBlockedOffline,
|
|
15
|
-
ocrImage,
|
|
16
|
-
ocrIntegrityFailed,
|
|
17
|
-
quarantineOcrLangCache,
|
|
18
|
-
resetOcrStateForTesting,
|
|
19
|
-
resolveOcrLang,
|
|
20
|
-
setOcrTimeoutForTesting,
|
|
21
|
-
setTesseractEntryForTesting,
|
|
22
|
-
verifyOcrLangCache
|
|
23
|
-
} from "./token-goat-chunk-RC35RBUL.mjs";
|
|
24
|
-
import "./token-goat-chunk-ARDNEC2U.mjs";
|
|
25
|
-
import "./token-goat-chunk-3Z5S4KGM.mjs";
|
|
26
|
-
import "./token-goat-chunk-VL3YIFHZ.mjs";
|
|
27
|
-
import "./token-goat-chunk-XB5KKOCG.mjs";
|
|
28
|
-
import "./token-goat-chunk-4FVIAHSI.mjs";
|
|
29
|
-
import {
|
|
30
|
-
DEFAULT_OCR_LANG,
|
|
31
|
-
isSupportedOcrLang,
|
|
32
|
-
resolveOcrLangs
|
|
33
|
-
} from "./token-goat-chunk-7IN2MKDS.mjs";
|
|
34
|
-
import "./token-goat-chunk-U4N3BN2W.mjs";
|
|
35
|
-
import "./token-goat-chunk-YZAAZU2S.mjs";
|
|
36
|
-
import "./token-goat-chunk-IVE6U7KV.mjs";
|
|
37
|
-
import "./token-goat-chunk-GOLEOXZP.mjs";
|
|
38
|
-
import "./token-goat-chunk-AM5V6GSX.mjs";
|
|
39
|
-
import "./token-goat-chunk-FNFBKLRD.mjs";
|
|
40
|
-
import "./token-goat-chunk-VES7EL7O.mjs";
|
|
41
|
-
import "./token-goat-chunk-A37V4PBF.mjs";
|
|
42
|
-
export {
|
|
43
|
-
DEFAULT_OCR_LANG,
|
|
44
|
-
OCR_LANG_FILE,
|
|
45
|
-
OCR_LANG_PATH,
|
|
46
|
-
OCR_LANG_SHA256,
|
|
47
|
-
SUPPORTED_OCR_LANGS,
|
|
48
|
-
buildChildScript,
|
|
49
|
-
formatOcrSummary,
|
|
50
|
-
getActiveOcrLangs,
|
|
51
|
-
getOcrLangSpec,
|
|
52
|
-
isOcrEngineAvailable,
|
|
53
|
-
isSupportedOcrLang,
|
|
54
|
-
isTextHeavy,
|
|
55
|
-
ocrBlockedOffline,
|
|
56
|
-
ocrImage,
|
|
57
|
-
ocrIntegrityFailed,
|
|
58
|
-
quarantineOcrLangCache,
|
|
59
|
-
resetOcrStateForTesting,
|
|
60
|
-
resolveOcrLang,
|
|
61
|
-
resolveOcrLangs,
|
|
62
|
-
setOcrTimeoutForTesting,
|
|
63
|
-
setTesseractEntryForTesting,
|
|
64
|
-
verifyOcrLangCache
|
|
65
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
|
-
const require = __cjsRequire(import.meta.url);
|
|
3
|
-
import {
|
|
4
|
-
MAX_RESUME_CHARS,
|
|
5
|
-
MAX_RESUME_TOKENS,
|
|
6
|
-
buildResumePacket
|
|
7
|
-
} from "./token-goat-chunk-FZ3NEW5O.mjs";
|
|
8
|
-
import "./token-goat-chunk-Q5VTGRH7.mjs";
|
|
9
|
-
import "./token-goat-chunk-Y776AENC.mjs";
|
|
10
|
-
import "./token-goat-chunk-SJHWVNDQ.mjs";
|
|
11
|
-
import "./token-goat-chunk-AFLYLHDH.mjs";
|
|
12
|
-
import "./token-goat-chunk-BPGCUMR7.mjs";
|
|
13
|
-
import "./token-goat-chunk-C63JQV5K.mjs";
|
|
14
|
-
import "./token-goat-chunk-JB6QN6VF.mjs";
|
|
15
|
-
import "./token-goat-chunk-EVMZJ27Z.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
|
-
MAX_RESUME_CHARS,
|
|
35
|
-
MAX_RESUME_TOKENS,
|
|
36
|
-
buildResumePacket
|
|
37
|
-
};
|
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
|
-
const require = __cjsRequire(import.meta.url);
|
|
3
|
-
import {
|
|
4
|
-
DEFAULT_OCR_LANG,
|
|
5
|
-
isSupportedOcrLang,
|
|
6
|
-
loadConfig,
|
|
7
|
-
resolveOcrLangs
|
|
8
|
-
} from "./token-goat-chunk-7IN2MKDS.mjs";
|
|
9
|
-
import {
|
|
10
|
-
ensureDirSync
|
|
11
|
-
} from "./token-goat-chunk-GOLEOXZP.mjs";
|
|
12
|
-
import {
|
|
13
|
-
fenceUntrustedOcrText
|
|
14
|
-
} from "./token-goat-chunk-FNFBKLRD.mjs";
|
|
15
|
-
import {
|
|
16
|
-
tokenGoatHome
|
|
17
|
-
} from "./token-goat-chunk-VES7EL7O.mjs";
|
|
18
|
-
import {
|
|
19
|
-
init_define_import_meta_env
|
|
20
|
-
} from "./token-goat-chunk-A37V4PBF.mjs";
|
|
21
|
-
|
|
22
|
-
// src/image_ocr.ts
|
|
23
|
-
init_define_import_meta_env();
|
|
24
|
-
import { spawn } from "node:child_process";
|
|
25
|
-
import { createHash } from "node:crypto";
|
|
26
|
-
import * as fs from "node:fs";
|
|
27
|
-
import { createRequire } from "node:module";
|
|
28
|
-
import * as path from "node:path";
|
|
29
|
-
|
|
30
|
-
// src/ocr_hashes.ts
|
|
31
|
-
init_define_import_meta_env();
|
|
32
|
-
function ocrLangPath(lang) {
|
|
33
|
-
return `https://cdn.jsdelivr.net/npm/@tesseract.js-data/${lang}@1.0.0/4.0.0_best_int`;
|
|
34
|
-
}
|
|
35
|
-
var OCR_LANG_HASHES = {
|
|
36
|
-
eng: "5dc5d8d640a212c9d6184921ba103b186f50e0fed9ee716c53e6b312b400d747",
|
|
37
|
-
fra: "bf83833fa957ff0076f6aa93f69e3bdf7b014dea829ea0c0d6be6b48a3ceef6d",
|
|
38
|
-
spa: "0062377729b81cc268b1822f09eb1c08c09f3f7f1c6b422540b51555a7eeea70",
|
|
39
|
-
deu: "a1b72cc25753eac167edfef5af4448a8dc34973503a2265c34c84520f896eb03",
|
|
40
|
-
ita: "36ec897f5f1f489b257801881286167a79b99a16040c6fbc7e3e30f03821b10b",
|
|
41
|
-
por: "42fab1f017aedab69b92bdecc01bbb11166cd3b177575612ee860f8e2825ece0",
|
|
42
|
-
nld: "363c360db9838838ff7ed3d8b885b33acc0d61d37165708303cf8a81e50164f3",
|
|
43
|
-
pol: "02b89cad819f1374631b4a3c92bdac79c214150f97a3686df78de6c8c30782db",
|
|
44
|
-
rus: "eb9be824435f6bb0f993925acb85fd842c8418d6db7613c818e749e619a1ad6d",
|
|
45
|
-
tur: "f0127d0f3745f9c65e2ae7ec6b23198fbe5aa186a61b35661426f5e1ef9dedd7",
|
|
46
|
-
swe: "a4c33cbd23d988c84b5f9d5d5b2417fc16da061e3dc7b16acb904a4566088b14",
|
|
47
|
-
ara: "e7d6494e2ef249ee97ad151eb01e0e6ae3aaf429256442ad6af534862a2a8c0f",
|
|
48
|
-
chi_sim: "9784f7c917c546424b690fcde708ce1f604a4393d08bb51ddab146d7d7c794e6",
|
|
49
|
-
chi_tra: "6abfb87cce5db0d09624f16eedd8a0b24173718856121f721b6d1214193d4dab",
|
|
50
|
-
jpn: "1a0175291ea145d4a66be681d1084496f10af938aacab247c5d40b31359a604e",
|
|
51
|
-
kor: "ec1749377d49ac38fb3d3cd05dd5e2a53359d329f359762bc638a81132109992"
|
|
52
|
-
};
|
|
53
|
-
var SUPPORTED_OCR_LANGS = Object.fromEntries(
|
|
54
|
-
Object.entries(OCR_LANG_HASHES).map(([lang, sha256]) => [lang, { langPath: ocrLangPath(lang), sha256 }])
|
|
55
|
-
);
|
|
56
|
-
function getOcrLangSpec(lang) {
|
|
57
|
-
const tokens = lang.split("+");
|
|
58
|
-
const primary = tokens.find((t) => t !== DEFAULT_OCR_LANG && isSupportedOcrLang(t)) ?? tokens[0] ?? DEFAULT_OCR_LANG;
|
|
59
|
-
const active = isSupportedOcrLang(primary) ? primary : DEFAULT_OCR_LANG;
|
|
60
|
-
const sha256 = OCR_LANG_HASHES[active];
|
|
61
|
-
return {
|
|
62
|
-
langPath: ocrLangPath(active),
|
|
63
|
-
sha256
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// src/image_ocr.ts
|
|
68
|
-
var _ocrTimeoutMs = 12e3;
|
|
69
|
-
function setOcrTimeoutForTesting(ms) {
|
|
70
|
-
_ocrTimeoutMs = ms ?? 12e3;
|
|
71
|
-
}
|
|
72
|
-
function getActiveOcrLangs(lang) {
|
|
73
|
-
if (typeof lang === "string" && lang.trim()) {
|
|
74
|
-
return resolveOcrLangs(lang);
|
|
75
|
-
}
|
|
76
|
-
try {
|
|
77
|
-
const configured = loadConfig().image_shrink?.ocr_lang;
|
|
78
|
-
if (typeof configured === "string" && configured.trim()) {
|
|
79
|
-
return resolveOcrLangs(configured);
|
|
80
|
-
}
|
|
81
|
-
} catch {
|
|
82
|
-
}
|
|
83
|
-
return [DEFAULT_OCR_LANG];
|
|
84
|
-
}
|
|
85
|
-
function resolveOcrLang(lang) {
|
|
86
|
-
return getActiveOcrLangs(lang).join("+");
|
|
87
|
-
}
|
|
88
|
-
var OCR_LANG_FILE = `${DEFAULT_OCR_LANG}.traineddata`;
|
|
89
|
-
var OCR_LANG_PATH = getOcrLangSpec("eng").langPath;
|
|
90
|
-
var OCR_LANG_SHA256 = getOcrLangSpec("eng").sha256;
|
|
91
|
-
function verifyOcrLangCache(lang) {
|
|
92
|
-
const activeLangs = getActiveOcrLangs(lang);
|
|
93
|
-
let anyAbsent = false;
|
|
94
|
-
for (const l of activeLangs) {
|
|
95
|
-
const spec = getOcrLangSpec(l);
|
|
96
|
-
const file = path.join(ocrCacheDir(), `${l}.traineddata`);
|
|
97
|
-
try {
|
|
98
|
-
if (!fs.existsSync(file)) {
|
|
99
|
-
anyAbsent = true;
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
const bytes = fs.readFileSync(file);
|
|
103
|
-
if (createHash("sha256").update(bytes).digest("hex") !== spec.sha256) {
|
|
104
|
-
return "mismatch";
|
|
105
|
-
}
|
|
106
|
-
} catch {
|
|
107
|
-
return "unreadable";
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return anyAbsent ? "absent" : "ok";
|
|
111
|
-
}
|
|
112
|
-
function quarantineOcrLangCache(lang) {
|
|
113
|
-
const activeLangs = getActiveOcrLangs(lang);
|
|
114
|
-
for (const l of activeLangs) {
|
|
115
|
-
const spec = getOcrLangSpec(l);
|
|
116
|
-
const file = path.join(ocrCacheDir(), `${l}.traineddata`);
|
|
117
|
-
try {
|
|
118
|
-
if (fs.existsSync(file)) {
|
|
119
|
-
const bytes = fs.readFileSync(file);
|
|
120
|
-
if (createHash("sha256").update(bytes).digest("hex") !== spec.sha256) {
|
|
121
|
-
fs.rmSync(file, { force: true });
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
} catch {
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
var _ocrIntegrityFailed = false;
|
|
129
|
-
function ocrIntegrityFailed() {
|
|
130
|
-
return _ocrIntegrityFailed;
|
|
131
|
-
}
|
|
132
|
-
function ocrBlockedOffline(lang) {
|
|
133
|
-
if (!loadConfig().network.offline) return false;
|
|
134
|
-
return verifyOcrLangCache(lang) === "absent";
|
|
135
|
-
}
|
|
136
|
-
function ocrCacheDir() {
|
|
137
|
-
return path.join(tokenGoatHome(), "ocr-cache");
|
|
138
|
-
}
|
|
139
|
-
function ensureOcrCacheDir() {
|
|
140
|
-
try {
|
|
141
|
-
ensureDirSync(ocrCacheDir());
|
|
142
|
-
} catch {
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
var _require = createRequire(import.meta.url);
|
|
146
|
-
var _tesseractEntryPath;
|
|
147
|
-
function resolveTesseractEntry() {
|
|
148
|
-
if (_tesseractEntryPath !== void 0) return _tesseractEntryPath;
|
|
149
|
-
try {
|
|
150
|
-
_tesseractEntryPath = _require.resolve("tesseract.js");
|
|
151
|
-
} catch {
|
|
152
|
-
_tesseractEntryPath = null;
|
|
153
|
-
}
|
|
154
|
-
return _tesseractEntryPath;
|
|
155
|
-
}
|
|
156
|
-
function isOcrEngineAvailable() {
|
|
157
|
-
return !_ocrUnavailableThisProcess && resolveTesseractEntry() !== null;
|
|
158
|
-
}
|
|
159
|
-
function setTesseractEntryForTesting(entryPath) {
|
|
160
|
-
_tesseractEntryPath = entryPath;
|
|
161
|
-
}
|
|
162
|
-
var _ocrUnavailableThisProcess = false;
|
|
163
|
-
function resetOcrStateForTesting() {
|
|
164
|
-
_ocrUnavailableThisProcess = false;
|
|
165
|
-
_ocrIntegrityFailed = false;
|
|
166
|
-
_tesseractEntryPath = void 0;
|
|
167
|
-
_ocrTimeoutMs = 12e3;
|
|
168
|
-
}
|
|
169
|
-
function buildChildScript(entryPath, cacheDir, lang) {
|
|
170
|
-
const activeLangs = getActiveOcrLangs(lang);
|
|
171
|
-
const activeLangString = activeLangs.join("+");
|
|
172
|
-
const spec = getOcrLangSpec(lang ?? activeLangString);
|
|
173
|
-
return [
|
|
174
|
-
`const { createWorker } = require(${JSON.stringify(entryPath)});`,
|
|
175
|
-
"const chunks = [];",
|
|
176
|
-
"process.stdin.on('data', (c) => chunks.push(c));",
|
|
177
|
-
"process.stdin.on('end', async () => {",
|
|
178
|
-
" try {",
|
|
179
|
-
" const buf = Buffer.concat(chunks);",
|
|
180
|
-
` const worker = await createWorker(${JSON.stringify(activeLangString)}, 1, { cachePath: ${JSON.stringify(cacheDir)}, langPath: ${JSON.stringify(spec.langPath)}, errorHandler: () => {} });`,
|
|
181
|
-
" const { data } = await worker.recognize(buf);",
|
|
182
|
-
" process.stdout.write(JSON.stringify({ text: data.text || '', confidence: data.confidence || 0 }));",
|
|
183
|
-
" await worker.terminate();",
|
|
184
|
-
" process.exit(0);",
|
|
185
|
-
" } catch (e) {",
|
|
186
|
-
" process.exit(1);",
|
|
187
|
-
" }",
|
|
188
|
-
"});"
|
|
189
|
-
].join("\n");
|
|
190
|
-
}
|
|
191
|
-
async function ocrImage(input, lang) {
|
|
192
|
-
if (_ocrUnavailableThisProcess) return null;
|
|
193
|
-
const activeLangs = getActiveOcrLangs(lang);
|
|
194
|
-
const entryPath = resolveTesseractEntry();
|
|
195
|
-
if (entryPath === null) return null;
|
|
196
|
-
if (ocrBlockedOffline(lang)) return null;
|
|
197
|
-
if (_ocrIntegrityFailed) return null;
|
|
198
|
-
if (verifyOcrLangCache(lang) === "mismatch") {
|
|
199
|
-
_ocrIntegrityFailed = true;
|
|
200
|
-
quarantineOcrLangCache(lang);
|
|
201
|
-
return null;
|
|
202
|
-
}
|
|
203
|
-
for (const l of activeLangs) {
|
|
204
|
-
if (l !== DEFAULT_OCR_LANG) {
|
|
205
|
-
const file = path.join(ocrCacheDir(), `${l}.traineddata`);
|
|
206
|
-
if (!fs.existsSync(file)) {
|
|
207
|
-
if (loadConfig().network.offline) return null;
|
|
208
|
-
try {
|
|
209
|
-
const res = await fetch(getOcrLangSpec(l).langPath + `/${l}.traineddata.gz`);
|
|
210
|
-
if (!res.ok) return null;
|
|
211
|
-
const gz = Buffer.from(await res.arrayBuffer());
|
|
212
|
-
const unzipped = (await import("node:zlib")).gunzipSync(gz);
|
|
213
|
-
if (createHash("sha256").update(unzipped).digest("hex") !== getOcrLangSpec(l).sha256) {
|
|
214
|
-
_ocrIntegrityFailed = true;
|
|
215
|
-
return null;
|
|
216
|
-
}
|
|
217
|
-
ensureOcrCacheDir();
|
|
218
|
-
fs.writeFileSync(file, unzipped);
|
|
219
|
-
} catch {
|
|
220
|
-
return null;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
return new Promise((resolve) => {
|
|
226
|
-
let settled = false;
|
|
227
|
-
let child;
|
|
228
|
-
try {
|
|
229
|
-
ensureOcrCacheDir();
|
|
230
|
-
child = spawn(process.execPath, ["-e", buildChildScript(entryPath, ocrCacheDir(), lang)], {
|
|
231
|
-
stdio: ["pipe", "pipe", "ignore"]
|
|
232
|
-
});
|
|
233
|
-
} catch {
|
|
234
|
-
_ocrUnavailableThisProcess = true;
|
|
235
|
-
resolve(null);
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
const chunks = [];
|
|
239
|
-
const finish = (result, subprocessBroken) => {
|
|
240
|
-
if (settled) return;
|
|
241
|
-
settled = true;
|
|
242
|
-
clearTimeout(timer);
|
|
243
|
-
if (subprocessBroken) _ocrUnavailableThisProcess = true;
|
|
244
|
-
try {
|
|
245
|
-
child.kill();
|
|
246
|
-
} catch {
|
|
247
|
-
}
|
|
248
|
-
resolve(result);
|
|
249
|
-
};
|
|
250
|
-
const timer = setTimeout(() => finish(null, true), _ocrTimeoutMs);
|
|
251
|
-
child.stdout?.on("data", (c) => chunks.push(c));
|
|
252
|
-
child.on("error", () => finish(null, true));
|
|
253
|
-
child.on("close", (code) => {
|
|
254
|
-
if (code !== 0) {
|
|
255
|
-
finish(null, false);
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
if (verifyOcrLangCache(lang) === "mismatch") {
|
|
259
|
-
_ocrIntegrityFailed = true;
|
|
260
|
-
quarantineOcrLangCache(lang);
|
|
261
|
-
finish(null, false);
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
try {
|
|
265
|
-
const raw = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
266
|
-
const parsed = raw;
|
|
267
|
-
const text = typeof parsed.text === "string" ? parsed.text.trim() : "";
|
|
268
|
-
const confidence = typeof parsed.confidence === "number" ? parsed.confidence : 0;
|
|
269
|
-
finish({ text, confidence }, false);
|
|
270
|
-
} catch {
|
|
271
|
-
finish(null, false);
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
try {
|
|
275
|
-
child.stdin?.end(input);
|
|
276
|
-
} catch {
|
|
277
|
-
finish(null, false);
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
function isTextHeavy(result, minConfidence, minChars = 40) {
|
|
282
|
-
return result.confidence >= minConfidence && result.text.length >= minChars;
|
|
283
|
-
}
|
|
284
|
-
function formatOcrSummary(result, subject, originalBytes) {
|
|
285
|
-
const kb = Math.round(originalBytes / 1024);
|
|
286
|
-
const summary = `token-goat OCR'd ${subject} instead of shrinking it: text-heavy image detected (${Math.round(result.confidence)}% confidence), extracted ${result.text.length} chars of text from ${kb}kb of pixels.`;
|
|
287
|
-
return `${summary}
|
|
288
|
-
|
|
289
|
-
${fenceUntrustedOcrText(result.text)}`;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
export {
|
|
293
|
-
SUPPORTED_OCR_LANGS,
|
|
294
|
-
getOcrLangSpec,
|
|
295
|
-
setOcrTimeoutForTesting,
|
|
296
|
-
getActiveOcrLangs,
|
|
297
|
-
resolveOcrLang,
|
|
298
|
-
OCR_LANG_FILE,
|
|
299
|
-
OCR_LANG_PATH,
|
|
300
|
-
OCR_LANG_SHA256,
|
|
301
|
-
verifyOcrLangCache,
|
|
302
|
-
quarantineOcrLangCache,
|
|
303
|
-
ocrIntegrityFailed,
|
|
304
|
-
ocrBlockedOffline,
|
|
305
|
-
isOcrEngineAvailable,
|
|
306
|
-
setTesseractEntryForTesting,
|
|
307
|
-
resetOcrStateForTesting,
|
|
308
|
-
buildChildScript,
|
|
309
|
-
ocrImage,
|
|
310
|
-
isTextHeavy,
|
|
311
|
-
formatOcrSummary
|
|
312
|
-
};
|