tenjin-cli 0.1.0-alpha.30 → 0.1.0-alpha.32

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 (280) hide show
  1. package/README.md +65 -116
  2. package/dist/{_esm-CE7KNONL.js → _esm-RLLC72MS.js} +127 -131
  3. package/dist/alive-MROUMFH3.js +38 -0
  4. package/dist/auto-update-OPWMRZLS.js +22 -0
  5. package/dist/{ccip-7RMRLAGV.js → ccip-DHDFKTQV.js} +2 -2
  6. package/dist/chunk-2GNOFONN.js +560 -0
  7. package/dist/chunk-2GNOFONN.js.map +1 -0
  8. package/dist/{chunk-TTNESUPQ.js → chunk-2GP3HRYK.js} +2120 -193
  9. package/dist/chunk-2GP3HRYK.js.map +1 -0
  10. package/dist/chunk-3623BLPV.js +184 -0
  11. package/dist/chunk-3623BLPV.js.map +1 -0
  12. package/dist/chunk-3AIHRXKO.js +72 -0
  13. package/dist/chunk-3AIHRXKO.js.map +1 -0
  14. package/dist/chunk-3DIL66VX.js +120 -0
  15. package/dist/chunk-3DIL66VX.js.map +1 -0
  16. package/dist/{chunk-S4SAZ7OD.js → chunk-3FMZGI7I.js} +12 -2
  17. package/dist/{chunk-S4SAZ7OD.js.map → chunk-3FMZGI7I.js.map} +1 -1
  18. package/dist/chunk-3UCIG4TG.js +65 -0
  19. package/dist/chunk-3UCIG4TG.js.map +1 -0
  20. package/dist/{chunk-LFZJM56J.js → chunk-445VQTVM.js} +3 -3
  21. package/dist/{chunk-A36LQPHV.js → chunk-4LMUQMBH.js} +1 -1
  22. package/dist/{chunk-A36LQPHV.js.map → chunk-4LMUQMBH.js.map} +1 -1
  23. package/dist/{chunk-RAULEAZ6.js → chunk-4USCZ2NI.js} +3 -3
  24. package/dist/chunk-62KNUYWD.js +111 -0
  25. package/dist/chunk-62KNUYWD.js.map +1 -0
  26. package/dist/{chunk-POUWHWID.js → chunk-6CMM6YCB.js} +3 -3
  27. package/dist/{chunk-POUWHWID.js.map → chunk-6CMM6YCB.js.map} +1 -1
  28. package/dist/chunk-7WEQQJLG.js +68 -0
  29. package/dist/chunk-7WEQQJLG.js.map +1 -0
  30. package/dist/{chunk-3O2BQIF6.js → chunk-AD226HDR.js} +344 -534
  31. package/dist/chunk-AD226HDR.js.map +1 -0
  32. package/dist/chunk-ADV4LDTB.js +106 -0
  33. package/dist/chunk-ADV4LDTB.js.map +1 -0
  34. package/dist/{chunk-AWFUPKTM.js → chunk-AV5NZMYO.js} +15 -7
  35. package/dist/{chunk-AWFUPKTM.js.map → chunk-AV5NZMYO.js.map} +1 -1
  36. package/dist/chunk-B7EM4GGF.js +198 -0
  37. package/dist/chunk-B7EM4GGF.js.map +1 -0
  38. package/dist/chunk-BFDQ4WNW.js +119 -0
  39. package/dist/chunk-BFDQ4WNW.js.map +1 -0
  40. package/dist/{chunk-OSYTBCUC.js → chunk-BI673VEJ.js} +531 -503
  41. package/dist/chunk-BI673VEJ.js.map +1 -0
  42. package/dist/chunk-CEXSOI5R.js +808 -0
  43. package/dist/chunk-CEXSOI5R.js.map +1 -0
  44. package/dist/{chunk-OK2TDZQU.js → chunk-CISYM4EO.js} +9 -7
  45. package/dist/chunk-CISYM4EO.js.map +1 -0
  46. package/dist/{chunk-VFMQTSXG.js → chunk-D3ZURCG7.js} +3 -3
  47. package/dist/chunk-D5TOQSO4.js +474 -0
  48. package/dist/chunk-D5TOQSO4.js.map +1 -0
  49. package/dist/{chunk-P7LABKCW.js → chunk-DOQGNFHM.js} +33 -2
  50. package/dist/{chunk-P7LABKCW.js.map → chunk-DOQGNFHM.js.map} +1 -1
  51. package/dist/{chunk-QUVVWYJW.js → chunk-DRDUIZIA.js} +11 -9
  52. package/dist/{chunk-QUVVWYJW.js.map → chunk-DRDUIZIA.js.map} +1 -1
  53. package/dist/{chunk-O2FRQ2L2.js → chunk-DW4YTVR3.js} +5 -65
  54. package/dist/chunk-DW4YTVR3.js.map +1 -0
  55. package/dist/chunk-E7LGOMH6.js +449 -0
  56. package/dist/chunk-E7LGOMH6.js.map +1 -0
  57. package/dist/chunk-E7SW44LM.js +138 -0
  58. package/dist/chunk-E7SW44LM.js.map +1 -0
  59. package/dist/chunk-EDJWHDDL.js +33 -0
  60. package/dist/chunk-EDJWHDDL.js.map +1 -0
  61. package/dist/chunk-F3ED5WTR.js +13 -0
  62. package/dist/chunk-F3ED5WTR.js.map +1 -0
  63. package/dist/chunk-G75OPGAK.js +111 -0
  64. package/dist/chunk-G75OPGAK.js.map +1 -0
  65. package/dist/{chunk-YFQOA5AU.js → chunk-GAKUQHKA.js} +13 -17
  66. package/dist/{chunk-YFQOA5AU.js.map → chunk-GAKUQHKA.js.map} +1 -1
  67. package/dist/{chunk-PAYV4XUA.js → chunk-HDPUXS3Z.js} +20 -49
  68. package/dist/chunk-HDPUXS3Z.js.map +1 -0
  69. package/dist/{chunk-ORWL5BSN.js → chunk-HGZEPQUT.js} +2 -2
  70. package/dist/{chunk-HPWO4O6S.js → chunk-HREHWL32.js} +4 -4
  71. package/dist/{chunk-HPWO4O6S.js.map → chunk-HREHWL32.js.map} +1 -1
  72. package/dist/{chunk-VZGAONSJ.js → chunk-I5TDIUKM.js} +16 -35
  73. package/dist/chunk-I5TDIUKM.js.map +1 -0
  74. package/dist/{chunk-7QKHZQKW.js → chunk-IADZOXKN.js} +39 -6
  75. package/dist/chunk-IADZOXKN.js.map +1 -0
  76. package/dist/{chunk-U6YQ6FRI.js → chunk-IDTRSAHE.js} +32 -12
  77. package/dist/chunk-IDTRSAHE.js.map +1 -0
  78. package/dist/{chunk-SPAVAYSW.js → chunk-JEVQ5LKO.js} +7 -5
  79. package/dist/{chunk-SPAVAYSW.js.map → chunk-JEVQ5LKO.js.map} +1 -1
  80. package/dist/{chunk-EBVIKMCH.js → chunk-JKKAIPTU.js} +2 -2
  81. package/dist/chunk-JNJWBTU2.js +3497 -0
  82. package/dist/chunk-JNJWBTU2.js.map +1 -0
  83. package/dist/{chunk-TTBKWWTV.js → chunk-JRZBBPO6.js} +390 -146
  84. package/dist/chunk-JRZBBPO6.js.map +1 -0
  85. package/dist/{chunk-WVUSXNIE.js → chunk-MPZUYCAP.js} +9 -2
  86. package/dist/{chunk-WVUSXNIE.js.map → chunk-MPZUYCAP.js.map} +1 -1
  87. package/dist/{chunk-SJLTEINJ.js → chunk-OJNTCYQQ.js} +17 -1
  88. package/dist/chunk-OJNTCYQQ.js.map +1 -0
  89. package/dist/{chunk-IOODYAXL.js → chunk-OTWLERSW.js} +25 -6
  90. package/dist/chunk-OTWLERSW.js.map +1 -0
  91. package/dist/{chunk-AWQPGIR6.js → chunk-PJNENX2A.js} +1535 -422
  92. package/dist/chunk-PJNENX2A.js.map +1 -0
  93. package/dist/{chunk-KHE6L6TD.js → chunk-PKHI276N.js} +97 -11
  94. package/dist/chunk-PKHI276N.js.map +1 -0
  95. package/dist/{chunk-YHKXNYTB.js → chunk-QF3LSMGS.js} +2 -2
  96. package/dist/chunk-QXP3Z3JN.js +131 -0
  97. package/dist/chunk-QXP3Z3JN.js.map +1 -0
  98. package/dist/{chunk-XZKD7DIF.js → chunk-RL5UUDT4.js} +3 -3
  99. package/dist/{chunk-XZKD7DIF.js.map → chunk-RL5UUDT4.js.map} +1 -1
  100. package/dist/chunk-SFASB5FL.js +69 -0
  101. package/dist/chunk-SFASB5FL.js.map +1 -0
  102. package/dist/{chunk-WO5BJNIB.js → chunk-SNNSAGMT.js} +7273 -2741
  103. package/dist/chunk-SNNSAGMT.js.map +1 -0
  104. package/dist/{chunk-NZIP4PA2.js → chunk-SO3XRZPX.js} +3 -3
  105. package/dist/chunk-SYOS5CAC.js +176 -0
  106. package/dist/chunk-SYOS5CAC.js.map +1 -0
  107. package/dist/chunk-TAW4UFFF.js +293 -0
  108. package/dist/chunk-TAW4UFFF.js.map +1 -0
  109. package/dist/chunk-TF5HCP33.js +271 -0
  110. package/dist/chunk-TF5HCP33.js.map +1 -0
  111. package/dist/{chunk-AKWGE6JQ.js → chunk-UUGOUOVT.js} +37 -2
  112. package/dist/chunk-UUGOUOVT.js.map +1 -0
  113. package/dist/{chunk-AEG2PXBP.js → chunk-V2LQLN5H.js} +7 -7
  114. package/dist/{chunk-KYFZTGMC.js → chunk-VJUVFZ2D.js} +5 -3
  115. package/dist/{chunk-KYFZTGMC.js.map → chunk-VJUVFZ2D.js.map} +1 -1
  116. package/dist/{chunk-JMM6YE7J.js → chunk-VOZA6O7K.js} +708 -709
  117. package/dist/chunk-VOZA6O7K.js.map +1 -0
  118. package/dist/{chunk-5LJCEMFD.js → chunk-VUGQTZ2L.js} +209 -77
  119. package/dist/chunk-VUGQTZ2L.js.map +1 -0
  120. package/dist/chunk-WOM257PW.js +393 -0
  121. package/dist/chunk-WOM257PW.js.map +1 -0
  122. package/dist/chunk-WYXUQGOL.js +191 -0
  123. package/dist/chunk-WYXUQGOL.js.map +1 -0
  124. package/dist/chunk-X5ZBP3IY.js +97 -0
  125. package/dist/chunk-X5ZBP3IY.js.map +1 -0
  126. package/dist/chunk-XQJXNMSB.js +23 -0
  127. package/dist/chunk-XQJXNMSB.js.map +1 -0
  128. package/dist/chunk-Y527D4TV.js +56 -0
  129. package/dist/chunk-Y527D4TV.js.map +1 -0
  130. package/dist/{chunk-VUFAK2LW.js → chunk-YUY4SAGM.js} +17 -2
  131. package/dist/chunk-YUY4SAGM.js.map +1 -0
  132. package/dist/clack-EZ7TDWQU.js +19 -0
  133. package/dist/claude-cli-2YKABJJZ.js +31 -0
  134. package/dist/{cli-O5SN7ZJ4.js → cli-FB4LOA5A.js} +221 -68
  135. package/dist/{cli-O5SN7ZJ4.js.map → cli-FB4LOA5A.js.map} +1 -1
  136. package/dist/codex-event-TYVES3UX.js +16 -0
  137. package/dist/codex-host-WW4H2SKT.js +29 -0
  138. package/dist/codex-install-2C623HPW.js +393 -0
  139. package/dist/codex-install-2C623HPW.js.map +1 -0
  140. package/dist/{config-OJQI27LT.js → config-HOVJFEKD.js} +25 -15
  141. package/dist/doctor-NKU4V5OV.js +1312 -0
  142. package/dist/doctor-NKU4V5OV.js.map +1 -0
  143. package/dist/{env-proxy-XL4P73MZ.js → env-proxy-R6ZMLQTT.js} +6 -2
  144. package/dist/{ethersCompat-Df4a6QIZ-THAVUGIJ.js → ethersCompat-Df4a6QIZ-X6YZWAML.js} +3 -3
  145. package/dist/{fund-WEV6DMTD.js → fund-WEBHTZGN.js} +38 -30
  146. package/dist/{fund-WEV6DMTD.js.map → fund-WEBHTZGN.js.map} +1 -1
  147. package/dist/hook-command-ZA2PNKS6.js +44 -0
  148. package/dist/hosts/claude/.claude-plugin/marketplace.json +2 -2
  149. package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +3 -2
  150. package/dist/hosts/claude/tenjin/hooks/hooks.json +4 -1
  151. package/dist/hosts/claude/tenjin/hooks/register.tsx +589 -0
  152. package/dist/hosts/claude/tenjin/skills/tenjin-pay/SKILL.md +82 -0
  153. package/dist/hosts/claude/tenjin/types/index.d.ts +41 -0
  154. package/dist/hosts/codex/.agents/plugins/marketplace.json +20 -0
  155. package/dist/hosts/codex/tenjin/.codex-plugin/plugin.json +16 -0
  156. package/dist/hosts/codex/tenjin/.mcp.json +15 -0
  157. package/dist/hosts/codex/tenjin/hooks/hooks.json +98 -0
  158. package/dist/hosts-AV5MHBAU.js +38 -0
  159. package/dist/index.js +28 -8
  160. package/dist/index.js.map +1 -1
  161. package/dist/install-PT4EZS4R.js +100 -0
  162. package/dist/{install-identity-WHPNMNMQ.js → install-identity-5A4OE6YC.js} +13 -8
  163. package/dist/install-wallet-SAAPKB73.js +281 -0
  164. package/dist/install-wallet-SAAPKB73.js.map +1 -0
  165. package/dist/{mcp-QML7ZMPH.js → mcp-HAWKCTPQ.js} +909 -208
  166. package/dist/mcp-HAWKCTPQ.js.map +1 -0
  167. package/dist/{mine.wasm-6PIT3DK6.js → mine.wasm-QFAHIFPY.js} +2 -2
  168. package/dist/{mine.wasm-6PIT3DK6.js.map → mine.wasm-QFAHIFPY.js.map} +1 -1
  169. package/dist/{package-LGKYOEPV.js → package-SR2WB6MK.js} +4 -2
  170. package/dist/passphrase-IFTDS3CU.js +44 -0
  171. package/dist/{paths-POPTXJO6.js → paths-XCSAKISU.js} +10 -2
  172. package/dist/pay-OXC3WKYV.js +55 -0
  173. package/dist/pay-OXC3WKYV.js.map +1 -0
  174. package/dist/{payments-C44QUFXU.js → payments-3KHMP2MG.js} +18 -13
  175. package/dist/{payments-C44QUFXU.js.map → payments-3KHMP2MG.js.map} +1 -1
  176. package/dist/plugin-registration-N3GRIZVM.js +67 -0
  177. package/dist/plugin-registration-N3GRIZVM.js.map +1 -0
  178. package/dist/{redact-6W23GGJC.js → redact-D7ASVWKL.js} +2 -2
  179. package/dist/redact-D7ASVWKL.js.map +1 -0
  180. package/dist/runtime-UVNUA3AS.js +1203 -0
  181. package/dist/runtime-UVNUA3AS.js.map +1 -0
  182. package/dist/runtime-fetch-EKFRNR6Z.js +20 -0
  183. package/dist/runtime-fetch-EKFRNR6Z.js.map +1 -0
  184. package/dist/runtime-layout-BDWZG2TQ.js +25 -0
  185. package/dist/runtime-layout-BDWZG2TQ.js.map +1 -0
  186. package/dist/{send-KVJX4XIR.js → send-HMKJLT34.js} +26 -18
  187. package/dist/{send-KVJX4XIR.js.map → send-HMKJLT34.js.map} +1 -1
  188. package/dist/{status-S7C3WMSH.js → status-RWXIIWYS.js} +57 -22
  189. package/dist/status-RWXIIWYS.js.map +1 -0
  190. package/dist/{status-line-YR2T5HC4.js → status-line-77XYZP7E.js} +13 -8
  191. package/dist/{status-line-YR2T5HC4.js.map → status-line-77XYZP7E.js.map} +1 -1
  192. package/dist/uninstall-D5G67UJH.js +480 -0
  193. package/dist/uninstall-D5G67UJH.js.map +1 -0
  194. package/dist/update-LRNOEGSB.js +53 -0
  195. package/dist/update-LRNOEGSB.js.map +1 -0
  196. package/dist/{usdc-JK4RRFFQ.js → usdc-D6X7EIQ2.js} +7 -8
  197. package/dist/usdc-D6X7EIQ2.js.map +1 -0
  198. package/dist/{viemAdapter-By13KInL-X2VY6CY3.js → viemAdapter-By13KInL-RL742ETX.js} +3 -3
  199. package/dist/viemAdapter-By13KInL-RL742ETX.js.map +1 -0
  200. package/dist/wallet-XFYC27BR.js +55 -0
  201. package/dist/wallet-XFYC27BR.js.map +1 -0
  202. package/dist/wallet-kdf-worker.mjs +8 -8
  203. package/docs/agent-permissions.md +56 -22
  204. package/docs/safety-model.md +1 -1
  205. package/docs/troubleshooting.md +72 -1
  206. package/package.json +14 -1
  207. package/dist/alive-3J3CHOQP.js +0 -21
  208. package/dist/ccip-NLCSCHKI.js +0 -19
  209. package/dist/chunk-3O2BQIF6.js.map +0 -1
  210. package/dist/chunk-5IEP5EGE.js +0 -5332
  211. package/dist/chunk-5IEP5EGE.js.map +0 -1
  212. package/dist/chunk-5LJCEMFD.js.map +0 -1
  213. package/dist/chunk-6W5GYG3W.js +0 -128
  214. package/dist/chunk-6W5GYG3W.js.map +0 -1
  215. package/dist/chunk-7EKYXMUO.js +0 -7536
  216. package/dist/chunk-7EKYXMUO.js.map +0 -1
  217. package/dist/chunk-7QKHZQKW.js.map +0 -1
  218. package/dist/chunk-AKWGE6JQ.js.map +0 -1
  219. package/dist/chunk-AWQPGIR6.js.map +0 -1
  220. package/dist/chunk-EGELTSPU.js +0 -2865
  221. package/dist/chunk-EGELTSPU.js.map +0 -1
  222. package/dist/chunk-EL56RW2J.js +0 -7611
  223. package/dist/chunk-EL56RW2J.js.map +0 -1
  224. package/dist/chunk-HE2MS4QO.js +0 -256
  225. package/dist/chunk-HE2MS4QO.js.map +0 -1
  226. package/dist/chunk-IOODYAXL.js.map +0 -1
  227. package/dist/chunk-JMM6YE7J.js.map +0 -1
  228. package/dist/chunk-KHE6L6TD.js.map +0 -1
  229. package/dist/chunk-N35E6CM2.js +0 -1185
  230. package/dist/chunk-N35E6CM2.js.map +0 -1
  231. package/dist/chunk-O2FRQ2L2.js.map +0 -1
  232. package/dist/chunk-OK2TDZQU.js.map +0 -1
  233. package/dist/chunk-OSYTBCUC.js.map +0 -1
  234. package/dist/chunk-PAYV4XUA.js.map +0 -1
  235. package/dist/chunk-SJLTEINJ.js.map +0 -1
  236. package/dist/chunk-TTBKWWTV.js.map +0 -1
  237. package/dist/chunk-TTNESUPQ.js.map +0 -1
  238. package/dist/chunk-U6YQ6FRI.js.map +0 -1
  239. package/dist/chunk-VUFAK2LW.js.map +0 -1
  240. package/dist/chunk-VZGAONSJ.js.map +0 -1
  241. package/dist/chunk-WO5BJNIB.js.map +0 -1
  242. package/dist/doctor-IQQJHGGM.js +0 -590
  243. package/dist/doctor-IQQJHGGM.js.map +0 -1
  244. package/dist/hook-command-D2P3ILRV.js +0 -32
  245. package/dist/install-TUCRF32I.js +0 -60
  246. package/dist/install-wallet-MA27FTQ5.js +0 -113
  247. package/dist/install-wallet-MA27FTQ5.js.map +0 -1
  248. package/dist/mcp-QML7ZMPH.js.map +0 -1
  249. package/dist/pay-2C2UBBXJ.js +0 -51
  250. package/dist/status-S7C3WMSH.js.map +0 -1
  251. package/dist/uninstall-HY6LKIIT.js +0 -149
  252. package/dist/uninstall-HY6LKIIT.js.map +0 -1
  253. package/dist/update-OJV22LR3.js +0 -36
  254. package/dist/wallet-PD2IMZDU.js +0 -39
  255. /package/dist/{_esm-CE7KNONL.js.map → _esm-RLLC72MS.js.map} +0 -0
  256. /package/dist/{alive-3J3CHOQP.js.map → alive-MROUMFH3.js.map} +0 -0
  257. /package/dist/{ccip-7RMRLAGV.js.map → auto-update-OPWMRZLS.js.map} +0 -0
  258. /package/dist/{ccip-NLCSCHKI.js.map → ccip-DHDFKTQV.js.map} +0 -0
  259. /package/dist/{chunk-LFZJM56J.js.map → chunk-445VQTVM.js.map} +0 -0
  260. /package/dist/{chunk-RAULEAZ6.js.map → chunk-4USCZ2NI.js.map} +0 -0
  261. /package/dist/{chunk-VFMQTSXG.js.map → chunk-D3ZURCG7.js.map} +0 -0
  262. /package/dist/{chunk-ORWL5BSN.js.map → chunk-HGZEPQUT.js.map} +0 -0
  263. /package/dist/{chunk-EBVIKMCH.js.map → chunk-JKKAIPTU.js.map} +0 -0
  264. /package/dist/{chunk-YHKXNYTB.js.map → chunk-QF3LSMGS.js.map} +0 -0
  265. /package/dist/{chunk-NZIP4PA2.js.map → chunk-SO3XRZPX.js.map} +0 -0
  266. /package/dist/{chunk-AEG2PXBP.js.map → chunk-V2LQLN5H.js.map} +0 -0
  267. /package/dist/{config-OJQI27LT.js.map → clack-EZ7TDWQU.js.map} +0 -0
  268. /package/dist/{env-proxy-XL4P73MZ.js.map → claude-cli-2YKABJJZ.js.map} +0 -0
  269. /package/dist/{ethersCompat-Df4a6QIZ-THAVUGIJ.js.map → codex-event-TYVES3UX.js.map} +0 -0
  270. /package/dist/{hook-command-D2P3ILRV.js.map → codex-host-WW4H2SKT.js.map} +0 -0
  271. /package/dist/{install-TUCRF32I.js.map → config-HOVJFEKD.js.map} +0 -0
  272. /package/dist/{install-identity-WHPNMNMQ.js.map → env-proxy-R6ZMLQTT.js.map} +0 -0
  273. /package/dist/{package-LGKYOEPV.js.map → ethersCompat-Df4a6QIZ-X6YZWAML.js.map} +0 -0
  274. /package/dist/{paths-POPTXJO6.js.map → hook-command-ZA2PNKS6.js.map} +0 -0
  275. /package/dist/{pay-2C2UBBXJ.js.map → hosts-AV5MHBAU.js.map} +0 -0
  276. /package/dist/{redact-6W23GGJC.js.map → install-PT4EZS4R.js.map} +0 -0
  277. /package/dist/{update-OJV22LR3.js.map → install-identity-5A4OE6YC.js.map} +0 -0
  278. /package/dist/{usdc-JK4RRFFQ.js.map → package-SR2WB6MK.js.map} +0 -0
  279. /package/dist/{viemAdapter-By13KInL-X2VY6CY3.js.map → passphrase-IFTDS3CU.js.map} +0 -0
  280. /package/dist/{wallet-PD2IMZDU.js.map → paths-XCSAKISU.js.map} +0 -0
