@caspian2026/agent-sdk 0.0.25 → 0.0.27

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 (362) hide show
  1. package/dist/gateway/index.js +98 -22
  2. package/dist/gateway/worker.js +1005 -982
  3. package/dist/sdk/query.cjs +2 -362
  4. package/dist/sdk/query.js +2 -367
  5. package/package.json +126 -128
  6. package/dist/chunk-04n4fe72.js +0 -107
  7. package/dist/chunk-04ys66ej.js +0 -344
  8. package/dist/chunk-07069jq1.js +0 -30
  9. package/dist/chunk-0731m51q.js +0 -8
  10. package/dist/chunk-086x4ct4.js +0 -26
  11. package/dist/chunk-0btqb97n.js +0 -295
  12. package/dist/chunk-0paqc2yw.js +0 -15
  13. package/dist/chunk-0r1rjydx.js +0 -145
  14. package/dist/chunk-0r5bb9j4.js +0 -477
  15. package/dist/chunk-0t81d427.js +0 -41
  16. package/dist/chunk-0teq2mz0.js +0 -420
  17. package/dist/chunk-0vkfrmqm.js +0 -690
  18. package/dist/chunk-0vp3wfab.js +0 -12
  19. package/dist/chunk-0warp8dx.js +0 -253
  20. package/dist/chunk-0xjaqda8.js +0 -1124
  21. package/dist/chunk-10gzv316.js +0 -62
  22. package/dist/chunk-11pq9n08.js +0 -168
  23. package/dist/chunk-1ae3nt9j.js +0 -31
  24. package/dist/chunk-1fmb0njn.js +0 -396
  25. package/dist/chunk-1gx78081.js +0 -66
  26. package/dist/chunk-1h2famwb.js +0 -49
  27. package/dist/chunk-1ng8xwxz.js +0 -276
  28. package/dist/chunk-1v7jp29h.js +0 -206
  29. package/dist/chunk-1xxy5zhb.js +0 -673
  30. package/dist/chunk-20b73w7w.js +0 -117
  31. package/dist/chunk-20qxd83a.js +0 -1161
  32. package/dist/chunk-2239ny9q.js +0 -90
  33. package/dist/chunk-22d4rnef.js +0 -226
  34. package/dist/chunk-26wtxbdc.js +0 -13870
  35. package/dist/chunk-27225bjh.js +0 -618
  36. package/dist/chunk-2b0e32an.js +0 -5822
  37. package/dist/chunk-2bfa9w1y.js +0 -323
  38. package/dist/chunk-2epq04w1.js +0 -63
  39. package/dist/chunk-2fwze72g.js +0 -24
  40. package/dist/chunk-2gzv8nrw.js +0 -205
  41. package/dist/chunk-2mexte1r.js +0 -349
  42. package/dist/chunk-2mzaqh5g.js +0 -338
  43. package/dist/chunk-2tb6mzfc.js +0 -81
  44. package/dist/chunk-2xq0g43w.js +0 -558
  45. package/dist/chunk-334aeqg9.js +0 -90
  46. package/dist/chunk-34jx4rjd.js +0 -995
  47. package/dist/chunk-35w5nhex.js +0 -132
  48. package/dist/chunk-3c25bcsw.js +0 -17
  49. package/dist/chunk-3eaxj8dg.js +0 -151
  50. package/dist/chunk-3fdgrwd2.js +0 -111
  51. package/dist/chunk-3jw0r58d.js +0 -121
  52. package/dist/chunk-3mgywd32.js +0 -8
  53. package/dist/chunk-3nk79af8.js +0 -8
  54. package/dist/chunk-3vy1jt9p.js +0 -1010
  55. package/dist/chunk-3x78pd4j.js +0 -153
  56. package/dist/chunk-47x3dsmn.js +0 -95
  57. package/dist/chunk-49pqt48n.js +0 -108
  58. package/dist/chunk-4f7m9fjw.js +0 -317
  59. package/dist/chunk-4jm600zv.js +0 -13
  60. package/dist/chunk-4k9d7gxv.js +0 -118
  61. package/dist/chunk-4net8san.js +0 -155
  62. package/dist/chunk-4pbx3g7s.js +0 -26
  63. package/dist/chunk-4v125j4z.js +0 -58
  64. package/dist/chunk-4vxkv5vz.js +0 -1438
  65. package/dist/chunk-51fqpjy3.js +0 -121
  66. package/dist/chunk-52e64f2h.js +0 -439
  67. package/dist/chunk-52e9mdjv.js +0 -684
  68. package/dist/chunk-55raexh7.js +0 -14358
  69. package/dist/chunk-59pq5122.js +0 -269
  70. package/dist/chunk-5bsj67v1.js +0 -349
  71. package/dist/chunk-5ccdsxgy.js +0 -74
  72. package/dist/chunk-5ekyhb1w.js +0 -422
  73. package/dist/chunk-5gcqdn8x.js +0 -867
  74. package/dist/chunk-5h5kx2jd.js +0 -34
  75. package/dist/chunk-5hf3werb.js +0 -193
  76. package/dist/chunk-5n1jc02d.js +0 -87
  77. package/dist/chunk-5wfxvxm8.js +0 -127
  78. package/dist/chunk-5wjebwmn.js +0 -89
  79. package/dist/chunk-5z28bqne.js +0 -6748
  80. package/dist/chunk-5zwsxpjn.js +0 -671
  81. package/dist/chunk-60phw466.js +0 -29
  82. package/dist/chunk-64c1avct.js +0 -13
  83. package/dist/chunk-64r16v22.js +0 -162
  84. package/dist/chunk-65t1r7zs.js +0 -418
  85. package/dist/chunk-66zry909.js +0 -11
  86. package/dist/chunk-67hxjjgc.js +0 -731
  87. package/dist/chunk-68ffk5qa.js +0 -14
  88. package/dist/chunk-69dr6rrd.js +0 -177
  89. package/dist/chunk-69n11zng.js +0 -436
  90. package/dist/chunk-6dj5t602.js +0 -341
  91. package/dist/chunk-6dngjwkh.js +0 -63
  92. package/dist/chunk-6dp8sz55.js +0 -3561
  93. package/dist/chunk-6hqgg0sv.js +0 -103
  94. package/dist/chunk-6nsd9606.js +0 -790
  95. package/dist/chunk-6p0hbwz3.js +0 -65
  96. package/dist/chunk-6ywdv5vg.js +0 -97
  97. package/dist/chunk-6zc758qw.js +0 -640
  98. package/dist/chunk-7aw745vx.js +0 -40175
  99. package/dist/chunk-7fxaphbq.js +0 -116
  100. package/dist/chunk-7sgtxrsc.js +0 -1059
  101. package/dist/chunk-7wm5s02e.js +0 -216
  102. package/dist/chunk-7xdk4109.js +0 -442
  103. package/dist/chunk-7xyswgjh.js +0 -8
  104. package/dist/chunk-83hfzbx3.js +0 -10
  105. package/dist/chunk-87m69h0v.js +0 -219
  106. package/dist/chunk-8g5pe1gr.js +0 -37
  107. package/dist/chunk-8jbw0fnf.js +0 -167
  108. package/dist/chunk-8jf9se66.js +0 -321
  109. package/dist/chunk-8p65embj.js +0 -875
  110. package/dist/chunk-8qrmaff1.js +0 -2669
  111. package/dist/chunk-8r975mwc.js +0 -93
  112. package/dist/chunk-8yhf030a.js +0 -69
  113. package/dist/chunk-93emz367.js +0 -107
  114. package/dist/chunk-948mn975.js +0 -460
  115. package/dist/chunk-99chkt7r.js +0 -54
  116. package/dist/chunk-9f7c1hzz.js +0 -50
  117. package/dist/chunk-9fk9ps1g.js +0 -178
  118. package/dist/chunk-9rh0k0aq.js +0 -90
  119. package/dist/chunk-9x5zgy22.js +0 -12
  120. package/dist/chunk-a0k2vj5b.js +0 -460
  121. package/dist/chunk-a0m57ssq.js +0 -325
  122. package/dist/chunk-a0nsmmz1.js +0 -133
  123. package/dist/chunk-a25jh1v4.js +0 -105
  124. package/dist/chunk-a4j5ekv0.js +0 -83
  125. package/dist/chunk-a8k3zf58.js +0 -313
  126. package/dist/chunk-ah0zarbq.js +0 -260
  127. package/dist/chunk-ase86y73.js +0 -15
  128. package/dist/chunk-b0kf00ff.js +0 -637
  129. package/dist/chunk-b1kcd3ss.js +0 -27
  130. package/dist/chunk-b8kcqqds.js +0 -93
  131. package/dist/chunk-bg4x9ex0.js +0 -21
  132. package/dist/chunk-bh5zqvyc.js +0 -36
  133. package/dist/chunk-bqrkfekw.js +0 -267
  134. package/dist/chunk-brjd9zmk.js +0 -42
  135. package/dist/chunk-byfawrfx.js +0 -121
  136. package/dist/chunk-c6sjhj89.js +0 -1284
  137. package/dist/chunk-c7e5yv0q.js +0 -212
  138. package/dist/chunk-c7jwbe76.js +0 -29030
  139. package/dist/chunk-cb5v8w7k.js +0 -289
  140. package/dist/chunk-cdef9v7b.js +0 -27
  141. package/dist/chunk-cdz5yb0r.js +0 -57
  142. package/dist/chunk-cgfdkzhb.js +0 -12
  143. package/dist/chunk-cgqw4x5z.js +0 -155
  144. package/dist/chunk-cnsj3vq2.js +0 -35
  145. package/dist/chunk-cqxm7ggc.js +0 -123
  146. package/dist/chunk-cxrktb5g.js +0 -51
  147. package/dist/chunk-d089t7dk.js +0 -312
  148. package/dist/chunk-d1z934cp.js +0 -71
  149. package/dist/chunk-d4mdda98.js +0 -94
  150. package/dist/chunk-d7xw8v91.js +0 -332
  151. package/dist/chunk-dc06c3rw.js +0 -1154
  152. package/dist/chunk-ddsjkqs4.js +0 -39
  153. package/dist/chunk-dfzkwynj.js +0 -5368
  154. package/dist/chunk-dnmp7s85.js +0 -20
  155. package/dist/chunk-dqqwjkv3.js +0 -8583
  156. package/dist/chunk-dt2mr4vf.js +0 -2962
  157. package/dist/chunk-dztm97gg.js +0 -150
  158. package/dist/chunk-e0abab5b.js +0 -445
  159. package/dist/chunk-e0ragz46.js +0 -209386
  160. package/dist/chunk-e9w9zc0g.js +0 -392
  161. package/dist/chunk-ebwskmsr.js +0 -107
  162. package/dist/chunk-efztk52j.js +0 -114
  163. package/dist/chunk-ehd8wacx.js +0 -40
  164. package/dist/chunk-ehtwnxpg.js +0 -1591
  165. package/dist/chunk-eqp1rfft.js +0 -17
  166. package/dist/chunk-etdt1xz3.js +0 -19
  167. package/dist/chunk-eva785x8.js +0 -88
  168. package/dist/chunk-ewadzrm8.js +0 -103
  169. package/dist/chunk-f2ajmcav.js +0 -92
  170. package/dist/chunk-fajg8x36.js +0 -8158
  171. package/dist/chunk-fbv4apne.js +0 -51
  172. package/dist/chunk-fcynwjpm.js +0 -1072
  173. package/dist/chunk-fev86f95.js +0 -1052
  174. package/dist/chunk-feyzykye.js +0 -10
  175. package/dist/chunk-ff85rwvc.js +0 -180
  176. package/dist/chunk-fk6ktvg2.js +0 -275
  177. package/dist/chunk-fqak69ft.js +0 -458
  178. package/dist/chunk-fqwas4jk.js +0 -281
  179. package/dist/chunk-fs35fdpj.js +0 -439
  180. package/dist/chunk-fvr3f9s3.js +0 -55
  181. package/dist/chunk-fyc5fepv.js +0 -10
  182. package/dist/chunk-g2g9cwt9.js +0 -54
  183. package/dist/chunk-g4znz46v.js +0 -2335
  184. package/dist/chunk-g5ts4e6k.js +0 -697
  185. package/dist/chunk-g6een9wr.js +0 -654
  186. package/dist/chunk-g7cmtx8r.js +0 -77
  187. package/dist/chunk-g9f19ttm.js +0 -15
  188. package/dist/chunk-gc7ap41t.js +0 -516
  189. package/dist/chunk-gdwdqewd.js +0 -19
  190. package/dist/chunk-gg14h3n4.js +0 -131
  191. package/dist/chunk-gg55fns0.js +0 -6440
  192. package/dist/chunk-gq7zab4e.js +0 -418
  193. package/dist/chunk-gydw3qy3.js +0 -169
  194. package/dist/chunk-gz1e8y1w.js +0 -33
  195. package/dist/chunk-h19r628d.js +0 -91
  196. package/dist/chunk-h2k8mt3z.js +0 -329
  197. package/dist/chunk-h9n54swm.js +0 -27
  198. package/dist/chunk-hakdhagh.js +0 -16606
  199. package/dist/chunk-hc2chp3g.js +0 -308
  200. package/dist/chunk-hemcv9t7.js +0 -153
  201. package/dist/chunk-hm62ntv3.js +0 -20
  202. package/dist/chunk-hmq09ytj.js +0 -100
  203. package/dist/chunk-hmv4hhqt.js +0 -2718
  204. package/dist/chunk-hwfknpxv.js +0 -39
  205. package/dist/chunk-j5bth84e.js +0 -97
  206. package/dist/chunk-j64ga6ta.js +0 -8035
  207. package/dist/chunk-j6v3w4yf.js +0 -244
  208. package/dist/chunk-jc29d2nm.js +0 -130
  209. package/dist/chunk-jd32zbps.js +0 -15
  210. package/dist/chunk-jd4sx4wh.js +0 -594
  211. package/dist/chunk-jha8n8b9.js +0 -33118
  212. package/dist/chunk-jj71qx7m.js +0 -122
  213. package/dist/chunk-jka9vpak.js +0 -114
  214. package/dist/chunk-jkf6ayv0.js +0 -32
  215. package/dist/chunk-jpz6t2tt.js +0 -61
  216. package/dist/chunk-jqt3sw12.js +0 -9114
  217. package/dist/chunk-jswd1q63.js +0 -101
  218. package/dist/chunk-jtc4aa2y.js +0 -1543
  219. package/dist/chunk-jyx3h86z.js +0 -635
  220. package/dist/chunk-jzthz1bx.js +0 -15
  221. package/dist/chunk-k0p9w03v.js +0 -4957
  222. package/dist/chunk-k6x3s7x5.js +0 -211
  223. package/dist/chunk-k7kmvnnx.js +0 -942
  224. package/dist/chunk-k8vp0atq.js +0 -2331
  225. package/dist/chunk-k9vm6x6z.js +0 -257
  226. package/dist/chunk-kb1edvhs.js +0 -120
  227. package/dist/chunk-kbhbe33q.js +0 -113
  228. package/dist/chunk-kgcgpp7z.js +0 -140
  229. package/dist/chunk-kvywbvqs.js +0 -261
  230. package/dist/chunk-kwekc97v.js +0 -18
  231. package/dist/chunk-kwyk9zp1.js +0 -74
  232. package/dist/chunk-ky1z78ve.js +0 -119
  233. package/dist/chunk-mcws22k3.js +0 -42
  234. package/dist/chunk-mr2z79r3.js +0 -1385
  235. package/dist/chunk-mst9nmns.js +0 -642
  236. package/dist/chunk-mswx2nma.js +0 -103
  237. package/dist/chunk-n1e3fjpz.js +0 -266
  238. package/dist/chunk-n6vjp9yg.js +0 -138
  239. package/dist/chunk-n84tqtvv.js +0 -120
  240. package/dist/chunk-n8ssddbw.js +0 -105
  241. package/dist/chunk-na35whkd.js +0 -227
  242. package/dist/chunk-netzwgv1.js +0 -154
  243. package/dist/chunk-ng7j0yy1.js +0 -100
  244. package/dist/chunk-nmgj86tt.js +0 -24
  245. package/dist/chunk-ns7x6xam.js +0 -22820
  246. package/dist/chunk-p7vkh4wx.js +0 -15
  247. package/dist/chunk-p8na2wwp.js +0 -14
  248. package/dist/chunk-pe3rkfp2.js +0 -74
  249. package/dist/chunk-pf0152j3.js +0 -40
  250. package/dist/chunk-pgtnj1mt.js +0 -705
  251. package/dist/chunk-ppwjyveh.js +0 -8
  252. package/dist/chunk-pq5qp2y4.js +0 -388
  253. package/dist/chunk-pqqxdk5f.js +0 -543
  254. package/dist/chunk-ps49ymvj.js +0 -43
  255. package/dist/chunk-pws8gq7m.js +0 -7422
  256. package/dist/chunk-pwwa7s62.js +0 -11
  257. package/dist/chunk-pyq0fabn.js +0 -860
  258. package/dist/chunk-q0p1m40t.js +0 -79
  259. package/dist/chunk-q0vhv550.js +0 -393
  260. package/dist/chunk-q7r0kt08.js +0 -1809
  261. package/dist/chunk-qajrkk97.js +0 -298
  262. package/dist/chunk-qatfdxvd.js +0 -34
  263. package/dist/chunk-qb6k2afy.js +0 -153
  264. package/dist/chunk-qg2qgx8h.js +0 -266
  265. package/dist/chunk-qkczt8cr.js +0 -24
  266. package/dist/chunk-qnfx3qtx.js +0 -617
  267. package/dist/chunk-qp2qdcda.js +0 -100
  268. package/dist/chunk-qtwgzej9.js +0 -85
  269. package/dist/chunk-r1dh0ymt.js +0 -91
  270. package/dist/chunk-r36xvgvv.js +0 -407
  271. package/dist/chunk-r48he8g3.js +0 -251
  272. package/dist/chunk-r63tqmtk.js +0 -146
  273. package/dist/chunk-rbdd3q5k.js +0 -101
  274. package/dist/chunk-rmbbmd3s.js +0 -68
  275. package/dist/chunk-rn0v1hk8.js +0 -34
  276. package/dist/chunk-rnxctq9p.js +0 -1646
  277. package/dist/chunk-rrs2mchs.js +0 -183
  278. package/dist/chunk-rtrybvnp.js +0 -209
  279. package/dist/chunk-rw2wkn45.js +0 -494
  280. package/dist/chunk-s4kzkdhd.js +0 -847
  281. package/dist/chunk-s7a0zn7b.js +0 -55
  282. package/dist/chunk-s8gy4ky9.js +0 -122
  283. package/dist/chunk-s8kj6ajy.js +0 -32
  284. package/dist/chunk-sag785ad.js +0 -283
  285. package/dist/chunk-scqjyben.js +0 -174
  286. package/dist/chunk-sd36yzx8.js +0 -954
  287. package/dist/chunk-sdtqm0nm.js +0 -374
  288. package/dist/chunk-sg60xg0x.js +0 -52
  289. package/dist/chunk-sgpmpn90.js +0 -35
  290. package/dist/chunk-sh02d2qn.js +0 -38
  291. package/dist/chunk-sz9y6z13.js +0 -61
  292. package/dist/chunk-szj5wvdy.js +0 -28
  293. package/dist/chunk-t29a6zb5.js +0 -45
  294. package/dist/chunk-t2b49hcf.js +0 -87
  295. package/dist/chunk-t2wqdppz.js +0 -445
  296. package/dist/chunk-t4khqff1.js +0 -16
  297. package/dist/chunk-t70t2gne.js +0 -121
  298. package/dist/chunk-t9p85zff.js +0 -24
  299. package/dist/chunk-tkrstmwz.js +0 -94
  300. package/dist/chunk-tnyb4exc.js +0 -74
  301. package/dist/chunk-tpn8jsvw.js +0 -71
  302. package/dist/chunk-tt7x5j1q.js +0 -111
  303. package/dist/chunk-tw1p628z.js +0 -984
  304. package/dist/chunk-twvdafcz.js +0 -528
  305. package/dist/chunk-tzwjafgn.js +0 -24
  306. package/dist/chunk-v140t8ay.js +0 -152
  307. package/dist/chunk-v1kzp02e.js +0 -785
  308. package/dist/chunk-v4t6dyyh.js +0 -9076
  309. package/dist/chunk-v78fj8by.js +0 -145
  310. package/dist/chunk-v8kjswxt.js +0 -61
  311. package/dist/chunk-v9smspw2.js +0 -4301
  312. package/dist/chunk-vcfbjkk9.js +0 -201
  313. package/dist/chunk-ve167rcs.js +0 -148
  314. package/dist/chunk-vf612n57.js +0 -472
  315. package/dist/chunk-vhffyae8.js +0 -895
  316. package/dist/chunk-vkhrrvfq.js +0 -44
  317. package/dist/chunk-vybkmfhf.js +0 -91
  318. package/dist/chunk-vyjeh50y.js +0 -2149
  319. package/dist/chunk-w6m6trzq.js +0 -58
  320. package/dist/chunk-w9b6kngq.js +0 -234
  321. package/dist/chunk-wa8yn2p0.js +0 -2007
  322. package/dist/chunk-wanceff6.js +0 -2840
  323. package/dist/chunk-wcze2nea.js +0 -336
  324. package/dist/chunk-wgk9sxk7.js +0 -329
  325. package/dist/chunk-wnxcgfsd.js +0 -253
  326. package/dist/chunk-wyjerrr6.js +0 -565
  327. package/dist/chunk-wz9brkq5.js +0 -60
  328. package/dist/chunk-x47h283a.js +0 -56
  329. package/dist/chunk-x59j3x9c.js +0 -98
  330. package/dist/chunk-x6r4v44b.js +0 -8
  331. package/dist/chunk-x7fdwq3d.js +0 -33
  332. package/dist/chunk-x8d2ehd7.js +0 -19
  333. package/dist/chunk-xeb6075z.js +0 -3435
  334. package/dist/chunk-xfw2pxwd.js +0 -223
  335. package/dist/chunk-xh06jc72.js +0 -200
  336. package/dist/chunk-xhfmdq1y.js +0 -147
  337. package/dist/chunk-xkwyg1d2.js +0 -195
  338. package/dist/chunk-xv3era3s.js +0 -8
  339. package/dist/chunk-xyapc58m.js +0 -87
  340. package/dist/chunk-xzgnc76g.js +0 -107
  341. package/dist/chunk-y1784krc.js +0 -19
  342. package/dist/chunk-y4ca9kqz.js +0 -3830
  343. package/dist/chunk-y9bhjjdz.js +0 -145
  344. package/dist/chunk-yb3bxv3w.js +0 -30
  345. package/dist/chunk-yddek6xk.js +0 -146
  346. package/dist/chunk-ypaq3d12.js +0 -4265
  347. package/dist/chunk-yq8z040g.js +0 -111
  348. package/dist/chunk-yqs481qq.js +0 -1163
  349. package/dist/chunk-ys9a9c9h.js +0 -105
  350. package/dist/chunk-yyex5gsf.js +0 -269
  351. package/dist/chunk-yzn396hn.js +0 -89
  352. package/dist/chunk-z2dp53wn.js +0 -17
  353. package/dist/chunk-zay4xp4n.js +0 -251
  354. package/dist/chunk-zc8bwy57.js +0 -212
  355. package/dist/chunk-zhx88cfx.js +0 -97
  356. package/dist/chunk-zkh6f4ct.js +0 -385
  357. package/dist/chunk-zq56gcca.js +0 -206
  358. package/dist/chunk-zrkefd22.js +0 -490
  359. package/dist/chunk-zs5p0yq1.js +0 -1030
  360. package/dist/chunk-zxh62ved.js +0 -31
  361. package/dist/chunk-zzm33q8x.js +0 -8
  362. package/dist/cli.js +0 -220
