clikcode 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +494 -112923
- package/dist/computer-tools.js +36642 -21259
- 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,235 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
disposeSessionState,
|
|
5
|
+
existingSessionAgents,
|
|
6
|
+
runSessionTurn,
|
|
7
|
+
sessionState
|
|
8
|
+
} from "./chunk-32IKAIZC.js";
|
|
9
|
+
import {
|
|
10
|
+
renderActivityLine
|
|
11
|
+
} from "./chunk-BTJDSTQP.js";
|
|
12
|
+
import {
|
|
13
|
+
emitHarnessOutput
|
|
14
|
+
} from "./chunk-4RHXTL3W.js";
|
|
15
|
+
import {
|
|
16
|
+
turnCancelledError
|
|
17
|
+
} from "./chunk-4LPDG57B.js";
|
|
18
|
+
import {
|
|
19
|
+
WorkerClient
|
|
20
|
+
} from "./chunk-KI5GZFCE.js";
|
|
21
|
+
import {
|
|
22
|
+
cancelOrigin
|
|
23
|
+
} from "./chunk-UBMVADBF.js";
|
|
24
|
+
import {
|
|
25
|
+
COMPACTED,
|
|
26
|
+
COMPACTING,
|
|
27
|
+
isCompactRequest,
|
|
28
|
+
readState
|
|
29
|
+
} from "./chunk-MXS6S2PY.js";
|
|
30
|
+
import {
|
|
31
|
+
writeState
|
|
32
|
+
} from "./chunk-RKUVLRZI.js";
|
|
33
|
+
import {
|
|
34
|
+
consumeSessionTurn,
|
|
35
|
+
sessionTranscriptMessages
|
|
36
|
+
} from "./chunk-FF7ZVYJF.js";
|
|
37
|
+
import {
|
|
38
|
+
textTranscript
|
|
39
|
+
} from "./chunk-3B2CHX7M.js";
|
|
40
|
+
import {
|
|
41
|
+
takeConversation
|
|
42
|
+
} from "./chunk-QUS4ER2W.js";
|
|
43
|
+
import {
|
|
44
|
+
sleep
|
|
45
|
+
} from "./chunk-YMCH3L2S.js";
|
|
46
|
+
import {
|
|
47
|
+
isJsonDefaultMode
|
|
48
|
+
} from "./chunk-5B6TVO4A.js";
|
|
49
|
+
import {
|
|
50
|
+
quiet
|
|
51
|
+
} from "./chunk-RDDWQBEM.js";
|
|
52
|
+
import {
|
|
53
|
+
stateDirectory
|
|
54
|
+
} from "./chunk-MPAJ446F.js";
|
|
55
|
+
|
|
56
|
+
// src/worker/scripted-send.ts
|
|
57
|
+
import { stdout as output } from "node:process";
|
|
58
|
+
async function sendScriptedTurn(config, sessionId, prompt, signal) {
|
|
59
|
+
const text = prompt.trim();
|
|
60
|
+
if (!text) throw new Error("prompt is required");
|
|
61
|
+
let spawnFailed = false;
|
|
62
|
+
for (; ; ) {
|
|
63
|
+
if (signal?.aborted) throw turnCancelledError();
|
|
64
|
+
const client = await WorkerClient.attachExisting(sessionId).catch(quiet("worker/scripted-send")) ?? (spawnFailed ? void 0 : await WorkerClient.attach(sessionId).catch(() => {
|
|
65
|
+
spawnFailed = true;
|
|
66
|
+
return void 0;
|
|
67
|
+
}));
|
|
68
|
+
if (client) {
|
|
69
|
+
try {
|
|
70
|
+
if (await turnThroughWorker(client, sessionId, text, signal)) return;
|
|
71
|
+
} finally {
|
|
72
|
+
client.send({ type: "detach" });
|
|
73
|
+
client.close();
|
|
74
|
+
}
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const taken = await takeConversation(sessionId, "turn");
|
|
78
|
+
if ("hold" in taken) {
|
|
79
|
+
try {
|
|
80
|
+
return await runSessionTurn(config, sessionId, text, signal);
|
|
81
|
+
} finally {
|
|
82
|
+
await settleInProcessWork(sessionId);
|
|
83
|
+
await taken.hold.release();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
await sleep(250);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function turnThroughWorker(client, sessionId, text, signal) {
|
|
90
|
+
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
91
|
+
const compacting = isCompactRequest(text);
|
|
92
|
+
const initial = client.initialEvent;
|
|
93
|
+
let running = initial?.type === "snapshot" && Boolean(initial.live);
|
|
94
|
+
let ours = false;
|
|
95
|
+
let queuedTurnId;
|
|
96
|
+
let failure;
|
|
97
|
+
let stopping = false;
|
|
98
|
+
return new Promise((resolveTurn, rejectTurn) => {
|
|
99
|
+
let settled = false;
|
|
100
|
+
const finish = (settle) => {
|
|
101
|
+
if (settled) return;
|
|
102
|
+
settled = true;
|
|
103
|
+
client.off("event", onEvent);
|
|
104
|
+
client.off("close", onGone);
|
|
105
|
+
signal?.removeEventListener("abort", onAbort);
|
|
106
|
+
settle();
|
|
107
|
+
};
|
|
108
|
+
const dequeue = async () => {
|
|
109
|
+
if (!queuedTurnId) return;
|
|
110
|
+
const state = await readState({ transcripts: [sessionId] });
|
|
111
|
+
const session = state.sessions.find((item) => item.id === sessionId);
|
|
112
|
+
if (session && consumeSessionTurn(session, queuedTurnId)) await writeState(state);
|
|
113
|
+
};
|
|
114
|
+
const sendWhenDue = async () => {
|
|
115
|
+
if (!queuedTurnId || running || ours) return;
|
|
116
|
+
const session = (await readState({ transcripts: [sessionId] })).sessions.find((item) => item.id === sessionId);
|
|
117
|
+
const queue = session?.queuedTurns ?? [];
|
|
118
|
+
if (!queue.some((item) => item.id === queuedTurnId)) {
|
|
119
|
+
finish(() => rejectTurn(new Error("The queued message was removed before it ran.")));
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (queue[0]?.id === queuedTurnId && !running && !ours) client.send({ type: "submit", text, echo: true, queuedTurnId });
|
|
123
|
+
};
|
|
124
|
+
const done = async () => {
|
|
125
|
+
if (failure) {
|
|
126
|
+
finish(() => rejectTurn(failure));
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (stopping) {
|
|
130
|
+
finish(() => rejectTurn(turnCancelledError()));
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const state = await readState({ transcripts: [sessionId] });
|
|
134
|
+
const session = state.sessions.find((item) => item.id === sessionId);
|
|
135
|
+
const answer = session ? textTranscript(sessionTranscriptMessages(session)).at(-1) : void 0;
|
|
136
|
+
const invocation = state.invocations.filter((item) => item.sessionId === sessionId && item.at >= startedAt).at(-1);
|
|
137
|
+
emitHarnessOutput({
|
|
138
|
+
session,
|
|
139
|
+
text: compacting ? COMPACTED : answer?.role === "assistant" ? answer.content : "",
|
|
140
|
+
...invocation ? { invocation } : {},
|
|
141
|
+
...session?.lastUsage ? { usage: session.lastUsage } : {}
|
|
142
|
+
});
|
|
143
|
+
finish(() => resolveTurn(true));
|
|
144
|
+
};
|
|
145
|
+
const onEvent = (event) => {
|
|
146
|
+
switch (event.type) {
|
|
147
|
+
case "submit-queued":
|
|
148
|
+
queuedTurnId = event.queuedTurnId;
|
|
149
|
+
return;
|
|
150
|
+
case "waiting-start":
|
|
151
|
+
running = true;
|
|
152
|
+
if (event.prompt?.trim() === text || compacting && event.message === COMPACTING) ours = true;
|
|
153
|
+
return;
|
|
154
|
+
case "snapshot":
|
|
155
|
+
if (event.live) running = true;
|
|
156
|
+
if (event.live?.prompt?.trim() === text) ours = true;
|
|
157
|
+
return;
|
|
158
|
+
case "activity":
|
|
159
|
+
if (ours && !isJsonDefaultMode()) for (const line of renderActivityLine(event.event)) output.write(`${line}
|
|
160
|
+
`);
|
|
161
|
+
return;
|
|
162
|
+
case "turn-error":
|
|
163
|
+
if (ours) failure = new Error(event.message);
|
|
164
|
+
return;
|
|
165
|
+
case "waiting-stop":
|
|
166
|
+
running = false;
|
|
167
|
+
if (ours) void done().catch((error) => finish(() => rejectTurn(error)));
|
|
168
|
+
else void sendWhenDue().catch((error) => finish(() => rejectTurn(error)));
|
|
169
|
+
return;
|
|
170
|
+
case "queue-changed":
|
|
171
|
+
void sendWhenDue().catch(quiet("worker/scripted-send"));
|
|
172
|
+
return;
|
|
173
|
+
// A script or pipe has no one to answer. The worker waits on each of
|
|
174
|
+
// these for ever (a signed-out amp/aider/devin/mcode send, a goose
|
|
175
|
+
// ask-mode send hung with no output), so each is answered at once:
|
|
176
|
+
// sign-in fails as 'not signed in', an approval is refused, a
|
|
177
|
+
// question is cancelled -- never answered on the user's behalf.
|
|
178
|
+
case "sign-in-request":
|
|
179
|
+
if (ours) client.send({ type: "sign-in-response", id: event.id, outcome: "unavailable", error: `${event.name} is not signed in; run "clikcode accounts login <harness>" in a terminal` });
|
|
180
|
+
return;
|
|
181
|
+
case "approval-request":
|
|
182
|
+
if (ours) {
|
|
183
|
+
(isJsonDefaultMode() ? process.stderr : output).write(`Declined (no one to ask in a script; use --permissions auto or bypass): ${event.title}
|
|
184
|
+
`);
|
|
185
|
+
client.send({ type: "approval-response", id: event.id, approved: false });
|
|
186
|
+
}
|
|
187
|
+
return;
|
|
188
|
+
case "question-request":
|
|
189
|
+
if (ours) {
|
|
190
|
+
(isJsonDefaultMode() ? process.stderr : output).write(`A question was cancelled because a script cannot answer it: ${event.request.title}
|
|
191
|
+
`);
|
|
192
|
+
client.send({ type: "question-response", id: event.id, result: { kind: "cancelled" } });
|
|
193
|
+
}
|
|
194
|
+
return;
|
|
195
|
+
case "submit-rejected":
|
|
196
|
+
if (event.retry && ours) finish(() => rejectTurn(new Error("the conversation's worker was being replaced, so the message was not sent; send it again")));
|
|
197
|
+
return;
|
|
198
|
+
case "shutdown":
|
|
199
|
+
onGone(event.reason);
|
|
200
|
+
return;
|
|
201
|
+
default:
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
const onGone = (reason) => {
|
|
205
|
+
if (ours) {
|
|
206
|
+
finish(() => rejectTurn(new Error(`session worker exited mid-turn${reason ? `: ${reason}` : ': its connection closed with no reason given (see "clikcode logs")'}`)));
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
void dequeue().then(() => finish(() => resolveTurn(false)), (error) => finish(() => rejectTurn(error)));
|
|
210
|
+
};
|
|
211
|
+
const onAbort = () => {
|
|
212
|
+
stopping = true;
|
|
213
|
+
if (ours) {
|
|
214
|
+
client.send({ type: "cancel", restoreDraft: false, origin: cancelOrigin("scripted", "abort-signal") });
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
void dequeue().then(() => finish(() => rejectTurn(turnCancelledError())), (error) => finish(() => rejectTurn(error)));
|
|
218
|
+
};
|
|
219
|
+
client.on("event", onEvent);
|
|
220
|
+
client.on("close", () => onGone());
|
|
221
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
222
|
+
client.send({ type: "submit", text, echo: true });
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
async function settleInProcessWork(sessionId) {
|
|
226
|
+
const agents = existingSessionAgents(sessionState(stateDirectory(), sessionId));
|
|
227
|
+
if (agents?.running()) await Promise.race([agents.stopAll("the command that started it ended and no ClikCode worker could keep it; its work is committed to its branch"), new Promise((resolve) => {
|
|
228
|
+
setTimeout(resolve, 3e4).unref();
|
|
229
|
+
})]);
|
|
230
|
+
disposeSessionState(stateDirectory(), sessionId, "the command that started it ended and no ClikCode worker could keep it");
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export {
|
|
234
|
+
sendScriptedTurn
|
|
235
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
clikDeploySessionServer
|
|
5
|
+
} from "./chunk-7AULZ7OD.js";
|
|
6
|
+
import {
|
|
7
|
+
mcpOAuthProvider,
|
|
8
|
+
mcpOAuthState
|
|
9
|
+
} from "./chunk-UA5K2BTI.js";
|
|
10
|
+
import {
|
|
11
|
+
vendorMcpServerNames
|
|
12
|
+
} from "./chunk-R7QN6ONS.js";
|
|
13
|
+
import {
|
|
14
|
+
loadMcpServers
|
|
15
|
+
} from "./chunk-DQYVQ2N7.js";
|
|
16
|
+
import {
|
|
17
|
+
computerEnabledSync
|
|
18
|
+
} from "./chunk-5SM5UAWN.js";
|
|
19
|
+
import {
|
|
20
|
+
quiet
|
|
21
|
+
} from "./chunk-RDDWQBEM.js";
|
|
22
|
+
import {
|
|
23
|
+
stateDirectory
|
|
24
|
+
} from "./chunk-MPAJ446F.js";
|
|
25
|
+
|
|
26
|
+
// src/harness/transport/acp-mcp-servers.ts
|
|
27
|
+
import { homedir } from "node:os";
|
|
28
|
+
var pairs = (record) => Object.entries(record).map(([name, value]) => ({ name, value }));
|
|
29
|
+
function acpMcpServer(spec, capabilities) {
|
|
30
|
+
if (spec.transport === "stdio") return { name: spec.name, command: spec.command, args: [...spec.args], env: pairs(spec.env) };
|
|
31
|
+
if (!capabilities?.mcpCapabilities?.[spec.transport]) return void 0;
|
|
32
|
+
return { type: spec.transport, name: spec.name, url: spec.url, headers: pairs(spec.headers) };
|
|
33
|
+
}
|
|
34
|
+
var BUILT_IN_MCP_NAME = "clikcode";
|
|
35
|
+
function builtInMcpServer() {
|
|
36
|
+
const entry = process.env.CLIKCODE_MCP_ENTRY || process.argv[1];
|
|
37
|
+
if (!entry || !computerEnabledSync(stateDirectory())) return void 0;
|
|
38
|
+
return { name: BUILT_IN_MCP_NAME, transport: "stdio", command: process.execPath, args: [entry, "mcp-serve"], env: { CLIKCODE_WORKER_PID: String(process.pid) } };
|
|
39
|
+
}
|
|
40
|
+
async function withSignIn(stateDir, spec) {
|
|
41
|
+
if (Object.keys(spec.headers).some((name) => name.toLowerCase() === "authorization")) return spec;
|
|
42
|
+
const state = await mcpOAuthState(stateDir, spec);
|
|
43
|
+
if (state === "none") return spec;
|
|
44
|
+
if (state === "needs-sign-in") return void 0;
|
|
45
|
+
try {
|
|
46
|
+
const authorization = await mcpOAuthProvider(stateDir, spec).authorization();
|
|
47
|
+
return authorization ? { ...spec, headers: { ...spec.headers, Authorization: authorization } } : void 0;
|
|
48
|
+
} catch {
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function globalMcpServers(command, profile, home = homedir(), signIns = true, workspace) {
|
|
53
|
+
try {
|
|
54
|
+
const stateDir = stateDirectory();
|
|
55
|
+
const { servers: recorded } = await loadMcpServers(stateDir);
|
|
56
|
+
const builtIns = [builtInMcpServer(), clikDeploySessionServer()].filter((server) => server !== void 0);
|
|
57
|
+
const servers = [...builtIns.filter((builtIn) => !recorded.some((server) => server.name === builtIn.name)), ...recorded];
|
|
58
|
+
if (!servers.length) return [];
|
|
59
|
+
const { names } = await vendorMcpServerNames(command, home, profile, workspace);
|
|
60
|
+
const wanted = servers.filter((server) => !names.has(server.name));
|
|
61
|
+
const resolved = await Promise.all(wanted.map(async (server) => {
|
|
62
|
+
if (server.transport === "stdio") return server;
|
|
63
|
+
if (!signIns) return await mcpOAuthState(stateDir, server) === "none" ? server : void 0;
|
|
64
|
+
return withSignIn(stateDir, server);
|
|
65
|
+
}).map((pending) => pending.catch(quiet("harness/transport/acp-mcp-servers"))));
|
|
66
|
+
return resolved.filter((server) => server !== void 0);
|
|
67
|
+
} catch {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async function globalMcpServersForAcp(command, capabilities, profile, home = homedir(), workspace) {
|
|
72
|
+
return (await globalMcpServers(command, profile, home, true, workspace)).flatMap((server) => acpMcpServer(server, capabilities) ?? []);
|
|
73
|
+
}
|
|
74
|
+
var tomlKey = (key) => /^[A-Za-z0-9_-]+$/.test(key) ? key : JSON.stringify(key);
|
|
75
|
+
var SECRET_NAME = /KEY|TOKEN|SECRET|PASSWORD|PASSWD|CREDENTIAL|AUTH/i;
|
|
76
|
+
function codexMcpLaunch(servers, inherited = {}) {
|
|
77
|
+
const args = [];
|
|
78
|
+
const env = {};
|
|
79
|
+
for (const server of servers) {
|
|
80
|
+
if (!/^[A-Za-z0-9_-]+$/.test(server.name)) continue;
|
|
81
|
+
const prefix = `mcp_servers.${server.name}`;
|
|
82
|
+
if (server.transport === "stdio") {
|
|
83
|
+
const plain = [];
|
|
84
|
+
const forwarded = [];
|
|
85
|
+
for (const [key, value] of Object.entries(server.env)) {
|
|
86
|
+
const forwardable = SECRET_NAME.test(key) && /^[A-Za-z_][A-Za-z0-9_]*$/.test(key) && (env[key] === void 0 || env[key] === value) && (inherited[key] === void 0 || inherited[key] === value);
|
|
87
|
+
if (forwardable) {
|
|
88
|
+
env[key] = value;
|
|
89
|
+
forwarded.push(JSON.stringify(key));
|
|
90
|
+
} else plain.push(`${tomlKey(key)}=${JSON.stringify(value)}`);
|
|
91
|
+
}
|
|
92
|
+
args.push(
|
|
93
|
+
"-c",
|
|
94
|
+
`${prefix}.command=${JSON.stringify(server.command)}`,
|
|
95
|
+
"-c",
|
|
96
|
+
`${prefix}.args=${JSON.stringify(server.args)}`,
|
|
97
|
+
...plain.length ? ["-c", `${prefix}.env={${plain.join(",")}}`] : [],
|
|
98
|
+
...forwarded.length ? ["-c", `${prefix}.env_vars=[${forwarded.join(",")}]`] : []
|
|
99
|
+
);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (server.transport !== "http") continue;
|
|
103
|
+
args.push("-c", `${prefix}.url=${JSON.stringify(server.url)}`);
|
|
104
|
+
const headers = Object.entries(server.headers).map(([header, value]) => {
|
|
105
|
+
const variable = `CLIKCODE_MCP_SECRET_${Object.keys(env).length}`;
|
|
106
|
+
env[variable] = value;
|
|
107
|
+
return `${tomlKey(header)}=${JSON.stringify(variable)}`;
|
|
108
|
+
});
|
|
109
|
+
if (headers.length) args.push("-c", `${prefix}.env_http_headers={${headers.join(",")}}`);
|
|
110
|
+
}
|
|
111
|
+
return { args, env };
|
|
112
|
+
}
|
|
113
|
+
function ampMcpConfig(servers) {
|
|
114
|
+
return Object.fromEntries(servers.map((server) => [server.name, server.transport === "stdio" ? { command: server.command, args: [...server.args], ...Object.keys(server.env).length ? { env: { ...server.env } } : {} } : { url: server.url, ...Object.keys(server.headers).length ? { headers: { ...server.headers } } : {} }]));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export {
|
|
118
|
+
BUILT_IN_MCP_NAME,
|
|
119
|
+
globalMcpServers,
|
|
120
|
+
globalMcpServersForAcp,
|
|
121
|
+
codexMcpLaunch,
|
|
122
|
+
ampMcpConfig
|
|
123
|
+
};
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
vendorMcpServerNames
|
|
5
|
+
} from "./chunk-R7QN6ONS.js";
|
|
6
|
+
import {
|
|
7
|
+
PROBE_DEADLINE_MS,
|
|
8
|
+
backgroundEnvironment,
|
|
9
|
+
mayRunInBackground,
|
|
10
|
+
resolveBinaryPath
|
|
11
|
+
} from "./chunk-DF35KMXM.js";
|
|
12
|
+
import {
|
|
13
|
+
JsonRpcPeer
|
|
14
|
+
} from "./chunk-IGZ6C2MC.js";
|
|
15
|
+
import {
|
|
16
|
+
spawnPortable
|
|
17
|
+
} from "./chunk-WPB5WEZJ.js";
|
|
18
|
+
import {
|
|
19
|
+
sleep
|
|
20
|
+
} from "./chunk-YMCH3L2S.js";
|
|
21
|
+
import {
|
|
22
|
+
lifecycle,
|
|
23
|
+
quiet
|
|
24
|
+
} from "./chunk-RDDWQBEM.js";
|
|
25
|
+
import {
|
|
26
|
+
stateDirectory
|
|
27
|
+
} from "./chunk-MPAJ446F.js";
|
|
28
|
+
|
|
29
|
+
// src/harness/accounts/acp-query.ts
|
|
30
|
+
import { randomBytes } from "node:crypto";
|
|
31
|
+
import { mkdir } from "node:fs/promises";
|
|
32
|
+
import { homedir } from "node:os";
|
|
33
|
+
import { join } from "node:path";
|
|
34
|
+
|
|
35
|
+
// src/harness/accounts/discovery-cleanup.ts
|
|
36
|
+
import { rm } from "node:fs/promises";
|
|
37
|
+
import { relative, resolve, isAbsolute } from "node:path";
|
|
38
|
+
async function discoveryCleanup(harness, environment) {
|
|
39
|
+
const { nativeSessionStore } = await import("./chunk-AMNSE36L.js");
|
|
40
|
+
const store = nativeSessionStore(harness);
|
|
41
|
+
if (store?.remove) return (id, cwd) => store.remove(id, cwd, environment);
|
|
42
|
+
const root = store?.root(environment);
|
|
43
|
+
if (!store?.locate || !root) return void 0;
|
|
44
|
+
return async (id, cwd) => {
|
|
45
|
+
const found = await store.locate(root, id, cwd, environment);
|
|
46
|
+
if (!found) return;
|
|
47
|
+
const within = relative(resolve(root), resolve(found.path));
|
|
48
|
+
if (!within || within.startsWith("..") || isAbsolute(within)) throw new Error("Probe session is outside its vendor store");
|
|
49
|
+
await rm(found.path, { recursive: true, force: true });
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/harness/transport/process-group.ts
|
|
54
|
+
import { execFile } from "node:child_process";
|
|
55
|
+
import { readdir, readFile, readlink, stat } from "node:fs/promises";
|
|
56
|
+
import { basename } from "node:path";
|
|
57
|
+
async function processGroup(pgid, platform = process.platform) {
|
|
58
|
+
return await readProcessGroup(pgid, platform) ?? /* @__PURE__ */ new Map();
|
|
59
|
+
}
|
|
60
|
+
async function readProcessGroup(pgid, platform = process.platform) {
|
|
61
|
+
const members = /* @__PURE__ */ new Map();
|
|
62
|
+
if (platform === "win32" || !Number.isInteger(pgid) || pgid <= 1) return members;
|
|
63
|
+
if (platform === "linux") {
|
|
64
|
+
const entries = await readdir("/proc").catch(quiet("harness/transport/process-group"));
|
|
65
|
+
if (!entries) return void 0;
|
|
66
|
+
await Promise.all(entries.filter((name) => /^\d+$/.test(name)).map(async (name) => {
|
|
67
|
+
const stat2 = await readFile(`/proc/${name}/stat`, "utf8").catch(quiet("harness/transport/process-group"));
|
|
68
|
+
if (!stat2) return;
|
|
69
|
+
const close = stat2.lastIndexOf(")");
|
|
70
|
+
const fields = stat2.slice(close + 2).split(" ");
|
|
71
|
+
if (fields[0] !== "Z" && Number(fields[2]) === pgid) {
|
|
72
|
+
members.set(Number(name), { ppid: Number(fields[1]), name: stat2.slice(stat2.indexOf("(") + 1, close) });
|
|
73
|
+
}
|
|
74
|
+
}));
|
|
75
|
+
return members;
|
|
76
|
+
}
|
|
77
|
+
return new Promise((resolve2) => {
|
|
78
|
+
execFile("ps", ["-A", "-o", "pid=,ppid=,pgid=,stat=,comm="], { timeout: 5e3 }, (error, stdout) => {
|
|
79
|
+
if (error) {
|
|
80
|
+
resolve2(void 0);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
for (const line of stdout.split("\n")) {
|
|
84
|
+
const [pid, ppid, group, state, ...command] = line.trim().split(/\s+/);
|
|
85
|
+
if (Number(group) === pgid && !state?.startsWith("Z")) members.set(Number(pid), { ppid: Number(ppid), name: basename(command.join(" ")) });
|
|
86
|
+
}
|
|
87
|
+
resolve2(members);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
async function processGroupMembers(pgid, platform = process.platform) {
|
|
92
|
+
return new Set((await processGroup(pgid, platform)).keys());
|
|
93
|
+
}
|
|
94
|
+
var SHELLS = /* @__PURE__ */ new Set(["sh", "bash", "zsh", "dash", "ash", "ksh", "mksh", "fish", "tcsh", "csh", "pwsh"]);
|
|
95
|
+
function isShellName(name) {
|
|
96
|
+
return SHELLS.has(name.replace(/^-/, ""));
|
|
97
|
+
}
|
|
98
|
+
function toolCallWork(group, root, candidates) {
|
|
99
|
+
const work = /* @__PURE__ */ new Set();
|
|
100
|
+
for (const pid of candidates) {
|
|
101
|
+
if (pid === root || !group.has(pid)) continue;
|
|
102
|
+
const seen = /* @__PURE__ */ new Set([pid]);
|
|
103
|
+
for (let parent = group.get(pid).ppid; ; parent = group.get(parent).ppid) {
|
|
104
|
+
if (parent === root) break;
|
|
105
|
+
const above = group.get(parent);
|
|
106
|
+
if (!above) {
|
|
107
|
+
work.add(pid);
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
if (seen.has(parent)) break;
|
|
111
|
+
if (candidates.has(parent) && isShellName(above.name) && (above.ppid === root || group.get(above.ppid)?.ppid === root)) {
|
|
112
|
+
work.add(pid);
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
seen.add(parent);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return work;
|
|
119
|
+
}
|
|
120
|
+
function commandRoots(group, candidates, work) {
|
|
121
|
+
const roots = /* @__PURE__ */ new Set();
|
|
122
|
+
for (const pid of work) {
|
|
123
|
+
let top = pid;
|
|
124
|
+
const seen = /* @__PURE__ */ new Set([pid]);
|
|
125
|
+
for (let parent = group.get(pid)?.ppid; parent !== void 0 && group.has(parent) && !seen.has(parent); parent = group.get(parent)?.ppid) {
|
|
126
|
+
seen.add(parent);
|
|
127
|
+
if (candidates.has(parent) && isShellName(group.get(parent).name)) top = parent;
|
|
128
|
+
}
|
|
129
|
+
roots.add(top);
|
|
130
|
+
}
|
|
131
|
+
return roots;
|
|
132
|
+
}
|
|
133
|
+
async function commandLine(pid, platform = process.platform) {
|
|
134
|
+
if (platform !== "linux") return void 0;
|
|
135
|
+
const raw = await readFile(`/proc/${pid}/cmdline`, "utf8").catch(quiet("harness/transport/process-group"));
|
|
136
|
+
if (!raw) return void 0;
|
|
137
|
+
const argv = raw.split("\0").filter(Boolean);
|
|
138
|
+
const script = argv.findIndex((arg) => arg === "-c" || /^-\w*c$/.test(arg));
|
|
139
|
+
const text = script >= 0 && argv[script + 1] ? argv[script + 1] : argv.join(" ");
|
|
140
|
+
const wrapped = /\beval '((?:[^']|'\\'')*)'/.exec(text)?.[1];
|
|
141
|
+
return (wrapped !== void 0 ? wrapped.replace(/'\\''/g, "'") : text).trim() || void 0;
|
|
142
|
+
}
|
|
143
|
+
async function outputFile(pid, platform = process.platform) {
|
|
144
|
+
if (platform !== "linux") return void 0;
|
|
145
|
+
const target = await readlink(`/proc/${pid}/fd/1`).catch(quiet("harness/transport/process-group"));
|
|
146
|
+
return target?.startsWith("/") && !target.startsWith("/dev/") && !target.startsWith("/proc/") ? target.replace(/ \(deleted\)$/, "") : void 0;
|
|
147
|
+
}
|
|
148
|
+
async function processesWithEnvironment(name, value, platform = process.platform) {
|
|
149
|
+
if (platform !== "linux") return [];
|
|
150
|
+
const needle = `\0${name}=${value}\0`;
|
|
151
|
+
const uid = process.getuid?.();
|
|
152
|
+
const entries = await readdir("/proc").catch(() => []);
|
|
153
|
+
const found = [];
|
|
154
|
+
await Promise.all(entries.filter((entry) => /^\d+$/.test(entry) && Number(entry) !== process.pid).map(async (entry) => {
|
|
155
|
+
if (uid !== void 0 && uid !== 0) {
|
|
156
|
+
const owner = await stat(`/proc/${entry}`).catch(quiet("harness/transport/process-group"));
|
|
157
|
+
if (!owner || owner.uid !== uid) return;
|
|
158
|
+
}
|
|
159
|
+
const environment = await readFile(`/proc/${entry}/environ`, "latin1").catch((error) => {
|
|
160
|
+
if (error.code !== "EACCES" && error.code !== "EPERM") quiet("harness/transport/process-group")(error);
|
|
161
|
+
return void 0;
|
|
162
|
+
});
|
|
163
|
+
if (environment && `\0${environment}`.includes(needle)) found.push(Number(entry));
|
|
164
|
+
}));
|
|
165
|
+
return found;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// src/harness/accounts/acp-query.ts
|
|
169
|
+
async function queryAcp(binary, argv, environment, ask, timeoutMs, options) {
|
|
170
|
+
timeoutMs ??= PROBE_DEADLINE_MS;
|
|
171
|
+
if (options.signal?.aborted) return void 0;
|
|
172
|
+
if (!await mayRunInBackground(options.gate, environment)) return void 0;
|
|
173
|
+
const executable = await resolveBinaryPath(binary);
|
|
174
|
+
if (!executable) return void 0;
|
|
175
|
+
const detached = process.platform !== "win32";
|
|
176
|
+
const tag = randomBytes(8).toString("hex");
|
|
177
|
+
const keyring = "inert" in options.gate ? Boolean(options.gate.keyring) : Boolean(options.gate.keyringAuth);
|
|
178
|
+
const child = spawnPortable(executable, [...argv], {
|
|
179
|
+
env: { ...backgroundEnvironment(environment, { keyring }), [QUERY_TAG]: tag },
|
|
180
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
181
|
+
detached,
|
|
182
|
+
windowsHide: true,
|
|
183
|
+
...options.cwd ? { cwd: options.cwd } : {}
|
|
184
|
+
});
|
|
185
|
+
child.once("error", () => void 0);
|
|
186
|
+
const peer = new JsonRpcPeer(child, { label: `${binary} ACP`, detached, forwardParentSignals: false, onNotification: options.onNotification });
|
|
187
|
+
const signal = options.signal;
|
|
188
|
+
let closing;
|
|
189
|
+
const close = () => closing ??= peer.shutdown({ graceMs: 500, killMs: 1e3 }).catch(quiet("harness/accounts/acp-query"));
|
|
190
|
+
const abort = () => {
|
|
191
|
+
void close();
|
|
192
|
+
};
|
|
193
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
194
|
+
const deadline = setTimeout(abort, timeoutMs);
|
|
195
|
+
deadline.unref();
|
|
196
|
+
let capabilities = {};
|
|
197
|
+
let remove;
|
|
198
|
+
const created = /* @__PURE__ */ new Map();
|
|
199
|
+
const request = async (method, params = {}) => {
|
|
200
|
+
if (method === "session/new") {
|
|
201
|
+
if (!options.discovery) throw new Error("Metadata sessions need an owned cleanup lifecycle");
|
|
202
|
+
if (!capabilities.sessionCapabilities?.delete) {
|
|
203
|
+
remove ??= await discoveryCleanup(options.discovery, environment);
|
|
204
|
+
if (!remove) throw new Error("This vendor cannot clean up a metadata session");
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const result = await peer.request(method, params, { timeoutMs });
|
|
208
|
+
if (method === "session/new" && typeof result.sessionId === "string") created.set(result.sessionId, String(params.cwd ?? ""));
|
|
209
|
+
return result;
|
|
210
|
+
};
|
|
211
|
+
try {
|
|
212
|
+
if (signal?.aborted) return void 0;
|
|
213
|
+
const initialized = await request("initialize", { protocolVersion: 1, clientCapabilities: {} });
|
|
214
|
+
capabilities = initialized.agentCapabilities ?? {};
|
|
215
|
+
return await ask(request, capabilities);
|
|
216
|
+
} catch {
|
|
217
|
+
return void 0;
|
|
218
|
+
} finally {
|
|
219
|
+
clearTimeout(deadline);
|
|
220
|
+
signal?.removeEventListener("abort", abort);
|
|
221
|
+
if (capabilities.sessionCapabilities?.delete && !peer.closed) {
|
|
222
|
+
for (const id of created.keys()) {
|
|
223
|
+
try {
|
|
224
|
+
await peer.request("session/delete", { sessionId: id }, { timeoutMs: 1e3 });
|
|
225
|
+
created.delete(id);
|
|
226
|
+
} catch {
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
await close();
|
|
231
|
+
await stopEscaped(tag).catch(quiet("harness/accounts/acp-query"));
|
|
232
|
+
for (const [id, cwd] of created) {
|
|
233
|
+
try {
|
|
234
|
+
if (!remove && options.discovery) remove = await discoveryCleanup(options.discovery, environment);
|
|
235
|
+
if (!remove) throw new Error("No local cleanup after the vendor delete failed");
|
|
236
|
+
await remove(id, cwd);
|
|
237
|
+
} catch {
|
|
238
|
+
lifecycle("vendor.discovery-cleanup-failed", { harness: options.discovery?.command });
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
var QUERY_TAG = "CLIKCODE_ACP_QUERY";
|
|
244
|
+
async function stopEscaped(tag) {
|
|
245
|
+
const signal = (pids, name) => {
|
|
246
|
+
for (const pid of pids) {
|
|
247
|
+
try {
|
|
248
|
+
process.kill(pid, name);
|
|
249
|
+
} catch {
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
const escaped = await processesWithEnvironment(QUERY_TAG, tag);
|
|
254
|
+
if (!escaped.length) return;
|
|
255
|
+
signal(escaped, "SIGTERM");
|
|
256
|
+
await sleep(1e3);
|
|
257
|
+
signal(await processesWithEnvironment(QUERY_TAG, tag), "SIGKILL");
|
|
258
|
+
}
|
|
259
|
+
function acpDiscoveryDirectory() {
|
|
260
|
+
return join(stateDirectory(), "model-discovery");
|
|
261
|
+
}
|
|
262
|
+
async function acpDiscoverySession(request) {
|
|
263
|
+
const cwd = acpDiscoveryDirectory();
|
|
264
|
+
await mkdir(cwd, { recursive: true });
|
|
265
|
+
return request("session/new", { cwd, mcpServers: [] });
|
|
266
|
+
}
|
|
267
|
+
function acpSessionModels(result) {
|
|
268
|
+
const available = Array.isArray(result?.models?.availableModels) ? result.models.availableModels : [];
|
|
269
|
+
const models = [];
|
|
270
|
+
const labels = {};
|
|
271
|
+
for (const entry of available) {
|
|
272
|
+
const { modelId, name } = entry ?? {};
|
|
273
|
+
if (typeof modelId !== "string" || !modelId) continue;
|
|
274
|
+
models.push(modelId);
|
|
275
|
+
if (typeof name === "string" && name && name !== modelId) labels[modelId] = name;
|
|
276
|
+
}
|
|
277
|
+
const current = typeof result?.models?.currentModelId === "string" ? result.models.currentModelId : void 0;
|
|
278
|
+
const modelOption = Array.isArray(result?.configOptions) ? result.configOptions.find((option) => (option?.id ?? option?.configId) === "model") : void 0;
|
|
279
|
+
if (models.length === 0 && Array.isArray(modelOption?.options)) {
|
|
280
|
+
for (const option of modelOption.options) {
|
|
281
|
+
if (typeof option?.value !== "string" || !option.value) continue;
|
|
282
|
+
models.push(option.value);
|
|
283
|
+
if (typeof option.name === "string" && option.name && option.name !== option.value) labels[option.value] = option.name;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
const configured = typeof modelOption?.currentValue === "string" && modelOption.currentValue ? modelOption.currentValue : void 0;
|
|
287
|
+
return { models, labels, ...current ?? configured ? { current: current ?? configured } : {} };
|
|
288
|
+
}
|
|
289
|
+
function acpConfigOptionValues(result, configId) {
|
|
290
|
+
const option = Array.isArray(result?.configOptions) ? result.configOptions.find((entry) => (entry?.id ?? entry?.configId) === configId) : void 0;
|
|
291
|
+
const values = [];
|
|
292
|
+
const visit = (entries) => {
|
|
293
|
+
if (!Array.isArray(entries)) return;
|
|
294
|
+
for (const entry of entries) {
|
|
295
|
+
if (Array.isArray(entry?.options)) visit(entry.options);
|
|
296
|
+
else if (typeof entry?.value === "string" && entry.value && !values.includes(entry.value)) values.push(entry.value);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
visit(option?.options);
|
|
300
|
+
return values;
|
|
301
|
+
}
|
|
302
|
+
async function acpProbeArgv(harness, account, home = homedir()) {
|
|
303
|
+
const fixed = [...harness.acp?.probeArgv ?? []];
|
|
304
|
+
const prefix = harness.acp?.probeDisableMcpPrefix;
|
|
305
|
+
if (!prefix?.length) return fixed;
|
|
306
|
+
const profile = account?.nativeProfile ? { env: account.nativeProfile.env, path: account.nativeProfile.path } : void 0;
|
|
307
|
+
const { names } = await vendorMcpServerNames(harness.command, home, profile);
|
|
308
|
+
return [...fixed, ...[...names].sort().flatMap((name) => [...prefix, name])];
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export {
|
|
312
|
+
processGroup,
|
|
313
|
+
readProcessGroup,
|
|
314
|
+
processGroupMembers,
|
|
315
|
+
toolCallWork,
|
|
316
|
+
commandRoots,
|
|
317
|
+
commandLine,
|
|
318
|
+
outputFile,
|
|
319
|
+
queryAcp,
|
|
320
|
+
acpDiscoveryDirectory,
|
|
321
|
+
acpDiscoverySession,
|
|
322
|
+
acpSessionModels,
|
|
323
|
+
acpConfigOptionValues,
|
|
324
|
+
acpProbeArgv
|
|
325
|
+
};
|