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.
Files changed (197) hide show
  1. package/README.md +53 -42
  2. package/SECURITY.md +37 -11
  3. package/THIRD_PARTY_NOTICES.md +41 -4
  4. package/dist/native/linux-arm64/tg-hook +0 -0
  5. package/dist/native/linux-x64/tg-hook +0 -0
  6. package/dist/native/win32-arm64/tg-hook.exe +0 -0
  7. package/dist/native/win32-x64/tg-hook.exe +0 -0
  8. package/dist/ort-wasm-simd-threaded.mjs +59 -0
  9. package/dist/{token-goat-chunk-SE6E4BKJ.mjs → token-goat-chunk-25TRAWET.mjs} +23 -6
  10. package/dist/token-goat-chunk-2KXO6V2B.mjs +203 -0
  11. package/dist/{token-goat-chunk-UXSXQQIY.mjs → token-goat-chunk-2M7E4PF7.mjs} +43 -14
  12. package/dist/token-goat-chunk-2UPZGKKY.mjs +188 -0
  13. package/dist/token-goat-chunk-2WLPWKHV.mjs +135 -0
  14. package/dist/token-goat-chunk-2XBMMDBD.mjs +126 -0
  15. package/dist/token-goat-chunk-32ZOY4N5.mjs +23 -0
  16. package/dist/token-goat-chunk-3EZRNKTK.mjs +188 -0
  17. package/dist/token-goat-chunk-4ADZHI7J.mjs +63 -0
  18. package/dist/token-goat-chunk-4GBVPH3D.mjs +242 -0
  19. package/dist/{token-goat-chunk-2WOUYWLM.mjs → token-goat-chunk-4GILLLWY.mjs} +34 -7
  20. package/dist/token-goat-chunk-4NAPX7BA.mjs +90 -0
  21. package/dist/{token-goat-chunk-NMBWLRHW.mjs → token-goat-chunk-4SC7UJYV.mjs} +9981 -11563
  22. package/dist/token-goat-chunk-4SMRO4TO.mjs +366 -0
  23. package/dist/{token-goat-chunk-O6I2XU4P.mjs → token-goat-chunk-4ZBFWLXF.mjs} +310 -441
  24. package/dist/token-goat-chunk-57BIAXJL.mjs +286 -0
  25. package/dist/token-goat-chunk-5AC66HNP.mjs +115 -0
  26. package/dist/token-goat-chunk-5IMLKSOP.mjs +145 -0
  27. package/dist/token-goat-chunk-5RG5SBL6.mjs +221 -0
  28. package/dist/{token-goat-chunk-RRNZMM3A.mjs → token-goat-chunk-5Y6ZYL6U.mjs} +21 -2
  29. package/dist/token-goat-chunk-646E6U44.mjs +398 -0
  30. package/dist/token-goat-chunk-65N4RHP4.mjs +33 -0
  31. package/dist/{token-goat-chunk-6AK46ZT7.mjs → token-goat-chunk-6DG6HWP3.mjs} +13 -3
  32. package/dist/token-goat-chunk-6ENQSNRZ.mjs +573 -0
  33. package/dist/token-goat-chunk-6ZY4GNF2.mjs +91 -0
  34. package/dist/{token-goat-chunk-E5TK5DNO.mjs → token-goat-chunk-76FGDLRO.mjs} +574 -340
  35. package/dist/{token-goat-chunk-TGOXNAHW.mjs → token-goat-chunk-7EZTZOMC.mjs} +780 -767
  36. package/dist/token-goat-chunk-7MAOA6X4.mjs +3647 -0
  37. package/dist/token-goat-chunk-7R2ZVVAX.mjs +218 -0
  38. package/dist/{token-goat-chunk-TCQANXYC.mjs → token-goat-chunk-AM5V6GSX.mjs} +18 -2
  39. package/dist/token-goat-chunk-AUNGYYQX.mjs +184 -0
  40. package/dist/token-goat-chunk-AUQYRMMH.mjs +2985 -0
  41. package/dist/token-goat-chunk-B3PEKBYG.mjs +128 -0
  42. package/dist/{token-goat-chunk-KOPIR3KZ.mjs → token-goat-chunk-BA4HI6BW.mjs} +1910 -165
  43. package/dist/{token-goat-chunk-52NSDWYY.mjs → token-goat-chunk-BFCWY73P.mjs} +58 -20
  44. package/dist/token-goat-chunk-BPGCUMR7.mjs +30 -0
  45. package/dist/token-goat-chunk-BWGFUZZE.mjs +25 -0
  46. package/dist/token-goat-chunk-C75NA7PL.mjs +322 -0
  47. package/dist/token-goat-chunk-CBIQ7WTD.mjs +87 -0
  48. package/dist/token-goat-chunk-CETM74KC.mjs +307 -0
  49. package/dist/token-goat-chunk-CIMQ2BB3.mjs +233 -0
  50. package/dist/{token-goat-chunk-DNSPXQXQ.mjs → token-goat-chunk-CJLS3CDL.mjs} +70 -18
  51. package/dist/{token-goat-chunk-MELOKFDJ.mjs → token-goat-chunk-CO3UYX6G.mjs} +7 -1
  52. package/dist/token-goat-chunk-COPNXRJM.mjs +154 -0
  53. package/dist/token-goat-chunk-CSJ5L3NL.mjs +479 -0
  54. package/dist/token-goat-chunk-CVCEVUGK.mjs +315 -0
  55. package/dist/token-goat-chunk-CXHOFN7R.mjs +371 -0
  56. package/dist/token-goat-chunk-D735C4QM.mjs +603 -0
  57. package/dist/{token-goat-chunk-E4ZOJIZK.mjs → token-goat-chunk-DGS2LVNA.mjs} +70 -160
  58. package/dist/{token-goat-chunk-L7H3U27L.mjs → token-goat-chunk-DOWRSMWO.mjs} +1 -1
  59. package/dist/token-goat-chunk-E45INMY3.mjs +71 -0
  60. package/dist/token-goat-chunk-EC5F37F4.mjs +244 -0
  61. package/dist/{token-goat-chunk-XTQAOTSO.mjs → token-goat-chunk-EDBDRVH5.mjs} +4 -1
  62. package/dist/token-goat-chunk-EELTBKDM.mjs +613 -0
  63. package/dist/token-goat-chunk-EVMZJ27Z.mjs +147 -0
  64. package/dist/token-goat-chunk-EXKGNHEG.mjs +2096 -0
  65. package/dist/{token-goat-chunk-YOOVFPTP.mjs → token-goat-chunk-F4HYL64R.mjs} +12 -2
  66. package/dist/token-goat-chunk-F6PAUIEK.mjs +624 -0
  67. package/dist/token-goat-chunk-FDSREWLX.mjs +692 -0
  68. package/dist/{token-goat-chunk-NMTKNYGF.mjs → token-goat-chunk-FNFBKLRD.mjs} +74 -9
  69. package/dist/token-goat-chunk-G5PJ7AGM.mjs +36 -0
  70. package/dist/token-goat-chunk-GGGG7RWB.mjs +236 -0
  71. package/dist/{token-goat-chunk-TDUT2CL6.mjs → token-goat-chunk-GL3ETKSC.mjs} +276 -19
  72. package/dist/{token-goat-chunk-7CPMDFGB.mjs → token-goat-chunk-GVB2MUST.mjs} +265 -1567
  73. package/dist/token-goat-chunk-GWFLAUMQ.mjs +307 -0
  74. package/dist/token-goat-chunk-HAVAOB3S.mjs +87 -0
  75. package/dist/token-goat-chunk-HLPW63A7.mjs +48 -0
  76. package/dist/token-goat-chunk-HU4TORC5.mjs +1377 -0
  77. package/dist/token-goat-chunk-I7VKZZAW.mjs +35 -0
  78. package/dist/token-goat-chunk-IA6XSPE3.mjs +218 -0
  79. package/dist/token-goat-chunk-IAGXMHIK.mjs +863 -0
  80. package/dist/{token-goat-chunk-435UQTKD.mjs → token-goat-chunk-IK2DRMFX.mjs} +129 -74
  81. package/dist/{token-goat-chunk-ZER6EAXZ.mjs → token-goat-chunk-INNPTRUX.mjs} +2954 -2783
  82. package/dist/token-goat-chunk-JJ5BX4F4.mjs +129 -0
  83. package/dist/token-goat-chunk-JVFSHVFJ.mjs +129 -0
  84. package/dist/token-goat-chunk-KGEFFSHD.mjs +50 -0
  85. package/dist/token-goat-chunk-KKUFXAPD.mjs +25 -0
  86. package/dist/token-goat-chunk-KQBLRPBN.mjs +433 -0
  87. package/dist/token-goat-chunk-LCNQ2CNN.mjs +497 -0
  88. package/dist/token-goat-chunk-M3LFJDPU.mjs +58 -0
  89. package/dist/token-goat-chunk-M52KPT3C.mjs +87 -0
  90. package/dist/token-goat-chunk-MBEG42H7.mjs +150 -0
  91. package/dist/{token-goat-chunk-EVC4TOLE.mjs → token-goat-chunk-METECDOH.mjs} +3 -12
  92. package/dist/{token-goat-chunk-2AWQ2R5X.mjs → token-goat-chunk-MHX7XCC3.mjs} +3 -2
  93. package/dist/token-goat-chunk-MNWKPRAL.mjs +13 -0
  94. package/dist/token-goat-chunk-N5LSOVSU.mjs +137 -0
  95. package/dist/{token-goat-chunk-DPNLUJWB.mjs → token-goat-chunk-N5MMR2IW.mjs} +30 -8
  96. package/dist/token-goat-chunk-N7B3JQ2C.mjs +160 -0
  97. package/dist/{token-goat-chunk-VMFWNHGR.mjs → token-goat-chunk-NISNMD7T.mjs} +2545 -2953
  98. package/dist/token-goat-chunk-NMD42SFQ.mjs +434 -0
  99. package/dist/token-goat-chunk-NOSS5VWY.mjs +174 -0
  100. package/dist/token-goat-chunk-NSNSPPBG.mjs +69 -0
  101. package/dist/token-goat-chunk-OBOFIHKN.mjs +38 -0
  102. package/dist/token-goat-chunk-OBRFJ5O5.mjs +76 -0
  103. package/dist/token-goat-chunk-ODBT2USM.mjs +800 -0
  104. package/dist/token-goat-chunk-OS5EM5PP.mjs +107 -0
  105. package/dist/token-goat-chunk-OUKDTVNU.mjs +1178 -0
  106. package/dist/token-goat-chunk-OXFMP75N.mjs +566 -0
  107. package/dist/{token-goat-chunk-ASLWOQ3I.mjs → token-goat-chunk-OYIYKDDT.mjs} +2 -1
  108. package/dist/{token-goat-chunk-67BNIKKO.mjs → token-goat-chunk-P6HQSWQ3.mjs} +55 -47
  109. package/dist/token-goat-chunk-P6VGNTQT.mjs +71 -0
  110. package/dist/token-goat-chunk-PFWIMH2E.mjs +261 -0
  111. package/dist/token-goat-chunk-PJZXIS3G.mjs +39 -0
  112. package/dist/token-goat-chunk-PUO5INXP.mjs +606 -0
  113. package/dist/token-goat-chunk-PX5PQWTY.mjs +462 -0
  114. package/dist/token-goat-chunk-Q5QDBC6O.mjs +111 -0
  115. package/dist/token-goat-chunk-QFNQXSDT.mjs +40 -0
  116. package/dist/token-goat-chunk-QH7YVYOY.mjs +3957 -0
  117. package/dist/token-goat-chunk-QLMUHEPB.mjs +43 -0
  118. package/dist/{token-goat-chunk-PYSUADX4.mjs → token-goat-chunk-QQOJIHL3.mjs} +50 -14
  119. package/dist/token-goat-chunk-QQTWJY2O.mjs +85 -0
  120. package/dist/token-goat-chunk-QYHO5CPH.mjs +93 -0
  121. package/dist/token-goat-chunk-RELAVWAD.mjs +27 -0
  122. package/dist/token-goat-chunk-RSLPOBKQ.mjs +339 -0
  123. package/dist/token-goat-chunk-SAMFDIS2.mjs +712 -0
  124. package/dist/token-goat-chunk-SDELXLDM.mjs +48 -0
  125. package/dist/{token-goat-chunk-PGTH2U4C.mjs → token-goat-chunk-SOAFZNNZ.mjs} +164 -40
  126. package/dist/{token-goat-chunk-G23DWHV4.mjs → token-goat-chunk-SRTHT7KV.mjs} +33 -15
  127. package/dist/token-goat-chunk-T5P5ACNQ.mjs +212 -0
  128. package/dist/token-goat-chunk-T5YGG4V3.mjs +45 -0
  129. package/dist/token-goat-chunk-TAUZ4OFS.mjs +110 -0
  130. package/dist/token-goat-chunk-TM6MC754.mjs +40 -0
  131. package/dist/token-goat-chunk-TWUKBOMP.mjs +72 -0
  132. package/dist/token-goat-chunk-U2KSB4SG.mjs +56 -0
  133. package/dist/token-goat-chunk-U4WHMG6Y.mjs +898 -0
  134. package/dist/token-goat-chunk-UA5V6P3P.mjs +122 -0
  135. package/dist/token-goat-chunk-UGJHGR5A.mjs +52 -0
  136. package/dist/{token-goat-chunk-RQGGMPCR.mjs → token-goat-chunk-UOUDVA5U.mjs} +76 -16
  137. package/dist/{token-goat-chunk-HNFZZHFW.mjs → token-goat-chunk-URRJ33GR.mjs} +22 -4
  138. package/dist/token-goat-chunk-UZOROKIS.mjs +165 -0
  139. package/dist/token-goat-chunk-VIHGGGEI.mjs +4234 -0
  140. package/dist/token-goat-chunk-VTJLAA7P.mjs +21 -0
  141. package/dist/token-goat-chunk-VWDXLT4F.mjs +678 -0
  142. package/dist/token-goat-chunk-VWZA2H4P.mjs +368 -0
  143. package/dist/{token-goat-chunk-QO3LXVVR.mjs → token-goat-chunk-VXEXMJDL.mjs} +2964 -3153
  144. package/dist/token-goat-chunk-WBA5SKT4.mjs +547 -0
  145. package/dist/{token-goat-chunk-ONXH6NZ5.mjs → token-goat-chunk-WDH44VAU.mjs} +19 -22
  146. package/dist/token-goat-chunk-X2SUP3EI.mjs +107 -0
  147. package/dist/token-goat-chunk-X3BELZSJ.mjs +125 -0
  148. package/dist/{token-goat-chunk-RLP6J7WR.mjs → token-goat-chunk-XLRBNZCC.mjs} +40 -21
  149. package/dist/{token-goat-chunk-S4VSXURL.mjs → token-goat-chunk-XRKUX6CM.mjs} +4 -0
  150. package/dist/token-goat-chunk-XX6O25RN.mjs +82 -0
  151. package/dist/token-goat-chunk-XZSUHBVS.mjs +65 -0
  152. package/dist/token-goat-chunk-Y2ZTQOCL.mjs +35 -0
  153. package/dist/{token-goat-chunk-UA5BKWWQ.mjs → token-goat-chunk-YB4VMGK2.mjs} +15 -4
  154. package/dist/token-goat-chunk-YBIIY3HR.mjs +51 -0
  155. package/dist/{token-goat-chunk-PKRWMHVP.mjs → token-goat-chunk-YHVDKQBR.mjs} +389 -221
  156. package/dist/token-goat-chunk-YJB5XLWI.mjs +26 -0
  157. package/dist/{token-goat-chunk-PQ53BSCF.mjs → token-goat-chunk-YKB6AQG3.mjs} +53 -31
  158. package/dist/token-goat-chunk-YMTG2YA5.mjs +35 -0
  159. package/dist/token-goat-chunk-YPBZYQRV.mjs +40 -0
  160. package/dist/{token-goat-chunk-HUYUHODZ.mjs → token-goat-chunk-YY6AVUFL.mjs} +13246 -12247
  161. package/dist/token-goat-chunk-Z7N5OMMP.mjs +98 -0
  162. package/dist/{token-goat-chunk-BGHSSJUA.mjs → token-goat-chunk-ZFOBKUWH.mjs} +1 -1
  163. package/dist/token-goat-chunk-ZMBL6UVV.mjs +110 -0
  164. package/dist/token-goat-chunk-ZNMNUPAZ.mjs +938 -0
  165. package/dist/token-goat-hook-client.cjs +87 -23
  166. package/dist/token-goat-hook-client.mjs +3 -3
  167. package/dist/token-goat-hook.mjs +76 -31
  168. package/dist/token-goat.core.mjs +6 -6
  169. package/docs/C4_RUNTIME_ARCHITECTURE.md +2 -2
  170. package/docs/cli.md +113 -60
  171. package/docs/install.md +63 -20
  172. package/docs/security.md +10 -8
  173. package/package.json +18 -7
  174. package/scripts/verify-native-dist.mjs +386 -0
  175. package/dist/token-goat-chunk-2NNUA2LR.mjs +0 -143
  176. package/dist/token-goat-chunk-44BM7DDQ.mjs +0 -294
  177. package/dist/token-goat-chunk-BGYOZ6DO.mjs +0 -24
  178. package/dist/token-goat-chunk-C5YPNZKQ.mjs +0 -318
  179. package/dist/token-goat-chunk-CIQ2FTY3.mjs +0 -1990
  180. package/dist/token-goat-chunk-D4ETHJD6.mjs +0 -246
  181. package/dist/token-goat-chunk-DNRPXHYH.mjs +0 -1062
  182. package/dist/token-goat-chunk-EUSDXRXU.mjs +0 -1429
  183. package/dist/token-goat-chunk-FTP4U4QA.mjs +0 -64
  184. package/dist/token-goat-chunk-G7IWXCFF.mjs +0 -456
  185. package/dist/token-goat-chunk-GLXRTTLE.mjs +0 -36
  186. package/dist/token-goat-chunk-H5J3C56Q.mjs +0 -1511
  187. package/dist/token-goat-chunk-IVWI2OCK.mjs +0 -368
  188. package/dist/token-goat-chunk-JTKCQMQA.mjs +0 -418
  189. package/dist/token-goat-chunk-LZNBQTDK.mjs +0 -26
  190. package/dist/token-goat-chunk-ORNFMIER.mjs +0 -295
  191. package/dist/token-goat-chunk-RTMVLHWX.mjs +0 -7113
  192. package/dist/token-goat-chunk-VQ6F6T7X.mjs +0 -36
  193. package/dist/token-goat-chunk-VZQEWRVH.mjs +0 -312
  194. package/dist/token-goat-chunk-XYWPOSCN.mjs +0 -807
  195. package/dist/token-goat-chunk-YAGLESS3.mjs +0 -23
  196. package/dist/token-goat-chunk-YKSRAWUU.mjs +0 -33
  197. package/dist/token-goat-chunk-Z6KBMOBI.mjs +0 -53