@@ -1,1161 +0,0 @@
1
- // @bun
2
- import {
3
- acquireProcessLifetimeLock,
4
- cleanupStaleLocks,
5
- filterClaudeAliases,
6
- getCurrentInstallationType,
7
- getShellConfigPaths,
8
- getShellType,
9
- init_doctorDiagnostic,
10
- init_localInstaller,
11
- init_pidLock,
12
- init_shellConfig,
13
- isLockActive,
14
- isPidBasedLockingEnabled,
15
- readFileLines,
16
- readLockContent,
17
- withLock,
18
- writeFileLines
19
- } from "./chunk-tw1p628z.js";
20
- import {
21
- getUserBinDir,
22
- getXDGCacheHome,
23
- getXDGDataHome,
24
- getXDGStateHome,
25
- init_xdg
26
- } from "./chunk-x7fdwq3d.js";
27
- import {
28
- envDynamic,
29
- init_envDynamic
30
- } from "./chunk-e0ragz46.js";
31
- import {
32
- gt,
33
- gte,
34
- init_semver
35
- } from "./chunk-ps49ymvj.js";
36
- import {
37
- getGlobalConfig,
38
- init_config,
39
- saveGlobalConfig
40
- } from "./chunk-2b0e32an.js";
41
- import {
42
- check,
43
- init_lockfile,
44
- lock
45
- } from "./chunk-6nsd9606.js";
46
- import {
47
- init_sleep,
48
- sleep
49
- } from "./chunk-8g5pe1gr.js";
50
- import {
51
- env,
52
- init_env
53
- } from "./chunk-5ekyhb1w.js";
54
- import {
55
- init_analytics,
56
- logEvent
57
- } from "./chunk-x8d2ehd7.js";
58
- import {
59
- execFileNoThrowWithCwd,
60
- init_execFileNoThrow
61
- } from "./chunk-64r16v22.js";
62
- import {
63
- errorMessage,
64
- getErrnoCode,
65
- init_cleanupRegistry,
66
- init_debug,
67
- init_errors,
68
- init_log,
69
- isENOENT,
70
- logError,
71
- logForDebugging,
72
- registerCleanup,
73
- toError
74
- } from "./chunk-gg55fns0.js";
75
- import {
76
- init_envUtils,
77
- isEnvTruthy
78
- } from "./chunk-5n1jc02d.js";
79
- import {
80
- __esm
81
- } from "./chunk-qp2qdcda.js";
82
-
83
- // src/utils/nativeInstaller/download.ts
84
- async function getLatestVersion(channelOrVersion) {
85
- if (/^v?\d+\.\d+\.\d+(-\S+)?$/.test(channelOrVersion)) {
86
- const normalized = channelOrVersion.startsWith("v") ? channelOrVersion.slice(1) : channelOrVersion;
87
- if (/^99\.99\./.test(normalized) && true) {
88
- throw new Error(`Version ${normalized} is not available for installation. Use 'stable' or 'latest'.`);
89
- }
90
- return normalized;
91
- }
92
- const channel = channelOrVersion;
93
- if (channel !== "stable" && channel !== "latest") {
94
- throw new Error(`Invalid channel: ${channelOrVersion}. Use 'stable' or 'latest'`);
95
- }
96
- throw new Error("Binary version check is disabled in this build (intranet deployment).");
97
- }
98
- async function downloadVersion(version, stagingPath) {
99
- throw new Error("Binary download is disabled in this build (intranet deployment).");
100
- }
101
- var init_download = () => {};
102
-
103
- // src/utils/nativeInstaller/installer.ts
104
- import { constants as fsConstants } from "fs";
105
- import {
106
- access,
107
- chmod,
108
- copyFile,
109
- lstat,
110
- mkdir,
111
- readdir,
112
- readlink,
113
- realpath,
114
- rename,
115
- rm,
116
- rmdir,
117
- stat,
118
- symlink,
119
- unlink,
120
- writeFile
121
- } from "fs/promises";
122
- import { homedir } from "os";
123
- import { basename, delimiter, dirname, join, resolve } from "path";
124
- function getPlatform() {
125
- const os = env.platform;
126
- const arch = process.arch === "x64" ? "x64" : process.arch === "arm64" ? "arm64" : null;
127
- if (!arch) {
128
- const error = new Error(`Unsupported architecture: ${process.arch}`);
129
- logForDebugging(`Native installer does not support architecture: ${process.arch}`, { level: "error" });
130
- throw error;
131
- }
132
- if (os === "linux" && envDynamic.isMuslEnvironment()) {
133
- return `linux-${arch}-musl`;
134
- }
135
- return `${os}-${arch}`;
136
- }
137
- function getBinaryName(platform) {
138
- return platform.startsWith("win32") ? "claude.exe" : "claude";
139
- }
140
- function getBaseDirectories() {
141
- const platform = getPlatform();
142
- const executableName = getBinaryName(platform);
143
- return {
144
- versions: join(getXDGDataHome(), "claude", "versions"),
145
- staging: join(getXDGCacheHome(), "claude", "staging"),
146
- locks: join(getXDGStateHome(), "claude", "locks"),
147
- executable: join(getUserBinDir(), executableName)
148
- };
149
- }
150
- async function isPossibleClaudeBinary(filePath) {
151
- try {
152
- const stats = await stat(filePath);
153
- if (!stats.isFile() || stats.size === 0) {
154
- return false;
155
- }
156
- await access(filePath, fsConstants.X_OK);
157
- return true;
158
- } catch {
159
- return false;
160
- }
161
- }
162
- async function getVersionPaths(version) {
163
- const dirs = getBaseDirectories();
164
- const dirsToCreate = [dirs.versions, dirs.staging, dirs.locks];
165
- await Promise.all(dirsToCreate.map((dir) => mkdir(dir, { recursive: true })));
166
- const executableParentDir = dirname(dirs.executable);
167
- await mkdir(executableParentDir, { recursive: true });
168
- const installPath = join(dirs.versions, version);
169
- try {
170
- await stat(installPath);
171
- } catch {
172
- await writeFile(installPath, "", { encoding: "utf8" });
173
- }
174
- return {
175
- stagingPath: join(dirs.staging, version),
176
- installPath
177
- };
178
- }
179
- async function tryWithVersionLock(versionFilePath, callback, retries = 0) {
180
- const dirs = getBaseDirectories();
181
- const lockfilePath = getLockFilePathFromVersionPath(dirs, versionFilePath);
182
- await mkdir(dirs.locks, { recursive: true });
183
- if (isPidBasedLockingEnabled()) {
184
- let attempts = 0;
185
- const maxAttempts = retries + 1;
186
- const minTimeout = retries > 0 ? 1000 : 100;
187
- const maxTimeout = retries > 0 ? 5000 : 500;
188
- while (attempts < maxAttempts) {
189
- const success = await withLock(versionFilePath, lockfilePath, async () => {
190
- try {
191
- await callback();
192
- } catch (error) {
193
- logError(error);
194
- throw error;
195
- }
196
- });
197
- if (success) {
198
- logEvent("tengu_version_lock_acquired", {
199
- is_pid_based: true,
200
- is_lifetime_lock: false,
201
- attempts: attempts + 1
202
- });
203
- return true;
204
- }
205
- attempts++;
206
- if (attempts < maxAttempts) {
207
- const timeout = Math.min(minTimeout * Math.pow(2, attempts - 1), maxTimeout);
208
- await sleep(timeout);
209
- }
210
- }
211
- logEvent("tengu_version_lock_failed", {
212
- is_pid_based: true,
213
- is_lifetime_lock: false,
214
- attempts: maxAttempts
215
- });
216
- logLockAcquisitionError(versionFilePath, new Error("Lock held by another process"));
217
- return false;
218
- }
219
- let release = null;
220
- try {
221
- try {
222
- release = await lock(versionFilePath, {
223
- stale: LOCK_STALE_MS,
224
- retries: {
225
- retries,
226
- minTimeout: retries > 0 ? 1000 : 100,
227
- maxTimeout: retries > 0 ? 5000 : 500
228
- },
229
- lockfilePath,
230
- onCompromised: (err) => {
231
- logForDebugging(`NON-FATAL: Version lock was compromised during operation: ${err.message}`, { level: "info" });
232
- }
233
- });
234
- } catch (lockError) {
235
- logEvent("tengu_version_lock_failed", {
236
- is_pid_based: false,
237
- is_lifetime_lock: false
238
- });
239
- logLockAcquisitionError(versionFilePath, lockError);
240
- return false;
241
- }
242
- try {
243
- await callback();
244
- logEvent("tengu_version_lock_acquired", {
245
- is_pid_based: false,
246
- is_lifetime_lock: false
247
- });
248
- return true;
249
- } catch (error) {
250
- logError(error);
251
- throw error;
252
- }
253
- } finally {
254
- if (release) {
255
- await release();
256
- }
257
- }
258
- }
259
- async function atomicMoveToInstallPath(stagedBinaryPath, installPath) {
260
- await mkdir(dirname(installPath), { recursive: true });
261
- const tempInstallPath = `${installPath}.tmp.${process.pid}.${Date.now()}`;
262
- try {
263
- await copyFile(stagedBinaryPath, tempInstallPath);
264
- await chmod(tempInstallPath, 493);
265
- await rename(tempInstallPath, installPath);
266
- logForDebugging(`Atomically installed binary to ${installPath}`);
267
- } catch (error) {
268
- try {
269
- await unlink(tempInstallPath);
270
- } catch {}
271
- throw error;
272
- }
273
- }
274
- async function installVersionFromPackage(stagingPath, installPath) {
275
- try {
276
- const nodeModulesDir = join(stagingPath, "node_modules", "@anthropic-ai");
277
- const entries = await readdir(nodeModulesDir);
278
- const nativePackage = entries.find((entry) => entry.startsWith("claude-cli-native-"));
279
- if (!nativePackage) {
280
- logEvent("tengu_native_install_package_failure", {
281
- stage_find_package: true,
282
- error_package_not_found: true
283
- });
284
- const error = new Error("Could not find platform-specific native package");
285
- throw error;
286
- }
287
- const stagedBinaryPath = join(nodeModulesDir, nativePackage, "cli");
288
- try {
289
- await stat(stagedBinaryPath);
290
- } catch {
291
- logEvent("tengu_native_install_package_failure", {
292
- stage_binary_exists: true,
293
- error_binary_not_found: true
294
- });
295
- const error = new Error("Native binary not found in staged package");
296
- throw error;
297
- }
298
- await atomicMoveToInstallPath(stagedBinaryPath, installPath);
299
- await rm(stagingPath, { recursive: true, force: true });
300
- logEvent("tengu_native_install_package_success", {});
301
- } catch (error) {
302
- const msg = errorMessage(error);
303
- if (!msg.includes("Could not find platform-specific") && !msg.includes("Native binary not found")) {
304
- logEvent("tengu_native_install_package_failure", {
305
- stage_atomic_move: true,
306
- error_move_failed: true
307
- });
308
- }
309
- logError(toError(error));
310
- throw error;
311
- }
312
- }
313
- async function installVersionFromBinary(stagingPath, installPath) {
314
- try {
315
- const platform = getPlatform();
316
- const binaryName = getBinaryName(platform);
317
- const stagedBinaryPath = join(stagingPath, binaryName);
318
- try {
319
- await stat(stagedBinaryPath);
320
- } catch {
321
- logEvent("tengu_native_install_binary_failure", {
322
- stage_binary_exists: true,
323
- error_binary_not_found: true
324
- });
325
- const error = new Error("Staged binary not found");
326
- throw error;
327
- }
328
- await atomicMoveToInstallPath(stagedBinaryPath, installPath);
329
- await rm(stagingPath, { recursive: true, force: true });
330
- logEvent("tengu_native_install_binary_success", {});
331
- } catch (error) {
332
- if (!errorMessage(error).includes("Staged binary not found")) {
333
- logEvent("tengu_native_install_binary_failure", {
334
- stage_atomic_move: true,
335
- error_move_failed: true
336
- });
337
- }
338
- logError(toError(error));
339
- throw error;
340
- }
341
- }
342
- async function installVersion(stagingPath, installPath, downloadType) {
343
- if (downloadType === "npm") {
344
- await installVersionFromPackage(stagingPath, installPath);
345
- } else {
346
- await installVersionFromBinary(stagingPath, installPath);
347
- }
348
- }
349
- async function performVersionUpdate(version, forceReinstall) {
350
- const { stagingPath: baseStagingPath, installPath } = await getVersionPaths(version);
351
- const { executable: executablePath } = getBaseDirectories();
352
- const stagingPath = isEnvTruthy(process.env.ENABLE_LOCKLESS_UPDATES) ? `${baseStagingPath}.${process.pid}.${Date.now()}` : baseStagingPath;
353
- const needsInstall = !await versionIsAvailable(version) || forceReinstall;
354
- if (needsInstall) {
355
- logForDebugging(forceReinstall ? `Force reinstalling native installer version ${version}` : `Downloading native installer version ${version}`);
356
- const downloadType = await downloadVersion(version, stagingPath);
357
- await installVersion(stagingPath, installPath, downloadType);
358
- } else {
359
- logForDebugging(`Version ${version} already installed, updating symlink`);
360
- }
361
- await removeDirectoryIfEmpty(executablePath);
362
- await updateSymlink(executablePath, installPath);
363
- if (!await isPossibleClaudeBinary(executablePath)) {
364
- let installPathExists = false;
365
- try {
366
- await stat(installPath);
367
- installPathExists = true;
368
- } catch {}
369
- throw new Error(`Failed to create executable at ${executablePath}. ` + `Source file exists: ${installPathExists}. ` + `Check write permissions to ${executablePath}.`);
370
- }
371
- return needsInstall;
372
- }
373
- async function versionIsAvailable(version) {
374
- const { installPath } = await getVersionPaths(version);
375
- return isPossibleClaudeBinary(installPath);
376
- }
377
- async function updateLatest(channelOrVersion, forceReinstall = false) {
378
- const startTime = Date.now();
379
- let version = await getLatestVersion(channelOrVersion);
380
- const { executable: executablePath } = getBaseDirectories();
381
- logForDebugging(`Checking for native installer update to version ${version}`);
382
- if (!forceReinstall) {
383
- const maxVersion = await getMaxVersion();
384
- if (maxVersion && gt(version, maxVersion)) {
385
- logForDebugging(`Native installer: maxVersion ${maxVersion} is set, capping update from ${version} to ${maxVersion}`);
386
- if (gte("0.0.25", maxVersion)) {
387
- logForDebugging(`Native installer: current version ${"0.0.25"} is already at or above maxVersion ${maxVersion}, skipping update`);
388
- logEvent("tengu_native_update_skipped_max_version", {
389
- latency_ms: Date.now() - startTime,
390
- max_version: maxVersion,
391
- available_version: version
392
- });
393
- return { success: true, latestVersion: version };
394
- }
395
- version = maxVersion;
396
- }
397
- }
398
- if (!forceReinstall && version === "0.0.25" && await versionIsAvailable(version) && await isPossibleClaudeBinary(executablePath)) {
399
- logForDebugging(`Found ${version} at ${executablePath}, skipping install`);
400
- logEvent("tengu_native_update_complete", {
401
- latency_ms: Date.now() - startTime,
402
- was_new_install: false,
403
- was_force_reinstall: false,
404
- was_already_running: true
405
- });
406
- return { success: true, latestVersion: version };
407
- }
408
- if (!forceReinstall && shouldSkipVersion(version)) {
409
- logEvent("tengu_native_update_skipped_minimum_version", {
410
- latency_ms: Date.now() - startTime,
411
- target_version: version
412
- });
413
- return { success: true, latestVersion: version };
414
- }
415
- let wasNewInstall = false;
416
- let latencyMs;
417
- if (isEnvTruthy(process.env.ENABLE_LOCKLESS_UPDATES)) {
418
- wasNewInstall = await performVersionUpdate(version, forceReinstall);
419
- latencyMs = Date.now() - startTime;
420
- } else {
421
- const { installPath } = await getVersionPaths(version);
422
- if (forceReinstall) {
423
- await forceRemoveLock(installPath);
424
- }
425
- const lockAcquired = await tryWithVersionLock(installPath, async () => {
426
- wasNewInstall = await performVersionUpdate(version, forceReinstall);
427
- }, 3);
428
- latencyMs = Date.now() - startTime;
429
- if (!lockAcquired) {
430
- const dirs = getBaseDirectories();
431
- let lockHolderPid;
432
- if (isPidBasedLockingEnabled()) {
433
- const lockfilePath = getLockFilePathFromVersionPath(dirs, installPath);
434
- if (isLockActive(lockfilePath)) {
435
- lockHolderPid = readLockContent(lockfilePath)?.pid;
436
- }
437
- }
438
- logEvent("tengu_native_update_lock_failed", {
439
- latency_ms: latencyMs,
440
- lock_holder_pid: lockHolderPid
441
- });
442
- return {
443
- success: false,
444
- latestVersion: version,
445
- lockFailed: true,
446
- lockHolderPid
447
- };
448
- }
449
- }
450
- logEvent("tengu_native_update_complete", {
451
- latency_ms: latencyMs,
452
- was_new_install: wasNewInstall,
453
- was_force_reinstall: forceReinstall
454
- });
455
- logForDebugging(`Successfully updated to version ${version}`);
456
- return { success: true, latestVersion: version };
457
- }
458
- async function removeDirectoryIfEmpty(path) {
459
- try {
460
- await rmdir(path);
461
- logForDebugging(`Removed empty directory at ${path}`);
462
- } catch (error) {
463
- const code = getErrnoCode(error);
464
- if (code !== "ENOTDIR" && code !== "ENOENT" && code !== "ENOTEMPTY") {
465
- logForDebugging(`Could not remove directory at ${path}: ${error}`);
466
- }
467
- }
468
- }
469
- async function updateSymlink(symlinkPath, targetPath) {
470
- const platform = getPlatform();
471
- const isWindows = platform.startsWith("win32");
472
- if (isWindows) {
473
- try {
474
- const parentDir2 = dirname(symlinkPath);
475
- await mkdir(parentDir2, { recursive: true });
476
- let existingStats;
477
- try {
478
- existingStats = await stat(symlinkPath);
479
- } catch {}
480
- if (existingStats) {
481
- try {
482
- const targetStats = await stat(targetPath);
483
- if (existingStats.size === targetStats.size) {
484
- return false;
485
- }
486
- } catch {}
487
- const oldFileName = `${symlinkPath}.old.${Date.now()}`;
488
- await rename(symlinkPath, oldFileName);
489
- try {
490
- await copyFile(targetPath, symlinkPath);
491
- try {
492
- await unlink(oldFileName);
493
- } catch {}
494
- } catch (copyError) {
495
- try {
496
- await rename(oldFileName, symlinkPath);
497
- } catch (restoreError) {
498
- const errorWithCause = new Error(`Failed to restore old executable: ${restoreError}`, { cause: copyError });
499
- logError(errorWithCause);
500
- throw errorWithCause;
501
- }
502
- throw copyError;
503
- }
504
- } else {
505
- try {
506
- await copyFile(targetPath, symlinkPath);
507
- } catch (e) {
508
- if (isENOENT(e)) {
509
- throw new Error(`Source file does not exist: ${targetPath}`);
510
- }
511
- throw e;
512
- }
513
- }
514
- return true;
515
- } catch (error) {
516
- logError(new Error(`Failed to copy executable from ${targetPath} to ${symlinkPath}: ${error}`));
517
- return false;
518
- }
519
- }
520
- const parentDir = dirname(symlinkPath);
521
- try {
522
- await mkdir(parentDir, { recursive: true });
523
- logForDebugging(`Created directory ${parentDir} for symlink`);
524
- } catch (mkdirError) {
525
- logError(new Error(`Failed to create directory ${parentDir}: ${mkdirError}`));
526
- return false;
527
- }
528
- try {
529
- let symlinkExists = false;
530
- try {
531
- await stat(symlinkPath);
532
- symlinkExists = true;
533
- } catch {}
534
- if (symlinkExists) {
535
- try {
536
- const currentTarget = await readlink(symlinkPath);
537
- const resolvedCurrentTarget = resolve(dirname(symlinkPath), currentTarget);
538
- const resolvedTargetPath = resolve(targetPath);
539
- if (resolvedCurrentTarget === resolvedTargetPath) {
540
- return false;
541
- }
542
- } catch {}
543
- await unlink(symlinkPath);
544
- }
545
- } catch (error) {
546
- logError(new Error(`Failed to check/remove existing symlink: ${error}`));
547
- }
548
- const tempSymlink = `${symlinkPath}.tmp.${process.pid}.${Date.now()}`;
549
- try {
550
- await symlink(targetPath, tempSymlink);
551
- await rename(tempSymlink, symlinkPath);
552
- logForDebugging(`Atomically updated symlink ${symlinkPath} -> ${targetPath}`);
553
- return true;
554
- } catch (error) {
555
- try {
556
- await unlink(tempSymlink);
557
- } catch {}
558
- logError(new Error(`Failed to create symlink from ${symlinkPath} to ${targetPath}: ${error}`));
559
- return false;
560
- }
561
- }
562
- async function checkInstall(force = false) {
563
- if (isEnvTruthy(process.env.DISABLE_INSTALLATION_CHECKS)) {
564
- return [];
565
- }
566
- const installationType = await getCurrentInstallationType();
567
- if (installationType === "development") {
568
- return [];
569
- }
570
- const config = getGlobalConfig();
571
- const shouldCheckNative = force || installationType === "native" || config.installMethod === "native";
572
- if (!shouldCheckNative) {
573
- return [];
574
- }
575
- const dirs = getBaseDirectories();
576
- const messages = [];
577
- const localBinDir = dirname(dirs.executable);
578
- const resolvedLocalBinPath = resolve(localBinDir);
579
- const platform = getPlatform();
580
- const isWindows = platform.startsWith("win32");
581
- try {
582
- await access(localBinDir);
583
- } catch {
584
- messages.push({
585
- message: `installMethod is native, but directory ${localBinDir} does not exist`,
586
- userActionRequired: true,
587
- type: "error"
588
- });
589
- }
590
- if (isWindows) {
591
- if (!await isPossibleClaudeBinary(dirs.executable)) {
592
- messages.push({
593
- message: `installMethod is native, but claude command is missing or invalid at ${dirs.executable}`,
594
- userActionRequired: true,
595
- type: "error"
596
- });
597
- }
598
- } else {
599
- try {
600
- const target = await readlink(dirs.executable);
601
- const absoluteTarget = resolve(dirname(dirs.executable), target);
602
- if (!await isPossibleClaudeBinary(absoluteTarget)) {
603
- messages.push({
604
- message: `Claude symlink points to missing or invalid binary: ${target}`,
605
- userActionRequired: true,
606
- type: "error"
607
- });
608
- }
609
- } catch (e) {
610
- if (isENOENT(e)) {
611
- messages.push({
612
- message: `installMethod is native, but claude command not found at ${dirs.executable}`,
613
- userActionRequired: true,
614
- type: "error"
615
- });
616
- } else {
617
- if (!await isPossibleClaudeBinary(dirs.executable)) {
618
- messages.push({
619
- message: `${dirs.executable} exists but is not a valid Claude binary`,
620
- userActionRequired: true,
621
- type: "error"
622
- });
623
- }
624
- }
625
- }
626
- }
627
- const isInCurrentPath = (process.env.PATH || "").split(delimiter).some((entry) => {
628
- try {
629
- const resolvedEntry = resolve(entry);
630
- if (isWindows) {
631
- return resolvedEntry.toLowerCase() === resolvedLocalBinPath.toLowerCase();
632
- }
633
- return resolvedEntry === resolvedLocalBinPath;
634
- } catch {
635
- return false;
636
- }
637
- });
638
- if (!isInCurrentPath) {
639
- if (isWindows) {
640
- const windowsBinPath = localBinDir.replace(/\//g, "\\");
641
- messages.push({
642
- message: `Native installation exists but ${windowsBinPath} is not in your PATH. Add it by opening: System Properties \u2192 Environment Variables \u2192 Edit User PATH \u2192 New \u2192 Add the path above. Then restart your terminal.`,
643
- userActionRequired: true,
644
- type: "path"
645
- });
646
- } else {
647
- const shellType = getShellType();
648
- const configPaths = getShellConfigPaths();
649
- const configFile = configPaths[shellType];
650
- const displayPath = configFile ? configFile.replace(homedir(), "~") : "your shell config file";
651
- messages.push({
652
- message: `Native installation exists but ~/.local/bin is not in your PATH. Run:
653
-
654
- echo 'export PATH="$HOME/.local/bin:$PATH"' >> ${displayPath} && source ${displayPath}`,
655
- userActionRequired: true,
656
- type: "path"
657
- });
658
- }
659
- }
660
- return messages;
661
- }
662
- function installLatest(channelOrVersion, forceReinstall = false) {
663
- if (forceReinstall) {
664
- return installLatestImpl(channelOrVersion, forceReinstall);
665
- }
666
- if (inFlightInstall) {
667
- logForDebugging("installLatest: joining in-flight call");
668
- return inFlightInstall;
669
- }
670
- const promise = installLatestImpl(channelOrVersion, forceReinstall);
671
- inFlightInstall = promise;
672
- const clear = () => {
673
- inFlightInstall = null;
674
- };
675
- promise.then(clear, clear);
676
- return promise;
677
- }
678
- async function installLatestImpl(channelOrVersion, forceReinstall = false) {
679
- const updateResult = await updateLatest(channelOrVersion, forceReinstall);
680
- if (!updateResult.success) {
681
- return {
682
- latestVersion: null,
683
- wasUpdated: false,
684
- lockFailed: updateResult.lockFailed,
685
- lockHolderPid: updateResult.lockHolderPid
686
- };
687
- }
688
- const config = getGlobalConfig();
689
- if (config.installMethod !== "native") {
690
- saveGlobalConfig((current) => ({
691
- ...current,
692
- installMethod: "native",
693
- autoUpdates: false,
694
- autoUpdatesProtectedForNative: true
695
- }));
696
- logForDebugging('Native installer: Set installMethod to "native" and disabled legacy auto-updater for protection');
697
- }
698
- cleanupOldVersions();
699
- return {
700
- latestVersion: updateResult.latestVersion,
701
- wasUpdated: updateResult.success,
702
- lockFailed: false
703
- };
704
- }
705
- async function getVersionFromSymlink(symlinkPath) {
706
- try {
707
- const target = await readlink(symlinkPath);
708
- const absoluteTarget = resolve(dirname(symlinkPath), target);
709
- if (await isPossibleClaudeBinary(absoluteTarget)) {
710
- return absoluteTarget;
711
- }
712
- } catch {}
713
- return null;
714
- }
715
- function getLockFilePathFromVersionPath(dirs, versionPath) {
716
- const versionName = basename(versionPath);
717
- return join(dirs.locks, `${versionName}.lock`);
718
- }
719
- async function lockCurrentVersion() {
720
- const dirs = getBaseDirectories();
721
- if (!process.execPath.includes(dirs.versions)) {
722
- return;
723
- }
724
- const versionPath = resolve(process.execPath);
725
- try {
726
- const lockfilePath = getLockFilePathFromVersionPath(dirs, versionPath);
727
- await mkdir(dirs.locks, { recursive: true });
728
- if (isPidBasedLockingEnabled()) {
729
- const acquired = await acquireProcessLifetimeLock(versionPath, lockfilePath);
730
- if (!acquired) {
731
- logEvent("tengu_version_lock_failed", {
732
- is_pid_based: true,
733
- is_lifetime_lock: true
734
- });
735
- logLockAcquisitionError(versionPath, new Error("Lock already held by another process"));
736
- return;
737
- }
738
- logEvent("tengu_version_lock_acquired", {
739
- is_pid_based: true,
740
- is_lifetime_lock: true
741
- });
742
- logForDebugging(`Acquired PID lock on running version: ${versionPath}`);
743
- } else {
744
- let release;
745
- try {
746
- release = await lock(versionPath, {
747
- stale: LOCK_STALE_MS,
748
- retries: 0,
749
- lockfilePath,
750
- onCompromised: (err) => {
751
- logForDebugging(`NON-FATAL: Lock on running version was compromised: ${err.message}`, { level: "info" });
752
- }
753
- });
754
- logEvent("tengu_version_lock_acquired", {
755
- is_pid_based: false,
756
- is_lifetime_lock: true
757
- });
758
- logForDebugging(`Acquired mtime-based lock on running version: ${versionPath}`);
759
- registerCleanup(async () => {
760
- try {
761
- await release?.();
762
- } catch {}
763
- });
764
- } catch (lockError) {
765
- if (isENOENT(lockError)) {
766
- logForDebugging(`Cannot lock current version - file does not exist: ${versionPath}`, { level: "info" });
767
- return;
768
- }
769
- logEvent("tengu_version_lock_failed", {
770
- is_pid_based: false,
771
- is_lifetime_lock: true
772
- });
773
- logLockAcquisitionError(versionPath, lockError);
774
- return;
775
- }
776
- }
777
- } catch (error) {
778
- if (isENOENT(error)) {
779
- logForDebugging(`Cannot lock current version - file does not exist: ${versionPath}`, { level: "info" });
780
- return;
781
- }
782
- logForDebugging(`NON-FATAL: Failed to lock current version during execution ${errorMessage(error)}`, { level: "info" });
783
- }
784
- }
785
- function logLockAcquisitionError(versionPath, lockError) {
786
- logError(new Error(`NON-FATAL: Lock acquisition failed for ${versionPath} (expected in multi-process scenarios)`, { cause: lockError }));
787
- }
788
- async function forceRemoveLock(versionFilePath) {
789
- const dirs = getBaseDirectories();
790
- const lockfilePath = getLockFilePathFromVersionPath(dirs, versionFilePath);
791
- try {
792
- await unlink(lockfilePath);
793
- logForDebugging(`Force-removed lock file at ${lockfilePath}`);
794
- } catch (error) {
795
- logForDebugging(`Failed to force-remove lock file: ${errorMessage(error)}`);
796
- }
797
- }
798
- async function cleanupOldVersions() {
799
- await Promise.resolve();
800
- const dirs = getBaseDirectories();
801
- const oneHourAgo = Date.now() - 3600000;
802
- if (getPlatform().startsWith("win32")) {
803
- const executableDir = dirname(dirs.executable);
804
- try {
805
- const files = await readdir(executableDir);
806
- let cleanedCount = 0;
807
- for (const file of files) {
808
- if (!/^claude\.exe\.old\.\d+$/.test(file))
809
- continue;
810
- try {
811
- await unlink(join(executableDir, file));
812
- cleanedCount++;
813
- } catch {}
814
- }
815
- if (cleanedCount > 0) {
816
- logForDebugging(`Cleaned up ${cleanedCount} old Windows executables on startup`);
817
- }
818
- } catch (error) {
819
- if (!isENOENT(error)) {
820
- logForDebugging(`Failed to clean up old Windows executables: ${error}`);
821
- }
822
- }
823
- }
824
- try {
825
- const stagingEntries = await readdir(dirs.staging);
826
- let stagingCleanedCount = 0;
827
- for (const entry of stagingEntries) {
828
- const stagingPath = join(dirs.staging, entry);
829
- try {
830
- const stats = await stat(stagingPath);
831
- if (stats.mtime.getTime() < oneHourAgo) {
832
- await rm(stagingPath, { recursive: true, force: true });
833
- stagingCleanedCount++;
834
- logForDebugging(`Cleaned up old staging directory: ${entry}`);
835
- }
836
- } catch {}
837
- }
838
- if (stagingCleanedCount > 0) {
839
- logForDebugging(`Cleaned up ${stagingCleanedCount} orphaned staging directories`);
840
- logEvent("tengu_native_staging_cleanup", {
841
- cleaned_count: stagingCleanedCount
842
- });
843
- }
844
- } catch (error) {
845
- if (!isENOENT(error)) {
846
- logForDebugging(`Failed to clean up staging directories: ${error}`);
847
- }
848
- }
849
- if (isPidBasedLockingEnabled()) {
850
- const staleLocksCleaned = cleanupStaleLocks(dirs.locks);
851
- if (staleLocksCleaned > 0) {
852
- logForDebugging(`Cleaned up ${staleLocksCleaned} stale version locks`);
853
- logEvent("tengu_native_stale_locks_cleanup", {
854
- cleaned_count: staleLocksCleaned
855
- });
856
- }
857
- }
858
- let versionEntries;
859
- try {
860
- versionEntries = await readdir(dirs.versions);
861
- } catch (error) {
862
- if (!isENOENT(error)) {
863
- logForDebugging(`Failed to readdir versions directory: ${error}`);
864
- }
865
- return;
866
- }
867
- const versionFiles = [];
868
- let tempFilesCleanedCount = 0;
869
- for (const entry of versionEntries) {
870
- const entryPath = join(dirs.versions, entry);
871
- if (/\.tmp\.\d+\.\d+$/.test(entry)) {
872
- try {
873
- const stats = await stat(entryPath);
874
- if (stats.mtime.getTime() < oneHourAgo) {
875
- await unlink(entryPath);
876
- tempFilesCleanedCount++;
877
- logForDebugging(`Cleaned up orphaned temp install file: ${entry}`);
878
- }
879
- } catch {}
880
- continue;
881
- }
882
- try {
883
- const stats = await stat(entryPath);
884
- if (!stats.isFile())
885
- continue;
886
- if (process.platform !== "win32" && stats.size > 0 && (stats.mode & 73) === 0) {
887
- continue;
888
- }
889
- versionFiles.push({
890
- name: entry,
891
- path: entryPath,
892
- resolvedPath: resolve(entryPath),
893
- mtime: stats.mtime
894
- });
895
- } catch {}
896
- }
897
- if (tempFilesCleanedCount > 0) {
898
- logForDebugging(`Cleaned up ${tempFilesCleanedCount} orphaned temp install files`);
899
- logEvent("tengu_native_temp_files_cleanup", {
900
- cleaned_count: tempFilesCleanedCount
901
- });
902
- }
903
- if (versionFiles.length === 0) {
904
- return;
905
- }
906
- try {
907
- const currentBinaryPath = process.execPath;
908
- const protectedVersions = new Set;
909
- if (currentBinaryPath && currentBinaryPath.includes(dirs.versions)) {
910
- protectedVersions.add(resolve(currentBinaryPath));
911
- }
912
- const currentSymlinkVersion = await getVersionFromSymlink(dirs.executable);
913
- if (currentSymlinkVersion) {
914
- protectedVersions.add(currentSymlinkVersion);
915
- }
916
- for (const v of versionFiles) {
917
- if (protectedVersions.has(v.resolvedPath))
918
- continue;
919
- const lockFilePath = getLockFilePathFromVersionPath(dirs, v.resolvedPath);
920
- let hasActiveLock = false;
921
- if (isPidBasedLockingEnabled()) {
922
- hasActiveLock = isLockActive(lockFilePath);
923
- } else {
924
- try {
925
- hasActiveLock = await check(v.resolvedPath, {
926
- stale: LOCK_STALE_MS,
927
- lockfilePath: lockFilePath
928
- });
929
- } catch {
930
- hasActiveLock = false;
931
- }
932
- }
933
- if (hasActiveLock) {
934
- protectedVersions.add(v.resolvedPath);
935
- logForDebugging(`Protecting locked version from cleanup: ${v.name}`);
936
- }
937
- }
938
- const eligibleVersions = versionFiles.filter((v) => !protectedVersions.has(v.resolvedPath)).sort((a, b) => b.mtime.getTime() - a.mtime.getTime());
939
- const versionsToDelete = eligibleVersions.slice(VERSION_RETENTION_COUNT);
940
- if (versionsToDelete.length === 0) {
941
- logEvent("tengu_native_version_cleanup", {
942
- total_count: versionFiles.length,
943
- deleted_count: 0,
944
- protected_count: protectedVersions.size,
945
- retained_count: VERSION_RETENTION_COUNT,
946
- lock_failed_count: 0,
947
- error_count: 0
948
- });
949
- return;
950
- }
951
- let deletedCount = 0;
952
- let lockFailedCount = 0;
953
- let errorCount = 0;
954
- await Promise.all(versionsToDelete.map(async (version) => {
955
- try {
956
- const deleted = await tryWithVersionLock(version.path, async () => {
957
- await unlink(version.path);
958
- });
959
- if (deleted) {
960
- deletedCount++;
961
- } else {
962
- lockFailedCount++;
963
- logForDebugging(`Skipping deletion of ${version.name} - locked by another process`);
964
- }
965
- } catch (error) {
966
- errorCount++;
967
- logError(new Error(`Failed to delete version ${version.name}: ${error}`));
968
- }
969
- }));
970
- logEvent("tengu_native_version_cleanup", {
971
- total_count: versionFiles.length,
972
- deleted_count: deletedCount,
973
- protected_count: protectedVersions.size,
974
- retained_count: VERSION_RETENTION_COUNT,
975
- lock_failed_count: lockFailedCount,
976
- error_count: errorCount
977
- });
978
- } catch (error) {
979
- if (!isENOENT(error)) {
980
- logError(new Error(`Version cleanup failed: ${error}`));
981
- }
982
- }
983
- }
984
- async function cleanupShellAliases() {
985
- const messages = [];
986
- const configMap = getShellConfigPaths();
987
- for (const [shellType, configFile] of Object.entries(configMap)) {
988
- try {
989
- const lines = await readFileLines(configFile);
990
- if (!lines)
991
- continue;
992
- const { filtered, hadAlias } = filterClaudeAliases(lines);
993
- if (hadAlias) {
994
- await writeFileLines(configFile, filtered);
995
- messages.push({
996
- message: `Removed claude alias from ${configFile}. Run: unalias claude`,
997
- userActionRequired: true,
998
- type: "alias"
999
- });
1000
- logForDebugging(`Cleaned up claude alias from ${shellType} config`);
1001
- }
1002
- } catch (error) {
1003
- logError(error);
1004
- messages.push({
1005
- message: `Failed to clean up ${configFile}: ${error}`,
1006
- userActionRequired: false,
1007
- type: "error"
1008
- });
1009
- }
1010
- }
1011
- return messages;
1012
- }
1013
- async function manualRemoveNpmPackage(packageName) {
1014
- try {
1015
- const prefixResult = await execFileNoThrowWithCwd("npm", [
1016
- "config",
1017
- "get",
1018
- "prefix"
1019
- ]);
1020
- if (prefixResult.code !== 0 || !prefixResult.stdout) {
1021
- return {
1022
- success: false,
1023
- error: "Failed to get npm global prefix"
1024
- };
1025
- }
1026
- const globalPrefix = prefixResult.stdout.trim();
1027
- let manuallyRemoved = false;
1028
- async function tryRemove(filePath, description) {
1029
- try {
1030
- await unlink(filePath);
1031
- logForDebugging(`Manually removed ${description}: ${filePath}`);
1032
- return true;
1033
- } catch {
1034
- return false;
1035
- }
1036
- }
1037
- if (getPlatform().startsWith("win32")) {
1038
- const binCmd = join(globalPrefix, "claude.cmd");
1039
- const binPs1 = join(globalPrefix, "claude.ps1");
1040
- const binExe = join(globalPrefix, "claude");
1041
- if (await tryRemove(binCmd, "bin script")) {
1042
- manuallyRemoved = true;
1043
- }
1044
- if (await tryRemove(binPs1, "PowerShell script")) {
1045
- manuallyRemoved = true;
1046
- }
1047
- if (await tryRemove(binExe, "bin executable")) {
1048
- manuallyRemoved = true;
1049
- }
1050
- } else {
1051
- const binSymlink = join(globalPrefix, "bin", "claude");
1052
- if (await tryRemove(binSymlink, "bin symlink")) {
1053
- manuallyRemoved = true;
1054
- }
1055
- }
1056
- if (manuallyRemoved) {
1057
- logForDebugging(`Successfully removed ${packageName} manually`);
1058
- const nodeModulesPath = getPlatform().startsWith("win32") ? join(globalPrefix, "node_modules", packageName) : join(globalPrefix, "lib", "node_modules", packageName);
1059
- return {
1060
- success: true,
1061
- warning: `${packageName} executables removed, but node_modules directory was left intact for safety. You may manually delete it later at: ${nodeModulesPath}`
1062
- };
1063
- } else {
1064
- return { success: false };
1065
- }
1066
- } catch (manualError) {
1067
- logForDebugging(`Manual removal failed: ${manualError}`, {
1068
- level: "error"
1069
- });
1070
- return {
1071
- success: false,
1072
- error: `Manual removal failed: ${manualError}`
1073
- };
1074
- }
1075
- }
1076
- async function attemptNpmUninstall(packageName) {
1077
- const { code, stderr } = await execFileNoThrowWithCwd("npm", ["uninstall", "-g", packageName], { cwd: process.cwd() });
1078
- if (code === 0) {
1079
- logForDebugging(`Removed global npm installation of ${packageName}`);
1080
- return { success: true };
1081
- } else if (stderr && !stderr.includes("npm ERR! code E404")) {
1082
- if (stderr.includes("npm error code ENOTEMPTY")) {
1083
- logForDebugging(`Failed to uninstall global npm package ${packageName}: ${stderr}`, { level: "error" });
1084
- logForDebugging(`Attempting manual removal due to ENOTEMPTY error`);
1085
- const manualResult = await manualRemoveNpmPackage(packageName);
1086
- if (manualResult.success) {
1087
- return { success: true, warning: manualResult.warning };
1088
- } else if (manualResult.error) {
1089
- return {
1090
- success: false,
1091
- error: `Failed to remove global npm installation of ${packageName}: ${stderr}. Manual removal also failed: ${manualResult.error}`
1092
- };
1093
- }
1094
- }
1095
- logForDebugging(`Failed to uninstall global npm package ${packageName}: ${stderr}`, { level: "error" });
1096
- return {
1097
- success: false,
1098
- error: `Failed to remove global npm installation of ${packageName}: ${stderr}`
1099
- };
1100
- }
1101
- return { success: false };
1102
- }
1103
- async function cleanupNpmInstallations() {
1104
- const errors = [];
1105
- const warnings = [];
1106
- let removed = 0;
1107
- const codePackageResult = await attemptNpmUninstall("@anthropic-ai/claude-code");
1108
- if (codePackageResult.success) {
1109
- removed++;
1110
- if (codePackageResult.warning) {
1111
- warnings.push(codePackageResult.warning);
1112
- }
1113
- } else if (codePackageResult.error) {
1114
- errors.push(codePackageResult.error);
1115
- }
1116
- if ("") {}
1117
- const localInstallDir = join(homedir(), ".claude", "local");
1118
- try {
1119
- await rm(localInstallDir, { recursive: true });
1120
- removed++;
1121
- logForDebugging(`Removed local installation at ${localInstallDir}`);
1122
- } catch (error) {
1123
- if (!isENOENT(error)) {
1124
- errors.push(`Failed to remove ${localInstallDir}: ${error}`);
1125
- logForDebugging(`Failed to remove local installation: ${error}`, {
1126
- level: "error"
1127
- });
1128
- }
1129
- }
1130
- return { removed, errors, warnings };
1131
- }
1132
- var getMaxVersion = async () => null, shouldSkipVersion = (_version) => false, VERSION_RETENTION_COUNT = 2, LOCK_STALE_MS, inFlightInstall = null;
1133
- var init_installer = __esm(() => {
1134
- init_analytics();
1135
- init_cleanupRegistry();
1136
- init_config();
1137
- init_debug();
1138
- init_doctorDiagnostic();
1139
- init_env();
1140
- init_envDynamic();
1141
- init_envUtils();
1142
- init_errors();
1143
- init_execFileNoThrow();
1144
- init_localInstaller();
1145
- init_lockfile();
1146
- init_log();
1147
- init_semver();
1148
- init_shellConfig();
1149
- init_sleep();
1150
- init_xdg();
1151
- init_download();
1152
- init_pidLock();
1153
- LOCK_STALE_MS = 7 * 24 * 60 * 60 * 1000;
1154
- });
1155
-
1156
- // src/utils/nativeInstaller/index.ts
1157
- var init_nativeInstaller = __esm(() => {
1158
- init_installer();
1159
- });
1160
-
1161
- export { checkInstall, installLatest, lockCurrentVersion, cleanupOldVersions, cleanupShellAliases, cleanupNpmInstallations, init_nativeInstaller };