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,454 @@
1
+ import { createRequire as __clikcodeCreateRequire } from 'node:module';
2
+ const require = __clikcodeCreateRequire(import.meta.url);
3
+ import {
4
+ parseMcpServerEntry
5
+ } from "./chunk-DQYVQ2N7.js";
6
+ import {
7
+ lazyModule
8
+ } from "./chunk-JGIWATSG.js";
9
+ import {
10
+ atomicWriteFile
11
+ } from "./chunk-F6F47QAY.js";
12
+
13
+ // src/agent/plugins.ts
14
+ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
15
+ import { homedir } from "node:os";
16
+ import path2 from "node:path";
17
+
18
+ // src/agent/skills.ts
19
+ import fs from "node:fs/promises";
20
+ import path from "node:path";
21
+ var SKILL_FILE = "SKILL.md";
22
+ var SKILL_TOOL = "skill";
23
+ var MAX_LISTED_SKILLS = 20;
24
+ var MAX_DESCRIPTION_CHARS = 150;
25
+ var MAX_SKILL_DIRS = 200;
26
+ var FRONTMATTER_READ_BYTES = 16 * 1024;
27
+ var MAX_NAME_CHARS = 64;
28
+ var CACHE_ENTRIES = 16;
29
+ function looseFields(block) {
30
+ const fields = {};
31
+ for (const line of block.split(/\r?\n/)) {
32
+ const match = /^([A-Za-z][\w-]*):\s*(.*)$/.exec(line);
33
+ if (!match) continue;
34
+ let value = match[2].trim();
35
+ if (value.length >= 2 && (value[0] === '"' || value[0] === "'") && value.endsWith(value[0])) value = value.slice(1, -1);
36
+ if (value) fields[match[1]] = value;
37
+ }
38
+ return fields;
39
+ }
40
+ var yaml = lazyModule("yaml");
41
+ function parseFrontmatter(text) {
42
+ const source = text.replace(/^/, "");
43
+ const match = /^---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/.exec(source);
44
+ if (!match) return { error: "no YAML frontmatter (the file must start with a --- block)" };
45
+ const body = source.slice(match[0].length);
46
+ try {
47
+ const value = yaml().parse(match[1]);
48
+ if (value && typeof value === "object" && !Array.isArray(value)) return { fields: value, body };
49
+ return { error: "frontmatter is not a key/value mapping" };
50
+ } catch (error) {
51
+ const fields = looseFields(match[1]);
52
+ if (typeof fields.description === "string") return { fields, body };
53
+ return { error: `invalid YAML frontmatter: ${(error instanceof Error ? error.message : String(error)).split("\n")[0]}` };
54
+ }
55
+ }
56
+ function validate(fields, dirName) {
57
+ const name = fields.name === void 0 ? dirName : fields.name;
58
+ if (typeof name !== "string" || !name.trim()) return { reason: "`name` must be a non-empty string" };
59
+ if (/\s/.test(name.trim())) return { reason: `name "${name}" contains whitespace` };
60
+ if (name.trim().length > MAX_NAME_CHARS) return { reason: `name is longer than ${MAX_NAME_CHARS} characters` };
61
+ if (typeof fields.description !== "string" || !fields.description.trim()) return { reason: "missing `description`: the model could not tell when to use it" };
62
+ if (fields["disable-model-invocation"] === true) return { reason: "disable-model-invocation is set" };
63
+ return { name: name.trim(), description: fields.description.replace(/\s+/g, " ").trim() };
64
+ }
65
+ async function readHead(file, bytes) {
66
+ const handle = await fs.open(file, "r");
67
+ try {
68
+ const buffer = Buffer.alloc(bytes);
69
+ const { bytesRead } = await handle.read(buffer, 0, bytes, 0);
70
+ return buffer.subarray(0, bytesRead).toString("utf8");
71
+ } finally {
72
+ await handle.close();
73
+ }
74
+ }
75
+ async function exists(file) {
76
+ try {
77
+ await fs.access(file);
78
+ return true;
79
+ } catch {
80
+ return false;
81
+ }
82
+ }
83
+ async function findRepoRoot(cwd) {
84
+ for (let dir = cwd; ; dir = path.dirname(dir)) {
85
+ if (await exists(path.join(dir, ".git"))) return dir;
86
+ if (path.dirname(dir) === dir) return void 0;
87
+ }
88
+ }
89
+ async function scanLocation(dir, source, skipped, pluginRoot) {
90
+ let entries;
91
+ try {
92
+ entries = await fs.readdir(dir, { withFileTypes: true });
93
+ } catch {
94
+ return [];
95
+ }
96
+ const candidates = entries.filter((entry) => !entry.name.startsWith(".") && (entry.isDirectory() || entry.isSymbolicLink())).map((entry) => entry.name).sort().slice(0, MAX_SKILL_DIRS);
97
+ const found = await Promise.all(candidates.map(async (dirName) => {
98
+ const skillDir = path.join(dir, dirName);
99
+ const file = path.join(skillDir, SKILL_FILE);
100
+ let head;
101
+ try {
102
+ head = await readHead(file, FRONTMATTER_READ_BYTES);
103
+ } catch {
104
+ return void 0;
105
+ }
106
+ const parsed = parseFrontmatter(head);
107
+ if ("error" in parsed) {
108
+ skipped.push({ file, reason: parsed.error });
109
+ return void 0;
110
+ }
111
+ const checked = validate(parsed.fields, dirName);
112
+ if ("reason" in checked) {
113
+ skipped.push({ file, reason: checked.reason });
114
+ return void 0;
115
+ }
116
+ return { ...checked, dir: skillDir, file, source, ...pluginRoot ? { pluginRoot } : {} };
117
+ }));
118
+ return found.filter((skill) => !!skill);
119
+ }
120
+ async function scanAll(roots) {
121
+ const cwd = path.resolve(roots.cwd);
122
+ const repoRoot = await findRepoRoot(cwd);
123
+ const projectDirs = [];
124
+ for (let dir = cwd; ; dir = path.dirname(dir)) {
125
+ projectDirs.push(dir);
126
+ if (!repoRoot || dir === repoRoot || path.dirname(dir) === dir) break;
127
+ }
128
+ const locations = [
129
+ ...projectDirs.map((dir) => ({ dir: path.join(dir, ".clikcode", "skills"), source: "project" })),
130
+ ...projectDirs.map((dir) => ({ dir: path.join(dir, ".claude", "skills"), source: "project-claude" })),
131
+ { dir: path.join(roots.stateDir, "skills"), source: "user" },
132
+ { dir: path.join(roots.homeDir, ".claude", "skills"), source: "user-claude" },
133
+ ...enabledPluginSkillDirs({ stateDir: roots.stateDir, home: roots.homeDir }).map((item) => ({ dir: item.dir, source: "plugin", pluginRoot: item.root }))
134
+ ];
135
+ const skipped = [];
136
+ const scanned = await Promise.all(locations.map((location) => scanLocation(location.dir, location.source, skipped, location.pluginRoot)));
137
+ const seenDirs = /* @__PURE__ */ new Set();
138
+ const byName = /* @__PURE__ */ new Map();
139
+ const shadowed = [];
140
+ for (const skill of scanned.flat()) {
141
+ const real = await fs.realpath(skill.dir).catch(() => skill.dir);
142
+ if (seenDirs.has(real)) continue;
143
+ seenDirs.add(real);
144
+ if (byName.has(skill.name)) shadowed.push(skill);
145
+ else byName.set(skill.name, skill);
146
+ }
147
+ return { skills: [...byName.values()], skipped, shadowed };
148
+ }
149
+ var cache = /* @__PURE__ */ new Map();
150
+ function discoverSkills(roots) {
151
+ if (!roots.turnId) return scanAll(roots);
152
+ const key = [roots.turnId, path.resolve(roots.cwd), roots.stateDir, roots.homeDir].join("\0");
153
+ let pending = cache.get(key);
154
+ if (!pending) {
155
+ pending = scanAll(roots);
156
+ cache.set(key, pending);
157
+ while (cache.size > CACHE_ENTRIES) cache.delete(cache.keys().next().value);
158
+ }
159
+ return pending;
160
+ }
161
+ function clip(text, max) {
162
+ if (text.length <= max) return text;
163
+ const cut = text.slice(0, max - 1);
164
+ const space = cut.lastIndexOf(" ");
165
+ return `${(space > max * 0.6 ? cut.slice(0, space) : cut).replace(/[\s,;:.]+$/, "")}\u2026`;
166
+ }
167
+ function skillsPromptSection(skills, limits = { maxListedSkills: MAX_LISTED_SKILLS, skillDescriptionChars: MAX_DESCRIPTION_CHARS }) {
168
+ if (!skills.length) return "";
169
+ const listed = skills.slice(0, limits.maxListedSkills);
170
+ const more = skills.length - listed.length;
171
+ return [
172
+ "# Skills",
173
+ `Skills are instructions for specific kinds of task. When one fits the task, call ${SKILL_TOOL} with its name before starting and follow what it says.`,
174
+ ...listed.map((skill) => `- ${skill.name}: ${clip(skill.description, limits.skillDescriptionChars)}`),
175
+ ...more > 0 ? [`(${more} more not listed; ${SKILL_TOOL} with an unknown name lists them all.)`] : []
176
+ ].join("\n");
177
+ }
178
+
179
+ // src/agent/plugins.ts
180
+ var PLUGIN_MANIFEST = path2.join(".claude-plugin", "plugin.json");
181
+ var REGISTRY_FILE = "plugins.json";
182
+ var MAX_AGENT_FILES = 100;
183
+ var MAX_FILE_BYTES = 256 * 1024;
184
+ function isRecord(value) {
185
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
186
+ }
187
+ function readJson(file) {
188
+ try {
189
+ return JSON.parse(readFileSync(file, "utf8"));
190
+ } catch {
191
+ return void 0;
192
+ }
193
+ }
194
+ function pluginsDirectory(stateDir) {
195
+ return path2.join(stateDir, "plugins");
196
+ }
197
+ function pluginRegistryPath(stateDir) {
198
+ return path2.join(pluginsDirectory(stateDir), REGISTRY_FILE);
199
+ }
200
+ function readPluginRegistry(stateDir) {
201
+ const raw = readJson(pluginRegistryPath(stateDir));
202
+ const table = (key) => isRecord(raw) && isRecord(raw[key]) ? raw[key] : {};
203
+ return { claude: table("claude") };
204
+ }
205
+ function claudePluginsDirectory(home = homedir()) {
206
+ return path2.join(home, ".claude", "plugins");
207
+ }
208
+ function readPluginManifest(root) {
209
+ const raw = readJson(path2.join(root, PLUGIN_MANIFEST));
210
+ return isRecord(raw) ? raw : void 0;
211
+ }
212
+ function claudeInstalledPlugins(home = homedir()) {
213
+ const record = readJson(path2.join(claudePluginsDirectory(home), "installed_plugins.json"));
214
+ const table = isRecord(record) && isRecord(record.plugins) ? record.plugins : isRecord(record) ? record : {};
215
+ const settings = readJson(path2.join(home, ".claude", "settings.json"));
216
+ const enabled = isRecord(settings) && isRecord(settings.enabledPlugins) ? settings.enabledPlugins : {};
217
+ const found = [];
218
+ for (const [id, value] of Object.entries(table)) {
219
+ if (id === "version") continue;
220
+ const entries = (Array.isArray(value) ? value : [value]).filter(isRecord);
221
+ const entry = entries.find((item) => (item.scope ?? "user") === "user");
222
+ const root = typeof entry?.installPath === "string" ? entry.installPath : void 0;
223
+ if (!root || !existsSync(root)) continue;
224
+ const manifest = readPluginManifest(root);
225
+ found.push({
226
+ id,
227
+ name: manifest?.name ?? id.split("@")[0],
228
+ root,
229
+ claudeEnabled: enabled[id] !== false,
230
+ ...typeof entry?.version === "string" ? { version: entry.version } : manifest?.version ? { version: manifest.version } : {},
231
+ ...manifest?.description ? { description: manifest.description } : {}
232
+ });
233
+ }
234
+ return found;
235
+ }
236
+ function listPlugins(roots) {
237
+ const registry = readPluginRegistry(roots.stateDir);
238
+ return claudeInstalledPlugins(roots.home ?? homedir()).map(({ claudeEnabled, ...plugin }) => ({ ...plugin, enabled: registry.claude[plugin.id]?.enabled ?? claudeEnabled }));
239
+ }
240
+ function findPlugin(roots, query) {
241
+ const plugins = listPlugins(roots);
242
+ const exact = plugins.find((plugin) => plugin.id === query);
243
+ if (exact) return exact;
244
+ const named = plugins.filter((plugin) => plugin.name === query);
245
+ if (named.length === 1) return named[0];
246
+ if (named.length > 1) throw new Error(`${query} is ambiguous: ${named.map((plugin) => plugin.id).join(", ")}`);
247
+ throw new Error(`No plugin named ${query}`);
248
+ }
249
+ async function setPluginEnabled(roots, query, enabled) {
250
+ const plugin = findPlugin(roots, query);
251
+ const registry = readPluginRegistry(roots.stateDir);
252
+ registry.claude[plugin.id] = { enabled };
253
+ await atomicWriteFile(pluginRegistryPath(roots.stateDir), `${JSON.stringify(registry, null, 2)}
254
+ `);
255
+ return { ...plugin, enabled };
256
+ }
257
+ function enabledPlugins(roots) {
258
+ return listPlugins(roots).filter((plugin) => plugin.enabled && existsSync(plugin.root));
259
+ }
260
+ function expandPluginRoot(text, root, dataDir) {
261
+ let out = text.replace(/\$\{CLAUDE_PLUGIN_ROOT\}/g, root);
262
+ if (dataDir) out = out.replace(/\$\{CLAUDE_PLUGIN_DATA\}/g, dataDir);
263
+ return out;
264
+ }
265
+ function manifestPaths(root, value) {
266
+ const list = typeof value === "string" ? [value] : Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
267
+ return list.map((item) => path2.resolve(root, expandPluginRoot(item, root))).filter((item) => item === root || item.startsWith(`${root}${path2.sep}`));
268
+ }
269
+ function isDirectory(file) {
270
+ try {
271
+ return statSync(file).isDirectory();
272
+ } catch {
273
+ return false;
274
+ }
275
+ }
276
+ function pluginSkillDirs(plugin) {
277
+ const manifest = readPluginManifest(plugin.root);
278
+ return [.../* @__PURE__ */ new Set([path2.join(plugin.root, "skills"), ...manifestPaths(plugin.root, manifest?.skills)])].filter(isDirectory);
279
+ }
280
+ function pluginCommandDirs(plugin) {
281
+ const manifest = readPluginManifest(plugin.root);
282
+ return [.../* @__PURE__ */ new Set([path2.join(plugin.root, "commands"), ...manifestPaths(plugin.root, manifest?.commands)])].filter(isDirectory);
283
+ }
284
+ function toolList(value) {
285
+ const list = typeof value === "string" ? value.split(",") : Array.isArray(value) ? value.filter((item) => typeof item === "string") : void 0;
286
+ const cleaned = list?.map((item) => item.trim()).filter(Boolean);
287
+ return cleaned?.length ? cleaned : void 0;
288
+ }
289
+ function readAgentFile(file, plugin) {
290
+ let text;
291
+ try {
292
+ if (statSync(file).size > MAX_FILE_BYTES) return void 0;
293
+ text = readFileSync(file, "utf8");
294
+ } catch {
295
+ return void 0;
296
+ }
297
+ const parsed = parseFrontmatter(text);
298
+ if ("error" in parsed) return void 0;
299
+ const name = typeof parsed.fields.name === "string" && parsed.fields.name.trim() ? parsed.fields.name.trim() : path2.basename(file, ".md");
300
+ const description = typeof parsed.fields.description === "string" ? parsed.fields.description.replace(/\s+/g, " ").trim() : "";
301
+ const prompt = expandPluginRoot(parsed.body.trim(), plugin.root);
302
+ if (!/^[\w.:-]+$/.test(name) || !prompt) return void 0;
303
+ const tools = toolList(parsed.fields.tools);
304
+ return { name, description, prompt, plugin: plugin.name, ...tools ? { tools } : {} };
305
+ }
306
+ function pluginAgents(plugin) {
307
+ const manifest = readPluginManifest(plugin.root);
308
+ const files = [];
309
+ for (const entry of [path2.join(plugin.root, "agents"), ...manifestPaths(plugin.root, manifest?.agents)]) {
310
+ if (isDirectory(entry)) {
311
+ let names = [];
312
+ try {
313
+ names = readdirSync(entry).sort();
314
+ } catch {
315
+ }
316
+ files.push(...names.filter((name) => name.toLowerCase().endsWith(".md")).map((name) => path2.join(entry, name)));
317
+ } else if (entry.toLowerCase().endsWith(".md") && existsSync(entry)) files.push(entry);
318
+ }
319
+ return [...new Set(files)].slice(0, MAX_AGENT_FILES).flatMap((file) => readAgentFile(file, plugin) ?? []);
320
+ }
321
+ function pluginDataDir(stateDir, id) {
322
+ return path2.join(pluginsDirectory(stateDir), "data", id.replace(/[^\w.@-]/g, "_"));
323
+ }
324
+ function pluginHooks(plugin, stateDir) {
325
+ const manifest = readPluginManifest(plugin.root);
326
+ const dataDir = pluginDataDir(stateDir, plugin.id);
327
+ const sources = [];
328
+ const add = (value) => {
329
+ if (typeof value === "string") manifestPaths(plugin.root, value).forEach((file) => sources.push(readJson(file)));
330
+ else if (Array.isArray(value)) value.forEach(add);
331
+ else if (isRecord(value)) sources.push(value);
332
+ };
333
+ add(path2.join(plugin.root, "hooks", "hooks.json"));
334
+ if (manifest?.hooks !== void 0) add(manifest.hooks);
335
+ const merged = {};
336
+ const seen = /* @__PURE__ */ new Set();
337
+ for (const source of sources) {
338
+ if (!isRecord(source)) continue;
339
+ const table = isRecord(source.hooks) ? source.hooks : source;
340
+ for (const [event, groups] of Object.entries(table)) {
341
+ if (!Array.isArray(groups)) continue;
342
+ for (const group of groups) {
343
+ if (!isRecord(group)) continue;
344
+ const key = JSON.stringify([event, group]);
345
+ if (seen.has(key)) continue;
346
+ seen.add(key);
347
+ const hooks = (Array.isArray(group.hooks) ? group.hooks : []).filter(isRecord).map((hook) => ({
348
+ ...hook,
349
+ ...typeof hook.command === "string" ? { command: expandPluginRoot(hook.command, plugin.root, dataDir) } : {},
350
+ env: { CLAUDE_PLUGIN_ROOT: plugin.root, CLAUDE_PLUGIN_DATA: dataDir }
351
+ }));
352
+ (merged[event] ??= []).push({ ...group, hooks });
353
+ }
354
+ }
355
+ }
356
+ return merged;
357
+ }
358
+ function expandEnv(text, root, dataDir) {
359
+ return expandPluginRoot(text, root, dataDir).replace(/\$\{([A-Za-z_]\w*)(?::-([^}]*))?\}/g, (_, name, fallback) => process.env[name] ?? fallback ?? "");
360
+ }
361
+ function expandDeep(value, root, dataDir) {
362
+ if (typeof value === "string") return expandEnv(value, root, dataDir);
363
+ if (Array.isArray(value)) return value.map((item) => expandDeep(item, root, dataDir));
364
+ if (isRecord(value)) return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, expandDeep(item, root, dataDir)]));
365
+ return value;
366
+ }
367
+ function pluginServerName(plugin, server) {
368
+ return `plugin:${plugin}:${server}`;
369
+ }
370
+ function pluginMcpServers(plugin, stateDir) {
371
+ const manifest = readPluginManifest(plugin.root);
372
+ const dataDir = pluginDataDir(stateDir, plugin.id);
373
+ const tables = [readJson(path2.join(plugin.root, ".mcp.json"))];
374
+ const declared = manifest?.mcpServers;
375
+ for (const item of Array.isArray(declared) ? declared : [declared]) {
376
+ if (typeof item === "string") manifestPaths(plugin.root, item).forEach((file) => tables.push(readJson(file)));
377
+ else if (isRecord(item)) tables.push(item);
378
+ }
379
+ const servers = /* @__PURE__ */ new Map();
380
+ for (const raw of tables) {
381
+ if (!isRecord(raw)) continue;
382
+ const table = isRecord(raw.mcpServers) ? raw.mcpServers : raw;
383
+ for (const [name, entry] of Object.entries(table)) {
384
+ const fullName = pluginServerName(plugin.name, name);
385
+ if (servers.has(fullName)) continue;
386
+ const spec = parseMcpServerEntry(fullName, expandDeep(entry, plugin.root, dataDir));
387
+ if (spec) servers.set(fullName, spec);
388
+ }
389
+ }
390
+ return [...servers.values()];
391
+ }
392
+ function enabledPluginAgents(roots) {
393
+ const all = enabledPlugins(roots).flatMap((plugin) => pluginAgents(plugin));
394
+ const count = /* @__PURE__ */ new Map();
395
+ for (const agent of all) count.set(agent.name, (count.get(agent.name) ?? 0) + 1);
396
+ const named = all.map((agent) => count.get(agent.name) === 1 ? agent : { ...agent, name: `${agent.plugin}:${agent.name}` });
397
+ const seen = /* @__PURE__ */ new Set();
398
+ return named.filter((agent) => !seen.has(agent.name) && Boolean(seen.add(agent.name)));
399
+ }
400
+ function findPluginAgent(roots, type) {
401
+ const agents = enabledPluginAgents(roots);
402
+ return agents.find((agent) => agent.name === type || `${agent.plugin}:${agent.name}` === type);
403
+ }
404
+ var GENERAL_AGENT_NAMES = /* @__PURE__ */ new Set(["general-purpose", "general", "default"]);
405
+ function resolveAgentType(roots, type) {
406
+ const wanted = type?.trim();
407
+ if (!wanted) return {};
408
+ const agent = findPluginAgent(roots, wanted);
409
+ if (!agent && GENERAL_AGENT_NAMES.has(wanted.toLowerCase().replace(/[\s_]+/g, "-"))) return {};
410
+ if (agent) return { agentType: { name: agent.name, prompt: agent.prompt, ...agent.tools ? { tools: agent.tools } : {} } };
411
+ const names = enabledPluginAgents(roots).map((item) => item.name);
412
+ return { error: `No agent type "${wanted}".${names.length ? ` Available: ${names.join(", ")}.` : " No plugin agents are installed; leave subagent_type out."}` };
413
+ }
414
+ function agentTypesPromptSection(agents, maxDescription = 150) {
415
+ if (!agents.length) return "";
416
+ return [
417
+ "# Agent types",
418
+ "Plugins provide these specialised sub-agents. Pass one as subagent_type to agent (coding) or task (read-only research) when it fits the job.",
419
+ ...agents.slice(0, 20).map((agent) => `- ${agent.name}: ${agent.description.length > maxDescription ? `${agent.description.slice(0, maxDescription - 1)}\u2026` : agent.description}`)
420
+ ].join("\n");
421
+ }
422
+ function enabledPluginHooks(roots) {
423
+ const merged = {};
424
+ for (const plugin of enabledPlugins(roots)) {
425
+ for (const [event, groups] of Object.entries(pluginHooks(plugin, roots.stateDir))) (merged[event] ??= []).push(...groups ?? []);
426
+ }
427
+ return merged;
428
+ }
429
+ function enabledPluginMcpServers(roots) {
430
+ return enabledPlugins(roots).flatMap((plugin) => pluginMcpServers(plugin, roots.stateDir));
431
+ }
432
+ function enabledPluginCommandDirs(roots) {
433
+ return enabledPlugins(roots).flatMap((plugin) => pluginCommandDirs(plugin).map((dir) => ({ plugin: plugin.name, root: plugin.root, dir })));
434
+ }
435
+ function enabledPluginSkillDirs(roots) {
436
+ return enabledPlugins(roots).flatMap((plugin) => pluginSkillDirs(plugin).map((dir) => ({ plugin: plugin.name, root: plugin.root, dir })));
437
+ }
438
+
439
+ export {
440
+ SKILL_FILE,
441
+ SKILL_TOOL,
442
+ parseFrontmatter,
443
+ discoverSkills,
444
+ skillsPromptSection,
445
+ listPlugins,
446
+ setPluginEnabled,
447
+ expandPluginRoot,
448
+ enabledPluginAgents,
449
+ resolveAgentType,
450
+ agentTypesPromptSection,
451
+ enabledPluginHooks,
452
+ enabledPluginMcpServers,
453
+ enabledPluginCommandDirs
454
+ };
@@ -0,0 +1,164 @@
1
+ import { createRequire as __clikcodeCreateRequire } from 'node:module';
2
+ const require = __clikcodeCreateRequire(import.meta.url);
3
+ import {
4
+ readVaultRecords,
5
+ removeVaultRecord,
6
+ writeVaultRecord
7
+ } from "./chunk-I75EDU75.js";
8
+
9
+ // src/agent/computer/payment-cards.ts
10
+ import { randomUUID } from "node:crypto";
11
+ var FOLDER = "card";
12
+ var MAX_CARDS = 12;
13
+ var shown = ({ number: _number, code: _code, ...card }) => card;
14
+ var digits = (value) => value.replace(/\D+/g, "");
15
+ function luhnValid(number) {
16
+ const d = digits(number);
17
+ if (d.length < 12 || d.length > 19) return false;
18
+ let sum = 0;
19
+ for (let i = 0; i < d.length; i++) {
20
+ let n = d.charCodeAt(d.length - 1 - i) - 48;
21
+ if (i % 2 === 1) {
22
+ n *= 2;
23
+ if (n > 9) n -= 9;
24
+ }
25
+ sum += n;
26
+ }
27
+ return sum % 10 === 0;
28
+ }
29
+ function cardBrand(number) {
30
+ const d = digits(number);
31
+ if (/^4/.test(d)) return "Visa";
32
+ if (/^(5[1-5]|2(2[2-9][1-9]|2[3-9]|[3-6]|7[01]|720))/.test(d)) return "Mastercard";
33
+ if (/^3[47]/.test(d)) return "American Express";
34
+ if (/^(6011|65|64[4-9])/.test(d)) return "Discover";
35
+ if (/^35(2[89]|[3-8])/.test(d)) return "JCB";
36
+ if (/^3(0[0-5]|[689])/.test(d)) return "Diners Club";
37
+ if (/^62/.test(d)) return "UnionPay";
38
+ return "Card";
39
+ }
40
+ function parseExpiry(text) {
41
+ const t = text.trim();
42
+ const iso = /^(20\d{2})\D+(\d{1,2})$/.exec(t);
43
+ const split = iso ? [iso[2], iso[1]] : /^(\d{1,2})\D+(\d{2}|\d{4})$/.exec(t)?.slice(1) ?? (/^(\d{2})(\d{2}|\d{4})$/.exec(digits(t)) && digits(t) === t.replace(/\s+/g, "") ? [digits(t).slice(0, 2), digits(t).slice(2)] : null);
44
+ if (!split) return null;
45
+ const month = Number(split[0]);
46
+ const year = split[1].length === 2 ? 2e3 + Number(split[1]) : Number(split[1]);
47
+ if (!(month >= 1 && month <= 12) || !(year >= 2e3 && year <= 2099)) return null;
48
+ return { month: String(month).padStart(2, "0"), year: String(year) };
49
+ }
50
+ function cardExpired(card, now = /* @__PURE__ */ new Date()) {
51
+ const year = Number(card.expYear);
52
+ const month = Number(card.expMonth);
53
+ return year < now.getFullYear() || year === now.getFullYear() && month < now.getMonth() + 1;
54
+ }
55
+ function describeCard(card) {
56
+ return `${card.brand} ending ${card.last4}, expires ${card.expMonth}/${card.expYear.slice(2)}${card.label && card.label !== card.brand ? ` (${card.label})` : ""}`;
57
+ }
58
+ function describeSavedCard(card, now = /* @__PURE__ */ new Date()) {
59
+ return `${describeCard(card)}${card.name ? `, name ${card.name}` : ""}; security code ${card.hasCode ? "saved" : "asked each time"}${cardExpired(card, now) ? "; EXPIRED" : ""}`;
60
+ }
61
+ async function listCards(stateDir) {
62
+ return (await readVaultRecords(stateDir, FOLDER)).map(({ id, value }) => ({ id, ...shown(value) })).sort((a, b) => a.addedAt.localeCompare(b.addedAt));
63
+ }
64
+ async function saveCard(stateDir, input) {
65
+ const number = digits(input.number);
66
+ if (!luhnValid(number)) throw new Error("That is not a valid card number.");
67
+ const expiry = parseExpiry(input.expiry);
68
+ if (!expiry) throw new Error("The expiry is a month and a year, like 04/27.");
69
+ const code = digits(input.code ?? "");
70
+ if (code && (code.length < 3 || code.length > 4)) throw new Error("The security code is 3 or 4 digits.");
71
+ const stored = await readVaultRecords(stateDir, FOLDER);
72
+ const existing = stored.find(({ value }) => value.number === number);
73
+ if (!existing && stored.length >= MAX_CARDS) throw new Error(`At most ${MAX_CARDS} cards are kept. Remove one first.`);
74
+ const brand = cardBrand(number);
75
+ const id = existing?.id ?? randomUUID();
76
+ const name = input.name?.trim().slice(0, 80) || existing?.value.name;
77
+ const kept = code || (input.code === void 0 ? existing?.value.code : void 0);
78
+ const card = {
79
+ label: (input.label?.trim() || existing?.value.label || brand).slice(0, 40),
80
+ brand,
81
+ last4: number.slice(-4),
82
+ expMonth: expiry.month,
83
+ expYear: expiry.year,
84
+ ...name ? { name } : {},
85
+ hasCode: Boolean(kept),
86
+ addedAt: existing?.value.addedAt ?? (/* @__PURE__ */ new Date()).toISOString()
87
+ };
88
+ await writeVaultRecord(stateDir, FOLDER, id, { ...card, number, ...kept ? { code: kept } : {} });
89
+ return { id, ...card };
90
+ }
91
+ async function removeCard(stateDir, which) {
92
+ const want = which.trim().toLowerCase();
93
+ const all = await listCards(stateDir);
94
+ const matches = all.filter((card2) => card2.id === which || card2.last4 === digits(which) || card2.label.toLowerCase() === want);
95
+ if (matches.length !== 1) return void 0;
96
+ const card = matches[0];
97
+ await removeVaultRecord(stateDir, FOLDER, card.id);
98
+ return card;
99
+ }
100
+ async function readCardSecret(stateDir, card, kind) {
101
+ const record = (await readVaultRecords(stateDir, FOLDER)).find(({ id }) => id === card.id)?.value;
102
+ return kind === "number" ? record?.number : record?.code;
103
+ }
104
+ var plain = (text) => ` ${text.toLowerCase().replace(/[^a-z0-9]+/g, " ").trim()} `;
105
+ function cardFieldFor(hint, onCardForm = false) {
106
+ const tokens = hint.autocomplete.toLowerCase().split(/\s+/);
107
+ if (tokens.includes("cc-number")) return "number";
108
+ if (tokens.includes("cc-exp")) return "exp";
109
+ if (tokens.includes("cc-exp-month")) return "exp-month";
110
+ if (tokens.includes("cc-exp-year")) return "exp-year";
111
+ if (tokens.includes("cc-csc")) return "code";
112
+ if (tokens.includes("cc-name")) return "name";
113
+ const text = plain(`${hint.label ?? ""} ${hint.text}`);
114
+ if (/ (gift|loyalty|membership|library|id|identity|business|sim|green) card | card (type|brand|nickname|label) | postal | zip | post code | coupon | promo /.test(text)) return void 0;
115
+ if (tokens.includes("one-time-code")) return void 0;
116
+ if (/ (cvc|cvv|cvn|csc|cvc2|cvv2) | card code | card security code | card verification /.test(text)) return "code";
117
+ if (onCardForm && / security code | verification (code|value) | cid /.test(text)) return "code";
118
+ if (/ (card ?number|cardnumber|cc ?num(ber)?|ccnumber|credit card|debit card|numero de tarjeta|kartennummer|numero de carte) /.test(text) && !/ name | holder /.test(text)) return "number";
119
+ if (/ (exp(iry|iration|ires)?|valid thru|valid until|vencimiento|ablauf) /.test(text) || / mm ?yy(yy)? /.test(text)) {
120
+ if (/ (exp\w* )?(month|mes|monat|mm) /.test(text) && !/ yy| year /.test(text)) return "exp-month";
121
+ if (/ (year|ano|jahr|yy|yyyy) /.test(text) && !/ (month|mm) /.test(text)) return "exp-year";
122
+ return "exp";
123
+ }
124
+ if (/ (name on card|cardholder( name)?|card holder( name)?|ccname|cc name|nombre en la tarjeta|karteninhaber) /.test(text)) return "name";
125
+ return void 0;
126
+ }
127
+ function cardValueFor(kind, card, secrets, box = {}) {
128
+ const hint = (box.placeholder ?? "").toLowerCase();
129
+ const yy = card.expYear.slice(2);
130
+ switch (kind) {
131
+ case "number":
132
+ return secrets.number;
133
+ case "code":
134
+ return secrets.code;
135
+ case "name":
136
+ return card.name;
137
+ case "exp-month":
138
+ return box.maxlength === 1 ? String(Number(card.expMonth)) : card.expMonth;
139
+ case "exp-year":
140
+ return box.maxlength === 2 || /^\s*yy\s*$/.test(hint) ? yy : card.expYear;
141
+ case "exp": {
142
+ const year = /yyyy/.test(hint) || box.maxlength === 7 && !/\s/.test(hint) && /\//.test(hint) ? card.expYear : yy;
143
+ const sep = /mm\s*\/\s*yy/.test(hint) ? hint.match(/mm(\s*\/\s*)yy/)[1] : /mm\s*-\s*yy/.test(hint) ? "-" : /mmyy/.test(hint) || box.maxlength === 4 ? "" : "/";
144
+ return `${card.expMonth}${sep}${year}`;
145
+ }
146
+ }
147
+ }
148
+ var CARD_APPROVAL_MS = 5 * 6e4;
149
+
150
+ export {
151
+ luhnValid,
152
+ cardBrand,
153
+ parseExpiry,
154
+ cardExpired,
155
+ describeCard,
156
+ describeSavedCard,
157
+ listCards,
158
+ saveCard,
159
+ removeCard,
160
+ readCardSecret,
161
+ cardFieldFor,
162
+ cardValueFor,
163
+ CARD_APPROVAL_MS
164
+ };