clikcode 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (323) hide show
  1. package/README.md +25 -14
  2. package/dist/chunk-23TDEBGZ.js +71 -0
  3. package/dist/chunk-25T3GVS7.js +425 -0
  4. package/dist/chunk-2BBELGHY.js +11 -0
  5. package/dist/chunk-2EOL5PZL.js +208 -0
  6. package/dist/chunk-2GAB36IE.js +26 -0
  7. package/dist/chunk-2OLS7V66.js +2440 -0
  8. package/dist/chunk-2QFO2URB.js +179 -0
  9. package/dist/chunk-2QWPQRSU.js +254 -0
  10. package/dist/chunk-2YPAPAR3.js +184 -0
  11. package/dist/chunk-2ZAG5372.js +33 -0
  12. package/dist/chunk-32IKAIZC.js +12507 -0
  13. package/dist/chunk-34AZEGYW.js +95 -0
  14. package/dist/chunk-34JQYQCA.js +175 -0
  15. package/dist/chunk-34ZISPAO.js +67 -0
  16. package/dist/chunk-3AAAARE6.js +46 -0
  17. package/dist/chunk-3AJ6Q3OY.js +510 -0
  18. package/dist/chunk-3B2CHX7M.js +884 -0
  19. package/dist/chunk-3BUFORRX.js +59 -0
  20. package/dist/chunk-3QLHYYFK.js +30 -0
  21. package/dist/chunk-3RXBMYKZ.js +140 -0
  22. package/dist/chunk-3TFNIJWS.js +52 -0
  23. package/dist/chunk-3W3IPDFP.js +119 -0
  24. package/dist/chunk-3WMS7SEE.js +417 -0
  25. package/dist/chunk-435ZNSZ3.js +23 -0
  26. package/dist/chunk-4AQ5NINV.js +39 -0
  27. package/dist/chunk-4GVEJ5FK.js +168 -0
  28. package/dist/chunk-4GXAO3UY.js +262 -0
  29. package/dist/chunk-4L2ZZM4Q.js +332 -0
  30. package/dist/chunk-4LPDG57B.js +17 -0
  31. package/dist/chunk-4NN3XQQT.js +223 -0
  32. package/dist/chunk-4QZEZME7.js +54 -0
  33. package/dist/chunk-4R6CSC3S.js +38 -0
  34. package/dist/chunk-4RHXTL3W.js +514 -0
  35. package/dist/chunk-4SJMPTVQ.js +18 -0
  36. package/dist/chunk-4VY7G6TX.js +114 -0
  37. package/dist/chunk-5642PBF7.js +124 -0
  38. package/dist/chunk-5B6TVO4A.js +33 -0
  39. package/dist/chunk-5BJLDUPL.js +62 -0
  40. package/dist/chunk-5HMFFJWU.js +19 -0
  41. package/dist/chunk-5IKLK33T.js +69 -0
  42. package/dist/chunk-5NQ5FFMX.js +44 -0
  43. package/dist/chunk-5QNNW5L6.js +176 -0
  44. package/dist/chunk-5SM5UAWN.js +239 -0
  45. package/dist/chunk-5WYJTA6O.js +74 -0
  46. package/dist/chunk-5ZSR2Y5T.js +227 -0
  47. package/dist/chunk-5ZWUM5GH.js +39 -0
  48. package/dist/chunk-64E7D4HY.js +364 -0
  49. package/dist/chunk-6CK466BC.js +99 -0
  50. package/dist/chunk-6ES45HHO.js +138 -0
  51. package/dist/chunk-6HYEZFGL.js +277 -0
  52. package/dist/chunk-6Y7HLXGW.js +29 -0
  53. package/dist/chunk-6YKK4FYR.js +258 -0
  54. package/dist/chunk-74WNMLMS.js +117 -0
  55. package/dist/chunk-7AULZ7OD.js +55 -0
  56. package/dist/chunk-7DOKGSUN.js +101 -0
  57. package/dist/chunk-7IH5LTIZ.js +195 -0
  58. package/dist/chunk-7ISTS5NS.js +21 -0
  59. package/dist/chunk-7NMUTGOW.js +527 -0
  60. package/dist/chunk-7PNHUZEL.js +153 -0
  61. package/dist/chunk-7TSQLONI.js +88 -0
  62. package/dist/chunk-AE7TOLD5.js +30 -0
  63. package/dist/chunk-AEMHSXKA.js +130 -0
  64. package/dist/chunk-AKRYTS2D.js +211 -0
  65. package/dist/chunk-AMNSE36L.js +59 -0
  66. package/dist/chunk-AZVD74ZV.js +23 -0
  67. package/dist/chunk-B35DVOTK.js +1981 -0
  68. package/dist/chunk-B4HNJRAH.js +626 -0
  69. package/dist/chunk-B5WYPPHS.js +13 -0
  70. package/dist/chunk-BBOVDXQM.js +59 -0
  71. package/dist/chunk-BD3ECZLK.js +62 -0
  72. package/dist/chunk-BDGSOT74.js +4578 -0
  73. package/dist/chunk-BF5VEOPK.js +31 -0
  74. package/dist/chunk-BFFRW4XH.js +47 -0
  75. package/dist/chunk-BFPC6PEW.js +208 -0
  76. package/dist/chunk-BGEMY2JJ.js +376 -0
  77. package/dist/chunk-BISGNHKD.js +35 -0
  78. package/dist/chunk-BMRAEBRY.js +21 -0
  79. package/dist/chunk-BNTXAZXW.js +127 -0
  80. package/dist/chunk-BOQBXGSN.js +75 -0
  81. package/dist/chunk-BTJDSTQP.js +213 -0
  82. package/dist/chunk-BUOPJQP5.js +218 -0
  83. package/dist/chunk-BXFJS65Q.js +52 -0
  84. package/dist/chunk-BXPQFSX5.js +59 -0
  85. package/dist/chunk-C57LIWNY.js +1269 -0
  86. package/dist/chunk-C6YVCCWR.js +74 -0
  87. package/dist/chunk-CAADDF6M.js +167 -0
  88. package/dist/chunk-CBANJFBO.js +69 -0
  89. package/dist/chunk-CERF3RIB.js +597 -0
  90. package/dist/chunk-COAS5ETR.js +46 -0
  91. package/dist/chunk-CQ7J6UQ7.js +78 -0
  92. package/dist/chunk-CRUVYGO2.js +26 -0
  93. package/dist/chunk-CVFVFRGN.js +58 -0
  94. package/dist/chunk-D2UK66HM.js +37 -0
  95. package/dist/chunk-D2W7SA4R.js +18 -0
  96. package/dist/chunk-DA44ZENT.js +501 -0
  97. package/dist/chunk-DAJ76TOC.js +99 -0
  98. package/dist/chunk-DCZ6CIUM.js +147 -0
  99. package/dist/chunk-DF35KMXM.js +1314 -0
  100. package/dist/chunk-DGASQT26.js +151 -0
  101. package/dist/chunk-DJT57C5P.js +55 -0
  102. package/dist/chunk-DKDPZTD3.js +44 -0
  103. package/dist/chunk-DQYVQ2N7.js +77 -0
  104. package/dist/chunk-DRTP2RTY.js +266 -0
  105. package/dist/chunk-DW2BMUKY.js +61 -0
  106. package/dist/chunk-DW5T5ZVU.js +307 -0
  107. package/dist/chunk-DXKNDNFC.js +164 -0
  108. package/dist/chunk-DZEQ7UYR.js +291 -0
  109. package/dist/chunk-E4F4OUAC.js +463 -0
  110. package/dist/chunk-EE4B6A7W.js +69 -0
  111. package/dist/chunk-EISKIYWG.js +23 -0
  112. package/dist/chunk-EKAQK7UQ.js +235 -0
  113. package/dist/chunk-EOBTJV32.js +123 -0
  114. package/dist/chunk-ESF3DIZY.js +325 -0
  115. package/dist/chunk-EVOHOZ4U.js +45 -0
  116. package/dist/chunk-EXN4KHLB.js +110 -0
  117. package/dist/chunk-F252T6Y3.js +78 -0
  118. package/dist/chunk-F3DP4ZA2.js +40 -0
  119. package/dist/chunk-F6F47QAY.js +58 -0
  120. package/dist/chunk-FA3Y23ZW.js +57 -0
  121. package/dist/chunk-FBKXE4EJ.js +640 -0
  122. package/dist/chunk-FCGEB3H6.js +23 -0
  123. package/dist/chunk-FF7ZVYJF.js +3732 -0
  124. package/dist/chunk-FFGKN6L3.js +39 -0
  125. package/dist/chunk-FFGU4GCC.js +94 -0
  126. package/dist/chunk-FSFDAOVP.js +74 -0
  127. package/dist/chunk-FT5TX7OX.js +1573 -0
  128. package/dist/chunk-G3QP67Z7.js +232 -0
  129. package/dist/chunk-G5ORJKV2.js +179 -0
  130. package/dist/chunk-GFNC62PE.js +111 -0
  131. package/dist/chunk-GGK43Q3N.js +67 -0
  132. package/dist/chunk-GGYKY4GF.js +11537 -0
  133. package/dist/chunk-GGYNHGNJ.js +55 -0
  134. package/dist/chunk-GLY7RM3C.js +354 -0
  135. package/dist/chunk-GQBZU6EO.js +20 -0
  136. package/dist/chunk-GSXENUZL.js +9 -0
  137. package/dist/chunk-GTOAT5D3.js +40 -0
  138. package/dist/chunk-GWCMDPQU.js +1007 -0
  139. package/dist/chunk-GXYSMYHJ.js +152 -0
  140. package/dist/chunk-GYMAI5NY.js +14 -0
  141. package/dist/chunk-H2VZMKPE.js +30 -0
  142. package/dist/chunk-H4THUNBM.js +2091 -0
  143. package/dist/chunk-HGRVSNUZ.js +361 -0
  144. package/dist/chunk-HI4VY473.js +27 -0
  145. package/dist/chunk-HOJRSD3Q.js +447 -0
  146. package/dist/chunk-HRX25W35.js +82 -0
  147. package/dist/chunk-HSE4AQYV.js +55 -0
  148. package/dist/chunk-HU5SSUFX.js +383 -0
  149. package/dist/chunk-I3GDBJLH.js +196 -0
  150. package/dist/chunk-I75EDU75.js +684 -0
  151. package/dist/chunk-IBA7DMIO.js +20 -0
  152. package/dist/chunk-IC6N4NZA.js +231 -0
  153. package/dist/chunk-IF43HIGV.js +284 -0
  154. package/dist/chunk-IGZ6C2MC.js +439 -0
  155. package/dist/chunk-IMLTL2MY.js +192 -0
  156. package/dist/chunk-IMZL6SGR.js +33 -0
  157. package/dist/chunk-IS4USJPY.js +516 -0
  158. package/dist/chunk-ISFSPN2F.js +82 -0
  159. package/dist/chunk-IXE7GTFI.js +55 -0
  160. package/dist/chunk-IZ77QJQG.js +36 -0
  161. package/dist/chunk-J2PACWRQ.js +34 -0
  162. package/dist/chunk-J6EGFVQX.js +180 -0
  163. package/dist/chunk-JEKOD43D.js +22 -0
  164. package/dist/chunk-JGIWATSG.js +30 -0
  165. package/dist/chunk-JYBONKD4.js +43 -0
  166. package/dist/chunk-K2NLG2HK.js +454 -0
  167. package/dist/chunk-KCQ4TBLS.js +164 -0
  168. package/dist/chunk-KD5KIVMS.js +176 -0
  169. package/dist/chunk-KHW6TX6I.js +63 -0
  170. package/dist/chunk-KI5GZFCE.js +520 -0
  171. package/dist/chunk-KN34B7NO.js +105 -0
  172. package/dist/chunk-KYUHIFP3.js +136 -0
  173. package/dist/chunk-KZL5VS4B.js +300 -0
  174. package/dist/chunk-L3VW3QIH.js +48 -0
  175. package/dist/chunk-LA6MG4ET.js +2110 -0
  176. package/dist/chunk-LAVFOA3S.js +66 -0
  177. package/dist/chunk-LB4OA77N.js +13 -0
  178. package/dist/chunk-LBFRF2K4.js +196 -0
  179. package/dist/chunk-LM6EIA4B.js +93 -0
  180. package/dist/chunk-LPCNRGJ7.js +692 -0
  181. package/dist/chunk-LSLNL5T3.js +168 -0
  182. package/dist/chunk-LVRRWP4W.js +568 -0
  183. package/dist/chunk-LWCFBRHL.js +33 -0
  184. package/dist/chunk-LXFTMGZZ.js +166 -0
  185. package/dist/chunk-M33LVA4M.js +151 -0
  186. package/dist/chunk-M3FO5UMK.js +4944 -0
  187. package/dist/chunk-M5QNDBAY.js +66 -0
  188. package/dist/chunk-M6ND6KBE.js +1291 -0
  189. package/dist/chunk-M7H3WQTE.js +76 -0
  190. package/dist/chunk-MCBRVPA7.js +191 -0
  191. package/dist/chunk-MCSDWZET.js +91 -0
  192. package/dist/chunk-MDT5XDXL.js +289 -0
  193. package/dist/chunk-MJG3IQY4.js +91 -0
  194. package/dist/chunk-MOU3N2UL.js +44 -0
  195. package/dist/chunk-MP4KZOQC.js +3451 -0
  196. package/dist/chunk-MPAJ446F.js +66 -0
  197. package/dist/chunk-MVJZZ6AL.js +16 -0
  198. package/dist/chunk-MXS6S2PY.js +253 -0
  199. package/dist/chunk-N3SFDYM7.js +291 -0
  200. package/dist/chunk-NAOX3JUB.js +13 -0
  201. package/dist/chunk-NEKKIBCX.js +283 -0
  202. package/dist/chunk-NKDATMEM.js +133 -0
  203. package/dist/chunk-NR4FMC4K.js +395 -0
  204. package/dist/chunk-NSOHOJBR.js +221 -0
  205. package/dist/chunk-NTDB6QKF.js +29 -0
  206. package/dist/chunk-NWEYRBWK.js +25 -0
  207. package/dist/chunk-O2YSNYWD.js +23 -0
  208. package/dist/chunk-O3EW7LAY.js +54 -0
  209. package/dist/chunk-O7BNJIXU.js +366 -0
  210. package/dist/chunk-OARL2NXZ.js +116 -0
  211. package/dist/chunk-OHKZUEJW.js +351 -0
  212. package/dist/chunk-OKU45BXA.js +647 -0
  213. package/dist/chunk-OL4JBD3J.js +59 -0
  214. package/dist/chunk-OLUO5DDR.js +192 -0
  215. package/dist/chunk-OQ245JLA.js +196 -0
  216. package/dist/chunk-P72UZAQI.js +289 -0
  217. package/dist/chunk-PAL2ENB6.js +20 -0
  218. package/dist/chunk-PAXYQZH7.js +53 -0
  219. package/dist/chunk-PDPEM5VW.js +51 -0
  220. package/dist/chunk-PEWCDI2C.js +668 -0
  221. package/dist/chunk-PGZ54EDX.js +27 -0
  222. package/dist/chunk-PRWVLDZF.js +73 -0
  223. package/dist/chunk-PSQQ75VJ.js +52 -0
  224. package/dist/chunk-PUOVIFHW.js +118 -0
  225. package/dist/chunk-PWBF2X3V.js +107 -0
  226. package/dist/chunk-PWXII6HF.js +43 -0
  227. package/dist/chunk-Q35VLJRT.js +80 -0
  228. package/dist/chunk-QJP7EYGL.js +128 -0
  229. package/dist/chunk-QPQKX2MK.js +8836 -0
  230. package/dist/chunk-QQRLPY25.js +1053 -0
  231. package/dist/chunk-QUS4ER2W.js +407 -0
  232. package/dist/chunk-QYHI3YET.js +29 -0
  233. package/dist/chunk-QYRU2UQI.js +32 -0
  234. package/dist/chunk-R6XVVQGC.js +13 -0
  235. package/dist/chunk-R7QN6ONS.js +483 -0
  236. package/dist/chunk-RD23MPGC.js +221 -0
  237. package/dist/chunk-RDDWQBEM.js +185 -0
  238. package/dist/chunk-RDLLDYFO.js +104 -0
  239. package/dist/chunk-RE4TGORR.js +84 -0
  240. package/dist/chunk-RJLHVYQY.js +217 -0
  241. package/dist/chunk-RJLPTWHW.js +905 -0
  242. package/dist/chunk-RKUVLRZI.js +295 -0
  243. package/dist/chunk-ROGXPGYR.js +37 -0
  244. package/dist/chunk-RSZGEL5U.js +163 -0
  245. package/dist/chunk-RVUOIJXN.js +909 -0
  246. package/dist/chunk-RW7F4JRP.js +11 -0
  247. package/dist/chunk-S4UO3AO3.js +53 -0
  248. package/dist/chunk-S5JAAF6S.js +585 -0
  249. package/dist/chunk-SNU37TQI.js +56 -0
  250. package/dist/chunk-SQVUDO2O.js +31 -0
  251. package/dist/chunk-SYVHIYQT.js +66 -0
  252. package/dist/chunk-SZBQMTG2.js +85 -0
  253. package/dist/chunk-T5VCXA3J.js +25 -0
  254. package/dist/chunk-TK6NSP56.js +30 -0
  255. package/dist/chunk-TKWVMA6L.js +22 -0
  256. package/dist/chunk-TQDKJHWX.js +59 -0
  257. package/dist/chunk-TQDM7S5N.js +127 -0
  258. package/dist/chunk-TULAXS77.js +23 -0
  259. package/dist/chunk-TVT45XNH.js +4625 -0
  260. package/dist/chunk-TWCVV2JO.js +467 -0
  261. package/dist/chunk-U4DKAD6S.js +47 -0
  262. package/dist/chunk-UA5K2BTI.js +564 -0
  263. package/dist/chunk-UAMKCMOK.js +40 -0
  264. package/dist/chunk-UBMVADBF.js +51 -0
  265. package/dist/chunk-UFQ5A5PW.js +645 -0
  266. package/dist/chunk-UOD2SOLL.js +1301 -0
  267. package/dist/chunk-UTSB4LOW.js +156 -0
  268. package/dist/chunk-UVXNIUTN.js +412 -0
  269. package/dist/chunk-UXVPXYPE.js +90 -0
  270. package/dist/chunk-UYEEMIWR.js +374 -0
  271. package/dist/chunk-VBGM5ZBW.js +54 -0
  272. package/dist/chunk-VEWPCZPG.js +762 -0
  273. package/dist/chunk-VIRDLZ5E.js +108 -0
  274. package/dist/chunk-VMPO7WKN.js +52 -0
  275. package/dist/chunk-W2NVSDO5.js +5122 -0
  276. package/dist/chunk-W3YYPBEA.js +176 -0
  277. package/dist/chunk-W5AYOICN.js +280 -0
  278. package/dist/chunk-W5GZOIUF.js +27 -0
  279. package/dist/chunk-WHKNLZ3C.js +76 -0
  280. package/dist/chunk-WKBEPPQ5.js +1409 -0
  281. package/dist/chunk-WM3Z6QKQ.js +151 -0
  282. package/dist/chunk-WMI2TPMA.js +31 -0
  283. package/dist/chunk-WNX5VD7S.js +150 -0
  284. package/dist/chunk-WOVTYST3.js +60 -0
  285. package/dist/chunk-WPB5WEZJ.js +546 -0
  286. package/dist/chunk-WUO5EOAT.js +44 -0
  287. package/dist/chunk-WWLJMP6D.js +133 -0
  288. package/dist/chunk-WZMLH3XP.js +58 -0
  289. package/dist/chunk-WZYVLUVQ.js +79 -0
  290. package/dist/chunk-X2OCPVU5.js +135 -0
  291. package/dist/chunk-X3CL6DTR.js +95 -0
  292. package/dist/chunk-X6WF7JEV.js +354 -0
  293. package/dist/chunk-XAHGBPWT.js +44 -0
  294. package/dist/chunk-XCKQ5BM2.js +228 -0
  295. package/dist/chunk-XIBYREEY.js +106 -0
  296. package/dist/chunk-XKW5NDMR.js +378 -0
  297. package/dist/chunk-XRDALAO3.js +100 -0
  298. package/dist/chunk-XUP22EAS.js +41 -0
  299. package/dist/chunk-XWAC3MKW.js +243 -0
  300. package/dist/chunk-Y3R7JMXB.js +59 -0
  301. package/dist/chunk-Y54LTP4W.js +82 -0
  302. package/dist/chunk-Y7UECI4M.js +99 -0
  303. package/dist/chunk-YACGDFHC.js +47 -0
  304. package/dist/chunk-YHNIQPKY.js +71 -0
  305. package/dist/chunk-YMBR6HYP.js +111 -0
  306. package/dist/chunk-YMCH3L2S.js +26 -0
  307. package/dist/chunk-Z4ZU6T7V.js +99 -0
  308. package/dist/chunk-ZDPF67ZZ.js +173 -0
  309. package/dist/chunk-ZFC2Q67K.js +101 -0
  310. package/dist/chunk-ZGHNNSCT.js +114 -0
  311. package/dist/chunk-ZGX3ERAT.js +173 -0
  312. package/dist/chunk-ZI3YHEBY.js +37 -0
  313. package/dist/chunk-ZN7G6JLS.js +639 -0
  314. package/dist/chunk-ZNPFQMXT.js +47 -0
  315. package/dist/chunk-ZOU3LV4U.js +63 -0
  316. package/dist/chunk-ZT7B4H2V.js +117 -0
  317. package/dist/chunk-ZZCBDNZI.js +58 -0
  318. package/dist/cli.js +498 -112593
  319. package/dist/computer-tools.js +36642 -21258
  320. package/dist/harness-catalog.cjs +88 -43
  321. package/dist/index.js +1 -1
  322. package/dist/local-model-supervisor.cjs +555 -0
  323. package/package.json +3 -4
