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,354 @@
1
+ import { createRequire as __clikcodeCreateRequire } from 'node:module';
2
+ const require = __clikcodeCreateRequire(import.meta.url);
3
+ import {
4
+ bridgeScript,
5
+ runSsh,
6
+ spawnSsh,
7
+ targetHost,
8
+ validateSshTarget,
9
+ withUser
10
+ } from "./chunk-UFQ5A5PW.js";
11
+ import {
12
+ harnessIndexPath
13
+ } from "./chunk-NWEYRBWK.js";
14
+ import {
15
+ failureText
16
+ } from "./chunk-CQ7J6UQ7.js";
17
+ import {
18
+ CLIKCODE_COMMIT,
19
+ CLIKCODE_VERSION
20
+ } from "./chunk-NAOX3JUB.js";
21
+ import {
22
+ atomicWriteFile
23
+ } from "./chunk-F6F47QAY.js";
24
+ import {
25
+ quiet
26
+ } from "./chunk-RDDWQBEM.js";
27
+ import {
28
+ stateDirectory
29
+ } from "./chunk-MPAJ446F.js";
30
+
31
+ // src/remote/peer.ts
32
+ import { hostname, userInfo } from "node:os";
33
+ import { readFile as readFile2 } from "node:fs/promises";
34
+
35
+ // src/remote/machines.ts
36
+ import { readFile } from "node:fs/promises";
37
+ import { join } from "node:path";
38
+ import { randomUUID } from "node:crypto";
39
+ function updatePolicy(machine) {
40
+ return machine.updates === "ask" ? "ask" : "auto";
41
+ }
42
+ function machinesPath() {
43
+ return join(stateDirectory(), "remote", "machines.json");
44
+ }
45
+ async function readMachines() {
46
+ return (await readMachinesFile()).machines;
47
+ }
48
+ async function readForgotten() {
49
+ return (await readMachinesFile()).forgotten;
50
+ }
51
+ async function readMachinesFile() {
52
+ try {
53
+ const parsed = JSON.parse(await readFile(machinesPath(), "utf8"));
54
+ return {
55
+ machines: Array.isArray(parsed.machines) ? parsed.machines.filter((machine) => machine && typeof machine.id === "string" && typeof machine.sshTarget === "string") : [],
56
+ forgotten: Array.isArray(parsed.forgotten) ? parsed.forgotten.filter((item) => item && (typeof item.installationId === "string" || typeof item.nodeId === "string")) : []
57
+ };
58
+ } catch {
59
+ return { machines: [], forgotten: [] };
60
+ }
61
+ }
62
+ function isForgotten(forgotten, machine) {
63
+ return forgotten.some((item) => item.installationId !== void 0 && item.installationId === machine.installationId || item.nodeId !== void 0 && item.nodeId === machine.nodeId);
64
+ }
65
+ var writing = Promise.resolve();
66
+ function updateMachines(change, options = {}) {
67
+ const next = writing.then(async () => {
68
+ const file = await readMachinesFile();
69
+ const changed = change(file.machines, file.forgotten) ?? file.machines;
70
+ let forgotten = file.forgotten.filter((item) => !changed.some((machine) => isForgotten([item], { ...machine.installationId ? { installationId: machine.installationId } : {}, ...machine.tailscale ? { nodeId: machine.tailscale.nodeId } : {} })));
71
+ const gone = options.forget;
72
+ if (gone && (gone.installationId || gone.tailscale)) {
73
+ forgotten = [...forgotten, { ...gone.installationId ? { installationId: gone.installationId } : {}, ...gone.tailscale ? { nodeId: gone.tailscale.nodeId } : {}, at: (/* @__PURE__ */ new Date()).toISOString() }];
74
+ }
75
+ const body = { version: 1, machines: changed, ...forgotten.length ? { forgotten } : {} };
76
+ await atomicWriteFile(machinesPath(), `${JSON.stringify(body, null, 2)}
77
+ `, { ...options.durable !== void 0 ? { durable: options.durable } : {} });
78
+ return changed;
79
+ });
80
+ writing = next.catch(quiet("remote/machines"));
81
+ return next;
82
+ }
83
+ function updateMachine(id, patch, options = {}) {
84
+ let found;
85
+ return updateMachines((machines) => {
86
+ found = machines.find((machine) => machine.id === id);
87
+ if (found) patch(found);
88
+ }, options).then(() => found);
89
+ }
90
+ function newMachineRecord(input) {
91
+ return { id: randomUUID(), addedAt: (/* @__PURE__ */ new Date()).toISOString(), updates: "auto", ...input };
92
+ }
93
+ async function forgetMachine(id, options = {}) {
94
+ const gone = options.remember ? (await readMachines()).find((machine) => machine.id === id) : void 0;
95
+ return updateMachines((machines) => machines.filter((machine) => machine.id !== id), gone ? { forget: gone } : {});
96
+ }
97
+
98
+ // src/remote/tailscale.ts
99
+ import { spawn } from "node:child_process";
100
+ var DISCOVERY_RECENT_MS = 30 * 24 * 60 * 60 * 1e3;
101
+ function notYetAdded(discovered, machines) {
102
+ const hosts = new Set(machines.map((machine) => targetHost(machine.sshTarget).toLowerCase()));
103
+ const nodes = new Set(machines.flatMap((machine) => machine.tailscale ? [machine.tailscale.nodeId] : []));
104
+ return discovered.filter((machine) => !nodes.has(machine.nodeId) && !(machine.dnsName && hosts.has(machine.dnsName.toLowerCase())) && !hosts.has(machine.name.toLowerCase()));
105
+ }
106
+ var DESKTOP_OS = { linux: "linux", macos: "macOS", windows: "windows" };
107
+ function baseMachineName(name) {
108
+ return name.toLowerCase().replace(/['’`]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
109
+ }
110
+ var lastSeenMs = (node) => {
111
+ const at = node.LastSeen ? Date.parse(node.LastSeen) : Number.NaN;
112
+ return Number.isNaN(at) || at < 0 ? -Infinity : at;
113
+ };
114
+ function discoverMachines(status, now = Date.now()) {
115
+ const self2 = status.Self;
116
+ if (!self2 || self2.UserID === void 0) return [];
117
+ const own = Object.values(status.Peer ?? {}).filter((node) => node.UserID === self2.UserID && !node.ShareeNode);
118
+ const candidates = own.flatMap((node) => {
119
+ const os = DESKTOP_OS[(node.OS ?? "").toLowerCase()];
120
+ if (!os || !node.ID) return [];
121
+ const online = node.Online === true;
122
+ const seen = lastSeenMs(node);
123
+ if (!online && !(now - seen < DISCOVERY_RECENT_MS)) return [];
124
+ const dnsName = node.DNSName?.replace(/\.$/, "") || void 0;
125
+ const label = dnsName?.split(".")[0];
126
+ const hostName = node.HostName ?? label ?? node.ID;
127
+ return [{
128
+ nodeId: node.ID,
129
+ name: label || hostName,
130
+ ...dnsName ? { dnsName } : {},
131
+ hostName,
132
+ os,
133
+ online,
134
+ ...Number.isFinite(seen) ? { lastSeen: new Date(seen).toISOString() } : {}
135
+ }];
136
+ });
137
+ const rank = (machine) => machine.online ? Infinity : machine.lastSeen ? Date.parse(machine.lastSeen) : -Infinity;
138
+ const kept = [];
139
+ for (const machine of [...candidates].sort((left, right) => rank(right) - rank(left))) {
140
+ const keys = /* @__PURE__ */ new Set([baseMachineName(machine.hostName), baseMachineName(machine.name)]);
141
+ const duplicate = kept.some((other) => [baseMachineName(other.hostName), baseMachineName(other.name)].some((key) => keys.has(key)));
142
+ if (!duplicate || machine.online) kept.push(machine);
143
+ }
144
+ return kept.sort((left, right) => Number(right.online) - Number(left.online) || left.name.localeCompare(right.name));
145
+ }
146
+ function readTailscaleStatus(timeoutMs = 5e3) {
147
+ return new Promise((resolve) => {
148
+ let out = "";
149
+ let err = "";
150
+ let child;
151
+ try {
152
+ child = spawn("tailscale", ["status", "--json"], { stdio: ["ignore", "pipe", "pipe"] });
153
+ } catch (error) {
154
+ resolve({ error: error instanceof Error ? error.message : String(error) });
155
+ return;
156
+ }
157
+ const timer = setTimeout(() => child.kill("SIGTERM"), timeoutMs);
158
+ timer.unref();
159
+ child.stdout.on("data", (chunk) => {
160
+ out += chunk.toString("utf8");
161
+ });
162
+ child.stderr.on("data", (chunk) => {
163
+ err += chunk.toString("utf8");
164
+ });
165
+ child.once("error", (error) => {
166
+ clearTimeout(timer);
167
+ resolve({ error: error.code === "ENOENT" ? "Tailscale is not installed here" : error.message });
168
+ });
169
+ child.once("close", (code) => {
170
+ clearTimeout(timer);
171
+ try {
172
+ const status = JSON.parse(out);
173
+ if (status.BackendState && status.BackendState !== "Running") {
174
+ resolve({ error: `Tailscale is ${status.BackendState.toLowerCase()}` });
175
+ return;
176
+ }
177
+ resolve({ status });
178
+ } catch {
179
+ resolve({ error: failureText(err) || `tailscale status exited ${code}` });
180
+ }
181
+ });
182
+ });
183
+ }
184
+
185
+ // src/remote/peer.ts
186
+ function startBridge(target, self2 = selfAsPeer) {
187
+ const child = spawnSsh(target, bridgeScript());
188
+ announceWhenReady(child, self2);
189
+ return child;
190
+ }
191
+ function announceWhenReady(child, self2) {
192
+ let pending = "";
193
+ const onData = (chunk) => {
194
+ pending += chunk.toString("utf8");
195
+ for (let at = pending.indexOf("\n"); at >= 0; at = pending.indexOf("\n")) {
196
+ const line = pending.slice(0, at);
197
+ pending = pending.slice(at + 1);
198
+ if (!line.includes('"host-ready"')) continue;
199
+ try {
200
+ if (JSON.parse(line).type !== "host-ready") continue;
201
+ } catch {
202
+ continue;
203
+ }
204
+ child.stdout.off("data", onData);
205
+ pending = "";
206
+ void self2().then((peer) => {
207
+ if (peer && !child.stdin.destroyed) child.stdin.write(`${JSON.stringify({ type: "host-peer", machine: peer })}
208
+ `);
209
+ }, () => void 0);
210
+ return;
211
+ }
212
+ };
213
+ child.stdout.on("data", onData);
214
+ }
215
+ var OS_NAMES = { darwin: "macOS", linux: "linux" };
216
+ function peerFromStatus(status, facts) {
217
+ const self2 = status?.Self;
218
+ const dnsName = self2?.DNSName?.replace(/\.$/, "");
219
+ if (!self2?.ID || !dnsName) return void 0;
220
+ let sshTarget;
221
+ try {
222
+ sshTarget = withUser(validateSshTarget(dnsName), facts.user);
223
+ } catch {
224
+ return void 0;
225
+ }
226
+ const os = OS_NAMES[facts.platform ?? process.platform];
227
+ return {
228
+ name: dnsName.split(".")[0] || self2.HostName || facts.host || dnsName,
229
+ sshTarget,
230
+ tailscale: { nodeId: self2.ID, dnsName },
231
+ ...os ? { os } : {},
232
+ ...facts.installationId ? { installationId: facts.installationId } : {},
233
+ version: CLIKCODE_VERSION,
234
+ ...CLIKCODE_COMMIT ? { commit: CLIKCODE_COMMIT } : {}
235
+ };
236
+ }
237
+ var self;
238
+ async function readInstallationId() {
239
+ try {
240
+ const index = JSON.parse(await readFile2(harnessIndexPath(), "utf8"));
241
+ return typeof index.installationId === "string" ? index.installationId : void 0;
242
+ } catch {
243
+ return void 0;
244
+ }
245
+ }
246
+ function selfAsPeer() {
247
+ self ??= (async () => {
248
+ const [{ status }, installationId] = await Promise.all([
249
+ readTailscaleStatus(),
250
+ readInstallationId()
251
+ ]);
252
+ const user = (() => {
253
+ try {
254
+ return userInfo().username;
255
+ } catch {
256
+ return process.env.USER ?? "";
257
+ }
258
+ })();
259
+ if (!user) return void 0;
260
+ return peerFromStatus(status, { user, ...installationId ? { installationId } : {}, host: hostname() });
261
+ })().catch(quiet("remote/peer"));
262
+ return self;
263
+ }
264
+ function recordsOf(machines, peer) {
265
+ const reaches = (record) => record.tailscale?.nodeId === peer.tailscale.nodeId || targetHost(record.sshTarget).toLowerCase() === peer.tailscale.dnsName.toLowerCase();
266
+ const loose = machines.filter((record) => !record.installationId && reaches(record));
267
+ const same = peer.installationId ? machines.filter((record) => record.installationId === peer.installationId) : [];
268
+ if (!same.length) return { ...loose[0] ? { keep: loose[0] } : {}, drop: loose.slice(1) };
269
+ const installedAt = (record) => Date.parse(record.installed?.at ?? record.addedAt) || Infinity;
270
+ const [keep, ...others] = [...same].sort((left, right) => installedAt(left) - installedAt(right));
271
+ return { keep, drop: [...others, ...loose] };
272
+ }
273
+ function withPeer(machines, peer, own, options = {}) {
274
+ if (peer.installationId && peer.installationId === own) return [...machines];
275
+ const at = (options.now ?? /* @__PURE__ */ new Date()).toISOString();
276
+ const installed = { version: peer.version, ...peer.commit ? { commit: peer.commit } : {}, at };
277
+ const { keep: existing, drop } = recordsOf(machines, peer);
278
+ if (existing) {
279
+ const own2 = existing.addedBy === "peer" ? { name: peer.name, sshTarget: peer.sshTarget, tailscale: peer.tailscale } : {};
280
+ return machines.filter((record) => !drop.includes(record)).map((record) => record !== existing ? record : {
281
+ ...record,
282
+ ...own2,
283
+ ...peer.installationId ? { installationId: peer.installationId } : {},
284
+ // It answered from there with ClikCode running: its install is done.
285
+ ready: true,
286
+ installed,
287
+ lastSeen: at,
288
+ ...record.tailscale ? {} : { tailscale: peer.tailscale },
289
+ ...record.os || !peer.os ? {} : { os: peer.os }
290
+ });
291
+ }
292
+ if (!options.add || isForgotten(options.forgotten ?? [], { ...peer.installationId ? { installationId: peer.installationId } : {}, nodeId: peer.tailscale.nodeId })) return [...machines];
293
+ return [...machines, newMachineRecord({
294
+ name: peer.name,
295
+ sshTarget: peer.sshTarget,
296
+ tailscale: peer.tailscale,
297
+ ...peer.os ? { os: peer.os } : {},
298
+ ...peer.installationId ? { installationId: peer.installationId } : {},
299
+ ready: true,
300
+ installed,
301
+ lastSeen: at,
302
+ updates: "ask",
303
+ addedBy: "peer"
304
+ })];
305
+ }
306
+ function wouldAdd(machines, forgotten, peer, own) {
307
+ if (peer.installationId && peer.installationId === own) return false;
308
+ if (recordsOf(machines, peer).keep) return false;
309
+ return !isForgotten(forgotten, { ...peer.installationId ? { installationId: peer.installationId } : {}, nodeId: peer.tailscale.nodeId });
310
+ }
311
+ var sshReachBack = async (target) => (await runSsh(target, "true", { timeoutMs: 2e4 })).code === 0;
312
+ async function recordPeer(peer, reach = sshReachBack) {
313
+ if (!validPeer(peer)) return "skipped";
314
+ const own = await readInstallationId();
315
+ const [machines, forgotten] = await Promise.all([readMachines(), readForgotten()]);
316
+ const adding = wouldAdd(machines, forgotten, peer, own);
317
+ if (!adding) {
318
+ if (!recordsOf(machines, peer).keep) return "skipped";
319
+ await updateMachines((list, gone) => withPeer(list, peer, own, { forgotten: gone }));
320
+ return "refreshed";
321
+ }
322
+ if (!await reach(peer.sshTarget).catch(() => false)) return "unreachable";
323
+ await updateMachines((list, gone) => withPeer(list, peer, own, { forgotten: gone, add: true }));
324
+ return "added";
325
+ }
326
+ function validPeer(peer) {
327
+ const value = peer;
328
+ if (!value || typeof value.name !== "string" || !value.name || typeof value.sshTarget !== "string" || typeof value.version !== "string") return false;
329
+ if (typeof value.tailscale?.nodeId !== "string" || typeof value.tailscale.dnsName !== "string") return false;
330
+ try {
331
+ validateSshTarget(value.sshTarget);
332
+ } catch {
333
+ return false;
334
+ }
335
+ return true;
336
+ }
337
+
338
+ export {
339
+ updatePolicy,
340
+ readMachines,
341
+ updateMachines,
342
+ updateMachine,
343
+ newMachineRecord,
344
+ forgetMachine,
345
+ notYetAdded,
346
+ discoverMachines,
347
+ readTailscaleStatus,
348
+ startBridge,
349
+ announceWhenReady,
350
+ peerFromStatus,
351
+ withPeer,
352
+ recordPeer,
353
+ validPeer
354
+ };
@@ -0,0 +1,44 @@
1
+ import { createRequire as __clikcodeCreateRequire } from 'node:module';
2
+ const require = __clikcodeCreateRequire(import.meta.url);
3
+ import {
4
+ withFileLock
5
+ } from "./chunk-4L2ZZM4Q.js";
6
+ import {
7
+ swallowed
8
+ } from "./chunk-RDDWQBEM.js";
9
+
10
+ // src/agent/computer/email-consumed.ts
11
+ import fs from "node:fs/promises";
12
+ import path from "node:path";
13
+ var KEEP_MS = 24 * 36e5;
14
+ var file = (stateDir, store = "email") => path.join(stateDir, "computer", `${store}-consumed.json`);
15
+ var locked = (stateDir, store, work) => withFileLock(`${file(stateDir, store)}.lock`, work);
16
+ async function claimMessage(stateDir, id, store = "email") {
17
+ return locked(stateDir, store, async () => {
18
+ let record = {};
19
+ try {
20
+ record = JSON.parse(await fs.readFile(file(stateDir, store), "utf8"));
21
+ } catch (error) {
22
+ swallowed("agent/computer/email-consumed", error);
23
+ }
24
+ const now = Date.now();
25
+ for (const [key, at] of Object.entries(record)) if (now - at > KEEP_MS) delete record[key];
26
+ if (record[id]) return false;
27
+ record[id] = now;
28
+ await fs.mkdir(path.dirname(file(stateDir, store)), { recursive: true });
29
+ await fs.writeFile(file(stateDir, store), JSON.stringify(record), { mode: 384 });
30
+ return true;
31
+ });
32
+ }
33
+ async function isClaimed(stateDir, id, store = "email") {
34
+ try {
35
+ return Boolean(JSON.parse(await fs.readFile(file(stateDir, store), "utf8"))[id]);
36
+ } catch {
37
+ return false;
38
+ }
39
+ }
40
+
41
+ export {
42
+ claimMessage,
43
+ isClaimed
44
+ };
@@ -0,0 +1,228 @@
1
+ import { createRequire as __clikcodeCreateRequire } from 'node:module';
2
+ const require = __clikcodeCreateRequire(import.meta.url);
3
+ import {
4
+ HARNESS_STATE_VERSION,
5
+ harnessIndexPath
6
+ } from "./chunk-NWEYRBWK.js";
7
+ import {
8
+ loadInvocationLog,
9
+ storeInvocationLog
10
+ } from "./chunk-NKDATMEM.js";
11
+ import {
12
+ cachedFile
13
+ } from "./chunk-O3EW7LAY.js";
14
+ import {
15
+ cloneData,
16
+ sameData
17
+ } from "./chunk-KHW6TX6I.js";
18
+ import {
19
+ pidIsAlive
20
+ } from "./chunk-4L2ZZM4Q.js";
21
+ import {
22
+ atomicWriteFile
23
+ } from "./chunk-F6F47QAY.js";
24
+ import {
25
+ quiet
26
+ } from "./chunk-RDDWQBEM.js";
27
+ import {
28
+ stateDirectory
29
+ } from "./chunk-MPAJ446F.js";
30
+
31
+ // src/session/state/index-file.ts
32
+ import { readFile, readdir, stat, unlink } from "node:fs/promises";
33
+ import { basename, dirname, join as join3 } from "node:path";
34
+
35
+ // src/session/state/model-lists.ts
36
+ import { createHash } from "node:crypto";
37
+ import { join } from "node:path";
38
+ function listsPath() {
39
+ return join(stateDirectory(), "account-models.json");
40
+ }
41
+ var listsFile = cachedFile(listsPath, (raw) => {
42
+ const parsed = JSON.parse(raw);
43
+ const lists = {};
44
+ if (parsed?.lists && typeof parsed.lists === "object") {
45
+ for (const [key, value] of Object.entries(parsed.lists)) {
46
+ if (Array.isArray(value)) lists[key] = value.filter((item) => typeof item === "string");
47
+ }
48
+ }
49
+ return lists;
50
+ });
51
+ async function loadLists() {
52
+ return await listsFile.load().catch(quiet("session/state/model-lists")) ?? {};
53
+ }
54
+ function listKey(models) {
55
+ return createHash("sha256").update(JSON.stringify(models)).digest("hex").slice(0, 16);
56
+ }
57
+ async function hydrateAccountModels(accounts) {
58
+ if (!accounts.some((account) => account.modelsRef)) return accounts;
59
+ const lists = await loadLists();
60
+ return accounts.map((stored) => {
61
+ const { modelsRef, ...account } = stored;
62
+ if (!modelsRef) return stored;
63
+ if (Array.isArray(account.models) && account.models.length) return account;
64
+ return { ...account, models: lists[modelsRef] ? [...lists[modelsRef]] : [] };
65
+ });
66
+ }
67
+ async function storeAccountModels(accounts, replacing = []) {
68
+ const disk = await loadLists();
69
+ const lists = {};
70
+ for (const account of replacing) {
71
+ const key = account.modelsRef;
72
+ if (key && disk[key]) lists[key] = disk[key];
73
+ }
74
+ const stored = accounts.map((account) => {
75
+ const { modelsRef: _stale, ...rest } = account;
76
+ if (!Array.isArray(rest.models) || !rest.models.length) return rest;
77
+ const key = listKey(rest.models);
78
+ lists[key] = rest.models;
79
+ return { ...rest, models: [], modelsRef: key };
80
+ });
81
+ if (!sameData(disk, lists)) {
82
+ const raw = JSON.stringify({ lists });
83
+ await atomicWriteFile(listsPath(), raw);
84
+ await listsFile.remember(raw, lists);
85
+ }
86
+ return stored;
87
+ }
88
+
89
+ // src/session/state/account-readings.ts
90
+ import { join as join2 } from "node:path";
91
+ function readingsPath() {
92
+ return join2(stateDirectory(), "account-usage.json");
93
+ }
94
+ var readingsFile = cachedFile(readingsPath, (raw) => {
95
+ const parsed = JSON.parse(raw);
96
+ return parsed?.accounts && typeof parsed.accounts === "object" ? parsed.accounts : {};
97
+ });
98
+ var EMPTY = {};
99
+ async function loadReadings() {
100
+ return await readingsFile.load().catch(quiet("session/state/account-readings")) ?? EMPTY;
101
+ }
102
+ var time = (at) => {
103
+ const parsed = Date.parse(at ?? "");
104
+ return Number.isFinite(parsed) ? parsed : Number.NEGATIVE_INFINITY;
105
+ };
106
+ function hydrateAccountReadings(accounts, readings) {
107
+ if (readings === EMPTY) return accounts;
108
+ return accounts.map((account) => {
109
+ const stored = readings[account.id];
110
+ if (!stored) return account;
111
+ const usage = time(stored.usage?.at) > time(account.usage?.at) ? stored.usage : account.usage;
112
+ const checked = time(stored.usageCheckedAt) > time(account.usageCheckedAt) ? stored.usageCheckedAt : account.usageCheckedAt;
113
+ return { ...account, ...usage ? { usage } : {}, ...checked ? { usageCheckedAt: checked } : {} };
114
+ });
115
+ }
116
+ async function storeAccountReadings(accounts) {
117
+ const readings = {};
118
+ const stored = accounts.map((account) => {
119
+ const { usage, usageCheckedAt, ...rest } = account;
120
+ if (usage || usageCheckedAt) readings[account.id] = { ...usage ? { usage } : {}, ...usageCheckedAt ? { usageCheckedAt } : {} };
121
+ return rest;
122
+ });
123
+ if (!sameData(await loadReadings(), readings)) {
124
+ const raw = JSON.stringify({ accounts: readings });
125
+ await atomicWriteFile(readingsPath(), raw, { durable: false });
126
+ await readingsFile.remember(raw, readings);
127
+ }
128
+ return stored;
129
+ }
130
+
131
+ // src/session/state/index-file.ts
132
+ var HarnessStateVersionError = class extends Error {
133
+ constructor(found) {
134
+ super(`Local ClikCode state is version ${found}, written by a newer ClikCode than this one (supports up to ${HARNESS_STATE_VERSION}). It can be read but not changed from here. Update ClikCode to continue.`);
135
+ this.name = "HarnessStateVersionError";
136
+ }
137
+ };
138
+ var HARNESS_STATE_STATS = { indexWrites: 0 };
139
+ function parseIndex(raw) {
140
+ const parsed = JSON.parse(raw);
141
+ if (typeof parsed?.version !== "number" || !Array.isArray(parsed.accounts) || !Array.isArray(parsed.sessions)) {
142
+ throw new Error("unsupported local AI harness state");
143
+ }
144
+ return {
145
+ ...parsed,
146
+ // Only an index from before the log moved out (or one an older build
147
+ // still running wrote) holds invocations; loadIndex folds them in.
148
+ invocations: Array.isArray(parsed.invocations) ? parsed.invocations : [],
149
+ invocationRollups: parsed.invocationRollups && typeof parsed.invocationRollups === "object" ? parsed.invocationRollups : {}
150
+ };
151
+ }
152
+ var indexFile = cachedFile(harnessIndexPath, parseIndex);
153
+ var assembled;
154
+ async function assemble(file) {
155
+ const log = await loadInvocationLog();
156
+ const readings = await loadReadings();
157
+ if (assembled && assembled.file === file && assembled.log === log && assembled.readings === readings) return assembled.index;
158
+ let invocations = log.invocations;
159
+ if (file.invocations.length) {
160
+ const logged = new Set(invocations.map((invocation) => invocation.id));
161
+ invocations = [...invocations, ...file.invocations.filter((invocation) => !logged.has(invocation.id))];
162
+ }
163
+ const index = { ...file, accounts: hydrateAccountReadings(await hydrateAccountModels(file.accounts), readings), invocations };
164
+ assembled = { file, log, index, readings };
165
+ return index;
166
+ }
167
+ async function loadIndex() {
168
+ let file;
169
+ try {
170
+ file = await indexFile.load();
171
+ } catch (error) {
172
+ try {
173
+ file = parseIndex(await readFile(`${harnessIndexPath()}.bak`, "utf8"));
174
+ } catch (backupError) {
175
+ if (backupError.code === "ENOENT") throw error;
176
+ throw backupError;
177
+ }
178
+ }
179
+ return file ? assemble(file) : void 0;
180
+ }
181
+ function indexStructureChanged(previous, next) {
182
+ if (!previous) return true;
183
+ const ids = (list) => list.map((item) => item.id).join("\n");
184
+ return ids(previous.sessions) !== ids(next.sessions) || ids(previous.accounts) !== ids(next.accounts);
185
+ }
186
+ async function storeIndex(index, options) {
187
+ const path = harnessIndexPath();
188
+ await storeInvocationLog(index.invocations);
189
+ const { invocations: _logged, ...rest } = index;
190
+ const replacing = await indexFile.load().catch(quiet("session/state/index-file"));
191
+ const file = { ...rest, accounts: await storeAccountReadings(await storeAccountModels(index.accounts, replacing?.accounts)) };
192
+ const raw = `${JSON.stringify(file)}
193
+ `;
194
+ if (replacing && raw === indexFile.raw()) return;
195
+ await atomicWriteFile(path, raw, { durable: options.durable !== false });
196
+ HARNESS_STATE_STATS.indexWrites += 1;
197
+ if (Date.now() - tempsSweptAt > TEMP_SWEEP_EVERY_MS) {
198
+ tempsSweptAt = Date.now();
199
+ await sweepDeadWriterTemps(path).catch(quiet("session/state/index-file"));
200
+ }
201
+ await indexFile.remember(raw, { ...cloneData(file), invocations: [] });
202
+ if (options.backup) await atomicWriteFile(`${path}.bak`, raw).catch(quiet("session/state/index-file"));
203
+ }
204
+ var tempsSweptAt = 0;
205
+ var TEMP_SWEEP_EVERY_MS = 5 * 6e4;
206
+ var DEAD_TEMP_MIN_AGE_MS = 6e4;
207
+ async function sweepDeadWriterTemps(path, now = Date.now()) {
208
+ const prefix = `${basename(path)}.`;
209
+ let removed = 0;
210
+ for (const name of await readdir(dirname(path)).catch(() => [])) {
211
+ const pid = name.startsWith(prefix) ? /^(\d+)\.[0-9a-f]+\.tmp$/.exec(name.slice(prefix.length))?.[1] : void 0;
212
+ if (!pid || Number(pid) === process.pid || pidIsAlive(Number(pid))) continue;
213
+ const temp = join3(dirname(path), name);
214
+ const info = await stat(temp).catch(quiet("session/state/index-file"));
215
+ if (!info || now - info.mtimeMs < DEAD_TEMP_MIN_AGE_MS) continue;
216
+ await unlink(temp).then(() => {
217
+ removed += 1;
218
+ }, () => void 0);
219
+ }
220
+ return removed;
221
+ }
222
+
223
+ export {
224
+ HarnessStateVersionError,
225
+ loadIndex,
226
+ indexStructureChanged,
227
+ storeIndex
228
+ };