token-goat 2.9.29 → 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.
Files changed (131) hide show
  1. package/README.md +34 -40
  2. package/SECURITY.md +28 -10
  3. package/THIRD_PARTY_NOTICES.md +40 -3
  4. package/dist/native/linux-arm64/tg-hook +0 -0
  5. package/dist/native/linux-x64/tg-hook +0 -0
  6. package/dist/ort-wasm-simd-threaded.mjs +59 -0
  7. package/dist/token-goat-chunk-3CHUNJ2O.mjs +53 -0
  8. package/dist/token-goat-chunk-3Z5S4KGM.mjs +918 -0
  9. package/dist/token-goat-chunk-4FVIAHSI.mjs +211 -0
  10. package/dist/{token-goat-chunk-PGTH2U4C.mjs → token-goat-chunk-4JJS54TR.mjs} +4 -3
  11. package/dist/token-goat-chunk-4LCCNRTG.mjs +313 -0
  12. package/dist/{token-goat-chunk-L7H3U27L.mjs → token-goat-chunk-54K3EUV3.mjs} +1 -1
  13. package/dist/token-goat-chunk-56EIMS3E.mjs +159 -0
  14. package/dist/token-goat-chunk-5BCIJXMO.mjs +609 -0
  15. package/dist/token-goat-chunk-5KDMCMF2.mjs +362 -0
  16. package/dist/token-goat-chunk-5RG5SBL6.mjs +221 -0
  17. package/dist/{token-goat-chunk-RRNZMM3A.mjs → token-goat-chunk-5Y6ZYL6U.mjs} +21 -2
  18. package/dist/{token-goat-chunk-GLXRTTLE.mjs → token-goat-chunk-64FBPDTK.mjs} +12 -8
  19. package/dist/{token-goat-chunk-G23DWHV4.mjs → token-goat-chunk-664RTTUV.mjs} +28 -15
  20. package/dist/token-goat-chunk-67TQJ76B.mjs +57 -0
  21. package/dist/token-goat-chunk-6QMAS7AB.mjs +42 -0
  22. package/dist/token-goat-chunk-7BXSNBY5.mjs +253 -0
  23. package/dist/{token-goat-chunk-IVWI2OCK.mjs → token-goat-chunk-7F2UBPD3.mjs} +40 -11
  24. package/dist/{token-goat-chunk-TGOXNAHW.mjs → token-goat-chunk-7IN2MKDS.mjs} +682 -501
  25. package/dist/token-goat-chunk-7NADEDKJ.mjs +124 -0
  26. package/dist/{token-goat-chunk-KOPIR3KZ.mjs → token-goat-chunk-A3CK6N5Z.mjs} +618 -72
  27. package/dist/{token-goat-chunk-O6I2XU4P.mjs → token-goat-chunk-AFLYLHDH.mjs} +44 -31
  28. package/dist/{token-goat-chunk-TCQANXYC.mjs → token-goat-chunk-AM5V6GSX.mjs} +18 -2
  29. package/dist/{token-goat-chunk-E4ZOJIZK.mjs → token-goat-chunk-APGZXSPS.mjs} +39 -146
  30. package/dist/{token-goat-chunk-D4ETHJD6.mjs → token-goat-chunk-ARDNEC2U.mjs} +9 -7
  31. package/dist/token-goat-chunk-ATCPY7EQ.mjs +134 -0
  32. package/dist/token-goat-chunk-B2RZZCSS.mjs +354 -0
  33. package/dist/{token-goat-chunk-BGYOZ6DO.mjs → token-goat-chunk-B45VMIIH.mjs} +6 -7
  34. package/dist/token-goat-chunk-BPGCUMR7.mjs +30 -0
  35. package/dist/{token-goat-chunk-TDUT2CL6.mjs → token-goat-chunk-C63JQV5K.mjs} +45 -6
  36. package/dist/{token-goat-chunk-ZER6EAXZ.mjs → token-goat-chunk-COBQGL5S.mjs} +2661 -2440
  37. package/dist/token-goat-chunk-COTXZHTS.mjs +39 -0
  38. package/dist/{token-goat-chunk-RQGGMPCR.mjs → token-goat-chunk-CYCEYAEO.mjs} +76 -16
  39. package/dist/token-goat-chunk-CZ3LUXYZ.mjs +4115 -0
  40. package/dist/{token-goat-chunk-ASLWOQ3I.mjs → token-goat-chunk-DZX2YDPT.mjs} +2 -1
  41. package/dist/token-goat-chunk-E3OQX2XT.mjs +824 -0
  42. package/dist/token-goat-chunk-EFHMMIGP.mjs +68 -0
  43. package/dist/token-goat-chunk-ETBHVDB6.mjs +328 -0
  44. package/dist/token-goat-chunk-EVMZJ27Z.mjs +147 -0
  45. package/dist/token-goat-chunk-EXKGNHEG.mjs +2096 -0
  46. package/dist/{token-goat-chunk-RTMVLHWX.mjs → token-goat-chunk-FBNQNSJK.mjs} +2555 -5127
  47. package/dist/{token-goat-chunk-NMTKNYGF.mjs → token-goat-chunk-FNFBKLRD.mjs} +74 -9
  48. package/dist/{token-goat-chunk-RLP6J7WR.mjs → token-goat-chunk-FZ3NEW5O.mjs} +33 -19
  49. package/dist/token-goat-chunk-G5PJ7AGM.mjs +36 -0
  50. package/dist/{token-goat-chunk-DNRPXHYH.mjs → token-goat-chunk-GFBSN7BD.mjs} +29 -401
  51. package/dist/{token-goat-chunk-XYWPOSCN.mjs → token-goat-chunk-GOLEOXZP.mjs} +763 -211
  52. package/dist/token-goat-chunk-H2K3QP6H.mjs +24 -0
  53. package/dist/token-goat-chunk-H2PHHGM5.mjs +188 -0
  54. package/dist/token-goat-chunk-HAVAOB3S.mjs +87 -0
  55. package/dist/token-goat-chunk-HG45AF2B.mjs +2228 -0
  56. package/dist/{token-goat-chunk-HUYUHODZ.mjs → token-goat-chunk-HOJLCGDP.mjs} +12965 -11748
  57. package/dist/{token-goat-chunk-435UQTKD.mjs → token-goat-chunk-HYBFA5X3.mjs} +118 -19
  58. package/dist/token-goat-chunk-IVALLT3S.mjs +48 -0
  59. package/dist/{token-goat-chunk-UXSXQQIY.mjs → token-goat-chunk-IVKIZWAB.mjs} +3 -3
  60. package/dist/{token-goat-chunk-52NSDWYY.mjs → token-goat-chunk-JB6QN6VF.mjs} +6 -4
  61. package/dist/{token-goat-chunk-HNFZZHFW.mjs → token-goat-chunk-JDHE26RP.mjs} +10 -3
  62. package/dist/{token-goat-chunk-FTP4U4QA.mjs → token-goat-chunk-JDU3EXSU.mjs} +12 -11
  63. package/dist/token-goat-chunk-JDWCRD6M.mjs +253 -0
  64. package/dist/{token-goat-chunk-6AK46ZT7.mjs → token-goat-chunk-JN4XMLSD.mjs} +5 -1
  65. package/dist/token-goat-chunk-JTQQGXZH.mjs +733 -0
  66. package/dist/token-goat-chunk-KKUFXAPD.mjs +25 -0
  67. package/dist/token-goat-chunk-KQNZDCBD.mjs +47 -0
  68. package/dist/{token-goat-chunk-2WOUYWLM.mjs → token-goat-chunk-KWPNJBDH.mjs} +27 -3
  69. package/dist/{token-goat-chunk-DPNLUJWB.mjs → token-goat-chunk-LOBGHXPB.mjs} +30 -8
  70. package/dist/token-goat-chunk-MKPF4CL5.mjs +37 -0
  71. package/dist/token-goat-chunk-MNWKPRAL.mjs +13 -0
  72. package/dist/{token-goat-chunk-DNSPXQXQ.mjs → token-goat-chunk-N2NMER56.mjs} +25 -15
  73. package/dist/token-goat-chunk-NYKZLXMK.mjs +218 -0
  74. package/dist/token-goat-chunk-OJBNYTJP.mjs +3087 -0
  75. package/dist/token-goat-chunk-P4QMM4WK.mjs +295 -0
  76. package/dist/token-goat-chunk-PD5VKH46.mjs +184 -0
  77. package/dist/token-goat-chunk-PEPTHRFF.mjs +129 -0
  78. package/dist/{token-goat-chunk-NMBWLRHW.mjs → token-goat-chunk-PU7V3FD6.mjs} +8721 -11104
  79. package/dist/token-goat-chunk-PY533T7F.mjs +46 -0
  80. package/dist/token-goat-chunk-Q5VTGRH7.mjs +761 -0
  81. package/dist/{token-goat-chunk-67BNIKKO.mjs → token-goat-chunk-QCLDAQTS.mjs} +31 -20
  82. package/dist/{token-goat-chunk-SE6E4BKJ.mjs → token-goat-chunk-QSBRTGM2.mjs} +9 -2
  83. package/dist/{token-goat-chunk-VZQEWRVH.mjs → token-goat-chunk-RC35RBUL.mjs} +4 -4
  84. package/dist/{token-goat-chunk-VMFWNHGR.mjs → token-goat-chunk-RHXKCZX3.mjs} +873 -504
  85. package/dist/{token-goat-chunk-PYSUADX4.mjs → token-goat-chunk-RZRTDST7.mjs} +17 -7
  86. package/dist/{token-goat-chunk-ONXH6NZ5.mjs → token-goat-chunk-SJHWVNDQ.mjs} +15 -21
  87. package/dist/token-goat-chunk-SMVRN2HU.mjs +188 -0
  88. package/dist/{token-goat-chunk-QO3LXVVR.mjs → token-goat-chunk-SQSSNQPE.mjs} +2295 -1718
  89. package/dist/{token-goat-chunk-2AWQ2R5X.mjs → token-goat-chunk-T4FK7VOV.mjs} +2 -2
  90. package/dist/token-goat-chunk-U4N3BN2W.mjs +92 -0
  91. package/dist/token-goat-chunk-UA5V6P3P.mjs +122 -0
  92. package/dist/{token-goat-chunk-UA5BKWWQ.mjs → token-goat-chunk-UQ5UK2T7.mjs} +15 -4
  93. package/dist/token-goat-chunk-USILZ3T3.mjs +53 -0
  94. package/dist/{token-goat-chunk-MELOKFDJ.mjs → token-goat-chunk-VES7EL7O.mjs} +7 -1
  95. package/dist/{token-goat-chunk-7CPMDFGB.mjs → token-goat-chunk-VL3YIFHZ.mjs} +389 -14
  96. package/dist/{token-goat-chunk-E5TK5DNO.mjs → token-goat-chunk-VPBBTSJR.mjs} +356 -129
  97. package/dist/{token-goat-chunk-YOOVFPTP.mjs → token-goat-chunk-W3QCJS6G.mjs} +10 -2
  98. package/dist/{token-goat-chunk-LZNBQTDK.mjs → token-goat-chunk-WY3L4DVT.mjs} +11 -7
  99. package/dist/token-goat-chunk-XKI4SEMX.mjs +66 -0
  100. package/dist/token-goat-chunk-XU4P6Z24.mjs +133 -0
  101. package/dist/{token-goat-chunk-H5J3C56Q.mjs → token-goat-chunk-Y776AENC.mjs} +112 -26
  102. package/dist/token-goat-chunk-YARZFCZS.mjs +359 -0
  103. package/dist/{token-goat-chunk-S4VSXURL.mjs → token-goat-chunk-Z44YO3QZ.mjs} +4 -0
  104. package/dist/token-goat-chunk-Z57YODA2.mjs +35 -0
  105. package/dist/{token-goat-chunk-PQ53BSCF.mjs → token-goat-chunk-ZCDTCVIS.mjs} +48 -29
  106. package/dist/token-goat-chunk-ZEJVMUQH.mjs +48 -0
  107. package/dist/{token-goat-chunk-BGHSSJUA.mjs → token-goat-chunk-ZFOBKUWH.mjs} +1 -1
  108. package/dist/token-goat-chunk-ZMBL6UVV.mjs +110 -0
  109. package/dist/{token-goat-chunk-PKRWMHVP.mjs → token-goat-chunk-ZQSJMO2R.mjs} +338 -170
  110. package/dist/token-goat-hook-client.cjs +87 -23
  111. package/dist/token-goat-hook-client.mjs +3 -3
  112. package/dist/token-goat-hook.mjs +46 -30
  113. package/dist/token-goat.core.mjs +6 -6
  114. package/docs/C4_RUNTIME_ARCHITECTURE.md +1 -1
  115. package/docs/cli.md +80 -46
  116. package/docs/install.md +47 -14
  117. package/docs/security.md +7 -7
  118. package/package.json +17 -7
  119. package/scripts/verify-native-dist.mjs +386 -0
  120. package/dist/token-goat-chunk-2NNUA2LR.mjs +0 -143
  121. package/dist/token-goat-chunk-44BM7DDQ.mjs +0 -294
  122. package/dist/token-goat-chunk-C5YPNZKQ.mjs +0 -318
  123. package/dist/token-goat-chunk-CIQ2FTY3.mjs +0 -1990
  124. package/dist/token-goat-chunk-EUSDXRXU.mjs +0 -1429
  125. package/dist/token-goat-chunk-G7IWXCFF.mjs +0 -456
  126. package/dist/token-goat-chunk-JTKCQMQA.mjs +0 -418
  127. package/dist/token-goat-chunk-ORNFMIER.mjs +0 -295
  128. package/dist/token-goat-chunk-VQ6F6T7X.mjs +0 -36
  129. package/dist/token-goat-chunk-YAGLESS3.mjs +0 -23
  130. package/dist/token-goat-chunk-YKSRAWUU.mjs +0 -33
  131. package/dist/token-goat-chunk-Z6KBMOBI.mjs +0 -53
