clikcode 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -14
- package/dist/chunk-23TDEBGZ.js +71 -0
- package/dist/chunk-25T3GVS7.js +425 -0
- package/dist/chunk-2BBELGHY.js +11 -0
- package/dist/chunk-2EOL5PZL.js +208 -0
- package/dist/chunk-2GAB36IE.js +26 -0
- package/dist/chunk-2OLS7V66.js +2440 -0
- package/dist/chunk-2QFO2URB.js +179 -0
- package/dist/chunk-2QWPQRSU.js +254 -0
- package/dist/chunk-2YPAPAR3.js +184 -0
- package/dist/chunk-2ZAG5372.js +33 -0
- package/dist/chunk-32IKAIZC.js +12507 -0
- package/dist/chunk-34AZEGYW.js +95 -0
- package/dist/chunk-34JQYQCA.js +175 -0
- package/dist/chunk-34ZISPAO.js +67 -0
- package/dist/chunk-3AAAARE6.js +46 -0
- package/dist/chunk-3AJ6Q3OY.js +510 -0
- package/dist/chunk-3B2CHX7M.js +884 -0
- package/dist/chunk-3BUFORRX.js +59 -0
- package/dist/chunk-3QLHYYFK.js +30 -0
- package/dist/chunk-3RXBMYKZ.js +140 -0
- package/dist/chunk-3TFNIJWS.js +52 -0
- package/dist/chunk-3W3IPDFP.js +119 -0
- package/dist/chunk-3WMS7SEE.js +417 -0
- package/dist/chunk-435ZNSZ3.js +23 -0
- package/dist/chunk-4AQ5NINV.js +39 -0
- package/dist/chunk-4GVEJ5FK.js +168 -0
- package/dist/chunk-4GXAO3UY.js +262 -0
- package/dist/chunk-4L2ZZM4Q.js +332 -0
- package/dist/chunk-4LPDG57B.js +17 -0
- package/dist/chunk-4NN3XQQT.js +223 -0
- package/dist/chunk-4QZEZME7.js +54 -0
- package/dist/chunk-4R6CSC3S.js +38 -0
- package/dist/chunk-4RHXTL3W.js +514 -0
- package/dist/chunk-4SJMPTVQ.js +18 -0
- package/dist/chunk-4VY7G6TX.js +114 -0
- package/dist/chunk-5642PBF7.js +124 -0
- package/dist/chunk-5B6TVO4A.js +33 -0
- package/dist/chunk-5BJLDUPL.js +62 -0
- package/dist/chunk-5HMFFJWU.js +19 -0
- package/dist/chunk-5IKLK33T.js +69 -0
- package/dist/chunk-5NQ5FFMX.js +44 -0
- package/dist/chunk-5QNNW5L6.js +176 -0
- package/dist/chunk-5SM5UAWN.js +239 -0
- package/dist/chunk-5WYJTA6O.js +74 -0
- package/dist/chunk-5ZSR2Y5T.js +227 -0
- package/dist/chunk-5ZWUM5GH.js +39 -0
- package/dist/chunk-64E7D4HY.js +364 -0
- package/dist/chunk-6CK466BC.js +99 -0
- package/dist/chunk-6ES45HHO.js +138 -0
- package/dist/chunk-6HYEZFGL.js +277 -0
- package/dist/chunk-6Y7HLXGW.js +29 -0
- package/dist/chunk-6YKK4FYR.js +258 -0
- package/dist/chunk-74WNMLMS.js +117 -0
- package/dist/chunk-7AULZ7OD.js +55 -0
- package/dist/chunk-7DOKGSUN.js +101 -0
- package/dist/chunk-7IH5LTIZ.js +195 -0
- package/dist/chunk-7ISTS5NS.js +21 -0
- package/dist/chunk-7NMUTGOW.js +527 -0
- package/dist/chunk-7PNHUZEL.js +153 -0
- package/dist/chunk-7TSQLONI.js +88 -0
- package/dist/chunk-AE7TOLD5.js +30 -0
- package/dist/chunk-AEMHSXKA.js +130 -0
- package/dist/chunk-AKRYTS2D.js +211 -0
- package/dist/chunk-AMNSE36L.js +59 -0
- package/dist/chunk-AZVD74ZV.js +23 -0
- package/dist/chunk-B35DVOTK.js +1981 -0
- package/dist/chunk-B4HNJRAH.js +626 -0
- package/dist/chunk-B5WYPPHS.js +13 -0
- package/dist/chunk-BBOVDXQM.js +59 -0
- package/dist/chunk-BD3ECZLK.js +62 -0
- package/dist/chunk-BDGSOT74.js +4578 -0
- package/dist/chunk-BF5VEOPK.js +31 -0
- package/dist/chunk-BFFRW4XH.js +47 -0
- package/dist/chunk-BFPC6PEW.js +208 -0
- package/dist/chunk-BGEMY2JJ.js +376 -0
- package/dist/chunk-BISGNHKD.js +35 -0
- package/dist/chunk-BMRAEBRY.js +21 -0
- package/dist/chunk-BNTXAZXW.js +127 -0
- package/dist/chunk-BOQBXGSN.js +75 -0
- package/dist/chunk-BTJDSTQP.js +213 -0
- package/dist/chunk-BUOPJQP5.js +218 -0
- package/dist/chunk-BXFJS65Q.js +52 -0
- package/dist/chunk-BXPQFSX5.js +59 -0
- package/dist/chunk-C57LIWNY.js +1269 -0
- package/dist/chunk-C6YVCCWR.js +74 -0
- package/dist/chunk-CAADDF6M.js +167 -0
- package/dist/chunk-CBANJFBO.js +69 -0
- package/dist/chunk-CERF3RIB.js +597 -0
- package/dist/chunk-COAS5ETR.js +46 -0
- package/dist/chunk-CQ7J6UQ7.js +78 -0
- package/dist/chunk-CRUVYGO2.js +26 -0
- package/dist/chunk-CVFVFRGN.js +58 -0
- package/dist/chunk-D2UK66HM.js +37 -0
- package/dist/chunk-D2W7SA4R.js +18 -0
- package/dist/chunk-DA44ZENT.js +501 -0
- package/dist/chunk-DAJ76TOC.js +99 -0
- package/dist/chunk-DCZ6CIUM.js +147 -0
- package/dist/chunk-DF35KMXM.js +1314 -0
- package/dist/chunk-DGASQT26.js +151 -0
- package/dist/chunk-DJT57C5P.js +55 -0
- package/dist/chunk-DKDPZTD3.js +44 -0
- package/dist/chunk-DQYVQ2N7.js +77 -0
- package/dist/chunk-DRTP2RTY.js +266 -0
- package/dist/chunk-DW2BMUKY.js +61 -0
- package/dist/chunk-DW5T5ZVU.js +307 -0
- package/dist/chunk-DXKNDNFC.js +164 -0
- package/dist/chunk-DZEQ7UYR.js +291 -0
- package/dist/chunk-E4F4OUAC.js +463 -0
- package/dist/chunk-EE4B6A7W.js +69 -0
- package/dist/chunk-EISKIYWG.js +23 -0
- package/dist/chunk-EKAQK7UQ.js +235 -0
- package/dist/chunk-EOBTJV32.js +123 -0
- package/dist/chunk-ESF3DIZY.js +325 -0
- package/dist/chunk-EVOHOZ4U.js +45 -0
- package/dist/chunk-EXN4KHLB.js +110 -0
- package/dist/chunk-F252T6Y3.js +78 -0
- package/dist/chunk-F3DP4ZA2.js +40 -0
- package/dist/chunk-F6F47QAY.js +58 -0
- package/dist/chunk-FA3Y23ZW.js +57 -0
- package/dist/chunk-FBKXE4EJ.js +640 -0
- package/dist/chunk-FCGEB3H6.js +23 -0
- package/dist/chunk-FF7ZVYJF.js +3732 -0
- package/dist/chunk-FFGKN6L3.js +39 -0
- package/dist/chunk-FFGU4GCC.js +94 -0
- package/dist/chunk-FSFDAOVP.js +74 -0
- package/dist/chunk-FT5TX7OX.js +1573 -0
- package/dist/chunk-G3QP67Z7.js +232 -0
- package/dist/chunk-G5ORJKV2.js +179 -0
- package/dist/chunk-GFNC62PE.js +111 -0
- package/dist/chunk-GGK43Q3N.js +67 -0
- package/dist/chunk-GGYKY4GF.js +11537 -0
- package/dist/chunk-GGYNHGNJ.js +55 -0
- package/dist/chunk-GLY7RM3C.js +354 -0
- package/dist/chunk-GQBZU6EO.js +20 -0
- package/dist/chunk-GSXENUZL.js +9 -0
- package/dist/chunk-GTOAT5D3.js +40 -0
- package/dist/chunk-GWCMDPQU.js +1007 -0
- package/dist/chunk-GXYSMYHJ.js +152 -0
- package/dist/chunk-GYMAI5NY.js +14 -0
- package/dist/chunk-H2VZMKPE.js +30 -0
- package/dist/chunk-H4THUNBM.js +2091 -0
- package/dist/chunk-HGRVSNUZ.js +361 -0
- package/dist/chunk-HI4VY473.js +27 -0
- package/dist/chunk-HOJRSD3Q.js +447 -0
- package/dist/chunk-HRX25W35.js +82 -0
- package/dist/chunk-HSE4AQYV.js +55 -0
- package/dist/chunk-HU5SSUFX.js +383 -0
- package/dist/chunk-I3GDBJLH.js +196 -0
- package/dist/chunk-I75EDU75.js +684 -0
- package/dist/chunk-IBA7DMIO.js +20 -0
- package/dist/chunk-IC6N4NZA.js +231 -0
- package/dist/chunk-IF43HIGV.js +284 -0
- package/dist/chunk-IGZ6C2MC.js +439 -0
- package/dist/chunk-IMLTL2MY.js +192 -0
- package/dist/chunk-IMZL6SGR.js +33 -0
- package/dist/chunk-IS4USJPY.js +516 -0
- package/dist/chunk-ISFSPN2F.js +82 -0
- package/dist/chunk-IXE7GTFI.js +55 -0
- package/dist/chunk-IZ77QJQG.js +36 -0
- package/dist/chunk-J2PACWRQ.js +34 -0
- package/dist/chunk-J6EGFVQX.js +180 -0
- package/dist/chunk-JEKOD43D.js +22 -0
- package/dist/chunk-JGIWATSG.js +30 -0
- package/dist/chunk-JYBONKD4.js +43 -0
- package/dist/chunk-K2NLG2HK.js +454 -0
- package/dist/chunk-KCQ4TBLS.js +164 -0
- package/dist/chunk-KD5KIVMS.js +176 -0
- package/dist/chunk-KHW6TX6I.js +63 -0
- package/dist/chunk-KI5GZFCE.js +520 -0
- package/dist/chunk-KN34B7NO.js +105 -0
- package/dist/chunk-KYUHIFP3.js +136 -0
- package/dist/chunk-KZL5VS4B.js +300 -0
- package/dist/chunk-L3VW3QIH.js +48 -0
- package/dist/chunk-LA6MG4ET.js +2110 -0
- package/dist/chunk-LAVFOA3S.js +66 -0
- package/dist/chunk-LB4OA77N.js +13 -0
- package/dist/chunk-LBFRF2K4.js +196 -0
- package/dist/chunk-LM6EIA4B.js +93 -0
- package/dist/chunk-LPCNRGJ7.js +692 -0
- package/dist/chunk-LSLNL5T3.js +168 -0
- package/dist/chunk-LVRRWP4W.js +568 -0
- package/dist/chunk-LWCFBRHL.js +33 -0
- package/dist/chunk-LXFTMGZZ.js +166 -0
- package/dist/chunk-M33LVA4M.js +151 -0
- package/dist/chunk-M3FO5UMK.js +4944 -0
- package/dist/chunk-M5QNDBAY.js +66 -0
- package/dist/chunk-M6ND6KBE.js +1291 -0
- package/dist/chunk-M7H3WQTE.js +76 -0
- package/dist/chunk-MCBRVPA7.js +191 -0
- package/dist/chunk-MCSDWZET.js +91 -0
- package/dist/chunk-MDT5XDXL.js +289 -0
- package/dist/chunk-MJG3IQY4.js +91 -0
- package/dist/chunk-MOU3N2UL.js +44 -0
- package/dist/chunk-MP4KZOQC.js +3451 -0
- package/dist/chunk-MPAJ446F.js +66 -0
- package/dist/chunk-MVJZZ6AL.js +16 -0
- package/dist/chunk-MXS6S2PY.js +253 -0
- package/dist/chunk-N3SFDYM7.js +291 -0
- package/dist/chunk-NAOX3JUB.js +13 -0
- package/dist/chunk-NEKKIBCX.js +283 -0
- package/dist/chunk-NKDATMEM.js +133 -0
- package/dist/chunk-NR4FMC4K.js +395 -0
- package/dist/chunk-NSOHOJBR.js +221 -0
- package/dist/chunk-NTDB6QKF.js +29 -0
- package/dist/chunk-NWEYRBWK.js +25 -0
- package/dist/chunk-O2YSNYWD.js +23 -0
- package/dist/chunk-O3EW7LAY.js +54 -0
- package/dist/chunk-O7BNJIXU.js +366 -0
- package/dist/chunk-OARL2NXZ.js +116 -0
- package/dist/chunk-OHKZUEJW.js +351 -0
- package/dist/chunk-OKU45BXA.js +647 -0
- package/dist/chunk-OL4JBD3J.js +59 -0
- package/dist/chunk-OLUO5DDR.js +192 -0
- package/dist/chunk-OQ245JLA.js +196 -0
- package/dist/chunk-P72UZAQI.js +289 -0
- package/dist/chunk-PAL2ENB6.js +20 -0
- package/dist/chunk-PAXYQZH7.js +53 -0
- package/dist/chunk-PDPEM5VW.js +51 -0
- package/dist/chunk-PEWCDI2C.js +668 -0
- package/dist/chunk-PGZ54EDX.js +27 -0
- package/dist/chunk-PRWVLDZF.js +73 -0
- package/dist/chunk-PSQQ75VJ.js +52 -0
- package/dist/chunk-PUOVIFHW.js +118 -0
- package/dist/chunk-PWBF2X3V.js +107 -0
- package/dist/chunk-PWXII6HF.js +43 -0
- package/dist/chunk-Q35VLJRT.js +80 -0
- package/dist/chunk-QJP7EYGL.js +128 -0
- package/dist/chunk-QPQKX2MK.js +8836 -0
- package/dist/chunk-QQRLPY25.js +1053 -0
- package/dist/chunk-QUS4ER2W.js +407 -0
- package/dist/chunk-QYHI3YET.js +29 -0
- package/dist/chunk-QYRU2UQI.js +32 -0
- package/dist/chunk-R6XVVQGC.js +13 -0
- package/dist/chunk-R7QN6ONS.js +483 -0
- package/dist/chunk-RD23MPGC.js +221 -0
- package/dist/chunk-RDDWQBEM.js +185 -0
- package/dist/chunk-RDLLDYFO.js +104 -0
- package/dist/chunk-RE4TGORR.js +84 -0
- package/dist/chunk-RJLHVYQY.js +217 -0
- package/dist/chunk-RJLPTWHW.js +905 -0
- package/dist/chunk-RKUVLRZI.js +295 -0
- package/dist/chunk-ROGXPGYR.js +37 -0
- package/dist/chunk-RSZGEL5U.js +163 -0
- package/dist/chunk-RVUOIJXN.js +909 -0
- package/dist/chunk-RW7F4JRP.js +11 -0
- package/dist/chunk-S4UO3AO3.js +53 -0
- package/dist/chunk-S5JAAF6S.js +585 -0
- package/dist/chunk-SNU37TQI.js +56 -0
- package/dist/chunk-SQVUDO2O.js +31 -0
- package/dist/chunk-SYVHIYQT.js +66 -0
- package/dist/chunk-SZBQMTG2.js +85 -0
- package/dist/chunk-T5VCXA3J.js +25 -0
- package/dist/chunk-TK6NSP56.js +30 -0
- package/dist/chunk-TKWVMA6L.js +22 -0
- package/dist/chunk-TQDKJHWX.js +59 -0
- package/dist/chunk-TQDM7S5N.js +127 -0
- package/dist/chunk-TULAXS77.js +23 -0
- package/dist/chunk-TVT45XNH.js +4625 -0
- package/dist/chunk-TWCVV2JO.js +467 -0
- package/dist/chunk-U4DKAD6S.js +47 -0
- package/dist/chunk-UA5K2BTI.js +564 -0
- package/dist/chunk-UAMKCMOK.js +40 -0
- package/dist/chunk-UBMVADBF.js +51 -0
- package/dist/chunk-UFQ5A5PW.js +645 -0
- package/dist/chunk-UOD2SOLL.js +1301 -0
- package/dist/chunk-UTSB4LOW.js +156 -0
- package/dist/chunk-UVXNIUTN.js +412 -0
- package/dist/chunk-UXVPXYPE.js +90 -0
- package/dist/chunk-UYEEMIWR.js +374 -0
- package/dist/chunk-VBGM5ZBW.js +54 -0
- package/dist/chunk-VEWPCZPG.js +762 -0
- package/dist/chunk-VIRDLZ5E.js +108 -0
- package/dist/chunk-VMPO7WKN.js +52 -0
- package/dist/chunk-W2NVSDO5.js +5122 -0
- package/dist/chunk-W3YYPBEA.js +176 -0
- package/dist/chunk-W5AYOICN.js +280 -0
- package/dist/chunk-W5GZOIUF.js +27 -0
- package/dist/chunk-WHKNLZ3C.js +76 -0
- package/dist/chunk-WKBEPPQ5.js +1409 -0
- package/dist/chunk-WM3Z6QKQ.js +151 -0
- package/dist/chunk-WMI2TPMA.js +31 -0
- package/dist/chunk-WNX5VD7S.js +150 -0
- package/dist/chunk-WOVTYST3.js +60 -0
- package/dist/chunk-WPB5WEZJ.js +546 -0
- package/dist/chunk-WUO5EOAT.js +44 -0
- package/dist/chunk-WWLJMP6D.js +133 -0
- package/dist/chunk-WZMLH3XP.js +58 -0
- package/dist/chunk-WZYVLUVQ.js +79 -0
- package/dist/chunk-X2OCPVU5.js +135 -0
- package/dist/chunk-X3CL6DTR.js +95 -0
- package/dist/chunk-X6WF7JEV.js +354 -0
- package/dist/chunk-XAHGBPWT.js +44 -0
- package/dist/chunk-XCKQ5BM2.js +228 -0
- package/dist/chunk-XIBYREEY.js +106 -0
- package/dist/chunk-XKW5NDMR.js +378 -0
- package/dist/chunk-XRDALAO3.js +100 -0
- package/dist/chunk-XUP22EAS.js +41 -0
- package/dist/chunk-XWAC3MKW.js +243 -0
- package/dist/chunk-Y3R7JMXB.js +59 -0
- package/dist/chunk-Y54LTP4W.js +82 -0
- package/dist/chunk-Y7UECI4M.js +99 -0
- package/dist/chunk-YACGDFHC.js +47 -0
- package/dist/chunk-YHNIQPKY.js +71 -0
- package/dist/chunk-YMBR6HYP.js +111 -0
- package/dist/chunk-YMCH3L2S.js +26 -0
- package/dist/chunk-Z4ZU6T7V.js +99 -0
- package/dist/chunk-ZDPF67ZZ.js +173 -0
- package/dist/chunk-ZFC2Q67K.js +101 -0
- package/dist/chunk-ZGHNNSCT.js +114 -0
- package/dist/chunk-ZGX3ERAT.js +173 -0
- package/dist/chunk-ZI3YHEBY.js +37 -0
- package/dist/chunk-ZN7G6JLS.js +639 -0
- package/dist/chunk-ZNPFQMXT.js +47 -0
- package/dist/chunk-ZOU3LV4U.js +63 -0
- package/dist/chunk-ZT7B4H2V.js +117 -0
- package/dist/chunk-ZZCBDNZI.js +58 -0
- package/dist/cli.js +498 -112593
- package/dist/computer-tools.js +36642 -21258
- package/dist/harness-catalog.cjs +88 -43
- package/dist/index.js +1 -1
- package/dist/local-model-supervisor.cjs +555 -0
- package/package.json +3 -4
|
@@ -0,0 +1,1314 @@
|
|
|
1
|
+
import { createRequire as __clikcodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __clikcodeCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
jsonMemo
|
|
5
|
+
} from "./chunk-ZT7B4H2V.js";
|
|
6
|
+
import {
|
|
7
|
+
installerEnv
|
|
8
|
+
} from "./chunk-OL4JBD3J.js";
|
|
9
|
+
import {
|
|
10
|
+
JsonRpcPeer,
|
|
11
|
+
forwardParentSignals
|
|
12
|
+
} from "./chunk-IGZ6C2MC.js";
|
|
13
|
+
import {
|
|
14
|
+
BROWSER_OPENERS
|
|
15
|
+
} from "./chunk-4AQ5NINV.js";
|
|
16
|
+
import {
|
|
17
|
+
killProcessTreePortable,
|
|
18
|
+
spawnPortable,
|
|
19
|
+
terminatePortable
|
|
20
|
+
} from "./chunk-WPB5WEZJ.js";
|
|
21
|
+
import {
|
|
22
|
+
failureText
|
|
23
|
+
} from "./chunk-CQ7J6UQ7.js";
|
|
24
|
+
import {
|
|
25
|
+
SPIN_MS,
|
|
26
|
+
waitingSpinnerGlyph
|
|
27
|
+
} from "./chunk-XKW5NDMR.js";
|
|
28
|
+
import {
|
|
29
|
+
addToProcessPath,
|
|
30
|
+
expandInstallDir,
|
|
31
|
+
installStepFor,
|
|
32
|
+
managedNpmPrefix,
|
|
33
|
+
npmPrefixBinDir
|
|
34
|
+
} from "./chunk-WZYVLUVQ.js";
|
|
35
|
+
import {
|
|
36
|
+
sleep
|
|
37
|
+
} from "./chunk-YMCH3L2S.js";
|
|
38
|
+
import {
|
|
39
|
+
pidIsAlive
|
|
40
|
+
} from "./chunk-4L2ZZM4Q.js";
|
|
41
|
+
import {
|
|
42
|
+
lifecycle,
|
|
43
|
+
quiet
|
|
44
|
+
} from "./chunk-RDDWQBEM.js";
|
|
45
|
+
import {
|
|
46
|
+
stateDirectory
|
|
47
|
+
} from "./chunk-MPAJ446F.js";
|
|
48
|
+
|
|
49
|
+
// src/harness/accounts/auth-files.ts
|
|
50
|
+
import { copyFile, cp, mkdir as mkdir2, readdir, readFile as readFile2, rename, rm as rm2, stat as stat3, writeFile as writeFile2 } from "node:fs/promises";
|
|
51
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
52
|
+
import { execFile } from "node:child_process";
|
|
53
|
+
import { homedir as homedir2 } from "node:os";
|
|
54
|
+
import { dirname as dirname2, join as join4, relative, resolve } from "node:path";
|
|
55
|
+
|
|
56
|
+
// src/harness/transport/native/binary.ts
|
|
57
|
+
import { constants } from "node:fs";
|
|
58
|
+
import { access } from "node:fs/promises";
|
|
59
|
+
import { delimiter, extname, isAbsolute, join } from "node:path";
|
|
60
|
+
function executableNames(binary, platform = process.platform, pathExt = process.env.PATHEXT) {
|
|
61
|
+
if (platform !== "win32" || extname(binary)) return [binary];
|
|
62
|
+
const extensions = (pathExt || ".COM;.EXE;.BAT;.CMD").split(";").map((value) => value.trim()).filter(Boolean);
|
|
63
|
+
return [binary, ...extensions.map((extension) => `${binary}${extension.startsWith(".") ? extension : `.${extension}`}`)];
|
|
64
|
+
}
|
|
65
|
+
async function binaryOnPath(binary, options = {}) {
|
|
66
|
+
return Boolean(await resolveBinaryPath(binary, options));
|
|
67
|
+
}
|
|
68
|
+
async function resolveBinaryPath(binary, options = {}) {
|
|
69
|
+
const platform = options.platform ?? process.platform;
|
|
70
|
+
const names = executableNames(binary, platform, options.pathExt ?? process.env.PATHEXT);
|
|
71
|
+
const directories = isAbsolute(binary) ? [""] : (options.path ?? process.env.PATH ?? "").split(platform === "win32" ? ";" : delimiter);
|
|
72
|
+
for (const rawDirectory of directories) {
|
|
73
|
+
const directory = rawDirectory.replace(/^"|"$/g, "") || ".";
|
|
74
|
+
for (const name of names) {
|
|
75
|
+
const candidate = isAbsolute(name) ? name : join(directory, name);
|
|
76
|
+
try {
|
|
77
|
+
await access(candidate, platform === "win32" ? constants.F_OK : constants.X_OK);
|
|
78
|
+
return candidate;
|
|
79
|
+
} catch {
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return void 0;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/harness/accounts/vendor-probe.ts
|
|
87
|
+
import { chmodSync, existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
88
|
+
import { delimiter as delimiter2, join as join2 } from "node:path";
|
|
89
|
+
var PROBE_DEADLINE_MS = 3e4;
|
|
90
|
+
var VENDOR_IMPORT_DEADLINE_MS = 6e4;
|
|
91
|
+
var INERT_DEADLINE_MS = 1e4;
|
|
92
|
+
var KEYRING_DEADLINE_MS = 2e4;
|
|
93
|
+
var PROBE_FETCH_MS = 15e3;
|
|
94
|
+
var KILL_GRACE_MS = 2e3;
|
|
95
|
+
var CAPTURE_LIMIT_BYTES = 2 * 1024 * 1024;
|
|
96
|
+
var STDERR_KEEP = 256 * 1024;
|
|
97
|
+
var BackgroundVendorError = class extends Error {
|
|
98
|
+
constructor(outcome, binary) {
|
|
99
|
+
super(outcome.status === "failed" ? outcome.detail ?? `${binary} ${outcome.reason}` : `${binary}: ${outcome.status}`);
|
|
100
|
+
this.outcome = outcome;
|
|
101
|
+
this.name = "BackgroundVendorError";
|
|
102
|
+
}
|
|
103
|
+
outcome;
|
|
104
|
+
};
|
|
105
|
+
function isSignedOutRefusal(error) {
|
|
106
|
+
return error instanceof BackgroundVendorError && error.outcome.status === "signed-out";
|
|
107
|
+
}
|
|
108
|
+
var NO_OP_OPENERS = [.../* @__PURE__ */ new Set([
|
|
109
|
+
...BROWSER_OPENERS,
|
|
110
|
+
"gvfs-open",
|
|
111
|
+
"gnome-open",
|
|
112
|
+
"kde-open",
|
|
113
|
+
"kde-open5",
|
|
114
|
+
"kfmclient",
|
|
115
|
+
"wslview",
|
|
116
|
+
"exo-open",
|
|
117
|
+
"firefox",
|
|
118
|
+
"google-chrome",
|
|
119
|
+
"google-chrome-stable",
|
|
120
|
+
"chromium",
|
|
121
|
+
"chromium-browser",
|
|
122
|
+
"brave-browser",
|
|
123
|
+
"microsoft-edge",
|
|
124
|
+
"lynx",
|
|
125
|
+
"w3m",
|
|
126
|
+
"links",
|
|
127
|
+
"elinks"
|
|
128
|
+
])];
|
|
129
|
+
function noBrowserDirectory() {
|
|
130
|
+
const directory = join2(stateDirectory(), "tools", "probe-no-browser");
|
|
131
|
+
try {
|
|
132
|
+
for (const name of NO_OP_OPENERS) {
|
|
133
|
+
const file = join2(directory, name);
|
|
134
|
+
if (existsSync(file)) continue;
|
|
135
|
+
mkdirSync(directory, { recursive: true });
|
|
136
|
+
writeFileSync(file, "#!/bin/sh\nexit 0\n");
|
|
137
|
+
chmodSync(file, 493);
|
|
138
|
+
}
|
|
139
|
+
return directory;
|
|
140
|
+
} catch {
|
|
141
|
+
return void 0;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function probeEnvironment(environment) {
|
|
145
|
+
if (process.platform === "win32") return { ...environment };
|
|
146
|
+
const directory = noBrowserDirectory();
|
|
147
|
+
if (!directory) return { ...environment };
|
|
148
|
+
return {
|
|
149
|
+
...environment,
|
|
150
|
+
BROWSER: join2(directory, "xdg-open"),
|
|
151
|
+
PATH: [directory, environment.PATH ?? process.env.PATH].filter(Boolean).join(delimiter2)
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function backgroundEnvironment(environment, options = {}) {
|
|
155
|
+
const merged = {};
|
|
156
|
+
for (const [name, value] of Object.entries({ ...process.env, ...environment })) if (value !== void 0) merged[name] = value;
|
|
157
|
+
delete merged.DISPLAY;
|
|
158
|
+
delete merged.WAYLAND_DISPLAY;
|
|
159
|
+
delete merged.XAUTHORITY;
|
|
160
|
+
if (!options.keyring) merged.DBUS_SESSION_BUS_ADDRESS = "unix:path=/nonexistent";
|
|
161
|
+
return probeEnvironment(merged);
|
|
162
|
+
}
|
|
163
|
+
function gateKeyring(gate) {
|
|
164
|
+
return "inert" in gate ? Boolean(gate.keyring) : Boolean(gate.keyringAuth);
|
|
165
|
+
}
|
|
166
|
+
function probeFetch(url, init = {}, timeoutMs = PROBE_FETCH_MS) {
|
|
167
|
+
const timeout = AbortSignal.timeout(timeoutMs);
|
|
168
|
+
return fetch(url, { ...init, signal: init.signal ? AbortSignal.any([init.signal, timeout]) : timeout });
|
|
169
|
+
}
|
|
170
|
+
async function mayRunSignInCapable(harness, environment) {
|
|
171
|
+
return hasAuthEvidence(harness) && await authEvidencePresent(harness, environment);
|
|
172
|
+
}
|
|
173
|
+
async function mayRunInBackground(gate, environment) {
|
|
174
|
+
if ("inert" in gate) return true;
|
|
175
|
+
if (gate.signInOptional) return true;
|
|
176
|
+
return mayRunSignInCapable(gate, environment);
|
|
177
|
+
}
|
|
178
|
+
function gateBinary(spec) {
|
|
179
|
+
const binary = spec.binary ?? ("inert" in spec.gate ? void 0 : spec.gate.binary);
|
|
180
|
+
if (!binary) throw new Error("A background vendor run needs a binary");
|
|
181
|
+
return binary;
|
|
182
|
+
}
|
|
183
|
+
async function runVendorProcess(spec, use) {
|
|
184
|
+
if (spec.signal?.aborted) return { status: "failed", reason: "cancelled" };
|
|
185
|
+
if (!await mayRunInBackground(spec.gate, spec.environment)) return { status: "signed-out" };
|
|
186
|
+
const binary = gateBinary(spec);
|
|
187
|
+
const executable = await resolveBinaryPath(binary);
|
|
188
|
+
if (!executable) return { status: "missing" };
|
|
189
|
+
const detached = process.platform !== "win32";
|
|
190
|
+
let child;
|
|
191
|
+
try {
|
|
192
|
+
child = spawnPortable(executable, [...spec.argv], {
|
|
193
|
+
stdio: [spec.stdin ?? "ignore", "pipe", "pipe"],
|
|
194
|
+
env: backgroundEnvironment(spec.environment, { keyring: gateKeyring(spec.gate) }),
|
|
195
|
+
detached,
|
|
196
|
+
windowsHide: true,
|
|
197
|
+
...spec.cwd ? { cwd: spec.cwd } : {}
|
|
198
|
+
});
|
|
199
|
+
} catch (error) {
|
|
200
|
+
return { status: "failed", reason: "spawn", detail: error instanceof Error ? error.message : String(error) };
|
|
201
|
+
}
|
|
202
|
+
child.stdin?.on("error", () => void 0);
|
|
203
|
+
child.stdout?.on("error", () => void 0);
|
|
204
|
+
child.stderr?.on("error", () => void 0);
|
|
205
|
+
const controller = new AbortController();
|
|
206
|
+
let timer;
|
|
207
|
+
const deadline = new Promise((resolve2) => {
|
|
208
|
+
timer = setTimeout(() => {
|
|
209
|
+
controller.abort();
|
|
210
|
+
resolve2({ status: "failed", reason: "timeout", detail: `${binary} did not answer within ${spec.deadlineMs} ms` });
|
|
211
|
+
}, spec.deadlineMs);
|
|
212
|
+
});
|
|
213
|
+
const onCancel = () => controller.abort();
|
|
214
|
+
const cancelled = new Promise((resolve2) => {
|
|
215
|
+
spec.signal?.addEventListener("abort", () => {
|
|
216
|
+
onCancel();
|
|
217
|
+
resolve2({ status: "failed", reason: "cancelled" });
|
|
218
|
+
}, { once: true });
|
|
219
|
+
});
|
|
220
|
+
const failed = new Promise((resolve2) => {
|
|
221
|
+
child.once("error", (error) => resolve2({ status: "failed", reason: "spawn", detail: error.message }));
|
|
222
|
+
});
|
|
223
|
+
const answered = use(child, controller.signal).then(
|
|
224
|
+
(value) => ({ status: "ok", value }),
|
|
225
|
+
(error) => ({ status: "failed", reason: "error", detail: error instanceof Error ? error.message : String(error) })
|
|
226
|
+
);
|
|
227
|
+
try {
|
|
228
|
+
return await Promise.race([answered, deadline, cancelled, failed]);
|
|
229
|
+
} finally {
|
|
230
|
+
if (timer) clearTimeout(timer);
|
|
231
|
+
controller.abort();
|
|
232
|
+
stopGroup(child, detached);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
async function probeVendor(spec, use) {
|
|
236
|
+
const outcome = await runVendorProcess(spec, (child, signal) => {
|
|
237
|
+
child.stderr?.resume();
|
|
238
|
+
return use(child, signal);
|
|
239
|
+
});
|
|
240
|
+
return outcome.status === "ok" ? outcome.value : void 0;
|
|
241
|
+
}
|
|
242
|
+
function stopGroup(child, detached) {
|
|
243
|
+
killProcessTreePortable(child, "SIGTERM", detached);
|
|
244
|
+
const pid = child.pid;
|
|
245
|
+
if (!detached || !pid) return;
|
|
246
|
+
const kill = setTimeout(() => {
|
|
247
|
+
try {
|
|
248
|
+
process.kill(-pid, "SIGKILL");
|
|
249
|
+
} catch {
|
|
250
|
+
}
|
|
251
|
+
}, KILL_GRACE_MS);
|
|
252
|
+
kill.unref();
|
|
253
|
+
}
|
|
254
|
+
function runVendorCommand(spec) {
|
|
255
|
+
const binary = gateBinary(spec);
|
|
256
|
+
return runVendorProcess({ ...spec, stdin: spec.stdinText === void 0 ? "ignore" : "pipe" }, (child) => new Promise((resolve2, reject) => {
|
|
257
|
+
if (spec.stdinText !== void 0) child.stdin?.end(spec.stdinText);
|
|
258
|
+
let stdout = "";
|
|
259
|
+
let stderr = "";
|
|
260
|
+
let exceeded = false;
|
|
261
|
+
child.stdout.setEncoding("utf8");
|
|
262
|
+
child.stderr.setEncoding("utf8");
|
|
263
|
+
child.stdout.on("data", (chunk) => {
|
|
264
|
+
stdout += chunk;
|
|
265
|
+
if (stdout.length > CAPTURE_LIMIT_BYTES && !exceeded) {
|
|
266
|
+
exceeded = true;
|
|
267
|
+
killProcessTreePortable(child, "SIGKILL", process.platform !== "win32");
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
child.stderr.on("data", (chunk) => {
|
|
271
|
+
stderr = (stderr + chunk).slice(-STDERR_KEEP);
|
|
272
|
+
});
|
|
273
|
+
child.once("close", (code, killedBy) => {
|
|
274
|
+
if (exceeded) return reject(new Error(`${binary} printed more than ${CAPTURE_LIMIT_BYTES / 1024 / 1024} MiB`));
|
|
275
|
+
if (code === 0) return resolve2({ stdout, stderr });
|
|
276
|
+
const why = failureText(stderr);
|
|
277
|
+
reject(new Error(`${binary} ${killedBy ? `stopped (${killedBy})` : `exited ${code ?? 1}`}${why ? `: ${why}` : ""}`));
|
|
278
|
+
});
|
|
279
|
+
}));
|
|
280
|
+
}
|
|
281
|
+
async function vendorCommandText(spec) {
|
|
282
|
+
const outcome = await runVendorCommand(spec);
|
|
283
|
+
if (outcome.status !== "ok") throw new BackgroundVendorError(outcome, gateBinary(spec));
|
|
284
|
+
const { stdout, stderr } = outcome.value;
|
|
285
|
+
return stdout.trim() ? stdout : stderr.trim() ? stderr : stdout;
|
|
286
|
+
}
|
|
287
|
+
async function probeCommand(gate, argv, environment, deadlineMs = PROBE_DEADLINE_MS) {
|
|
288
|
+
const outcome = await runVendorCommand({ gate, argv, environment, deadlineMs });
|
|
289
|
+
return outcome.status === "ok" ? outcome.value.stdout : void 0;
|
|
290
|
+
}
|
|
291
|
+
function queryJsonRpc(spec, ask) {
|
|
292
|
+
return probeVendor({ ...spec, stdin: "pipe" }, async (child, signal) => {
|
|
293
|
+
const peer = new JsonRpcPeer(child, {
|
|
294
|
+
label: spec.label,
|
|
295
|
+
detached: process.platform !== "win32",
|
|
296
|
+
forwardParentSignals: false,
|
|
297
|
+
...spec.jsonrpcVersion === void 0 ? {} : { jsonrpcVersion: spec.jsonrpcVersion },
|
|
298
|
+
...spec.framing ? { framing: spec.framing } : {}
|
|
299
|
+
});
|
|
300
|
+
signal.addEventListener("abort", () => peer.rejectPending(new Error(`${spec.label} probe timed out`)), { once: true });
|
|
301
|
+
return ask(peer, signal);
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// src/harness/transport/native/version-memo.ts
|
|
306
|
+
import { stat } from "node:fs/promises";
|
|
307
|
+
var memo = jsonMemo("harness-versions.json", () => ({ v: 1, harnesses: {} }), (parsed) => {
|
|
308
|
+
const file = parsed;
|
|
309
|
+
return file.v === 1 && file.harnesses && typeof file.harnesses === "object" ? file : void 0;
|
|
310
|
+
});
|
|
311
|
+
function sameFingerprint(left, right) {
|
|
312
|
+
return Boolean(left && right && left.path === right.path && left.mtimeMs === right.mtimeMs && left.size === right.size);
|
|
313
|
+
}
|
|
314
|
+
async function binaryFingerprint(path) {
|
|
315
|
+
if (!path) return void 0;
|
|
316
|
+
try {
|
|
317
|
+
const info = await stat(path);
|
|
318
|
+
return { path, mtimeMs: info.mtimeMs, size: info.size };
|
|
319
|
+
} catch {
|
|
320
|
+
return void 0;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
async function harnessBinaryIdentity(binary) {
|
|
324
|
+
const fingerprint = await binaryFingerprint(await resolveBinaryPath(binary));
|
|
325
|
+
return fingerprint ? `${fingerprint.path}:${fingerprint.mtimeMs}:${fingerprint.size}` : void 0;
|
|
326
|
+
}
|
|
327
|
+
async function rememberedVersion(command, fingerprint) {
|
|
328
|
+
if (!fingerprint) return void 0;
|
|
329
|
+
const entry = (await memo.load()).harnesses[command];
|
|
330
|
+
return sameFingerprint(entry, fingerprint) && !entry.error ? entry : void 0;
|
|
331
|
+
}
|
|
332
|
+
async function rememberVersion(command, fingerprint, result) {
|
|
333
|
+
const data = await memo.load();
|
|
334
|
+
if (result.error) {
|
|
335
|
+
delete data.harnesses[command];
|
|
336
|
+
memo.changed();
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
data.harnesses[command] = { ...fingerprint, ...result.version ? { version: result.version } : {} };
|
|
340
|
+
memo.changed();
|
|
341
|
+
}
|
|
342
|
+
async function saveVersionMemo() {
|
|
343
|
+
await memo.save();
|
|
344
|
+
}
|
|
345
|
+
function resetVersionMemo() {
|
|
346
|
+
memo.reset();
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// src/harness/transport/native/install.ts
|
|
350
|
+
import { constants as constants2 } from "node:fs";
|
|
351
|
+
import { access as access2, mkdir, mkdtemp, readFile, rm, stat as stat2, writeFile } from "node:fs/promises";
|
|
352
|
+
import { homedir, tmpdir } from "node:os";
|
|
353
|
+
import { dirname, join as join3 } from "node:path";
|
|
354
|
+
|
|
355
|
+
// src/tui/active-terminal.ts
|
|
356
|
+
var TERMINAL = {};
|
|
357
|
+
|
|
358
|
+
// src/tui/capabilities.ts
|
|
359
|
+
import { stdin as input, stdout as output } from "node:process";
|
|
360
|
+
function environmentFlag(...values) {
|
|
361
|
+
const value = values.find((candidate) => candidate !== void 0 && candidate !== "");
|
|
362
|
+
return value !== void 0 && value !== "0" && value.toLowerCase() !== "false";
|
|
363
|
+
}
|
|
364
|
+
function screenReaderMode(environment = process.env) {
|
|
365
|
+
return environmentFlag(environment.CLIKCODE_SCREEN_READER);
|
|
366
|
+
}
|
|
367
|
+
function reducedMotion(environment = process.env) {
|
|
368
|
+
return environmentFlag(environment.CLIKCODE_REDUCED_MOTION, environment.NO_MOTION);
|
|
369
|
+
}
|
|
370
|
+
function terminalUiSupported(stdinTty = Boolean(input.isTTY), stdoutTty = Boolean(output.isTTY), environment = process.env) {
|
|
371
|
+
if (environment.CLIKCODE_TUI?.trim().toLowerCase() === "classic") return false;
|
|
372
|
+
if (screenReaderMode(environment)) return false;
|
|
373
|
+
return stdinTty && stdoutTty && environment.TERM?.toLowerCase() !== "dumb";
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// src/harness/install-progress.ts
|
|
377
|
+
var FAILURE_TAIL_LINES = 12;
|
|
378
|
+
function installFailureTail(output2, limit = FAILURE_TAIL_LINES) {
|
|
379
|
+
const lines = output2.split(/\r?\n/).filter((line) => line.trim() && !/^\s*(?:npm (?:notice|fund|warn deprecated)|\d+ packages are looking for funding|run `npm fund`)/i.test(line));
|
|
380
|
+
return lines.slice(-limit).join("\n");
|
|
381
|
+
}
|
|
382
|
+
function startSpinner(label, write = (text) => process.stdout.write(text), isTty = process.stdout.isTTY, still = reducedMotion()) {
|
|
383
|
+
if (!isTty) {
|
|
384
|
+
write(`${label}
|
|
385
|
+
`);
|
|
386
|
+
return { stop: (finalLine) => {
|
|
387
|
+
if (finalLine) write(`${finalLine}
|
|
388
|
+
`);
|
|
389
|
+
} };
|
|
390
|
+
}
|
|
391
|
+
let frame = 0;
|
|
392
|
+
const paint = () => {
|
|
393
|
+
write(`\r\x1B[2K\x1B[2m${waitingSpinnerGlyph(frame)}\x1B[0m ${label}`);
|
|
394
|
+
frame += 1;
|
|
395
|
+
};
|
|
396
|
+
paint();
|
|
397
|
+
const timer = still ? void 0 : setInterval(paint, SPIN_MS);
|
|
398
|
+
timer?.unref?.();
|
|
399
|
+
return {
|
|
400
|
+
stop: (finalLine) => {
|
|
401
|
+
if (timer) clearInterval(timer);
|
|
402
|
+
write(`\r\x1B[2K${finalLine ? `${finalLine}
|
|
403
|
+
` : ""}`);
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// src/harness/transport/native/install-route.ts
|
|
409
|
+
function harnessInstallRoute(spec, platform = process.platform) {
|
|
410
|
+
if (spec.npmPackage) return { kind: "npm", package: spec.npmPackage };
|
|
411
|
+
const step = installStepFor(spec.installer, platform);
|
|
412
|
+
if (step?.kind === "script") return { kind: "script", step };
|
|
413
|
+
if (step?.kind === "uv-tool") return { kind: "uv-tool", step };
|
|
414
|
+
if (spec.installer) {
|
|
415
|
+
return { kind: "none", reason: `${spec.displayName} publishes no installer for ${platformName(platform)}; see ${spec.installer.docs}.` };
|
|
416
|
+
}
|
|
417
|
+
return { kind: "none", reason: `ClikCode has no installer for ${spec.displayName}; install it so a \`${spec.binary}\` command is on PATH.` };
|
|
418
|
+
}
|
|
419
|
+
function platformName(platform) {
|
|
420
|
+
return platform === "win32" ? "Windows" : platform === "darwin" ? "macOS" : platform === "linux" ? "Linux" : platform;
|
|
421
|
+
}
|
|
422
|
+
function manualInstallCommand(route, platform = process.platform) {
|
|
423
|
+
switch (route.kind) {
|
|
424
|
+
case "npm":
|
|
425
|
+
return `npm install -g ${route.package}`;
|
|
426
|
+
case "uv-tool":
|
|
427
|
+
return `uv tool install ${route.step.python ? `--python ${route.step.python} ` : ""}${route.step.package}${(route.step.with ?? []).map((name) => ` --with ${name}`).join("")}`;
|
|
428
|
+
case "script": {
|
|
429
|
+
const args = route.step.args ?? [];
|
|
430
|
+
if (platform === "win32") {
|
|
431
|
+
const env2 = Object.entries(route.step.env ?? {}).map(([name, value]) => `$env:${name}='${value}'; `).join("");
|
|
432
|
+
return args.length ? `${env2}& ([scriptblock]::Create((irm '${route.step.url}'))) ${args.join(" ")}` : `${env2}irm '${route.step.url}' | iex`;
|
|
433
|
+
}
|
|
434
|
+
const env = Object.entries(route.step.env ?? {}).map(([name, value]) => `${name}=${value} `).join("");
|
|
435
|
+
return `curl -fsSL '${route.step.url}' | ${env}bash${args.length ? ` -s -- ${args.join(" ")}` : ""}`;
|
|
436
|
+
}
|
|
437
|
+
default:
|
|
438
|
+
return void 0;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// src/harness/transport/native/install.ts
|
|
443
|
+
var processReporter;
|
|
444
|
+
function setHarnessInstallReporter(reporter) {
|
|
445
|
+
processReporter = reporter;
|
|
446
|
+
}
|
|
447
|
+
function defaultReporter() {
|
|
448
|
+
if (processReporter) return processReporter;
|
|
449
|
+
const terminal = TERMINAL.active;
|
|
450
|
+
if (terminal) return terminalInstallReporter(terminal);
|
|
451
|
+
let spinner;
|
|
452
|
+
const write = (text) => {
|
|
453
|
+
process.stderr.write(text);
|
|
454
|
+
};
|
|
455
|
+
return {
|
|
456
|
+
start: (label) => {
|
|
457
|
+
spinner?.stop();
|
|
458
|
+
spinner = startSpinner(label, write, process.stderr.isTTY);
|
|
459
|
+
},
|
|
460
|
+
done: (message) => {
|
|
461
|
+
spinner?.stop(message);
|
|
462
|
+
spinner = void 0;
|
|
463
|
+
},
|
|
464
|
+
failed: () => {
|
|
465
|
+
spinner?.stop();
|
|
466
|
+
spinner = void 0;
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
function terminalInstallReporter(terminal) {
|
|
471
|
+
let started = false;
|
|
472
|
+
let borrowed;
|
|
473
|
+
const end = () => {
|
|
474
|
+
if (!started) return;
|
|
475
|
+
started = false;
|
|
476
|
+
if (borrowed !== void 0) terminal.updateWaitingLabel(borrowed);
|
|
477
|
+
else terminal.stopWaiting();
|
|
478
|
+
};
|
|
479
|
+
return {
|
|
480
|
+
start: (label) => {
|
|
481
|
+
if (!started) {
|
|
482
|
+
started = true;
|
|
483
|
+
borrowed = terminal.waitingLabel();
|
|
484
|
+
if (borrowed === void 0) {
|
|
485
|
+
terminal.startWaiting(label);
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
terminal.updateWaitingLabel(label);
|
|
490
|
+
},
|
|
491
|
+
done: () => {
|
|
492
|
+
end();
|
|
493
|
+
},
|
|
494
|
+
failed: end
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
function requiredBinaries(spec) {
|
|
498
|
+
return [.../* @__PURE__ */ new Set([spec.binary, ...spec.acp?.binary ? [spec.acp.binary] : []])];
|
|
499
|
+
}
|
|
500
|
+
async function missingBinaries(spec) {
|
|
501
|
+
const missing = [];
|
|
502
|
+
for (const binary of requiredBinaries(spec)) if (!await resolveBinaryPath(binary)) missing.push(binary);
|
|
503
|
+
return missing;
|
|
504
|
+
}
|
|
505
|
+
var inFlight = /* @__PURE__ */ new Map();
|
|
506
|
+
async function ensureHarnessInstalled(spec, options = {}) {
|
|
507
|
+
const route = harnessInstallRoute(spec);
|
|
508
|
+
if (!(await missingBinaries(spec)).length) return false;
|
|
509
|
+
if (route.kind === "none") throw new Error(installFailureMessage(spec, route, new Error(route.reason)));
|
|
510
|
+
const running = inFlight.get(spec.command);
|
|
511
|
+
if (running) return running;
|
|
512
|
+
const work = installOnce(spec, route, options.reporter ?? defaultReporter());
|
|
513
|
+
inFlight.set(spec.command, work);
|
|
514
|
+
try {
|
|
515
|
+
return await work;
|
|
516
|
+
} finally {
|
|
517
|
+
inFlight.delete(spec.command);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
async function installOnce(spec, route, reporter) {
|
|
521
|
+
const label = `installing ${spec.displayName}\u2026`;
|
|
522
|
+
let shown = false;
|
|
523
|
+
const show = (text) => {
|
|
524
|
+
shown = true;
|
|
525
|
+
reporter.start(text);
|
|
526
|
+
};
|
|
527
|
+
try {
|
|
528
|
+
const installed = await withInstallLock(spec.command, async () => {
|
|
529
|
+
if (!(await missingBinaries(spec)).length) return false;
|
|
530
|
+
show(label);
|
|
531
|
+
const missingBefore = await missingBinaries(spec);
|
|
532
|
+
try {
|
|
533
|
+
if (missingBefore.includes(spec.binary) || !spec.acp?.npmPackage) await runRoute(spec, route);
|
|
534
|
+
if (spec.acp?.binary && spec.acp.npmPackage && missingBefore.includes(spec.acp.binary)) {
|
|
535
|
+
await installNpmPackage(spec.acp.npmPackage);
|
|
536
|
+
}
|
|
537
|
+
} catch (error) {
|
|
538
|
+
if (route.kind !== "script" || (await missingBinaries(spec)).length) throw error;
|
|
539
|
+
}
|
|
540
|
+
const missing = await missingBinaries(spec);
|
|
541
|
+
if (missing.length) {
|
|
542
|
+
throw new Error(`the installer finished, but \`${missing.join("`, `")}\` is not on PATH or in ${searchedDirs(route).join(", ") || "any directory it declares"}`);
|
|
543
|
+
}
|
|
544
|
+
return true;
|
|
545
|
+
}, () => show(`waiting for another ClikCode to finish installing ${spec.displayName}\u2026`));
|
|
546
|
+
if (installed) reporter.done(`Installed ${spec.displayName}.`);
|
|
547
|
+
else if (shown) reporter.done(`${spec.displayName} is installed.`);
|
|
548
|
+
return installed;
|
|
549
|
+
} catch (error) {
|
|
550
|
+
const message = installFailureMessage(spec, route, error);
|
|
551
|
+
if (shown) reporter.failed(message);
|
|
552
|
+
throw new Error(message, { cause: error });
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
function installFailureMessage(spec, route, error) {
|
|
556
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
557
|
+
if (route.kind === "none") return `${reason} Then retry /${spec.command}.`;
|
|
558
|
+
const manual = manualInstallCommand(route);
|
|
559
|
+
const source = route.kind === "npm" ? "" : ` (from ${spec.installer?.docs ?? "the vendor"})`;
|
|
560
|
+
return `Could not install ${spec.displayName} automatically: ${reason}` + (manual ? `
|
|
561
|
+
|
|
562
|
+
To install it yourself${source}:
|
|
563
|
+
|
|
564
|
+
${manual}
|
|
565
|
+
|
|
566
|
+
Then retry /${spec.command}.` : "");
|
|
567
|
+
}
|
|
568
|
+
function searchedDirs(route) {
|
|
569
|
+
if (route.kind === "script" || route.kind === "uv-tool") {
|
|
570
|
+
return route.step.binDirs.map((dir) => expandInstallDir(dir)).filter((dir) => Boolean(dir));
|
|
571
|
+
}
|
|
572
|
+
return [];
|
|
573
|
+
}
|
|
574
|
+
async function runRoute(spec, route) {
|
|
575
|
+
if (route.kind === "npm") return installNpmPackage(route.package);
|
|
576
|
+
addToProcessPath(searchedDirs(route));
|
|
577
|
+
if (route.kind === "script") return runInstallerScript(route.step);
|
|
578
|
+
return installUvTool(route.step);
|
|
579
|
+
}
|
|
580
|
+
function runInstallCommand(command, args, options = {}) {
|
|
581
|
+
return new Promise((resolve2, reject) => {
|
|
582
|
+
const child = spawnPortable(command, [...args], {
|
|
583
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
584
|
+
env: options.env ?? process.env,
|
|
585
|
+
detached: process.platform !== "win32",
|
|
586
|
+
windowsHide: true,
|
|
587
|
+
...options.cwd ? { cwd: options.cwd } : {}
|
|
588
|
+
});
|
|
589
|
+
let output2 = "";
|
|
590
|
+
const collect = (chunk) => {
|
|
591
|
+
output2 += chunk.toString();
|
|
592
|
+
if (output2.length > 256e3) output2 = output2.slice(-128e3);
|
|
593
|
+
};
|
|
594
|
+
child.stdout?.on("data", collect);
|
|
595
|
+
child.stderr?.on("data", collect);
|
|
596
|
+
const timer = setTimeout(() => {
|
|
597
|
+
output2 += `
|
|
598
|
+
${command} did not finish within ${Math.round((options.timeoutMs ?? INSTALL_TIMEOUT_MS) / 6e4)} minutes and was stopped.`;
|
|
599
|
+
if (child.pid && process.platform !== "win32") {
|
|
600
|
+
try {
|
|
601
|
+
process.kill(-child.pid, "SIGKILL");
|
|
602
|
+
} catch {
|
|
603
|
+
terminatePortable(child, "SIGKILL");
|
|
604
|
+
}
|
|
605
|
+
} else terminatePortable(child, "SIGKILL");
|
|
606
|
+
}, options.timeoutMs ?? INSTALL_TIMEOUT_MS);
|
|
607
|
+
timer.unref();
|
|
608
|
+
child.once("error", (error) => {
|
|
609
|
+
clearTimeout(timer);
|
|
610
|
+
reject(error);
|
|
611
|
+
});
|
|
612
|
+
child.once("close", (code) => {
|
|
613
|
+
clearTimeout(timer);
|
|
614
|
+
resolve2({ code, output: output2 });
|
|
615
|
+
});
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
var INSTALL_TIMEOUT_MS = 20 * 6e4;
|
|
619
|
+
function commandFailure(what, result) {
|
|
620
|
+
const tail = installFailureTail(result.output);
|
|
621
|
+
return new Error(`${what} exited ${result.code ?? "abnormally"}${tail ? `
|
|
622
|
+
${tail}` : ""}`);
|
|
623
|
+
}
|
|
624
|
+
async function npmGlobalPrefix() {
|
|
625
|
+
try {
|
|
626
|
+
const result = await runInstallCommand("npm", ["prefix", "--global"], { timeoutMs: 6e4 });
|
|
627
|
+
const prefix = result.output.trim().split(/\r?\n/).pop()?.trim();
|
|
628
|
+
return result.code === 0 && prefix ? prefix : void 0;
|
|
629
|
+
} catch {
|
|
630
|
+
return void 0;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
async function npmPrefixWritable(prefix, platform = process.platform) {
|
|
634
|
+
const targets = platform === "win32" ? [join3(prefix, "node_modules"), prefix] : [join3(prefix, "lib", "node_modules"), join3(prefix, "bin")];
|
|
635
|
+
for (const target of targets) {
|
|
636
|
+
let candidate = target;
|
|
637
|
+
for (; ; ) {
|
|
638
|
+
try {
|
|
639
|
+
await stat2(candidate);
|
|
640
|
+
break;
|
|
641
|
+
} catch {
|
|
642
|
+
const parent = dirname(candidate);
|
|
643
|
+
if (parent === candidate) return false;
|
|
644
|
+
candidate = parent;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
try {
|
|
648
|
+
await access2(candidate, constants2.W_OK);
|
|
649
|
+
} catch {
|
|
650
|
+
return false;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
return true;
|
|
654
|
+
}
|
|
655
|
+
var refreshing = /* @__PURE__ */ new Map();
|
|
656
|
+
var REFRESH_EVERY_MS = 6 * 60 * 60 * 1e3;
|
|
657
|
+
function refreshAcpAgent(spec, deps = {}) {
|
|
658
|
+
const npmPackage = spec.acp?.npmPackage;
|
|
659
|
+
if (!npmPackage) return Promise.resolve(false);
|
|
660
|
+
const running = refreshing.get(spec.command);
|
|
661
|
+
if (running) return running;
|
|
662
|
+
const now = deps.now ?? Date.now;
|
|
663
|
+
const stamp = join3(deps.directory ?? join3(stateDirectory(), "tools"), `acp-refresh-${spec.command.replace(/[^A-Za-z0-9._-]/g, "_")}.json`);
|
|
664
|
+
const work = (async () => {
|
|
665
|
+
try {
|
|
666
|
+
const last = JSON.parse(await readFile(stamp, "utf8"));
|
|
667
|
+
if (typeof last.at === "number" && now() - last.at < REFRESH_EVERY_MS) return false;
|
|
668
|
+
} catch {
|
|
669
|
+
}
|
|
670
|
+
try {
|
|
671
|
+
await withInstallLock(`${spec.command}-acp`, () => (deps.install ?? installNpmPackage)(npmPackage));
|
|
672
|
+
await mkdir(dirname(stamp), { recursive: true });
|
|
673
|
+
await writeFile(stamp, JSON.stringify({ at: now(), package: npmPackage }));
|
|
674
|
+
lifecycle("vendor.acp-agent.refreshed", { harness: spec.command, package: npmPackage });
|
|
675
|
+
return true;
|
|
676
|
+
} catch (error) {
|
|
677
|
+
lifecycle("vendor.acp-agent.refresh-failed", { harness: spec.command, package: npmPackage, message: (error instanceof Error ? error.message : String(error)).slice(0, 300) });
|
|
678
|
+
return false;
|
|
679
|
+
}
|
|
680
|
+
})();
|
|
681
|
+
refreshing.set(spec.command, work);
|
|
682
|
+
return work;
|
|
683
|
+
}
|
|
684
|
+
function isPermissionFailure(output2) {
|
|
685
|
+
return /\b(EACCES|EPERM|EROFS)\b|permission denied|read-only file system/i.test(output2);
|
|
686
|
+
}
|
|
687
|
+
async function installNpmPackage(npmPackage) {
|
|
688
|
+
const globalPrefix = await npmGlobalPrefix();
|
|
689
|
+
if (globalPrefix && await npmPrefixWritable(globalPrefix)) {
|
|
690
|
+
const result2 = await runInstallCommand("npm", ["install", "--global", npmPackage]);
|
|
691
|
+
if (result2.code === 0) {
|
|
692
|
+
addToProcessPath([npmPrefixBinDir(globalPrefix)]);
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
if (!isPermissionFailure(result2.output)) throw commandFailure(`npm install --global ${npmPackage}`, result2);
|
|
696
|
+
}
|
|
697
|
+
const prefix = managedNpmPrefix();
|
|
698
|
+
await mkdir(prefix, { recursive: true });
|
|
699
|
+
const result = await runInstallCommand("npm", ["install", "--global", "--prefix", prefix, npmPackage]);
|
|
700
|
+
if (result.code !== 0) throw commandFailure(`npm install --global --prefix ${prefix} ${npmPackage}`, result);
|
|
701
|
+
addToProcessPath([npmPrefixBinDir(prefix)]);
|
|
702
|
+
}
|
|
703
|
+
function assertInstallerUrl(url) {
|
|
704
|
+
let parsed;
|
|
705
|
+
try {
|
|
706
|
+
parsed = new URL(url);
|
|
707
|
+
} catch {
|
|
708
|
+
throw new Error(`installer URL is not a URL: ${url}`);
|
|
709
|
+
}
|
|
710
|
+
if (parsed.protocol !== "https:") throw new Error(`refusing to run an installer from a non-https URL: ${url}`);
|
|
711
|
+
return parsed;
|
|
712
|
+
}
|
|
713
|
+
async function downloadInstaller(url, destination) {
|
|
714
|
+
assertInstallerUrl(url);
|
|
715
|
+
let body;
|
|
716
|
+
let fetchError;
|
|
717
|
+
try {
|
|
718
|
+
const response = await fetch(url, { redirect: "follow", signal: AbortSignal.timeout(12e4) });
|
|
719
|
+
assertInstallerUrl(response.url || url);
|
|
720
|
+
if (!response.ok) throw new Error(`${url} answered HTTP ${response.status}`);
|
|
721
|
+
body = await response.text();
|
|
722
|
+
} catch (error) {
|
|
723
|
+
fetchError = error;
|
|
724
|
+
}
|
|
725
|
+
if (body === void 0) {
|
|
726
|
+
const result = await runInstallCommand("curl", ["-fsSL", "--proto", "=https", "--proto-redir", "=https", "-o", destination, url], { timeoutMs: 18e4 }).catch(quiet("harness/transport/native/install"));
|
|
727
|
+
if (result?.code === 0) return;
|
|
728
|
+
throw new Error(`could not download ${url}: ${fetchError instanceof Error ? fetchError.message : String(fetchError)}`);
|
|
729
|
+
}
|
|
730
|
+
if (!body.trim()) throw new Error(`${url} returned an empty installer`);
|
|
731
|
+
await writeFile(destination, body, { mode: 448 });
|
|
732
|
+
}
|
|
733
|
+
async function firstOnPath(names) {
|
|
734
|
+
for (const name of names) if (await resolveBinaryPath(name)) return name;
|
|
735
|
+
return void 0;
|
|
736
|
+
}
|
|
737
|
+
async function runInstallerScript(step) {
|
|
738
|
+
const windows = process.platform === "win32";
|
|
739
|
+
const directory = await mkdtemp(join3(tmpdir(), "clikcode-install-"));
|
|
740
|
+
try {
|
|
741
|
+
const script = join3(directory, windows ? "install.ps1" : "install.sh");
|
|
742
|
+
await downloadInstaller(step.url, script);
|
|
743
|
+
const env = installerEnv(process.env, step.env ?? {});
|
|
744
|
+
let command;
|
|
745
|
+
let args;
|
|
746
|
+
if (windows) {
|
|
747
|
+
command = await firstOnPath(["pwsh", "powershell"]) ?? "powershell";
|
|
748
|
+
args = ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-File", script, ...step.args ?? []];
|
|
749
|
+
} else {
|
|
750
|
+
command = await firstOnPath(["bash", "sh"]) ?? "sh";
|
|
751
|
+
args = [script, ...step.args ?? []];
|
|
752
|
+
}
|
|
753
|
+
const result = await runInstallCommand(command, args, { env, cwd: directory });
|
|
754
|
+
if (result.code !== 0) throw commandFailure(`the installer from ${step.url}`, result);
|
|
755
|
+
} finally {
|
|
756
|
+
await rm(directory, { recursive: true, force: true }).catch(quiet("harness/transport/native/install"));
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
var UV_INSTALLER = {
|
|
760
|
+
posix: "https://astral.sh/uv/install.sh",
|
|
761
|
+
windows: "https://astral.sh/uv/install.ps1"
|
|
762
|
+
};
|
|
763
|
+
async function installUvTool(step) {
|
|
764
|
+
addToProcessPath([join3(homedir(), ".local", "bin"), join3(homedir(), ".cargo", "bin")]);
|
|
765
|
+
if (!await resolveBinaryPath("uv")) {
|
|
766
|
+
await runInstallerScript({
|
|
767
|
+
kind: "script",
|
|
768
|
+
url: process.platform === "win32" ? UV_INSTALLER.windows : UV_INSTALLER.posix,
|
|
769
|
+
// ClikCode finds ~/.local/bin itself; the user's shell profile is left alone.
|
|
770
|
+
env: { UV_NO_MODIFY_PATH: "1" },
|
|
771
|
+
binDirs: ["~/.local/bin"]
|
|
772
|
+
});
|
|
773
|
+
if (!await resolveBinaryPath("uv")) throw new Error("uv was installed but cannot be found in ~/.local/bin");
|
|
774
|
+
}
|
|
775
|
+
const installArgv = [
|
|
776
|
+
"tool",
|
|
777
|
+
"install",
|
|
778
|
+
...step.python ? ["--python", step.python] : [],
|
|
779
|
+
step.package,
|
|
780
|
+
...(step.with ?? []).flatMap((name) => ["--with", name])
|
|
781
|
+
];
|
|
782
|
+
const result = await runInstallCommand("uv", installArgv);
|
|
783
|
+
if (result.code !== 0) throw commandFailure(`uv ${installArgv.join(" ")}`, result);
|
|
784
|
+
const bin = await runInstallCommand("uv", ["tool", "dir", "--bin"], { timeoutMs: 6e4 }).catch(quiet("harness/transport/native/install"));
|
|
785
|
+
const dir = bin?.code === 0 ? bin.output.trim().split(/\r?\n/).pop()?.trim() : void 0;
|
|
786
|
+
if (dir) addToProcessPath([dir]);
|
|
787
|
+
}
|
|
788
|
+
var LOCK_STALE_MS = INSTALL_TIMEOUT_MS + 5 * 6e4;
|
|
789
|
+
var LOCK_POLL_MS = 250;
|
|
790
|
+
var LOCK_MAX_WAIT_MS = 10 * 60 * 1e3;
|
|
791
|
+
async function withInstallLock(key, work, onWait, options = {}) {
|
|
792
|
+
const directory = options.directory ?? join3(stateDirectory(), "tools", "locks");
|
|
793
|
+
await mkdir(directory, { recursive: true });
|
|
794
|
+
const lock = join3(directory, `${key.replace(/[^A-Za-z0-9._-]/g, "_")}.lock`);
|
|
795
|
+
const owner = join3(lock, "owner.json");
|
|
796
|
+
let waited = false;
|
|
797
|
+
const waitStarted = Date.now();
|
|
798
|
+
for (; ; ) {
|
|
799
|
+
try {
|
|
800
|
+
await mkdir(lock);
|
|
801
|
+
await writeFile(owner, JSON.stringify({ pid: process.pid, at: Date.now() }));
|
|
802
|
+
break;
|
|
803
|
+
} catch (error) {
|
|
804
|
+
if (error.code !== "EEXIST") throw error;
|
|
805
|
+
}
|
|
806
|
+
let holder;
|
|
807
|
+
try {
|
|
808
|
+
holder = JSON.parse(await readFile(owner, "utf8"));
|
|
809
|
+
} catch {
|
|
810
|
+
holder = void 0;
|
|
811
|
+
}
|
|
812
|
+
const since = holder?.at ?? await stat2(lock).then((info) => info.mtimeMs).catch(() => Date.now());
|
|
813
|
+
const dead = holder?.pid !== void 0 && !pidIsAlive(holder.pid);
|
|
814
|
+
if (dead || Date.now() - since > (options.staleMs ?? LOCK_STALE_MS)) {
|
|
815
|
+
await rm(lock, { recursive: true, force: true }).catch(quiet("harness/transport/native/install"));
|
|
816
|
+
continue;
|
|
817
|
+
}
|
|
818
|
+
if (!waited) {
|
|
819
|
+
waited = true;
|
|
820
|
+
onWait?.();
|
|
821
|
+
}
|
|
822
|
+
if (Date.now() - waitStarted > (options.maxWaitMs ?? LOCK_MAX_WAIT_MS)) {
|
|
823
|
+
throw new Error(`another ClikCode install of ${key} is still running (pid ${holder?.pid ?? "unknown"}); try again once it finishes`);
|
|
824
|
+
}
|
|
825
|
+
await sleep(options.pollMs ?? LOCK_POLL_MS);
|
|
826
|
+
}
|
|
827
|
+
try {
|
|
828
|
+
return await work();
|
|
829
|
+
} finally {
|
|
830
|
+
await rm(lock, { recursive: true, force: true }).catch(quiet("harness/transport/native/install"));
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
// src/harness/transport/native/inspect.ts
|
|
835
|
+
var inspectionCache = /* @__PURE__ */ new Map();
|
|
836
|
+
var pickerInspectionCache = /* @__PURE__ */ new Map();
|
|
837
|
+
async function inspectNativeHarnessForPicker(spec) {
|
|
838
|
+
const identity = await harnessBinaryIdentity(spec.binary);
|
|
839
|
+
const cached = inspectionCache.get(spec.command);
|
|
840
|
+
if (cached && cached.identity === identity) return cached.result;
|
|
841
|
+
const pickerCached = pickerInspectionCache.get(spec.command);
|
|
842
|
+
if (pickerCached && pickerCached.identity === identity) return pickerCached.result;
|
|
843
|
+
const result = { installed: identity !== void 0 };
|
|
844
|
+
pickerInspectionCache.set(spec.command, { identity, result });
|
|
845
|
+
if (!result.installed) inspectionCache.set(spec.command, { identity, result });
|
|
846
|
+
return result;
|
|
847
|
+
}
|
|
848
|
+
function clearNativeHarnessInspectionCache(command) {
|
|
849
|
+
if (command === void 0) {
|
|
850
|
+
inspectionCache.clear();
|
|
851
|
+
pickerInspectionCache.clear();
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
854
|
+
inspectionCache.delete(command);
|
|
855
|
+
pickerInspectionCache.delete(command);
|
|
856
|
+
resetVersionMemo();
|
|
857
|
+
}
|
|
858
|
+
async function inspectNativeHarness(spec, timeoutMs = 5e3) {
|
|
859
|
+
const fingerprint = await binaryFingerprint(await resolveBinaryPath(spec.binary));
|
|
860
|
+
const identity = fingerprint ? `${fingerprint.path}:${fingerprint.mtimeMs}:${fingerprint.size}` : void 0;
|
|
861
|
+
const cached = inspectionCache.get(spec.command);
|
|
862
|
+
if (cached && cached.identity === identity) return cached.result;
|
|
863
|
+
const remembered = await rememberedVersion(spec.command, fingerprint);
|
|
864
|
+
if (remembered) {
|
|
865
|
+
const result2 = {
|
|
866
|
+
installed: true,
|
|
867
|
+
...remembered.version ? { version: remembered.version } : {},
|
|
868
|
+
...remembered.error ? { error: remembered.error } : {}
|
|
869
|
+
};
|
|
870
|
+
inspectionCache.set(spec.command, { identity, result: result2 });
|
|
871
|
+
pickerInspectionCache.set(spec.command, { identity, result: result2 });
|
|
872
|
+
return result2;
|
|
873
|
+
}
|
|
874
|
+
const result = await inspectNativeHarnessUncached(spec, timeoutMs, fingerprint);
|
|
875
|
+
if (result.error !== "version probe timed out") {
|
|
876
|
+
inspectionCache.set(spec.command, { identity, result });
|
|
877
|
+
pickerInspectionCache.set(spec.command, { identity, result });
|
|
878
|
+
}
|
|
879
|
+
if (fingerprint && result.installed && result.error !== "version probe timed out") {
|
|
880
|
+
await rememberVersion(spec.command, fingerprint, {
|
|
881
|
+
...result.version ? { version: result.version } : {},
|
|
882
|
+
...result.error ? { error: result.error } : {}
|
|
883
|
+
});
|
|
884
|
+
await saveVersionMemo().catch(quiet("harness/transport/native/inspect"));
|
|
885
|
+
}
|
|
886
|
+
return result;
|
|
887
|
+
}
|
|
888
|
+
async function inspectNativeHarnessUncached(spec, timeoutMs, fingerprint) {
|
|
889
|
+
if (!(fingerprint ?? await binaryOnPath(spec.binary))) return { installed: false };
|
|
890
|
+
const outcome = await runVendorProcess({
|
|
891
|
+
gate: { inert: "version probe" },
|
|
892
|
+
binary: spec.binary,
|
|
893
|
+
argv: spec.versionArgv ?? ["--version"],
|
|
894
|
+
environment: {},
|
|
895
|
+
deadlineMs: timeoutMs
|
|
896
|
+
}, (child) => new Promise((resolve2) => {
|
|
897
|
+
let text = "";
|
|
898
|
+
const collect = (chunk) => {
|
|
899
|
+
if (text.length < 4096) text += String(chunk);
|
|
900
|
+
};
|
|
901
|
+
child.stdout.on("data", collect);
|
|
902
|
+
child.stderr.on("data", collect);
|
|
903
|
+
child.once("close", (code, signal) => {
|
|
904
|
+
const version = text.trim().split(/\r?\n/).find(Boolean)?.trim();
|
|
905
|
+
if (code === 0) resolve2({ installed: true, ...version ? { version } : {} });
|
|
906
|
+
else resolve2({ installed: true, ...version ? { version } : {}, error: signal ? `version probe stopped (${signal})` : `version probe exited ${code ?? 1}` });
|
|
907
|
+
});
|
|
908
|
+
}));
|
|
909
|
+
if (outcome.status === "ok") return outcome.value;
|
|
910
|
+
if (outcome.status === "missing") return { installed: false };
|
|
911
|
+
if (outcome.status === "failed" && outcome.reason === "timeout") return { installed: true, error: "version probe timed out" };
|
|
912
|
+
return { installed: true, error: outcome.status === "failed" ? outcome.detail ?? outcome.reason : outcome.status };
|
|
913
|
+
}
|
|
914
|
+
async function ensureNativeHarness(spec, options = {}) {
|
|
915
|
+
const installed = await ensureHarnessInstalled(spec, options);
|
|
916
|
+
if (installed) clearNativeHarnessInspectionCache(spec.command);
|
|
917
|
+
return installed;
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
// src/runtime/machine-folder.ts
|
|
921
|
+
import { statSync } from "node:fs";
|
|
922
|
+
import { hostname } from "node:os";
|
|
923
|
+
function machineName() {
|
|
924
|
+
try {
|
|
925
|
+
return hostname().split(".")[0] || "this machine";
|
|
926
|
+
} catch {
|
|
927
|
+
return "this machine";
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
function folderExists(path) {
|
|
931
|
+
try {
|
|
932
|
+
return statSync(path).isDirectory();
|
|
933
|
+
} catch {
|
|
934
|
+
return false;
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
function missingFolderMessage(folder, machine = machineName()) {
|
|
938
|
+
return `The folder ${folder} does not exist on ${machine}`;
|
|
939
|
+
}
|
|
940
|
+
function notInstalledMessage(name, binary, machine = machineName()) {
|
|
941
|
+
return `${name} is not installed on ${machine} (no \`${binary}\` on PATH)`;
|
|
942
|
+
}
|
|
943
|
+
function spawnFailure(error, launch) {
|
|
944
|
+
const errno = error;
|
|
945
|
+
if (errno.code !== "ENOENT" || !(errno.syscall?.startsWith("spawn") ?? /^spawn\b/.test(error.message))) return error;
|
|
946
|
+
const message = launch.cwd && !folderExists(launch.cwd) ? missingFolderMessage(launch.cwd) : notInstalledMessage(launch.name, launch.binary);
|
|
947
|
+
return Object.assign(new Error(message, { cause: error }), { code: "ENOENT" });
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
// src/harness/transport/native/command.ts
|
|
951
|
+
function run(command, args, envOverrides = {}) {
|
|
952
|
+
return new Promise((resolve2, reject) => {
|
|
953
|
+
const child = spawnPortable(command, [...args], { stdio: "inherit", env: { ...process.env, ...envOverrides } });
|
|
954
|
+
const cleanup = forwardParentSignals((signal) => terminatePortable(child, signal));
|
|
955
|
+
child.once("error", (error) => {
|
|
956
|
+
cleanup();
|
|
957
|
+
reject(spawnFailure(error, { name: command, binary: command }));
|
|
958
|
+
});
|
|
959
|
+
child.once("exit", (code, signal) => {
|
|
960
|
+
cleanup();
|
|
961
|
+
if (code === 0) resolve2();
|
|
962
|
+
else reject(new Error(`${command} ${signal ? `stopped (${signal})` : `exited ${code ?? 1}`}`));
|
|
963
|
+
});
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
async function runNativeHarnessCommand(spec, args, envOverrides = {}) {
|
|
967
|
+
await ensureNativeHarness(spec);
|
|
968
|
+
await run(spec.binary, args, envOverrides);
|
|
969
|
+
}
|
|
970
|
+
async function captureNativeHarness(spec, args, envOverrides = {}) {
|
|
971
|
+
const stdout = await captureNativeHarnessOutput(spec, args, envOverrides);
|
|
972
|
+
const value = stdout.trim();
|
|
973
|
+
if (!value) throw new Error(`${spec.displayName} did not return a native session id`);
|
|
974
|
+
return value.split(/\s+/)[0];
|
|
975
|
+
}
|
|
976
|
+
var CAPTURE_LIMIT_BYTES2 = 2 * 1024 * 1024;
|
|
977
|
+
var STDERR_KEEP2 = 256 * 1024;
|
|
978
|
+
var NATIVE_HELPER_TIMEOUT_MS = 12e4;
|
|
979
|
+
async function captureNativeHarnessOutput(spec, args, envOverrides = {}, timeoutMs = NATIVE_HELPER_TIMEOUT_MS, cwd, stdinText, signal) {
|
|
980
|
+
if (!await binaryOnPath(spec.binary)) throw Object.assign(new Error(notInstalledMessage(spec.displayName, spec.binary)), { code: "ENOENT" });
|
|
981
|
+
const detached = process.platform !== "win32";
|
|
982
|
+
return new Promise((resolve2, reject) => {
|
|
983
|
+
const child = spawnPortable(spec.binary, [...args], { stdio: [stdinText === void 0 ? "ignore" : "pipe", "pipe", "pipe"], env: { ...process.env, ...envOverrides }, detached, windowsHide: true, ...cwd ? { cwd } : {} });
|
|
984
|
+
const stop = () => {
|
|
985
|
+
killProcessTreePortable(child, "SIGTERM", detached);
|
|
986
|
+
const pid = child.pid;
|
|
987
|
+
if (!detached || !pid) return;
|
|
988
|
+
setTimeout(() => {
|
|
989
|
+
try {
|
|
990
|
+
process.kill(-pid, "SIGKILL");
|
|
991
|
+
} catch {
|
|
992
|
+
}
|
|
993
|
+
}, 2e3).unref();
|
|
994
|
+
};
|
|
995
|
+
const unsignal = forwardParentSignals(() => stop(), ["SIGTERM", "SIGHUP"]);
|
|
996
|
+
const onExit = () => {
|
|
997
|
+
if (detached && child.pid) {
|
|
998
|
+
try {
|
|
999
|
+
process.kill(-child.pid, "SIGKILL");
|
|
1000
|
+
} catch {
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
};
|
|
1004
|
+
process.once("exit", onExit);
|
|
1005
|
+
const unforward = () => {
|
|
1006
|
+
unsignal();
|
|
1007
|
+
process.off("exit", onExit);
|
|
1008
|
+
};
|
|
1009
|
+
if (stdinText !== void 0) {
|
|
1010
|
+
child.stdin?.on("error", () => void 0);
|
|
1011
|
+
child.stdin?.end(stdinText);
|
|
1012
|
+
}
|
|
1013
|
+
let stdout = "";
|
|
1014
|
+
let stderr = "";
|
|
1015
|
+
let exceededLimit = false;
|
|
1016
|
+
let settled = false;
|
|
1017
|
+
const onAbort = () => {
|
|
1018
|
+
stop();
|
|
1019
|
+
finish(new Error(`${spec.displayName} helper cancelled`));
|
|
1020
|
+
};
|
|
1021
|
+
let timer;
|
|
1022
|
+
const finish = (error) => {
|
|
1023
|
+
if (settled) return;
|
|
1024
|
+
settled = true;
|
|
1025
|
+
unforward();
|
|
1026
|
+
if (timer) clearTimeout(timer);
|
|
1027
|
+
signal?.removeEventListener("abort", onAbort);
|
|
1028
|
+
if (error) reject(error);
|
|
1029
|
+
else resolve2(stdout.trim() ? stdout : stderr.trim() ? stderr : stdout);
|
|
1030
|
+
};
|
|
1031
|
+
child.stdout.setEncoding("utf8");
|
|
1032
|
+
child.stderr.setEncoding("utf8");
|
|
1033
|
+
child.stdout.on("data", (chunk) => {
|
|
1034
|
+
stdout += chunk;
|
|
1035
|
+
if (stdout.length > CAPTURE_LIMIT_BYTES2) {
|
|
1036
|
+
exceededLimit = true;
|
|
1037
|
+
stop();
|
|
1038
|
+
}
|
|
1039
|
+
});
|
|
1040
|
+
child.stderr.on("data", (chunk) => {
|
|
1041
|
+
stderr = (stderr + chunk).slice(-STDERR_KEEP2);
|
|
1042
|
+
});
|
|
1043
|
+
child.once("error", (error) => finish(spawnFailure(error, { name: spec.displayName, binary: spec.binary, cwd })));
|
|
1044
|
+
child.once("close", (code, killedBy) => {
|
|
1045
|
+
if (exceededLimit) return finish(new Error(`${spec.displayName} helper output exceeded ${CAPTURE_LIMIT_BYTES2 / 1024 / 1024} MiB`));
|
|
1046
|
+
if (code !== 0) return finish(new Error(`${spec.binary} ${killedBy ? `stopped (${killedBy})` : `exited ${code ?? 1}`}${failureText(stderr) ? `: ${failureText(stderr)}` : ""}`));
|
|
1047
|
+
finish();
|
|
1048
|
+
});
|
|
1049
|
+
timer = timeoutMs > 0 ? setTimeout(() => {
|
|
1050
|
+
stop();
|
|
1051
|
+
finish(new Error(`${spec.displayName} helper timed out`));
|
|
1052
|
+
}, timeoutMs) : void 0;
|
|
1053
|
+
timer?.unref();
|
|
1054
|
+
if (signal?.aborted) onAbort();
|
|
1055
|
+
else signal?.addEventListener("abort", onAbort, { once: true });
|
|
1056
|
+
});
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
// src/harness/accounts/auth-files.ts
|
|
1060
|
+
function expandAuthPath(path, environment, home = homedir2()) {
|
|
1061
|
+
const expanded = path.replace(/\$\{([A-Z0-9_]+)(?::-([^}]*))?\}/g, (_, name, fallback) => {
|
|
1062
|
+
const value = environment[name]?.trim();
|
|
1063
|
+
return value || (fallback ?? "");
|
|
1064
|
+
});
|
|
1065
|
+
const profileHome = environment.HOME?.trim() || home;
|
|
1066
|
+
return expanded.startsWith("~") ? `${profileHome}${expanded.slice(1)}` : expanded;
|
|
1067
|
+
}
|
|
1068
|
+
async function expandAuthPaths(path, environment, home = homedir2()) {
|
|
1069
|
+
const expanded = expandAuthPath(path, environment, home);
|
|
1070
|
+
if (!expanded.includes("*")) return [expanded];
|
|
1071
|
+
const trailing = expanded.endsWith("/") ? "/" : "";
|
|
1072
|
+
const segments = expanded.replace(/\/$/, "").split("/");
|
|
1073
|
+
let found = [segments[0] ?? ""];
|
|
1074
|
+
for (const segment of segments.slice(1)) {
|
|
1075
|
+
if (segment !== "*") {
|
|
1076
|
+
found = found.map((base) => `${base}/${segment}`);
|
|
1077
|
+
continue;
|
|
1078
|
+
}
|
|
1079
|
+
found = (await Promise.all(found.map(async (base) => (await readdir(base || "/").catch(() => [])).sort().map((name) => `${base}/${name}`)))).flat();
|
|
1080
|
+
}
|
|
1081
|
+
return found.map((item) => `${item}${trailing}`);
|
|
1082
|
+
}
|
|
1083
|
+
async function present(entry, environment) {
|
|
1084
|
+
for (const path of await expandAuthPaths(entry.path, environment)) if (await presentAt(path, entry)) return true;
|
|
1085
|
+
return false;
|
|
1086
|
+
}
|
|
1087
|
+
function jsonFieldValues(data, fields) {
|
|
1088
|
+
return fields.map((field) => field.split(".").reduce((value, key) => value !== null && typeof value === "object" ? value[key] : void 0, data));
|
|
1089
|
+
}
|
|
1090
|
+
async function presentAt(path, entry) {
|
|
1091
|
+
try {
|
|
1092
|
+
if (path.endsWith("/")) return (await readdir(path)).length > 0;
|
|
1093
|
+
if (entry.jsonFields) {
|
|
1094
|
+
const data = JSON.parse(await readFile2(path, "utf8"));
|
|
1095
|
+
return jsonFieldValues(data, entry.jsonFields).every((value) => typeof value === "string" && value.trim().length > 0);
|
|
1096
|
+
}
|
|
1097
|
+
if (entry.contains === void 0) return (await stat3(path)).size > 0;
|
|
1098
|
+
return (await readFile2(path, "utf8")).includes(entry.contains);
|
|
1099
|
+
} catch {
|
|
1100
|
+
return false;
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
function parsesAsJson(text) {
|
|
1104
|
+
try {
|
|
1105
|
+
JSON.parse(text);
|
|
1106
|
+
return true;
|
|
1107
|
+
} catch {
|
|
1108
|
+
return false;
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
async function prepareAuthFilesForLogin(harness, profileEnvironment, processEnvironment = process.env) {
|
|
1112
|
+
const environment = { ...processEnvironment, ...profileEnvironment };
|
|
1113
|
+
for (const entry of harness.authFiles ?? []) {
|
|
1114
|
+
if (!entry.jsonFields) continue;
|
|
1115
|
+
for (const path of await expandAuthPaths(entry.path, environment)) {
|
|
1116
|
+
let text;
|
|
1117
|
+
try {
|
|
1118
|
+
text = await readFile2(path, "utf8");
|
|
1119
|
+
} catch (error) {
|
|
1120
|
+
if (error.code === "ENOENT") continue;
|
|
1121
|
+
throw error;
|
|
1122
|
+
}
|
|
1123
|
+
if (parsesAsJson(text)) continue;
|
|
1124
|
+
await rename(path, `${path}.invalid-${randomUUID()}.bak`);
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
async function credentialDigest(path, entry) {
|
|
1129
|
+
const hash = (text2) => createHash("sha256").update(text2).digest("hex");
|
|
1130
|
+
if (path.endsWith("/")) {
|
|
1131
|
+
const names = (await readdir(path)).sort();
|
|
1132
|
+
return hash((await Promise.all(names.map(async (name) => `${name}:${hash(await readFile2(`${path}${name}`).catch(() => ""))}`))).join("\n"));
|
|
1133
|
+
}
|
|
1134
|
+
const text = await readFile2(path);
|
|
1135
|
+
if (!entry.jsonFields) return hash(text);
|
|
1136
|
+
try {
|
|
1137
|
+
return hash(JSON.stringify(jsonFieldValues(JSON.parse(text.toString("utf8")), entry.jsonFields)));
|
|
1138
|
+
} catch {
|
|
1139
|
+
return "invalid";
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
async function authFilesStamp(harness, profileEnvironment, processEnvironment = process.env) {
|
|
1143
|
+
const environment = { ...processEnvironment, ...profileEnvironment };
|
|
1144
|
+
const parts = await Promise.all((harness.authFiles ?? []).map(async (entry) => {
|
|
1145
|
+
const paths = await expandAuthPaths(entry.path, environment);
|
|
1146
|
+
if (!paths.length) return `${entry.path}:-`;
|
|
1147
|
+
return (await Promise.all(paths.map(async (path) => {
|
|
1148
|
+
try {
|
|
1149
|
+
return `${path}:${await presentAt(path, entry)}:${await credentialDigest(path, entry)}`;
|
|
1150
|
+
} catch {
|
|
1151
|
+
return `${path}:-`;
|
|
1152
|
+
}
|
|
1153
|
+
}))).join("|");
|
|
1154
|
+
}));
|
|
1155
|
+
return parts.join("|");
|
|
1156
|
+
}
|
|
1157
|
+
async function filesSignIn(entries, environment) {
|
|
1158
|
+
let any = false;
|
|
1159
|
+
for (const entry of entries) {
|
|
1160
|
+
const there = await present(entry, environment);
|
|
1161
|
+
if (entry.required && !there) return false;
|
|
1162
|
+
any ||= there;
|
|
1163
|
+
}
|
|
1164
|
+
return any;
|
|
1165
|
+
}
|
|
1166
|
+
async function authFilePresent(harness, profileEnvironment, processEnvironment = process.env) {
|
|
1167
|
+
return filesSignIn(harness.authFiles ?? [], { ...processEnvironment, ...profileEnvironment });
|
|
1168
|
+
}
|
|
1169
|
+
async function adoptAuthFiles(harness, from, to, processEnvironment = process.env) {
|
|
1170
|
+
const environment = { ...processEnvironment, ...from.environment };
|
|
1171
|
+
const fromRoot = resolve(from.root);
|
|
1172
|
+
let carried = false;
|
|
1173
|
+
for (const entry of harness.authFiles ?? []) {
|
|
1174
|
+
for (const source of await expandAuthPaths(entry.path, environment)) {
|
|
1175
|
+
if (!await presentAt(source, entry)) continue;
|
|
1176
|
+
const inside = relative(fromRoot, resolve(source));
|
|
1177
|
+
if (!inside || inside.startsWith("..")) continue;
|
|
1178
|
+
const target = join4(resolve(to.root), inside);
|
|
1179
|
+
await mkdir2(dirname2(target), { recursive: true, mode: 448 });
|
|
1180
|
+
if (source.endsWith("/")) {
|
|
1181
|
+
await cp(source, target, { recursive: true, force: true });
|
|
1182
|
+
} else if (entry.removeLine && entry.contains !== void 0) {
|
|
1183
|
+
const holds = (line) => line.includes(entry.contains);
|
|
1184
|
+
const kept = (await readFile2(target, "utf8").catch(() => "")).split("\n").filter((line) => line && !holds(line));
|
|
1185
|
+
const fresh = (await readFile2(source, "utf8")).split("\n").filter(holds);
|
|
1186
|
+
await writeFile2(target, `${[...kept, ...fresh].join("\n")}
|
|
1187
|
+
`, { mode: 384 });
|
|
1188
|
+
} else if (entry.jsonFields) {
|
|
1189
|
+
const fresh = JSON.parse(await readFile2(source, "utf8"));
|
|
1190
|
+
let merged = {};
|
|
1191
|
+
try {
|
|
1192
|
+
const existing = JSON.parse(await readFile2(target, "utf8"));
|
|
1193
|
+
if (existing && typeof existing === "object" && !Array.isArray(existing)) merged = existing;
|
|
1194
|
+
} catch {
|
|
1195
|
+
}
|
|
1196
|
+
for (const key of new Set(entry.jsonFields.map((field) => field.split(".")[0]))) merged[key] = fresh[key];
|
|
1197
|
+
await writeFile2(target, `${JSON.stringify(merged, null, 2)}
|
|
1198
|
+
`, { mode: 384 });
|
|
1199
|
+
} else {
|
|
1200
|
+
await copyFile(source, target);
|
|
1201
|
+
}
|
|
1202
|
+
carried = true;
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
return carried;
|
|
1206
|
+
}
|
|
1207
|
+
function hasAuthEvidence(harness) {
|
|
1208
|
+
return Boolean(harness.authFiles?.length || harness.authEnv?.length || process.platform === "darwin" && harness.authKeychain?.length);
|
|
1209
|
+
}
|
|
1210
|
+
async function authEvidencePresent(harness, profileEnvironment, processEnvironment = process.env) {
|
|
1211
|
+
const environment = { ...processEnvironment, ...profileEnvironment };
|
|
1212
|
+
if (harness.authEnv?.some((name) => environment[name]?.trim())) return true;
|
|
1213
|
+
if (await filesSignIn(harness.authFiles ?? [], environment)) return true;
|
|
1214
|
+
return keychainSignIn(harness, environment);
|
|
1215
|
+
}
|
|
1216
|
+
function keychainService(template, profileValue) {
|
|
1217
|
+
const hash = profileValue?.trim() ? `-${createHash("sha256").update(profileValue.trim()).digest("hex").slice(0, 8)}` : "";
|
|
1218
|
+
return template.replace("{profileHash}", hash);
|
|
1219
|
+
}
|
|
1220
|
+
async function keychainSignIn(harness, environment) {
|
|
1221
|
+
if (process.platform !== "darwin" || !harness.authKeychain?.length) return false;
|
|
1222
|
+
const profileValue = harness.profileEnv ? environment[harness.profileEnv] : void 0;
|
|
1223
|
+
for (const template of harness.authKeychain) {
|
|
1224
|
+
const service = keychainService(template, profileValue);
|
|
1225
|
+
const found = await new Promise((resolve2) => {
|
|
1226
|
+
execFile("/usr/bin/security", ["find-generic-password", "-s", service], { timeout: 5e3, windowsHide: true }, (error) => resolve2(!error));
|
|
1227
|
+
});
|
|
1228
|
+
if (found) return true;
|
|
1229
|
+
}
|
|
1230
|
+
return false;
|
|
1231
|
+
}
|
|
1232
|
+
function removableAuthFiles(harness) {
|
|
1233
|
+
return (harness.authFiles ?? []).filter((entry) => entry.contains === void 0 || entry.removeLine);
|
|
1234
|
+
}
|
|
1235
|
+
async function removeAuthFiles(harness, profileEnvironment, processEnvironment = process.env) {
|
|
1236
|
+
const environment = { ...processEnvironment, ...profileEnvironment };
|
|
1237
|
+
const removed = [];
|
|
1238
|
+
for (const entry of removableAuthFiles(harness)) {
|
|
1239
|
+
for (const path of await expandAuthPaths(entry.path, environment)) {
|
|
1240
|
+
if (!await presentAt(path, entry)) continue;
|
|
1241
|
+
if (entry.removeLine && entry.contains !== void 0) {
|
|
1242
|
+
const text = await readFile2(path, "utf8");
|
|
1243
|
+
await writeFile2(path, text.split("\n").filter((line) => !line.includes(entry.contains)).join("\n"), "utf8");
|
|
1244
|
+
} else {
|
|
1245
|
+
await rm2(path, { recursive: path.endsWith("/"), force: true });
|
|
1246
|
+
}
|
|
1247
|
+
removed.push(path);
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
return removed;
|
|
1251
|
+
}
|
|
1252
|
+
function harnessCanLogout(harness) {
|
|
1253
|
+
return Boolean(harness.logoutArgv) || removableAuthFiles(harness).length > 0;
|
|
1254
|
+
}
|
|
1255
|
+
async function logoutNativeHarness(harness, profileEnvironment, timeoutMs) {
|
|
1256
|
+
if (harness.logoutArgv) {
|
|
1257
|
+
await captureNativeHarnessOutput(harness, harness.logoutArgv, profileEnvironment, timeoutMs);
|
|
1258
|
+
return;
|
|
1259
|
+
}
|
|
1260
|
+
if (!removableAuthFiles(harness).length) throw new Error(`${harness.displayName} has no logout command and keeps no credential file ClikCode can remove`);
|
|
1261
|
+
await removeAuthFiles(harness, profileEnvironment);
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
export {
|
|
1265
|
+
resolveBinaryPath,
|
|
1266
|
+
folderExists,
|
|
1267
|
+
missingFolderMessage,
|
|
1268
|
+
spawnFailure,
|
|
1269
|
+
runNativeHarnessCommand,
|
|
1270
|
+
captureNativeHarness,
|
|
1271
|
+
captureNativeHarnessOutput,
|
|
1272
|
+
expandAuthPath,
|
|
1273
|
+
expandAuthPaths,
|
|
1274
|
+
prepareAuthFilesForLogin,
|
|
1275
|
+
authFilesStamp,
|
|
1276
|
+
authFilePresent,
|
|
1277
|
+
adoptAuthFiles,
|
|
1278
|
+
hasAuthEvidence,
|
|
1279
|
+
authEvidencePresent,
|
|
1280
|
+
keychainService,
|
|
1281
|
+
removableAuthFiles,
|
|
1282
|
+
removeAuthFiles,
|
|
1283
|
+
harnessCanLogout,
|
|
1284
|
+
logoutNativeHarness,
|
|
1285
|
+
PROBE_DEADLINE_MS,
|
|
1286
|
+
VENDOR_IMPORT_DEADLINE_MS,
|
|
1287
|
+
INERT_DEADLINE_MS,
|
|
1288
|
+
KEYRING_DEADLINE_MS,
|
|
1289
|
+
isSignedOutRefusal,
|
|
1290
|
+
backgroundEnvironment,
|
|
1291
|
+
probeFetch,
|
|
1292
|
+
mayRunSignInCapable,
|
|
1293
|
+
mayRunInBackground,
|
|
1294
|
+
probeVendor,
|
|
1295
|
+
runVendorCommand,
|
|
1296
|
+
vendorCommandText,
|
|
1297
|
+
probeCommand,
|
|
1298
|
+
queryJsonRpc,
|
|
1299
|
+
sameFingerprint,
|
|
1300
|
+
binaryFingerprint,
|
|
1301
|
+
harnessBinaryIdentity,
|
|
1302
|
+
saveVersionMemo,
|
|
1303
|
+
TERMINAL,
|
|
1304
|
+
reducedMotion,
|
|
1305
|
+
terminalUiSupported,
|
|
1306
|
+
harnessInstallRoute,
|
|
1307
|
+
manualInstallCommand,
|
|
1308
|
+
setHarnessInstallReporter,
|
|
1309
|
+
refreshAcpAgent,
|
|
1310
|
+
inspectNativeHarnessForPicker,
|
|
1311
|
+
clearNativeHarnessInspectionCache,
|
|
1312
|
+
inspectNativeHarness,
|
|
1313
|
+
ensureNativeHarness
|
|
1314
|
+
};
|