tenjin-cli 0.1.0-alpha.31 → 0.1.0-alpha.33

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 (270) hide show
  1. package/README.md +45 -26
  2. package/dist/{_esm-MEXZI5DL.js → _esm-BIN7VY2L.js} +128 -132
  3. package/dist/{alive-J64H46HI.js → alive-GSOWKUOY.js} +13 -6
  4. package/dist/auto-update-Y24UL56V.js +24 -0
  5. package/dist/{ccip-7RMRLAGV.js → ccip-DHDFKTQV.js} +2 -2
  6. package/dist/{chunk-TTNESUPQ.js → chunk-2GP3HRYK.js} +2120 -193
  7. package/dist/chunk-2GP3HRYK.js.map +1 -0
  8. package/dist/chunk-2M2VPI2E.js +560 -0
  9. package/dist/chunk-2M2VPI2E.js.map +1 -0
  10. package/dist/{chunk-D65GNPS3.js → chunk-2RWB7RKE.js} +288 -108
  11. package/dist/chunk-2RWB7RKE.js.map +1 -0
  12. package/dist/{chunk-AGZ7PJKY.js → chunk-36RVGZNY.js} +22 -5
  13. package/dist/chunk-36RVGZNY.js.map +1 -0
  14. package/dist/chunk-3AIHRXKO.js +72 -0
  15. package/dist/chunk-3AIHRXKO.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-3GNJXKIT.js +198 -0
  19. package/dist/chunk-3GNJXKIT.js.map +1 -0
  20. package/dist/{chunk-UQUOVWBG.js → chunk-4K7TQHNP.js} +7 -7
  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-KXQ4UIP7.js → chunk-4USCZ2NI.js} +2 -2
  24. package/dist/chunk-4YOZGGTZ.js +247 -0
  25. package/dist/chunk-4YOZGGTZ.js.map +1 -0
  26. package/dist/chunk-62KNUYWD.js +111 -0
  27. package/dist/chunk-62KNUYWD.js.map +1 -0
  28. package/dist/{chunk-POUWHWID.js → chunk-6CMM6YCB.js} +3 -3
  29. package/dist/{chunk-POUWHWID.js.map → chunk-6CMM6YCB.js.map} +1 -1
  30. package/dist/{chunk-5MARFNSB.js → chunk-A5GKIG5O.js} +49 -30
  31. package/dist/chunk-A5GKIG5O.js.map +1 -0
  32. package/dist/{chunk-YFPY4ONH.js → chunk-AGMVASXZ.js} +4 -4
  33. package/dist/chunk-BF4XHEQK.js +116 -0
  34. package/dist/chunk-BF4XHEQK.js.map +1 -0
  35. package/dist/chunk-BFDQ4WNW.js +119 -0
  36. package/dist/chunk-BFDQ4WNW.js.map +1 -0
  37. package/dist/{chunk-P4NH7OUK.js → chunk-C2Q76BVM.js} +49 -50
  38. package/dist/chunk-C2Q76BVM.js.map +1 -0
  39. package/dist/chunk-CEXSOI5R.js +808 -0
  40. package/dist/chunk-CEXSOI5R.js.map +1 -0
  41. package/dist/{chunk-QSCPK4F5.js → chunk-E7SW44LM.js} +4 -11
  42. package/dist/chunk-E7SW44LM.js.map +1 -0
  43. package/dist/chunk-EDJWHDDL.js +33 -0
  44. package/dist/chunk-EDJWHDDL.js.map +1 -0
  45. package/dist/chunk-F3ED5WTR.js +13 -0
  46. package/dist/chunk-F3ED5WTR.js.map +1 -0
  47. package/dist/{chunk-K72RURN3.js → chunk-FVIGCDSV.js} +2 -2
  48. package/dist/chunk-FVIGCDSV.js.map +1 -0
  49. package/dist/{chunk-5K5W4S66.js → chunk-GTTUCOPD.js} +2 -2
  50. package/dist/{chunk-4ZZO6ULA.js → chunk-HDPUXS3Z.js} +19 -48
  51. package/dist/chunk-HDPUXS3Z.js.map +1 -0
  52. package/dist/{chunk-LEFIX6RS.js → chunk-HGGWCP7W.js} +31 -11
  53. package/dist/chunk-HGGWCP7W.js.map +1 -0
  54. package/dist/{chunk-ORWL5BSN.js → chunk-HGZEPQUT.js} +2 -2
  55. package/dist/chunk-HMWYAUA6.js +478 -0
  56. package/dist/chunk-HMWYAUA6.js.map +1 -0
  57. package/dist/{chunk-7QKHZQKW.js → chunk-IADZOXKN.js} +39 -6
  58. package/dist/chunk-IADZOXKN.js.map +1 -0
  59. package/dist/{chunk-7Q5FDF65.js → chunk-IE7P2BZE.js} +3 -3
  60. package/dist/{chunk-77TCKDEC.js → chunk-ILNIZ5I2.js} +788 -508
  61. package/dist/chunk-ILNIZ5I2.js.map +1 -0
  62. package/dist/{hosts-FWZOV26H.js → chunk-INTFHMU4.js} +79 -24
  63. package/dist/chunk-INTFHMU4.js.map +1 -0
  64. package/dist/{chunk-6E5R45ZO.js → chunk-J57UC3DD.js} +4 -4
  65. package/dist/{chunk-6E5R45ZO.js.map → chunk-J57UC3DD.js.map} +1 -1
  66. package/dist/chunk-JNJWBTU2.js +3497 -0
  67. package/dist/chunk-JNJWBTU2.js.map +1 -0
  68. package/dist/{chunk-7WU4OPLP.js → chunk-KM7RY2ZS.js} +5 -3
  69. package/dist/{chunk-7WU4OPLP.js.map → chunk-KM7RY2ZS.js.map} +1 -1
  70. package/dist/chunk-L6JEXB3E.js +293 -0
  71. package/dist/chunk-L6JEXB3E.js.map +1 -0
  72. package/dist/chunk-LRW6S53P.js +450 -0
  73. package/dist/chunk-LRW6S53P.js.map +1 -0
  74. package/dist/{chunk-UKY4CHNC.js → chunk-LXAYUOXI.js} +24 -11
  75. package/dist/chunk-LXAYUOXI.js.map +1 -0
  76. package/dist/{chunk-WJXLQXJY.js → chunk-MPZUYCAP.js} +4 -1
  77. package/dist/{chunk-WJXLQXJY.js.map → chunk-MPZUYCAP.js.map} +1 -1
  78. package/dist/chunk-NDGZDTSJ.js +393 -0
  79. package/dist/chunk-NDGZDTSJ.js.map +1 -0
  80. package/dist/{chunk-SJLTEINJ.js → chunk-OJNTCYQQ.js} +17 -1
  81. package/dist/chunk-OJNTCYQQ.js.map +1 -0
  82. package/dist/{chunk-OHRR5OYM.js → chunk-P3LFTKE7.js} +5 -10
  83. package/dist/chunk-P3LFTKE7.js.map +1 -0
  84. package/dist/{chunk-XZKD7DIF.js → chunk-RL5UUDT4.js} +3 -3
  85. package/dist/{chunk-XZKD7DIF.js.map → chunk-RL5UUDT4.js.map} +1 -1
  86. package/dist/{chunk-5C32RLTA.js → chunk-RVPYTUP4.js} +20 -5
  87. package/dist/chunk-RVPYTUP4.js.map +1 -0
  88. package/dist/{chunk-YVFXE7RR.js → chunk-SNNSAGMT.js} +7279 -2627
  89. package/dist/chunk-SNNSAGMT.js.map +1 -0
  90. package/dist/{chunk-WK7F3B2E.js → chunk-SO3XRZPX.js} +3 -3
  91. package/dist/{chunk-R5LCN54M.js → chunk-TC2WZLSC.js} +13 -17
  92. package/dist/{chunk-R5LCN54M.js.map → chunk-TC2WZLSC.js.map} +1 -1
  93. package/dist/{chunk-B7HUUJOK.js → chunk-TKPF35W6.js} +3 -3
  94. package/dist/{chunk-KXVP2VKA.js → chunk-U3IKUGRP.js} +32 -33
  95. package/dist/chunk-U3IKUGRP.js.map +1 -0
  96. package/dist/{chunk-AKWGE6JQ.js → chunk-UUGOUOVT.js} +37 -2
  97. package/dist/chunk-UUGOUOVT.js.map +1 -0
  98. package/dist/{chunk-2XLC3AEX.js → chunk-UXZONNEQ.js} +536 -510
  99. package/dist/chunk-UXZONNEQ.js.map +1 -0
  100. package/dist/{chunk-7ZRL2LBQ.js → chunk-V2LQLN5H.js} +6 -6
  101. package/dist/{chunk-NEFNKLBE.js → chunk-WFSPCCVW.js} +1536 -423
  102. package/dist/chunk-WFSPCCVW.js.map +1 -0
  103. package/dist/{chunk-27EPWVOY.js → chunk-WXA2BWTE.js} +7 -3
  104. package/dist/chunk-WXA2BWTE.js.map +1 -0
  105. package/dist/chunk-WYXUQGOL.js +191 -0
  106. package/dist/chunk-WYXUQGOL.js.map +1 -0
  107. package/dist/chunk-X5ZBP3IY.js +97 -0
  108. package/dist/chunk-X5ZBP3IY.js.map +1 -0
  109. package/dist/{chunk-MNXS2U45.js → chunk-ZDZERB6L.js} +206 -297
  110. package/dist/chunk-ZDZERB6L.js.map +1 -0
  111. package/dist/chunk-ZNNXRNFD.js +113 -0
  112. package/dist/chunk-ZNNXRNFD.js.map +1 -0
  113. package/dist/{chunk-FW75G2W4.js → chunk-ZURZHELF.js} +5 -5
  114. package/dist/{cli-D5OE3URZ.js → cli-E36SPKBW.js} +145 -64
  115. package/dist/{cli-D5OE3URZ.js.map → cli-E36SPKBW.js.map} +1 -1
  116. package/dist/{codex-event-PPNVRRDH.js → codex-event-ZO2GEFE6.js} +2 -2
  117. package/dist/{codex-host-2RJOJW2B.js → codex-host-KECJVTA2.js} +7 -6
  118. package/dist/codex-install-HQZDGFXW.js +436 -0
  119. package/dist/codex-install-HQZDGFXW.js.map +1 -0
  120. package/dist/{config-ZD4OB2DO.js → config-HY2E4GGW.js} +21 -17
  121. package/dist/doctor-I6XQEKWD.js +1323 -0
  122. package/dist/doctor-I6XQEKWD.js.map +1 -0
  123. package/dist/{env-proxy-XL4P73MZ.js → env-proxy-R6ZMLQTT.js} +6 -2
  124. package/dist/{ethersCompat-Df4a6QIZ-THAVUGIJ.js → ethersCompat-Df4a6QIZ-X6YZWAML.js} +3 -3
  125. package/dist/{fund-5ITKQGYF.js → fund-2QRO7OJL.js} +43 -37
  126. package/dist/{fund-5ITKQGYF.js.map → fund-2QRO7OJL.js.map} +1 -1
  127. package/dist/hook-command-2UBCSZG6.js +43 -0
  128. package/dist/hosts/claude/.claude-plugin/marketplace.json +2 -2
  129. package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +2 -2
  130. package/dist/hosts/claude/tenjin/hooks/register.tsx +51 -11
  131. package/dist/hosts/claude/tenjin/skills/tenjin-pay/SKILL.md +82 -0
  132. package/dist/hosts/claude/tenjin/types/index.d.ts +2 -1
  133. package/dist/hosts/codex/tenjin/.mcp.json +3 -0
  134. package/dist/hosts/codex/tenjin/hooks/hooks.json +51 -5
  135. package/dist/hosts-DVQJ32QC.js +38 -0
  136. package/dist/index.js +32 -11
  137. package/dist/index.js.map +1 -1
  138. package/dist/install-ILUX5C4A.js +107 -0
  139. package/dist/{install-identity-K7EJIQFP.js → install-identity-TZKGY6LQ.js} +11 -10
  140. package/dist/install-wallet-5M4OTYLX.js +281 -0
  141. package/dist/install-wallet-5M4OTYLX.js.map +1 -0
  142. package/dist/isows-native-Q2UDIVPT.js +9 -0
  143. package/dist/isows-native-Q2UDIVPT.js.map +1 -0
  144. package/dist/{mcp-3LIJSSJB.js → mcp-LE4DUS22.js} +785 -211
  145. package/dist/mcp-LE4DUS22.js.map +1 -0
  146. package/dist/{mine.wasm-6PIT3DK6.js → mine.wasm-QFAHIFPY.js} +2 -2
  147. package/dist/{mine.wasm-6PIT3DK6.js.map → mine.wasm-QFAHIFPY.js.map} +1 -1
  148. package/dist/{package-ZKQFDWLE.js → package-IJFGMWEV.js} +4 -2
  149. package/dist/passphrase-IFTDS3CU.js +44 -0
  150. package/dist/{paths-POPTXJO6.js → paths-XCSAKISU.js} +10 -2
  151. package/dist/{pay-WHBERZ3W.js → pay-WCG3IH4R.js} +29 -29
  152. package/dist/{payments-KVICEKD2.js → payments-HFPPWHTV.js} +15 -14
  153. package/dist/{payments-KVICEKD2.js.map → payments-HFPPWHTV.js.map} +1 -1
  154. package/dist/plugin-registration-PZFI5GZW.js +68 -0
  155. package/dist/{redact-6W23GGJC.js → redact-D7ASVWKL.js} +2 -2
  156. package/dist/runtime-UZOKSUZX.js +1321 -0
  157. package/dist/runtime-UZOKSUZX.js.map +1 -0
  158. package/dist/runtime-fetch-ZSSSK72Y.js +23 -0
  159. package/dist/runtime-layout-WIDILZ6K.js +25 -0
  160. package/dist/{send-7G7Y7DLN.js → send-GCVEAQKL.js} +24 -22
  161. package/dist/{send-7G7Y7DLN.js.map → send-GCVEAQKL.js.map} +1 -1
  162. package/dist/{status-OF7RH5HM.js → status-HCVAOCN7.js} +55 -25
  163. package/dist/status-HCVAOCN7.js.map +1 -0
  164. package/dist/{status-line-XOUE6MPL.js → status-line-OPCXDHL2.js} +10 -9
  165. package/dist/{status-line-XOUE6MPL.js.map → status-line-OPCXDHL2.js.map} +1 -1
  166. package/dist/uninstall-BAWRBXXQ.js +481 -0
  167. package/dist/uninstall-BAWRBXXQ.js.map +1 -0
  168. package/dist/update-CACXLQLR.js +56 -0
  169. package/dist/update-CACXLQLR.js.map +1 -0
  170. package/dist/{usdc-OGOGEHV2.js → usdc-VG4CIOUK.js} +6 -8
  171. package/dist/usdc-VG4CIOUK.js.map +1 -0
  172. package/dist/{viemAdapter-By13KInL-S3DA7DFW.js → viemAdapter-By13KInL-DOFTEIJV.js} +3 -3
  173. package/dist/viemAdapter-By13KInL-DOFTEIJV.js.map +1 -0
  174. package/dist/wallet-QL4UUXEZ.js +55 -0
  175. package/dist/wallet-QL4UUXEZ.js.map +1 -0
  176. package/dist/wallet-kdf-worker.mjs +8 -8
  177. package/docs/agent-permissions.md +50 -28
  178. package/docs/safety-model.md +1 -1
  179. package/docs/troubleshooting.md +72 -1
  180. package/package.json +17 -4
  181. package/scripts/installers/install.ps1 +67 -0
  182. package/scripts/installers/install.sh +68 -0
  183. package/dist/_esm-C5CRWCYU.js +0 -3737
  184. package/dist/_esm-C5CRWCYU.js.map +0 -1
  185. package/dist/ccip-NLCSCHKI.js +0 -19
  186. package/dist/chunk-27EPWVOY.js.map +0 -1
  187. package/dist/chunk-2XLC3AEX.js.map +0 -1
  188. package/dist/chunk-4ZZO6ULA.js.map +0 -1
  189. package/dist/chunk-5C32RLTA.js.map +0 -1
  190. package/dist/chunk-5IEP5EGE.js +0 -5332
  191. package/dist/chunk-5IEP5EGE.js.map +0 -1
  192. package/dist/chunk-5MARFNSB.js.map +0 -1
  193. package/dist/chunk-77TCKDEC.js.map +0 -1
  194. package/dist/chunk-7EKYXMUO.js +0 -7536
  195. package/dist/chunk-7EKYXMUO.js.map +0 -1
  196. package/dist/chunk-7QKHZQKW.js.map +0 -1
  197. package/dist/chunk-AGZ7PJKY.js.map +0 -1
  198. package/dist/chunk-AKWGE6JQ.js.map +0 -1
  199. package/dist/chunk-BL3332HQ.js +0 -7611
  200. package/dist/chunk-BL3332HQ.js.map +0 -1
  201. package/dist/chunk-D65GNPS3.js.map +0 -1
  202. package/dist/chunk-EGELTSPU.js +0 -2865
  203. package/dist/chunk-EGELTSPU.js.map +0 -1
  204. package/dist/chunk-GA7JETVM.js +0 -150
  205. package/dist/chunk-GA7JETVM.js.map +0 -1
  206. package/dist/chunk-I3EQFHCD.js +0 -175
  207. package/dist/chunk-I3EQFHCD.js.map +0 -1
  208. package/dist/chunk-K3I7C2MO.js +0 -1185
  209. package/dist/chunk-K3I7C2MO.js.map +0 -1
  210. package/dist/chunk-K72RURN3.js.map +0 -1
  211. package/dist/chunk-KXVP2VKA.js.map +0 -1
  212. package/dist/chunk-LEFIX6RS.js.map +0 -1
  213. package/dist/chunk-MNXS2U45.js.map +0 -1
  214. package/dist/chunk-NEFNKLBE.js.map +0 -1
  215. package/dist/chunk-OHRR5OYM.js.map +0 -1
  216. package/dist/chunk-P4NH7OUK.js.map +0 -1
  217. package/dist/chunk-QSCPK4F5.js.map +0 -1
  218. package/dist/chunk-SJLTEINJ.js.map +0 -1
  219. package/dist/chunk-TTNESUPQ.js.map +0 -1
  220. package/dist/chunk-UKY4CHNC.js.map +0 -1
  221. package/dist/chunk-V6BSF6OC.js +0 -260
  222. package/dist/chunk-V6BSF6OC.js.map +0 -1
  223. package/dist/chunk-YVFXE7RR.js.map +0 -1
  224. package/dist/codex-install-UUZ6QMBQ.js +0 -221
  225. package/dist/codex-install-UUZ6QMBQ.js.map +0 -1
  226. package/dist/doctor-KBR34Q4B.js +0 -601
  227. package/dist/doctor-KBR34Q4B.js.map +0 -1
  228. package/dist/hook-command-4TYCHHRL.js +0 -39
  229. package/dist/hosts-FWZOV26H.js.map +0 -1
  230. package/dist/install-XWGE4Q7L.js +0 -77
  231. package/dist/install-wallet-XQ6XFZV4.js +0 -117
  232. package/dist/install-wallet-XQ6XFZV4.js.map +0 -1
  233. package/dist/mcp-3LIJSSJB.js.map +0 -1
  234. package/dist/plugin-registration-5TIA564H.js +0 -54
  235. package/dist/status-OF7RH5HM.js.map +0 -1
  236. package/dist/uninstall-JXUAFNDB.js +0 -158
  237. package/dist/uninstall-JXUAFNDB.js.map +0 -1
  238. package/dist/update-ZKUERSO2.js +0 -44
  239. package/dist/wallet-2HA6W4R4.js +0 -43
  240. /package/dist/{_esm-MEXZI5DL.js.map → _esm-BIN7VY2L.js.map} +0 -0
  241. /package/dist/{alive-J64H46HI.js.map → alive-GSOWKUOY.js.map} +0 -0
  242. /package/dist/{ccip-7RMRLAGV.js.map → auto-update-Y24UL56V.js.map} +0 -0
  243. /package/dist/{ccip-NLCSCHKI.js.map → ccip-DHDFKTQV.js.map} +0 -0
  244. /package/dist/{chunk-UQUOVWBG.js.map → chunk-4K7TQHNP.js.map} +0 -0
  245. /package/dist/{chunk-KXQ4UIP7.js.map → chunk-4USCZ2NI.js.map} +0 -0
  246. /package/dist/{chunk-YFPY4ONH.js.map → chunk-AGMVASXZ.js.map} +0 -0
  247. /package/dist/{chunk-5K5W4S66.js.map → chunk-GTTUCOPD.js.map} +0 -0
  248. /package/dist/{chunk-ORWL5BSN.js.map → chunk-HGZEPQUT.js.map} +0 -0
  249. /package/dist/{chunk-7Q5FDF65.js.map → chunk-IE7P2BZE.js.map} +0 -0
  250. /package/dist/{chunk-WK7F3B2E.js.map → chunk-SO3XRZPX.js.map} +0 -0
  251. /package/dist/{chunk-B7HUUJOK.js.map → chunk-TKPF35W6.js.map} +0 -0
  252. /package/dist/{chunk-7ZRL2LBQ.js.map → chunk-V2LQLN5H.js.map} +0 -0
  253. /package/dist/{chunk-FW75G2W4.js.map → chunk-ZURZHELF.js.map} +0 -0
  254. /package/dist/{codex-event-PPNVRRDH.js.map → codex-event-ZO2GEFE6.js.map} +0 -0
  255. /package/dist/{codex-host-2RJOJW2B.js.map → codex-host-KECJVTA2.js.map} +0 -0
  256. /package/dist/{config-ZD4OB2DO.js.map → config-HY2E4GGW.js.map} +0 -0
  257. /package/dist/{env-proxy-XL4P73MZ.js.map → env-proxy-R6ZMLQTT.js.map} +0 -0
  258. /package/dist/{ethersCompat-Df4a6QIZ-THAVUGIJ.js.map → ethersCompat-Df4a6QIZ-X6YZWAML.js.map} +0 -0
  259. /package/dist/{hook-command-4TYCHHRL.js.map → hook-command-2UBCSZG6.js.map} +0 -0
  260. /package/dist/{install-XWGE4Q7L.js.map → hosts-DVQJ32QC.js.map} +0 -0
  261. /package/dist/{install-identity-K7EJIQFP.js.map → install-ILUX5C4A.js.map} +0 -0
  262. /package/dist/{package-ZKQFDWLE.js.map → install-identity-TZKGY6LQ.js.map} +0 -0
  263. /package/dist/{paths-POPTXJO6.js.map → package-IJFGMWEV.js.map} +0 -0
  264. /package/dist/{pay-WHBERZ3W.js.map → passphrase-IFTDS3CU.js.map} +0 -0
  265. /package/dist/{plugin-registration-5TIA564H.js.map → paths-XCSAKISU.js.map} +0 -0
  266. /package/dist/{redact-6W23GGJC.js.map → pay-WCG3IH4R.js.map} +0 -0
  267. /package/dist/{update-ZKUERSO2.js.map → plugin-registration-PZFI5GZW.js.map} +0 -0
  268. /package/dist/{usdc-OGOGEHV2.js.map → redact-D7ASVWKL.js.map} +0 -0
  269. /package/dist/{viemAdapter-By13KInL-S3DA7DFW.js.map → runtime-fetch-ZSSSK72Y.js.map} +0 -0
  270. /package/dist/{wallet-2HA6W4R4.js.map → runtime-layout-WIDILZ6K.js.map} +0 -0
