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.
- package/README.md +25 -14
- package/dist/chunk-23TDEBGZ.js +71 -0
- package/dist/chunk-25T3GVS7.js +425 -0
- package/dist/chunk-2BBELGHY.js +11 -0
- package/dist/chunk-2EOL5PZL.js +208 -0
- package/dist/chunk-2GAB36IE.js +26 -0
- package/dist/chunk-2OLS7V66.js +2440 -0
- package/dist/chunk-2QFO2URB.js +179 -0
- package/dist/chunk-2QWPQRSU.js +254 -0
- package/dist/chunk-2YPAPAR3.js +184 -0
- package/dist/chunk-2ZAG5372.js +33 -0
- package/dist/chunk-32IKAIZC.js +12507 -0
- package/dist/chunk-34AZEGYW.js +95 -0
- package/dist/chunk-34JQYQCA.js +175 -0
- package/dist/chunk-34ZISPAO.js +67 -0
- package/dist/chunk-3AAAARE6.js +46 -0
- package/dist/chunk-3AJ6Q3OY.js +510 -0
- package/dist/chunk-3B2CHX7M.js +884 -0
- package/dist/chunk-3BUFORRX.js +59 -0
- package/dist/chunk-3QLHYYFK.js +30 -0
- package/dist/chunk-3RXBMYKZ.js +140 -0
- package/dist/chunk-3TFNIJWS.js +52 -0
- package/dist/chunk-3W3IPDFP.js +119 -0
- package/dist/chunk-3WMS7SEE.js +417 -0
- package/dist/chunk-435ZNSZ3.js +23 -0
- package/dist/chunk-4AQ5NINV.js +39 -0
- package/dist/chunk-4GVEJ5FK.js +168 -0
- package/dist/chunk-4GXAO3UY.js +262 -0
- package/dist/chunk-4L2ZZM4Q.js +332 -0
- package/dist/chunk-4LPDG57B.js +17 -0
- package/dist/chunk-4NN3XQQT.js +223 -0
- package/dist/chunk-4QZEZME7.js +54 -0
- package/dist/chunk-4R6CSC3S.js +38 -0
- package/dist/chunk-4RHXTL3W.js +514 -0
- package/dist/chunk-4SJMPTVQ.js +18 -0
- package/dist/chunk-4VY7G6TX.js +114 -0
- package/dist/chunk-5642PBF7.js +124 -0
- package/dist/chunk-5B6TVO4A.js +33 -0
- package/dist/chunk-5BJLDUPL.js +62 -0
- package/dist/chunk-5HMFFJWU.js +19 -0
- package/dist/chunk-5IKLK33T.js +69 -0
- package/dist/chunk-5NQ5FFMX.js +44 -0
- package/dist/chunk-5QNNW5L6.js +176 -0
- package/dist/chunk-5SM5UAWN.js +239 -0
- package/dist/chunk-5WYJTA6O.js +74 -0
- package/dist/chunk-5ZSR2Y5T.js +227 -0
- package/dist/chunk-5ZWUM5GH.js +39 -0
- package/dist/chunk-64E7D4HY.js +364 -0
- package/dist/chunk-6CK466BC.js +99 -0
- package/dist/chunk-6ES45HHO.js +138 -0
- package/dist/chunk-6HYEZFGL.js +277 -0
- package/dist/chunk-6Y7HLXGW.js +29 -0
- package/dist/chunk-6YKK4FYR.js +258 -0
- package/dist/chunk-74WNMLMS.js +117 -0
- package/dist/chunk-7AULZ7OD.js +55 -0
- package/dist/chunk-7DOKGSUN.js +101 -0
- package/dist/chunk-7IH5LTIZ.js +195 -0
- package/dist/chunk-7ISTS5NS.js +21 -0
- package/dist/chunk-7NMUTGOW.js +527 -0
- package/dist/chunk-7PNHUZEL.js +153 -0
- package/dist/chunk-7TSQLONI.js +88 -0
- package/dist/chunk-AE7TOLD5.js +30 -0
- package/dist/chunk-AEMHSXKA.js +130 -0
- package/dist/chunk-AKRYTS2D.js +211 -0
- package/dist/chunk-AMNSE36L.js +59 -0
- package/dist/chunk-AZVD74ZV.js +23 -0
- package/dist/chunk-B35DVOTK.js +1981 -0
- package/dist/chunk-B4HNJRAH.js +626 -0
- package/dist/chunk-B5WYPPHS.js +13 -0
- package/dist/chunk-BBOVDXQM.js +59 -0
- package/dist/chunk-BD3ECZLK.js +62 -0
- package/dist/chunk-BDGSOT74.js +4578 -0
- package/dist/chunk-BF5VEOPK.js +31 -0
- package/dist/chunk-BFFRW4XH.js +47 -0
- package/dist/chunk-BFPC6PEW.js +208 -0
- package/dist/chunk-BGEMY2JJ.js +376 -0
- package/dist/chunk-BISGNHKD.js +35 -0
- package/dist/chunk-BMRAEBRY.js +21 -0
- package/dist/chunk-BNTXAZXW.js +127 -0
- package/dist/chunk-BOQBXGSN.js +75 -0
- package/dist/chunk-BTJDSTQP.js +213 -0
- package/dist/chunk-BUOPJQP5.js +218 -0
- package/dist/chunk-BXFJS65Q.js +52 -0
- package/dist/chunk-BXPQFSX5.js +59 -0
- package/dist/chunk-C57LIWNY.js +1269 -0
- package/dist/chunk-C6YVCCWR.js +74 -0
- package/dist/chunk-CAADDF6M.js +167 -0
- package/dist/chunk-CBANJFBO.js +69 -0
- package/dist/chunk-CERF3RIB.js +597 -0
- package/dist/chunk-COAS5ETR.js +46 -0
- package/dist/chunk-CQ7J6UQ7.js +78 -0
- package/dist/chunk-CRUVYGO2.js +26 -0
- package/dist/chunk-CVFVFRGN.js +58 -0
- package/dist/chunk-D2UK66HM.js +37 -0
- package/dist/chunk-D2W7SA4R.js +18 -0
- package/dist/chunk-DA44ZENT.js +501 -0
- package/dist/chunk-DAJ76TOC.js +99 -0
- package/dist/chunk-DCZ6CIUM.js +147 -0
- package/dist/chunk-DF35KMXM.js +1314 -0
- package/dist/chunk-DGASQT26.js +151 -0
- package/dist/chunk-DJT57C5P.js +55 -0
- package/dist/chunk-DKDPZTD3.js +44 -0
- package/dist/chunk-DQYVQ2N7.js +77 -0
- package/dist/chunk-DRTP2RTY.js +266 -0
- package/dist/chunk-DW2BMUKY.js +61 -0
- package/dist/chunk-DW5T5ZVU.js +307 -0
- package/dist/chunk-DXKNDNFC.js +164 -0
- package/dist/chunk-DZEQ7UYR.js +291 -0
- package/dist/chunk-E4F4OUAC.js +463 -0
- package/dist/chunk-EE4B6A7W.js +69 -0
- package/dist/chunk-EISKIYWG.js +23 -0
- package/dist/chunk-EKAQK7UQ.js +235 -0
- package/dist/chunk-EOBTJV32.js +123 -0
- package/dist/chunk-ESF3DIZY.js +325 -0
- package/dist/chunk-EVOHOZ4U.js +45 -0
- package/dist/chunk-EXN4KHLB.js +110 -0
- package/dist/chunk-F252T6Y3.js +78 -0
- package/dist/chunk-F3DP4ZA2.js +40 -0
- package/dist/chunk-F6F47QAY.js +58 -0
- package/dist/chunk-FA3Y23ZW.js +57 -0
- package/dist/chunk-FBKXE4EJ.js +640 -0
- package/dist/chunk-FCGEB3H6.js +23 -0
- package/dist/chunk-FF7ZVYJF.js +3732 -0
- package/dist/chunk-FFGKN6L3.js +39 -0
- package/dist/chunk-FFGU4GCC.js +94 -0
- package/dist/chunk-FSFDAOVP.js +74 -0
- package/dist/chunk-FT5TX7OX.js +1573 -0
- package/dist/chunk-G3QP67Z7.js +232 -0
- package/dist/chunk-G5ORJKV2.js +179 -0
- package/dist/chunk-GFNC62PE.js +111 -0
- package/dist/chunk-GGK43Q3N.js +67 -0
- package/dist/chunk-GGYKY4GF.js +11537 -0
- package/dist/chunk-GGYNHGNJ.js +55 -0
- package/dist/chunk-GLY7RM3C.js +354 -0
- package/dist/chunk-GQBZU6EO.js +20 -0
- package/dist/chunk-GSXENUZL.js +9 -0
- package/dist/chunk-GTOAT5D3.js +40 -0
- package/dist/chunk-GWCMDPQU.js +1007 -0
- package/dist/chunk-GXYSMYHJ.js +152 -0
- package/dist/chunk-GYMAI5NY.js +14 -0
- package/dist/chunk-H2VZMKPE.js +30 -0
- package/dist/chunk-H4THUNBM.js +2091 -0
- package/dist/chunk-HGRVSNUZ.js +361 -0
- package/dist/chunk-HI4VY473.js +27 -0
- package/dist/chunk-HOJRSD3Q.js +447 -0
- package/dist/chunk-HRX25W35.js +82 -0
- package/dist/chunk-HSE4AQYV.js +55 -0
- package/dist/chunk-HU5SSUFX.js +383 -0
- package/dist/chunk-I3GDBJLH.js +196 -0
- package/dist/chunk-I75EDU75.js +684 -0
- package/dist/chunk-IBA7DMIO.js +20 -0
- package/dist/chunk-IC6N4NZA.js +231 -0
- package/dist/chunk-IF43HIGV.js +284 -0
- package/dist/chunk-IGZ6C2MC.js +439 -0
- package/dist/chunk-IMLTL2MY.js +192 -0
- package/dist/chunk-IMZL6SGR.js +33 -0
- package/dist/chunk-IS4USJPY.js +516 -0
- package/dist/chunk-ISFSPN2F.js +82 -0
- package/dist/chunk-IXE7GTFI.js +55 -0
- package/dist/chunk-IZ77QJQG.js +36 -0
- package/dist/chunk-J2PACWRQ.js +34 -0
- package/dist/chunk-J6EGFVQX.js +180 -0
- package/dist/chunk-JEKOD43D.js +22 -0
- package/dist/chunk-JGIWATSG.js +30 -0
- package/dist/chunk-JYBONKD4.js +43 -0
- package/dist/chunk-K2NLG2HK.js +454 -0
- package/dist/chunk-KCQ4TBLS.js +164 -0
- package/dist/chunk-KD5KIVMS.js +176 -0
- package/dist/chunk-KHW6TX6I.js +63 -0
- package/dist/chunk-KI5GZFCE.js +520 -0
- package/dist/chunk-KN34B7NO.js +105 -0
- package/dist/chunk-KYUHIFP3.js +136 -0
- package/dist/chunk-KZL5VS4B.js +300 -0
- package/dist/chunk-L3VW3QIH.js +48 -0
- package/dist/chunk-LA6MG4ET.js +2110 -0
- package/dist/chunk-LAVFOA3S.js +66 -0
- package/dist/chunk-LB4OA77N.js +13 -0
- package/dist/chunk-LBFRF2K4.js +196 -0
- package/dist/chunk-LM6EIA4B.js +93 -0
- package/dist/chunk-LPCNRGJ7.js +692 -0
- package/dist/chunk-LSLNL5T3.js +168 -0
- package/dist/chunk-LVRRWP4W.js +568 -0
- package/dist/chunk-LWCFBRHL.js +33 -0
- package/dist/chunk-LXFTMGZZ.js +166 -0
- package/dist/chunk-M33LVA4M.js +151 -0
- package/dist/chunk-M3FO5UMK.js +4944 -0
- package/dist/chunk-M5QNDBAY.js +66 -0
- package/dist/chunk-M6ND6KBE.js +1291 -0
- package/dist/chunk-M7H3WQTE.js +76 -0
- package/dist/chunk-MCBRVPA7.js +191 -0
- package/dist/chunk-MCSDWZET.js +91 -0
- package/dist/chunk-MDT5XDXL.js +289 -0
- package/dist/chunk-MJG3IQY4.js +91 -0
- package/dist/chunk-MOU3N2UL.js +44 -0
- package/dist/chunk-MP4KZOQC.js +3451 -0
- package/dist/chunk-MPAJ446F.js +66 -0
- package/dist/chunk-MVJZZ6AL.js +16 -0
- package/dist/chunk-MXS6S2PY.js +253 -0
- package/dist/chunk-N3SFDYM7.js +291 -0
- package/dist/chunk-NAOX3JUB.js +13 -0
- package/dist/chunk-NEKKIBCX.js +283 -0
- package/dist/chunk-NKDATMEM.js +133 -0
- package/dist/chunk-NR4FMC4K.js +395 -0
- package/dist/chunk-NSOHOJBR.js +221 -0
- package/dist/chunk-NTDB6QKF.js +29 -0
- package/dist/chunk-NWEYRBWK.js +25 -0
- package/dist/chunk-O2YSNYWD.js +23 -0
- package/dist/chunk-O3EW7LAY.js +54 -0
- package/dist/chunk-O7BNJIXU.js +366 -0
- package/dist/chunk-OARL2NXZ.js +116 -0
- package/dist/chunk-OHKZUEJW.js +351 -0
- package/dist/chunk-OKU45BXA.js +647 -0
- package/dist/chunk-OL4JBD3J.js +59 -0
- package/dist/chunk-OLUO5DDR.js +192 -0
- package/dist/chunk-OQ245JLA.js +196 -0
- package/dist/chunk-P72UZAQI.js +289 -0
- package/dist/chunk-PAL2ENB6.js +20 -0
- package/dist/chunk-PAXYQZH7.js +53 -0
- package/dist/chunk-PDPEM5VW.js +51 -0
- package/dist/chunk-PEWCDI2C.js +668 -0
- package/dist/chunk-PGZ54EDX.js +27 -0
- package/dist/chunk-PRWVLDZF.js +73 -0
- package/dist/chunk-PSQQ75VJ.js +52 -0
- package/dist/chunk-PUOVIFHW.js +118 -0
- package/dist/chunk-PWBF2X3V.js +107 -0
- package/dist/chunk-PWXII6HF.js +43 -0
- package/dist/chunk-Q35VLJRT.js +80 -0
- package/dist/chunk-QJP7EYGL.js +128 -0
- package/dist/chunk-QPQKX2MK.js +8836 -0
- package/dist/chunk-QQRLPY25.js +1053 -0
- package/dist/chunk-QUS4ER2W.js +407 -0
- package/dist/chunk-QYHI3YET.js +29 -0
- package/dist/chunk-QYRU2UQI.js +32 -0
- package/dist/chunk-R6XVVQGC.js +13 -0
- package/dist/chunk-R7QN6ONS.js +483 -0
- package/dist/chunk-RD23MPGC.js +221 -0
- package/dist/chunk-RDDWQBEM.js +185 -0
- package/dist/chunk-RDLLDYFO.js +104 -0
- package/dist/chunk-RE4TGORR.js +84 -0
- package/dist/chunk-RJLHVYQY.js +217 -0
- package/dist/chunk-RJLPTWHW.js +905 -0
- package/dist/chunk-RKUVLRZI.js +295 -0
- package/dist/chunk-ROGXPGYR.js +37 -0
- package/dist/chunk-RSZGEL5U.js +163 -0
- package/dist/chunk-RVUOIJXN.js +909 -0
- package/dist/chunk-RW7F4JRP.js +11 -0
- package/dist/chunk-S4UO3AO3.js +53 -0
- package/dist/chunk-S5JAAF6S.js +585 -0
- package/dist/chunk-SNU37TQI.js +56 -0
- package/dist/chunk-SQVUDO2O.js +31 -0
- package/dist/chunk-SYVHIYQT.js +66 -0
- package/dist/chunk-SZBQMTG2.js +85 -0
- package/dist/chunk-T5VCXA3J.js +25 -0
- package/dist/chunk-TK6NSP56.js +30 -0
- package/dist/chunk-TKWVMA6L.js +22 -0
- package/dist/chunk-TQDKJHWX.js +59 -0
- package/dist/chunk-TQDM7S5N.js +127 -0
- package/dist/chunk-TULAXS77.js +23 -0
- package/dist/chunk-TVT45XNH.js +4625 -0
- package/dist/chunk-TWCVV2JO.js +467 -0
- package/dist/chunk-U4DKAD6S.js +47 -0
- package/dist/chunk-UA5K2BTI.js +564 -0
- package/dist/chunk-UAMKCMOK.js +40 -0
- package/dist/chunk-UBMVADBF.js +51 -0
- package/dist/chunk-UFQ5A5PW.js +645 -0
- package/dist/chunk-UOD2SOLL.js +1301 -0
- package/dist/chunk-UTSB4LOW.js +156 -0
- package/dist/chunk-UVXNIUTN.js +412 -0
- package/dist/chunk-UXVPXYPE.js +90 -0
- package/dist/chunk-UYEEMIWR.js +374 -0
- package/dist/chunk-VBGM5ZBW.js +54 -0
- package/dist/chunk-VEWPCZPG.js +762 -0
- package/dist/chunk-VIRDLZ5E.js +108 -0
- package/dist/chunk-VMPO7WKN.js +52 -0
- package/dist/chunk-W2NVSDO5.js +5122 -0
- package/dist/chunk-W3YYPBEA.js +176 -0
- package/dist/chunk-W5AYOICN.js +280 -0
- package/dist/chunk-W5GZOIUF.js +27 -0
- package/dist/chunk-WHKNLZ3C.js +76 -0
- package/dist/chunk-WKBEPPQ5.js +1409 -0
- package/dist/chunk-WM3Z6QKQ.js +151 -0
- package/dist/chunk-WMI2TPMA.js +31 -0
- package/dist/chunk-WNX5VD7S.js +150 -0
- package/dist/chunk-WOVTYST3.js +60 -0
- package/dist/chunk-WPB5WEZJ.js +546 -0
- package/dist/chunk-WUO5EOAT.js +44 -0
- package/dist/chunk-WWLJMP6D.js +133 -0
- package/dist/chunk-WZMLH3XP.js +58 -0
- package/dist/chunk-WZYVLUVQ.js +79 -0
- package/dist/chunk-X2OCPVU5.js +135 -0
- package/dist/chunk-X3CL6DTR.js +95 -0
- package/dist/chunk-X6WF7JEV.js +354 -0
- package/dist/chunk-XAHGBPWT.js +44 -0
- package/dist/chunk-XCKQ5BM2.js +228 -0
- package/dist/chunk-XIBYREEY.js +106 -0
- package/dist/chunk-XKW5NDMR.js +378 -0
- package/dist/chunk-XRDALAO3.js +100 -0
- package/dist/chunk-XUP22EAS.js +41 -0
- package/dist/chunk-XWAC3MKW.js +243 -0
- package/dist/chunk-Y3R7JMXB.js +59 -0
- package/dist/chunk-Y54LTP4W.js +82 -0
- package/dist/chunk-Y7UECI4M.js +99 -0
- package/dist/chunk-YACGDFHC.js +47 -0
- package/dist/chunk-YHNIQPKY.js +71 -0
- package/dist/chunk-YMBR6HYP.js +111 -0
- package/dist/chunk-YMCH3L2S.js +26 -0
- package/dist/chunk-Z4ZU6T7V.js +99 -0
- package/dist/chunk-ZDPF67ZZ.js +173 -0
- package/dist/chunk-ZFC2Q67K.js +101 -0
- package/dist/chunk-ZGHNNSCT.js +114 -0
- package/dist/chunk-ZGX3ERAT.js +173 -0
- package/dist/chunk-ZI3YHEBY.js +37 -0
- package/dist/chunk-ZN7G6JLS.js +639 -0
- package/dist/chunk-ZNPFQMXT.js +47 -0
- package/dist/chunk-ZOU3LV4U.js +63 -0
- package/dist/chunk-ZT7B4H2V.js +117 -0
- package/dist/chunk-ZZCBDNZI.js +58 -0
- package/dist/cli.js +498 -112593
- package/dist/computer-tools.js +36642 -21258
- package/dist/harness-catalog.cjs +88 -43
- package/dist/index.js +1 -1
- package/dist/local-model-supervisor.cjs +555 -0
- package/package.json +3 -4
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
SECRET_SHAPES
|
|
5
|
+
} from "./chunk-RDDWQBEM.js";
|
|
6
|
+
|
|
7
|
+
// src/search/secrets.ts
|
|
8
|
+
var MASK = "[secret]";
|
|
9
|
+
var AUTH_SCHEME = /\b(Bearer|Basic|Token)(\s+)[A-Za-z0-9._~+/=-]{8,}/g;
|
|
10
|
+
var ASSIGNED = /((?:api[_-]?key|access[_-]?key|secret|token|password|passwd|pwd|auth|credential|private[_-]?key|[\w-]*-key)["']?\s*(?:[:=]|\s)\s*["']?)([^\s"'`,;)]{8,})/gi;
|
|
11
|
+
var NOT_A_VALUE = /^(?:is|are|was|the|and|for|with|from|that|this|should|would|could|will|must|into|when|which|where|here|there|true|false|null|undefined|required|optional|string|number|boolean|object|missing|invalid|expired|present|provided|example|placeholder|refresh|header|value|field|file|path|name|type|env|environment|variable|\[secret\])$/i;
|
|
12
|
+
function maskSecrets(text) {
|
|
13
|
+
if (!text) return text;
|
|
14
|
+
let out = text;
|
|
15
|
+
for (const pattern of SECRET_SHAPES) out = out.replace(pattern, MASK);
|
|
16
|
+
out = out.replace(AUTH_SCHEME, (_match, scheme, gap) => `${scheme}${gap}${MASK}`);
|
|
17
|
+
out = out.replace(ASSIGNED, (match, name, value) => {
|
|
18
|
+
if (NOT_A_VALUE.test(value) || value.includes("(") || !/\d/.test(value) || value.includes(MASK)) return match;
|
|
19
|
+
return `${name}${MASK}`;
|
|
20
|
+
});
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// src/search/format.ts
|
|
25
|
+
var SNIPPET_LINE_CHARS = 160;
|
|
26
|
+
function shortId(id) {
|
|
27
|
+
return id.slice(0, 8);
|
|
28
|
+
}
|
|
29
|
+
function anchorOf(conversationId, position) {
|
|
30
|
+
return `${shortId(conversationId)}:${position}`;
|
|
31
|
+
}
|
|
32
|
+
function parseAnchor(value) {
|
|
33
|
+
if (typeof value === "number" && Number.isInteger(value) && value >= 0) return { messageIndex: value };
|
|
34
|
+
if (typeof value !== "string") return void 0;
|
|
35
|
+
const match = /^@?(?:([A-Za-z0-9._-]{6,}):)?#?(\d+)$/.exec(value.trim());
|
|
36
|
+
if (!match) return void 0;
|
|
37
|
+
return { ...match[1] ? { session: match[1] } : {}, messageIndex: Number(match[2]) };
|
|
38
|
+
}
|
|
39
|
+
function ago(atMs, now = Date.now()) {
|
|
40
|
+
if (!Number.isFinite(atMs)) return "unknown";
|
|
41
|
+
const seconds = Math.max(0, Math.round((now - atMs) / 1e3));
|
|
42
|
+
if (seconds < 90) return "just now";
|
|
43
|
+
const minutes = Math.round(seconds / 60);
|
|
44
|
+
if (minutes < 90) return `${minutes}m ago`;
|
|
45
|
+
const hours = Math.round(minutes / 60);
|
|
46
|
+
if (hours < 36) return `${hours}h ago`;
|
|
47
|
+
const days = Math.round(hours / 24);
|
|
48
|
+
return days < 60 ? `${days}d ago` : new Date(atMs).toISOString().slice(0, 10);
|
|
49
|
+
}
|
|
50
|
+
function runsOn(item) {
|
|
51
|
+
return [item.harness ?? item.provider ?? "no provider", item.model].filter(Boolean).join(" \xB7 ");
|
|
52
|
+
}
|
|
53
|
+
function clipAround(line, at, width = SNIPPET_LINE_CHARS) {
|
|
54
|
+
if (line.length <= width) return line;
|
|
55
|
+
const start = Math.max(0, Math.min(line.length - width, at - Math.floor(width / 3)));
|
|
56
|
+
return `${start > 0 ? "\u2026" : ""}${line.slice(start, start + width)}${start + width < line.length ? "\u2026" : ""}`;
|
|
57
|
+
}
|
|
58
|
+
function snippet(message, mention, context = 1) {
|
|
59
|
+
const text = message.text;
|
|
60
|
+
const lines = text.split("\n");
|
|
61
|
+
let at = mention.offset;
|
|
62
|
+
let lineIndex = 0;
|
|
63
|
+
for (; lineIndex < lines.length - 1 && at > lines[lineIndex].length; lineIndex += 1) at -= lines[lineIndex].length + 1;
|
|
64
|
+
const picked = [];
|
|
65
|
+
for (let index = Math.max(0, lineIndex - context); index <= Math.min(lines.length - 1, lineIndex + context); index += 1) {
|
|
66
|
+
const line = lines[index].trim();
|
|
67
|
+
if (!line && index !== lineIndex) continue;
|
|
68
|
+
picked.push(index === lineIndex ? clipAround(lines[index].trimEnd(), at) : clipAround(line, 0));
|
|
69
|
+
}
|
|
70
|
+
const where = mention.offset >= message.contentLength ? `${message.role} (tool call)` : message.role;
|
|
71
|
+
return `${where}: ${maskSecrets(picked.join(" \u23CE ").replace(/\s+/g, " ").trim())}`;
|
|
72
|
+
}
|
|
73
|
+
function hitSnippets(hit, view, count = 3) {
|
|
74
|
+
const out = [];
|
|
75
|
+
let last = -1;
|
|
76
|
+
for (const mention of hit.mentions) {
|
|
77
|
+
if (out.length >= count) break;
|
|
78
|
+
if (mention.position === last) continue;
|
|
79
|
+
last = mention.position;
|
|
80
|
+
const message = view.entries[mention.position]?.message;
|
|
81
|
+
if (message) out.push(`@${anchorOf(hit.conversationId, mention.position)} ${snippet(message, mention)}`);
|
|
82
|
+
}
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
function mentionCount(hit, words) {
|
|
86
|
+
const count = hit.mentions.length;
|
|
87
|
+
if (hit.exactCount) return `${count} mention${count === 1 ? "" : "s"}${words > 1 ? " of the phrase" : ""}`;
|
|
88
|
+
if (!count) return "no mentions in its messages";
|
|
89
|
+
return `${count} message${count === 1 ? "" : "s"} with all the words (not the phrase)`;
|
|
90
|
+
}
|
|
91
|
+
function renderMessage(index, message, budget, focus) {
|
|
92
|
+
const head = `[#${index} ${message.role}]`;
|
|
93
|
+
const content = message.text.slice(0, message.contentLength).trim();
|
|
94
|
+
const calls = message.text.slice(message.contentLength).split("\n").filter(Boolean);
|
|
95
|
+
const compactCalls = [];
|
|
96
|
+
let outputKept = 0;
|
|
97
|
+
let dropped = false;
|
|
98
|
+
for (const line of calls) {
|
|
99
|
+
if (line.startsWith(" \u23FA")) {
|
|
100
|
+
compactCalls.push(line);
|
|
101
|
+
outputKept = 0;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (outputKept < 2) {
|
|
105
|
+
compactCalls.push(line);
|
|
106
|
+
outputKept += 1;
|
|
107
|
+
} else {
|
|
108
|
+
dropped = true;
|
|
109
|
+
if (outputKept === 2) {
|
|
110
|
+
compactCalls.push(" \u2026");
|
|
111
|
+
outputKept += 1;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
let body = content;
|
|
116
|
+
let callText = compactCalls.join("\n");
|
|
117
|
+
let shortened = dropped;
|
|
118
|
+
const room = Math.max(200, budget - head.length - 2);
|
|
119
|
+
if (body.length + callText.length + 1 > room) {
|
|
120
|
+
shortened = true;
|
|
121
|
+
const callRoom = Math.min(callText.length, Math.floor(room * 0.3));
|
|
122
|
+
if (callText.length > callRoom) {
|
|
123
|
+
const kept = callText.slice(0, callRoom);
|
|
124
|
+
callText = `${kept.slice(0, kept.lastIndexOf("\n") > 0 ? kept.lastIndexOf("\n") : kept.length)}
|
|
125
|
+
\u2026 ${calls.filter((line) => line.startsWith(" \u23FA")).length} tool calls in all`;
|
|
126
|
+
}
|
|
127
|
+
const bodyRoom = Math.max(100, room - callText.length - 1);
|
|
128
|
+
if (body.length > bodyRoom) {
|
|
129
|
+
if (focus !== void 0 && focus < message.contentLength) {
|
|
130
|
+
const start = Math.max(0, Math.min(body.length - bodyRoom, focus - Math.floor(bodyRoom / 3)));
|
|
131
|
+
body = `${start > 0 ? `[\u2026 ${start} chars] ` : ""}${body.slice(start, start + bodyRoom)}${start + bodyRoom < body.length ? ` [\u2026 ${body.length - start - bodyRoom} chars]` : ""}`;
|
|
132
|
+
} else {
|
|
133
|
+
const half = Math.floor(bodyRoom / 2);
|
|
134
|
+
body = `${body.slice(0, half)} [\u2026 ${body.length - bodyRoom} chars] ${body.slice(body.length - half)}`;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return { text: maskSecrets([`${head} ${body}`.trimEnd(), ...callText ? [callText] : []].join("\n")), shortened };
|
|
139
|
+
}
|
|
140
|
+
function renderFullMessage(index, message, budget) {
|
|
141
|
+
const text = `[#${index} ${message.role}] ${message.text.trim()}`;
|
|
142
|
+
if (text.length <= budget) return maskSecrets(text);
|
|
143
|
+
return maskSecrets(`${text.slice(0, budget)} [\u2026 ${text.length - budget} more chars; raise maxChars]`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export {
|
|
147
|
+
maskSecrets,
|
|
148
|
+
shortId,
|
|
149
|
+
parseAnchor,
|
|
150
|
+
ago,
|
|
151
|
+
runsOn,
|
|
152
|
+
hitSnippets,
|
|
153
|
+
mentionCount,
|
|
154
|
+
renderMessage,
|
|
155
|
+
renderFullMessage
|
|
156
|
+
};
|
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
mcpToolDefinition,
|
|
5
|
+
mcpToolName
|
|
6
|
+
} from "./chunk-RDLLDYFO.js";
|
|
7
|
+
import {
|
|
8
|
+
McpClient
|
|
9
|
+
} from "./chunk-74WNMLMS.js";
|
|
10
|
+
import {
|
|
11
|
+
IMAGE_MIME,
|
|
12
|
+
MAX_IMAGE_SIDE,
|
|
13
|
+
MAX_TOOL_IMAGE_BYTES,
|
|
14
|
+
sniffImage
|
|
15
|
+
} from "./chunk-LAVFOA3S.js";
|
|
16
|
+
import {
|
|
17
|
+
enabledPluginMcpServers
|
|
18
|
+
} from "./chunk-K2NLG2HK.js";
|
|
19
|
+
import {
|
|
20
|
+
carriesCredentials,
|
|
21
|
+
isMcpSignInRequired,
|
|
22
|
+
mcpOAuthProvider,
|
|
23
|
+
mcpSignInNote
|
|
24
|
+
} from "./chunk-UA5K2BTI.js";
|
|
25
|
+
import {
|
|
26
|
+
defineTool
|
|
27
|
+
} from "./chunk-2BBELGHY.js";
|
|
28
|
+
import {
|
|
29
|
+
importNotice,
|
|
30
|
+
importVendorMcpServers
|
|
31
|
+
} from "./chunk-R7QN6ONS.js";
|
|
32
|
+
import {
|
|
33
|
+
loadMcpServers
|
|
34
|
+
} from "./chunk-DQYVQ2N7.js";
|
|
35
|
+
import {
|
|
36
|
+
diagnostic,
|
|
37
|
+
lifecycle,
|
|
38
|
+
quiet
|
|
39
|
+
} from "./chunk-RDDWQBEM.js";
|
|
40
|
+
|
|
41
|
+
// src/agent/mcp/resources.ts
|
|
42
|
+
var LIST_MCP_RESOURCES = "list_mcp_resources";
|
|
43
|
+
var READ_MCP_RESOURCE = "read_mcp_resource";
|
|
44
|
+
var SEEABLE = new Set(Object.values(IMAGE_MIME));
|
|
45
|
+
function byteSize(base64) {
|
|
46
|
+
const bytes = Math.floor(base64.length * 3 / 4);
|
|
47
|
+
return bytes >= 1024 ? `${(bytes / 1024).toFixed(1)} KB` : `${bytes} B`;
|
|
48
|
+
}
|
|
49
|
+
function failure(error) {
|
|
50
|
+
return (error instanceof Error ? error.message : String(error)).split("\n")[0].slice(0, 300);
|
|
51
|
+
}
|
|
52
|
+
function resourceLine(resource) {
|
|
53
|
+
const about = [resource.title ?? resource.name, resource.mimeType].filter(Boolean).join(", ");
|
|
54
|
+
return `- ${resource.uri}${about ? ` (${about})` : ""}${resource.description?.trim() ? `: ${resource.description.trim().replace(/\s+/g, " ")}` : ""}`;
|
|
55
|
+
}
|
|
56
|
+
function mcpResourceTools(sources) {
|
|
57
|
+
if (!sources.length) return [];
|
|
58
|
+
const servers = sources.map((source) => source.server);
|
|
59
|
+
const byName = new Map(sources.map((source) => [source.server, source]));
|
|
60
|
+
const unknown = (server) => ({ output: `No MCP server "${server}" with resources. Servers: ${servers.join(", ")}.`, isError: true });
|
|
61
|
+
const list = defineTool({
|
|
62
|
+
name: LIST_MCP_RESOURCES,
|
|
63
|
+
class: "read",
|
|
64
|
+
description: `List the resources (files, records, documents) connected MCP servers publish, with each one's URI. Read one with ${READ_MCP_RESOURCE}. Servers with resources: ${servers.join(", ")}.`,
|
|
65
|
+
parameters: {
|
|
66
|
+
type: "object",
|
|
67
|
+
additionalProperties: false,
|
|
68
|
+
properties: { server: { type: "string", enum: servers, description: "Only this server's resources. Omit for every server." } }
|
|
69
|
+
},
|
|
70
|
+
label: (args) => `List MCP resources${args.server ? ` of ${args.server}` : ""}`,
|
|
71
|
+
async run(args, ctx) {
|
|
72
|
+
if (args.server !== void 0 && !byName.has(args.server)) return unknown(args.server);
|
|
73
|
+
const chosen = args.server !== void 0 ? [byName.get(args.server)] : sources;
|
|
74
|
+
const sections = await Promise.all(chosen.map(async (source) => {
|
|
75
|
+
try {
|
|
76
|
+
const resources = await source.list(ctx.signal);
|
|
77
|
+
return { ok: true, text: `${source.server}: ${resources.length ? `${resources.length} resource${resources.length === 1 ? "" : "s"}
|
|
78
|
+
${resources.map(resourceLine).join("\n")}` : "no resources"}` };
|
|
79
|
+
} catch (error) {
|
|
80
|
+
return { ok: false, text: `${source.server}: could not list resources: ${failure(error)}` };
|
|
81
|
+
}
|
|
82
|
+
}));
|
|
83
|
+
return { output: sections.map((section) => section.text).join("\n\n"), ...sections.every((section) => !section.ok) ? { isError: true } : {} };
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
const read = defineTool({
|
|
87
|
+
name: READ_MCP_RESOURCE,
|
|
88
|
+
class: "read",
|
|
89
|
+
description: `Read one MCP resource by its URI (from ${LIST_MCP_RESOURCES}, or one a tool result named). Text comes back as text; binary content is summarized.`,
|
|
90
|
+
parameters: {
|
|
91
|
+
type: "object",
|
|
92
|
+
additionalProperties: false,
|
|
93
|
+
required: ["server", "uri"],
|
|
94
|
+
properties: {
|
|
95
|
+
server: { type: "string", enum: servers, description: "The MCP server that publishes it." },
|
|
96
|
+
uri: { type: "string", description: "The resource URI." }
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
label: (args) => `Read MCP resource ${args.uri}`,
|
|
100
|
+
async run(args, ctx) {
|
|
101
|
+
const source = byName.get(args.server);
|
|
102
|
+
if (!source) return unknown(args.server);
|
|
103
|
+
let contents;
|
|
104
|
+
try {
|
|
105
|
+
contents = await source.read(args.uri, ctx.signal);
|
|
106
|
+
} catch (error) {
|
|
107
|
+
return { output: `Could not read ${args.uri} from MCP server "${args.server}": ${failure(error)}`, isError: true };
|
|
108
|
+
}
|
|
109
|
+
if (!contents.length) return { output: `${args.uri} has no content.` };
|
|
110
|
+
const images = [];
|
|
111
|
+
const parts = contents.map((item) => {
|
|
112
|
+
const uri = item.uri ?? args.uri;
|
|
113
|
+
const header = contents.length > 1 ? `[${uri}${item.mimeType ? ` (${item.mimeType})` : ""}]
|
|
114
|
+
` : "";
|
|
115
|
+
if (typeof item.text === "string") return `${header}${item.text}`;
|
|
116
|
+
if (typeof item.blob !== "string") return `${header}[${uri}: no content]`;
|
|
117
|
+
const summary = `[binary resource ${uri}${item.mimeType ? ` (${item.mimeType})` : ""}, ${byteSize(item.blob)}]`;
|
|
118
|
+
const image = seeableImage(item, ctx.acceptsImages === true);
|
|
119
|
+
if (!image) return summary;
|
|
120
|
+
images.push({ ...image, name: uri });
|
|
121
|
+
return `${summary} attached for you to see.`;
|
|
122
|
+
});
|
|
123
|
+
return { output: parts.join("\n\n"), ...images.length ? { images } : {} };
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
return [list, read];
|
|
127
|
+
}
|
|
128
|
+
function seeableImage(item, acceptsImages) {
|
|
129
|
+
if (!acceptsImages || !item.blob || item.mimeType && !SEEABLE.has(item.mimeType)) return void 0;
|
|
130
|
+
const bytes = Buffer.from(item.blob, "base64");
|
|
131
|
+
if (bytes.length > MAX_TOOL_IMAGE_BYTES) return void 0;
|
|
132
|
+
const sniffed = sniffImage(bytes);
|
|
133
|
+
if (!sniffed || Math.max(sniffed.width ?? 0, sniffed.height ?? 0) > MAX_IMAGE_SIDE) return void 0;
|
|
134
|
+
return { mimeType: sniffed.mimeType, data: item.blob };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// src/agent/mcp/manager.ts
|
|
138
|
+
var DEFAULT_TIMEOUTS = { connectMs: 3e4, callMs: 3e5, retryAfterMs: 6e4 };
|
|
139
|
+
function withinWait(ready, waitMs) {
|
|
140
|
+
if (waitMs === void 0) return ready;
|
|
141
|
+
let timer;
|
|
142
|
+
const waited = new Promise((resolve) => {
|
|
143
|
+
timer = setTimeout(resolve, waitMs);
|
|
144
|
+
});
|
|
145
|
+
return Promise.race([ready, waited]).finally(() => clearTimeout(timer));
|
|
146
|
+
}
|
|
147
|
+
function firstLine(error) {
|
|
148
|
+
const text = error instanceof Error ? error.message : String(error);
|
|
149
|
+
return text.split("\n").map((line) => line.trim()).filter(Boolean).slice(0, 3).join(" | ").slice(0, 300);
|
|
150
|
+
}
|
|
151
|
+
var McpManager = class {
|
|
152
|
+
constructor(loadServers, options = {}) {
|
|
153
|
+
this.loadServers = loadServers;
|
|
154
|
+
this.timeouts = { ...DEFAULT_TIMEOUTS, ...options.timeouts };
|
|
155
|
+
this.fetchImpl = options.fetchImpl;
|
|
156
|
+
this.now = options.now ?? Date.now;
|
|
157
|
+
this.authFor = options.authFor;
|
|
158
|
+
}
|
|
159
|
+
loadServers;
|
|
160
|
+
servers = /* @__PURE__ */ new Map();
|
|
161
|
+
timeouts;
|
|
162
|
+
exitHookInstalled = false;
|
|
163
|
+
killAll = () => {
|
|
164
|
+
for (const state of this.servers.values()) state.client?.killNow();
|
|
165
|
+
};
|
|
166
|
+
fetchImpl;
|
|
167
|
+
authFor;
|
|
168
|
+
now;
|
|
169
|
+
/** The tools every configured server offers right now. Servers connect in
|
|
170
|
+
* parallel, so the slowest one bounds the wait, not the sum of them. */
|
|
171
|
+
async toolset() {
|
|
172
|
+
const { servers, problem } = await this.loadServers();
|
|
173
|
+
if (problem) diagnostic("mcp.config", problem);
|
|
174
|
+
await this.reconcile(servers);
|
|
175
|
+
await Promise.all([...this.servers.values()].map((state) => withinWait(this.ensureReady(state), state.spec.turnWaitMs)));
|
|
176
|
+
const tools = [];
|
|
177
|
+
const resources = [];
|
|
178
|
+
const taken = /* @__PURE__ */ new Set();
|
|
179
|
+
const ordered = [...this.servers.values()].sort((a, b) => a.spec.name < b.spec.name ? -1 : a.spec.name > b.spec.name ? 1 : 0);
|
|
180
|
+
for (const state of ordered) {
|
|
181
|
+
if (!state.client || !state.tools) {
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
for (const info of state.tools) {
|
|
185
|
+
const name = mcpToolName(state.spec.name, info.name, taken);
|
|
186
|
+
taken.add(name);
|
|
187
|
+
tools.push(mcpToolDefinition(state.spec.name, info, name, (tool, args, signal) => this.call(state, tool, args, signal), state.spec.core?.includes(info.name) ?? false));
|
|
188
|
+
}
|
|
189
|
+
if (state.client.hasResources) {
|
|
190
|
+
const options = (signal) => ({ timeoutMs: this.timeouts.callMs, ...signal ? { signal } : {} });
|
|
191
|
+
resources.push({
|
|
192
|
+
server: state.spec.name,
|
|
193
|
+
list: async (signal) => (await this.clientFor(state)).listResources(options(signal)),
|
|
194
|
+
read: async (uri, signal) => (await this.clientFor(state)).readResource(uri, options(signal))
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return { tools: [...tools, ...mcpResourceTools(resources)] };
|
|
199
|
+
}
|
|
200
|
+
/** Stops every server. Safe to call more than once. */
|
|
201
|
+
async shutdown() {
|
|
202
|
+
const states = [...this.servers.values()];
|
|
203
|
+
for (const state of states) {
|
|
204
|
+
state.retired = true;
|
|
205
|
+
state.starting?.abort();
|
|
206
|
+
}
|
|
207
|
+
this.servers.clear();
|
|
208
|
+
process.off("exit", this.killAll);
|
|
209
|
+
this.exitHookInstalled = false;
|
|
210
|
+
await Promise.all(states.map((state) => this.stop(state)));
|
|
211
|
+
}
|
|
212
|
+
async reconcile(specs) {
|
|
213
|
+
const wanted = new Map(specs.map((spec) => [spec.name, spec]));
|
|
214
|
+
const stopping = [];
|
|
215
|
+
for (const [name, state] of this.servers) {
|
|
216
|
+
const spec = wanted.get(name);
|
|
217
|
+
if (spec && JSON.stringify(spec) === state.key) continue;
|
|
218
|
+
state.retired = true;
|
|
219
|
+
state.starting?.abort();
|
|
220
|
+
this.servers.delete(name);
|
|
221
|
+
stopping.push(this.stop(state));
|
|
222
|
+
}
|
|
223
|
+
for (const spec of specs) {
|
|
224
|
+
if (!this.servers.has(spec.name)) this.servers.set(spec.name, { spec, key: JSON.stringify(spec) });
|
|
225
|
+
}
|
|
226
|
+
await Promise.all(stopping);
|
|
227
|
+
}
|
|
228
|
+
async stop(state) {
|
|
229
|
+
const client = state.client;
|
|
230
|
+
const wasUp = Boolean(client);
|
|
231
|
+
state.client = void 0;
|
|
232
|
+
state.tools = void 0;
|
|
233
|
+
await client?.close().catch(quiet("agent/mcp/manager"));
|
|
234
|
+
if (wasUp) lifecycle("mcp.stop", { server: state.spec.name, reason: state.retired ? "removed" : "stopped" });
|
|
235
|
+
}
|
|
236
|
+
ensureReady(state) {
|
|
237
|
+
if (state.connecting) return state.connecting;
|
|
238
|
+
if (state.client?.closed) {
|
|
239
|
+
state.client = void 0;
|
|
240
|
+
state.tools = void 0;
|
|
241
|
+
state.failure = void 0;
|
|
242
|
+
}
|
|
243
|
+
if (state.client && state.tools && !state.stale) return Promise.resolve();
|
|
244
|
+
const signIn = !state.client ? state.failure?.signIn : void 0;
|
|
245
|
+
if (signIn) {
|
|
246
|
+
state.connecting = (async () => {
|
|
247
|
+
if (await this.auth(state)?.stamp() === signIn.stamp) return;
|
|
248
|
+
await this.connect(state);
|
|
249
|
+
})().finally(() => {
|
|
250
|
+
state.connecting = void 0;
|
|
251
|
+
});
|
|
252
|
+
return state.connecting;
|
|
253
|
+
}
|
|
254
|
+
if (!state.client && state.failure && this.now() - state.failure.at < this.timeouts.retryAfterMs) return Promise.resolve();
|
|
255
|
+
state.connecting = this.connect(state).finally(() => {
|
|
256
|
+
state.connecting = void 0;
|
|
257
|
+
});
|
|
258
|
+
return state.connecting;
|
|
259
|
+
}
|
|
260
|
+
async connect(state) {
|
|
261
|
+
const started = Date.now();
|
|
262
|
+
try {
|
|
263
|
+
if (!state.client) {
|
|
264
|
+
this.installExitHook();
|
|
265
|
+
state.starting = new AbortController();
|
|
266
|
+
const client = await McpClient.connect(state.spec, {
|
|
267
|
+
signal: state.starting.signal,
|
|
268
|
+
timeoutMs: this.timeouts.connectMs,
|
|
269
|
+
...this.fetchImpl ? { fetchImpl: this.fetchImpl } : {},
|
|
270
|
+
...this.auth(state) ? { auth: this.auth(state) } : {},
|
|
271
|
+
onNotification: (method) => {
|
|
272
|
+
if (method === "notifications/tools/list_changed") state.stale = true;
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
state.starting = void 0;
|
|
276
|
+
if (state.retired) {
|
|
277
|
+
await client.close().catch(quiet("agent/mcp/manager"));
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
state.client = client;
|
|
281
|
+
}
|
|
282
|
+
state.stale = false;
|
|
283
|
+
state.tools = await state.client.listTools(this.timeouts.connectMs);
|
|
284
|
+
if (state.retired) {
|
|
285
|
+
await this.stop(state);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
state.failure = void 0;
|
|
289
|
+
lifecycle("mcp.ready", { server: state.spec.name, tools: state.tools?.length ?? 0, ms: Date.now() - started });
|
|
290
|
+
} catch (error) {
|
|
291
|
+
state.starting = void 0;
|
|
292
|
+
await this.fail(state, error);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
auth(state) {
|
|
296
|
+
if (state.spec.transport === "stdio") return void 0;
|
|
297
|
+
state.auth ??= this.authFor?.(state.spec);
|
|
298
|
+
return state.auth;
|
|
299
|
+
}
|
|
300
|
+
async fail(state, error) {
|
|
301
|
+
const signIn = isMcpSignInRequired(error);
|
|
302
|
+
const message = signIn ? mcpSignInNote(state.spec.name) : firstLine(error);
|
|
303
|
+
if (state.failure?.message !== message) diagnostic("mcp.server-unavailable", `${state.spec.name}: ${message}`);
|
|
304
|
+
state.failure = {
|
|
305
|
+
message,
|
|
306
|
+
at: this.now(),
|
|
307
|
+
...signIn ? { signIn: { stamp: await this.auth(state)?.stamp() ?? "" } } : {}
|
|
308
|
+
};
|
|
309
|
+
await this.stop(state);
|
|
310
|
+
}
|
|
311
|
+
/** A call to a server that died since its tools were listed gets one
|
|
312
|
+
* reconnect before failing: the model already chose this tool, and a
|
|
313
|
+
* restart is cheaper than a wasted step. */
|
|
314
|
+
async call(state, tool, args, signal) {
|
|
315
|
+
const started = Date.now();
|
|
316
|
+
try {
|
|
317
|
+
const result = await (await this.clientFor(state)).callTool(tool, args, { timeoutMs: this.timeouts.callMs, ...signal ? { signal } : {} });
|
|
318
|
+
lifecycle("mcp.call", { server: state.spec.name, tool, ms: Date.now() - started, ok: !result.isError });
|
|
319
|
+
return result;
|
|
320
|
+
} catch (error) {
|
|
321
|
+
lifecycle("mcp.call", { server: state.spec.name, tool, ms: Date.now() - started, ok: false });
|
|
322
|
+
if (isMcpSignInRequired(error)) await this.fail(state, error);
|
|
323
|
+
throw error;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
/** The server's live client, restarted once if it died since this turn's
|
|
327
|
+
* listing. A server that failed to start is retried only once the failure
|
|
328
|
+
* backoff has passed: a call to a dead one fails at once rather than each
|
|
329
|
+
* waiting out the connect timeout again. */
|
|
330
|
+
async clientFor(state) {
|
|
331
|
+
if (!state.client || state.client.closed) await this.ensureReady(state);
|
|
332
|
+
const client = state.client;
|
|
333
|
+
if (!client) throw new Error(`MCP server "${state.spec.name}" is not running: ${state.failure?.message ?? "it could not be started"}`);
|
|
334
|
+
return client;
|
|
335
|
+
}
|
|
336
|
+
/** Stdio servers are their own process group (see transport.ts), so
|
|
337
|
+
* nothing else reaps them if ClikCode exits; `exit` handlers must be
|
|
338
|
+
* synchronous, which is why this kills rather than shutting down politely. */
|
|
339
|
+
installExitHook() {
|
|
340
|
+
if (this.exitHookInstalled) return;
|
|
341
|
+
this.exitHookInstalled = true;
|
|
342
|
+
process.once("exit", this.killAll);
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
var shared;
|
|
346
|
+
var imports;
|
|
347
|
+
var builtinServers = [];
|
|
348
|
+
async function userMcpServers(stateDir) {
|
|
349
|
+
const loaded = await loadMcpServers(stateDir);
|
|
350
|
+
const names = new Set(loaded.servers.map((server) => server.name));
|
|
351
|
+
return { ...loaded, servers: [...loaded.servers, ...enabledPluginMcpServers({ stateDir }).filter((server) => !names.has(server.name))] };
|
|
352
|
+
}
|
|
353
|
+
async function loadAllServers(stateDir) {
|
|
354
|
+
const loaded = await loadMcpServers(stateDir);
|
|
355
|
+
const names = new Set(loaded.servers.map((server) => server.name));
|
|
356
|
+
const builtins = builtinServers.filter((server) => !names.has(server.name));
|
|
357
|
+
builtins.forEach((server) => names.add(server.name));
|
|
358
|
+
const plugins = enabledPluginMcpServers({ stateDir }).filter((server) => !names.has(server.name));
|
|
359
|
+
return { ...loaded, servers: [...loaded.servers, ...builtins, ...plugins] };
|
|
360
|
+
}
|
|
361
|
+
async function mcpToolsForTurn(stateDir, signal, builtins = []) {
|
|
362
|
+
builtinServers = builtins;
|
|
363
|
+
if (!signal) return sharedToolset(stateDir);
|
|
364
|
+
return new Promise((resolve) => {
|
|
365
|
+
const onAbort = () => resolve({ tools: [] });
|
|
366
|
+
if (signal.aborted) return onAbort();
|
|
367
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
368
|
+
void sharedToolset(stateDir).then(resolve).finally(() => signal.removeEventListener("abort", onAbort));
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
async function sharedToolset(stateDir) {
|
|
372
|
+
if (shared?.stateDir !== stateDir) {
|
|
373
|
+
await shared?.manager.shutdown();
|
|
374
|
+
shared = {
|
|
375
|
+
stateDir,
|
|
376
|
+
manager: new McpManager(() => loadAllServers(stateDir), {
|
|
377
|
+
// A server the user gave its own credential (an API key header) is
|
|
378
|
+
// theirs to authorize; a 401 there is a wrong key, not a sign-in.
|
|
379
|
+
authFor: (spec) => spec.transport === "stdio" || carriesCredentials(spec.headers) ? void 0 : mcpOAuthProvider(stateDir, spec)
|
|
380
|
+
})
|
|
381
|
+
};
|
|
382
|
+
imports = void 0;
|
|
383
|
+
}
|
|
384
|
+
imports ??= importVendorMcpServers(stateDir).then(importNotice, (error) => `MCP import from harness configs failed: ${firstLine(error)}`);
|
|
385
|
+
const imported = await imports;
|
|
386
|
+
imports = Promise.resolve(void 0);
|
|
387
|
+
if (imported) diagnostic("mcp.import", imported);
|
|
388
|
+
try {
|
|
389
|
+
return await shared.manager.toolset();
|
|
390
|
+
} catch (error) {
|
|
391
|
+
diagnostic("mcp.toolset", firstLine(error));
|
|
392
|
+
return { tools: [] };
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
function prepareMcp(stateDir, builtins = []) {
|
|
396
|
+
builtinServers = builtins;
|
|
397
|
+
void sharedToolset(stateDir).catch(quiet("agent/mcp/manager"));
|
|
398
|
+
}
|
|
399
|
+
async function releaseMcp() {
|
|
400
|
+
builtinServers = [];
|
|
401
|
+
const current = shared;
|
|
402
|
+
shared = void 0;
|
|
403
|
+
imports = void 0;
|
|
404
|
+
await current?.manager.shutdown();
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
export {
|
|
408
|
+
userMcpServers,
|
|
409
|
+
mcpToolsForTurn,
|
|
410
|
+
prepareMcp,
|
|
411
|
+
releaseMcp
|
|
412
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
currentToolName,
|
|
5
|
+
installedBuildStamp,
|
|
6
|
+
latestToolSet
|
|
7
|
+
} from "./chunk-LM6EIA4B.js";
|
|
8
|
+
import "./chunk-EXN4KHLB.js";
|
|
9
|
+
import {
|
|
10
|
+
untilInputEnds
|
|
11
|
+
} from "./chunk-4R6CSC3S.js";
|
|
12
|
+
import "./chunk-PWXII6HF.js";
|
|
13
|
+
|
|
14
|
+
// src/commands/mcp-serve.ts
|
|
15
|
+
import { createInterface } from "node:readline";
|
|
16
|
+
var VERSIONS = ["2025-06-18", "2025-03-26", "2024-11-05"];
|
|
17
|
+
async function toolSet() {
|
|
18
|
+
return await latestToolSet() ?? (await import("./chunk-5WYJTA6O.js")).SHARED_COMPUTER_TOOLS;
|
|
19
|
+
}
|
|
20
|
+
async function tools() {
|
|
21
|
+
return (await toolSet()).map((tool) => ({ name: tool.name, description: tool.description, inputSchema: tool.parameters }));
|
|
22
|
+
}
|
|
23
|
+
var callInWorker = async (input) => (await import("./chunk-NEKKIBCX.js")).callWorkerTool(input);
|
|
24
|
+
var listedStamp;
|
|
25
|
+
var toldStamp;
|
|
26
|
+
async function buildChangedSinceListed() {
|
|
27
|
+
const now = await installedBuildStamp();
|
|
28
|
+
if (now === void 0 || listedStamp === void 0 || now === listedStamp || now === toldStamp) return false;
|
|
29
|
+
toldStamp = now;
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
async function handleMcpRequest(message, call = callInWorker) {
|
|
33
|
+
if (message.id === void 0) return void 0;
|
|
34
|
+
const reply = (result) => ({ jsonrpc: "2.0", id: message.id, result });
|
|
35
|
+
switch (message.method) {
|
|
36
|
+
case "initialize": {
|
|
37
|
+
const asked = String(message.params?.protocolVersion ?? "");
|
|
38
|
+
return reply({ protocolVersion: VERSIONS.includes(asked) ? asked : VERSIONS[0], capabilities: { tools: { listChanged: true } }, serverInfo: { name: "clikcode", version: "1" } });
|
|
39
|
+
}
|
|
40
|
+
case "ping":
|
|
41
|
+
return reply({});
|
|
42
|
+
case "tools/list": {
|
|
43
|
+
listedStamp = await installedBuildStamp();
|
|
44
|
+
return reply({ tools: await tools() });
|
|
45
|
+
}
|
|
46
|
+
case "tools/call": {
|
|
47
|
+
const name = currentToolName(String(message.params?.name ?? ""));
|
|
48
|
+
if (!(await toolSet()).some((tool) => tool.name === name)) return { jsonrpc: "2.0", id: message.id, error: { code: -32602, message: `Unknown tool "${name}".` } };
|
|
49
|
+
try {
|
|
50
|
+
const result = await call({ tool: name, args: message.params?.arguments ?? {} });
|
|
51
|
+
const stale = !result.ok && /^Invalid arguments/.test(result.output) && await installedBuildStamp() !== listedStamp;
|
|
52
|
+
const text = stale ? `${result.output}
|
|
53
|
+
restart needed: the installed ClikCode build is newer than the tool list this session was given; start a new chat (or reconnect the clikcode MCP server) to get the new arguments.` : result.output;
|
|
54
|
+
return reply({ content: [{ type: "text", text }], isError: !result.ok });
|
|
55
|
+
} catch (error) {
|
|
56
|
+
return reply({ content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }], isError: true });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
default:
|
|
60
|
+
return { jsonrpc: "2.0", id: message.id, error: { code: -32601, message: `Method not found: ${message.method}` } };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async function mcpServe(signal) {
|
|
64
|
+
const lines = createInterface({ input: process.stdin });
|
|
65
|
+
const pending = /* @__PURE__ */ new Set();
|
|
66
|
+
lines.on("line", (line) => {
|
|
67
|
+
if (!line.trim()) return;
|
|
68
|
+
let message;
|
|
69
|
+
try {
|
|
70
|
+
message = JSON.parse(line);
|
|
71
|
+
} catch {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const work = handleMcpRequest(message).then(async (response) => {
|
|
75
|
+
if (response) process.stdout.write(`${JSON.stringify(response)}
|
|
76
|
+
`);
|
|
77
|
+
if (await buildChangedSinceListed()) process.stdout.write(`${JSON.stringify({ jsonrpc: "2.0", method: "notifications/tools/list_changed" })}
|
|
78
|
+
`);
|
|
79
|
+
});
|
|
80
|
+
pending.add(work);
|
|
81
|
+
void work.finally(() => pending.delete(work));
|
|
82
|
+
});
|
|
83
|
+
await untilInputEnds(lines, signal);
|
|
84
|
+
await Promise.allSettled([...pending]);
|
|
85
|
+
}
|
|
86
|
+
export {
|
|
87
|
+
buildChangedSinceListed,
|
|
88
|
+
handleMcpRequest,
|
|
89
|
+
mcpServe
|
|
90
|
+
};
|