clikcode 1.0.4 → 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 +494 -112923
  319. package/dist/computer-tools.js +36642 -21259
  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,221 @@
1
+ import { createRequire as __clikcodeCreateRequire } from 'node:module';
2
+ const require = __clikcodeCreateRequire(import.meta.url);
3
+ import "./chunk-PWXII6HF.js";
4
+
5
+ // src/agent/computer/captcha-log.ts
6
+ import fs from "node:fs/promises";
7
+ import path from "node:path";
8
+ function captchaLogPath(stateDir) {
9
+ return path.join(stateDir, "computer", "captcha-log.jsonl");
10
+ }
11
+ var CAPTCHA_LOG_MAX_BYTES = 1e6;
12
+ var KEEP_MS = 30 * 864e5;
13
+ async function recordCaptcha(stateDir, record, now = Date.now()) {
14
+ try {
15
+ const file = captchaLogPath(stateDir);
16
+ await fs.mkdir(path.dirname(file), { recursive: true, mode: 448 });
17
+ await fs.appendFile(file, `${JSON.stringify(record)}
18
+ `, { mode: 384 });
19
+ if ((await fs.stat(file)).size > CAPTCHA_LOG_MAX_BYTES) await rotate(file, now);
20
+ } catch {
21
+ }
22
+ }
23
+ async function rotate(file, now) {
24
+ const kept = [];
25
+ let bytes = 0;
26
+ const lines = (await fs.readFile(file, "utf8")).split("\n").filter((line) => line.trim());
27
+ for (let i = lines.length - 1; i >= 0; i--) {
28
+ const line = lines[i];
29
+ let at = NaN;
30
+ try {
31
+ at = Date.parse(JSON.parse(line).at);
32
+ } catch {
33
+ continue;
34
+ }
35
+ if (!(at >= now - KEEP_MS) || bytes + line.length + 1 > CAPTCHA_LOG_MAX_BYTES / 2) break;
36
+ kept.push(line);
37
+ bytes += line.length + 1;
38
+ }
39
+ const aside = `${file}.${process.pid}.tmp`;
40
+ await fs.writeFile(aside, kept.reverse().map((line) => `${line}
41
+ `).join(""), { mode: 384 });
42
+ await fs.rename(aside, file);
43
+ }
44
+ var parsed;
45
+ async function readRecords(stateDir) {
46
+ const file = captchaLogPath(stateDir);
47
+ let stat;
48
+ try {
49
+ stat = await fs.stat(file);
50
+ } catch {
51
+ return [];
52
+ }
53
+ if (parsed && parsed.file === file && parsed.size === stat.size && parsed.mtimeMs === stat.mtimeMs) return parsed.records;
54
+ let text = "";
55
+ try {
56
+ text = await fs.readFile(file, "utf8");
57
+ } catch {
58
+ return [];
59
+ }
60
+ const records = [];
61
+ for (const line of text.split("\n")) {
62
+ if (!line.trim()) continue;
63
+ try {
64
+ records.push(JSON.parse(line));
65
+ } catch {
66
+ }
67
+ }
68
+ parsed = { file, size: stat.size, mtimeMs: stat.mtimeMs, records };
69
+ return records;
70
+ }
71
+ async function recordsSince(stateDir, since) {
72
+ return (await readRecords(stateDir)).filter((record) => Date.parse(record.at) >= since);
73
+ }
74
+ async function weakKinds(stateDir, now = Date.now()) {
75
+ const seen = /* @__PURE__ */ new Map();
76
+ for (const record of await recordsSince(stateDir, now - 30 * 864e5)) {
77
+ for (const kind of new Set(record.kinds ?? [])) {
78
+ const tally = seen.get(kind) ?? { runs: 0, cleared: 0 };
79
+ tally.runs++;
80
+ if (record.outcome === "cleared") tally.cleared++;
81
+ seen.set(kind, tally);
82
+ }
83
+ }
84
+ return new Set([...seen].filter(([, tally]) => tally.runs >= 3 && tally.cleared === 0).map(([kind]) => kind));
85
+ }
86
+ async function shouldHoldOff(stateDir, host, now = Date.now()) {
87
+ if (!host) return false;
88
+ const recent = (await recordsSince(stateDir, now - 30 * 6e4)).filter((record) => record.host === host && record.outcome !== "none");
89
+ return recent.length >= 3 && recent.slice(-3).every((record) => record.outcome === "still-there");
90
+ }
91
+ var RECAPTCHA_REFUSAL_COOLDOWN_MS = 6 * 60 * 6e4;
92
+ async function recaptchaRefusedRecently(stateDir, now = Date.now(), egress) {
93
+ const wanted = egress && egress !== "home" ? egress : "home";
94
+ return (await recordsSince(stateDir, now - RECAPTCHA_REFUSAL_COOLDOWN_MS)).some((record) => record.family === "recaptcha" && record.steps.includes("refused") && (record.egress ?? "home") === wanted);
95
+ }
96
+ async function heldOffHosts(stateDir, now = Date.now()) {
97
+ const hosts = new Set((await recordsSince(stateDir, now - 30 * 6e4)).map((record) => record.host).filter(Boolean));
98
+ const held = [];
99
+ for (const host of hosts) if (await shouldHoldOff(stateDir, host, now)) held.push(host);
100
+ return held.sort();
101
+ }
102
+ async function captchaCost(stateDir, days = 30, now = Date.now()) {
103
+ const models = /* @__PURE__ */ new Map();
104
+ for (const record of await recordsSince(stateDir, now - days * 864e5)) for (const [model, asks] of Object.entries(record.models ?? {})) models.set(model, (models.get(model) ?? 0) + asks);
105
+ const rows = [...models].map(([model, asks]) => ({ model, asks })).sort((a, b) => b.asks - a.asks);
106
+ return { asks: rows.reduce((total, row) => total + row.asks, 0), subscription: rows.filter((row) => row.model.startsWith("subscription-")).reduce((total, row) => total + row.asks, 0), models: rows };
107
+ }
108
+ var votersFile = (stateDir) => path.join(stateDir, "computer", "captcha-voters.json");
109
+ async function readScores(stateDir) {
110
+ try {
111
+ return JSON.parse(await fs.readFile(votersFile(stateDir), "utf8"));
112
+ } catch {
113
+ return {};
114
+ }
115
+ }
116
+ async function recordVotes(stateDir, votes) {
117
+ if (!votes.length) return;
118
+ try {
119
+ const scores = await readScores(stateDir);
120
+ for (const vote of votes) {
121
+ const row = (scores[vote.roster] ??= {})[vote.model] ??= { asked: 0, right: 0 };
122
+ row.asked++;
123
+ if (vote.withWinner) row.right++;
124
+ }
125
+ await fs.mkdir(path.dirname(votersFile(stateDir)), { recursive: true, mode: 448 });
126
+ await fs.writeFile(votersFile(stateDir), `${JSON.stringify(scores, null, 2)}
127
+ `, { mode: 384 });
128
+ } catch {
129
+ }
130
+ }
131
+ async function voterOrder(stateDir, least = 20) {
132
+ const out = {};
133
+ for (const [roster, models] of Object.entries(await readScores(stateDir))) {
134
+ const ranked = Object.entries(models).filter(([model, row]) => row.asked >= least && !model.startsWith("subscription-")).sort((a, b) => b[1].right / b[1].asked - a[1].right / a[1].asked).map(([model]) => model);
135
+ if (ranked.length) out[roster] = ranked;
136
+ }
137
+ return out;
138
+ }
139
+ async function voterScores(stateDir) {
140
+ return Object.entries(await readScores(stateDir)).flatMap(([roster, models]) => Object.entries(models).map(([model, row]) => ({ roster, model, ...row }))).sort((a, b) => a.roster.localeCompare(b.roster) || b.right / b.asked - a.right / a.asked);
141
+ }
142
+ var SAMPLES_KEPT = 300;
143
+ async function saveSamples(stateDir, outcome, family, samples, now = /* @__PURE__ */ new Date()) {
144
+ if (!samples.length) return;
145
+ try {
146
+ const root = path.join(stateDir, "computer", "captcha-samples");
147
+ const stamp = now.toISOString().replace(/[:.]/g, "-");
148
+ for (const [index, sample] of samples.entries()) {
149
+ const dir = path.join(root, `${stamp}-${index + 1}`);
150
+ await fs.mkdir(dir, { recursive: true, mode: 448 });
151
+ const pictures = [];
152
+ for (const [n, image] of sample.images.entries()) {
153
+ const name = `picture-${n + 1}.${/png/.test(image.mimeType) ? "png" : "jpg"}`;
154
+ await fs.writeFile(path.join(dir, name), Buffer.from(image.data, "base64"), { mode: 384 });
155
+ pictures.push(name);
156
+ }
157
+ await fs.writeFile(path.join(dir, "question.json"), `${JSON.stringify({ at: now.toISOString(), family, outcome, roster: sample.roster, text: sample.text, pictures, answers: sample.answers }, null, 2)}
158
+ `, { mode: 384 });
159
+ }
160
+ const all = (await fs.readdir(root)).sort();
161
+ for (const old of all.slice(0, Math.max(0, all.length - SAMPLES_KEPT))) await fs.rm(path.join(root, old), { recursive: true, force: true });
162
+ } catch {
163
+ }
164
+ }
165
+ async function captchaTally(stateDir, days = 30, now = Date.now()) {
166
+ const byFamily = /* @__PURE__ */ new Map();
167
+ for (const record of await recordsSince(stateDir, now - days * 864e5)) {
168
+ const tally = byFamily.get(record.family) ?? { family: record.family, runs: 0, cleared: 0, seconds: 0 };
169
+ tally.runs++;
170
+ if (record.outcome === "cleared") tally.cleared++;
171
+ tally.seconds += record.seconds;
172
+ byFamily.set(record.family, tally);
173
+ }
174
+ return [...byFamily.values()].sort((a, b) => b.runs - a.runs);
175
+ }
176
+ function stepOf(traceLine) {
177
+ if (/^Google refused|\(Google refused it\)/i.test(traceLine)) return "refused";
178
+ if (/^audio:/i.test(traceLine)) return "audio";
179
+ if (/^\d+ squares/i.test(traceLine)) return "pictures";
180
+ if (/GeeTest slide/i.test(traceLine)) return "slide";
181
+ if (/^slider/i.test(traceLine)) return "slider";
182
+ if (/holding off/i.test(traceLine)) return "held-off";
183
+ if (/GeeTest board/i.test(traceLine)) return "board";
184
+ if (/GeeTest icons/i.test(traceLine)) return "icons";
185
+ if (/GeeTest match/i.test(traceLine)) return "match";
186
+ if (/^Arkose/i.test(traceLine)) return "arkose";
187
+ if (/press and hold/i.test(traceLine)) return "hold";
188
+ if (/text captcha/i.test(traceLine)) return "text";
189
+ if (/proof of work/i.test(traceLine)) return "pow";
190
+ if (/dragging/i.test(traceLine)) return "drag";
191
+ if (/clicking/i.test(traceLine)) return "click";
192
+ if (/another challenge|asking for another/i.test(traceLine)) return "refresh";
193
+ return void 0;
194
+ }
195
+ function familyOf(widget, steps) {
196
+ if (widget && widget !== "slider") return widget;
197
+ if (steps.some((s) => s === "slide" || s === "board" || s === "icons" || s === "match")) return "geetest";
198
+ if (steps.includes("arkose")) return "arkose";
199
+ if (steps.includes("hold")) return "hold";
200
+ if (steps.includes("text")) return "text";
201
+ if (steps.includes("pow")) return "pow";
202
+ return widget ?? "unknown";
203
+ }
204
+ export {
205
+ CAPTCHA_LOG_MAX_BYTES,
206
+ RECAPTCHA_REFUSAL_COOLDOWN_MS,
207
+ captchaCost,
208
+ captchaLogPath,
209
+ captchaTally,
210
+ familyOf,
211
+ heldOffHosts,
212
+ recaptchaRefusedRecently,
213
+ recordCaptcha,
214
+ recordVotes,
215
+ saveSamples,
216
+ shouldHoldOff,
217
+ stepOf,
218
+ voterOrder,
219
+ voterScores,
220
+ weakKinds
221
+ };
@@ -0,0 +1,185 @@
1
+ import { createRequire as __clikcodeCreateRequire } from 'node:module';
2
+ const require = __clikcodeCreateRequire(import.meta.url);
3
+ import {
4
+ stateDirectory
5
+ } from "./chunk-MPAJ446F.js";
6
+ import {
7
+ scrubSecrets
8
+ } from "./chunk-CBANJFBO.js";
9
+
10
+ // src/runtime/lifecycle-log.ts
11
+ import { appendFileSync, existsSync, mkdirSync, readFileSync, renameSync, statSync } from "node:fs";
12
+ import { join } from "node:path";
13
+ import { subscribe } from "node:diagnostics_channel";
14
+ import { basename } from "node:path";
15
+
16
+ // src/runtime/secret-shapes.ts
17
+ var SECRET_SHAPES = [
18
+ /-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z0-9 ]*PRIVATE KEY-----|$)/g,
19
+ // OpenAI, Anthropic, OpenRouter and most `sk-` style keys.
20
+ /\b(?:sk|pk|rk)-(?:ant-|proj-|or-)?[A-Za-z0-9_-]{16,}/g,
21
+ // GitHub tokens.
22
+ /\b(?:gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,})/g,
23
+ // Slack, Stripe, Google, AWS, Hugging Face, npm, GitLab.
24
+ /\bxox[abprs]-[A-Za-z0-9-]{10,}/g,
25
+ /\b(?:sk|rk|pk)_(?:live|test)_[A-Za-z0-9]{16,}/g,
26
+ /\bAIza[0-9A-Za-z_-]{30,}/g,
27
+ /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g,
28
+ /\bhf_[A-Za-z0-9]{20,}/g,
29
+ /\bnpm_[A-Za-z0-9]{30,}/g,
30
+ /\bglpat-[A-Za-z0-9_-]{16,}/g,
31
+ // A JWT: three base64url parts, the first an encoded `{"`.
32
+ /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g
33
+ ];
34
+
35
+ // src/runtime/redact.ts
36
+ var LOG_SHAPES = [
37
+ ...SECRET_SHAPES,
38
+ /\b(?:Bearer|Basic)\s+[\w.=+/-]{12,}/gi,
39
+ /\b((?:api[_-]?key|token|secret|password|passwd|authorization)["']?\s*[=:]\s*["']?)[^\s"']{8,}/gi,
40
+ /(:\/\/[^\s/:@]+:)[^\s/@]+@/g
41
+ ];
42
+ function redactForLog(text) {
43
+ let out = scrubSecrets(text);
44
+ for (const shape of LOG_SHAPES) out = out.replace(shape, (_whole, keep) => typeof keep === "string" ? `${keep}[secret hidden]${keep.endsWith(":") && keep.includes("//") ? "@" : ""}` : "[secret hidden]");
45
+ return out;
46
+ }
47
+
48
+ // src/runtime/lifecycle-log.ts
49
+ var ROTATE_BYTES = 10 * 1024 * 1024;
50
+ var ROTATE_CHECK_EVERY = 200;
51
+ var role = "command";
52
+ var session;
53
+ var linesSinceCheck = ROTATE_CHECK_EVERY;
54
+ function setLifecycleRole(next, sessionId) {
55
+ role = next;
56
+ if (sessionId !== void 0) session = sessionId;
57
+ }
58
+ function setLifecycleSession(sessionId) {
59
+ session = sessionId;
60
+ }
61
+ var sessionSource;
62
+ function setLifecycleSessionSource(source) {
63
+ sessionSource = source;
64
+ }
65
+ function lifecycleLogPath() {
66
+ return join(stateDirectory(), "logs", "lifecycle.log");
67
+ }
68
+ function enabled() {
69
+ return process.env.CLIKCODE_LIFECYCLE_LOG !== "0";
70
+ }
71
+ function lifecycle(event, fields = {}) {
72
+ if (!enabled()) return;
73
+ try {
74
+ const home = stateDirectory();
75
+ if (!existsSync(home)) return;
76
+ const dir = join(home, "logs");
77
+ mkdirSync(dir, { recursive: true, mode: 448 });
78
+ const path = join(dir, "lifecycle.log");
79
+ if (++linesSinceCheck >= ROTATE_CHECK_EVERY) {
80
+ linesSinceCheck = 0;
81
+ try {
82
+ if (statSync(path).size > ROTATE_BYTES) renameSync(path, `${path}.1`);
83
+ } catch {
84
+ }
85
+ }
86
+ const current = sessionSource ? sessionSource() : session;
87
+ const line = JSON.stringify({ ...fields, t: (/* @__PURE__ */ new Date()).toISOString(), pid: process.pid, role, ...current ? { session: current } : {}, event });
88
+ appendFileSync(path, `${line}
89
+ `, { encoding: "utf8", mode: 384 });
90
+ } catch {
91
+ }
92
+ }
93
+ function diagnostic(kind, message) {
94
+ lifecycle("note", { kind, message: redactForLog(message).slice(0, 300) });
95
+ }
96
+ var BENIGN_CODES = /* @__PURE__ */ new Set(["ENOENT", "ESRCH", "ECANCELED", "EEXIST", "ENOTEMPTY"]);
97
+ var QUIET_WINDOW_MS = 6e4;
98
+ var quietSeen = /* @__PURE__ */ new Map();
99
+ function oncePerWindow(key) {
100
+ const now = Date.now();
101
+ const seen = quietSeen.get(key);
102
+ if (seen && now - seen.at < QUIET_WINDOW_MS) {
103
+ seen.skipped += 1;
104
+ return void 0;
105
+ }
106
+ quietSeen.set(key, { at: now, skipped: 0 });
107
+ if (quietSeen.size > 500) quietSeen.delete(quietSeen.keys().next().value);
108
+ return { more: seen?.skipped ?? 0 };
109
+ }
110
+ function swallowed(area, error) {
111
+ const code = errnoOf(error);
112
+ if (code && BENIGN_CODES.has(code)) return void 0;
113
+ if (error?.name === "AbortError") return void 0;
114
+ const window = oncePerWindow(`swallowed:${area}`);
115
+ if (!window) return void 0;
116
+ const message = error instanceof Error ? error.message : String(error ?? "");
117
+ lifecycle("swallowed", { area, ...code ? { errno: code } : {}, message: redactForLog(message).slice(0, 200), ...window.more ? { more: window.more } : {} });
118
+ return void 0;
119
+ }
120
+ var quiet = (area) => (error) => swallowed(area, error);
121
+ var childrenObserved = false;
122
+ function observeChildProcesses() {
123
+ if (childrenObserved) return;
124
+ childrenObserved = true;
125
+ subscribe("child_process", (message) => {
126
+ const child = message.process;
127
+ if (!child) return;
128
+ const startedAt = Date.now();
129
+ const report = (how) => {
130
+ const program = basename(child.spawnfile || "unknown").slice(0, 40);
131
+ const window = oncePerWindow(`child:${program}:${String(how.errno ?? how.code ?? how.signal ?? "")}`);
132
+ if (window) lifecycle("child.failed", { program, argc: Math.max(0, (child.spawnargs?.length ?? 1) - 1), ms: Date.now() - startedAt, ...how, ...window.more ? { more: window.more } : {} });
133
+ };
134
+ child.once("error", (error) => report({ errno: errnoOf(error) ?? "error" }));
135
+ child.once("exit", (code, signal) => {
136
+ if (code !== 0) report({ ...code !== null ? { code } : {}, ...signal ? { signal } : {} });
137
+ });
138
+ });
139
+ }
140
+ var exitHooked = false;
141
+ function errnoOf(error) {
142
+ const code = error?.code;
143
+ return typeof code === "string" ? code : void 0;
144
+ }
145
+ function parentProcessName() {
146
+ try {
147
+ return readFileSync(`/proc/${process.ppid}/comm`, "utf8").trim().slice(0, 40) || void 0;
148
+ } catch {
149
+ return void 0;
150
+ }
151
+ }
152
+ function lifecycleProcess(details = {}) {
153
+ const argv = process.argv.slice(2, 4).join(" ");
154
+ const parent = parentProcessName();
155
+ const startedAt = Date.now();
156
+ observeChildProcesses();
157
+ lifecycle("process.start", { argv, ppid: process.ppid, ...parent ? { parent } : {}, node: process.version, ...details });
158
+ if (exitHooked) return;
159
+ exitHooked = true;
160
+ process.on("exit", (code) => lifecycle("process.exit", { code, argv, ...parent ? { parent } : {}, ms: Date.now() - startedAt }));
161
+ for (const signal of ["SIGTERM", "SIGHUP"]) {
162
+ const onSignal = () => {
163
+ lifecycle("process.signal", { signal, argv, ...parent ? { parent } : {}, ms: Date.now() - startedAt });
164
+ if (process.listenerCount(signal) > 1) return;
165
+ process.removeListener(signal, onSignal);
166
+ process.kill(process.pid, signal);
167
+ };
168
+ process.on(signal, onSignal);
169
+ }
170
+ process.on("uncaughtExceptionMonitor", (error, origin) => lifecycle("process.error", { origin, argv, ...errnoOf(error) ? { errno: errnoOf(error) } : {}, message: redactForLog(error?.message ?? "").slice(0, 300) }));
171
+ }
172
+
173
+ export {
174
+ SECRET_SHAPES,
175
+ redactForLog,
176
+ setLifecycleRole,
177
+ setLifecycleSession,
178
+ setLifecycleSessionSource,
179
+ lifecycleLogPath,
180
+ lifecycle,
181
+ diagnostic,
182
+ swallowed,
183
+ quiet,
184
+ lifecycleProcess
185
+ };
@@ -0,0 +1,104 @@
1
+ import { createRequire as __clikcodeCreateRequire } from 'node:module';
2
+ const require = __clikcodeCreateRequire(import.meta.url);
3
+ import {
4
+ MAX_IMAGE_SIDE,
5
+ MAX_TOOL_IMAGE_BYTES,
6
+ sniffImage
7
+ } from "./chunk-LAVFOA3S.js";
8
+ import {
9
+ defineTool
10
+ } from "./chunk-2BBELGHY.js";
11
+ import {
12
+ argumentSummary,
13
+ formatToolRow
14
+ } from "./chunk-W3YYPBEA.js";
15
+
16
+ // src/agent/mcp/tools.ts
17
+ import { createHash } from "node:crypto";
18
+ var MAX_TOOL_NAME = 64;
19
+ var MAX_DESCRIPTION = 2e3;
20
+ var MAX_PREVIEW_ARGS = 2e3;
21
+ function cleanPart(part) {
22
+ return part.replace(/[^a-zA-Z0-9_-]/g, "_");
23
+ }
24
+ function shortHash(text) {
25
+ return createHash("sha256").update(text).digest("hex").slice(0, 8);
26
+ }
27
+ function mcpToolName(server, tool, taken = /* @__PURE__ */ new Set()) {
28
+ const plain = `mcp__${cleanPart(server)}__${cleanPart(tool)}`;
29
+ const exact = plain === `mcp__${server}__${tool}`;
30
+ if (exact && plain.length <= MAX_TOOL_NAME && !taken.has(plain)) return plain;
31
+ const suffix = `_${shortHash(`${server}\0${tool}`)}`;
32
+ return `${plain.slice(0, MAX_TOOL_NAME - suffix.length)}${suffix}`;
33
+ }
34
+ function mcpToolParameters(schema) {
35
+ const base = schema && typeof schema === "object" && !Array.isArray(schema) ? { ...schema } : {};
36
+ delete base.$schema;
37
+ return { ...base, type: "object", properties: base.properties && typeof base.properties === "object" ? base.properties : {} };
38
+ }
39
+ function byteSize(base64) {
40
+ const bytes = typeof base64 === "string" ? Math.floor(base64.length * 3 / 4) : 0;
41
+ return bytes >= 1024 ? `${(bytes / 1024).toFixed(1)} KB` : `${bytes} B`;
42
+ }
43
+ function describeContent(item) {
44
+ const entry = item;
45
+ switch (item.type) {
46
+ case "text":
47
+ return String(entry.text ?? "");
48
+ case "image":
49
+ case "audio":
50
+ return `[${item.type}: ${entry.mimeType ?? "unknown type"}, ${byteSize(entry.data)}]`;
51
+ case "resource": {
52
+ const resource = entry.resource ?? {};
53
+ if (typeof resource.text === "string") return resource.text;
54
+ return `[resource: ${String(resource.uri ?? "unnamed")}${resource.mimeType ? ` (${String(resource.mimeType)})` : ""}${resource.blob ? `, ${byteSize(resource.blob)}` : ""}]`;
55
+ }
56
+ case "resource_link":
57
+ return `[resource link: ${[entry.name, entry.uri].filter(Boolean).join(" ")}]`;
58
+ default:
59
+ return `[${String(item.type)} content]`;
60
+ }
61
+ }
62
+ function formatMcpResult(result, acceptsImages = false) {
63
+ const parts = (Array.isArray(result.content) ? result.content : []).map(describeContent).filter((part) => part.length);
64
+ const images = acceptsImages && !result.isError ? (result.content ?? []).flatMap((item) => {
65
+ if (item.type !== "image" || typeof item.data !== "string" || typeof item.mimeType !== "string") return [];
66
+ if (!/^[A-Za-z0-9+/]+={0,2}$/.test(item.data) || item.data.length > Math.ceil(MAX_TOOL_IMAGE_BYTES * 4 / 3) + 4) return [];
67
+ const bytes = Buffer.from(item.data, "base64");
68
+ const found = sniffImage(bytes);
69
+ if (!found || found.mimeType !== item.mimeType || bytes.length > MAX_TOOL_IMAGE_BYTES || found.width !== void 0 && found.width > MAX_IMAGE_SIDE || found.height !== void 0 && found.height > MAX_IMAGE_SIDE) return [];
70
+ return [{ mimeType: found.mimeType, data: item.data }];
71
+ }) : [];
72
+ let output = parts.join("\n");
73
+ if (!output && result.structuredContent !== void 0) output = JSON.stringify(result.structuredContent, null, 2);
74
+ return { output: output || "(no output)", ...result.isError ? { isError: true } : {}, ...images.length ? { images } : {} };
75
+ }
76
+ function mcpToolDefinition(server, info, name, call, core = false) {
77
+ const title = info.title ?? info.annotations?.title ?? info.name;
78
+ const description = `${info.description?.trim() || title} (from MCP server "${server}")`;
79
+ return defineTool({
80
+ name,
81
+ description: description.length > MAX_DESCRIPTION ? `${description.slice(0, MAX_DESCRIPTION - 1)}\u2026` : description,
82
+ parameters: mcpToolParameters(info.inputSchema),
83
+ class: info.annotations?.readOnlyHint === true ? "read" : "exec",
84
+ mcp: { server, tool: info.name, ...core ? { core: true } : {} },
85
+ label: (args) => formatToolRow(`mcp__${server}__${info.name}`, argumentSummary(args)),
86
+ describe: async (args) => {
87
+ const json = JSON.stringify(args, null, 2);
88
+ return [
89
+ `MCP server: ${server}`,
90
+ `tool: ${info.name}`,
91
+ "arguments:",
92
+ json.length > MAX_PREVIEW_ARGS ? `${json.slice(0, MAX_PREVIEW_ARGS)}
93
+ \u2026 truncated` : json
94
+ ].join("\n");
95
+ },
96
+ run: async (args, ctx) => formatMcpResult(await call(info.name, args, ctx.signal), ctx.acceptsImages)
97
+ });
98
+ }
99
+
100
+ export {
101
+ mcpToolName,
102
+ formatMcpResult,
103
+ mcpToolDefinition
104
+ };
@@ -0,0 +1,84 @@
1
+ import { createRequire as __clikcodeCreateRequire } from 'node:module';
2
+ const require = __clikcodeCreateRequire(import.meta.url);
3
+ import {
4
+ osc52Sequence
5
+ } from "./chunk-DCZ6CIUM.js";
6
+ import {
7
+ loginPortForwardHint
8
+ } from "./chunk-4AQ5NINV.js";
9
+ import {
10
+ spawnPortable
11
+ } from "./chunk-WPB5WEZJ.js";
12
+ import {
13
+ HYPERLINK_CLOSE,
14
+ hyperlinkOpen,
15
+ stripAnsi
16
+ } from "./chunk-G3QP67Z7.js";
17
+
18
+ // src/gateway/login/url.ts
19
+ function loginLinkLine(url, hyperlinked = Boolean(process.stdout.isTTY)) {
20
+ return hyperlinked && /^https?:\/\//.test(url) && !/[\x00-\x1f\x7f]/.test(url) ? `${hyperlinkOpen(url)}${url}${HYPERLINK_CLOSE}` : url;
21
+ }
22
+ function extractLoginUrl(text) {
23
+ const urls = joinWrappedLoginUrls(stripAnsi(text)).match(/https:\/\/[^\s"'<>)\]\u2500-\u259f]+/g) ?? [];
24
+ const isAuth = (url) => /\b(?:oauth2?|auth|authorize|authorise|login|sign-?in|device|activate)\b|user_code=|_device\b/i.test(url);
25
+ return urls.filter((url) => isAuth(url) && completeLoginUrl(url)).sort((left, right) => right.length - left.length)[0];
26
+ }
27
+ function joinWrappedLoginUrls(text) {
28
+ const lines = text.split(/\r?\n/).map((line) => line.replace(/[ \t]*[│┃║][ \t]*$/, "").trimEnd());
29
+ const joined = [];
30
+ for (const line of lines) {
31
+ const continuation = line.replace(/^[ \t│┃║]+/, "").trimEnd();
32
+ const previous = joined.at(-1);
33
+ if (/^[ \t│┃║]+/.test(line) && previous && /https:\/\/[^\s]+$/.test(previous) && !continuation.startsWith("https://") && /^[A-Za-z0-9_%~.!$&()*+,;=:@/?#-]+$/.test(continuation)) {
34
+ joined[joined.length - 1] = previous + continuation;
35
+ } else joined.push(line);
36
+ }
37
+ return joined.join("\n");
38
+ }
39
+ function completeLoginUrl(value) {
40
+ try {
41
+ const url = new URL(value);
42
+ if (url.hostname !== "accounts.google.com") return true;
43
+ if (!/^\/o\/oauth2(?:\/v2)?\/auth$/.test(url.pathname)) return true;
44
+ return ["client_id", "response_type", "redirect_uri", "scope"].every((key) => Boolean(url.searchParams.get(key))) && url.searchParams.get("response_type") === "code" && url.searchParams.get("client_id").endsWith(".apps.googleusercontent.com");
45
+ } catch {
46
+ return false;
47
+ }
48
+ }
49
+ function callbacksReachable(environment = process.env) {
50
+ return hasLocalDisplay(environment) || environment.CLIKDEPLOY_REMOTE_TERMINAL === "1";
51
+ }
52
+ function hasLocalDisplay(environment = process.env) {
53
+ if (environment.CLIKDEPLOY_REMOTE_TERMINAL === "1" || environment.SSH_CONNECTION || environment.SSH_TTY) return false;
54
+ if (process.platform === "darwin" || process.platform === "win32") return true;
55
+ return Boolean(environment.DISPLAY || environment.WAYLAND_DISPLAY);
56
+ }
57
+ function openLoginUrl(url, platform = process.platform) {
58
+ const [command, args] = platform === "darwin" ? ["open", [url]] : platform === "win32" ? ["cmd", ["/c", "start", "", url]] : ["xdg-open", [url]];
59
+ const child = spawnPortable(command, [...args], { stdio: "ignore", detached: true });
60
+ child.on("error", () => {
61
+ });
62
+ child.unref();
63
+ }
64
+ function loginUrlNotice(url, environment = process.env) {
65
+ const local = hasLocalDisplay(environment);
66
+ return {
67
+ clipboard: osc52Sequence(url, environment),
68
+ lines: [
69
+ `ClikCode \xB7 ${loginLinkLine(url)}`,
70
+ ...loginPortForwardHint(url, environment) ? [loginPortForwardHint(url, environment)] : [],
71
+ local ? "A browser should have opened here; paste the link if it did not." : "Paste it into your phone's browser, then come back and paste any code below."
72
+ ]
73
+ };
74
+ }
75
+
76
+ export {
77
+ loginLinkLine,
78
+ extractLoginUrl,
79
+ completeLoginUrl,
80
+ callbacksReachable,
81
+ hasLocalDisplay,
82
+ openLoginUrl,
83
+ loginUrlNotice
84
+ };