clikcode 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -14
- package/dist/chunk-23TDEBGZ.js +71 -0
- package/dist/chunk-25T3GVS7.js +425 -0
- package/dist/chunk-2BBELGHY.js +11 -0
- package/dist/chunk-2EOL5PZL.js +208 -0
- package/dist/chunk-2GAB36IE.js +26 -0
- package/dist/chunk-2OLS7V66.js +2440 -0
- package/dist/chunk-2QFO2URB.js +179 -0
- package/dist/chunk-2QWPQRSU.js +254 -0
- package/dist/chunk-2YPAPAR3.js +184 -0
- package/dist/chunk-2ZAG5372.js +33 -0
- package/dist/chunk-32IKAIZC.js +12507 -0
- package/dist/chunk-34AZEGYW.js +95 -0
- package/dist/chunk-34JQYQCA.js +175 -0
- package/dist/chunk-34ZISPAO.js +67 -0
- package/dist/chunk-3AAAARE6.js +46 -0
- package/dist/chunk-3AJ6Q3OY.js +510 -0
- package/dist/chunk-3B2CHX7M.js +884 -0
- package/dist/chunk-3BUFORRX.js +59 -0
- package/dist/chunk-3QLHYYFK.js +30 -0
- package/dist/chunk-3RXBMYKZ.js +140 -0
- package/dist/chunk-3TFNIJWS.js +52 -0
- package/dist/chunk-3W3IPDFP.js +119 -0
- package/dist/chunk-3WMS7SEE.js +417 -0
- package/dist/chunk-435ZNSZ3.js +23 -0
- package/dist/chunk-4AQ5NINV.js +39 -0
- package/dist/chunk-4GVEJ5FK.js +168 -0
- package/dist/chunk-4GXAO3UY.js +262 -0
- package/dist/chunk-4L2ZZM4Q.js +332 -0
- package/dist/chunk-4LPDG57B.js +17 -0
- package/dist/chunk-4NN3XQQT.js +223 -0
- package/dist/chunk-4QZEZME7.js +54 -0
- package/dist/chunk-4R6CSC3S.js +38 -0
- package/dist/chunk-4RHXTL3W.js +514 -0
- package/dist/chunk-4SJMPTVQ.js +18 -0
- package/dist/chunk-4VY7G6TX.js +114 -0
- package/dist/chunk-5642PBF7.js +124 -0
- package/dist/chunk-5B6TVO4A.js +33 -0
- package/dist/chunk-5BJLDUPL.js +62 -0
- package/dist/chunk-5HMFFJWU.js +19 -0
- package/dist/chunk-5IKLK33T.js +69 -0
- package/dist/chunk-5NQ5FFMX.js +44 -0
- package/dist/chunk-5QNNW5L6.js +176 -0
- package/dist/chunk-5SM5UAWN.js +239 -0
- package/dist/chunk-5WYJTA6O.js +74 -0
- package/dist/chunk-5ZSR2Y5T.js +227 -0
- package/dist/chunk-5ZWUM5GH.js +39 -0
- package/dist/chunk-64E7D4HY.js +364 -0
- package/dist/chunk-6CK466BC.js +99 -0
- package/dist/chunk-6ES45HHO.js +138 -0
- package/dist/chunk-6HYEZFGL.js +277 -0
- package/dist/chunk-6Y7HLXGW.js +29 -0
- package/dist/chunk-6YKK4FYR.js +258 -0
- package/dist/chunk-74WNMLMS.js +117 -0
- package/dist/chunk-7AULZ7OD.js +55 -0
- package/dist/chunk-7DOKGSUN.js +101 -0
- package/dist/chunk-7IH5LTIZ.js +195 -0
- package/dist/chunk-7ISTS5NS.js +21 -0
- package/dist/chunk-7NMUTGOW.js +527 -0
- package/dist/chunk-7PNHUZEL.js +153 -0
- package/dist/chunk-7TSQLONI.js +88 -0
- package/dist/chunk-AE7TOLD5.js +30 -0
- package/dist/chunk-AEMHSXKA.js +130 -0
- package/dist/chunk-AKRYTS2D.js +211 -0
- package/dist/chunk-AMNSE36L.js +59 -0
- package/dist/chunk-AZVD74ZV.js +23 -0
- package/dist/chunk-B35DVOTK.js +1981 -0
- package/dist/chunk-B4HNJRAH.js +626 -0
- package/dist/chunk-B5WYPPHS.js +13 -0
- package/dist/chunk-BBOVDXQM.js +59 -0
- package/dist/chunk-BD3ECZLK.js +62 -0
- package/dist/chunk-BDGSOT74.js +4578 -0
- package/dist/chunk-BF5VEOPK.js +31 -0
- package/dist/chunk-BFFRW4XH.js +47 -0
- package/dist/chunk-BFPC6PEW.js +208 -0
- package/dist/chunk-BGEMY2JJ.js +376 -0
- package/dist/chunk-BISGNHKD.js +35 -0
- package/dist/chunk-BMRAEBRY.js +21 -0
- package/dist/chunk-BNTXAZXW.js +127 -0
- package/dist/chunk-BOQBXGSN.js +75 -0
- package/dist/chunk-BTJDSTQP.js +213 -0
- package/dist/chunk-BUOPJQP5.js +218 -0
- package/dist/chunk-BXFJS65Q.js +52 -0
- package/dist/chunk-BXPQFSX5.js +59 -0
- package/dist/chunk-C57LIWNY.js +1269 -0
- package/dist/chunk-C6YVCCWR.js +74 -0
- package/dist/chunk-CAADDF6M.js +167 -0
- package/dist/chunk-CBANJFBO.js +69 -0
- package/dist/chunk-CERF3RIB.js +597 -0
- package/dist/chunk-COAS5ETR.js +46 -0
- package/dist/chunk-CQ7J6UQ7.js +78 -0
- package/dist/chunk-CRUVYGO2.js +26 -0
- package/dist/chunk-CVFVFRGN.js +58 -0
- package/dist/chunk-D2UK66HM.js +37 -0
- package/dist/chunk-D2W7SA4R.js +18 -0
- package/dist/chunk-DA44ZENT.js +501 -0
- package/dist/chunk-DAJ76TOC.js +99 -0
- package/dist/chunk-DCZ6CIUM.js +147 -0
- package/dist/chunk-DF35KMXM.js +1314 -0
- package/dist/chunk-DGASQT26.js +151 -0
- package/dist/chunk-DJT57C5P.js +55 -0
- package/dist/chunk-DKDPZTD3.js +44 -0
- package/dist/chunk-DQYVQ2N7.js +77 -0
- package/dist/chunk-DRTP2RTY.js +266 -0
- package/dist/chunk-DW2BMUKY.js +61 -0
- package/dist/chunk-DW5T5ZVU.js +307 -0
- package/dist/chunk-DXKNDNFC.js +164 -0
- package/dist/chunk-DZEQ7UYR.js +291 -0
- package/dist/chunk-E4F4OUAC.js +463 -0
- package/dist/chunk-EE4B6A7W.js +69 -0
- package/dist/chunk-EISKIYWG.js +23 -0
- package/dist/chunk-EKAQK7UQ.js +235 -0
- package/dist/chunk-EOBTJV32.js +123 -0
- package/dist/chunk-ESF3DIZY.js +325 -0
- package/dist/chunk-EVOHOZ4U.js +45 -0
- package/dist/chunk-EXN4KHLB.js +110 -0
- package/dist/chunk-F252T6Y3.js +78 -0
- package/dist/chunk-F3DP4ZA2.js +40 -0
- package/dist/chunk-F6F47QAY.js +58 -0
- package/dist/chunk-FA3Y23ZW.js +57 -0
- package/dist/chunk-FBKXE4EJ.js +640 -0
- package/dist/chunk-FCGEB3H6.js +23 -0
- package/dist/chunk-FF7ZVYJF.js +3732 -0
- package/dist/chunk-FFGKN6L3.js +39 -0
- package/dist/chunk-FFGU4GCC.js +94 -0
- package/dist/chunk-FSFDAOVP.js +74 -0
- package/dist/chunk-FT5TX7OX.js +1573 -0
- package/dist/chunk-G3QP67Z7.js +232 -0
- package/dist/chunk-G5ORJKV2.js +179 -0
- package/dist/chunk-GFNC62PE.js +111 -0
- package/dist/chunk-GGK43Q3N.js +67 -0
- package/dist/chunk-GGYKY4GF.js +11537 -0
- package/dist/chunk-GGYNHGNJ.js +55 -0
- package/dist/chunk-GLY7RM3C.js +354 -0
- package/dist/chunk-GQBZU6EO.js +20 -0
- package/dist/chunk-GSXENUZL.js +9 -0
- package/dist/chunk-GTOAT5D3.js +40 -0
- package/dist/chunk-GWCMDPQU.js +1007 -0
- package/dist/chunk-GXYSMYHJ.js +152 -0
- package/dist/chunk-GYMAI5NY.js +14 -0
- package/dist/chunk-H2VZMKPE.js +30 -0
- package/dist/chunk-H4THUNBM.js +2091 -0
- package/dist/chunk-HGRVSNUZ.js +361 -0
- package/dist/chunk-HI4VY473.js +27 -0
- package/dist/chunk-HOJRSD3Q.js +447 -0
- package/dist/chunk-HRX25W35.js +82 -0
- package/dist/chunk-HSE4AQYV.js +55 -0
- package/dist/chunk-HU5SSUFX.js +383 -0
- package/dist/chunk-I3GDBJLH.js +196 -0
- package/dist/chunk-I75EDU75.js +684 -0
- package/dist/chunk-IBA7DMIO.js +20 -0
- package/dist/chunk-IC6N4NZA.js +231 -0
- package/dist/chunk-IF43HIGV.js +284 -0
- package/dist/chunk-IGZ6C2MC.js +439 -0
- package/dist/chunk-IMLTL2MY.js +192 -0
- package/dist/chunk-IMZL6SGR.js +33 -0
- package/dist/chunk-IS4USJPY.js +516 -0
- package/dist/chunk-ISFSPN2F.js +82 -0
- package/dist/chunk-IXE7GTFI.js +55 -0
- package/dist/chunk-IZ77QJQG.js +36 -0
- package/dist/chunk-J2PACWRQ.js +34 -0
- package/dist/chunk-J6EGFVQX.js +180 -0
- package/dist/chunk-JEKOD43D.js +22 -0
- package/dist/chunk-JGIWATSG.js +30 -0
- package/dist/chunk-JYBONKD4.js +43 -0
- package/dist/chunk-K2NLG2HK.js +454 -0
- package/dist/chunk-KCQ4TBLS.js +164 -0
- package/dist/chunk-KD5KIVMS.js +176 -0
- package/dist/chunk-KHW6TX6I.js +63 -0
- package/dist/chunk-KI5GZFCE.js +520 -0
- package/dist/chunk-KN34B7NO.js +105 -0
- package/dist/chunk-KYUHIFP3.js +136 -0
- package/dist/chunk-KZL5VS4B.js +300 -0
- package/dist/chunk-L3VW3QIH.js +48 -0
- package/dist/chunk-LA6MG4ET.js +2110 -0
- package/dist/chunk-LAVFOA3S.js +66 -0
- package/dist/chunk-LB4OA77N.js +13 -0
- package/dist/chunk-LBFRF2K4.js +196 -0
- package/dist/chunk-LM6EIA4B.js +93 -0
- package/dist/chunk-LPCNRGJ7.js +692 -0
- package/dist/chunk-LSLNL5T3.js +168 -0
- package/dist/chunk-LVRRWP4W.js +568 -0
- package/dist/chunk-LWCFBRHL.js +33 -0
- package/dist/chunk-LXFTMGZZ.js +166 -0
- package/dist/chunk-M33LVA4M.js +151 -0
- package/dist/chunk-M3FO5UMK.js +4944 -0
- package/dist/chunk-M5QNDBAY.js +66 -0
- package/dist/chunk-M6ND6KBE.js +1291 -0
- package/dist/chunk-M7H3WQTE.js +76 -0
- package/dist/chunk-MCBRVPA7.js +191 -0
- package/dist/chunk-MCSDWZET.js +91 -0
- package/dist/chunk-MDT5XDXL.js +289 -0
- package/dist/chunk-MJG3IQY4.js +91 -0
- package/dist/chunk-MOU3N2UL.js +44 -0
- package/dist/chunk-MP4KZOQC.js +3451 -0
- package/dist/chunk-MPAJ446F.js +66 -0
- package/dist/chunk-MVJZZ6AL.js +16 -0
- package/dist/chunk-MXS6S2PY.js +253 -0
- package/dist/chunk-N3SFDYM7.js +291 -0
- package/dist/chunk-NAOX3JUB.js +13 -0
- package/dist/chunk-NEKKIBCX.js +283 -0
- package/dist/chunk-NKDATMEM.js +133 -0
- package/dist/chunk-NR4FMC4K.js +395 -0
- package/dist/chunk-NSOHOJBR.js +221 -0
- package/dist/chunk-NTDB6QKF.js +29 -0
- package/dist/chunk-NWEYRBWK.js +25 -0
- package/dist/chunk-O2YSNYWD.js +23 -0
- package/dist/chunk-O3EW7LAY.js +54 -0
- package/dist/chunk-O7BNJIXU.js +366 -0
- package/dist/chunk-OARL2NXZ.js +116 -0
- package/dist/chunk-OHKZUEJW.js +351 -0
- package/dist/chunk-OKU45BXA.js +647 -0
- package/dist/chunk-OL4JBD3J.js +59 -0
- package/dist/chunk-OLUO5DDR.js +192 -0
- package/dist/chunk-OQ245JLA.js +196 -0
- package/dist/chunk-P72UZAQI.js +289 -0
- package/dist/chunk-PAL2ENB6.js +20 -0
- package/dist/chunk-PAXYQZH7.js +53 -0
- package/dist/chunk-PDPEM5VW.js +51 -0
- package/dist/chunk-PEWCDI2C.js +668 -0
- package/dist/chunk-PGZ54EDX.js +27 -0
- package/dist/chunk-PRWVLDZF.js +73 -0
- package/dist/chunk-PSQQ75VJ.js +52 -0
- package/dist/chunk-PUOVIFHW.js +118 -0
- package/dist/chunk-PWBF2X3V.js +107 -0
- package/dist/chunk-PWXII6HF.js +43 -0
- package/dist/chunk-Q35VLJRT.js +80 -0
- package/dist/chunk-QJP7EYGL.js +128 -0
- package/dist/chunk-QPQKX2MK.js +8836 -0
- package/dist/chunk-QQRLPY25.js +1053 -0
- package/dist/chunk-QUS4ER2W.js +407 -0
- package/dist/chunk-QYHI3YET.js +29 -0
- package/dist/chunk-QYRU2UQI.js +32 -0
- package/dist/chunk-R6XVVQGC.js +13 -0
- package/dist/chunk-R7QN6ONS.js +483 -0
- package/dist/chunk-RD23MPGC.js +221 -0
- package/dist/chunk-RDDWQBEM.js +185 -0
- package/dist/chunk-RDLLDYFO.js +104 -0
- package/dist/chunk-RE4TGORR.js +84 -0
- package/dist/chunk-RJLHVYQY.js +217 -0
- package/dist/chunk-RJLPTWHW.js +905 -0
- package/dist/chunk-RKUVLRZI.js +295 -0
- package/dist/chunk-ROGXPGYR.js +37 -0
- package/dist/chunk-RSZGEL5U.js +163 -0
- package/dist/chunk-RVUOIJXN.js +909 -0
- package/dist/chunk-RW7F4JRP.js +11 -0
- package/dist/chunk-S4UO3AO3.js +53 -0
- package/dist/chunk-S5JAAF6S.js +585 -0
- package/dist/chunk-SNU37TQI.js +56 -0
- package/dist/chunk-SQVUDO2O.js +31 -0
- package/dist/chunk-SYVHIYQT.js +66 -0
- package/dist/chunk-SZBQMTG2.js +85 -0
- package/dist/chunk-T5VCXA3J.js +25 -0
- package/dist/chunk-TK6NSP56.js +30 -0
- package/dist/chunk-TKWVMA6L.js +22 -0
- package/dist/chunk-TQDKJHWX.js +59 -0
- package/dist/chunk-TQDM7S5N.js +127 -0
- package/dist/chunk-TULAXS77.js +23 -0
- package/dist/chunk-TVT45XNH.js +4625 -0
- package/dist/chunk-TWCVV2JO.js +467 -0
- package/dist/chunk-U4DKAD6S.js +47 -0
- package/dist/chunk-UA5K2BTI.js +564 -0
- package/dist/chunk-UAMKCMOK.js +40 -0
- package/dist/chunk-UBMVADBF.js +51 -0
- package/dist/chunk-UFQ5A5PW.js +645 -0
- package/dist/chunk-UOD2SOLL.js +1301 -0
- package/dist/chunk-UTSB4LOW.js +156 -0
- package/dist/chunk-UVXNIUTN.js +412 -0
- package/dist/chunk-UXVPXYPE.js +90 -0
- package/dist/chunk-UYEEMIWR.js +374 -0
- package/dist/chunk-VBGM5ZBW.js +54 -0
- package/dist/chunk-VEWPCZPG.js +762 -0
- package/dist/chunk-VIRDLZ5E.js +108 -0
- package/dist/chunk-VMPO7WKN.js +52 -0
- package/dist/chunk-W2NVSDO5.js +5122 -0
- package/dist/chunk-W3YYPBEA.js +176 -0
- package/dist/chunk-W5AYOICN.js +280 -0
- package/dist/chunk-W5GZOIUF.js +27 -0
- package/dist/chunk-WHKNLZ3C.js +76 -0
- package/dist/chunk-WKBEPPQ5.js +1409 -0
- package/dist/chunk-WM3Z6QKQ.js +151 -0
- package/dist/chunk-WMI2TPMA.js +31 -0
- package/dist/chunk-WNX5VD7S.js +150 -0
- package/dist/chunk-WOVTYST3.js +60 -0
- package/dist/chunk-WPB5WEZJ.js +546 -0
- package/dist/chunk-WUO5EOAT.js +44 -0
- package/dist/chunk-WWLJMP6D.js +133 -0
- package/dist/chunk-WZMLH3XP.js +58 -0
- package/dist/chunk-WZYVLUVQ.js +79 -0
- package/dist/chunk-X2OCPVU5.js +135 -0
- package/dist/chunk-X3CL6DTR.js +95 -0
- package/dist/chunk-X6WF7JEV.js +354 -0
- package/dist/chunk-XAHGBPWT.js +44 -0
- package/dist/chunk-XCKQ5BM2.js +228 -0
- package/dist/chunk-XIBYREEY.js +106 -0
- package/dist/chunk-XKW5NDMR.js +378 -0
- package/dist/chunk-XRDALAO3.js +100 -0
- package/dist/chunk-XUP22EAS.js +41 -0
- package/dist/chunk-XWAC3MKW.js +243 -0
- package/dist/chunk-Y3R7JMXB.js +59 -0
- package/dist/chunk-Y54LTP4W.js +82 -0
- package/dist/chunk-Y7UECI4M.js +99 -0
- package/dist/chunk-YACGDFHC.js +47 -0
- package/dist/chunk-YHNIQPKY.js +71 -0
- package/dist/chunk-YMBR6HYP.js +111 -0
- package/dist/chunk-YMCH3L2S.js +26 -0
- package/dist/chunk-Z4ZU6T7V.js +99 -0
- package/dist/chunk-ZDPF67ZZ.js +173 -0
- package/dist/chunk-ZFC2Q67K.js +101 -0
- package/dist/chunk-ZGHNNSCT.js +114 -0
- package/dist/chunk-ZGX3ERAT.js +173 -0
- package/dist/chunk-ZI3YHEBY.js +37 -0
- package/dist/chunk-ZN7G6JLS.js +639 -0
- package/dist/chunk-ZNPFQMXT.js +47 -0
- package/dist/chunk-ZOU3LV4U.js +63 -0
- package/dist/chunk-ZT7B4H2V.js +117 -0
- package/dist/chunk-ZZCBDNZI.js +58 -0
- package/dist/cli.js +498 -112593
- package/dist/computer-tools.js +36642 -21258
- package/dist/harness-catalog.cjs +88 -43
- package/dist/index.js +1 -1
- package/dist/local-model-supervisor.cjs +555 -0
- package/package.json +3 -4
|
@@ -0,0 +1,1981 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
accountList,
|
|
5
|
+
addAccountForHarness,
|
|
6
|
+
browseSearch,
|
|
7
|
+
chatSettings,
|
|
8
|
+
conversationList,
|
|
9
|
+
dispatchLine,
|
|
10
|
+
gatewayCheckoutUrl,
|
|
11
|
+
gatewayCreditLabel,
|
|
12
|
+
gatewayStatus,
|
|
13
|
+
harnessOf,
|
|
14
|
+
manageAccountAction,
|
|
15
|
+
modelList,
|
|
16
|
+
offerResumeIn,
|
|
17
|
+
planModeOnChat,
|
|
18
|
+
providerList,
|
|
19
|
+
setAgentPlanMode,
|
|
20
|
+
shouldWarmVendorChat,
|
|
21
|
+
useAddedAccount,
|
|
22
|
+
walkTurns
|
|
23
|
+
} from "./chunk-WKBEPPQ5.js";
|
|
24
|
+
import {
|
|
25
|
+
queuedNext
|
|
26
|
+
} from "./chunk-PAL2ENB6.js";
|
|
27
|
+
import {
|
|
28
|
+
SessionDeltaSender,
|
|
29
|
+
interactiveSessionPicker,
|
|
30
|
+
withArgValues
|
|
31
|
+
} from "./chunk-LPCNRGJ7.js";
|
|
32
|
+
import {
|
|
33
|
+
IDE_PROTOCOL
|
|
34
|
+
} from "./chunk-VEWPCZPG.js";
|
|
35
|
+
import {
|
|
36
|
+
encodeTerminalSpec
|
|
37
|
+
} from "./chunk-O2YSNYWD.js";
|
|
38
|
+
import {
|
|
39
|
+
WindowSignIns,
|
|
40
|
+
commandDuringTurn,
|
|
41
|
+
slashLineIsCommand
|
|
42
|
+
} from "./chunk-KD5KIVMS.js";
|
|
43
|
+
import {
|
|
44
|
+
watchConversationList
|
|
45
|
+
} from "./chunk-ZGHNNSCT.js";
|
|
46
|
+
import {
|
|
47
|
+
hostedAdapter,
|
|
48
|
+
hostedList,
|
|
49
|
+
hostedPlan,
|
|
50
|
+
hostedSelectionCommand
|
|
51
|
+
} from "./chunk-S5JAAF6S.js";
|
|
52
|
+
import {
|
|
53
|
+
TERMINAL_ONLY_COMMANDS,
|
|
54
|
+
aiSessionCommand,
|
|
55
|
+
aiSettingsSetGlobal,
|
|
56
|
+
lastAnswer,
|
|
57
|
+
slashControls,
|
|
58
|
+
slashHelpText,
|
|
59
|
+
slashPalette
|
|
60
|
+
} from "./chunk-H4THUNBM.js";
|
|
61
|
+
import {
|
|
62
|
+
isShellCommandLine,
|
|
63
|
+
liveSettingsOf
|
|
64
|
+
} from "./chunk-32IKAIZC.js";
|
|
65
|
+
import {
|
|
66
|
+
autoSelectSessionHarness,
|
|
67
|
+
providerConversationKey
|
|
68
|
+
} from "./chunk-M7H3WQTE.js";
|
|
69
|
+
import {
|
|
70
|
+
selectProviderConversation
|
|
71
|
+
} from "./chunk-QPQKX2MK.js";
|
|
72
|
+
import {
|
|
73
|
+
conversationCost
|
|
74
|
+
} from "./chunk-LBFRF2K4.js";
|
|
75
|
+
import {
|
|
76
|
+
GATEWAY_ID
|
|
77
|
+
} from "./chunk-J6EGFVQX.js";
|
|
78
|
+
import {
|
|
79
|
+
afterTurnFailure,
|
|
80
|
+
claimConversation,
|
|
81
|
+
leaveConversation,
|
|
82
|
+
newConversation,
|
|
83
|
+
openConversation,
|
|
84
|
+
prepareTurn,
|
|
85
|
+
resolveSessionModel,
|
|
86
|
+
selectGatewayAgent
|
|
87
|
+
} from "./chunk-RJLPTWHW.js";
|
|
88
|
+
import {
|
|
89
|
+
sessionHarness,
|
|
90
|
+
slashExtrasFor,
|
|
91
|
+
slashRouteContextFor
|
|
92
|
+
} from "./chunk-2EOL5PZL.js";
|
|
93
|
+
import {
|
|
94
|
+
followModelDownloadsInEditor,
|
|
95
|
+
holdLocalModelAfterTurn,
|
|
96
|
+
reconcileLocalModelLeases
|
|
97
|
+
} from "./chunk-UYEEMIWR.js";
|
|
98
|
+
import {
|
|
99
|
+
resumeWaitLabel
|
|
100
|
+
} from "./chunk-IF43HIGV.js";
|
|
101
|
+
import {
|
|
102
|
+
synchronizeNativeTranscript
|
|
103
|
+
} from "./chunk-PUOVIFHW.js";
|
|
104
|
+
import {
|
|
105
|
+
nativeUsageReading,
|
|
106
|
+
recheckRecoveredAccounts,
|
|
107
|
+
signInCancelledLine
|
|
108
|
+
} from "./chunk-LA6MG4ET.js";
|
|
109
|
+
import {
|
|
110
|
+
emitHarnessOutput,
|
|
111
|
+
panelParts,
|
|
112
|
+
renderPanelText,
|
|
113
|
+
sessionModelLabel
|
|
114
|
+
} from "./chunk-4RHXTL3W.js";
|
|
115
|
+
import {
|
|
116
|
+
catalogModel,
|
|
117
|
+
resolveLocalModelId
|
|
118
|
+
} from "./chunk-TQDKJHWX.js";
|
|
119
|
+
import {
|
|
120
|
+
embeddedImageReferences,
|
|
121
|
+
expandHomePath,
|
|
122
|
+
queueAttachment
|
|
123
|
+
} from "./chunk-DCZ6CIUM.js";
|
|
124
|
+
import {
|
|
125
|
+
usageNextReset,
|
|
126
|
+
usageResetLabel,
|
|
127
|
+
usageWindowsDetail
|
|
128
|
+
} from "./chunk-XWAC3MKW.js";
|
|
129
|
+
import {
|
|
130
|
+
WorkerClient,
|
|
131
|
+
warmSessionWorker
|
|
132
|
+
} from "./chunk-KI5GZFCE.js";
|
|
133
|
+
import {
|
|
134
|
+
MOVED_REASON,
|
|
135
|
+
cancelOrigin,
|
|
136
|
+
shownSettingsKey
|
|
137
|
+
} from "./chunk-UBMVADBF.js";
|
|
138
|
+
import {
|
|
139
|
+
readState
|
|
140
|
+
} from "./chunk-MXS6S2PY.js";
|
|
141
|
+
import {
|
|
142
|
+
writeState
|
|
143
|
+
} from "./chunk-RKUVLRZI.js";
|
|
144
|
+
import {
|
|
145
|
+
pinDraft,
|
|
146
|
+
unpinDraft
|
|
147
|
+
} from "./chunk-BGEMY2JJ.js";
|
|
148
|
+
import {
|
|
149
|
+
parseSendMode,
|
|
150
|
+
sendModeOf
|
|
151
|
+
} from "./chunk-TWCVV2JO.js";
|
|
152
|
+
import {
|
|
153
|
+
GATEWAY_LABEL,
|
|
154
|
+
isClikCodeAgent,
|
|
155
|
+
isGatewayService
|
|
156
|
+
} from "./chunk-CRUVYGO2.js";
|
|
157
|
+
import {
|
|
158
|
+
consumeSessionTurn
|
|
159
|
+
} from "./chunk-FF7ZVYJF.js";
|
|
160
|
+
import {
|
|
161
|
+
viewedActivity
|
|
162
|
+
} from "./chunk-3B2CHX7M.js";
|
|
163
|
+
import {
|
|
164
|
+
loadChatLog
|
|
165
|
+
} from "./chunk-RVUOIJXN.js";
|
|
166
|
+
import {
|
|
167
|
+
CONVERSATION_HANDOFF_REASON,
|
|
168
|
+
currentWorkerBuild,
|
|
169
|
+
readWorkerRecord,
|
|
170
|
+
workerIsReachable
|
|
171
|
+
} from "./chunk-QUS4ER2W.js";
|
|
172
|
+
import {
|
|
173
|
+
localHarnessForCommand
|
|
174
|
+
} from "./chunk-KYUHIFP3.js";
|
|
175
|
+
import {
|
|
176
|
+
sleep
|
|
177
|
+
} from "./chunk-YMCH3L2S.js";
|
|
178
|
+
import {
|
|
179
|
+
CLIKCODE_VERSION
|
|
180
|
+
} from "./chunk-NAOX3JUB.js";
|
|
181
|
+
import {
|
|
182
|
+
lifecycle,
|
|
183
|
+
quiet,
|
|
184
|
+
setLifecycleSession
|
|
185
|
+
} from "./chunk-RDDWQBEM.js";
|
|
186
|
+
import {
|
|
187
|
+
safeRecordFileName,
|
|
188
|
+
stateDirectory
|
|
189
|
+
} from "./chunk-MPAJ446F.js";
|
|
190
|
+
|
|
191
|
+
// src/ide/activity-details.ts
|
|
192
|
+
function activityDetails(session, ids, scope = {}) {
|
|
193
|
+
const wanted = new Set(ids);
|
|
194
|
+
const found = /* @__PURE__ */ new Map();
|
|
195
|
+
const visit = (items) => {
|
|
196
|
+
if (!Array.isArray(items)) return;
|
|
197
|
+
for (const item of items) {
|
|
198
|
+
const event = item?.event;
|
|
199
|
+
if (event?.id && wanted.has(event.id)) found.set(event.id, event);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
const messages = session.messages ?? [];
|
|
203
|
+
if (scope.messageIndex !== void 0 && scope.messageIndex < messages.length) {
|
|
204
|
+
visit(messages[scope.messageIndex]?.activities);
|
|
205
|
+
} else if (scope.userIndex !== void 0) {
|
|
206
|
+
const answer = messages.slice(scope.userIndex + 1).find((message) => message.role === "assistant");
|
|
207
|
+
if (answer) visit(answer.activities);
|
|
208
|
+
else visit(session.pendingTurn?.activities);
|
|
209
|
+
} else visit(session.pendingTurn?.activities);
|
|
210
|
+
return [...found.values()];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// src/ide/upload.ts
|
|
214
|
+
import { mkdtemp, open, rm } from "node:fs/promises";
|
|
215
|
+
import { tmpdir } from "node:os";
|
|
216
|
+
import { basename, extname, join } from "node:path";
|
|
217
|
+
var IMAGE_EXTENSIONS = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".gif", ".webp"]);
|
|
218
|
+
var MAX_IMAGE_BYTES = 20 * 1024 * 1024;
|
|
219
|
+
var MAX_FILE_BYTES = 100 * 1024 * 1024;
|
|
220
|
+
var MAX_CHUNK_BYTES = 256 * 1024;
|
|
221
|
+
var MAX_OPEN_UPLOADS = 4;
|
|
222
|
+
var ABANDONED_MS = 2 * 6e4;
|
|
223
|
+
var ideUploadLimits = { maxImageBytes: MAX_IMAGE_BYTES, maxFileBytes: MAX_FILE_BYTES, maxChunkBytes: MAX_CHUNK_BYTES };
|
|
224
|
+
function safeUploadName(name) {
|
|
225
|
+
const base = basename(name.replace(/\\/g, "/")).replace(/[\u0000-\u001f\u007f<>:"|?*]/g, "").replace(/^\.+/, "").trim();
|
|
226
|
+
const extension = extname(base).slice(0, 16);
|
|
227
|
+
const stem = base.slice(0, base.length - extname(base).length).slice(0, 120 - extension.length);
|
|
228
|
+
return `${stem || "file"}${extension}`;
|
|
229
|
+
}
|
|
230
|
+
var IdeUploads = class {
|
|
231
|
+
open = /* @__PURE__ */ new Map();
|
|
232
|
+
finished = /* @__PURE__ */ new Map();
|
|
233
|
+
async start(id, name, size) {
|
|
234
|
+
if (!/^[A-Za-z0-9_-]{8,80}$/.test(id)) throw new Error("Invalid upload id.");
|
|
235
|
+
if (this.open.has(id)) throw new Error("That upload is already open.");
|
|
236
|
+
if (this.open.size >= MAX_OPEN_UPLOADS) throw new Error("Too many files are uploading at once.");
|
|
237
|
+
const safe = safeUploadName(String(name));
|
|
238
|
+
const image = IMAGE_EXTENSIONS.has(extname(safe).toLowerCase());
|
|
239
|
+
const limit = image ? MAX_IMAGE_BYTES : MAX_FILE_BYTES;
|
|
240
|
+
if (!Number.isSafeInteger(size) || size <= 0) throw new Error("An attachment cannot be empty.");
|
|
241
|
+
if (size > limit) throw new Error(image ? "Images are limited to 20 MiB each." : "Files are limited to 100 MiB each.");
|
|
242
|
+
const directory = await mkdtemp(join(tmpdir(), "clikcode-upload."));
|
|
243
|
+
try {
|
|
244
|
+
const path = join(directory, safe);
|
|
245
|
+
const handle = await open(path, "wx", 384);
|
|
246
|
+
this.open.set(id, { path, directory, name: safe, image, handle, size, written: 0, expires: this.abandon(() => this.abort(id)) });
|
|
247
|
+
} catch (error) {
|
|
248
|
+
await rm(directory, { recursive: true, force: true });
|
|
249
|
+
throw error;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
async append(id, offset, encoded) {
|
|
253
|
+
const upload = this.open.get(id);
|
|
254
|
+
if (!upload) throw new Error("That upload expired. Try again.");
|
|
255
|
+
if (!Number.isSafeInteger(offset) || offset !== upload.written) throw new Error("Upload arrived out of order.");
|
|
256
|
+
if (typeof encoded !== "string" || encoded.length > Math.ceil(MAX_CHUNK_BYTES / 3) * 4 + 4 || !/^[A-Za-z0-9+/]*={0,2}$/.test(encoded)) throw new Error("Invalid upload data.");
|
|
257
|
+
const bytes = Buffer.from(encoded, "base64");
|
|
258
|
+
if (bytes.length === 0 || bytes.length > MAX_CHUNK_BYTES || upload.written + bytes.length > upload.size) throw new Error("Invalid upload chunk size.");
|
|
259
|
+
await upload.handle.write(bytes, 0, bytes.length, upload.written);
|
|
260
|
+
upload.written += bytes.length;
|
|
261
|
+
clearTimeout(upload.expires);
|
|
262
|
+
upload.expires = this.abandon(() => this.abort(id));
|
|
263
|
+
}
|
|
264
|
+
/** The staged path, to be named in `send.attachments`. */
|
|
265
|
+
async finish(id) {
|
|
266
|
+
const upload = this.open.get(id);
|
|
267
|
+
if (!upload) throw new Error("That upload expired. Try again.");
|
|
268
|
+
if (upload.written !== upload.size) throw new Error("Upload ended before all bytes arrived.");
|
|
269
|
+
this.open.delete(id);
|
|
270
|
+
clearTimeout(upload.expires);
|
|
271
|
+
await upload.handle.close();
|
|
272
|
+
const { path, directory, name, image } = upload;
|
|
273
|
+
this.finished.set(path, { path, directory, name, image, expires: this.abandon(() => this.discard(path)) });
|
|
274
|
+
return path;
|
|
275
|
+
}
|
|
276
|
+
/** Hands a finished upload to the turn attaching it. Only a path this bridge
|
|
277
|
+
* staged itself can be attached: undefined for anything else. */
|
|
278
|
+
claim(path) {
|
|
279
|
+
const staged = this.finished.get(path);
|
|
280
|
+
if (!staged) return void 0;
|
|
281
|
+
this.finished.delete(path);
|
|
282
|
+
clearTimeout(staged.expires);
|
|
283
|
+
const { expires: _expires, ...upload } = staged;
|
|
284
|
+
return upload;
|
|
285
|
+
}
|
|
286
|
+
async abort(id) {
|
|
287
|
+
const upload = this.open.get(id);
|
|
288
|
+
if (!upload) return;
|
|
289
|
+
this.open.delete(id);
|
|
290
|
+
clearTimeout(upload.expires);
|
|
291
|
+
await upload.handle.close().catch(quiet("ide/upload"));
|
|
292
|
+
await rm(upload.directory, { recursive: true, force: true }).catch(quiet("ide/upload"));
|
|
293
|
+
}
|
|
294
|
+
async close() {
|
|
295
|
+
await Promise.all([...this.open.keys()].map((id) => this.abort(id)));
|
|
296
|
+
await Promise.all([...this.finished.keys()].map((path) => this.discard(path)));
|
|
297
|
+
}
|
|
298
|
+
async discard(path) {
|
|
299
|
+
const staged = this.claim(path);
|
|
300
|
+
if (staged) await rm(staged.directory, { recursive: true, force: true }).catch(quiet("ide/upload"));
|
|
301
|
+
}
|
|
302
|
+
abandon(drop) {
|
|
303
|
+
const timer = setTimeout(() => {
|
|
304
|
+
void drop();
|
|
305
|
+
}, ABANDONED_MS);
|
|
306
|
+
timer.unref?.();
|
|
307
|
+
return timer;
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
// src/ide/bridge.ts
|
|
312
|
+
import { stripVTControlCharacters } from "node:util";
|
|
313
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
314
|
+
|
|
315
|
+
// src/ide/prompter.ts
|
|
316
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
317
|
+
import { randomUUID } from "node:crypto";
|
|
318
|
+
|
|
319
|
+
// src/ide/session-event.ts
|
|
320
|
+
function sessionProvider(session) {
|
|
321
|
+
if (session.route === "gateway") return { id: "gateway", name: GATEWAY_LABEL };
|
|
322
|
+
if (session.route === "clikcode-local") return { id: "gateway", name: GATEWAY_LABEL };
|
|
323
|
+
if (!session.nativeHarness) return {};
|
|
324
|
+
const name = localHarnessForCommand(session.nativeHarness)?.displayName;
|
|
325
|
+
return { id: session.nativeHarness, ...name ? { name } : {} };
|
|
326
|
+
}
|
|
327
|
+
function sessionEvent(session, account) {
|
|
328
|
+
const automatic = session.route === "gateway" && !session.model && !session.gatewayAgentId;
|
|
329
|
+
const model = automatic ? "auto" : session.reported?.model ?? session.model ?? void 0;
|
|
330
|
+
const label = model ? sessionModelLabel(session, model) : void 0;
|
|
331
|
+
const provider = sessionProvider(session);
|
|
332
|
+
return {
|
|
333
|
+
type: "session",
|
|
334
|
+
session,
|
|
335
|
+
...account ? { account } : {},
|
|
336
|
+
...model && label ? { modelLabel: { model, label } } : {},
|
|
337
|
+
...provider.id ? { providerId: provider.id } : {},
|
|
338
|
+
...provider.name ? { providerName: provider.name } : {}
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// src/ide/prompter.ts
|
|
343
|
+
function pickItems(options) {
|
|
344
|
+
return options.map((option) => ({
|
|
345
|
+
label: option.label,
|
|
346
|
+
...option.detail ? { detail: option.detail } : {},
|
|
347
|
+
...option.group ? { group: option.group } : {},
|
|
348
|
+
...option.argHint ? { argHint: option.argHint } : {},
|
|
349
|
+
...option.actions?.length ? { actions: option.actions.map(({ label, value }) => ({ label, value })) } : {},
|
|
350
|
+
...option.deleteAction ? { deleteAction: { label: option.deleteAction.label, value: option.deleteAction.value } } : {},
|
|
351
|
+
...option.inline ? { inline: { choices: option.inline.choices.map(({ label, value }) => ({ label, value })), current: option.inline.current } } : {}
|
|
352
|
+
}));
|
|
353
|
+
}
|
|
354
|
+
var IdePrompter = class {
|
|
355
|
+
constructor(channel) {
|
|
356
|
+
this.channel = channel;
|
|
357
|
+
}
|
|
358
|
+
channel;
|
|
359
|
+
pending = /* @__PURE__ */ new Map();
|
|
360
|
+
filters = /* @__PURE__ */ new Map();
|
|
361
|
+
/** Sign-ins whose card the panel shows, by id: its Cancel aborts one. */
|
|
362
|
+
signIns = /* @__PURE__ */ new Map();
|
|
363
|
+
/** The key row a sign-in's card offers, by sign-in id: what is typed there. */
|
|
364
|
+
signInAnswers = /* @__PURE__ */ new Map();
|
|
365
|
+
/** The bridge's queued job a sign-in opens inside: it lets the queue go
|
|
366
|
+
* (see IdeBridge.enqueue). */
|
|
367
|
+
queueHolder = new AsyncLocalStorage();
|
|
368
|
+
/** Pickers, inputs and sign-ins open in the editor now. */
|
|
369
|
+
get openCount() {
|
|
370
|
+
return this.pending.size + this.signIns.size;
|
|
371
|
+
}
|
|
372
|
+
/** Runs `work`; a sign-in opening anywhere inside it calls `release`. */
|
|
373
|
+
holding(release, work) {
|
|
374
|
+
return this.queueHolder.run(release, work);
|
|
375
|
+
}
|
|
376
|
+
/** A vendor sign-in in the panel: a card with its link and code (which
|
|
377
|
+
* the extension opens on the editor's machine) and Cancel; a code or key
|
|
378
|
+
* entered on that same card; a choice in a pick list. `busy` says it too,
|
|
379
|
+
* for an extension from before the card. */
|
|
380
|
+
signInScreen(name) {
|
|
381
|
+
const id = randomUUID();
|
|
382
|
+
const controller = new AbortController();
|
|
383
|
+
this.signIns.set(id, controller);
|
|
384
|
+
this.queueHolder.getStore()?.();
|
|
385
|
+
this.channel.send({ type: "busy", label: `signing in to ${name}\u2026` });
|
|
386
|
+
let card = {};
|
|
387
|
+
const sendCard = () => this.channel.send({ type: "sign-in-link", id, name, ...card });
|
|
388
|
+
sendCard();
|
|
389
|
+
const stop = () => {
|
|
390
|
+
this.signInAnswers.delete(id);
|
|
391
|
+
if (!this.signIns.delete(id)) return;
|
|
392
|
+
this.channel.send({ type: "sign-in-link", id, name, done: true });
|
|
393
|
+
this.channel.send({ type: "busy" });
|
|
394
|
+
};
|
|
395
|
+
return {
|
|
396
|
+
signal: controller.signal,
|
|
397
|
+
show: (link) => {
|
|
398
|
+
card = { ...card, url: link.url, ...link.code ? { code: link.code } : {} };
|
|
399
|
+
sendCard();
|
|
400
|
+
},
|
|
401
|
+
ask: async (prompt, secret, _optional, alongside) => {
|
|
402
|
+
if (alongside || secret) {
|
|
403
|
+
card = { ...card, ask: { prompt, ...secret ? { secret: true } : {} } };
|
|
404
|
+
sendCard();
|
|
405
|
+
return new Promise((resolve) => {
|
|
406
|
+
this.signInAnswers.set(id, (text) => {
|
|
407
|
+
this.signInAnswers.delete(id);
|
|
408
|
+
const { ask: _answered, ...rest } = card;
|
|
409
|
+
card = rest;
|
|
410
|
+
sendCard();
|
|
411
|
+
resolve(text);
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
const result = await this.ask({ kind: "input", prompt, ...secret ? { secret: true } : {} });
|
|
416
|
+
if ("text" in result) return result.text;
|
|
417
|
+
controller.abort();
|
|
418
|
+
return "";
|
|
419
|
+
},
|
|
420
|
+
choose: (title, choices) => this.select(title, choices.map((choice, index) => ({ label: choice, value: index }))),
|
|
421
|
+
stop,
|
|
422
|
+
// Taken down at once (the card goes), the vendor's login stopped by the abort.
|
|
423
|
+
withdraw: () => {
|
|
424
|
+
controller.abort();
|
|
425
|
+
stop();
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
/** The card's Cancel. */
|
|
430
|
+
cancelSignIn(id) {
|
|
431
|
+
this.signIns.get(id)?.abort();
|
|
432
|
+
}
|
|
433
|
+
/** A key typed into the card's key row. */
|
|
434
|
+
answerSignIn(id, text) {
|
|
435
|
+
this.signInAnswers.get(id)?.(text);
|
|
436
|
+
}
|
|
437
|
+
/** An answer from the editor. Unknown ids are ignored: a request the
|
|
438
|
+
* bridge already gave up on is simply late. */
|
|
439
|
+
answer(id, result) {
|
|
440
|
+
const resolve = this.pending.get(id);
|
|
441
|
+
if (!resolve) return;
|
|
442
|
+
this.pending.delete(id);
|
|
443
|
+
resolve(result);
|
|
444
|
+
}
|
|
445
|
+
search(id, query) {
|
|
446
|
+
const filter = this.filters.get(id);
|
|
447
|
+
if (!filter) return;
|
|
448
|
+
const revision = ++filter.revision;
|
|
449
|
+
void filter.query(query).then((items) => {
|
|
450
|
+
if (this.filters.get(id) !== filter || filter.revision !== revision) return;
|
|
451
|
+
this.channel.send({ type: "ui-update", id, items: pickItems(items) });
|
|
452
|
+
}, () => void 0);
|
|
453
|
+
}
|
|
454
|
+
/** Everything still open is cancelled -- the editor went away. */
|
|
455
|
+
cancelAll() {
|
|
456
|
+
for (const [id, resolve] of [...this.pending]) {
|
|
457
|
+
this.pending.delete(id);
|
|
458
|
+
resolve({ cancelled: true });
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
ask(request, id = randomUUID()) {
|
|
462
|
+
return new Promise((resolve) => {
|
|
463
|
+
this.pending.set(id, resolve);
|
|
464
|
+
this.channel.send({ type: "ui-request", id, request });
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
async question(prompt, _commands, settings) {
|
|
468
|
+
const result = await this.ask({ kind: "input", prompt: prompt.replace(/\s*›\s*$/, ""), ...settings?.secret ? { secret: true } : {} });
|
|
469
|
+
return "text" in result ? result.text : "";
|
|
470
|
+
}
|
|
471
|
+
async select(title, options, onAction, settings) {
|
|
472
|
+
let current = options;
|
|
473
|
+
let refresh = settings?.refresh;
|
|
474
|
+
for (; ; ) {
|
|
475
|
+
if (!current.length) return void 0;
|
|
476
|
+
const id = randomUUID();
|
|
477
|
+
const shown = current;
|
|
478
|
+
if (settings?.onFilter) this.filters.set(id, { query: async (query) => {
|
|
479
|
+
current = await settings.onFilter(query);
|
|
480
|
+
return current;
|
|
481
|
+
}, revision: 0 });
|
|
482
|
+
const answer = this.ask({ kind: "pick", title, items: pickItems(shown), canGoBack: Boolean(settings?.onBack), searchable: Boolean(settings?.onFilter) }, id);
|
|
483
|
+
if (refresh && settings?.refreshedOptions) {
|
|
484
|
+
const pendingRefresh = refresh;
|
|
485
|
+
refresh = void 0;
|
|
486
|
+
for (const stage of [pendingRefresh].flat()) {
|
|
487
|
+
void stage.then(() => {
|
|
488
|
+
if (!this.pending.has(id)) return;
|
|
489
|
+
current = settings.refreshedOptions();
|
|
490
|
+
this.channel.send({ type: "ui-update", id, items: pickItems(current) });
|
|
491
|
+
}, () => void 0);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
const result = await answer;
|
|
495
|
+
this.filters.delete(id);
|
|
496
|
+
if ("cancelled" in result) {
|
|
497
|
+
if (result.back && settings?.onBack) settings.onBack();
|
|
498
|
+
else settings?.onEscape?.();
|
|
499
|
+
return void 0;
|
|
500
|
+
}
|
|
501
|
+
if (!("index" in result)) return void 0;
|
|
502
|
+
const option = current[result.index];
|
|
503
|
+
if (!option) return void 0;
|
|
504
|
+
if (result.action !== void 0) {
|
|
505
|
+
await onAction?.(option.value, result.action);
|
|
506
|
+
return void 0;
|
|
507
|
+
}
|
|
508
|
+
if (option.inline) {
|
|
509
|
+
const { choices, current: selected } = option.inline;
|
|
510
|
+
const next = choices.find((choice) => choice.value === result.value) ?? choices[(choices.findIndex((choice) => choice.value === selected) + 1) % choices.length];
|
|
511
|
+
if (next) await option.inline.apply(next.value);
|
|
512
|
+
current = settings?.refreshedOptions?.() ?? current.map((item) => item === option && next ? { ...item, inline: { ...option.inline, current: next.value } } : item);
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
return option.value;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
render(session, account) {
|
|
519
|
+
this.channel.send(sessionEvent(session, account));
|
|
520
|
+
}
|
|
521
|
+
panel(title, body) {
|
|
522
|
+
this.channel.send({ type: "panel", title, body });
|
|
523
|
+
}
|
|
524
|
+
close() {
|
|
525
|
+
this.cancelAll();
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
// src/ide/session-wire.ts
|
|
530
|
+
var WHOLE_MESSAGES = 8;
|
|
531
|
+
var PREVIEW_MESSAGES = 48;
|
|
532
|
+
function wireMessage(message, after) {
|
|
533
|
+
if (after < WHOLE_MESSAGES || !message.activities?.length) return message;
|
|
534
|
+
const bare = after >= PREVIEW_MESSAGES;
|
|
535
|
+
const activities = message.activities.map((item) => item && typeof item === "object" && "event" in item ? viewedActivity(item, bare) : item);
|
|
536
|
+
return { ...message, activities };
|
|
537
|
+
}
|
|
538
|
+
var WHOLE_CALLS = 12;
|
|
539
|
+
var PREVIEW_CALLS = 40;
|
|
540
|
+
function wireCalls(activities) {
|
|
541
|
+
return activities.map((item, index) => {
|
|
542
|
+
const after = activities.length - 1 - index;
|
|
543
|
+
if (after < WHOLE_CALLS || !item || typeof item !== "object" || !("event" in item)) return item;
|
|
544
|
+
return viewedActivity(item, after >= PREVIEW_CALLS);
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
function wireTurn(turn) {
|
|
548
|
+
return turn.activities?.length ? { ...turn, activities: wireCalls(turn.activities) } : turn;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
// src/ide/bridge-slash-host.ts
|
|
552
|
+
import { existsSync } from "node:fs";
|
|
553
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
554
|
+
import { dirname } from "node:path";
|
|
555
|
+
function searchScreen(host) {
|
|
556
|
+
let shown = Promise.resolve();
|
|
557
|
+
return {
|
|
558
|
+
showMention: (session, focus) => {
|
|
559
|
+
shown = shown.then(async () => {
|
|
560
|
+
if (session.id !== host.sessionId) await host.switchTo(session.id);
|
|
561
|
+
host.channel.send({ type: "search", focus: {
|
|
562
|
+
sessionId: session.id,
|
|
563
|
+
messageIndex: focus.messageIndex,
|
|
564
|
+
occurrence: focus.occurrence,
|
|
565
|
+
words: [...focus.words],
|
|
566
|
+
status: focus.status ?? ""
|
|
567
|
+
} });
|
|
568
|
+
});
|
|
569
|
+
},
|
|
570
|
+
mentionKey: async () => {
|
|
571
|
+
await shown;
|
|
572
|
+
if (host.closed) return "done";
|
|
573
|
+
return new Promise((resolve) => {
|
|
574
|
+
host.setSearchKey(resolve);
|
|
575
|
+
});
|
|
576
|
+
},
|
|
577
|
+
endMention: () => {
|
|
578
|
+
host.setSearchKey(void 0);
|
|
579
|
+
host.channel.send({ type: "search" });
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
function createSlashHost(host, turns) {
|
|
584
|
+
return {
|
|
585
|
+
config: host.config,
|
|
586
|
+
prompter: host.prompter,
|
|
587
|
+
canPick: true,
|
|
588
|
+
pickProviderBeforeSending: true,
|
|
589
|
+
panel: (_kind, title, body) => host.prompter.panel(title, body),
|
|
590
|
+
withBusy: (label, work) => turns.withBusy(label, work),
|
|
591
|
+
ask: (label) => host.prompter.question(label),
|
|
592
|
+
redraw: () => host.emitSession(),
|
|
593
|
+
runTurn: (targetId, prompt) => turns.runTurn(targetId, prompt, { echo: false }),
|
|
594
|
+
openConversationPicker: async (id) => {
|
|
595
|
+
const picked = await interactiveSessionPicker(host.prompter, id);
|
|
596
|
+
if (picked && "new" in picked) return { id: await newConversation(id) };
|
|
597
|
+
return { id: picked?.id ?? id };
|
|
598
|
+
},
|
|
599
|
+
editFile: async (path) => {
|
|
600
|
+
if (!existsSync(path)) {
|
|
601
|
+
await mkdir(dirname(path), { recursive: true });
|
|
602
|
+
await writeFile(path, "", { flag: "a" });
|
|
603
|
+
}
|
|
604
|
+
host.channel.send({ type: "open-file", path });
|
|
605
|
+
},
|
|
606
|
+
runManager: (harness, label, argv, environment) => host.runInTerminal({ command: harness.command, mode: "run", argv }, { environment, name: `${harness.displayName} ${label}` }),
|
|
607
|
+
exported: (path) => host.channel.send({ type: "open-file", path }),
|
|
608
|
+
// Each step of /update, as the chat's own notice (in a terminal client
|
|
609
|
+
// of a chat on this machine too: remote/terminal-chat.ts shows them).
|
|
610
|
+
line: (text) => host.channel.send({ type: "notice", message: text, level: "info" }),
|
|
611
|
+
// The terminal's walk, where the editor can show it.
|
|
612
|
+
...host.features.has("search-walk") ? {
|
|
613
|
+
browseSearch: (query) => browseSearch(searchScreen(host), query, (label, work) => turns.withBusy(label, work)),
|
|
614
|
+
walkTurns: (turns2, start) => walkTurns(searchScreen(host), turns2, start)
|
|
615
|
+
} : {},
|
|
616
|
+
intercept: (route, session, harness) => {
|
|
617
|
+
const name = route.entry.name;
|
|
618
|
+
if (TERMINAL_ONLY_COMMANDS.has(name)) return { notice: `/${name} is for the terminal; the editor has no use for it.` };
|
|
619
|
+
if (name === "help") {
|
|
620
|
+
emitHarnessOutput({ panel: "help", helpText: slashHelpText(session, harness, { ...slashExtrasFor(session, harness), omit: TERMINAL_ONLY_COMMANDS }), controls: slashControls() });
|
|
621
|
+
return {};
|
|
622
|
+
}
|
|
623
|
+
if (name === "copy" && host.features.has("copy")) {
|
|
624
|
+
host.channel.send({ type: "copy", text: lastAnswer(session) });
|
|
625
|
+
return { notice: "Last response copied to the clipboard." };
|
|
626
|
+
}
|
|
627
|
+
return void 0;
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// src/session/retained-images.ts
|
|
633
|
+
import { createHash } from "node:crypto";
|
|
634
|
+
import { createReadStream } from "node:fs";
|
|
635
|
+
import { copyFile, mkdir as mkdir2, readFile, writeFile as writeFile2 } from "node:fs/promises";
|
|
636
|
+
import { extname as extname2, join as join2 } from "node:path";
|
|
637
|
+
import { pipeline } from "node:stream/promises";
|
|
638
|
+
function conversationAttachmentsDirectory(sessionId) {
|
|
639
|
+
return join2(stateDirectory(), "attachments", safeRecordFileName(sessionId));
|
|
640
|
+
}
|
|
641
|
+
async function retainUpload(path, name, sessionId) {
|
|
642
|
+
const hash = createHash("sha256");
|
|
643
|
+
await pipeline(createReadStream(path), hash);
|
|
644
|
+
const directory = join2(conversationAttachmentsDirectory(sessionId), hash.digest("hex").slice(0, 32));
|
|
645
|
+
await mkdir2(directory, { recursive: true, mode: 448 });
|
|
646
|
+
const file = join2(directory, name);
|
|
647
|
+
try {
|
|
648
|
+
await copyFile(
|
|
649
|
+
path,
|
|
650
|
+
file,
|
|
651
|
+
1
|
|
652
|
+
/* COPYFILE_EXCL */
|
|
653
|
+
);
|
|
654
|
+
} catch (error) {
|
|
655
|
+
if (error.code !== "EEXIST") throw error;
|
|
656
|
+
}
|
|
657
|
+
return file;
|
|
658
|
+
}
|
|
659
|
+
async function retainUploadedImages(text, sessionId) {
|
|
660
|
+
let retained = text;
|
|
661
|
+
for (const { token, path } of await embeddedImageReferences(text, process.cwd())) {
|
|
662
|
+
if (!/\/clikcode-image\.[^/]+\/image\.(?:png|jpe?g|gif|webp)$/i.test(path)) continue;
|
|
663
|
+
const bytes = await readFile(path);
|
|
664
|
+
if (bytes.length > 20 * 1024 * 1024) throw new Error("Image attachments are limited to 20 MiB each.");
|
|
665
|
+
const directory = conversationAttachmentsDirectory(sessionId);
|
|
666
|
+
await mkdir2(directory, { recursive: true, mode: 448 });
|
|
667
|
+
const file = join2(directory, `${createHash("sha256").update(bytes).digest("hex")}${extname2(path).toLowerCase()}`);
|
|
668
|
+
try {
|
|
669
|
+
await writeFile2(file, bytes, { flag: "wx", mode: 384 });
|
|
670
|
+
} catch (error) {
|
|
671
|
+
if (error.code !== "EEXIST") throw error;
|
|
672
|
+
}
|
|
673
|
+
retained = retained.split(token).join(file);
|
|
674
|
+
}
|
|
675
|
+
return retained;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
// src/ide/bridge-turns.ts
|
|
679
|
+
import { existsSync as existsSync2 } from "node:fs";
|
|
680
|
+
import { rm as rm2 } from "node:fs/promises";
|
|
681
|
+
|
|
682
|
+
// src/ide/bridge-support.ts
|
|
683
|
+
var TurnFailed = class extends Error {
|
|
684
|
+
};
|
|
685
|
+
var WorkerRetiring = class extends Error {
|
|
686
|
+
};
|
|
687
|
+
function messageOf(error) {
|
|
688
|
+
return error instanceof Error ? error.message : String(error);
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
// src/ide/bridge-turns.ts
|
|
692
|
+
var RETIRING_RETRY_MS = [150, 300, 600, 1200, 2400];
|
|
693
|
+
var BridgeTurns = class {
|
|
694
|
+
constructor(host, uploads) {
|
|
695
|
+
this.host = host;
|
|
696
|
+
this.uploads = uploads;
|
|
697
|
+
}
|
|
698
|
+
host;
|
|
699
|
+
uploads;
|
|
700
|
+
/** The same-provider retry after running out: once per interrupted turn. */
|
|
701
|
+
exhaustionGuard = {};
|
|
702
|
+
/** What the last turn actually sent, when a slash command expanded the
|
|
703
|
+
* line (/review): what an interrupted turn recorded is compared to. */
|
|
704
|
+
sentPrompt;
|
|
705
|
+
/** Counted by every Stop: a submit prepared before one is dropped, not sent
|
|
706
|
+
* (the Stop reached the worker while nothing was there to stop). */
|
|
707
|
+
cancelEpoch = 0;
|
|
708
|
+
/** The epoch the queued send job was typed at. */
|
|
709
|
+
submitEpoch;
|
|
710
|
+
/** Whether the line being executed reached its turn (turn-start was sent). */
|
|
711
|
+
turnStarted = false;
|
|
712
|
+
/** The window's identity for the send currently entering a new turn. */
|
|
713
|
+
submissionId;
|
|
714
|
+
noteCancel() {
|
|
715
|
+
this.cancelEpoch++;
|
|
716
|
+
}
|
|
717
|
+
/** Takes the files a `send` names from this bridge's uploads into the
|
|
718
|
+
* conversation. Images are queued for the turn, so the model is shown them;
|
|
719
|
+
* every other file is kept with the conversation and named in the message,
|
|
720
|
+
* so the agent can open it with its own tools. Returns the message to send. */
|
|
721
|
+
async attach(paths, line) {
|
|
722
|
+
if (paths.length > 10) throw new Error("A message can carry up to 10 attachments.");
|
|
723
|
+
const staged = paths.map((path) => this.uploads.claim(path));
|
|
724
|
+
try {
|
|
725
|
+
if (staged.some((upload) => !upload)) throw new Error("An attachment expired before it was sent. Attach it again.");
|
|
726
|
+
const sessionId = this.host.requireSession();
|
|
727
|
+
const state = await readState({ transcripts: [sessionId] });
|
|
728
|
+
const session = state.sessions.find((item) => item.id === sessionId);
|
|
729
|
+
if (!session) throw new Error("The ClikCode conversation is no longer available.");
|
|
730
|
+
const files = [];
|
|
731
|
+
for (const upload of staged) {
|
|
732
|
+
const kept = await retainUpload(upload.path, upload.name, sessionId);
|
|
733
|
+
if (upload.image) await queueAttachment(session, kept);
|
|
734
|
+
else files.push(kept);
|
|
735
|
+
}
|
|
736
|
+
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
737
|
+
await writeState(state);
|
|
738
|
+
if (files.length) return [line, ...files.map((file) => `Attached file: ${file}`)].filter(Boolean).join("\n");
|
|
739
|
+
return line || (staged.length === 1 ? "Look at the attached image." : "Look at the attached images.");
|
|
740
|
+
} finally {
|
|
741
|
+
for (const upload of staged) if (upload) await rm2(upload.directory, { recursive: true, force: true }).catch(quiet("ide/bridge"));
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
async send(text, id, mode, attachments = []) {
|
|
745
|
+
let line = text.trim();
|
|
746
|
+
const complete = () => {
|
|
747
|
+
if (id) this.host.channel.send({ type: "send-complete", id });
|
|
748
|
+
};
|
|
749
|
+
if (!line && !attachments.length) {
|
|
750
|
+
complete();
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
try {
|
|
754
|
+
if (attachments.length) {
|
|
755
|
+
line = await this.attach(attachments, line);
|
|
756
|
+
mode = "queue";
|
|
757
|
+
} else if (this.host.sessionId) line = await retainUploadedImages(line, this.host.sessionId);
|
|
758
|
+
if (this.host.link.workerTurnRunning && this.host.link.worker) {
|
|
759
|
+
const sessionId = this.host.link.worker.sessionId;
|
|
760
|
+
const { session } = await this.host.current(sessionId);
|
|
761
|
+
const context = slashRouteContextFor(session, sessionHarness(session), (path) => existsSync2(expandHomePath(path)));
|
|
762
|
+
if (isShellCommandLine(line) || slashLineIsCommand(line, context)) {
|
|
763
|
+
const result = await commandDuringTurn(sessionId, line);
|
|
764
|
+
if (id) this.host.channel.send({ type: "worker", sessionId, event: { type: "submission", id, disposition: result.disposition, ...result.commandOutcome ? { commandOutcome: result.commandOutcome } : {} } });
|
|
765
|
+
await this.host.emitSession();
|
|
766
|
+
complete();
|
|
767
|
+
return;
|
|
768
|
+
}
|
|
769
|
+
this.host.link.worker.client.send({ type: "steer", text: line, ...id ? { id } : {}, ...mode ? { mode } : {} });
|
|
770
|
+
complete();
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
} catch (error) {
|
|
774
|
+
this.host.channel.send({ type: "restore-draft", text: line });
|
|
775
|
+
this.host.report(error);
|
|
776
|
+
complete();
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
const typedAt = this.cancelEpoch;
|
|
780
|
+
this.host.link.stopped = false;
|
|
781
|
+
this.host.enqueue(async () => {
|
|
782
|
+
try {
|
|
783
|
+
this.submitEpoch = typedAt;
|
|
784
|
+
this.submissionId = id;
|
|
785
|
+
await this.host.execute(line, {});
|
|
786
|
+
this.submissionId = void 0;
|
|
787
|
+
await this.host.drainQueue();
|
|
788
|
+
} finally {
|
|
789
|
+
this.submissionId = void 0;
|
|
790
|
+
complete();
|
|
791
|
+
}
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
/** Messages typed during a turn that the harness could not take mid-turn,
|
|
795
|
+
* and commands that waited for the turn to end: sent in order, as the
|
|
796
|
+
* interactive loop does at the top of every pass. */
|
|
797
|
+
async drainQueue() {
|
|
798
|
+
let previous;
|
|
799
|
+
while (!this.host.closed && this.host.sessionId) {
|
|
800
|
+
const state = await readState({ transcripts: [this.host.sessionId] });
|
|
801
|
+
const session = state.sessions.find((item) => item.id === this.host.sessionId);
|
|
802
|
+
const next = session ? queuedNext(session, { stopped: this.host.link.stopped, ...previous ? { justRan: previous } : {} }) : void 0;
|
|
803
|
+
if (!session || !next) return;
|
|
804
|
+
const queued = next.entry;
|
|
805
|
+
previous = queued.id;
|
|
806
|
+
if (next.kind === "command") {
|
|
807
|
+
if (consumeSessionTurn(session, queued.id)) await writeState(state);
|
|
808
|
+
await this.host.execute(queued.text, { fromQueuedCommand: true });
|
|
809
|
+
} else {
|
|
810
|
+
await this.host.execute(queued.text, { queuedTurnId: queued.id });
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
async execute(line, options) {
|
|
815
|
+
const id = this.host.requireSession();
|
|
816
|
+
this.sentPrompt = void 0;
|
|
817
|
+
this.turnStarted = false;
|
|
818
|
+
try {
|
|
819
|
+
if (options.queuedTurnId) {
|
|
820
|
+
await this.host.runTurn(id, line, { echo: true, queuedTurnId: options.queuedTurnId });
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
const outcome = await this.host.dispatch(line, Boolean(options.fromQueuedCommand));
|
|
824
|
+
if (outcome.notice) this.host.channel.send({ type: "notice", message: outcome.notice, level: "info" });
|
|
825
|
+
if (outcome.exit) {
|
|
826
|
+
this.host.channel.send({ type: "closed", sessionId: id });
|
|
827
|
+
this.host.closeConversation();
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
if (outcome.id && outcome.id !== this.host.sessionId) await this.host.switchTo(outcome.id);
|
|
831
|
+
else await this.host.emitSession();
|
|
832
|
+
if (outcome.draft !== void 0) this.host.channel.send({ type: "restore-draft", text: outcome.draft });
|
|
833
|
+
if (outcome.prompt) {
|
|
834
|
+
this.sentPrompt = outcome.prompt;
|
|
835
|
+
await this.host.runTurn(this.host.requireSession(), outcome.prompt, { echo: outcome.echo !== false });
|
|
836
|
+
}
|
|
837
|
+
} catch (error) {
|
|
838
|
+
const next = await afterTurnFailure(this.host.prompter && offerResumeIn(this.host.prompter), id, error, {
|
|
839
|
+
line,
|
|
840
|
+
sent: this.sentPrompt ?? line,
|
|
841
|
+
guard: this.exhaustionGuard,
|
|
842
|
+
...options.queuedTurnId ? { queuedTurnId: options.queuedTurnId } : {}
|
|
843
|
+
});
|
|
844
|
+
if ("retry" in next) {
|
|
845
|
+
await this.host.execute(next.retry, {});
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
if ("moved" in next) {
|
|
849
|
+
await this.host.switchTo(next.moved.id);
|
|
850
|
+
if (next.moved.prompt !== void 0) await this.host.execute(next.moved.prompt, {});
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
if (next.waiting) {
|
|
854
|
+
this.host.link.worker?.client.send({ type: "refresh" });
|
|
855
|
+
this.host.channel.send({ type: "notice", message: `${resumeWaitLabel(next.waiting)} \xB7 a new message cancels`, level: "info" });
|
|
856
|
+
void this.host.refreshUsage().catch(quiet("ide/bridge-turns"));
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
859
|
+
const back = !this.turnStarted && !options.queuedTurnId && !next.cancelled && this.sentPrompt !== void 0 && !next.back.includes(line) ? [...next.back, line] : next.back;
|
|
860
|
+
if (back.length) this.host.channel.send({ type: "restore-draft", text: back.join("\n\n") });
|
|
861
|
+
this.host.report(error);
|
|
862
|
+
} finally {
|
|
863
|
+
await this.host.emitSession().catch(quiet("ide/bridge-turns"));
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
/** One turn through the conversation's worker, after what the terminal
|
|
867
|
+
* does before one (prepareTurn). */
|
|
868
|
+
async runTurn(targetId, prompt, turn) {
|
|
869
|
+
try {
|
|
870
|
+
await this.sendTurn(targetId, prompt, turn);
|
|
871
|
+
} finally {
|
|
872
|
+
await holdLocalModelAfterTurn(targetId).catch(quiet("ide/bridge-turns"));
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
async sendTurn(targetId, prompt, turn) {
|
|
876
|
+
const epoch = this.submitEpoch ?? this.cancelEpoch;
|
|
877
|
+
this.submitEpoch = void 0;
|
|
878
|
+
await prepareTurn(targetId);
|
|
879
|
+
await this.host.prepareRoute();
|
|
880
|
+
const client = await this.host.link.workerFor(targetId);
|
|
881
|
+
if (epoch !== this.cancelEpoch) {
|
|
882
|
+
this.host.link.stopped = true;
|
|
883
|
+
this.host.channel.send({ type: "worker", sessionId: targetId, event: { type: "submit-rejected", message: "Stopped" } });
|
|
884
|
+
if (turn.echo && !turn.queuedTurnId) this.host.channel.send({ type: "worker", sessionId: targetId, event: { type: "restore-draft", text: prompt } });
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
887
|
+
this.turnStarted = true;
|
|
888
|
+
this.host.channel.send({ type: "turn-start", sessionId: targetId, ...this.submissionId ? { submissionId: this.submissionId } : {}, ...turn.echo ? { prompt } : {}, ...turn.queuedTurnId ? { queuedTurnId: turn.queuedTurnId } : {} });
|
|
889
|
+
let current = client;
|
|
890
|
+
for (let attempt = 0; ; attempt++) {
|
|
891
|
+
try {
|
|
892
|
+
await new Promise((resolve, reject) => {
|
|
893
|
+
this.host.link.turnWaiter = { resolve, reject };
|
|
894
|
+
current.send({ type: "submit", text: prompt, echo: turn.echo, ...turn.queuedTurnId ? { queuedTurnId: turn.queuedTurnId } : {} });
|
|
895
|
+
});
|
|
896
|
+
return;
|
|
897
|
+
} catch (error) {
|
|
898
|
+
if (error instanceof WorkerRetiring && attempt < RETIRING_RETRY_MS.length) {
|
|
899
|
+
this.host.link.detach();
|
|
900
|
+
await sleep(RETIRING_RETRY_MS[attempt]);
|
|
901
|
+
current = await this.host.link.workerFor(targetId);
|
|
902
|
+
continue;
|
|
903
|
+
}
|
|
904
|
+
throw error instanceof TurnFailed || error instanceof WorkerRetiring ? error : new TurnFailed(messageOf(error));
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
/** A line typed between turns: the terminal's routing (dispatchLine), with
|
|
909
|
+
* the editor's widgets where the terminal draws its own. */
|
|
910
|
+
async dispatch(line, fromQueuedCommand) {
|
|
911
|
+
const id = this.host.requireSession();
|
|
912
|
+
if (isShellCommandLine(line)) {
|
|
913
|
+
return this.withBusy(line, () => this.host.quietly(async () => {
|
|
914
|
+
const resulting = await aiSessionCommand(id, line);
|
|
915
|
+
return resulting !== id ? { id: resulting } : {};
|
|
916
|
+
}));
|
|
917
|
+
}
|
|
918
|
+
return dispatchLine(createSlashHost(this.host, this), id, line, { fromQueuedCommand });
|
|
919
|
+
}
|
|
920
|
+
async withBusy(label, work) {
|
|
921
|
+
this.host.channel.send({ type: "busy", label });
|
|
922
|
+
try {
|
|
923
|
+
return await work();
|
|
924
|
+
} finally {
|
|
925
|
+
this.host.channel.send({ type: "busy" });
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
};
|
|
929
|
+
|
|
930
|
+
// src/ide/bridge-choose-conversation.ts
|
|
931
|
+
async function chooseConversation(cx, choice) {
|
|
932
|
+
const { host, queued } = cx;
|
|
933
|
+
switch (choice.kind) {
|
|
934
|
+
case "conversation": {
|
|
935
|
+
const current = choice.sessionId === host.sessionId;
|
|
936
|
+
if (current && host.link.workerTurnRunning && choice.action === "delete") {
|
|
937
|
+
throw new Error("A turn is running in this conversation: stop it first.");
|
|
938
|
+
}
|
|
939
|
+
queued(async () => {
|
|
940
|
+
const replacement = current && choice.action === "delete" ? await newConversation(choice.sessionId) : void 0;
|
|
941
|
+
if (choice.action === "rename") {
|
|
942
|
+
const name = choice.name?.trim();
|
|
943
|
+
if (!name) throw new Error("A name is needed.");
|
|
944
|
+
await aiSessionCommand(choice.sessionId, `/rename ${name}`);
|
|
945
|
+
} else await aiSessionCommand(choice.sessionId, "/delete confirm");
|
|
946
|
+
if (replacement) await host.switchTo(replacement);
|
|
947
|
+
else if (host.sessionId) await host.emitSession();
|
|
948
|
+
return { sessionId: host.sessionId };
|
|
949
|
+
});
|
|
950
|
+
return true;
|
|
951
|
+
}
|
|
952
|
+
default:
|
|
953
|
+
return false;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
// src/ide/bridge-choose-provider.ts
|
|
958
|
+
async function chooseProvider(cx, choice) {
|
|
959
|
+
const { host, done, queued } = cx;
|
|
960
|
+
switch (choice.kind) {
|
|
961
|
+
case "provider": {
|
|
962
|
+
queued(async () => {
|
|
963
|
+
const id = host.requireSession();
|
|
964
|
+
const moved = await selectProviderConversation(host.config, host.prompter, id, providerConversationKey(choice.provider), { offerLocal: true });
|
|
965
|
+
if (choice.model) {
|
|
966
|
+
const { session } = await host.current(moved);
|
|
967
|
+
if (session.route === "gateway" && !await (await import("./chunk-HSE4AQYV.js")).reviewGatewayModelAgreement(choice.model, host.prompter)) return { sessionId: moved };
|
|
968
|
+
await aiSessionCommand(moved, session.route === "clikcode-local" ? `/model --download ${choice.model}` : `/model ${choice.model}`);
|
|
969
|
+
} else await resolveSessionModel(moved);
|
|
970
|
+
if (host.sessionId !== id) return { sessionId: moved };
|
|
971
|
+
if (moved !== id) await host.switchTo(moved);
|
|
972
|
+
await host.prepareRoute().catch(quiet("ide/bridge-choose-provider"));
|
|
973
|
+
await host.emitSession();
|
|
974
|
+
void host.refreshUsage().catch(quiet("ide/bridge-choose-provider"));
|
|
975
|
+
return { sessionId: host.sessionId };
|
|
976
|
+
});
|
|
977
|
+
return true;
|
|
978
|
+
}
|
|
979
|
+
case "hosted":
|
|
980
|
+
queued(async () => {
|
|
981
|
+
const selection = await hostedAdapter(choice.row.target).start(choice.row);
|
|
982
|
+
const id = host.requireSession();
|
|
983
|
+
const moved = selection.route === "gateway" ? await selectProviderConversation(host.config, host.prompter, id, providerConversationKey(GATEWAY_ID)) : id;
|
|
984
|
+
await aiSessionCommand(moved, hostedSelectionCommand(selection));
|
|
985
|
+
if (host.sessionId !== id) return { sessionId: moved };
|
|
986
|
+
if (moved !== id) await host.switchTo(moved);
|
|
987
|
+
await host.prepareRoute().catch(quiet("ide/bridge-choose-provider"));
|
|
988
|
+
await host.emitSession();
|
|
989
|
+
void host.refreshUsage().catch(quiet("ide/bridge-choose-provider"));
|
|
990
|
+
return { sessionId: host.sessionId };
|
|
991
|
+
});
|
|
992
|
+
return true;
|
|
993
|
+
case "add-account":
|
|
994
|
+
queued(async () => {
|
|
995
|
+
const harness = localHarnessForCommand(choice.provider);
|
|
996
|
+
if (!harness) throw new Error(`unknown provider "${choice.provider}"`);
|
|
997
|
+
const added = await addAccountForHarness(host.prompter, harness);
|
|
998
|
+
if (added && host.sessionId) {
|
|
999
|
+
const { session } = await host.current();
|
|
1000
|
+
if (session.provider === harness.provider || session.nativeHarness === harness.command) await useAddedAccount(session.id, harness, added);
|
|
1001
|
+
await host.emitSession();
|
|
1002
|
+
}
|
|
1003
|
+
return { added: added ?? null };
|
|
1004
|
+
});
|
|
1005
|
+
return true;
|
|
1006
|
+
case "account-action":
|
|
1007
|
+
queued(async () => {
|
|
1008
|
+
await manageAccountAction(host.prompter, choice.accountId, choice.action);
|
|
1009
|
+
await host.emitSession().catch(quiet("ide/bridge-choose-provider"));
|
|
1010
|
+
});
|
|
1011
|
+
return true;
|
|
1012
|
+
case "gateway-credit":
|
|
1013
|
+
done({ url: await gatewayCheckoutUrl(host.config) });
|
|
1014
|
+
return true;
|
|
1015
|
+
default:
|
|
1016
|
+
return false;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
// src/ide/bridge-choose-settings.ts
|
|
1021
|
+
async function chooseSetting(cx, choice) {
|
|
1022
|
+
const { host, done, setting } = cx;
|
|
1023
|
+
switch (choice.kind) {
|
|
1024
|
+
case "model": {
|
|
1025
|
+
const { session } = await host.current();
|
|
1026
|
+
if (session.route === "gateway" && !await (await import("./chunk-HSE4AQYV.js")).reviewGatewayModelAgreement(choice.model, host.prompter)) {
|
|
1027
|
+
done();
|
|
1028
|
+
return true;
|
|
1029
|
+
}
|
|
1030
|
+
const line = session.route === "clikcode-local" ? `/model --download ${choice.model}` : `/model ${choice.model}`;
|
|
1031
|
+
await setting(line);
|
|
1032
|
+
done();
|
|
1033
|
+
return true;
|
|
1034
|
+
}
|
|
1035
|
+
case "agent": {
|
|
1036
|
+
await selectGatewayAgent(host.requireSession(), choice.agent ?? void 0);
|
|
1037
|
+
await host.emitSession();
|
|
1038
|
+
done();
|
|
1039
|
+
return true;
|
|
1040
|
+
}
|
|
1041
|
+
case "effort":
|
|
1042
|
+
await setting(`/effort ${choice.value}`);
|
|
1043
|
+
done();
|
|
1044
|
+
return true;
|
|
1045
|
+
case "permissions":
|
|
1046
|
+
await setting(`/permissions ${choice.value}`);
|
|
1047
|
+
done();
|
|
1048
|
+
return true;
|
|
1049
|
+
case "account":
|
|
1050
|
+
await setting(`/accounts use ${choice.accountId}`);
|
|
1051
|
+
done();
|
|
1052
|
+
return true;
|
|
1053
|
+
// Global, not this chat's. With a chat open it goes through the chat as every setting does; with none -- an editor setting its own
|
|
1054
|
+
// for a chat on another machine, asked of this computer's ClikCode -- it is the global setting alone.
|
|
1055
|
+
case "send":
|
|
1056
|
+
if (host.sessionId) await setting(`/send ${choice.mode}`);
|
|
1057
|
+
else await aiSettingsSetGlobal("send", parseSendMode(choice.mode), false);
|
|
1058
|
+
done();
|
|
1059
|
+
return true;
|
|
1060
|
+
case "fast":
|
|
1061
|
+
await setting(`/fast ${choice.on ? "on" : "off"}`);
|
|
1062
|
+
done();
|
|
1063
|
+
return true;
|
|
1064
|
+
case "plan": {
|
|
1065
|
+
const { session } = await host.current();
|
|
1066
|
+
const harness = harnessOf(session);
|
|
1067
|
+
if (planModeOnChat(session, harness)) {
|
|
1068
|
+
await setAgentPlanMode(session.id, choice.on);
|
|
1069
|
+
await host.emitSession();
|
|
1070
|
+
done();
|
|
1071
|
+
return true;
|
|
1072
|
+
}
|
|
1073
|
+
if (!harness?.planMode) throw new Error("This provider has no plan mode.");
|
|
1074
|
+
const on = harness.planMode.value === true ? "on" : String(harness.planMode.value);
|
|
1075
|
+
await setting(`/settings option ${harness.planMode.option} ${choice.on ? on : "default"}`);
|
|
1076
|
+
done();
|
|
1077
|
+
return true;
|
|
1078
|
+
}
|
|
1079
|
+
default:
|
|
1080
|
+
return false;
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
// src/ide/bridge-choose.ts
|
|
1085
|
+
async function routedChoice(host, choice) {
|
|
1086
|
+
if (choice.kind !== "model") return choice;
|
|
1087
|
+
const { session } = await host.current();
|
|
1088
|
+
if (session.route !== "clikcode-local") return choice;
|
|
1089
|
+
const local = (() => {
|
|
1090
|
+
try {
|
|
1091
|
+
return Boolean(catalogModel(resolveLocalModelId(choice.model)));
|
|
1092
|
+
} catch {
|
|
1093
|
+
return false;
|
|
1094
|
+
}
|
|
1095
|
+
})();
|
|
1096
|
+
return local ? choice : { kind: "provider", provider: GATEWAY_ID, model: choice.model };
|
|
1097
|
+
}
|
|
1098
|
+
async function choose(host, requestId, choice) {
|
|
1099
|
+
const done = (data) => host.channel.send({ type: "result", requestId, ok: true, ...data === void 0 ? {} : { data } });
|
|
1100
|
+
const failed = (error) => host.channel.send({ type: "result", requestId, ok: false, error: messageOf(error) });
|
|
1101
|
+
const quietly = (job) => host.quietly(job);
|
|
1102
|
+
const setting = async (line) => {
|
|
1103
|
+
const id = host.requireSession();
|
|
1104
|
+
await quietly(async () => {
|
|
1105
|
+
if (host.link.workerTurnRunning) await commandDuringTurn(id, line);
|
|
1106
|
+
else await aiSessionCommand(id, line);
|
|
1107
|
+
});
|
|
1108
|
+
await host.emitSession();
|
|
1109
|
+
};
|
|
1110
|
+
const queued = (job) => {
|
|
1111
|
+
host.enqueue(async () => {
|
|
1112
|
+
try {
|
|
1113
|
+
done(await quietly(job));
|
|
1114
|
+
} catch (error) {
|
|
1115
|
+
failed(error);
|
|
1116
|
+
}
|
|
1117
|
+
});
|
|
1118
|
+
};
|
|
1119
|
+
const cx = { host, done, setting, queued };
|
|
1120
|
+
try {
|
|
1121
|
+
const routed = await routedChoice(host, choice);
|
|
1122
|
+
if (await chooseSetting(cx, routed)) return;
|
|
1123
|
+
if (await chooseProvider(cx, routed)) return;
|
|
1124
|
+
if (await chooseConversation(cx, routed)) return;
|
|
1125
|
+
throw new Error(`unknown choice "${String(choice.kind)}"`);
|
|
1126
|
+
} catch (error) {
|
|
1127
|
+
failed(error);
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
// src/ide/bridge-query.ts
|
|
1132
|
+
async function answerQuery(host, requestId, query, options) {
|
|
1133
|
+
const answer = (data) => host.channel.send({ type: "result", requestId, ok: true, data });
|
|
1134
|
+
try {
|
|
1135
|
+
const state = await readState({ transcripts: query === "conversations" || !host.sessionId ? [] : [host.sessionId] });
|
|
1136
|
+
const session = host.sessionId ? state.sessions.find((item) => item.id === host.sessionId) : void 0;
|
|
1137
|
+
switch (query) {
|
|
1138
|
+
case "slash-commands": {
|
|
1139
|
+
const { session: current } = await host.current();
|
|
1140
|
+
const harness = sessionHarness(current);
|
|
1141
|
+
const rows = withArgValues(slashPalette(current, harness, { ...slashExtrasFor(current, harness), omit: TERMINAL_ONLY_COMMANDS }), current, harness, state);
|
|
1142
|
+
answer(rows.map((row) => {
|
|
1143
|
+
const values = row.argValues?.();
|
|
1144
|
+
return {
|
|
1145
|
+
command: row.value,
|
|
1146
|
+
description: row.detail ?? "",
|
|
1147
|
+
...row.argHint ? { argHint: row.argHint } : {},
|
|
1148
|
+
group: row.group,
|
|
1149
|
+
...row.aliases?.length ? { aliases: row.aliases } : {},
|
|
1150
|
+
...values?.length ? { argValues: values } : {}
|
|
1151
|
+
};
|
|
1152
|
+
}));
|
|
1153
|
+
return;
|
|
1154
|
+
}
|
|
1155
|
+
case "providers":
|
|
1156
|
+
answer(await providerList(host.config, state, session));
|
|
1157
|
+
return;
|
|
1158
|
+
case "models":
|
|
1159
|
+
if (!options.provider) throw new Error("models needs a provider");
|
|
1160
|
+
answer(await modelList(host.config, state, session, options.provider));
|
|
1161
|
+
return;
|
|
1162
|
+
case "conversations":
|
|
1163
|
+
answer(await conversationList(state, host.sessionId));
|
|
1164
|
+
return;
|
|
1165
|
+
case "accounts":
|
|
1166
|
+
answer(await accountList(state, session, Boolean(options.network)));
|
|
1167
|
+
return;
|
|
1168
|
+
case "chat-settings":
|
|
1169
|
+
answer(session ? await chatSettings(state, session) : {});
|
|
1170
|
+
return;
|
|
1171
|
+
// This machine's choice of what a message typed mid-turn does, with no chat open: an editor showing a chat on another machine asks its own.
|
|
1172
|
+
case "send-mode":
|
|
1173
|
+
answer(sendModeOf(state.globalSettings));
|
|
1174
|
+
return;
|
|
1175
|
+
case "gateway":
|
|
1176
|
+
answer(await gatewayStatus(host.config));
|
|
1177
|
+
return;
|
|
1178
|
+
case "hosted":
|
|
1179
|
+
answer(await hostedList(options.search ?? ""));
|
|
1180
|
+
return;
|
|
1181
|
+
case "hosted-plan":
|
|
1182
|
+
if (!options.row) throw new Error("hosted-plan needs a row");
|
|
1183
|
+
answer(await hostedPlan(options.row));
|
|
1184
|
+
return;
|
|
1185
|
+
default:
|
|
1186
|
+
throw new Error(`unknown query "${String(query)}"`);
|
|
1187
|
+
}
|
|
1188
|
+
} catch (error) {
|
|
1189
|
+
host.channel.send({ type: "result", requestId, ok: false, error: messageOf(error) });
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
// src/ide/notice-level.ts
|
|
1194
|
+
function noticeLevel(text) {
|
|
1195
|
+
const colour = /\u001b\[(?:[0-9;]*;)?(3[13]|9[13])m/.exec(text)?.[1];
|
|
1196
|
+
return colour === "31" || colour === "91" ? "error" : colour === "33" || colour === "93" ? "warning" : "info";
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
// src/ide/bridge-worker.ts
|
|
1200
|
+
var WorkerLink = class {
|
|
1201
|
+
constructor(host) {
|
|
1202
|
+
this.host = host;
|
|
1203
|
+
}
|
|
1204
|
+
host;
|
|
1205
|
+
worker;
|
|
1206
|
+
/** Seen waiting-start without its waiting-stop: a turn is running on this
|
|
1207
|
+
* conversation's worker, whichever client started it. */
|
|
1208
|
+
workerTurnRunning = false;
|
|
1209
|
+
/** The last turn ended stopped: nothing queued behind it runs until the user acts. */
|
|
1210
|
+
stopped = false;
|
|
1211
|
+
/** `taken`: the worker has said it has the submit (a turn started, queued, or failed). Until then it may only be in the socket. */
|
|
1212
|
+
turnWaiter;
|
|
1213
|
+
/** Sign-ins the panel runs for its worker: only for the conversation it
|
|
1214
|
+
* shows, and taken down when it stops showing it or the request closes. */
|
|
1215
|
+
signIns = new WindowSignIns();
|
|
1216
|
+
async workerFor(sessionId) {
|
|
1217
|
+
if (this.worker?.sessionId === sessionId) return this.worker.client;
|
|
1218
|
+
this.detach();
|
|
1219
|
+
const client = await WorkerClient.attach(sessionId);
|
|
1220
|
+
const initial = await client.initialSnapshot;
|
|
1221
|
+
this.worker = { sessionId, client };
|
|
1222
|
+
this.workerTurnRunning = initial.type === "snapshot" && Boolean(initial.live);
|
|
1223
|
+
this.host.channel.send({ type: "worker", sessionId, event: initial });
|
|
1224
|
+
let movedAway = false;
|
|
1225
|
+
client.on("event", (event) => {
|
|
1226
|
+
if (event.type === "shutdown" && (event.reason === MOVED_REASON || event.reason === CONVERSATION_HANDOFF_REASON)) movedAway = true;
|
|
1227
|
+
this.onWorkerEvent(sessionId, client, event);
|
|
1228
|
+
});
|
|
1229
|
+
client.on("close", () => {
|
|
1230
|
+
if (this.worker?.client !== client) return;
|
|
1231
|
+
this.signIns.withdrawAll();
|
|
1232
|
+
const midTurn = this.workerTurnRunning || Boolean(this.turnWaiter);
|
|
1233
|
+
const untaken = this.untakenSubmit();
|
|
1234
|
+
this.worker = void 0;
|
|
1235
|
+
this.workerTurnRunning = false;
|
|
1236
|
+
if (untaken) this.failTurn(new WorkerRetiring("The worker left before it took the message."));
|
|
1237
|
+
else if (midTurn) this.failTurn(new Error("session worker connection closed unexpectedly"));
|
|
1238
|
+
if (this.host.closed || this.host.sessionId !== sessionId || movedAway) return;
|
|
1239
|
+
this.host.enqueue(async () => {
|
|
1240
|
+
if (this.host.closed || this.host.sessionId !== sessionId || this.worker) return;
|
|
1241
|
+
await this.workerFor(sessionId).catch(quiet("ide/bridge-worker"));
|
|
1242
|
+
});
|
|
1243
|
+
});
|
|
1244
|
+
return client;
|
|
1245
|
+
}
|
|
1246
|
+
/** Stop: sent to the worker, attached on the way if need be. The worker
|
|
1247
|
+
* answers (`stopping`, then the turn's end, or `stop-done`); this keeps no
|
|
1248
|
+
* clock and sends nothing twice. */
|
|
1249
|
+
async cancelTurn(restoreDraft, trigger = "editor-stop") {
|
|
1250
|
+
const id = this.host.sessionId;
|
|
1251
|
+
try {
|
|
1252
|
+
const client = this.worker?.client ?? (id ? await this.workerFor(id) : void 0);
|
|
1253
|
+
client?.send({ type: "cancel", restoreDraft, origin: cancelOrigin("bridge", trigger) });
|
|
1254
|
+
} catch (error) {
|
|
1255
|
+
this.host.report(error);
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
detach() {
|
|
1259
|
+
const worker = this.worker;
|
|
1260
|
+
if (!worker) return;
|
|
1261
|
+
this.worker = void 0;
|
|
1262
|
+
this.workerTurnRunning = false;
|
|
1263
|
+
this.signIns.withdrawAll();
|
|
1264
|
+
try {
|
|
1265
|
+
worker.client.send({ type: "detach" });
|
|
1266
|
+
worker.client.close();
|
|
1267
|
+
} catch {
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
onWorkerEvent(sessionId, client, event) {
|
|
1271
|
+
if (event.type === "submit-rejected" && event.retry) {
|
|
1272
|
+
this.failTurn(new WorkerRetiring(event.message));
|
|
1273
|
+
return;
|
|
1274
|
+
}
|
|
1275
|
+
if (this.turnWaiter && (event.type === "waiting-start" || event.type === "submit-queued" || event.type === "turn-error")) this.turnWaiter.taken = true;
|
|
1276
|
+
this.host.channel.send({ type: "worker", sessionId, event, ...event.type === "note" ? { level: noticeLevel(event.message) } : {} });
|
|
1277
|
+
switch (event.type) {
|
|
1278
|
+
case "waiting-start":
|
|
1279
|
+
this.workerTurnRunning = true;
|
|
1280
|
+
this.stopped = false;
|
|
1281
|
+
return;
|
|
1282
|
+
case "sign-in-pending":
|
|
1283
|
+
if (this.host.sessionId === sessionId) client.send({ type: "sign-in-claim", id: event.id });
|
|
1284
|
+
return;
|
|
1285
|
+
case "sign-in-request":
|
|
1286
|
+
if (this.host.sessionId !== sessionId) {
|
|
1287
|
+
client.send({ type: "sign-in-release", id: event.id });
|
|
1288
|
+
return;
|
|
1289
|
+
}
|
|
1290
|
+
this.signIns.run(event, this.host.prompter, (response) => client.send(response), (work) => this.host.prompter.holding(void 0, work));
|
|
1291
|
+
return;
|
|
1292
|
+
case "request-closed":
|
|
1293
|
+
this.signIns.withdraw(event.id);
|
|
1294
|
+
return;
|
|
1295
|
+
case "turn-error":
|
|
1296
|
+
if (this.turnWaiter) this.turnWaiter.error = new TurnFailed(event.message);
|
|
1297
|
+
return;
|
|
1298
|
+
case "waiting-stop": {
|
|
1299
|
+
this.workerTurnRunning = false;
|
|
1300
|
+
this.stopped = event.stopped === true;
|
|
1301
|
+
const waiter = this.turnWaiter;
|
|
1302
|
+
this.turnWaiter = void 0;
|
|
1303
|
+
if (this.host.shown) void this.host.refreshUsage().catch(quiet("ide/bridge-worker"));
|
|
1304
|
+
if (waiter) waiter.error ? waiter.reject(waiter.error) : waiter.resolve();
|
|
1305
|
+
else this.host.scheduleDrain();
|
|
1306
|
+
return;
|
|
1307
|
+
}
|
|
1308
|
+
case "queue-changed":
|
|
1309
|
+
this.host.scheduleDrain();
|
|
1310
|
+
return;
|
|
1311
|
+
case "submit-queued": {
|
|
1312
|
+
if (this.workerTurnRunning) return;
|
|
1313
|
+
const waiter = this.turnWaiter;
|
|
1314
|
+
this.turnWaiter = void 0;
|
|
1315
|
+
waiter?.resolve();
|
|
1316
|
+
return;
|
|
1317
|
+
}
|
|
1318
|
+
case "shutdown":
|
|
1319
|
+
if (this.untakenSubmit()) this.failTurn(new WorkerRetiring(event.reason));
|
|
1320
|
+
else if (this.workerTurnRunning || this.turnWaiter) this.failTurn(new Error(`session worker exited mid-turn: ${event.reason}`));
|
|
1321
|
+
return;
|
|
1322
|
+
default:
|
|
1323
|
+
return;
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
/** A submit was sent and the worker has not said it has it: it may never have been read. */
|
|
1327
|
+
untakenSubmit() {
|
|
1328
|
+
return Boolean(this.turnWaiter) && !this.turnWaiter?.taken && !this.workerTurnRunning;
|
|
1329
|
+
}
|
|
1330
|
+
failTurn(error) {
|
|
1331
|
+
const waiter = this.turnWaiter;
|
|
1332
|
+
this.turnWaiter = void 0;
|
|
1333
|
+
waiter?.reject(error);
|
|
1334
|
+
}
|
|
1335
|
+
/** A turn is running here, or this client is waiting on one it sent. */
|
|
1336
|
+
get running() {
|
|
1337
|
+
return this.workerTurnRunning || Boolean(this.turnWaiter);
|
|
1338
|
+
}
|
|
1339
|
+
};
|
|
1340
|
+
|
|
1341
|
+
// src/ide/bridge.ts
|
|
1342
|
+
var USAGE_REFRESH_MS = 15e3;
|
|
1343
|
+
var READ_ONLY_REQUESTS = /* @__PURE__ */ new Set(["query", "visible", "watch-conversations", "activity-details"]);
|
|
1344
|
+
var HOUSEKEEPING_EVENTS = /* @__PURE__ */ new Set(["usage", "conversations-changed", "result"]);
|
|
1345
|
+
var IdeBridge = class {
|
|
1346
|
+
constructor(config, editor, siblings) {
|
|
1347
|
+
this.config = config;
|
|
1348
|
+
this.siblings = siblings;
|
|
1349
|
+
this.channel = {
|
|
1350
|
+
send: (event) => {
|
|
1351
|
+
if (!HOUSEKEEPING_EVENTS.has(event.type)) this.lastActivityAt = Date.now();
|
|
1352
|
+
editor.send(this.features.has("session-delta") ? this.delta.slim(event) : event);
|
|
1353
|
+
}
|
|
1354
|
+
};
|
|
1355
|
+
const channel = this.channel;
|
|
1356
|
+
this.prompter = new IdePrompter(channel);
|
|
1357
|
+
const bridge = this;
|
|
1358
|
+
this.host = {
|
|
1359
|
+
config,
|
|
1360
|
+
channel,
|
|
1361
|
+
prompter: this.prompter,
|
|
1362
|
+
get sessionId() {
|
|
1363
|
+
return bridge.sessionId;
|
|
1364
|
+
},
|
|
1365
|
+
get closed() {
|
|
1366
|
+
return bridge.closed;
|
|
1367
|
+
},
|
|
1368
|
+
get shown() {
|
|
1369
|
+
return bridge.shown;
|
|
1370
|
+
},
|
|
1371
|
+
get features() {
|
|
1372
|
+
return bridge.features;
|
|
1373
|
+
},
|
|
1374
|
+
get link() {
|
|
1375
|
+
return bridge.link;
|
|
1376
|
+
},
|
|
1377
|
+
quietly: async (job) => {
|
|
1378
|
+
bridge.quietOutput += 1;
|
|
1379
|
+
try {
|
|
1380
|
+
return await job();
|
|
1381
|
+
} finally {
|
|
1382
|
+
bridge.quietOutput -= 1;
|
|
1383
|
+
}
|
|
1384
|
+
},
|
|
1385
|
+
requireSession: () => bridge.requireSession(),
|
|
1386
|
+
current: (id) => bridge.current(id),
|
|
1387
|
+
emitSession: () => bridge.emitSession(),
|
|
1388
|
+
enqueue: (job) => bridge.enqueue(job),
|
|
1389
|
+
report: (error) => bridge.report(error),
|
|
1390
|
+
switchTo: (id) => bridge.switchTo(id),
|
|
1391
|
+
prepareRoute: () => bridge.prepareRoute(),
|
|
1392
|
+
refreshUsage: () => bridge.refreshUsage(),
|
|
1393
|
+
scheduleDrain: () => bridge.scheduleDrain(),
|
|
1394
|
+
closeConversation: () => {
|
|
1395
|
+
bridge.link.detach();
|
|
1396
|
+
bridge.sessionId = void 0;
|
|
1397
|
+
},
|
|
1398
|
+
setSearchKey: (answer) => {
|
|
1399
|
+
bridge.searchKey = answer;
|
|
1400
|
+
},
|
|
1401
|
+
runInTerminal: (spec, request) => bridge.runInTerminal(spec, request),
|
|
1402
|
+
drainQueue: () => bridge.drainQueue(),
|
|
1403
|
+
execute: (line, options) => bridge.execute(line, options),
|
|
1404
|
+
runTurn: (targetId, prompt, turn) => bridge.runTurn(targetId, prompt, turn),
|
|
1405
|
+
dispatch: (line, fromQueuedCommand) => bridge.dispatch(line, fromQueuedCommand)
|
|
1406
|
+
};
|
|
1407
|
+
this.link = new WorkerLink(this.host);
|
|
1408
|
+
this.turns = new BridgeTurns(this.host, this.uploads);
|
|
1409
|
+
this.stopDownloadFeed = followModelDownloadsInEditor((event) => channel.send(event), {
|
|
1410
|
+
sessionId: () => this.sessionId,
|
|
1411
|
+
refresh: () => this.emitSession()
|
|
1412
|
+
});
|
|
1413
|
+
}
|
|
1414
|
+
config;
|
|
1415
|
+
siblings;
|
|
1416
|
+
prompter;
|
|
1417
|
+
sessionId;
|
|
1418
|
+
shownLiveSettings;
|
|
1419
|
+
/** shownSettingsKey of the chat as last sent to the editor. */
|
|
1420
|
+
shownSettings;
|
|
1421
|
+
preparedRoute;
|
|
1422
|
+
drainScheduled = false;
|
|
1423
|
+
work = Promise.resolve();
|
|
1424
|
+
signIns = /* @__PURE__ */ new Map();
|
|
1425
|
+
uploads = new IdeUploads();
|
|
1426
|
+
timers = [];
|
|
1427
|
+
closed = false;
|
|
1428
|
+
/** Open conversations lists in the editor, and the watch behind them. */
|
|
1429
|
+
listWatchers = 0;
|
|
1430
|
+
listWatch;
|
|
1431
|
+
/** A choice made in the editor's own widgets is on screen there already:
|
|
1432
|
+
* its confirmation ("Model set to …", "Renamed to …", an account removed)
|
|
1433
|
+
* is not said again in the chat. Errors still are. */
|
|
1434
|
+
quietOutput = 0;
|
|
1435
|
+
/** What the editor said it handles, with its last `open`. */
|
|
1436
|
+
features = /* @__PURE__ */ new Set();
|
|
1437
|
+
/** What the editor holds of the conversation (the `session-delta` feature). */
|
|
1438
|
+
delta = new SessionDeltaSender(wireMessage, { pendingTurn: wireTurn, liveActivities: wireCalls });
|
|
1439
|
+
/** The editor shows this chat (its `visible`): only then is usage polled. */
|
|
1440
|
+
shown = true;
|
|
1441
|
+
/** /search waiting on the editor's next key. */
|
|
1442
|
+
searchKey;
|
|
1443
|
+
/** What the parts of the bridge (bridge-*.ts) see of it. */
|
|
1444
|
+
host;
|
|
1445
|
+
link;
|
|
1446
|
+
turns;
|
|
1447
|
+
channel;
|
|
1448
|
+
/** Requests still being answered, and jobs queued or running (enqueue). */
|
|
1449
|
+
inFlight = 0;
|
|
1450
|
+
/** When the editor last asked for something, or anything was relayed to it:
|
|
1451
|
+
* a newer build replaces this bridge only once this is old (bridge-retire.ts). */
|
|
1452
|
+
lastActivityAt = Date.now();
|
|
1453
|
+
stopDownloadFeed;
|
|
1454
|
+
start() {
|
|
1455
|
+
const usage = setInterval(() => {
|
|
1456
|
+
if (this.shown) void this.refreshUsage(true).catch(quiet("ide/bridge"));
|
|
1457
|
+
}, USAGE_REFRESH_MS);
|
|
1458
|
+
usage.unref();
|
|
1459
|
+
this.timers.push(usage);
|
|
1460
|
+
const build = currentWorkerBuild();
|
|
1461
|
+
this.channel.send({ type: "ready", version: CLIKCODE_VERSION, protocol: IDE_PROTOCOL.version, revision: IDE_PROTOCOL.revision, ...build ? { build } : {}, pid: process.pid });
|
|
1462
|
+
}
|
|
1463
|
+
/** What keeps a newer build from replacing this bridge now (bridge-retire.ts):
|
|
1464
|
+
* anything it is doing for the editor. Undefined when nothing does. */
|
|
1465
|
+
retireBlocker() {
|
|
1466
|
+
if (this.inFlight > 0) return "a request is being answered";
|
|
1467
|
+
if (this.link.running) return "a turn is running";
|
|
1468
|
+
if (this.prompter.openCount > 0 || this.signIns.size > 0) return "a picker or sign-in is open";
|
|
1469
|
+
if (this.searchKey) return "/search is open";
|
|
1470
|
+
return void 0;
|
|
1471
|
+
}
|
|
1472
|
+
/** A request answered later: counted in flight until it settles. */
|
|
1473
|
+
track(work, activity = true) {
|
|
1474
|
+
this.inFlight += 1;
|
|
1475
|
+
void work.finally(() => {
|
|
1476
|
+
this.inFlight -= 1;
|
|
1477
|
+
if (activity) this.lastActivityAt = Date.now();
|
|
1478
|
+
}).catch(quiet("ide/bridge"));
|
|
1479
|
+
}
|
|
1480
|
+
handle(request) {
|
|
1481
|
+
if (request.type !== "query") lifecycle("bridge.request", { type: request.type, ...request.type === "choose" ? { kind: request.choice.kind } : {} });
|
|
1482
|
+
if (!READ_ONLY_REQUESTS.has(request.type)) this.lastActivityAt = Date.now();
|
|
1483
|
+
switch (request.type) {
|
|
1484
|
+
case "upload-start":
|
|
1485
|
+
this.answerUpload(request.requestId, request.uploadId, async () => {
|
|
1486
|
+
await this.uploads.start(request.uploadId, request.name, request.size);
|
|
1487
|
+
return { maxChunkBytes: ideUploadLimits.maxChunkBytes };
|
|
1488
|
+
});
|
|
1489
|
+
return;
|
|
1490
|
+
case "upload-chunk":
|
|
1491
|
+
this.answerUpload(request.requestId, request.uploadId, async () => {
|
|
1492
|
+
await this.uploads.append(request.uploadId, request.offset, request.data);
|
|
1493
|
+
return {};
|
|
1494
|
+
});
|
|
1495
|
+
return;
|
|
1496
|
+
case "upload-finish":
|
|
1497
|
+
this.answerUpload(request.requestId, request.uploadId, async () => ({ path: await this.uploads.finish(request.uploadId) }));
|
|
1498
|
+
return;
|
|
1499
|
+
case "upload-abort":
|
|
1500
|
+
this.answerUpload(request.requestId, request.uploadId, async () => {
|
|
1501
|
+
await this.uploads.abort(request.uploadId);
|
|
1502
|
+
return {};
|
|
1503
|
+
});
|
|
1504
|
+
return;
|
|
1505
|
+
case "activity-details":
|
|
1506
|
+
this.track((async () => {
|
|
1507
|
+
try {
|
|
1508
|
+
const { session } = await this.current(this.requireSession());
|
|
1509
|
+
const data = activityDetails(session, request.ids, request);
|
|
1510
|
+
this.channel.send({ type: "result", requestId: request.requestId, ok: true, data });
|
|
1511
|
+
} catch (error) {
|
|
1512
|
+
this.channel.send({ type: "result", requestId: request.requestId, ok: false, error: messageOf(error) });
|
|
1513
|
+
}
|
|
1514
|
+
})(), false);
|
|
1515
|
+
return;
|
|
1516
|
+
case "subagent":
|
|
1517
|
+
this.track((async () => {
|
|
1518
|
+
try {
|
|
1519
|
+
if (!this.sessionId) throw new Error("No conversation is open.");
|
|
1520
|
+
const client = await this.link.workerFor(this.sessionId);
|
|
1521
|
+
const id = randomUUID2();
|
|
1522
|
+
const data = await new Promise((resolve, reject) => {
|
|
1523
|
+
const cleanup = () => {
|
|
1524
|
+
clearTimeout(timer);
|
|
1525
|
+
client.off("event", onEvent);
|
|
1526
|
+
client.off("close", onClose);
|
|
1527
|
+
};
|
|
1528
|
+
const onClose = () => {
|
|
1529
|
+
cleanup();
|
|
1530
|
+
reject(new Error("The conversation worker disconnected."));
|
|
1531
|
+
};
|
|
1532
|
+
const onEvent = (event) => {
|
|
1533
|
+
if (request.action === "read" && event.type === "subagent" && event.id === id) {
|
|
1534
|
+
cleanup();
|
|
1535
|
+
resolve({ rows: event.rows, steer: event.steer });
|
|
1536
|
+
}
|
|
1537
|
+
if (request.action === "steer" && event.type === "submission" && event.id === id) {
|
|
1538
|
+
cleanup();
|
|
1539
|
+
if (event.disposition === "error") reject(new Error(event.message ?? "Not sent."));
|
|
1540
|
+
else resolve(event.message);
|
|
1541
|
+
}
|
|
1542
|
+
};
|
|
1543
|
+
const timer = setTimeout(() => {
|
|
1544
|
+
cleanup();
|
|
1545
|
+
reject(new Error("The sub-agent did not answer."));
|
|
1546
|
+
}, 1e4);
|
|
1547
|
+
client.on("event", onEvent);
|
|
1548
|
+
client.once("close", onClose);
|
|
1549
|
+
try {
|
|
1550
|
+
client.send(request.action === "read" ? { type: "read-subagent", id, parentId: request.parentId } : { type: "steer-subagent", id, parentId: request.parentId, text: request.text ?? "", ...request.agentId ? { agentId: request.agentId } : {} });
|
|
1551
|
+
} catch (error) {
|
|
1552
|
+
cleanup();
|
|
1553
|
+
reject(error);
|
|
1554
|
+
}
|
|
1555
|
+
});
|
|
1556
|
+
this.channel.send({ type: "result", requestId: request.requestId, ok: true, data });
|
|
1557
|
+
} catch (error) {
|
|
1558
|
+
this.channel.send({ type: "result", requestId: request.requestId, ok: false, error: messageOf(error) });
|
|
1559
|
+
}
|
|
1560
|
+
})(), false);
|
|
1561
|
+
return;
|
|
1562
|
+
case "open":
|
|
1563
|
+
this.features = new Set(request.features ?? []);
|
|
1564
|
+
this.delta.reset();
|
|
1565
|
+
this.enqueue(async () => {
|
|
1566
|
+
try {
|
|
1567
|
+
if (request.held && request.sessionId && request.held.sessionId === request.sessionId && this.features.has("session-delta") && request.held.gen && (await loadChatLog(request.sessionId).catch(quiet("ide/bridge")))?.gen === request.held.gen) this.delta.adopt(request.held);
|
|
1568
|
+
await this.open(request.workspace ?? "", request.mode, request.sessionId);
|
|
1569
|
+
const gen = this.sessionId ? (await loadChatLog(this.sessionId).catch(quiet("ide/bridge")))?.gen : void 0;
|
|
1570
|
+
this.channel.send({ type: "result", requestId: request.requestId, ok: true, data: { sessionId: this.sessionId, ...gen ? { gen } : {} } });
|
|
1571
|
+
} catch (error) {
|
|
1572
|
+
this.channel.send({ type: "result", requestId: request.requestId, ok: false, error: messageOf(error) });
|
|
1573
|
+
return;
|
|
1574
|
+
}
|
|
1575
|
+
await this.drainQueue();
|
|
1576
|
+
});
|
|
1577
|
+
return;
|
|
1578
|
+
case "send":
|
|
1579
|
+
this.track(this.turns.send(request.text, request.id, request.mode, request.attachments));
|
|
1580
|
+
return;
|
|
1581
|
+
case "cancel":
|
|
1582
|
+
this.turns.noteCancel();
|
|
1583
|
+
this.track(this.link.cancelTurn(request.restoreDraft, request.trigger));
|
|
1584
|
+
return;
|
|
1585
|
+
case "stop-agents":
|
|
1586
|
+
if (this.sessionId) this.track(this.link.workerFor(this.sessionId).then((client) => client.send({ type: "agents", action: "stop", ...request.ids ? { ids: request.ids } : {}, ...request.all ? { all: true } : {}, ...request.confirm ? { confirm: true } : {} }), (error) => this.report(error)));
|
|
1587
|
+
return;
|
|
1588
|
+
case "send-queued":
|
|
1589
|
+
this.link.worker?.client.send({ type: "send-queued" });
|
|
1590
|
+
return;
|
|
1591
|
+
case "unqueue":
|
|
1592
|
+
if (this.sessionId) this.track(this.link.workerFor(this.sessionId).then((client) => client.send({ type: "unqueue", id: request.id }), (error) => this.report(error)));
|
|
1593
|
+
return;
|
|
1594
|
+
case "approval-response":
|
|
1595
|
+
this.link.worker?.client.send({ type: "approval-response", id: request.id, approved: request.approved });
|
|
1596
|
+
return;
|
|
1597
|
+
case "question-response":
|
|
1598
|
+
this.link.worker?.client.send({ type: "question-response", id: request.id, result: request.result });
|
|
1599
|
+
return;
|
|
1600
|
+
case "ui-response":
|
|
1601
|
+
this.prompter.answer(request.id, request.result);
|
|
1602
|
+
return;
|
|
1603
|
+
case "ui-search":
|
|
1604
|
+
this.prompter.search(request.id, request.query);
|
|
1605
|
+
return;
|
|
1606
|
+
case "sign-in-cancel":
|
|
1607
|
+
this.prompter.cancelSignIn(request.id);
|
|
1608
|
+
return;
|
|
1609
|
+
case "sign-in-answer":
|
|
1610
|
+
this.prompter.answerSignIn(request.id, request.text);
|
|
1611
|
+
return;
|
|
1612
|
+
case "sign-in-result": {
|
|
1613
|
+
const pending = this.signIns.get(request.id);
|
|
1614
|
+
if (!pending) return;
|
|
1615
|
+
this.signIns.delete(request.id);
|
|
1616
|
+
if (request.error) pending.reject(new Error(request.error));
|
|
1617
|
+
else pending.resolve();
|
|
1618
|
+
return;
|
|
1619
|
+
}
|
|
1620
|
+
case "query":
|
|
1621
|
+
this.track(answerQuery(this.host, request.requestId, request.query ?? "slash-commands", request), false);
|
|
1622
|
+
return;
|
|
1623
|
+
case "choose":
|
|
1624
|
+
this.track(choose(this.host, request.requestId, request.choice));
|
|
1625
|
+
return;
|
|
1626
|
+
case "watch-conversations":
|
|
1627
|
+
this.watchConversations(request.on);
|
|
1628
|
+
return;
|
|
1629
|
+
case "export-chat":
|
|
1630
|
+
case "chat-have":
|
|
1631
|
+
case "import-chat":
|
|
1632
|
+
case "mark-moved":
|
|
1633
|
+
case "reclaim-moved":
|
|
1634
|
+
this.track(this.answerMove(request));
|
|
1635
|
+
return;
|
|
1636
|
+
case "search-key": {
|
|
1637
|
+
const answer = this.searchKey;
|
|
1638
|
+
this.searchKey = void 0;
|
|
1639
|
+
answer?.(request.key);
|
|
1640
|
+
return;
|
|
1641
|
+
}
|
|
1642
|
+
case "visible": {
|
|
1643
|
+
const appeared = request.visible && !this.shown;
|
|
1644
|
+
this.shown = request.visible;
|
|
1645
|
+
if (appeared) void this.refreshUsage().catch(quiet("ide/bridge"));
|
|
1646
|
+
return;
|
|
1647
|
+
}
|
|
1648
|
+
case "close":
|
|
1649
|
+
void this.shutdown();
|
|
1650
|
+
return;
|
|
1651
|
+
default:
|
|
1652
|
+
return;
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
/** A move to or from this machine (session/move.ts): the chat this bridge
|
|
1656
|
+
* shows is exported when none is named, and shown again once marked moved. */
|
|
1657
|
+
async answerMove(request) {
|
|
1658
|
+
const { requestId, ...move } = request;
|
|
1659
|
+
try {
|
|
1660
|
+
const { answerMoveRequest } = await import("./chunk-NR4FMC4K.js");
|
|
1661
|
+
const followed = this.link.worker?.sessionId;
|
|
1662
|
+
const following = Boolean(followed) && move.type === "export-chat" && (move.sessionId ?? this.sessionId) === followed;
|
|
1663
|
+
if (move.type === "mark-moved" && move.sessionId === this.link.worker?.sessionId) this.link.detach();
|
|
1664
|
+
const data = await answerMoveRequest(this.config, move, this.sessionId, following ? { turnRunning: async () => this.link.running } : {});
|
|
1665
|
+
this.channel.send({ type: "result", requestId, ok: true, ...data === void 0 ? {} : { data } });
|
|
1666
|
+
if ((move.type === "mark-moved" || move.type === "reclaim-moved") && move.sessionId === this.sessionId) await this.emitSession().catch(quiet("ide/bridge"));
|
|
1667
|
+
} catch (error) {
|
|
1668
|
+
this.channel.send({ type: "result", requestId, ok: false, error: messageOf(error) });
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
/** While the editor shows a conversations list, tell it when the state or
|
|
1672
|
+
* worker directories change, so it re-queries then instead of on a timer. */
|
|
1673
|
+
watchConversations(on) {
|
|
1674
|
+
this.listWatchers = Math.max(0, this.listWatchers + (on ? 1 : -1));
|
|
1675
|
+
if (this.listWatchers && !this.listWatch && !this.closed) {
|
|
1676
|
+
this.listWatch = watchConversationList(() => this.channel.send({ type: "conversations-changed" }));
|
|
1677
|
+
} else if (!this.listWatchers && this.listWatch) {
|
|
1678
|
+
this.listWatch.stop();
|
|
1679
|
+
this.listWatch = void 0;
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
stopping;
|
|
1683
|
+
/** One shutdown, however many ask: the editor sends `close` and then
|
|
1684
|
+
* disconnects at once, and the disconnect's exit used to land while the
|
|
1685
|
+
* close was still writing the state -- a lock file left empty, which every
|
|
1686
|
+
* other ClikCode then waited 30 s to judge stale (an open stood that long). */
|
|
1687
|
+
shutdown() {
|
|
1688
|
+
this.stopping ??= this.stop();
|
|
1689
|
+
return this.stopping;
|
|
1690
|
+
}
|
|
1691
|
+
/** One upload step, answered by `result`. A step that fails ends the upload: its staged bytes are removed. */
|
|
1692
|
+
answerUpload(requestId, uploadId, step) {
|
|
1693
|
+
this.track((async () => {
|
|
1694
|
+
try {
|
|
1695
|
+
this.channel.send({ type: "result", requestId, ok: true, data: await step() });
|
|
1696
|
+
} catch (error) {
|
|
1697
|
+
await this.uploads.abort(uploadId);
|
|
1698
|
+
this.channel.send({ type: "result", requestId, ok: false, error: messageOf(error) });
|
|
1699
|
+
}
|
|
1700
|
+
})(), false);
|
|
1701
|
+
}
|
|
1702
|
+
async stop() {
|
|
1703
|
+
this.closed = true;
|
|
1704
|
+
await this.uploads.close();
|
|
1705
|
+
this.stopDownloadFeed();
|
|
1706
|
+
this.listWatch?.stop();
|
|
1707
|
+
this.listWatch = void 0;
|
|
1708
|
+
for (const timer of this.timers) clearInterval(timer);
|
|
1709
|
+
this.prompter.cancelAll();
|
|
1710
|
+
this.searchKey?.("done");
|
|
1711
|
+
for (const pending of this.signIns.values()) pending.reject(new Error("the editor closed"));
|
|
1712
|
+
this.signIns.clear();
|
|
1713
|
+
this.link.detach();
|
|
1714
|
+
await reconcileLocalModelLeases(void 0, this.elsewhere()).catch(quiet("ide/bridge"));
|
|
1715
|
+
if (this.sessionId) await this.leave(this.sessionId);
|
|
1716
|
+
}
|
|
1717
|
+
/** The conversation this chat shows, if any. */
|
|
1718
|
+
get conversation() {
|
|
1719
|
+
return this.sessionId;
|
|
1720
|
+
}
|
|
1721
|
+
elsewhere() {
|
|
1722
|
+
return this.siblings?.showingElsewhere(this) ?? /* @__PURE__ */ new Set();
|
|
1723
|
+
}
|
|
1724
|
+
/** Leaves `id` unless another chat of this process still shows it. */
|
|
1725
|
+
async leave(id) {
|
|
1726
|
+
if (this.elsewhere().has(id)) return;
|
|
1727
|
+
unpinDraft(id);
|
|
1728
|
+
await leaveConversation(id);
|
|
1729
|
+
}
|
|
1730
|
+
/** One job at a time, in order -- until a job opens a vendor sign-in. That
|
|
1731
|
+
* waits on a browser for as long as the user likes, and every open, send
|
|
1732
|
+
* and choice behind it waited too; the job carries on by itself from there,
|
|
1733
|
+
* and the queue moves on. */
|
|
1734
|
+
enqueue(job) {
|
|
1735
|
+
let ended;
|
|
1736
|
+
this.track(new Promise((resolve) => {
|
|
1737
|
+
ended = resolve;
|
|
1738
|
+
}));
|
|
1739
|
+
this.work = this.work.then(() => new Promise((release) => {
|
|
1740
|
+
void this.prompter.holding(release, job).catch((error) => this.report(error)).finally(() => {
|
|
1741
|
+
release();
|
|
1742
|
+
ended();
|
|
1743
|
+
});
|
|
1744
|
+
}));
|
|
1745
|
+
}
|
|
1746
|
+
report(error) {
|
|
1747
|
+
if (error instanceof TurnFailed) return;
|
|
1748
|
+
if (signInCancelledLine(error)) return;
|
|
1749
|
+
this.channel.send({ type: "notice", message: messageOf(error), level: "error" });
|
|
1750
|
+
}
|
|
1751
|
+
requireSession() {
|
|
1752
|
+
if (!this.sessionId) throw new Error("No conversation is open.");
|
|
1753
|
+
return this.sessionId;
|
|
1754
|
+
}
|
|
1755
|
+
async current(id = this.requireSession()) {
|
|
1756
|
+
const state = await readState({ transcripts: [id] });
|
|
1757
|
+
const session = state.sessions.find((item) => item.id === id);
|
|
1758
|
+
if (!session) throw new Error(`AI session "${id}" was not found`);
|
|
1759
|
+
const account = session.accountId ? state.accounts.find((item) => item.id === session.accountId)?.label : void 0;
|
|
1760
|
+
return { session, ...account ? { account } : {} };
|
|
1761
|
+
}
|
|
1762
|
+
async emitSession() {
|
|
1763
|
+
if (!this.sessionId) return;
|
|
1764
|
+
const { session, account } = await this.current();
|
|
1765
|
+
this.channel.send(sessionEvent(session, account));
|
|
1766
|
+
const key = shownSettingsKey(session);
|
|
1767
|
+
if (this.shownSettings?.startsWith(`${session.id}|`) && this.shownSettings !== key && this.link.worker?.sessionId === session.id) this.link.worker.client.send({ type: "refresh" });
|
|
1768
|
+
this.shownSettings = key;
|
|
1769
|
+
const liveKey = `${session.id}|${JSON.stringify(liveSettingsOf(session))}`;
|
|
1770
|
+
if (this.shownLiveSettings?.startsWith(`${session.id}|`) && this.shownLiveSettings !== liveKey && this.link.worker?.sessionId === session.id) {
|
|
1771
|
+
this.link.worker.client.send({ type: "settings-changed", settings: liveSettingsOf(session) });
|
|
1772
|
+
}
|
|
1773
|
+
this.shownLiveSettings = liveKey;
|
|
1774
|
+
}
|
|
1775
|
+
// ---- conversations -------------------------------------------------------
|
|
1776
|
+
async open(workspace, mode, ref) {
|
|
1777
|
+
const notices = [];
|
|
1778
|
+
const began = Date.now();
|
|
1779
|
+
const steps = {};
|
|
1780
|
+
const timed = async (name, work) => {
|
|
1781
|
+
const at = Date.now();
|
|
1782
|
+
try {
|
|
1783
|
+
return await work();
|
|
1784
|
+
} finally {
|
|
1785
|
+
steps[name] = Date.now() - at;
|
|
1786
|
+
}
|
|
1787
|
+
};
|
|
1788
|
+
const id = await timed("openMs", () => openConversation(workspace, mode, ref, { sameWorkspace: true, pin: true, notice: (message) => notices.push(message) }));
|
|
1789
|
+
const { session } = await timed("currentMs", () => this.current(id));
|
|
1790
|
+
if (!session.nativeHarness && !isClikCodeAgent(session)) await autoSelectSessionHarness(id).catch(() => false);
|
|
1791
|
+
await timed("modelMs", () => resolveSessionModel(id));
|
|
1792
|
+
await timed("switchMs", () => this.switchTo(id, steps));
|
|
1793
|
+
lifecycle("bridge.open", { ms: Date.now() - began, ...steps, messages: session.messages?.length ?? 0, running: this.link.worker !== void 0 });
|
|
1794
|
+
for (const message of notices) this.channel.send({ type: "notice", message, level: "warning" });
|
|
1795
|
+
void this.synchronizeOpened(id);
|
|
1796
|
+
}
|
|
1797
|
+
/** Vendor transcripts are folded in after the editor is already showing the
|
|
1798
|
+
* chat. The open itself only reads that one conversation. */
|
|
1799
|
+
async synchronizeOpened(id) {
|
|
1800
|
+
const synced = await readState({ transcripts: [id] });
|
|
1801
|
+
const syncing = synced.sessions.find((item) => item.id === id);
|
|
1802
|
+
if (!syncing || !await synchronizeNativeTranscript(synced, syncing)) return;
|
|
1803
|
+
await writeState(synced);
|
|
1804
|
+
if (this.sessionId === id) await this.emitSession();
|
|
1805
|
+
}
|
|
1806
|
+
async switchTo(id, steps = {}) {
|
|
1807
|
+
const timed = async (name, work) => {
|
|
1808
|
+
const at = Date.now();
|
|
1809
|
+
try {
|
|
1810
|
+
return await work();
|
|
1811
|
+
} finally {
|
|
1812
|
+
steps[name] = Date.now() - at;
|
|
1813
|
+
}
|
|
1814
|
+
};
|
|
1815
|
+
const previous = this.sessionId;
|
|
1816
|
+
if (previous && previous !== id) {
|
|
1817
|
+
if (this.link.worker?.sessionId === previous) this.link.worker.client.send({ type: "release" });
|
|
1818
|
+
this.link.detach();
|
|
1819
|
+
await this.leave(previous);
|
|
1820
|
+
}
|
|
1821
|
+
this.sessionId = id;
|
|
1822
|
+
pinDraft(id);
|
|
1823
|
+
setLifecycleSession(id);
|
|
1824
|
+
lifecycle("bridge.conversation");
|
|
1825
|
+
this.preparedRoute = void 0;
|
|
1826
|
+
await timed("claimMs", () => claimConversation(id));
|
|
1827
|
+
await timed("emitMs", () => this.emitSession());
|
|
1828
|
+
await timed("workerMs", async () => {
|
|
1829
|
+
const record = await readWorkerRecord(id).catch(quiet("ide/bridge"));
|
|
1830
|
+
if (record && await workerIsReachable(record.socketPath)) await this.link.workerFor(id).catch(quiet("ide/bridge"));
|
|
1831
|
+
});
|
|
1832
|
+
await timed("routeMs", () => this.prepareRoute());
|
|
1833
|
+
void this.refreshUsage().catch(quiet("ide/bridge"));
|
|
1834
|
+
}
|
|
1835
|
+
/** `poll`: the periodic redraw (a vendor's reset countdown moves with time). Anything else is an
|
|
1836
|
+
* event that can change the Gateway's credit -- a turn ended, the account or conversation
|
|
1837
|
+
* changed, the window appeared -- and reads it fresh; a poll shows the last reading. */
|
|
1838
|
+
async refreshUsage(poll = false) {
|
|
1839
|
+
if (!this.sessionId) return;
|
|
1840
|
+
const state = await readState({ transcripts: [] });
|
|
1841
|
+
const session = state.sessions.find((item) => item.id === this.sessionId);
|
|
1842
|
+
if (!session) return;
|
|
1843
|
+
void recheckRecoveredAccounts(state).catch(quiet("ide/bridge"));
|
|
1844
|
+
const reading = isGatewayService(session) ? await gatewayCreditLabel(this.config, poll ? { cachedOnly: true } : { fresh: true }).then((label) => label ? { label, windows: void 0 } : void 0).catch(quiet("ide/bridge")) : await nativeUsageReading(session, state);
|
|
1845
|
+
const reset = session.resumeAt ? resumeWaitLabel(session.resumeAt) : usageResetLabel(reading?.windows);
|
|
1846
|
+
const chatCost = conversationCost(state, session.id);
|
|
1847
|
+
const next = usageNextReset(reading?.windows);
|
|
1848
|
+
const detail = usageWindowsDetail(reading?.windows);
|
|
1849
|
+
this.channel.send({
|
|
1850
|
+
type: "usage",
|
|
1851
|
+
...reading?.label ? { label: reading.label } : {},
|
|
1852
|
+
...reset ? { reset } : {},
|
|
1853
|
+
...next ? { next } : {},
|
|
1854
|
+
...detail ? { detail } : {},
|
|
1855
|
+
...chatCost !== void 0 ? { chatCost } : {}
|
|
1856
|
+
});
|
|
1857
|
+
}
|
|
1858
|
+
/** The conversation's route is ready before the first message: MCP servers
|
|
1859
|
+
* and the Gateway connection for an agent route, and nothing left running
|
|
1860
|
+
* for one that moved off it. Mirrors the interactive loop's preparedRoute. */
|
|
1861
|
+
async prepareRoute() {
|
|
1862
|
+
const { session } = await this.current();
|
|
1863
|
+
await reconcileLocalModelLeases(session, this.elsewhere()).catch(quiet("ide/bridge"));
|
|
1864
|
+
const key = `${session.id} ${session.route} ${session.nativeHarness ?? ""} ${session.accountId ?? ""}`;
|
|
1865
|
+
if (key === this.preparedRoute) return;
|
|
1866
|
+
this.preparedRoute = key;
|
|
1867
|
+
if (shouldWarmVendorChat(session)) {
|
|
1868
|
+
void warmSessionWorker(session.id).catch(quiet("ide/bridge"));
|
|
1869
|
+
}
|
|
1870
|
+
if (!isClikCodeAgent(session) && this.link.worker?.sessionId !== session.id) return;
|
|
1871
|
+
const client = await this.link.workerFor(session.id).catch(quiet("ide/bridge"));
|
|
1872
|
+
client?.send({ type: "prepare" });
|
|
1873
|
+
}
|
|
1874
|
+
/** Send the queue's head once no turn runs. Coalesced: however many
|
|
1875
|
+
* queue-changed arrive, one drain is pending at a time, and none while a
|
|
1876
|
+
* turn runs or this client is sending one (its caller drains after). */
|
|
1877
|
+
scheduleDrain() {
|
|
1878
|
+
if (this.drainScheduled || this.closed || !this.sessionId) return;
|
|
1879
|
+
if (this.link.running) return;
|
|
1880
|
+
this.drainScheduled = true;
|
|
1881
|
+
this.enqueue(async () => {
|
|
1882
|
+
this.drainScheduled = false;
|
|
1883
|
+
if (this.link.running) return;
|
|
1884
|
+
await this.drainQueue();
|
|
1885
|
+
});
|
|
1886
|
+
}
|
|
1887
|
+
runInTerminal(spec, request) {
|
|
1888
|
+
if (this.closed) return Promise.reject(new Error("the editor closed"));
|
|
1889
|
+
const id = randomUUID2();
|
|
1890
|
+
return new Promise((resolve, reject) => {
|
|
1891
|
+
this.signIns.set(id, { resolve, reject });
|
|
1892
|
+
this.channel.send({ type: "sign-in", id, name: request.name, spec: encodeTerminalSpec(spec), environment: { ...request.environment } });
|
|
1893
|
+
});
|
|
1894
|
+
}
|
|
1895
|
+
// The turn and worker steps live in bridge-turns.ts and bridge-worker.ts; these
|
|
1896
|
+
// are the seams the parts call through (and the ones a test replaces).
|
|
1897
|
+
get worker() {
|
|
1898
|
+
return this.link.worker;
|
|
1899
|
+
}
|
|
1900
|
+
set worker(value) {
|
|
1901
|
+
this.link.worker = value;
|
|
1902
|
+
}
|
|
1903
|
+
get workerTurnRunning() {
|
|
1904
|
+
return this.link.workerTurnRunning;
|
|
1905
|
+
}
|
|
1906
|
+
set workerTurnRunning(value) {
|
|
1907
|
+
this.link.workerTurnRunning = value;
|
|
1908
|
+
}
|
|
1909
|
+
get turnWaiter() {
|
|
1910
|
+
return this.link.turnWaiter;
|
|
1911
|
+
}
|
|
1912
|
+
set turnWaiter(value) {
|
|
1913
|
+
this.link.turnWaiter = value;
|
|
1914
|
+
}
|
|
1915
|
+
onWorkerEvent(sessionId, client, event) {
|
|
1916
|
+
this.link.onWorkerEvent(sessionId, client, event);
|
|
1917
|
+
}
|
|
1918
|
+
drainQueue() {
|
|
1919
|
+
return this.turns.drainQueue();
|
|
1920
|
+
}
|
|
1921
|
+
execute(line, options) {
|
|
1922
|
+
return this.turns.execute(line, options);
|
|
1923
|
+
}
|
|
1924
|
+
runTurn(targetId, prompt, turn) {
|
|
1925
|
+
return this.turns.runTurn(targetId, prompt, turn);
|
|
1926
|
+
}
|
|
1927
|
+
/** /search's screen in the editor (bridge-slash-host.ts). */
|
|
1928
|
+
searchScreen() {
|
|
1929
|
+
return searchScreen(this.host);
|
|
1930
|
+
}
|
|
1931
|
+
dispatch(line, fromQueuedCommand) {
|
|
1932
|
+
return this.turns.dispatch(line, fromQueuedCommand);
|
|
1933
|
+
}
|
|
1934
|
+
};
|
|
1935
|
+
function captureStdout(channel, stream = process.stdout, log = (line) => process.stderr.write(`${line}
|
|
1936
|
+
`)) {
|
|
1937
|
+
let buffer = "";
|
|
1938
|
+
stream.write = ((chunk, encoding, callback) => {
|
|
1939
|
+
buffer += typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8");
|
|
1940
|
+
for (let newline = buffer.indexOf("\n"); newline >= 0; newline = buffer.indexOf("\n")) {
|
|
1941
|
+
const line = buffer.slice(0, newline);
|
|
1942
|
+
buffer = buffer.slice(newline + 1);
|
|
1943
|
+
let payload;
|
|
1944
|
+
try {
|
|
1945
|
+
payload = JSON.parse(line);
|
|
1946
|
+
} catch {
|
|
1947
|
+
payload = void 0;
|
|
1948
|
+
}
|
|
1949
|
+
if (payload && typeof payload === "object" && !Array.isArray(payload)) {
|
|
1950
|
+
const record = payload;
|
|
1951
|
+
const text = renderPanelText(record);
|
|
1952
|
+
channel.send({ type: "output", payload: record, ...text === void 0 ? {} : { formatted: panelParts(stripVTControlCharacters(text)) } });
|
|
1953
|
+
} else if (line.trim()) log(line);
|
|
1954
|
+
}
|
|
1955
|
+
const done = typeof encoding === "function" ? encoding : callback;
|
|
1956
|
+
done?.();
|
|
1957
|
+
return true;
|
|
1958
|
+
});
|
|
1959
|
+
}
|
|
1960
|
+
function ideInstallReporter(channel) {
|
|
1961
|
+
return {
|
|
1962
|
+
start: (label) => channel.send({ type: "busy", label }),
|
|
1963
|
+
done: () => channel.send({ type: "busy" }),
|
|
1964
|
+
// The error itself reaches the editor as the failed request's notice.
|
|
1965
|
+
failed: () => channel.send({ type: "busy" })
|
|
1966
|
+
};
|
|
1967
|
+
}
|
|
1968
|
+
async function runIdeBridge(config) {
|
|
1969
|
+
const send = process.send?.bind(process);
|
|
1970
|
+
if (!send) throw new Error("ide-bridge is started by an editor extension, over an IPC channel");
|
|
1971
|
+
process.env.CLIKCODE_OUTPUT_MODE = "json";
|
|
1972
|
+
const { runMultiplexedBridge } = await import("./chunk-3WMS7SEE.js");
|
|
1973
|
+
return runMultiplexedBridge(config, send);
|
|
1974
|
+
}
|
|
1975
|
+
|
|
1976
|
+
export {
|
|
1977
|
+
IdeBridge,
|
|
1978
|
+
captureStdout,
|
|
1979
|
+
ideInstallReporter,
|
|
1980
|
+
runIdeBridge
|
|
1981
|
+
};
|