@@ -0,0 +1,315 @@
1
+ import { createRequire as __cjsRequire } from 'node:module';
2
+ const require = __cjsRequire(import.meta.url);
3
+ import {
4
+ copyFromSharedCache,
5
+ downloadPinned
6
+ } from "./token-goat-chunk-AUNGYYQX.mjs";
7
+ import "./token-goat-chunk-2UPZGKKY.mjs";
8
+ import {
9
+ loadConfig
10
+ } from "./token-goat-chunk-7EZTZOMC.mjs";
11
+ import "./token-goat-chunk-QYHO5CPH.mjs";
12
+ import "./token-goat-chunk-4GBVPH3D.mjs";
13
+ import {
14
+ registerReset
15
+ } from "./token-goat-chunk-YZAAZU2S.mjs";
16
+ import "./token-goat-chunk-IVE6U7KV.mjs";
17
+ import {
18
+ atomicWriteText,
19
+ ensureDirSync
20
+ } from "./token-goat-chunk-HU4TORC5.mjs";
21
+ import "./token-goat-chunk-GGGG7RWB.mjs";
22
+ import "./token-goat-chunk-AM5V6GSX.mjs";
23
+ import "./token-goat-chunk-FNFBKLRD.mjs";
24
+ import {
25
+ ensureDataDirPrivate
26
+ } from "./token-goat-chunk-CO3UYX6G.mjs";
27
+ import {
28
+ init_define_import_meta_env
29
+ } from "./token-goat-chunk-A37V4PBF.mjs";
30
+
31
+ // src/embed_runtime_web.ts
32
+ init_define_import_meta_env();
33
+ import { createHash } from "node:crypto";
34
+ import * as fs from "node:fs";
35
+ import { createRequire } from "node:module";
36
+ import * as path from "node:path";
37
+ import { fileURLToPath, pathToFileURL } from "node:url";
38
+ import { createGunzip } from "node:zlib";
39
+ var _require = createRequire(import.meta.url);
40
+ var ORT_WEB_TARBALL = {
41
+ name: "onnxruntime-web-1.30.0.tgz",
42
+ sha256: "d2228df7e4616bc3348bf504ee888f3bec43789a273f0a63f3e68d203ce3bf71",
43
+ bytes: 33106585
44
+ };
45
+ var ORT_WEB_GLUE = {
46
+ name: "ort-wasm-simd-threaded.mjs",
47
+ sha256: "e13f7f94fc51b4ca72b12faeb1ee95f4ace6dfbc8939bc718aabdc0a27c4299b",
48
+ bytes: 24381
49
+ };
50
+ var TARBALL_MEMBER = "package/dist/ort-wasm-simd-threaded.wasm";
51
+ var BACKEND_START_FAILED = "no available backend found";
52
+ var _webLoad = null;
53
+ var _inFlightWasm = null;
54
+ var _placeFailures = /* @__PURE__ */ new WeakSet();
55
+ function readVerified(filePath, file) {
56
+ const info = fs.lstatSync(filePath, { throwIfNoEntry: false });
57
+ if (!info?.isFile() || info.size !== file.bytes) return null;
58
+ const bytes = fs.readFileSync(filePath);
59
+ if (bytes.length !== file.bytes) return null;
60
+ return createHash("sha256").update(bytes).digest("hex") === file.sha256 ? bytes : null;
61
+ }
62
+ function ensureWasmBinary(host) {
63
+ if (_inFlightWasm === null) {
64
+ _inFlightWasm = (async () => {
65
+ try {
66
+ return await placeWasmBinary(host);
67
+ } finally {
68
+ _inFlightWasm = null;
69
+ }
70
+ })();
71
+ }
72
+ return _inFlightWasm;
73
+ }
74
+ async function placeWasmBinary(host) {
75
+ ensureDataDirPrivate();
76
+ const { dir, version, wasm } = host;
77
+ const target = path.join(dir, wasm.name);
78
+ const cached = readVerified(target, wasm);
79
+ if (cached) return cached;
80
+ fs.rmSync(target, { force: true });
81
+ ensureDirSync(dir);
82
+ const shared = host.sharedDir;
83
+ if (shared && await copyFromSharedCache(shared, wasm, target)) {
84
+ const copied = readVerified(target, wasm);
85
+ if (copied) return copied;
86
+ }
87
+ if (loadConfig().network.offline) {
88
+ throw new Error(
89
+ `Offline mode is on (network.offline): refusing to download the WebAssembly inference runtime (onnxruntime-web ${version}). Copy ${wasm.name} from that package's dist/ into ${dir} on a connected machine to use semantic search here.`
90
+ );
91
+ }
92
+ console.warn(
93
+ `Downloading the embedding runtime, once (onnxruntime-web ${version} from registry.npmjs.org, ${Math.round(ORT_WEB_TARBALL.bytes / 1024 / 1024)} MB, keeping its ${Math.round(wasm.bytes / 1024 / 1024)} MB ${wasm.name}) into ${dir}`
94
+ );
95
+ const archive = path.join(dir, ORT_WEB_TARBALL.name);
96
+ try {
97
+ await downloadPinned(tarballUrl(), ORT_WEB_TARBALL, archive);
98
+ await extractTarMember(archive, TARBALL_MEMBER, wasm, target);
99
+ } finally {
100
+ fs.rmSync(archive, { force: true, maxRetries: 20, retryDelay: 25 });
101
+ }
102
+ if (shared) host.publish(shared, wasm, target);
103
+ const placed = readVerified(target, wasm);
104
+ if (!placed) throw new Error(`${target} did not verify after extraction`);
105
+ return placed;
106
+ }
107
+ function tarballUrl() {
108
+ return `https://registry.npmjs.org/onnxruntime-web/-/${ORT_WEB_TARBALL.name}`;
109
+ }
110
+ var ExactReader = class {
111
+ constructor(source) {
112
+ this.source = source;
113
+ }
114
+ source;
115
+ chunks = [];
116
+ buffered = 0;
117
+ ended = false;
118
+ async fill(n) {
119
+ while (this.buffered < n && !this.ended) {
120
+ const next = await this.source.next();
121
+ if (next.done === true) {
122
+ this.ended = true;
123
+ break;
124
+ }
125
+ this.chunks.push(next.value);
126
+ this.buffered += next.value.length;
127
+ }
128
+ }
129
+ /** Exactly `n` bytes, or fewer only when the input ends first. */
130
+ async read(n) {
131
+ await this.fill(n);
132
+ const all = this.chunks.length === 1 ? this.chunks[0] : Buffer.concat(this.chunks);
133
+ const out = all.subarray(0, n);
134
+ const rest = all.subarray(out.length);
135
+ this.chunks = rest.length > 0 ? [rest] : [];
136
+ this.buffered = rest.length;
137
+ return out;
138
+ }
139
+ /** Discard exactly `n` bytes without holding them, or throw if the input ends first. */
140
+ async skip(n) {
141
+ let left = n;
142
+ while (left > 0) {
143
+ if (this.buffered === 0) await this.fill(1);
144
+ const head = this.chunks[0];
145
+ if (head === void 0) throw new Error("archive ended inside an entry");
146
+ if (head.length <= left) {
147
+ this.chunks.shift();
148
+ this.buffered -= head.length;
149
+ left -= head.length;
150
+ } else {
151
+ this.chunks[0] = head.subarray(left);
152
+ this.buffered -= left;
153
+ left = 0;
154
+ }
155
+ }
156
+ }
157
+ };
158
+ function tarString(block, start, length) {
159
+ const field = block.subarray(start, start + length);
160
+ const end = field.indexOf(0);
161
+ return field.subarray(0, end === -1 ? field.length : end).toString("utf8");
162
+ }
163
+ function tarOctal(block, start, length) {
164
+ if ((block[start] & 128) !== 0) throw new Error("tar header uses a base-256 number, which this reader does not support");
165
+ const text = tarString(block, start, length).trim();
166
+ const value = text === "" ? 0 : Number.parseInt(text, 8);
167
+ if (!Number.isSafeInteger(value) || value < 0) throw new Error(`tar header holds an invalid number: ${JSON.stringify(text)}`);
168
+ return value;
169
+ }
170
+ function paxPath(data) {
171
+ let at = 0;
172
+ let found = null;
173
+ while (at < data.length) {
174
+ const space = data.indexOf(32, at);
175
+ if (space === -1) break;
176
+ const length = Number.parseInt(data.subarray(at, space).toString("latin1"), 10);
177
+ if (!Number.isSafeInteger(length) || length <= 0 || at + length > data.length) break;
178
+ const record = data.subarray(space + 1, at + length - 1).toString("utf8");
179
+ const eq = record.indexOf("=");
180
+ if (eq !== -1 && record.slice(0, eq) === "path") found = record.slice(eq + 1);
181
+ at += length;
182
+ }
183
+ return found;
184
+ }
185
+ async function extractTarMember(archive, member, file, target) {
186
+ const raw = fs.createReadStream(archive);
187
+ const gunzip = createGunzip();
188
+ raw.on("error", (e) => gunzip.destroy(e));
189
+ raw.pipe(gunzip);
190
+ const reader = new ExactReader(gunzip[Symbol.asyncIterator]());
191
+ try {
192
+ let nextName = null;
193
+ for (; ; ) {
194
+ const header = await reader.read(512);
195
+ if (header.length < 512) throw new Error(`${archive} ended before its end-of-archive marker, without ${member}`);
196
+ if (header.every((b) => b === 0)) throw new Error(`${archive} has no ${member}`);
197
+ let sum = 0;
198
+ for (let i = 0; i < 512; i++) sum += i >= 148 && i < 156 ? 32 : header[i];
199
+ if (sum !== tarOctal(header, 148, 8)) throw new Error(`${archive} has a tar header with a bad checksum`);
200
+ const size = tarOctal(header, 124, 12);
201
+ const padding = (512 - size % 512) % 512;
202
+ const type = header[156] === 0 ? "0" : String.fromCharCode(header[156]);
203
+ let name = tarString(header, 0, 100);
204
+ if (header.subarray(257, 263).toString("latin1") === "ustar\0") {
205
+ const prefix = tarString(header, 345, 155);
206
+ if (prefix !== "") name = `${prefix}/${name}`;
207
+ }
208
+ if (nextName !== null) {
209
+ name = nextName;
210
+ nextName = null;
211
+ }
212
+ if (type === "x" || type === "L") {
213
+ const data = await reader.read(size);
214
+ if (data.length < size) throw new Error(`${archive} ended inside an extended header`);
215
+ await reader.skip(padding);
216
+ nextName = type === "x" ? paxPath(data) : tarString(data, 0, data.length);
217
+ continue;
218
+ }
219
+ if ((type === "0" || type === "7") && name === member) {
220
+ if (size !== file.bytes) throw new Error(`${member} is ${size} bytes in ${archive}, expected the pinned ${file.bytes}`);
221
+ const data = await reader.read(size);
222
+ if (data.length !== file.bytes) throw new Error(`${archive} ended inside ${member}`);
223
+ const digest = createHash("sha256").update(data).digest("hex");
224
+ if (digest !== file.sha256) throw new Error(`${member} has sha256 ${digest}, expected the pinned ${file.sha256}`);
225
+ const temp = `${target}.${process.pid}.partial`;
226
+ try {
227
+ fs.writeFileSync(temp, data);
228
+ fs.renameSync(temp, target);
229
+ } catch (e) {
230
+ fs.rmSync(temp, { force: true, maxRetries: 20, retryDelay: 25 });
231
+ throw e;
232
+ }
233
+ return;
234
+ }
235
+ await reader.skip(size + padding);
236
+ }
237
+ } finally {
238
+ raw.destroy();
239
+ gunzip.destroy();
240
+ }
241
+ }
242
+ function verifiedGlueUrl(version) {
243
+ const beside = fileURLToPath(new URL(`./${ORT_WEB_GLUE.name}`, import.meta.url));
244
+ const file = fs.existsSync(beside) ? beside : _require.resolve(`onnxruntime-web/${ORT_WEB_GLUE.name}`);
245
+ if (readVerified(file, ORT_WEB_GLUE) === null) {
246
+ throw new Error(`${file} is not the ${ORT_WEB_GLUE.name} onnxruntime-web ${version} ships (pinned sha256 ${ORT_WEB_GLUE.sha256})`);
247
+ }
248
+ return pathToFileURL(file).href;
249
+ }
250
+ function loadWebRuntime(threads, host) {
251
+ if (_webLoad !== null) return _webLoad;
252
+ const pending = (async () => {
253
+ const ort = await import("./token-goat-chunk-EXKGNHEG.mjs");
254
+ if (ort.env.versions.web !== host.version) {
255
+ throw new Error(`the bundled onnxruntime-web is ${ort.env.versions.web ?? "unknown"}, but its binary is pinned for ${host.version}`);
256
+ }
257
+ const glue = verifiedGlueUrl(host.version);
258
+ const binary = await ensureWasmBinary(host).catch((e) => {
259
+ if (typeof e === "object" && e !== null) _placeFailures.add(e);
260
+ throw e;
261
+ });
262
+ ort.env.wasm.wasmBinary = binary;
263
+ ort.env.wasm.wasmPaths = { mjs: glue };
264
+ ort.env.wasm.numThreads = threads;
265
+ return ort;
266
+ })();
267
+ _webLoad = pending;
268
+ pending.catch(() => {
269
+ if (_webLoad === pending) _webLoad = null;
270
+ });
271
+ return pending;
272
+ }
273
+ async function createWebSession(modelPath, threads, host) {
274
+ let ort;
275
+ try {
276
+ ort = await loadWebRuntime(threads, host);
277
+ } catch (e) {
278
+ if (typeof e === "object" && e !== null && _placeFailures.has(e)) throw host.failed(e, false);
279
+ throw startFailed(e, host);
280
+ }
281
+ let session;
282
+ try {
283
+ session = await ort.InferenceSession.create(modelPath, { intraOpNumThreads: threads, interOpNumThreads: 1 });
284
+ } catch (e) {
285
+ if (e instanceof Error && e.message.startsWith(BACKEND_START_FAILED)) throw startFailed(e, host);
286
+ throw e;
287
+ }
288
+ try {
289
+ const recorded = JSON.parse(fs.readFileSync(host.startFailure.path, "utf8"));
290
+ if (recorded.key === host.startFailure.key) fs.rmSync(host.startFailure.path, { force: true });
291
+ } catch {
292
+ }
293
+ return { session, Tensor: ort.Tensor };
294
+ }
295
+ function startFailed(e, host) {
296
+ const message = e instanceof Error ? e.message : String(e);
297
+ try {
298
+ ensureDirSync(path.dirname(host.startFailure.path));
299
+ atomicWriteText(host.startFailure.path, JSON.stringify({ key: host.startFailure.key, message, at: Date.now() }));
300
+ } catch {
301
+ return host.failed(e, false);
302
+ }
303
+ return host.failed(e, true);
304
+ }
305
+ registerReset(() => {
306
+ _webLoad = null;
307
+ _inFlightWasm = null;
308
+ });
309
+ export {
310
+ ORT_WEB_GLUE,
311
+ ORT_WEB_TARBALL,
312
+ createWebSession,
313
+ ensureWasmBinary,
314
+ extractTarMember
315
+ };
@@ -0,0 +1,371 @@
1
+ import { createRequire as __cjsRequire } from 'node:module';
2
+ const require = __cjsRequire(import.meta.url);
3
+ import {
4
+ formatCommandError,
5
+ writeCommandFailure
6
+ } from "./token-goat-chunk-CBIQ7WTD.mjs";
7
+ import {
8
+ loadConfig
9
+ } from "./token-goat-chunk-7EZTZOMC.mjs";
10
+ import {
11
+ ensureDirSync
12
+ } from "./token-goat-chunk-HU4TORC5.mjs";
13
+ import {
14
+ fencedCommand
15
+ } from "./token-goat-chunk-GGGG7RWB.mjs";
16
+ import {
17
+ displaySafeJson
18
+ } from "./token-goat-chunk-FNFBKLRD.mjs";
19
+ import {
20
+ VERSION,
21
+ dataDir
22
+ } from "./token-goat-chunk-CO3UYX6G.mjs";
23
+ import {
24
+ init_define_import_meta_env
25
+ } from "./token-goat-chunk-A37V4PBF.mjs";
26
+
27
+ // src/cli_upgrade.ts
28
+ init_define_import_meta_env();
29
+ import { spawnSync } from "node:child_process";
30
+ import * as fs from "node:fs";
31
+ import * as path from "node:path";
32
+ import * as https from "node:https";
33
+ import { createRequire } from "node:module";
34
+ import { fileURLToPath } from "node:url";
35
+ var require2 = createRequire(import.meta.url);
36
+ var UPDATE_CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
37
+ var SEMVER = /^\d+\.\d+\.\d+(?:-[\w.-]+)?$/;
38
+ var FAILED_CHECK_TTL_MS = 60 * 60 * 1e3;
39
+ function getCachedUpdateStatus() {
40
+ try {
41
+ const cachePath = path.join(dataDir(), "update_check.json");
42
+ if (!fs.existsSync(cachePath)) return null;
43
+ const raw = fs.readFileSync(cachePath, "utf8");
44
+ const parsed = JSON.parse(raw);
45
+ if (parsed && typeof parsed.checkedAt === "number") {
46
+ const latest = typeof parsed.latest === "string" && SEMVER.test(parsed.latest) ? parsed.latest : null;
47
+ 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 };
48
+ }
49
+ } catch {
50
+ }
51
+ return null;
52
+ }
53
+ function saveCachedUpdateStatus(info) {
54
+ try {
55
+ const dir = dataDir();
56
+ ensureDirSync(dir);
57
+ const cachePath = path.join(dir, "update_check.json");
58
+ fs.writeFileSync(cachePath, JSON.stringify(info, null, 2), "utf8");
59
+ } catch {
60
+ }
61
+ }
62
+ function getRegistryUrl() {
63
+ const envRegistry = process.env["NPM_CONFIG_REGISTRY"] || process.env["npm_config_registry"];
64
+ if (envRegistry && typeof envRegistry === "string") {
65
+ return envRegistry.endsWith("/") ? envRegistry : `${envRegistry}/`;
66
+ }
67
+ return "https://registry.npmjs.org/";
68
+ }
69
+ function npmInvocation(host) {
70
+ const named = host.env["npm_execpath"];
71
+ if (typeof named === "string" && /(?:^|[\\/])npm-cli\.js$/.test(named) && host.exists(named)) return { file: host.execPath, prefix: [named] };
72
+ if (host.platform !== "win32") return { file: "npm", prefix: [] };
73
+ const bundled = path.win32.join(path.win32.dirname(host.execPath), "node_modules", "npm", "bin", "npm-cli.js");
74
+ return host.exists(bundled) ? { file: host.execPath, prefix: [bundled] } : null;
75
+ }
76
+ function hostNpm() {
77
+ return npmInvocation({ platform: process.platform, env: process.env, execPath: process.execPath, exists: (p) => fs.existsSync(p) });
78
+ }
79
+ function runningPackageRoot(moduleUrl = import.meta.url) {
80
+ let dir;
81
+ try {
82
+ dir = fs.realpathSync(path.dirname(fileURLToPath(moduleUrl)));
83
+ } catch {
84
+ return null;
85
+ }
86
+ for (; ; ) {
87
+ try {
88
+ const pkg = JSON.parse(fs.readFileSync(path.join(dir, "package.json"), "utf8"));
89
+ if (pkg.name === "token-goat") return dir;
90
+ } catch {
91
+ }
92
+ const parent = path.dirname(dir);
93
+ if (parent === dir) return null;
94
+ dir = parent;
95
+ }
96
+ }
97
+ function isDevCheckout(root) {
98
+ return root !== null && fs.existsSync(path.join(root, ".git")) && fs.existsSync(path.join(root, "esbuild.config.mjs"));
99
+ }
100
+ function upgradeDecision(status, offline, devCheckout) {
101
+ if (offline) return "offline";
102
+ if (status.error || !status.latest) return "unreachable";
103
+ if (!status.updateAvailable) return "up-to-date";
104
+ if (devCheckout) return "dev-checkout";
105
+ return "install";
106
+ }
107
+ function currentUpgradeDecision(status) {
108
+ return upgradeDecision(status, loadConfig().network.offline, isDevCheckout(runningPackageRoot()));
109
+ }
110
+ var DEV_CHECKOUT_ADVICE = "git pull && npm run build && token-goat install";
111
+ function updateAdvice(decision) {
112
+ if (decision === "install") return "Run `token-goat upgrade` to update.";
113
+ if (decision === "dev-checkout") return `This token-goat runs from a development checkout. To update it, run: ${DEV_CHECKOUT_ADVICE}`;
114
+ return null;
115
+ }
116
+ function fetchViaNpm(timeoutMs = 2500) {
117
+ const npm = hostNpm();
118
+ if (!npm) return null;
119
+ try {
120
+ const res = spawnSync(npm.file, [...npm.prefix, "view", "token-goat", "version"], {
121
+ encoding: "utf8",
122
+ timeout: timeoutMs,
123
+ stdio: ["ignore", "pipe", "ignore"],
124
+ windowsHide: true
125
+ });
126
+ if (res.status === 0 && res.stdout) {
127
+ const trimmed = res.stdout.trim();
128
+ if (SEMVER.test(trimmed)) {
129
+ return trimmed;
130
+ }
131
+ }
132
+ } catch {
133
+ }
134
+ return null;
135
+ }
136
+ async function fetchViaHttp(registryUrl, timeoutMs = 3500) {
137
+ return new Promise((resolve) => {
138
+ try {
139
+ const cleanUrl = registryUrl.endsWith("/") ? registryUrl : `${registryUrl}/`;
140
+ const targetUrl = new URL(`token-goat/latest`, cleanUrl);
141
+ const isHttps = targetUrl.protocol === "https:";
142
+ const getFn = isHttps ? https.get : require2("node:http").get;
143
+ const req = getFn(
144
+ targetUrl,
145
+ {
146
+ headers: { "User-Agent": `token-goat/${VERSION} (node/${process.version})` },
147
+ // A fresh connection, never one pooled by the global agent: after npm's blocking spawn the registry may have closed the pooled one, and reusing it fails with ECONNRESET.
148
+ agent: false,
149
+ timeout: timeoutMs
150
+ },
151
+ (res) => {
152
+ if (res.statusCode !== 200) {
153
+ res.resume();
154
+ resolve(null);
155
+ return;
156
+ }
157
+ let data = "";
158
+ res.setEncoding("utf8");
159
+ res.on("data", (chunk) => {
160
+ data += chunk;
161
+ if (data.length > 32768) {
162
+ req.destroy();
163
+ resolve(null);
164
+ }
165
+ });
166
+ res.on("end", () => {
167
+ try {
168
+ const parsed = JSON.parse(data);
169
+ const version = parsed.version || parsed["dist-tags"]?.latest;
170
+ if (version && typeof version === "string" && SEMVER.test(version)) {
171
+ resolve(version);
172
+ } else {
173
+ resolve(null);
174
+ }
175
+ } catch {
176
+ resolve(null);
177
+ }
178
+ });
179
+ }
180
+ );
181
+ req.on("timeout", () => {
182
+ req.destroy();
183
+ resolve(null);
184
+ });
185
+ req.on("error", () => {
186
+ resolve(null);
187
+ });
188
+ } catch {
189
+ resolve(null);
190
+ }
191
+ });
192
+ }
193
+ async function fetchLatestVersion(timeoutMs = 3500) {
194
+ if (loadConfig().network.offline) {
195
+ return null;
196
+ }
197
+ const npmVersion = fetchViaNpm(Math.min(timeoutMs, 2500));
198
+ if (npmVersion) {
199
+ return npmVersion;
200
+ }
201
+ const registryUrl = getRegistryUrl();
202
+ return fetchViaHttp(registryUrl, timeoutMs);
203
+ }
204
+ function compareSemver(a, b) {
205
+ const pa = a.split("-")[0].split(".").map((x) => parseInt(x, 10) || 0);
206
+ const pb = b.split("-")[0].split(".").map((x) => parseInt(x, 10) || 0);
207
+ for (let i = 0; i < 3; i++) {
208
+ const na = pa[i] ?? 0;
209
+ const nb = pb[i] ?? 0;
210
+ if (na > nb) return 1;
211
+ if (na < nb) return -1;
212
+ }
213
+ return 0;
214
+ }
215
+ async function checkUpdateStatus(timeoutMs = 3500, forceFresh = false) {
216
+ if (!forceFresh) {
217
+ const cached = getCachedUpdateStatus();
218
+ if (cached && Date.now() - cached.checkedAt < (cached.latest ? UPDATE_CACHE_TTL_MS : FAILED_CHECK_TTL_MS)) {
219
+ return { current: VERSION, latest: cached.latest, updateAvailable: cached.updateAvailable, error: cached.error };
220
+ }
221
+ }
222
+ const latest = await fetchLatestVersion(timeoutMs);
223
+ if (!latest) {
224
+ if (loadConfig().network.offline) {
225
+ return { current: VERSION, latest: null, updateAvailable: false, error: "network.offline is set, so no update check was made" };
226
+ }
227
+ const result2 = {
228
+ current: VERSION,
229
+ latest: null,
230
+ updateAvailable: false,
231
+ error: "Could not reach npm or internal registry (request failed or timed out)"
232
+ };
233
+ saveCachedUpdateStatus({
234
+ checkedAt: Date.now(),
235
+ current: VERSION,
236
+ latest: null,
237
+ updateAvailable: false,
238
+ error: result2.error
239
+ });
240
+ return result2;
241
+ }
242
+ const updateAvailable = compareSemver(latest, VERSION) > 0;
243
+ const result = {
244
+ current: VERSION,
245
+ latest,
246
+ updateAvailable
247
+ };
248
+ saveCachedUpdateStatus({
249
+ checkedAt: Date.now(),
250
+ current: VERSION,
251
+ latest,
252
+ updateAvailable
253
+ });
254
+ return result;
255
+ }
256
+ async function cmdUpgrade(opts = {}, onSyncHooks) {
257
+ const status = await checkUpdateStatus(3500, true);
258
+ if (opts.check) {
259
+ const failure = status.error ?? (status.latest ? void 0 : "could not determine the latest version");
260
+ if (failure !== void 0) {
261
+ writeCommandFailure(opts.json === true, { ...status }, [`${failure}.`, `Current version: v${status.current}`]);
262
+ return;
263
+ }
264
+ if (opts.json) {
265
+ console.log(displaySafeJson(status, 2));
266
+ return;
267
+ }
268
+ if (status.updateAvailable && status.latest) {
269
+ console.log(`Update available: v${status.current} -> v${status.latest}`);
270
+ console.log(`Run \`token-goat upgrade\` to update.`);
271
+ } else {
272
+ console.log(`token-goat is up to date (v${status.current})`);
273
+ }
274
+ return;
275
+ }
276
+ const decision = currentUpgradeDecision(status);
277
+ switch (decision) {
278
+ case "offline":
279
+ console.error(formatCommandError("network.offline is set, so no update check was made and nothing was installed. Unset it (or TOKEN_GOAT_OFFLINE) to upgrade."));
280
+ process.exitCode = 1;
281
+ return;
282
+ case "unreachable":
283
+ console.error(formatCommandError(`${status.error ?? "could not determine the latest version"}. Nothing was installed.`));
284
+ process.exitCode = 1;
285
+ return;
286
+ case "up-to-date":
287
+ console.log(`token-goat is up to date (v${status.current})`);
288
+ return;
289
+ case "dev-checkout":
290
+ console.log(`Update available: v${status.current} -> v${status.latest}`);
291
+ console.log(`This token-goat runs from a development checkout, so it was not replaced. To update it, run:`);
292
+ console.log(` ${DEV_CHECKOUT_ADVICE}`);
293
+ return;
294
+ case "install":
295
+ break;
296
+ }
297
+ console.log(`Upgrading token-goat v${status.current} -> v${status.latest}...`);
298
+ const outcome = await performUpgrade(onSyncHooks);
299
+ if (!outcome.ok) {
300
+ console.error(formatCommandError(outcome.message));
301
+ process.exitCode = 1;
302
+ return;
303
+ }
304
+ console.log(`[\u2713] token-goat successfully updated.`);
305
+ }
306
+ var MANUAL_INSTALL = "npm install -g token-goat@latest";
307
+ async function performUpgrade(onSyncHooks, npm = hostNpm()) {
308
+ if (!npm) return { ok: false, message: `npm was not found next to this Node.js, so token-goat could not upgrade itself. Run ${fencedCommand(MANUAL_INSTALL)} yourself.` };
309
+ let stoppedPid = [];
310
+ try {
311
+ const { stopWorker, readPidFile } = await import("./token-goat-chunk-NSNSPPBG.mjs");
312
+ const { queryServers } = await import("./token-goat-hook-client.mjs");
313
+ await queryServers("stop");
314
+ const tracked = readPidFile(dataDir());
315
+ if (stopWorker() && tracked !== null) stoppedPid = [tracked];
316
+ } catch {
317
+ }
318
+ try {
319
+ const { retireStrayResidents, describeRetirement, UPGRADE_RESIDENT_KINDS } = await import("./token-goat-chunk-TAUZ4OFS.mjs");
320
+ const note = describeRetirement(await retireStrayResidents({ kinds: UPGRADE_RESIDENT_KINDS, skip: stoppedPid }));
321
+ if (note !== null) console.log(note);
322
+ } catch {
323
+ }
324
+ const install = spawnSync(npm.file, [...npm.prefix, "install", "-g", "token-goat@latest"], { stdio: "inherit", windowsHide: true });
325
+ if (install.status !== 0) {
326
+ const why = install.error ? install.error.message : `exit code ${install.status ?? "unknown"}`;
327
+ 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 ${fencedCommand(MANUAL_INSTALL)}.` };
328
+ }
329
+ console.log(`Syncing token-goat hooks and integration manifests...`);
330
+ const launcher = installedLauncher(npm);
331
+ if (launcher) {
332
+ const sync = spawnSync(process.execPath, [launcher, "install"], { stdio: "inherit", windowsHide: true });
333
+ 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.` };
334
+ return { ok: true };
335
+ }
336
+ try {
337
+ if (onSyncHooks) await onSyncHooks();
338
+ } catch (e) {
339
+ 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.` };
340
+ }
341
+ return { ok: true };
342
+ }
343
+ function installedLauncher(npm) {
344
+ const res = spawnSync(npm.file, [...npm.prefix, "root", "-g"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], windowsHide: true });
345
+ const root = res.status === 0 && typeof res.stdout === "string" ? res.stdout.trim() : "";
346
+ if (!root) return null;
347
+ const launcher = path.join(root, "token-goat", "dist", "token-goat.mjs");
348
+ return fs.existsSync(launcher) ? launcher : null;
349
+ }
350
+
351
+ export {
352
+ UPDATE_CACHE_TTL_MS,
353
+ FAILED_CHECK_TTL_MS,
354
+ getCachedUpdateStatus,
355
+ saveCachedUpdateStatus,
356
+ getRegistryUrl,
357
+ npmInvocation,
358
+ runningPackageRoot,
359
+ isDevCheckout,
360
+ upgradeDecision,
361
+ currentUpgradeDecision,
362
+ DEV_CHECKOUT_ADVICE,
363
+ updateAdvice,
364
+ fetchViaNpm,
365
+ fetchViaHttp,
366
+ fetchLatestVersion,
367
+ compareSemver,
368
+ checkUpdateStatus,
369
+ cmdUpgrade,
370
+ performUpgrade
371
+ };