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,439 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
markTurn
|
|
5
|
+
} from "./chunk-4NN3XQQT.js";
|
|
6
|
+
import {
|
|
7
|
+
killProcessTreePortable
|
|
8
|
+
} from "./chunk-WPB5WEZJ.js";
|
|
9
|
+
import {
|
|
10
|
+
LineBuffer
|
|
11
|
+
} from "./chunk-XIBYREEY.js";
|
|
12
|
+
import {
|
|
13
|
+
swallowed
|
|
14
|
+
} from "./chunk-RDDWQBEM.js";
|
|
15
|
+
|
|
16
|
+
// src/harness/transport/parent-signals.ts
|
|
17
|
+
var stops = /* @__PURE__ */ new Map();
|
|
18
|
+
var handlers = /* @__PURE__ */ new Map();
|
|
19
|
+
var ALL = process.platform === "win32" ? ["SIGINT", "SIGTERM"] : ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
20
|
+
function sync() {
|
|
21
|
+
const wanted = /* @__PURE__ */ new Set();
|
|
22
|
+
for (const signals of stops.values()) for (const signal of signals) wanted.add(signal);
|
|
23
|
+
for (const [signal, handler] of [...handlers]) {
|
|
24
|
+
if (wanted.has(signal)) continue;
|
|
25
|
+
process.off(signal, handler);
|
|
26
|
+
handlers.delete(signal);
|
|
27
|
+
}
|
|
28
|
+
for (const signal of wanted) {
|
|
29
|
+
if (handlers.has(signal)) continue;
|
|
30
|
+
const handler = () => received(signal);
|
|
31
|
+
handlers.set(signal, handler);
|
|
32
|
+
process.on(signal, handler);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function received(signal) {
|
|
36
|
+
for (const [stop, signals] of [...stops]) {
|
|
37
|
+
if (!signals.has(signal)) continue;
|
|
38
|
+
stops.delete(stop);
|
|
39
|
+
try {
|
|
40
|
+
stop(signal);
|
|
41
|
+
} catch {
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
sync();
|
|
45
|
+
if (signal === "SIGINT") return;
|
|
46
|
+
const handler = handlers.get(signal);
|
|
47
|
+
if (handler) {
|
|
48
|
+
process.off(signal, handler);
|
|
49
|
+
handlers.delete(signal);
|
|
50
|
+
}
|
|
51
|
+
if (process.listenerCount(signal) === 0) process.kill(process.pid, signal);
|
|
52
|
+
}
|
|
53
|
+
function forwardParentSignals(stop, signals = ALL) {
|
|
54
|
+
stops.set(stop, new Set(signals.filter((signal) => ALL.includes(signal))));
|
|
55
|
+
sync();
|
|
56
|
+
return () => {
|
|
57
|
+
stops.delete(stop);
|
|
58
|
+
sync();
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/harness/transport/jsonrpc-peer.ts
|
|
63
|
+
var NOISE_LIMIT = 8e3;
|
|
64
|
+
var CLOSE_AFTER_EXIT_MS = 500;
|
|
65
|
+
var GROUP_REAP_MS = 2e3;
|
|
66
|
+
function signalGroup(pgid, signal) {
|
|
67
|
+
try {
|
|
68
|
+
process.kill(-pgid, signal);
|
|
69
|
+
return true;
|
|
70
|
+
} catch {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function jsonRpcStructuredKind(data) {
|
|
75
|
+
if (!data || typeof data !== "object") return {};
|
|
76
|
+
const record = data;
|
|
77
|
+
let errorKind;
|
|
78
|
+
let statusCode;
|
|
79
|
+
const direct = [record.errorKind, record.error_kind].find((value) => typeof value === "string" && value.trim().length > 0);
|
|
80
|
+
if (direct) errorKind = direct.trim();
|
|
81
|
+
const info = record.codexErrorInfo ?? record.codex_error_info;
|
|
82
|
+
if (!errorKind && typeof info === "string" && info.trim()) errorKind = info.trim();
|
|
83
|
+
else if (info && typeof info === "object") {
|
|
84
|
+
const [tag, body] = Object.entries(info)[0] ?? [];
|
|
85
|
+
if (!errorKind && tag) errorKind = tag;
|
|
86
|
+
const code = body && typeof body === "object" ? body.httpStatusCode ?? body.http_status_code : void 0;
|
|
87
|
+
if (typeof code === "number" && code >= 400 && code < 600) statusCode = code;
|
|
88
|
+
}
|
|
89
|
+
return { ...errorKind ? { errorKind } : {}, ...statusCode !== void 0 ? { statusCode } : {} };
|
|
90
|
+
}
|
|
91
|
+
function jsonRpcErrorDetail(data) {
|
|
92
|
+
const field = (name) => {
|
|
93
|
+
const value = data && typeof data === "object" ? data[name] : void 0;
|
|
94
|
+
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
95
|
+
};
|
|
96
|
+
const text = typeof data === "string" ? data.trim() : field("message") ?? field("details") ?? field("error") ?? field("reason") ?? field("detail");
|
|
97
|
+
if (!text) return {};
|
|
98
|
+
const leading = /^(\d{3})\b\s*/.exec(text);
|
|
99
|
+
const body = leading ? text.slice(leading[0].length) : text;
|
|
100
|
+
let reason = body;
|
|
101
|
+
let status = leading ? Number(leading[1]) : void 0;
|
|
102
|
+
try {
|
|
103
|
+
const parsed = JSON.parse(body);
|
|
104
|
+
const said = [parsed.detail, parsed.message, parsed.error].find((value) => typeof value === "string" && value.trim().length > 0);
|
|
105
|
+
if (said) reason = said.replace(/\s+/g, " ").trim();
|
|
106
|
+
if (status === void 0 && typeof parsed.status === "number") status = parsed.status;
|
|
107
|
+
} catch {
|
|
108
|
+
}
|
|
109
|
+
return { reason, ...status !== void 0 && status >= 400 && status < 600 ? { statusCode: status } : {} };
|
|
110
|
+
}
|
|
111
|
+
var JsonRpcError = class extends Error {
|
|
112
|
+
constructor(message, rpcCode, data) {
|
|
113
|
+
const detail = jsonRpcErrorDetail(data);
|
|
114
|
+
const structured = jsonRpcStructuredKind(data);
|
|
115
|
+
super(detail.reason && !message.includes(detail.reason) ? `${message}: ${detail.reason}` : message);
|
|
116
|
+
this.rpcCode = rpcCode;
|
|
117
|
+
this.data = data;
|
|
118
|
+
this.name = "JsonRpcError";
|
|
119
|
+
const status = detail.statusCode ?? structured.statusCode;
|
|
120
|
+
if (status !== void 0) this.statusCode = status;
|
|
121
|
+
if (structured.errorKind) this.errorKind = structured.errorKind;
|
|
122
|
+
}
|
|
123
|
+
rpcCode;
|
|
124
|
+
data;
|
|
125
|
+
statusCode;
|
|
126
|
+
/** The vendor's structured failure kind (data.errorKind, codexErrorInfo);
|
|
127
|
+
* classifyAccountFailure reads it before any wording. */
|
|
128
|
+
errorKind;
|
|
129
|
+
};
|
|
130
|
+
var JsonRpcPeer = class {
|
|
131
|
+
constructor(child, options) {
|
|
132
|
+
this.child = child;
|
|
133
|
+
this.options = options;
|
|
134
|
+
const framed = options.framing === "content-length";
|
|
135
|
+
if (!framed) child.stdout?.setEncoding?.("utf8");
|
|
136
|
+
child.stderr?.setEncoding?.("utf8");
|
|
137
|
+
child.stdout?.on("data", (chunk) => framed ? this.receiveFrames(Buffer.from(chunk)) : this.receive(String(chunk)));
|
|
138
|
+
child.stderr?.on("data", (chunk) => {
|
|
139
|
+
this.stderrTail = `${this.stderrTail}${String(chunk)}`.slice(-NOISE_LIMIT);
|
|
140
|
+
this.stillAlive();
|
|
141
|
+
const crash = this.options.crashReport?.(this.stderrTail);
|
|
142
|
+
if (crash === void 0 || this.isClosed) return;
|
|
143
|
+
this.handleClose(new Error(`the agent crashed: ${crash}`));
|
|
144
|
+
killProcessTreePortable(this.child, "SIGTERM", this.options.detached === true);
|
|
145
|
+
});
|
|
146
|
+
child.stdin?.on("error", () => void 0);
|
|
147
|
+
child.stdout?.on("error", () => void 0);
|
|
148
|
+
child.stderr?.on("error", () => void 0);
|
|
149
|
+
child.once("error", (error) => {
|
|
150
|
+
this.markExited(null, null);
|
|
151
|
+
const cause = error instanceof Error ? error : new Error(String(error));
|
|
152
|
+
this.handleClose(this.options.startFailure?.(cause) ?? cause);
|
|
153
|
+
});
|
|
154
|
+
child.once("exit", (code, signal) => {
|
|
155
|
+
this.markExited(code, signal);
|
|
156
|
+
if (this.isClosed) return;
|
|
157
|
+
this.closeFallback = setTimeout(() => this.handleClose(), CLOSE_AFTER_EXIT_MS);
|
|
158
|
+
});
|
|
159
|
+
child.once("close", (code, signal) => {
|
|
160
|
+
this.markExited(code, signal);
|
|
161
|
+
this.handleClose();
|
|
162
|
+
});
|
|
163
|
+
if (options.forwardParentSignals !== false) this.installSignalForwarding();
|
|
164
|
+
}
|
|
165
|
+
child;
|
|
166
|
+
options;
|
|
167
|
+
pending = /* @__PURE__ */ new Map();
|
|
168
|
+
nextId = 1;
|
|
169
|
+
lines = new LineBuffer();
|
|
170
|
+
/** Unparsed bytes under Content-Length framing. */
|
|
171
|
+
frames = Buffer.alloc(0);
|
|
172
|
+
stderrTail = "";
|
|
173
|
+
stdoutNoise = "";
|
|
174
|
+
isClosed = false;
|
|
175
|
+
exited = false;
|
|
176
|
+
exitCode = null;
|
|
177
|
+
exitSignal = null;
|
|
178
|
+
closeFallback;
|
|
179
|
+
shutdownPromise;
|
|
180
|
+
exitWaiters = [];
|
|
181
|
+
signalCleanup = [];
|
|
182
|
+
/** The group is to outlive its leader (keepGroup). */
|
|
183
|
+
groupKept = false;
|
|
184
|
+
groupReaped = false;
|
|
185
|
+
get closed() {
|
|
186
|
+
return this.isClosed;
|
|
187
|
+
}
|
|
188
|
+
get pendingCount() {
|
|
189
|
+
return this.pending.size;
|
|
190
|
+
}
|
|
191
|
+
/** Best available explanation for a dead child: stderr, then stray stdout. */
|
|
192
|
+
failureDetail() {
|
|
193
|
+
return this.stderrTail.trim() || this.stdoutNoise.trim();
|
|
194
|
+
}
|
|
195
|
+
/** Fire-and-forget write. A no-op once the peer is closed or stdin is gone. */
|
|
196
|
+
send(message) {
|
|
197
|
+
const stdin = this.child.stdin;
|
|
198
|
+
if (this.isClosed || this.exited || !stdin || stdin.destroyed || stdin.writableEnded) return false;
|
|
199
|
+
const framed = this.options.jsonrpcVersion === false ? message : { jsonrpc: "2.0", ...message };
|
|
200
|
+
try {
|
|
201
|
+
if (this.options.framing === "content-length") {
|
|
202
|
+
const body = Buffer.from(JSON.stringify(framed));
|
|
203
|
+
stdin.write(Buffer.concat([Buffer.from(`Content-Length: ${body.length}\r
|
|
204
|
+
\r
|
|
205
|
+
`), body]));
|
|
206
|
+
} else stdin.write(`${JSON.stringify(framed)}
|
|
207
|
+
`);
|
|
208
|
+
return true;
|
|
209
|
+
} catch {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
notify(method, params) {
|
|
214
|
+
return this.send(params === void 0 ? { method } : { method, params });
|
|
215
|
+
}
|
|
216
|
+
request(method, params, options = {}) {
|
|
217
|
+
return new Promise((resolve, reject) => {
|
|
218
|
+
if (this.isClosed || this.exited) return reject(this.closedError());
|
|
219
|
+
const id = this.nextId++;
|
|
220
|
+
const entry = { method, resolve, reject, idleReset: options.idleReset === true };
|
|
221
|
+
if (options.timeoutMs !== void 0 && options.timeoutMs > 0) {
|
|
222
|
+
entry.timer = setTimeout(() => {
|
|
223
|
+
if (!this.pending.delete(id)) return;
|
|
224
|
+
const seconds = Math.round(options.timeoutMs / 1e3);
|
|
225
|
+
const message = entry.idleReset ? `${this.options.label} stalled at ${method}: nothing from it for ${seconds}s` : `${this.options.label} ${method} timed out after ${seconds}s`;
|
|
226
|
+
reject(Object.assign(new JsonRpcError(message), { code: "ERR_JSONRPC_TIMEOUT" }));
|
|
227
|
+
}, options.timeoutMs);
|
|
228
|
+
}
|
|
229
|
+
this.pending.set(id, entry);
|
|
230
|
+
options.onId?.(id);
|
|
231
|
+
if (!this.send({ id, method, params })) {
|
|
232
|
+
this.pending.delete(id);
|
|
233
|
+
if (entry.timer) clearTimeout(entry.timer);
|
|
234
|
+
reject(this.closedError());
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
/** Reject in-flight requests without closing the peer. Turn-scoped calls
|
|
239
|
+
* such as `turn/steer` must settle when their turn ends, even though the
|
|
240
|
+
* server may never answer them. */
|
|
241
|
+
rejectPending(error, filter) {
|
|
242
|
+
for (const [id, entry] of [...this.pending]) {
|
|
243
|
+
if (filter && !filter(entry.method)) continue;
|
|
244
|
+
this.pending.delete(id);
|
|
245
|
+
if (entry.timer) clearTimeout(entry.timer);
|
|
246
|
+
entry.reject(error);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/** Resolves once the child has exited (immediately if it already has). */
|
|
250
|
+
waitForExit() {
|
|
251
|
+
if (this.exited) return Promise.resolve();
|
|
252
|
+
return new Promise((resolve) => {
|
|
253
|
+
this.exitWaiters.push(resolve);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
/** Whether the child's process group is left running when its leader exits.
|
|
257
|
+
* By default it is not: a vendor that exits (or crashes) leaves its MCP servers,
|
|
258
|
+
* shells and daemons in its group, and they get SIGTERM, then SIGKILL after
|
|
259
|
+
* GROUP_REAP_MS. A retired session (persistent-session.ts retire) keeps its
|
|
260
|
+
* group: its work runs on after the vendor. Released (false) after the leader
|
|
261
|
+
* has gone, the group is reaped now. */
|
|
262
|
+
keepGroup(keep = true) {
|
|
263
|
+
this.groupKept = keep;
|
|
264
|
+
if (!keep && this.exited) this.reapGroup();
|
|
265
|
+
}
|
|
266
|
+
/** The leader is gone: end what it left in its group, unless kept. Once. */
|
|
267
|
+
reapGroup() {
|
|
268
|
+
const pgid = this.child.pid;
|
|
269
|
+
if (this.groupKept || this.groupReaped || this.options.detached !== true || process.platform === "win32" || !pgid) return;
|
|
270
|
+
this.groupReaped = true;
|
|
271
|
+
if (!signalGroup(pgid, "SIGTERM")) return;
|
|
272
|
+
const timer = setTimeout(() => {
|
|
273
|
+
signalGroup(pgid, "SIGKILL");
|
|
274
|
+
}, GROUP_REAP_MS);
|
|
275
|
+
timer.unref?.();
|
|
276
|
+
}
|
|
277
|
+
kill(signal = "SIGTERM") {
|
|
278
|
+
if (this.exited) return;
|
|
279
|
+
killProcessTreePortable(this.child, signal, this.options.detached === true);
|
|
280
|
+
}
|
|
281
|
+
/** cancel -> stdin EOF -> (graceMs) SIGTERM -> (killMs) SIGKILL. Idempotent;
|
|
282
|
+
* resolves when the child is gone or SIGKILL has been delivered. */
|
|
283
|
+
shutdown(options = {}) {
|
|
284
|
+
this.shutdownPromise ??= this.runShutdown(options);
|
|
285
|
+
return this.shutdownPromise;
|
|
286
|
+
}
|
|
287
|
+
async runShutdown(options) {
|
|
288
|
+
if (this.exited) return;
|
|
289
|
+
const graceMs = options.graceMs ?? 2e3;
|
|
290
|
+
const killMs = options.killMs ?? 3e3;
|
|
291
|
+
const exit = this.waitForExit();
|
|
292
|
+
let graceTimer;
|
|
293
|
+
const grace = new Promise((resolve) => {
|
|
294
|
+
graceTimer = setTimeout(() => resolve("timeout"), graceMs);
|
|
295
|
+
});
|
|
296
|
+
try {
|
|
297
|
+
let timedOut = false;
|
|
298
|
+
if (options.cancel) {
|
|
299
|
+
const cancelled = Promise.resolve().then(() => options.cancel()).then(() => void 0, () => void 0);
|
|
300
|
+
timedOut = await Promise.race([cancelled, exit, grace]) === "timeout";
|
|
301
|
+
}
|
|
302
|
+
if (this.exited) return;
|
|
303
|
+
try {
|
|
304
|
+
this.child.stdin?.end();
|
|
305
|
+
} catch {
|
|
306
|
+
}
|
|
307
|
+
if (!timedOut) await Promise.race([exit, grace]);
|
|
308
|
+
} finally {
|
|
309
|
+
if (graceTimer) clearTimeout(graceTimer);
|
|
310
|
+
}
|
|
311
|
+
if (this.exited) return;
|
|
312
|
+
this.kill("SIGTERM");
|
|
313
|
+
let killTimer;
|
|
314
|
+
const escalate = new Promise((resolve) => {
|
|
315
|
+
killTimer = setTimeout(resolve, killMs);
|
|
316
|
+
});
|
|
317
|
+
await Promise.race([exit, escalate]);
|
|
318
|
+
if (killTimer) clearTimeout(killTimer);
|
|
319
|
+
if (!this.exited) this.kill("SIGKILL");
|
|
320
|
+
}
|
|
321
|
+
closedError() {
|
|
322
|
+
const detail = this.failureDetail();
|
|
323
|
+
const status = this.exitSignal ? `stopped (${this.exitSignal})` : this.exited ? `exited ${this.exitCode ?? 1}` : "closed";
|
|
324
|
+
return Object.assign(new JsonRpcError(detail || `${this.options.label} ${status}`), { code: "ERR_JSONRPC_CLOSED" });
|
|
325
|
+
}
|
|
326
|
+
markExited(code, signal) {
|
|
327
|
+
if (this.exited) return;
|
|
328
|
+
this.exited = true;
|
|
329
|
+
this.exitCode = code;
|
|
330
|
+
this.exitSignal = signal;
|
|
331
|
+
for (const cleanup of this.signalCleanup.splice(0)) cleanup();
|
|
332
|
+
for (const waiter of this.exitWaiters.splice(0)) waiter();
|
|
333
|
+
this.reapGroup();
|
|
334
|
+
}
|
|
335
|
+
handleClose(cause) {
|
|
336
|
+
if (this.isClosed) return;
|
|
337
|
+
if (this.closeFallback) clearTimeout(this.closeFallback);
|
|
338
|
+
const tail = this.lines.flush();
|
|
339
|
+
if (tail.trim()) this.handleLine(tail);
|
|
340
|
+
const error = cause ?? this.closedError();
|
|
341
|
+
this.isClosed = true;
|
|
342
|
+
this.rejectPending(error);
|
|
343
|
+
this.options.onClose?.(error);
|
|
344
|
+
}
|
|
345
|
+
/** Anything from the child -- a message, a partial line, stderr -- is a sign
|
|
346
|
+
* of life: an idle-window request's clock starts again. */
|
|
347
|
+
stillAlive() {
|
|
348
|
+
for (const entry of this.pending.values()) if (entry.idleReset) entry.timer?.refresh();
|
|
349
|
+
}
|
|
350
|
+
receive(chunk) {
|
|
351
|
+
if (this.isClosed) return;
|
|
352
|
+
this.stillAlive();
|
|
353
|
+
markTurn("first-byte");
|
|
354
|
+
for (const line of this.lines.push(chunk)) if (line.trim()) this.handleLine(line);
|
|
355
|
+
}
|
|
356
|
+
receiveFrames(chunk) {
|
|
357
|
+
if (this.isClosed) return;
|
|
358
|
+
this.stillAlive();
|
|
359
|
+
this.frames = Buffer.concat([this.frames, chunk]);
|
|
360
|
+
for (; ; ) {
|
|
361
|
+
const headerEnd = this.frames.indexOf("\r\n\r\n");
|
|
362
|
+
if (headerEnd < 0) return;
|
|
363
|
+
const length = Number(/Content-Length:\s*(\d+)/i.exec(this.frames.subarray(0, headerEnd).toString())?.[1]);
|
|
364
|
+
if (!Number.isFinite(length)) {
|
|
365
|
+
this.stdoutNoise = `${this.stdoutNoise}${this.frames.subarray(0, headerEnd + 4).toString()}`.slice(-NOISE_LIMIT);
|
|
366
|
+
this.frames = this.frames.subarray(headerEnd + 4);
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
if (this.frames.length < headerEnd + 4 + length) return;
|
|
370
|
+
const body = this.frames.subarray(headerEnd + 4, headerEnd + 4 + length).toString();
|
|
371
|
+
this.frames = this.frames.subarray(headerEnd + 4 + length);
|
|
372
|
+
this.handleLine(body);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
handleLine(line) {
|
|
376
|
+
let message;
|
|
377
|
+
try {
|
|
378
|
+
const parsed = JSON.parse(line);
|
|
379
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error("not a message");
|
|
380
|
+
message = parsed;
|
|
381
|
+
} catch {
|
|
382
|
+
this.stdoutNoise = `${this.stdoutNoise}${line}
|
|
383
|
+
`.slice(-NOISE_LIMIT);
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
const hasId = message.id !== void 0 && message.id !== null;
|
|
387
|
+
if (typeof message.method === "string") {
|
|
388
|
+
if (hasId) this.handleServerRequest(message.method, message.params ?? {}, message.id);
|
|
389
|
+
else {
|
|
390
|
+
try {
|
|
391
|
+
this.options.onNotification?.(message.method, message.params ?? {});
|
|
392
|
+
} catch (error) {
|
|
393
|
+
swallowed("harness/transport/jsonrpc-peer", error);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
if (!hasId) return;
|
|
399
|
+
const entry = this.pending.get(Number(message.id));
|
|
400
|
+
if (!entry) return;
|
|
401
|
+
this.pending.delete(Number(message.id));
|
|
402
|
+
if (entry.timer) clearTimeout(entry.timer);
|
|
403
|
+
if (message.error) {
|
|
404
|
+
const detail = message.error;
|
|
405
|
+
entry.reject(new JsonRpcError(String(detail.message ?? `${entry.method} failed`), typeof detail.code === "number" ? detail.code : void 0, detail.data));
|
|
406
|
+
} else entry.resolve(message.result ?? {});
|
|
407
|
+
}
|
|
408
|
+
handleServerRequest(method, params, id) {
|
|
409
|
+
let handled;
|
|
410
|
+
try {
|
|
411
|
+
handled = this.options.onRequest?.(method, params, id);
|
|
412
|
+
} catch (error) {
|
|
413
|
+
handled = Promise.reject(error);
|
|
414
|
+
}
|
|
415
|
+
if (!handled) {
|
|
416
|
+
this.send({ id, error: { code: -32601, message: `Unsupported client method: ${method}` } });
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
handled.then(
|
|
420
|
+
(result) => {
|
|
421
|
+
this.send({ id, result: result ?? {} });
|
|
422
|
+
},
|
|
423
|
+
(error) => {
|
|
424
|
+
this.send({ id, error: { code: -32603, message: error instanceof Error ? error.message : String(error) } });
|
|
425
|
+
}
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
installSignalForwarding() {
|
|
429
|
+
this.signalCleanup.push(forwardParentSignals((signal) => this.kill(signal)));
|
|
430
|
+
const onExit = () => this.kill("SIGKILL");
|
|
431
|
+
process.once("exit", onExit);
|
|
432
|
+
this.signalCleanup.push(() => process.off("exit", onExit));
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
export {
|
|
437
|
+
forwardParentSignals,
|
|
438
|
+
JsonRpcPeer
|
|
439
|
+
};
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
|
|
4
|
+
// src/agent/security.ts
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
var ConfinementError = class extends Error {
|
|
8
|
+
code = "ERR_PATH_NOT_CONFINED";
|
|
9
|
+
};
|
|
10
|
+
function expandHome(input, homeDir) {
|
|
11
|
+
if (input === "~") return homeDir;
|
|
12
|
+
if (input.startsWith("~/") || input.startsWith("~\\")) return path.join(homeDir, input.slice(2));
|
|
13
|
+
return input;
|
|
14
|
+
}
|
|
15
|
+
function realpathNearest(absolute) {
|
|
16
|
+
let current = absolute;
|
|
17
|
+
const tail = [];
|
|
18
|
+
for (; ; ) {
|
|
19
|
+
try {
|
|
20
|
+
const real = fs.realpathSync.native(current);
|
|
21
|
+
return tail.length ? path.join(real, ...tail.reverse()) : real;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
const code = error.code;
|
|
24
|
+
if (code !== "ENOENT" && code !== "ENOTDIR") throw error;
|
|
25
|
+
try {
|
|
26
|
+
const link = fs.readlinkSync(current);
|
|
27
|
+
current = path.resolve(path.dirname(current), link);
|
|
28
|
+
continue;
|
|
29
|
+
} catch {
|
|
30
|
+
}
|
|
31
|
+
const parent = path.dirname(current);
|
|
32
|
+
if (parent === current) return tail.length ? path.join(current, ...tail.reverse()) : current;
|
|
33
|
+
tail.push(path.basename(current));
|
|
34
|
+
current = parent;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function isInside(candidate, root) {
|
|
39
|
+
const relative = path.relative(root, candidate);
|
|
40
|
+
return relative === "" || !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
41
|
+
}
|
|
42
|
+
function workspaceRoots(scope) {
|
|
43
|
+
return [scope.cwd, ...scope.addDirs].map((dir) => realpathNearest(path.resolve(dir)));
|
|
44
|
+
}
|
|
45
|
+
function resolvePath(input, scope) {
|
|
46
|
+
if (typeof input !== "string" || !input.trim()) throw new ConfinementError("A non-empty path is required");
|
|
47
|
+
if (input.includes("\0")) throw new ConfinementError("Path contains a NUL byte");
|
|
48
|
+
const absolute = path.resolve(scope.cwd, expandHome(input, scope.homeDir));
|
|
49
|
+
const real = realpathNearest(absolute);
|
|
50
|
+
const root = workspaceRoots(scope).find((candidate) => isInside(real, candidate));
|
|
51
|
+
return { absolute, real, confined: root !== void 0, ...root ? { root } : {} };
|
|
52
|
+
}
|
|
53
|
+
var SHELL_RC_FILES = /* @__PURE__ */ new Set([
|
|
54
|
+
".bashrc",
|
|
55
|
+
".bash_profile",
|
|
56
|
+
".bash_login",
|
|
57
|
+
".bash_logout",
|
|
58
|
+
".profile",
|
|
59
|
+
".zshrc",
|
|
60
|
+
".zshenv",
|
|
61
|
+
".zprofile",
|
|
62
|
+
".zlogin",
|
|
63
|
+
".kshrc",
|
|
64
|
+
".cshrc",
|
|
65
|
+
".tcshrc",
|
|
66
|
+
".inputrc",
|
|
67
|
+
".gitconfig",
|
|
68
|
+
".npmrc",
|
|
69
|
+
".netrc"
|
|
70
|
+
]);
|
|
71
|
+
var AGENT_CONFIG_FILES = {
|
|
72
|
+
".claude": /^settings(?:\..+)?\.json$/,
|
|
73
|
+
".gemini": /^settings\.json$/,
|
|
74
|
+
".qwen": /^settings\.json$/,
|
|
75
|
+
".codex": /^config\.toml$/,
|
|
76
|
+
".cursor": /^(?:mcp|hooks|cli)\.json$/
|
|
77
|
+
};
|
|
78
|
+
function writeDenyReason(resolved, scope) {
|
|
79
|
+
for (const candidate of /* @__PURE__ */ new Set([resolved.real, resolved.absolute])) {
|
|
80
|
+
const segments = candidate.split(path.sep);
|
|
81
|
+
if (segments.includes(".git")) return "writes inside .git are never allowed; use git commands instead";
|
|
82
|
+
const home = realpathNearest(path.resolve(scope.homeDir));
|
|
83
|
+
for (const dir of [".ssh", ".gnupg", ".aws", ".kube", path.join(".config", "gcloud"), path.join(".config", "gh")]) {
|
|
84
|
+
if (isInside(candidate, path.join(home, dir))) return `writes under ~/${dir} are never allowed`;
|
|
85
|
+
}
|
|
86
|
+
const state = realpathNearest(path.resolve(scope.stateDir));
|
|
87
|
+
if (isInside(candidate, state) && !isInside(candidate, path.join(state, "t"))) return "the ClikCode state directory is managed by ClikCode itself";
|
|
88
|
+
const name = path.basename(candidate);
|
|
89
|
+
if (segments.includes(".clikcode") && /^settings(?:\..+)?\.json$/.test(name)) return "ClikCode permission settings can only be changed by the user";
|
|
90
|
+
const config = AGENT_CONFIG_FILES[path.basename(path.dirname(candidate))];
|
|
91
|
+
if (config && config.test(name) || name === ".mcp.json") return `${path.join(path.basename(path.dirname(candidate)), name)} declares hooks, permissions or MCP servers, and can only be changed by the user`;
|
|
92
|
+
const inHomeRoot = path.dirname(candidate) === home;
|
|
93
|
+
if (inHomeRoot && SHELL_RC_FILES.has(name) && !resolved.confined) return `${name} is a shell/credential startup file outside the workspace`;
|
|
94
|
+
if (isInside(candidate, path.join(home, ".config", "fish")) && !resolved.confined) return "fish shell configuration is outside the workspace";
|
|
95
|
+
}
|
|
96
|
+
return void 0;
|
|
97
|
+
}
|
|
98
|
+
function readDenyReason(resolved, scope) {
|
|
99
|
+
const home = realpathNearest(path.resolve(scope.homeDir));
|
|
100
|
+
for (const candidate of /* @__PURE__ */ new Set([resolved.real, resolved.absolute])) {
|
|
101
|
+
for (const dir of [".ssh", ".gnupg", ".aws"]) {
|
|
102
|
+
if (isInside(candidate, path.join(home, dir))) return `reading ~/${dir} is never allowed`;
|
|
103
|
+
}
|
|
104
|
+
const state = realpathNearest(path.resolve(scope.stateDir));
|
|
105
|
+
if (isInside(candidate, state) && !isSessionToolOutput(candidate, scope)) return "the ClikCode state directory is private to ClikCode";
|
|
106
|
+
}
|
|
107
|
+
return void 0;
|
|
108
|
+
}
|
|
109
|
+
function toolOutputDir(stateDir, sessionId) {
|
|
110
|
+
return path.join(stateDir, "sessions", sessionId, "tool-output");
|
|
111
|
+
}
|
|
112
|
+
function isSessionToolOutput(candidate, scope) {
|
|
113
|
+
if (!scope.sessionId) return false;
|
|
114
|
+
const parts = path.relative(realpathNearest(path.resolve(scope.stateDir)), candidate).split(path.sep);
|
|
115
|
+
return parts.length === 4 && parts[0] === "sessions" && parts[1] === scope.sessionId && parts[2] === "tool-output";
|
|
116
|
+
}
|
|
117
|
+
var SCRUBBED_ENV_PATTERN = /(_KEY|_TOKEN|_SECRET)$|_SECRET_|PASSWORD|PASSWD|^CLIKCODE_/i;
|
|
118
|
+
function scrubEnvironment(env) {
|
|
119
|
+
const out = {};
|
|
120
|
+
for (const [key, value] of Object.entries(env)) {
|
|
121
|
+
if (value === void 0 || SCRUBBED_ENV_PATTERN.test(key)) continue;
|
|
122
|
+
out[key] = value;
|
|
123
|
+
}
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
var MASK = "[REDACTED]";
|
|
127
|
+
var URL_CREDENTIAL_RE = /(\b[a-z][a-z0-9+.-]*:\/\/)([^:@/\s]+):([^@/\s]+)@/gi;
|
|
128
|
+
var VALUE_SHAPES = [
|
|
129
|
+
/-----BEGIN(?: [A-Z0-9]+)* PRIVATE KEY-----[\s\S]*?-----END(?: [A-Z0-9]+)* PRIVATE KEY-----/g,
|
|
130
|
+
/\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g,
|
|
131
|
+
/\bgh[pousr]_[A-Za-z0-9]{20,}\b/g,
|
|
132
|
+
/\bgithub_pat_[A-Za-z0-9_]{20,}\b/g,
|
|
133
|
+
/\bxox[abdeoprs]-[A-Za-z0-9-]{10,}\b/g,
|
|
134
|
+
/\b(?:sk|rk)_(?:live|test)_[A-Za-z0-9]{10,}\b/g,
|
|
135
|
+
/\bsk-(?:ant-|proj-)?[A-Za-z0-9_-]{24,}\b/g,
|
|
136
|
+
/\bAIza[0-9A-Za-z_-]{30,}\b/g,
|
|
137
|
+
/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g,
|
|
138
|
+
/\b(Bearer)\s+[A-Za-z0-9._~+/-]{20,}=*/g
|
|
139
|
+
];
|
|
140
|
+
var ASSIGNMENT_RE = /("?\b[A-Za-z0-9_.-]*(?:[-_.]KEY|[-_.]?TOKEN|[-_.]?SECRET|PASSWORD|PASSWD)[A-Za-z0-9_.-]*"?\s*[:=]\s*)("[^"]*"|'[^']*'|[^,\s}]+)/gi;
|
|
141
|
+
function redactSecrets(text) {
|
|
142
|
+
let out = String(text ?? "");
|
|
143
|
+
if (out.includes("@")) out = out.replace(URL_CREDENTIAL_RE, (_match, scheme, user) => `${scheme}${user}:${MASK}@`);
|
|
144
|
+
for (const shape of VALUE_SHAPES) out = out.replace(shape, (match, bearer) => typeof bearer === "string" && match.startsWith("Bearer") ? `Bearer ${MASK}` : MASK);
|
|
145
|
+
return out.replace(ASSIGNMENT_RE, (_match, head) => `${head}${MASK}`);
|
|
146
|
+
}
|
|
147
|
+
var OUTPUT_CAPS = {
|
|
148
|
+
/** Tool output returned to the model. */
|
|
149
|
+
toolOutputBytes: 30 * 1024,
|
|
150
|
+
/** Lines of output attached to an activity event. */
|
|
151
|
+
eventOutputLines: 8,
|
|
152
|
+
eventLineChars: 240,
|
|
153
|
+
readFileLines: 2e3,
|
|
154
|
+
readFileLineChars: 2e3,
|
|
155
|
+
webFetchBytes: 10 * 1024 * 1024,
|
|
156
|
+
webFetchTextChars: 6e4,
|
|
157
|
+
spillFileBytes: 64 * 1024 * 1024
|
|
158
|
+
};
|
|
159
|
+
function capHeadTail(text, maxBytes = OUTPUT_CAPS.toolOutputBytes, note) {
|
|
160
|
+
if (Buffer.byteLength(text, "utf8") <= maxBytes) return { text, truncated: false };
|
|
161
|
+
const half = Math.floor(maxBytes / 2);
|
|
162
|
+
const buffer = Buffer.from(text, "utf8");
|
|
163
|
+
const head = buffer.subarray(0, half).toString("utf8").replace(/�$/, "");
|
|
164
|
+
const tail = buffer.subarray(buffer.length - half).toString("utf8").replace(/^�/, "");
|
|
165
|
+
const dropped = buffer.length - half * 2;
|
|
166
|
+
return { text: `${head}
|
|
167
|
+
|
|
168
|
+
\u2026 [${dropped} bytes truncated${note ? `; ${note}` : ""}] \u2026
|
|
169
|
+
|
|
170
|
+
${tail}`, truncated: true };
|
|
171
|
+
}
|
|
172
|
+
function eventOutputPreview(text) {
|
|
173
|
+
const trimmed = redactSecrets(text).replace(/\r?\n$/, "");
|
|
174
|
+
if (!trimmed.trim()) return void 0;
|
|
175
|
+
const lines = trimmed.split(/\r?\n/);
|
|
176
|
+
const tail = lines.slice(-OUTPUT_CAPS.eventOutputLines).map((line) => line.length > OUTPUT_CAPS.eventLineChars ? `${line.slice(0, OUTPUT_CAPS.eventLineChars)}\u2026` : line);
|
|
177
|
+
return { output: tail, ...lines.length > tail.length ? { outputOmitted: lines.length - tail.length } : {}, outputTail: true };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export {
|
|
181
|
+
realpathNearest,
|
|
182
|
+
resolvePath,
|
|
183
|
+
writeDenyReason,
|
|
184
|
+
readDenyReason,
|
|
185
|
+
toolOutputDir,
|
|
186
|
+
isSessionToolOutput,
|
|
187
|
+
scrubEnvironment,
|
|
188
|
+
redactSecrets,
|
|
189
|
+
OUTPUT_CAPS,
|
|
190
|
+
capHeadTail,
|
|
191
|
+
eventOutputPreview
|
|
192
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
ACTIVE_MS,
|
|
5
|
+
allTabs,
|
|
6
|
+
closeTabsByLabel,
|
|
7
|
+
closeTabsOfOwner,
|
|
8
|
+
describeTabs,
|
|
9
|
+
planTabClosures,
|
|
10
|
+
readTabRecords,
|
|
11
|
+
sweepTabs,
|
|
12
|
+
tabLimits,
|
|
13
|
+
writeTabRecord
|
|
14
|
+
} from "./chunk-AKRYTS2D.js";
|
|
15
|
+
import "./chunk-4GVEJ5FK.js";
|
|
16
|
+
import "./chunk-4L2ZZM4Q.js";
|
|
17
|
+
import "./chunk-F6F47QAY.js";
|
|
18
|
+
import "./chunk-RDDWQBEM.js";
|
|
19
|
+
import "./chunk-MPAJ446F.js";
|
|
20
|
+
import "./chunk-CBANJFBO.js";
|
|
21
|
+
import "./chunk-PWXII6HF.js";
|
|
22
|
+
export {
|
|
23
|
+
ACTIVE_MS,
|
|
24
|
+
allTabs,
|
|
25
|
+
closeTabsByLabel,
|
|
26
|
+
closeTabsOfOwner,
|
|
27
|
+
describeTabs,
|
|
28
|
+
planTabClosures,
|
|
29
|
+
readTabRecords,
|
|
30
|
+
sweepTabs,
|
|
31
|
+
tabLimits,
|
|
32
|
+
writeTabRecord
|
|
33
|
+
};
|