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,31 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
quiet
|
|
5
|
+
} from "./chunk-RDDWQBEM.js";
|
|
6
|
+
|
|
7
|
+
// src/agent/headless/activity.ts
|
|
8
|
+
import { appendFile, readFile } from "node:fs/promises";
|
|
9
|
+
var ACTIVITY_ENV = "CLIKCODE_AGENT_ACTIVITY";
|
|
10
|
+
var MAX_CALLS_ENV = "CLIKCODE_AGENT_MAX_CALLS";
|
|
11
|
+
function parseActivity(text) {
|
|
12
|
+
let started = 0, finished = 0;
|
|
13
|
+
for (const ch of text) {
|
|
14
|
+
if (ch === "+") started++;
|
|
15
|
+
else if (ch === ".") finished++;
|
|
16
|
+
}
|
|
17
|
+
return { started, finished, inFlight: started > finished };
|
|
18
|
+
}
|
|
19
|
+
async function readActivity(file) {
|
|
20
|
+
return parseActivity(await readFile(file, "utf8").catch(() => ""));
|
|
21
|
+
}
|
|
22
|
+
async function markActivity(file, mark) {
|
|
23
|
+
if (file) await appendFile(file, mark).catch(quiet("agent/headless/activity"));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
ACTIVITY_ENV,
|
|
28
|
+
MAX_CALLS_ENV,
|
|
29
|
+
readActivity,
|
|
30
|
+
markActivity
|
|
31
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
BROWSER_CHANNELS,
|
|
5
|
+
NoBrowserError,
|
|
6
|
+
VIRTUAL_DISPLAY_ENV,
|
|
7
|
+
desktopSession,
|
|
8
|
+
hostStatusFile,
|
|
9
|
+
installChromium,
|
|
10
|
+
installMarkerFile,
|
|
11
|
+
installingMessage,
|
|
12
|
+
launchComputerBrowser,
|
|
13
|
+
launchFirst,
|
|
14
|
+
liveHostStatus,
|
|
15
|
+
noBrowserMessage,
|
|
16
|
+
progressLine,
|
|
17
|
+
readHostStatus,
|
|
18
|
+
remoteSession,
|
|
19
|
+
shouldRunHeadless,
|
|
20
|
+
writeHostStatus
|
|
21
|
+
} from "./chunk-CAADDF6M.js";
|
|
22
|
+
import "./chunk-G3QP67Z7.js";
|
|
23
|
+
import "./chunk-4L2ZZM4Q.js";
|
|
24
|
+
import "./chunk-F6F47QAY.js";
|
|
25
|
+
import "./chunk-RDDWQBEM.js";
|
|
26
|
+
import "./chunk-MPAJ446F.js";
|
|
27
|
+
import "./chunk-CBANJFBO.js";
|
|
28
|
+
import "./chunk-PWXII6HF.js";
|
|
29
|
+
export {
|
|
30
|
+
BROWSER_CHANNELS,
|
|
31
|
+
NoBrowserError,
|
|
32
|
+
VIRTUAL_DISPLAY_ENV,
|
|
33
|
+
desktopSession,
|
|
34
|
+
hostStatusFile,
|
|
35
|
+
installChromium,
|
|
36
|
+
installMarkerFile,
|
|
37
|
+
installingMessage,
|
|
38
|
+
launchComputerBrowser,
|
|
39
|
+
launchFirst,
|
|
40
|
+
liveHostStatus,
|
|
41
|
+
noBrowserMessage,
|
|
42
|
+
progressLine,
|
|
43
|
+
readHostStatus,
|
|
44
|
+
remoteSession,
|
|
45
|
+
shouldRunHeadless,
|
|
46
|
+
writeHostStatus
|
|
47
|
+
};
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
CLIKDEPLOY_CORE_TOOLS,
|
|
5
|
+
PERMISSION_MODE_HEADER
|
|
6
|
+
} from "./chunk-WZMLH3XP.js";
|
|
7
|
+
import {
|
|
8
|
+
openTransport
|
|
9
|
+
} from "./chunk-GLY7RM3C.js";
|
|
10
|
+
import {
|
|
11
|
+
clikDeployConnection
|
|
12
|
+
} from "./chunk-7AULZ7OD.js";
|
|
13
|
+
import "./chunk-UA5K2BTI.js";
|
|
14
|
+
import "./chunk-2OLS7V66.js";
|
|
15
|
+
import "./chunk-2QWPQRSU.js";
|
|
16
|
+
import "./chunk-IS4USJPY.js";
|
|
17
|
+
import "./chunk-2BBELGHY.js";
|
|
18
|
+
import "./chunk-QYHI3YET.js";
|
|
19
|
+
import "./chunk-4LPDG57B.js";
|
|
20
|
+
import "./chunk-TQDM7S5N.js";
|
|
21
|
+
import "./chunk-TQDKJHWX.js";
|
|
22
|
+
import "./chunk-GQBZU6EO.js";
|
|
23
|
+
import "./chunk-PEWCDI2C.js";
|
|
24
|
+
import "./chunk-TULAXS77.js";
|
|
25
|
+
import "./chunk-NWEYRBWK.js";
|
|
26
|
+
import "./chunk-CRUVYGO2.js";
|
|
27
|
+
import "./chunk-DQYVQ2N7.js";
|
|
28
|
+
import "./chunk-IGZ6C2MC.js";
|
|
29
|
+
import "./chunk-4NN3XQQT.js";
|
|
30
|
+
import "./chunk-WPB5WEZJ.js";
|
|
31
|
+
import "./chunk-GYMAI5NY.js";
|
|
32
|
+
import "./chunk-XIBYREEY.js";
|
|
33
|
+
import "./chunk-YMCH3L2S.js";
|
|
34
|
+
import "./chunk-NAOX3JUB.js";
|
|
35
|
+
import "./chunk-GGYKY4GF.js";
|
|
36
|
+
import {
|
|
37
|
+
untilInputEnds
|
|
38
|
+
} from "./chunk-4R6CSC3S.js";
|
|
39
|
+
import "./chunk-PAXYQZH7.js";
|
|
40
|
+
import "./chunk-4L2ZZM4Q.js";
|
|
41
|
+
import "./chunk-F6F47QAY.js";
|
|
42
|
+
import {
|
|
43
|
+
quiet
|
|
44
|
+
} from "./chunk-RDDWQBEM.js";
|
|
45
|
+
import "./chunk-MPAJ446F.js";
|
|
46
|
+
import "./chunk-CBANJFBO.js";
|
|
47
|
+
import "./chunk-PWXII6HF.js";
|
|
48
|
+
|
|
49
|
+
// src/commands/clikdeploy-mcp-serve.ts
|
|
50
|
+
import { createInterface } from "node:readline";
|
|
51
|
+
var AREA = "commands/clikdeploy-mcp-serve";
|
|
52
|
+
var CLIKDEPLOY_TOOL_PREFIX = "clikdeploy_";
|
|
53
|
+
var VERSIONS = ["2025-06-18", "2025-03-26", "2024-11-05"];
|
|
54
|
+
var MODES = /* @__PURE__ */ new Set(["ask", "auto", "bypass"]);
|
|
55
|
+
var LIST_WAIT_MS = 8e3;
|
|
56
|
+
var CALL_WAIT_MS = 10 * 6e4;
|
|
57
|
+
var SIGN_IN_AGAIN = "ClikDeploy refused the saved sign-in (it expired or was revoked). Sign in again with `clikdeploy login` or `clikcode gateway login`; the ClikDeploy tools use the new sign-in on their next call.";
|
|
58
|
+
var FALLBACK_TOOLS = [
|
|
59
|
+
{
|
|
60
|
+
name: "search_tools",
|
|
61
|
+
description: "Search ClikDeploy's tools (platform actions and the actions of each connected connector, e.g. Gmail) by what you want to do. Returns tool names and their arguments for call_tool.",
|
|
62
|
+
inputSchema: { type: "object", properties: { query: { type: "string", description: "What you want to do." } }, required: ["query"] }
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: "call_tool",
|
|
66
|
+
description: "Run a ClikDeploy tool found with search_tools, by its exact name.",
|
|
67
|
+
inputSchema: { type: "object", properties: { name: { type: "string" }, arguments: { type: "object" } }, required: ["name"] }
|
|
68
|
+
}
|
|
69
|
+
];
|
|
70
|
+
async function chatPermissionMode(env = process.env) {
|
|
71
|
+
const workerPid = Number(env.CLIKCODE_WORKER_PID);
|
|
72
|
+
if (Number.isSafeInteger(workerPid) && workerPid > 0) {
|
|
73
|
+
try {
|
|
74
|
+
const { listWorkerRecords } = await import("./chunk-SYVHIYQT.js");
|
|
75
|
+
const sessionId = (await listWorkerRecords()).find((record) => record.pid === workerPid)?.sessionId;
|
|
76
|
+
if (sessionId) {
|
|
77
|
+
const { readState } = await import("./chunk-5NQ5FFMX.js");
|
|
78
|
+
const mode = (await readState({ transcripts: [] })).sessions.find((session) => session.id === sessionId)?.permissionMode;
|
|
79
|
+
if (mode && MODES.has(mode)) return mode;
|
|
80
|
+
}
|
|
81
|
+
} catch {
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const fromTurn = env.CLIKDEPLOY_PERMISSION_MODE;
|
|
85
|
+
return fromTurn && MODES.has(fromTurn) ? fromTurn : void 0;
|
|
86
|
+
}
|
|
87
|
+
var refusedSignIn = (error) => /HTTP 40[13]\b/.test(error instanceof Error ? error.message : String(error));
|
|
88
|
+
function createClikDeployProxy(options = {}) {
|
|
89
|
+
const connect = options.connection ?? (() => clikDeployConnection());
|
|
90
|
+
const permissionMode = options.permissionMode ?? (() => chatPermissionMode());
|
|
91
|
+
let upstream;
|
|
92
|
+
async function open() {
|
|
93
|
+
const connection = connect();
|
|
94
|
+
if (!upstream || upstream.transport.closed || upstream.key !== connection.key || upstream.url !== connection.url) {
|
|
95
|
+
void upstream?.transport.close().catch(quiet(AREA));
|
|
96
|
+
const headers = { authorization: `Bearer ${connection.key}` };
|
|
97
|
+
const transport = openTransport({ name: "clikdeploy", transport: "http", url: `${connection.url}/mcp?toolmode=search`, headers }, {});
|
|
98
|
+
const ready = (async () => {
|
|
99
|
+
const initialized = await transport.request("initialize", { protocolVersion: VERSIONS[0], capabilities: {}, clientInfo: { name: "clikcode", version: "1" } }, { timeoutMs: LIST_WAIT_MS });
|
|
100
|
+
if (typeof initialized.protocolVersion === "string") transport.setProtocolVersion(initialized.protocolVersion);
|
|
101
|
+
transport.notify("notifications/initialized");
|
|
102
|
+
})();
|
|
103
|
+
upstream = { transport, headers, key: connection.key, url: connection.url, ready };
|
|
104
|
+
}
|
|
105
|
+
const current = upstream;
|
|
106
|
+
try {
|
|
107
|
+
await current.ready;
|
|
108
|
+
} catch (error) {
|
|
109
|
+
if (upstream === current) upstream = void 0;
|
|
110
|
+
void current.transport.close().catch(quiet(AREA));
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
return { transport: current.transport, connection, headers: current.headers };
|
|
114
|
+
}
|
|
115
|
+
async function prepare(headers, connection) {
|
|
116
|
+
const token = connection.config.get("adminMfaToken");
|
|
117
|
+
if (typeof token === "string" && token) headers["x-admin-mfa"] = token;
|
|
118
|
+
else delete headers["x-admin-mfa"];
|
|
119
|
+
const mode = await permissionMode().catch(quiet(AREA));
|
|
120
|
+
if (mode) headers[PERMISSION_MODE_HEADER] = mode;
|
|
121
|
+
else delete headers[PERMISSION_MODE_HEADER];
|
|
122
|
+
}
|
|
123
|
+
async function listTools() {
|
|
124
|
+
try {
|
|
125
|
+
const { transport, connection, headers } = await open();
|
|
126
|
+
await prepare(headers, connection);
|
|
127
|
+
const listed = await transport.request("tools/list", {}, { timeoutMs: LIST_WAIT_MS });
|
|
128
|
+
const tools = Array.isArray(listed.tools) ? listed.tools : [];
|
|
129
|
+
const core = tools.filter((tool) => CLIKDEPLOY_CORE_TOOLS.includes(String(tool.name)));
|
|
130
|
+
const missing = FALLBACK_TOOLS.filter((fallback) => !core.some((tool) => tool.name === fallback.name));
|
|
131
|
+
return [...core, ...missing];
|
|
132
|
+
} catch {
|
|
133
|
+
return [...FALLBACK_TOOLS];
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
async function callTool(name, args) {
|
|
137
|
+
const text = (message) => ({ content: [{ type: "text", text: message }], isError: true });
|
|
138
|
+
try {
|
|
139
|
+
connect();
|
|
140
|
+
} catch (error) {
|
|
141
|
+
return text(error instanceof Error ? error.message : String(error));
|
|
142
|
+
}
|
|
143
|
+
for (let attempt = 0; ; attempt++) {
|
|
144
|
+
try {
|
|
145
|
+
const opened = await open();
|
|
146
|
+
await prepare(opened.headers, opened.connection);
|
|
147
|
+
return await opened.transport.request("tools/call", { name, arguments: args }, { timeoutMs: CALL_WAIT_MS });
|
|
148
|
+
} catch (error) {
|
|
149
|
+
if (refusedSignIn(error)) return text(SIGN_IN_AGAIN);
|
|
150
|
+
if (attempt === 0 && upstream?.transport.closed !== false) {
|
|
151
|
+
upstream = void 0;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
return text(`ClikDeploy could not run ${name}: ${error instanceof Error ? error.message : String(error)}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return async (message) => {
|
|
159
|
+
if (message.id === void 0) return void 0;
|
|
160
|
+
const reply = (result) => ({ jsonrpc: "2.0", id: message.id, result });
|
|
161
|
+
switch (message.method) {
|
|
162
|
+
case "initialize": {
|
|
163
|
+
const asked = String(message.params?.protocolVersion ?? "");
|
|
164
|
+
return reply({ protocolVersion: VERSIONS.includes(asked) ? asked : VERSIONS[0], capabilities: { tools: {} }, serverInfo: { name: "clikdeploy", version: "1" } });
|
|
165
|
+
}
|
|
166
|
+
case "ping":
|
|
167
|
+
return reply({});
|
|
168
|
+
case "tools/list":
|
|
169
|
+
return reply({ tools: (await listTools()).map((tool) => ({ ...tool, name: `${CLIKDEPLOY_TOOL_PREFIX}${String(tool.name)}` })) });
|
|
170
|
+
case "tools/call": {
|
|
171
|
+
const called = String(message.params?.name ?? "");
|
|
172
|
+
if (!called.startsWith(CLIKDEPLOY_TOOL_PREFIX)) return { jsonrpc: "2.0", id: message.id, error: { code: -32602, message: `Unknown tool "${called}".` } };
|
|
173
|
+
return reply(await callTool(called.slice(CLIKDEPLOY_TOOL_PREFIX.length), message.params?.arguments ?? {}));
|
|
174
|
+
}
|
|
175
|
+
default:
|
|
176
|
+
return { jsonrpc: "2.0", id: message.id, error: { code: -32601, message: `Method not found: ${message.method}` } };
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
async function clikDeployMcpServe(signal) {
|
|
181
|
+
const handle = createClikDeployProxy();
|
|
182
|
+
const lines = createInterface({ input: process.stdin });
|
|
183
|
+
const pending = /* @__PURE__ */ new Set();
|
|
184
|
+
lines.on("line", (line) => {
|
|
185
|
+
if (!line.trim()) return;
|
|
186
|
+
let message;
|
|
187
|
+
try {
|
|
188
|
+
message = JSON.parse(line);
|
|
189
|
+
} catch {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const work = handle(message).then((response) => {
|
|
193
|
+
if (response) process.stdout.write(`${JSON.stringify(response)}
|
|
194
|
+
`);
|
|
195
|
+
}, () => void 0);
|
|
196
|
+
pending.add(work);
|
|
197
|
+
void work.finally(() => pending.delete(work));
|
|
198
|
+
});
|
|
199
|
+
await untilInputEnds(lines, signal);
|
|
200
|
+
await Promise.allSettled([...pending]);
|
|
201
|
+
}
|
|
202
|
+
export {
|
|
203
|
+
CLIKDEPLOY_TOOL_PREFIX,
|
|
204
|
+
SIGN_IN_AGAIN,
|
|
205
|
+
chatPermissionMode,
|
|
206
|
+
clikDeployMcpServe,
|
|
207
|
+
createClikDeployProxy
|
|
208
|
+
};
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
loadIndex
|
|
5
|
+
} from "./chunk-XCKQ5BM2.js";
|
|
6
|
+
import {
|
|
7
|
+
HARNESS_STATE_VERSION,
|
|
8
|
+
harnessSecretsPath
|
|
9
|
+
} from "./chunk-NWEYRBWK.js";
|
|
10
|
+
import {
|
|
11
|
+
isBlankConversation
|
|
12
|
+
} from "./chunk-TWCVV2JO.js";
|
|
13
|
+
import {
|
|
14
|
+
transcriptOf
|
|
15
|
+
} from "./chunk-RVUOIJXN.js";
|
|
16
|
+
import {
|
|
17
|
+
cloneData,
|
|
18
|
+
hidden,
|
|
19
|
+
mergeFields,
|
|
20
|
+
sameData
|
|
21
|
+
} from "./chunk-KHW6TX6I.js";
|
|
22
|
+
import {
|
|
23
|
+
withStateLock
|
|
24
|
+
} from "./chunk-4L2ZZM4Q.js";
|
|
25
|
+
import {
|
|
26
|
+
atomicWriteFile
|
|
27
|
+
} from "./chunk-F6F47QAY.js";
|
|
28
|
+
import {
|
|
29
|
+
lifecycle,
|
|
30
|
+
quiet
|
|
31
|
+
} from "./chunk-RDDWQBEM.js";
|
|
32
|
+
|
|
33
|
+
// src/session/ephemeral.ts
|
|
34
|
+
var byHome = /* @__PURE__ */ new Map();
|
|
35
|
+
var forced = /* @__PURE__ */ new Set();
|
|
36
|
+
function homeKey() {
|
|
37
|
+
return process.env.CLIKCODE_HOME?.trim() || "default";
|
|
38
|
+
}
|
|
39
|
+
function overlay() {
|
|
40
|
+
const key = homeKey();
|
|
41
|
+
let drafts = byHome.get(key);
|
|
42
|
+
if (!drafts) byHome.set(key, drafts = /* @__PURE__ */ new Map());
|
|
43
|
+
return drafts;
|
|
44
|
+
}
|
|
45
|
+
function ephemeralSessions() {
|
|
46
|
+
return [...overlay().values()].map((session) => cloneData(session));
|
|
47
|
+
}
|
|
48
|
+
function holdEphemeral(session) {
|
|
49
|
+
if (!isBlankConversation(session) || forced.has(session.id)) {
|
|
50
|
+
overlay().delete(session.id);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
overlay().set(session.id, cloneData(session));
|
|
54
|
+
}
|
|
55
|
+
function dropEphemeral(id) {
|
|
56
|
+
overlay().delete(id);
|
|
57
|
+
}
|
|
58
|
+
var pinned = /* @__PURE__ */ new Set();
|
|
59
|
+
function pinDraft(id) {
|
|
60
|
+
pinned.add(id);
|
|
61
|
+
}
|
|
62
|
+
function unpinDraft(id) {
|
|
63
|
+
pinned.delete(id);
|
|
64
|
+
}
|
|
65
|
+
function draftPinned(id) {
|
|
66
|
+
return pinned.has(id);
|
|
67
|
+
}
|
|
68
|
+
function forceStoreSession(id) {
|
|
69
|
+
forced.add(id);
|
|
70
|
+
}
|
|
71
|
+
function unforceStoreSession(id) {
|
|
72
|
+
forced.delete(id);
|
|
73
|
+
}
|
|
74
|
+
function sessionForceStored(id) {
|
|
75
|
+
return forced.has(id);
|
|
76
|
+
}
|
|
77
|
+
function ephemeralSession(id) {
|
|
78
|
+
const session = overlay().get(id);
|
|
79
|
+
return session ? cloneData(session) : void 0;
|
|
80
|
+
}
|
|
81
|
+
var REEXEC_DRAFT_ENV = "CLIKCODE_REEXEC_DRAFT";
|
|
82
|
+
function adoptHandedOverDraft() {
|
|
83
|
+
const raw = process.env[REEXEC_DRAFT_ENV];
|
|
84
|
+
delete process.env[REEXEC_DRAFT_ENV];
|
|
85
|
+
if (!raw) return;
|
|
86
|
+
try {
|
|
87
|
+
const session = JSON.parse(raw);
|
|
88
|
+
if (session && typeof session.id === "string") holdEphemeral(session);
|
|
89
|
+
} catch {
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
var REEXEC_TYPED_ENV = "CLIKCODE_REEXEC_TYPED";
|
|
93
|
+
function adoptHandedOverTyped() {
|
|
94
|
+
const text = process.env[REEXEC_TYPED_ENV];
|
|
95
|
+
delete process.env[REEXEC_TYPED_ENV];
|
|
96
|
+
return text || void 0;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// src/session/state/deletions.ts
|
|
100
|
+
var DELETIONS = /* @__PURE__ */ Symbol("clikcode.deletions");
|
|
101
|
+
function deleteConversations(state, ids) {
|
|
102
|
+
const doomed = new Set(ids);
|
|
103
|
+
if (!doomed.size) return;
|
|
104
|
+
state.sessions = state.sessions.filter((item) => !doomed.has(item.id));
|
|
105
|
+
const held = state[DELETIONS] ?? /* @__PURE__ */ new Set();
|
|
106
|
+
for (const id of doomed) held.add(id);
|
|
107
|
+
hidden(state, DELETIONS, held);
|
|
108
|
+
}
|
|
109
|
+
function pendingDeletions(state) {
|
|
110
|
+
return state[DELETIONS] ?? /* @__PURE__ */ new Set();
|
|
111
|
+
}
|
|
112
|
+
function clearDeletions(state, written) {
|
|
113
|
+
const held = state[DELETIONS];
|
|
114
|
+
if (!held) return;
|
|
115
|
+
for (const id of written) held.delete(id);
|
|
116
|
+
}
|
|
117
|
+
var TOMBSTONE_KEEP_MS = 90 * 24 * 60 * 6e4;
|
|
118
|
+
function nextTombstones(stored, added, listed, now = Date.now()) {
|
|
119
|
+
const out = {};
|
|
120
|
+
for (const [id, at] of Object.entries(stored ?? {})) {
|
|
121
|
+
if (!listed.has(id) && now - (Date.parse(at) || 0) < TOMBSTONE_KEEP_MS) out[id] = at;
|
|
122
|
+
}
|
|
123
|
+
for (const id of added) if (!listed.has(id)) out[id] = new Date(now).toISOString();
|
|
124
|
+
return Object.keys(out).length ? out : void 0;
|
|
125
|
+
}
|
|
126
|
+
async function conversationWasDeleted(id) {
|
|
127
|
+
return Boolean((await loadIndex())?.deletedSessions?.[id]);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/session/state/merge.ts
|
|
131
|
+
import { randomUUID } from "node:crypto";
|
|
132
|
+
function mergeAccount(baseline, working, disk) {
|
|
133
|
+
const merged = mergeFields(baseline, working, disk);
|
|
134
|
+
if (!disk) return merged;
|
|
135
|
+
if (working.nativeProfile && disk.nativeProfile) {
|
|
136
|
+
merged.nativeProfile = mergeFields(baseline?.nativeProfile, working.nativeProfile, disk.nativeProfile);
|
|
137
|
+
}
|
|
138
|
+
if (working.usage && disk.usage) {
|
|
139
|
+
merged.usage = (Date.parse(working.usage.at) || 0) >= (Date.parse(disk.usage.at) || 0) ? working.usage : disk.usage;
|
|
140
|
+
}
|
|
141
|
+
delete merged.usageLearning;
|
|
142
|
+
return merged;
|
|
143
|
+
}
|
|
144
|
+
function mergeById(baseline, working, disk, mergeRecordFields = (_before, after) => after) {
|
|
145
|
+
const before = new Map(baseline.map((item) => [item.id, item]));
|
|
146
|
+
const workingIds = new Set(working.map((item) => item.id));
|
|
147
|
+
const merged = new Map(disk.map((item) => [item.id, item]));
|
|
148
|
+
for (const id of before.keys()) if (!workingIds.has(id)) merged.delete(id);
|
|
149
|
+
for (const item of working) {
|
|
150
|
+
if (before.has(item.id) && !merged.has(item.id)) continue;
|
|
151
|
+
const previous = before.get(item.id);
|
|
152
|
+
if (previous === void 0) merged.set(item.id, item);
|
|
153
|
+
else if (!sameData(previous, item)) merged.set(item.id, mergeRecordFields(previous, item, merged.get(item.id)));
|
|
154
|
+
}
|
|
155
|
+
return [...merged.values()];
|
|
156
|
+
}
|
|
157
|
+
function mergeSessionRows(baseline, working, disk, drafts, removed, tombstoned) {
|
|
158
|
+
const before = new Map(baseline.map((item) => [item.id, item]));
|
|
159
|
+
const merged = new Map(disk.map((item) => [item.id, item]));
|
|
160
|
+
for (const id of removed) merged.delete(id);
|
|
161
|
+
for (const item of working) {
|
|
162
|
+
if (removed.has(item.id)) continue;
|
|
163
|
+
const known = before.has(item.id);
|
|
164
|
+
if (known && tombstoned.has(item.id)) {
|
|
165
|
+
merged.delete(item.id);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (known && !merged.has(item.id)) {
|
|
169
|
+
lifecycle("state.index-row-restored", { session: item.id });
|
|
170
|
+
merged.set(item.id, item);
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
const previous = before.get(item.id) ?? (merged.has(item.id) ? drafts?.get(item.id) : void 0);
|
|
174
|
+
if (previous === void 0) merged.set(item.id, item);
|
|
175
|
+
else if (!sameData(previous, item)) merged.set(item.id, mergeSessionMeta(previous, item, merged.get(item.id)));
|
|
176
|
+
}
|
|
177
|
+
return [...merged.values()];
|
|
178
|
+
}
|
|
179
|
+
function mergeRecord(baseline, working, disk) {
|
|
180
|
+
return mergeFields(baseline ?? {}, working ?? {}, disk ?? {});
|
|
181
|
+
}
|
|
182
|
+
function mergeQueuedTurns(baseline, working, disk) {
|
|
183
|
+
const was = new Set((baseline ?? []).map((item) => item.id));
|
|
184
|
+
const has = new Set((working ?? []).map((item) => item.id));
|
|
185
|
+
const merged = (disk ?? []).filter((item) => !(was.has(item.id) && !has.has(item.id)));
|
|
186
|
+
for (const item of working ?? []) {
|
|
187
|
+
if (!was.has(item.id) && !merged.some((entry) => entry.id === item.id)) merged.push(item);
|
|
188
|
+
}
|
|
189
|
+
return merged;
|
|
190
|
+
}
|
|
191
|
+
function mergeSessionMeta(baseline, working, disk) {
|
|
192
|
+
const merged = mergeFields(baseline, working, disk);
|
|
193
|
+
if (!disk || merged === working) return merged;
|
|
194
|
+
const queue = mergeQueuedTurns(baseline?.queuedTurns, working.queuedTurns, disk.queuedTurns);
|
|
195
|
+
if (queue.length) merged.queuedTurns = queue;
|
|
196
|
+
else delete merged.queuedTurns;
|
|
197
|
+
return merged;
|
|
198
|
+
}
|
|
199
|
+
function splitSession(session) {
|
|
200
|
+
const { messages: _messages, pendingTurn: _pendingTurn, ...meta } = session;
|
|
201
|
+
return { meta, transcript: transcriptOf(session) };
|
|
202
|
+
}
|
|
203
|
+
function baselineList(working, kept, from) {
|
|
204
|
+
if (!working) return { copy: void 0, from: void 0 };
|
|
205
|
+
const source = { list: working, length: working.length, last: working[working.length - 1] };
|
|
206
|
+
const unchanged = kept !== void 0 && (from?.list === working && from.length === working.length && from.last === source.last && sameData(kept[kept.length - 1], source.last) || sameData(kept, working));
|
|
207
|
+
const copy = unchanged ? kept : Object.isFrozen(working) ? working : working.map((item) => Object.isFrozen(item) ? item : cloneData(item));
|
|
208
|
+
return { copy, from: source };
|
|
209
|
+
}
|
|
210
|
+
var STATE_BASELINE = /* @__PURE__ */ Symbol("clikcode.stateBaseline");
|
|
211
|
+
var DRAFT_BASELINE = /* @__PURE__ */ Symbol("clikcode.draftBaseline");
|
|
212
|
+
function baselineSession(session, kept) {
|
|
213
|
+
const { meta } = splitSession(session);
|
|
214
|
+
if (session.messages === void 0 && session.pendingTurn === void 0 && kept) {
|
|
215
|
+
return {
|
|
216
|
+
meta: cloneData(meta),
|
|
217
|
+
transcript: kept.transcript,
|
|
218
|
+
...kept.messagesFrom ? { messagesFrom: kept.messagesFrom } : {}
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
const messages = baselineList(session.messages, kept?.transcript.messages, kept?.messagesFrom);
|
|
222
|
+
const pendingTurn = kept && sameData(kept.transcript.pendingTurn, session.pendingTurn) ? kept.transcript.pendingTurn : cloneData(session.pendingTurn);
|
|
223
|
+
const transcript = kept && messages.copy === kept.transcript.messages && pendingTurn === kept.transcript.pendingTurn ? kept.transcript : { ...messages.copy !== void 0 ? { messages: messages.copy } : {}, ...pendingTurn !== void 0 ? { pendingTurn } : {} };
|
|
224
|
+
return {
|
|
225
|
+
meta: cloneData(meta),
|
|
226
|
+
transcript,
|
|
227
|
+
...messages.from ? { messagesFrom: messages.from } : {}
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
function baselineOf(state, previous) {
|
|
231
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
232
|
+
for (const session of state.sessions ?? []) sessions.set(session.id, baselineSession(session, previous?.sessions.get(session.id)));
|
|
233
|
+
const invocations = baselineList(state.invocations ?? [], previous?.invocations, previous?.invocationsFrom);
|
|
234
|
+
return {
|
|
235
|
+
installationId: state.installationId,
|
|
236
|
+
devicePublicKey: cloneData(state.devicePublicKey),
|
|
237
|
+
localApiToken: state.localApiToken,
|
|
238
|
+
devicePrivateKeyPem: state.devicePrivateKeyPem,
|
|
239
|
+
accounts: cloneData(state.accounts ?? []),
|
|
240
|
+
invocations: invocations.copy ?? [],
|
|
241
|
+
globalSettings: cloneData(state.globalSettings),
|
|
242
|
+
providerSettings: cloneData(state.providerSettings),
|
|
243
|
+
sessions,
|
|
244
|
+
...invocations.from ? { invocationsFrom: invocations.from } : {}
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function refreshAccount(state, stored) {
|
|
248
|
+
const working = state.accounts.find((account) => account.id === stored.id);
|
|
249
|
+
if (!working || working === stored) return;
|
|
250
|
+
const baseline = state[STATE_BASELINE];
|
|
251
|
+
const at = baseline ? baseline.accounts.findIndex((account) => account.id === stored.id) : -1;
|
|
252
|
+
if (baseline && at >= 0 && !sameData(baseline.accounts[at], working)) return;
|
|
253
|
+
for (const key of Object.keys(working)) delete working[key];
|
|
254
|
+
Object.assign(working, cloneData(stored));
|
|
255
|
+
if (baseline && at >= 0) baseline.accounts[at] = cloneData(stored);
|
|
256
|
+
}
|
|
257
|
+
function rememberBaseline(state, baseline = baselineOf(state)) {
|
|
258
|
+
return hidden(state, STATE_BASELINE, baseline);
|
|
259
|
+
}
|
|
260
|
+
function indexFromWorking(state, disk, removed = /* @__PURE__ */ new Set()) {
|
|
261
|
+
const sessions = (state.sessions ?? []).map((session) => splitSession(session).meta);
|
|
262
|
+
const accounts = state.accounts ?? [];
|
|
263
|
+
const listed = new Set(sessions.map((session) => session.id));
|
|
264
|
+
const known = new Set(accounts.map((account) => account.id));
|
|
265
|
+
const deletedSessions = nextTombstones(disk?.deletedSessions, removed, listed);
|
|
266
|
+
return {
|
|
267
|
+
version: HARNESS_STATE_VERSION,
|
|
268
|
+
installationId: state.installationId || disk?.installationId || randomUUID(),
|
|
269
|
+
...state.devicePublicKey && Object.keys(state.devicePublicKey).length ? { devicePublicKey: state.devicePublicKey } : {},
|
|
270
|
+
accounts: [...(disk?.accounts ?? []).filter((account) => !known.has(account.id)), ...accounts],
|
|
271
|
+
sessions: [...(disk?.sessions ?? []).filter((session) => !listed.has(session.id) && !removed.has(session.id)), ...sessions],
|
|
272
|
+
...deletedSessions ? { deletedSessions } : {},
|
|
273
|
+
invocations: state.invocations ?? [],
|
|
274
|
+
// Rollups are derived on disk under the lock and never come from a snapshot.
|
|
275
|
+
invocationRollups: disk?.invocationRollups ?? {},
|
|
276
|
+
...disk?.rolledThrough ? { rolledThrough: disk.rolledThrough } : {},
|
|
277
|
+
globalSettings: state.globalSettings,
|
|
278
|
+
providerSettings: state.providerSettings ?? {}
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
function mergedIndex(baseline, state, disk, drafts, removed = /* @__PURE__ */ new Set()) {
|
|
282
|
+
const changed = (before, after, onDisk) => !sameData(before, after) ? after : onDisk;
|
|
283
|
+
const devicePublicKey = changed(baseline.devicePublicKey, state.devicePublicKey, disk.devicePublicKey);
|
|
284
|
+
const { devicePublicKey: _previousKey, deletedSessions: stored, ...rest } = disk;
|
|
285
|
+
const sessions = mergeSessionRows(
|
|
286
|
+
[...baseline.sessions.values()].map((entry) => entry.meta),
|
|
287
|
+
(state.sessions ?? []).map((session) => splitSession(session).meta),
|
|
288
|
+
disk.sessions ?? [],
|
|
289
|
+
drafts && new Map([...drafts].map(([id, entry]) => [id, entry.meta])),
|
|
290
|
+
removed,
|
|
291
|
+
new Set(Object.keys(stored ?? {}))
|
|
292
|
+
);
|
|
293
|
+
const deletedSessions = nextTombstones(stored, removed, new Set(sessions.map((session) => session.id)));
|
|
294
|
+
return {
|
|
295
|
+
...rest,
|
|
296
|
+
// Never stamp this writer's version over what is on disk.
|
|
297
|
+
version: disk.version,
|
|
298
|
+
installationId: disk.installationId || state.installationId,
|
|
299
|
+
...devicePublicKey && Object.keys(devicePublicKey).length ? { devicePublicKey } : {},
|
|
300
|
+
accounts: mergeById(baseline.accounts, state.accounts ?? [], disk.accounts ?? [], mergeAccount),
|
|
301
|
+
sessions,
|
|
302
|
+
...deletedSessions ? { deletedSessions } : {},
|
|
303
|
+
invocations: mergeById(baseline.invocations, state.invocations ?? [], disk.invocations ?? []),
|
|
304
|
+
globalSettings: mergeRecord(baseline.globalSettings, state.globalSettings, disk.globalSettings),
|
|
305
|
+
providerSettings: mergeRecord(baseline.providerSettings, state.providerSettings, disk.providerSettings)
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// src/session/state/secrets.ts
|
|
310
|
+
import { randomBytes, timingSafeEqual } from "node:crypto";
|
|
311
|
+
import { chmod, readFile, stat } from "node:fs/promises";
|
|
312
|
+
function sameSecret(left, right) {
|
|
313
|
+
const a = Buffer.from(left ?? "", "utf8");
|
|
314
|
+
const b = Buffer.from(right ?? "", "utf8");
|
|
315
|
+
return a.length === b.length && timingSafeEqual(a, b);
|
|
316
|
+
}
|
|
317
|
+
async function readSecretsFile() {
|
|
318
|
+
const path = harnessSecretsPath();
|
|
319
|
+
try {
|
|
320
|
+
const info = await stat(path);
|
|
321
|
+
if ((info.mode & 63) !== 0) await chmod(path, 384).catch(quiet("session/state/secrets"));
|
|
322
|
+
const parsed = JSON.parse(await readFile(path, "utf8"));
|
|
323
|
+
return parsed && typeof parsed === "object" ? parsed : {};
|
|
324
|
+
} catch (error) {
|
|
325
|
+
if (error.code === "ENOENT") return {};
|
|
326
|
+
throw error;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
async function writeSecretsFile(secrets) {
|
|
330
|
+
await atomicWriteFile(harnessSecretsPath(), `${JSON.stringify(cloneData(secrets), null, 2)}
|
|
331
|
+
`);
|
|
332
|
+
}
|
|
333
|
+
async function readLocalApiToken() {
|
|
334
|
+
const existing = (await readSecretsFile()).localApiToken;
|
|
335
|
+
if (existing) return existing;
|
|
336
|
+
return withStateLock(async () => {
|
|
337
|
+
const current = await readSecretsFile();
|
|
338
|
+
if (current.localApiToken) return current.localApiToken;
|
|
339
|
+
const localApiToken = randomBytes(32).toString("base64url");
|
|
340
|
+
await writeSecretsFile({ ...current, localApiToken });
|
|
341
|
+
return localApiToken;
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export {
|
|
346
|
+
ephemeralSessions,
|
|
347
|
+
holdEphemeral,
|
|
348
|
+
dropEphemeral,
|
|
349
|
+
pinDraft,
|
|
350
|
+
unpinDraft,
|
|
351
|
+
draftPinned,
|
|
352
|
+
forceStoreSession,
|
|
353
|
+
unforceStoreSession,
|
|
354
|
+
sessionForceStored,
|
|
355
|
+
ephemeralSession,
|
|
356
|
+
REEXEC_DRAFT_ENV,
|
|
357
|
+
adoptHandedOverDraft,
|
|
358
|
+
REEXEC_TYPED_ENV,
|
|
359
|
+
adoptHandedOverTyped,
|
|
360
|
+
deleteConversations,
|
|
361
|
+
pendingDeletions,
|
|
362
|
+
clearDeletions,
|
|
363
|
+
conversationWasDeleted,
|
|
364
|
+
STATE_BASELINE,
|
|
365
|
+
DRAFT_BASELINE,
|
|
366
|
+
baselineSession,
|
|
367
|
+
baselineOf,
|
|
368
|
+
refreshAccount,
|
|
369
|
+
rememberBaseline,
|
|
370
|
+
indexFromWorking,
|
|
371
|
+
mergedIndex,
|
|
372
|
+
sameSecret,
|
|
373
|
+
readSecretsFile,
|
|
374
|
+
writeSecretsFile,
|
|
375
|
+
readLocalApiToken
|
|
376
|
+
};
|