clikcode 1.0.3 → 1.0.5

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 (323) hide show
  1. package/README.md +25 -14
  2. package/dist/chunk-23TDEBGZ.js +71 -0
  3. package/dist/chunk-25T3GVS7.js +425 -0
  4. package/dist/chunk-2BBELGHY.js +11 -0
  5. package/dist/chunk-2EOL5PZL.js +208 -0
  6. package/dist/chunk-2GAB36IE.js +26 -0
  7. package/dist/chunk-2OLS7V66.js +2440 -0
  8. package/dist/chunk-2QFO2URB.js +179 -0
  9. package/dist/chunk-2QWPQRSU.js +254 -0
  10. package/dist/chunk-2YPAPAR3.js +184 -0
  11. package/dist/chunk-2ZAG5372.js +33 -0
  12. package/dist/chunk-32IKAIZC.js +12507 -0
  13. package/dist/chunk-34AZEGYW.js +95 -0
  14. package/dist/chunk-34JQYQCA.js +175 -0
  15. package/dist/chunk-34ZISPAO.js +67 -0
  16. package/dist/chunk-3AAAARE6.js +46 -0
  17. package/dist/chunk-3AJ6Q3OY.js +510 -0
  18. package/dist/chunk-3B2CHX7M.js +884 -0
  19. package/dist/chunk-3BUFORRX.js +59 -0
  20. package/dist/chunk-3QLHYYFK.js +30 -0
  21. package/dist/chunk-3RXBMYKZ.js +140 -0
  22. package/dist/chunk-3TFNIJWS.js +52 -0
  23. package/dist/chunk-3W3IPDFP.js +119 -0
  24. package/dist/chunk-3WMS7SEE.js +417 -0
  25. package/dist/chunk-435ZNSZ3.js +23 -0
  26. package/dist/chunk-4AQ5NINV.js +39 -0
  27. package/dist/chunk-4GVEJ5FK.js +168 -0
  28. package/dist/chunk-4GXAO3UY.js +262 -0
  29. package/dist/chunk-4L2ZZM4Q.js +332 -0
  30. package/dist/chunk-4LPDG57B.js +17 -0
  31. package/dist/chunk-4NN3XQQT.js +223 -0
  32. package/dist/chunk-4QZEZME7.js +54 -0
  33. package/dist/chunk-4R6CSC3S.js +38 -0
  34. package/dist/chunk-4RHXTL3W.js +514 -0
  35. package/dist/chunk-4SJMPTVQ.js +18 -0
  36. package/dist/chunk-4VY7G6TX.js +114 -0
  37. package/dist/chunk-5642PBF7.js +124 -0
  38. package/dist/chunk-5B6TVO4A.js +33 -0
  39. package/dist/chunk-5BJLDUPL.js +62 -0
  40. package/dist/chunk-5HMFFJWU.js +19 -0
  41. package/dist/chunk-5IKLK33T.js +69 -0
  42. package/dist/chunk-5NQ5FFMX.js +44 -0
  43. package/dist/chunk-5QNNW5L6.js +176 -0
  44. package/dist/chunk-5SM5UAWN.js +239 -0
  45. package/dist/chunk-5WYJTA6O.js +74 -0
  46. package/dist/chunk-5ZSR2Y5T.js +227 -0
  47. package/dist/chunk-5ZWUM5GH.js +39 -0
  48. package/dist/chunk-64E7D4HY.js +364 -0
  49. package/dist/chunk-6CK466BC.js +99 -0
  50. package/dist/chunk-6ES45HHO.js +138 -0
  51. package/dist/chunk-6HYEZFGL.js +277 -0
  52. package/dist/chunk-6Y7HLXGW.js +29 -0
  53. package/dist/chunk-6YKK4FYR.js +258 -0
  54. package/dist/chunk-74WNMLMS.js +117 -0
  55. package/dist/chunk-7AULZ7OD.js +55 -0
  56. package/dist/chunk-7DOKGSUN.js +101 -0
  57. package/dist/chunk-7IH5LTIZ.js +195 -0
  58. package/dist/chunk-7ISTS5NS.js +21 -0
  59. package/dist/chunk-7NMUTGOW.js +527 -0
  60. package/dist/chunk-7PNHUZEL.js +153 -0
  61. package/dist/chunk-7TSQLONI.js +88 -0
  62. package/dist/chunk-AE7TOLD5.js +30 -0
  63. package/dist/chunk-AEMHSXKA.js +130 -0
  64. package/dist/chunk-AKRYTS2D.js +211 -0
  65. package/dist/chunk-AMNSE36L.js +59 -0
  66. package/dist/chunk-AZVD74ZV.js +23 -0
  67. package/dist/chunk-B35DVOTK.js +1981 -0
  68. package/dist/chunk-B4HNJRAH.js +626 -0
  69. package/dist/chunk-B5WYPPHS.js +13 -0
  70. package/dist/chunk-BBOVDXQM.js +59 -0
  71. package/dist/chunk-BD3ECZLK.js +62 -0
  72. package/dist/chunk-BDGSOT74.js +4578 -0
  73. package/dist/chunk-BF5VEOPK.js +31 -0
  74. package/dist/chunk-BFFRW4XH.js +47 -0
  75. package/dist/chunk-BFPC6PEW.js +208 -0
  76. package/dist/chunk-BGEMY2JJ.js +376 -0
  77. package/dist/chunk-BISGNHKD.js +35 -0
  78. package/dist/chunk-BMRAEBRY.js +21 -0
  79. package/dist/chunk-BNTXAZXW.js +127 -0
  80. package/dist/chunk-BOQBXGSN.js +75 -0
  81. package/dist/chunk-BTJDSTQP.js +213 -0
  82. package/dist/chunk-BUOPJQP5.js +218 -0
  83. package/dist/chunk-BXFJS65Q.js +52 -0
  84. package/dist/chunk-BXPQFSX5.js +59 -0
  85. package/dist/chunk-C57LIWNY.js +1269 -0
  86. package/dist/chunk-C6YVCCWR.js +74 -0
  87. package/dist/chunk-CAADDF6M.js +167 -0
  88. package/dist/chunk-CBANJFBO.js +69 -0
  89. package/dist/chunk-CERF3RIB.js +597 -0
  90. package/dist/chunk-COAS5ETR.js +46 -0
  91. package/dist/chunk-CQ7J6UQ7.js +78 -0
  92. package/dist/chunk-CRUVYGO2.js +26 -0
  93. package/dist/chunk-CVFVFRGN.js +58 -0
  94. package/dist/chunk-D2UK66HM.js +37 -0
  95. package/dist/chunk-D2W7SA4R.js +18 -0
  96. package/dist/chunk-DA44ZENT.js +501 -0
  97. package/dist/chunk-DAJ76TOC.js +99 -0
  98. package/dist/chunk-DCZ6CIUM.js +147 -0
  99. package/dist/chunk-DF35KMXM.js +1314 -0
  100. package/dist/chunk-DGASQT26.js +151 -0
  101. package/dist/chunk-DJT57C5P.js +55 -0
  102. package/dist/chunk-DKDPZTD3.js +44 -0
  103. package/dist/chunk-DQYVQ2N7.js +77 -0
  104. package/dist/chunk-DRTP2RTY.js +266 -0
  105. package/dist/chunk-DW2BMUKY.js +61 -0
  106. package/dist/chunk-DW5T5ZVU.js +307 -0
  107. package/dist/chunk-DXKNDNFC.js +164 -0
  108. package/dist/chunk-DZEQ7UYR.js +291 -0
  109. package/dist/chunk-E4F4OUAC.js +463 -0
  110. package/dist/chunk-EE4B6A7W.js +69 -0
  111. package/dist/chunk-EISKIYWG.js +23 -0
  112. package/dist/chunk-EKAQK7UQ.js +235 -0
  113. package/dist/chunk-EOBTJV32.js +123 -0
  114. package/dist/chunk-ESF3DIZY.js +325 -0
  115. package/dist/chunk-EVOHOZ4U.js +45 -0
  116. package/dist/chunk-EXN4KHLB.js +110 -0
  117. package/dist/chunk-F252T6Y3.js +78 -0
  118. package/dist/chunk-F3DP4ZA2.js +40 -0
  119. package/dist/chunk-F6F47QAY.js +58 -0
  120. package/dist/chunk-FA3Y23ZW.js +57 -0
  121. package/dist/chunk-FBKXE4EJ.js +640 -0
  122. package/dist/chunk-FCGEB3H6.js +23 -0
  123. package/dist/chunk-FF7ZVYJF.js +3732 -0
  124. package/dist/chunk-FFGKN6L3.js +39 -0
  125. package/dist/chunk-FFGU4GCC.js +94 -0
  126. package/dist/chunk-FSFDAOVP.js +74 -0
  127. package/dist/chunk-FT5TX7OX.js +1573 -0
  128. package/dist/chunk-G3QP67Z7.js +232 -0
  129. package/dist/chunk-G5ORJKV2.js +179 -0
  130. package/dist/chunk-GFNC62PE.js +111 -0
  131. package/dist/chunk-GGK43Q3N.js +67 -0
  132. package/dist/chunk-GGYKY4GF.js +11537 -0
  133. package/dist/chunk-GGYNHGNJ.js +55 -0
  134. package/dist/chunk-GLY7RM3C.js +354 -0
  135. package/dist/chunk-GQBZU6EO.js +20 -0
  136. package/dist/chunk-GSXENUZL.js +9 -0
  137. package/dist/chunk-GTOAT5D3.js +40 -0
  138. package/dist/chunk-GWCMDPQU.js +1007 -0
  139. package/dist/chunk-GXYSMYHJ.js +152 -0
  140. package/dist/chunk-GYMAI5NY.js +14 -0
  141. package/dist/chunk-H2VZMKPE.js +30 -0
  142. package/dist/chunk-H4THUNBM.js +2091 -0
  143. package/dist/chunk-HGRVSNUZ.js +361 -0
  144. package/dist/chunk-HI4VY473.js +27 -0
  145. package/dist/chunk-HOJRSD3Q.js +447 -0
  146. package/dist/chunk-HRX25W35.js +82 -0
  147. package/dist/chunk-HSE4AQYV.js +55 -0
  148. package/dist/chunk-HU5SSUFX.js +383 -0
  149. package/dist/chunk-I3GDBJLH.js +196 -0
  150. package/dist/chunk-I75EDU75.js +684 -0
  151. package/dist/chunk-IBA7DMIO.js +20 -0
  152. package/dist/chunk-IC6N4NZA.js +231 -0
  153. package/dist/chunk-IF43HIGV.js +284 -0
  154. package/dist/chunk-IGZ6C2MC.js +439 -0
  155. package/dist/chunk-IMLTL2MY.js +192 -0
  156. package/dist/chunk-IMZL6SGR.js +33 -0
  157. package/dist/chunk-IS4USJPY.js +516 -0
  158. package/dist/chunk-ISFSPN2F.js +82 -0
  159. package/dist/chunk-IXE7GTFI.js +55 -0
  160. package/dist/chunk-IZ77QJQG.js +36 -0
  161. package/dist/chunk-J2PACWRQ.js +34 -0
  162. package/dist/chunk-J6EGFVQX.js +180 -0
  163. package/dist/chunk-JEKOD43D.js +22 -0
  164. package/dist/chunk-JGIWATSG.js +30 -0
  165. package/dist/chunk-JYBONKD4.js +43 -0
  166. package/dist/chunk-K2NLG2HK.js +454 -0
  167. package/dist/chunk-KCQ4TBLS.js +164 -0
  168. package/dist/chunk-KD5KIVMS.js +176 -0
  169. package/dist/chunk-KHW6TX6I.js +63 -0
  170. package/dist/chunk-KI5GZFCE.js +520 -0
  171. package/dist/chunk-KN34B7NO.js +105 -0
  172. package/dist/chunk-KYUHIFP3.js +136 -0
  173. package/dist/chunk-KZL5VS4B.js +300 -0
  174. package/dist/chunk-L3VW3QIH.js +48 -0
  175. package/dist/chunk-LA6MG4ET.js +2110 -0
  176. package/dist/chunk-LAVFOA3S.js +66 -0
  177. package/dist/chunk-LB4OA77N.js +13 -0
  178. package/dist/chunk-LBFRF2K4.js +196 -0
  179. package/dist/chunk-LM6EIA4B.js +93 -0
  180. package/dist/chunk-LPCNRGJ7.js +692 -0
  181. package/dist/chunk-LSLNL5T3.js +168 -0
  182. package/dist/chunk-LVRRWP4W.js +568 -0
  183. package/dist/chunk-LWCFBRHL.js +33 -0
  184. package/dist/chunk-LXFTMGZZ.js +166 -0
  185. package/dist/chunk-M33LVA4M.js +151 -0
  186. package/dist/chunk-M3FO5UMK.js +4944 -0
  187. package/dist/chunk-M5QNDBAY.js +66 -0
  188. package/dist/chunk-M6ND6KBE.js +1291 -0
  189. package/dist/chunk-M7H3WQTE.js +76 -0
  190. package/dist/chunk-MCBRVPA7.js +191 -0
  191. package/dist/chunk-MCSDWZET.js +91 -0
  192. package/dist/chunk-MDT5XDXL.js +289 -0
  193. package/dist/chunk-MJG3IQY4.js +91 -0
  194. package/dist/chunk-MOU3N2UL.js +44 -0
  195. package/dist/chunk-MP4KZOQC.js +3451 -0
  196. package/dist/chunk-MPAJ446F.js +66 -0
  197. package/dist/chunk-MVJZZ6AL.js +16 -0
  198. package/dist/chunk-MXS6S2PY.js +253 -0
  199. package/dist/chunk-N3SFDYM7.js +291 -0
  200. package/dist/chunk-NAOX3JUB.js +13 -0
  201. package/dist/chunk-NEKKIBCX.js +283 -0
  202. package/dist/chunk-NKDATMEM.js +133 -0
  203. package/dist/chunk-NR4FMC4K.js +395 -0
  204. package/dist/chunk-NSOHOJBR.js +221 -0
  205. package/dist/chunk-NTDB6QKF.js +29 -0
  206. package/dist/chunk-NWEYRBWK.js +25 -0
  207. package/dist/chunk-O2YSNYWD.js +23 -0
  208. package/dist/chunk-O3EW7LAY.js +54 -0
  209. package/dist/chunk-O7BNJIXU.js +366 -0
  210. package/dist/chunk-OARL2NXZ.js +116 -0
  211. package/dist/chunk-OHKZUEJW.js +351 -0
  212. package/dist/chunk-OKU45BXA.js +647 -0
  213. package/dist/chunk-OL4JBD3J.js +59 -0
  214. package/dist/chunk-OLUO5DDR.js +192 -0
  215. package/dist/chunk-OQ245JLA.js +196 -0
  216. package/dist/chunk-P72UZAQI.js +289 -0
  217. package/dist/chunk-PAL2ENB6.js +20 -0
  218. package/dist/chunk-PAXYQZH7.js +53 -0
  219. package/dist/chunk-PDPEM5VW.js +51 -0
  220. package/dist/chunk-PEWCDI2C.js +668 -0
  221. package/dist/chunk-PGZ54EDX.js +27 -0
  222. package/dist/chunk-PRWVLDZF.js +73 -0
  223. package/dist/chunk-PSQQ75VJ.js +52 -0
  224. package/dist/chunk-PUOVIFHW.js +118 -0
  225. package/dist/chunk-PWBF2X3V.js +107 -0
  226. package/dist/chunk-PWXII6HF.js +43 -0
  227. package/dist/chunk-Q35VLJRT.js +80 -0
  228. package/dist/chunk-QJP7EYGL.js +128 -0
  229. package/dist/chunk-QPQKX2MK.js +8836 -0
  230. package/dist/chunk-QQRLPY25.js +1053 -0
  231. package/dist/chunk-QUS4ER2W.js +407 -0
  232. package/dist/chunk-QYHI3YET.js +29 -0
  233. package/dist/chunk-QYRU2UQI.js +32 -0
  234. package/dist/chunk-R6XVVQGC.js +13 -0
  235. package/dist/chunk-R7QN6ONS.js +483 -0
  236. package/dist/chunk-RD23MPGC.js +221 -0
  237. package/dist/chunk-RDDWQBEM.js +185 -0
  238. package/dist/chunk-RDLLDYFO.js +104 -0
  239. package/dist/chunk-RE4TGORR.js +84 -0
  240. package/dist/chunk-RJLHVYQY.js +217 -0
  241. package/dist/chunk-RJLPTWHW.js +905 -0
  242. package/dist/chunk-RKUVLRZI.js +295 -0
  243. package/dist/chunk-ROGXPGYR.js +37 -0
  244. package/dist/chunk-RSZGEL5U.js +163 -0
  245. package/dist/chunk-RVUOIJXN.js +909 -0
  246. package/dist/chunk-RW7F4JRP.js +11 -0
  247. package/dist/chunk-S4UO3AO3.js +53 -0
  248. package/dist/chunk-S5JAAF6S.js +585 -0
  249. package/dist/chunk-SNU37TQI.js +56 -0
  250. package/dist/chunk-SQVUDO2O.js +31 -0
  251. package/dist/chunk-SYVHIYQT.js +66 -0
  252. package/dist/chunk-SZBQMTG2.js +85 -0
  253. package/dist/chunk-T5VCXA3J.js +25 -0
  254. package/dist/chunk-TK6NSP56.js +30 -0
  255. package/dist/chunk-TKWVMA6L.js +22 -0
  256. package/dist/chunk-TQDKJHWX.js +59 -0
  257. package/dist/chunk-TQDM7S5N.js +127 -0
  258. package/dist/chunk-TULAXS77.js +23 -0
  259. package/dist/chunk-TVT45XNH.js +4625 -0
  260. package/dist/chunk-TWCVV2JO.js +467 -0
  261. package/dist/chunk-U4DKAD6S.js +47 -0
  262. package/dist/chunk-UA5K2BTI.js +564 -0
  263. package/dist/chunk-UAMKCMOK.js +40 -0
  264. package/dist/chunk-UBMVADBF.js +51 -0
  265. package/dist/chunk-UFQ5A5PW.js +645 -0
  266. package/dist/chunk-UOD2SOLL.js +1301 -0
  267. package/dist/chunk-UTSB4LOW.js +156 -0
  268. package/dist/chunk-UVXNIUTN.js +412 -0
  269. package/dist/chunk-UXVPXYPE.js +90 -0
  270. package/dist/chunk-UYEEMIWR.js +374 -0
  271. package/dist/chunk-VBGM5ZBW.js +54 -0
  272. package/dist/chunk-VEWPCZPG.js +762 -0
  273. package/dist/chunk-VIRDLZ5E.js +108 -0
  274. package/dist/chunk-VMPO7WKN.js +52 -0
  275. package/dist/chunk-W2NVSDO5.js +5122 -0
  276. package/dist/chunk-W3YYPBEA.js +176 -0
  277. package/dist/chunk-W5AYOICN.js +280 -0
  278. package/dist/chunk-W5GZOIUF.js +27 -0
  279. package/dist/chunk-WHKNLZ3C.js +76 -0
  280. package/dist/chunk-WKBEPPQ5.js +1409 -0
  281. package/dist/chunk-WM3Z6QKQ.js +151 -0
  282. package/dist/chunk-WMI2TPMA.js +31 -0
  283. package/dist/chunk-WNX5VD7S.js +150 -0
  284. package/dist/chunk-WOVTYST3.js +60 -0
  285. package/dist/chunk-WPB5WEZJ.js +546 -0
  286. package/dist/chunk-WUO5EOAT.js +44 -0
  287. package/dist/chunk-WWLJMP6D.js +133 -0
  288. package/dist/chunk-WZMLH3XP.js +58 -0
  289. package/dist/chunk-WZYVLUVQ.js +79 -0
  290. package/dist/chunk-X2OCPVU5.js +135 -0
  291. package/dist/chunk-X3CL6DTR.js +95 -0
  292. package/dist/chunk-X6WF7JEV.js +354 -0
  293. package/dist/chunk-XAHGBPWT.js +44 -0
  294. package/dist/chunk-XCKQ5BM2.js +228 -0
  295. package/dist/chunk-XIBYREEY.js +106 -0
  296. package/dist/chunk-XKW5NDMR.js +378 -0
  297. package/dist/chunk-XRDALAO3.js +100 -0
  298. package/dist/chunk-XUP22EAS.js +41 -0
  299. package/dist/chunk-XWAC3MKW.js +243 -0
  300. package/dist/chunk-Y3R7JMXB.js +59 -0
  301. package/dist/chunk-Y54LTP4W.js +82 -0
  302. package/dist/chunk-Y7UECI4M.js +99 -0
  303. package/dist/chunk-YACGDFHC.js +47 -0
  304. package/dist/chunk-YHNIQPKY.js +71 -0
  305. package/dist/chunk-YMBR6HYP.js +111 -0
  306. package/dist/chunk-YMCH3L2S.js +26 -0
  307. package/dist/chunk-Z4ZU6T7V.js +99 -0
  308. package/dist/chunk-ZDPF67ZZ.js +173 -0
  309. package/dist/chunk-ZFC2Q67K.js +101 -0
  310. package/dist/chunk-ZGHNNSCT.js +114 -0
  311. package/dist/chunk-ZGX3ERAT.js +173 -0
  312. package/dist/chunk-ZI3YHEBY.js +37 -0
  313. package/dist/chunk-ZN7G6JLS.js +639 -0
  314. package/dist/chunk-ZNPFQMXT.js +47 -0
  315. package/dist/chunk-ZOU3LV4U.js +63 -0
  316. package/dist/chunk-ZT7B4H2V.js +117 -0
  317. package/dist/chunk-ZZCBDNZI.js +58 -0
  318. package/dist/cli.js +498 -112593
  319. package/dist/computer-tools.js +36642 -21258
  320. package/dist/harness-catalog.cjs +88 -43
  321. package/dist/index.js +1 -1
  322. package/dist/local-model-supervisor.cjs +555 -0
  323. package/package.json +3 -4
