token-goat 2.9.28 → 2.9.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -40
- package/SECURITY.md +28 -10
- package/THIRD_PARTY_NOTICES.md +40 -3
- package/dist/native/linux-arm64/tg-hook +0 -0
- package/dist/native/linux-x64/tg-hook +0 -0
- package/dist/ort-wasm-simd-threaded.mjs +59 -0
- package/dist/token-goat-chunk-3CHUNJ2O.mjs +53 -0
- package/dist/token-goat-chunk-3Z5S4KGM.mjs +918 -0
- package/dist/token-goat-chunk-4FVIAHSI.mjs +211 -0
- package/dist/{token-goat-chunk-66LODAUT.mjs → token-goat-chunk-4JJS54TR.mjs} +4 -3
- package/dist/token-goat-chunk-4LCCNRTG.mjs +313 -0
- package/dist/token-goat-chunk-54K3EUV3.mjs +35 -0
- package/dist/token-goat-chunk-56EIMS3E.mjs +159 -0
- package/dist/token-goat-chunk-5BCIJXMO.mjs +609 -0
- package/dist/token-goat-chunk-5KDMCMF2.mjs +362 -0
- package/dist/token-goat-chunk-5RG5SBL6.mjs +221 -0
- package/dist/{token-goat-chunk-RRNZMM3A.mjs → token-goat-chunk-5Y6ZYL6U.mjs} +21 -2
- package/dist/{token-goat-chunk-NILVK7XM.mjs → token-goat-chunk-64FBPDTK.mjs} +12 -6
- package/dist/{token-goat-chunk-LEG3JNJ6.mjs → token-goat-chunk-664RTTUV.mjs} +31 -15
- package/dist/token-goat-chunk-67TQJ76B.mjs +57 -0
- package/dist/token-goat-chunk-6QMAS7AB.mjs +42 -0
- package/dist/token-goat-chunk-7BXSNBY5.mjs +253 -0
- package/dist/{token-goat-chunk-F7QZRIWM.mjs → token-goat-chunk-7F2UBPD3.mjs} +42 -35
- package/dist/{token-goat-chunk-CC2PYJM7.mjs → token-goat-chunk-7IN2MKDS.mjs} +718 -595
- package/dist/token-goat-chunk-7NADEDKJ.mjs +124 -0
- package/dist/{token-goat-chunk-6SGLIPQB.mjs → token-goat-chunk-A3CK6N5Z.mjs} +621 -72
- package/dist/{token-goat-chunk-HXNAC4ZF.mjs → token-goat-chunk-AFLYLHDH.mjs} +48 -33
- package/dist/token-goat-chunk-AM5V6GSX.mjs +367 -0
- package/dist/{token-goat-chunk-I7CB3X4K.mjs → token-goat-chunk-APGZXSPS.mjs} +44 -148
- package/dist/{token-goat-chunk-BJBRGPBX.mjs → token-goat-chunk-ARDNEC2U.mjs} +11 -7
- package/dist/token-goat-chunk-ATCPY7EQ.mjs +134 -0
- package/dist/token-goat-chunk-B2RZZCSS.mjs +354 -0
- package/dist/{token-goat-chunk-QM76S6YS.mjs → token-goat-chunk-B45VMIIH.mjs} +6 -5
- package/dist/token-goat-chunk-BPGCUMR7.mjs +30 -0
- package/dist/{token-goat-chunk-GGLEE35R.mjs → token-goat-chunk-C63JQV5K.mjs} +49 -10
- package/dist/{token-goat-chunk-RJH64KQH.mjs → token-goat-chunk-COBQGL5S.mjs} +2661 -2440
- package/dist/token-goat-chunk-COTXZHTS.mjs +39 -0
- package/dist/token-goat-chunk-CYCEYAEO.mjs +265 -0
- package/dist/token-goat-chunk-CZ3LUXYZ.mjs +4115 -0
- package/dist/token-goat-chunk-DZX2YDPT.mjs +15 -0
- package/dist/token-goat-chunk-E3OQX2XT.mjs +824 -0
- package/dist/token-goat-chunk-EFHMMIGP.mjs +68 -0
- package/dist/token-goat-chunk-ETBHVDB6.mjs +328 -0
- package/dist/token-goat-chunk-EVMZJ27Z.mjs +147 -0
- package/dist/token-goat-chunk-EXKGNHEG.mjs +2096 -0
- package/dist/{token-goat-chunk-6Z5ULNE5.mjs → token-goat-chunk-FBNQNSJK.mjs} +2490 -4957
- package/dist/{token-goat-chunk-NMTKNYGF.mjs → token-goat-chunk-FNFBKLRD.mjs} +74 -9
- package/dist/{token-goat-chunk-XI2VFAV6.mjs → token-goat-chunk-FZ3NEW5O.mjs} +33 -19
- package/dist/token-goat-chunk-G5PJ7AGM.mjs +36 -0
- package/dist/{token-goat-chunk-VE27HPIF.mjs → token-goat-chunk-GFBSN7BD.mjs} +30 -398
- package/dist/{token-goat-chunk-L45ZQRT7.mjs → token-goat-chunk-GOLEOXZP.mjs} +780 -786
- package/dist/token-goat-chunk-H2K3QP6H.mjs +24 -0
- package/dist/token-goat-chunk-H2PHHGM5.mjs +188 -0
- package/dist/token-goat-chunk-HAVAOB3S.mjs +87 -0
- package/dist/token-goat-chunk-HG45AF2B.mjs +2228 -0
- package/dist/{token-goat-chunk-CBMY2FGI.mjs → token-goat-chunk-HOJLCGDP.mjs} +17113 -15554
- package/dist/{token-goat-chunk-HUDC5GS5.mjs → token-goat-chunk-HYBFA5X3.mjs} +120 -19
- package/dist/token-goat-chunk-IVALLT3S.mjs +48 -0
- package/dist/token-goat-chunk-IVE6U7KV.mjs +53 -0
- package/dist/{token-goat-chunk-UBUKHVYW.mjs → token-goat-chunk-IVKIZWAB.mjs} +3 -3
- package/dist/{token-goat-chunk-4JMWPWCS.mjs → token-goat-chunk-JB6QN6VF.mjs} +6 -4
- package/dist/{token-goat-chunk-Q4S3UQGO.mjs → token-goat-chunk-JDHE26RP.mjs} +10 -3
- package/dist/{token-goat-chunk-7R2XYKC5.mjs → token-goat-chunk-JDU3EXSU.mjs} +14 -10
- package/dist/token-goat-chunk-JDWCRD6M.mjs +253 -0
- package/dist/{token-goat-chunk-XBESNWEX.mjs → token-goat-chunk-JN4XMLSD.mjs} +7 -4
- package/dist/token-goat-chunk-JTQQGXZH.mjs +733 -0
- package/dist/token-goat-chunk-KKUFXAPD.mjs +25 -0
- package/dist/token-goat-chunk-KQNZDCBD.mjs +47 -0
- package/dist/{token-goat-chunk-4RN64ZND.mjs → token-goat-chunk-KWPNJBDH.mjs} +28 -3
- package/dist/token-goat-chunk-LOBGHXPB.mjs +242 -0
- package/dist/token-goat-chunk-MKPF4CL5.mjs +37 -0
- package/dist/token-goat-chunk-MNWKPRAL.mjs +13 -0
- package/dist/{token-goat-chunk-YWSP6IU7.mjs → token-goat-chunk-N2NMER56.mjs} +25 -15
- package/dist/token-goat-chunk-NYKZLXMK.mjs +218 -0
- package/dist/token-goat-chunk-OJBNYTJP.mjs +3087 -0
- package/dist/token-goat-chunk-P4QMM4WK.mjs +295 -0
- package/dist/token-goat-chunk-PD5VKH46.mjs +184 -0
- package/dist/token-goat-chunk-PEPTHRFF.mjs +129 -0
- package/dist/{token-goat-chunk-VWZKZPSR.mjs → token-goat-chunk-PU7V3FD6.mjs} +8752 -11098
- package/dist/token-goat-chunk-PY533T7F.mjs +46 -0
- package/dist/token-goat-chunk-Q5VTGRH7.mjs +761 -0
- package/dist/{token-goat-chunk-IHKZ3QNA.mjs → token-goat-chunk-QCLDAQTS.mjs} +33 -19
- package/dist/{token-goat-chunk-LKSXAMJB.mjs → token-goat-chunk-QSBRTGM2.mjs} +9 -2
- package/dist/{token-goat-chunk-4STDIGYC.mjs → token-goat-chunk-RC35RBUL.mjs} +7 -5
- package/dist/{token-goat-chunk-D5ICEPSB.mjs → token-goat-chunk-RHXKCZX3.mjs} +887 -507
- package/dist/{token-goat-chunk-RSS3TLXU.mjs → token-goat-chunk-RZRTDST7.mjs} +17 -7
- package/dist/{token-goat-chunk-MAMQPC43.mjs → token-goat-chunk-SJHWVNDQ.mjs} +15 -21
- package/dist/token-goat-chunk-SMVRN2HU.mjs +188 -0
- package/dist/{token-goat-chunk-EL7M26WP.mjs → token-goat-chunk-SQSSNQPE.mjs} +2100 -1442
- package/dist/{token-goat-chunk-OZRSREKR.mjs → token-goat-chunk-T4FK7VOV.mjs} +3 -3
- package/dist/token-goat-chunk-U4N3BN2W.mjs +92 -0
- package/dist/token-goat-chunk-UA5V6P3P.mjs +122 -0
- package/dist/{token-goat-chunk-XKY4VKJ4.mjs → token-goat-chunk-UQ5UK2T7.mjs} +15 -4
- package/dist/token-goat-chunk-USILZ3T3.mjs +53 -0
- package/dist/token-goat-chunk-VES7EL7O.mjs +205 -0
- package/dist/{token-goat-chunk-M56BWPBN.mjs → token-goat-chunk-VL3YIFHZ.mjs} +550 -49
- package/dist/{token-goat-chunk-IZXKVT4A.mjs → token-goat-chunk-VPBBTSJR.mjs} +362 -128
- package/dist/{token-goat-chunk-F2ARFHLJ.mjs → token-goat-chunk-W3QCJS6G.mjs} +10 -2
- package/dist/{token-goat-chunk-FSTWAOW6.mjs → token-goat-chunk-WY3L4DVT.mjs} +11 -5
- package/dist/{token-goat-chunk-OSUFN2FV.mjs → token-goat-chunk-XB5KKOCG.mjs} +5 -25
- package/dist/token-goat-chunk-XKI4SEMX.mjs +66 -0
- package/dist/token-goat-chunk-XU4P6Z24.mjs +133 -0
- package/dist/{token-goat-chunk-6CCQDAYY.mjs → token-goat-chunk-Y776AENC.mjs} +138 -33
- package/dist/token-goat-chunk-YARZFCZS.mjs +359 -0
- package/dist/{token-goat-chunk-EEIDFMEM.mjs → token-goat-chunk-YZAAZU2S.mjs} +12 -3
- package/dist/{token-goat-chunk-E3K3BTEQ.mjs → token-goat-chunk-Z44YO3QZ.mjs} +12 -6
- package/dist/token-goat-chunk-Z57YODA2.mjs +35 -0
- package/dist/{token-goat-chunk-DA43OE7L.mjs → token-goat-chunk-ZCDTCVIS.mjs} +49 -30
- package/dist/token-goat-chunk-ZEJVMUQH.mjs +48 -0
- package/dist/{token-goat-chunk-BGHSSJUA.mjs → token-goat-chunk-ZFOBKUWH.mjs} +1 -1
- package/dist/token-goat-chunk-ZMBL6UVV.mjs +110 -0
- package/dist/{token-goat-chunk-SJEKA7Y2.mjs → token-goat-chunk-ZQSJMO2R.mjs} +381 -201
- package/dist/token-goat-hook-client.cjs +539 -0
- package/dist/token-goat-hook-client.mjs +26 -0
- package/dist/token-goat-hook.mjs +48 -28
- package/dist/token-goat.core.mjs +10 -45
- package/docs/C4_RUNTIME_ARCHITECTURE.md +3 -3
- package/docs/cli.md +82 -47
- package/docs/install.md +58 -23
- package/docs/security.md +7 -7
- package/package.json +17 -7
- package/scripts/verify-native-dist.mjs +386 -0
- package/dist/token-goat-chunk-4JJBFT7V.mjs +0 -20
- package/dist/token-goat-chunk-5NNYIUGV.mjs +0 -143
- package/dist/token-goat-chunk-6DQNNFJ6.mjs +0 -294
- package/dist/token-goat-chunk-7MAFDRVR.mjs +0 -47
- package/dist/token-goat-chunk-BCN2YQC6.mjs +0 -32
- package/dist/token-goat-chunk-D7GHQKQD.mjs +0 -30
- package/dist/token-goat-chunk-GMOUBOX4.mjs +0 -386
- package/dist/token-goat-chunk-IFORDBGC.mjs +0 -192
- package/dist/token-goat-chunk-JXK2HQXS.mjs +0 -318
- package/dist/token-goat-chunk-L7SDVGBT.mjs +0 -430
- package/dist/token-goat-chunk-MMLMALWK.mjs +0 -1381
- package/dist/token-goat-chunk-MVSWBNMD.mjs +0 -1985
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
|
+
const require = __cjsRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
loadConfig
|
|
5
|
+
} from "./token-goat-chunk-7IN2MKDS.mjs";
|
|
6
|
+
import {
|
|
7
|
+
ensureDirSync
|
|
8
|
+
} from "./token-goat-chunk-GOLEOXZP.mjs";
|
|
9
|
+
import {
|
|
10
|
+
displaySafeJson
|
|
11
|
+
} from "./token-goat-chunk-FNFBKLRD.mjs";
|
|
12
|
+
import {
|
|
13
|
+
VERSION,
|
|
14
|
+
dataDir
|
|
15
|
+
} from "./token-goat-chunk-VES7EL7O.mjs";
|
|
16
|
+
import {
|
|
17
|
+
init_define_import_meta_env
|
|
18
|
+
} from "./token-goat-chunk-A37V4PBF.mjs";
|
|
19
|
+
|
|
20
|
+
// src/cli_upgrade.ts
|
|
21
|
+
init_define_import_meta_env();
|
|
22
|
+
import { spawnSync } from "node:child_process";
|
|
23
|
+
import * as fs from "node:fs";
|
|
24
|
+
import * as path from "node:path";
|
|
25
|
+
import * as https from "node:https";
|
|
26
|
+
import { createRequire } from "node:module";
|
|
27
|
+
import { fileURLToPath } from "node:url";
|
|
28
|
+
var require2 = createRequire(import.meta.url);
|
|
29
|
+
var UPDATE_CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
30
|
+
var SEMVER = /^\d+\.\d+\.\d+(?:-[\w.-]+)?$/;
|
|
31
|
+
var FAILED_CHECK_TTL_MS = 60 * 60 * 1e3;
|
|
32
|
+
function getCachedUpdateStatus() {
|
|
33
|
+
try {
|
|
34
|
+
const cachePath = path.join(dataDir(), "update_check.json");
|
|
35
|
+
if (!fs.existsSync(cachePath)) return null;
|
|
36
|
+
const raw = fs.readFileSync(cachePath, "utf8");
|
|
37
|
+
const parsed = JSON.parse(raw);
|
|
38
|
+
if (parsed && typeof parsed.checkedAt === "number") {
|
|
39
|
+
const latest = typeof parsed.latest === "string" && SEMVER.test(parsed.latest) ? parsed.latest : null;
|
|
40
|
+
return { checkedAt: parsed.checkedAt, current: VERSION, latest, updateAvailable: latest !== null && compareSemver(latest, VERSION) > 0, error: latest === null && typeof parsed.error === "string" ? parsed.error : void 0 };
|
|
41
|
+
}
|
|
42
|
+
} catch {
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
function saveCachedUpdateStatus(info) {
|
|
47
|
+
try {
|
|
48
|
+
const dir = dataDir();
|
|
49
|
+
ensureDirSync(dir);
|
|
50
|
+
const cachePath = path.join(dir, "update_check.json");
|
|
51
|
+
fs.writeFileSync(cachePath, JSON.stringify(info, null, 2), "utf8");
|
|
52
|
+
} catch {
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function getRegistryUrl() {
|
|
56
|
+
const envRegistry = process.env["NPM_CONFIG_REGISTRY"] || process.env["npm_config_registry"];
|
|
57
|
+
if (envRegistry && typeof envRegistry === "string") {
|
|
58
|
+
return envRegistry.endsWith("/") ? envRegistry : `${envRegistry}/`;
|
|
59
|
+
}
|
|
60
|
+
return "https://registry.npmjs.org/";
|
|
61
|
+
}
|
|
62
|
+
function npmInvocation(host) {
|
|
63
|
+
const named = host.env["npm_execpath"];
|
|
64
|
+
if (typeof named === "string" && /(?:^|[\\/])npm-cli\.js$/.test(named) && host.exists(named)) return { file: host.execPath, prefix: [named] };
|
|
65
|
+
if (host.platform !== "win32") return { file: "npm", prefix: [] };
|
|
66
|
+
const bundled = path.win32.join(path.win32.dirname(host.execPath), "node_modules", "npm", "bin", "npm-cli.js");
|
|
67
|
+
return host.exists(bundled) ? { file: host.execPath, prefix: [bundled] } : null;
|
|
68
|
+
}
|
|
69
|
+
function hostNpm() {
|
|
70
|
+
return npmInvocation({ platform: process.platform, env: process.env, execPath: process.execPath, exists: (p) => fs.existsSync(p) });
|
|
71
|
+
}
|
|
72
|
+
function runningPackageRoot(moduleUrl = import.meta.url) {
|
|
73
|
+
let dir;
|
|
74
|
+
try {
|
|
75
|
+
dir = fs.realpathSync(path.dirname(fileURLToPath(moduleUrl)));
|
|
76
|
+
} catch {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
for (; ; ) {
|
|
80
|
+
try {
|
|
81
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(dir, "package.json"), "utf8"));
|
|
82
|
+
if (pkg.name === "token-goat") return dir;
|
|
83
|
+
} catch {
|
|
84
|
+
}
|
|
85
|
+
const parent = path.dirname(dir);
|
|
86
|
+
if (parent === dir) return null;
|
|
87
|
+
dir = parent;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function isDevCheckout(root) {
|
|
91
|
+
return root !== null && fs.existsSync(path.join(root, ".git")) && fs.existsSync(path.join(root, "esbuild.config.mjs"));
|
|
92
|
+
}
|
|
93
|
+
function upgradeDecision(status, offline, devCheckout) {
|
|
94
|
+
if (offline) return "offline";
|
|
95
|
+
if (status.error || !status.latest) return "unreachable";
|
|
96
|
+
if (!status.updateAvailable) return "up-to-date";
|
|
97
|
+
if (devCheckout) return "dev-checkout";
|
|
98
|
+
return "install";
|
|
99
|
+
}
|
|
100
|
+
function currentUpgradeDecision(status) {
|
|
101
|
+
return upgradeDecision(status, loadConfig().network.offline, isDevCheckout(runningPackageRoot()));
|
|
102
|
+
}
|
|
103
|
+
var DEV_CHECKOUT_ADVICE = "git pull && npm run build && token-goat install";
|
|
104
|
+
function updateAdvice(decision) {
|
|
105
|
+
if (decision === "install") return "Run 'token-goat upgrade' to update.";
|
|
106
|
+
if (decision === "dev-checkout") return `This token-goat runs from a development checkout. To update it, run: ${DEV_CHECKOUT_ADVICE}`;
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
function fetchViaNpm(timeoutMs = 2500) {
|
|
110
|
+
const npm = hostNpm();
|
|
111
|
+
if (!npm) return null;
|
|
112
|
+
try {
|
|
113
|
+
const res = spawnSync(npm.file, [...npm.prefix, "view", "token-goat", "version"], {
|
|
114
|
+
encoding: "utf8",
|
|
115
|
+
timeout: timeoutMs,
|
|
116
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
117
|
+
windowsHide: true
|
|
118
|
+
});
|
|
119
|
+
if (res.status === 0 && res.stdout) {
|
|
120
|
+
const trimmed = res.stdout.trim();
|
|
121
|
+
if (SEMVER.test(trimmed)) {
|
|
122
|
+
return trimmed;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
} catch {
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
async function fetchViaHttp(registryUrl, timeoutMs = 3500) {
|
|
130
|
+
return new Promise((resolve) => {
|
|
131
|
+
try {
|
|
132
|
+
const cleanUrl = registryUrl.endsWith("/") ? registryUrl : `${registryUrl}/`;
|
|
133
|
+
const targetUrl = new URL(`token-goat/latest`, cleanUrl);
|
|
134
|
+
const isHttps = targetUrl.protocol === "https:";
|
|
135
|
+
const getFn = isHttps ? https.get : require2("node:http").get;
|
|
136
|
+
const req = getFn(
|
|
137
|
+
targetUrl,
|
|
138
|
+
{
|
|
139
|
+
headers: { "User-Agent": `token-goat/${VERSION} (node/${process.version})` },
|
|
140
|
+
timeout: timeoutMs
|
|
141
|
+
},
|
|
142
|
+
(res) => {
|
|
143
|
+
if (res.statusCode !== 200) {
|
|
144
|
+
res.resume();
|
|
145
|
+
resolve(null);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
let data = "";
|
|
149
|
+
res.setEncoding("utf8");
|
|
150
|
+
res.on("data", (chunk) => {
|
|
151
|
+
data += chunk;
|
|
152
|
+
if (data.length > 32768) {
|
|
153
|
+
req.destroy();
|
|
154
|
+
resolve(null);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
res.on("end", () => {
|
|
158
|
+
try {
|
|
159
|
+
const parsed = JSON.parse(data);
|
|
160
|
+
const version = parsed.version || parsed["dist-tags"]?.latest;
|
|
161
|
+
if (version && typeof version === "string" && SEMVER.test(version)) {
|
|
162
|
+
resolve(version);
|
|
163
|
+
} else {
|
|
164
|
+
resolve(null);
|
|
165
|
+
}
|
|
166
|
+
} catch {
|
|
167
|
+
resolve(null);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
);
|
|
172
|
+
req.on("timeout", () => {
|
|
173
|
+
req.destroy();
|
|
174
|
+
resolve(null);
|
|
175
|
+
});
|
|
176
|
+
req.on("error", () => {
|
|
177
|
+
resolve(null);
|
|
178
|
+
});
|
|
179
|
+
} catch {
|
|
180
|
+
resolve(null);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
async function fetchLatestVersion(timeoutMs = 3500) {
|
|
185
|
+
if (loadConfig().network.offline) {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
const npmVersion = fetchViaNpm(Math.min(timeoutMs, 2500));
|
|
189
|
+
if (npmVersion) {
|
|
190
|
+
return npmVersion;
|
|
191
|
+
}
|
|
192
|
+
const registryUrl = getRegistryUrl();
|
|
193
|
+
return fetchViaHttp(registryUrl, timeoutMs);
|
|
194
|
+
}
|
|
195
|
+
function compareSemver(a, b) {
|
|
196
|
+
const pa = a.split("-")[0].split(".").map((x) => parseInt(x, 10) || 0);
|
|
197
|
+
const pb = b.split("-")[0].split(".").map((x) => parseInt(x, 10) || 0);
|
|
198
|
+
for (let i = 0; i < 3; i++) {
|
|
199
|
+
const na = pa[i] ?? 0;
|
|
200
|
+
const nb = pb[i] ?? 0;
|
|
201
|
+
if (na > nb) return 1;
|
|
202
|
+
if (na < nb) return -1;
|
|
203
|
+
}
|
|
204
|
+
return 0;
|
|
205
|
+
}
|
|
206
|
+
async function checkUpdateStatus(timeoutMs = 3500, forceFresh = false) {
|
|
207
|
+
if (!forceFresh) {
|
|
208
|
+
const cached = getCachedUpdateStatus();
|
|
209
|
+
if (cached && Date.now() - cached.checkedAt < (cached.latest ? UPDATE_CACHE_TTL_MS : FAILED_CHECK_TTL_MS)) {
|
|
210
|
+
return { current: VERSION, latest: cached.latest, updateAvailable: cached.updateAvailable, error: cached.error };
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
const latest = await fetchLatestVersion(timeoutMs);
|
|
214
|
+
if (!latest) {
|
|
215
|
+
if (loadConfig().network.offline) {
|
|
216
|
+
return { current: VERSION, latest: null, updateAvailable: false, error: "network.offline is set, so no update check was made" };
|
|
217
|
+
}
|
|
218
|
+
const result2 = {
|
|
219
|
+
current: VERSION,
|
|
220
|
+
latest: null,
|
|
221
|
+
updateAvailable: false,
|
|
222
|
+
error: "Could not reach npm or internal registry (request failed or timed out)"
|
|
223
|
+
};
|
|
224
|
+
saveCachedUpdateStatus({
|
|
225
|
+
checkedAt: Date.now(),
|
|
226
|
+
current: VERSION,
|
|
227
|
+
latest: null,
|
|
228
|
+
updateAvailable: false,
|
|
229
|
+
error: result2.error
|
|
230
|
+
});
|
|
231
|
+
return result2;
|
|
232
|
+
}
|
|
233
|
+
const updateAvailable = compareSemver(latest, VERSION) > 0;
|
|
234
|
+
const result = {
|
|
235
|
+
current: VERSION,
|
|
236
|
+
latest,
|
|
237
|
+
updateAvailable
|
|
238
|
+
};
|
|
239
|
+
saveCachedUpdateStatus({
|
|
240
|
+
checkedAt: Date.now(),
|
|
241
|
+
current: VERSION,
|
|
242
|
+
latest,
|
|
243
|
+
updateAvailable
|
|
244
|
+
});
|
|
245
|
+
return result;
|
|
246
|
+
}
|
|
247
|
+
async function cmdUpgrade(opts = {}, onSyncHooks) {
|
|
248
|
+
const status = await checkUpdateStatus(3500, true);
|
|
249
|
+
if (opts.check) {
|
|
250
|
+
if (opts.json) {
|
|
251
|
+
console.log(displaySafeJson(status, 2));
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
if (status.error) {
|
|
255
|
+
console.log(`Current version: v${status.current}`);
|
|
256
|
+
console.log(`[!] ${status.error}`);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (status.updateAvailable && status.latest) {
|
|
260
|
+
console.log(`Update available: v${status.current} -> v${status.latest}`);
|
|
261
|
+
console.log(`Run 'token-goat upgrade' to update.`);
|
|
262
|
+
} else {
|
|
263
|
+
console.log(`token-goat is up to date (v${status.current})`);
|
|
264
|
+
}
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
const decision = currentUpgradeDecision(status);
|
|
268
|
+
switch (decision) {
|
|
269
|
+
case "offline":
|
|
270
|
+
console.error(`token-goat: network.offline is set, so no update check was made and nothing was installed. Unset it (or TOKEN_GOAT_OFFLINE) to upgrade.`);
|
|
271
|
+
process.exitCode = 1;
|
|
272
|
+
return;
|
|
273
|
+
case "unreachable":
|
|
274
|
+
console.error(`token-goat: ${status.error ?? "could not determine the latest version"}. Nothing was installed.`);
|
|
275
|
+
process.exitCode = 1;
|
|
276
|
+
return;
|
|
277
|
+
case "up-to-date":
|
|
278
|
+
console.log(`token-goat is up to date (v${status.current})`);
|
|
279
|
+
return;
|
|
280
|
+
case "dev-checkout":
|
|
281
|
+
console.log(`Update available: v${status.current} -> v${status.latest}`);
|
|
282
|
+
console.log(`This token-goat runs from a development checkout, so it was not replaced. To update it, run:`);
|
|
283
|
+
console.log(` ${DEV_CHECKOUT_ADVICE}`);
|
|
284
|
+
return;
|
|
285
|
+
case "install":
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
console.log(`Upgrading token-goat v${status.current} -> v${status.latest}...`);
|
|
289
|
+
const outcome = await performUpgrade(onSyncHooks);
|
|
290
|
+
if (!outcome.ok) {
|
|
291
|
+
console.error(`token-goat: ${outcome.message}`);
|
|
292
|
+
process.exitCode = 1;
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
console.log(`[\u2713] token-goat successfully updated.`);
|
|
296
|
+
}
|
|
297
|
+
var MANUAL_INSTALL = "npm install -g token-goat@latest";
|
|
298
|
+
async function performUpgrade(onSyncHooks, npm = hostNpm()) {
|
|
299
|
+
if (!npm) return { ok: false, message: `npm was not found next to this Node.js, so token-goat could not upgrade itself. Run '${MANUAL_INSTALL}' yourself.` };
|
|
300
|
+
try {
|
|
301
|
+
const { stopWorker } = await import("./token-goat-chunk-KQNZDCBD.mjs");
|
|
302
|
+
const { queryServers } = await import("./token-goat-hook-client.mjs");
|
|
303
|
+
await queryServers("stop");
|
|
304
|
+
stopWorker();
|
|
305
|
+
} catch {
|
|
306
|
+
}
|
|
307
|
+
const install = spawnSync(npm.file, [...npm.prefix, "install", "-g", "token-goat@latest"], { stdio: "inherit", windowsHide: true });
|
|
308
|
+
if (install.status !== 0) {
|
|
309
|
+
const why = install.error ? install.error.message : `exit code ${install.status ?? "unknown"}`;
|
|
310
|
+
return { ok: false, message: `npm install failed (${why}). If npm reported EPERM or EBUSY, another program still has token-goat's files open: close running agent sessions and run '${MANUAL_INSTALL}'.` };
|
|
311
|
+
}
|
|
312
|
+
console.log(`Syncing token-goat hooks and integration manifests...`);
|
|
313
|
+
const launcher = installedLauncher(npm);
|
|
314
|
+
if (launcher) {
|
|
315
|
+
const sync = spawnSync(process.execPath, [launcher, "install"], { stdio: "inherit", windowsHide: true });
|
|
316
|
+
if (sync.status !== 0) return { ok: false, message: `the new version installed, but 'token-goat install' failed (exit code ${sync.status ?? "unknown"}). Run 'token-goat install' to finish.` };
|
|
317
|
+
return { ok: true };
|
|
318
|
+
}
|
|
319
|
+
try {
|
|
320
|
+
if (onSyncHooks) await onSyncHooks();
|
|
321
|
+
} catch (e) {
|
|
322
|
+
return { ok: false, message: `the new version installed, but syncing hooks failed (${e instanceof Error ? e.message : String(e)}). Run 'token-goat install' to finish.` };
|
|
323
|
+
}
|
|
324
|
+
return { ok: true };
|
|
325
|
+
}
|
|
326
|
+
function installedLauncher(npm) {
|
|
327
|
+
const res = spawnSync(npm.file, [...npm.prefix, "root", "-g"], { encoding: "utf8", timeout: 1e4, stdio: ["ignore", "pipe", "ignore"], windowsHide: true });
|
|
328
|
+
const root = res.status === 0 && typeof res.stdout === "string" ? res.stdout.trim() : "";
|
|
329
|
+
if (!root) return null;
|
|
330
|
+
const launcher = path.join(root, "token-goat", "dist", "token-goat.mjs");
|
|
331
|
+
return fs.existsSync(launcher) ? launcher : null;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export {
|
|
335
|
+
UPDATE_CACHE_TTL_MS,
|
|
336
|
+
FAILED_CHECK_TTL_MS,
|
|
337
|
+
getCachedUpdateStatus,
|
|
338
|
+
saveCachedUpdateStatus,
|
|
339
|
+
getRegistryUrl,
|
|
340
|
+
npmInvocation,
|
|
341
|
+
runningPackageRoot,
|
|
342
|
+
isDevCheckout,
|
|
343
|
+
upgradeDecision,
|
|
344
|
+
currentUpgradeDecision,
|
|
345
|
+
DEV_CHECKOUT_ADVICE,
|
|
346
|
+
updateAdvice,
|
|
347
|
+
fetchViaNpm,
|
|
348
|
+
fetchViaHttp,
|
|
349
|
+
fetchLatestVersion,
|
|
350
|
+
compareSemver,
|
|
351
|
+
checkUpdateStatus,
|
|
352
|
+
cmdUpgrade,
|
|
353
|
+
performUpgrade
|
|
354
|
+
};
|
|
@@ -5,14 +5,15 @@ import {
|
|
|
5
5
|
docxTables,
|
|
6
6
|
docxText,
|
|
7
7
|
formatDocxTables
|
|
8
|
-
} from "./token-goat-chunk-
|
|
9
|
-
import "./token-goat-chunk-
|
|
8
|
+
} from "./token-goat-chunk-UQ5UK2T7.mjs";
|
|
9
|
+
import "./token-goat-chunk-IVKIZWAB.mjs";
|
|
10
10
|
import "./token-goat-chunk-XTQAOTSO.mjs";
|
|
11
11
|
import "./token-goat-chunk-AH6QILZM.mjs";
|
|
12
|
-
import "./token-goat-chunk-L45ZQRT7.mjs";
|
|
13
|
-
import "./token-goat-chunk-NMTKNYGF.mjs";
|
|
14
12
|
import "./token-goat-chunk-Y4AFKTHK.mjs";
|
|
15
|
-
import "./token-goat-chunk-
|
|
13
|
+
import "./token-goat-chunk-GOLEOXZP.mjs";
|
|
14
|
+
import "./token-goat-chunk-AM5V6GSX.mjs";
|
|
15
|
+
import "./token-goat-chunk-FNFBKLRD.mjs";
|
|
16
|
+
import "./token-goat-chunk-VES7EL7O.mjs";
|
|
16
17
|
import "./token-goat-chunk-A37V4PBF.mjs";
|
|
17
18
|
export {
|
|
18
19
|
docxOutline,
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
|
+
const require = __cjsRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
init_define_import_meta_env
|
|
5
|
+
} from "./token-goat-chunk-A37V4PBF.mjs";
|
|
6
|
+
|
|
7
|
+
// src/claude_config_dir.ts
|
|
8
|
+
init_define_import_meta_env();
|
|
9
|
+
import * as os from "node:os";
|
|
10
|
+
import * as path from "node:path";
|
|
11
|
+
function claudeConfigDir(homeDir = os.homedir()) {
|
|
12
|
+
const override = process.env["CLAUDE_CONFIG_DIR"];
|
|
13
|
+
if (override !== void 0 && override !== "") return override;
|
|
14
|
+
return path.join(homeDir, ".claude");
|
|
15
|
+
}
|
|
16
|
+
function claudeGlobalJsonPath(homeDir = os.homedir()) {
|
|
17
|
+
const override = process.env["CLAUDE_CONFIG_DIR"];
|
|
18
|
+
return path.join(override !== void 0 && override !== "" ? override : homeDir, ".claude.json");
|
|
19
|
+
}
|
|
20
|
+
function projectTranscriptsDir(projectRoot) {
|
|
21
|
+
const rootStr = path.resolve(projectRoot);
|
|
22
|
+
const slug = rootStr.replace(/[^A-Za-z0-9]/g, "-");
|
|
23
|
+
return path.join(claudeConfigDir(), "projects", slug);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
claudeConfigDir,
|
|
28
|
+
claudeGlobalJsonPath,
|
|
29
|
+
projectTranscriptsDir
|
|
30
|
+
};
|
|
@@ -2,19 +2,20 @@ import { createRequire as __cjsRequire } from 'node:module';
|
|
|
2
2
|
const require = __cjsRequire(import.meta.url);
|
|
3
3
|
import {
|
|
4
4
|
redactSecrets
|
|
5
|
-
} from "./token-goat-chunk-
|
|
5
|
+
} from "./token-goat-chunk-4FVIAHSI.mjs";
|
|
6
6
|
import {
|
|
7
7
|
shortFingerprint
|
|
8
|
-
} from "./token-goat-chunk-
|
|
8
|
+
} from "./token-goat-chunk-7IN2MKDS.mjs";
|
|
9
9
|
import {
|
|
10
10
|
registerReset
|
|
11
|
-
} from "./token-goat-chunk-
|
|
11
|
+
} from "./token-goat-chunk-YZAAZU2S.mjs";
|
|
12
12
|
import {
|
|
13
13
|
foldPath
|
|
14
|
-
} from "./token-goat-chunk-
|
|
14
|
+
} from "./token-goat-chunk-AM5V6GSX.mjs";
|
|
15
15
|
import {
|
|
16
|
+
hostPathOfIndexKey,
|
|
16
17
|
normalizePath
|
|
17
|
-
} from "./token-goat-chunk-
|
|
18
|
+
} from "./token-goat-chunk-FNFBKLRD.mjs";
|
|
18
19
|
import {
|
|
19
20
|
init_define_import_meta_env
|
|
20
21
|
} from "./token-goat-chunk-A37V4PBF.mjs";
|
|
@@ -47,11 +48,13 @@ var _compactedAt = 0;
|
|
|
47
48
|
var _cliReads = /* @__PURE__ */ new Set();
|
|
48
49
|
var _pendingLargeFileHints = /* @__PURE__ */ new Map();
|
|
49
50
|
var _pendingLargeFileHintsAtLoad = /* @__PURE__ */ new Map();
|
|
51
|
+
var _bashStartCwds = /* @__PURE__ */ new Map();
|
|
52
|
+
var _bashStartCwdsAtLoad = /* @__PURE__ */ new Map();
|
|
50
53
|
var _sessionId = null;
|
|
51
54
|
var _transcriptPath = null;
|
|
52
55
|
function fileSize(absPath) {
|
|
53
56
|
try {
|
|
54
|
-
return fs.statSync(absPath).size;
|
|
57
|
+
return fs.statSync(hostPathOfIndexKey(absPath)).size;
|
|
55
58
|
} catch {
|
|
56
59
|
return 0;
|
|
57
60
|
}
|
|
@@ -153,6 +156,7 @@ function markCompacted(now = Date.now()) {
|
|
|
153
156
|
_compactedAt = now;
|
|
154
157
|
_fileLineRanges = /* @__PURE__ */ new Map();
|
|
155
158
|
_fileServedOutputs = /* @__PURE__ */ new Map();
|
|
159
|
+
_cliReads = /* @__PURE__ */ new Set();
|
|
156
160
|
}
|
|
157
161
|
function getSessionFileEntry(filePath) {
|
|
158
162
|
return _files.get(resolveFilesKey(normalizePath(filePath)));
|
|
@@ -194,6 +198,31 @@ function consumedPendingLargeFileHintKeys() {
|
|
|
194
198
|
function pendingLargeFileHintsAtLoad() {
|
|
195
199
|
return _pendingLargeFileHintsAtLoad;
|
|
196
200
|
}
|
|
201
|
+
var MAX_BASH_START_CWDS = 32;
|
|
202
|
+
function recordBashStartCwd(toolUseId, cwd) {
|
|
203
|
+
_bashStartCwds.delete(toolUseId);
|
|
204
|
+
_bashStartCwds.set(toolUseId, cwd);
|
|
205
|
+
for (const oldest of _bashStartCwds.keys()) {
|
|
206
|
+
if (_bashStartCwds.size <= MAX_BASH_START_CWDS) break;
|
|
207
|
+
_bashStartCwds.delete(oldest);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function takeBashStartCwd(toolUseId) {
|
|
211
|
+
const cwd = _bashStartCwds.get(toolUseId);
|
|
212
|
+
if (cwd === void 0) return null;
|
|
213
|
+
_bashStartCwds.delete(toolUseId);
|
|
214
|
+
return cwd;
|
|
215
|
+
}
|
|
216
|
+
function bashStartCwdsAtLoad() {
|
|
217
|
+
return _bashStartCwdsAtLoad;
|
|
218
|
+
}
|
|
219
|
+
function consumedBashStartCwdKeys() {
|
|
220
|
+
const consumed = [];
|
|
221
|
+
for (const key of _bashStartCwdsAtLoad.keys()) {
|
|
222
|
+
if (!_bashStartCwds.has(key)) consumed.push(key);
|
|
223
|
+
}
|
|
224
|
+
return consumed;
|
|
225
|
+
}
|
|
197
226
|
var WEB_FETCH_KEY_SEP = "\0";
|
|
198
227
|
function webFetchKey(url, prompt) {
|
|
199
228
|
const digest = shortFingerprint(`${url}${WEB_FETCH_KEY_SEP}${prompt}`);
|
|
@@ -327,7 +356,7 @@ function consumedFileServedOutputKeys() {
|
|
|
327
356
|
var MAX_RANGES_PER_FILE = 64;
|
|
328
357
|
function statIdentity(absPath) {
|
|
329
358
|
try {
|
|
330
|
-
const st = fs.statSync(absPath);
|
|
359
|
+
const st = fs.statSync(hostPathOfIndexKey(absPath));
|
|
331
360
|
return { size: st.size, mtimeMs: st.mtimeMs };
|
|
332
361
|
} catch {
|
|
333
362
|
return void 0;
|
|
@@ -399,9 +428,9 @@ function generateSessionId() {
|
|
|
399
428
|
}
|
|
400
429
|
}
|
|
401
430
|
function getSessionId() {
|
|
402
|
-
if (_sessionId !== null) return _sessionId;
|
|
403
431
|
const fromEnv = process.env["CLAUDE_CODE_SESSION_ID"];
|
|
404
|
-
|
|
432
|
+
if (fromEnv !== void 0 && fromEnv !== "") return fromEnv;
|
|
433
|
+
_sessionId ??= generateSessionId();
|
|
405
434
|
return _sessionId;
|
|
406
435
|
}
|
|
407
436
|
function setTranscriptPath(path, sessionId) {
|
|
@@ -425,6 +454,7 @@ function exportSessionState() {
|
|
|
425
454
|
..._fileServedOutputs.size > 0 ? { fileServedOutputs: Array.from(_fileServedOutputs.entries()) } : {},
|
|
426
455
|
cliReads: Array.from(_cliReads),
|
|
427
456
|
pendingLargeFileHints: Array.from(_pendingLargeFileHints.entries()),
|
|
457
|
+
..._bashStartCwds.size > 0 ? { bashStartCwds: Array.from(_bashStartCwds.entries()) } : {},
|
|
428
458
|
grepQueries: Array.from(_grepQueries.entries()),
|
|
429
459
|
globQueries: Array.from(_globQueries.entries()),
|
|
430
460
|
outstandingAgentSpawns: _outstandingAgentSpawns.map((e) => [e.prompt, e.ts]),
|
|
@@ -454,6 +484,8 @@ function importSessionState(s) {
|
|
|
454
484
|
_cliReads = new Set(s.cliReads ?? []);
|
|
455
485
|
_pendingLargeFileHints = new Map(s.pendingLargeFileHints ?? []);
|
|
456
486
|
_pendingLargeFileHintsAtLoad = new Map(_pendingLargeFileHints);
|
|
487
|
+
_bashStartCwds = new Map(s.bashStartCwds ?? []);
|
|
488
|
+
_bashStartCwdsAtLoad = new Map(_bashStartCwds);
|
|
457
489
|
_grepQueries = new Map(s.grepQueries ?? []);
|
|
458
490
|
_globQueries = new Map(s.globQueries ?? []);
|
|
459
491
|
_outstandingAgentSpawns = (s.outstandingAgentSpawns ?? []).map(([prompt, ts]) => ({ prompt, ts }));
|
|
@@ -480,6 +512,8 @@ registerReset(() => {
|
|
|
480
512
|
_cliReads = /* @__PURE__ */ new Set();
|
|
481
513
|
_pendingLargeFileHints = /* @__PURE__ */ new Map();
|
|
482
514
|
_pendingLargeFileHintsAtLoad = /* @__PURE__ */ new Map();
|
|
515
|
+
_bashStartCwds = /* @__PURE__ */ new Map();
|
|
516
|
+
_bashStartCwdsAtLoad = /* @__PURE__ */ new Map();
|
|
483
517
|
_grepQueries = /* @__PURE__ */ new Map();
|
|
484
518
|
_globQueries = /* @__PURE__ */ new Map();
|
|
485
519
|
_outstandingAgentSpawns = [];
|
|
@@ -489,7 +523,7 @@ registerReset(() => {
|
|
|
489
523
|
_compactedAt = 0;
|
|
490
524
|
_sessionId = null;
|
|
491
525
|
_transcriptPath = null;
|
|
492
|
-
});
|
|
526
|
+
}, { perRequest: true });
|
|
493
527
|
|
|
494
528
|
export {
|
|
495
529
|
recordFileRead,
|
|
@@ -512,6 +546,11 @@ export {
|
|
|
512
546
|
takePendingLargeFileHint,
|
|
513
547
|
consumedPendingLargeFileHintKeys,
|
|
514
548
|
pendingLargeFileHintsAtLoad,
|
|
549
|
+
MAX_BASH_START_CWDS,
|
|
550
|
+
recordBashStartCwd,
|
|
551
|
+
takeBashStartCwd,
|
|
552
|
+
bashStartCwdsAtLoad,
|
|
553
|
+
consumedBashStartCwdKeys,
|
|
515
554
|
WEB_FETCH_KEY_SEP,
|
|
516
555
|
recordWebFetch,
|
|
517
556
|
migrateCurlDownloadKey,
|