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,76 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
selectProviderConversation
|
|
5
|
+
} from "./chunk-QPQKX2MK.js";
|
|
6
|
+
import {
|
|
7
|
+
chooseOption
|
|
8
|
+
} from "./chunk-ROGXPGYR.js";
|
|
9
|
+
import {
|
|
10
|
+
GATEWAY_ID,
|
|
11
|
+
LOCAL_ID,
|
|
12
|
+
harnessSignedIn,
|
|
13
|
+
providerRows
|
|
14
|
+
} from "./chunk-J6EGFVQX.js";
|
|
15
|
+
import {
|
|
16
|
+
aiHarnessSelect
|
|
17
|
+
} from "./chunk-MDT5XDXL.js";
|
|
18
|
+
import {
|
|
19
|
+
readState
|
|
20
|
+
} from "./chunk-MXS6S2PY.js";
|
|
21
|
+
import {
|
|
22
|
+
allLocalHarnesses,
|
|
23
|
+
harnessCanRunTurns,
|
|
24
|
+
harnessTierRank,
|
|
25
|
+
localHarnessForProvider
|
|
26
|
+
} from "./chunk-KYUHIFP3.js";
|
|
27
|
+
import {
|
|
28
|
+
inspectNativeHarnessForPicker
|
|
29
|
+
} from "./chunk-DF35KMXM.js";
|
|
30
|
+
|
|
31
|
+
// src/tui/pickers/engine.ts
|
|
32
|
+
function providerPickerOptions(rows) {
|
|
33
|
+
return rows.map((row) => {
|
|
34
|
+
const current = row.current ? "\xB7 current " : "";
|
|
35
|
+
if (row.kind === "gateway") return { label: row.name, detail: `${current}\xB7 ${row.signedIn ? "connected" : "sign in, or use a model on this computer"}`, value: row.id };
|
|
36
|
+
const install = row.install === "ready" ? `installed${row.version ? ` ${row.version}` : ""}` : row.install === "auto" ? "installs when chosen" : "install it yourself";
|
|
37
|
+
return { label: row.name, detail: `${current}\xB7 ${install} \xB7 ${row.integration}`, value: row.id };
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
async function interactiveEnginePicker(config, rl, id) {
|
|
41
|
+
const state = await readState({ transcripts: [id] });
|
|
42
|
+
const session = state.sessions.find((item) => item.id === id);
|
|
43
|
+
if (!session) throw new Error(`AI session "${id}" was not found`);
|
|
44
|
+
const provider = await chooseOption(rl, "Choose a provider", providerPickerOptions(await providerRows(config, state, session)));
|
|
45
|
+
return provider ? selectProviderConversation(config, rl, id, providerConversationKey(provider), { offerLocal: true }) : void 0;
|
|
46
|
+
}
|
|
47
|
+
function providerConversationKey(provider) {
|
|
48
|
+
return provider === GATEWAY_ID ? "__gateway__" : provider === LOCAL_ID ? "__clikcode_local__" : provider;
|
|
49
|
+
}
|
|
50
|
+
async function autoSelectSessionHarness(id) {
|
|
51
|
+
const isInstalled = async (harness) => (await inspectNativeHarnessForPicker(harness)).installed;
|
|
52
|
+
const state = await readState({ transcripts: [id] });
|
|
53
|
+
const session = state.sessions.find((item) => item.id === id);
|
|
54
|
+
if (!session) return false;
|
|
55
|
+
if (session.nativeHarness) return true;
|
|
56
|
+
const account = session.accountId ? state.accounts.find((item) => item.id === session.accountId) : void 0;
|
|
57
|
+
const preferred = localHarnessForProvider(session.provider ?? account?.provider ?? "");
|
|
58
|
+
if (preferred && await isInstalled(preferred)) {
|
|
59
|
+
await aiHarnessSelect(preferred.command, id, { emit: false, signIn: false });
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
const candidates = allLocalHarnesses().filter((harness) => harnessCanRunTurns(harness)).sort((left, right) => harnessTierRank(left) - harnessTierRank(right));
|
|
63
|
+
const installed = (await Promise.all(candidates.map(async (harness) => await isInstalled(harness) ? harness : void 0))).filter((harness) => harness !== void 0);
|
|
64
|
+
const ready = await Promise.all(installed.map((harness) => harnessSignedIn(harness, state.accounts, true)));
|
|
65
|
+
const chosen = installed.find((_harness, index) => ready[index]) ?? installed[0];
|
|
66
|
+
if (!chosen) return false;
|
|
67
|
+
await aiHarnessSelect(chosen.command, id, { emit: false, signIn: false });
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export {
|
|
72
|
+
providerPickerOptions,
|
|
73
|
+
interactiveEnginePicker,
|
|
74
|
+
providerConversationKey,
|
|
75
|
+
autoSelectSessionHarness
|
|
76
|
+
};
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
isSecretRef,
|
|
5
|
+
secretRef
|
|
6
|
+
} from "./chunk-CBANJFBO.js";
|
|
7
|
+
|
|
8
|
+
// src/agent/computer/secret-finder.ts
|
|
9
|
+
var MAX_KEY_LENGTH = 8e3;
|
|
10
|
+
var STRONG_KEY = /api.?key|secret|access.?token|private.?key|auth.?token|bearer|credential/i;
|
|
11
|
+
var PREFIXED = /^(?:[a-z]{2,12}(?:_[a-z]+)*_[A-Za-z0-9]{12,}|sk-|ghp_|github_pat_|AKIA|AIza|AQ\.|xox[abp]-|eyJ)/;
|
|
12
|
+
var LABEL_THEN_VALUE = /\b(?:api[ _-]?key|secret(?:[ _-]?key)?|access[ _-]?token|token|key|credential|password)s?(?:[ \t]*[:=][ \t]*|[ \t]+)([A-Za-z0-9_\-+/=.:~]{16,8000})/gi;
|
|
13
|
+
var SECRET_UUID = /(\bsecret[ _-]?(?:key|token)?s?(?:[ \t]*[:=][ \t]*|[ \t]+))([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/gi;
|
|
14
|
+
var mixedCase = (value) => /[a-z]/.test(value) && /[A-Z]/.test(value) && (/\d/.test(value) || entropy(value) >= 4.5);
|
|
15
|
+
function labelledValues(text) {
|
|
16
|
+
const found = /* @__PURE__ */ new Set();
|
|
17
|
+
for (const match of text.matchAll(LABEL_THEN_VALUE)) found.add(match[1].replace(/[.,;:)]+$/, ""));
|
|
18
|
+
return found;
|
|
19
|
+
}
|
|
20
|
+
var WORTH_SAVING_HINT = /\bcopy\b|won'?t be (?:shown|displayed|visible)|only (?:once|time)|(?:save|store) (?:this|it|your)|make sure to (?:copy|save)|never (?:be )?shown again/i;
|
|
21
|
+
function entropy(text) {
|
|
22
|
+
const counts = /* @__PURE__ */ new Map();
|
|
23
|
+
for (const char of text) counts.set(char, (counts.get(char) ?? 0) + 1);
|
|
24
|
+
let bits = 0;
|
|
25
|
+
for (const count of counts.values()) {
|
|
26
|
+
const p = count / text.length;
|
|
27
|
+
bits -= p * Math.log2(p);
|
|
28
|
+
}
|
|
29
|
+
return bits;
|
|
30
|
+
}
|
|
31
|
+
function keyShaped(value) {
|
|
32
|
+
if (value.length < 16 || value.length > MAX_KEY_LENGTH || !/^[A-Za-z0-9_\-+/=.:~]+$/.test(value)) return false;
|
|
33
|
+
if (value.length > 130 && !/^[\w-]+\.[\w-]+\.[\w-]+$/.test(value) && !(mixedCase(value) && entropy(value) >= 4.2)) return false;
|
|
34
|
+
if (/^https?:|@/.test(value) || /^\d+$/.test(value)) return false;
|
|
35
|
+
if (!/\d/.test(value) && !PREFIXED.test(value) && !(value.length >= 32 && mixedCase(value))) return false;
|
|
36
|
+
if (/^[a-z][a-z-]*\/[\w-]+$/.test(value)) return false;
|
|
37
|
+
return entropy(value) >= 3;
|
|
38
|
+
}
|
|
39
|
+
function compactToken(text) {
|
|
40
|
+
const trimmed = text.trim();
|
|
41
|
+
if (!/\s/.test(trimmed)) return trimmed;
|
|
42
|
+
const parts = trimmed.split(/\s+/);
|
|
43
|
+
const joined = parts.join("");
|
|
44
|
+
return parts.length <= 400 && joined.length >= 100 && joined.length <= MAX_KEY_LENGTH && parts.every((part) => /^[A-Za-z0-9_\-+/=.:~]+$/.test(part)) && keyShaped(joined) ? joined : trimmed;
|
|
45
|
+
}
|
|
46
|
+
function walk(node, key, out, depth = 0) {
|
|
47
|
+
if (depth > 6 || out.length > 200) return;
|
|
48
|
+
if (typeof node === "string") {
|
|
49
|
+
if (keyShaped(node)) out.push({ value: node, ...key ? { keyName: key } : {} });
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (Array.isArray(node)) {
|
|
53
|
+
for (const item of node.slice(0, 50)) walk(item, key, out, depth + 1);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (node && typeof node === "object") for (const [name, child] of Object.entries(node).slice(0, 100)) walk(child, name, out, depth + 1);
|
|
57
|
+
}
|
|
58
|
+
function decide(input) {
|
|
59
|
+
const scored = /* @__PURE__ */ new Map();
|
|
60
|
+
const responseFor = /* @__PURE__ */ new Map();
|
|
61
|
+
for (const found of input.responses) responseFor.set(found.value, found);
|
|
62
|
+
const candidates = /* @__PURE__ */ new Set([...input.after.filter((value) => !input.before.has(value) && keyShaped(value)), ...responseFor.keys()]);
|
|
63
|
+
for (const value of [...candidates]) if ([...candidates].some((other) => other.length > value.length && other.includes(value))) candidates.delete(value);
|
|
64
|
+
for (const value of candidates) {
|
|
65
|
+
const onPage = input.after.includes(value) && !input.before.has(value);
|
|
66
|
+
const response = responseFor.get(value);
|
|
67
|
+
const strong = !!response?.keyName && STRONG_KEY.test(response.keyName);
|
|
68
|
+
if (!onPage && !strong) continue;
|
|
69
|
+
if (input.existing && !strong && !input.labelled?.has(value) && !PREFIXED.test(value)) continue;
|
|
70
|
+
scored.set(value, (onPage ? 3 : 0) + (response ? 2 : 0) + (strong ? 2 : 0) + (PREFIXED.test(value) ? 2 : 0) + (input.labelled?.has(value) ? 2 : 0) + (mixedCase(value) ? 1 : 0) + (value.length >= 24 ? 1 : 0) + (input.hint ? 1 : 0));
|
|
71
|
+
}
|
|
72
|
+
const ranked = [...scored.entries()].sort((a, b) => b[1] - a[1]);
|
|
73
|
+
const [top, next] = ranked;
|
|
74
|
+
if (!top || top[1] < 5) return { kind: "none" };
|
|
75
|
+
if (next && next[1] > top[1] - 2) return { kind: "ambiguous" };
|
|
76
|
+
return { kind: "found", value: top[0] };
|
|
77
|
+
}
|
|
78
|
+
function pageTokens(withMasked) {
|
|
79
|
+
const doc = globalThis.document;
|
|
80
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
81
|
+
for (const word of doc.body.innerText.split(/\s+/)) tokens.add(word.replace(/^[("'`]+|[)"'`,.;]+$/g, ""));
|
|
82
|
+
for (const element of Array.from(doc.querySelectorAll("input, textarea"))) if (element.value && (withMasked || element.type !== "password")) tokens.add(element.value);
|
|
83
|
+
for (const element of Array.from(doc.querySelectorAll('pre, code, textarea, samp, [class*="token"], [class*="secret"]'))) {
|
|
84
|
+
const text = (element.value || element.textContent || "").trim();
|
|
85
|
+
if (text.length >= 100 && text.length <= 16e3 && /\s/.test(text)) {
|
|
86
|
+
const parts = text.split(/\s+/);
|
|
87
|
+
if (parts.length <= 400 && parts.every((part) => /^[A-Za-z0-9_\-+/=.:~]+$/.test(part))) tokens.add(parts.join(""));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
for (const element of Array.from(doc.querySelectorAll("[data-clipboard-text], [data-copy], [data-value], [data-key], [data-secret]"))) {
|
|
91
|
+
for (const name of ["data-clipboard-text", "data-copy", "data-value", "data-key", "data-secret"]) {
|
|
92
|
+
const attribute = element.getAttribute(name);
|
|
93
|
+
if (attribute) tokens.add(attribute);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return { tokens: [...tokens].filter((token) => token.length >= 16 && token.length <= 8e3), hint: false, labelled: /* @__PURE__ */ new Set() };
|
|
97
|
+
}
|
|
98
|
+
async function snapshot(page, withMasked = false) {
|
|
99
|
+
try {
|
|
100
|
+
const taken = await page.evaluate(pageTokens, withMasked);
|
|
101
|
+
const text = await page.evaluate(() => globalThis.document.body.innerText);
|
|
102
|
+
return { tokens: taken.tokens, hint: WORTH_SAVING_HINT.test(text), labelled: labelledValues(text) };
|
|
103
|
+
} catch {
|
|
104
|
+
return { tokens: [], hint: false, labelled: /* @__PURE__ */ new Set() };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async function armFinder(page, existing = false) {
|
|
108
|
+
const before = existing ? /* @__PURE__ */ new Set() : new Set((await snapshot(page)).tokens);
|
|
109
|
+
const responses = [];
|
|
110
|
+
const listen = async (response) => {
|
|
111
|
+
try {
|
|
112
|
+
const type = response.request().resourceType();
|
|
113
|
+
if (type !== "fetch" && type !== "xhr" || !/json/i.test(response.headers()["content-type"] ?? "")) return;
|
|
114
|
+
const body = await response.text();
|
|
115
|
+
if (body.length > 5e5) return;
|
|
116
|
+
walk(JSON.parse(body), void 0, responses);
|
|
117
|
+
} catch {
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
page.on("response", listen);
|
|
121
|
+
return {
|
|
122
|
+
async look() {
|
|
123
|
+
const now = await snapshot(page, existing);
|
|
124
|
+
return decide({ before, after: now.tokens, responses, hint: now.hint, labelled: now.labelled, existing });
|
|
125
|
+
},
|
|
126
|
+
dispose() {
|
|
127
|
+
page.off("response", listen);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function hideKeyLikeText(text) {
|
|
132
|
+
const labelled = labelledValues(text);
|
|
133
|
+
const copyHint = WORTH_SAVING_HINT.test(text);
|
|
134
|
+
let hidden = 0;
|
|
135
|
+
text = text.replace(SECRET_UUID, (match, label, uuid) => {
|
|
136
|
+
hidden++;
|
|
137
|
+
const shown = secretRef(uuid ?? match);
|
|
138
|
+
return typeof label === "string" ? `${label}${shown}` : shown;
|
|
139
|
+
});
|
|
140
|
+
const longNumber = (bare) => /^\d{24,}$/.test(bare);
|
|
141
|
+
const randomLooking = (bare) => keyShaped(bare) && (mixedCase(bare) || PREFIXED.test(bare) || bare.length >= 32 && /^[0-9a-f]+$/i.test(bare) || /^[A-Za-z0-9]{20,}$/.test(bare) && /\d/.test(bare) && /[A-Za-z]/.test(bare) && entropy(bare) >= 3.6);
|
|
142
|
+
const lines = text.split("\n").map((line) => {
|
|
143
|
+
const isUrl = /^\s*- \/url:/.test(line);
|
|
144
|
+
return line.replace(/[A-Za-z0-9_\-+/=.:~]{20,}/g, (token) => {
|
|
145
|
+
const bare = token.replace(/[.,;:)]+$/, "");
|
|
146
|
+
if (longNumber(bare)) {
|
|
147
|
+
if (isUrl) return token;
|
|
148
|
+
hidden++;
|
|
149
|
+
return secretRef(bare);
|
|
150
|
+
}
|
|
151
|
+
if (!keyShaped(bare)) return token;
|
|
152
|
+
const marked = mixedCase(bare) && labelled.has(bare) || copyHint && bare.length >= 32;
|
|
153
|
+
if (isUrl ? !marked : !(marked || randomLooking(bare))) return token;
|
|
154
|
+
hidden++;
|
|
155
|
+
return secretRef(bare) + token.slice(bare.length);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
const NAMED = /\b(?:secret|token|api[ _-]?key|app[ _-]?key|client[ _-]?secret|password|credential)s?\b/i;
|
|
159
|
+
const guarded = lines.map((line, index) => {
|
|
160
|
+
if (!NAMED.test(line) && !(index > 0 && NAMED.test(lines[index - 1]))) return line;
|
|
161
|
+
return line.replace(/(?<![\w-])[A-Za-z0-9_-]{12,23}(?![\w-])/g, (token) => {
|
|
162
|
+
if (!/\d/.test(token) || !/[A-Za-z]/.test(token) || /^ref=|^f\d*e\d+$/.test(token)) return token;
|
|
163
|
+
hidden++;
|
|
164
|
+
return secretRef(token);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
const BOX = /^(\s*- (?:textbox|searchbox|text|textarea)\b[^\n]*?\]):\s+(\S{8,})\s*$/;
|
|
168
|
+
const boxed = guarded.map((line) => {
|
|
169
|
+
const match = BOX.exec(line);
|
|
170
|
+
if (!match) return line;
|
|
171
|
+
const value = match[2].replace(/^"|"$/g, "");
|
|
172
|
+
const named = /(?:^|[^a-z])(?:key|token|secret|credential)s?(?![a-z])/i.test(match[1]);
|
|
173
|
+
const shaped = value.length >= 12 && /^[A-Za-z0-9_\-+/=.:~]+$/.test(value) && /[A-Za-z]/.test(value) && /\d/.test(value) && !/^https?:|@/.test(value);
|
|
174
|
+
const nameBox = /\b(?:name|label|title|description|note|nickname|alias)\b/i.test(match[1]);
|
|
175
|
+
const plainWord = /^[A-Za-z][A-Za-z._-]*$/.test(value) && value.length <= 14;
|
|
176
|
+
if (value === "[secret hidden]" || value === "[hidden]" || isSecretRef(value) || !(named && !nameBox && !plainWord || shaped)) return line;
|
|
177
|
+
hidden++;
|
|
178
|
+
return `${match[1]}: ${secretRef(value)}`;
|
|
179
|
+
});
|
|
180
|
+
return { text: boxed.join("\n"), hidden };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export {
|
|
184
|
+
MAX_KEY_LENGTH,
|
|
185
|
+
labelledValues,
|
|
186
|
+
keyShaped,
|
|
187
|
+
compactToken,
|
|
188
|
+
decide,
|
|
189
|
+
armFinder,
|
|
190
|
+
hideKeyLikeText
|
|
191
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
hideKeyLikeText
|
|
5
|
+
} from "./chunk-MCBRVPA7.js";
|
|
6
|
+
import {
|
|
7
|
+
quiet
|
|
8
|
+
} from "./chunk-RDDWQBEM.js";
|
|
9
|
+
import {
|
|
10
|
+
scrubSecrets
|
|
11
|
+
} from "./chunk-CBANJFBO.js";
|
|
12
|
+
|
|
13
|
+
// src/agent/computer/network-capture.ts
|
|
14
|
+
var KINDS = /* @__PURE__ */ new Set(["xhr", "fetch"]);
|
|
15
|
+
var MAX_CALLS = 60;
|
|
16
|
+
var MAX_BODY = 1500;
|
|
17
|
+
function safeUrl(raw) {
|
|
18
|
+
try {
|
|
19
|
+
const u = new URL(raw);
|
|
20
|
+
const names = [.../* @__PURE__ */ new Set([...u.searchParams.keys()])];
|
|
21
|
+
return `${u.origin}${u.pathname}${names.length ? `?${names.map((name) => `${name}=\u2026`).join("&")}` : ""}`;
|
|
22
|
+
} catch {
|
|
23
|
+
return raw.slice(0, 200);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function jsonShape(value, depth = 3) {
|
|
27
|
+
if (Array.isArray(value)) return value.length ? `[${depth > 0 ? jsonShape(value[0], depth - 1) : "\u2026"}]` : "[]";
|
|
28
|
+
if (value && typeof value === "object") {
|
|
29
|
+
if (depth <= 0) return "{\u2026}";
|
|
30
|
+
return `{${Object.entries(value).slice(0, 25).map(([key, inner]) => `${key}: ${jsonShape(inner, depth - 1)}`).join(", ")}}`;
|
|
31
|
+
}
|
|
32
|
+
return value === null ? "null" : typeof value;
|
|
33
|
+
}
|
|
34
|
+
var clip = (text) => hideKeyLikeText(scrubSecrets(text.slice(0, MAX_BODY))).text;
|
|
35
|
+
async function recordNetwork(page, run, options = {}) {
|
|
36
|
+
const calls = [];
|
|
37
|
+
const pending = [];
|
|
38
|
+
let dropped = 0;
|
|
39
|
+
const onRequest = (request) => {
|
|
40
|
+
if (!KINDS.has(request.resourceType())) return;
|
|
41
|
+
const url = request.url();
|
|
42
|
+
if (options.find && !url.toLowerCase().includes(options.find.toLowerCase())) return;
|
|
43
|
+
if (calls.length >= MAX_CALLS) {
|
|
44
|
+
dropped++;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const call = { method: request.method(), url: safeUrl(url), type: request.resourceType(), requestHeaders: Object.keys(request.headers()).sort() };
|
|
48
|
+
calls.push(call);
|
|
49
|
+
if (options.bodies) {
|
|
50
|
+
const body = request.postData();
|
|
51
|
+
if (body) call.body = clip(body);
|
|
52
|
+
}
|
|
53
|
+
pending.push((async () => {
|
|
54
|
+
const response = await request.response().catch(() => null);
|
|
55
|
+
if (!response) return;
|
|
56
|
+
call.status = response.status();
|
|
57
|
+
call.contentType = response.headers()["content-type"]?.split(";")[0];
|
|
58
|
+
if (call.contentType?.includes("json")) {
|
|
59
|
+
const parsed = await response.json().catch(quiet("agent/computer/network-capture"));
|
|
60
|
+
if (parsed !== void 0) {
|
|
61
|
+
call.jsonShape = jsonShape(parsed);
|
|
62
|
+
if (options.bodies) call.answer = clip(JSON.stringify(parsed));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
})());
|
|
66
|
+
};
|
|
67
|
+
page.on("request", onRequest);
|
|
68
|
+
try {
|
|
69
|
+
const result = await run();
|
|
70
|
+
await page.waitForTimeout(options.quietMs ?? 800);
|
|
71
|
+
await Promise.allSettled(pending);
|
|
72
|
+
return { result, calls, dropped };
|
|
73
|
+
} finally {
|
|
74
|
+
page.off("request", onRequest);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function describeCalls(calls, dropped = 0) {
|
|
78
|
+
if (!calls.length) return "No API calls (xhr/fetch) were made.";
|
|
79
|
+
return [`${calls.length} API call${calls.length === 1 ? "" : "s"}${dropped ? ` (${dropped} more not shown)` : ""}:`, ...calls.map((call) => `${call.method} ${call.url} \u2192 ${call.status ?? "?"}${call.contentType ? ` ${call.contentType}` : ""}${call.jsonShape ? `
|
|
80
|
+
answer: ${call.jsonShape}` : ""}${call.body ? `
|
|
81
|
+
sent: ${call.body}` : ""}${call.answer ? `
|
|
82
|
+
body: ${call.answer}` : ""}
|
|
83
|
+
header names: ${call.requestHeaders.join(", ")}`)].join("\n");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export {
|
|
87
|
+
safeUrl,
|
|
88
|
+
jsonShape,
|
|
89
|
+
recordNetwork,
|
|
90
|
+
describeCalls
|
|
91
|
+
};
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
turnBackendForAccount
|
|
5
|
+
} from "./chunk-IF43HIGV.js";
|
|
6
|
+
import {
|
|
7
|
+
accountSignedOutOnDisk,
|
|
8
|
+
accountView,
|
|
9
|
+
harnessNeedsLogin,
|
|
10
|
+
loginNativeHarness,
|
|
11
|
+
syncAccountIdentityAfterLogin,
|
|
12
|
+
withSignIn
|
|
13
|
+
} from "./chunk-LA6MG4ET.js";
|
|
14
|
+
import {
|
|
15
|
+
emitHarnessOutput
|
|
16
|
+
} from "./chunk-4RHXTL3W.js";
|
|
17
|
+
import {
|
|
18
|
+
signedInAccountId
|
|
19
|
+
} from "./chunk-SQVUDO2O.js";
|
|
20
|
+
import {
|
|
21
|
+
modelIdFromLabel,
|
|
22
|
+
resolveNativeModel
|
|
23
|
+
} from "./chunk-QQRLPY25.js";
|
|
24
|
+
import {
|
|
25
|
+
accountCanTakeTurn
|
|
26
|
+
} from "./chunk-XWAC3MKW.js";
|
|
27
|
+
import {
|
|
28
|
+
deriveAccountLabel,
|
|
29
|
+
nameAccount
|
|
30
|
+
} from "./chunk-ZN7G6JLS.js";
|
|
31
|
+
import {
|
|
32
|
+
nativeProfileEnvironment
|
|
33
|
+
} from "./chunk-ZGX3ERAT.js";
|
|
34
|
+
import {
|
|
35
|
+
readState
|
|
36
|
+
} from "./chunk-MXS6S2PY.js";
|
|
37
|
+
import {
|
|
38
|
+
writeState
|
|
39
|
+
} from "./chunk-RKUVLRZI.js";
|
|
40
|
+
import {
|
|
41
|
+
forceStoreSession
|
|
42
|
+
} from "./chunk-BGEMY2JJ.js";
|
|
43
|
+
import {
|
|
44
|
+
harnessCommand
|
|
45
|
+
} from "./chunk-NWEYRBWK.js";
|
|
46
|
+
import {
|
|
47
|
+
leaveProvider
|
|
48
|
+
} from "./chunk-TWCVV2JO.js";
|
|
49
|
+
import {
|
|
50
|
+
sessionProviderLabel
|
|
51
|
+
} from "./chunk-WWLJMP6D.js";
|
|
52
|
+
import {
|
|
53
|
+
isClikCodeAgent
|
|
54
|
+
} from "./chunk-CRUVYGO2.js";
|
|
55
|
+
import {
|
|
56
|
+
harnessCanRunTurns,
|
|
57
|
+
harnessSupportsModelSelection,
|
|
58
|
+
localHarnessForCommand,
|
|
59
|
+
localHarnessForProvider
|
|
60
|
+
} from "./chunk-KYUHIFP3.js";
|
|
61
|
+
import {
|
|
62
|
+
TERMINAL,
|
|
63
|
+
ensureNativeHarness,
|
|
64
|
+
hasAuthEvidence
|
|
65
|
+
} from "./chunk-DF35KMXM.js";
|
|
66
|
+
|
|
67
|
+
// src/commands/ai/harness.ts
|
|
68
|
+
import { randomUUID } from "node:crypto";
|
|
69
|
+
async function aiHarnessSelect(harnessCommandName, sessionId, options = {}) {
|
|
70
|
+
const harness = localHarnessForCommand(harnessCommandName);
|
|
71
|
+
if (!harness) throw new Error(`unknown local harness: ${harnessCommandName}`);
|
|
72
|
+
if (!harnessCanRunTurns(harness)) throw new Error(`${harness.displayName} does not publish a non-interactive turn contract (CLI or ACP) required by the centralized ClikCode UI.`);
|
|
73
|
+
const freshInstall = await ensureNativeHarness(harness);
|
|
74
|
+
const state = await readState({ transcripts: [sessionId] });
|
|
75
|
+
const session = state.sessions.find((item) => item.id === sessionId);
|
|
76
|
+
if (!session) throw new Error(`AI session "${sessionId}" was not found`);
|
|
77
|
+
const sameHarness = session.nativeHarness === harness.command;
|
|
78
|
+
if (!sameHarness) {
|
|
79
|
+
leaveProvider(session);
|
|
80
|
+
session.model = null;
|
|
81
|
+
}
|
|
82
|
+
session.nativeHarness = harness.command;
|
|
83
|
+
session.provider = harness.provider;
|
|
84
|
+
session.route = "local";
|
|
85
|
+
session.workspace ??= process.cwd();
|
|
86
|
+
const selected = session.accountId ? state.accounts.find((account2) => account2.id === session.accountId) : void 0;
|
|
87
|
+
const selectedUsable = selected?.provider === harness.provider && turnBackendForAccount(selected) === "vendor" && accountCanTakeTurn(selected);
|
|
88
|
+
let accountJustCreated = false;
|
|
89
|
+
if (!selectedUsable) {
|
|
90
|
+
const accounts = state.accounts.filter((account2) => account2.provider === harness.provider && turnBackendForAccount(account2) === "vendor");
|
|
91
|
+
if (accounts.some((account2) => account2.status === "ready")) {
|
|
92
|
+
session.accountId = signedInAccountId(state, harness.provider, session.accountId, (account2) => turnBackendForAccount(account2) === "vendor");
|
|
93
|
+
} else if (accounts.length) {
|
|
94
|
+
session.accountId = null;
|
|
95
|
+
} else {
|
|
96
|
+
accountJustCreated = true;
|
|
97
|
+
const label = nameAccount(state.accounts, harness, await deriveAccountLabel(harness, void 0) ?? harness.displayName);
|
|
98
|
+
const account2 = {
|
|
99
|
+
id: randomUUID(),
|
|
100
|
+
provider: harness.provider,
|
|
101
|
+
label,
|
|
102
|
+
authKind: "vendor-cli",
|
|
103
|
+
models: [],
|
|
104
|
+
status: "ready",
|
|
105
|
+
credentialRef: `native:${harness.binary}:default`
|
|
106
|
+
};
|
|
107
|
+
state.accounts.push(account2);
|
|
108
|
+
session.accountId = account2.id;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
let account = session.accountId ? state.accounts.find((item) => item.id === session.accountId) : void 0;
|
|
112
|
+
const signIn = options.signIn !== false;
|
|
113
|
+
const signer = options.prompter ?? TERMINAL.active;
|
|
114
|
+
if (harness.loginArgv && (signer || !signIn)) {
|
|
115
|
+
const environment = nativeProfileEnvironment(account?.nativeProfile);
|
|
116
|
+
const shouldCheckLogin = !account || account.status !== "ready" || accountJustCreated && !harness.signInOptional && (freshInstall || !hasAuthEvidence(harness) || await harnessNeedsLogin(harness, environment));
|
|
117
|
+
if (shouldCheckLogin && !signIn) {
|
|
118
|
+
account ??= state.accounts.find((item) => item.provider === harness.provider && turnBackendForAccount(item) === "vendor");
|
|
119
|
+
if (account) {
|
|
120
|
+
if (account.status === "ready") account.status = "needs_login";
|
|
121
|
+
if (accountJustCreated) account.neverSignedIn = true;
|
|
122
|
+
session.accountId = account.id;
|
|
123
|
+
}
|
|
124
|
+
} else if (shouldCheckLogin && signer) {
|
|
125
|
+
await withSignIn(signer, harness.displayName, () => loginNativeHarness(harness, environment));
|
|
126
|
+
if (!account) account = state.accounts.find((item) => item.provider === harness.provider);
|
|
127
|
+
if (account) {
|
|
128
|
+
account = await syncAccountIdentityAfterLogin(harness, account, state);
|
|
129
|
+
session.accountId = account.id;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (!session.accountId && state.accounts.some((item) => item.provider === harness.provider)) {
|
|
134
|
+
throw new Error(`${harness.displayName} is not signed in. Run \`${harnessCommand()} accounts login ${harness.command}\`.`);
|
|
135
|
+
}
|
|
136
|
+
if (!session.model) {
|
|
137
|
+
const lastUsedModel = [...state.sessions].filter((item) => item.id !== session.id && item.nativeHarness === harness.command && item.model).sort((left, right) => Date.parse(right.updatedAt ?? "") - Date.parse(left.updatedAt ?? ""))[0]?.model;
|
|
138
|
+
session.model = lastUsedModel ?? state.providerSettings[harness.provider]?.model ?? await resolveNativeModel(harness, account) ?? null;
|
|
139
|
+
}
|
|
140
|
+
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
141
|
+
await writeState(state);
|
|
142
|
+
if (options.emit === false) return;
|
|
143
|
+
const compatible = state.accounts.filter((account2) => account2.provider === harness.provider && account2.status === "ready");
|
|
144
|
+
emitHarnessOutput({
|
|
145
|
+
panel: "provider-selected",
|
|
146
|
+
harness: harness.command,
|
|
147
|
+
displayName: harness.displayName,
|
|
148
|
+
provider: harness.provider,
|
|
149
|
+
account: state.accounts.find((account2) => account2.id === session.accountId)?.label ?? null,
|
|
150
|
+
model: session.model ?? "provider default",
|
|
151
|
+
centralized: true,
|
|
152
|
+
...session.accountId ? {} : { actionRequired: `Choose one with /accounts use <label>`, accounts: compatible.map(accountView) }
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
async function signInBeforeUse(id) {
|
|
156
|
+
const state = await readState({ transcripts: [] });
|
|
157
|
+
const session = state.sessions.find((item) => item.id === id);
|
|
158
|
+
if (!session?.nativeHarness || session.route !== "local") return false;
|
|
159
|
+
const account = session.accountId ? state.accounts.find((item) => item.id === session.accountId) : void 0;
|
|
160
|
+
if (account?.status !== "needs_login") return false;
|
|
161
|
+
await aiHarnessSelect(session.nativeHarness, id, { emit: false });
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
async function ensureChatReady(id) {
|
|
165
|
+
const state = await readState({ transcripts: [] });
|
|
166
|
+
const session = state.sessions.find((item) => item.id === id);
|
|
167
|
+
if (!session || isClikCodeAgent(session) || session.accountId) return;
|
|
168
|
+
const harness = session.nativeHarness ? localHarnessForCommand(session.nativeHarness) : session.provider ? localHarnessForProvider(session.provider) : void 0;
|
|
169
|
+
if (harness) return aiHarnessSelect(harness.command, id, { emit: false, signIn: false });
|
|
170
|
+
const { autoSelectSessionHarness } = await import("./chunk-3W3IPDFP.js");
|
|
171
|
+
if (!await autoSelectSessionHarness(id)) throw new Error("no harness is installed -- install one, e.g. npm i -g @anthropic-ai/claude-code");
|
|
172
|
+
}
|
|
173
|
+
async function resolveChat(ref) {
|
|
174
|
+
const state = await readState({ transcripts: [] });
|
|
175
|
+
if (state.sessions.some((item) => item.id === ref)) return ref;
|
|
176
|
+
const { chatNamed } = await import("./chunk-23TDEBGZ.js");
|
|
177
|
+
const id = chatNamed(state.sessions, ref, "");
|
|
178
|
+
if (!id) throw new Error(`no chat matches "${ref}" -- use its name, the start of its id, or last`);
|
|
179
|
+
return id;
|
|
180
|
+
}
|
|
181
|
+
async function startOrResumeChat(options) {
|
|
182
|
+
if (options.harness === "clikcode-local" || options.harness === "gateway") return startOrResumeAgentChat({ ...options, route: options.harness });
|
|
183
|
+
let id;
|
|
184
|
+
if (options.chat) id = await resolveChat(options.chat);
|
|
185
|
+
else {
|
|
186
|
+
const { launchSession } = await import("./chunk-AEMHSXKA.js");
|
|
187
|
+
const state = await readState({ transcripts: [] });
|
|
188
|
+
const session = launchSession(state, process.cwd());
|
|
189
|
+
state.sessions.push(session);
|
|
190
|
+
forceStoreSession(session.id);
|
|
191
|
+
await writeState(state);
|
|
192
|
+
id = session.id;
|
|
193
|
+
}
|
|
194
|
+
if (options.harness) {
|
|
195
|
+
const harness = localHarnessForCommand(options.harness) ?? localHarnessForProvider(options.harness);
|
|
196
|
+
if (!harness) throw new Error(`unknown harness "${options.harness}"`);
|
|
197
|
+
const state = await readState({ transcripts: [] });
|
|
198
|
+
const session = state.sessions.find((item) => item.id === id);
|
|
199
|
+
if (session?.nativeHarness !== harness.command) {
|
|
200
|
+
const { moveToProvider } = await import("./chunk-OARL2NXZ.js");
|
|
201
|
+
if (options.chat) await moveToProvider(id, harness.command);
|
|
202
|
+
else await aiHarnessSelect(harness.command, id, { emit: false });
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
await ensureChatReady(id);
|
|
206
|
+
if (options.permissions) await setChatPermissions(id, options.permissions);
|
|
207
|
+
if (options.model) {
|
|
208
|
+
const state = await readState({ transcripts: [id] });
|
|
209
|
+
const session = state.sessions.find((item) => item.id === id);
|
|
210
|
+
const harness = session?.nativeHarness ? localHarnessForCommand(session.nativeHarness) : void 0;
|
|
211
|
+
if (session && harness) {
|
|
212
|
+
if (!harnessSupportsModelSelection(harness)) throw new Error(`${harness.displayName} does not publish a model selector, so --model ${options.model} would be ignored; leave it out to use ${harness.displayName}'s own model.`);
|
|
213
|
+
session.model = modelIdFromLabel(harness, [], options.model);
|
|
214
|
+
await writeState(state);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
await refuseAccountThatCannotTakeTurn(id);
|
|
218
|
+
return id;
|
|
219
|
+
}
|
|
220
|
+
async function refuseAccountThatCannotTakeTurn(id) {
|
|
221
|
+
const state = await readState({ transcripts: [id] });
|
|
222
|
+
const session = state.sessions.find((item) => item.id === id);
|
|
223
|
+
const account = session?.accountId ? state.accounts.find((item) => item.id === session.accountId) : void 0;
|
|
224
|
+
if (!session || !account || isClikCodeAgent(session) || account.authKind !== "vendor-cli") return;
|
|
225
|
+
const name = sessionProviderLabel(session);
|
|
226
|
+
const command = session.nativeHarness ?? account.provider;
|
|
227
|
+
if (account.status === "needs_login" || await accountSignedOutOnDisk(account)) {
|
|
228
|
+
if (process.stdin.isTTY) return;
|
|
229
|
+
throw new Error(`${name} is not signed in. Run \`${harnessCommand()} accounts login ${command}\` in a terminal.`);
|
|
230
|
+
}
|
|
231
|
+
if (!accountCanTakeTurn(account)) {
|
|
232
|
+
const why = account.verification ? "it needs verification with the vendor" : account.usage?.label ?? "it is out of usage";
|
|
233
|
+
throw new Error(`${name} account "${account.label}" cannot take a turn: ${why}. Add or switch to another account, or wait for it to reset.`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
async function setChatPermissions(id, mode) {
|
|
237
|
+
const { sessionPermissionModes, setSessionHarnessOption } = await import("./chunk-23TDEBGZ.js");
|
|
238
|
+
const state = await readState({ transcripts: [id] });
|
|
239
|
+
const session = state.sessions.find((item) => item.id === id);
|
|
240
|
+
if (!session) throw new Error(`AI session "${id}" was not found`);
|
|
241
|
+
const harness = !isClikCodeAgent(session) && session.nativeHarness ? localHarnessForCommand(session.nativeHarness) : void 0;
|
|
242
|
+
const supported = sessionPermissionModes(session, harness);
|
|
243
|
+
if (!supported.includes(mode)) {
|
|
244
|
+
throw new Error(`${sessionProviderLabel(session)} supports ${supported.join(", ") || "no"} permission modes, not ${mode}`);
|
|
245
|
+
}
|
|
246
|
+
if (harness) setSessionHarnessOption(session, harness, "permissions", mode);
|
|
247
|
+
else session.permissionMode = mode;
|
|
248
|
+
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
249
|
+
await writeState(state);
|
|
250
|
+
}
|
|
251
|
+
async function startOrResumeAgentChat(options) {
|
|
252
|
+
const { applyClikCodeAgentSessionPolicy, launchSession } = await import("./chunk-AEMHSXKA.js");
|
|
253
|
+
const state = await readState({ transcripts: [] });
|
|
254
|
+
let session;
|
|
255
|
+
if (options.chat) {
|
|
256
|
+
const id = await resolveChat(options.chat);
|
|
257
|
+
session = state.sessions.find((item) => item.id === id);
|
|
258
|
+
if (session && session.route !== options.route) {
|
|
259
|
+
throw new Error(`that chat runs on ${sessionProviderLabel(session)}; move it with /provider, or leave out --chat to start a new one`);
|
|
260
|
+
}
|
|
261
|
+
} else {
|
|
262
|
+
session = launchSession(state, process.cwd());
|
|
263
|
+
applyClikCodeAgentSessionPolicy(session, options.route, state);
|
|
264
|
+
state.sessions.push(session);
|
|
265
|
+
forceStoreSession(session.id);
|
|
266
|
+
}
|
|
267
|
+
if (!session) throw new Error(`AI session "${options.chat}" was not found`);
|
|
268
|
+
if (options.model) {
|
|
269
|
+
if (options.route === "gateway") {
|
|
270
|
+
const { chooseGatewayModel } = await import("./chunk-AEMHSXKA.js");
|
|
271
|
+
session.model = await chooseGatewayModel(options.model);
|
|
272
|
+
if (session.reported?.model) delete session.reported.model;
|
|
273
|
+
} else {
|
|
274
|
+
const { resolveLocalModelId } = await import("./chunk-PGZ54EDX.js");
|
|
275
|
+
session.model = resolveLocalModelId(options.model);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
await writeState(state);
|
|
279
|
+
if (options.permissions) await setChatPermissions(session.id, options.permissions);
|
|
280
|
+
return session.id;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export {
|
|
284
|
+
aiHarnessSelect,
|
|
285
|
+
signInBeforeUse,
|
|
286
|
+
ensureChatReady,
|
|
287
|
+
resolveChat,
|
|
288
|
+
startOrResumeChat
|
|
289
|
+
};
|