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,645 @@
1
+ import { createRequire as __clikcodeCreateRequire } from 'node:module';
2
+ const require = __clikcodeCreateRequire(import.meta.url);
3
+ import {
4
+ WIRE_GZIP_ENV
5
+ } from "./chunk-AZVD74ZV.js";
6
+ import {
7
+ failureText
8
+ } from "./chunk-CQ7J6UQ7.js";
9
+
10
+ // src/remote/shell.ts
11
+ function shellQuote(value) {
12
+ if (value.includes("\0")) throw new Error("a shell word cannot contain a NUL byte");
13
+ return `'${value.replace(/'/g, `'\\''`)}'`;
14
+ }
15
+ function remoteShell(script) {
16
+ return `sh -c ${shellQuote(script)}`;
17
+ }
18
+ function validateSshTarget(input) {
19
+ const target = input.trim();
20
+ if (!target) throw new Error("Type an SSH address: user@host, host, or a Host alias from ~/.ssh/config.");
21
+ if (target.startsWith("-")) throw new Error(`"${target}" starts with "-", which ssh would read as an option. Type user@host.`);
22
+ if (/[\s'"`\\$;&|<>(){}*?!#\u0000-\u001f\u007f]/.test(target)) throw new Error(`"${target}" is not an SSH address: user@host, host, or a Host alias.`);
23
+ const at = target.lastIndexOf("@");
24
+ const user = at >= 0 ? target.slice(0, at) : void 0;
25
+ const host = at >= 0 ? target.slice(at + 1) : target;
26
+ if (!host || host.startsWith("-")) throw new Error(`"${target}" has no host after "@".`);
27
+ if (user !== void 0 && (!user || user.startsWith("-") || user.includes("@"))) throw new Error(`"${target}" is not user@host.`);
28
+ return target;
29
+ }
30
+ function targetHost(target) {
31
+ const at = target.lastIndexOf("@");
32
+ return at >= 0 ? target.slice(at + 1) : target;
33
+ }
34
+ function targetUser(target) {
35
+ const at = target.lastIndexOf("@");
36
+ return at >= 0 ? target.slice(0, at) : void 0;
37
+ }
38
+ function withUser(target, user) {
39
+ const name = user.trim();
40
+ if (!name || name.startsWith("-") || /[\s@'"`\\$;&|<>(){}*?!#\u0000-\u001f\u007f]/.test(name)) throw new Error(`"${user}" is not a user name.`);
41
+ return validateSshTarget(`${name}@${targetHost(target)}`);
42
+ }
43
+
44
+ // src/remote/ssh.ts
45
+ import { spawn } from "node:child_process";
46
+ import { userInfo } from "node:os";
47
+ var SSH_OPTIONS = [
48
+ "-o",
49
+ "BatchMode=yes",
50
+ "-o",
51
+ "ConnectTimeout=10",
52
+ // A machine's first connection trusts its host key and remembers it, as
53
+ // answering "yes" would; a key that CHANGED is still refused (host-key).
54
+ "-o",
55
+ "StrictHostKeyChecking=accept-new",
56
+ // A dropped network is noticed within a minute, not at TCP's leisure.
57
+ "-o",
58
+ "ServerAliveInterval=15",
59
+ "-o",
60
+ "ServerAliveCountMax=3"
61
+ ];
62
+ function sshFailure(result) {
63
+ if (result.code !== 255) return void 0;
64
+ const text = result.stderr;
65
+ if (/Permission denied|Authentication failed|Too many authentication failures|no matching host key|publickey|tailnet policy does not permit/i.test(text) && !/host key verification failed/i.test(text)) return "auth";
66
+ if (/Host key verification failed|REMOTE HOST IDENTIFICATION HAS CHANGED/i.test(text)) return "host-key";
67
+ if (/Could not resolve|Connection timed out|Connection refused|No route to host|Network is unreachable|Operation timed out|timed out|Name or service not known|nodename nor servname/i.test(text)) return "unreachable";
68
+ return "other";
69
+ }
70
+ function sshFailureMessage(target, result) {
71
+ const failure = sshFailure(result);
72
+ const lines = result.stderr.trim().split("\n").map((line) => line.trim()).filter(Boolean);
73
+ const said = failureText(lines.filter((line) => !/^Connection (closed|reset) by /i.test(line)).join("\n")) || lines.pop() || "";
74
+ if (failure === "auth") return `${target} refused the login (${said || "permission denied"}). ClikCode never asks for passwords: add your SSH key to that machine (ssh-copy-id ${target}), or turn on Tailscale SSH there.`;
75
+ if (failure === "unreachable") return `${target} could not be reached (${said || "no answer"}). Check that it is on and online.`;
76
+ if (failure === "host-key") return `${target}'s host key is not trusted yet (${said}). Connect once with \`ssh ${target}\` to check and accept it.`;
77
+ return `ssh ${target} failed: ${said || `exit ${result.code}`}`;
78
+ }
79
+ function sshArgv(target, script, extra = []) {
80
+ return [...SSH_OPTIONS, ...extra, "--", validateSshTarget(target), remoteShell(script)];
81
+ }
82
+ function spawnSsh(target, script) {
83
+ return spawn("ssh", sshArgv(target, script, ["-T"]), { stdio: ["pipe", "pipe", "pipe"] });
84
+ }
85
+ var EXIT_MARK = "__clikcode_exit=";
86
+ function reportingExit(script) {
87
+ return remoteShell(`${remoteShell(script)}; echo "${EXIT_MARK}$?" >&2`);
88
+ }
89
+ function scriptResult(code, stdout, stderr) {
90
+ const at = stderr.lastIndexOf(EXIT_MARK);
91
+ if (code === 255) return { code, stdout, stderr: at >= 0 ? stderr.slice(0, at) : stderr };
92
+ if (at < 0) return { code: code || 1, stdout, stderr: code ? stderr : `${stderr}${stderr && !stderr.endsWith("\n") ? "\n" : ""}the command did not finish on the other machine` };
93
+ const said = Number.parseInt(stderr.slice(at + EXIT_MARK.length), 10);
94
+ return { code: Number.isFinite(said) ? said : code, stdout, stderr: stderr.slice(0, at) };
95
+ }
96
+ function runSsh(target, script, options = {}) {
97
+ return new Promise((resolve) => {
98
+ let child;
99
+ try {
100
+ child = spawn("ssh", [...SSH_OPTIONS, "-T", "--", validateSshTarget(target), reportingExit(script)], { stdio: ["pipe", "pipe", "pipe"] });
101
+ } catch (error) {
102
+ resolve({ code: 255, stdout: "", stderr: error instanceof Error ? error.message : String(error) });
103
+ return;
104
+ }
105
+ child.stdin.end();
106
+ let stdout = "";
107
+ let stderr = "";
108
+ let pending = "";
109
+ child.stdout.on("data", (chunk) => {
110
+ const text = chunk.toString("utf8");
111
+ stdout += text;
112
+ if (!options.onLine) return;
113
+ pending += text;
114
+ for (let at = pending.indexOf("\n"); at >= 0; at = pending.indexOf("\n")) {
115
+ options.onLine(pending.slice(0, at));
116
+ pending = pending.slice(at + 1);
117
+ }
118
+ });
119
+ child.stderr.on("data", (chunk) => {
120
+ stderr += chunk.toString("utf8");
121
+ });
122
+ const timer = options.timeoutMs ? setTimeout(() => {
123
+ stderr += "\nssh: timed out";
124
+ child.kill("SIGTERM");
125
+ }, options.timeoutMs) : void 0;
126
+ timer?.unref();
127
+ child.once("error", (error) => {
128
+ clearTimeout(timer);
129
+ resolve({ code: 255, stdout, stderr: error.code === "ENOENT" ? "ssh is not installed on this machine (OpenSSH client)" : error.message });
130
+ });
131
+ child.once("close", (code) => {
132
+ clearTimeout(timer);
133
+ resolve(scriptResult(code ?? 255, stdout, stderr));
134
+ });
135
+ });
136
+ }
137
+ async function defaultLoginUser(target) {
138
+ const named = targetUser(target);
139
+ if (named) return named;
140
+ const local = (() => {
141
+ try {
142
+ return userInfo().username;
143
+ } catch {
144
+ return process.env.USER ?? "root";
145
+ }
146
+ })();
147
+ const configured = await new Promise((resolve) => {
148
+ let out = "";
149
+ let child;
150
+ try {
151
+ child = spawn("ssh", ["-G", "--", validateSshTarget(targetHost(target))], { stdio: ["ignore", "pipe", "ignore"] });
152
+ } catch {
153
+ resolve(void 0);
154
+ return;
155
+ }
156
+ child.stdout.on("data", (chunk) => {
157
+ out += chunk.toString("utf8");
158
+ });
159
+ child.once("error", () => resolve(void 0));
160
+ child.once("close", () => resolve(/^user (\S+)$/m.exec(out)?.[1]));
161
+ });
162
+ return configured || local;
163
+ }
164
+
165
+ // src/remote/install.ts
166
+ import { spawn as spawn2 } from "node:child_process";
167
+ import { homedir } from "node:os";
168
+ var REMOTE_REPO_URL = "https://github.com/Jgracier/ClikCode.git";
169
+ var NODE_MIRROR = "https://nodejs.org/dist";
170
+ var MACPORTS_MIRROR = "https://packages.macports.org";
171
+ var MIN_NODE = [22, 12];
172
+ var MACPORTS_NODE = {
173
+ 19: {
174
+ version: "v22.22.2",
175
+ node: { port: "nodejs22", file: "nodejs22-22.22.2_0.darwin_19.x86_64.tbz2", sha256: "7db89a4738f5745c54f68090e9f8272ae37e436943ba33fcbabefd300ab2214c" },
176
+ libs: [
177
+ { port: "zlib", file: "zlib-1.3.2_0.darwin_19.x86_64.tbz2", sha256: "cca691a7f4b224c749bb29ca89987211f011df055bda32c59098b7e9d0ec927e" },
178
+ { port: "icu", file: "icu-78.3_1.darwin_19.x86_64.tbz2", sha256: "aee9d8730bd2e1c5e1476b1d781e40c17311b81038a348e0295f530019bd2538" }
179
+ ],
180
+ npm: { port: "npm10", file: "npm10-10.9.8_0.any_any.noarch.tbz2", sha256: "17d50e577d7ab0d6e2c34b2847a6befcd83f6e2b59d5064e40e0f7f6266c5ff0" }
181
+ }
182
+ };
183
+ var PNPM_FALLBACK = "10";
184
+ var SHARE = '"$HOME/.local/share/clikcode"';
185
+ var BIN_LINK = '"$HOME/.local/bin/clikcode"';
186
+ var OWN_NODE_BIN = '"$HOME/.local/share/clikcode/node/bin"';
187
+ function repoUrl() {
188
+ return process.env.CLIKCODE_REMOTE_REPO_URL?.trim() || REMOTE_REPO_URL;
189
+ }
190
+ function nodeMirror() {
191
+ return (process.env.CLIKCODE_REMOTE_NODE_MIRROR?.trim() || NODE_MIRROR).replace(/\/+$/, "");
192
+ }
193
+ function macportsMirror() {
194
+ return (process.env.CLIKCODE_REMOTE_MACPORTS_MIRROR?.trim() || MACPORTS_MIRROR).replace(/\/+$/, "");
195
+ }
196
+ function macportsPins() {
197
+ const json = process.env.CLIKCODE_REMOTE_MACPORTS_PINS?.trim();
198
+ return json ? JSON.parse(json) : MACPORTS_NODE;
199
+ }
200
+ var INSTALL_STEPS = ["Checking the machine", "Node.js", "git", "Getting ClikCode from GitHub", "Building and installing", "Checking the install"];
201
+ function nodeIsNewEnough(version) {
202
+ const match = /^v?(\d+)\.(\d+)/.exec(version?.trim() ?? "");
203
+ if (!match) return false;
204
+ const [major, minor] = [Number(match[1]), Number(match[2])];
205
+ return major > MIN_NODE[0] || major === MIN_NODE[0] && minor >= MIN_NODE[1];
206
+ }
207
+ function probeScript() {
208
+ return [
209
+ `printf 'os=%s\\n' "$(uname -s 2>/dev/null)"`,
210
+ `printf 'arch=%s\\n' "$(uname -m 2>/dev/null)"`,
211
+ `printf 'home=%s\\n' "$HOME"`,
212
+ `if [ "$(uname -s 2>/dev/null)" = Darwin ]; then printf 'macos=%s\\n' "$(sw_vers -productVersion 2>/dev/null)"; fi`,
213
+ `printf 'git=%s\\n' "$(command -v git 2>/dev/null)"`,
214
+ // A Node counts only when it runs: `node -v` failing (a build for a newer
215
+ // macOS, a missing library) is what it said, on one line.
216
+ `oneline() { printf '%s' "$1" | tr '\\n\\r' ' ' | cut -c1-400; }`,
217
+ `n="$(command -v node 2>/dev/null)"; printf 'node=%s\\n' "$n"`,
218
+ `if [ -n "$n" ]; then if v="$("$n" -v 2>/dev/null)"; then printf 'nodeVersion=%s\\n' "$v"; else printf 'nodeError=%s\\n' "$(oneline "$("$n" -v 2>&1)")"; fi; fi`,
219
+ `own=${SHARE}/node/bin/node; if [ -e "$own" ]; then if v="$("$own" -v 2>/dev/null)"; then printf 'ownNodeVersion=%s\\n' "$v"; else printf 'ownNodeError=%s\\n' "$(oneline "$("$own" -v 2>&1)")"; fi; fi`,
220
+ `link=${BIN_LINK}; if [ -L "$link" ]; then case "$(readlink "$link")" in ${SHARE}/*) echo clikcode=ours;; *) echo clikcode=other;; esac; elif [ -e "$link" ]; then echo clikcode=other; fi`,
221
+ `echo probe=ok`
222
+ ].join("\n");
223
+ }
224
+ var keyValues = (text) => {
225
+ const values = /* @__PURE__ */ new Map();
226
+ for (const line of text.split("\n")) {
227
+ const at = line.indexOf("=");
228
+ if (at > 0) values.set(line.slice(0, at).trim(), line.slice(at + 1).trim());
229
+ }
230
+ return values;
231
+ };
232
+ function parseProbe(stdout) {
233
+ const values = keyValues(stdout);
234
+ if (values.get("probe") !== "ok") return void 0;
235
+ const value = (key) => values.get(key) || void 0;
236
+ const clikcode = value("clikcode");
237
+ return {
238
+ os: value("os") ?? "",
239
+ arch: value("arch") ?? "",
240
+ home: value("home") ?? "",
241
+ ...Object.fromEntries(["macos", "git", "node", "nodeVersion", "nodeError", "ownNodeVersion", "ownNodeError"].flatMap((key) => value(key) ? [[key, value(key)]] : [])),
242
+ ...clikcode === "ours" || clikcode === "other" ? { clikcode } : {}
243
+ };
244
+ }
245
+ function looksLikeWindows(result, probe) {
246
+ if (probe) return /^(MINGW|MSYS|CYGWIN|Windows)/i.test(probe.os);
247
+ return /is not recognized as an internal or external command|The term 'sh' is not recognized|CommandNotFoundException|Windows/i.test(`${result.stdout}
248
+ ${result.stderr}`);
249
+ }
250
+ function nodePlatform(probe) {
251
+ const os = probe.os === "Linux" ? "linux" : probe.os === "Darwin" ? "darwin" : void 0;
252
+ const arch = { x86_64: "x64", amd64: "x64", aarch64: "arm64", arm64: "arm64" }[probe.arch];
253
+ return os && arch ? { os, arch } : void 0;
254
+ }
255
+ function macosVersion(text) {
256
+ const match = /^(\d+)\.(\d+)(?:\.(\d+))?/.exec(text?.trim() ?? "");
257
+ return match ? [Number(match[1]), Number(match[2]), Number(match[3] ?? 0)] : void 0;
258
+ }
259
+ var atLeast = (version, floor) => {
260
+ for (let at = 0; at < floor.length; at += 1) if ((version[at] ?? 0) !== floor[at]) return (version[at] ?? 0) > floor[at];
261
+ return true;
262
+ };
263
+ function nodeSource(probe, machine, pins = macportsPins()) {
264
+ const platform = nodePlatform(probe);
265
+ if (!platform) return { kind: "refused", message: `${machine} is ${probe.os || "an unknown OS"} on ${probe.arch || "an unknown CPU"}; ClikCode Remote installs on Linux and macOS (x64, arm64).` };
266
+ if (platform.os === "linux") return { kind: "nodejs", line: "latest-v24.x", ...platform };
267
+ const version = macosVersion(probe.macos);
268
+ if (!version) return { kind: "refused", message: `${machine} did not say which macOS it runs (sw_vers -productVersion), so ClikCode cannot tell which Node.js runs there. Install Node.js ${MIN_NODE.join(".")} or newer there yourself and add it again.` };
269
+ if (atLeast(version, [13, 5])) return { kind: "nodejs", line: "latest-v24.x", ...platform };
270
+ if (atLeast(version, [11, 0])) return { kind: "nodejs", line: "latest-v22.x", ...platform };
271
+ const darwin = version[1] + 4;
272
+ const pinned = version[0] === 10 ? pins[darwin] : void 0;
273
+ if (pinned && platform.arch === "x64") return { kind: "macports", darwin, pinned };
274
+ const floor = Math.min(...Object.keys(pins).map(Number));
275
+ return { kind: "refused", message: `macOS ${probe.macos} is too old for ClikCode: it needs Node.js ${MIN_NODE.join(".")} or newer, which needs macOS 10.${floor - 4} or newer. Update macOS on ${machine}, or install Node.js ${MIN_NODE.join(".")}+ there yourself and add it again.` };
276
+ }
277
+ function nodeSourceText(source) {
278
+ return source.kind === "nodejs" ? `nodejs.org ${source.line}` : `MacPorts ${source.pinned.node.port} ${source.pinned.version}`;
279
+ }
280
+ var NODE_SCRIPT_START = [
281
+ "set -eu",
282
+ `dir=${SHARE}`,
283
+ 'mkdir -p "$dir"',
284
+ 'tmp="$(mktemp -d "${TMPDIR:-/tmp}/clikcode-node.XXXXXX")"',
285
+ `trap 'rm -rf "$tmp"' EXIT`,
286
+ 'fetch() { if command -v curl >/dev/null 2>&1; then curl -fsSL "$1" -o "$2"; elif command -v wget >/dev/null 2>&1; then wget -q -O "$2" "$1"; else echo "step-error=neither curl nor wget is installed"; exit 3; fi; }',
287
+ 'sha256() { if command -v sha256sum >/dev/null 2>&1; then s="$(sha256sum "$1")"; else s="$(shasum -a 256 "$1")"; fi; printf %s "${s%% *}"; }',
288
+ `oneline() { printf '%s' "$1" | tr '\\n\\r' ' ' | cut -c1-600; }`,
289
+ 'rm -rf "$dir/node.new"'
290
+ ];
291
+ var NODE_SCRIPT_END = [
292
+ 'if ! v="$("$dir/node.new/bin/node" -v 2>/dev/null)"; then echo "step-error=node-fails $(oneline "$("$dir/node.new/bin/node" -v 2>&1)")"; rm -rf "$dir/node.new"; exit 6; fi',
293
+ 'rm -rf "$dir/node"',
294
+ 'mv "$dir/node.new" "$dir/node"',
295
+ 'echo "nodeVersion=$v"'
296
+ ];
297
+ function nodeInstallScript(source, mirror = nodeMirror()) {
298
+ return [
299
+ ...NODE_SCRIPT_START,
300
+ `base=${shellQuote(`${mirror}/${source.line}`)}`,
301
+ `os=${shellQuote(source.os)}; arch=${shellQuote(source.arch)}`,
302
+ 'fetch "$base/SHASUMS256.txt" "$tmp/SHASUMS256.txt" || { echo "step-error=could not download $base/SHASUMS256.txt"; exit 3; }',
303
+ 'line="$(grep -E " node-v[0-9.]+-$os-$arch\\.tar\\.gz\\$" "$tmp/SHASUMS256.txt" | head -n 1)"',
304
+ '[ -n "$line" ] || { echo "step-error=nodejs.org has no Node build for $os-$arch"; exit 3; }',
305
+ 'expected="${line%% *}"; name="${line##* }"',
306
+ 'fetch "$base/$name" "$tmp/$name" || { echo "step-error=could not download $base/$name"; exit 3; }',
307
+ 'actual="$(sha256 "$tmp/$name")"',
308
+ '[ "$actual" = "$expected" ] || { echo "step-error=checksum mismatch for $name: expected $expected, got $actual"; exit 4; }',
309
+ 'mkdir "$tmp/unpacked"',
310
+ 'tar -xzf "$tmp/$name" -C "$tmp/unpacked"',
311
+ 'mv "$tmp/unpacked/${name%.tar.gz}" "$dir/node.new"',
312
+ ...NODE_SCRIPT_END
313
+ ].join("\n");
314
+ }
315
+ function macportsInstallScript(source, mirror = macportsMirror()) {
316
+ const { node, libs, npm } = source.pinned;
317
+ return [
318
+ ...NODE_SCRIPT_START,
319
+ 'for tool in otool install_name_tool codesign; do command -v "$tool" >/dev/null 2>&1 || { echo "step-error=$tool is missing: it is one of the Xcode command line tools (xcode-select --install)"; exit 3; }; done',
320
+ `base=${shellQuote(mirror)}`,
321
+ 'mkdir "$tmp/x"',
322
+ // Every archive is checked before any is unpacked.
323
+ 'get() { fetch "$base/$1/$2" "$tmp/$2" || { echo "step-error=could not download $base/$1/$2"; exit 3; }; actual="$(sha256 "$tmp/$2")"; [ "$actual" = "$3" ] || { echo "step-error=checksum mismatch for $2: expected $3, got $actual"; exit 4; }; }',
324
+ ...[node, ...libs, npm].map((archive) => `get ${shellQuote(archive.port)} ${shellQuote(archive.file)} ${shellQuote(archive.sha256)}`),
325
+ // Not share/ (man pages, docs): nothing here uses it, and on macOS 10.15
326
+ // tar cannot restore the resource fork of nodejs22's man page.
327
+ ...[node, ...libs, npm].map((archive) => `tar -xjf "$tmp/"${shellQuote(archive.file)} -C "$tmp/x" --exclude './opt/local/share/*' || { echo ${shellQuote(`step-error=could not unpack ${archive.file}`)}; exit 6; }`),
328
+ 'from="$tmp/x/opt/local"',
329
+ 'new="$dir/node.new"',
330
+ 'mkdir -p "$new/bin" "$new/lib/node_modules"',
331
+ 'cp "$from/bin/node" "$new/bin/node"',
332
+ 'chmod 755 "$new/bin/node"',
333
+ // `run FILE COMMAND...`: a failure says which tool, on which file, and what it said.
334
+ 'run() { on="${1##*/}"; shift; out="$("$@" 2>&1)" || { echo "step-error=$1 failed on $on: $(oneline "$out")"; exit 6; }; }',
335
+ // Until a pass copies nothing: each file's /opt/local/lib references,
336
+ // the library copied in when it is not yet, the reference rewritten.
337
+ "more=1",
338
+ 'while [ "$more" = 1 ]; do',
339
+ " more=0",
340
+ ' for f in "$new/bin/node" "$new"/lib/*.dylib; do',
341
+ ' [ -f "$f" ] || continue',
342
+ ' listed="$(otool -L "$f")" || { echo "step-error=otool -L ${f##*/} failed: $(oneline "$listed")"; exit 6; }',
343
+ ` for d in $(printf '%s\\n' "$listed" | tail -n +2 | awk '{print $1}' | grep '^/opt/local/lib/' || true); do`,
344
+ ' b="${d##*/}"',
345
+ ' if [ ! -e "$new/lib/$b" ]; then',
346
+ ' [ -e "$from/lib/$b" ] || { echo "step-error=${f##*/} needs $d, which no MacPorts archive ClikCode fetched has"; exit 6; }',
347
+ ' cp "$from/lib/$b" "$new/lib/$b"; chmod 755 "$new/lib/$b"; more=1',
348
+ " fi",
349
+ ' [ "${f##*/}" = "$b" ] || run "$f" install_name_tool -change "$d" "@loader_path/../lib/$b" "$f"',
350
+ " done",
351
+ " done",
352
+ "done",
353
+ 'for f in "$new"/lib/*.dylib; do [ -f "$f" ] || continue; run "$f" install_name_tool -id "@loader_path/../lib/${f##*/}" "$f"; done',
354
+ 'for f in "$new/bin/node" "$new"/lib/*.dylib; do [ -f "$f" ] || continue; run "$f" codesign -f -s - "$f"; done',
355
+ // npm, run by this node whatever its scripts' #! lines say (/opt/local/bin/node).
356
+ 'cp -R "$from/lib/node_modules/npm" "$new/lib/node_modules/npm"',
357
+ `for t in npm npx; do printf '#!/bin/sh\\nd="$(cd "$(dirname "$0")" && pwd)"\\nexec "$d/node" "$d/../lib/node_modules/npm/bin/%s-cli.js" "$@"\\n' "$t" > "$new/bin/$t"; chmod 755 "$new/bin/$t"; done`,
358
+ // A node that does not run is said by the run below, in its own words.
359
+ 'if "$new/bin/node" -v >/dev/null 2>&1 && ! out="$("$new/bin/npm" -v 2>&1)"; then echo "step-error=npm does not run: $(oneline "$out")"; exit 6; fi',
360
+ `echo ${shellQuote(`sha256=${node.sha256}`)}`,
361
+ ...NODE_SCRIPT_END
362
+ ].join("\n");
363
+ }
364
+ function sourceScript(url = repoUrl(), commit) {
365
+ return [
366
+ "set -eu",
367
+ `src=${SHARE}/src`,
368
+ `url=${shellQuote(url)}`,
369
+ `want=${shellQuote(commit ?? "")}`,
370
+ 'if [ -d "$src/.git" ]; then',
371
+ ' cd "$src"',
372
+ ' origin="$(git remote get-url origin 2>/dev/null || true)"',
373
+ ' [ "$origin" = "$url" ] || { echo "step-error=not-ours $origin"; exit 5; }',
374
+ ' echo "before=$(git rev-parse HEAD 2>/dev/null || true)"',
375
+ " action=updated",
376
+ 'elif [ -e "$src" ]; then',
377
+ ' echo "step-error=not-a-checkout"; exit 7',
378
+ "else",
379
+ ' mkdir -p "$(dirname "$src")"',
380
+ ' git clone -q --depth 1 --branch main "$url" "$src" || { echo "step-error=fetch main"; exit 9; }',
381
+ ' cd "$src"',
382
+ " action=cloned",
383
+ "fi",
384
+ 'if [ -n "$want" ]; then',
385
+ // A full sha is fetched by itself; a short one needs main's history to be found in.
386
+ ' git fetch -q --depth 1 origin "$want" 2>/dev/null || git fetch -q --unshallow origin main 2>/dev/null || git fetch -q origin main || { echo "step-error=fetch $want"; exit 9; }',
387
+ ' target="$(git rev-parse -q --verify "$want^{commit}" 2>/dev/null || true)"',
388
+ ' [ -n "$target" ] || { echo "step-error=unknown-commit $want"; exit 10; }',
389
+ "else",
390
+ ' if [ "$action" = updated ]; then git fetch -q --depth 1 origin main || { echo "step-error=fetch main"; exit 9; }; fi',
391
+ ' target="$(git rev-parse origin/main)"',
392
+ "fi",
393
+ 'git reset -q --hard "$target"',
394
+ "git clean -fdq",
395
+ 'echo "action=$action"',
396
+ 'echo "commit=$(git rev-parse HEAD)"'
397
+ ].join("\n");
398
+ }
399
+ var withOwnNode = `PATH=${OWN_NODE_BIN}:"$PATH"; export PATH`;
400
+ function buildScript(pinned = false) {
401
+ return [
402
+ "set -eu",
403
+ withOwnNode,
404
+ `cd ${SHARE}/src`,
405
+ `pm="$(node -e "const p=require('./package.json').packageManager||'';process.stdout.write(p.startsWith('pnpm@')?p.slice(5).split('+')[0]:'')" 2>/dev/null || true)"`,
406
+ `if [ -n "$pm" ] && command -v corepack >/dev/null 2>&1; then pnpm() { COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack pnpm "$@"; }; else pnpm() { npx --yes "pnpm@\${pm:-${PNPM_FALLBACK}}" "$@"; }; fi`,
407
+ // esbuild's install step runs its native binary, which needs a newer OS
408
+ // than some machines ClikCode runs on (macOS 12; a Mac on 10.15 cannot).
409
+ // Where that binary is what failed, the install goes without that step and
410
+ // the build uses esbuild's WebAssembly build (scripts/build.mjs).
411
+ "if ! pnpm install --frozen-lockfile; then",
412
+ ` if node -e "require('esbuild').transformSync('')" >/dev/null 2>&1; then exit 1; fi`,
413
+ ` echo "esbuild's native binary does not run on this machine: installing without it, to build with esbuild-wasm" >&2`,
414
+ " pnpm install --frozen-lockfile --ignore-scripts",
415
+ "fi",
416
+ ...pinned ? ["pnpm run build", "pnpm run install-local --force --even-if-behind"] : ["pnpm run install-local"],
417
+ "echo build=ok"
418
+ ].join("\n");
419
+ }
420
+ function verifyScript() {
421
+ return [
422
+ "set -eu",
423
+ withOwnNode,
424
+ `bin=${BIN_LINK}`,
425
+ '[ -e "$bin" ] || { echo "step-error=~/.local/bin/clikcode is missing"; exit 8; }',
426
+ 'echo "version=$("$bin" --version)"',
427
+ 'echo "info=$("$bin" remote-info)"'
428
+ ].join("\n");
429
+ }
430
+ function bridgeScript() {
431
+ return [withOwnNode, `CLIKCODE_IDE_MULTIPLEX=1 ${WIRE_GZIP_ENV}=1 exec ${BIN_LINK} ide-bridge --stdio`].join("\n");
432
+ }
433
+ function remoteTerminalScript(spec) {
434
+ return [withOwnNode, `exec ${BIN_LINK} ide-terminal ${shellQuote(spec)}`].join("\n");
435
+ }
436
+ function uninstallScript(data) {
437
+ return [
438
+ `d=${SHARE}`,
439
+ 'rm -rf "$d/src" "$d/release" "$d/node"',
440
+ `link=${BIN_LINK}`,
441
+ 'if [ -L "$link" ]; then case "$(readlink "$link")" in "$d"/*) rm -f "$link";; esac; fi',
442
+ ...data ? ['rm -rf "$HOME/.clikcode"'] : [],
443
+ 'rmdir "$d" 2>/dev/null || true',
444
+ "echo uninstall=ok"
445
+ ].join("\n");
446
+ }
447
+ var STEP_TIMEOUT_MS = 5 * 6e4;
448
+ var BUILD_TIMEOUT_MS = 20 * 6e4;
449
+ var NOTICE = /^\s*(npm (notice|warn)|WARN\s)/;
450
+ var lastLines = (text, count = 3) => text.trim().split("\n").filter((line) => line.trim() && !NOTICE.test(line)).slice(-count).join(" / ");
451
+ function stepError(result) {
452
+ const said = keyValues(result.stdout).get("step-error");
453
+ return said ?? (lastLines(result.stderr) || lastLines(result.stdout) || `exit ${result.code}`);
454
+ }
455
+ async function probeMachine(target) {
456
+ const step = "Checking the machine";
457
+ const result = await runSsh(target, probeScript(), { timeoutMs: 6e4 });
458
+ const failure = sshFailure(result);
459
+ if (failure) {
460
+ return { failed: { ok: false, step, message: sshFailureMessage(target, result), ...failure === "auth" ? { auth: true } : {}, ...failure === "unreachable" ? { unreachable: true } : {} } };
461
+ }
462
+ const probe = parseProbe(result.stdout);
463
+ if (!probe || looksLikeWindows(result, probe)) {
464
+ if (looksLikeWindows(result, probe)) return { failed: { ok: false, step, windows: true, message: `${target} runs Windows. ClikCode Remote does not support Windows machines yet.` } };
465
+ return { failed: { ok: false, step, message: `${target} did not run the check (${stepError(result)}). ClikCode Remote needs a POSIX shell (sh) there.` } };
466
+ }
467
+ return { probe };
468
+ }
469
+ async function installOnMachine(target, reporter, options = {}) {
470
+ const steps = options.update ? ["Checking the machine", ...UPDATE_STEPS] : [...INSTALL_STEPS];
471
+ const progress = stepper(reporter, steps.length);
472
+ const fail = (step, message) => ({ ok: false, step, message });
473
+ progress.begin("Checking the machine");
474
+ const probed = await probeMachine(target);
475
+ if (probed.failed) return probed.failed;
476
+ const probe = probed.probe;
477
+ if (!nodePlatform(probe)) return fail("Checking the machine", `${target} is ${probe.os || "an unknown OS"} on ${probe.arch || "an unknown CPU"}; ClikCode Remote installs on Linux and macOS (x64, arm64).`);
478
+ if (probe.clikcode === "other") return fail("Checking the machine", `${target} already has a ~/.local/bin/clikcode that ClikCode Remote did not install. Move it away (or remove it) and choose the machine again.`);
479
+ const ownUsable = nodeIsNewEnough(probe.ownNodeVersion);
480
+ const systemUsable = nodeIsNewEnough(probe.nodeVersion);
481
+ const source = options.update || ownUsable || systemUsable ? void 0 : nodeSource(probe, target);
482
+ if (source?.kind === "refused") return fail("Checking the machine", source.message);
483
+ reporter.done("Checking the machine", probe.os === "Darwin" ? `macOS${probe.macos ? ` ${probe.macos}` : ""} ${probe.arch}` : `${probe.os} ${probe.arch}`);
484
+ if (!options.update) {
485
+ progress.begin("Node.js");
486
+ const node = await nodeStep(target, probe, source);
487
+ if (!node.ok) return fail("Node.js", node.message);
488
+ reporter.done("Node.js", node.detail);
489
+ progress.begin("git");
490
+ if (!probe.git) {
491
+ const remedy = probe.os === "Darwin" ? "run `xcode-select --install` there" : "install it with the machine's package manager (for example `sudo apt install git`)";
492
+ return fail("git", `${target} has no git. ClikCode never uses sudo: ${remedy}, then choose the machine again.`);
493
+ }
494
+ reporter.done("git", probe.git);
495
+ }
496
+ const updated = await runManagedUpdate(sshRunner(target), target, progress, options.commit ? { commit: options.commit } : {});
497
+ if (!updated.ok) return updated;
498
+ if (updated.upToDate) return fail("Checking the install", `ClikCode on ${target} was not checked.`);
499
+ return { ok: true, info: updated.info, probe, ...updated.from ? { from: updated.from } : {} };
500
+ }
501
+ async function nodeStep(target, probe, source) {
502
+ const yourself = `Install Node.js ${MIN_NODE.join(".")} or newer there yourself, then choose the machine again.`;
503
+ const ownThere = Boolean(probe.ownNodeVersion || probe.ownNodeError);
504
+ const ownWas = probe.ownNodeError ? "no longer ran" : "was too old";
505
+ if (nodeIsNewEnough(probe.ownNodeVersion)) return { ok: true, detail: `ClikCode's own ${probe.ownNodeVersion}` };
506
+ if (!source) {
507
+ if (ownThere) {
508
+ const removed = await runSsh(target, `rm -rf ${SHARE}/node && echo removed=ok`, { timeoutMs: 6e4 });
509
+ if (keyValues(removed.stdout).get("removed") !== "ok") return { ok: false, message: `Removing ClikCode's own Node on ${target}, which ${ownWas}, failed: ${sshFailure(removed) ? sshFailureMessage(target, removed) : stepError(removed)}.` };
510
+ }
511
+ return { ok: true, detail: `${probe.nodeVersion} (already installed)${ownThere ? `; ClikCode's own Node, which ${ownWas}, removed` : ""}` };
512
+ }
513
+ if (source.kind === "refused") return { ok: false, message: source.message };
514
+ const from = nodeSourceText(source);
515
+ const result = await runSsh(target, source.kind === "nodejs" ? nodeInstallScript(source) : macportsInstallScript(source), { timeoutMs: STEP_TIMEOUT_MS });
516
+ if (result.code !== 0) {
517
+ if (sshFailure(result)) return { ok: false, message: sshFailureMessage(target, result) };
518
+ const said = stepError(result);
519
+ if (said.startsWith("node-fails")) return { ok: false, message: `Node.js from ${from} was installed on ${target} but does not run: ${said.slice(10).trim() || `exit ${result.code}`}. ${yourself}` };
520
+ return { ok: false, message: `Installing Node.js from ${from} on ${target} failed: ${said}. ${yourself}` };
521
+ }
522
+ const version = keyValues(result.stdout).get("nodeVersion");
523
+ if (!nodeIsNewEnough(version)) return { ok: false, message: `Node.js from ${from} on ${target} runs but says it is ${version || "no version"}; ClikCode needs ${MIN_NODE.join(".")} or newer. ${yourself}` };
524
+ const notes = [
525
+ ...probe.nodeError ? [`the node at ${probe.node} does not run, so it is not used`] : [],
526
+ ...ownThere ? [`it replaces ClikCode's own Node, which ${ownWas}`] : []
527
+ ];
528
+ return { ok: true, detail: `${version} from ${from} into ~/.local/share/clikcode/node (${source.kind === "nodejs" ? "SHA-256 checked" : "SHA-256 pinned"}, runs)${notes.length ? `; ${notes.join("; ")}` : ""}` };
529
+ }
530
+ var sshRunner = (target) => (script, options) => runSsh(target, script, options);
531
+ var localRunner = (script, options) => new Promise((resolve) => {
532
+ let child;
533
+ try {
534
+ child = spawn2("/bin/sh", ["-c", script], { cwd: homedir(), stdio: ["ignore", "pipe", "pipe"] });
535
+ } catch (error) {
536
+ resolve({ code: 127, stdout: "", stderr: error instanceof Error ? error.message : String(error) });
537
+ return;
538
+ }
539
+ let stdout = "";
540
+ let stderr = "";
541
+ child.stdout.on("data", (chunk) => {
542
+ stdout += chunk.toString("utf8");
543
+ });
544
+ child.stderr.on("data", (chunk) => {
545
+ stderr = `${stderr}${chunk.toString("utf8")}`.slice(-2e4);
546
+ });
547
+ const timer = setTimeout(() => {
548
+ stderr += "\ntimed out";
549
+ child.kill("SIGTERM");
550
+ }, options.timeoutMs);
551
+ timer.unref();
552
+ child.once("error", (error) => {
553
+ clearTimeout(timer);
554
+ resolve({ code: 127, stdout, stderr: error.message });
555
+ });
556
+ child.once("close", (code) => {
557
+ clearTimeout(timer);
558
+ resolve({ code: code ?? 1, stdout, stderr });
559
+ });
560
+ });
561
+ var UPDATE_STEPS = ["Getting ClikCode from GitHub", "Building and installing", "Checking the install"];
562
+ function stepper(reporter, total) {
563
+ let index = 0;
564
+ return {
565
+ begin: (step) => {
566
+ index += 1;
567
+ reporter.start(step, index, total);
568
+ },
569
+ done: (step, detail) => reporter.done(step, detail)
570
+ };
571
+ }
572
+ async function runManagedUpdate(run, where, progress, options = {}) {
573
+ const fail = (step, message) => ({ ok: false, step, message });
574
+ const source = "Getting ClikCode from GitHub";
575
+ progress.begin(source);
576
+ const fetched = await run(sourceScript(repoUrl(), options.commit), { timeoutMs: STEP_TIMEOUT_MS });
577
+ const values = keyValues(fetched.stdout);
578
+ if (fetched.code !== 0) {
579
+ if (sshFailure(fetched)) return fail(source, sshFailureMessage(where, fetched));
580
+ const said = values.get("step-error") ?? "";
581
+ if (said.startsWith("not-ours")) return fail(source, `~/.local/share/clikcode/src on ${where} is a checkout of ${said.slice(9) || "another repository"}, not ${repoUrl()}; ClikCode will not touch it. Move it away, then try again.`);
582
+ if (said === "not-a-checkout") return fail(source, `~/.local/share/clikcode/src on ${where} exists and is not a git checkout; ClikCode will not touch it. Move it away, then try again.`);
583
+ if (said.startsWith("unknown-commit") || options.commit && said.startsWith("fetch")) return fail(source, `${repoUrl()} has no commit ${options.commit} that ${where} could fetch. Push it to main, or name another commit.`);
584
+ return fail(source, `Getting ClikCode on ${where} failed: ${stepError(fetched)}. Check that it can reach github.com.`);
585
+ }
586
+ const to = values.get("commit") ?? "";
587
+ const from = values.get("before") || void 0;
588
+ progress.done(source, `${values.get("action") ?? "done"} at ${to.slice(0, 8)}`);
589
+ if (options.running !== void 0 && from === to && (options.running || to) === to) return { ok: true, upToDate: true, from: to, to };
590
+ const build = "Building and installing";
591
+ progress.begin(build);
592
+ const pinned = Boolean(options.commit);
593
+ const built = await run(buildScript(pinned), { timeoutMs: BUILD_TIMEOUT_MS });
594
+ if (built.code !== 0 || keyValues(built.stdout).get("build") !== "ok") {
595
+ const rerun = pinned ? "pnpm install --frozen-lockfile && pnpm run build && pnpm run install-local --force --even-if-behind" : "pnpm install --frozen-lockfile && pnpm run install-local";
596
+ return fail(build, `Building ClikCode on ${where} failed: ${stepError(built)}. Run \`cd ~/.local/share/clikcode/src && ${rerun}\` there to see the whole error.`);
597
+ }
598
+ progress.done(build, "~/.local/bin/clikcode");
599
+ const check = "Checking the install";
600
+ progress.begin(check);
601
+ const verify = await run(verifyScript(), { timeoutMs: 6e4 });
602
+ const info = parseRemoteInfo(keyValues(verify.stdout).get("info"));
603
+ if (verify.code !== 0 || !info) return fail(check, `ClikCode on ${where} did not start: ${stepError(verify)}.`);
604
+ progress.done(check, `ClikCode ${info.version}${info.commit ? ` (${info.commit.slice(0, 8)})` : ""}`);
605
+ return { ok: true, info, to: info.commit ?? to, ...from ? { from } : {} };
606
+ }
607
+ function parseRemoteInfo(text) {
608
+ if (!text) return void 0;
609
+ try {
610
+ const parsed = JSON.parse(text);
611
+ if (typeof parsed.version !== "string") return void 0;
612
+ return {
613
+ version: parsed.version,
614
+ ...typeof parsed.commit === "string" && parsed.commit ? { commit: parsed.commit } : {},
615
+ ...typeof parsed.installationId === "string" && parsed.installationId ? { installationId: parsed.installationId } : {}
616
+ };
617
+ } catch {
618
+ return void 0;
619
+ }
620
+ }
621
+ async function uninstallFromMachine(target, data) {
622
+ const result = await runSsh(target, uninstallScript(data), { timeoutMs: 12e4 });
623
+ if (result.code === 0 && keyValues(result.stdout).get("uninstall") === "ok") return { ok: true };
624
+ return { ok: false, message: sshFailure(result) ? sshFailureMessage(target, result) : stepError(result) };
625
+ }
626
+
627
+ export {
628
+ shellQuote,
629
+ validateSshTarget,
630
+ targetHost,
631
+ targetUser,
632
+ withUser,
633
+ sshArgv,
634
+ spawnSsh,
635
+ runSsh,
636
+ defaultLoginUser,
637
+ bridgeScript,
638
+ remoteTerminalScript,
639
+ installOnMachine,
640
+ localRunner,
641
+ UPDATE_STEPS,
642
+ stepper,
643
+ runManagedUpdate,
644
+ uninstallFromMachine
645
+ };