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.
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 +494 -112923
  319. package/dist/computer-tools.js +36642 -21259
  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,762 @@
1
+ import { createRequire as __clikcodeCreateRequire } from 'node:module';
2
+ const require = __clikcodeCreateRequire(import.meta.url);
3
+ import {
4
+ listedChats
5
+ } from "./chunk-O2YSNYWD.js";
6
+ import {
7
+ readMachines,
8
+ startBridge,
9
+ updateMachine,
10
+ updatePolicy
11
+ } from "./chunk-X6WF7JEV.js";
12
+ import {
13
+ bridgeScript,
14
+ installOnMachine
15
+ } from "./chunk-UFQ5A5PW.js";
16
+ import {
17
+ decodeWireLine
18
+ } from "./chunk-AZVD74ZV.js";
19
+ import {
20
+ failureText
21
+ } from "./chunk-CQ7J6UQ7.js";
22
+ import {
23
+ CLIKCODE_COMMIT
24
+ } from "./chunk-NAOX3JUB.js";
25
+ import {
26
+ lifecycle,
27
+ quiet
28
+ } from "./chunk-RDDWQBEM.js";
29
+
30
+ // src/remote/connection.ts
31
+ import { randomUUID } from "node:crypto";
32
+ import { networkInterfaces } from "node:os";
33
+ import { createInterface } from "node:readline";
34
+
35
+ // src/ide/protocol-version.ts
36
+ var IDE_PROTOCOL = {
37
+ version: 1,
38
+ revision: 12,
39
+ oldestSupported: 1,
40
+ oldestRevision: 11
41
+ };
42
+
43
+ // src/remote/updates.ts
44
+ function localBuildCommit() {
45
+ return process.env.CLIKCODE_REMOTE_LOCAL_COMMIT?.trim() || CLIKCODE_COMMIT;
46
+ }
47
+ function pinnedUpdateLine(line, editorCommit) {
48
+ return editorCommit && /^\/update\s*$/i.test(line.trim()) ? `/update ${editorCommit}` : line;
49
+ }
50
+ function installedRecord(record, info) {
51
+ record.ready = true;
52
+ record.installed = { version: info.version, ...info.commit ? { commit: info.commit } : {}, at: (/* @__PURE__ */ new Date()).toISOString() };
53
+ if (info.installationId) record.installationId = info.installationId;
54
+ record.needsUpdate = false;
55
+ delete record.updateError;
56
+ }
57
+ var noSteps = { start: () => void 0, done: () => void 0 };
58
+ async function updateRemoteMachine(machine, reporter = noSteps, options = {}) {
59
+ const outcome = await installOnMachine(machine.sshTarget, reporter, { update: true, ...options.commit ? { commit: options.commit } : {} });
60
+ await updateMachine(machine.id, (record) => {
61
+ if (outcome.ok) installedRecord(record, outcome.info);
62
+ else record.updateError = `${outcome.step}: ${outcome.message}`;
63
+ }).catch(quiet("remote/updates"));
64
+ return outcome;
65
+ }
66
+ function autoUpdateDecision(machine, needsUpdate2, localCommit, attempted) {
67
+ if (!needsUpdate2) return { update: false, reason: "current" };
68
+ if (updatePolicy(machine) === "ask") return { update: false, reason: "ask" };
69
+ if (!localCommit) return { update: false, reason: "no-commit" };
70
+ if (attempted.has(attemptKey(machine.id, localCommit))) return { update: false, reason: "attempted" };
71
+ return { update: true, commit: localCommit };
72
+ }
73
+ var attemptKey = (machineId, commit) => `${machineId}\0${commit}`;
74
+ var AutoUpdates = class {
75
+ constructor(run = (machine, commit) => updateRemoteMachine(machine, noSteps, { commit })) {
76
+ this.run = run;
77
+ }
78
+ run;
79
+ attempted = /* @__PURE__ */ new Set();
80
+ running = /* @__PURE__ */ new Map();
81
+ /** A connection found `machine` outdated. Resolves once decided: with
82
+ * the update (`done`, its outcome) when one starts or is already running
83
+ * for it, undefined when none is due. The policy is read from the saved
84
+ * record, which /machine may have changed since. */
85
+ async consider(machine, localCommit = localBuildCommit()) {
86
+ const already = this.running.get(machine.id);
87
+ if (already) return { done: already };
88
+ const saved = (await readMachines()).find((item) => item.id === machine.id) ?? machine;
89
+ const decision = autoUpdateDecision(saved, true, localCommit, this.attempted);
90
+ const raced = this.running.get(machine.id);
91
+ if (raced) return { done: raced };
92
+ if (!decision.update) return void 0;
93
+ this.attempted.add(attemptKey(machine.id, decision.commit));
94
+ const done = this.run(saved, decision.commit).finally(() => this.running.delete(machine.id));
95
+ this.running.set(machine.id, done);
96
+ return { done };
97
+ }
98
+ /** The update running for a machine now, if any. */
99
+ runningFor(machineId) {
100
+ return this.running.get(machineId);
101
+ }
102
+ };
103
+ var autoUpdates = new AutoUpdates();
104
+
105
+ // src/remote/connection.ts
106
+ function needsUpdate(ready, localCommit = localBuildCommit()) {
107
+ if (ready.protocol !== void 0 && ready.protocol !== IDE_PROTOCOL.version) return true;
108
+ return Boolean(ready.commit && localCommit && ready.commit !== localCommit);
109
+ }
110
+ var CHAT = "clikcode-remote-board";
111
+ var READY_TIMEOUT_MS = 3e4;
112
+ var REQUEST_TIMEOUT_MS = 6e4;
113
+ var STDERR_KEEP = 16e3;
114
+ var BACKOFF_MS = [1e3, 2e3, 5e3, 1e4, 3e4, 6e4, 12e4, 24e4, 48e4, 6e5];
115
+ var NETWORK_POLL_MS = 3e4;
116
+ function networkSignature() {
117
+ return JSON.stringify(Object.values(networkInterfaces()).flatMap((list) => (list ?? []).filter((i) => !i.internal).map((i) => i.address)).sort());
118
+ }
119
+ var CACHE_WRITE_MS = 5e3;
120
+ var RemoteLink = class {
121
+ constructor(machine, changed, options = {}) {
122
+ this.changed = changed;
123
+ this.options = options;
124
+ this.view = {
125
+ machine,
126
+ state: "connecting",
127
+ needsUpdate: Boolean(machine.needsUpdate),
128
+ chats: listedChats(machine.chats ?? []),
129
+ ...machine.updateError ? { updateError: machine.updateError } : {}
130
+ };
131
+ }
132
+ changed;
133
+ options;
134
+ child;
135
+ stopped = false;
136
+ attempt = 0;
137
+ retry;
138
+ readyTimer;
139
+ requestSeq = 0;
140
+ querying = false;
141
+ queryAgain = false;
142
+ cacheTimer;
143
+ cacheDirty = false;
144
+ /** The connection is being made again (after an update): no offline in between. */
145
+ reconnecting = false;
146
+ /** The bridge there said it is leaving for a newer build (ide/bridge-retire.ts):
147
+ * its close is followed at once by a new connection, and the machine still
148
+ * reads as connected meanwhile -- nothing about it changed for the user. */
149
+ retiring = false;
150
+ /** Offline with nothing showing it: tried again on `wake()`, not on a timer. */
151
+ parked = false;
152
+ /** An automatic update is being considered or run from this link. */
153
+ updatingNow = false;
154
+ view;
155
+ /** What the bridge there said in its host-ready (1 when it did not say). */
156
+ revision = 1;
157
+ channels = /* @__PURE__ */ new Map();
158
+ taps = /* @__PURE__ */ new Map();
159
+ start() {
160
+ if (this.stopped || this.child) return;
161
+ this.connect();
162
+ }
163
+ set(patch) {
164
+ Object.assign(this.view, patch);
165
+ this.changed();
166
+ }
167
+ send(message) {
168
+ const stdin = this.child?.stdin;
169
+ if (stdin && !stdin.destroyed) stdin.write(`${JSON.stringify(message)}
170
+ `);
171
+ }
172
+ /** When the connection being made began: how long a host takes to say it is ready is the number that says the link is slow. */
173
+ connectedAt = 0;
174
+ connect() {
175
+ this.stopNetworkWatch();
176
+ const machine = this.view.machine;
177
+ this.connectedAt = Date.now();
178
+ lifecycle("remote.connect", { machine: machine.name, attempt: this.attempt });
179
+ let child;
180
+ try {
181
+ child = this.options.spawn ? this.options.spawn(machine.sshTarget, bridgeScript()) : startBridge(machine.sshTarget, this.options.self);
182
+ } catch (error) {
183
+ this.lost(error instanceof Error ? error.message : String(error));
184
+ return;
185
+ }
186
+ this.child = child;
187
+ let stderr = "";
188
+ child.stderr?.on("data", (chunk) => {
189
+ stderr = `${stderr}${chunk.toString("utf8")}`.slice(-STDERR_KEEP);
190
+ });
191
+ child.stdin?.on("error", () => void 0);
192
+ child.once("error", (error) => {
193
+ stderr += `
194
+ ${error.message}`;
195
+ });
196
+ const lines = createInterface({ input: child.stdout, crlfDelay: Infinity });
197
+ lines.on("line", (line) => {
198
+ let event;
199
+ try {
200
+ event = JSON.parse(decodeWireLine(line));
201
+ } catch {
202
+ return;
203
+ }
204
+ this.onEvent(event);
205
+ });
206
+ this.readyTimer = setTimeout(() => {
207
+ stderr += "\nno answer from ClikCode there";
208
+ child.kill("SIGTERM");
209
+ }, READY_TIMEOUT_MS);
210
+ this.readyTimer.unref();
211
+ child.once("close", (code) => {
212
+ clearTimeout(this.readyTimer);
213
+ if (this.child === child) this.child = void 0;
214
+ const retired = this.retiring;
215
+ const said = failureText(stderr);
216
+ const gone = new Error(said && !retired && !this.reconnecting ? said : `The connection to ${machine.name} ended`);
217
+ this.dropChannels(gone);
218
+ this.dropTaps(gone, retired || this.reconnecting);
219
+ this.retiring = false;
220
+ if (this.stopped) return;
221
+ if (this.reconnecting || retired) {
222
+ this.reconnecting = false;
223
+ if (!retired) this.set({ state: "connecting", error: void 0 });
224
+ this.connect();
225
+ return;
226
+ }
227
+ this.lost(said ? `${said} (exit ${code ?? "?"})` : `the connection ended (exit ${code ?? "?"})`);
228
+ });
229
+ }
230
+ wanted() {
231
+ return this.options.wanted?.() ?? true;
232
+ }
233
+ lost(error) {
234
+ lifecycle("remote.lost", { machine: this.view.machine.name, attempt: this.attempt, ms: this.connectedAt ? Date.now() - this.connectedAt : 0, error: error.slice(0, 200) });
235
+ this.set({ state: "offline", error });
236
+ if (this.stopped) return;
237
+ if (!this.wanted()) {
238
+ this.parked = true;
239
+ return;
240
+ }
241
+ const backoff = this.options.backoffMs ?? BACKOFF_MS;
242
+ const wait = backoff[Math.min(this.attempt, backoff.length - 1)];
243
+ this.attempt += 1;
244
+ this.retry = setTimeout(() => {
245
+ this.retry = void 0;
246
+ if (this.stopped) return;
247
+ if (!this.wanted()) {
248
+ this.parked = true;
249
+ return;
250
+ }
251
+ this.connect();
252
+ }, wait);
253
+ this.retry.unref();
254
+ if (wait >= NETWORK_POLL_MS * 2) {
255
+ const signature = this.options.networkSignature ?? networkSignature;
256
+ const before = signature();
257
+ this.netWatch = setInterval(() => {
258
+ if (signature() === before) return;
259
+ this.stopNetworkWatch();
260
+ clearTimeout(this.retry);
261
+ this.retry = void 0;
262
+ if (this.stopped || !this.wanted()) {
263
+ this.parked = !this.stopped;
264
+ return;
265
+ }
266
+ this.attempt = 0;
267
+ lifecycle("remote.network-changed", { machine: this.view.machine.name });
268
+ this.set({ state: "connecting", error: void 0 });
269
+ this.connect();
270
+ }, NETWORK_POLL_MS);
271
+ this.netWatch.unref();
272
+ }
273
+ }
274
+ netWatch;
275
+ stopNetworkWatch() {
276
+ if (this.netWatch) clearInterval(this.netWatch);
277
+ this.netWatch = void 0;
278
+ }
279
+ /** A list shows the machine again: one offline is tried at once, not after
280
+ * its pause (as a fresh connection would be); one connected is left as is. */
281
+ wake() {
282
+ if (this.stopped || this.child) return;
283
+ if (!this.parked && !this.retry) return;
284
+ this.parked = false;
285
+ clearTimeout(this.retry);
286
+ this.retry = void 0;
287
+ this.set({ state: "connecting", error: void 0 });
288
+ this.connect();
289
+ }
290
+ updatesAllowed() {
291
+ const allowed = this.options.autoUpdate;
292
+ return typeof allowed === "function" ? allowed() : allowed !== false;
293
+ }
294
+ /** The board shows a machine already connected and outdated: brought to
295
+ * this build by its policy, as on connecting (each commit tried once). */
296
+ considerUpdate() {
297
+ if (this.stopped || this.view.state !== "connected" || !this.view.needsUpdate || this.view.updating || !this.updatesAllowed()) return;
298
+ this.autoUpdate(this.options.localCommit ?? localBuildCommit());
299
+ }
300
+ onEvent(event) {
301
+ if (event.type === "host-ready") {
302
+ clearTimeout(this.readyTimer);
303
+ this.attempt = 0;
304
+ const localCommit = this.options.localCommit ?? localBuildCommit();
305
+ const outdated = needsUpdate(event, localCommit);
306
+ const machine = this.view.machine;
307
+ if (event.installationId && !machine.installationId) machine.installationId = event.installationId;
308
+ machine.needsUpdate = outdated;
309
+ if (!outdated) delete machine.updateError;
310
+ this.revision = event.revision ?? 1;
311
+ lifecycle("remote.ready", { machine: machine.name, ms: Date.now() - this.connectedAt, revision: this.revision, outdated, ...event.commit ? { commit: event.commit.slice(0, 8) } : {} });
312
+ this.set({ state: "connected", needsUpdate: outdated, error: void 0, ...outdated ? {} : { updateError: void 0 } });
313
+ if (this.options.board !== false) this.send({ type: "chat-attach", chat: CHAT });
314
+ if (outdated && this.updatesAllowed()) this.autoUpdate(localCommit);
315
+ return;
316
+ }
317
+ if (event.type === "host-retiring") {
318
+ this.retiring = true;
319
+ return;
320
+ }
321
+ if (event.type === "chat" && this.taps.has(event.chat)) {
322
+ this.taps.get(event.chat).event(event.event);
323
+ return;
324
+ }
325
+ if (event.type === "chat" && this.channels.has(event.chat)) {
326
+ this.onChannelEvent(this.channels.get(event.chat), event.event);
327
+ return;
328
+ }
329
+ if (event.type !== "chat" || event.chat !== CHAT) return;
330
+ const inner = event.event;
331
+ if (inner.type === "ready") {
332
+ this.send({ type: "chat", chat: CHAT, request: { type: "watch-conversations", on: true } });
333
+ this.query();
334
+ } else if (inner.type === "conversations-changed") {
335
+ this.query();
336
+ } else if (inner.type === "result" && inner.requestId === `list-${this.requestSeq}`) {
337
+ this.querying = false;
338
+ if (inner.ok && Array.isArray(inner.data)) {
339
+ this.set({ chats: listedChats(inner.data) });
340
+ this.saveCache();
341
+ }
342
+ if (this.queryAgain) {
343
+ this.queryAgain = false;
344
+ this.query();
345
+ }
346
+ }
347
+ }
348
+ onChannelEvent(channel, event) {
349
+ if (event.type === "ready") {
350
+ channel.ready();
351
+ return;
352
+ }
353
+ if (event.type !== "result") return;
354
+ const waiter = channel.pending.get(event.requestId);
355
+ if (!waiter) return;
356
+ channel.pending.delete(event.requestId);
357
+ if (event.ok) waiter.resolve(event.data);
358
+ else waiter.reject(new Error(event.error ?? "Remote request failed"));
359
+ }
360
+ dropChannels(error) {
361
+ const open = [...this.channels.values()];
362
+ this.channels.clear();
363
+ for (const channel of open) {
364
+ channel.failed(error);
365
+ for (const waiter of channel.pending.values()) waiter.reject(error);
366
+ }
367
+ }
368
+ dropTaps(error, retiring) {
369
+ const open = [...this.taps.values()];
370
+ this.taps.clear();
371
+ for (const handlers of open) handlers.ended(error, retiring);
372
+ }
373
+ /** A chat of its own on this connection, whose events all come to `handlers`: opening it is a message on a connection already
374
+ * up, not an ssh and a process started there. Undefined while the machine is not connected. */
375
+ tap(chat, handlers) {
376
+ if (this.view.state !== "connected" || !this.child) return void 0;
377
+ this.taps.set(chat, handlers);
378
+ this.send({ type: "chat-attach", chat });
379
+ return {
380
+ revision: this.revision,
381
+ outdated: Boolean(this.view.needsUpdate),
382
+ post: (request) => {
383
+ if (!this.taps.has(chat)) throw new Error(`The connection to ${this.view.machine.name} ended`);
384
+ this.send({ type: "chat", chat, request });
385
+ },
386
+ detach: () => {
387
+ this.taps.delete(chat);
388
+ }
389
+ };
390
+ }
391
+ /** A chat channel on this connection, once the ClikCode there has it open;
392
+ * undefined while the machine is not connected. */
393
+ async channel() {
394
+ if (this.view.state !== "connected" || !this.child) return void 0;
395
+ const chat = `clikcode-move-${randomUUID()}`;
396
+ const open = { ready: () => void 0, failed: () => void 0, pending: /* @__PURE__ */ new Map() };
397
+ const ready = new Promise((resolve, reject) => {
398
+ const timer = setTimeout(() => reject(new Error(`No answer from ${this.view.machine.name}`)), READY_TIMEOUT_MS);
399
+ timer.unref();
400
+ open.ready = () => {
401
+ clearTimeout(timer);
402
+ resolve();
403
+ };
404
+ open.failed = (error) => {
405
+ clearTimeout(timer);
406
+ reject(error);
407
+ };
408
+ });
409
+ this.channels.set(chat, open);
410
+ this.send({ type: "chat-attach", chat });
411
+ try {
412
+ await ready;
413
+ } catch (error) {
414
+ this.channels.delete(chat);
415
+ throw error;
416
+ }
417
+ const revision = this.revision;
418
+ return {
419
+ revision,
420
+ request: (request) => {
421
+ if (!this.channels.has(chat)) return Promise.reject(new Error(`The connection to ${this.view.machine.name} ended`));
422
+ const requestId = randomUUID();
423
+ const answered = new Promise((resolve, reject) => {
424
+ const timer = setTimeout(() => {
425
+ open.pending.delete(requestId);
426
+ reject(new Error(`${this.view.machine.name} did not answer "${request.type}" within ${(this.options.requestTimeoutMs ?? REQUEST_TIMEOUT_MS) / 1e3}s`));
427
+ }, this.options.requestTimeoutMs ?? REQUEST_TIMEOUT_MS);
428
+ timer.unref();
429
+ open.pending.set(requestId, { resolve: (value) => {
430
+ clearTimeout(timer);
431
+ resolve(value);
432
+ }, reject: (error) => {
433
+ clearTimeout(timer);
434
+ reject(error);
435
+ } });
436
+ });
437
+ this.send({ type: "chat", chat, request: { ...request, requestId } });
438
+ return answered;
439
+ },
440
+ close: () => {
441
+ if (!this.channels.delete(chat)) return;
442
+ this.send({ type: "chat", chat, request: { type: "close" } });
443
+ }
444
+ };
445
+ }
446
+ /** Brings the machine to this build when its policy says so; once it is,
447
+ * connects again, to the new build's bridge. */
448
+ autoUpdate(localCommit) {
449
+ if (this.updatingNow) return;
450
+ this.updatingNow = true;
451
+ const machine = this.view.machine;
452
+ void (async () => {
453
+ const started = await (this.options.autoUpdates ?? autoUpdates).consider(machine, localCommit);
454
+ if (!started) return;
455
+ this.set({ updating: true });
456
+ const outcome = await started.done;
457
+ if (outcome.ok) {
458
+ delete machine.updateError;
459
+ this.set({ updating: false, updateError: void 0 });
460
+ this.reconnect();
461
+ } else {
462
+ machine.updateError = `${outcome.step}: ${outcome.message}`;
463
+ this.set({ updating: false, updateError: machine.updateError });
464
+ }
465
+ })().catch(() => this.set({ updating: false })).finally(() => {
466
+ this.updatingNow = false;
467
+ });
468
+ }
469
+ /** Ends this connection and makes it again at once (a new build there). */
470
+ reconnect() {
471
+ if (this.stopped) return;
472
+ this.attempt = 0;
473
+ this.parked = false;
474
+ const child = this.child;
475
+ if (!child) {
476
+ clearTimeout(this.retry);
477
+ this.retry = void 0;
478
+ this.set({ state: "connecting", error: void 0 });
479
+ this.connect();
480
+ return;
481
+ }
482
+ this.reconnecting = true;
483
+ child.stdin?.end();
484
+ child.kill("SIGTERM");
485
+ }
486
+ /** One query at a time; a change during one asks once more after it. */
487
+ query() {
488
+ if (this.querying) {
489
+ this.queryAgain = true;
490
+ return;
491
+ }
492
+ this.querying = true;
493
+ this.requestSeq += 1;
494
+ this.send({ type: "chat", chat: CHAT, request: { type: "query", requestId: `list-${this.requestSeq}`, query: "conversations" } });
495
+ }
496
+ /** The chats as last seen, for the offline view -- at most every few
497
+ * seconds, and once more when the connection closes. */
498
+ saveCache() {
499
+ this.cacheDirty = true;
500
+ if (this.cacheTimer) return;
501
+ this.cacheTimer = setTimeout(() => {
502
+ this.cacheTimer = void 0;
503
+ void this.flushCache();
504
+ }, CACHE_WRITE_MS);
505
+ this.cacheTimer.unref();
506
+ }
507
+ flushCache() {
508
+ clearTimeout(this.cacheTimer);
509
+ this.cacheTimer = void 0;
510
+ if (!this.cacheDirty) return Promise.resolve();
511
+ this.cacheDirty = false;
512
+ const { chats, needsUpdate: outdated, machine } = this.view;
513
+ return updateMachine(machine.id, (record) => {
514
+ record.chats = [...chats];
515
+ record.lastSeen = (/* @__PURE__ */ new Date()).toISOString();
516
+ record.needsUpdate = outdated;
517
+ if (!outdated) delete record.updateError;
518
+ if (machine.installationId) record.installationId = machine.installationId;
519
+ }, { durable: false }).then(() => void 0, () => void 0);
520
+ }
521
+ /** Ends the connection: the remote bridge sees its stdin close and exits. */
522
+ async stop() {
523
+ this.stopped = true;
524
+ clearTimeout(this.retry);
525
+ this.stopNetworkWatch();
526
+ clearTimeout(this.readyTimer);
527
+ const child = this.child;
528
+ this.child = void 0;
529
+ if (child && child.exitCode === null) {
530
+ child.stdin?.end();
531
+ const exited = new Promise((resolve) => child.once("close", () => resolve()));
532
+ const grace = setTimeout(() => child.kill("SIGTERM"), 1500);
533
+ grace.unref();
534
+ await Promise.race([exited, new Promise((resolve) => setTimeout(resolve, 3e3).unref())]);
535
+ clearTimeout(grace);
536
+ }
537
+ await this.flushCache();
538
+ }
539
+ };
540
+ var RemoteMachines = class {
541
+ constructor(options = {}, held = false) {
542
+ this.options = options;
543
+ this.held = held;
544
+ }
545
+ options;
546
+ held;
547
+ links = [];
548
+ listeners = /* @__PURE__ */ new Set();
549
+ closed = false;
550
+ /** Lists holding the connections now, and of them those that let an
551
+ * outdated machine be updated by its policy (the board). */
552
+ holders = 0;
553
+ updaters = 0;
554
+ syncing = Promise.resolve();
555
+ /** Bumped on every change: the board rebuilds its rows only then. */
556
+ revision = 0;
557
+ linkFor(machine) {
558
+ const options = this.held ? { ...this.options, wanted: () => this.holders > 0, autoUpdate: () => this.updaters > 0 } : this.options;
559
+ return new RemoteLink(machine, () => this.notify(), options);
560
+ }
561
+ /** The links match machines.json as it is now: a machine added since gets
562
+ * one, one forgotten (or no longer ready) loses its, and one now reached
563
+ * at another address or name is connected to anew. The rest stay as they are. */
564
+ sync() {
565
+ const run = this.syncing.then(async () => {
566
+ const machines = (await readMachines()).filter((machine) => machine.ready);
567
+ if (this.closed) return;
568
+ const next = [];
569
+ const ended = [];
570
+ for (const link of this.links) {
571
+ const record = machines.find((machine) => machine.id === link.view.machine.id);
572
+ if (record && record.sshTarget === link.view.machine.sshTarget && record.name === link.view.machine.name) {
573
+ link.view.machine.updates = record.updates;
574
+ next.push(link);
575
+ } else ended.push(link);
576
+ }
577
+ for (const machine of machines) {
578
+ if (next.some((link2) => link2.view.machine.id === machine.id)) continue;
579
+ const link = this.linkFor(machine);
580
+ next.push(link);
581
+ link.start();
582
+ }
583
+ next.sort((a, b) => machines.findIndex((m) => m.id === a.view.machine.id) - machines.findIndex((m) => m.id === b.view.machine.id));
584
+ this.links = next;
585
+ for (const link of ended) void link.stop();
586
+ this.notify();
587
+ });
588
+ this.syncing = run.catch(quiet("remote/connection"));
589
+ return run;
590
+ }
591
+ /** Holds the connections for a list: made now for any machine without one,
592
+ * an offline one tried again at once, and kept after `release()`. With
593
+ * `autoUpdate` (the board), an outdated machine is updated by its policy. */
594
+ async hold(use = {}) {
595
+ this.holders += 1;
596
+ if (use.autoUpdate) this.updaters += 1;
597
+ const stops = /* @__PURE__ */ new Set();
598
+ let released = false;
599
+ const release = () => {
600
+ if (released) return;
601
+ released = true;
602
+ this.holders -= 1;
603
+ if (use.autoUpdate) this.updaters -= 1;
604
+ for (const stop of stops) stop();
605
+ stops.clear();
606
+ };
607
+ await this.sync().catch(quiet("remote/connection"));
608
+ for (const link of this.links) link.wake();
609
+ if (use.autoUpdate) for (const link of this.links) link.considerUpdate();
610
+ return {
611
+ views: () => this.views(),
612
+ onChange: (listener) => {
613
+ if (released) return () => void 0;
614
+ const stop = this.onChange(listener);
615
+ const remove = () => {
616
+ stop();
617
+ stops.delete(remove);
618
+ };
619
+ stops.add(remove);
620
+ return remove;
621
+ },
622
+ channel: (machineId) => this.channel(machineId),
623
+ reconnect: (machineId) => this.reconnect(machineId),
624
+ release
625
+ };
626
+ }
627
+ /** Opens a connection to each ready machine (the list is read now). */
628
+ async open() {
629
+ const machines = (await readMachines()).filter((machine) => machine.ready);
630
+ if (this.closed) return this;
631
+ this.links = machines.map((machine) => new RemoteLink(machine, () => this.notify(), this.options));
632
+ for (const link of this.links) link.start();
633
+ this.notify();
634
+ return this;
635
+ }
636
+ /** Pick up a newly installed machine without disturbing existing links. */
637
+ async refresh() {
638
+ const machines = (await readMachines()).filter((machine) => machine.ready);
639
+ if (this.closed) return;
640
+ for (const machine of machines) {
641
+ if (this.links.some((link2) => link2.view.machine.id === machine.id)) continue;
642
+ const link = new RemoteLink(machine, () => this.notify(), this.options);
643
+ this.links.push(link);
644
+ link.start();
645
+ }
646
+ this.notify();
647
+ }
648
+ notify() {
649
+ this.revision += 1;
650
+ for (const listener of this.listeners) listener();
651
+ }
652
+ onChange(listener) {
653
+ this.listeners.add(listener);
654
+ return () => this.listeners.delete(listener);
655
+ }
656
+ views() {
657
+ return this.links.map((link) => link.view);
658
+ }
659
+ /** A chat channel on the connection to a machine, once it is connected: one
660
+ * still connecting (a list opened a moment ago) is waited for, not passed by. */
661
+ async channel(machineId) {
662
+ const link = this.links.find((item) => item.view.machine.id === machineId);
663
+ if (!link) return void 0;
664
+ if (link.view.state === "connecting") {
665
+ await new Promise((resolve) => {
666
+ const timer = setTimeout(resolve, READY_TIMEOUT_MS);
667
+ timer.unref();
668
+ const stop = this.onChange(() => {
669
+ if (link.view.state !== "connecting") {
670
+ clearTimeout(timer);
671
+ stop();
672
+ resolve();
673
+ }
674
+ });
675
+ });
676
+ }
677
+ return link.channel();
678
+ }
679
+ /** A chat on the connection to a machine: undefined while it is not connected. */
680
+ tap(machineId, chat, handlers) {
681
+ return this.links.find((link) => link.view.machine.id === machineId)?.tap(chat, handlers);
682
+ }
683
+ /** Whether a chat can be opened on a machine now, from its connection -- the one place that knows: connected is yes at once; one
684
+ * offline is tried at once (not after its pause) and one connecting is waited for, for at most `ms`. Otherwise why not, in the
685
+ * connection's own words. */
686
+ async reach(machineId, ms) {
687
+ const link = this.links.find((item) => item.view.machine.id === machineId);
688
+ if (!link) return { ok: false, reason: "it is no longer added" };
689
+ link.wake();
690
+ if (link.view.state === "connecting") {
691
+ await new Promise((resolve) => {
692
+ const timer = setTimeout(() => {
693
+ stop();
694
+ resolve();
695
+ }, ms);
696
+ timer.unref();
697
+ const stop = this.onChange(() => {
698
+ if (link.view.state !== "connecting") {
699
+ clearTimeout(timer);
700
+ stop();
701
+ resolve();
702
+ }
703
+ });
704
+ });
705
+ }
706
+ if (link.view.state === "connected") return { ok: true };
707
+ return { ok: false, reason: link.view.state === "connecting" ? `no answer within ${Math.round(ms / 1e3)}s` : link.view.error ?? "not connected" };
708
+ }
709
+ /** Connects to a machine again: its ClikCode was just updated. */
710
+ reconnect(machineId) {
711
+ this.links.find((link) => link.view.machine.id === machineId)?.reconnect();
712
+ }
713
+ async close() {
714
+ this.closed = true;
715
+ this.listeners.clear();
716
+ await Promise.all(this.links.map((link) => link.stop()));
717
+ this.links = [];
718
+ }
719
+ };
720
+ var windowMachines;
721
+ function holdWindowMachines(use = {}, options = {}) {
722
+ windowMachines ??= new RemoteMachines(options, true);
723
+ return windowMachines.hold(use);
724
+ }
725
+ async function reachWindowMachine(machineId, ms) {
726
+ const held = await holdWindowMachines();
727
+ try {
728
+ return await windowMachines.reach(machineId, ms);
729
+ } finally {
730
+ held.release();
731
+ }
732
+ }
733
+ function tapWindowMachine(machineId, chat, handlers) {
734
+ return windowMachines?.tap(machineId, chat, handlers);
735
+ }
736
+ function reconnectWindowMachine(machineId) {
737
+ windowMachines?.reconnect(machineId);
738
+ }
739
+ async function closeWindowMachines() {
740
+ const machines = windowMachines;
741
+ windowMachines = void 0;
742
+ await machines?.close();
743
+ }
744
+
745
+ export {
746
+ IDE_PROTOCOL,
747
+ localBuildCommit,
748
+ pinnedUpdateLine,
749
+ installedRecord,
750
+ updateRemoteMachine,
751
+ autoUpdates,
752
+ needsUpdate,
753
+ REQUEST_TIMEOUT_MS,
754
+ BACKOFF_MS,
755
+ RemoteLink,
756
+ RemoteMachines,
757
+ holdWindowMachines,
758
+ reachWindowMachine,
759
+ tapWindowMachine,
760
+ reconnectWindowMachine,
761
+ closeWindowMachines
762
+ };