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,807 +0,0 @@
|
|
|
1
|
-
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
|
-
const require = __cjsRequire(import.meta.url);
|
|
3
|
-
import {
|
|
4
|
-
foldPath,
|
|
5
|
-
isInsideRoot,
|
|
6
|
-
quotePowershellPath,
|
|
7
|
-
quoteShellPath,
|
|
8
|
-
sleepSync
|
|
9
|
-
} from "./token-goat-chunk-TCQANXYC.mjs";
|
|
10
|
-
import {
|
|
11
|
-
normalizePath
|
|
12
|
-
} from "./token-goat-chunk-NMTKNYGF.mjs";
|
|
13
|
-
import {
|
|
14
|
-
dataDir,
|
|
15
|
-
ensureStorageRootPrivate,
|
|
16
|
-
isTokenGoatStorage
|
|
17
|
-
} from "./token-goat-chunk-MELOKFDJ.mjs";
|
|
18
|
-
import {
|
|
19
|
-
compileGuardedRegex
|
|
20
|
-
} from "./token-goat-chunk-JTKCQMQA.mjs";
|
|
21
|
-
import {
|
|
22
|
-
init_define_import_meta_env
|
|
23
|
-
} from "./token-goat-chunk-A37V4PBF.mjs";
|
|
24
|
-
|
|
25
|
-
// src/encoding.ts
|
|
26
|
-
init_define_import_meta_env();
|
|
27
|
-
function stripBom(text) {
|
|
28
|
-
return text.charCodeAt(0) === 65279 ? text.slice(1) : text;
|
|
29
|
-
}
|
|
30
|
-
function detectSourceEncoding(buf) {
|
|
31
|
-
if (buf.length >= 4) {
|
|
32
|
-
if (buf[0] === 255 && buf[1] === 254 && buf[2] === 0 && buf[3] === 0) return "utf32le";
|
|
33
|
-
if (buf[0] === 0 && buf[1] === 0 && buf[2] === 254 && buf[3] === 255) return "utf32be";
|
|
34
|
-
}
|
|
35
|
-
if (buf.length >= 2) {
|
|
36
|
-
if (buf[0] === 255 && buf[1] === 254) return "utf16le";
|
|
37
|
-
if (buf[0] === 254 && buf[1] === 255) return "utf16be";
|
|
38
|
-
}
|
|
39
|
-
if (buf.length >= 3 && buf[0] === 239 && buf[1] === 187 && buf[2] === 191) return "utf8-bom";
|
|
40
|
-
return "utf8";
|
|
41
|
-
}
|
|
42
|
-
function decodeSource(buf) {
|
|
43
|
-
switch (detectSourceEncoding(buf)) {
|
|
44
|
-
case "utf32le":
|
|
45
|
-
return decodeUtf32(buf.subarray(4), true);
|
|
46
|
-
case "utf32be":
|
|
47
|
-
return decodeUtf32(buf.subarray(4), false);
|
|
48
|
-
case "utf16le":
|
|
49
|
-
return buf.subarray(2).toString("utf16le");
|
|
50
|
-
case "utf16be":
|
|
51
|
-
return swap16(buf.subarray(2)).toString("utf16le");
|
|
52
|
-
case "utf8-bom":
|
|
53
|
-
return buf.subarray(3).toString("utf8");
|
|
54
|
-
default:
|
|
55
|
-
return buf.toString("utf8");
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
function encodeSource(text, encoding) {
|
|
59
|
-
switch (encoding) {
|
|
60
|
-
case "utf32le":
|
|
61
|
-
return Buffer.concat([Buffer.from([255, 254, 0, 0]), encodeUtf32(text, true)]);
|
|
62
|
-
case "utf32be":
|
|
63
|
-
return Buffer.concat([Buffer.from([0, 0, 254, 255]), encodeUtf32(text, false)]);
|
|
64
|
-
case "utf16le":
|
|
65
|
-
return Buffer.concat([Buffer.from([255, 254]), Buffer.from(text, "utf16le")]);
|
|
66
|
-
case "utf16be":
|
|
67
|
-
return Buffer.concat([Buffer.from([254, 255]), swap16(Buffer.from(text, "utf16le"))]);
|
|
68
|
-
case "utf8-bom":
|
|
69
|
-
return Buffer.concat([Buffer.from([239, 187, 191]), Buffer.from(text, "utf8")]);
|
|
70
|
-
default:
|
|
71
|
-
return Buffer.from(text, "utf8");
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
function swap16(buf) {
|
|
75
|
-
const out = Buffer.from(buf);
|
|
76
|
-
return out.subarray(0, out.length - out.length % 2).swap16();
|
|
77
|
-
}
|
|
78
|
-
function decodeUtf32(buf, littleEndian) {
|
|
79
|
-
const points = [];
|
|
80
|
-
for (let i = 0; i + 4 <= buf.length; i += 4) {
|
|
81
|
-
const cp = littleEndian ? buf.readUInt32LE(i) : buf.readUInt32BE(i);
|
|
82
|
-
points.push(cp > 1114111 || cp >= 55296 && cp <= 57343 ? 65533 : cp);
|
|
83
|
-
}
|
|
84
|
-
return String.fromCodePoint(...points);
|
|
85
|
-
}
|
|
86
|
-
function encodeUtf32(text, littleEndian) {
|
|
87
|
-
const points = [...text];
|
|
88
|
-
const out = Buffer.alloc(points.length * 4);
|
|
89
|
-
points.forEach((ch, i) => {
|
|
90
|
-
const cp = ch.codePointAt(0) ?? 65533;
|
|
91
|
-
if (littleEndian) out.writeUInt32LE(cp, i * 4);
|
|
92
|
-
else out.writeUInt32BE(cp, i * 4);
|
|
93
|
-
});
|
|
94
|
-
return out;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// src/util.ts
|
|
98
|
-
init_define_import_meta_env();
|
|
99
|
-
import { chmodSync, closeSync, constants as fsConstants, copyFileSync, existsSync as existsSync2, mkdirSync, openSync, readdirSync, readFileSync as readFileSync3, renameSync, rmdirSync, statSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
|
|
100
|
-
import * as path4 from "node:path";
|
|
101
|
-
|
|
102
|
-
// src/bridges/created_configs.ts
|
|
103
|
-
init_define_import_meta_env();
|
|
104
|
-
import * as fs from "fs";
|
|
105
|
-
import * as path from "path";
|
|
106
|
-
function ledgerPath() {
|
|
107
|
-
return path.join(dataDir(), "created-configs.json");
|
|
108
|
-
}
|
|
109
|
-
function keyOf(filePath) {
|
|
110
|
-
return normalizePath(path.resolve(filePath));
|
|
111
|
-
}
|
|
112
|
-
function foldKey(key) {
|
|
113
|
-
return foldPath(key);
|
|
114
|
-
}
|
|
115
|
-
function readLedger() {
|
|
116
|
-
try {
|
|
117
|
-
const parsed = JSON.parse(fs.readFileSync(ledgerPath(), "utf8"));
|
|
118
|
-
return Array.isArray(parsed) ? parsed.filter((entry) => typeof entry === "string") : [];
|
|
119
|
-
} catch {
|
|
120
|
-
return [];
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
function writeLedger(entries) {
|
|
124
|
-
try {
|
|
125
|
-
ensureDirSync(path.dirname(ledgerPath()));
|
|
126
|
-
atomicWriteText(ledgerPath(), `${JSON.stringify(entries)}
|
|
127
|
-
`);
|
|
128
|
-
} catch {
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
function recordCreatedConfig(filePath) {
|
|
132
|
-
const key = keyOf(filePath);
|
|
133
|
-
const entries = readLedger();
|
|
134
|
-
if (entries.some((entry) => foldKey(entry) === foldKey(key))) return;
|
|
135
|
-
writeLedger([...entries, key]);
|
|
136
|
-
}
|
|
137
|
-
function hasCreatedConfig(filePath) {
|
|
138
|
-
const key = foldKey(keyOf(filePath));
|
|
139
|
-
return readLedger().some((entry) => foldKey(entry) === key);
|
|
140
|
-
}
|
|
141
|
-
function takeCreatedConfig(filePath) {
|
|
142
|
-
const key = foldKey(keyOf(filePath));
|
|
143
|
-
const entries = readLedger();
|
|
144
|
-
if (!entries.some((entry) => foldKey(entry) === key)) return false;
|
|
145
|
-
writeLedger(entries.filter((entry) => foldKey(entry) !== key));
|
|
146
|
-
return true;
|
|
147
|
-
}
|
|
148
|
-
function recordCreatedBackup(backupPath) {
|
|
149
|
-
recordCreatedConfig(backupPath);
|
|
150
|
-
}
|
|
151
|
-
function forgetCreatedBackup(backupPath) {
|
|
152
|
-
takeCreatedConfig(backupPath);
|
|
153
|
-
}
|
|
154
|
-
function createdBackupsFor(configPath) {
|
|
155
|
-
const prefix = foldKey(`${keyOf(configPath)}.bak.`);
|
|
156
|
-
return readLedger().filter((entry) => foldKey(entry).startsWith(prefix)).sort();
|
|
157
|
-
}
|
|
158
|
-
function removeCreatedBackups(configPath) {
|
|
159
|
-
const prefix = foldKey(`${keyOf(configPath)}.bak.`);
|
|
160
|
-
const entries = readLedger();
|
|
161
|
-
const ours = entries.filter((entry) => foldKey(entry).startsWith(prefix));
|
|
162
|
-
if (ours.length === 0) return 0;
|
|
163
|
-
const failed = /* @__PURE__ */ new Set();
|
|
164
|
-
let removed = 0;
|
|
165
|
-
for (const target of ours) {
|
|
166
|
-
try {
|
|
167
|
-
if (fs.existsSync(target) && removeFileInScope(target)) {
|
|
168
|
-
removed++;
|
|
169
|
-
}
|
|
170
|
-
} catch {
|
|
171
|
-
failed.add(target);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
writeLedger(entries.filter((entry) => !ours.includes(entry) || failed.has(entry)));
|
|
175
|
-
return removed;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// src/bridges/project_scope_guard.ts
|
|
179
|
-
init_define_import_meta_env();
|
|
180
|
-
import * as path2 from "node:path";
|
|
181
|
-
function assertProjectScopeTarget(target, projectRoot) {
|
|
182
|
-
if (projectRoot === void 0) return;
|
|
183
|
-
if (isInsideRoot(target, projectRoot)) return;
|
|
184
|
-
throw new Error(
|
|
185
|
-
`refusing to touch ${target}: it resolves outside the project (${projectRoot}). A repository can check a config path in as a symlink to a private file, and installing over it would read and back up that file's contents into the working tree. Remove the link, or run the install with --user.`
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
var installProjectRoot;
|
|
189
|
-
function withInstallScope(projectRoot, fn) {
|
|
190
|
-
const previous = installProjectRoot;
|
|
191
|
-
installProjectRoot = projectRoot === void 0 ? void 0 : path2.resolve(projectRoot);
|
|
192
|
-
try {
|
|
193
|
-
const result = fn();
|
|
194
|
-
if (typeof result?.then === "function") {
|
|
195
|
-
throw new Error(
|
|
196
|
-
"withInstallScope was given a function that returned a thenable. The install scope is held in a module-level variable and restored synchronously, so an async installer would run every write after its first await with containment already switched off. Make the installer synchronous, or move the scope to AsyncLocalStorage first."
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
return result;
|
|
200
|
-
} finally {
|
|
201
|
-
installProjectRoot = previous;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
function projectScopeRoot(opts) {
|
|
205
|
-
if (opts === void 0) return void 0;
|
|
206
|
-
if (opts.project !== true && opts.local !== true) return void 0;
|
|
207
|
-
return path2.resolve(opts.projectRoot ?? process.cwd());
|
|
208
|
-
}
|
|
209
|
-
function assertWriteInScope(target) {
|
|
210
|
-
const root = installProjectRoot;
|
|
211
|
-
if (root === void 0) return;
|
|
212
|
-
if (isTokenGoatStorage(target)) return;
|
|
213
|
-
assertProjectScopeTarget(target, root);
|
|
214
|
-
}
|
|
215
|
-
function projectPathIsConsultable(target, projectRoot) {
|
|
216
|
-
return isInsideRoot(target, projectRoot);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// src/util.ts
|
|
220
|
-
import { spawnSync } from "node:child_process";
|
|
221
|
-
|
|
222
|
-
// src/util_config.ts
|
|
223
|
-
init_define_import_meta_env();
|
|
224
|
-
import { readFileSync as readFileSync2 } from "node:fs";
|
|
225
|
-
import * as path3 from "node:path";
|
|
226
|
-
function stripOwnHooksFromMap(hooks, isOurs) {
|
|
227
|
-
let removed = false;
|
|
228
|
-
for (const eventKey of Object.keys(hooks)) {
|
|
229
|
-
const groups = hooks[eventKey];
|
|
230
|
-
if (groups === void 0 || !Array.isArray(groups)) continue;
|
|
231
|
-
const kept = [];
|
|
232
|
-
for (const group of groups) {
|
|
233
|
-
const keptHooks = (group.hooks ?? []).filter((h) => {
|
|
234
|
-
const isOur = isOurs(h.command, h.args);
|
|
235
|
-
if (isOur) removed = true;
|
|
236
|
-
return !isOur;
|
|
237
|
-
});
|
|
238
|
-
if (keptHooks.length > 0) {
|
|
239
|
-
kept.push({ ...group, hooks: keptHooks });
|
|
240
|
-
} else if ((group.hooks ?? []).length === 0) {
|
|
241
|
-
kept.push(group);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
if (kept.length > 0) {
|
|
245
|
-
hooks[eventKey] = kept;
|
|
246
|
-
} else {
|
|
247
|
-
delete hooks[eventKey];
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
return removed;
|
|
251
|
-
}
|
|
252
|
-
function stripStaleGroupHooks(groups, isOurs, matcherFilter) {
|
|
253
|
-
const list = Array.isArray(groups) ? groups : [];
|
|
254
|
-
const next = [];
|
|
255
|
-
for (const group of list) {
|
|
256
|
-
if (matcherFilter !== void 0 && group.matcher !== matcherFilter.matcher) {
|
|
257
|
-
next.push(group);
|
|
258
|
-
continue;
|
|
259
|
-
}
|
|
260
|
-
const keptHooks = (group.hooks ?? []).filter((h) => !isOurs(h.command, h.args));
|
|
261
|
-
if (keptHooks.length > 0) {
|
|
262
|
-
next.push({ ...group, hooks: keptHooks });
|
|
263
|
-
} else if ((group.hooks ?? []).length === 0) {
|
|
264
|
-
next.push(group);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
return next;
|
|
268
|
-
}
|
|
269
|
-
function stripDelimitedBlock(p, beginMarker, endMarker, keepBackups = false) {
|
|
270
|
-
let existing;
|
|
271
|
-
try {
|
|
272
|
-
existing = readFileSync2(p, "utf8");
|
|
273
|
-
} catch {
|
|
274
|
-
return false;
|
|
275
|
-
}
|
|
276
|
-
const beginIdx = existing.indexOf(beginMarker);
|
|
277
|
-
const endIdx = existing.indexOf(endMarker);
|
|
278
|
-
if (beginIdx === -1 || endIdx === -1 || endIdx <= beginIdx) return false;
|
|
279
|
-
const before = existing.slice(0, beginIdx).replace(/\s+$/, "");
|
|
280
|
-
const after = existing.slice(endIdx + endMarker.length).replace(/^\s+/, "");
|
|
281
|
-
let next;
|
|
282
|
-
if (before.length > 0 && after.length > 0) {
|
|
283
|
-
next = `${before}
|
|
284
|
-
|
|
285
|
-
${after}`;
|
|
286
|
-
} else if (before.length > 0) {
|
|
287
|
-
next = `${before}
|
|
288
|
-
`;
|
|
289
|
-
} else {
|
|
290
|
-
next = after;
|
|
291
|
-
}
|
|
292
|
-
backupFile(p);
|
|
293
|
-
atomicWriteText(p, next);
|
|
294
|
-
if (!keepBackups) removeCreatedBackups(p);
|
|
295
|
-
return true;
|
|
296
|
-
}
|
|
297
|
-
function upsertDelimitedBlock(p, beginMarker, endMarker, block) {
|
|
298
|
-
assertWriteInScope(p);
|
|
299
|
-
let existing;
|
|
300
|
-
try {
|
|
301
|
-
existing = readFileSync2(p, "utf8");
|
|
302
|
-
} catch {
|
|
303
|
-
existing = "";
|
|
304
|
-
}
|
|
305
|
-
const beginIdx = existing.indexOf(beginMarker);
|
|
306
|
-
const endIdx = existing.indexOf(endMarker);
|
|
307
|
-
if (beginIdx !== -1 && endIdx !== -1 && endIdx > beginIdx) {
|
|
308
|
-
const before = existing.slice(0, beginIdx);
|
|
309
|
-
const after = existing.slice(endIdx + endMarker.length);
|
|
310
|
-
const current = existing.slice(beginIdx, endIdx + endMarker.length);
|
|
311
|
-
if (current === block) return false;
|
|
312
|
-
ensureDirSync(path3.dirname(p));
|
|
313
|
-
backupFile(p);
|
|
314
|
-
atomicWriteText(p, `${before}${block}${after}`);
|
|
315
|
-
return true;
|
|
316
|
-
}
|
|
317
|
-
const trimmed = existing.replace(/\s+$/, "");
|
|
318
|
-
const next = trimmed.length > 0 ? `${trimmed}
|
|
319
|
-
|
|
320
|
-
${block}
|
|
321
|
-
` : `${block}
|
|
322
|
-
`;
|
|
323
|
-
ensureDirSync(path3.dirname(p));
|
|
324
|
-
backupFile(p);
|
|
325
|
-
atomicWriteText(p, next);
|
|
326
|
-
return true;
|
|
327
|
-
}
|
|
328
|
-
function writeJsonSettings(p, settings) {
|
|
329
|
-
ensureDirSync(path3.dirname(p));
|
|
330
|
-
backupFile(p);
|
|
331
|
-
atomicWriteText(p, `${JSON.stringify(settings, null, 2)}
|
|
332
|
-
`);
|
|
333
|
-
}
|
|
334
|
-
function writeIfDifferent(p, content, backup = false) {
|
|
335
|
-
let existing;
|
|
336
|
-
try {
|
|
337
|
-
existing = readFileSync2(p, "utf8");
|
|
338
|
-
} catch {
|
|
339
|
-
existing = void 0;
|
|
340
|
-
}
|
|
341
|
-
if (existing === content) return false;
|
|
342
|
-
if (backup) backupFile(p);
|
|
343
|
-
ensureDirSync(path3.dirname(p));
|
|
344
|
-
atomicWriteText(p, content);
|
|
345
|
-
return true;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
// src/util.ts
|
|
349
|
-
function runGit(args, opts = {}) {
|
|
350
|
-
const subArgs = args[0] === "diff" ? [args[0], "--no-ext-diff", "--no-textconv", ...args.slice(1)] : args;
|
|
351
|
-
const fullArgs = [
|
|
352
|
-
"--no-optional-locks",
|
|
353
|
-
"-c",
|
|
354
|
-
"core.fsmonitor=",
|
|
355
|
-
"-c",
|
|
356
|
-
"core.quotepath=false",
|
|
357
|
-
...subArgs
|
|
358
|
-
];
|
|
359
|
-
const result = spawnSync("git", fullArgs, {
|
|
360
|
-
...opts.cwd !== void 0 ? { cwd: opts.cwd } : {},
|
|
361
|
-
...opts.timeoutMs !== void 0 ? { timeout: opts.timeoutMs } : {},
|
|
362
|
-
encoding: "utf-8",
|
|
363
|
-
windowsHide: true,
|
|
364
|
-
maxBuffer: 200 * 1024 * 1024
|
|
365
|
-
});
|
|
366
|
-
if (result.error) {
|
|
367
|
-
return { stdout: "", stderr: String(result.error.message ?? result.error), exitCode: -1 };
|
|
368
|
-
}
|
|
369
|
-
return {
|
|
370
|
-
stdout: result.stdout ?? "",
|
|
371
|
-
stderr: result.stderr ?? "",
|
|
372
|
-
exitCode: result.status ?? 1
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
function statSize(absPath) {
|
|
376
|
-
try {
|
|
377
|
-
const st = statSync(absPath);
|
|
378
|
-
return st.isFile() ? st.size : null;
|
|
379
|
-
} catch {
|
|
380
|
-
return null;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
var RETRYABLE_ERRNO = /* @__PURE__ */ new Set(["EPERM", "EBUSY", "ETXTBSY"]);
|
|
384
|
-
function isRetryable(err) {
|
|
385
|
-
if (typeof err !== "object" || err === null) return false;
|
|
386
|
-
const code = err.code;
|
|
387
|
-
return typeof code === "string" && RETRYABLE_ERRNO.has(code);
|
|
388
|
-
}
|
|
389
|
-
function isEExist(err) {
|
|
390
|
-
if (typeof err !== "object" || err === null) return false;
|
|
391
|
-
return err.code === "EEXIST";
|
|
392
|
-
}
|
|
393
|
-
function ensureDirSync(dir) {
|
|
394
|
-
assertWriteInScope(dir);
|
|
395
|
-
ensureStorageRootPrivate(dir);
|
|
396
|
-
try {
|
|
397
|
-
mkdirSync(dir, { recursive: true });
|
|
398
|
-
} catch (err) {
|
|
399
|
-
if (!isEExist(err)) {
|
|
400
|
-
throw err;
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
function withRetryOnLock(fn) {
|
|
405
|
-
let lastErr;
|
|
406
|
-
for (let attempt = 1; attempt <= 5; attempt++) {
|
|
407
|
-
try {
|
|
408
|
-
fn();
|
|
409
|
-
return;
|
|
410
|
-
} catch (err) {
|
|
411
|
-
lastErr = err;
|
|
412
|
-
if (!isRetryable(err) || attempt === 5) throw err;
|
|
413
|
-
sleepSync(50 * attempt);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
throw lastErr;
|
|
417
|
-
}
|
|
418
|
-
function atomicWriteCore(dest, content) {
|
|
419
|
-
assertWriteInScope(dest);
|
|
420
|
-
const tmp = `${dest}.${process.pid}.${process.hrtime.bigint().toString()}.tmp`;
|
|
421
|
-
ensureDirSync(path4.dirname(dest));
|
|
422
|
-
try {
|
|
423
|
-
const fd = openSync(tmp, "w", 384);
|
|
424
|
-
try {
|
|
425
|
-
if (typeof content === "string") {
|
|
426
|
-
writeSync(fd, Buffer.from(content, "utf-8"));
|
|
427
|
-
} else {
|
|
428
|
-
writeSync(fd, Buffer.from(content));
|
|
429
|
-
}
|
|
430
|
-
} finally {
|
|
431
|
-
closeSync(fd);
|
|
432
|
-
}
|
|
433
|
-
try {
|
|
434
|
-
const destMode = statSync(dest).mode;
|
|
435
|
-
chmodSync(tmp, destMode);
|
|
436
|
-
} catch (e) {
|
|
437
|
-
if (e.code !== "ENOENT") throw e;
|
|
438
|
-
}
|
|
439
|
-
withRetryOnLock(() => renameSync(tmp, dest));
|
|
440
|
-
} catch (err) {
|
|
441
|
-
try {
|
|
442
|
-
unlinkSync(tmp);
|
|
443
|
-
} catch {
|
|
444
|
-
}
|
|
445
|
-
throw err;
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
function atomicWriteText(filePath, content) {
|
|
449
|
-
atomicWriteCore(filePath, content);
|
|
450
|
-
}
|
|
451
|
-
function atomicWriteBytes(filePath, content) {
|
|
452
|
-
atomicWriteCore(filePath, content);
|
|
453
|
-
}
|
|
454
|
-
function installSingleFilePlugin(filePath, sidecarPath, template) {
|
|
455
|
-
let existing;
|
|
456
|
-
try {
|
|
457
|
-
existing = readFileSync3(filePath, "utf8");
|
|
458
|
-
} catch {
|
|
459
|
-
existing = void 0;
|
|
460
|
-
}
|
|
461
|
-
const entryPath = process.argv[1];
|
|
462
|
-
if (entryPath) {
|
|
463
|
-
ensureDirSync(path4.dirname(filePath));
|
|
464
|
-
atomicWriteText(sidecarPath, JSON.stringify({ entryPath }));
|
|
465
|
-
}
|
|
466
|
-
if (existing === template) {
|
|
467
|
-
return { filePath, alreadyInstalled: true };
|
|
468
|
-
}
|
|
469
|
-
ensureDirSync(path4.dirname(filePath));
|
|
470
|
-
atomicWriteText(filePath, template);
|
|
471
|
-
return { filePath, alreadyInstalled: false };
|
|
472
|
-
}
|
|
473
|
-
function removeFileInScope(p) {
|
|
474
|
-
assertWriteInScope(p);
|
|
475
|
-
try {
|
|
476
|
-
unlinkSync(p);
|
|
477
|
-
return true;
|
|
478
|
-
} catch {
|
|
479
|
-
return false;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
function removeEmptyDirInScope(dirPath) {
|
|
483
|
-
assertWriteInScope(dirPath);
|
|
484
|
-
try {
|
|
485
|
-
const entries = readdirSync(dirPath);
|
|
486
|
-
if (entries.length === 0) {
|
|
487
|
-
rmdirSync(dirPath);
|
|
488
|
-
return true;
|
|
489
|
-
}
|
|
490
|
-
return false;
|
|
491
|
-
} catch {
|
|
492
|
-
return false;
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
function uninstallSingleFilePlugin(filePath, sidecarPath) {
|
|
496
|
-
removeFileInScope(sidecarPath);
|
|
497
|
-
return removeFileInScope(filePath);
|
|
498
|
-
}
|
|
499
|
-
var MAX_BACKUPS_PER_FILE = 5;
|
|
500
|
-
var MAX_BACKUP_NAME_ATTEMPTS = 16;
|
|
501
|
-
function backupFile(p) {
|
|
502
|
-
assertWriteInScope(p);
|
|
503
|
-
if (!existsSync2(p)) return;
|
|
504
|
-
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
505
|
-
let backupPath;
|
|
506
|
-
for (let attempt = 0; ; attempt++) {
|
|
507
|
-
backupPath = attempt === 0 ? `${p}.bak.${stamp}` : `${p}.bak.${stamp}-${attempt}`;
|
|
508
|
-
try {
|
|
509
|
-
copyFileSync(p, backupPath, fsConstants.COPYFILE_EXCL);
|
|
510
|
-
break;
|
|
511
|
-
} catch (err) {
|
|
512
|
-
if (!isEExist(err) || attempt >= MAX_BACKUP_NAME_ATTEMPTS - 1) throw err;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
recordCreatedBackup(backupPath);
|
|
516
|
-
pruneOldBackups(p);
|
|
517
|
-
}
|
|
518
|
-
function pruneOldBackups(p) {
|
|
519
|
-
const backups = createdBackupsFor(p);
|
|
520
|
-
const excess = backups.length - MAX_BACKUPS_PER_FILE;
|
|
521
|
-
for (const stalePath of backups.slice(0, Math.max(0, excess))) {
|
|
522
|
-
try {
|
|
523
|
-
removeFileInScope(stalePath);
|
|
524
|
-
forgetCreatedBackup(stalePath);
|
|
525
|
-
} catch {
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
var PER_FILE_COUNTERFACTUAL_CEILING = 1e5;
|
|
530
|
-
function cappedSourceBytesSaved(fullSourceBytes, emittedBytes) {
|
|
531
|
-
return Math.max(1, Math.min(fullSourceBytes, PER_FILE_COUNTERFACTUAL_CEILING) - emittedBytes);
|
|
532
|
-
}
|
|
533
|
-
var IDENTICAL_READ_MIN_BODY_BYTES = 512;
|
|
534
|
-
function containsLineRun(haystack, needle) {
|
|
535
|
-
const h = haystack.endsWith("\n") ? haystack.slice(0, -1) : haystack;
|
|
536
|
-
const n = needle.endsWith("\n") ? needle.slice(0, -1) : needle;
|
|
537
|
-
if (n.length === 0 || n.length > h.length) return false;
|
|
538
|
-
return ("\n" + h + "\n").includes("\n" + n + "\n");
|
|
539
|
-
}
|
|
540
|
-
var LOCK_WAIT_MS = 2e3;
|
|
541
|
-
var LOCK_STALE_MS = 5e3;
|
|
542
|
-
var LOCK_WAIT_MS_HARDENED = 15e3;
|
|
543
|
-
var LOCK_LIVE_HOLDER_MAX_MS = 6e4;
|
|
544
|
-
function lockHolderAlive(token) {
|
|
545
|
-
const pid = Number(/^(\d+):/.exec(token)?.[1]);
|
|
546
|
-
if (!Number.isSafeInteger(pid) || pid <= 0 || pid === process.pid) return false;
|
|
547
|
-
try {
|
|
548
|
-
process.kill(pid, 0);
|
|
549
|
-
return true;
|
|
550
|
-
} catch (err) {
|
|
551
|
-
return err.code === "EPERM";
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
function withFileLock(lockPath, fn, opts = {}) {
|
|
555
|
-
const waitMs = opts.waitMs ?? LOCK_WAIT_MS;
|
|
556
|
-
const staleMs = opts.staleMs ?? LOCK_STALE_MS;
|
|
557
|
-
const token = `${process.pid}:${process.hrtime.bigint().toString()}`;
|
|
558
|
-
const deadline = Date.now() + waitMs;
|
|
559
|
-
let attempt = 0;
|
|
560
|
-
for (; ; ) {
|
|
561
|
-
try {
|
|
562
|
-
writeFileSync(lockPath, token, { flag: "wx" });
|
|
563
|
-
break;
|
|
564
|
-
} catch (err) {
|
|
565
|
-
if (!isEExist(err)) return void 0;
|
|
566
|
-
}
|
|
567
|
-
let stale;
|
|
568
|
-
try {
|
|
569
|
-
const age = Date.now() - statSync(lockPath).mtimeMs;
|
|
570
|
-
stale = age > staleMs && (age > Math.max(staleMs, LOCK_LIVE_HOLDER_MAX_MS) || !lockHolderAlive(readFileSync3(lockPath, "utf8")));
|
|
571
|
-
} catch {
|
|
572
|
-
stale = true;
|
|
573
|
-
}
|
|
574
|
-
if (stale) {
|
|
575
|
-
try {
|
|
576
|
-
unlinkSync(lockPath);
|
|
577
|
-
} catch {
|
|
578
|
-
}
|
|
579
|
-
continue;
|
|
580
|
-
}
|
|
581
|
-
if (Date.now() >= deadline) return void 0;
|
|
582
|
-
sleepSync(Math.min(20 * ++attempt, 200));
|
|
583
|
-
}
|
|
584
|
-
try {
|
|
585
|
-
return fn();
|
|
586
|
-
} finally {
|
|
587
|
-
try {
|
|
588
|
-
if (readFileSync3(lockPath, "utf8") === token) unlinkSync(lockPath);
|
|
589
|
-
} catch {
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
function stripLower(s) {
|
|
594
|
-
return s.trim().toLowerCase();
|
|
595
|
-
}
|
|
596
|
-
function sanitizeIdForFilename(id, maxLen, fallback) {
|
|
597
|
-
const safe = id.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, maxLen);
|
|
598
|
-
return safe.length > 0 ? safe : fallback ?? safe;
|
|
599
|
-
}
|
|
600
|
-
function toKB(bytes) {
|
|
601
|
-
return Math.round(bytes / 1024);
|
|
602
|
-
}
|
|
603
|
-
function compileGrepMatcher(pattern) {
|
|
604
|
-
const guarded = compileGuardedRegex(pattern);
|
|
605
|
-
if (!guarded.ok) return (candidate) => candidate.includes(pattern);
|
|
606
|
-
const re = guarded.re;
|
|
607
|
-
return (candidate) => re.test(candidate);
|
|
608
|
-
}
|
|
609
|
-
function grepFilteredToEmptyNotice(preFilterCount, grep, nounSingular, nounPlural) {
|
|
610
|
-
const noun = preFilterCount === 1 ? nounSingular : nounPlural;
|
|
611
|
-
const verb = preFilterCount === 1 ? "was" : "were";
|
|
612
|
-
const pronoun = preFilterCount === 1 ? "it" : "them";
|
|
613
|
-
return ` (all ${preFilterCount} ${noun} ${verb} filtered out by --grep ${grep} -- widen or drop the filter to see ${pronoun})`;
|
|
614
|
-
}
|
|
615
|
-
function filtersFilteredToEmptyNotice(preFilterCount, activeFilters, nounSingular, nounPlural, reassurance) {
|
|
616
|
-
const noun = preFilterCount === 1 ? nounSingular : nounPlural;
|
|
617
|
-
const cause = activeFilters.length === 0 ? "the active filter" : activeFilters.join(" + ");
|
|
618
|
-
const knob = activeFilters.length > 1 ? "filters" : "filter";
|
|
619
|
-
const verb = preFilterCount === 1 ? "was" : "were";
|
|
620
|
-
const tail = reassurance === void 0 ? "" : `; ${reassurance}`;
|
|
621
|
-
return ` (all ${preFilterCount} ${noun} ${verb} filtered out by ${cause}${tail} -- widen or drop the ${knob} to see them)`;
|
|
622
|
-
}
|
|
623
|
-
function countNoun(count, singular, plural = `${singular}s`) {
|
|
624
|
-
return `${count} ${count === 1 ? singular : plural}`;
|
|
625
|
-
}
|
|
626
|
-
function excludeTestsHiddenNote(count) {
|
|
627
|
-
return `${count} in test ${count === 1 ? "file" : "files"} hidden by --exclude-tests`;
|
|
628
|
-
}
|
|
629
|
-
function countContentLines(content) {
|
|
630
|
-
if (content === "") return 0;
|
|
631
|
-
const n = content.split("\n").length;
|
|
632
|
-
return content.endsWith("\n") ? n - 1 : n;
|
|
633
|
-
}
|
|
634
|
-
function pushAll(target, items) {
|
|
635
|
-
for (const item of items) target.push(item);
|
|
636
|
-
}
|
|
637
|
-
function escapeRegExp(s) {
|
|
638
|
-
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
639
|
-
}
|
|
640
|
-
function redactUrlQuery(raw) {
|
|
641
|
-
const q = raw.indexOf("?");
|
|
642
|
-
return q === -1 ? raw : raw.slice(0, q);
|
|
643
|
-
}
|
|
644
|
-
function withExtension(filePath, format) {
|
|
645
|
-
const ext = format === "jpeg" ? ".jpg" : `.${format}`;
|
|
646
|
-
const dir = path4.dirname(filePath);
|
|
647
|
-
const base = path4.basename(filePath, path4.extname(filePath));
|
|
648
|
-
return path4.join(dir, `${base}${ext}`);
|
|
649
|
-
}
|
|
650
|
-
function ensureNewline(text) {
|
|
651
|
-
return text.endsWith("\n") ? text : text + "\n";
|
|
652
|
-
}
|
|
653
|
-
function extractErrorMessage(err, fallback = "") {
|
|
654
|
-
return err instanceof Error ? err.message : fallback || String(err);
|
|
655
|
-
}
|
|
656
|
-
function requireStrictInt(flag, raw) {
|
|
657
|
-
if (!/^-?\d+$/.test(raw)) {
|
|
658
|
-
throw new Error(`${flag} must be a number, got: "${raw}"`);
|
|
659
|
-
}
|
|
660
|
-
const n = Number.parseInt(raw, 10);
|
|
661
|
-
if (!Number.isFinite(n)) {
|
|
662
|
-
throw new Error(`${flag} must be a number, got: "${raw}"`);
|
|
663
|
-
}
|
|
664
|
-
return n;
|
|
665
|
-
}
|
|
666
|
-
function requireNonNegativeStrictInt(flag, raw) {
|
|
667
|
-
const n = requireStrictInt(flag, raw);
|
|
668
|
-
if (n < 0) {
|
|
669
|
-
throw new Error(`${flag} must be a non-negative number, got: "${raw}"`);
|
|
670
|
-
}
|
|
671
|
-
return n;
|
|
672
|
-
}
|
|
673
|
-
function requirePositiveStrictInt(flag, raw) {
|
|
674
|
-
const n = requireStrictInt(flag, raw);
|
|
675
|
-
if (n <= 0) {
|
|
676
|
-
throw new Error(`${flag} must be a positive number, got: "${raw}"`);
|
|
677
|
-
}
|
|
678
|
-
return n;
|
|
679
|
-
}
|
|
680
|
-
function isCodeFenceDelimiter(line) {
|
|
681
|
-
const s = line.trim();
|
|
682
|
-
return s.startsWith("```") || s.startsWith("~~~");
|
|
683
|
-
}
|
|
684
|
-
function pad(s, n) {
|
|
685
|
-
return s.length >= n ? s : s + " ".repeat(n - s.length);
|
|
686
|
-
}
|
|
687
|
-
function normalizePathForwardSlash(p, toLowerCase) {
|
|
688
|
-
let result = normalizePath(p).replace(/\\/g, "/");
|
|
689
|
-
if (toLowerCase) result = result.toLowerCase();
|
|
690
|
-
return result;
|
|
691
|
-
}
|
|
692
|
-
function safeSlice(str, endIndex) {
|
|
693
|
-
let idx = endIndex;
|
|
694
|
-
if (idx > 0 && idx < str.length) {
|
|
695
|
-
const codeUnit = str.charCodeAt(idx);
|
|
696
|
-
if (codeUnit >= 56320 && codeUnit <= 57343) {
|
|
697
|
-
idx--;
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
return str.slice(0, idx);
|
|
701
|
-
}
|
|
702
|
-
function isTestFile(p) {
|
|
703
|
-
return /(^|[/\\])(tests?)[/\\]/i.test(p) || /\.(test|spec)\.|_test\.|(^|[/\\])test_/i.test(p);
|
|
704
|
-
}
|
|
705
|
-
function isUnderBlockedRoot(filePath, blockedRoots) {
|
|
706
|
-
if (blockedRoots.length === 0) return false;
|
|
707
|
-
const target = foldPath(normalizePath(path4.resolve(filePath)));
|
|
708
|
-
for (const root of blockedRoots) {
|
|
709
|
-
if (!root) continue;
|
|
710
|
-
const normRoot = foldPath(normalizePath(path4.resolve(root)));
|
|
711
|
-
if (target === normRoot) return true;
|
|
712
|
-
const boundary = normRoot.endsWith("/") ? normRoot : `${normRoot}/`;
|
|
713
|
-
if (target.startsWith(boundary)) return true;
|
|
714
|
-
}
|
|
715
|
-
return false;
|
|
716
|
-
}
|
|
717
|
-
var QUIET_HOURS_RE = /^([01]\d|2[0-3]):([0-5]\d)-([01]\d|2[0-3]):([0-5]\d)$/;
|
|
718
|
-
function isWithinQuietHours(spec, now = /* @__PURE__ */ new Date()) {
|
|
719
|
-
const m = QUIET_HOURS_RE.exec(spec);
|
|
720
|
-
if (!m) return false;
|
|
721
|
-
const startMin = Number(m[1]) * 60 + Number(m[2]);
|
|
722
|
-
const endMin = Number(m[3]) * 60 + Number(m[4]);
|
|
723
|
-
const nowMin = now.getHours() * 60 + now.getMinutes();
|
|
724
|
-
if (startMin === endMin) return false;
|
|
725
|
-
if (startMin < endMin) return nowMin >= startMin && nowMin < endMin;
|
|
726
|
-
return nowMin >= startMin || nowMin < endMin;
|
|
727
|
-
}
|
|
728
|
-
function hookCommandFor(scriptPath, event) {
|
|
729
|
-
const entryPath = process.argv[1];
|
|
730
|
-
const entryArg = entryPath ? ` ${quoteShellPath(entryPath)}` : "";
|
|
731
|
-
return `${quoteShellPath(process.execPath)} ${quoteShellPath(scriptPath)} ${event}${entryArg}`;
|
|
732
|
-
}
|
|
733
|
-
function hookExecPartsFor(scriptPath, event) {
|
|
734
|
-
const entryPath = process.argv[1];
|
|
735
|
-
return { command: process.execPath, args: entryPath ? [scriptPath, event, entryPath] : [scriptPath, event] };
|
|
736
|
-
}
|
|
737
|
-
function hookPowershellCommand(scriptPath, event) {
|
|
738
|
-
const entryPath = process.argv[1];
|
|
739
|
-
const entryArg = entryPath ? ` ${quotePowershellPath(entryPath)}` : "";
|
|
740
|
-
return `${quotePowershellPath(process.execPath)} ${quotePowershellPath(scriptPath)} ${event}${entryArg}`;
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
export {
|
|
744
|
-
recordCreatedConfig,
|
|
745
|
-
hasCreatedConfig,
|
|
746
|
-
takeCreatedConfig,
|
|
747
|
-
removeCreatedBackups,
|
|
748
|
-
assertProjectScopeTarget,
|
|
749
|
-
withInstallScope,
|
|
750
|
-
projectScopeRoot,
|
|
751
|
-
assertWriteInScope,
|
|
752
|
-
projectPathIsConsultable,
|
|
753
|
-
stripOwnHooksFromMap,
|
|
754
|
-
stripStaleGroupHooks,
|
|
755
|
-
stripDelimitedBlock,
|
|
756
|
-
upsertDelimitedBlock,
|
|
757
|
-
writeJsonSettings,
|
|
758
|
-
writeIfDifferent,
|
|
759
|
-
stripBom,
|
|
760
|
-
detectSourceEncoding,
|
|
761
|
-
decodeSource,
|
|
762
|
-
encodeSource,
|
|
763
|
-
runGit,
|
|
764
|
-
statSize,
|
|
765
|
-
ensureDirSync,
|
|
766
|
-
withRetryOnLock,
|
|
767
|
-
atomicWriteText,
|
|
768
|
-
atomicWriteBytes,
|
|
769
|
-
installSingleFilePlugin,
|
|
770
|
-
removeFileInScope,
|
|
771
|
-
removeEmptyDirInScope,
|
|
772
|
-
uninstallSingleFilePlugin,
|
|
773
|
-
backupFile,
|
|
774
|
-
PER_FILE_COUNTERFACTUAL_CEILING,
|
|
775
|
-
cappedSourceBytesSaved,
|
|
776
|
-
IDENTICAL_READ_MIN_BODY_BYTES,
|
|
777
|
-
containsLineRun,
|
|
778
|
-
LOCK_WAIT_MS_HARDENED,
|
|
779
|
-
withFileLock,
|
|
780
|
-
stripLower,
|
|
781
|
-
sanitizeIdForFilename,
|
|
782
|
-
toKB,
|
|
783
|
-
compileGrepMatcher,
|
|
784
|
-
grepFilteredToEmptyNotice,
|
|
785
|
-
filtersFilteredToEmptyNotice,
|
|
786
|
-
countNoun,
|
|
787
|
-
excludeTestsHiddenNote,
|
|
788
|
-
countContentLines,
|
|
789
|
-
pushAll,
|
|
790
|
-
escapeRegExp,
|
|
791
|
-
redactUrlQuery,
|
|
792
|
-
withExtension,
|
|
793
|
-
ensureNewline,
|
|
794
|
-
extractErrorMessage,
|
|
795
|
-
requireNonNegativeStrictInt,
|
|
796
|
-
requirePositiveStrictInt,
|
|
797
|
-
isCodeFenceDelimiter,
|
|
798
|
-
pad,
|
|
799
|
-
normalizePathForwardSlash,
|
|
800
|
-
safeSlice,
|
|
801
|
-
isTestFile,
|
|
802
|
-
isUnderBlockedRoot,
|
|
803
|
-
isWithinQuietHours,
|
|
804
|
-
hookCommandFor,
|
|
805
|
-
hookExecPartsFor,
|
|
806
|
-
hookPowershellCommand
|
|
807
|
-
};
|