@@ -1,35 +1,20 @@
1
1
  import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
- import {
3
- ROUTER_PATH
4
- } from "./chunk-UKY4CHNC.js";
5
2
  import {
6
3
  NUDGE_OPT_OUT,
7
4
  channelTag,
8
5
  fetchDistTags,
9
- isNewer,
6
+ fetchPublishTime,
10
7
  resolveTarget
11
- } from "./chunk-KXVP2VKA.js";
12
- import {
13
- MOD_FILES,
14
- OWNER_MARKER,
15
- PLUGIN_DIR,
16
- PLUGIN_FILES,
17
- renderPluginFiles
18
- } from "./chunk-GA7JETVM.js";
8
+ } from "./chunk-U3IKUGRP.js";
19
9
  import {
20
10
  underAgentHarness
21
11
  } from "./chunk-KOGZDMHO.js";
22
12
  import {
23
- CLAUDE_CODE_FLOOR,
24
- claudeConfigDir,
25
- findClaudeBinary,
26
- jsonList,
27
- jsonResult,
28
- readClaudeCode,
29
- runClaude,
30
- userMcpFile,
31
- userSettingsPath
32
- } from "./chunk-QXP3Z3JN.js";
13
+ ROUTER_PATH
14
+ } from "./chunk-LXAYUOXI.js";
15
+ import {
16
+ readMcpServers
17
+ } from "./chunk-3GNJXKIT.js";
33
18
  import {
34
19
  CLI_SKILL_NAMES,
35
20
  FEE_APPROVAL,
@@ -47,238 +32,140 @@ import {
47
32
  skillsDirsFor,
48
33
  spendChoiceQuestion,
49
34
  spendOptions
50
- } from "./chunk-5MARFNSB.js";
51
- import {
52
- LEGACY_HOOK_TOOL,
53
- LEGACY_MCP_SERVER_NAME,
54
- LEGACY_REQUEST_TOOL,
55
- MARKETPLACE_NAME,
56
- PLUGIN_ID,
57
- PLUGIN_NAME,
58
- SKILLS_DIR_PLUGIN_ID
59
- } from "./chunk-WJXLQXJY.js";
60
- import {
61
- SUGGESTED_FUND_USD
62
- } from "./chunk-4ZZO6ULA.js";
35
+ } from "./chunk-A5GKIG5O.js";
63
36
  import {
64
37
  emitWriteNotice,
65
38
  paint,
66
39
  sanitizeForTerminal
67
- } from "./chunk-K72RURN3.js";
40
+ } from "./chunk-FVIGCDSV.js";
41
+ import {
42
+ SUGGESTED_FUND_USD
43
+ } from "./chunk-HDPUXS3Z.js";
68
44
  import {
69
45
  askText,
70
46
  selectOne
71
47
  } from "./chunk-DOQGNFHM.js";
72
48
  import {
73
- readAliveStamp
74
- } from "./chunk-I3EQFHCD.js";
49
+ MANAGERS,
50
+ classifyManager,
51
+ inspectPluginFolder,
52
+ isSourceCheckout,
53
+ pluginFolderPath,
54
+ readModSources,
55
+ refuse,
56
+ removePluginFolder,
57
+ resolveManagerScript,
58
+ writePluginFolder
59
+ } from "./chunk-L6JEXB3E.js";
60
+ import {
61
+ PLUGIN_DIR,
62
+ RUNTIME_MISSING_FIX,
63
+ renderPluginFiles,
64
+ shQuote
65
+ } from "./chunk-LRW6S53P.js";
66
+ import {
67
+ LEGACY_HOOK_TOOL,
68
+ LEGACY_MCP_SERVER_NAME,
69
+ LEGACY_REQUEST_TOOL,
70
+ MARKETPLACE_NAME,
71
+ MCP_SERVER_NAME,
72
+ PLUGIN_ID,
73
+ PLUGIN_NAME,
74
+ SKILLS_DIR_PLUGIN_ID
75
+ } from "./chunk-MPZUYCAP.js";
76
+ import {
77
+ runningGlibc,
78
+ unpinnedPlatform
79
+ } from "./chunk-4YOZGGTZ.js";
75
80
  import {
76
81
  envProxySupported,
82
+ proxyNodeStep,
83
+ proxySkipped,
77
84
  proxyVariable
78
- } from "./chunk-S4SAZ7OD.js";
85
+ } from "./chunk-3FMZGI7I.js";
79
86
  import {
80
87
  httpRequest
81
- } from "./chunk-AGZ7PJKY.js";
88
+ } from "./chunk-36RVGZNY.js";
82
89
  import {
83
- hasCode
84
- } from "./chunk-2I4QTOLB.js";
90
+ CLAUDE_CODE_FLOOR,
91
+ claudeConfigDir,
92
+ findClaudeBinary,
93
+ jsonList,
94
+ jsonResult,
95
+ readClaudeCode,
96
+ runClaude,
97
+ userMcpFile,
98
+ userSettingsPath
99
+ } from "./chunk-QXP3Z3JN.js";
100
+ import {
101
+ package_default
102
+ } from "./chunk-RVPYTUP4.js";
85
103
  import {
86
104
  resolveContextSettings
87
- } from "./chunk-7WU4OPLP.js";
105
+ } from "./chunk-KM7RY2ZS.js";
88
106
  import {
89
107
  parseUsdToAtomic,
90
108
  toMoney
91
109
  } from "./chunk-Y527D4TV.js";
110
+ import {
111
+ readAliveStamp
112
+ } from "./chunk-NDGZDTSJ.js";
113
+ import {
114
+ WALLET_REASONS,
115
+ agentFixFor
116
+ } from "./chunk-BFDQ4WNW.js";
117
+ import {
118
+ REPAIR_CLAUSE
119
+ } from "./chunk-X5ZBP3IY.js";
120
+ import {
121
+ hasCode
122
+ } from "./chunk-2I4QTOLB.js";
92
123
  import {
93
124
  MAX_AUTO_SPEND_FLOOR_ATOMIC,
94
125
  MAX_AUTO_SPEND_FLOOR_WHY,
95
126
  loadRawConfig
96
- } from "./chunk-YVFXE7RR.js";
127
+ } from "./chunk-2M2VPI2E.js";
97
128
  import {
98
129
  PRODUCTION_ORIGIN,
99
130
  isSameDeployment
100
131
  } from "./chunk-XQJXNMSB.js";
132
+ import {
133
+ writeFileAtomic
134
+ } from "./chunk-7WEQQJLG.js";
101
135
  import {
102
136
  CliError
103
137
  } from "./chunk-3UCIG4TG.js";