@@ -0,0 +1,516 @@
1
+ import { createRequire as __clikcodeCreateRequire } from 'node:module';
2
+ const require = __clikcodeCreateRequire(import.meta.url);
3
+ import {
4
+ allLocalModels,
5
+ registerRemoteModels
6
+ } from "./chunk-TQDKJHWX.js";
7
+ import {
8
+ discoveredModelsFile,
9
+ modelsDir
10
+ } from "./chunk-PEWCDI2C.js";
11
+ import {
12
+ quiet
13
+ } from "./chunk-RDDWQBEM.js";
14
+
15
+ // src/local-models/download.ts
16
+ import { createHash } from "node:crypto";
17
+ import { createReadStream, createWriteStream, existsSync } from "node:fs";
18
+ import { mkdir, rename, rm, stat, statfs } from "node:fs/promises";
19
+ import { dirname } from "node:path";
20
+ import http from "node:http";
21
+ import https from "node:https";
22
+ function formatBytes(bytes) {
23
+ return bytes >= 1e9 ? `${(bytes / 1e9).toFixed(1)} GB` : `${Math.max(1, Math.round(bytes / 1e6))} MB`;
24
+ }
25
+ async function freeDiskBytes(directory) {
26
+ let target = directory;
27
+ while (!existsSync(target) && dirname(target) !== target) target = dirname(target);
28
+ const disk = await statfs(target).catch(quiet("local-models/download"));
29
+ return disk ? disk.bavail * disk.bsize : void 0;
30
+ }
31
+ async function checkDiskSpace(directory, bytesNeeded, spareBytes = 1e9) {
32
+ const free = await freeDiskBytes(directory);
33
+ const needed = bytesNeeded + spareBytes;
34
+ if (free !== void 0 && free < needed) {
35
+ throw new Error(`Needs ${formatBytes(needed)} free on the disk holding ${directory}; ${formatBytes(free)} is free.`);
36
+ }
37
+ }
38
+ async function sha256File(path, onProgress) {
39
+ const hash = createHash("sha256");
40
+ let bytes = 0;
41
+ let reported = 0;
42
+ for await (const chunk of createReadStream(path, { highWaterMark: 4 * 1024 * 1024 })) {
43
+ hash.update(chunk);
44
+ bytes += chunk.length;
45
+ if (onProgress && bytes - reported >= 256 * 1024 * 1024) {
46
+ reported = bytes;
47
+ onProgress(bytes);
48
+ }
49
+ }
50
+ return hash.digest("hex");
51
+ }
52
+ async function isDownloaded(destination, sizeBytes) {
53
+ return (await stat(destination).catch(quiet("local-models/download")))?.size === sizeBytes;
54
+ }
55
+ function openRange(url, offset, signal, hops = 0) {
56
+ return new Promise((resolve, reject) => {
57
+ const target = new URL(url);
58
+ const send = target.protocol === "http:" ? http.get : https.get;
59
+ const request = send(target, {
60
+ headers: { "user-agent": "clikcode-local-models", ...offset > 0 ? { range: `bytes=${offset}-` } : {} },
61
+ timeout: 6e4,
62
+ ...signal ? { signal } : {}
63
+ }, (response) => {
64
+ const status = response.statusCode ?? 0;
65
+ if (status >= 300 && status < 400 && response.headers.location) {
66
+ response.resume();
67
+ if (hops >= 10) {
68
+ reject(new Error(`Too many redirects fetching ${url}`));
69
+ return;
70
+ }
71
+ resolve(openRange(new URL(response.headers.location, target).href, offset, signal, hops + 1));
72
+ return;
73
+ }
74
+ resolve(response);
75
+ });
76
+ request.on("timeout", () => request.destroy(new Error(`The download of ${url} stalled`)));
77
+ request.on("error", reject);
78
+ });
79
+ }
80
+ async function downloadVerified(request) {
81
+ const { url, destination, sizeBytes, sha256 } = request;
82
+ if (await isDownloaded(destination, sizeBytes)) return;
83
+ await mkdir(dirname(destination), { recursive: true });
84
+ const partial = `${destination}.part`;
85
+ let offset = (await stat(partial).catch(quiet("local-models/download")))?.size ?? 0;
86
+ if (offset > sizeBytes) {
87
+ await rm(partial, { force: true });
88
+ offset = 0;
89
+ }
90
+ await checkDiskSpace(dirname(destination), sizeBytes - offset);
91
+ if (offset < sizeBytes) {
92
+ const response = await openRange(url, offset, request.signal);
93
+ if (response.statusCode === 416 && offset > 0) {
94
+ response.resume();
95
+ } else if (response.statusCode !== 200 && response.statusCode !== 206) {
96
+ response.resume();
97
+ throw new Error(`Download failed (HTTP ${response.statusCode}) for ${url}`);
98
+ } else {
99
+ if (response.statusCode !== 206) offset = 0;
100
+ const out = createWriteStream(partial, { flags: offset > 0 ? "a" : "w" });
101
+ let bytes = offset;
102
+ let lastReport = 0;
103
+ try {
104
+ for await (const chunk of response) {
105
+ const buffer = chunk;
106
+ if (!out.write(buffer)) await new Promise((resolve) => out.once("drain", resolve));
107
+ bytes += buffer.length;
108
+ const now = Date.now();
109
+ if (now - lastReport >= 500) {
110
+ lastReport = now;
111
+ request.onProgress?.({ bytes, totalBytes: sizeBytes });
112
+ }
113
+ }
114
+ } finally {
115
+ await new Promise((resolve, reject) => out.end((error) => error ? reject(error) : resolve()));
116
+ }
117
+ request.onProgress?.({ bytes, totalBytes: sizeBytes });
118
+ }
119
+ }
120
+ const size = (await stat(partial)).size;
121
+ if (size !== sizeBytes) {
122
+ throw new Error(`Download of ${url} ended at ${formatBytes(size)} of ${formatBytes(sizeBytes)}; it resumes from there next time.`);
123
+ }
124
+ const actual = await sha256File(partial, (bytes) => request.onVerify?.({ bytes, totalBytes: sizeBytes }));
125
+ if (actual !== sha256) {
126
+ await rm(partial, { force: true });
127
+ throw new Error(`Downloaded file failed its integrity check (sha256 ${actual}, expected ${sha256}); it was removed.`);
128
+ }
129
+ await rename(partial, destination);
130
+ }
131
+
132
+ // src/local-models/models.ts
133
+ import { copyFile, link, mkdir as mkdir2, readdir, stat as stat2 } from "node:fs/promises";
134
+ import { homedir } from "node:os";
135
+ import { basename, dirname as dirname2, join } from "node:path";
136
+ function weightFiles(model) {
137
+ const parts = model.weightParts;
138
+ return parts?.length ? parts : [model.weights];
139
+ }
140
+ function safeRepoPath(file) {
141
+ const segments = file.split("/");
142
+ return segments.length <= 2 && segments.every((segment) => /^[\w.+-]+$/.test(segment) && !/^\.+$/.test(segment));
143
+ }
144
+ function modelFilePath(file) {
145
+ if (!safeRepoPath(file.file)) throw new Error(`refusing an unsafe model file name: ${file.file}`);
146
+ return join(modelsDir(), file.repo.replace("/", "--"), file.revision.slice(0, 12), ...file.file.split("/"));
147
+ }
148
+ function hubFileUrl(repo, revision, file) {
149
+ return `https://huggingface.co/${repo}/resolve/${revision}/${file.split("/").map(encodeURIComponent).join("/")}`;
150
+ }
151
+ function huggingFaceUrl(file) {
152
+ return hubFileUrl(file.repo, file.revision, file.file);
153
+ }
154
+ function adoptionDirs() {
155
+ return [join(homedir(), "Models")];
156
+ }
157
+ async function findBySizeAndName(directory, name, size, depth) {
158
+ const entries = await readdir(directory, { withFileTypes: true }).catch(() => []);
159
+ const found = [];
160
+ for (const entry of entries) {
161
+ const path = join(directory, entry.name);
162
+ if (entry.isFile() && entry.name === name && (await stat2(path).catch(quiet("local-models/models")))?.size === size) found.push(path);
163
+ else if (entry.isDirectory() && depth > 0 && !entry.name.startsWith(".")) found.push(...await findBySizeAndName(path, name, size, depth - 1));
164
+ }
165
+ return found;
166
+ }
167
+ async function adopt(file, destination, onProgress) {
168
+ for (const directory of adoptionDirs()) {
169
+ for (const candidate of await findBySizeAndName(directory, basename(file.file), file.sizeBytes, 4)) {
170
+ onProgress({ message: `checking ${candidate}\u2026`, bytes: 0, totalBytes: file.sizeBytes });
171
+ const hash = await sha256File(candidate, (bytes) => onProgress({ message: `checking ${candidate}\u2026`, bytes, totalBytes: file.sizeBytes }));
172
+ if (hash !== file.sha256) continue;
173
+ await mkdir2(dirname2(destination), { recursive: true });
174
+ try {
175
+ await link(candidate, destination);
176
+ } catch {
177
+ await checkDiskSpace(dirname2(destination), file.sizeBytes);
178
+ await copyFile(candidate, destination);
179
+ }
180
+ return true;
181
+ }
182
+ }
183
+ return false;
184
+ }
185
+ async function ensureModelFile(file, onProgress, signal) {
186
+ const destination = modelFilePath(file);
187
+ if (await isDownloaded(destination, file.sizeBytes)) return destination;
188
+ if (await adopt(file, destination, onProgress)) return destination;
189
+ const label = `downloading ${file.file} (${formatBytes(file.sizeBytes)})`;
190
+ await downloadVerified({
191
+ url: huggingFaceUrl(file),
192
+ destination,
193
+ sizeBytes: file.sizeBytes,
194
+ sha256: file.sha256,
195
+ onProgress: (progress) => onProgress({ message: label, ...progress }),
196
+ onVerify: (progress) => onProgress({ message: `verifying ${file.file}\u2026`, ...progress }),
197
+ ...signal ? { signal } : {}
198
+ });
199
+ return destination;
200
+ }
201
+ async function ensureModelWeights(model, onProgress, signal) {
202
+ const files = weightFiles(model);
203
+ const paths = [];
204
+ for (const [index, file] of files.entries()) {
205
+ paths.push(await ensureModelFile(file, files.length > 1 ? (progress) => onProgress({ ...progress, message: `${progress.message} (part ${index + 1} of ${files.length})` }) : onProgress, signal));
206
+ }
207
+ return paths[0];
208
+ }
209
+ async function missingBytes(files) {
210
+ let total = 0;
211
+ for (const file of files) if (!await isDownloaded(modelFilePath(file), file.sizeBytes)) total += file.sizeBytes;
212
+ return total;
213
+ }
214
+
215
+ // src/local-models/discover.ts
216
+ import { mkdir as mkdir3, readFile, writeFile } from "node:fs/promises";
217
+ import { dirname as dirname3 } from "node:path";
218
+ var CACHE_MS = 24 * 60 * 60 * 1e3;
219
+ var RETRY_MS = 30 * 60 * 1e3;
220
+ var HEADER_DEADLINE_MS = 15e4;
221
+ var MAX_REJECTED = 300;
222
+ var SEARCHES = ["Qwen3.5-GGUF", "Qwen3.6-GGUF", "Gemma-4-GGUF", "gpt-oss-GGUF", "Ornith-GGUF"];
223
+ var QUANT = /(?:Q4_K_M|Q4_0|MXFP4|Q6_K|Q8_0)\.gguf$/i;
224
+ var SPLIT = /^(.*)-(\d{5})-of-(\d{5})\.gguf$/i;
225
+ var MIN_QUERY = 3;
226
+ var LICENSES = /* @__PURE__ */ new Set(["apache-2.0", "mit"]);
227
+ var MAX_REPOS = 12;
228
+ var MAX_HEADERS = 12;
229
+ function fileBytes(file) {
230
+ return file.lfs?.size ?? file.size ?? Infinity;
231
+ }
232
+ function unsplitName(name) {
233
+ const match = SPLIT.exec(name);
234
+ return match ? `${match[1]}.gguf` : name;
235
+ }
236
+ function repoCandidates(repo, capacity) {
237
+ const files = (repo.siblings ?? []).filter((file) => safeRepoPath(file.rfilename) && !/mmproj|projector/i.test(file.rfilename) && QUANT.test(unsplitName(file.rfilename)));
238
+ const singles = files.filter((file) => !SPLIT.test(file.rfilename)).map((file) => ({ repo, file, sizeBytes: fileBytes(file) }));
239
+ const groups = /* @__PURE__ */ new Map();
240
+ for (const file of files) {
241
+ const match = SPLIT.exec(file.rfilename);
242
+ if (!match) continue;
243
+ const key = `${match[1]}|${match[3]}`;
244
+ groups.set(key, [...groups.get(key) ?? [], file]);
245
+ }
246
+ const splits = [...groups].flatMap(([key, parts]) => {
247
+ const count = Number(key.slice(key.lastIndexOf("|") + 1));
248
+ const ordered = [...parts].sort((a, b) => Number(SPLIT.exec(a.rfilename)[2]) - Number(SPLIT.exec(b.rfilename)[2]));
249
+ if (count < 2 || ordered.length !== count || ordered.some((part, index) => Number(SPLIT.exec(part.rfilename)[2]) !== index + 1)) return [];
250
+ return [{ repo, file: ordered[0], parts: ordered, sizeBytes: ordered.reduce((sum, part) => sum + fileBytes(part), 0) }];
251
+ });
252
+ return [...singles, ...splits].filter((candidate) => candidate.sizeBytes <= capacity);
253
+ }
254
+ async function hubJson(url) {
255
+ const response = await fetch(url, { signal: AbortSignal.timeout(1e4), headers: { accept: "application/json" } });
256
+ if (!response.ok) throw new Error(`Hugging Face returned ${response.status}`);
257
+ return response.json();
258
+ }
259
+ function scalar(value) {
260
+ const result = Number(value);
261
+ return Number.isFinite(result) && result > 0 ? result : void 0;
262
+ }
263
+ function geometry(metadata) {
264
+ const arch = metadata["general.architecture"];
265
+ if (!["qwen35", "qwen35moe", "gemma4", "gpt-oss"].includes(String(arch))) return void 0;
266
+ const get = (key) => metadata[`${arch}.${key}`];
267
+ const blocks = scalar(get("block_count"));
268
+ const heads = get("attention.head_count_kv");
269
+ const headList = Array.isArray(heads) ? heads.map(Number) : void 0;
270
+ const kvHeads = scalar(headList?.at(-1) ?? heads);
271
+ const keyLength = scalar(get("attention.key_length"));
272
+ const valueLength = scalar(get("attention.value_length"));
273
+ if (!blocks || !kvHeads || !keyLength || !valueLength) return void 0;
274
+ if (arch === "qwen35" || arch === "qwen35moe") {
275
+ const interval = scalar(get("full_attention_interval"));
276
+ const inner = scalar(get("ssm.inner_size"));
277
+ const state = scalar(get("ssm.state_size"));
278
+ const groups = scalar(get("ssm.group_count"));
279
+ if (!interval || !inner || !state || !groups) return void 0;
280
+ const layers = Math.floor(blocks / interval);
281
+ const linear = blocks - layers;
282
+ const recurrentHeads = inner / state;
283
+ return {
284
+ layers,
285
+ kvHeads,
286
+ keyLength,
287
+ valueLength,
288
+ recurrentStateBytes: linear * (recurrentHeads * state * state * 4 + 3 * (recurrentHeads * state + 2 * groups * state) * 4)
289
+ };
290
+ }
291
+ const window = scalar(get("attention.sliding_window"));
292
+ if (!window) return void 0;
293
+ if (arch === "gpt-oss") {
294
+ if (blocks % 2) return void 0;
295
+ return {
296
+ layers: blocks / 2,
297
+ kvHeads,
298
+ keyLength,
299
+ valueLength,
300
+ sliding: { layers: blocks / 2, kvHeads, keyLength, valueLength, window }
301
+ };
302
+ }
303
+ const pattern = get("attention.sliding_window_pattern");
304
+ if (!Array.isArray(pattern) || pattern.length !== blocks || !headList || headList.length !== blocks) return void 0;
305
+ const slidingLayers = pattern.filter(Boolean).length;
306
+ const fullLayers = blocks - slidingLayers;
307
+ const slidingHeads = scalar(headList.find((_, i) => pattern[i]));
308
+ const slidingKey = scalar(get("attention.key_length_swa"));
309
+ const slidingValue = scalar(get("attention.value_length_swa"));
310
+ if (!fullLayers || !slidingLayers || !slidingHeads || !slidingKey || !slidingValue) return void 0;
311
+ return {
312
+ layers: fullLayers,
313
+ kvHeads,
314
+ keyLength,
315
+ valueLength,
316
+ sliding: { layers: slidingLayers, kvHeads: slidingHeads, keyLength: slidingKey, valueLength: slidingValue, window }
317
+ };
318
+ }
319
+ var TENSOR_LAYOUT = /* @__PURE__ */ new Map([
320
+ [0, [4, 1]],
321
+ [1, [2, 1]],
322
+ [30, [2, 1]],
323
+ [2, [18, 32]],
324
+ [3, [20, 32]],
325
+ [6, [22, 32]],
326
+ [7, [24, 32]],
327
+ [8, [34, 32]],
328
+ [9, [36, 32]],
329
+ [10, [84, 256]],
330
+ [11, [110, 256]],
331
+ [12, [144, 256]],
332
+ [13, [176, 256]],
333
+ [14, [210, 256]],
334
+ [15, [292, 256]],
335
+ [39, [17, 32]]
336
+ ]);
337
+ function candidateId(repo, file) {
338
+ return `hf:${repo.id}:${repo.sha.slice(0, 12)}:${file.rfilename}`;
339
+ }
340
+ function weightCapacityBytes(hardware) {
341
+ const dedicated = hardware.gpus.filter((gpu) => !gpu.unified && !gpu.integrated).reduce((sum, gpu) => sum + gpu.vramBytes, 0);
342
+ return hardware.totalRamBytes + dedicated;
343
+ }
344
+ function remoteModelFromHeader(repo, file, header, split) {
345
+ const files = split?.parts ?? [file];
346
+ if (files.some((part) => !part.lfs?.sha256?.match(/^[0-9a-f]{64}$/) || !(part.lfs?.size ?? part.size))) return void 0;
347
+ const sizeBytes = files.reduce((sum, part) => sum + (part.lfs?.size ?? part.size ?? 0), 0);
348
+ const sha256 = file.lfs?.sha256;
349
+ const license = repo.cardData?.license;
350
+ const metadata = header.metadata;
351
+ const kv = geometry(metadata);
352
+ const context = scalar(metadata[`${metadata["general.architecture"]}.context_length`]);
353
+ const template = metadata["tokenizer.chat_template"];
354
+ const splitCount = scalar(metadata["split.count"]);
355
+ if (split && splitCount !== split.parts.length) return void 0;
356
+ if (!/^[\w.-]+\/[\w.-]+$/.test(repo.id) || !files.every((part) => safeRepoPath(part.rfilename) && /\.gguf$/i.test(part.rfilename)) || !repo.sha?.match(/^[0-9a-f]{40}$/) || !sha256?.match(/^[0-9a-f]{64}$/) || !sizeBytes || !license || !LICENSES.has(license) || !kv || !context || typeof template !== "string" || !/(?:tool|function)/i.test(template)) return void 0;
357
+ const expertCount = scalar(metadata[`${metadata["general.architecture"]}.expert_count`]);
358
+ const expertsUsed = scalar(metadata[`${metadata["general.architecture"]}.expert_used_count`]);
359
+ if (expertCount && (!expertsUsed || expertsUsed > expertCount)) return void 0;
360
+ const tensorInfos = split?.tensorInfos ?? header.tensorInfos;
361
+ const hasOutput = tensorInfos.some((item) => item.name === "output.weight");
362
+ let totalParams = 0, activeParams = 0, activeBytes = 0;
363
+ for (const tensor of tensorInfos) {
364
+ const layout = TENSOR_LAYOUT.get(tensor.dtype);
365
+ if (!layout) return void 0;
366
+ const elements = tensor.shape.reduce((product, n) => product * Number(n), 1);
367
+ if (!Number.isSafeInteger(elements)) return void 0;
368
+ const bytes = Math.ceil(elements / layout[1]) * layout[0];
369
+ const active = tensor.name === "token_embd.weight" && hasOutput ? 0 : expertCount && /_exps(?:\.|_)/.test(tensor.name) ? expertsUsed / expertCount : 1;
370
+ totalParams += elements;
371
+ activeParams += elements * active;
372
+ activeBytes += bytes * active;
373
+ }
374
+ if (!totalParams || !activeParams) return void 0;
375
+ const quantization = unsplitName(file.rfilename).match(QUANT)?.[0].replace(/\.gguf$/i, "") ?? "unknown";
376
+ const name = String(metadata["general.name"] ?? repo.id.split("/")[1]).replace(/[\x00-\x1f\x7f]/g, " ").trim().slice(0, 80);
377
+ const model = {
378
+ id: candidateId(repo, file),
379
+ label: `${name} ${quantization}`,
380
+ weights: { repo: repo.id, revision: repo.sha, file: file.rfilename, sizeBytes, sha256 },
381
+ architecture: String(metadata["general.architecture"]),
382
+ totalParamsB: totalParams / 1e9,
383
+ activeParamsB: activeParams / 1e9,
384
+ activeWeightBytes: activeBytes,
385
+ quantization,
386
+ defaultContext: Math.min(context, 65536),
387
+ maxContext: context,
388
+ license,
389
+ kv,
390
+ quality: 30,
391
+ qualityNote: "Hugging Face candidate; tool reliability is checked after first start",
392
+ discovered: true
393
+ };
394
+ if (split) {
395
+ model.weightParts = split.parts.map((part) => ({
396
+ repo: repo.id,
397
+ revision: repo.sha,
398
+ file: part.rfilename,
399
+ sizeBytes: part.lfs?.size ?? part.size,
400
+ sha256: part.lfs.sha256
401
+ }));
402
+ }
403
+ return model;
404
+ }
405
+ var NETWORK = {
406
+ json: hubJson,
407
+ async header(url, signal) {
408
+ const { gguf } = await import("@huggingface/gguf");
409
+ return gguf(url, { fetch: (input, init) => fetch(input, { ...init, signal }) });
410
+ },
411
+ now: () => Date.now()
412
+ };
413
+ async function inspect({ repo, file, parts }, deps) {
414
+ const signal = AbortSignal.timeout(HEADER_DEADLINE_MS);
415
+ try {
416
+ const headers = await Promise.all((parts ?? [file]).map((part) => deps.header(hubFileUrl(repo.id, repo.sha, part.rfilename), signal)));
417
+ const model = remoteModelFromHeader(
418
+ repo,
419
+ file,
420
+ headers[0],
421
+ parts ? { parts, tensorInfos: headers.flatMap((header) => header.tensorInfos) } : void 0
422
+ );
423
+ return model ? { model } : { rejected: candidateId(repo, file) };
424
+ } catch {
425
+ return { failed: true };
426
+ }
427
+ }
428
+ async function readCache() {
429
+ return readFile(discoveredModelsFile(), "utf8").then((text) => JSON.parse(text), () => ({}));
430
+ }
431
+ function cacheState(cache, capacity, now) {
432
+ if (cache.failedAt && now - cache.failedAt < RETRY_MS) return "fresh";
433
+ const good = cache.at !== void 0 && Array.isArray(cache.models) && (cache.maxWeightBytes ?? 0) >= capacity * 0.9;
434
+ return good && now - cache.at < (cache.incomplete ? RETRY_MS : CACHE_MS) ? "fresh" : "stale";
435
+ }
436
+ var refreshing;
437
+ var pendingQueries = /* @__PURE__ */ new Set();
438
+ function enqueue(job) {
439
+ const next = (refreshing ?? Promise.resolve(false)).catch(() => false).then(job).finally(() => {
440
+ if (refreshing === next) refreshing = void 0;
441
+ });
442
+ refreshing = next;
443
+ return next;
444
+ }
445
+ function discoveryRefresh() {
446
+ return refreshing;
447
+ }
448
+ async function refresh(capacity, deps, query) {
449
+ const cache = await readCache();
450
+ const known = new Map((cache.models ?? []).map((model) => [model.id, model]));
451
+ const rejected = new Set(cache.rejected ?? []);
452
+ try {
453
+ const results = await Promise.all((query ? [query] : SEARCHES).map(async (term) => deps.json(
454
+ `https://huggingface.co/api/models?filter=gguf&search=${encodeURIComponent(term)}&sort=downloads&direction=-1&limit=8`
455
+ )));
456
+ const repos = [...new Map(results.flat().map((item) => [item.id, item])).values()].sort((a, b) => (b.downloads ?? 0) - (a.downloads ?? 0)).slice(0, MAX_REPOS);
457
+ const details = await Promise.all(repos.map(async (item) => deps.json(
458
+ `https://huggingface.co/api/models/${item.id}?blobs=true`
459
+ ).catch(quiet("local-models/discover"))));
460
+ const candidates = details.filter((item) => Boolean(item && !item.gated && !item.private && !item.disabled)).flatMap((repo) => repoCandidates(repo, capacity)).sort((a, b) => {
461
+ const quantRank = (name) => /Q4_K_M/i.test(name) ? 0 : /Q4_0|MXFP4/i.test(name) ? 1 : /Q6_K/i.test(name) ? 2 : 3;
462
+ return quantRank(unsplitName(a.file.rfilename)) - quantRank(unsplitName(b.file.rfilename));
463
+ }).slice(0, MAX_HEADERS);
464
+ const unread = candidates.filter(({ repo, file }) => repo.sha && !known.has(candidateId(repo, file)) && !rejected.has(candidateId(repo, file)));
465
+ const read = await Promise.all(unread.map((candidate) => inspect(candidate, deps)));
466
+ const added = read.flatMap((item) => "model" in item ? [item.model] : []);
467
+ const unreadable = read.filter((item) => "failed" in item).length;
468
+ if (unread.length && unreadable === unread.length) throw new Error("no header could be read");
469
+ const merged = [...new Map([...cache.models ?? [], ...added].map((model) => [model.id, model])).values()];
470
+ const verdicts = [...rejected, ...read.flatMap((item) => "rejected" in item ? [item.rejected] : [])].slice(-MAX_REJECTED);
471
+ await mkdir3(dirname3(discoveredModelsFile()), { recursive: true });
472
+ const next = query ? { ...cache, models: merged, rejected: verdicts, searched: { ...cache.searched, [query]: deps.now() } } : { ...cache, at: deps.now(), maxWeightBytes: capacity, models: merged, rejected: verdicts, failedAt: void 0, incomplete: unreadable ? true : void 0 };
473
+ await writeFile(discoveredModelsFile(), JSON.stringify(next));
474
+ registerRemoteModels(merged);
475
+ return added.length > 0;
476
+ } catch (error) {
477
+ quiet("local-models/discover")(error);
478
+ if (query) return false;
479
+ try {
480
+ await mkdir3(dirname3(discoveredModelsFile()), { recursive: true });
481
+ await writeFile(discoveredModelsFile(), JSON.stringify({ ...cache, failedAt: deps.now() }));
482
+ } catch (writeError) {
483
+ quiet("local-models/discover")(writeError);
484
+ }
485
+ return false;
486
+ }
487
+ }
488
+ async function discoverHuggingFaceModels(capacity, options = {}, deps = NETWORK) {
489
+ const cache = await readCache();
490
+ if (Array.isArray(cache.models) && cache.models.length) registerRemoteModels(cache.models);
491
+ if (options.refresh !== "never") {
492
+ if (!refreshing && cacheState(cache, capacity, deps.now()) === "stale") enqueue(() => refresh(capacity, deps));
493
+ const query = options.query?.trim().toLowerCase().replace(/\s+/g, " ");
494
+ if (query && query.length >= MIN_QUERY && !pendingQueries.has(query) && deps.now() - (cache.searched?.[query] ?? 0) >= CACHE_MS) {
495
+ pendingQueries.add(query);
496
+ enqueue(() => refresh(capacity, deps, query).finally(() => pendingQueries.delete(query)));
497
+ }
498
+ if (options.wait && refreshing) await refreshing;
499
+ }
500
+ return allLocalModels();
501
+ }
502
+
503
+ export {
504
+ formatBytes,
505
+ sha256File,
506
+ downloadVerified,
507
+ weightFiles,
508
+ modelFilePath,
509
+ ensureModelFile,
510
+ ensureModelWeights,
511
+ missingBytes,
512
+ weightCapacityBytes,
513
+ remoteModelFromHeader,
514
+ discoveryRefresh,
515
+ discoverHuggingFaceModels
516
+ };
@@ -0,0 +1,82 @@
1
+ import { createRequire as __clikcodeCreateRequire } from 'node:module';
2
+ const require = __clikcodeCreateRequire(import.meta.url);
3
+ import {
4
+ computerSettingsPath
5
+ } from "./chunk-5SM5UAWN.js";
6
+ import {
7
+ objectOrEmpty,
8
+ updateJsonFile
9
+ } from "./chunk-PAXYQZH7.js";
10
+ import "./chunk-4L2ZZM4Q.js";
11
+ import "./chunk-F6F47QAY.js";
12
+ import "./chunk-RDDWQBEM.js";
13
+ import "./chunk-MPAJ446F.js";
14
+ import "./chunk-CBANJFBO.js";
15
+ import "./chunk-PWXII6HF.js";
16
+
17
+ // src/agent/computer/card-rule.ts
18
+ import { appendFile, mkdir, readFile } from "node:fs/promises";
19
+ import path from "node:path";
20
+ var MAX_RULE_USES_PER_DAY = 6;
21
+ async function cardRule(stateDir) {
22
+ try {
23
+ return JSON.parse(await readFile(computerSettingsPath(stateDir), "utf8")).cardRule === "usage-only" ? "usage-only" : "off";
24
+ } catch {
25
+ return "off";
26
+ }
27
+ }
28
+ async function setCardRule(stateDir, rule) {
29
+ await updateJsonFile(computerSettingsPath(stateDir), objectOrEmpty, (current) => ({ ...current, cardRule: rule }));
30
+ }
31
+ var RECURRING = /(?:\/|\bper |\ba )\s?(?:month|mo|year|yr|annum|user\/mo)\b|\bmonthly\b|\bannual(?:ly)?\b|\byearly\b|\bsubscri(?:be|ption)\b|\bauto[- ]?renew|\brenew(?:s|al)\b|\btrial (?:ends|expires|period ends)|\bafter (?:your|the) (?:\d+[- ]day )?(?:free )?trial\b|\bbilled (?:every|each|monthly|annually|yearly)\b|\brecurring\b|\bcancel (?:any ?time|before)\b|\buntil (?:you|you've) cancel/i;
32
+ var USAGE_INVOICE = /\b(?:billed|invoiced|charged) monthly (?:for|based on) (?:your |what you )?(?:usage|use)\b|\bmonthly (?:usage|invoice for usage)\b/gi;
33
+ var NO_CHARGE = /\bwon'?t be charged\b|\bwill not be charged\b|\bnot be charged (?:until|unless)\b|\bno charges? (?:today|now|until|unless)\b|\bnothing (?:is )?(?:due|charged) (?:today|now)\b|[$€£]\s?0(?:\.00)? (?:due|today|now)\b|\bdue today:?\s*[$€£]\s?0(?:\.00)?\b|\bpay[- ]as[- ]you[- ]go\b|\bonly pay for what you use\b|\busage[- ]based\b|\bcharged (?:only )?(?:for|when) (?:what )?you use\b|\bfree (?:tier|credits?)\b|\b(?:verify|verification of) (?:your )?(?:card|payment method|identity)\b|\bcard (?:is )?(?:required|needed) (?:for|to) (?:verif|prevent|avoid)|\bto prevent (?:abuse|fraud|spam)\b|\btemporary (?:authori[sz]ation|hold)\b/i;
34
+ var DUE_NOW = /(?:\b(?:due|total|charged?|pay(?:ing)?)\b(?: (?:today|now))?)[^.\n]{0,25}?[$€£]\s?(\d+(?:[.,]\d{1,2})?)|[$€£]\s?(\d+(?:[.,]\d{1,2})?)[^.\n]{0,15}?\b(?:due|charged) (?:today|now)\b/gi;
35
+ function chargeTerms(pageText) {
36
+ const text = pageText.replace(/\s+/g, " ").slice(0, 2e4);
37
+ const recurring = RECURRING.exec(text.replace(USAGE_INVOICE, " "));
38
+ if (recurring) return { allowed: false, why: `the page speaks of a recurring charge ("${recurring[0].trim()}")` };
39
+ for (const due of text.matchAll(DUE_NOW)) {
40
+ const amount = Number((due[1] ?? due[2] ?? "0").replace(",", "."));
41
+ if (amount > 0) return { allowed: false, why: `the page charges ${due[0].trim()} now` };
42
+ }
43
+ const free = NO_CHARGE.exec(text);
44
+ if (!free) return { allowed: false, why: "the page does not say that nothing is charged until something is used" };
45
+ return { allowed: true, why: `the page says "${free[0].trim()}" and names no recurring charge` };
46
+ }
47
+ var usesPath = (stateDir) => path.join(stateDir, "computer", "card-uses.jsonl");
48
+ async function ruleUsesToday(stateDir, now = Date.now()) {
49
+ const day = new Date(now).toISOString().slice(0, 10);
50
+ try {
51
+ return (await readFile(usesPath(stateDir), "utf8")).split("\n").filter((line) => line.includes(`"at":"${day}`)).length;
52
+ } catch {
53
+ return 0;
54
+ }
55
+ }
56
+ async function recordCardUse(stateDir, use) {
57
+ await mkdir(path.dirname(usesPath(stateDir)), { recursive: true, mode: 448 });
58
+ await appendFile(usesPath(stateDir), `${JSON.stringify(use)}
59
+ `, { mode: 384 });
60
+ }
61
+ async function cardUses(stateDir) {
62
+ try {
63
+ return (await readFile(usesPath(stateDir), "utf8")).split("\n").filter(Boolean).map((line) => JSON.parse(line));
64
+ } catch {
65
+ return [];
66
+ }
67
+ }
68
+ async function ruleAllowsCard(stateDir, pageText, now = Date.now()) {
69
+ if (await cardRule(stateDir) !== "usage-only") return { allowed: false, why: "no standing card rule is set" };
70
+ if (await ruleUsesToday(stateDir, now) >= MAX_RULE_USES_PER_DAY) return { allowed: false, why: `the standing rule's ${MAX_RULE_USES_PER_DAY} card uses for today are spent` };
71
+ return chargeTerms(pageText);
72
+ }
73
+ export {
74
+ MAX_RULE_USES_PER_DAY,
75
+ cardRule,
76
+ cardUses,
77
+ chargeTerms,
78
+ recordCardUse,
79
+ ruleAllowsCard,
80
+ ruleUsesToday,
81
+ setCardRule
82
+ };
@@ -0,0 +1,55 @@
1
+ import { createRequire as __clikcodeCreateRequire } from 'node:module';
2
+ const require = __clikcodeCreateRequire(import.meta.url);
3
+ import {
4
+ readState
5
+ } from "./chunk-MXS6S2PY.js";
6
+ import "./chunk-BISGNHKD.js";
7
+ import "./chunk-BGEMY2JJ.js";
8
+ import "./chunk-XCKQ5BM2.js";
9
+ import "./chunk-NWEYRBWK.js";
10
+ import "./chunk-TWCVV2JO.js";
11
+ import "./chunk-PDPEM5VW.js";
12
+ import "./chunk-WWLJMP6D.js";
13
+ import "./chunk-CRUVYGO2.js";
14
+ import "./chunk-FF7ZVYJF.js";
15
+ import "./chunk-IMLTL2MY.js";
16
+ import "./chunk-BUOPJQP5.js";
17
+ import "./chunk-3B2CHX7M.js";
18
+ import "./chunk-RVUOIJXN.js";
19
+ import "./chunk-QUS4ER2W.js";
20
+ import "./chunk-DQYVQ2N7.js";
21
+ import "./chunk-KYUHIFP3.js";
22
+ import "./chunk-RSZGEL5U.js";
23
+ import "./chunk-NKDATMEM.js";
24
+ import "./chunk-CQ7J6UQ7.js";
25
+ import "./chunk-XKW5NDMR.js";
26
+ import "./chunk-W3YYPBEA.js";
27
+ import "./chunk-XIBYREEY.js";
28
+ import "./chunk-EE4B6A7W.js";
29
+ import "./chunk-WZYVLUVQ.js";
30
+ import "./chunk-O3EW7LAY.js";
31
+ import "./chunk-KHW6TX6I.js";
32
+ import "./chunk-YMCH3L2S.js";
33
+ import {
34
+ CLIKCODE_COMMIT,
35
+ CLIKCODE_VERSION
36
+ } from "./chunk-NAOX3JUB.js";
37
+ import "./chunk-4QZEZME7.js";
38
+ import "./chunk-LVRRWP4W.js";
39
+ import "./chunk-G3QP67Z7.js";
40
+ import "./chunk-4L2ZZM4Q.js";
41
+ import "./chunk-F6F47QAY.js";
42
+ import "./chunk-RDDWQBEM.js";
43
+ import "./chunk-MPAJ446F.js";
44
+ import "./chunk-CBANJFBO.js";
45
+ import "./chunk-PWXII6HF.js";
46
+
47
+ // src/remote/info.ts
48
+ async function printRemoteInfo() {
49
+ const installationId = await readState({ transcripts: [] }).then((state) => state.installationId, () => void 0);
50
+ process.stdout.write(`${JSON.stringify({ version: CLIKCODE_VERSION, ...CLIKCODE_COMMIT ? { commit: CLIKCODE_COMMIT } : {}, ...installationId ? { installationId } : {} })}
51
+ `);
52
+ }
53
+ export {
54
+ printRemoteInfo
55
+ };