@@ -0,0 +1,134 @@
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
+ };
@@ -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,16 +5,15 @@ import {
5
5
  docxTables,
6
6
  docxText,
7
7
  formatDocxTables
8
- } from "./token-goat-chunk-UA5BKWWQ.mjs";
9
- import "./token-goat-chunk-UXSXQQIY.mjs";
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-XYWPOSCN.mjs";
13
- import "./token-goat-chunk-TCQANXYC.mjs";
14
- import "./token-goat-chunk-NMTKNYGF.mjs";
15
- import "./token-goat-chunk-MELOKFDJ.mjs";
16
12
  import "./token-goat-chunk-Y4AFKTHK.mjs";
17
- import "./token-goat-chunk-JTKCQMQA.mjs";
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";
18
17
  import "./token-goat-chunk-A37V4PBF.mjs";
19
18
  export {
20
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-CIQ2FTY3.mjs";
5
+ } from "./token-goat-chunk-4FVIAHSI.mjs";
6
6
  import {
7
7
  shortFingerprint
8
- } from "./token-goat-chunk-TGOXNAHW.mjs";
8
+ } from "./token-goat-chunk-7IN2MKDS.mjs";
9
9
  import {
10
10
  registerReset
11
11
  } from "./token-goat-chunk-YZAAZU2S.mjs";
12
12
  import {
13
13
  foldPath
14
- } from "./token-goat-chunk-TCQANXYC.mjs";
14
+ } from "./token-goat-chunk-AM5V6GSX.mjs";
15
15
  import {
16
+ hostPathOfIndexKey,
16
17
  normalizePath
17
- } from "./token-goat-chunk-NMTKNYGF.mjs";
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;
@@ -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 = [];
@@ -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,