@@ -0,0 +1,1203 @@
1
+ import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
+ import {
3
+ download,
4
+ extract,
5
+ nodeArtifact,
6
+ nodeKey,
7
+ runningGlibc,
8
+ unpinnedPlatform
9
+ } from "./chunk-SYOS5CAC.js";
10
+ import {
11
+ isSourceCheckout,
12
+ readModSources
13
+ } from "./chunk-TAW4UFFF.js";
14
+ import {
15
+ LAUNCHER_MARKER,
16
+ PLUGIN_DIR,
17
+ renderCodexHostFiles,
18
+ renderHostFiles,
19
+ renderLauncherCmd,
20
+ renderLauncherSh,
21
+ renderPluginHooks,
22
+ renderPluginMcp
23
+ } from "./chunk-E7LGOMH6.js";
24
+ import {
25
+ LockTimeoutError
26
+ } from "./chunk-MEFB5KHA.js";
27
+ import "./chunk-UUGOUOVT.js";
28
+ import "./chunk-MPZUYCAP.js";
29
+ import {
30
+ proxyNodeStep,
31
+ proxySkipped
32
+ } from "./chunk-3FMZGI7I.js";
33
+ import {
34
+ hasCode
35
+ } from "./chunk-2I4QTOLB.js";
36
+ import "./chunk-XQJXNMSB.js";
37
+ import {
38
+ writeFileAtomic
39
+ } from "./chunk-7WEQQJLG.js";
40
+ import {
41
+ CliError
42
+ } from "./chunk-3UCIG4TG.js";
43
+ import {
44
+ nodeBinPath,
45
+ readRuntimeState,
46
+ runtimeBuild,
47
+ runtimeStatePath,
48
+ versionDir,
49
+ versionEntry
50
+ } from "./chunk-G75OPGAK.js";
51
+ import {
52
+ isNewer,
53
+ parseVersion
54
+ } from "./chunk-EDJWHDDL.js";
55
+ import {
56
+ defaultDataDir,
57
+ launcherDir,
58
+ runtimeDir
59
+ } from "./chunk-OJNTCYQQ.js";
60
+ import "./chunk-ZXTAQYNA.js";
61
+
62
+ // src/lib/runtime.ts
63
+ import { spawn } from "node:child_process";
64
+ import { randomBytes } from "node:crypto";
65
+ import {
66
+ existsSync,
67
+ mkdirSync,
68
+ readFileSync,
69
+ renameSync,
70
+ rmSync,
71
+ statSync,
72
+ writeFileSync
73
+ } from "node:fs";
74
+ import {
75
+ chmod,
76
+ cp,
77
+ lstat,
78
+ mkdir,
79
+ mkdtemp,
80
+ readdir,
81
+ readFile,
82
+ realpath,
83
+ rename,
84
+ rm,
85
+ stat,
86
+ utimes,
87
+ writeFile
88
+ } from "node:fs/promises";
89
+ import { tmpdir } from "node:os";
90
+ import { basename, dirname, join, posix, relative, resolve, sep, win32 } from "node:path";
91
+
92
+ // src/router/hook-form.ts
93
+ function isPlainObject(value) {
94
+ return typeof value === "object" && value !== null && !Array.isArray(value);
95
+ }
96
+ function handlersIn(file) {
97
+ const events = isPlainObject(file) ? file.hooks : void 0;
98
+ if (!isPlainObject(events)) return [];
99
+ return Object.values(events).flatMap(
100
+ (groups) => Array.isArray(groups) ? groups.flatMap((g) => isPlainObject(g) && Array.isArray(g.hooks) ? g.hooks : []) : []
101
+ );
102
+ }
103
+
104
+ // src/lib/runtime.ts
105
+ var NODE_VERSION_RE = /^\d+\.\d+\.\d+$/;
106
+ var SHA256_RE = /^[0-9a-f]{64}$/;
107
+ function readNodePin(packageRoot) {
108
+ try {
109
+ const pkg = JSON.parse(readFileSync(join(packageRoot, "package.json"), "utf8"));
110
+ const node = pkg.tenjinRuntime?.node;
111
+ if (typeof node?.version !== "string" || !NODE_VERSION_RE.test(node.version)) return null;
112
+ if (typeof node.sha256 !== "object" || node.sha256 === null) return null;
113
+ const sha256 = {};
114
+ for (const [key, value] of Object.entries(node.sha256)) {
115
+ if (typeof value === "string" && SHA256_RE.test(value)) sha256[key] = value;
116
+ }
117
+ return { version: node.version, sha256 };
118
+ } catch {
119
+ return null;
120
+ }
121
+ }
122
+ function packageRootOf(moduleDir) {
123
+ let dir = moduleDir;
124
+ for (let i = 0; i < 8; i += 1) {
125
+ try {
126
+ const pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
127
+ if (pkg.name === "tenjin-cli") return dir;
128
+ } catch {
129
+ }
130
+ const parent = dirname(dir);
131
+ if (parent === dir) break;
132
+ dir = parent;
133
+ }
134
+ return null;
135
+ }
136
+ var LOCK_STALE_MS = 10 * 6e4;
137
+ var OWNERLESS_STALE_MS = 1e4;
138
+ var TAKEOVER_STALE_MS = 6e4;
139
+ var LOCK_POLL_MS = 50;
140
+ var held = /* @__PURE__ */ new Map();
141
+ var exitHookInstalled = false;
142
+ function releaseHeld() {
143
+ for (const [path, ino] of held) releaseIfOurs(path, ino);
144
+ held.clear();
145
+ }
146
+ function releaseIfOurs(path, ino) {
147
+ try {
148
+ if (statSync(path).ino === ino) rmSync(path, { recursive: true, force: true });
149
+ } catch {
150
+ }
151
+ }
152
+ function pidAlive(pid) {
153
+ try {
154
+ process.kill(pid, 0);
155
+ return true;
156
+ } catch (err) {
157
+ return hasCode(err, "EPERM");
158
+ }
159
+ }
160
+ function staleLock(lock, isAlive, now) {
161
+ let info;
162
+ try {
163
+ info = statSync(lock);
164
+ } catch {
165
+ return null;
166
+ }
167
+ let text;
168
+ try {
169
+ text = readFileSync(join(lock, "owner.json"), "utf8");
170
+ } catch {
171
+ return now - info.mtimeMs > OWNERLESS_STALE_MS ? `${info.ino}:` : null;
172
+ }
173
+ let owner;
174
+ try {
175
+ owner = JSON.parse(text);
176
+ } catch {
177
+ return now - info.mtimeMs > OWNERLESS_STALE_MS ? `${info.ino}:${text}` : null;
178
+ }
179
+ const started = typeof owner.startedAt === "string" ? Date.parse(owner.startedAt) : NaN;
180
+ const dead = typeof owner.pid === "number" && !isAlive(owner.pid);
181
+ const old = Number.isNaN(started) || now - started > LOCK_STALE_MS;
182
+ return dead || old ? `${info.ino}:${text}` : null;
183
+ }
184
+ function takeOver(root, lock, judged, o) {
185
+ const gate = join(root, ".lock-takeover");
186
+ try {
187
+ mkdirSync(gate);
188
+ } catch (err) {
189
+ if (!hasCode(err, "EEXIST")) return false;
190
+ try {
191
+ if (o.now() - statSync(gate).mtimeMs > TAKEOVER_STALE_MS) {
192
+ rmSync(gate, { recursive: true, force: true });
193
+ }
194
+ } catch {
195
+ }
196
+ return false;
197
+ }
198
+ try {
199
+ if (staleLock(lock, o.isAlive, o.now()) !== judged) return false;
200
+ mkdirSync(join(root, "tmp"), { recursive: true });
201
+ renameSync(lock, join(root, "tmp", `trash-lock-${randomBytes(6).toString("hex")}`));
202
+ return true;
203
+ } catch {
204
+ return false;
205
+ } finally {
206
+ rmSync(gate, { recursive: true, force: true });
207
+ }
208
+ }
209
+ async function withRuntimeLock(root, fn, o = {}) {
210
+ const opts = {
211
+ lockWaitMs: o.lockWaitMs ?? 3e5,
212
+ isAlive: o.isAlive ?? pidAlive,
213
+ now: o.now ?? Date.now
214
+ };
215
+ const lock = join(root, ".lock");
216
+ const deadline = opts.now() + opts.lockWaitMs;
217
+ mkdirSync(root, { recursive: true });
218
+ let ino;
219
+ for (; ; ) {
220
+ try {
221
+ mkdirSync(lock);
222
+ ino = statSync(lock).ino;
223
+ held.set(lock, ino);
224
+ break;
225
+ } catch (err) {
226
+ if (!hasCode(err, "EEXIST")) throw err;
227
+ const judged = staleLock(lock, opts.isAlive, opts.now());
228
+ if (judged !== null && takeOver(root, lock, judged, opts)) continue;
229
+ if (opts.now() >= deadline) throw new LockTimeoutError(lock, opts.lockWaitMs);
230
+ await new Promise((done) => setTimeout(done, LOCK_POLL_MS));
231
+ }
232
+ }
233
+ if (!exitHookInstalled) {
234
+ exitHookInstalled = true;
235
+ process.once("exit", releaseHeld);
236
+ }
237
+ try {
238
+ writeFileSync(
239
+ join(lock, "owner.json"),
240
+ JSON.stringify({ pid: process.pid, startedAt: new Date(opts.now()).toISOString() })
241
+ );
242
+ return await fn();
243
+ } finally {
244
+ held.delete(lock);
245
+ releaseIfOurs(lock, ino);
246
+ }
247
+ }
248
+ var NODE_MAX_BYTES = 100 * 1024 * 1024;
249
+ var TARBALL_MAX_BYTES = 50 * 1024 * 1024;
250
+ var NODE_FIX = "Check access to nodejs.org and run `tenjin install` again.";
251
+ var rand = () => randomBytes(6).toString("hex");
252
+ var tmpOf = (root) => join(root, "tmp");
253
+ function completeValid(dir) {
254
+ try {
255
+ const marker = JSON.parse(readFileSync(join(dir, ".complete"), "utf8"));
256
+ return marker.version === basename(dir);
257
+ } catch {
258
+ return false;
259
+ }
260
+ }
261
+ async function markComplete(dir, version) {
262
+ await writeFile(join(dir, ".complete"), `${JSON.stringify({ version })}
263
+ `);
264
+ }
265
+ async function touchComplete(dir) {
266
+ const now = /* @__PURE__ */ new Date();
267
+ await utimes(join(dir, ".complete"), now, now).catch(() => void 0);
268
+ }
269
+ var RENAME_RETRY_MS = 2e3;
270
+ async function renameDir(from, to, platform = process.platform) {
271
+ const deadline = Date.now() + RENAME_RETRY_MS;
272
+ for (let wait = 20; ; wait = Math.min(wait * 2, 400)) {
273
+ try {
274
+ await rename(from, to);
275
+ return;
276
+ } catch (err) {
277
+ const transient = platform === "win32" && ["EPERM", "EACCES", "EBUSY"].some((c) => hasCode(err, c));
278
+ if (!transient || Date.now() + wait > deadline) throw err;
279
+ await new Promise((done) => setTimeout(done, wait));
280
+ }
281
+ }
282
+ }
283
+ async function trash(root, path, platform) {
284
+ if (!existsSync(path)) return;
285
+ await mkdir(tmpOf(root), { recursive: true });
286
+ const to = join(tmpOf(root), `trash-${rand()}`);
287
+ await renameDir(path, to, platform);
288
+ await rm(to, { recursive: true, force: true }).catch(() => void 0);
289
+ }
290
+ function nodeVersionOf(bin) {
291
+ return new Promise((done) => {
292
+ const child = spawn(bin, ["-p", "process.version"], {
293
+ shell: false,
294
+ stdio: ["ignore", "pipe", "ignore"],
295
+ windowsHide: true,
296
+ timeout: 15e3
297
+ });
298
+ let out = "";
299
+ child.stdout.setEncoding("utf8");
300
+ child.stdout.on("data", (chunk) => out += chunk);
301
+ child.on("error", () => done(null));
302
+ child.on("close", (code) => done(code === 0 ? out.trim() : null));
303
+ });
304
+ }
305
+ async function ensureNode(root, pin, o) {
306
+ const platform = o.platform ?? process.platform;
307
+ const arch = o.arch ?? process.arch;
308
+ const glibc = o.glibc !== void 0 ? o.glibc : platform === "linux" ? runningGlibc() : null;
309
+ const key = nodeKey(platform, arch, glibc);
310
+ const expected = key === null ? void 0 : pin.sha256[key];
311
+ if (key === null || expected === void 0) {
312
+ throw new CliError("UPDATE_FAILED", `no pinned Node for ${key ?? `${platform}-${arch}`}`);
313
+ }
314
+ return withRuntimeLock(
315
+ root,
316
+ async () => {
317
+ const dir = join(root, "node", pin.version);
318
+ const bin = nodeBinPath(root, pin.version, platform);
319
+ if (completeValid(dir) && existsSync(bin)) {
320
+ await touchComplete(dir);
321
+ return bin;
322
+ }
323
+ if (existsSync(bin) && await nodeVersionOf(bin) === `v${pin.version}`) {
324
+ await markComplete(dir, pin.version);
325
+ return bin;
326
+ }
327
+ const made = [];
328
+ try {
329
+ await mkdir(tmpOf(root), { recursive: true });
330
+ const artifact = nodeArtifact(pin.version, key);
331
+ let got;
332
+ try {
333
+ got = await download(artifact.url, {
334
+ dir: tmpOf(root),
335
+ maxBytes: NODE_MAX_BYTES,
336
+ timeoutMs: o.timeoutMs,
337
+ hash: "sha256",
338
+ fetchImpl: o.fetchImpl
339
+ });
340
+ } catch (err) {
341
+ if (err instanceof CliError && err.code === "NETWORK_ERROR") {
342
+ throw new CliError("NETWORK_ERROR", err.message, { fix: NODE_FIX, cause: err });
343
+ }
344
+ throw err;
345
+ }
346
+ made.push(got.file);
347
+ if (got.digest.toString("hex") !== expected) {
348
+ throw new CliError(
349
+ "UPDATE_FAILED",
350
+ `the Node ${pin.version} download did not match its pinned checksum`
351
+ );
352
+ }
353
+ const stage = join(tmpOf(root), `node-${rand()}`);
354
+ made.push(stage);
355
+ await mkdir(stage);
356
+ await extract(got.file, stage, { member: artifact.member, strip: 1, platform });
357
+ const staged = join(stage, relative(dir, bin));
358
+ if (platform !== "win32") await chmod(staged, 493);
359
+ const said2 = await nodeVersionOf(staged);
360
+ if (said2 !== `v${pin.version}`) {
361
+ throw new CliError(
362
+ "UPDATE_FAILED",
363
+ `the downloaded Node ${pin.version} did not run (it printed ${said2 ?? "nothing"})`
364
+ );
365
+ }
366
+ await markComplete(stage, pin.version);
367
+ await trash(root, dir, platform);
368
+ await mkdir(dirname(dir), { recursive: true });
369
+ await renameDir(stage, dir, platform);
370
+ return bin;
371
+ } finally {
372
+ for (const path of made)
373
+ await rm(path, { recursive: true, force: true }).catch(() => void 0);
374
+ }
375
+ },
376
+ o
377
+ );
378
+ }
379
+ var NOT_COPIED = /* @__PURE__ */ new Set(["src", ".git", "runtime"]);
380
+ function copied(packageRoot, src) {
381
+ const rel = relative(packageRoot, src);
382
+ if (rel === "") return true;
383
+ const parts = rel.split(sep);
384
+ if (parts.includes("node_modules")) return false;
385
+ return !NOT_COPIED.has(parts[0]);
386
+ }
387
+ async function tally(dir, keep) {
388
+ let files = 0;
389
+ let bytes = 0;
390
+ const walk = async (current) => {
391
+ for (const entry of await readdir(current, { withFileTypes: true })) {
392
+ const path = join(current, entry.name);
393
+ if (!keep(path)) continue;
394
+ if (entry.isDirectory()) await walk(path);
395
+ else {
396
+ files += 1;
397
+ bytes += (await stat(path)).size;
398
+ }
399
+ }
400
+ };
401
+ await walk(dir);
402
+ return { files, bytes };
403
+ }
404
+ async function packageVersion(dir) {
405
+ return JSON.parse(await readFile(join(dir, "package.json"), "utf8"));
406
+ }
407
+ async function stageSelf(root, packageRoot) {
408
+ const { version } = await packageVersion(packageRoot);
409
+ if (typeof version !== "string" || parseVersion(version) === null) {
410
+ throw new CliError("UPDATE_FAILED", `${packageRoot} names no tenjin-cli version`);
411
+ }
412
+ const stage = join(tmpOf(root), `stage-${version}-${rand()}`);
413
+ try {
414
+ await mkdir(tmpOf(root), { recursive: true });
415
+ await cp(packageRoot, stage, { recursive: true, filter: (src) => copied(packageRoot, src) });
416
+ const want = await tally(packageRoot, (p) => copied(packageRoot, p));
417
+ const got = await tally(stage, () => true);
418
+ if (want.files !== got.files || want.bytes !== got.bytes) {
419
+ throw new CliError(
420
+ "UPDATE_FAILED",
421
+ `the copy of tenjin-cli ${version} is incomplete (${got.files} of ${want.files} files)`
422
+ );
423
+ }
424
+ if ((await packageVersion(stage)).version !== version) {
425
+ throw new CliError(
426
+ "UPDATE_FAILED",
427
+ `the copy of tenjin-cli ${version} names another version`
428
+ );
429
+ }
430
+ return stage;
431
+ } catch (err) {
432
+ await rm(stage, { recursive: true, force: true }).catch(() => void 0);
433
+ throw err;
434
+ }
435
+ }
436
+ var REGISTRY = "https://registry.npmjs.org/tenjin-cli";
437
+ async function stageTarball(root, version, o) {
438
+ const fetchImpl = o.fetchImpl ?? fetch;
439
+ let meta;
440
+ try {
441
+ const res = await fetchImpl(`${REGISTRY}/${version}`, {
442
+ signal: AbortSignal.timeout(o.timeoutMs),
443
+ headers: { accept: "application/json" }
444
+ });
445
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
446
+ meta = await res.json();
447
+ } catch (err) {
448
+ throw new CliError(
449
+ "NETWORK_ERROR",
450
+ `could not read tenjin-cli ${version} from the npm registry: ${err instanceof Error ? err.message : String(err)}`,
451
+ { fix: "Check access to registry.npmjs.org and run `tenjin update` again.", cause: err }
452
+ );
453
+ }
454
+ const tarball = meta.dist?.tarball;
455
+ const integrity = typeof meta.dist?.integrity === "string" ? meta.dist.integrity.split(/\s+/).find((h) => h.startsWith("sha512-")) : void 0;
456
+ if (typeof tarball !== "string" || !tarball.startsWith(`${REGISTRY}/-/`)) {
457
+ throw new CliError(
458
+ "UPDATE_FAILED",
459
+ `tenjin-cli ${version} names a tarball outside the npm registry`
460
+ );
461
+ }
462
+ if (integrity === void 0) {
463
+ throw new CliError("UPDATE_FAILED", `tenjin-cli ${version} carries no sha512 integrity`);
464
+ }
465
+ await mkdir(tmpOf(root), { recursive: true });
466
+ const got = await download(tarball, {
467
+ dir: tmpOf(root),
468
+ maxBytes: TARBALL_MAX_BYTES,
469
+ timeoutMs: o.timeoutMs,
470
+ hash: "sha512",
471
+ fetchImpl
472
+ });
473
+ const stage = join(tmpOf(root), `stage-${version}-${rand()}`);
474
+ try {
475
+ if (got.digest.toString("base64") !== integrity.slice("sha512-".length)) {
476
+ throw new CliError(
477
+ "UPDATE_FAILED",
478
+ `the tenjin-cli ${version} tarball did not match its integrity`
479
+ );
480
+ }
481
+ await mkdir(stage);
482
+ await extract(got.file, stage, { strip: 1 });
483
+ const pkg = await packageVersion(stage);
484
+ if (pkg.name !== "tenjin-cli" || pkg.version !== version) {
485
+ throw new CliError(
486
+ "UPDATE_FAILED",
487
+ `the tarball for tenjin-cli ${version} holds another package`
488
+ );
489
+ }
490
+ return stage;
491
+ } catch (err) {
492
+ await rm(stage, { recursive: true, force: true }).catch(() => void 0);
493
+ throw err;
494
+ } finally {
495
+ await rm(got.file, { force: true }).catch(() => void 0);
496
+ }
497
+ }
498
+ async function placeVersion(root, stageDir, version, o = {}) {
499
+ return withRuntimeLock(
500
+ root,
501
+ async () => {
502
+ const dir = versionDir(root, version);
503
+ if (completeValid(dir)) {
504
+ await touchComplete(dir);
505
+ await rm(stageDir, { recursive: true, force: true });
506
+ return dir;
507
+ }
508
+ await markComplete(stageDir, version);
509
+ await trash(root, dir, o.platform);
510
+ await mkdir(dirname(dir), { recursive: true });
511
+ await renameDir(stageDir, dir, o.platform);
512
+ return dir;
513
+ },
514
+ o
515
+ );
516
+ }
517
+ var spawnVerify = (command, args, o) => new Promise((done) => {
518
+ const child = spawn(command, args, {
519
+ env: o.env,
520
+ shell: false,
521
+ stdio: "pipe",
522
+ windowsHide: true
523
+ });
524
+ let stdout = "";
525
+ let stderr = "";
526
+ let settled = false;
527
+ const finish = (code, matched) => {
528
+ if (settled) return;
529
+ settled = true;
530
+ clearTimeout(timer);
531
+ if (child.exitCode === null) child.kill();
532
+ done({ code, stdout, stderr, matched });
533
+ };
534
+ const timer = setTimeout(() => finish(null, false), o.timeoutMs);
535
+ child.stdout.setEncoding("utf8");
536
+ child.stderr.setEncoding("utf8");
537
+ child.stdout.on("data", (chunk) => {
538
+ stdout += chunk;
539
+ if (o.until?.(stdout) === true) finish(0, true);
540
+ });
541
+ child.stderr.on("data", (chunk) => {
542
+ if (stderr.length < 4096) stderr += chunk;
543
+ });
544
+ child.stdin.on("error", () => void 0);
545
+ child.on("error", (err) => {
546
+ stderr += err.message;
547
+ finish(null, false);
548
+ });
549
+ child.on("close", (code) => finish(code, false));
550
+ child.stdin.write(o.input);
551
+ if (o.until === void 0) child.stdin.end();
552
+ });
553
+ var VERIFY_VERSION_MS = 1e4;
554
+ var VERIFY_HOOKS_MS = 1e4;
555
+ var VERIFY_MCP_MS = 15e3;
556
+ var said = (run) => {
557
+ const text = run.stderr.trim().slice(0, 200);
558
+ return `${run.code === null ? "no exit in time" : `exit ${run.code}`}${text ? `: ${text}` : ""}`;
559
+ };
560
+ async function verifyBuild(launch, version, o = {}) {
561
+ const run = o.spawnImpl ?? spawnVerify;
562
+ const deadline = Date.now() + (o.timeoutMs ?? VERIFY_VERSION_MS + VERIFY_HOOKS_MS + VERIFY_MCP_MS);
563
+ const budget = (own) => Math.min(own, deadline - Date.now());
564
+ const outOfTime = { ok: false, reason: `tenjin-cli ${version} was not checked in time` };
565
+ const data = await mkdtemp(join(tmpdir(), "tenjin-verify-"));
566
+ const env = {
567
+ ...process.env,
568
+ TENJIN_DATA_DIR: data,
569
+ TENJIN_NO_UPDATE_CHECK: "1",
570
+ TENJIN_HANDOFF: "1"
571
+ };
572
+ const bounded = (command, args, input, ms, until) => {
573
+ let timer;
574
+ return Promise.race([
575
+ run(command, args, { env, input, timeoutMs: ms, until }),
576
+ new Promise((done) => timer = setTimeout(() => done(null), ms + 250))
577
+ ]).finally(() => clearTimeout(timer));
578
+ };
579
+ try {
580
+ let ms = budget(VERIFY_VERSION_MS);
581
+ if (ms <= 0) return outOfTime;
582
+ const shown = await bounded(launch.node, [launch.entry, "--version"], "", ms);
583
+ if (shown === null) return outOfTime;
584
+ if (shown.code !== 0 || shown.stdout.trim() !== version) {
585
+ return {
586
+ ok: false,
587
+ reason: `tenjin-cli ${version} did not start (${shown.code === 0 ? `it printed ${shown.stdout.trim().slice(0, 50) || "nothing"}` : said(shown)})`
588
+ };
589
+ }
590
+ ms = budget(VERIFY_HOOKS_MS);
591
+ if (ms <= 0) return outOfTime;
592
+ const { hooks } = renderPluginHooks(launch.entry, { node: launch.node });
593
+ const commands = Object.entries(hooks).flatMap(
594
+ ([event, groups]) => handlersIn({ hooks: { [event]: groups } }).filter((h) => h.type === "command").map((h) => ({ event, command: h.command, args: h.args }))
595
+ );
596
+ const results = await Promise.all(
597
+ commands.map(async (c) => ({
598
+ ...c,
599
+ out: await bounded(
600
+ c.command,
601
+ c.args,
602
+ JSON.stringify({ session_id: "verify", hook_event_name: c.event }),
603
+ ms
604
+ )
605
+ }))
606
+ );
607
+ for (const { event, out } of results) {
608
+ if (out === null) return outOfTime;
609
+ if (out.code !== 0) return { ok: false, reason: `its ${event} hook failed (${said(out)})` };
610
+ if (out.stdout.trim().length > 0) {
611
+ try {
612
+ JSON.parse(out.stdout);
613
+ } catch {
614
+ return { ok: false, reason: `its ${event} hook printed something other than JSON` };
615
+ }
616
+ }
617
+ }
618
+ ms = budget(VERIFY_MCP_MS);
619
+ if (ms <= 0) return outOfTime;
620
+ const server = renderPluginMcp(launch.entry, { node: launch.node }).mcpServers.router;
621
+ const initialize = `${JSON.stringify({
622
+ jsonrpc: "2.0",
623
+ id: 1,
624
+ method: "initialize",
625
+ params: {
626
+ protocolVersion: "2025-06-18",
627
+ capabilities: {},
628
+ clientInfo: { name: "tenjin-verify", version }
629
+ }
630
+ })}
631
+ `;
632
+ const answered = await bounded(
633
+ server.command,
634
+ server.args,
635
+ initialize,
636
+ ms,
637
+ (stdout) => stdout.split("\n").some((line) => line.includes('"id":1') && line.includes('"result"'))
638
+ );
639
+ if (answered === null || !answered.matched) {
640
+ return {
641
+ ok: false,
642
+ reason: `its MCP server did not answer initialize (${answered === null ? "no answer in time" : said(answered)})`
643
+ };
644
+ }
645
+ return { ok: true };
646
+ } finally {
647
+ await rm(data, { recursive: true, force: true }).catch(() => void 0);
648
+ }
649
+ }
650
+ var launcherNames = (platform) => platform === "win32" ? ["tenjin", "tenjin.cmd"] : ["tenjin"];
651
+ function pathLine(env, _home, platform) {
652
+ if (platform === "win32") {
653
+ return `[Environment]::SetEnvironmentVariable('Path', "$env:USERPROFILE\\.local\\bin;" + [Environment]::GetEnvironmentVariable('Path','User'), 'User')`;
654
+ }
655
+ const add = `echo 'export PATH="$HOME/.local/bin:$PATH"' >>`;
656
+ const shell = basename(env.SHELL ?? "");
657
+ if (shell === "zsh") return `${add} ~/.zshrc`;
658
+ if (shell === "bash") return `${add} ${platform === "darwin" ? "~/.bash_profile" : "~/.bashrc"}`;
659
+ if (shell === "fish") return "fish_add_path ~/.local/bin";
660
+ return 'export PATH="$HOME/.local/bin:$PATH"';
661
+ }
662
+ function onPath(dir, env, platform) {
663
+ const p = platform === "win32" ? win32 : posix;
664
+ const raw = (platform === "win32" ? env.Path ?? env.PATH : env.PATH) ?? "";
665
+ const norm = (value) => {
666
+ const full = p.resolve(value).replace(/[\\/]+$/, "");
667
+ return platform === "win32" ? full.toLowerCase() : full;
668
+ };
669
+ const want = norm(dir);
670
+ return raw.split(p.delimiter).filter((entry) => entry.length > 0).some((entry) => norm(entry) === want);
671
+ }
672
+ async function npmsOwn(path, isLink, body) {
673
+ if (isLink) {
674
+ try {
675
+ return packageRootOf(dirname(await realpath(path))) !== null;
676
+ } catch {
677
+ return false;
678
+ }
679
+ }
680
+ return body !== null && /node_modules[\\/]tenjin-cli[\\/]/.test(body);
681
+ }
682
+ async function inspectLauncher(path) {
683
+ let link;
684
+ try {
685
+ link = await lstat(path);
686
+ } catch {
687
+ return { state: "absent", body: null };
688
+ }
689
+ const body = await readFile(path, "utf8").catch(() => null);
690
+ if (await npmsOwn(path, link.isSymbolicLink(), body)) return { state: "npm", body };
691
+ if (!link.isSymbolicLink() && body !== null && body.includes(LAUNCHER_MARKER)) {
692
+ return { state: "ours", body };
693
+ }
694
+ return { state: "foreign", body };
695
+ }
696
+ async function writeLaunchers(home, launch, o) {
697
+ const platform = o.platform ?? launch.platform ?? process.platform;
698
+ const dir = launcherDir(home);
699
+ const paths = launcherNames(platform).map((name) => join(dir, name));
700
+ const found = onPath(dir, o.env, platform);
701
+ const where = { onPath: found, ...found ? {} : { pathLine: pathLine(o.env, home, platform) } };
702
+ let bodies;
703
+ try {
704
+ const full = { ...launch, platform, home: launch.home ?? home };
705
+ bodies = [renderLauncherSh(full), ...platform === "win32" ? [renderLauncherCmd(full)] : []];
706
+ } catch (err) {
707
+ return {
708
+ paths,
709
+ state: "failed",
710
+ ...where,
711
+ reason: err instanceof Error ? err.message : String(err)
712
+ };
713
+ }
714
+ const existing = await Promise.all(paths.map(inspectLauncher));
715
+ const foreign = paths.filter((_, i) => existing[i].state === "foreign");
716
+ if (foreign.length > 0) {
717
+ return { paths, state: "foreign", ...where, reason: `${foreign.join(", ")} is not Tenjin's` };
718
+ }
719
+ if (existing.some((f) => f.state === "npm")) return { paths, state: "npm", ...where };
720
+ if (existing.every((f, i) => f.body === bodies[i])) return { paths, state: "current", ...where };
721
+ try {
722
+ for (const [i, path] of paths.entries()) {
723
+ if (existing[i].body !== bodies[i]) {
724
+ await writeFileAtomic(path, bodies[i], { mode: 493, dirMode: 493 });
725
+ }
726
+ }
727
+ } catch (err) {
728
+ return {
729
+ paths,
730
+ state: "failed",
731
+ ...where,
732
+ reason: err instanceof Error ? err.message : String(err)
733
+ };
734
+ }
735
+ return { paths, state: "written", ...where };
736
+ }
737
+ async function removeLaunchers(home, platform = process.platform) {
738
+ const removed = [];
739
+ const left = [];
740
+ for (const name of ["tenjin", "tenjin.cmd"]) {
741
+ const path = join(launcherDir(home), name);
742
+ const found = await inspectLauncher(path);
743
+ if (found.state === "absent") continue;
744
+ if (found.state !== "ours") {
745
+ if (name === "tenjin" || platform === "win32") left.push(path);
746
+ continue;
747
+ }
748
+ try {
749
+ await rm(path, { force: true });
750
+ removed.push(path);
751
+ } catch {
752
+ left.push(path);
753
+ }
754
+ }
755
+ return { removed, left };
756
+ }
757
+ function pointerOf(raw) {
758
+ if (typeof raw !== "object" || raw === null) return null;
759
+ const { cli, node } = raw;
760
+ if (typeof cli !== "string" || parseVersion(cli) === null) return null;
761
+ if (typeof node !== "string" || !NODE_VERSION_RE.test(node)) return null;
762
+ return { cli, node };
763
+ }
764
+ function readRawState(root) {
765
+ try {
766
+ const raw = JSON.parse(readFileSync(runtimeStatePath(root), "utf8"));
767
+ return {
768
+ current: pointerOf(raw.current),
769
+ previous: pointerOf(raw.previous),
770
+ pending: pointerOf(raw.pending),
771
+ ...typeof raw.activation === "string" ? { activation: raw.activation } : {}
772
+ };
773
+ } catch {
774
+ return { current: null, previous: null, pending: null };
775
+ }
776
+ }
777
+ async function writeState(root, state) {
778
+ await writeFileAtomic(
779
+ runtimeStatePath(root),
780
+ `${JSON.stringify({ schemaVersion: 1, ...state }, null, 2)}
781
+ `
782
+ );
783
+ }
784
+ var readOrNull = (path) => readFile(path, "utf8").catch(() => null);
785
+ async function putBack(path, body, mode) {
786
+ if (body === null) await rm(path, { force: true });
787
+ else await writeFileAtomic(path, body, { mode });
788
+ }
789
+ function renderOrder(files) {
790
+ const rank = (path) => {
791
+ const inHost = path.slice(path.indexOf("/") + 1);
792
+ if (inHost === "tenjin/hooks/hooks.json") return 1;
793
+ if (inHost.startsWith("tenjin/bin/")) return 2;
794
+ if (/^tenjin\/\.(claude|codex)-plugin\/plugin\.json$/.test(inHost)) return 3;
795
+ if ([".claude-plugin/marketplace.json", ".agents/plugins/marketplace.json"].includes(inHost)) {
796
+ return 4;
797
+ }
798
+ return 0;
799
+ };
800
+ return Object.keys(files).sort((a, b) => rank(a) - rank(b));
801
+ }
802
+ function runtimeMod(launch) {
803
+ return readModSources(join(dirname(launch.entry), "hosts", "claude", PLUGIN_DIR));
804
+ }
805
+ function runtimeHostFiles(root, version, launch, mod) {
806
+ const under = (host, files) => Object.entries(files).map(([path, body]) => [`${host}/${path}`, body]);
807
+ return Object.fromEntries([
808
+ ...under("claude", renderHostFiles(version, { launch, mod })),
809
+ ...under(
810
+ "codex",
811
+ renderCodexHostFiles({ launch, binDir: join(root, "codex", PLUGIN_DIR, "bin") })
812
+ )
813
+ ]);
814
+ }
815
+ var modeFor = (path) => path.includes("/tenjin/bin/") ? 493 : 420;
816
+ function runnable(root, p, platform) {
817
+ return existsSync(nodeBinPath(root, p.node, platform)) && existsSync(versionEntry(root, p.cli));
818
+ }
819
+ var NewerRuntime = class extends Error {
820
+ constructor(current) {
821
+ super(`Tenjin ${current.cli} is already set up here`);
822
+ this.current = current;
823
+ }
824
+ current;
825
+ };
826
+ async function activate(root, next, o) {
827
+ const platform = o.platform ?? process.platform;
828
+ const launch = {
829
+ node: nodeBinPath(root, next.node, platform),
830
+ entry: versionEntry(root, next.cli),
831
+ platform,
832
+ home: o.home
833
+ };
834
+ return withRuntimeLock(
835
+ root,
836
+ async () => {
837
+ const old = readRawState(root);
838
+ if (old.current !== null && isNewer(old.current.cli, next.cli) && runnable(root, old.current, platform)) {
839
+ throw new NewerRuntime(old.current);
840
+ }
841
+ if (!completeValid(versionDir(root, next.cli)) || !existsSync(launch.entry) || !completeValid(join(root, "node", next.node)) || !existsSync(launch.node)) {
842
+ throw new CliError(
843
+ "UPDATE_FAILED",
844
+ `tenjin-cli ${next.cli} or its Node ${next.node} is no longer in place in ${root}, so the runtime was not switched to it`
845
+ );
846
+ }
847
+ const oldStateText = await readOrNull(runtimeStatePath(root));
848
+ await writeState(root, { ...old, pending: next });
849
+ const files = runtimeHostFiles(root, next.cli, launch, await runtimeMod(launch));
850
+ const order = renderOrder(files);
851
+ const oldBodies = /* @__PURE__ */ new Map();
852
+ try {
853
+ for (const path of order) {
854
+ const target = join(root, path);
855
+ oldBodies.set(path, await readOrNull(target));
856
+ await writeFileAtomic(target, files[path], { mode: modeFor(path) });
857
+ }
858
+ } catch (err) {
859
+ for (const [path, body] of [...oldBodies].reverse()) {
860
+ await putBack(join(root, path), body, modeFor(path)).catch(() => void 0);
861
+ }
862
+ throw err;
863
+ }
864
+ const launcherPaths = launcherNames(platform).map((n) => join(launcherDir(o.home), n));
865
+ const oldLaunchers = await Promise.all(launcherPaths.map(inspectLauncher));
866
+ const launcher = await writeLaunchers(o.home, launch, { env: o.env, platform });
867
+ const previous = old.current !== null && old.current.cli !== next.cli ? old.current : old.previous;
868
+ const activation = rand();
869
+ await writeState(root, { current: next, previous, pending: null, activation });
870
+ const restore = () => withRuntimeLock(
871
+ root,
872
+ async () => {
873
+ if (readRawState(root).activation !== activation) return;
874
+ for (const path of [...order].reverse()) {
875
+ await putBack(join(root, path), oldBodies.get(path) ?? null, modeFor(path));
876
+ }
877
+ if (oldStateText === null) await rm(runtimeStatePath(root), { force: true });
878
+ else await writeFileAtomic(runtimeStatePath(root), oldStateText);
879
+ for (const [i, path] of launcherPaths.entries()) {
880
+ const before = oldLaunchers[i];
881
+ if (before.state === "ours") await putBack(path, before.body, 493);
882
+ else if (before.state === "absent" && (await inspectLauncher(path)).state === "ours") {
883
+ await rm(path, { force: true });
884
+ }
885
+ }
886
+ },
887
+ o
888
+ );
889
+ return { previous: old.current, launcher, restore };
890
+ },
891
+ o
892
+ );
893
+ }
894
+ var IN_USE = "in use; removed by a later install";
895
+ var PLACED = "placed for an activation still on its way";
896
+ var TMP_MAX_AGE_MS = 60 * 6e4;
897
+ var PLACED_GRACE_MS = 15 * 6e4;
898
+ var KEPT_FOR_FOLDER = "a plugin folder runs it";
899
+ async function collect(root, o = {}) {
900
+ const isAlive = o.isAlive ?? pidAlive;
901
+ const now = o.now ?? Date.now;
902
+ return withRuntimeLock(
903
+ root,
904
+ async () => {
905
+ const state = readRawState(root);
906
+ const removed = [];
907
+ const kept = [];
908
+ const keepNode = /* @__PURE__ */ new Set();
909
+ const roles = /* @__PURE__ */ new Map();
910
+ for (const role of ["current", "previous", "pending"]) {
911
+ const p = state[role];
912
+ if (p === null) continue;
913
+ if (!roles.has(p.cli)) roles.set(p.cli, role);
914
+ keepNode.add(p.node);
915
+ }
916
+ for (const p of o.keep ?? []) {
917
+ if (!roles.has(p.cli)) roles.set(p.cli, KEPT_FOR_FOLDER);
918
+ keepNode.add(p.node);
919
+ }
920
+ const remove = async (path) => {
921
+ const to = join(tmpOf(root), `trash-${rand()}`);
922
+ try {
923
+ await mkdir(tmpOf(root), { recursive: true });
924
+ await renameDir(path, to, o.platform);
925
+ } catch (err) {
926
+ kept.push({
927
+ path,
928
+ reason: ["EBUSY", "EPERM", "ENOTEMPTY"].some((c) => hasCode(err, c)) ? IN_USE : `not removed: ${err instanceof Error ? err.message : String(err)}`
929
+ });
930
+ return;
931
+ }
932
+ removed.push(path);
933
+ await rm(to, { recursive: true, force: true }).catch(() => void 0);
934
+ };
935
+ const placedJustNow = async (dir) => completeValid(dir) && await stat(join(dir, ".complete")).then(
936
+ (s) => now() - s.mtimeMs < PLACED_GRACE_MS,
937
+ () => false
938
+ );
939
+ const versions = join(root, "versions");
940
+ for (const name of await readdir(versions).catch(() => [])) {
941
+ const dir = join(versions, name);
942
+ const liveDir = join(dir, ".live");
943
+ let live = false;
944
+ for (const pid of await readdir(liveDir).catch(() => [])) {
945
+ if (/^\d+$/.test(pid) && isAlive(Number(pid))) live = true;
946
+ else await rm(join(liveDir, pid), { force: true }).catch(() => void 0);
947
+ }
948
+ const role = roles.get(name);
949
+ if (role !== void 0) {
950
+ kept.push({ path: dir, reason: role });
951
+ } else if (live) {
952
+ kept.push({ path: dir, reason: "a running tenjin mcp uses it" });
953
+ const pin = readNodePin(dir);
954
+ if (pin !== null) keepNode.add(pin.version);
955
+ } else if (await placedJustNow(dir)) {
956
+ kept.push({ path: dir, reason: PLACED });
957
+ const pin = readNodePin(dir);
958
+ if (pin !== null) keepNode.add(pin.version);
959
+ } else {
960
+ await remove(dir);
961
+ }
962
+ }
963
+ const nodes = join(root, "node");
964
+ for (const name of await readdir(nodes).catch(() => [])) {
965
+ const dir = join(nodes, name);
966
+ if (keepNode.has(name)) kept.push({ path: dir, reason: "pinned by a kept version" });
967
+ else if (await placedJustNow(dir)) kept.push({ path: dir, reason: PLACED });
968
+ else await remove(dir);
969
+ }
970
+ for (const name of await readdir(tmpOf(root)).catch(() => [])) {
971
+ const path = join(tmpOf(root), name);
972
+ const age = await stat(path).then(
973
+ (s) => now() - s.mtimeMs,
974
+ () => 0
975
+ );
976
+ if (name.startsWith("trash-") || age > TMP_MAX_AGE_MS) {
977
+ await rm(path, { recursive: true, force: true }).catch(() => void 0);
978
+ }
979
+ }
980
+ return { removed, kept };
981
+ },
982
+ o
983
+ );
984
+ }
985
+ async function removeWhatCan(dir) {
986
+ try {
987
+ await rm(dir, { recursive: true, force: true });
988
+ return [];
989
+ } catch (err) {
990
+ if (!["EBUSY", "EPERM", "ENOTEMPTY"].some((c) => hasCode(err, c))) throw err;
991
+ }
992
+ const entries = await readdir(dir, { withFileTypes: true }).catch(() => null);
993
+ if (entries === null) return [dir];
994
+ const left = [];
995
+ for (const entry of entries) {
996
+ const path = join(dir, entry.name);
997
+ if (entry.isDirectory()) left.push(...await removeWhatCan(path));
998
+ else await rm(path, { force: true }).catch(() => left.push(path));
999
+ }
1000
+ if (left.length === 0)
1001
+ await rm(dir, { recursive: true, force: true }).catch(() => left.push(dir));
1002
+ return left;
1003
+ }
1004
+ async function removeRuntime(root, o = {}) {
1005
+ if (!existsSync(root)) return { removed: false, left: [] };
1006
+ return withRuntimeLock(
1007
+ root,
1008
+ async () => {
1009
+ const left = await removeWhatCan(root);
1010
+ return { removed: left.length === 0, left };
1011
+ },
1012
+ o
1013
+ );
1014
+ }
1015
+ var REFRESH_BUDGET_MS = 35e3;
1016
+ var REFRESH_LOCK_MS = 5e3;
1017
+ var REFRESH_NODE_MS = 2e4;
1018
+ var REFRESH_VERIFY_MS = 18e3;
1019
+ var BUDGET_GONE = "the 35 s refresh budget ran out";
1020
+ var BudgetGone = class extends Error {
1021
+ constructor() {
1022
+ super(BUDGET_GONE);
1023
+ }
1024
+ };
1025
+ async function within(work, ms) {
1026
+ if (!Number.isFinite(ms)) return work;
1027
+ let timer;
1028
+ try {
1029
+ return await Promise.race([
1030
+ work,
1031
+ new Promise((_, fail) => timer = setTimeout(() => fail(new BudgetGone()), ms))
1032
+ ]);
1033
+ } finally {
1034
+ clearTimeout(timer);
1035
+ }
1036
+ }
1037
+ async function hostsMatch(root, version, launch) {
1038
+ const mod = await runtimeMod(launch);
1039
+ try {
1040
+ return Object.entries(runtimeHostFiles(root, version, launch, mod)).every(
1041
+ ([path, body]) => readFileSync(join(root, path), "utf8") === body
1042
+ );
1043
+ } catch {
1044
+ return false;
1045
+ }
1046
+ }
1047
+ async function setupRuntime(o) {
1048
+ const root = runtimeDir(o.dataDir);
1049
+ if (isSourceCheckout(o.moduleDir) || resolve(o.dataDir) !== resolve(defaultDataDir(o.home))) {
1050
+ return { state: "skipped", root, firstTime: false, launcher: null };
1051
+ }
1052
+ const platform = o.platform ?? process.platform;
1053
+ const arch = o.arch ?? process.arch;
1054
+ const deadline = o.refresh ? Date.now() + REFRESH_BUDGET_MS : Infinity;
1055
+ const left = (cap) => {
1056
+ if (!o.refresh) return Infinity;
1057
+ const ms = Math.min(cap, deadline - Date.now());
1058
+ if (ms <= 0) throw new BudgetGone();
1059
+ return ms;
1060
+ };
1061
+ const lockOpts = () => o.refresh ? { lockWaitMs: left(REFRESH_LOCK_MS) } : {};
1062
+ const firstTime = !existsSync(runtimeStatePath(root));
1063
+ const hostsDir = join(root, "claude");
1064
+ const launchOf = (p) => ({
1065
+ node: nodeBinPath(root, p.node, platform),
1066
+ entry: versionEntry(root, p.cli),
1067
+ platform,
1068
+ home: o.home
1069
+ });
1070
+ const runs = (p) => ({
1071
+ state: "kept",
1072
+ root,
1073
+ cli: p.cli,
1074
+ nodeVersion: p.node,
1075
+ node: launchOf(p).node,
1076
+ entry: launchOf(p).entry,
1077
+ hostsDir,
1078
+ firstTime,
1079
+ launcher: null
1080
+ });
1081
+ const keptNewer = (p) => ({
1082
+ ...runs(p),
1083
+ reason: `Tenjin ${p.cli} is already set up here; this ${o.version} did not replace it`,
1084
+ newer: true
1085
+ });
1086
+ const state = readRuntimeState(root);
1087
+ const usable = state !== null && runnable(root, state.current, platform) ? state.current : null;
1088
+ if (usable !== null && isNewer(usable.cli, o.version)) return keptNewer(usable);
1089
+ const alreadyCurrent = usable !== null && state !== null && usable.cli === o.version && state.pending === null && completeValid(versionDir(root, usable.cli)) && completeValid(join(root, "node", usable.node)) && await hostsMatch(root, o.version, launchOf(usable));
1090
+ const stillCurrent = (p) => withRuntimeLock(
1091
+ root,
1092
+ async () => {
1093
+ const now = readRawState(root);
1094
+ if (now.current !== null && isNewer(now.current.cli, p.cli) && runnable(root, now.current, platform)) {
1095
+ return keptNewer(now.current);
1096
+ }
1097
+ if (now.pending !== null || now.current?.cli !== p.cli || now.current.node !== p.node) {
1098
+ return null;
1099
+ }
1100
+ const launcher = await writeLaunchers(o.home, launchOf(p), { env: o.env, platform });
1101
+ return { ...runs(p), state: "current", launcher };
1102
+ },
1103
+ lockOpts()
1104
+ );
1105
+ const failed = (reason) => usable !== null ? { ...runs(usable), reason } : { state: "fallback", root, firstTime, launcher: null, reason };
1106
+ let downloading = false;
1107
+ try {
1108
+ if (alreadyCurrent) {
1109
+ const current = await stillCurrent(usable);
1110
+ if (current !== null) return current;
1111
+ }
1112
+ const glibc = platform === "linux" ? runningGlibc() : null;
1113
+ const key = nodeKey(platform, arch, glibc);
1114
+ const unpinned = unpinnedPlatform(platform, arch, glibc);
1115
+ if (unpinned !== null) {
1116
+ return { ...failed(`no pinned Node for this platform, ${unpinned}`), unpinned };
1117
+ }
1118
+ const build = runtimeBuild(o.moduleDir);
1119
+ const packageRoot = build !== null ? versionDir(build.root, build.cli) : packageRootOf(o.moduleDir);
1120
+ const pin = packageRoot === null ? null : readNodePin(packageRoot);
1121
+ if (key === null || pin === null || pin.sha256[key] === void 0) {
1122
+ return failed(`no pinned Node for ${key ?? `${platform}-${arch}`}`);
1123
+ }
1124
+ const next = { cli: o.version, node: pin.version };
1125
+ if (build === null || build.cli !== o.version || resolve(build.root) !== resolve(root)) {
1126
+ const stage = await within(stageSelf(root, packageRoot), left(REFRESH_BUDGET_MS));
1127
+ await within(
1128
+ placeVersion(root, stage, o.version, { ...lockOpts(), platform }),
1129
+ left(REFRESH_BUDGET_MS)
1130
+ );
1131
+ }
1132
+ const nodeMs = left(REFRESH_NODE_MS);
1133
+ downloading = true;
1134
+ await within(
1135
+ ensureNode(root, pin, {
1136
+ ...lockOpts(),
1137
+ timeoutMs: Number.isFinite(nodeMs) ? nodeMs : 3e5,
1138
+ fetchImpl: o.fetchImpl,
1139
+ platform,
1140
+ arch,
1141
+ glibc
1142
+ }),
1143
+ nodeMs
1144
+ );
1145
+ downloading = false;
1146
+ const launch = launchOf(next);
1147
+ const verified = await (o.verify ?? verifyBuild)(
1148
+ launch,
1149
+ o.version,
1150
+ o.refresh ? { timeoutMs: left(REFRESH_VERIFY_MS) } : {}
1151
+ );
1152
+ if (!verified.ok) return failed(verified.reason.slice(0, 200));
1153
+ const activation = await activate(root, next, {
1154
+ ...lockOpts(),
1155
+ home: o.home,
1156
+ env: o.env,
1157
+ platform
1158
+ });
1159
+ return {
1160
+ state: "active",
1161
+ root,
1162
+ cli: next.cli,
1163
+ nodeVersion: next.node,
1164
+ node: launch.node,
1165
+ entry: launch.entry,
1166
+ hostsDir,
1167
+ firstTime,
1168
+ launcher: activation.launcher,
1169
+ restore: activation.restore
1170
+ };
1171
+ } catch (err) {
1172
+ if (err instanceof NewerRuntime) return keptNewer(err.current);
1173
+ const message = err instanceof Error ? err.message : String(err);
1174
+ const network = err instanceof CliError && err.code === "NETWORK_ERROR" || err instanceof BudgetGone;
1175
+ const skipped = downloading && network ? proxySkipped(o.env, o.proxySupported) : null;
1176
+ if (skipped !== null) {
1177
+ return {
1178
+ ...failed(`${skipped}: ${message}`.slice(0, 200)),
1179
+ fix: proxyNodeStep("tenjin install")
1180
+ };
1181
+ }
1182
+ return failed(message.slice(0, 200));
1183
+ }
1184
+ }
1185
+ export {
1186
+ NewerRuntime,
1187
+ activate,
1188
+ collect,
1189
+ ensureNode,
1190
+ packageRootOf,
1191
+ pathLine,
1192
+ placeVersion,
1193
+ readNodePin,
1194
+ removeLaunchers,
1195
+ removeRuntime,
1196
+ setupRuntime,
1197
+ stageSelf,
1198
+ stageTarball,
1199
+ verifyBuild,
1200
+ withRuntimeLock,
1201
+ writeLaunchers
1202
+ };
1203
+ //# sourceMappingURL=runtime-UVNUA3AS.js.map