clikcode 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -14
- package/dist/chunk-23TDEBGZ.js +71 -0
- package/dist/chunk-25T3GVS7.js +425 -0
- package/dist/chunk-2BBELGHY.js +11 -0
- package/dist/chunk-2EOL5PZL.js +208 -0
- package/dist/chunk-2GAB36IE.js +26 -0
- package/dist/chunk-2OLS7V66.js +2440 -0
- package/dist/chunk-2QFO2URB.js +179 -0
- package/dist/chunk-2QWPQRSU.js +254 -0
- package/dist/chunk-2YPAPAR3.js +184 -0
- package/dist/chunk-2ZAG5372.js +33 -0
- package/dist/chunk-32IKAIZC.js +12507 -0
- package/dist/chunk-34AZEGYW.js +95 -0
- package/dist/chunk-34JQYQCA.js +175 -0
- package/dist/chunk-34ZISPAO.js +67 -0
- package/dist/chunk-3AAAARE6.js +46 -0
- package/dist/chunk-3AJ6Q3OY.js +510 -0
- package/dist/chunk-3B2CHX7M.js +884 -0
- package/dist/chunk-3BUFORRX.js +59 -0
- package/dist/chunk-3QLHYYFK.js +30 -0
- package/dist/chunk-3RXBMYKZ.js +140 -0
- package/dist/chunk-3TFNIJWS.js +52 -0
- package/dist/chunk-3W3IPDFP.js +119 -0
- package/dist/chunk-3WMS7SEE.js +417 -0
- package/dist/chunk-435ZNSZ3.js +23 -0
- package/dist/chunk-4AQ5NINV.js +39 -0
- package/dist/chunk-4GVEJ5FK.js +168 -0
- package/dist/chunk-4GXAO3UY.js +262 -0
- package/dist/chunk-4L2ZZM4Q.js +332 -0
- package/dist/chunk-4LPDG57B.js +17 -0
- package/dist/chunk-4NN3XQQT.js +223 -0
- package/dist/chunk-4QZEZME7.js +54 -0
- package/dist/chunk-4R6CSC3S.js +38 -0
- package/dist/chunk-4RHXTL3W.js +514 -0
- package/dist/chunk-4SJMPTVQ.js +18 -0
- package/dist/chunk-4VY7G6TX.js +114 -0
- package/dist/chunk-5642PBF7.js +124 -0
- package/dist/chunk-5B6TVO4A.js +33 -0
- package/dist/chunk-5BJLDUPL.js +62 -0
- package/dist/chunk-5HMFFJWU.js +19 -0
- package/dist/chunk-5IKLK33T.js +69 -0
- package/dist/chunk-5NQ5FFMX.js +44 -0
- package/dist/chunk-5QNNW5L6.js +176 -0
- package/dist/chunk-5SM5UAWN.js +239 -0
- package/dist/chunk-5WYJTA6O.js +74 -0
- package/dist/chunk-5ZSR2Y5T.js +227 -0
- package/dist/chunk-5ZWUM5GH.js +39 -0
- package/dist/chunk-64E7D4HY.js +364 -0
- package/dist/chunk-6CK466BC.js +99 -0
- package/dist/chunk-6ES45HHO.js +138 -0
- package/dist/chunk-6HYEZFGL.js +277 -0
- package/dist/chunk-6Y7HLXGW.js +29 -0
- package/dist/chunk-6YKK4FYR.js +258 -0
- package/dist/chunk-74WNMLMS.js +117 -0
- package/dist/chunk-7AULZ7OD.js +55 -0
- package/dist/chunk-7DOKGSUN.js +101 -0
- package/dist/chunk-7IH5LTIZ.js +195 -0
- package/dist/chunk-7ISTS5NS.js +21 -0
- package/dist/chunk-7NMUTGOW.js +527 -0
- package/dist/chunk-7PNHUZEL.js +153 -0
- package/dist/chunk-7TSQLONI.js +88 -0
- package/dist/chunk-AE7TOLD5.js +30 -0
- package/dist/chunk-AEMHSXKA.js +130 -0
- package/dist/chunk-AKRYTS2D.js +211 -0
- package/dist/chunk-AMNSE36L.js +59 -0
- package/dist/chunk-AZVD74ZV.js +23 -0
- package/dist/chunk-B35DVOTK.js +1981 -0
- package/dist/chunk-B4HNJRAH.js +626 -0
- package/dist/chunk-B5WYPPHS.js +13 -0
- package/dist/chunk-BBOVDXQM.js +59 -0
- package/dist/chunk-BD3ECZLK.js +62 -0
- package/dist/chunk-BDGSOT74.js +4578 -0
- package/dist/chunk-BF5VEOPK.js +31 -0
- package/dist/chunk-BFFRW4XH.js +47 -0
- package/dist/chunk-BFPC6PEW.js +208 -0
- package/dist/chunk-BGEMY2JJ.js +376 -0
- package/dist/chunk-BISGNHKD.js +35 -0
- package/dist/chunk-BMRAEBRY.js +21 -0
- package/dist/chunk-BNTXAZXW.js +127 -0
- package/dist/chunk-BOQBXGSN.js +75 -0
- package/dist/chunk-BTJDSTQP.js +213 -0
- package/dist/chunk-BUOPJQP5.js +218 -0
- package/dist/chunk-BXFJS65Q.js +52 -0
- package/dist/chunk-BXPQFSX5.js +59 -0
- package/dist/chunk-C57LIWNY.js +1269 -0
- package/dist/chunk-C6YVCCWR.js +74 -0
- package/dist/chunk-CAADDF6M.js +167 -0
- package/dist/chunk-CBANJFBO.js +69 -0
- package/dist/chunk-CERF3RIB.js +597 -0
- package/dist/chunk-COAS5ETR.js +46 -0
- package/dist/chunk-CQ7J6UQ7.js +78 -0
- package/dist/chunk-CRUVYGO2.js +26 -0
- package/dist/chunk-CVFVFRGN.js +58 -0
- package/dist/chunk-D2UK66HM.js +37 -0
- package/dist/chunk-D2W7SA4R.js +18 -0
- package/dist/chunk-DA44ZENT.js +501 -0
- package/dist/chunk-DAJ76TOC.js +99 -0
- package/dist/chunk-DCZ6CIUM.js +147 -0
- package/dist/chunk-DF35KMXM.js +1314 -0
- package/dist/chunk-DGASQT26.js +151 -0
- package/dist/chunk-DJT57C5P.js +55 -0
- package/dist/chunk-DKDPZTD3.js +44 -0
- package/dist/chunk-DQYVQ2N7.js +77 -0
- package/dist/chunk-DRTP2RTY.js +266 -0
- package/dist/chunk-DW2BMUKY.js +61 -0
- package/dist/chunk-DW5T5ZVU.js +307 -0
- package/dist/chunk-DXKNDNFC.js +164 -0
- package/dist/chunk-DZEQ7UYR.js +291 -0
- package/dist/chunk-E4F4OUAC.js +463 -0
- package/dist/chunk-EE4B6A7W.js +69 -0
- package/dist/chunk-EISKIYWG.js +23 -0
- package/dist/chunk-EKAQK7UQ.js +235 -0
- package/dist/chunk-EOBTJV32.js +123 -0
- package/dist/chunk-ESF3DIZY.js +325 -0
- package/dist/chunk-EVOHOZ4U.js +45 -0
- package/dist/chunk-EXN4KHLB.js +110 -0
- package/dist/chunk-F252T6Y3.js +78 -0
- package/dist/chunk-F3DP4ZA2.js +40 -0
- package/dist/chunk-F6F47QAY.js +58 -0
- package/dist/chunk-FA3Y23ZW.js +57 -0
- package/dist/chunk-FBKXE4EJ.js +640 -0
- package/dist/chunk-FCGEB3H6.js +23 -0
- package/dist/chunk-FF7ZVYJF.js +3732 -0
- package/dist/chunk-FFGKN6L3.js +39 -0
- package/dist/chunk-FFGU4GCC.js +94 -0
- package/dist/chunk-FSFDAOVP.js +74 -0
- package/dist/chunk-FT5TX7OX.js +1573 -0
- package/dist/chunk-G3QP67Z7.js +232 -0
- package/dist/chunk-G5ORJKV2.js +179 -0
- package/dist/chunk-GFNC62PE.js +111 -0
- package/dist/chunk-GGK43Q3N.js +67 -0
- package/dist/chunk-GGYKY4GF.js +11537 -0
- package/dist/chunk-GGYNHGNJ.js +55 -0
- package/dist/chunk-GLY7RM3C.js +354 -0
- package/dist/chunk-GQBZU6EO.js +20 -0
- package/dist/chunk-GSXENUZL.js +9 -0
- package/dist/chunk-GTOAT5D3.js +40 -0
- package/dist/chunk-GWCMDPQU.js +1007 -0
- package/dist/chunk-GXYSMYHJ.js +152 -0
- package/dist/chunk-GYMAI5NY.js +14 -0
- package/dist/chunk-H2VZMKPE.js +30 -0
- package/dist/chunk-H4THUNBM.js +2091 -0
- package/dist/chunk-HGRVSNUZ.js +361 -0
- package/dist/chunk-HI4VY473.js +27 -0
- package/dist/chunk-HOJRSD3Q.js +447 -0
- package/dist/chunk-HRX25W35.js +82 -0
- package/dist/chunk-HSE4AQYV.js +55 -0
- package/dist/chunk-HU5SSUFX.js +383 -0
- package/dist/chunk-I3GDBJLH.js +196 -0
- package/dist/chunk-I75EDU75.js +684 -0
- package/dist/chunk-IBA7DMIO.js +20 -0
- package/dist/chunk-IC6N4NZA.js +231 -0
- package/dist/chunk-IF43HIGV.js +284 -0
- package/dist/chunk-IGZ6C2MC.js +439 -0
- package/dist/chunk-IMLTL2MY.js +192 -0
- package/dist/chunk-IMZL6SGR.js +33 -0
- package/dist/chunk-IS4USJPY.js +516 -0
- package/dist/chunk-ISFSPN2F.js +82 -0
- package/dist/chunk-IXE7GTFI.js +55 -0
- package/dist/chunk-IZ77QJQG.js +36 -0
- package/dist/chunk-J2PACWRQ.js +34 -0
- package/dist/chunk-J6EGFVQX.js +180 -0
- package/dist/chunk-JEKOD43D.js +22 -0
- package/dist/chunk-JGIWATSG.js +30 -0
- package/dist/chunk-JYBONKD4.js +43 -0
- package/dist/chunk-K2NLG2HK.js +454 -0
- package/dist/chunk-KCQ4TBLS.js +164 -0
- package/dist/chunk-KD5KIVMS.js +176 -0
- package/dist/chunk-KHW6TX6I.js +63 -0
- package/dist/chunk-KI5GZFCE.js +520 -0
- package/dist/chunk-KN34B7NO.js +105 -0
- package/dist/chunk-KYUHIFP3.js +136 -0
- package/dist/chunk-KZL5VS4B.js +300 -0
- package/dist/chunk-L3VW3QIH.js +48 -0
- package/dist/chunk-LA6MG4ET.js +2110 -0
- package/dist/chunk-LAVFOA3S.js +66 -0
- package/dist/chunk-LB4OA77N.js +13 -0
- package/dist/chunk-LBFRF2K4.js +196 -0
- package/dist/chunk-LM6EIA4B.js +93 -0
- package/dist/chunk-LPCNRGJ7.js +692 -0
- package/dist/chunk-LSLNL5T3.js +168 -0
- package/dist/chunk-LVRRWP4W.js +568 -0
- package/dist/chunk-LWCFBRHL.js +33 -0
- package/dist/chunk-LXFTMGZZ.js +166 -0
- package/dist/chunk-M33LVA4M.js +151 -0
- package/dist/chunk-M3FO5UMK.js +4944 -0
- package/dist/chunk-M5QNDBAY.js +66 -0
- package/dist/chunk-M6ND6KBE.js +1291 -0
- package/dist/chunk-M7H3WQTE.js +76 -0
- package/dist/chunk-MCBRVPA7.js +191 -0
- package/dist/chunk-MCSDWZET.js +91 -0
- package/dist/chunk-MDT5XDXL.js +289 -0
- package/dist/chunk-MJG3IQY4.js +91 -0
- package/dist/chunk-MOU3N2UL.js +44 -0
- package/dist/chunk-MP4KZOQC.js +3451 -0
- package/dist/chunk-MPAJ446F.js +66 -0
- package/dist/chunk-MVJZZ6AL.js +16 -0
- package/dist/chunk-MXS6S2PY.js +253 -0
- package/dist/chunk-N3SFDYM7.js +291 -0
- package/dist/chunk-NAOX3JUB.js +13 -0
- package/dist/chunk-NEKKIBCX.js +283 -0
- package/dist/chunk-NKDATMEM.js +133 -0
- package/dist/chunk-NR4FMC4K.js +395 -0
- package/dist/chunk-NSOHOJBR.js +221 -0
- package/dist/chunk-NTDB6QKF.js +29 -0
- package/dist/chunk-NWEYRBWK.js +25 -0
- package/dist/chunk-O2YSNYWD.js +23 -0
- package/dist/chunk-O3EW7LAY.js +54 -0
- package/dist/chunk-O7BNJIXU.js +366 -0
- package/dist/chunk-OARL2NXZ.js +116 -0
- package/dist/chunk-OHKZUEJW.js +351 -0
- package/dist/chunk-OKU45BXA.js +647 -0
- package/dist/chunk-OL4JBD3J.js +59 -0
- package/dist/chunk-OLUO5DDR.js +192 -0
- package/dist/chunk-OQ245JLA.js +196 -0
- package/dist/chunk-P72UZAQI.js +289 -0
- package/dist/chunk-PAL2ENB6.js +20 -0
- package/dist/chunk-PAXYQZH7.js +53 -0
- package/dist/chunk-PDPEM5VW.js +51 -0
- package/dist/chunk-PEWCDI2C.js +668 -0
- package/dist/chunk-PGZ54EDX.js +27 -0
- package/dist/chunk-PRWVLDZF.js +73 -0
- package/dist/chunk-PSQQ75VJ.js +52 -0
- package/dist/chunk-PUOVIFHW.js +118 -0
- package/dist/chunk-PWBF2X3V.js +107 -0
- package/dist/chunk-PWXII6HF.js +43 -0
- package/dist/chunk-Q35VLJRT.js +80 -0
- package/dist/chunk-QJP7EYGL.js +128 -0
- package/dist/chunk-QPQKX2MK.js +8836 -0
- package/dist/chunk-QQRLPY25.js +1053 -0
- package/dist/chunk-QUS4ER2W.js +407 -0
- package/dist/chunk-QYHI3YET.js +29 -0
- package/dist/chunk-QYRU2UQI.js +32 -0
- package/dist/chunk-R6XVVQGC.js +13 -0
- package/dist/chunk-R7QN6ONS.js +483 -0
- package/dist/chunk-RD23MPGC.js +221 -0
- package/dist/chunk-RDDWQBEM.js +185 -0
- package/dist/chunk-RDLLDYFO.js +104 -0
- package/dist/chunk-RE4TGORR.js +84 -0
- package/dist/chunk-RJLHVYQY.js +217 -0
- package/dist/chunk-RJLPTWHW.js +905 -0
- package/dist/chunk-RKUVLRZI.js +295 -0
- package/dist/chunk-ROGXPGYR.js +37 -0
- package/dist/chunk-RSZGEL5U.js +163 -0
- package/dist/chunk-RVUOIJXN.js +909 -0
- package/dist/chunk-RW7F4JRP.js +11 -0
- package/dist/chunk-S4UO3AO3.js +53 -0
- package/dist/chunk-S5JAAF6S.js +585 -0
- package/dist/chunk-SNU37TQI.js +56 -0
- package/dist/chunk-SQVUDO2O.js +31 -0
- package/dist/chunk-SYVHIYQT.js +66 -0
- package/dist/chunk-SZBQMTG2.js +85 -0
- package/dist/chunk-T5VCXA3J.js +25 -0
- package/dist/chunk-TK6NSP56.js +30 -0
- package/dist/chunk-TKWVMA6L.js +22 -0
- package/dist/chunk-TQDKJHWX.js +59 -0
- package/dist/chunk-TQDM7S5N.js +127 -0
- package/dist/chunk-TULAXS77.js +23 -0
- package/dist/chunk-TVT45XNH.js +4625 -0
- package/dist/chunk-TWCVV2JO.js +467 -0
- package/dist/chunk-U4DKAD6S.js +47 -0
- package/dist/chunk-UA5K2BTI.js +564 -0
- package/dist/chunk-UAMKCMOK.js +40 -0
- package/dist/chunk-UBMVADBF.js +51 -0
- package/dist/chunk-UFQ5A5PW.js +645 -0
- package/dist/chunk-UOD2SOLL.js +1301 -0
- package/dist/chunk-UTSB4LOW.js +156 -0
- package/dist/chunk-UVXNIUTN.js +412 -0
- package/dist/chunk-UXVPXYPE.js +90 -0
- package/dist/chunk-UYEEMIWR.js +374 -0
- package/dist/chunk-VBGM5ZBW.js +54 -0
- package/dist/chunk-VEWPCZPG.js +762 -0
- package/dist/chunk-VIRDLZ5E.js +108 -0
- package/dist/chunk-VMPO7WKN.js +52 -0
- package/dist/chunk-W2NVSDO5.js +5122 -0
- package/dist/chunk-W3YYPBEA.js +176 -0
- package/dist/chunk-W5AYOICN.js +280 -0
- package/dist/chunk-W5GZOIUF.js +27 -0
- package/dist/chunk-WHKNLZ3C.js +76 -0
- package/dist/chunk-WKBEPPQ5.js +1409 -0
- package/dist/chunk-WM3Z6QKQ.js +151 -0
- package/dist/chunk-WMI2TPMA.js +31 -0
- package/dist/chunk-WNX5VD7S.js +150 -0
- package/dist/chunk-WOVTYST3.js +60 -0
- package/dist/chunk-WPB5WEZJ.js +546 -0
- package/dist/chunk-WUO5EOAT.js +44 -0
- package/dist/chunk-WWLJMP6D.js +133 -0
- package/dist/chunk-WZMLH3XP.js +58 -0
- package/dist/chunk-WZYVLUVQ.js +79 -0
- package/dist/chunk-X2OCPVU5.js +135 -0
- package/dist/chunk-X3CL6DTR.js +95 -0
- package/dist/chunk-X6WF7JEV.js +354 -0
- package/dist/chunk-XAHGBPWT.js +44 -0
- package/dist/chunk-XCKQ5BM2.js +228 -0
- package/dist/chunk-XIBYREEY.js +106 -0
- package/dist/chunk-XKW5NDMR.js +378 -0
- package/dist/chunk-XRDALAO3.js +100 -0
- package/dist/chunk-XUP22EAS.js +41 -0
- package/dist/chunk-XWAC3MKW.js +243 -0
- package/dist/chunk-Y3R7JMXB.js +59 -0
- package/dist/chunk-Y54LTP4W.js +82 -0
- package/dist/chunk-Y7UECI4M.js +99 -0
- package/dist/chunk-YACGDFHC.js +47 -0
- package/dist/chunk-YHNIQPKY.js +71 -0
- package/dist/chunk-YMBR6HYP.js +111 -0
- package/dist/chunk-YMCH3L2S.js +26 -0
- package/dist/chunk-Z4ZU6T7V.js +99 -0
- package/dist/chunk-ZDPF67ZZ.js +173 -0
- package/dist/chunk-ZFC2Q67K.js +101 -0
- package/dist/chunk-ZGHNNSCT.js +114 -0
- package/dist/chunk-ZGX3ERAT.js +173 -0
- package/dist/chunk-ZI3YHEBY.js +37 -0
- package/dist/chunk-ZN7G6JLS.js +639 -0
- package/dist/chunk-ZNPFQMXT.js +47 -0
- package/dist/chunk-ZOU3LV4U.js +63 -0
- package/dist/chunk-ZT7B4H2V.js +117 -0
- package/dist/chunk-ZZCBDNZI.js +58 -0
- package/dist/cli.js +494 -112923
- package/dist/computer-tools.js +36642 -21259
- package/dist/harness-catalog.cjs +88 -43
- package/dist/index.js +1 -1
- package/dist/local-model-supervisor.cjs +555 -0
- package/package.json +3 -4
|
@@ -0,0 +1,2091 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
agentsReport,
|
|
5
|
+
conversationSubagentEvents,
|
|
6
|
+
readConversationSubagent
|
|
7
|
+
} from "./chunk-5642PBF7.js";
|
|
8
|
+
import {
|
|
9
|
+
computerInspect,
|
|
10
|
+
computerLogin,
|
|
11
|
+
computerTool
|
|
12
|
+
} from "./chunk-OKU45BXA.js";
|
|
13
|
+
import {
|
|
14
|
+
sendScriptedTurn
|
|
15
|
+
} from "./chunk-EKAQK7UQ.js";
|
|
16
|
+
import {
|
|
17
|
+
ConversationStore,
|
|
18
|
+
FileCheckpointStore,
|
|
19
|
+
SHELL_HEADLESS_TIMEOUT_MS,
|
|
20
|
+
fileTurnRow,
|
|
21
|
+
hasThreadToCompact,
|
|
22
|
+
isShellCommandLine,
|
|
23
|
+
oneLine,
|
|
24
|
+
presentTopics,
|
|
25
|
+
readAgentRecords,
|
|
26
|
+
readTurnChanges,
|
|
27
|
+
runShellCommand,
|
|
28
|
+
shellMessageContent,
|
|
29
|
+
turnChangesAgo,
|
|
30
|
+
turnChangesDiff,
|
|
31
|
+
turnChangesList,
|
|
32
|
+
turnsThatEdited,
|
|
33
|
+
withTurnChangesLock,
|
|
34
|
+
writeTurnChanges
|
|
35
|
+
} from "./chunk-32IKAIZC.js";
|
|
36
|
+
import {
|
|
37
|
+
cliThreadTransport,
|
|
38
|
+
turnEnvironment
|
|
39
|
+
} from "./chunk-M6ND6KBE.js";
|
|
40
|
+
import {
|
|
41
|
+
SELECTION_MODE,
|
|
42
|
+
putOnAgentRoute,
|
|
43
|
+
setSelectionMode
|
|
44
|
+
} from "./chunk-QPQKX2MK.js";
|
|
45
|
+
import {
|
|
46
|
+
exportTranscript
|
|
47
|
+
} from "./chunk-ZOU3LV4U.js";
|
|
48
|
+
import {
|
|
49
|
+
usageReport,
|
|
50
|
+
usageReportAll
|
|
51
|
+
} from "./chunk-LBFRF2K4.js";
|
|
52
|
+
import {
|
|
53
|
+
aiSessionClose,
|
|
54
|
+
aiSessionLeave,
|
|
55
|
+
applyClikCodeAgentSessionPolicy,
|
|
56
|
+
applyFreshLocalSessionPolicy,
|
|
57
|
+
applyGatewaySessionPolicy,
|
|
58
|
+
assertRealModel,
|
|
59
|
+
chooseGatewayModel,
|
|
60
|
+
moveToProvider,
|
|
61
|
+
newConversation
|
|
62
|
+
} from "./chunk-RJLPTWHW.js";
|
|
63
|
+
import {
|
|
64
|
+
customCommandPrompt,
|
|
65
|
+
customCommandsFor,
|
|
66
|
+
sessionHarness,
|
|
67
|
+
slashExtrasFor,
|
|
68
|
+
slashRouteContextFor
|
|
69
|
+
} from "./chunk-2EOL5PZL.js";
|
|
70
|
+
import {
|
|
71
|
+
aiHarnessSelect
|
|
72
|
+
} from "./chunk-MDT5XDXL.js";
|
|
73
|
+
import {
|
|
74
|
+
backgroundDownloadsAllowed,
|
|
75
|
+
localModelChosen,
|
|
76
|
+
releaseHeldLocalModel,
|
|
77
|
+
reportDownloadOutcome,
|
|
78
|
+
startModelDownload
|
|
79
|
+
} from "./chunk-UYEEMIWR.js";
|
|
80
|
+
import {
|
|
81
|
+
leavePersistentTransport
|
|
82
|
+
} from "./chunk-TVT45XNH.js";
|
|
83
|
+
import {
|
|
84
|
+
effortChoicesFor
|
|
85
|
+
} from "./chunk-DGASQT26.js";
|
|
86
|
+
import {
|
|
87
|
+
conversationTitle,
|
|
88
|
+
searchConversations
|
|
89
|
+
} from "./chunk-WNX5VD7S.js";
|
|
90
|
+
import {
|
|
91
|
+
searchResultsPayload
|
|
92
|
+
} from "./chunk-34AZEGYW.js";
|
|
93
|
+
import {
|
|
94
|
+
runsOn,
|
|
95
|
+
shortId
|
|
96
|
+
} from "./chunk-UTSB4LOW.js";
|
|
97
|
+
import {
|
|
98
|
+
accountView,
|
|
99
|
+
aiAccountLogin,
|
|
100
|
+
aiAccountLogout,
|
|
101
|
+
aiAccountRemove,
|
|
102
|
+
aiDoctor
|
|
103
|
+
} from "./chunk-LA6MG4ET.js";
|
|
104
|
+
import {
|
|
105
|
+
wakeOwnModel
|
|
106
|
+
} from "./chunk-X3CL6DTR.js";
|
|
107
|
+
import {
|
|
108
|
+
emitHarnessOutput,
|
|
109
|
+
parseSandboxMode,
|
|
110
|
+
renderSessionCard,
|
|
111
|
+
sandboxModeText,
|
|
112
|
+
sessionSandboxMode
|
|
113
|
+
} from "./chunk-4RHXTL3W.js";
|
|
114
|
+
import {
|
|
115
|
+
gatewayModelDetail,
|
|
116
|
+
gatewayModelForWord,
|
|
117
|
+
gatewayModelLabel,
|
|
118
|
+
gatewayModels,
|
|
119
|
+
gatewayUncensoredConsent,
|
|
120
|
+
isAutomaticModelWord
|
|
121
|
+
} from "./chunk-W5AYOICN.js";
|
|
122
|
+
import {
|
|
123
|
+
localModelChoices
|
|
124
|
+
} from "./chunk-2OLS7V66.js";
|
|
125
|
+
import {
|
|
126
|
+
formatBytes,
|
|
127
|
+
missingBytes,
|
|
128
|
+
weightFiles
|
|
129
|
+
} from "./chunk-IS4USJPY.js";
|
|
130
|
+
import {
|
|
131
|
+
GATEWAY_DEFAULT_EFFORT,
|
|
132
|
+
GATEWAY_EFFORTS
|
|
133
|
+
} from "./chunk-QYHI3YET.js";
|
|
134
|
+
import {
|
|
135
|
+
catalogModel,
|
|
136
|
+
resolveLocalModelId
|
|
137
|
+
} from "./chunk-TQDKJHWX.js";
|
|
138
|
+
import {
|
|
139
|
+
copyToClipboard,
|
|
140
|
+
decodeAttachmentPath,
|
|
141
|
+
expandHomePath,
|
|
142
|
+
queueAttachment
|
|
143
|
+
} from "./chunk-DCZ6CIUM.js";
|
|
144
|
+
import {
|
|
145
|
+
harnessModelLabel,
|
|
146
|
+
nativeModelCatalogForPicker,
|
|
147
|
+
resolveNativeModel
|
|
148
|
+
} from "./chunk-QQRLPY25.js";
|
|
149
|
+
import {
|
|
150
|
+
clearQuotaMark
|
|
151
|
+
} from "./chunk-XWAC3MKW.js";
|
|
152
|
+
import {
|
|
153
|
+
WorkerClient
|
|
154
|
+
} from "./chunk-KI5GZFCE.js";
|
|
155
|
+
import {
|
|
156
|
+
COMPACT_REQUEST,
|
|
157
|
+
MIN_COMPACT_AT_TOKENS,
|
|
158
|
+
NOTHING_TO_COMPACT,
|
|
159
|
+
compactDescription,
|
|
160
|
+
compactFailedLine,
|
|
161
|
+
noteCompactAt,
|
|
162
|
+
parseCompactAt,
|
|
163
|
+
readState,
|
|
164
|
+
tokenLabel
|
|
165
|
+
} from "./chunk-MXS6S2PY.js";
|
|
166
|
+
import {
|
|
167
|
+
resolveDefaultSettings
|
|
168
|
+
} from "./chunk-BISGNHKD.js";
|
|
169
|
+
import {
|
|
170
|
+
writeState
|
|
171
|
+
} from "./chunk-RKUVLRZI.js";
|
|
172
|
+
import {
|
|
173
|
+
deleteConversations
|
|
174
|
+
} from "./chunk-BGEMY2JJ.js";
|
|
175
|
+
import {
|
|
176
|
+
harnessCommand
|
|
177
|
+
} from "./chunk-NWEYRBWK.js";
|
|
178
|
+
import {
|
|
179
|
+
SEND_MODES,
|
|
180
|
+
SEND_MODE_DETAIL,
|
|
181
|
+
applyDefaultSetting,
|
|
182
|
+
commonControlFor,
|
|
183
|
+
forgetNativeThread,
|
|
184
|
+
normalizeModelWord,
|
|
185
|
+
optionForControl,
|
|
186
|
+
parseSendMode,
|
|
187
|
+
sendModeOf,
|
|
188
|
+
sessionPermissionModes,
|
|
189
|
+
setSessionHarnessOption
|
|
190
|
+
} from "./chunk-TWCVV2JO.js";
|
|
191
|
+
import {
|
|
192
|
+
compactPath
|
|
193
|
+
} from "./chunk-WWLJMP6D.js";
|
|
194
|
+
import {
|
|
195
|
+
AGENT_COMPACT_UNAVAILABLE,
|
|
196
|
+
GATEWAY_LABEL,
|
|
197
|
+
ROUTE_CHOICES_TEXT,
|
|
198
|
+
isAiHarnessRoute,
|
|
199
|
+
isClikCodeAgent,
|
|
200
|
+
isGatewayService
|
|
201
|
+
} from "./chunk-CRUVYGO2.js";
|
|
202
|
+
import {
|
|
203
|
+
LEGACY_INTERRUPTED_TURN_REQUEST,
|
|
204
|
+
sessionTranscriptMessages
|
|
205
|
+
} from "./chunk-FF7ZVYJF.js";
|
|
206
|
+
import {
|
|
207
|
+
realpathNearest
|
|
208
|
+
} from "./chunk-IMLTL2MY.js";
|
|
209
|
+
import {
|
|
210
|
+
conversationIdFor
|
|
211
|
+
} from "./chunk-BUOPJQP5.js";
|
|
212
|
+
import {
|
|
213
|
+
textTranscript
|
|
214
|
+
} from "./chunk-3B2CHX7M.js";
|
|
215
|
+
import {
|
|
216
|
+
readStoredPendingTurn
|
|
217
|
+
} from "./chunk-RVUOIJXN.js";
|
|
218
|
+
import {
|
|
219
|
+
conversationHolder
|
|
220
|
+
} from "./chunk-QUS4ER2W.js";
|
|
221
|
+
import {
|
|
222
|
+
harnessCanRunTurns,
|
|
223
|
+
harnessSupportsEffort,
|
|
224
|
+
harnessSupportsModelSelection,
|
|
225
|
+
localHarnessCapabilityManifest,
|
|
226
|
+
localHarnessForCommand,
|
|
227
|
+
localHarnessForProvider,
|
|
228
|
+
modelIdFromDisplay
|
|
229
|
+
} from "./chunk-KYUHIFP3.js";
|
|
230
|
+
import {
|
|
231
|
+
PROBE_DEADLINE_MS,
|
|
232
|
+
TERMINAL,
|
|
233
|
+
isSignedOutRefusal,
|
|
234
|
+
vendorCommandText
|
|
235
|
+
} from "./chunk-DF35KMXM.js";
|
|
236
|
+
import {
|
|
237
|
+
spawnPortable
|
|
238
|
+
} from "./chunk-WPB5WEZJ.js";
|
|
239
|
+
import {
|
|
240
|
+
compactCount,
|
|
241
|
+
relativeTime
|
|
242
|
+
} from "./chunk-EE4B6A7W.js";
|
|
243
|
+
import {
|
|
244
|
+
closeComputerBrowser
|
|
245
|
+
} from "./chunk-MP4KZOQC.js";
|
|
246
|
+
import {
|
|
247
|
+
lockCredentialVault
|
|
248
|
+
} from "./chunk-I75EDU75.js";
|
|
249
|
+
import {
|
|
250
|
+
emitResult
|
|
251
|
+
} from "./chunk-JGIWATSG.js";
|
|
252
|
+
import {
|
|
253
|
+
Conf
|
|
254
|
+
} from "./chunk-GGYKY4GF.js";
|
|
255
|
+
import {
|
|
256
|
+
computerEnabled,
|
|
257
|
+
setComputerEnabled
|
|
258
|
+
} from "./chunk-5SM5UAWN.js";
|
|
259
|
+
import {
|
|
260
|
+
quiet
|
|
261
|
+
} from "./chunk-RDDWQBEM.js";
|
|
262
|
+
import {
|
|
263
|
+
stateDirectory
|
|
264
|
+
} from "./chunk-MPAJ446F.js";
|
|
265
|
+
|
|
266
|
+
// src/tui/slash/registry.ts
|
|
267
|
+
var SLASH_GROUP_ORDER = [
|
|
268
|
+
"Common",
|
|
269
|
+
"Conversation",
|
|
270
|
+
"Workspace",
|
|
271
|
+
"Provider",
|
|
272
|
+
"Settings",
|
|
273
|
+
"Sessions",
|
|
274
|
+
"Info",
|
|
275
|
+
"Tools",
|
|
276
|
+
"Custom",
|
|
277
|
+
"Switch harness"
|
|
278
|
+
];
|
|
279
|
+
function harnessCommandGroup(harness) {
|
|
280
|
+
return `${harness?.displayName ?? "Harness"} commands`;
|
|
281
|
+
}
|
|
282
|
+
function groupRank(group) {
|
|
283
|
+
const index = SLASH_GROUP_ORDER.indexOf(group);
|
|
284
|
+
return index >= 0 ? index : SLASH_GROUP_ORDER.indexOf("Custom") + 0.5;
|
|
285
|
+
}
|
|
286
|
+
var SLASH_PALETTE_PINNED = [
|
|
287
|
+
"resume",
|
|
288
|
+
"provider",
|
|
289
|
+
"account",
|
|
290
|
+
"model",
|
|
291
|
+
"hosted",
|
|
292
|
+
"machine",
|
|
293
|
+
"new",
|
|
294
|
+
"permissions",
|
|
295
|
+
"settings",
|
|
296
|
+
"sessions",
|
|
297
|
+
"status",
|
|
298
|
+
"help"
|
|
299
|
+
];
|
|
300
|
+
var always = () => ({ available: true });
|
|
301
|
+
var GATEWAY_MANAGED = "ClikDeploy Gateway selects this by platform policy; it applies only to local harnesses.";
|
|
302
|
+
var CLIKCODE_LOCAL_AGENT = "A model on this computer runs ClikCode's own agent; this applies only to vendor harnesses.";
|
|
303
|
+
var CLIKCODE_LOCAL_NO_EFFORT = "A model on this computer runs with its own default reasoning; llama.cpp publishes no effort control to set.";
|
|
304
|
+
var localOnly = (session) => {
|
|
305
|
+
if (!isClikCodeAgent(session)) return { available: true };
|
|
306
|
+
return { available: false, reason: isGatewayService(session) ? GATEWAY_MANAGED : CLIKCODE_LOCAL_AGENT };
|
|
307
|
+
};
|
|
308
|
+
var ownOrNative = (name) => (session, harness, _args, native = []) => {
|
|
309
|
+
if (isClikCodeAgent(session)) return { available: true };
|
|
310
|
+
if (!harness) return { available: false, reason: `Choose a provider before /${name}.`, needs: "provider" };
|
|
311
|
+
const has = harness.nativeSlashPassthrough || native.some((command) => command.replace(/^\//, "").toLowerCase() === name);
|
|
312
|
+
return has ? { available: true } : { available: false, reason: `/${name} is not available for ${harness.displayName}.` };
|
|
313
|
+
};
|
|
314
|
+
var agentOnly = (session) => isClikCodeAgent(session) ? { available: true } : { available: false, reason: "The sandbox applies to ClikCode's own agent (ClikDeploy Gateway, a model on this computer included); a vendor harness sandboxes its own commands." };
|
|
315
|
+
var needsHarness = (what) => (session, harness) => {
|
|
316
|
+
const local = localOnly(session);
|
|
317
|
+
if (!local.available) return local;
|
|
318
|
+
return harness ? { available: true } : { available: false, reason: `Choose a provider before ${what}.`, needs: "provider" };
|
|
319
|
+
};
|
|
320
|
+
var notOffered = (what, base, harness, offered, session) => {
|
|
321
|
+
if (!base.available || !harness || isClikCodeAgent(session)) return base;
|
|
322
|
+
return offered(harness) ? base : { available: false, reason: `${what} are not available for ${harness.displayName}.`.replace("effort are", "effort is") };
|
|
323
|
+
};
|
|
324
|
+
var bothRoutes = (what) => (session, harness) => isClikCodeAgent(session) ? { available: true } : harness ? { available: true } : { available: false, reason: `Choose a provider before ${what}.`, needs: "provider" };
|
|
325
|
+
var recordedEditsAvailability = (session, harness, args) => {
|
|
326
|
+
if (isClikCodeAgent(session) || harness?.transport !== "text-cli") return { available: true };
|
|
327
|
+
if (args?.trim() && !/^\d+$/.test(args.trim())) return { available: true };
|
|
328
|
+
return {
|
|
329
|
+
available: false,
|
|
330
|
+
reason: `${harness.displayName} runs as a plain-text CLI: its output reports no file edits ClikCode could record. Use /diff to see what changed and git to revert it.`
|
|
331
|
+
};
|
|
332
|
+
};
|
|
333
|
+
function entry(name, group, description, extra = {}) {
|
|
334
|
+
return {
|
|
335
|
+
name,
|
|
336
|
+
group,
|
|
337
|
+
description,
|
|
338
|
+
aliases: extra.aliases ?? [],
|
|
339
|
+
availability: extra.availability ?? always,
|
|
340
|
+
handlerKey: extra.handlerKey ?? name,
|
|
341
|
+
...extra.argHint ? { argHint: extra.argHint } : {},
|
|
342
|
+
...extra.duringTurn ? { duringTurn: extra.duringTurn } : {}
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
var TERMINAL_ONLY_COMMANDS = /* @__PURE__ */ new Set(["select", "redraw", "exit", "restart"]);
|
|
346
|
+
var SLASH_COMMANDS = [
|
|
347
|
+
entry("new", "Conversation", "start a fresh conversation (the current one stays resumable)", { aliases: ["clear", "reset"], argHint: "[first message]" }),
|
|
348
|
+
// The description names the threshold as it stands (turn/compaction.ts).
|
|
349
|
+
Object.defineProperty(entry("compact", "Conversation", "", { argHint: "[tokens]" }), "description", { get: compactDescription, enumerable: true }),
|
|
350
|
+
entry("history", "Conversation", "show this conversation"),
|
|
351
|
+
entry("hindsight", "Conversation", "this conversation by topic, with the files each changed; numbered as /fork and /redo take them"),
|
|
352
|
+
entry("copy", "Conversation", "copy the last answer"),
|
|
353
|
+
entry("export", "Conversation", "write the transcript as markdown", { argHint: "[path]" }),
|
|
354
|
+
entry("changes", "Conversation", "each turn's file edits; N shows that turn's diff; a path lists the conversations that edited it", { argHint: "[N|path]", availability: recordedEditsAvailability }),
|
|
355
|
+
entry("select", "Conversation", "hand the mouse to the terminal's own selection (drag-to-copy works without it)"),
|
|
356
|
+
entry("redraw", "Conversation", "repaint the screen"),
|
|
357
|
+
entry("exit", "Conversation", "save and leave", { aliases: ["quit"] }),
|
|
358
|
+
entry("restart", "Info", "switch this window to the newest installed ClikCode; the chat stays and what is running keeps running"),
|
|
359
|
+
entry("review", "Workspace", "review uncommitted changes (the provider's own /review where it has one)", { argHint: "[focus]", availability: ownOrNative("review") }),
|
|
360
|
+
entry("init", "Workspace", "create or improve the agent instructions file (the provider's own /init where it has one)", { availability: ownOrNative("init") }),
|
|
361
|
+
entry("memory", "Workspace", "show the harness's memory file; `edit` opens $EDITOR", { argHint: "[edit]" }),
|
|
362
|
+
entry("diff", "Workspace", "changes against HEAD, staged included, plus untracked files"),
|
|
363
|
+
entry("cwd", "Workspace", "show or change the working directory", { argHint: "[dir]" }),
|
|
364
|
+
entry("add-dir", "Workspace", "give the harness another writable directory", { argHint: "<dir>", availability: bothRoutes("adding directories") }),
|
|
365
|
+
entry("mention", "Workspace", "attach a file to the next request; alone, lists what is attached", { argHint: "[path|clear]" }),
|
|
366
|
+
entry("provider", "Provider", "choose a provider", { aliases: ["switch"] }),
|
|
367
|
+
entry("account", "Provider", "switch, add or remove accounts", { aliases: ["accounts"], handlerKey: "accounts", argHint: "[label|login|add|remove \u2026]", duringTurn: "apply" }),
|
|
368
|
+
entry("machine", "Provider", "the machine this chat runs on: move it, add one (Tailscale or SSH), or Tab to update or remove one"),
|
|
369
|
+
entry("login", "Provider", "sign in to the current provider", { availability: needsHarness("signing in") }),
|
|
370
|
+
entry("logout", "Provider", "sign the current account out", { availability: needsHarness("signing out") }),
|
|
371
|
+
entry("gateway", "Provider", "route this conversation through ClikDeploy Gateway"),
|
|
372
|
+
entry("model", "Settings", "choose or set a model", {
|
|
373
|
+
argHint: "[name]",
|
|
374
|
+
duringTurn: "apply",
|
|
375
|
+
availability: (session, harness) => {
|
|
376
|
+
if (isGatewayService(session)) return { available: true };
|
|
377
|
+
if (session?.route === "clikcode-local") return { available: true };
|
|
378
|
+
const base = needsHarness("choosing a model")(session, harness);
|
|
379
|
+
if (!base.available) return base;
|
|
380
|
+
return harnessSupportsModelSelection(harness) ? { available: true } : { available: false, reason: `${harness.displayName} does not publish a model selector.` };
|
|
381
|
+
}
|
|
382
|
+
}),
|
|
383
|
+
entry("hosted", "Settings", "hosted AI: run a model on this computer or on a ClikDeploy GPU", {
|
|
384
|
+
handlerKey: "hostedModels",
|
|
385
|
+
argHint: "ai",
|
|
386
|
+
// Any chat that runs ClikCode's own agent: a model on this computer is hosted AI under the Gateway, so a chat that chose one
|
|
387
|
+
// keeps this command -- it is how the next hosted model is chosen. A vendor harness's chat has to choose the Gateway first.
|
|
388
|
+
availability: (session) => isClikCodeAgent(session) ? { available: true } : { available: false, reason: "Hosted AI runs on ClikDeploy Gateway: choose it with /provider first." }
|
|
389
|
+
}),
|
|
390
|
+
entry("effort", "Settings", "reasoning level", {
|
|
391
|
+
argHint: "[level]",
|
|
392
|
+
duringTurn: "apply",
|
|
393
|
+
availability: (session, harness) => session?.route === "clikcode-local" ? { available: false, reason: CLIKCODE_LOCAL_NO_EFFORT } : isGatewayService(session) ? { available: true } : notOffered("Reasoning effort", needsHarness("setting effort")(session, harness), harness, harnessSupportsEffort)
|
|
394
|
+
}),
|
|
395
|
+
entry("fast", "Settings", "serve from the fastest provider instead of the cheapest", {
|
|
396
|
+
argHint: "[on|off]",
|
|
397
|
+
duringTurn: "apply",
|
|
398
|
+
availability: (session) => isGatewayService(session) ? { available: true } : { available: false, reason: "Speed is a ClikDeploy Gateway choice: it picks among the providers of one model." }
|
|
399
|
+
}),
|
|
400
|
+
entry("permissions", "Settings", "approval behavior", {
|
|
401
|
+
aliases: ["permission"],
|
|
402
|
+
argHint: "[ask|bypass|auto]",
|
|
403
|
+
duringTurn: "apply",
|
|
404
|
+
availability: (session, harness) => notOffered(
|
|
405
|
+
"Permission modes",
|
|
406
|
+
bothRoutes("setting permissions")(session, harness),
|
|
407
|
+
harness,
|
|
408
|
+
(found) => sessionPermissionModes(session ?? { route: "local" }, found).length > 0,
|
|
409
|
+
session
|
|
410
|
+
)
|
|
411
|
+
}),
|
|
412
|
+
entry("sandbox", "Settings", "whether the agent's shell commands write only the workspace, temp and caches (on by default)", { argHint: "[on|off]", availability: agentOnly, duringTurn: "apply" }),
|
|
413
|
+
entry("computer", "Settings", "let the agent use this computer\u2019s browser and desktop", { argHint: "[on|off|inspect|logins|login [url] [--new]]", duringTurn: "apply" }),
|
|
414
|
+
entry("send", "Settings", "messages typed mid-turn: steer into the turn, or queue for after it", { argHint: "[steer|queue]", duringTurn: "apply" }),
|
|
415
|
+
entry("options", "Settings", "provider-specific modes and controls", { availability: needsHarness("setting options") }),
|
|
416
|
+
entry("capabilities", "Settings", "what the selected provider supports"),
|
|
417
|
+
entry("settings", "Settings", "configure this workspace", { argHint: "[tools|model|effort|permissions|option|global|provider \u2026]" }),
|
|
418
|
+
entry("sessions", "Sessions", "manage conversations", { argHint: "[list|show|open|close <id>]" }),
|
|
419
|
+
entry("resume", "Sessions", "resume another conversation"),
|
|
420
|
+
entry("search", "Sessions", "open the conversation that mentions something most, at each mention", { argHint: "<words>" }),
|
|
421
|
+
entry("rename", "Sessions", "name this conversation", { argHint: "[name]" }),
|
|
422
|
+
entry("fork", "Sessions", "branch this conversation, or only through message N", { argHint: "[@N] [name]" }),
|
|
423
|
+
entry("redo", "Conversation", 'go back to before one of your prompts and send it again, edited or not; its edits and later ones are put back unless "keep"', { argHint: "[@N] [keep]" }),
|
|
424
|
+
entry("archive", "Sessions", "archive this conversation"),
|
|
425
|
+
entry("delete", "Sessions", "delete this conversation", { argHint: "[confirm]" }),
|
|
426
|
+
entry("status", "Info", "current configuration"),
|
|
427
|
+
entry("context", "Info", "context window and token usage reported by the harness"),
|
|
428
|
+
entry("usage", "Info", "quota, tokens, and cost for this provider", { aliases: ["cost"], argHint: "[all]" }),
|
|
429
|
+
entry("agents", "Tools", "background agents: list, view recorded work, or stop one", { argHint: "[view [id]|stop <id>|stop all] [confirm]", duringTurn: "apply" }),
|
|
430
|
+
entry("doctor", "Info", "check installed harnesses and accounts"),
|
|
431
|
+
entry("update", "Info", "update ClikCode on the machine this chat runs on: to GitHub main, or a commit for a ClikCode Remote install", { argHint: "[commit]" }),
|
|
432
|
+
entry("help", "Info", "all commands")
|
|
433
|
+
];
|
|
434
|
+
var BY_NAME = new Map(
|
|
435
|
+
SLASH_COMMANDS.flatMap((item) => [[item.name, item], ...item.aliases.map((alias) => [alias, item])])
|
|
436
|
+
);
|
|
437
|
+
function resolveSlashCommand(head) {
|
|
438
|
+
return BY_NAME.get(head.toLowerCase());
|
|
439
|
+
}
|
|
440
|
+
function parseSlashInput(line) {
|
|
441
|
+
const match = /^\/([^\s/][^\s]*)(?:\s+([\s\S]*))?$/.exec(line.trim());
|
|
442
|
+
if (!match) return void 0;
|
|
443
|
+
const args = (match[2] ?? "").trim();
|
|
444
|
+
return { head: match[1].toLowerCase(), args, words: args ? args.split(/\s+/) : [] };
|
|
445
|
+
}
|
|
446
|
+
function slashRows(session, harness, extras, vendor) {
|
|
447
|
+
const rows = SLASH_COMMANDS.filter((item) => !extras.omit?.has(item.name)).map((item) => {
|
|
448
|
+
const state = item.availability(session, harness, void 0, extras.native?.map((command) => command.name));
|
|
449
|
+
return {
|
|
450
|
+
label: `/${item.name}`,
|
|
451
|
+
value: `/${item.name}`,
|
|
452
|
+
group: item.group,
|
|
453
|
+
detail: state.available ? item.description : `unavailable \xB7 ${state.reason ?? item.description}`,
|
|
454
|
+
...item.argHint ? { argHint: item.argHint } : {}
|
|
455
|
+
};
|
|
456
|
+
});
|
|
457
|
+
const taken = new Set(BY_NAME.keys());
|
|
458
|
+
const push = (row) => {
|
|
459
|
+
const name = row.value.slice(1).toLowerCase();
|
|
460
|
+
if (taken.has(name)) return;
|
|
461
|
+
taken.add(name);
|
|
462
|
+
rows.push(row);
|
|
463
|
+
};
|
|
464
|
+
if (vendor) {
|
|
465
|
+
const group = harnessCommandGroup(harness);
|
|
466
|
+
for (const manager of extras.managers ?? []) push({ label: `/${manager.name}`, value: `/${manager.name}`, detail: manager.label, group });
|
|
467
|
+
for (const item of extras.native ?? []) {
|
|
468
|
+
push({ label: `/${item.name}`, value: `/${item.name}`, detail: item.description ?? "harness command", group, ...item.hint ? { argHint: item.hint } : {} });
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
for (const item of extras.custom ?? []) {
|
|
472
|
+
push({ label: `/${item.name}`, value: `/${item.name}`, detail: item.description ?? "custom command", group: "Custom", ...item.argumentHint ? { argHint: item.argumentHint } : {} });
|
|
473
|
+
}
|
|
474
|
+
for (const item of extras.harnesses ?? []) {
|
|
475
|
+
push({ label: `/${item.command}`, value: `/${item.command}`, detail: `switch to ${item.displayName}`, argHint: "[request]", group: "Switch harness" });
|
|
476
|
+
}
|
|
477
|
+
const rank = (row) => groupRank(row.group);
|
|
478
|
+
return rows.map((row, index) => ({ row, index })).sort((a, b) => rank(a.row) - rank(b.row) || a.index - b.index).map(({ row }) => row);
|
|
479
|
+
}
|
|
480
|
+
function slashPalette(session, harness, extras = {}) {
|
|
481
|
+
const rows = slashRows(session, harness, extras, true).filter((row) => row.group !== "Switch harness");
|
|
482
|
+
const pinned = SLASH_PALETTE_PINNED.map((name) => rows.find((row) => row.value === `/${name}`)).filter((row) => row !== void 0 && !row.detail.startsWith("unavailable \xB7 ")).map((row) => ({ ...row, group: "Common" }));
|
|
483
|
+
const pinnedValues = new Set(pinned.map((row) => row.value));
|
|
484
|
+
return [...pinned, ...rows.filter((row) => !pinnedValues.has(row.value))];
|
|
485
|
+
}
|
|
486
|
+
function slashHelpSections(session, harness, extras = {}) {
|
|
487
|
+
const sections = /* @__PURE__ */ new Map();
|
|
488
|
+
for (const row of slashRows(session, harness, extras, true)) {
|
|
489
|
+
if (row.group === "Switch harness") continue;
|
|
490
|
+
const aliases = resolveSlashCommand(row.value.slice(1))?.aliases ?? [];
|
|
491
|
+
sections.set(row.group, [...sections.get(row.group) ?? [], [row.label, `${row.detail}${aliases.length ? ` (also /${aliases.join(", /")})` : ""}`]]);
|
|
492
|
+
}
|
|
493
|
+
const result = [...sections.keys()].sort((left, right) => groupRank(left) - groupRank(right)).map((group) => ({ group, rows: sections.get(group) }));
|
|
494
|
+
result.push({ group: "Switch harness", rows: [
|
|
495
|
+
["/<harness>", "hand off to another provider and optionally send a first request"],
|
|
496
|
+
["//<text>", "send a slash command to the harness itself, verbatim"],
|
|
497
|
+
["!<command>", "run a shell command on this machine and carry its output into the next request"]
|
|
498
|
+
] });
|
|
499
|
+
return result;
|
|
500
|
+
}
|
|
501
|
+
function slashHelpText(session, harness, extras = {}) {
|
|
502
|
+
return slashHelpSections(session, harness, extras).map(({ group, rows }) => {
|
|
503
|
+
const width = Math.min(34, Math.max(...rows.map(([usage]) => usage.length)) + 2);
|
|
504
|
+
return `${group}
|
|
505
|
+
${rows.map(([usage, description]) => ` ${usage.padEnd(width)}${description}`).join("\n")}`;
|
|
506
|
+
}).join("\n\n");
|
|
507
|
+
}
|
|
508
|
+
function terminalKeysHelp() {
|
|
509
|
+
const rows = [
|
|
510
|
+
["esc", "stop the running turn; or take back a waiting message, or cancel a sign-in"],
|
|
511
|
+
["enter", "send; while a turn runs the message waits for the next turn"],
|
|
512
|
+
["enter again", "with nothing typed, send the waiting message into the running turn"],
|
|
513
|
+
["ctrl+c twice", "exit"],
|
|
514
|
+
["up / ctrl+b", "read earlier messages; down / ctrl+f read later ones"],
|
|
515
|
+
["tab", "complete a command"]
|
|
516
|
+
];
|
|
517
|
+
return `Keys
|
|
518
|
+
${rows.map(([key, what]) => ` ${key.padEnd(14)}${what}`).join("\n")}`;
|
|
519
|
+
}
|
|
520
|
+
function slashControls() {
|
|
521
|
+
return [
|
|
522
|
+
...SLASH_COMMANDS.map((item) => ({
|
|
523
|
+
command: `/${item.name}`,
|
|
524
|
+
aliases: item.aliases.map((alias) => `/${alias}`),
|
|
525
|
+
description: item.description,
|
|
526
|
+
group: item.group,
|
|
527
|
+
...item.argHint ? { argHint: item.argHint } : {}
|
|
528
|
+
})),
|
|
529
|
+
{ command: "/<harness>", aliases: [], argHint: "[request]", description: "hand off to another provider and optionally send a first request", group: "Switch harness" },
|
|
530
|
+
{ command: "//<text>", aliases: [], description: "send a slash command to the harness itself, verbatim", group: "Conversation" },
|
|
531
|
+
{ command: "!<command>", aliases: [], description: "run a shell command and carry its output into the next request", group: "Conversation" }
|
|
532
|
+
];
|
|
533
|
+
}
|
|
534
|
+
function editDistance(left, right) {
|
|
535
|
+
const previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
536
|
+
for (let row = 1; row <= left.length; row += 1) {
|
|
537
|
+
let diagonal = previous[0];
|
|
538
|
+
previous[0] = row;
|
|
539
|
+
for (let column = 1; column <= right.length; column += 1) {
|
|
540
|
+
const above = previous[column];
|
|
541
|
+
previous[column] = Math.min(above + 1, previous[column - 1] + 1, diagonal + (left[row - 1] === right[column - 1] ? 0 : 1));
|
|
542
|
+
diagonal = above;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
return previous[right.length];
|
|
546
|
+
}
|
|
547
|
+
function suggestSlashCommand(head, candidates) {
|
|
548
|
+
let best;
|
|
549
|
+
for (const name of candidates) {
|
|
550
|
+
const distance = name.startsWith(head) || head.startsWith(name) ? 1 : editDistance(head, name);
|
|
551
|
+
if (!best || distance < best.distance) best = { name, distance };
|
|
552
|
+
}
|
|
553
|
+
return best && best.distance <= Math.max(2, Math.floor(head.length / 3)) ? best.name : void 0;
|
|
554
|
+
}
|
|
555
|
+
function slashRouteAppliesDuringTurn(route, session) {
|
|
556
|
+
if (route.kind === "command" && route.entry.name === "model" && session?.route === "clikcode-local") return false;
|
|
557
|
+
if (route.kind === "harness") return true;
|
|
558
|
+
return route.kind === "command" && route.entry.duringTurn === "apply" && route.args.trim().length > 0;
|
|
559
|
+
}
|
|
560
|
+
function routeSlashInput(line, context = {}) {
|
|
561
|
+
const text = line.trim();
|
|
562
|
+
if (!text.startsWith("/")) return { kind: "prompt", prompt: text };
|
|
563
|
+
if (text.startsWith("//")) {
|
|
564
|
+
const literal = text.slice(1).trim();
|
|
565
|
+
return literal.length > 1 ? { kind: "native", prompt: literal, why: "explicit" } : { kind: "prompt", prompt: text };
|
|
566
|
+
}
|
|
567
|
+
const firstToken = text.split(/\s+/, 1)[0];
|
|
568
|
+
const looksNested = firstToken.indexOf("/", 1) > 0;
|
|
569
|
+
if (looksNested && context.pathExists?.(firstToken)) return { kind: "prompt", prompt: text };
|
|
570
|
+
const parsed = parseSlashInput(text);
|
|
571
|
+
if (!parsed) return { kind: "prompt", prompt: text };
|
|
572
|
+
const { head, args, words } = parsed;
|
|
573
|
+
const entryMatch = resolveSlashCommand(head);
|
|
574
|
+
if (entryMatch) return { kind: "command", entry: entryMatch, head, args, words };
|
|
575
|
+
if (context.managerNames?.includes(head)) return { kind: "manager", name: head, args };
|
|
576
|
+
if (context.customCommands?.includes(head)) return { kind: "custom", name: head, args };
|
|
577
|
+
if (context.harnessCommands?.includes(head)) return { kind: "harness", command: head, args };
|
|
578
|
+
if (context.nativeCommands?.includes(head)) return { kind: "native", prompt: text, why: "advertised" };
|
|
579
|
+
if (!looksNested && context.pathExists?.(firstToken)) return { kind: "prompt", prompt: text };
|
|
580
|
+
if (context.harness?.nativeSlashPassthrough) return { kind: "native", prompt: text, why: "passthrough" };
|
|
581
|
+
const suggestion = suggestSlashCommand(head, [
|
|
582
|
+
...BY_NAME.keys(),
|
|
583
|
+
...context.managerNames ?? [],
|
|
584
|
+
...context.customCommands ?? [],
|
|
585
|
+
...context.harnessCommands ?? []
|
|
586
|
+
]);
|
|
587
|
+
return { kind: "unknown", head, ...suggestion ? { suggestion } : {} };
|
|
588
|
+
}
|
|
589
|
+
function unknownSlashMessage(route) {
|
|
590
|
+
return `unknown slash command: /${route.head}${route.suggestion ? ` \u2014 did you mean /${route.suggestion}?` : ""}. Use //${route.head} to send it to the harness verbatim.`;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// src/tui/slash/infer-provider.ts
|
|
594
|
+
function usable(accounts) {
|
|
595
|
+
return accounts.filter((account) => account.status === "ready");
|
|
596
|
+
}
|
|
597
|
+
function soleProvider(accounts) {
|
|
598
|
+
const providers = new Set(accounts.map((account) => account.provider));
|
|
599
|
+
return providers.size === 1 ? [...providers][0] : void 0;
|
|
600
|
+
}
|
|
601
|
+
var sameWord = (left, right) => left.trim().toLowerCase() === right.trim().toLowerCase();
|
|
602
|
+
function providerImpliedBy(route, accounts) {
|
|
603
|
+
const args = route.args.trim();
|
|
604
|
+
const ready = usable(accounts);
|
|
605
|
+
if (route.head === "model") {
|
|
606
|
+
if (!args) return void 0;
|
|
607
|
+
if (["auto", "default"].includes(args.toLowerCase())) return void 0;
|
|
608
|
+
return soleProvider(ready.filter((account) => account.models.some((model) => sameWord(model, args))));
|
|
609
|
+
}
|
|
610
|
+
if (route.head === "account" || route.head === "accounts") {
|
|
611
|
+
const label = route.head === "accounts" ? /^use\s+/i.test(args) ? args.replace(/^use\s+/i, "") : "" : args;
|
|
612
|
+
if (!label.trim()) return void 0;
|
|
613
|
+
return soleProvider(accounts.filter((account) => sameWord(account.label, label)));
|
|
614
|
+
}
|
|
615
|
+
if (route.head === "login") {
|
|
616
|
+
return soleProvider(accounts);
|
|
617
|
+
}
|
|
618
|
+
return void 0;
|
|
619
|
+
}
|
|
620
|
+
function impliedHarnessCommand(route, accounts, harnessForProvider) {
|
|
621
|
+
const provider = providerImpliedBy(route, accounts);
|
|
622
|
+
return provider ? harnessForProvider(provider)?.command : void 0;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
// src/tui/slash/native-manager.ts
|
|
626
|
+
async function nativeManagerListing(state, session, name) {
|
|
627
|
+
const harness = sessionHarness(session);
|
|
628
|
+
if (!harness) throw new Error("Choose a provider first.");
|
|
629
|
+
const manager = localHarnessCapabilityManifest(harness).managers?.[name];
|
|
630
|
+
if (!manager) throw new Error(`${harness.displayName} does not publish a ${name} manager.`);
|
|
631
|
+
if (!manager.listArgv) throw new Error(`${harness.displayName} manages ${manager.label} only in its own interactive UI; open it from the interactive ClikCode session.`);
|
|
632
|
+
const account = session.accountId ? state.accounts.find((item) => item.id === session.accountId) : void 0;
|
|
633
|
+
const text = await vendorCommandText({ gate: harness, argv: manager.listArgv, environment: turnEnvironment(harness, account), deadlineMs: PROBE_DEADLINE_MS, cwd: session.workspace }).catch((error) => {
|
|
634
|
+
throw isSignedOutRefusal(error) ? new Error(`${harness.displayName} is not signed in. Sign in with /login first.`) : error;
|
|
635
|
+
});
|
|
636
|
+
return { label: manager.label, text: text.trim() || "No entries." };
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
// src/tui/slash/handlers/conversation.ts
|
|
640
|
+
import { stripVTControlCharacters } from "node:util";
|
|
641
|
+
|
|
642
|
+
// src/tui/slash/hindsight-panel.ts
|
|
643
|
+
function promptNumberedMessages(messages) {
|
|
644
|
+
let prompt = 0;
|
|
645
|
+
return messages.flatMap((message) => {
|
|
646
|
+
if (message.role === "user" && message.content === LEGACY_INTERRUPTED_TURN_REQUEST) return [];
|
|
647
|
+
if (message.role === "user") prompt += 1;
|
|
648
|
+
const origin = message.origin;
|
|
649
|
+
return [{
|
|
650
|
+
index: prompt,
|
|
651
|
+
role: message.role,
|
|
652
|
+
content: message.content ?? "",
|
|
653
|
+
...origin ? { origin: { ...origin.harness ? { harness: origin.harness } : {}, provider: origin.provider, model: origin.model } } : {}
|
|
654
|
+
}];
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
function promptRange(topic) {
|
|
658
|
+
if (topic.from === void 0 || topic.to === void 0) return "";
|
|
659
|
+
return topic.from === topic.to ? `${topic.from}` : `${topic.from}\u2013${topic.to}`;
|
|
660
|
+
}
|
|
661
|
+
function topicRows(topic, now) {
|
|
662
|
+
const at = relativeTime(topic.at, now);
|
|
663
|
+
const head = [topic.status, ...at ? [at] : [], ...topic.origin ? [topic.origin] : []].join(" \xB7 ");
|
|
664
|
+
const more = topic.requests.length > 1 ? ` (+${topic.requests.length - 1} more)` : "";
|
|
665
|
+
const files = topic.files.map((file) => `${file.path} +${file.additions} -${file.removals}`);
|
|
666
|
+
if (topic.unnamedEdits) files.push(`${topic.unnamedEdits} unnamed edit${topic.unnamedEdits === 1 ? "" : "s"}`);
|
|
667
|
+
return [
|
|
668
|
+
` ${promptRange(topic).padStart(5)} ${head}`,
|
|
669
|
+
` ${oneLine(topic.requests[0]?.text ?? "", 80)}${more}`,
|
|
670
|
+
...files.length ? [` files: ${files.slice(0, 4).join(", ")}${files.length > 4 ? ` +${files.length - 4} more` : ""}`] : []
|
|
671
|
+
];
|
|
672
|
+
}
|
|
673
|
+
function hindsightPanelText(messages, records, options) {
|
|
674
|
+
const presented = presentTopics(promptNumberedMessages(messages), { records, originFallback: options.originFallback });
|
|
675
|
+
const topics = [...presented.earlier, ...presented.current ? [presented.current] : []].reverse();
|
|
676
|
+
if (!topics.length) return "Hindsight\nNo prompts in this conversation yet.";
|
|
677
|
+
const now = options.now ?? Date.now();
|
|
678
|
+
return [
|
|
679
|
+
`Hindsight \xB7 ${topics.length} topic${topics.length === 1 ? "" : "s"}, newest first`,
|
|
680
|
+
...topics.flatMap((topic) => topicRows(topic, now)),
|
|
681
|
+
"",
|
|
682
|
+
"Numbers are your prompts: /fork @N branches through prompt N, /redo @N goes back to before it."
|
|
683
|
+
].join("\n");
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// src/tui/slash/file-changes.ts
|
|
687
|
+
import path from "node:path";
|
|
688
|
+
function isChangesPath(args) {
|
|
689
|
+
const word = args.trim();
|
|
690
|
+
return word.length > 0 && !/^\d+$/.test(word);
|
|
691
|
+
}
|
|
692
|
+
function changesPath(args, workspace) {
|
|
693
|
+
return path.resolve(workspace, expandHomePath(args.trim()));
|
|
694
|
+
}
|
|
695
|
+
async function fileTurnRows(state, file, now = Date.now()) {
|
|
696
|
+
const byId = new Map(state.sessions.map((session) => [session.id, session]));
|
|
697
|
+
return (await turnsThatEdited(stateDirectory(), state.sessions, file)).map((turn) => {
|
|
698
|
+
const session = byId.get(turn.sessionId);
|
|
699
|
+
return { ...turn, ...fileTurnRow(turn, `${conversationTitle(session, 40)} ${shortId(session.id)}`, relativeTime(turn.record.at, now)) };
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
function noFileTurns(file) {
|
|
703
|
+
return `No recorded turn in any conversation edited ${compactPath(file)}`;
|
|
704
|
+
}
|
|
705
|
+
function fileTurnsText(file, rows) {
|
|
706
|
+
if (!rows.length) return `${noFileTurns(file)}.`;
|
|
707
|
+
return [
|
|
708
|
+
`${compactPath(file)} \xB7 ${rows.length} turn${rows.length === 1 ? "" : "s"} edited it, newest first`,
|
|
709
|
+
...rows.flatMap((row) => [` ${row.label}`, ` ${row.detail}`]),
|
|
710
|
+
"",
|
|
711
|
+
"/resume <id> opens that conversation; there /changes N shows the turn's diff."
|
|
712
|
+
].join("\n");
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
// src/tui/slash/handlers/conversation.ts
|
|
716
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
717
|
+
import { isAbsolute as isAbsolute2, resolve as resolve2 } from "node:path";
|
|
718
|
+
|
|
719
|
+
// src/tui/slash/capabilities-text.ts
|
|
720
|
+
function capabilitiesText(session) {
|
|
721
|
+
if (session.route === "clikcode-local") {
|
|
722
|
+
return [
|
|
723
|
+
"ClikDeploy Gateway capabilities (a model on this computer)",
|
|
724
|
+
"Inference: a local model on this machine",
|
|
725
|
+
"Tools: ClikCode's own tools, MCP servers, and skills",
|
|
726
|
+
"Permissions: ClikCode's own ask / auto / bypass modes",
|
|
727
|
+
"Sessions: durable ClikCode transcript replay",
|
|
728
|
+
"Context: compacted locally by ClikCode's agent"
|
|
729
|
+
].join("\n");
|
|
730
|
+
}
|
|
731
|
+
if (isGatewayService(session)) {
|
|
732
|
+
return [
|
|
733
|
+
"ClikDeploy Gateway capabilities",
|
|
734
|
+
"Inference routing: one model per name, served by its cheapest provider (/fast: its fastest)",
|
|
735
|
+
"Streaming: live SSE token deltas with bounded fallback chunking",
|
|
736
|
+
"Tools: ClikDeploy Gateway capability registry and MCP bridge",
|
|
737
|
+
"Permissions: authenticated server policy and confirmation gates",
|
|
738
|
+
"Sessions: durable ClikCode transcript replay",
|
|
739
|
+
"Models: chosen with /model from the Gateway's list, or automatic",
|
|
740
|
+
"Effort: /effort sets how hard a reasoning model thinks (none to xhigh)",
|
|
741
|
+
"Images: sent to models that take them"
|
|
742
|
+
].join("\n");
|
|
743
|
+
}
|
|
744
|
+
const harness = sessionHarness(session);
|
|
745
|
+
if (!harness) throw new Error("Choose a provider first.");
|
|
746
|
+
const manifest = localHarnessCapabilityManifest(harness);
|
|
747
|
+
return [
|
|
748
|
+
`${harness.displayName} capabilities`,
|
|
749
|
+
...manifest.options.map((option) => {
|
|
750
|
+
const control = commonControlFor(option.id);
|
|
751
|
+
return `${option.label}: ${option.description}${control ? ` (${control})` : ""}`;
|
|
752
|
+
}),
|
|
753
|
+
...Object.entries(manifest.managers ?? {}).map(([name, manager]) => `${manager?.label ?? name}: available`),
|
|
754
|
+
...(manifest.features ?? []).map((feature) => `${feature}: native`)
|
|
755
|
+
].join("\n");
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// src/tui/slash/compact.ts
|
|
759
|
+
async function compactConversation(id, session, args, send) {
|
|
760
|
+
if (args.trim()) return setCompactThreshold(args);
|
|
761
|
+
if (isClikCodeAgent(session)) throw new Error(compactFailedLine(AGENT_COMPACT_UNAVAILABLE));
|
|
762
|
+
if (!hasThreadToCompact(session)) return NOTHING_TO_COMPACT;
|
|
763
|
+
await send(id, COMPACT_REQUEST);
|
|
764
|
+
return void 0;
|
|
765
|
+
}
|
|
766
|
+
async function setCompactThreshold(word) {
|
|
767
|
+
const tokens = parseCompactAt(word);
|
|
768
|
+
if (tokens === void 0) throw new Error("usage: /compact [tokens, such as 150k]");
|
|
769
|
+
if (tokens < MIN_COMPACT_AT_TOKENS) throw new Error(`The threshold must be at least ${tokenLabel(MIN_COMPACT_AT_TOKENS)} tokens.`);
|
|
770
|
+
const state = await readState({ transcripts: [] });
|
|
771
|
+
state.globalSettings.compactAt = tokens;
|
|
772
|
+
await writeState(state);
|
|
773
|
+
noteCompactAt(state.globalSettings);
|
|
774
|
+
return `Compacts at ${tokenLabel(tokens)} tokens.`;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
// src/tui/slash/cost.ts
|
|
778
|
+
function formatTokens(value) {
|
|
779
|
+
return value === void 0 ? "\u2014" : compactCount(value);
|
|
780
|
+
}
|
|
781
|
+
function contextUsageText(session) {
|
|
782
|
+
const usage = session.lastUsage;
|
|
783
|
+
const who = isClikCodeAgent(session) ? GATEWAY_LABEL : sessionHarness(session)?.displayName ?? "The provider";
|
|
784
|
+
if (!usage) return `${who} has not reported token usage for this conversation yet. It appears here after a turn on a harness that publishes usage events.`;
|
|
785
|
+
const used = usage.contextUsed ?? usage.totalTokens ?? ((usage.input ?? 0) + (usage.output ?? 0) || void 0);
|
|
786
|
+
const window = usage.contextWindow;
|
|
787
|
+
return [
|
|
788
|
+
`Context usage (${relativeTime(usage.at)})`,
|
|
789
|
+
window && used !== void 0 ? ` window ${formatTokens(used)} / ${formatTokens(window)} tokens (${Math.min(100, Math.round(used / window * 100))}%)` : ` window not reported by ${who}`,
|
|
790
|
+
` input ${formatTokens(usage.input)}`,
|
|
791
|
+
` cached ${formatTokens(usage.cacheRead)}`,
|
|
792
|
+
` output ${formatTokens(usage.output)}`,
|
|
793
|
+
` total ${formatTokens(usage.totalTokens ?? used)}`,
|
|
794
|
+
` messages ${sessionTranscriptMessages(session).length}`
|
|
795
|
+
].join("\n");
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
// src/tui/slash/fork-at.ts
|
|
799
|
+
function userMessageIndexes(messages) {
|
|
800
|
+
return messages.flatMap((message, index) => message.role === "user" && message.content !== LEGACY_INTERRUPTED_TURN_REQUEST ? [index] : []);
|
|
801
|
+
}
|
|
802
|
+
function forkPoint(word) {
|
|
803
|
+
const match = /^@(\d+)$/.exec(word ?? "");
|
|
804
|
+
return match ? Number(match[1]) : void 0;
|
|
805
|
+
}
|
|
806
|
+
function messagesThrough(messages, n) {
|
|
807
|
+
const users = userMessageIndexes(messages);
|
|
808
|
+
if (!Number.isInteger(n) || n < 1 || n > users.length) {
|
|
809
|
+
throw new Error(users.length ? `No message ${n}: this conversation has messages 1 to ${users.length}.` : "This conversation has no messages to fork at yet.");
|
|
810
|
+
}
|
|
811
|
+
return messages.slice(0, users[n] ?? messages.length);
|
|
812
|
+
}
|
|
813
|
+
function forkPointOptions(messages) {
|
|
814
|
+
return userMessageIndexes(messages).map((at, position) => {
|
|
815
|
+
const line = messages[at].content.replace(/\s+/g, " ").trim();
|
|
816
|
+
return { label: `${position + 1} ${line.length > 72 ? `${line.slice(0, 71)}\u2026` : line}`, value: position + 1 };
|
|
817
|
+
}).reverse();
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
// src/tui/slash/memory.ts
|
|
821
|
+
import { readFile } from "node:fs/promises";
|
|
822
|
+
import { join } from "node:path";
|
|
823
|
+
function memoryFileName(session) {
|
|
824
|
+
return sessionHarness(session)?.memoryFile ?? "AGENTS.md";
|
|
825
|
+
}
|
|
826
|
+
function initPrompt(session) {
|
|
827
|
+
const file = memoryFileName(session);
|
|
828
|
+
return `Inspect this repository and create or improve ${file} with concise, accurate build, test, architecture, and contribution instructions for coding agents. Verify every command you include.`;
|
|
829
|
+
}
|
|
830
|
+
function reviewPrompt(extra) {
|
|
831
|
+
return `Review the uncommitted changes in this workspace. Identify concrete bugs, regressions, security issues, and missing tests. Prioritize findings and cite file paths.${extra ? ` Additional focus: ${extra}` : ""}`;
|
|
832
|
+
}
|
|
833
|
+
async function readMemoryFile(session) {
|
|
834
|
+
const path3 = join(session.workspace ?? process.cwd(), memoryFileName(session));
|
|
835
|
+
try {
|
|
836
|
+
return { path: path3, content: (await readFile(path3, "utf8")).slice(0, 256 * 1024) };
|
|
837
|
+
} catch (error) {
|
|
838
|
+
if (error.code === "ENOENT") return { path: path3 };
|
|
839
|
+
throw error;
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
// src/tui/slash/workspace.ts
|
|
844
|
+
import { stat } from "node:fs/promises";
|
|
845
|
+
import { isAbsolute, resolve } from "node:path";
|
|
846
|
+
function captureProcess(command, args, cwd, stdinText) {
|
|
847
|
+
return new Promise((resolve3, reject) => {
|
|
848
|
+
const child = spawnPortable(command, [...args], { cwd, stdio: [stdinText === void 0 ? "ignore" : "pipe", "pipe", "pipe"] });
|
|
849
|
+
let stdout = "";
|
|
850
|
+
let stderr = "";
|
|
851
|
+
child.stdout.setEncoding("utf8");
|
|
852
|
+
child.stderr.setEncoding("utf8");
|
|
853
|
+
child.stdout.on("data", (chunk) => {
|
|
854
|
+
if (stdout.length < 1024 * 1024) stdout += chunk;
|
|
855
|
+
});
|
|
856
|
+
child.stderr.on("data", (chunk) => {
|
|
857
|
+
if (stderr.length < 16 * 1024) stderr += chunk;
|
|
858
|
+
});
|
|
859
|
+
if (stdinText !== void 0) child.stdin.end(stdinText);
|
|
860
|
+
child.once("error", reject);
|
|
861
|
+
child.once("exit", (code) => code === 0 ? resolve3(stdout) : reject(new Error(stderr.trim() || `${command} exited ${code ?? 1}`)));
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
async function workspaceDiff(workspace) {
|
|
865
|
+
const git = (args) => captureProcess("git", args, workspace);
|
|
866
|
+
if (!await git(["rev-parse", "--is-inside-work-tree"]).then((out) => out.trim() === "true", () => false)) return void 0;
|
|
867
|
+
const hasHead = await git(["rev-parse", "--verify", "--quiet", "HEAD"]).then(() => true, () => false);
|
|
868
|
+
const base = hasHead ? ["diff", "--no-ext-diff", "HEAD"] : ["diff", "--no-ext-diff", "--cached"];
|
|
869
|
+
const [stat2, details, untracked] = await Promise.all([
|
|
870
|
+
git([...base, "--stat", "--", "."]),
|
|
871
|
+
git([...base, "--", "."]),
|
|
872
|
+
git(["ls-files", "--others", "--exclude-standard", "--", "."]).catch(() => "")
|
|
873
|
+
]);
|
|
874
|
+
const untrackedFiles = untracked.split(/\r?\n/).filter(Boolean);
|
|
875
|
+
const sections = [
|
|
876
|
+
stat2.trim(),
|
|
877
|
+
details.trim(),
|
|
878
|
+
untrackedFiles.length ? `Untracked files (${untrackedFiles.length}):
|
|
879
|
+
${untrackedFiles.slice(0, 200).map((file) => ` ${file}`).join("\n")}${untrackedFiles.length > 200 ? `
|
|
880
|
+
\u2026 ${untrackedFiles.length - 200} more` : ""}` : ""
|
|
881
|
+
].filter(Boolean);
|
|
882
|
+
return sections.join("\n\n").slice(0, 512 * 1024);
|
|
883
|
+
}
|
|
884
|
+
async function resolveExistingDirectory(session, raw) {
|
|
885
|
+
const expanded = expandHomePath(decodeAttachmentPath(raw));
|
|
886
|
+
const path3 = isAbsolute(expanded) ? resolve(expanded) : resolve(session.workspace ?? process.cwd(), expanded);
|
|
887
|
+
const info = await stat(path3).catch(quiet("tui/slash/workspace"));
|
|
888
|
+
if (!info) throw new Error(`${compactPath(path3)} does not exist.`);
|
|
889
|
+
if (!info.isDirectory()) throw new Error(`${compactPath(path3)} is not a directory.`);
|
|
890
|
+
return path3;
|
|
891
|
+
}
|
|
892
|
+
async function changeSessionWorkspace(state, session, raw) {
|
|
893
|
+
const path3 = await resolveExistingDirectory(session, raw);
|
|
894
|
+
if (path3 === (session.workspace ?? process.cwd())) return `Already working in ${compactPath(path3)}.`;
|
|
895
|
+
const droppedNative = Boolean(session.nativeSessionId);
|
|
896
|
+
session.workspace = path3;
|
|
897
|
+
forgetNativeThread(session);
|
|
898
|
+
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
899
|
+
await writeState(state);
|
|
900
|
+
await leavePersistentTransport(session.id);
|
|
901
|
+
return `Working directory is now ${compactPath(path3)}.${droppedNative ? " The native session belonged to the previous directory, so the next turn starts a fresh one with this conversation replayed." : ""}`;
|
|
902
|
+
}
|
|
903
|
+
async function addSessionDirectory(state, session, raw) {
|
|
904
|
+
if (!raw.trim()) throw new Error("usage: /add-dir <dir>");
|
|
905
|
+
const harness = sessionHarness(session);
|
|
906
|
+
if (!harness) throw new Error("Choose a provider before adding directories.");
|
|
907
|
+
const option = optionForControl(harness, "/add-dir");
|
|
908
|
+
if (!option) throw new Error(`${harness.displayName} does not declare an additional-directory option; start ClikCode from a common parent directory or use /cwd instead.`);
|
|
909
|
+
const path3 = await resolveExistingDirectory(session, raw);
|
|
910
|
+
const current = session.harnessOptions?.[option.id];
|
|
911
|
+
const existing = Array.isArray(current) ? current.map(String) : typeof current === "string" && current ? [current] : [];
|
|
912
|
+
if (existing.includes(path3)) return `${compactPath(path3)} is already available to ${harness.displayName}.`;
|
|
913
|
+
session.harnessOptions = { ...session.harnessOptions, [option.id]: option.kind === "path-list" || option.kind === "string-list" ? [...existing, path3] : path3 };
|
|
914
|
+
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
915
|
+
await writeState(state);
|
|
916
|
+
await leavePersistentTransport(session.id);
|
|
917
|
+
return `${harness.displayName} can now also work in ${compactPath(path3)}.`;
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
// src/session/redo.ts
|
|
921
|
+
import { randomUUID } from "node:crypto";
|
|
922
|
+
|
|
923
|
+
// src/session/undo-turn.ts
|
|
924
|
+
import fs from "node:fs/promises";
|
|
925
|
+
import path2 from "node:path";
|
|
926
|
+
|
|
927
|
+
// src/agent/diff-unwind.ts
|
|
928
|
+
function fileHunks(file) {
|
|
929
|
+
const hunks = [];
|
|
930
|
+
let current;
|
|
931
|
+
for (const line of file.lines) {
|
|
932
|
+
if (line.kind === "gap") {
|
|
933
|
+
current = void 0;
|
|
934
|
+
continue;
|
|
935
|
+
}
|
|
936
|
+
if (!current) {
|
|
937
|
+
current = { before: [], after: [] };
|
|
938
|
+
hunks.push(current);
|
|
939
|
+
}
|
|
940
|
+
if (line.kind !== "added") current.before.push(line.text);
|
|
941
|
+
if (line.kind !== "removed") current.after.push(line.text);
|
|
942
|
+
}
|
|
943
|
+
return hunks;
|
|
944
|
+
}
|
|
945
|
+
function applyHunks(text, hunks) {
|
|
946
|
+
const newline = text.includes("\r\n") ? "\r\n" : "\n";
|
|
947
|
+
const lines = text.split(/\r?\n/);
|
|
948
|
+
const out = [];
|
|
949
|
+
let at = 0;
|
|
950
|
+
for (const hunk of hunks) {
|
|
951
|
+
const find = (from) => {
|
|
952
|
+
for (let index2 = from; index2 + hunk.before.length <= lines.length; index2 += 1) {
|
|
953
|
+
if (hunk.before.every((line, offset) => lines[index2 + offset] === line)) return index2;
|
|
954
|
+
}
|
|
955
|
+
return -1;
|
|
956
|
+
};
|
|
957
|
+
const index = hunk.before.length ? find(at) : hunks.length === 1 && lines.length <= 1 && !lines[0] ? 0 : -1;
|
|
958
|
+
if (index < 0 || hunk.before.length && find(index + 1) >= 0) return void 0;
|
|
959
|
+
out.push(...lines.slice(at, index), ...hunk.after);
|
|
960
|
+
at = index + hunk.before.length;
|
|
961
|
+
}
|
|
962
|
+
out.push(...lines.slice(at));
|
|
963
|
+
return out.join(newline);
|
|
964
|
+
}
|
|
965
|
+
function fragmentText(file, newline) {
|
|
966
|
+
if (!file.lines.length || file.lines.some((line) => line.kind === "gap" || line.line !== void 0)) return void 0;
|
|
967
|
+
const side = (skip) => file.lines.filter((line) => line.kind !== skip).map((line) => line.text).join(newline);
|
|
968
|
+
return { before: side("added"), after: side("removed") };
|
|
969
|
+
}
|
|
970
|
+
function replaceOnce(text, find, replacement) {
|
|
971
|
+
if (!find) return void 0;
|
|
972
|
+
const at = text.indexOf(find);
|
|
973
|
+
if (at < 0 || text.indexOf(find, at + 1) >= 0) return void 0;
|
|
974
|
+
return text.slice(0, at) + replacement + text.slice(at + find.length);
|
|
975
|
+
}
|
|
976
|
+
function turnChanges(activities) {
|
|
977
|
+
const files = /* @__PURE__ */ new Map();
|
|
978
|
+
for (const activity of activities) {
|
|
979
|
+
if (activity.kind !== "tool-done") continue;
|
|
980
|
+
for (const file of activity.diff ?? []) {
|
|
981
|
+
if (!file.path) continue;
|
|
982
|
+
files.set(file.path, [...files.get(file.path) ?? [], file]);
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
return files;
|
|
986
|
+
}
|
|
987
|
+
function unwindChanges(current, changes) {
|
|
988
|
+
if (current === void 0) return { before: "", whole: false, created: false };
|
|
989
|
+
let text = current;
|
|
990
|
+
for (let index = changes.length - 1; index >= 0; index -= 1) {
|
|
991
|
+
const change = changes[index];
|
|
992
|
+
if (change.priorUnknown) return { before: text, whole: false, created: false };
|
|
993
|
+
const fragment = fragmentText(change, text.includes("\r\n") ? "\r\n" : "\n");
|
|
994
|
+
const undone = change.omitted ? void 0 : fragment ? replaceOnce(text, fragment.after, fragment.before) : applyHunks(text, fileHunks(change).map((hunk) => ({ before: hunk.after, after: hunk.before })));
|
|
995
|
+
if (change.change === "add") {
|
|
996
|
+
return undone !== void 0 && !undone.trim() ? { before: "", whole: true, created: true } : { before: text, whole: false, created: false };
|
|
997
|
+
}
|
|
998
|
+
if (undone === void 0) return { before: text, whole: false, created: false };
|
|
999
|
+
text = undone;
|
|
1000
|
+
}
|
|
1001
|
+
return { before: text, whole: true, created: false };
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
// src/session/undo-turn.ts
|
|
1005
|
+
var SHELL_CAVEAT = "Tracked: edits made through file-editing tools, and (ClikCode's agent) files a shell command changed in the git repository. Anything else a shell command changed (ignored or generated files, installs, git operations) is not undone.";
|
|
1006
|
+
var OUTSIDE_WORKSPACE = "outside this conversation's workspace; not touched";
|
|
1007
|
+
function shown(file, workspace) {
|
|
1008
|
+
const relative = path2.relative(workspace, file);
|
|
1009
|
+
return relative && !relative.startsWith("..") && !path2.isAbsolute(relative) ? relative : file;
|
|
1010
|
+
}
|
|
1011
|
+
function turnName(record) {
|
|
1012
|
+
const prompt = record?.prompt?.replace(/\s+/g, " ").trim();
|
|
1013
|
+
if (!prompt) return "the last turn";
|
|
1014
|
+
return `the turn "${prompt.length > 60 ? `${prompt.slice(0, 59)}\u2026` : prompt}"`;
|
|
1015
|
+
}
|
|
1016
|
+
function describe(result, workspace, name) {
|
|
1017
|
+
const done = result.restored.length + result.removed.length;
|
|
1018
|
+
const lines = [done ? `Undid ${name}: its changes to ${done} file${done === 1 ? "" : "s"}.` : `Could not undo ${name}: no file it changed could be put back.`];
|
|
1019
|
+
for (const file of result.restored) lines.push(` restored ${shown(file, workspace)}`);
|
|
1020
|
+
for (const file of result.removed) lines.push(` removed ${shown(file, workspace)} (the turn created it)`);
|
|
1021
|
+
for (const item of result.conflicts) lines.push(` kept ${shown(item.path, workspace)}: ${item.reason}`);
|
|
1022
|
+
if (result.conflicts.length) lines.push("", "Files kept were not touched: revert them with git.");
|
|
1023
|
+
lines.push("", SHELL_CAVEAT);
|
|
1024
|
+
return lines.join("\n");
|
|
1025
|
+
}
|
|
1026
|
+
function inside(target, workspace) {
|
|
1027
|
+
const relative = path2.relative(realpathNearest(path2.resolve(workspace)), realpathNearest(path2.resolve(target)));
|
|
1028
|
+
return relative !== "" && !relative.startsWith("..") && !path2.isAbsolute(relative);
|
|
1029
|
+
}
|
|
1030
|
+
async function undoAgentTurn(stateDir, sessionId, record, workspace, result) {
|
|
1031
|
+
const store = new FileCheckpointStore(stateDir);
|
|
1032
|
+
const from = record.startedAt ?? record.at;
|
|
1033
|
+
const turnIds = (await store.listTurns(sessionId)).filter((turn) => turn.createdAt >= from && turn.createdAt <= record.at).map((turn) => turn.turnId);
|
|
1034
|
+
if (!turnIds.length) return void 0;
|
|
1035
|
+
const outcome = await store.undo(sessionId, 1, { turnIds, roots: [workspace] });
|
|
1036
|
+
result.restored.push(...outcome.restored);
|
|
1037
|
+
result.removed.push(...outcome.deleted);
|
|
1038
|
+
result.conflicts.push(...outcome.failed.map((item) => ({ path: item.path, reason: /outside the allowed roots/.test(item.reason) ? OUTSIDE_WORKSPACE : item.reason })));
|
|
1039
|
+
const left = new Set((await store.listTurns(sessionId)).map((turn) => turn.turnId));
|
|
1040
|
+
return !turnIds.some((id) => left.has(id));
|
|
1041
|
+
}
|
|
1042
|
+
function conflictReason(current, changes) {
|
|
1043
|
+
if (changes.some((change) => change.priorUnknown)) return { reason: "the harness reported only what it wrote here, not what the file held before, so it cannot be put back", retry: false };
|
|
1044
|
+
if (changes.some((change) => change.omitted)) return { reason: "the harness reported this change only in part, so it cannot be reversed exactly", retry: false };
|
|
1045
|
+
if (current === void 0) {
|
|
1046
|
+
return changes.some((change) => change.change === "delete") ? { reason: "the turn deleted it and the harness did not report its content", retry: false } : { reason: "it no longer exists", retry: true };
|
|
1047
|
+
}
|
|
1048
|
+
return { reason: "changed since that turn; not overwritten", retry: true };
|
|
1049
|
+
}
|
|
1050
|
+
async function undoReportedTurn(record, workspace, result) {
|
|
1051
|
+
const kept = [];
|
|
1052
|
+
for (const [file, changes] of turnChanges([{ kind: "tool-done", diff: record.changes }])) {
|
|
1053
|
+
const target = path2.isAbsolute(file) ? file : path2.resolve(workspace, file);
|
|
1054
|
+
if (!inside(target, workspace)) {
|
|
1055
|
+
result.conflicts.push({ path: target, reason: OUTSIDE_WORKSPACE });
|
|
1056
|
+
continue;
|
|
1057
|
+
}
|
|
1058
|
+
const current = await fs.readFile(target, "utf8").catch(quiet("session/undo-turn"));
|
|
1059
|
+
const unwound = unwindChanges(current, changes);
|
|
1060
|
+
if (!unwound.whole) {
|
|
1061
|
+
const why = conflictReason(current, changes);
|
|
1062
|
+
result.conflicts.push({ path: target, reason: why.reason });
|
|
1063
|
+
if (why.retry) kept.push(...changes);
|
|
1064
|
+
continue;
|
|
1065
|
+
}
|
|
1066
|
+
try {
|
|
1067
|
+
if (unwound.created) {
|
|
1068
|
+
await fs.rm(target, { force: true });
|
|
1069
|
+
result.removed.push(target);
|
|
1070
|
+
} else {
|
|
1071
|
+
await fs.writeFile(target, unwound.before);
|
|
1072
|
+
result.restored.push(target);
|
|
1073
|
+
}
|
|
1074
|
+
} catch (error) {
|
|
1075
|
+
result.conflicts.push({ path: target, reason: error instanceof Error ? error.message : String(error) });
|
|
1076
|
+
kept.push(...changes);
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
return kept;
|
|
1080
|
+
}
|
|
1081
|
+
async function turnIsRunning(sessionId) {
|
|
1082
|
+
const holder = await conversationHolder(sessionId).catch(quiet("session/undo-turn"));
|
|
1083
|
+
if (!holder) return false;
|
|
1084
|
+
if (holder.kind === "turn") return true;
|
|
1085
|
+
return Boolean(await readStoredPendingTurn(sessionId).catch(quiet("session/undo-turn")));
|
|
1086
|
+
}
|
|
1087
|
+
async function undoLastTurn(session, options) {
|
|
1088
|
+
const workspace = session.workspace ?? process.cwd();
|
|
1089
|
+
const result = { restored: [], removed: [], conflicts: [] };
|
|
1090
|
+
if (await (options.turnIsRunning ?? turnIsRunning)(session.id)) {
|
|
1091
|
+
return { ...result, text: "Not undone: a turn is running in this conversation. Its edits are still being made -- wait for it to finish, or stop it first." };
|
|
1092
|
+
}
|
|
1093
|
+
return withTurnChangesLock(options.stateDir, session.id, async () => {
|
|
1094
|
+
const records = await readTurnChanges(options.stateDir, session.id);
|
|
1095
|
+
const last = records.at(-1);
|
|
1096
|
+
if (!last) {
|
|
1097
|
+
return { ...result, text: `Nothing to undo: no turn in this conversation has recorded file edits. ClikCode reverses the edits it saw a turn make through file-editing tools; edits made any other way (a shell command, a tool that reports no diff) are not seen -- use /diff and git for those.` };
|
|
1098
|
+
}
|
|
1099
|
+
const earlier = records.slice(0, -1);
|
|
1100
|
+
const name = turnName(last);
|
|
1101
|
+
let kept;
|
|
1102
|
+
let saw;
|
|
1103
|
+
const finished = last.store === "agent" ? await undoAgentTurn(options.stateDir, session.id, last, workspace, result) : void 0;
|
|
1104
|
+
if (finished !== void 0) {
|
|
1105
|
+
saw = true;
|
|
1106
|
+
if (finished === false) kept = last;
|
|
1107
|
+
} else {
|
|
1108
|
+
saw = last.changes.length > 0;
|
|
1109
|
+
const left = saw ? await undoReportedTurn(last, workspace, result) : [];
|
|
1110
|
+
if (left.length) kept = { ...last, changes: left };
|
|
1111
|
+
}
|
|
1112
|
+
await writeTurnChanges(options.stateDir, session.id, kept ? [...earlier, kept] : earlier);
|
|
1113
|
+
if (!saw) {
|
|
1114
|
+
const before = earlier.at(-1);
|
|
1115
|
+
const who = last.store === "agent" ? "ClikCode's agent" : options.who;
|
|
1116
|
+
return { ...result, text: [
|
|
1117
|
+
`Nothing undone: ${name} made no edits ClikCode saw.`,
|
|
1118
|
+
`${who}'s edits made any other way (a shell command, a tool that reports no diff) are not seen -- use /diff and git for those.`,
|
|
1119
|
+
...before ? [`The turn before it is ${turnName(before)}.`] : []
|
|
1120
|
+
].join("\n") };
|
|
1121
|
+
}
|
|
1122
|
+
return { ...result, text: describe(result, workspace, name) };
|
|
1123
|
+
});
|
|
1124
|
+
}
|
|
1125
|
+
async function undoTurnsBack(session, n, options) {
|
|
1126
|
+
if (n <= 1) return undoLastTurn(session, options);
|
|
1127
|
+
const total = { restored: [], removed: [], conflicts: [] };
|
|
1128
|
+
const texts = [];
|
|
1129
|
+
let undone = 0;
|
|
1130
|
+
let check = options.turnIsRunning;
|
|
1131
|
+
for (; undone < n; undone += 1) {
|
|
1132
|
+
const recorded = await readTurnChanges(options.stateDir, session.id);
|
|
1133
|
+
if (!recorded.length) break;
|
|
1134
|
+
const step = await undoLastTurn(session, { ...options, ...check ? { turnIsRunning: check } : {} });
|
|
1135
|
+
check = async () => false;
|
|
1136
|
+
if (step.text.startsWith("Not undone:")) return step;
|
|
1137
|
+
total.restored.push(...step.restored);
|
|
1138
|
+
total.removed.push(...step.removed);
|
|
1139
|
+
total.conflicts.push(...step.conflicts);
|
|
1140
|
+
texts.push(step.text.replace(`
|
|
1141
|
+
|
|
1142
|
+
${SHELL_CAVEAT}`, "").replace(/\nThe turn before it is .*$/, ""));
|
|
1143
|
+
if (step.conflicts.length) {
|
|
1144
|
+
undone += 1;
|
|
1145
|
+
break;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
if (!texts.length) return undoLastTurn(session, options);
|
|
1149
|
+
const stopped = total.conflicts.length && undone < n ? [`Stopped after ${undone} of ${n} turns: a file was left alone, so older turns were not undone.`] : [];
|
|
1150
|
+
const short = !total.conflicts.length && undone < n ? [`Only ${undone} turn${undone === 1 ? " was" : "s were"} recorded to undo.`] : [];
|
|
1151
|
+
return { ...total, text: [...texts, ...stopped, ...short, SHELL_CAVEAT].join("\n\n") };
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
// src/session/redo.ts
|
|
1155
|
+
async function redoFrom(state, session, n, options) {
|
|
1156
|
+
if (await (options.turnIsRunning ?? turnIsRunning)(session.id)) throw new Error("A turn is running in this conversation: stop it first, then /redo.");
|
|
1157
|
+
const messages = sessionTranscriptMessages(session);
|
|
1158
|
+
const users = userMessageIndexes(messages);
|
|
1159
|
+
if (!Number.isInteger(n) || n < 1 || n > users.length) {
|
|
1160
|
+
throw new Error(users.length ? `No prompt ${n}: this conversation has prompts 1 to ${users.length}.` : "This conversation has no prompts to redo yet.");
|
|
1161
|
+
}
|
|
1162
|
+
const at = users[n - 1];
|
|
1163
|
+
const prompt = messages[at].content;
|
|
1164
|
+
const turns = users.length - n + 1;
|
|
1165
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1166
|
+
state.sessions.push({
|
|
1167
|
+
...session,
|
|
1168
|
+
id: randomUUID(),
|
|
1169
|
+
name: session.name ? `${session.name} (before redo)` : void 0,
|
|
1170
|
+
conversationId: conversationIdFor(session),
|
|
1171
|
+
parentSessionId: session.id,
|
|
1172
|
+
fork: true,
|
|
1173
|
+
messages,
|
|
1174
|
+
pendingTurn: void 0,
|
|
1175
|
+
nativeSessionId: void 0,
|
|
1176
|
+
nativeStartedAt: void 0,
|
|
1177
|
+
nativeThreads: void 0,
|
|
1178
|
+
createdAt: now,
|
|
1179
|
+
updatedAt: now,
|
|
1180
|
+
status: "archived",
|
|
1181
|
+
closedAt: now
|
|
1182
|
+
});
|
|
1183
|
+
let files = "";
|
|
1184
|
+
if (options.keepFiles) {
|
|
1185
|
+
await withTurnChangesLock(options.stateDir, session.id, async () => {
|
|
1186
|
+
const records = await readTurnChanges(options.stateDir, session.id);
|
|
1187
|
+
await writeTurnChanges(options.stateDir, session.id, records.slice(0, Math.max(0, records.length - turns)));
|
|
1188
|
+
});
|
|
1189
|
+
} else {
|
|
1190
|
+
const undone = await undoTurnsBack(session, turns, { stateDir: options.stateDir, who: options.who, turnIsRunning: async () => false });
|
|
1191
|
+
if (undone.conflicts.length || undone.text.startsWith("Not undone:")) files = undone.text;
|
|
1192
|
+
}
|
|
1193
|
+
session.messages = messages.slice(0, at);
|
|
1194
|
+
session.pendingTurn = void 0;
|
|
1195
|
+
delete session.resumeAt;
|
|
1196
|
+
forgetNativeThread(session);
|
|
1197
|
+
delete session.nativeThreads;
|
|
1198
|
+
if (isClikCodeAgent(session)) {
|
|
1199
|
+
await new ConversationStore(options.stateDir, session.id).archive();
|
|
1200
|
+
delete session.agentThreadTurns;
|
|
1201
|
+
}
|
|
1202
|
+
session.updatedAt = now;
|
|
1203
|
+
return { prompt, text: files };
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
// src/tui/slash/handlers/shared.ts
|
|
1207
|
+
var INTERACTIVE_ONLY = (name) => async () => {
|
|
1208
|
+
throw new Error(`/${name} opens a picker and is only available in the interactive ClikCode session.`);
|
|
1209
|
+
};
|
|
1210
|
+
var sendSessionTurn = (id, prompt) => sendScriptedTurn(new Conf({ projectName: "clikcode", configFileMode: 384 }), id, prompt);
|
|
1211
|
+
async function saveSettings(state, session) {
|
|
1212
|
+
if (session.movedTo) throw new Error(`This chat moved to ${session.movedTo.machine}; change its settings there.`);
|
|
1213
|
+
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1214
|
+
await writeState(state);
|
|
1215
|
+
return emitHarnessOutput({ panel: "settings", session, account: state.accounts.find((item) => item.id === session.accountId)?.label });
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
// src/tui/slash/handlers/conversation.ts
|
|
1219
|
+
function lastAnswer(session) {
|
|
1220
|
+
const last = textTranscript(sessionTranscriptMessages(session)).reverse().find((message) => message.role === "assistant");
|
|
1221
|
+
if (!last) throw new Error("There is no assistant response to copy yet.");
|
|
1222
|
+
return last.content;
|
|
1223
|
+
}
|
|
1224
|
+
var conversationHandlers = {
|
|
1225
|
+
help: async ({ session }) => {
|
|
1226
|
+
const harness = sessionHarness(session);
|
|
1227
|
+
const extras = slashExtrasFor(session, harness);
|
|
1228
|
+
return emitHarnessOutput({ panel: "help", helpText: `${slashHelpText(session, harness, extras)}
|
|
1229
|
+
|
|
1230
|
+
${terminalKeysHelp()}`, controls: slashControls() });
|
|
1231
|
+
},
|
|
1232
|
+
status: async ({ state, session }) => {
|
|
1233
|
+
const account = session.accountId ? state.accounts.find((item) => item.id === session.accountId)?.label : void 0;
|
|
1234
|
+
return emitHarnessOutput({ panel: "status", session, account, text: stripVTControlCharacters(renderSessionCard(session, account)) });
|
|
1235
|
+
},
|
|
1236
|
+
new: async ({ state, session, args }) => {
|
|
1237
|
+
const id = await newConversation(session.id, { sameModel: true, lastSeen: session });
|
|
1238
|
+
if (args) await sendSessionTurn(id, args);
|
|
1239
|
+
else {
|
|
1240
|
+
const created = (await readState({ transcripts: [] })).sessions.find((item) => item.id === id);
|
|
1241
|
+
if (created) emitHarnessOutput({ panel: "conversation-reset", session: created });
|
|
1242
|
+
}
|
|
1243
|
+
return id;
|
|
1244
|
+
},
|
|
1245
|
+
history: async ({ session }) => emitHarnessOutput({ panel: "history", messages: textTranscript(sessionTranscriptMessages(session)) }),
|
|
1246
|
+
hindsight: async ({ session }) => {
|
|
1247
|
+
const records = await readTurnChanges(stateDirectory(), session.id);
|
|
1248
|
+
const originFallback = runsOn({ provider: session.provider ?? null, model: session.model ?? null, ...session.nativeHarness ? { harness: session.nativeHarness } : {} });
|
|
1249
|
+
return emitHarnessOutput({ panel: "hindsight", text: hindsightPanelText(sessionTranscriptMessages(session), records, { originFallback }) });
|
|
1250
|
+
},
|
|
1251
|
+
copy: async ({ session }) => {
|
|
1252
|
+
const via = await copyToClipboard(lastAnswer(session));
|
|
1253
|
+
return emitHarnessOutput({ panel: "copied", text: via === "osc52" ? "Last response sent to your terminal clipboard (OSC 52)." : "Last response copied to the clipboard." });
|
|
1254
|
+
},
|
|
1255
|
+
select: async ({ words }) => {
|
|
1256
|
+
const asked = words.join(" ").trim().toLowerCase();
|
|
1257
|
+
const active = asked === "on" ? true : asked === "off" ? false : !SELECTION_MODE.active;
|
|
1258
|
+
if (!TERMINAL.active) {
|
|
1259
|
+
throw new Error("Selection mode needs the interactive terminal; there is no mouse to release here.");
|
|
1260
|
+
}
|
|
1261
|
+
return emitHarnessOutput({ panel: "select", text: setSelectionMode(active) });
|
|
1262
|
+
},
|
|
1263
|
+
mention: async ({ state, session, words }) => {
|
|
1264
|
+
const action = words.join(" ").trim();
|
|
1265
|
+
if (!action) return emitHarnessOutput({ panel: "attachments", attachments: session.attachments ?? [] });
|
|
1266
|
+
if (action === "clear") {
|
|
1267
|
+
session.attachments = [];
|
|
1268
|
+
} else {
|
|
1269
|
+
const unquoted = decodeAttachmentPath(action);
|
|
1270
|
+
const workspace = session.workspace ?? process.cwd();
|
|
1271
|
+
const expanded = expandHomePath(unquoted);
|
|
1272
|
+
const path3 = isAbsolute2(expanded) ? resolve2(expanded) : resolve2(workspace, expanded);
|
|
1273
|
+
await queueAttachment(session, path3);
|
|
1274
|
+
}
|
|
1275
|
+
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1276
|
+
await writeState(state);
|
|
1277
|
+
return emitHarnessOutput({ panel: "attachments", attachments: session.attachments ?? [], changed: true });
|
|
1278
|
+
},
|
|
1279
|
+
search: async ({ args }) => {
|
|
1280
|
+
if (!args.trim()) throw new Error("usage: /search <words>");
|
|
1281
|
+
const result = await searchConversations(args);
|
|
1282
|
+
if (!result) throw new Error("usage: /search <words>");
|
|
1283
|
+
return emitHarnessOutput(searchResultsPayload(result));
|
|
1284
|
+
},
|
|
1285
|
+
diff: async ({ session }) => {
|
|
1286
|
+
const diff = await workspaceDiff(session.workspace ?? process.cwd());
|
|
1287
|
+
return emitHarnessOutput(diff === void 0 ? { panel: "diff", text: "Not a git repository" } : { panel: "diff", diff });
|
|
1288
|
+
},
|
|
1289
|
+
review: async ({ id, session, head, words }) => {
|
|
1290
|
+
const focus = words.join(" ").trim();
|
|
1291
|
+
if (!isClikCodeAgent(session)) return sendSessionTurn(id, `/${head}${head === "review" && focus ? ` ${focus}` : ""}`);
|
|
1292
|
+
return sendSessionTurn(id, head === "review" ? reviewPrompt(focus) : initPrompt(session));
|
|
1293
|
+
},
|
|
1294
|
+
rename: async ({ state, session, words }) => {
|
|
1295
|
+
const name = words.join(" ").trim();
|
|
1296
|
+
if (!name) throw new Error("Enter a name after /rename.");
|
|
1297
|
+
session.name = name.slice(0, 120);
|
|
1298
|
+
session.nameSource = "user";
|
|
1299
|
+
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1300
|
+
await writeState(state);
|
|
1301
|
+
return emitHarnessOutput({ panel: "session-renamed", text: `Conversation renamed to \u201C${session.name}\u201D.` });
|
|
1302
|
+
},
|
|
1303
|
+
archive: async ({ state, session }) => {
|
|
1304
|
+
session.status = "archived";
|
|
1305
|
+
session.closedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1306
|
+
session.updatedAt = session.closedAt;
|
|
1307
|
+
await writeState(state);
|
|
1308
|
+
return emitHarnessOutput({ panel: "session-archived", text: "Conversation archived." });
|
|
1309
|
+
},
|
|
1310
|
+
delete: async ({ id, state, words }) => {
|
|
1311
|
+
if (words[0]?.toLowerCase() !== "confirm") throw new Error("Use /delete confirm to permanently delete this ClikCode conversation. Provider-owned history is not deleted.");
|
|
1312
|
+
deleteConversations(state, [id]);
|
|
1313
|
+
await writeState(state);
|
|
1314
|
+
return emitHarnessOutput({ panel: "session-deleted", text: "Conversation deleted from ClikCode." });
|
|
1315
|
+
},
|
|
1316
|
+
fork: async ({ state, session, words }) => {
|
|
1317
|
+
const at = forkPoint(words[0]);
|
|
1318
|
+
if (at !== void 0) words.shift();
|
|
1319
|
+
const messages = sessionTranscriptMessages(session);
|
|
1320
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1321
|
+
const fork = {
|
|
1322
|
+
...session,
|
|
1323
|
+
id: randomUUID2(),
|
|
1324
|
+
name: words.join(" ").trim() || (session.name ? `${session.name} (fork)` : void 0),
|
|
1325
|
+
conversationId: conversationIdFor(session),
|
|
1326
|
+
parentSessionId: session.id,
|
|
1327
|
+
fork: true,
|
|
1328
|
+
messages: at === void 0 ? messages : messagesThrough(messages, at),
|
|
1329
|
+
pendingTurn: void 0,
|
|
1330
|
+
// No vendor thread: the next turn replays the kept messages to rebuild
|
|
1331
|
+
// the context, so a fork at N does not carry what came after it.
|
|
1332
|
+
nativeSessionId: void 0,
|
|
1333
|
+
nativeStartedAt: void 0,
|
|
1334
|
+
createdAt: now,
|
|
1335
|
+
updatedAt: now,
|
|
1336
|
+
status: "active",
|
|
1337
|
+
closedAt: void 0
|
|
1338
|
+
};
|
|
1339
|
+
delete fork.resumeAt;
|
|
1340
|
+
state.sessions.push(fork);
|
|
1341
|
+
await writeState(state);
|
|
1342
|
+
const text = at === void 0 ? `Forked as ${fork.id.slice(0, 8)} -- you are in the fork; the original is still in your conversations.` : `Forked after message ${at} as ${fork.id.slice(0, 8)} -- you are in the fork; the original is still in your conversations. Files on disk are not rewound: /changes lists what each turn edited, /redo puts it back.`;
|
|
1343
|
+
emitHarnessOutput({ panel: "session-forked", text, session: fork });
|
|
1344
|
+
return fork.id;
|
|
1345
|
+
},
|
|
1346
|
+
sessions: async ({ state, words }) => {
|
|
1347
|
+
const action = words.shift()?.toLowerCase();
|
|
1348
|
+
const targetId = words.shift();
|
|
1349
|
+
if (action === "close") {
|
|
1350
|
+
if (!targetId) throw new Error("usage: /sessions close <id>");
|
|
1351
|
+
return aiSessionClose(targetId);
|
|
1352
|
+
}
|
|
1353
|
+
if (action === "show" || action === "open" || action === "resume") {
|
|
1354
|
+
if (!targetId) throw new Error(`usage: /sessions ${action} <id>`);
|
|
1355
|
+
const target = (await readState({ transcripts: [targetId] })).sessions.find((item) => item.id === targetId);
|
|
1356
|
+
if (!target) throw new Error(`AI session "${targetId}" was not found`);
|
|
1357
|
+
return emitHarnessOutput({ panel: "session", session: target, next: `${harnessCommand()} sessions open ${target.id}` });
|
|
1358
|
+
}
|
|
1359
|
+
if (action && action !== "list" && action !== "ls") throw new Error("usage: /sessions [list|show <id>|open <id>|close <id>]");
|
|
1360
|
+
return emitHarnessOutput({
|
|
1361
|
+
panel: "sessions",
|
|
1362
|
+
sessions: state.sessions.map((item) => ({
|
|
1363
|
+
id: item.id,
|
|
1364
|
+
status: item.status,
|
|
1365
|
+
harness: item.nativeHarness,
|
|
1366
|
+
nativeSessionId: item.nativeSessionId,
|
|
1367
|
+
provider: item.provider,
|
|
1368
|
+
model: item.model,
|
|
1369
|
+
workspace: item.workspace,
|
|
1370
|
+
updatedAt: item.updatedAt
|
|
1371
|
+
})),
|
|
1372
|
+
controls: ["sessions list", "sessions open <id>", "sessions close <id>"]
|
|
1373
|
+
});
|
|
1374
|
+
},
|
|
1375
|
+
usage: async ({ state, session, words }) => {
|
|
1376
|
+
if (words[0]?.toLowerCase() === "all") {
|
|
1377
|
+
const report2 = usageReportAll(state, session, { providerName: (provider) => localHarnessForProvider(provider)?.displayName ?? provider });
|
|
1378
|
+
return emitHarnessOutput({ panel: "usage", text: report2.text });
|
|
1379
|
+
}
|
|
1380
|
+
const harness = sessionHarness(session);
|
|
1381
|
+
const report = usageReport(state, session, {
|
|
1382
|
+
...harness ? { providerName: harness.displayName, providerId: harness.provider } : {}
|
|
1383
|
+
});
|
|
1384
|
+
return emitHarnessOutput({ panel: "usage", text: report.text, totals: report.totals });
|
|
1385
|
+
},
|
|
1386
|
+
export: async ({ session, words }) => {
|
|
1387
|
+
const force = words.includes("--force");
|
|
1388
|
+
const path3 = await exportTranscript(session, words.filter((word) => word !== "--force").join(" "), async () => force);
|
|
1389
|
+
return emitHarnessOutput({ panel: "exported", text: `Transcript written to ${compactPath(path3)}.`, path: path3 });
|
|
1390
|
+
},
|
|
1391
|
+
cwd: async ({ state, session, args }) => {
|
|
1392
|
+
if (!args) return emitHarnessOutput({ panel: "cwd", text: compactPath(session.workspace ?? process.cwd()), workspace: session.workspace ?? process.cwd() });
|
|
1393
|
+
const notice = await changeSessionWorkspace(state, session, args);
|
|
1394
|
+
return emitHarnessOutput({ panel: "cwd", text: notice, workspace: session.workspace, changed: true });
|
|
1395
|
+
},
|
|
1396
|
+
"add-dir": async ({ state, session, args }) => emitHarnessOutput({ panel: "add-dir", text: await addSessionDirectory(state, session, args) }),
|
|
1397
|
+
memory: async ({ session, words }) => {
|
|
1398
|
+
if (words[0]?.toLowerCase() === "edit") throw new Error("/memory edit opens $EDITOR and is only available in the interactive ClikCode session.");
|
|
1399
|
+
const memory = await readMemoryFile(session);
|
|
1400
|
+
return emitHarnessOutput({ panel: "memory", text: `${compactPath(memory.path)}
|
|
1401
|
+
|
|
1402
|
+
${memory.content ?? "(not created yet \u2014 /init writes it)"}`, path: memory.path, exists: memory.content !== void 0 });
|
|
1403
|
+
},
|
|
1404
|
+
changes: async ({ state, session, args, words }) => {
|
|
1405
|
+
if (isChangesPath(args)) {
|
|
1406
|
+
const file = changesPath(args, session.workspace ?? process.cwd());
|
|
1407
|
+
const rows = await fileTurnRows(state, file);
|
|
1408
|
+
return emitHarnessOutput({
|
|
1409
|
+
panel: "changes",
|
|
1410
|
+
text: fileTurnsText(file, rows),
|
|
1411
|
+
file,
|
|
1412
|
+
turns: rows.map((row) => ({ sessionId: row.sessionId, turn: row.turnsAgo, at: row.record.at, prompt: row.record.prompt, additions: row.additions, removals: row.removals }))
|
|
1413
|
+
});
|
|
1414
|
+
}
|
|
1415
|
+
const records = await readTurnChanges(stateDirectory(), session.id);
|
|
1416
|
+
if (!words[0]) return emitHarnessOutput({ panel: "changes", text: turnChangesList(records, session.workspace) });
|
|
1417
|
+
const n = Number(words[0]);
|
|
1418
|
+
const record = turnChangesAgo(records, n);
|
|
1419
|
+
if (!record) throw new Error(records.length ? `usage: /changes [N|path] -- N from 1 (the last turn) to ${records.length}` : "No turns recorded yet in this conversation.");
|
|
1420
|
+
return emitHarnessOutput({ panel: "changes", text: turnChangesDiff(record, n, session.workspace), diff: record.changes });
|
|
1421
|
+
},
|
|
1422
|
+
redo: async ({ state, session, words }) => {
|
|
1423
|
+
const n = forkPoint(words[0]);
|
|
1424
|
+
if (n === void 0) throw new Error("usage: /redo @N [keep] -- N as /fork numbers your prompts; keep leaves files as they are");
|
|
1425
|
+
const who = isClikCodeAgent(session) ? GATEWAY_LABEL : sessionHarness(session)?.displayName ?? "This provider";
|
|
1426
|
+
const redone = await redoFrom(state, session, n, { keepFiles: words[1] === "keep", stateDir: stateDirectory(), who });
|
|
1427
|
+
await writeState(state);
|
|
1428
|
+
return emitHarnessOutput({ panel: redone.text ? "redo" : "redo-done", text: redone.text, prompt: redone.prompt });
|
|
1429
|
+
},
|
|
1430
|
+
compact: async ({ id, session, args }) => {
|
|
1431
|
+
const said = await compactConversation(id, session, args, sendSessionTurn);
|
|
1432
|
+
if (said) emitHarnessOutput({ panel: "compact", text: said });
|
|
1433
|
+
},
|
|
1434
|
+
context: async ({ session }) => emitHarnessOutput({ panel: "context", text: contextUsageText(session), usage: session.lastUsage ?? null }),
|
|
1435
|
+
capabilities: async ({ session }) => emitHarnessOutput({ panel: "capabilities", text: capabilitiesText(session) }),
|
|
1436
|
+
redraw: async () => emitHarnessOutput({ panel: "redraw", text: "Nothing to repaint outside the interactive session." }),
|
|
1437
|
+
restart: async () => emitHarnessOutput({ panel: "restart", text: "There is no window to restart outside the interactive session." }),
|
|
1438
|
+
exit: async ({ id }) => aiSessionLeave(id)
|
|
1439
|
+
};
|
|
1440
|
+
|
|
1441
|
+
// src/tui/slash/model-choices.ts
|
|
1442
|
+
function modelChoicesFor(session, accounts) {
|
|
1443
|
+
const scoped = session.accountId ? accounts.filter((account) => account.id === session.accountId) : accounts.filter((account) => Boolean(session.provider) && account.provider === session.provider);
|
|
1444
|
+
return scoped.flatMap((account) => account.models.map((model) => ({
|
|
1445
|
+
account: account.label,
|
|
1446
|
+
provider: account.provider,
|
|
1447
|
+
model
|
|
1448
|
+
})));
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
// src/tui/slash/handlers/model.ts
|
|
1452
|
+
function isLocalModelName(value) {
|
|
1453
|
+
try {
|
|
1454
|
+
return Boolean(catalogModel(resolveLocalModelId(value)));
|
|
1455
|
+
} catch {
|
|
1456
|
+
return false;
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
var placeOf = (session) => `${session.route}|${session.model ?? ""}|${session.nativeHarness ?? ""}`;
|
|
1460
|
+
async function switchWhenDownloaded(session, model, label, bytes) {
|
|
1461
|
+
const sessionId = session.id;
|
|
1462
|
+
const before = placeOf(session);
|
|
1463
|
+
const job = startModelDownload(model);
|
|
1464
|
+
job.ask(sessionId);
|
|
1465
|
+
const outcome = (level, switched, text) => reportDownloadOutcome({ sessionId, modelId: model, switched, level, text });
|
|
1466
|
+
job.done.then(async () => {
|
|
1467
|
+
const state = await readState({ transcripts: [sessionId] });
|
|
1468
|
+
const current = state.sessions.find((item) => item.id === sessionId);
|
|
1469
|
+
if (!current) return;
|
|
1470
|
+
const name = current.name ? `"${current.name}"` : "This chat";
|
|
1471
|
+
if (placeOf(current) !== before) {
|
|
1472
|
+
outcome("info", false, `${label} is downloaded. ${name} was changed while it downloaded, so it was left as it is: /model ${model} moves it.`);
|
|
1473
|
+
return;
|
|
1474
|
+
}
|
|
1475
|
+
if (current.route !== "clikcode-local") await putOnAgentRoute(sessionId, "clikcode-local");
|
|
1476
|
+
const moved = await readState({ transcripts: [sessionId] });
|
|
1477
|
+
const chat = moved.sessions.find((item) => item.id === sessionId);
|
|
1478
|
+
if (!chat) return;
|
|
1479
|
+
chat.model = model;
|
|
1480
|
+
if (chat.reported?.model) delete chat.reported.model;
|
|
1481
|
+
chat.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1482
|
+
await writeState(moved);
|
|
1483
|
+
outcome("info", true, `${label} is downloaded: ${name} runs on it now.`);
|
|
1484
|
+
}).catch((error) => {
|
|
1485
|
+
outcome("error", false, `The download of ${label} failed: ${error instanceof Error ? error.message : String(error)} It resumes from where it stopped when you ask again; this chat is as it was.`);
|
|
1486
|
+
});
|
|
1487
|
+
outcome("info", false, `Downloading ${label} (${formatBytes(bytes)}) in the background. This chat moves to it when it is ready: carry on meanwhile.`);
|
|
1488
|
+
}
|
|
1489
|
+
async function localModelCommand(session, value) {
|
|
1490
|
+
if (!value) {
|
|
1491
|
+
const choices = await localModelChoices();
|
|
1492
|
+
return emitHarnessOutput({
|
|
1493
|
+
panel: "models",
|
|
1494
|
+
models: choices.map((choice) => ({
|
|
1495
|
+
model: choice.id,
|
|
1496
|
+
provider: [choice.label, choice.recommended ? "recommended" : void 0, choice.detail].filter(Boolean).join(" \xB7 "),
|
|
1497
|
+
label: choice.label,
|
|
1498
|
+
detail: choice.detail,
|
|
1499
|
+
fits: choice.fits,
|
|
1500
|
+
recommended: choice.recommended
|
|
1501
|
+
})),
|
|
1502
|
+
selected: session.model
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
const explicitDownload = value.startsWith("--download ");
|
|
1506
|
+
const model = resolveLocalModelId(explicitDownload ? value.slice("--download ".length) : value);
|
|
1507
|
+
const entry2 = catalogModel(model);
|
|
1508
|
+
const bytes = await missingBytes(weightFiles(entry2));
|
|
1509
|
+
if (bytes && !explicitDownload) {
|
|
1510
|
+
if (!TERMINAL.active?.select) {
|
|
1511
|
+
throw new Error(`${entry2.label} needs a ${formatBytes(bytes)} download. Run /model --download ${model} to authorize it.`);
|
|
1512
|
+
}
|
|
1513
|
+
const confirmed = await TERMINAL.active.select(`Download ${entry2.label} (${formatBytes(bytes)})?`, [
|
|
1514
|
+
{ label: "Cancel", value: false },
|
|
1515
|
+
{ label: `Download ${formatBytes(bytes)}`, value: true }
|
|
1516
|
+
]);
|
|
1517
|
+
if (!confirmed) return;
|
|
1518
|
+
}
|
|
1519
|
+
if (bytes && backgroundDownloadsAllowed()) return switchWhenDownloaded(session, model, entry2.label, bytes);
|
|
1520
|
+
if (session.route !== "clikcode-local") await putOnAgentRoute(session.id, "clikcode-local");
|
|
1521
|
+
await localModelChosen(session.id, model);
|
|
1522
|
+
const state = await readState({ transcripts: [session.id] });
|
|
1523
|
+
const current = state.sessions.find((item) => item.id === session.id);
|
|
1524
|
+
if (!current) throw new Error(`AI session "${session.id}" was not found`);
|
|
1525
|
+
current.model = model;
|
|
1526
|
+
if (current.reported?.model) delete current.reported.model;
|
|
1527
|
+
return saveSettings(state, current);
|
|
1528
|
+
}
|
|
1529
|
+
async function keepEffortValidFor(session, harness, account) {
|
|
1530
|
+
if (!session.effort || !harnessSupportsEffort(harness)) return;
|
|
1531
|
+
const choices = await effortChoicesFor(harness, account, session.model);
|
|
1532
|
+
if (!choices.values.length || choices.values.includes(session.effort)) return;
|
|
1533
|
+
session.effort = choices.default ?? "";
|
|
1534
|
+
}
|
|
1535
|
+
var modelHandlers = {
|
|
1536
|
+
model: async ({ state, session, words }) => {
|
|
1537
|
+
let trusted = words[0] === "--any";
|
|
1538
|
+
if (trusted) words.shift();
|
|
1539
|
+
const sourceAt = words.indexOf("--source");
|
|
1540
|
+
const sourceWord = sourceAt >= 0 ? words[sourceAt + 1] : void 0;
|
|
1541
|
+
if (sourceAt >= 0) words.splice(sourceAt, 2);
|
|
1542
|
+
let value = words.join(" ").trim();
|
|
1543
|
+
if (value.startsWith("--download ")) return localModelCommand(session, value);
|
|
1544
|
+
if (session.route === "clikcode-local") {
|
|
1545
|
+
if (!value || isLocalModelName(value)) return localModelCommand(session, value);
|
|
1546
|
+
value = (trusted && !isAutomaticModelWord(value) ? value : await chooseGatewayModel(value)) ?? value;
|
|
1547
|
+
trusted = true;
|
|
1548
|
+
await releaseHeldLocalModel(session.id);
|
|
1549
|
+
applyClikCodeAgentSessionPolicy(session, "gateway", state);
|
|
1550
|
+
}
|
|
1551
|
+
if (isGatewayService(session)) {
|
|
1552
|
+
if (!value) {
|
|
1553
|
+
const { models } = await gatewayModels();
|
|
1554
|
+
return emitHarnessOutput({
|
|
1555
|
+
panel: "models",
|
|
1556
|
+
// The model and its price only: which provider serves it is the Gateway's decision.
|
|
1557
|
+
models: models.map((model2) => ({ model: model2.id, label: gatewayModelLabel(model2), price: gatewayModelDetail(model2) })),
|
|
1558
|
+
selected: session.model ?? "Automatic"
|
|
1559
|
+
});
|
|
1560
|
+
}
|
|
1561
|
+
const selectedModel = trusted && !isAutomaticModelWord(value) ? value : await chooseGatewayModel(value);
|
|
1562
|
+
const modelList = await gatewayModels().catch(() => ({ models: [] }));
|
|
1563
|
+
const chosen = selectedModel ? gatewayModelForWord(modelList.models, selectedModel) : void 0;
|
|
1564
|
+
if (chosen?.tags?.includes("uncensored")) {
|
|
1565
|
+
const consent = await gatewayUncensoredConsent().catch(() => null);
|
|
1566
|
+
if (!consent?.accepted) {
|
|
1567
|
+
emitHarnessOutput({ panel: "error", message: "This model requires the uncensored-model agreement. Run `clikcode gateway agreement` to read it, then `clikcode gateway agreement --accept-version <version>` to accept the version you reviewed, or use the /model picker." });
|
|
1568
|
+
return;
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
if (sourceWord && sourceWord !== "auto") {
|
|
1572
|
+
if (!chosen?.sources?.some((item) => item.id === sourceWord)) {
|
|
1573
|
+
const offered = chosen?.sources?.map((item) => item.id).join(", ");
|
|
1574
|
+
throw new Error(offered ? `"${sourceWord}" is not a funded source of ${chosen?.id}. Sources: ${offered}.` : `Choosing a source is not available on this account: the Gateway routes ${chosen?.id ?? "the model"}.`);
|
|
1575
|
+
}
|
|
1576
|
+
session.source = sourceWord;
|
|
1577
|
+
} else delete session.source;
|
|
1578
|
+
session.model = selectedModel;
|
|
1579
|
+
if (session.reported?.model) delete session.reported.model;
|
|
1580
|
+
await saveSettings(state, session);
|
|
1581
|
+
if (chosen?.own && chosen.own.state !== "running") {
|
|
1582
|
+
const state2 = await wakeOwnModel(chosen.id).catch(quiet("tui/slash/handlers/model"));
|
|
1583
|
+
if (state2 === "starting") {
|
|
1584
|
+
return emitHarnessOutput({ panel: "settings-updated", text: `Starting ${chosen.id} on its GPU. Type away: your message waits and goes the moment it is ready.` });
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
return;
|
|
1588
|
+
}
|
|
1589
|
+
const harness = session.nativeHarness ? localHarnessForCommand(session.nativeHarness) : void 0;
|
|
1590
|
+
if (!value) {
|
|
1591
|
+
const account2 = state.accounts.find((item) => item.id === session.accountId);
|
|
1592
|
+
const catalog = harness ? await nativeModelCatalogForPicker(harness, account2) : void 0;
|
|
1593
|
+
return emitHarnessOutput({
|
|
1594
|
+
panel: "models",
|
|
1595
|
+
models: catalog && harness ? catalog.models.map((model2) => ({ account: account2?.label ?? "automatic", provider: harness.provider, model: model2, label: harnessModelLabel(harness, model2) })) : modelChoicesFor({ ...session, provider: harness?.provider ?? session.provider }, state.accounts),
|
|
1596
|
+
selected: session.model
|
|
1597
|
+
});
|
|
1598
|
+
}
|
|
1599
|
+
if (!harness || !harnessSupportsModelSelection(harness)) throw new Error(`${harness?.displayName ?? "This provider"} does not publish a model selector.`);
|
|
1600
|
+
const account = state.accounts.find((item) => item.id === session.accountId);
|
|
1601
|
+
const typed = normalizeModelWord(harness ? modelIdFromDisplay(harness, value) : value);
|
|
1602
|
+
const requested = typed && !trusted ? await assertRealModel(harness, account, typed) : typed;
|
|
1603
|
+
const model = requested ?? await resolveNativeModel(harness, account) ?? null;
|
|
1604
|
+
if (!model) throw new Error(`${harness.displayName} does not publish any models to choose from.`);
|
|
1605
|
+
session.model = model;
|
|
1606
|
+
if (session.reported?.model) delete session.reported.model;
|
|
1607
|
+
await keepEffortValidFor(session, harness, account);
|
|
1608
|
+
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1609
|
+
await writeState(state);
|
|
1610
|
+
return emitHarnessOutput({ panel: "settings", session, account: state.accounts.find((item) => item.id === session.accountId)?.label });
|
|
1611
|
+
},
|
|
1612
|
+
effort: async ({ state, session, words }) => {
|
|
1613
|
+
const value = words.join(" ").trim().toLowerCase();
|
|
1614
|
+
if (isGatewayService(session)) {
|
|
1615
|
+
if (value !== "default" && !GATEWAY_EFFORTS.includes(value)) {
|
|
1616
|
+
throw new Error(`usage: /effort <${["default", ...GATEWAY_EFFORTS].join("|")}>`);
|
|
1617
|
+
}
|
|
1618
|
+
session.effort = value === "default" ? GATEWAY_DEFAULT_EFFORT : value;
|
|
1619
|
+
return saveSettings(state, session);
|
|
1620
|
+
}
|
|
1621
|
+
const harness = session.nativeHarness ? localHarnessForCommand(session.nativeHarness) : void 0;
|
|
1622
|
+
if (!harness) throw new Error("Choose a provider before setting effort.");
|
|
1623
|
+
const account = state.accounts.find((item) => item.id === session.accountId);
|
|
1624
|
+
if (value === "default") session.effort = "";
|
|
1625
|
+
else setSessionHarnessOption(session, harness, "effort", value, (await effortChoicesFor(harness, account, session.model)).values);
|
|
1626
|
+
return saveSettings(state, session);
|
|
1627
|
+
},
|
|
1628
|
+
fast: async ({ state, session, words }) => {
|
|
1629
|
+
if (!isGatewayService(session)) throw new Error("Speed is a ClikDeploy Gateway choice: it picks among the providers of one model.");
|
|
1630
|
+
const value = words.join(" ").trim().toLowerCase();
|
|
1631
|
+
const on = value === "" ? session.speed !== "fast" : value === "on" ? true : value === "off" ? false : void 0;
|
|
1632
|
+
if (on === void 0) throw new Error("usage: /fast [on|off]");
|
|
1633
|
+
if (on) session.speed = "fast";
|
|
1634
|
+
else delete session.speed;
|
|
1635
|
+
return saveSettings(state, session);
|
|
1636
|
+
}
|
|
1637
|
+
};
|
|
1638
|
+
|
|
1639
|
+
// src/tui/slash/handlers/settings.ts
|
|
1640
|
+
import { hostname } from "node:os";
|
|
1641
|
+
|
|
1642
|
+
// src/commands/ai/settings.ts
|
|
1643
|
+
async function aiSettingsSetGlobal(key, value, emit = true) {
|
|
1644
|
+
const state = await readState({ transcripts: [] });
|
|
1645
|
+
applyDefaultSetting(state.globalSettings, key, value);
|
|
1646
|
+
await writeState(state);
|
|
1647
|
+
if (emit) emitResult({ globalSettings: state.globalSettings });
|
|
1648
|
+
}
|
|
1649
|
+
async function aiSettingsSetProvider(providerOrHarness, key, value, emit = true) {
|
|
1650
|
+
const state = await readState({ transcripts: [] });
|
|
1651
|
+
const harness = localHarnessForCommand(providerOrHarness) ?? localHarnessForProvider(providerOrHarness);
|
|
1652
|
+
if (!harness) throw new Error(`unknown provider "${providerOrHarness}"`);
|
|
1653
|
+
const entry2 = { model: void 0, ...state.providerSettings[harness.provider] };
|
|
1654
|
+
applyDefaultSetting(entry2, key, value, harness);
|
|
1655
|
+
if (key.toLowerCase() === "model" && entry2.model) await assertRealModel(harness, void 0, entry2.model);
|
|
1656
|
+
state.providerSettings[harness.provider] = entry2;
|
|
1657
|
+
await writeState(state);
|
|
1658
|
+
if (emit) emitResult({ provider: harness.provider, settings: entry2 });
|
|
1659
|
+
}
|
|
1660
|
+
async function aiSettingsClearProvider(providerOrHarness, emit = true) {
|
|
1661
|
+
const state = await readState({ transcripts: [] });
|
|
1662
|
+
const harness = localHarnessForCommand(providerOrHarness) ?? localHarnessForProvider(providerOrHarness);
|
|
1663
|
+
if (!harness) throw new Error(`unknown provider "${providerOrHarness}"`);
|
|
1664
|
+
delete state.providerSettings[harness.provider];
|
|
1665
|
+
await writeState(state);
|
|
1666
|
+
if (emit) emitResult({ provider: harness.provider, settings: {} });
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1669
|
+
// src/tui/slash/handlers/settings.ts
|
|
1670
|
+
var settingsHandlers = {
|
|
1671
|
+
permissions: async ({ state, session, words }) => {
|
|
1672
|
+
const value = words.shift()?.toLowerCase();
|
|
1673
|
+
const agent = isClikCodeAgent(session);
|
|
1674
|
+
const harness = !agent && session.nativeHarness ? localHarnessForCommand(session.nativeHarness) : void 0;
|
|
1675
|
+
if (!agent && !harness) throw new Error("Choose a provider before setting permissions.");
|
|
1676
|
+
const controls = sessionPermissionModes(session, harness);
|
|
1677
|
+
if (!value) {
|
|
1678
|
+
if (!controls.length) throw new Error(`${harness.displayName} does not map ClikCode's permission modes to a real flag.`);
|
|
1679
|
+
return emitHarnessOutput({ panel: "permissions", session, controls });
|
|
1680
|
+
}
|
|
1681
|
+
if (value === "bypass" && harness?.bypassRefusedAsRoot && !controls.includes("bypass")) {
|
|
1682
|
+
throw new Error(`Bypass is not available for ${harness.displayName} running as root on ${hostname()}. Use ask or auto.`);
|
|
1683
|
+
}
|
|
1684
|
+
if (agent) {
|
|
1685
|
+
if (!controls.includes(value)) throw new Error("permissions must be ask, bypass, or auto");
|
|
1686
|
+
session.permissionMode = value;
|
|
1687
|
+
} else setSessionHarnessOption(session, harness, "permissions", value);
|
|
1688
|
+
if (session.reported?.permissionMode) delete session.reported.permissionMode;
|
|
1689
|
+
return saveSettings(state, session);
|
|
1690
|
+
},
|
|
1691
|
+
sandbox: async ({ state, session, words }) => {
|
|
1692
|
+
if (!isClikCodeAgent(session)) throw new Error("The sandbox applies to ClikCode's own agent; a vendor harness sandboxes its own commands.");
|
|
1693
|
+
if (!words[0]) {
|
|
1694
|
+
const current = sessionSandboxMode(session.sandbox);
|
|
1695
|
+
return emitHarnessOutput({ panel: "sandbox", sandbox: current, text: sandboxModeText(current), controls: ["sandbox on", "sandbox off"] });
|
|
1696
|
+
}
|
|
1697
|
+
const mode = words.length === 1 ? parseSandboxMode(words[0]) : void 0;
|
|
1698
|
+
if (!mode) throw new Error("usage: /sandbox [on|off]");
|
|
1699
|
+
if (mode === "off") session.sandbox = "off";
|
|
1700
|
+
else delete session.sandbox;
|
|
1701
|
+
return saveSettings(state, session);
|
|
1702
|
+
},
|
|
1703
|
+
computer: async ({ session, words }) => {
|
|
1704
|
+
const value = words[0]?.toLowerCase();
|
|
1705
|
+
if (value === "login") {
|
|
1706
|
+
const rest = words.slice(1);
|
|
1707
|
+
const newAccount = rest.includes("--new");
|
|
1708
|
+
const urls = rest.filter((word) => word !== "--new");
|
|
1709
|
+
if (urls.length <= 1) {
|
|
1710
|
+
await computerLogin(session.id, { ...urls[0] ? { url: urls[0] } : {}, ...newAccount ? { newAccount: true } : {} });
|
|
1711
|
+
return;
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
if (value === "logins" && words.length === 1) {
|
|
1715
|
+
await computerLogin(session.id, { manage: true });
|
|
1716
|
+
return;
|
|
1717
|
+
}
|
|
1718
|
+
if (value === "profile" && words.length === 1) {
|
|
1719
|
+
await computerTool("account_use", { action: "profile", ask: true }, session.id);
|
|
1720
|
+
return;
|
|
1721
|
+
}
|
|
1722
|
+
if (value === "inspect" && words.length === 1) {
|
|
1723
|
+
await computerInspect();
|
|
1724
|
+
return;
|
|
1725
|
+
}
|
|
1726
|
+
if (words.length > 1 || value && value !== "on" && value !== "off") throw new Error("usage: /computer [on|off|inspect|logins|profile|login [url] [--new]]");
|
|
1727
|
+
if (value) {
|
|
1728
|
+
await setComputerEnabled(stateDirectory(), value === "on");
|
|
1729
|
+
if (value === "off") {
|
|
1730
|
+
await closeComputerBrowser(stateDirectory());
|
|
1731
|
+
lockCredentialVault(stateDirectory());
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
const enabled = await computerEnabled(stateDirectory());
|
|
1735
|
+
return emitHarnessOutput({ panel: "settings-updated", text: enabled ? "Computer use is on. The agent can open URLs and control the desktop when a task needs it." : "Computer use is off. New computer actions are refused." });
|
|
1736
|
+
},
|
|
1737
|
+
// Global, not this chat's: how mid-turn messages go is the user's habit.
|
|
1738
|
+
// The worker reads it as each message arrives (session-worker.ts).
|
|
1739
|
+
send: async ({ state, words }) => {
|
|
1740
|
+
if (!words[0]) {
|
|
1741
|
+
const current = sendModeOf(state.globalSettings);
|
|
1742
|
+
return emitHarnessOutput({ panel: "send", sendMode: current, text: `Messages typed mid-turn: ${current} \xB7 ${SEND_MODE_DETAIL[current]}`, controls: SEND_MODES.map((mode2) => `send ${mode2}`) });
|
|
1743
|
+
}
|
|
1744
|
+
const mode = parseSendMode(words[0]);
|
|
1745
|
+
await aiSettingsSetGlobal("send", mode, false);
|
|
1746
|
+
return emitHarnessOutput({ panel: "settings-updated", sendMode: mode, text: `Messages typed mid-turn: ${mode}` });
|
|
1747
|
+
},
|
|
1748
|
+
settings: async ({ id, state, session, words }) => {
|
|
1749
|
+
const setting = words.shift()?.toLowerCase();
|
|
1750
|
+
const value = words.join(" ").trim();
|
|
1751
|
+
if (!setting) return emitHarnessOutput({ panel: "settings", session, account: state.accounts.find((item) => item.id === session.accountId)?.label });
|
|
1752
|
+
if (setting === "idle") {
|
|
1753
|
+
const { idleWords, ownModelIdleMinutes, setOwnModelIdleMinutes } = await import("./chunk-DKDPZTD3.js");
|
|
1754
|
+
if (!value) {
|
|
1755
|
+
const minutes2 = await ownModelIdleMinutes();
|
|
1756
|
+
return emitHarnessOutput({ panel: "settings-updated", text: `Your models turn off after: ${idleWords(minutes2)} idle (/settings idle <minutes|never>)` });
|
|
1757
|
+
}
|
|
1758
|
+
const minutes = /^(never|off|0)$/i.test(value) ? 0 : Number.parseInt(value, 10);
|
|
1759
|
+
if (!Number.isInteger(minutes) || minutes < 0) throw new Error("usage: /settings idle <minutes|never> (5 minutes to 1440)");
|
|
1760
|
+
const stored = await setOwnModelIdleMinutes(minutes);
|
|
1761
|
+
return emitHarnessOutput({ panel: "settings-updated", text: `Your models turn off after: ${idleWords(stored)} idle` });
|
|
1762
|
+
}
|
|
1763
|
+
if (setting === "global") {
|
|
1764
|
+
const [key, ...rest] = words;
|
|
1765
|
+
if (!key || !rest.length) throw new Error("usage: /settings global <effort|permissions|send> <value>");
|
|
1766
|
+
await aiSettingsSetGlobal(key, rest.join(" "), false);
|
|
1767
|
+
return emitHarnessOutput({ panel: "settings-updated", text: `Global default updated: ${key} = ${rest.join(" ")}` });
|
|
1768
|
+
}
|
|
1769
|
+
if (setting === "provider") {
|
|
1770
|
+
const [providerId, key, ...rest] = words;
|
|
1771
|
+
if (!providerId || !key) throw new Error("usage: /settings provider <id> <model|effort|permissions> <value>, or /settings provider <id> clear");
|
|
1772
|
+
if (key.toLowerCase() === "clear") {
|
|
1773
|
+
await aiSettingsClearProvider(providerId, false);
|
|
1774
|
+
return emitHarnessOutput({ panel: "settings-updated", text: `Provider defaults cleared for ${providerId}` });
|
|
1775
|
+
}
|
|
1776
|
+
if (!rest.length) throw new Error("usage: /settings provider <id> <key> <value>");
|
|
1777
|
+
await aiSettingsSetProvider(providerId, key, rest.join(" "), false);
|
|
1778
|
+
return emitHarnessOutput({ panel: "settings-updated", text: `${providerId} default updated: ${key} = ${rest.join(" ")}` });
|
|
1779
|
+
}
|
|
1780
|
+
if (!value) throw new Error(`usage: /settings ${setting} <value>`);
|
|
1781
|
+
if (setting === "route") {
|
|
1782
|
+
if (!isAiHarnessRoute(value)) throw new Error(ROUTE_CHOICES_TEXT);
|
|
1783
|
+
if (session.route === "clikcode-local" && value !== "clikcode-local") await releaseHeldLocalModel(session.id);
|
|
1784
|
+
if (value === "gateway" || value === "clikcode-local") applyClikCodeAgentSessionPolicy(session, value, state);
|
|
1785
|
+
else if (isClikCodeAgent(session)) applyFreshLocalSessionPolicy(state, session);
|
|
1786
|
+
else session.route = "local";
|
|
1787
|
+
} else if (setting === "account" || setting === "model" || setting === "effort" || setting === "permissions" || setting === "permission") {
|
|
1788
|
+
const command = setting === "account" ? "accounts use" : setting === "permission" ? "permissions" : setting;
|
|
1789
|
+
return aiSessionCommand(id, `/${command} ${value}`);
|
|
1790
|
+
} else if (setting === "option") {
|
|
1791
|
+
const [optionId, ...optionValue] = value.split(/\s+/);
|
|
1792
|
+
const harness = session.nativeHarness ? localHarnessForCommand(session.nativeHarness) : void 0;
|
|
1793
|
+
if (!harness || !optionId || !optionValue.length) throw new Error("usage: /settings option <id> <value|default>");
|
|
1794
|
+
if (optionValue.join(" ") === "default") {
|
|
1795
|
+
const { [optionId]: _cleared, ...rest } = session.harnessOptions ?? {};
|
|
1796
|
+
session.harnessOptions = rest;
|
|
1797
|
+
} else setSessionHarnessOption(session, harness, optionId, optionValue.join(" "));
|
|
1798
|
+
} else if (setting === "native-session") {
|
|
1799
|
+
if (!session.nativeHarness) throw new Error("select a native harness before attaching its session id");
|
|
1800
|
+
const selectedHarness = localHarnessForCommand(session.nativeHarness);
|
|
1801
|
+
if (!selectedHarness?.session?.resumeIdPrefix) throw new Error(`${selectedHarness?.displayName ?? session.nativeHarness} does not support exact session resume`);
|
|
1802
|
+
session.nativeSessionId = value;
|
|
1803
|
+
delete session.nativeSessionPreallocated;
|
|
1804
|
+
const pinned = cliThreadTransport(selectedHarness);
|
|
1805
|
+
if (pinned) session.nativeTransport = pinned;
|
|
1806
|
+
else delete session.nativeTransport;
|
|
1807
|
+
} else {
|
|
1808
|
+
throw new Error(`unknown setting: ${setting}`);
|
|
1809
|
+
}
|
|
1810
|
+
return saveSettings(state, session);
|
|
1811
|
+
}
|
|
1812
|
+
};
|
|
1813
|
+
|
|
1814
|
+
// src/tui/slash/handlers/accounts.ts
|
|
1815
|
+
async function resolveLocalModelFor(account, state) {
|
|
1816
|
+
const harness = localHarnessForProvider(account.provider);
|
|
1817
|
+
if (!harness) return void 0;
|
|
1818
|
+
return resolveNativeModel(harness, state.accounts.find((item) => item.id === account.id));
|
|
1819
|
+
}
|
|
1820
|
+
var accountsHandlers = {
|
|
1821
|
+
accounts: async ({ id, state, session, words }) => {
|
|
1822
|
+
const ACTIONS = ["use", "select", "login", "add", "remove", "rm"];
|
|
1823
|
+
const action = words.length && !ACTIONS.includes(words[0].toLowerCase()) ? "use" : words.shift()?.toLowerCase();
|
|
1824
|
+
if (action === "use" || action === "select") {
|
|
1825
|
+
const labelOrId = words.join(" ").trim();
|
|
1826
|
+
if (!labelOrId) throw new Error("usage: /accounts use <label-or-id>");
|
|
1827
|
+
const account = state.accounts.find((item) => item.id === labelOrId || item.label.toLowerCase() === labelOrId.toLowerCase());
|
|
1828
|
+
if (!account) throw new Error(`No account named "${labelOrId}" -- /account lists them`);
|
|
1829
|
+
const leavingAgentRoute = isClikCodeAgent(session);
|
|
1830
|
+
if (session.route === "clikcode-local") await releaseHeldLocalModel(session.id);
|
|
1831
|
+
if (leavingAgentRoute) applyFreshLocalSessionPolicy(state, session);
|
|
1832
|
+
if (session.nativeHarness) {
|
|
1833
|
+
const selectedHarness = localHarnessForCommand(session.nativeHarness);
|
|
1834
|
+
const accountCommand = localHarnessForProvider(account.provider)?.command ?? account.provider;
|
|
1835
|
+
if (selectedHarness && selectedHarness.provider !== account.provider) {
|
|
1836
|
+
await moveToProvider(id, accountCommand);
|
|
1837
|
+
await aiSessionCommand(id, `/accounts use ${account.id}`);
|
|
1838
|
+
return id;
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
const accountHarness = localHarnessForProvider(account.provider);
|
|
1842
|
+
if (accountHarness && harnessCanRunTurns(accountHarness) && session.nativeHarness !== accountHarness.command) {
|
|
1843
|
+
session.nativeHarness = accountHarness.command;
|
|
1844
|
+
forgetNativeThread(session);
|
|
1845
|
+
}
|
|
1846
|
+
session.accountId = account.id;
|
|
1847
|
+
clearQuotaMark(account);
|
|
1848
|
+
session.provider = account.provider;
|
|
1849
|
+
session.route = "local";
|
|
1850
|
+
if (leavingAgentRoute) {
|
|
1851
|
+
const defaults = resolveDefaultSettings(state, account.provider);
|
|
1852
|
+
session.model = state.providerSettings[account.provider]?.model ?? await resolveLocalModelFor(account, state) ?? null;
|
|
1853
|
+
session.effort = defaults.effort;
|
|
1854
|
+
session.permissionMode = defaults.permissionMode;
|
|
1855
|
+
}
|
|
1856
|
+
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1857
|
+
await writeState(state);
|
|
1858
|
+
return emitHarnessOutput({ panel: "accounts", selected: accountView(account), session });
|
|
1859
|
+
}
|
|
1860
|
+
if (action === "login") {
|
|
1861
|
+
const harnessName = words.shift()?.toLowerCase();
|
|
1862
|
+
if (!harnessName) throw new Error("usage: /accounts login <harness> [label]");
|
|
1863
|
+
await aiAccountLogin(harnessName, words.join(" ") || void 0);
|
|
1864
|
+
return;
|
|
1865
|
+
}
|
|
1866
|
+
if (action === "remove" || action === "rm") {
|
|
1867
|
+
const labelOrId = words.join(" ").trim();
|
|
1868
|
+
if (!labelOrId) throw new Error("usage: /accounts remove <label-or-id>");
|
|
1869
|
+
return aiAccountRemove(labelOrId);
|
|
1870
|
+
}
|
|
1871
|
+
if (action === "add") {
|
|
1872
|
+
const shortcut = words.shift()?.toLowerCase();
|
|
1873
|
+
const provider = shortcut ? localHarnessForCommand(shortcut)?.provider ?? shortcut : void 0;
|
|
1874
|
+
if (!provider) throw new Error("usage: /accounts add <harness>");
|
|
1875
|
+
const knownHarness = shortcut ? localHarnessForCommand(shortcut) : void 0;
|
|
1876
|
+
if (knownHarness) {
|
|
1877
|
+
await aiAccountLogin(knownHarness.command, words.join(" ") || void 0);
|
|
1878
|
+
return;
|
|
1879
|
+
}
|
|
1880
|
+
return emitHarnessOutput({ panel: "add-account", provider, next: `${harnessCommand()} accounts add --provider ${provider} --label <label> --auth api-key|vendor-cli --credential-ref <local-reference>`, credentialBoundary: "local-only" });
|
|
1881
|
+
}
|
|
1882
|
+
return emitHarnessOutput({ panel: "accounts", session, accounts: state.accounts.map(accountView), controls: ["use <label-or-id>", "login <harness> [label]", "add <harness> [label]", "remove <label-or-id>"] });
|
|
1883
|
+
},
|
|
1884
|
+
login: async ({ session }) => {
|
|
1885
|
+
const harness = sessionHarness(session);
|
|
1886
|
+
if (!harness) throw new Error("Choose a provider before signing in.");
|
|
1887
|
+
await aiAccountLogin(harness.command);
|
|
1888
|
+
},
|
|
1889
|
+
logout: async ({ state, session }) => {
|
|
1890
|
+
const account = session.accountId ? state.accounts.find((item) => item.id === session.accountId) : void 0;
|
|
1891
|
+
if (!account) throw new Error("This conversation has no account to sign out.");
|
|
1892
|
+
await aiAccountLogout(account.id);
|
|
1893
|
+
},
|
|
1894
|
+
doctor: async () => aiDoctor(),
|
|
1895
|
+
gateway: async ({ state, session }) => {
|
|
1896
|
+
if (sessionTranscriptMessages(session).length || session.nativeSessionId) {
|
|
1897
|
+
throw new Error("Use the interactive /provider menu to hand off an existing conversation to ClikDeploy Gateway.");
|
|
1898
|
+
}
|
|
1899
|
+
applyGatewaySessionPolicy(session, state);
|
|
1900
|
+
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1901
|
+
await writeState(state);
|
|
1902
|
+
return emitHarnessOutput({ panel: "provider-selected", harness: "gateway", displayName: "ClikDeploy Gateway", provider: "gateway", account: null, model: "platform", centralized: true });
|
|
1903
|
+
}
|
|
1904
|
+
};
|
|
1905
|
+
|
|
1906
|
+
// src/tui/slash/handlers/agents.ts
|
|
1907
|
+
var ANSWER_MS = 1e4;
|
|
1908
|
+
async function askAgents(sessionId, command) {
|
|
1909
|
+
const client = await WorkerClient.attachExisting(sessionId);
|
|
1910
|
+
if (!client) {
|
|
1911
|
+
const records = readAgentRecords(stateDirectory(), sessionId).map((record) => ({ id: record.id, label: record.label, status: record.status, startedAt: record.startedAt, ...record.worktree ? { branch: record.worktree.branch } : {} }));
|
|
1912
|
+
return `${agentsReport([], records)}
|
|
1913
|
+
|
|
1914
|
+
(No worker is running for this conversation.)`;
|
|
1915
|
+
}
|
|
1916
|
+
try {
|
|
1917
|
+
const answered = new Promise((resolve3, reject) => {
|
|
1918
|
+
const timer = setTimeout(() => reject(new Error("The conversation's worker did not answer.")), ANSWER_MS);
|
|
1919
|
+
client.on("event", (event) => {
|
|
1920
|
+
if (event.type === "agents") {
|
|
1921
|
+
clearTimeout(timer);
|
|
1922
|
+
resolve3(event);
|
|
1923
|
+
}
|
|
1924
|
+
});
|
|
1925
|
+
client.on("close", () => {
|
|
1926
|
+
clearTimeout(timer);
|
|
1927
|
+
reject(new Error("The conversation's worker closed the connection."));
|
|
1928
|
+
});
|
|
1929
|
+
});
|
|
1930
|
+
client.send(command);
|
|
1931
|
+
return (await answered).text;
|
|
1932
|
+
} finally {
|
|
1933
|
+
client.send({ type: "detach" });
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
function parseAgentsArgs(words) {
|
|
1937
|
+
const rest = words.map((word) => word.toLowerCase());
|
|
1938
|
+
if (rest[0] !== "stop") return { action: "list" };
|
|
1939
|
+
const args = rest.slice(1);
|
|
1940
|
+
const confirm = args.some((word) => word === "confirm" || word === "yes" || word === "--yes");
|
|
1941
|
+
const named = args.filter((word) => !["confirm", "yes", "--yes"].includes(word));
|
|
1942
|
+
const all = named.includes("all") || named.includes("everything");
|
|
1943
|
+
return { action: "stop", ids: named.filter((word) => word !== "all" && word !== "everything"), all, confirm };
|
|
1944
|
+
}
|
|
1945
|
+
var agentsHandlers = {
|
|
1946
|
+
agents: async ({ id, words, session, state }) => {
|
|
1947
|
+
if (words[0]?.toLowerCase() === "view") {
|
|
1948
|
+
const parentId = words[1];
|
|
1949
|
+
if (!parentId) {
|
|
1950
|
+
const agents = new Map(conversationSubagentEvents(session).filter((event) => event.agent && event.id).map((event) => [event.id, event.label]));
|
|
1951
|
+
return emitHarnessOutput({ panel: "agents", text: agents.size ? [...agents].map(([key, label]) => `${key} \xB7 ${label}`).join("\n") + "\n\n/agents view <id>" : "No recorded subagents in this conversation." });
|
|
1952
|
+
}
|
|
1953
|
+
const rows = await readConversationSubagent(session, state.accounts.find((account) => account.id === session.accountId), parentId);
|
|
1954
|
+
return emitHarnessOutput({ panel: "agents", text: rows.length ? rows.map((row) => row.kind === "activity" ? [row.event.label, ...row.event.output ?? []].join("\n") : row.text).join("\n\n") : "No recorded messages or tool calls for this subagent." });
|
|
1955
|
+
}
|
|
1956
|
+
const parsed = parseAgentsArgs(words);
|
|
1957
|
+
if (parsed.action === "stop" && !parsed.all && !parsed.ids.length) throw new Error("usage: /agents stop <id> [confirm], or /agents stop all [confirm]");
|
|
1958
|
+
const text = await askAgents(id, { type: "agents", ...parsed });
|
|
1959
|
+
return emitHarnessOutput({ panel: "agents", text });
|
|
1960
|
+
}
|
|
1961
|
+
};
|
|
1962
|
+
|
|
1963
|
+
// src/tui/slash/handlers/shell.ts
|
|
1964
|
+
async function runShellLine(id, command, signal, options = {}) {
|
|
1965
|
+
const workspace = (await readState({ transcripts: [] })).sessions.find((item) => item.id === id)?.workspace ?? process.cwd();
|
|
1966
|
+
const result = await runShellCommand(command, workspace, signal, options);
|
|
1967
|
+
const note = { command, output: result.output, exitCode: result.exitCode, at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
1968
|
+
const state = await readState({ transcripts: [id] });
|
|
1969
|
+
const session = state.sessions.find((item) => item.id === id);
|
|
1970
|
+
if (!session) throw new Error(`AI session "${id}" was not found`);
|
|
1971
|
+
session.messages = [...session.messages ?? [], { role: "user", content: shellMessageContent(note) }];
|
|
1972
|
+
session.shellNotes = [...session.shellNotes ?? [], note];
|
|
1973
|
+
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1974
|
+
await writeState(state);
|
|
1975
|
+
return note;
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
// src/tui/slash/handlers.ts
|
|
1979
|
+
var HEADLESS_SLASH_HANDLERS = {
|
|
1980
|
+
...conversationHandlers,
|
|
1981
|
+
...modelHandlers,
|
|
1982
|
+
...settingsHandlers,
|
|
1983
|
+
...accountsHandlers,
|
|
1984
|
+
...agentsHandlers,
|
|
1985
|
+
init: (context) => HEADLESS_SLASH_HANDLERS.review(context),
|
|
1986
|
+
options: INTERACTIVE_ONLY("options"),
|
|
1987
|
+
provider: INTERACTIVE_ONLY("provider"),
|
|
1988
|
+
resume: INTERACTIVE_ONLY("resume"),
|
|
1989
|
+
machine: INTERACTIVE_ONLY("machine"),
|
|
1990
|
+
hostedModels: INTERACTIVE_ONLY("hosted AI"),
|
|
1991
|
+
// This machine's ClikCode, the way it was installed (remote/self-update.ts).
|
|
1992
|
+
update: async ({ args }) => {
|
|
1993
|
+
const { parseCommitArgument, updateThisMachine } = await import("./chunk-J2PACWRQ.js");
|
|
1994
|
+
const commit = parseCommitArgument(args);
|
|
1995
|
+
const result = await updateThisMachine({ ...commit ? { commit } : {}, line: (text) => emitHarnessOutput({ panel: "update", text }) });
|
|
1996
|
+
emitHarnessOutput({ panel: "update", text: result.text });
|
|
1997
|
+
}
|
|
1998
|
+
};
|
|
1999
|
+
async function aiSessionCommand(id, input, options = {}) {
|
|
2000
|
+
const state = await readState({ transcripts: [id] });
|
|
2001
|
+
const session = state.sessions.find((item) => item.id === id);
|
|
2002
|
+
if (!session) throw new Error(`AI session "${id}" was not found`);
|
|
2003
|
+
const text = input.trim();
|
|
2004
|
+
if (!text.replace(/^\/+/, "")) throw new Error("slash command is required");
|
|
2005
|
+
if (isShellCommandLine(text)) {
|
|
2006
|
+
const command = text.slice(1).trim();
|
|
2007
|
+
if (!command) throw new Error("Type `!<command>` to run it, e.g. `!git status`.");
|
|
2008
|
+
const note = await runShellLine(id, command, options.signal, { timeoutMs: SHELL_HEADLESS_TIMEOUT_MS });
|
|
2009
|
+
emitHarnessOutput({ panel: "shell", text: shellMessageContent(note) });
|
|
2010
|
+
return id;
|
|
2011
|
+
}
|
|
2012
|
+
const harness = sessionHarness(session);
|
|
2013
|
+
const routeContext = slashRouteContextFor(session, harness);
|
|
2014
|
+
const route = routeSlashInput(text.startsWith("/") ? text : `/${text}`, routeContext);
|
|
2015
|
+
if (route.kind === "command") {
|
|
2016
|
+
const availability = route.entry.availability(session, harness, route.args, routeContext.nativeCommands);
|
|
2017
|
+
if (!availability.available && availability.needs === "provider" && !options.inferred) {
|
|
2018
|
+
const implied = impliedHarnessCommand(route, state.accounts, localHarnessForProvider);
|
|
2019
|
+
if (implied) {
|
|
2020
|
+
await aiHarnessSelect(implied, id);
|
|
2021
|
+
return aiSessionCommand(id, input, { ...options, inferred: true });
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
if (!availability.available) throw new Error(availability.reason ?? `/${route.entry.name} is not available here.`);
|
|
2025
|
+
const moved = await HEADLESS_SLASH_HANDLERS[route.entry.handlerKey]({ id, state, session, head: route.entry.name, args: route.args, words: [...route.words] });
|
|
2026
|
+
return typeof moved === "string" ? moved : id;
|
|
2027
|
+
}
|
|
2028
|
+
if (route.kind === "harness") {
|
|
2029
|
+
await moveToProvider(id, route.command);
|
|
2030
|
+
if (route.args) await sendSessionTurn(id, route.args);
|
|
2031
|
+
return id;
|
|
2032
|
+
}
|
|
2033
|
+
if (route.kind === "manager") {
|
|
2034
|
+
const listing = await nativeManagerListing(state, session, route.name);
|
|
2035
|
+
emitHarnessOutput({ panel: route.name, text: `${listing.label}
|
|
2036
|
+
|
|
2037
|
+
${listing.text}` });
|
|
2038
|
+
return id;
|
|
2039
|
+
}
|
|
2040
|
+
const turn = slashRouteTurn(route, session, harness);
|
|
2041
|
+
if (turn) {
|
|
2042
|
+
await sendSessionTurn(id, turn.prompt);
|
|
2043
|
+
return id;
|
|
2044
|
+
}
|
|
2045
|
+
throw new Error("slash command is required");
|
|
2046
|
+
}
|
|
2047
|
+
function slashRouteTurn(route, session, harness) {
|
|
2048
|
+
if (route.kind === "unknown") throw new Error(unknownSlashMessage(route));
|
|
2049
|
+
if (route.kind === "native") {
|
|
2050
|
+
if (isClikCodeAgent(session)) throw new Error("Native harness commands apply only to local harnesses.");
|
|
2051
|
+
return { prompt: route.prompt, echo: true };
|
|
2052
|
+
}
|
|
2053
|
+
if (route.kind === "custom") {
|
|
2054
|
+
const command = customCommandsFor(session, harness).find((item) => item.name === route.name);
|
|
2055
|
+
if (!command) throw new Error(`custom command /${route.name} is no longer available`);
|
|
2056
|
+
return { prompt: customCommandPrompt(command, route.args, harness), echo: false };
|
|
2057
|
+
}
|
|
2058
|
+
return void 0;
|
|
2059
|
+
}
|
|
2060
|
+
|
|
2061
|
+
export {
|
|
2062
|
+
TERMINAL_ONLY_COMMANDS,
|
|
2063
|
+
resolveSlashCommand,
|
|
2064
|
+
parseSlashInput,
|
|
2065
|
+
slashPalette,
|
|
2066
|
+
slashHelpText,
|
|
2067
|
+
slashControls,
|
|
2068
|
+
slashRouteAppliesDuringTurn,
|
|
2069
|
+
routeSlashInput,
|
|
2070
|
+
impliedHarnessCommand,
|
|
2071
|
+
nativeManagerListing,
|
|
2072
|
+
isChangesPath,
|
|
2073
|
+
changesPath,
|
|
2074
|
+
fileTurnRows,
|
|
2075
|
+
noFileTurns,
|
|
2076
|
+
capabilitiesText,
|
|
2077
|
+
compactConversation,
|
|
2078
|
+
userMessageIndexes,
|
|
2079
|
+
forkPoint,
|
|
2080
|
+
forkPointOptions,
|
|
2081
|
+
initPrompt,
|
|
2082
|
+
reviewPrompt,
|
|
2083
|
+
readMemoryFile,
|
|
2084
|
+
lastAnswer,
|
|
2085
|
+
aiSettingsSetGlobal,
|
|
2086
|
+
aiSettingsSetProvider,
|
|
2087
|
+
aiSettingsClearProvider,
|
|
2088
|
+
runShellLine,
|
|
2089
|
+
aiSessionCommand,
|
|
2090
|
+
slashRouteTurn
|
|
2091
|
+
};
|