@@ -0,0 +1,1301 @@
1
+ import { createRequire as __clikcodeCreateRequire } from 'node:module';
2
+ const require = __clikcodeCreateRequire(import.meta.url);
3
+ import {
4
+ SessionDeltaReceiver,
5
+ interactiveSessionPicker,
6
+ withArgValues
7
+ } from "./chunk-LPCNRGJ7.js";
8
+ import {
9
+ BACKOFF_MS,
10
+ IDE_PROTOCOL,
11
+ REQUEST_TIMEOUT_MS,
12
+ RemoteLink,
13
+ autoUpdates,
14
+ holdWindowMachines,
15
+ localBuildCommit,
16
+ pinnedUpdateLine,
17
+ reachWindowMachine,
18
+ reconnectWindowMachine,
19
+ tapWindowMachine
20
+ } from "./chunk-VEWPCZPG.js";
21
+ import {
22
+ discoverMachines,
23
+ notYetAdded,
24
+ readMachines,
25
+ readTailscaleStatus,
26
+ updatePolicy
27
+ } from "./chunk-X6WF7JEV.js";
28
+ import {
29
+ localMachineName,
30
+ remoteRowValue
31
+ } from "./chunk-Z4ZU6T7V.js";
32
+ import {
33
+ remoteTerminalScript,
34
+ runSsh,
35
+ shellQuote,
36
+ spawnSsh,
37
+ sshArgv
38
+ } from "./chunk-UFQ5A5PW.js";
39
+ import {
40
+ answerWorkerApproval,
41
+ applyLiveEvent,
42
+ drawJoinedTurn,
43
+ newLiveTurnState,
44
+ recordDecision
45
+ } from "./chunk-6ES45HHO.js";
46
+ import {
47
+ replaceWindowBuild
48
+ } from "./chunk-ZGHNNSCT.js";
49
+ import {
50
+ TERMINAL_ONLY_COMMANDS,
51
+ parseSlashInput,
52
+ resolveSlashCommand,
53
+ slashPalette
54
+ } from "./chunk-H4THUNBM.js";
55
+ import {
56
+ chooseOption
57
+ } from "./chunk-ROGXPGYR.js";
58
+ import {
59
+ chatHasContent,
60
+ moveChat,
61
+ movedChatMachine
62
+ } from "./chunk-DAJ76TOC.js";
63
+ import {
64
+ sessionHarness,
65
+ slashExtrasFor
66
+ } from "./chunk-2EOL5PZL.js";
67
+ import {
68
+ drawHarnessOutput
69
+ } from "./chunk-4RHXTL3W.js";
70
+ import {
71
+ copyToClipboard,
72
+ embeddedImageReferences
73
+ } from "./chunk-DCZ6CIUM.js";
74
+ import {
75
+ isTranscriptActivity
76
+ } from "./chunk-UBMVADBF.js";
77
+ import {
78
+ readState
79
+ } from "./chunk-MXS6S2PY.js";
80
+ import {
81
+ sendModeOf
82
+ } from "./chunk-TWCVV2JO.js";
83
+ import {
84
+ runningActivityLabel
85
+ } from "./chunk-FF7ZVYJF.js";
86
+ import {
87
+ backgroundWorkOf
88
+ } from "./chunk-BUOPJQP5.js";
89
+ import {
90
+ failureText
91
+ } from "./chunk-CQ7J6UQ7.js";
92
+ import {
93
+ source_default
94
+ } from "./chunk-LVRRWP4W.js";
95
+ import {
96
+ Conf
97
+ } from "./chunk-GGYKY4GF.js";
98
+ import {
99
+ atomicWriteFile
100
+ } from "./chunk-F6F47QAY.js";
101
+ import {
102
+ quiet
103
+ } from "./chunk-RDDWQBEM.js";
104
+ import {
105
+ stateDirectory
106
+ } from "./chunk-MPAJ446F.js";
107
+
108
+ // src/remote/deadline.ts
109
+ async function remoteDeadline(work, message, ms = 6e4) {
110
+ let timer;
111
+ try {
112
+ return await Promise.race([work, new Promise((_resolve, reject) => {
113
+ timer = setTimeout(() => reject(new Error(message)), ms);
114
+ timer.unref?.();
115
+ })]);
116
+ } finally {
117
+ clearTimeout(timer);
118
+ }
119
+ }
120
+
121
+ // src/remote/terminal-chat.ts
122
+ import { spawn } from "node:child_process";
123
+ import { randomUUID } from "node:crypto";
124
+
125
+ // src/remote/chat-cache.ts
126
+ import { createHash } from "node:crypto";
127
+ import { readdir, readFile, stat, unlink } from "node:fs/promises";
128
+ import { join } from "node:path";
129
+ import { gunzipSync, gzipSync } from "node:zlib";
130
+ var KEEP_CHATS = 40;
131
+ var VERSION = 1;
132
+ function directory() {
133
+ return join(stateDirectory(), "remote", "chats");
134
+ }
135
+ function fileOf(machineId, chatId) {
136
+ return join(directory(), `${createHash("sha256").update(`${machineId}\0${chatId}`).digest("hex").slice(0, 32)}.json.gz`);
137
+ }
138
+ async function readChatCache(machineId, chatId) {
139
+ try {
140
+ const saved = JSON.parse(gunzipSync(await readFile(fileOf(machineId, chatId))).toString("utf8"));
141
+ return saved.v === VERSION && saved.chatId === chatId && Array.isArray(saved.messages) ? { messages: saved.messages, ...saved.gen ? { gen: saved.gen } : {} } : void 0;
142
+ } catch {
143
+ return void 0;
144
+ }
145
+ }
146
+ async function writeChatCache(machineId, chatId, messages, gen) {
147
+ try {
148
+ await atomicWriteFile(fileOf(machineId, chatId), gzipSync(JSON.stringify({ v: VERSION, chatId, ...gen ? { gen } : {}, messages })), { durable: false });
149
+ await prune();
150
+ } catch {
151
+ }
152
+ }
153
+ async function prune() {
154
+ const names = (await readdir(directory())).filter((name) => name.endsWith(".json.gz"));
155
+ if (names.length <= KEEP_CHATS) return;
156
+ const aged = await Promise.all(names.map(async (name) => ({ name, at: (await stat(join(directory(), name))).mtimeMs })));
157
+ aged.sort((a, b) => b.at - a.at);
158
+ await Promise.all(aged.slice(KEEP_CHATS).map(({ name }) => unlink(join(directory(), name)).catch(quiet("remote/chat-cache"))));
159
+ }
160
+ var ChatKeeper = class {
161
+ constructor(machineId, held, pauseMs = 2e3) {
162
+ this.machineId = machineId;
163
+ this.held = held;
164
+ this.pauseMs = pauseMs;
165
+ }
166
+ machineId;
167
+ held;
168
+ pauseMs;
169
+ timer;
170
+ /** Something changed: kept shortly. */
171
+ soon() {
172
+ this.timer ??= setTimeout(() => this.now(), this.pauseMs);
173
+ this.timer.unref?.();
174
+ }
175
+ /** Kept now (the chat is leaving). */
176
+ now() {
177
+ if (this.timer) clearTimeout(this.timer);
178
+ this.timer = void 0;
179
+ const held = this.held();
180
+ if (held?.messages.length) void writeChatCache(this.machineId(), held.sessionId, held.messages, held.gen);
181
+ }
182
+ };
183
+
184
+ // src/remote/attach.ts
185
+ import { readFile as readFile2, stat as stat2 } from "node:fs/promises";
186
+ import { basename } from "node:path";
187
+
188
+ // src/remote/image.ts
189
+ import { dirname } from "node:path";
190
+ async function uploadRemoteImage(target, name, bytes) {
191
+ const suffix = name.toLowerCase().match(/\.(png|jpe?g|gif|webp)$/)?.[1] ?? "png";
192
+ const script = [
193
+ "set -eu",
194
+ "umask 077",
195
+ 'dir=$(mktemp -d "${TMPDIR:-/tmp}/clikcode-image.XXXXXXXX")',
196
+ `file="$dir/image.${suffix}"`,
197
+ 'cat > "$file"',
198
+ 'printf "%s\\n" "$file"'
199
+ ].join("\n");
200
+ return new Promise((resolve, reject) => {
201
+ const child = spawnSsh(target, script);
202
+ const timer = setTimeout(() => {
203
+ child.kill("SIGTERM");
204
+ reject(new Error("Image upload timed out; no message was sent."));
205
+ }, 6e4);
206
+ timer.unref?.();
207
+ let stdout = "";
208
+ let stderr = "";
209
+ child.stdout.on("data", (chunk) => {
210
+ stdout += chunk.toString("utf8");
211
+ });
212
+ child.stderr.on("data", (chunk) => {
213
+ stderr = `${stderr}${chunk.toString("utf8")}`.slice(-16e3);
214
+ });
215
+ child.stdin.on("error", () => void 0);
216
+ child.once("error", (error) => {
217
+ clearTimeout(timer);
218
+ reject(error);
219
+ });
220
+ child.once("close", (code) => {
221
+ clearTimeout(timer);
222
+ const path = stdout.trim();
223
+ if (code !== 0 || !/^\/[^\n]*\/clikcode-image\.[^/]+\/image\.(?:png|jpe?g|gif|webp)$/.test(path)) {
224
+ reject(new Error(failureText(stderr) || "Could not save the image on the remote machine."));
225
+ } else resolve(path);
226
+ });
227
+ child.stdin.end(bytes);
228
+ });
229
+ }
230
+ async function removeRemoteImage(target, path) {
231
+ if (!/^\/[^\n]*\/clikcode-image\.[^/]+\/image\.(?:png|jpe?g|gif|webp)$/.test(path)) return;
232
+ const folder = dirname(path);
233
+ await runSsh(target, `rm -f ${shellQuote(path)}; rmdir ${shellQuote(folder)} 2>/dev/null || true`, { timeoutMs: 1e4 });
234
+ }
235
+
236
+ // src/remote/attach.ts
237
+ var IMAGE_MAX_BYTES = 20 * 1024 * 1024;
238
+ var RemoteImages = class {
239
+ constructor(target, workspace = () => process.cwd(), upload = uploadRemoteImage, remove = removeRemoteImage) {
240
+ this.target = target;
241
+ this.workspace = workspace;
242
+ this.upload = upload;
243
+ this.remove = remove;
244
+ }
245
+ target;
246
+ workspace;
247
+ upload;
248
+ remove;
249
+ /** This computer's path -> the path on the machine, for the images already copied. */
250
+ copied = /* @__PURE__ */ new Map();
251
+ /** `text` as the machine should be sent it: every image it names that is a file here, copied there, named as it is there. */
252
+ async forMachine(text) {
253
+ let sent = text;
254
+ for (const { token, path } of await embeddedImageReferences(text, this.workspace())) {
255
+ let there = this.copied.get(path);
256
+ if (!there) {
257
+ const info = await stat2(path);
258
+ if (info.size > IMAGE_MAX_BYTES) throw new Error(`${basename(path)} is over 20 MiB: images are limited to that.`);
259
+ there = await this.upload(this.target, basename(path), await readFile2(path));
260
+ this.copied.set(path, there);
261
+ }
262
+ sent = sent.split(token).join(there);
263
+ }
264
+ return sent;
265
+ }
266
+ /** Once submitted, only the receiving host owns these files. It retains
267
+ * them before dispatch; leaving this view cannot delete an agent's inputs. */
268
+ handoff(text) {
269
+ for (const [here, there] of this.copied) if (text.includes(there)) this.copied.delete(here);
270
+ }
271
+ /** Remove only staging files never handed to the receiving host. */
272
+ async release() {
273
+ const paths = [...this.copied.values()];
274
+ this.copied.clear();
275
+ await Promise.all(paths.map((path) => this.remove(this.target, path).catch(quiet("remote/attach"))));
276
+ }
277
+ };
278
+
279
+ // src/commands/ai/interactive/board.ts
280
+ var BOARD_OWNS = /* @__PURE__ */ new Set(["resume"]);
281
+ var DELETED_ELSEWHERE = "That conversation was deleted \xB7 this is a new one";
282
+ var BOARD_LINE = "\0board";
283
+ function joinedTurn(session, runningPrompt) {
284
+ const pending = session.pendingTurn;
285
+ if (!pending || runningPrompt !== void 0 && pending.prompt.trim() !== runningPrompt.trim()) return void 0;
286
+ const startedAt = Date.parse(pending.startedAt);
287
+ const activity = runningActivityLabel(pending);
288
+ return { ...Number.isNaN(startedAt) ? {} : { startedAt }, ...activity ? { activity } : {} };
289
+ }
290
+ function conversationCommands(session, state) {
291
+ const harness = sessionHarness(session);
292
+ return withArgValues(slashPalette(session, harness, { ...slashExtrasFor(session, harness), omit: BOARD_OWNS }), session, harness, state);
293
+ }
294
+
295
+ // src/remote/terminal-chat.ts
296
+ var RECLAIM_REVISION = 6;
297
+ function remoteResume(chatId) {
298
+ return { type: "open", mode: "resume", sessionId: chatId, features: REMOTE_FEATURES };
299
+ }
300
+ var REMOTE_FEATURES = ["session-delta", "copy"];
301
+ var TerminalBridge = class {
302
+ constructor(target, start, requestTimeoutMs = REQUEST_TIMEOUT_MS, link) {
303
+ this.target = target;
304
+ this.requestTimeoutMs = requestTimeoutMs;
305
+ this.ready = new Promise((resolve, reject) => {
306
+ const timer = setTimeout(() => reject(new Error(`No answer from ${target}`)), 3e4);
307
+ const chatEvent = (sent) => {
308
+ const event = this.delta.expand(sent);
309
+ if (event.type === "ready") {
310
+ this.wasReady = true;
311
+ clearTimeout(timer);
312
+ resolve();
313
+ }
314
+ if (event.type === "result") {
315
+ const waiter = this.pending.get(event.requestId);
316
+ if (waiter) {
317
+ this.pending.delete(event.requestId);
318
+ event.ok ? waiter.resolve(event.data) : waiter.reject(new Error(event.error ?? "Remote request failed"));
319
+ }
320
+ }
321
+ this.onEvent(event);
322
+ };
323
+ const ended = (failure) => {
324
+ this.stopped = true;
325
+ clearTimeout(timer);
326
+ reject(failure);
327
+ for (const waiter of this.pending.values()) waiter.reject(failure);
328
+ this.pending.clear();
329
+ void this.own?.stop();
330
+ if (!this.closing) {
331
+ this.dropped = failure;
332
+ this.onClose(failure);
333
+ }
334
+ };
335
+ const handlers = {
336
+ event: chatEvent,
337
+ ended: (failure, retiring) => {
338
+ if (retiring) this.retiring = true;
339
+ ended(failure);
340
+ }
341
+ };
342
+ const attach = (tap) => {
343
+ this.tap = tap;
344
+ if (!tap) {
345
+ ended(new Error(`The connection to ${target} is not up`));
346
+ return;
347
+ }
348
+ this.outdated = tap.outdated;
349
+ this.revision = tap.revision;
350
+ };
351
+ if (link) {
352
+ attach(link(this.chat, handlers));
353
+ return;
354
+ }
355
+ const own = new RemoteLink({ id: `own-${this.chat}`, name: target, sshTarget: target, addedAt: "" }, () => {
356
+ if (this.tap || this.stopped) return;
357
+ if (own.view.state === "connected") attach(own.tap(this.chat, handlers));
358
+ else if (own.view.state === "offline") ended(new Error(own.view.error ?? `The connection to ${target} ended`));
359
+ }, { board: false, autoUpdate: false, wanted: () => false, ...start ? { spawn: (to) => start(to) } : {} });
360
+ this.own = own;
361
+ own.start();
362
+ });
363
+ }
364
+ target;
365
+ requestTimeoutMs;
366
+ own;
367
+ tap;
368
+ chat = randomUUID();
369
+ pending = /* @__PURE__ */ new Map();
370
+ ready;
371
+ stopped = false;
372
+ closing = false;
373
+ /** Its ClikCode is another build than this one (connection.ts needsUpdate). */
374
+ outdated = false;
375
+ /** Which additive requests it answers (protocol-version.ts); 1 when it did not say. */
376
+ revision = 1;
377
+ /** It said it is leaving for a newer build installed there (ide/bridge-retire.ts):
378
+ * the close that follows is a reconnect, not a lost connection. */
379
+ retiring = false;
380
+ /** The connection closed without this window asking: why, in the bridge's own words. */
381
+ dropped;
382
+ /** The chat there answered `ready` at least once: what closes after is a drop, not a refusal to start. */
383
+ wasReady = false;
384
+ onEvent = () => void 0;
385
+ /** The conversation as the bridge last sent it: its events made whole again. */
386
+ delta = new SessionDeltaReceiver();
387
+ onClose = () => void 0;
388
+ async connected() {
389
+ return this.ready;
390
+ }
391
+ /** The chat kept from last time as held: the next `open` of it says so. */
392
+ preload(sessionId, messages, gen) {
393
+ this.delta.preload(sessionId, messages, gen);
394
+ }
395
+ /** The conversation as held now, to keep for next time. */
396
+ held() {
397
+ return this.delta.current();
398
+ }
399
+ /** `open` of `sessionId`, saying what is already held of it. */
400
+ async resume(sessionId) {
401
+ const held = this.delta.claim(sessionId);
402
+ const opened = await this.request({ ...remoteResume(sessionId), ...held ? { held } : {} });
403
+ this.delta.generation(sessionId, opened?.gen);
404
+ return opened;
405
+ }
406
+ post(request) {
407
+ if (this.stopped || !this.tap) throw new Error("Remote connection closed");
408
+ this.tap.post(request);
409
+ }
410
+ request(request) {
411
+ const requestId = randomUUID();
412
+ const result = new Promise((resolve, reject) => {
413
+ const timer = setTimeout(() => {
414
+ this.pending.delete(requestId);
415
+ reject(new Error(`${this.target} did not answer "${request.type}" within ${this.requestTimeoutMs / 1e3}s`));
416
+ }, this.requestTimeoutMs);
417
+ timer.unref();
418
+ this.pending.set(requestId, { resolve: (value) => {
419
+ clearTimeout(timer);
420
+ resolve(value);
421
+ }, reject: (error) => {
422
+ clearTimeout(timer);
423
+ reject(error);
424
+ } });
425
+ });
426
+ this.post({ ...request, requestId });
427
+ return result;
428
+ }
429
+ close() {
430
+ if (this.stopped) return;
431
+ this.closing = true;
432
+ if (this.tap) {
433
+ this.post({ type: "close" });
434
+ this.tap.detach();
435
+ }
436
+ this.stopped = true;
437
+ void this.own?.stop();
438
+ }
439
+ };
440
+ async function answerInSignIn(bridge, screen, event) {
441
+ const request = event.request;
442
+ const cancelled = new Promise((resolve) => {
443
+ if (screen.signal.aborted) resolve(void 0);
444
+ else screen.signal.addEventListener("abort", () => resolve(void 0), { once: true });
445
+ });
446
+ let result;
447
+ if (request.kind === "input") {
448
+ const text = await Promise.race([screen.ask(request.prompt, Boolean(request.secret)), cancelled]);
449
+ result = text === void 0 ? { cancelled: true } : { text };
450
+ } else {
451
+ const index = await Promise.race([screen.choose(request.title, request.items.map((item) => item.label)), cancelled]);
452
+ result = index === void 0 ? { cancelled: true } : { index };
453
+ }
454
+ bridge.post({ type: "ui-response", id: event.id, result });
455
+ }
456
+ async function answerUi(bridge, terminal, event) {
457
+ const request = event.request;
458
+ let result;
459
+ if (request.kind === "input") {
460
+ try {
461
+ result = { text: await terminal.question(`${request.prompt} \u203A `, [], { cancellable: true, secret: request.secret }) };
462
+ } catch {
463
+ result = { cancelled: true };
464
+ }
465
+ } else {
466
+ const choices = request.items.flatMap((item, index) => [
467
+ { label: item.label, detail: item.detail, group: item.group, value: { index } },
468
+ ...item.inline?.choices.map((choice) => ({
469
+ label: ` ${choice.label}`,
470
+ detail: choice.value === item.inline?.current ? "\xB7 current" : void 0,
471
+ value: { index, value: choice.value }
472
+ })) ?? [],
473
+ ...item.actions?.map((action) => ({ label: ` ${action.label}`, value: { index, action: action.value } })) ?? [],
474
+ ...item.deleteAction ? [{ label: ` ${item.deleteAction.label}`, value: { index, action: item.deleteAction.value } }] : []
475
+ ]);
476
+ result = await terminal.select(request.title, choices) ?? { cancelled: true };
477
+ }
478
+ bridge.post({ type: "ui-response", id: event.id, result });
479
+ }
480
+ async function runSignIn(target, spec, terminal) {
481
+ await terminal.suspend();
482
+ try {
483
+ await new Promise((resolve, reject) => {
484
+ const child = spawn("ssh", sshArgv(target, remoteTerminalScript(spec), ["-tt"]), { stdio: "inherit" });
485
+ child.once("error", reject);
486
+ child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`Remote sign-in exited ${code ?? "?"}`)));
487
+ });
488
+ } finally {
489
+ terminal.resume();
490
+ }
491
+ }
492
+ var COMMANDS_WAIT_MS = 3e3;
493
+ var TERMINAL_HANDLED = ["machine", "select", "redraw", "exit"];
494
+ function remotePalette(commands) {
495
+ const rows = commands.filter((item) => !BOARD_OWNS.has(item.command.replace(/^\//, "").toLowerCase())).map((item) => {
496
+ const values = item.argValues ? [...item.argValues] : void 0;
497
+ return {
498
+ label: item.command,
499
+ value: item.command,
500
+ detail: item.description,
501
+ ...item.argHint ? { argHint: item.argHint } : {},
502
+ ...item.group ? { group: item.group } : {},
503
+ ...item.aliases?.length ? { aliases: item.aliases } : {},
504
+ ...values?.length ? { argValues: () => values } : {}
505
+ };
506
+ });
507
+ for (const name of TERMINAL_HANDLED) {
508
+ const entry = resolveSlashCommand(name);
509
+ if (!entry || rows.some((row) => row.value === `/${name}`)) continue;
510
+ rows.push({ label: `/${name}`, value: `/${name}`, detail: entry.description, group: entry.group, ...entry.argHint ? { argHint: entry.argHint } : {} });
511
+ }
512
+ return rows;
513
+ }
514
+ function outdatedNotice(machine, updating, localCommit = localBuildCommit()) {
515
+ const differs = `${machine.name} runs another ClikCode build than this one`;
516
+ if (updating) return `${differs}: updating it to this one's${localCommit ? ` (${localCommit.slice(0, 8)})` : ""} in the background; its chats switch over once they are quiet.`;
517
+ const how = "Type /update to update it, or Tab on it in /machine.";
518
+ if (machine.updateError && updatePolicy(machine) === "auto") return `${differs}, and updating it failed (${machine.updateError}). ${how}`;
519
+ return `${differs}. ${how}`;
520
+ }
521
+ var REJOIN_PAUSES_MS = BACKOFF_MS.slice(0, 5);
522
+ var REACH_MS = 2e4;
523
+ var RemoteUnavailable = class extends Error {
524
+ constructor(message, options) {
525
+ super(message, options);
526
+ this.name = "RemoteUnavailable";
527
+ }
528
+ };
529
+ async function runRemoteChat(terminal, localId, first, firstDraft, startBridge, pauses = REJOIN_PAUSES_MS, reachMs = REACH_MS) {
530
+ let choice = first;
531
+ let draft = firstDraft;
532
+ let rejoining = false;
533
+ let drops = 0;
534
+ while (choice) {
535
+ const machine = (await readMachines()).find((item) => item.id === choice.machineId && item.ready);
536
+ if (!machine) throw new Error("That remote machine is no longer added. Add it again with /machine.");
537
+ terminal.remoteMachineName = machine.name;
538
+ if (!startBridge) {
539
+ const saying = setTimeout(() => terminal.activity(`Connecting to ${machine.name}\u2026`), 700);
540
+ const reached = await reachWindowMachine(machine.id, reachMs).finally(() => clearTimeout(saying));
541
+ if (!reached.ok) {
542
+ terminal.remoteMachineName = void 0;
543
+ throw new RemoteUnavailable(`${machine.name} cannot be reached: ${reached.reason}`);
544
+ }
545
+ }
546
+ const bridge = new TerminalBridge(machine.sshTarget, startBridge, void 0, startBridge ? void 0 : (chat, handlers) => tapWindowMachine(machine.id, chat, handlers));
547
+ terminal.subAgentRead = (parentId) => bridge.request({ type: "subagent", parentId, action: "read" }).then((data) => data?.rows ?? []);
548
+ terminal.subAgentSteer = (ref, text) => bridge.request({ type: "subagent", parentId: ref.id, action: "steer", text, ...ref.agentId ? { agentId: ref.agentId } : {} }).then(() => void 0, (error) => error instanceof Error ? error.message : String(error));
549
+ const images = new RemoteImages(machine.sshTarget);
550
+ let session;
551
+ let account;
552
+ let running = false;
553
+ let waitingInput = false;
554
+ let leftTurn = false;
555
+ let wakePrompt;
556
+ const followChat = (id) => {
557
+ if (choice && choice.chatId !== id) choice = { ...choice, chatId: id };
558
+ };
559
+ let finishTurn;
560
+ let turnEnd;
561
+ let sending;
562
+ let early;
563
+ let held = [];
564
+ const flushHeld = () => {
565
+ const notes = held;
566
+ held = [];
567
+ for (const note of notes) terminal.activity(note);
568
+ };
569
+ const dropEarly = () => {
570
+ if (early === void 0) return;
571
+ early = void 0;
572
+ terminal.submitted(void 0);
573
+ if (!running && terminal.turn) terminal.stopWaiting();
574
+ flushHeld();
575
+ };
576
+ const liveTurn = newLiveTurnState();
577
+ const openPrompts = /* @__PURE__ */ new Map();
578
+ const completions = /* @__PURE__ */ new Map();
579
+ const typed = /* @__PURE__ */ new Map();
580
+ const promptController = new AbortController();
581
+ const signIns = /* @__PURE__ */ new Map();
582
+ const vendorAsking = /* @__PURE__ */ new Set();
583
+ const commands = [];
584
+ let commandsFor;
585
+ const refreshCommands = () => bridge.request({ type: "query", query: "slash-commands" }).then(
586
+ (list) => {
587
+ commands.splice(0, commands.length, ...remotePalette(Array.isArray(list) ? list : []));
588
+ },
589
+ // fail-open-ok: the machine did not list its commands now; the menu keeps what it had (or /machine alone).
590
+ () => {
591
+ if (!commands.length) commands.push(...remotePalette([]));
592
+ }
593
+ );
594
+ const keeper = new ChatKeeper(() => machine.id, () => bridge.held());
595
+ const sessionChanged = (next) => {
596
+ const key = [next.id, next.route, next.nativeHarness, next.provider, next.model, next.accountId, next.effort, next.permissionMode, next.gatewayAgentId].join("|");
597
+ if (commandsFor !== void 0 && key !== commandsFor) void refreshCommands();
598
+ commandsFor = key;
599
+ };
600
+ const submissions = /* @__PURE__ */ new Map();
601
+ const queued = async (text, windowId) => {
602
+ const id = windowId ?? randomUUID();
603
+ const submission = { id, text, submittedAt: (/* @__PURE__ */ new Date()).toISOString() };
604
+ const answered = new Promise((resolve, reject) => {
605
+ submissions.set(id, { text, resolve, reject });
606
+ });
607
+ try {
608
+ const wire = await images.forMachine(text).catch((error) => {
609
+ terminal.activity(source_default.yellow(`Could not copy the image to ${machine.name}: ${error instanceof Error ? error.message : String(error)}`));
610
+ throw error;
611
+ });
612
+ const mode = await readState({ transcripts: [] }).then((state) => sendModeOf(state.globalSettings), () => void 0);
613
+ bridge.post({ type: "send", text: wire, id, ...mode ? { mode } : {} });
614
+ images.handoff(wire);
615
+ const answer = await remoteDeadline(answered, "Delivery was not confirmed. The message may already be queued; reopen the chat before resending.");
616
+ if (answer.disposition === "error") throw new Error(answer.message ?? "message not sent");
617
+ return { disposition: answer.disposition, submission, ...answer.commandOutcome ? { commandOutcome: answer.commandOutcome } : {} };
618
+ } finally {
619
+ submissions.delete(id);
620
+ }
621
+ };
622
+ const windowCommandOrQueued = async (text, windowId) => {
623
+ const own = resolveSlashCommand(parseSlashInput(text)?.head ?? "")?.name;
624
+ if (own !== "restart" && own !== "send") return queued(text, windowId);
625
+ const submission = { id: windowId ?? randomUUID(), text, submittedAt: (/* @__PURE__ */ new Date()).toISOString() };
626
+ if (own === "restart") {
627
+ const leaving = replaceWindowBuild();
628
+ if (leaving) void leaving;
629
+ else terminal.activity("This window already runs the newest ClikCode.");
630
+ } else {
631
+ const { aiSessionCommand } = await import("./chunk-5QNNW5L6.js");
632
+ await aiSessionCommand(localId, text).catch((error) => terminal.activity(error instanceof Error ? error.message : String(error)));
633
+ }
634
+ return { disposition: "command", submission, commandOutcome: "applied" };
635
+ };
636
+ const takeBacks = /* @__PURE__ */ new Map();
637
+ const takeBack = (id) => {
638
+ const answered = new Promise((resolve) => {
639
+ takeBacks.set(id, resolve);
640
+ });
641
+ try {
642
+ bridge.post({ type: "unqueue", id });
643
+ } catch {
644
+ takeBacks.delete(id);
645
+ return Promise.resolve("error");
646
+ }
647
+ return remoteDeadline(answered, "Take-back was not confirmed; the message may still be queued.").catch((error) => {
648
+ terminal.activity(error instanceof Error ? error.message : String(error));
649
+ return "error";
650
+ }).finally(() => takeBacks.delete(id));
651
+ };
652
+ let wakeLeave;
653
+ const leave = () => {
654
+ leftTurn = true;
655
+ waitingInput = false;
656
+ finishTurn?.();
657
+ terminal.leaveTurn();
658
+ wakeLeave?.();
659
+ };
660
+ const beginWaiting = (prompt, label = "thinking") => {
661
+ if (waitingInput) return;
662
+ waitingInput = true;
663
+ turnEnd = new Promise((resolve) => {
664
+ finishTurn = resolve;
665
+ });
666
+ if (prompt !== void 0) terminal.submitted(prompt);
667
+ terminal.startWaiting(
668
+ label,
669
+ (restoreDraft) => bridge.post({ type: "cancel", restoreDraft }),
670
+ queued,
671
+ windowCommandOrQueued,
672
+ leave,
673
+ // Esc on a waiting message takes that message back, and does not stop the turn; "Enter again" offers it to the running turn now.
674
+ takeBack,
675
+ () => bridge.post({ type: "send-queued" })
676
+ );
677
+ };
678
+ const handleEvent = (event) => {
679
+ switch (event.type) {
680
+ // While a message drawn early waits for its turn, the chat is drawn as a turn's (run-turn.ts renders so too).
681
+ case "session":
682
+ session = event.session;
683
+ account = event.account;
684
+ followChat(session.id);
685
+ sessionChanged(session);
686
+ keeper.soon();
687
+ terminal.render(session, account, { running: running || early !== void 0 });
688
+ return;
689
+ case "turn-start":
690
+ for (const [id, pending] of submissions) {
691
+ if (event.submissionId ? id === event.submissionId : pending.text === event.prompt) pending.resolve({ type: "submission", id, disposition: "queued" });
692
+ }
693
+ for (const [id, text] of typed) if (event.submissionId ? id === event.submissionId : text === event.prompt) typed.delete(id);
694
+ applyLiveEvent(liveTurn, { type: "waiting-start", message: "", ...event.prompt !== void 0 ? { prompt: event.prompt } : {} });
695
+ early = void 0;
696
+ running = true;
697
+ beginWaiting(event.prompt);
698
+ flushHeld();
699
+ return;
700
+ case "worker": {
701
+ const worker = event.event;
702
+ applyLiveEvent(liveTurn, worker);
703
+ if (worker.type === "snapshot") {
704
+ session = worker.session;
705
+ account = worker.account;
706
+ followChat(session.id);
707
+ sessionChanged(session);
708
+ running = Boolean(worker.live);
709
+ if (worker.stopped) terminal.turnStopped();
710
+ terminal.render(session, account, worker.live ? { running: true, prompt: worker.live.prompt } : { running: early !== void 0 });
711
+ if (worker.live) {
712
+ beginWaiting(worker.live.prompt, worker.live.vendorWork ? worker.live.waitingLabel : void 0);
713
+ const startedAt = Date.parse(worker.session.pendingTurn?.startedAt ?? "");
714
+ terminal.joinedWaiting(Number.isNaN(startedAt) ? void 0 : startedAt);
715
+ drawJoinedTurn(terminal, liveTurn);
716
+ terminal.setBackgroundWork?.(worker.background ?? backgroundWorkOf(worker.live));
717
+ terminal.setSteerable(Boolean(worker.live.steerable));
718
+ }
719
+ } else if (worker.type === "delta") terminal.response(worker.text, worker.mode);
720
+ else if (worker.type === "activity") {
721
+ const index = liveTurn.running && isTranscriptActivity(worker.event) ? liveTurn.activities.length - 1 : -1;
722
+ const recorded = liveTurn.activities[index];
723
+ terminal.activityEvent(worker.event, recorded ? { index, responseOffset: recorded.responseOffset } : void 0);
724
+ } else if (worker.type === "background") terminal.setBackgroundWork?.(backgroundWorkOf({ background: worker.work, pendingBackground: worker.pending }));
725
+ else if (worker.type === "note") terminal.activity(worker.message, worker.seq === void 0 ? void 0 : `notice:${worker.seq}`);
726
+ else if (worker.type === "phase") terminal.phase(worker.message);
727
+ else if (worker.type === "plan") terminal.setPlan(worker.entries);
728
+ else if (worker.type === "restore-draft") terminal.restoreDraft(worker.text);
729
+ else if (worker.type === "waiting-stop") {
730
+ if (worker.stopped) terminal.turnStopped();
731
+ running = false;
732
+ waitingInput = false;
733
+ terminal.stopWaiting();
734
+ finishTurn?.();
735
+ } else if (worker.type === "turn-error" && !worker.said) terminal.activity(worker.message);
736
+ else if (worker.type === "approval-request") {
737
+ const closing = new AbortController();
738
+ openPrompts.set(worker.id, closing);
739
+ void answerWorkerApproval(terminal, worker, closing.signal, (approved) => bridge.post({ type: "approval-response", id: worker.id, approved })).finally(() => openPrompts.delete(worker.id));
740
+ } else if (worker.type === "question-request") {
741
+ const closing = new AbortController();
742
+ openPrompts.set(worker.id, closing);
743
+ void terminal.askQuestions(worker.request, closing.signal).catch(() => ({ kind: "cancelled" })).then((result) => {
744
+ openPrompts.delete(worker.id);
745
+ if (!closing.signal.aborted) {
746
+ terminal.markDrawn?.(`outcome:${worker.id}`);
747
+ bridge.post({ type: "question-response", id: worker.id, result });
748
+ }
749
+ });
750
+ } else if (worker.type === "request-closed") {
751
+ if (openPrompts.has(worker.id)) {
752
+ const decided = recordDecision(liveTurn, worker);
753
+ if (decided) terminal.joinMark(decided);
754
+ }
755
+ openPrompts.get(worker.id)?.abort();
756
+ openPrompts.delete(worker.id);
757
+ } else if (worker.type === "submission") {
758
+ submissions.get(worker.id)?.resolve(worker);
759
+ const text = typed.get(worker.id);
760
+ if (text !== void 0 && (worker.disposition === "steered" || worker.disposition === "queued")) {
761
+ typed.delete(worker.id);
762
+ dropEarly();
763
+ running = true;
764
+ beginWaiting(liveTurn.prompt);
765
+ terminal.adoptSubmission(worker.id, text, worker.disposition);
766
+ }
767
+ } else if (worker.type === "submit-queued") dropEarly();
768
+ else if (worker.type === "waiting-start") {
769
+ running = true;
770
+ wakePrompt?.();
771
+ beginWaiting(worker.prompt, worker.vendorWork ? worker.message : void 0);
772
+ } else if (worker.type === "unqueued") takeBacks.get(worker.id)?.(worker.outcome);
773
+ else if (worker.type === "steerable") terminal.setSteerable(worker.value);
774
+ else if (worker.type === "stopping") terminal.turnStopping(worker.restoreDraft === true);
775
+ else if (worker.type === "stop-done") terminal.stopSettled();
776
+ return;
777
+ }
778
+ case "ui-request": {
779
+ const open = [...signIns].at(-1);
780
+ if (open) {
781
+ const [id, screen] = open;
782
+ if (event.request.kind === "input") vendorAsking.add(id);
783
+ void answerInSignIn(bridge, screen, event).finally(() => vendorAsking.delete(id));
784
+ return;
785
+ }
786
+ if (!running && terminal.turn) terminal.stopWaiting(false);
787
+ void answerUi(bridge, terminal, event).catch((error) => {
788
+ terminal.activity(error instanceof Error ? error.message : String(error));
789
+ bridge.post({ type: "ui-response", id: event.id, result: { cancelled: true } });
790
+ });
791
+ return;
792
+ }
793
+ case "sign-in":
794
+ void runSignIn(machine.sshTarget, event.spec, terminal).then(
795
+ () => bridge.post({ type: "sign-in-result", id: event.id }),
796
+ (error) => bridge.post({ type: "sign-in-result", id: event.id, error: error instanceof Error ? error.message : String(error) })
797
+ );
798
+ return;
799
+ case "sign-in-link": {
800
+ let screen = signIns.get(event.id);
801
+ if (event.done) {
802
+ screen?.stop();
803
+ signIns.delete(event.id);
804
+ vendorAsking.delete(event.id);
805
+ return;
806
+ }
807
+ if (!screen) {
808
+ screen = terminal.signInScreen(event.name);
809
+ signIns.set(event.id, screen);
810
+ screen.signal.addEventListener("abort", () => bridge.post({ type: "sign-in-cancel", id: event.id }), { once: true });
811
+ }
812
+ if (event.url) screen.show({ url: event.url, ...event.code ? { code: event.code } : {} });
813
+ if (event.ask && !vendorAsking.has(event.id)) void screen.ask(event.ask.prompt, Boolean(event.ask.secret), false, true).then((text) => bridge.post({ type: "sign-in-answer", id: event.id, text }));
814
+ return;
815
+ }
816
+ case "usage":
817
+ terminal.usage(event.label, event.reset);
818
+ return;
819
+ case "notice":
820
+ if (early !== void 0 && !running) {
821
+ held.push(event.message);
822
+ return;
823
+ }
824
+ terminal.activity(event.message);
825
+ return;
826
+ case "panel":
827
+ terminal.panel(event.title, event.body);
828
+ return;
829
+ // A command's text result (/status, /usage, /help, /history ...): drawn as a chat here draws it. Dropped, most commands showed nothing.
830
+ case "output":
831
+ drawHarnessOutput(terminal, event.payload);
832
+ return;
833
+ // The machine wrote a file for the user (/export, /memory edit): it is there, not here, and is said so.
834
+ case "open-file":
835
+ terminal.activity(`On ${machine.name}: ${event.path}`);
836
+ return;
837
+ // /copy: the clipboard is this computer's, where the user is -- the machine's would fill a clipboard nobody is at.
838
+ case "copy":
839
+ void copyToClipboard(event.text).then(() => terminal.activity("Copied to the clipboard."), (error) => terminal.activity(error instanceof Error ? error.message : String(error)));
840
+ return;
841
+ case "restore-draft":
842
+ terminal.restoreDraft(event.text);
843
+ return;
844
+ case "send-complete":
845
+ if (completions.has(event.id)) dropEarly();
846
+ completions.get(event.id)?.resolve();
847
+ completions.delete(event.id);
848
+ return;
849
+ // Its last lines (an /update's steps) are drawn before the wait ends.
850
+ // Before a message drawn early starts (a local model loading there): the same wait, relabelled.
851
+ case "busy":
852
+ if (early !== void 0) {
853
+ if (event.label) terminal.updateWaitingLabel(event.label);
854
+ return;
855
+ }
856
+ if (event.label) terminal.startWaiting(event.label);
857
+ else if (!running) {
858
+ terminal.flushPaint();
859
+ terminal.stopWaiting();
860
+ }
861
+ return;
862
+ // Deleted or archived there: this chat is gone, so the list is what is left to show -- not a prompt to a chat that no longer exists.
863
+ case "closed":
864
+ terminal.activity("This conversation closed on the remote machine.");
865
+ leftTurn = true;
866
+ wakePrompt?.();
867
+ return;
868
+ }
869
+ };
870
+ bridge.onEvent = handleEvent;
871
+ bridge.onClose = (error) => {
872
+ dropEarly();
873
+ promptController.abort();
874
+ finishTurn?.();
875
+ for (const completion of completions.values()) completion.reject(error);
876
+ completions.clear();
877
+ for (const pending of submissions.values()) pending.reject(error);
878
+ submissions.clear();
879
+ for (const resolve of takeBacks.values()) resolve("error");
880
+ takeBacks.clear();
881
+ };
882
+ try {
883
+ await bridge.connected();
884
+ terminal.activityDetails = bridge.revision >= 10 ? (ids, messageIndex) => bridge.request({ type: "activity-details", ids, messageIndex }) : void 0;
885
+ const selection = choice;
886
+ const kept = selection.chatId ? await readChatCache(machine.id, selection.chatId) : void 0;
887
+ if (kept && selection.chatId) bridge.preload(selection.chatId, kept.messages, kept.gen);
888
+ terminal.holdPaints();
889
+ let opened;
890
+ try {
891
+ opened = await (selection.chatId ? bridge.resume(selection.chatId) : bridge.request({ type: "open", mode: "new", features: REMOTE_FEATURES }));
892
+ } finally {
893
+ terminal.releasePaints();
894
+ }
895
+ if (!selection.chatId && opened?.sessionId) choice = { ...selection, chatId: opened.sessionId };
896
+ if (bridge.outdated && !rejoining) {
897
+ const started = await autoUpdates.consider(machine).catch(quiet("remote/terminal-chat"));
898
+ terminal.activity(outdatedNotice(machine, Boolean(started)));
899
+ void started?.done.then((outcome) => {
900
+ if (outcome.ok) reconnectWindowMachine(machine.id);
901
+ terminal.activity(outcome.ok ? `ClikCode on ${machine.name} is updated${outcome.info.commit ? ` to ${outcome.info.commit.slice(0, 8)}` : ""}; its chats switch over once they are quiet.` : `ClikCode on ${machine.name} could not be updated -- type /update to try again: ${outcome.message}`);
902
+ }, () => void 0);
903
+ }
904
+ if (!rejoining && session?.movedTo) {
905
+ const copy = session;
906
+ const live = await liveChat(copy.movedTo, async () => {
907
+ if (bridge.revision < RECLAIM_REVISION) throw new Error(`This chat moved to ${copy.movedTo.machine}, which does not answer, and ClikCode on ${machine.name} is too old to go on with it: update it (Tab on it in /machine).`);
908
+ await bridge.request({ type: "reclaim-moved", sessionId: copy.id });
909
+ return { remote: { machineId: machine.id, chatId: copy.id } };
910
+ });
911
+ if (live.notice) terminal.activity(live.notice);
912
+ if ("local" in live.here) return live.here.local;
913
+ if (live.here.remote.machineId !== machine.id || live.here.remote.chatId !== copy.id) {
914
+ choice = live.here.remote;
915
+ continue;
916
+ }
917
+ }
918
+ await Promise.race([refreshCommands(), new Promise((resolve) => {
919
+ setTimeout(resolve, COMMANDS_WAIT_MS).unref?.();
920
+ })]);
921
+ if (draft) terminal.restoreDraft(draft);
922
+ draft = void 0;
923
+ rejoining = false;
924
+ drops = 0;
925
+ let setupSession;
926
+ const prepareBoardDraft = async () => {
927
+ if (setupSession && setupSession === session?.id && !chatHasContent(session)) return;
928
+ const opened2 = await bridge.request({ type: "open", mode: "new", ...session?.workspace ? { workspace: session.workspace } : {}, features: REMOTE_FEATURES });
929
+ setupSession = opened2?.sessionId ?? session?.id;
930
+ if (setupSession) choice = { machineId: machine.id, chatId: setupSession };
931
+ await refreshCommands();
932
+ };
933
+ for (; ; ) {
934
+ if (waitingInput) await turnEnd;
935
+ let line;
936
+ if (leftTurn) line = BOARD_LINE;
937
+ else {
938
+ const wake = new AbortController();
939
+ wakePrompt = () => wake.abort();
940
+ try {
941
+ line = (await terminal.question("\u203A ", commands, { conversation: true, rightArrowPalette: true, leftArrowCommand: BOARD_LINE, signal: AbortSignal.any([promptController.signal, wake.signal]) })).trim();
942
+ } catch (error) {
943
+ if (wake.signal.aborted && !promptController.signal.aborted && error.code === "ERR_PROMPT_INTERRUPTED") continue;
944
+ throw error;
945
+ } finally {
946
+ wakePrompt = void 0;
947
+ }
948
+ }
949
+ leftTurn = false;
950
+ if (line === BOARD_LINE) {
951
+ const picked = await interactiveSessionPicker(terminal, localId, commands, choice?.chatId ? { initial: remoteRowValue(machine.id, choice.chatId) } : void 0);
952
+ if (!picked) continue;
953
+ if ("remote" in picked) {
954
+ choice = picked.remote;
955
+ draft = picked.draft;
956
+ break;
957
+ }
958
+ if ("id" in picked) return picked.id;
959
+ if ("compose" in picked) {
960
+ await prepareBoardDraft();
961
+ terminal.restoreDraft(picked.compose);
962
+ continue;
963
+ }
964
+ if ("command" in picked) {
965
+ await prepareBoardDraft();
966
+ line = picked.command;
967
+ } else {
968
+ if ("new" in picked) await prepareBoardDraft();
969
+ continue;
970
+ }
971
+ }
972
+ if (!line) continue;
973
+ const own = resolveSlashCommand(parseSlashInput(line)?.head ?? "")?.name;
974
+ if (own === "send") {
975
+ const { aiSessionCommand } = await import("./chunk-5QNNW5L6.js");
976
+ await aiSessionCommand(localId, line).catch((error) => terminal.activity(error instanceof Error ? error.message : String(error)));
977
+ continue;
978
+ }
979
+ if (own && TERMINAL_ONLY_COMMANDS.has(own)) {
980
+ if (own === "exit") return { exit: true };
981
+ if (own === "restart") {
982
+ const leaving = replaceWindowBuild();
983
+ if (!leaving) {
984
+ terminal.activity("This window already runs the newest ClikCode.");
985
+ continue;
986
+ }
987
+ await leaving;
988
+ return { exit: true };
989
+ }
990
+ if (own === "redraw" && session) {
991
+ terminal.render(session, account);
992
+ continue;
993
+ }
994
+ const { aiSessionCommand } = await import("./chunk-5QNNW5L6.js");
995
+ await aiSessionCommand(localId, line).catch((error) => terminal.activity(error instanceof Error ? error.message : String(error)));
996
+ continue;
997
+ }
998
+ if (parseSlashInput(line)?.head === "machine") {
999
+ const next = await moveTerminalChat(
1000
+ terminal,
1001
+ { remote: choice },
1002
+ session?.id ?? choice.chatId ?? "",
1003
+ Boolean(session && chatHasContent(session)),
1004
+ remoteMoveEnd(bridge, machine),
1005
+ startBridge
1006
+ ).catch((error) => {
1007
+ terminal.activity(error instanceof Error ? error.message : String(error));
1008
+ return void 0;
1009
+ });
1010
+ if (!next) continue;
1011
+ if ("local" in next) return next.local;
1012
+ choice = next.remote;
1013
+ break;
1014
+ }
1015
+ const id = randomUUID();
1016
+ if (!/^[/!]/.test(line)) setupSession = void 0;
1017
+ const complete = new Promise((resolve, reject) => completions.set(id, { resolve, reject }));
1018
+ sending = line;
1019
+ const stepped = new Promise((resolve) => {
1020
+ wakeLeave = resolve;
1021
+ });
1022
+ if (!/^[/!]/.test(line)) {
1023
+ early = line;
1024
+ typed.set(id, line);
1025
+ terminal.submitted(line);
1026
+ terminal.turnStarting(leave);
1027
+ }
1028
+ let wire;
1029
+ try {
1030
+ wire = await images.forMachine(line);
1031
+ } catch (error) {
1032
+ dropEarly();
1033
+ completions.delete(id);
1034
+ sending = void 0;
1035
+ terminal.activity(source_default.yellow(`Could not copy the image to ${machine.name}: ${error instanceof Error ? error.message : String(error)}`));
1036
+ terminal.restoreDraft(line);
1037
+ continue;
1038
+ }
1039
+ const mode = await readState({ transcripts: [] }).then((state) => sendModeOf(state.globalSettings), () => void 0);
1040
+ try {
1041
+ bridge.post({ type: "send", text: pinnedUpdateLine(wire, localBuildCommit()), id, ...mode ? { mode } : {} });
1042
+ images.handoff(wire);
1043
+ } catch (error) {
1044
+ dropEarly();
1045
+ throw error;
1046
+ }
1047
+ await Promise.race([complete, stepped]);
1048
+ wakeLeave = void 0;
1049
+ sending = void 0;
1050
+ if (parseSlashInput(line)?.head === "update") reconnectWindowMachine(machine.id);
1051
+ if (line.startsWith("/")) void refreshCommands();
1052
+ }
1053
+ } catch (error) {
1054
+ const cause = bridge.dropped;
1055
+ const lost = !bridge.retiring && cause !== void 0 && (bridge.wasReady || rejoining);
1056
+ if (!bridge.retiring && !lost) throw bridge.wasReady || rejoining ? error : new RemoteUnavailable(`${machine.name}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
1057
+ if (lost) {
1058
+ if (startBridge) {
1059
+ if (drops >= pauses.length) throw cause;
1060
+ terminal.activity(source_default.yellow(`Connection to ${machine.name} lost: ${cause.message}
1061
+ Reconnecting${drops ? ` (try ${drops + 1} of ${pauses.length + 1})` : ""}.`));
1062
+ await new Promise((resolve) => {
1063
+ setTimeout(resolve, pauses[drops]).unref?.();
1064
+ });
1065
+ drops += 1;
1066
+ } else {
1067
+ terminal.activity(source_default.yellow(`Connection to ${machine.name} lost: ${cause.message}
1068
+ Reconnecting.`));
1069
+ }
1070
+ }
1071
+ rejoining = true;
1072
+ reconnectWindowMachine(machine.id);
1073
+ if (sending !== void 0) draft = sending;
1074
+ continue;
1075
+ } finally {
1076
+ terminal.activityDetails = void 0;
1077
+ terminal.subAgentRead = void 0;
1078
+ terminal.subAgentSteer = void 0;
1079
+ keeper.now();
1080
+ void images.release();
1081
+ promptController.abort();
1082
+ for (const screen of signIns.values()) screen.stop();
1083
+ bridge.close();
1084
+ terminal.remoteMachineName = void 0;
1085
+ }
1086
+ }
1087
+ return void 0;
1088
+ }
1089
+
1090
+ // src/remote/move-terminal.ts
1091
+ var MOVE_REVISION = 4;
1092
+ function localMoveEnd() {
1093
+ let config;
1094
+ return {
1095
+ name: localMachineName(),
1096
+ revision: IDE_PROTOCOL.revision,
1097
+ call: async (request) => {
1098
+ config ??= new Conf({ projectName: "clikcode", configFileMode: 384 });
1099
+ const { answerMoveRequest } = await import("./chunk-NR4FMC4K.js");
1100
+ return await answerMoveRequest(config, request);
1101
+ }
1102
+ };
1103
+ }
1104
+ function remoteMoveEnd(bridge, machine) {
1105
+ return {
1106
+ name: machine.name,
1107
+ get revision() {
1108
+ return bridge.revision;
1109
+ },
1110
+ call: async (request) => {
1111
+ if (bridge.revision < MOVE_REVISION) throw new Error(`ClikCode on ${machine.name} is too old to move chats: update it (/update in one of its chats, or Tab on it in /machine).`);
1112
+ return bridge.request(request);
1113
+ }
1114
+ };
1115
+ }
1116
+ function machineList(current, machines, links, tailnet, actionsOf) {
1117
+ const stateOf = (id) => {
1118
+ const view = links?.views().find((item) => item.machine.id === id);
1119
+ if (!view || view.state === "connected") return view?.updating ? "updating ClikCode\u2026" : view?.needsUpdate ? "needs update (tab)" : void 0;
1120
+ if (view.state === "offline") return "offline";
1121
+ return "connecting";
1122
+ };
1123
+ const rows = () => [
1124
+ { label: localMachineName(), detail: current === "local" ? "\xB7 this chat is here" : "\xB7 this machine", value: "local" },
1125
+ ...machines.map((machine) => {
1126
+ const state = machine.ready ? stateOf(machine.id) : "install not finished";
1127
+ const offline = state === "offline" ? state : void 0;
1128
+ return {
1129
+ label: machine.name,
1130
+ detail: `\xB7 ${[current === machine.id ? "this chat is here" : void 0, state].filter(Boolean).join(" \xB7 ") || "connected"}`,
1131
+ value: machine.id,
1132
+ actions: actionsOf(machine),
1133
+ ...offline ? { offline } : {}
1134
+ };
1135
+ }),
1136
+ ...tailnet.found.map((machine) => {
1137
+ const offline = machine.os === "windows" ? "Windows, not supported yet" : machine.online ? void 0 : "offline";
1138
+ return {
1139
+ label: machine.name,
1140
+ detail: `\xB7 ${machine.os} \xB7 ${machine.os === "windows" ? "not supported yet" : offline ?? "add: install ClikCode"}`,
1141
+ value: discoveredValue(machine),
1142
+ group: TAILNET,
1143
+ ...offline ? { offline } : {}
1144
+ };
1145
+ }),
1146
+ { label: "Add by SSH address\u2026", detail: "\xB7 user@host or a Host alias from ~/.ssh/config", value: ADDRESS, group: ELSEWHERE }
1147
+ ];
1148
+ const refresh = links ? [
1149
+ ...machines.map((machine) => new Promise((resolve) => {
1150
+ const check = () => {
1151
+ if (links.views().find((view) => view.machine.id === machine.id)?.state !== "connecting") resolve();
1152
+ };
1153
+ links.onChange(check);
1154
+ check();
1155
+ }))
1156
+ ] : [];
1157
+ return { rows, refresh: [...refresh, tailnet.landed] };
1158
+ }
1159
+ var TAILNET = "On your tailnet";
1160
+ var ELSEWHERE = "Somewhere else";
1161
+ var ADDRESS = "__address__";
1162
+ var discoveredValue = (machine) => `tailscale:${machine.nodeId}`;
1163
+ function readTailnet(added) {
1164
+ const tailnet = { found: [], landed: Promise.resolve() };
1165
+ tailnet.landed = readTailscaleStatus().then(({ status }) => {
1166
+ tailnet.found = status ? notYetAdded(discoverMachines(status), added) : [];
1167
+ }, () => void 0);
1168
+ return tailnet;
1169
+ }
1170
+ async function pickMachine(prompter, current, links) {
1171
+ const { addByAddress, addDiscoveredMachine, machineAction, machineActions, remoteHostOf } = await import("./chunk-MJG3IQY4.js");
1172
+ const host = remoteHostOf(prompter);
1173
+ for (; ; ) {
1174
+ const machines = await readMachines();
1175
+ const tailnet = readTailnet(machines);
1176
+ const list = machineList(current, machines, links, tailnet, machineActions);
1177
+ let acted;
1178
+ const picked = await chooseOption(prompter, "Move this chat to", list.rows(), async (value, action) => {
1179
+ const machine2 = machines.find((item) => item.id === value);
1180
+ if (machine2) acted = { machine: machine2, action };
1181
+ }, { startAt: current, refreshedOptions: list.rows, refresh: list.refresh });
1182
+ if (acted) {
1183
+ const { notice } = await machineAction(host, acted.machine, acted.action);
1184
+ if (notice) host.line(notice);
1185
+ continue;
1186
+ }
1187
+ if (!picked || picked === current) return void 0;
1188
+ const row = list.rows().find((item) => item.value === picked);
1189
+ if (row?.offline) throw new Error(`${row.label} is ${row.offline}: the chat stays here.`);
1190
+ if (picked === "local") return { id: "local" };
1191
+ const added = async (adding) => {
1192
+ const done = await adding;
1193
+ if (!done.id) return void 0;
1194
+ const machine2 = (await readMachines()).find((item) => item.id === done.id && item.ready);
1195
+ if (!machine2) return void 0;
1196
+ if (done.notice) host.line(done.notice);
1197
+ return { id: machine2.id, machine: machine2 };
1198
+ };
1199
+ if (picked === ADDRESS) {
1200
+ const typed = await host.ask("SSH address (user@host, host, or a Host alias)");
1201
+ if (!typed?.trim()) continue;
1202
+ return added(addByAddress(host, typed));
1203
+ }
1204
+ const found = tailnet.found.find((item) => discoveredValue(item) === picked);
1205
+ if (found) return added(addDiscoveredMachine(host, found));
1206
+ const machine = machines.find((item) => item.id === picked);
1207
+ if (!machine) throw new Error("That machine is no longer added.");
1208
+ if (!machine.ready) return added(machineAction(host, machine, "install").then(() => ({ id: machine.id })));
1209
+ return { id: picked, machine };
1210
+ }
1211
+ }
1212
+ async function moveTerminalChat(prompter, here, sessionId, hasContent, source, startBridge) {
1213
+ const current = "local" in here ? "local" : here.remote.machineId;
1214
+ const links = (await readMachines()).some((machine) => machine.ready) ? await holdWindowMachines().catch(quiet("remote/move-terminal")) : void 0;
1215
+ let bridge;
1216
+ let channel;
1217
+ try {
1218
+ const choice = await pickMachine(prompter, current, links);
1219
+ if (!choice) return void 0;
1220
+ if (!hasContent) {
1221
+ if (choice.machine) return { remote: { machineId: choice.machine.id } };
1222
+ const { newConversation } = await import("./chunk-OARL2NXZ.js");
1223
+ return { local: await newConversation(sessionId) };
1224
+ }
1225
+ if (!choice.machine) return { local: (await moveChat(source, localMoveEnd(), sessionId)).sessionId };
1226
+ channel = await links?.channel(choice.machine.id).catch(quiet("remote/move-terminal"));
1227
+ if (!channel) {
1228
+ bridge = new TerminalBridge(choice.machine.sshTarget, startBridge);
1229
+ await bridge.connected();
1230
+ }
1231
+ const outcome = await moveChat(source, remoteMoveEnd(channel ?? bridge, choice.machine), sessionId);
1232
+ return { remote: { machineId: choice.machine.id, chatId: outcome.sessionId } };
1233
+ } finally {
1234
+ channel?.close();
1235
+ bridge?.close();
1236
+ links?.release();
1237
+ }
1238
+ }
1239
+ async function movedChatPlace(movedTo) {
1240
+ const state = await readState({ transcripts: [] });
1241
+ const machine = movedChatMachine(movedTo, await readMachines(), { name: localMachineName(), installationId: state.installationId });
1242
+ if (!machine) return void 0;
1243
+ return machine === "local" ? { local: movedTo.sessionId } : { remote: { machineId: machine, chatId: movedTo.sessionId } };
1244
+ }
1245
+ var windowReach = async (machineId) => {
1246
+ const links = await holdWindowMachines().catch(quiet("remote/move-terminal"));
1247
+ try {
1248
+ const channel = await links?.channel(machineId).catch(quiet("remote/move-terminal"));
1249
+ channel?.close();
1250
+ return Boolean(channel);
1251
+ } finally {
1252
+ links?.release();
1253
+ }
1254
+ };
1255
+ async function liveChat(movedTo, reclaim, reach = windowReach) {
1256
+ const seen = /* @__PURE__ */ new Set();
1257
+ let next = movedTo;
1258
+ let why = "is not added here";
1259
+ for (; ; ) {
1260
+ const place = await movedChatPlace(next);
1261
+ if (!place) break;
1262
+ if ("remote" in place) {
1263
+ if (await reach(place.remote.machineId).catch(() => false)) return { here: place };
1264
+ why = "does not answer";
1265
+ break;
1266
+ }
1267
+ if (seen.has(place.local)) break;
1268
+ seen.add(place.local);
1269
+ const session = (await readState({ transcripts: [] })).sessions.find((item) => item.id === place.local);
1270
+ if (!session) {
1271
+ why = "no longer has it";
1272
+ break;
1273
+ }
1274
+ if (!session.movedTo) return { here: place };
1275
+ next = session.movedTo;
1276
+ }
1277
+ return { here: await reclaim(), notice: `This chat moved to ${next.machine}, which ${why}: it goes on here.` };
1278
+ }
1279
+ async function openedChat(id, reach = windowReach) {
1280
+ const opened = (await readState({ transcripts: [] })).sessions.find((item) => item.id === id);
1281
+ if (!opened?.movedTo) return void 0;
1282
+ return liveChat(opened.movedTo, async () => {
1283
+ const { reclaimMovedChat } = await import("./chunk-NR4FMC4K.js");
1284
+ return { local: await reclaimMovedChat(id) };
1285
+ }, reach);
1286
+ }
1287
+
1288
+ export {
1289
+ DELETED_ELSEWHERE,
1290
+ BOARD_LINE,
1291
+ joinedTurn,
1292
+ conversationCommands,
1293
+ RemoteUnavailable,
1294
+ runRemoteChat,
1295
+ localMoveEnd,
1296
+ remoteMoveEnd,
1297
+ moveTerminalChat,
1298
+ movedChatPlace,
1299
+ liveChat,
1300
+ openedChat
1301
+ };