104
138
  import {
105
- writeFileAtomic
106
- } from "./chunk-7WEQQJLG.js";
139
+ runtimeBuild,
140
+ runtimeStatePath
141
+ } from "./chunk-ZNNXRNFD.js";
107
142
  import {
108
- defaultDataDir
109
- } from "./chunk-SJLTEINJ.js";
143
+ isNewer
144
+ } from "./chunk-EDJWHDDL.js";
110
145
  import {
111
- package_default
112
- } from "./chunk-5C32RLTA.js";
146
+ defaultDataDir,
147
+ runtimeDir
148
+ } from "./chunk-OJNTCYQQ.js";
113
149
 
114
150
  // src/commands/update.ts
115
151
  import { spawn } from "node:child_process";
116
- import { existsSync as existsSync2, statSync as statSync2 } from "node:fs";
152
+ import { existsSync as existsSync2, statSync } from "node:fs";
153
+ import { rm as rm2 } from "node:fs/promises";
117
154
  import { homedir as homedir2 } from "node:os";
118
- import { resolve, sep as sep3 } from "node:path";
155
+ import { resolve as resolve2, sep as sep2 } from "node:path";
119
156
  import { fileURLToPath as fileURLToPath3 } from "node:url";
120
157
 
121
- // src/lib/install-location.ts
122
- import { existsSync, realpathSync, statSync } from "node:fs";
123
- import { delimiter, dirname, join, sep } from "node:path";
124
- var REFUSALS = [
125
- {
126
- test: isSourceCheckout,
127
- error: () => new CliError("REFUSED", "tenjin-cli is running from a source checkout, not an install", {
128
- fix: "Update the checkout instead: git pull && pnpm install"
129
- }),
130
- needsVersion: false,
131
- appliesToCheck: false
132
- },
133
- {
134
- test: (moduleDir) => moduleDir.split(sep).includes("_npx"),
135
- error: (spec) => new CliError("REFUSED", "tenjin-cli is running from the npx cache, not an install", {
136
- // Writing a global here would "succeed" and change nothing: the next
137
- // `npx tenjin` still resolves its own cached copy.
138
- fix: `npx fetches its own copy every time. To keep one: npm i -g ${spec}`
139
- }),
140
- needsVersion: true,
141
- appliesToCheck: false
142
- },
143
- {
144
- // The ONLY manager still refused. `yarn global add` is yarn-1 only, and
145
- // berry dropped global installs altogether, so there is no one command this
146
- // can drive across the versions a user might have. Every other manager is
147
- // delegated to rather than refused (see MANAGERS).
148
- test: (moduleDir) => classifyManager(moduleDir) === "yarn",
149
- error: (spec) => new CliError(
150
- "REFUSED",
151
- "This tenjin-cli was installed with yarn, whose global install exists only in yarn 1",
152
- { fix: `yarn global add ${spec}` }
153
- ),
154
- needsVersion: true,
155
- appliesToCheck: false
156
- },
157
- {
158
- // Scoped to npm on purpose: the prefix-vs-project-root test is written for
159
- // npm's layout. pnpm's global store and bun's global dir both keep a
160
- // package.json beside `node_modules`, so an unscoped test would read either
161
- // as a project-local install and refuse the very case we now delegate.
162
- test: (moduleDir) => classifyManager(moduleDir) === "npm" && !isGlobalTree(moduleDir),
163
- error: (spec) => new CliError(
164
- "REFUSED",
165
- "This tenjin-cli is a project-local dependency, not a global install",
166
- {
167
- fix: `Update it where it is declared: npm i ${spec}`
168
- }
169
- ),
170
- needsVersion: true,
171
- appliesToCheck: false
172
- }
173
- ];
174
- function refuse(moduleDir, opts) {
175
- for (const entry of REFUSALS) {
176
- if (opts.check && !entry.appliesToCheck) continue;
177
- if (entry.needsVersion !== (opts.spec !== null)) continue;
178
- if (entry.test(moduleDir)) throw entry.error(opts.spec ?? "", moduleDir);
179
- }
180
- }
181
- function isSourceCheckout(moduleDir) {
182
- let dir = moduleDir;
183
- for (let i = 0; i < 8; i += 1) {
184
- if (existsSync(join(dir, "package.json"))) return existsSync(join(dir, "src"));
185
- const parent = dirname(dir);
186
- if (parent === dir) break;
187
- dir = parent;
188
- }
189
- return false;
190
- }
191
- function isGlobalTree(moduleDir) {
192
- const segs = moduleDir.split(sep);
193
- const i = segs.lastIndexOf("node_modules");
194
- if (i <= 0) return false;
195
- return !existsSync(join(segs.slice(0, i).join(sep), "package.json"));
196
- }
197
- function classifyManager(moduleDir) {
198
- const segs = moduleDir.split(sep);
199
- const pair = (a, b) => segs.includes(a) && segs.includes(b);
200
- if (segs.includes(".pnpm") || pair("pnpm", "global")) return "pnpm";
201
- if (segs.includes(".bun")) return "bun";
202
- if (segs.includes(".yarn") || pair("yarn", "global")) return "yarn";
203
- return "npm";
204
- }
205
- var MANAGERS = {
206
- npm: {
207
- bin: "npm",
208
- scriptSuffixes: ["npm-cli.js"],
209
- besideNode: true,
210
- args: (spec) => ["install", "-g", "--ignore-scripts", spec],
211
- manual: (spec) => `npm i -g ${spec}`
212
- },
213
- pnpm: {
214
- bin: "pnpm",
215
- // corepack's shim resolves to `pnpm.js`, a standalone install to `pnpm.cjs`.
216
- scriptSuffixes: [".cjs", ".js"],
217
- besideNode: false,
218
- args: (spec) => ["add", "-g", "--ignore-scripts", spec],
219
- manual: (spec) => `pnpm add -g ${spec}`
220
- },
221
- bun: {
222
- bin: "bun",
223
- scriptSuffixes: [],
224
- besideNode: false,
225
- // No --ignore-scripts: bun's flag surface for it is not stable across the
226
- // versions in the wild, and an unknown flag would fail the install outright.
227
- args: (spec) => ["add", "-g", spec],
228
- manual: (spec) => `bun add -g ${spec}`
229
- }
230
- };
231
- function resolveManagerScript(manager, execPath, env = process.env) {
232
- const plan = MANAGERS[manager];
233
- if (plan.scriptSuffixes.length === 0) return null;
234
- const beside = plan.besideNode ? scriptNear(dirname(execPath), plan.bin) : null;
235
- return beside ?? scriptOnPath(plan.bin, plan.scriptSuffixes, env);
236
- }
237
- function scriptNear(dir, bin) {
238
- const candidates = [
239
- join(dir, "node_modules", bin, "bin", `${bin}-cli.js`),
240
- join(dir, "..", "lib", "node_modules", bin, "bin", `${bin}-cli.js`)
241
- ];
242
- return candidates.find(isFile) ?? null;
243
- }
244
- function scriptOnPath(bin, suffixes, env) {
245
- const exts = process.platform === "win32" ? ["", ...(env.PATHEXT ?? ".EXE;.CMD;.BAT;.COM").split(";").filter((e) => e.length > 0)] : [""];
246
- for (const part of (env.PATH ?? "").split(delimiter)) {
247
- if (part.length === 0) continue;
248
- for (const ext of exts) {
249
- if (!isFile(join(part, `${bin}${ext}`))) continue;
250
- const real = realpathOrNull(join(part, `${bin}${ext}`));
251
- if (real !== null && suffixes.some((suffix) => real.endsWith(suffix))) return real;
252
- const near = scriptNear(part, bin);
253
- if (near !== null) return near;
254
- }
255
- }
256
- return null;
257
- }
258
- function isFile(p) {
259
- try {
260
- return statSync(p).isFile();
261
- } catch {
262
- return false;
263
- }
264
- }
265
- function realpathOrNull(p) {
266
- try {
267
- return realpathSync(p);
268
- } catch {
269
- return null;
270
- }
271
- }
272
-
273
158
  // src/router/install.ts
274
- import { readFile as readFile4, realpath } from "node:fs/promises";
159
+ import { existsSync } from "node:fs";
160
+ import { readFile as readFile3, realpath, stat as stat3 } from "node:fs/promises";
275
161
  import { homedir } from "node:os";
276
- import { isAbsolute, join as join7 } from "node:path";
162
+ import { dirname as dirname3, isAbsolute, join as join4, relative, resolve, sep } from "node:path";
163
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
277
164
 
278
165
  // src/lib/skill-placement.ts
279
166
  import { lstatSync } from "node:fs";
280
167
  import { readdir, rm, rmdir } from "node:fs/promises";
281
- import { dirname as dirname2, join as join2 } from "node:path";
168
+ import { dirname, join } from "node:path";
282
169
  function isRealDirectory(path) {
283
170
  try {
284
171
  return lstatSync(path, { throwIfNoEntry: false })?.isDirectory() === true;
@@ -291,11 +178,11 @@ async function removeOwnedSkill(name, skillsDir) {
291
178
  if (!isRealDirectory(skillsDir)) {
292
179
  return { changed: false };
293
180
  }
294
- const skillDir = join2(skillsDir, name);
181
+ const skillDir = join(skillsDir, name);
295
182
  if (!isRealDirectory(skillDir)) {
296
183
  return { changed: false };
297
184
  }
298
- const path = join2(skillDir, "SKILL.md");
185
+ const path = join(skillDir, "SKILL.md");
299
186
  const read = await readSkillFile(path);
300
187
  if (read.kind === "absent") return { changed: false };
301
188
  if (read.kind !== "ok" || skillFrontmatterName(read.bytes.toString("utf8")) !== name) {
@@ -305,9 +192,9 @@ async function removeOwnedSkill(name, skillsDir) {
305
192
  const subdirs = /* @__PURE__ */ new Set();
306
193
  for (const rel of shipped) {
307
194
  if (rel === "SKILL.md") continue;
308
- const file = join2(skillDir, rel);
309
- if (!isRealDirectory(dirname2(file))) continue;
310
- subdirs.add(dirname2(file));
195
+ const file = join(skillDir, rel);
196
+ if (!isRealDirectory(dirname(file))) continue;
197
+ subdirs.add(dirname(file));
311
198
  if (lstatSync(file, { throwIfNoEntry: false })?.isFile() === true) await rm(file);
312
199
  }
313
200
  await rm(path, { force: true });
@@ -322,7 +209,7 @@ async function removeRetiredSkills(home, project) {
322
209
  const dirs = [...skillsDirsFor(home), ...project ? skillsDirsFor(project) : []];
323
210
  for (const dir of new Set(dirs)) {
324
211
  for (const name of [...RETIRED_SKILL_NAMES, ...CLI_SKILL_NAMES]) {
325
- if ((await removeOwnedSkill(name, dir)).changed) removed.push(join2(dir, name));
212
+ if ((await removeOwnedSkill(name, dir)).changed) removed.push(join(dir, name));
326
213
  }
327
214
  }
328
215
  return removed;
@@ -330,7 +217,7 @@ async function removeRetiredSkills(home, project) {
330
217
 
331
218
  // src/router/legacy-install.ts
332
219
  import { readFile, stat } from "node:fs/promises";
333
- import { join as join3 } from "node:path";
220
+ import { join as join2 } from "node:path";
334
221
 
335
222
  // src/router/status-line-wiring.ts
336
223
  var STATUS_LINE_COMMAND = "tenjin status-line";
@@ -562,101 +449,15 @@ async function removeMcpEntry(opts, out) {
562
449
  }
563
450
  }
564
451
  function projectMcpFile(cwd) {
565
- return join3(cwd, ".mcp.json");
452
+ return join2(cwd, ".mcp.json");
566
453
  }
567
454
 
568
455
  // src/router/plugin-registration.ts
569
- import { readFile as readFile3, stat as stat2 } from "node:fs/promises";
570
- import { dirname as dirname4, join as join5 } from "node:path";
456
+ import { readFile as readFile2, stat as stat2 } from "node:fs/promises";
457
+ import { dirname as dirname2, join as join3 } from "node:path";
571
458
  import { fileURLToPath } from "node:url";
572
-
573
- // src/router/plugin-folder.ts
574
- import { lstat, readdir as readdir2, readFile as readFile2, rm as rm2, rmdir as rmdir2 } from "node:fs/promises";
575
- import { dirname as dirname3, join as join4, relative, sep as sep2 } from "node:path";
576
- var FOLDER_NAME = "tenjin-router";
577
- async function readModSources(pluginDir) {
578
- const entries = await Promise.all(
579
- MOD_FILES.map(async (path) => [path, await readFile2(join4(pluginDir, path), "utf8")])
580
- ).catch(() => null);
581
- return entries === null ? void 0 : Object.fromEntries(entries);
582
- }
583
- function pluginFolderPath(base) {
584
- return join4(base, "skills", FOLDER_NAME);
585
- }
586
- async function inspectPluginFolder(dir) {
587
- const entry = await lstat(dir).catch(() => null);
588
- if (entry === null) return "absent";
589
- if (!entry.isDirectory() || entry.isSymbolicLink()) return "foreign";
590
- try {
591
- const manifest = JSON.parse(
592
- await readFile2(join4(dir, ".claude-plugin", "plugin.json"), "utf8")
593
- );
594
- const marked = manifest.metadata !== null && typeof manifest.metadata === "object" && OWNER_MARKER in manifest.metadata;
595
- return manifest.name === PLUGIN_NAME && marked ? "ours" : "foreign";
596
- } catch {
597
- return "foreign";
598
- }
599
- }
600
- async function writePluginFolder(dir, files) {
601
- const state = await inspectPluginFolder(dir);
602
- if (state === "foreign") {
603
- return {
604
- path: dir,
605
- state: "refused",
606
- reason: `${dir} exists and is not a folder this CLI wrote, so it was left as it is`
607
- };
608
- }
609
- try {
610
- for (const path of PLUGIN_FILES) {
611
- const body = files[path];
612
- if (body === void 0) continue;
613
- await writeFileAtomic(join4(dir, path), body);
614
- }
615
- } catch (err) {
616
- return {
617
- path: dir,
618
- state: "refused",
619
- reason: err instanceof Error ? err.message : String(err)
620
- };
621
- }
622
- return { path: dir, state: "written" };
623
- }
624
- async function removePluginFolder(dir) {
625
- const state = await inspectPluginFolder(dir);
626
- if (state === "absent") return { path: dir, removed: false, left: [] };
627
- if (state === "foreign") {
628
- return {
629
- path: dir,
630
- removed: false,
631
- left: [],
632
- reason: `${dir} is not a folder this CLI wrote, so nothing in it was removed`
633
- };
634
- }
635
- for (const path of PLUGIN_FILES) await rm2(join4(dir, path), { force: true });
636
- const subdirs = [...new Set(PLUGIN_FILES.map((p) => dirname3(p)).filter((d) => d !== "."))].sort(
637
- (a, b) => b.split("/").length - a.split("/").length
638
- );
639
- for (const sub of subdirs) await rmdir2(join4(dir, sub)).catch(() => void 0);
640
- const left = await listFiles(dir);
641
- if (left.length === 0) await rmdir2(dir).catch(() => void 0);
642
- return { path: dir, removed: true, left };
643
- }
644
- async function listFiles(dir) {
645
- const out = [];
646
- const walk = async (current) => {
647
- for (const entry of await readdir2(current, { withFileTypes: true }).catch(() => [])) {
648
- const path = join4(current, entry.name);
649
- if (entry.isDirectory()) await walk(path);
650
- else out.push(relative(dir, path).split(sep2).join("/"));
651
- }
652
- };
653
- await walk(dir);
654
- return out.sort();
655
- }
656
-
657
- // src/router/plugin-registration.ts
658
459
  function folderFor(scope, env, home, cwd) {
659
- return pluginFolderPath(scope === "local" ? join5(cwd, ".claude") : claudeConfigDir(env, home));
460
+ return pluginFolderPath(scope === "local" ? join3(cwd, ".claude") : claudeConfigDir(env, home));
660
461
  }
661
462
  async function registerPlugin(opts) {
662
463
  const folder = folderFor(opts.scope, opts.env, opts.home, opts.cwd);
@@ -711,11 +512,10 @@ async function registerPlugin(opts) {
711
512
  }
712
513
  const written = await writePluginFolder(
713
514
  folder,
714
- renderPluginFiles(
715
- opts.version,
716
- opts.cliEntry ?? packageCliEntry(),
717
- await packageMod(opts.hostsDir)
718
- )
515
+ renderPluginFiles(opts.version, opts.cliEntry ?? packageCliEntry(), {
516
+ node: opts.node,
517
+ mod: await packageMod(opts.hostsDir)
518
+ })
719
519
  );
720
520
  if (written.state === "written") {
721
521
  return {
@@ -779,10 +579,14 @@ async function viaPluginCommands(binary, hosts, opts, steps) {
779
579
  return { ok: true, state: "installed" };
780
580
  }
781
581
  if (installed === available) return { ok: true, state: "current" };
782
- const update = await step(steps, ["plugin", "update", PLUGIN_ID, ...scopeArgs, "--json"], run);
783
- if (!update.ok) return { ok: false, reason: `claude plugin update failed: ${update.detail}` };
582
+ const update2 = await step(steps, ["plugin", "update", PLUGIN_ID, ...scopeArgs, "--json"], run);
583
+ if (!update2.ok) return { ok: false, reason: `claude plugin update failed: ${update2.detail}` };
784
584
  return { ok: true, state: "updated" };
785
585
  }
586
+ function marketplaceAdded(reg, hosts) {
587
+ const add = `claude plugin marketplace add ${hosts} `;
588
+ return reg.steps.some((s) => s.ok && s.command.startsWith(add));
589
+ }
786
590
  async function step(steps, args, run) {
787
591
  const out = await run(args);
788
592
  const result = jsonResult(out.stdout);
@@ -801,9 +605,9 @@ async function ownMarketplace(row) {
801
605
  const path = typeof row.path === "string" ? row.path : void 0;
802
606
  if (row.source !== "directory" || path === void 0) return false;
803
607
  if (await stat2(path).catch(() => null) === null) {
804
- return /tenjin-cli[\\/]dist[\\/]hosts[\\/]claude$/.test(path);
608
+ return /tenjin-cli[\\/]dist[\\/]hosts[\\/]claude$/.test(path) || /[\\/]runtime[\\/]claude$/.test(path);
805
609
  }
806
- return await inspectPluginFolder(join5(path, PLUGIN_DIR)) === "ours";
610
+ return await inspectPluginFolder(join3(path, PLUGIN_DIR)) === "ours";
807
611
  }
808
612
  async function existingCopy(binary, env, home, cwd) {
809
613
  const out = await runClaude(binary, ["plugin", "list", "--json"], { env, cwd });
@@ -814,10 +618,40 @@ async function existingCopy(binary, env, home, cwd) {
814
618
  );
815
619
  return typeof row?.id === "string" ? row.id : null;
816
620
  }
621
+ async function recordedInstalls(env, home) {
622
+ let raw;
623
+ try {
624
+ raw = await readFile2(
625
+ join3(claudeConfigDir(env, home), "plugins", "installed_plugins.json"),
626
+ "utf8"
627
+ );
628
+ } catch (err) {
629
+ return hasCode(err, "ENOENT") ? [] : null;
630
+ }
631
+ let plugins;
632
+ try {
633
+ plugins = JSON.parse(raw).plugins;
634
+ } catch {
635
+ return null;
636
+ }
637
+ if (typeof plugins !== "object" || plugins === null || Array.isArray(plugins)) return null;
638
+ const entries = plugins[PLUGIN_ID];
639
+ if (!Array.isArray(entries)) return [];
640
+ const records = [];
641
+ for (const entry of entries) {
642
+ if (typeof entry !== "object" || entry === null) continue;
643
+ const { scope, projectPath } = entry;
644
+ if (scope === "user") records.push({ scope, projectPath: null });
645
+ else if (scope === "local" && typeof projectPath === "string" && projectPath.length > 0) {
646
+ records.push({ scope, projectPath });
647
+ }
648
+ }
649
+ return records;
650
+ }
817
651
  async function installedThroughCommands(env, home) {
818
652
  try {
819
- const raw = await readFile3(
820
- join5(claudeConfigDir(env, home), "plugins", "installed_plugins.json"),
653
+ const raw = await readFile2(
654
+ join3(claudeConfigDir(env, home), "plugins", "installed_plugins.json"),
821
655
  "utf8"
822
656
  );
823
657
  const plugins = JSON.parse(raw).plugins;
@@ -826,31 +660,40 @@ async function installedThroughCommands(env, home) {
826
660
  return false;
827
661
  }
828
662
  }
829
- async function packageHostsDir(moduleDir = dirname4(fileURLToPath(import.meta.url))) {
830
- const catalog = join5(moduleDir, "hosts", "claude", ".claude-plugin", "marketplace.json");
663
+ async function packageHostsDir(moduleDir = dirname2(fileURLToPath(import.meta.url))) {
664
+ const catalog = join3(moduleDir, "hosts", "claude", ".claude-plugin", "marketplace.json");
831
665
  const stable = versionFreeEntry(catalog) ?? catalog;
832
666
  if ((await stat2(stable).catch(() => null))?.isFile() !== true) return null;
833
- return dirname4(dirname4(stable));
667
+ return dirname2(dirname2(stable));
834
668
  }
835
669
  async function packageMod(hostsDir) {
836
670
  const hosts = hostsDir === void 0 ? await packageHostsDir() : hostsDir;
837
- return hosts === null ? void 0 : readModSources(join5(hosts, PLUGIN_DIR));
671
+ return hosts === null ? void 0 : readModSources(join3(hosts, PLUGIN_DIR));
838
672
  }
839
- function packageCliEntry(moduleDir = dirname4(fileURLToPath(import.meta.url))) {
840
- const entry = join5(moduleDir, "index.js");
673
+ function packageCliEntry(moduleDir = dirname2(fileURLToPath(import.meta.url))) {
674
+ const entry = join3(moduleDir, "index.js");
841
675
  return versionFreeEntry(entry) ?? entry;
842
676
  }
843
677
  async function readPluginListing(binary, env, cwd) {
844
678
  const out = await runClaude(binary, ["plugin", "list", "--json"], { env, cwd });
845
679
  const rows = out.code === 0 ? jsonList(out.stdout) : null;
846
- if (rows === null) return { id: null, enabled: false, version: null, read: false };
680
+ if (rows === null) {
681
+ return { id: null, enabled: false, version: null, read: false, scope: null, projects: [] };
682
+ }
683
+ const projects = rows.filter(
684
+ (r) => r.id === PLUGIN_ID && r.enabled !== true && typeof r.projectPath === "string" && r.projectPath.length > 0
685
+ ).map((r) => r.projectPath);
847
686
  const row = rows.find((r) => r.id === PLUGIN_ID && r.enabled === true) ?? rows.find((r) => r.id === SKILLS_DIR_PLUGIN_ID && r.enabled === true) ?? rows.find((r) => r.id === PLUGIN_ID || r.id === SKILLS_DIR_PLUGIN_ID);
848
- if (row === void 0) return { id: null, enabled: false, version: null, read: true };
687
+ if (row === void 0) {
688
+ return { id: null, enabled: false, version: null, read: true, scope: null, projects };
689
+ }
849
690
  return {
850
691
  id: String(row.id),
851
692
  enabled: row.enabled === true,
852
693
  version: typeof row.version === "string" ? row.version : null,
853
- read: true
694
+ read: true,
695
+ scope: typeof row.scope === "string" ? row.scope : null,
696
+ projects
854
697
  };
855
698
  }
856
699
  async function folderState(scope, env, home, cwd) {
@@ -972,111 +815,23 @@ function proxyCredentialsFix(env) {
972
815
  return `Put the proxy's credentials in ${proxy} (\`http://user:password@proxy:port\`), then try again.`;
973
816
  }
974
817
 
975
- // src/router/mcp-processes.ts
976
- import { execFile } from "node:child_process";
977
- import { stat as stat3 } from "node:fs/promises";
978
- import { dirname as dirname5, join as join6 } from "node:path";
979
- import { fileURLToPath as fileURLToPath2 } from "node:url";
980
- import { promisify } from "node:util";
981
- var exec = promisify(execFile);
982
- var listMcpProcesses = async () => {
983
- if (process.platform === "win32" || typeof process.getuid !== "function") return null;
984
- try {
985
- const { stdout } = await exec(
986
- "ps",
987
- ["-U", String(process.getuid()), "-o", "pid=,lstart=,args="],
988
- { timeout: 5e3, env: { ...process.env, LC_ALL: "C" }, maxBuffer: 4 * 1024 * 1024 }
989
- );
990
- return parsePs(stdout, process.pid);
991
- } catch {
992
- return null;
993
- }
994
- };
995
- var PS_LINE = /^\s*(\d+)\s+(\w{3}\s+\w{3}\s+\d{1,2}\s+\d{2}:\d{2}:\d{2}\s+\d{4})\s+(.*)$/;
996
- function parsePs(stdout, selfPid) {
997
- const found = [];
998
- for (const line of stdout.split("\n")) {
999
- const m = PS_LINE.exec(line);
1000
- if (m === null) continue;
1001
- const pid = Number(m[1]);
1002
- if (pid === selfPid || !isTenjinMcp(m[3])) continue;
1003
- const startedAt = Date.parse(m[2].replace(/\s+/g, " "));
1004
- found.push({ pid, startedAt: Number.isNaN(startedAt) ? null : startedAt });
1005
- }
1006
- return found;
1007
- }
1008
- function isTenjinMcp(args) {
1009
- const tokens = args.trim().split(/\s+/);
1010
- const bin = tokens.findIndex(
1011
- (t) => /(^|[/\\])tenjin(\.js|\.cmd)?$/.test(t) || /[/\\]tenjin-cli[/\\]/.test(t) || /[/\\]hosts[/\\]claude[/\\]tenjin[/\\]\.\.[/\\]\.\.[/\\]\.\.[/\\]index\.js$/.test(t)
1012
- );
1013
- return bin >= 0 && tokens[bin + 1] === "mcp";
1014
- }
1015
- var installedAt = async () => {
1016
- let dir = dirname5(fileURLToPath2(import.meta.url));
1017
- for (let i = 0; i < 6; i += 1) {
1018
- try {
1019
- const st = await stat3(join6(dir, "package.json"));
1020
- return Math.max(st.ctimeMs, st.mtimeMs);
1021
- } catch {
1022
- dir = dirname5(dir);
1023
- }
1024
- }
1025
- return null;
1026
- };
1027
- var RECONNECT_FIX = "Type /reload-plugins in this Claude Code session, or start a new session.";
1028
- var NEW_SESSION_FIX = "Start a new Claude Code session: the earlier Tenjin setup is still in this one, and /reload-plugins would run both.";
1029
- function mcpServersState(procs, installed, version = package_default.version, fix = RECONNECT_FIX) {
1030
- const check = (detail) => ({
1031
- stale: 0,
1032
- check: { name: "mcp server", status: "ok", required: false, detail }
1033
- });
1034
- if (procs === null) {
1035
- return check("unknown: running `tenjin mcp` processes cannot be listed on this platform");
1036
- }
1037
- if (procs.length === 0) return check("none running (starts with the next session)");
1038
- if (installed === null) {
1039
- return check(`${procs.length} running; when this build was installed is unknown`);
1040
- }
1041
- const stale = procs.filter((p) => p.startedAt !== null && p.startedAt < installed).length;
1042
- if (stale === 0) {
1043
- return check(`${procs.length} running, all started after this install`);
1044
- }
1045
- const which = stale === 1 ? "process" : "processes";
1046
- return {
1047
- stale,
1048
- check: {
1049
- name: "mcp server",
1050
- status: "warn",
1051
- required: false,
1052
- detail: `${stale} running \`tenjin mcp\` ${which} started before this install (${version}), so ${stale === 1 ? "it runs" : "they run"} the older build, where the hooks can fail with "Tool hook not found"`,
1053
- fix
1054
- }
1055
- };
1056
- }
1057
- async function readMcpServers(deps = {}, opts = {}) {
1058
- const [procs, installed] = await Promise.all([
1059
- (deps.listMcpProcesses ?? listMcpProcesses)().catch(() => null),
1060
- (deps.installedAt ?? installedAt)().catch(() => null)
1061
- ]);
1062
- const fix = opts.settingsInstallPending === true ? NEW_SESSION_FIX : RECONNECT_FIX;
1063
- return mcpServersState(procs, installed, package_default.version, fix);
1064
- }
1065
-
1066
818
  // src/router/install.ts
1067
819
  var DISCLOSURE = [
1068
- "What leaves this machine: the bounded text of each prompt, each native search query or URL (and, when one came back short, its status, size or error), each task handed to a subagent, and each question your assistant asks you with your answers, sent to Tenjin for the free routing gate, beside this session's id. When the gate offers free library docs for a search, that search query also goes to Tenjin's docs lookup, which asks Context7.",
820
+ "What leaves this machine: the bounded text of each prompt, each native search query or URL (and, when one came back short, its status, size or error), each task handed to a subagent, and each question your assistant asks you with your answers, sent to Tenjin for the free routing gate, beside this session's id. When your assistant calls the free library docs lookup, its query goes to Tenjin's docs lookup, which asks Context7.",
1069
821
  "What is kept when a lookup is paid: the capability chosen, a hash of the contract, a hash of the arguments, and your wallet address. No prompt text, no arguments, no hint text.",
1070
822
  "What never leaves: your private key. It is decrypted in this CLI to sign, and never sent anywhere."
1071
823
  ];
1072
- var RELOAD_STEP = "type /reload-plugins in this Claude Code session, or start a new session, so Tenjin loads";
1073
824
  var NEW_SESSION_STEP = "start a new Claude Code session so Tenjin loads";
1074
- function loadStep(settingsInstallPresent) {
825
+ var RELOAD_STEP = "run `/reload-plugins` in this conversation so Tenjin loads, then continue your task";
826
+ function loadStep(settingsInstallPresent, env = {}, command = "tenjin") {
827
+ if (env.CLAUDE_CODE_ENTRYPOINT === "claude-desktop" || env.CLAUDE_CODE_ENTRYPOINT === "claude-desktop-3p") {
828
+ return `choose New session in Claude Desktop's Code tab for this same folder so Tenjin loads. Before switching, give the person one short ready-to-paste continuation prompt filled with this conversation's task, progress and next action; carry over the person's funding and spending choices, and have the next session check Tenjin with \`${command} doctor\`${process.platform === "win32" ? " in PowerShell" : ""} before continuing`;
829
+ }
1075
830
  return settingsInstallPresent ? NEW_SESSION_STEP : RELOAD_STEP;
1076
831
  }
1077
832
  function settingsInstallPaths(project, env, home, cwd) {
1078
833
  return project ? {
1079
- settingsPath: join7(cwd, ".claude", "settings.json"),
834
+ settingsPath: join4(cwd, ".claude", "settings.json"),
1080
835
  mcpFile: projectMcpFile(cwd),
1081
836
  mcpScope: "project"
1082
837
  } : {
@@ -1125,7 +880,7 @@ async function projectInstallHere(cwd, home, env) {
1125
880
  return projectInstallAt(cwd, home, env);
1126
881
  }
1127
882
  async function projectInstallAt(dir, home, env) {
1128
- const local = await readFile4(join7(dir, ".claude", "settings.local.json"), "utf8").then((raw) => JSON.parse(raw)).catch(() => null);
883
+ const local = await readFile3(join4(dir, ".claude", "settings.local.json"), "utf8").then((raw) => JSON.parse(raw)).catch(() => null);
1129
884
  if (local?.enabledPlugins?.[PLUGIN_ID] === true) return true;
1130
885
  if (await isHome(dir, home)) return false;
1131
886
  if ((await folderState("local", env, home, dir)).state === "ours") return true;
@@ -1139,6 +894,7 @@ async function isHome(dir, home) {
1139
894
  ]);
1140
895
  return dirPath === homePath;
1141
896
  }
897
+ var NOTHING_TO_REFRESH = "Nothing to refresh";
1142
898
  async function somethingToRefresh(claude, scope, legacy, env, home, cwd) {
1143
899
  if (legacy.present) return true;
1144
900
  if ((await folderState(scope, env, home, cwd)).state === "ours") return true;
@@ -1156,6 +912,7 @@ async function runRouterInstall(args, ctx, deps = {}) {
1156
912
  fix: "Set HOME to your home directory (`export HOME=...`), then re-run `tenjin install`."
1157
913
  });
1158
914
  }
915
+ assertPluginInstallation(ctx.dataDir, home, env);
1159
916
  const config = await loadRawConfig(ctx.dataDir);
1160
917
  const named = namedLimits(args);
1161
918
  const cwd = deps.cwd ?? process.cwd();
@@ -1164,10 +921,29 @@ async function runRouterInstall(args, ctx, deps = {}) {
1164
921
  const claude = await readClaudeCode(env, cwd, deps.findClaude ?? findClaudeBinary);
1165
922
  const paths = settingsInstallPaths(project, env, home, cwd);
1166
923
  const legacy = await inspectLegacyInstall(paths.settingsPath, paths.mcpFile);
924
+ const setUpRuntime = () => (deps.runtime ?? defaultRuntime)({
925
+ dataDir: ctx.dataDir,
926
+ home,
927
+ env,
928
+ version: package_default.version,
929
+ moduleDir: dirname3(fileURLToPath2(import.meta.url)),
930
+ refresh: args.refresh === true
931
+ });
1167
932
  if (args.refresh === true && !await somethingToRefresh(claude, scope, legacy, env, home, cwd)) {
933
+ if (!project && hasRuntime(ctx.dataDir, home)) {
934
+ const rt2 = await setUpRuntime();
935
+ requireRuntime(rt2);
936
+ await recordClaudeProjects(ctx.dataDir, config.install?.routerProjects ?? [], env, home);
937
+ if (runtimeLaunch(rt2) !== null) {
938
+ await collectRuntime(rt2.root, await fallbackFolders(ctx.dataDir, env, home, cwd, false));
939
+ }
940
+ return runtimeOnlyRefresh(ctx, rt2, home);
941
+ }
942
+ if (!project)
943
+ await recordClaudeProjects(ctx.dataDir, config.install?.routerProjects ?? [], env, home);
1168
944
  throw new CliError(
1169
945
  "REFUSED",
1170
- `Nothing to refresh: neither the ${PLUGIN_ID} plugin nor a settings install of Tenjin is registered here.`,
946
+ `${NOTHING_TO_REFRESH}: neither the ${PLUGIN_ID} plugin nor a settings install of Tenjin is registered here.`,
1171
947
  { fix: "Run `tenjin install` to set this machine up." }
1172
948
  );
1173
949
  }
@@ -1176,21 +952,37 @@ async function runRouterInstall(args, ctx, deps = {}) {
1176
952
  const answered = args.yes === true || named.keys.length > 0;
1177
953
  const unasked = config.maxAutoSpend === void 0 && config.sessionBudget === void 0;
1178
954
  const limits = args.refresh === true ? void 0 : named.keys.length > 0 ? { ...shownLimits(config), ...named.limits } : args.yes === true ? shownLimits(config) : canPrompt && unasked ? await approveLimits(deps) : {};
955
+ const deferred = !claude.meetsFloor && legacy.present;
956
+ const rt = deferred ? null : await setUpRuntime();
957
+ requireRuntime(rt);
958
+ if (!project) {
959
+ await recordClaudeProjects(ctx.dataDir, config.install?.routerProjects ?? [], env, home);
960
+ }
1179
961
  const spend = await persistRouterDefaults(ctx.dataDir, args.refresh === true, limits, named.keys);
1180
962
  const removedKeysLines = spend.removed.length > 0 ? [
1181
963
  `Removed retired settings: ${spend.removed.join(", ")}. Automatic router limits remain in effect; manual pay always requires consent.`
1182
964
  ] : [];
1183
965
  const removedSkills = await removeRetiredSkills(home, project ? cwd : void 0);
1184
- const plugin = !claude.meetsFloor && legacy.present ? deferredRegistration(scope, claude) : await registerPlugin({
966
+ const launch = runtimeLaunch(rt);
967
+ const plugin = deferred ? deferredRegistration(scope, claude) : await registerPlugin({
1185
968
  binary: claude.binary,
1186
969
  scope,
1187
- version: package_default.version,
970
+ version: launch?.version ?? package_default.version,
1188
971
  env,
1189
972
  home,
1190
973
  cwd,
1191
- ...deps.hostsDir !== void 0 ? { hostsDir: deps.hostsDir } : {},
1192
- ...deps.cliEntry !== void 0 ? { cliEntry: deps.cliEntry } : {}
974
+ ...launch !== null ? { hostsDir: launch.hostsDir, cliEntry: launch.cliEntry, node: launch.node } : {
975
+ ...deps.hostsDir !== void 0 ? { hostsDir: deps.hostsDir } : {},
976
+ ...deps.cliEntry !== void 0 ? { cliEntry: deps.cliEntry } : {}
977
+ }
1193
978
  });
979
+ if (rt !== null && launch !== null) {
980
+ if (plugin.state !== "failed") {
981
+ await collectRuntime(rt.root, await fallbackFolders(ctx.dataDir, env, home, cwd, project));
982
+ } else if (!marketplaceAdded(plugin, launch.hostsDir)) {
983
+ await rt.restore?.().catch(() => void 0);
984
+ }
985
+ }
1194
986
  if (project && plugin.state !== "failed") {
1195
987
  await persistRouterProject(ctx.dataDir, cwd).catch(() => void 0);
1196
988
  }
@@ -1201,10 +993,13 @@ async function runRouterInstall(args, ctx, deps = {}) {
1201
993
  mcpScope: paths.mcpScope
1202
994
  });
1203
995
  const pending = settingsInstallStays(migration);
1204
- const servers = await readMcpServers(deps, { settingsInstallPending: pending });
996
+ const servers = await readMcpServers(deps, {
997
+ settingsInstallPending: pending,
998
+ ...launch !== null ? { version: launch.version } : {}
999
+ });
1205
1000
  const serverLines = servers.stale > 0 ? [paint(ctx.io, "yellow", `! ${servers.check.detail}. ${servers.check.fix ?? ""}`.trim())] : [];
1206
1001
  const claudeCode = claudeCodeData(claude);
1207
- const notices = refreshNotices(plugin, claude, migration);
1002
+ const notices = refreshNotices(plugin, claude, migration, rt, home);
1208
1003
  if (args.refresh === true) {
1209
1004
  if (plugin.state === "failed" && migration.state !== "pending") {
1210
1005
  throw new CliError(
@@ -1223,21 +1018,24 @@ async function runRouterInstall(args, ctx, deps = {}) {
1223
1018
  spend,
1224
1019
  removedSkills,
1225
1020
  scope,
1226
- mcpServer: servers.check
1021
+ mcpServer: servers.check,
1022
+ runtime: runtimeData(rt),
1023
+ launcher: rt?.launcher ?? null
1227
1024
  },
1228
1025
  humanLines: [
1229
- ...refreshLines(ctx, plugin, claude, migration),
1026
+ ...refreshLines(ctx, plugin, claude, migration, rt, home),
1230
1027
  ...removedKeysLines,
1231
1028
  ...serverLines
1232
1029
  ]
1233
1030
  };
1234
1031
  }
1235
- const { resolveWallet } = await import("./install-wallet-XQ6XFZV4.js");
1032
+ const { resolveWallet } = await import("./install-wallet-5M4OTYLX.js");
1236
1033
  const wallet = await resolveWallet(ctx, deps, args.noWallet === true ? "flag" : void 0, false);
1237
1034
  const effective = await resolveContextSettings(ctx);
1238
- const spendAsk = !canPrompt && !answered && unasked ? spendStep(args) : void 0;
1035
+ const command = continuationCommand(rt);
1036
+ const spendAsk = !canPrompt && !answered && unasked ? spendStep(args, command) : void 0;
1239
1037
  const asksAgent = !canPrompt && underAgentHarness(env);
1240
- const [router, fund] = await Promise.all([
1038
+ const [router, funding] = await Promise.all([
1241
1039
  probeRouter(effective.baseUrl, {
1242
1040
  timeoutMs: ctx.flags.timeout,
1243
1041
  env,
@@ -1245,8 +1043,9 @@ async function runRouterInstall(args, ctx, deps = {}) {
1245
1043
  }),
1246
1044
  // The spend question comes first, because its answer picks the install
1247
1045
  // command. The funding question rides on the install that follows it.
1248
- asksAgent && spendAsk === void 0 ? fundStep(wallet, effective.rpcUrl, deps) : Promise.resolve(void 0)
1046
+ asksAgent && spendAsk === void 0 ? fundStep(wallet, effective.rpcUrl, deps, `${command} wallet fund ${SUGGESTED_FUND_USD}`) : Promise.resolve(void 0)
1249
1047
  ]);
1048
+ const fund = funding?.step;
1250
1049
  const nextSteps = [
1251
1050
  ...spendAsk !== void 0 ? [spendAsk] : [],
1252
1051
  ...fund !== void 0 ? [fund] : []
@@ -1255,11 +1054,21 @@ async function runRouterInstall(args, ctx, deps = {}) {
1255
1054
  plugin,
1256
1055
  claudeCode,
1257
1056
  migration,
1258
- next: nextStep(plugin, claude, wallet, migration, asksAgent && nextSteps.length > 0),
1057
+ next: nextStep(
1058
+ plugin,
1059
+ claude,
1060
+ wallet,
1061
+ migration,
1062
+ asksAgent && nextSteps.length > 0,
1063
+ ctx.io.isTTY,
1064
+ command,
1065
+ env
1066
+ ),
1259
1067
  nextSteps,
1068
+ ...funding?.warning !== void 0 ? { fundingWarning: funding.warning } : {},
1260
1069
  // The check for this scope, said outright; a bare doctor in the project
1261
1070
  // also finds it from what the project holds.
1262
- ...project ? { doctor: "tenjin doctor --project" } : {},
1071
+ ...project ? { doctor: `${command} doctor --project` } : {},
1263
1072
  spend: { ...spend, effective: effectiveLimits(effective.policy) },
1264
1073
  wallet,
1265
1074
  router: {
@@ -1269,7 +1078,9 @@ async function runRouterInstall(args, ctx, deps = {}) {
1269
1078
  },
1270
1079
  disclosure: DISCLOSURE,
1271
1080
  removedSkills,
1272
- mcpServer: servers.check
1081
+ mcpServer: servers.check,
1082
+ runtime: runtimeData(rt),
1083
+ launcher: rt?.launcher ?? null
1273
1084
  };
1274
1085
  return {
1275
1086
  data,
@@ -1280,16 +1091,201 @@ async function runRouterInstall(args, ctx, deps = {}) {
1280
1091
  migration,
1281
1092
  wallet,
1282
1093
  ...fund !== void 0 ? { fund } : {},
1094
+ ...funding?.warning !== void 0 ? { fundingWarning: funding.warning } : {},
1283
1095
  asks: asksAgent && nextSteps.length > 0,
1284
1096
  policy: effective.policy,
1285
1097
  ...spendAsk !== void 0 ? { spendAsk } : {},
1286
- router
1098
+ router,
1099
+ rt,
1100
+ home,
1101
+ env
1287
1102
  }),
1288
1103
  ...removedKeysLines,
1289
1104
  ...serverLines
1290
1105
  ]
1291
1106
  };
1292
1107
  }
1108
+ async function defaultRuntime(o) {
1109
+ const { setupRuntime } = await import("./runtime-UZOKSUZX.js");
1110
+ return setupRuntime(o);
1111
+ }
1112
+ var sharedResults = /* @__PURE__ */ new WeakSet();
1113
+ function runtimeOncePerRun(setup = defaultRuntime) {
1114
+ let first;
1115
+ return async (o) => {
1116
+ if (first === void 0) {
1117
+ first = setup(o).then((rt2) => {
1118
+ const restore = rt2.restore;
1119
+ if (restore === void 0) return rt2;
1120
+ return {
1121
+ ...rt2,
1122
+ restore: async () => {
1123
+ try {
1124
+ await restore();
1125
+ } finally {
1126
+ first = void 0;
1127
+ }
1128
+ }
1129
+ };
1130
+ });
1131
+ return first;
1132
+ }
1133
+ const rt = { ...await first };
1134
+ delete rt.restore;
1135
+ sharedResults.add(rt);
1136
+ return rt;
1137
+ };
1138
+ }
1139
+ function hasRuntime(dataDir, home) {
1140
+ return resolve(dataDir) === resolve(defaultDataDir(home)) && existsSync(runtimeStatePath(runtimeDir(dataDir)));
1141
+ }
1142
+ function runtimeOnlyRefresh(ctx, rt, home) {
1143
+ return {
1144
+ data: {
1145
+ plugin: null,
1146
+ refresh: true,
1147
+ scope: "user",
1148
+ notices: runtimeNotices(rt, home),
1149
+ runtime: runtimeData(rt),
1150
+ launcher: rt.launcher
1151
+ },
1152
+ humanLines: [
1153
+ `${paint(ctx.io, "green", "\u2713")} Tenjin's runtime is up to date; no Claude Code plugin is registered here, so none was refreshed`,
1154
+ ...runtimeLines(ctx, rt, home)
1155
+ ]
1156
+ };
1157
+ }
1158
+ async function collectRuntime(root, folders) {
1159
+ try {
1160
+ const { collect } = await import("./runtime-UZOKSUZX.js");
1161
+ await collect(root, { lockWaitMs: 5e3, keep: await folderPointers(root, folders) });
1162
+ } catch {
1163
+ }
1164
+ }
1165
+ async function fallbackFolders(dataDir, env, home, cwd, project) {
1166
+ const projects = (await loadRawConfig(dataDir).catch(() => null))?.install?.routerProjects ?? [];
1167
+ return [
1168
+ folderFor("user", env, home, cwd),
1169
+ ...[...projects, ...project ? [cwd] : []].map((dir) => folderFor("local", env, home, dir))
1170
+ ];
1171
+ }
1172
+ var NODE_DIR_RE = /^\d+\.\d+\.\d+$/;
1173
+ async function folderPointers(root, folders) {
1174
+ const pointers = [];
1175
+ for (const dir of folders) {
1176
+ if (await inspectPluginFolder(dir) !== "ours") continue;
1177
+ const server = await readFile3(join4(dir, ".mcp.json"), "utf8").then(
1178
+ (raw) => JSON.parse(raw).mcpServers?.[MCP_SERVER_NAME]
1179
+ ).catch(() => void 0);
1180
+ const entry = Array.isArray(server?.args) ? server.args[0] : void 0;
1181
+ const node = server?.command;
1182
+ if (typeof entry !== "string" || typeof node !== "string") continue;
1183
+ const build = runtimeBuild(dirname3(entry));
1184
+ const nodeVersion = relative(join4(root, "node"), node).split(sep)[0] ?? "";
1185
+ if (build !== null && resolve(build.root) === resolve(root) && NODE_DIR_RE.test(nodeVersion)) {
1186
+ pointers.push({ cli: build.cli, node: nodeVersion });
1187
+ }
1188
+ }
1189
+ return pointers;
1190
+ }
1191
+ function assertPluginInstallation(dataDir, home, env) {
1192
+ if (env.TENJIN_DATA_DIR && resolve(dataDir) !== resolve(defaultDataDir(home))) {
1193
+ throw new CliError("REFUSED", "Plugin installation needs the default data directory.", {
1194
+ fix: "Run without TENJIN_DATA_DIR. Other CLI commands still support it."
1195
+ });
1196
+ }
1197
+ if (!isSourceCheckout(dirname3(fileURLToPath2(import.meta.url)))) {
1198
+ const unsupported = unpinnedPlatform(process.platform, process.arch, runningGlibc());
1199
+ if (unsupported !== null)
1200
+ throw new CliError("REFUSED", `Plugin installation is unsupported on ${unsupported}.`, {
1201
+ fix: "Use macOS, Windows or glibc Linux 2.28+ on x64/arm64. Your existing setup was kept."
1202
+ });
1203
+ }
1204
+ }
1205
+ function continuationCommand(rt, platform = process.platform) {
1206
+ if (rt === null || rt.state === "skipped" || rt.node === void 0 || rt.entry === void 0)
1207
+ return "tenjin";
1208
+ const launcher = rt.launcher;
1209
+ const verifiedLauncher = launcher?.state === "written" || launcher?.state === "current";
1210
+ const path = verifiedLauncher ? launcher.paths.find((p) => platform !== "win32" || p.endsWith(".cmd")) : void 0;
1211
+ const parts = path === void 0 ? [rt.node, rt.entry] : [path];
1212
+ return platform === "win32" ? `& ${parts.map((part) => `'${part.replaceAll("'", "''")}'`).join(" ")}` : parts.map(shQuote).join(" ");
1213
+ }
1214
+ function requireRuntime(rt) {
1215
+ if (rt === null || rt.state === "skipped") return;
1216
+ if (rt.state === "failed" || rt.state === "kept" && rt.reason !== void 0 && rt.newer !== true) {
1217
+ throw new CliError(
1218
+ "UPDATE_FAILED",
1219
+ `Tenjin could not finish installation: ${rt.reason ?? "runtime setup failed"}. Your existing plugin registration was kept.`,
1220
+ {
1221
+ fix: rt.fix ?? (rt.unpinned ? "Use macOS, Windows or glibc Linux 2.28+ on x64/arm64." : "Check your connection and run tenjin install again.")
1222
+ }
1223
+ );
1224
+ }
1225
+ }
1226
+ function runtimeLaunch(rt) {
1227
+ if (rt === null || rt.state !== "active" && rt.state !== "current" && rt.state !== "kept") {
1228
+ return null;
1229
+ }
1230
+ if (rt.cli === void 0 || rt.hostsDir === void 0 || rt.entry === void 0 || rt.node === void 0) {
1231
+ return null;
1232
+ }
1233
+ return { version: rt.cli, hostsDir: rt.hostsDir, cliEntry: rt.entry, node: rt.node };
1234
+ }
1235
+ function runtimeData(rt) {
1236
+ if (rt === null) return null;
1237
+ return {
1238
+ state: rt.state,
1239
+ root: rt.root,
1240
+ ...rt.cli !== void 0 ? { cli: rt.cli } : {},
1241
+ ...rt.nodeVersion !== void 0 ? { nodeVersion: rt.nodeVersion } : {},
1242
+ ...rt.reason !== void 0 ? { reason: rt.reason } : {},
1243
+ ...rt.fix !== void 0 ? { fix: rt.fix } : {}
1244
+ };
1245
+ }
1246
+ async function recordClaudeProjects(dataDir, known, env, home) {
1247
+ const records = await recordedInstalls(env, home).catch(() => null);
1248
+ if (records === null || records.every((r) => r.projectPath === null)) return;
1249
+ const seen = /* @__PURE__ */ new Set([
1250
+ ...known,
1251
+ ...await Promise.all(known.map((dir) => realpath(dir).catch(() => dir)))
1252
+ ]);
1253
+ for (const { projectPath } of records) {
1254
+ if (projectPath === null || seen.has(projectPath)) continue;
1255
+ if ((await stat3(projectPath).catch(() => null))?.isDirectory() !== true) continue;
1256
+ seen.add(projectPath);
1257
+ await persistRouterProject(dataDir, projectPath).catch(() => void 0);
1258
+ }
1259
+ }
1260
+ function tilde(path, home) {
1261
+ return path === home || path.startsWith(`${home}${sep}`) ? `~${path.slice(home.length)}` : path;
1262
+ }
1263
+ function runtimeSentence(rt, home) {
1264
+ if (rt.state !== "active" || !rt.firstTime) return null;
1265
+ return `Runs from ${tilde(rt.root, home)} on its own Node ${rt.nodeVersion ?? ""}, so a Node upgrade or \`npm rm -g tenjin-cli\` no longer stops it.`;
1266
+ }
1267
+ function launcherSentence(launcher, home) {
1268
+ if (launcher === null) return null;
1269
+ if (launcher.state === "foreign") {
1270
+ const who = launcher.reason?.replace(/ is not Tenjin's$/, "") ?? launcher.paths[0] ?? "";
1271
+ return `${who} is not Tenjin's, so it was left as it is, and \`tenjin\` there runs that file instead of Tenjin's runtime. Move it aside and run \`tenjin install\` again to put Tenjin's there.`;
1272
+ }
1273
+ if (launcher.state === "failed") {
1274
+ const dir = launcher.paths[0] !== void 0 ? tilde(dirname3(launcher.paths[0]), home) : "";
1275
+ return `Tenjin's \`tenjin\` launcher could not be written to ${dir} (${launcher.reason ?? "unknown reason"}), so a terminal finds \`tenjin\` only through npm's copy; run \`tenjin install\` again to retry.`;
1276
+ }
1277
+ if ((launcher.state === "written" || launcher.state === "current") && !launcher.onPath) {
1278
+ return `~/.local/bin is not on your PATH, so a terminal will not find \`tenjin\` once npm's copy is gone (inside Claude Code the plugin's own \`tenjin\` is on the Bash tool's PATH). Add it: ${launcher.pathLine ?? ""}`;
1279
+ }
1280
+ return null;
1281
+ }
1282
+ function runtimeLines(ctx, rt, home) {
1283
+ if (rt === null || sharedResults.has(rt)) return [];
1284
+ const warn = (text) => paint(ctx.io, "yellow", `! ${text}`);
1285
+ const runs = runtimeSentence(rt, home);
1286
+ const launcher = launcherSentence(rt.launcher, home);
1287
+ return [...runs !== null ? [` ${runs}`] : [], ...launcher !== null ? [warn(launcher)] : []];
1288
+ }
1293
1289
  function claudeCodeData(claude) {
1294
1290
  return {
1295
1291
  binary: claude.binary?.path ?? null,
@@ -1309,24 +1305,40 @@ function registrationFix(plugin) {
1309
1305
  }
1310
1306
  return `Run \`tenjin doctor${flag}\` to see the cause, then run \`tenjin install${flag}\` again.`;
1311
1307
  }
1312
- function nextStep(plugin, claude, wallet, migration, asksQuestion) {
1308
+ var REPAIRABLE = /* @__PURE__ */ new Set([
1309
+ "passphrase_missing",
1310
+ "passphrase_wrong",
1311
+ "env_passphrase_wrong"
1312
+ ]);
1313
+ function repairStep(tty) {
1314
+ return tty ? `run \`tenjin wallet repair\` yourself ${REPAIR_CLAUSE}` : "ask the person to run `tenjin wallet repair` in their own terminal (never ask for the passphrase)";
1315
+ }
1316
+ function nextStep(plugin, claude, wallet, migration, asksQuestion, tty, command, env) {
1313
1317
  if (plugin.state === "failed") return registrationFix(plugin);
1318
+ const steps = todaysSteps(plugin, claude, wallet, migration, asksQuestion, command, env);
1319
+ const signing = wallet.signing;
1320
+ if (signing?.status === "blocked" && REPAIRABLE.has(signing.reason)) {
1321
+ steps.unshift(repairStep(tty));
1322
+ }
1323
+ return steps.join(", then ");
1324
+ }
1325
+ function todaysSteps(plugin, claude, wallet, migration, asksQuestion, command, env) {
1314
1326
  const steps = [];
1315
1327
  if (asksQuestion) {
1316
1328
  steps.push("ask the person the question in nextSteps, then run what the answer names");
1317
1329
  } else if (wallet.status === "created") {
1318
- steps.push("fund the wallet with `tenjin wallet fund`");
1330
+ steps.push(`fund the wallet with \`${command} wallet fund ${SUGGESTED_FUND_USD}\``);
1319
1331
  }
1320
1332
  if (plugin.state === "deferred") {
1321
1333
  steps.unshift("run `claude update`");
1322
1334
  steps.push(
1323
- "run `tenjin install` again; until then the earlier Tenjin setup keeps routing as before"
1335
+ `run \`${command} install\` again; until then the earlier Tenjin setup keeps routing as before`
1324
1336
  );
1325
- return steps.join(", then ");
1337
+ return steps;
1326
1338
  }
1327
1339
  if (!claude.meetsFloor) steps.unshift("run `claude update`");
1328
- steps.push(loadStep(settingsInstallStays(migration)));
1329
- return steps.join(", then ");
1340
+ steps.push(loadStep(settingsInstallStays(migration) || !claude.meetsFloor, env, command));
1341
+ return steps;
1330
1342
  }
1331
1343
  function settingsInstallStays(migration) {
1332
1344
  return migration.state === "pending" || migration.state === "blocked";
@@ -1352,7 +1364,7 @@ function statusLineNotice(migration) {
1352
1364
  }
1353
1365
  return null;
1354
1366
  }
1355
- function refreshNotices(plugin, claude, migration) {
1367
+ function refreshNotices(plugin, claude, migration, rt, home) {
1356
1368
  const out = [];
1357
1369
  if (plugin.state === "deferred") {
1358
1370
  out.push(
@@ -1365,11 +1377,20 @@ function refreshNotices(plugin, claude, migration) {
1365
1377
  }
1366
1378
  const status = statusLineNotice(migration);
1367
1379
  if (status !== null) out.push(status);
1380
+ if (rt !== null) out.push(...runtimeNotices(rt, home));
1381
+ return out;
1382
+ }
1383
+ function runtimeNotices(rt, home) {
1384
+ const out = [];
1385
+ const runs = runtimeSentence(rt, home);
1386
+ if (runs !== null) out.push(`Tenjin ${runs.charAt(0).toLowerCase()}${runs.slice(1)}`);
1387
+ const launcher = launcherSentence(rt.launcher, home);
1388
+ if (launcher !== null) out.push(launcher);
1368
1389
  return out;
1369
1390
  }
1370
1391
  var SHOW_NOT_RUN = "Show the person addresses as written, and never ask them to run a command.";
1371
- function spendStep(args) {
1372
- return spendStepFor(installCommand(args));
1392
+ function spendStep(args, command) {
1393
+ return spendStepFor(installCommand(args, command));
1373
1394
  }
1374
1395
  function spendStepFor(command) {
1375
1396
  const options = spendOptions(command);
@@ -1378,12 +1399,12 @@ function spendStepFor(command) {
1378
1399
  id: "spend",
1379
1400
  question: spendChoiceQuestion(),
1380
1401
  options,
1381
- next: `In this session, ask the person this question with your question tool, offering these two options in order with the defaults marked recommended. The defaults are already in effect. Use the defaults: run \`${byDefault.command}\`. Set my own limits: ask for the most per day in USD (or none for no daily limit) and the most per call in USD (at least 0.25), then run \`${custom.command}\` with their amounts. Run the command alone, never joined with another command, and do not ask again a question its output repeats. ${SHOW_NOT_RUN}`
1402
+ next: `${process.platform === "win32" ? "Use PowerShell for these commands. " : ""}In this session, ask the person this question with your question tool, offering these two options in order with the defaults marked recommended. The defaults are already in effect. Use the defaults: run \`${byDefault.command}\`. Set my own limits: ask for the most per day in USD (or none for no daily limit) and the most per call in USD (at least 0.25), then run \`${custom.command}\` with their amounts. Run the command alone, never joined with another command, and do not ask again a question its output repeats. ${SHOW_NOT_RUN}`
1382
1403
  };
1383
1404
  }
1384
- function installCommand(args) {
1405
+ function installCommand(args, command) {
1385
1406
  return [
1386
- "tenjin install",
1407
+ `${command} install`,
1387
1408
  ...args.project === true ? ["--project"] : [],
1388
1409
  ...args.noWallet === true ? ["--no-wallet"] : []
1389
1410
  ].join(" ");
@@ -1413,9 +1434,9 @@ function namedLimits(args) {
1413
1434
  }
1414
1435
  return { limits, keys };
1415
1436
  }
1416
- var FUND_QUESTION = `Do you want to add $${SUGGESTED_FUND_USD} to your Tenjin wallet now?`;
1437
+ var FUND_QUESTION = `Add $${SUGGESTED_FUND_USD} to Tenjin now?`;
1417
1438
  var FUND_COMMAND = `tenjin wallet fund ${SUGGESTED_FUND_USD}`;
1418
- async function fundStep(wallet, rpcUrl, deps) {
1439
+ async function fundStep(wallet, rpcUrl, deps, command) {
1419
1440
  const address = wallet.address;
1420
1441
  if (address === void 0 || wallet.status !== "created" && wallet.status !== "existing") {
1421
1442
  return void 0;
@@ -1425,32 +1446,39 @@ async function fundStep(wallet, rpcUrl, deps) {
1425
1446
  () => null
1426
1447
  );
1427
1448
  if (funded === true) return void 0;
1428
- const show = `To add funds, send USDC on Base to ${address}.`;
1449
+ if (funded === null) {
1450
+ return {
1451
+ warning: "Could not check your Tenjin funds. Your usual tools keep working. Ask your agent to check your funds later; this check failing does not mean you need to add money again."
1452
+ };
1453
+ }
1454
+ const show = "You can ask your agent to add funds to Tenjin later. Paid tools need funds; your usual tools keep working.";
1429
1455
  return {
1430
- id: "fund",
1431
- question: FUND_QUESTION,
1432
- options: [
1433
- {
1434
- id: "fund",
1435
- label: "Yes, open the funding page",
1436
- recommended: false,
1437
- command: FUND_COMMAND
1438
- },
1439
- { id: "later", label: "Not now", recommended: false, command: null }
1440
- ],
1441
- next: `The install is done. Ask the person this question with your question tool. On "Yes, open the funding page", run \`${FUND_COMMAND}\` alone, in the same turn. On "Not now", run nothing and show the person this for later: ${show} Never run \`${FUND_COMMAND}\` without this yes. ${SHOW_NOT_RUN}`,
1442
- address,
1443
- show
1456
+ step: {
1457
+ id: "fund",
1458
+ question: FUND_QUESTION,
1459
+ options: [
1460
+ {
1461
+ id: "fund",
1462
+ label: `Add $${SUGGESTED_FUND_USD}`,
1463
+ recommended: false,
1464
+ command
1465
+ },
1466
+ { id: "later", label: "Not now", recommended: false, command: null }
1467
+ ],
1468
+ next: `${process.platform === "win32" ? "Use PowerShell for this command. " : ""}The install is done. Ask the person this question with your question tool. On "Add $${SUGGESTED_FUND_USD}", run \`${command}\` alone, in the same turn, then follow its nextStep. On "Not now", run nothing and show the person this for later: ${show} The address is an alternative only if they ask to transfer funds directly. Never run \`${command}\` without this yes. ${SHOW_NOT_RUN}`,
1469
+ address,
1470
+ show
1471
+ }
1444
1472
  };
1445
1473
  }
1446
1474
  async function defaultBalance(address, rpcUrl) {
1447
- const { getUsdcBalance } = await import("./usdc-OGOGEHV2.js");
1475
+ const { getUsdcBalance } = await import("./usdc-VG4CIOUK.js");
1448
1476
  return getUsdcBalance(address, rpcUrl);
1449
1477
  }
1450
1478
  function fundLines(fund) {
1451
1479
  return [
1452
1480
  ` Ask the person: ${fund.question}`,
1453
- ` Yes, open the funding page: ${FUND_COMMAND}`,
1481
+ ` Add $${SUGGESTED_FUND_USD}: ${fund.options[0]?.command ?? FUND_COMMAND}`,
1454
1482
  ` Not now: run nothing, show them: ${fund.show}`
1455
1483
  ];
1456
1484
  }
@@ -1532,8 +1560,46 @@ function effectiveLimits(policy) {
1532
1560
  };
1533
1561
  }
1534
1562
  function walletLines(ctx, ok, w) {
1535
- if (w.status === "created") return [`${ok} Wallet created: ${w.address}`];
1536
- if (w.status === "existing") return [`${ok} Wallet: ${w.address}`];
1563
+ const warn = (text) => paint(ctx.io, "yellow", text);
1564
+ if (w.status === "created" || w.status === "existing") {
1565
+ const a = w.address ?? "";
1566
+ const signing = w.signing;
1567
+ const tty = ctx.io.isTTY;
1568
+ if (signing?.status === "blocked") {
1569
+ const wallet = Object.prototype.hasOwnProperty.call(WALLET_REASONS, signing.reason) ? WALLET_REASONS[signing.reason] : void 0;
1570
+ return [
1571
+ warn(`! Wallet ${a} cannot be unlocked by Claude Code: ${signing.detail}.`),
1572
+ ` ${tty ? wallet?.fix ?? signing.fix : agentFixFor(signing.reason, signing.fix)}`
1573
+ ];
1574
+ }
1575
+ if (signing?.status === "unknown") {
1576
+ return [
1577
+ warn(`! Wallet: ${a}; could not check that it unlocks (${signing.detail}).`),
1578
+ " Run `tenjin doctor` to check it again."
1579
+ ];
1580
+ }
1581
+ if (w.shellOnly === "key") {
1582
+ return [
1583
+ warn(
1584
+ `! Wallet: ${a} signs here only through TENJIN_WALLET_KEY in this shell; Claude Code must have the same variable.`
1585
+ )
1586
+ ];
1587
+ }
1588
+ if (w.shellOnly === "passphrase") {
1589
+ return [
1590
+ warn(
1591
+ tty ? `! Wallet: ${a} unlocks here only through TENJIN_WALLET_PASSPHRASE in this shell; Claude Code must have the same variable, or run \`tenjin wallet repair\` yourself to store the passphrase ${REPAIR_CLAUSE}.` : `! Wallet: ${a} unlocks here only through TENJIN_WALLET_PASSPHRASE in this shell; Claude Code must have the same variable, or ask the person to run \`tenjin wallet repair\` in their own terminal to store the passphrase. Never ask for the passphrase.`
1592
+ )
1593
+ ];
1594
+ }
1595
+ if (w.status === "created") {
1596
+ return [
1597
+ `${ok} Wallet created: ${a}`,
1598
+ ...w.passphrase !== void 0 ? [` ${w.passphrase.note}`] : []
1599
+ ];
1600
+ }
1601
+ return [`${ok} Wallet: ${a}`];
1602
+ }
1537
1603
  if (w.reason === "flag") return [" No wallet yet. Create one with: tenjin wallet create"];
1538
1604
  return [
1539
1605
  paint(ctx.io, "yellow", `! No wallet was created. ${w.warning ?? ""}`.trimEnd()),
@@ -1604,20 +1670,23 @@ function lines(ctx, s) {
1604
1670
  ];
1605
1671
  return [
1606
1672
  s.plugin.state === "failed" ? warn("Tenjin could not finish setting up Claude Code") : s.plugin.state === "deferred" ? warn("Tenjin keeps its earlier Claude Code setup until Claude Code is updated") : `${ok} Tenjin is set up for Claude Code (plugin ${s.plugin.id ?? PLUGIN_ID})`,
1607
- ...s.plugin.scope === "local" && s.plugin.state !== "failed" ? [" For this project only; check it with: tenjin doctor --project"] : [],
1673
+ ...s.plugin.scope === "local" && s.plugin.state !== "failed" ? [` For this project only; check it with: ${continuationCommand(s.rt)} doctor --project`] : [],
1674
+ ...runtimeLines(ctx, s.rt, s.home),
1608
1675
  ...walletLines(ctx, ok, s.wallet),
1609
1676
  ...spend,
1610
1677
  ...s.fund !== void 0 ? fundLines(s.fund) : [],
1678
+ ...s.fundingWarning !== void 0 ? [warn(s.fundingWarning)] : [],
1611
1679
  ...pluginLines(ctx, s.plugin),
1612
1680
  ...claudeLines(ctx, s.claude),
1613
1681
  ...migrationLines(ctx, s.migration),
1614
1682
  ...router,
1615
1683
  "",
1616
- `Next: ${nextStep(s.plugin, s.claude, s.wallet, s.migration, s.asks)}`
1684
+ `Next: ${nextStep(s.plugin, s.claude, s.wallet, s.migration, s.asks, ctx.io.isTTY, continuationCommand(s.rt), s.env)}`
1617
1685
  ];
1618
1686
  }
1619
- function refreshLines(ctx, plugin, claude, migration) {
1687
+ function refreshLines(ctx, plugin, claude, migration, rt, home) {
1620
1688
  const issues = [
1689
+ ...runtimeLines(ctx, rt, home),
1621
1690
  ...pluginLines(ctx, plugin),
1622
1691
  ...claudeLines(ctx, claude),
1623
1692
  ...migrationLines(ctx, migration)
@@ -1628,11 +1697,46 @@ function refreshLines(ctx, plugin, claude, migration) {
1628
1697
 
1629
1698
  // src/commands/update.ts
1630
1699
  var INSTALL_TIMEOUT_MS = 3e5;
1700
+ var STAGE_TIMEOUT_MS = 12e4;
1701
+ var NODE_TIMEOUT_MS = 3e5;
1702
+ var BACKGROUND_COOLDOWN_MS = 24 * 60 * 6e4;
1631
1703
  function resolveManager(manager, deps) {
1632
1704
  const script = deps.managerScript !== void 0 ? deps.managerScript : resolveManagerScript(manager, process.execPath);
1633
1705
  return script === null ? { cmd: MANAGERS[manager].bin, prefix: [] } : { cmd: process.execPath, prefix: [script] };
1634
1706
  }
1635
1707
  async function runUpdate(opts, ctx, deps = {}) {
1708
+ if (opts.background !== true) return update(opts, ctx, deps);
1709
+ const root = deps.runtimeRoot ?? runtimeDir(ctx.dataDir);
1710
+ const [{ recordAutoUpdate }, { readRuntimeState }] = await Promise.all([
1711
+ import("./auto-update-Y24UL56V.js"),
1712
+ import("./runtime-layout-WIDILZ6K.js")
1713
+ ]);
1714
+ const from = readRuntimeState(root)?.current.cli;
1715
+ const record = (r) => {
1716
+ if (!existsSync2(root)) return;
1717
+ try {
1718
+ recordAutoUpdate(root, { finishedAt: (/* @__PURE__ */ new Date()).toISOString(), ...r });
1719
+ } catch {
1720
+ }
1721
+ };
1722
+ try {
1723
+ const result = await update(opts, ctx, deps);
1724
+ const d = result.data;
1725
+ record(
1726
+ d.skipped !== void 0 ? { outcome: "skipped", reason: d.skipped } : d.updated === true ? { outcome: "updated", from: d.current, to: d.latest } : { outcome: "current", from: d.current, to: d.current }
1727
+ );
1728
+ return result;
1729
+ } catch (err) {
1730
+ const reason = sanitizeForTerminal(err instanceof Error ? err.message : String(err)).trim();
1731
+ record({
1732
+ outcome: "failed",
1733
+ ...from !== void 0 ? { from } : {},
1734
+ reason: reason.slice(0, REASON_LIMIT)
1735
+ });
1736
+ throw err;
1737
+ }
1738
+ }
1739
+ async function update(opts, ctx, deps) {
1636
1740
  const current = deps.currentVersion ?? package_default.version;
1637
1741
  const channel = channelTag(current);
1638
1742
  const moduleDir = deps.moduleDir ?? fileURLToPath3(new URL(".", import.meta.url));
@@ -1651,7 +1755,15 @@ async function runUpdate(opts, ctx, deps = {}) {
1651
1755
  fix: "Check access to registry.npmjs.org and retry"
1652
1756
  });
1653
1757
  }
1654
- const latest = resolveTarget(current, tags);
1758
+ const runtime = await runtimeHere(ctx, deps, moduleDir);
1759
+ if (opts.background === true && runtime === null) {
1760
+ return {
1761
+ data: { skipped: "no runtime" },
1762
+ humanLines: ["Nothing to update in the background: Tenjin's runtime is not set up here."]
1763
+ };
1764
+ }
1765
+ const base = runtime?.current ?? current;
1766
+ const latest = resolveTarget(base, tags);
1655
1767
  if (latest === null) {
1656
1768
  const raw = tags[channel];
1657
1769
  throw raw === void 0 ? new CliError("RESOURCE_NOT_FOUND", "npm has no published tenjin-cli on the latest tag", {
@@ -1665,30 +1777,48 @@ async function runUpdate(opts, ctx, deps = {}) {
1665
1777
  }
1666
1778
  );
1667
1779
  }
1668
- const updateAvailable = isNewer(latest, current);
1669
- const data = (updated) => ({
1670
- current,
1780
+ const updateAvailable = isNewer(latest, base);
1781
+ const data = (updated2) => ({
1782
+ current: base,
1671
1783
  latest,
1672
1784
  updateAvailable,
1673
- updated
1785
+ updated: updated2
1674
1786
  });
1675
1787
  if (!updateAvailable) {
1676
1788
  return {
1677
1789
  data: data(false),
1678
- humanLines: [`tenjin-cli ${current} is up to date`]
1790
+ humanLines: [`tenjin-cli ${base} is up to date`]
1679
1791
  };
1680
1792
  }
1681
1793
  if (opts.check) {
1682
1794
  return {
1683
1795
  data: data(false),
1684
1796
  humanLines: [
1685
- `tenjin-cli ${latest} is available (you have ${current}).`,
1797
+ `tenjin-cli ${latest} is available (you have ${base}).`,
1686
1798
  "Run tenjin update to install it."
1687
1799
  ]
1688
1800
  };
1689
1801
  }
1802
+ if (opts.background === true) {
1803
+ const wait = await tooNewForBackground(latest, ctx, deps);
1804
+ if (wait !== null) {
1805
+ return {
1806
+ data: { ...data(false), skipped: wait },
1807
+ humanLines: [`${wait}; the background update takes a release a day after it is published.`]
1808
+ };
1809
+ }
1810
+ }
1811
+ if (runtime !== null) {
1812
+ return runtimeUpdate(ctx, deps, { ...runtime, base, latest, current, moduleDir, data });
1813
+ }
1814
+ await refuseRuntimeElsewhere(ctx, moduleDir, deps.homeDir ?? homedir2());
1690
1815
  const spec = `tenjin-cli@${latest}`;
1691
1816
  refuse(moduleDir, { check: false, spec });
1817
+ const { checkReleaseProvenance } = await import("./runtime-UZOKSUZX.js");
1818
+ await checkReleaseProvenance(latest, {
1819
+ timeoutMs: ctx.flags.timeout,
1820
+ fetchImpl: deps.fetchImpl
1821
+ });
1692
1822
  const human = ctx.io.isTTY && !ctx.flags.json;
1693
1823
  let tail = "";
1694
1824
  const onOutput = (chunk) => {
@@ -1731,14 +1861,18 @@ async function runUpdate(opts, ctx, deps = {}) {
1731
1861
  ctx.io,
1732
1862
  `tenjin update: replaced the global tenjin-cli with ${latest} via ${manager}`
1733
1863
  );
1734
- const refresh = await refreshProfiles(ctx, deps);
1864
+ const { refresh } = await refreshProfiles(ctx, deps, npmLaunch(deps));
1865
+ return updated(deps, data(true), refresh, [`Updated tenjin-cli ${current} -> ${latest}.`]);
1866
+ }
1867
+ async function updated(deps, data, refresh, head, version) {
1735
1868
  const servers = await readMcpServers(deps, {
1736
- settingsInstallPending: refresh.settingsInstallPending
1869
+ settingsInstallPending: refresh.settingsInstallPending,
1870
+ ...version !== void 0 ? { version } : {}
1737
1871
  });
1738
1872
  return {
1739
- data: { ...data(true), refresh, mcpServer: servers.check },
1873
+ data: { ...data, refresh, mcpServer: servers.check },
1740
1874
  humanLines: [
1741
- `Updated tenjin-cli ${current} -> ${latest}.`,
1875
+ ...head,
1742
1876
  ...refreshLines2(refresh),
1743
1877
  ...projectLines(refresh),
1744
1878
  ...refresh.notices,
@@ -1746,8 +1880,132 @@ async function runUpdate(opts, ctx, deps = {}) {
1746
1880
  ]
1747
1881
  };
1748
1882
  }
1883
+ async function runtimeHere(ctx, deps, moduleDir) {
1884
+ if (resolve2(ctx.dataDir) !== resolve2(defaultDataDir(deps.homeDir ?? homedir2()))) return null;
1885
+ const { readRuntimeState, runtimeBuild: runtimeBuild2 } = await import("./runtime-layout-WIDILZ6K.js");
1886
+ const root = deps.runtimeRoot ?? runtimeDir(ctx.dataDir);
1887
+ const state = readRuntimeState(root);
1888
+ const inRuntime = runtimeBuild2(moduleDir) !== null;
1889
+ if (state === null && !inRuntime) return null;
1890
+ return { root, current: state?.current.cli ?? null, inRuntime };
1891
+ }
1892
+ async function tooNewForBackground(latest, ctx, deps) {
1893
+ const answer = await fetchPublishTime(latest, {
1894
+ fetchImpl: deps.fetchImpl,
1895
+ timeoutMs: ctx.flags.timeout
1896
+ });
1897
+ if (answer === null) {
1898
+ throw new CliError("NETWORK_ERROR", `Could not read when tenjin-cli ${latest} was published`, {
1899
+ fix: "Check access to registry.npmjs.org and retry"
1900
+ });
1901
+ }
1902
+ if (answer.publishedAt === null) return `npm names no publish time for tenjin-cli ${latest}`;
1903
+ const age = (deps.now ?? Date.now)() - answer.publishedAt;
1904
+ return age >= BACKGROUND_COOLDOWN_MS ? null : `tenjin-cli ${latest} was published under 24 hours ago`;
1905
+ }
1906
+ async function refuseRuntimeElsewhere(ctx, moduleDir, home) {
1907
+ const { runtimeBuild: runtimeBuild2 } = await import("./runtime-layout-WIDILZ6K.js");
1908
+ if (runtimeBuild2(moduleDir) === null) return;
1909
+ throw new CliError(
1910
+ "REFUSED",
1911
+ `This tenjin runs from Tenjin's runtime, which only the default data dir (${tilde2(defaultDataDir(home), home)}) uses, and TENJIN_DATA_DIR is ${tilde2(ctx.dataDir, home)}, so nothing was updated`,
1912
+ {
1913
+ fix: "Run `tenjin update` with TENJIN_DATA_DIR unset: the runtime belongs to the default data dir. Another data dir runs on an npm copy, updated with `npm i -g tenjin-cli@latest`."
1914
+ }
1915
+ );
1916
+ }
1917
+ async function runtimeUpdate(ctx, deps, o) {
1918
+ const { root, base, latest } = o;
1919
+ const [rt, layout] = await Promise.all([
1920
+ import("./runtime-UZOKSUZX.js"),
1921
+ import("./runtime-layout-WIDILZ6K.js")
1922
+ ]);
1923
+ const stays = `so ${base} stays`;
1924
+ let stage;
1925
+ if (latest === o.current && !o.inRuntime) {
1926
+ const packageRoot = rt.packageRootOf(o.moduleDir);
1927
+ if (packageRoot === null) {
1928
+ throw new CliError(
1929
+ "UPDATE_FAILED",
1930
+ `tenjin-cli ${latest} cannot find its own package, ${stays}`,
1931
+ {
1932
+ fix: RUNTIME_MISSING_FIX
1933
+ }
1934
+ );
1935
+ }
1936
+ stage = await rt.stageSelf(root, packageRoot);
1937
+ } else {
1938
+ stage = await (deps.stage ?? rt.stageTarball)(root, latest, {
1939
+ timeoutMs: STAGE_TIMEOUT_MS,
1940
+ fetchImpl: deps.fetchImpl
1941
+ }).catch((err) => {
1942
+ throw proxyNamed(err, deps);
1943
+ });
1944
+ }
1945
+ let node;
1946
+ try {
1947
+ const pin = rt.readNodePin(stage);
1948
+ if (pin === null) {
1949
+ throw new CliError("UPDATE_FAILED", `tenjin-cli ${latest} carries no Node pin, ${stays}`, {
1950
+ fix: `Nothing to do: ${base} keeps running. Run \`tenjin update\` again after the next release.`
1951
+ });
1952
+ }
1953
+ node = await (deps.ensure ?? rt.ensureNode)(root, pin, {
1954
+ timeoutMs: NODE_TIMEOUT_MS,
1955
+ fetchImpl: deps.fetchImpl
1956
+ });
1957
+ await (deps.place ?? rt.placeVersion)(root, stage, latest);
1958
+ } catch (err) {
1959
+ await rm2(stage, { recursive: true, force: true }).catch(() => void 0);
1960
+ throw proxyNamed(err, deps);
1961
+ }
1962
+ const home = deps.homeDir ?? homedir2();
1963
+ emitWriteNotice(ctx.io, `tenjin update: staged tenjin-cli ${latest} in ${tilde2(root, home)}`);
1964
+ const { refresh, homeTail } = await refreshProfiles(ctx, deps, {
1965
+ node,
1966
+ entry: layout.versionEntry(root, latest)
1967
+ });
1968
+ if (layout.readRuntimeState(root)?.current.cli !== latest) {
1969
+ throw new CliError("UPDATE_FAILED", `tenjin-cli ${latest} did not pass its checks, ${stays}`, {
1970
+ fix: "Run `tenjin update` again; if it fails again, run `tenjin doctor`",
1971
+ details: {
1972
+ reason: refresh.failed[0]?.reason ?? runtimeReason(envelopeData(homeTail)) ?? "The new version did not switch the runtime to itself.",
1973
+ output: homeTail.slice(-2e3)
1974
+ }
1975
+ });
1976
+ }
1977
+ return updated(
1978
+ deps,
1979
+ o.data(true),
1980
+ refresh,
1981
+ [
1982
+ `Updated tenjin-cli ${base} -> ${latest}.`,
1983
+ `The previous version (${base}) stays as the fallback.`
1984
+ ],
1985
+ latest
1986
+ );
1987
+ }
1988
+ function proxyNamed(err, deps) {
1989
+ if (!(err instanceof CliError) || err.code !== "NETWORK_ERROR") return err;
1990
+ const skipped = proxySkipped(process.env, deps.proxySupported);
1991
+ if (skipped === null) return err;
1992
+ const step2 = proxyNodeStep("tenjin update");
1993
+ return new CliError("NETWORK_ERROR", `${err.message}: ${skipped}`, {
1994
+ fix: `${step2.charAt(0).toUpperCase()}${step2.slice(1)}.`,
1995
+ cause: err
1996
+ });
1997
+ }
1998
+ function runtimeReason(data) {
1999
+ const reason = data?.runtime?.reason;
2000
+ if (typeof reason !== "string") return void 0;
2001
+ const text = sanitizeForTerminal(reason).trim();
2002
+ return text.length > 0 ? text.slice(0, REASON_LIMIT) : void 0;
2003
+ }
2004
+ function tilde2(path, home) {
2005
+ return path === home || path.startsWith(`${home}${sep2}`) ? `~${path.slice(home.length)}` : path;
2006
+ }
1749
2007
  var REFRESH_TIMEOUT_MS = 6e4;
1750
- async function refreshProfiles(ctx, deps) {
2008
+ async function refreshProfiles(ctx, deps, launch) {
1751
2009
  const home = deps.homeDir ?? homedir2();
1752
2010
  const candidates = [ctx.dataDir];
1753
2011
  const fixFor = (dataDir) => manualFix(dataDir, home, ctx.dataDir);
@@ -1757,16 +2015,18 @@ async function refreshProfiles(ctx, deps) {
1757
2015
  if (isExistingDir(dataDir)) profiles.push(dataDir);
1758
2016
  else unrun.push({ dataDir, reason: "It is not a directory.", fix: fixFor(dataDir) });
1759
2017
  }
1760
- const entry = versionFreeEntry(deps.refreshCommand ?? process.argv[1]);
1761
- if (entry === null) {
2018
+ if (launch === null) {
1762
2019
  const reason = "This build has no entry the update could safely re-execute.";
1763
2020
  return {
1764
- profiles: [],
1765
- failed: candidates.map((d) => ({ dataDir: d, reason, fix: fixFor(d) })),
1766
- notices: [],
1767
- settingsInstallPending: false,
1768
- projects: [],
1769
- projectsFailed: []
2021
+ refresh: {
2022
+ profiles: [],
2023
+ failed: candidates.map((d) => ({ dataDir: d, reason, fix: fixFor(d) })),
2024
+ notices: [],
2025
+ settingsInstallPending: false,
2026
+ projects: [],
2027
+ projectsFailed: []
2028
+ },
2029
+ homeTail: ""
1770
2030
  };
1771
2031
  }
1772
2032
  const failed = [...unrun];
@@ -1779,8 +2039,10 @@ async function refreshProfiles(ctx, deps) {
1779
2039
  settingsInstallPending = true;
1780
2040
  }
1781
2041
  };
2042
+ let homeTail = "";
1782
2043
  for (const dataDir of profiles) {
1783
- const { outcome, tail } = await refreshChild(entry, homedir2(), dataDir, deps);
2044
+ const { outcome, tail } = await refreshChild(launch, homedir2(), dataDir, deps);
2045
+ homeTail = tail;
1784
2046
  if (outcome.kind !== "exit" || outcome.code !== 0) {
1785
2047
  failed.push({ dataDir, reason: refreshReason(outcome, tail), fix: fixFor(dataDir) });
1786
2048
  continue;
@@ -1796,7 +2058,7 @@ async function refreshProfiles(ctx, deps) {
1796
2058
  await forget();
1797
2059
  continue;
1798
2060
  }
1799
- const { outcome, tail } = await refreshChild(entry, project, ctx.dataDir, deps, ["--project"]);
2061
+ const { outcome, tail } = await refreshChild(launch, project, ctx.dataDir, deps, ["--project"]);
1800
2062
  if (outcome.kind !== "exit" || outcome.code !== 0) {
1801
2063
  projectsFailed.push({
1802
2064
  project,
@@ -1808,13 +2070,20 @@ async function refreshProfiles(ctx, deps) {
1808
2070
  projects.push(project);
1809
2071
  heard(envelopeData(tail));
1810
2072
  }
1811
- return { profiles, failed, notices, settingsInstallPending, projects, projectsFailed };
2073
+ return {
2074
+ refresh: { profiles, failed, notices, settingsInstallPending, projects, projectsFailed },
2075
+ homeTail
2076
+ };
1812
2077
  }
1813
- async function refreshChild(entry, cwd, dataDir, deps, flags = []) {
2078
+ function npmLaunch(deps) {
2079
+ const entry = versionFreeEntry(deps.refreshCommand ?? process.argv[1]);
2080
+ return entry === null ? null : { node: process.execPath, entry };
2081
+ }
2082
+ async function refreshChild(launch, cwd, dataDir, deps, flags = []) {
1814
2083
  let tail = "";
1815
2084
  const outcome = await (deps.spawnImpl ?? spawnCapture)(
1816
- process.execPath,
1817
- [entry, "install", "--refresh", ...flags],
2085
+ launch.node,
2086
+ [launch.entry, "install", "--refresh", ...flags],
1818
2087
  {
1819
2088
  cwd,
1820
2089
  timeoutMs: REFRESH_TIMEOUT_MS,
@@ -1875,21 +2144,21 @@ function envelopeMessage(output) {
1875
2144
  return void 0;
1876
2145
  }
1877
2146
  function isExistingDir(path) {
1878
- return statSync2(path, { throwIfNoEntry: false })?.isDirectory() === true;
2147
+ return statSync(path, { throwIfNoEntry: false })?.isDirectory() === true;
1879
2148
  }
1880
2149
  function manualFix(dataDir, home, invoking) {
1881
- const bare = resolve(dataDir) === resolve(defaultDataDir(home)) && resolve(dataDir) === resolve(invoking);
2150
+ const bare = resolve2(dataDir) === resolve2(defaultDataDir(home)) && resolve2(dataDir) === resolve2(invoking);
1882
2151
  const command = bare ? "tenjin install" : `TENJIN_DATA_DIR=${dataDir} tenjin install`;
1883
2152
  return `Run \`${command}\` to bring the Claude Code plugin up to this version.`;
1884
2153
  }
1885
2154
  function versionFreeEntry(entry) {
1886
2155
  if (entry === void 0 || entry.length === 0) return null;
1887
- const segs = entry.split(sep3);
2156
+ const segs = entry.split(sep2);
1888
2157
  const store = segs.indexOf(".pnpm");
1889
- if (store === -1) return segs.join(sep3);
2158
+ if (store === -1) return segs.join(sep2);
1890
2159
  const inner = segs.indexOf("node_modules", store);
1891
2160
  if (inner === -1) return null;
1892
- const derived = [...segs.slice(0, store), ...segs.slice(inner + 1)].join(sep3);
2161
+ const derived = [...segs.slice(0, store), ...segs.slice(inner + 1)].join(sep2);
1893
2162
  return existsSync2(derived) ? derived : null;
1894
2163
  }
1895
2164
  function refreshLines2(refresh) {
@@ -1952,14 +2221,15 @@ var spawnCapture = (cmd, args, opts, onOutput) => new Promise((res) => {
1952
2221
  export {
1953
2222
  inspectLegacyInstall,
1954
2223
  removeLegacyInstall,
1955
- readMcpServers,
2224
+ BACKGROUND_COOLDOWN_MS,
1956
2225
  runUpdate,
1957
2226
  versionFreeEntry,
1958
2227
  spawnCapture,
1959
- removePluginFolder,
1960
2228
  folderFor,
1961
2229
  registerPlugin,
2230
+ marketplaceAdded,
1962
2231
  ownMarketplace,
2232
+ recordedInstalls,
1963
2233
  packageHostsDir,
1964
2234
  packageMod,
1965
2235
  packageCliEntry,
@@ -1967,15 +2237,25 @@ export {
1967
2237
  folderState,
1968
2238
  probeRouter,
1969
2239
  DISCLOSURE,
1970
- RELOAD_STEP,
1971
2240
  NEW_SESSION_STEP,
2241
+ RELOAD_STEP,
1972
2242
  loadStep,
1973
2243
  settingsInstallPaths,
1974
2244
  pluginProof,
1975
2245
  migrateSettingsInstall,
1976
2246
  projectInstallHere,
1977
2247
  projectInstallAt,
2248
+ NOTHING_TO_REFRESH,
1978
2249
  runRouterInstall,
2250
+ defaultRuntime,
2251
+ runtimeOncePerRun,
2252
+ hasRuntime,
2253
+ assertPluginInstallation,
2254
+ continuationCommand,
2255
+ requireRuntime,
2256
+ runtimeData,
2257
+ tilde,
2258
+ runtimeLines,
1979
2259
  SHOW_NOT_RUN,
1980
2260
  spendStepFor,
1981
2261
  namedLimits,
@@ -1984,4 +2264,4 @@ export {
1984
2264
  approveLimits,
1985
2265
  effectiveLimits
1986
2266
  };
1987
- //# sourceMappingURL=chunk-77TCKDEC.js.map
2267
+ //# sourceMappingURL=chunk-ILNIZ5I2.js.map