tenjin-cli 0.1.0-alpha.30 → 0.1.0-alpha.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -116
- package/dist/{_esm-CE7KNONL.js → _esm-RLLC72MS.js} +127 -131
- package/dist/alive-MROUMFH3.js +38 -0
- package/dist/auto-update-OPWMRZLS.js +22 -0
- package/dist/{ccip-7RMRLAGV.js → ccip-DHDFKTQV.js} +2 -2
- package/dist/chunk-2GNOFONN.js +560 -0
- package/dist/chunk-2GNOFONN.js.map +1 -0
- package/dist/{chunk-TTNESUPQ.js → chunk-2GP3HRYK.js} +2120 -193
- package/dist/chunk-2GP3HRYK.js.map +1 -0
- package/dist/chunk-3623BLPV.js +184 -0
- package/dist/chunk-3623BLPV.js.map +1 -0
- package/dist/chunk-3AIHRXKO.js +72 -0
- package/dist/chunk-3AIHRXKO.js.map +1 -0
- package/dist/chunk-3DIL66VX.js +120 -0
- package/dist/chunk-3DIL66VX.js.map +1 -0
- package/dist/{chunk-S4SAZ7OD.js → chunk-3FMZGI7I.js} +12 -2
- package/dist/{chunk-S4SAZ7OD.js.map → chunk-3FMZGI7I.js.map} +1 -1
- package/dist/chunk-3UCIG4TG.js +65 -0
- package/dist/chunk-3UCIG4TG.js.map +1 -0
- package/dist/{chunk-LFZJM56J.js → chunk-445VQTVM.js} +3 -3
- package/dist/{chunk-A36LQPHV.js → chunk-4LMUQMBH.js} +1 -1
- package/dist/{chunk-A36LQPHV.js.map → chunk-4LMUQMBH.js.map} +1 -1
- package/dist/{chunk-RAULEAZ6.js → chunk-4USCZ2NI.js} +3 -3
- package/dist/chunk-62KNUYWD.js +111 -0
- package/dist/chunk-62KNUYWD.js.map +1 -0
- package/dist/{chunk-POUWHWID.js → chunk-6CMM6YCB.js} +3 -3
- package/dist/{chunk-POUWHWID.js.map → chunk-6CMM6YCB.js.map} +1 -1
- package/dist/chunk-7WEQQJLG.js +68 -0
- package/dist/chunk-7WEQQJLG.js.map +1 -0
- package/dist/{chunk-3O2BQIF6.js → chunk-AD226HDR.js} +344 -534
- package/dist/chunk-AD226HDR.js.map +1 -0
- package/dist/chunk-ADV4LDTB.js +106 -0
- package/dist/chunk-ADV4LDTB.js.map +1 -0
- package/dist/{chunk-AWFUPKTM.js → chunk-AV5NZMYO.js} +15 -7
- package/dist/{chunk-AWFUPKTM.js.map → chunk-AV5NZMYO.js.map} +1 -1
- package/dist/chunk-B7EM4GGF.js +198 -0
- package/dist/chunk-B7EM4GGF.js.map +1 -0
- package/dist/chunk-BFDQ4WNW.js +119 -0
- package/dist/chunk-BFDQ4WNW.js.map +1 -0
- package/dist/{chunk-OSYTBCUC.js → chunk-BI673VEJ.js} +531 -503
- package/dist/chunk-BI673VEJ.js.map +1 -0
- package/dist/chunk-CEXSOI5R.js +808 -0
- package/dist/chunk-CEXSOI5R.js.map +1 -0
- package/dist/{chunk-OK2TDZQU.js → chunk-CISYM4EO.js} +9 -7
- package/dist/chunk-CISYM4EO.js.map +1 -0
- package/dist/{chunk-VFMQTSXG.js → chunk-D3ZURCG7.js} +3 -3
- package/dist/chunk-D5TOQSO4.js +474 -0
- package/dist/chunk-D5TOQSO4.js.map +1 -0
- package/dist/{chunk-P7LABKCW.js → chunk-DOQGNFHM.js} +33 -2
- package/dist/{chunk-P7LABKCW.js.map → chunk-DOQGNFHM.js.map} +1 -1
- package/dist/{chunk-QUVVWYJW.js → chunk-DRDUIZIA.js} +11 -9
- package/dist/{chunk-QUVVWYJW.js.map → chunk-DRDUIZIA.js.map} +1 -1
- package/dist/{chunk-O2FRQ2L2.js → chunk-DW4YTVR3.js} +5 -65
- package/dist/chunk-DW4YTVR3.js.map +1 -0
- package/dist/chunk-E7LGOMH6.js +449 -0
- package/dist/chunk-E7LGOMH6.js.map +1 -0
- package/dist/chunk-E7SW44LM.js +138 -0
- package/dist/chunk-E7SW44LM.js.map +1 -0
- package/dist/chunk-EDJWHDDL.js +33 -0
- package/dist/chunk-EDJWHDDL.js.map +1 -0
- package/dist/chunk-F3ED5WTR.js +13 -0
- package/dist/chunk-F3ED5WTR.js.map +1 -0
- package/dist/chunk-G75OPGAK.js +111 -0
- package/dist/chunk-G75OPGAK.js.map +1 -0
- package/dist/{chunk-YFQOA5AU.js → chunk-GAKUQHKA.js} +13 -17
- package/dist/{chunk-YFQOA5AU.js.map → chunk-GAKUQHKA.js.map} +1 -1
- package/dist/{chunk-PAYV4XUA.js → chunk-HDPUXS3Z.js} +20 -49
- package/dist/chunk-HDPUXS3Z.js.map +1 -0
- package/dist/{chunk-ORWL5BSN.js → chunk-HGZEPQUT.js} +2 -2
- package/dist/{chunk-HPWO4O6S.js → chunk-HREHWL32.js} +4 -4
- package/dist/{chunk-HPWO4O6S.js.map → chunk-HREHWL32.js.map} +1 -1
- package/dist/{chunk-VZGAONSJ.js → chunk-I5TDIUKM.js} +16 -35
- package/dist/chunk-I5TDIUKM.js.map +1 -0
- package/dist/{chunk-7QKHZQKW.js → chunk-IADZOXKN.js} +39 -6
- package/dist/chunk-IADZOXKN.js.map +1 -0
- package/dist/{chunk-U6YQ6FRI.js → chunk-IDTRSAHE.js} +32 -12
- package/dist/chunk-IDTRSAHE.js.map +1 -0
- package/dist/{chunk-SPAVAYSW.js → chunk-JEVQ5LKO.js} +7 -5
- package/dist/{chunk-SPAVAYSW.js.map → chunk-JEVQ5LKO.js.map} +1 -1
- package/dist/{chunk-EBVIKMCH.js → chunk-JKKAIPTU.js} +2 -2
- package/dist/chunk-JNJWBTU2.js +3497 -0
- package/dist/chunk-JNJWBTU2.js.map +1 -0
- package/dist/{chunk-TTBKWWTV.js → chunk-JRZBBPO6.js} +390 -146
- package/dist/chunk-JRZBBPO6.js.map +1 -0
- package/dist/{chunk-WVUSXNIE.js → chunk-MPZUYCAP.js} +9 -2
- package/dist/{chunk-WVUSXNIE.js.map → chunk-MPZUYCAP.js.map} +1 -1
- package/dist/{chunk-SJLTEINJ.js → chunk-OJNTCYQQ.js} +17 -1
- package/dist/chunk-OJNTCYQQ.js.map +1 -0
- package/dist/{chunk-IOODYAXL.js → chunk-OTWLERSW.js} +25 -6
- package/dist/chunk-OTWLERSW.js.map +1 -0
- package/dist/{chunk-AWQPGIR6.js → chunk-PJNENX2A.js} +1535 -422
- package/dist/chunk-PJNENX2A.js.map +1 -0
- package/dist/{chunk-KHE6L6TD.js → chunk-PKHI276N.js} +97 -11
- package/dist/chunk-PKHI276N.js.map +1 -0
- package/dist/{chunk-YHKXNYTB.js → chunk-QF3LSMGS.js} +2 -2
- package/dist/chunk-QXP3Z3JN.js +131 -0
- package/dist/chunk-QXP3Z3JN.js.map +1 -0
- package/dist/{chunk-XZKD7DIF.js → chunk-RL5UUDT4.js} +3 -3
- package/dist/{chunk-XZKD7DIF.js.map → chunk-RL5UUDT4.js.map} +1 -1
- package/dist/chunk-SFASB5FL.js +69 -0
- package/dist/chunk-SFASB5FL.js.map +1 -0
- package/dist/{chunk-WO5BJNIB.js → chunk-SNNSAGMT.js} +7273 -2741
- package/dist/chunk-SNNSAGMT.js.map +1 -0
- package/dist/{chunk-NZIP4PA2.js → chunk-SO3XRZPX.js} +3 -3
- package/dist/chunk-SYOS5CAC.js +176 -0
- package/dist/chunk-SYOS5CAC.js.map +1 -0
- package/dist/chunk-TAW4UFFF.js +293 -0
- package/dist/chunk-TAW4UFFF.js.map +1 -0
- package/dist/chunk-TF5HCP33.js +271 -0
- package/dist/chunk-TF5HCP33.js.map +1 -0
- package/dist/{chunk-AKWGE6JQ.js → chunk-UUGOUOVT.js} +37 -2
- package/dist/chunk-UUGOUOVT.js.map +1 -0
- package/dist/{chunk-AEG2PXBP.js → chunk-V2LQLN5H.js} +7 -7
- package/dist/{chunk-KYFZTGMC.js → chunk-VJUVFZ2D.js} +5 -3
- package/dist/{chunk-KYFZTGMC.js.map → chunk-VJUVFZ2D.js.map} +1 -1
- package/dist/{chunk-JMM6YE7J.js → chunk-VOZA6O7K.js} +708 -709
- package/dist/chunk-VOZA6O7K.js.map +1 -0
- package/dist/{chunk-5LJCEMFD.js → chunk-VUGQTZ2L.js} +209 -77
- package/dist/chunk-VUGQTZ2L.js.map +1 -0
- package/dist/chunk-WOM257PW.js +393 -0
- package/dist/chunk-WOM257PW.js.map +1 -0
- package/dist/chunk-WYXUQGOL.js +191 -0
- package/dist/chunk-WYXUQGOL.js.map +1 -0
- package/dist/chunk-X5ZBP3IY.js +97 -0
- package/dist/chunk-X5ZBP3IY.js.map +1 -0
- package/dist/chunk-XQJXNMSB.js +23 -0
- package/dist/chunk-XQJXNMSB.js.map +1 -0
- package/dist/chunk-Y527D4TV.js +56 -0
- package/dist/chunk-Y527D4TV.js.map +1 -0
- package/dist/{chunk-VUFAK2LW.js → chunk-YUY4SAGM.js} +17 -2
- package/dist/chunk-YUY4SAGM.js.map +1 -0
- package/dist/clack-EZ7TDWQU.js +19 -0
- package/dist/claude-cli-2YKABJJZ.js +31 -0
- package/dist/{cli-O5SN7ZJ4.js → cli-FB4LOA5A.js} +221 -68
- package/dist/{cli-O5SN7ZJ4.js.map → cli-FB4LOA5A.js.map} +1 -1
- package/dist/codex-event-TYVES3UX.js +16 -0
- package/dist/codex-host-WW4H2SKT.js +29 -0
- package/dist/codex-install-2C623HPW.js +393 -0
- package/dist/codex-install-2C623HPW.js.map +1 -0
- package/dist/{config-OJQI27LT.js → config-HOVJFEKD.js} +25 -15
- package/dist/doctor-NKU4V5OV.js +1312 -0
- package/dist/doctor-NKU4V5OV.js.map +1 -0
- package/dist/{env-proxy-XL4P73MZ.js → env-proxy-R6ZMLQTT.js} +6 -2
- package/dist/{ethersCompat-Df4a6QIZ-THAVUGIJ.js → ethersCompat-Df4a6QIZ-X6YZWAML.js} +3 -3
- package/dist/{fund-WEV6DMTD.js → fund-WEBHTZGN.js} +38 -30
- package/dist/{fund-WEV6DMTD.js.map → fund-WEBHTZGN.js.map} +1 -1
- package/dist/hook-command-ZA2PNKS6.js +44 -0
- package/dist/hosts/claude/.claude-plugin/marketplace.json +2 -2
- package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +3 -2
- package/dist/hosts/claude/tenjin/hooks/hooks.json +4 -1
- package/dist/hosts/claude/tenjin/hooks/register.tsx +589 -0
- package/dist/hosts/claude/tenjin/skills/tenjin-pay/SKILL.md +82 -0
- package/dist/hosts/claude/tenjin/types/index.d.ts +41 -0
- package/dist/hosts/codex/.agents/plugins/marketplace.json +20 -0
- package/dist/hosts/codex/tenjin/.codex-plugin/plugin.json +16 -0
- package/dist/hosts/codex/tenjin/.mcp.json +15 -0
- package/dist/hosts/codex/tenjin/hooks/hooks.json +98 -0
- package/dist/hosts-AV5MHBAU.js +38 -0
- package/dist/index.js +28 -8
- package/dist/index.js.map +1 -1
- package/dist/install-PT4EZS4R.js +100 -0
- package/dist/{install-identity-WHPNMNMQ.js → install-identity-5A4OE6YC.js} +13 -8
- package/dist/install-wallet-SAAPKB73.js +281 -0
- package/dist/install-wallet-SAAPKB73.js.map +1 -0
- package/dist/{mcp-QML7ZMPH.js → mcp-HAWKCTPQ.js} +909 -208
- package/dist/mcp-HAWKCTPQ.js.map +1 -0
- package/dist/{mine.wasm-6PIT3DK6.js → mine.wasm-QFAHIFPY.js} +2 -2
- package/dist/{mine.wasm-6PIT3DK6.js.map → mine.wasm-QFAHIFPY.js.map} +1 -1
- package/dist/{package-LGKYOEPV.js → package-SR2WB6MK.js} +4 -2
- package/dist/passphrase-IFTDS3CU.js +44 -0
- package/dist/{paths-POPTXJO6.js → paths-XCSAKISU.js} +10 -2
- package/dist/pay-OXC3WKYV.js +55 -0
- package/dist/pay-OXC3WKYV.js.map +1 -0
- package/dist/{payments-C44QUFXU.js → payments-3KHMP2MG.js} +18 -13
- package/dist/{payments-C44QUFXU.js.map → payments-3KHMP2MG.js.map} +1 -1
- package/dist/plugin-registration-N3GRIZVM.js +67 -0
- package/dist/plugin-registration-N3GRIZVM.js.map +1 -0
- package/dist/{redact-6W23GGJC.js → redact-D7ASVWKL.js} +2 -2
- package/dist/redact-D7ASVWKL.js.map +1 -0
- package/dist/runtime-UVNUA3AS.js +1203 -0
- package/dist/runtime-UVNUA3AS.js.map +1 -0
- package/dist/runtime-fetch-EKFRNR6Z.js +20 -0
- package/dist/runtime-fetch-EKFRNR6Z.js.map +1 -0
- package/dist/runtime-layout-BDWZG2TQ.js +25 -0
- package/dist/runtime-layout-BDWZG2TQ.js.map +1 -0
- package/dist/{send-KVJX4XIR.js → send-HMKJLT34.js} +26 -18
- package/dist/{send-KVJX4XIR.js.map → send-HMKJLT34.js.map} +1 -1
- package/dist/{status-S7C3WMSH.js → status-RWXIIWYS.js} +57 -22
- package/dist/status-RWXIIWYS.js.map +1 -0
- package/dist/{status-line-YR2T5HC4.js → status-line-77XYZP7E.js} +13 -8
- package/dist/{status-line-YR2T5HC4.js.map → status-line-77XYZP7E.js.map} +1 -1
- package/dist/uninstall-D5G67UJH.js +480 -0
- package/dist/uninstall-D5G67UJH.js.map +1 -0
- package/dist/update-LRNOEGSB.js +53 -0
- package/dist/update-LRNOEGSB.js.map +1 -0
- package/dist/{usdc-JK4RRFFQ.js → usdc-D6X7EIQ2.js} +7 -8
- package/dist/usdc-D6X7EIQ2.js.map +1 -0
- package/dist/{viemAdapter-By13KInL-X2VY6CY3.js → viemAdapter-By13KInL-RL742ETX.js} +3 -3
- package/dist/viemAdapter-By13KInL-RL742ETX.js.map +1 -0
- package/dist/wallet-XFYC27BR.js +55 -0
- package/dist/wallet-XFYC27BR.js.map +1 -0
- package/dist/wallet-kdf-worker.mjs +8 -8
- package/docs/agent-permissions.md +56 -22
- package/docs/safety-model.md +1 -1
- package/docs/troubleshooting.md +72 -1
- package/package.json +14 -1
- package/dist/alive-3J3CHOQP.js +0 -21
- package/dist/ccip-NLCSCHKI.js +0 -19
- package/dist/chunk-3O2BQIF6.js.map +0 -1
- package/dist/chunk-5IEP5EGE.js +0 -5332
- package/dist/chunk-5IEP5EGE.js.map +0 -1
- package/dist/chunk-5LJCEMFD.js.map +0 -1
- package/dist/chunk-6W5GYG3W.js +0 -128
- package/dist/chunk-6W5GYG3W.js.map +0 -1
- package/dist/chunk-7EKYXMUO.js +0 -7536
- package/dist/chunk-7EKYXMUO.js.map +0 -1
- package/dist/chunk-7QKHZQKW.js.map +0 -1
- package/dist/chunk-AKWGE6JQ.js.map +0 -1
- package/dist/chunk-AWQPGIR6.js.map +0 -1
- package/dist/chunk-EGELTSPU.js +0 -2865
- package/dist/chunk-EGELTSPU.js.map +0 -1
- package/dist/chunk-EL56RW2J.js +0 -7611
- package/dist/chunk-EL56RW2J.js.map +0 -1
- package/dist/chunk-HE2MS4QO.js +0 -256
- package/dist/chunk-HE2MS4QO.js.map +0 -1
- package/dist/chunk-IOODYAXL.js.map +0 -1
- package/dist/chunk-JMM6YE7J.js.map +0 -1
- package/dist/chunk-KHE6L6TD.js.map +0 -1
- package/dist/chunk-N35E6CM2.js +0 -1185
- package/dist/chunk-N35E6CM2.js.map +0 -1
- package/dist/chunk-O2FRQ2L2.js.map +0 -1
- package/dist/chunk-OK2TDZQU.js.map +0 -1
- package/dist/chunk-OSYTBCUC.js.map +0 -1
- package/dist/chunk-PAYV4XUA.js.map +0 -1
- package/dist/chunk-SJLTEINJ.js.map +0 -1
- package/dist/chunk-TTBKWWTV.js.map +0 -1
- package/dist/chunk-TTNESUPQ.js.map +0 -1
- package/dist/chunk-U6YQ6FRI.js.map +0 -1
- package/dist/chunk-VUFAK2LW.js.map +0 -1
- package/dist/chunk-VZGAONSJ.js.map +0 -1
- package/dist/chunk-WO5BJNIB.js.map +0 -1
- package/dist/doctor-IQQJHGGM.js +0 -590
- package/dist/doctor-IQQJHGGM.js.map +0 -1
- package/dist/hook-command-D2P3ILRV.js +0 -32
- package/dist/install-TUCRF32I.js +0 -60
- package/dist/install-wallet-MA27FTQ5.js +0 -113
- package/dist/install-wallet-MA27FTQ5.js.map +0 -1
- package/dist/mcp-QML7ZMPH.js.map +0 -1
- package/dist/pay-2C2UBBXJ.js +0 -51
- package/dist/status-S7C3WMSH.js.map +0 -1
- package/dist/uninstall-HY6LKIIT.js +0 -149
- package/dist/uninstall-HY6LKIIT.js.map +0 -1
- package/dist/update-OJV22LR3.js +0 -36
- package/dist/wallet-PD2IMZDU.js +0 -39
- /package/dist/{_esm-CE7KNONL.js.map → _esm-RLLC72MS.js.map} +0 -0
- /package/dist/{alive-3J3CHOQP.js.map → alive-MROUMFH3.js.map} +0 -0
- /package/dist/{ccip-7RMRLAGV.js.map → auto-update-OPWMRZLS.js.map} +0 -0
- /package/dist/{ccip-NLCSCHKI.js.map → ccip-DHDFKTQV.js.map} +0 -0
- /package/dist/{chunk-LFZJM56J.js.map → chunk-445VQTVM.js.map} +0 -0
- /package/dist/{chunk-RAULEAZ6.js.map → chunk-4USCZ2NI.js.map} +0 -0
- /package/dist/{chunk-VFMQTSXG.js.map → chunk-D3ZURCG7.js.map} +0 -0
- /package/dist/{chunk-ORWL5BSN.js.map → chunk-HGZEPQUT.js.map} +0 -0
- /package/dist/{chunk-EBVIKMCH.js.map → chunk-JKKAIPTU.js.map} +0 -0
- /package/dist/{chunk-YHKXNYTB.js.map → chunk-QF3LSMGS.js.map} +0 -0
- /package/dist/{chunk-NZIP4PA2.js.map → chunk-SO3XRZPX.js.map} +0 -0
- /package/dist/{chunk-AEG2PXBP.js.map → chunk-V2LQLN5H.js.map} +0 -0
- /package/dist/{config-OJQI27LT.js.map → clack-EZ7TDWQU.js.map} +0 -0
- /package/dist/{env-proxy-XL4P73MZ.js.map → claude-cli-2YKABJJZ.js.map} +0 -0
- /package/dist/{ethersCompat-Df4a6QIZ-THAVUGIJ.js.map → codex-event-TYVES3UX.js.map} +0 -0
- /package/dist/{hook-command-D2P3ILRV.js.map → codex-host-WW4H2SKT.js.map} +0 -0
- /package/dist/{install-TUCRF32I.js.map → config-HOVJFEKD.js.map} +0 -0
- /package/dist/{install-identity-WHPNMNMQ.js.map → env-proxy-R6ZMLQTT.js.map} +0 -0
- /package/dist/{package-LGKYOEPV.js.map → ethersCompat-Df4a6QIZ-X6YZWAML.js.map} +0 -0
- /package/dist/{paths-POPTXJO6.js.map → hook-command-ZA2PNKS6.js.map} +0 -0
- /package/dist/{pay-2C2UBBXJ.js.map → hosts-AV5MHBAU.js.map} +0 -0
- /package/dist/{redact-6W23GGJC.js.map → install-PT4EZS4R.js.map} +0 -0
- /package/dist/{update-OJV22LR3.js.map → install-identity-5A4OE6YC.js.map} +0 -0
- /package/dist/{usdc-JK4RRFFQ.js.map → package-SR2WB6MK.js.map} +0 -0
- /package/dist/{viemAdapter-By13KInL-X2VY6CY3.js.map → passphrase-IFTDS3CU.js.map} +0 -0
- /package/dist/{wallet-PD2IMZDU.js.map → paths-XCSAKISU.js.map} +0 -0
|
@@ -3,15 +3,17 @@ import {
|
|
|
3
3
|
NUDGE_OPT_OUT,
|
|
4
4
|
channelTag,
|
|
5
5
|
fetchDistTags,
|
|
6
|
-
isNewer,
|
|
7
6
|
resolveTarget
|
|
8
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-I5TDIUKM.js";
|
|
9
8
|
import {
|
|
10
9
|
underAgentHarness
|
|
11
10
|
} from "./chunk-KOGZDMHO.js";
|
|
12
11
|
import {
|
|
13
12
|
ROUTER_PATH
|
|
14
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-PKHI276N.js";
|
|
14
|
+
import {
|
|
15
|
+
readMcpServers
|
|
16
|
+
} from "./chunk-B7EM4GGF.js";
|
|
15
17
|
import {
|
|
16
18
|
CLI_SKILL_NAMES,
|
|
17
19
|
FEE_APPROVAL,
|
|
@@ -29,240 +31,133 @@ import {
|
|
|
29
31
|
skillsDirsFor,
|
|
30
32
|
spendChoiceQuestion,
|
|
31
33
|
spendOptions
|
|
32
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-AD226HDR.js";
|
|
35
|
+
import {
|
|
36
|
+
emitWriteNotice,
|
|
37
|
+
paint,
|
|
38
|
+
sanitizeForTerminal
|
|
39
|
+
} from "./chunk-VJUVFZ2D.js";
|
|
40
|
+
import {
|
|
41
|
+
SUGGESTED_FUND_USD
|
|
42
|
+
} from "./chunk-HDPUXS3Z.js";
|
|
43
|
+
import {
|
|
44
|
+
askText,
|
|
45
|
+
selectOne
|
|
46
|
+
} from "./chunk-DOQGNFHM.js";
|
|
47
|
+
import {
|
|
48
|
+
MANAGERS,
|
|
49
|
+
classifyManager,
|
|
50
|
+
inspectPluginFolder,
|
|
51
|
+
pluginFolderPath,
|
|
52
|
+
readModSources,
|
|
53
|
+
refuse,
|
|
54
|
+
removePluginFolder,
|
|
55
|
+
resolveManagerScript,
|
|
56
|
+
writePluginFolder
|
|
57
|
+
} from "./chunk-TAW4UFFF.js";
|
|
33
58
|
import {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
} from "./chunk-
|
|
59
|
+
PLUGIN_DIR,
|
|
60
|
+
renderPluginFiles
|
|
61
|
+
} from "./chunk-E7LGOMH6.js";
|
|
37
62
|
import {
|
|
38
63
|
LEGACY_HOOK_TOOL,
|
|
39
64
|
LEGACY_MCP_SERVER_NAME,
|
|
40
65
|
LEGACY_REQUEST_TOOL,
|
|
41
66
|
MARKETPLACE_NAME,
|
|
42
67
|
MCP_SERVER_NAME,
|
|
43
|
-
PLUGIN_HOOK_TOOL,
|
|
44
68
|
PLUGIN_ID,
|
|
45
69
|
PLUGIN_NAME,
|
|
46
|
-
PLUGIN_SERVER,
|
|
47
|
-
REQUEST_TOOL,
|
|
48
70
|
SKILLS_DIR_PLUGIN_ID
|
|
49
|
-
} from "./chunk-
|
|
71
|
+
} from "./chunk-MPZUYCAP.js";
|
|
50
72
|
import {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
73
|
+
envProxySupported,
|
|
74
|
+
proxyNodeStep,
|
|
75
|
+
proxySkipped,
|
|
76
|
+
proxyVariable
|
|
77
|
+
} from "./chunk-3FMZGI7I.js";
|
|
54
78
|
import {
|
|
55
|
-
|
|
56
|
-
} from "./chunk-
|
|
79
|
+
httpRequest
|
|
80
|
+
} from "./chunk-OTWLERSW.js";
|
|
57
81
|
import {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
82
|
+
CLAUDE_CODE_FLOOR,
|
|
83
|
+
claudeConfigDir,
|
|
84
|
+
findClaudeBinary,
|
|
85
|
+
jsonList,
|
|
86
|
+
jsonResult,
|
|
87
|
+
readClaudeCode,
|
|
88
|
+
runClaude,
|
|
89
|
+
userMcpFile,
|
|
90
|
+
userSettingsPath
|
|
91
|
+
} from "./chunk-QXP3Z3JN.js";
|
|
92
|
+
import {
|
|
93
|
+
package_default
|
|
94
|
+
} from "./chunk-YUY4SAGM.js";
|
|
95
|
+
import {
|
|
96
|
+
resolveContextSettings
|
|
97
|
+
} from "./chunk-AV5NZMYO.js";
|
|
98
|
+
import {
|
|
99
|
+
parseUsdToAtomic,
|
|
100
|
+
toMoney
|
|
101
|
+
} from "./chunk-Y527D4TV.js";
|
|
62
102
|
import {
|
|
63
103
|
readAliveStamp
|
|
64
|
-
} from "./chunk-
|
|
104
|
+
} from "./chunk-WOM257PW.js";
|
|
65
105
|
import {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
} from "./chunk-
|
|
106
|
+
WALLET_REASONS,
|
|
107
|
+
agentFixFor
|
|
108
|
+
} from "./chunk-BFDQ4WNW.js";
|
|
69
109
|
import {
|
|
70
|
-
|
|
71
|
-
} from "./chunk-
|
|
110
|
+
REPAIR_CLAUSE
|
|
111
|
+
} from "./chunk-X5ZBP3IY.js";
|
|
72
112
|
import {
|
|
73
113
|
hasCode
|
|
74
114
|
} from "./chunk-2I4QTOLB.js";
|
|
75
115
|
import {
|
|
76
|
-
resolveContextSettings
|
|
77
|
-
} from "./chunk-AWFUPKTM.js";
|
|
78
|
-
import {
|
|
79
|
-
CliError,
|
|
80
116
|
MAX_AUTO_SPEND_FLOOR_ATOMIC,
|
|
81
117
|
MAX_AUTO_SPEND_FLOOR_WHY,
|
|
118
|
+
loadRawConfig
|
|
119
|
+
} from "./chunk-2GNOFONN.js";
|
|
120
|
+
import {
|
|
82
121
|
PRODUCTION_ORIGIN,
|
|
83
|
-
isSameDeployment
|
|
84
|
-
|
|
85
|
-
parseUsdToAtomic,
|
|
86
|
-
toMoney
|
|
87
|
-
} from "./chunk-WO5BJNIB.js";
|
|
122
|
+
isSameDeployment
|
|
123
|
+
} from "./chunk-XQJXNMSB.js";
|
|
88
124
|
import {
|
|
89
125
|
writeFileAtomic
|
|
90
|
-
} from "./chunk-
|
|
126
|
+
} from "./chunk-7WEQQJLG.js";
|
|
91
127
|
import {
|
|
92
|
-
|
|
93
|
-
} from "./chunk-
|
|
128
|
+
CliError
|
|
129
|
+
} from "./chunk-3UCIG4TG.js";
|
|
94
130
|
import {
|
|
95
|
-
|
|
96
|
-
|
|
131
|
+
runtimeBuild,
|
|
132
|
+
runtimeStatePath
|
|
133
|
+
} from "./chunk-G75OPGAK.js";
|
|
134
|
+
import {
|
|
135
|
+
isNewer
|
|
136
|
+
} from "./chunk-EDJWHDDL.js";
|
|
137
|
+
import {
|
|
138
|
+
defaultDataDir,
|
|
139
|
+
runtimeDir
|
|
140
|
+
} from "./chunk-OJNTCYQQ.js";
|
|
97
141
|
|
|
98
142
|
// src/commands/update.ts
|
|
99
143
|
import { spawn } from "node:child_process";
|
|
100
|
-
import { existsSync as existsSync2, statSync
|
|
101
|
-
import {
|
|
102
|
-
import {
|
|
144
|
+
import { existsSync as existsSync2, statSync } from "node:fs";
|
|
145
|
+
import { rm as rm2 } from "node:fs/promises";
|
|
146
|
+
import { homedir as homedir2 } from "node:os";
|
|
147
|
+
import { resolve as resolve2, sep as sep2 } from "node:path";
|
|
103
148
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
104
149
|
|
|
105
|
-
// src/lib/install-location.ts
|
|
106
|
-
import { existsSync, realpathSync, statSync } from "node:fs";
|
|
107
|
-
import { delimiter, dirname, join, sep } from "node:path";
|
|
108
|
-
var REFUSALS = [
|
|
109
|
-
{
|
|
110
|
-
test: isSourceCheckout,
|
|
111
|
-
error: () => new CliError("REFUSED", "tenjin-cli is running from a source checkout, not an install", {
|
|
112
|
-
fix: "Update the checkout instead: git pull && pnpm install"
|
|
113
|
-
}),
|
|
114
|
-
needsVersion: false,
|
|
115
|
-
appliesToCheck: false
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
test: (moduleDir) => moduleDir.split(sep).includes("_npx"),
|
|
119
|
-
error: (spec) => new CliError("REFUSED", "tenjin-cli is running from the npx cache, not an install", {
|
|
120
|
-
// Writing a global here would "succeed" and change nothing: the next
|
|
121
|
-
// `npx tenjin` still resolves its own cached copy.
|
|
122
|
-
fix: `npx fetches its own copy every time. To keep one: npm i -g ${spec}`
|
|
123
|
-
}),
|
|
124
|
-
needsVersion: true,
|
|
125
|
-
appliesToCheck: false
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
// The ONLY manager still refused. `yarn global add` is yarn-1 only, and
|
|
129
|
-
// berry dropped global installs altogether, so there is no one command this
|
|
130
|
-
// can drive across the versions a user might have. Every other manager is
|
|
131
|
-
// delegated to rather than refused (see MANAGERS).
|
|
132
|
-
test: (moduleDir) => classifyManager(moduleDir) === "yarn",
|
|
133
|
-
error: (spec) => new CliError(
|
|
134
|
-
"REFUSED",
|
|
135
|
-
"This tenjin-cli was installed with yarn, whose global install exists only in yarn 1",
|
|
136
|
-
{ fix: `yarn global add ${spec}` }
|
|
137
|
-
),
|
|
138
|
-
needsVersion: true,
|
|
139
|
-
appliesToCheck: false
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
// Scoped to npm on purpose: the prefix-vs-project-root test is written for
|
|
143
|
-
// npm's layout. pnpm's global store and bun's global dir both keep a
|
|
144
|
-
// package.json beside `node_modules`, so an unscoped test would read either
|
|
145
|
-
// as a project-local install and refuse the very case we now delegate.
|
|
146
|
-
test: (moduleDir) => classifyManager(moduleDir) === "npm" && !isGlobalTree(moduleDir),
|
|
147
|
-
error: (spec) => new CliError(
|
|
148
|
-
"REFUSED",
|
|
149
|
-
"This tenjin-cli is a project-local dependency, not a global install",
|
|
150
|
-
{
|
|
151
|
-
fix: `Update it where it is declared: npm i ${spec}`
|
|
152
|
-
}
|
|
153
|
-
),
|
|
154
|
-
needsVersion: true,
|
|
155
|
-
appliesToCheck: false
|
|
156
|
-
}
|
|
157
|
-
];
|
|
158
|
-
function refuse(moduleDir, opts) {
|
|
159
|
-
for (const entry of REFUSALS) {
|
|
160
|
-
if (opts.check && !entry.appliesToCheck) continue;
|
|
161
|
-
if (entry.needsVersion !== (opts.spec !== null)) continue;
|
|
162
|
-
if (entry.test(moduleDir)) throw entry.error(opts.spec ?? "", moduleDir);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
function isSourceCheckout(moduleDir) {
|
|
166
|
-
let dir = moduleDir;
|
|
167
|
-
for (let i = 0; i < 8; i += 1) {
|
|
168
|
-
if (existsSync(join(dir, "package.json"))) return existsSync(join(dir, "src"));
|
|
169
|
-
const parent = dirname(dir);
|
|
170
|
-
if (parent === dir) break;
|
|
171
|
-
dir = parent;
|
|
172
|
-
}
|
|
173
|
-
return false;
|
|
174
|
-
}
|
|
175
|
-
function isGlobalTree(moduleDir) {
|
|
176
|
-
const segs = moduleDir.split(sep);
|
|
177
|
-
const i = segs.lastIndexOf("node_modules");
|
|
178
|
-
if (i <= 0) return false;
|
|
179
|
-
return !existsSync(join(segs.slice(0, i).join(sep), "package.json"));
|
|
180
|
-
}
|
|
181
|
-
function classifyManager(moduleDir) {
|
|
182
|
-
const segs = moduleDir.split(sep);
|
|
183
|
-
const pair = (a, b) => segs.includes(a) && segs.includes(b);
|
|
184
|
-
if (segs.includes(".pnpm") || pair("pnpm", "global")) return "pnpm";
|
|
185
|
-
if (segs.includes(".bun")) return "bun";
|
|
186
|
-
if (segs.includes(".yarn") || pair("yarn", "global")) return "yarn";
|
|
187
|
-
return "npm";
|
|
188
|
-
}
|
|
189
|
-
var MANAGERS = {
|
|
190
|
-
npm: {
|
|
191
|
-
bin: "npm",
|
|
192
|
-
scriptSuffixes: ["npm-cli.js"],
|
|
193
|
-
besideNode: true,
|
|
194
|
-
args: (spec) => ["install", "-g", "--ignore-scripts", spec],
|
|
195
|
-
manual: (spec) => `npm i -g ${spec}`
|
|
196
|
-
},
|
|
197
|
-
pnpm: {
|
|
198
|
-
bin: "pnpm",
|
|
199
|
-
// corepack's shim resolves to `pnpm.js`, a standalone install to `pnpm.cjs`.
|
|
200
|
-
scriptSuffixes: [".cjs", ".js"],
|
|
201
|
-
besideNode: false,
|
|
202
|
-
args: (spec) => ["add", "-g", "--ignore-scripts", spec],
|
|
203
|
-
manual: (spec) => `pnpm add -g ${spec}`
|
|
204
|
-
},
|
|
205
|
-
bun: {
|
|
206
|
-
bin: "bun",
|
|
207
|
-
scriptSuffixes: [],
|
|
208
|
-
besideNode: false,
|
|
209
|
-
// No --ignore-scripts: bun's flag surface for it is not stable across the
|
|
210
|
-
// versions in the wild, and an unknown flag would fail the install outright.
|
|
211
|
-
args: (spec) => ["add", "-g", spec],
|
|
212
|
-
manual: (spec) => `bun add -g ${spec}`
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
function resolveManagerScript(manager, execPath, env = process.env) {
|
|
216
|
-
const plan = MANAGERS[manager];
|
|
217
|
-
if (plan.scriptSuffixes.length === 0) return null;
|
|
218
|
-
const beside = plan.besideNode ? scriptNear(dirname(execPath), plan.bin) : null;
|
|
219
|
-
return beside ?? scriptOnPath(plan.bin, plan.scriptSuffixes, env);
|
|
220
|
-
}
|
|
221
|
-
function scriptNear(dir, bin) {
|
|
222
|
-
const candidates = [
|
|
223
|
-
join(dir, "node_modules", bin, "bin", `${bin}-cli.js`),
|
|
224
|
-
join(dir, "..", "lib", "node_modules", bin, "bin", `${bin}-cli.js`)
|
|
225
|
-
];
|
|
226
|
-
return candidates.find(isFile) ?? null;
|
|
227
|
-
}
|
|
228
|
-
function scriptOnPath(bin, suffixes, env) {
|
|
229
|
-
const exts = process.platform === "win32" ? ["", ...(env.PATHEXT ?? ".EXE;.CMD;.BAT;.COM").split(";").filter((e) => e.length > 0)] : [""];
|
|
230
|
-
for (const part of (env.PATH ?? "").split(delimiter)) {
|
|
231
|
-
if (part.length === 0) continue;
|
|
232
|
-
for (const ext of exts) {
|
|
233
|
-
if (!isFile(join(part, `${bin}${ext}`))) continue;
|
|
234
|
-
const real = realpathOrNull(join(part, `${bin}${ext}`));
|
|
235
|
-
if (real !== null && suffixes.some((suffix) => real.endsWith(suffix))) return real;
|
|
236
|
-
const near = scriptNear(part, bin);
|
|
237
|
-
if (near !== null) return near;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
return null;
|
|
241
|
-
}
|
|
242
|
-
function isFile(p) {
|
|
243
|
-
try {
|
|
244
|
-
return statSync(p).isFile();
|
|
245
|
-
} catch {
|
|
246
|
-
return false;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
function realpathOrNull(p) {
|
|
250
|
-
try {
|
|
251
|
-
return realpathSync(p);
|
|
252
|
-
} catch {
|
|
253
|
-
return null;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
150
|
// src/router/install.ts
|
|
258
|
-
import {
|
|
259
|
-
import {
|
|
260
|
-
import {
|
|
151
|
+
import { existsSync } from "node:fs";
|
|
152
|
+
import { readFile as readFile3, realpath, stat as stat3 } from "node:fs/promises";
|
|
153
|
+
import { homedir } from "node:os";
|
|
154
|
+
import { dirname as dirname3, isAbsolute, join as join4, relative, resolve, sep } from "node:path";
|
|
155
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
261
156
|
|
|
262
157
|
// src/lib/skill-placement.ts
|
|
263
158
|
import { lstatSync } from "node:fs";
|
|
264
159
|
import { readdir, rm, rmdir } from "node:fs/promises";
|
|
265
|
-
import { dirname
|
|
160
|
+
import { dirname, join } from "node:path";
|
|
266
161
|
function isRealDirectory(path) {
|
|
267
162
|
try {
|
|
268
163
|
return lstatSync(path, { throwIfNoEntry: false })?.isDirectory() === true;
|
|
@@ -275,11 +170,11 @@ async function removeOwnedSkill(name, skillsDir) {
|
|
|
275
170
|
if (!isRealDirectory(skillsDir)) {
|
|
276
171
|
return { changed: false };
|
|
277
172
|
}
|
|
278
|
-
const skillDir =
|
|
173
|
+
const skillDir = join(skillsDir, name);
|
|
279
174
|
if (!isRealDirectory(skillDir)) {
|
|
280
175
|
return { changed: false };
|
|
281
176
|
}
|
|
282
|
-
const path =
|
|
177
|
+
const path = join(skillDir, "SKILL.md");
|
|
283
178
|
const read = await readSkillFile(path);
|
|
284
179
|
if (read.kind === "absent") return { changed: false };
|
|
285
180
|
if (read.kind !== "ok" || skillFrontmatterName(read.bytes.toString("utf8")) !== name) {
|
|
@@ -289,9 +184,9 @@ async function removeOwnedSkill(name, skillsDir) {
|
|
|
289
184
|
const subdirs = /* @__PURE__ */ new Set();
|
|
290
185
|
for (const rel of shipped) {
|
|
291
186
|
if (rel === "SKILL.md") continue;
|
|
292
|
-
const file =
|
|
293
|
-
if (!isRealDirectory(
|
|
294
|
-
subdirs.add(
|
|
187
|
+
const file = join(skillDir, rel);
|
|
188
|
+
if (!isRealDirectory(dirname(file))) continue;
|
|
189
|
+
subdirs.add(dirname(file));
|
|
295
190
|
if (lstatSync(file, { throwIfNoEntry: false })?.isFile() === true) await rm(file);
|
|
296
191
|
}
|
|
297
192
|
await rm(path, { force: true });
|
|
@@ -306,139 +201,25 @@ async function removeRetiredSkills(home, project) {
|
|
|
306
201
|
const dirs = [...skillsDirsFor(home), ...project ? skillsDirsFor(project) : []];
|
|
307
202
|
for (const dir of new Set(dirs)) {
|
|
308
203
|
for (const name of [...RETIRED_SKILL_NAMES, ...CLI_SKILL_NAMES]) {
|
|
309
|
-
if ((await removeOwnedSkill(name, dir)).changed) removed.push(
|
|
204
|
+
if ((await removeOwnedSkill(name, dir)).changed) removed.push(join(dir, name));
|
|
310
205
|
}
|
|
311
206
|
}
|
|
312
207
|
return removed;
|
|
313
208
|
}
|
|
314
209
|
|
|
315
|
-
// src/router/claude-cli.ts
|
|
316
|
-
import { execFile } from "node:child_process";
|
|
317
|
-
import { statSync as statSync2 } from "node:fs";
|
|
318
|
-
import { homedir } from "node:os";
|
|
319
|
-
import { delimiter as delimiter2, isAbsolute, join as join3 } from "node:path";
|
|
320
|
-
var CLAUDE_CODE_FLOOR = "2.1.287";
|
|
321
|
-
function claudeConfigDir(env, home = homedir()) {
|
|
322
|
-
const dir = env.CLAUDE_CONFIG_DIR;
|
|
323
|
-
return dir !== void 0 && dir.length > 0 ? dir : join3(home, ".claude");
|
|
324
|
-
}
|
|
325
|
-
function userSettingsPath(env, home = homedir()) {
|
|
326
|
-
return join3(claudeConfigDir(env, home), "settings.json");
|
|
327
|
-
}
|
|
328
|
-
function userMcpFile(env, home = homedir()) {
|
|
329
|
-
const dir = env.CLAUDE_CONFIG_DIR;
|
|
330
|
-
return dir !== void 0 && dir.length > 0 ? join3(dir, ".claude.json") : join3(home, ".claude.json");
|
|
331
|
-
}
|
|
332
|
-
function isFile2(path) {
|
|
333
|
-
try {
|
|
334
|
-
return statSync2(path).isFile();
|
|
335
|
-
} catch {
|
|
336
|
-
return false;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
function findClaudeBinary(env) {
|
|
340
|
-
const exts = process.platform === "win32" ? ["", ...(env.PATHEXT ?? ".EXE;.CMD;.BAT;.COM").split(";").filter((e) => e.length > 0)] : [""];
|
|
341
|
-
for (const part of (env.PATH ?? "").split(delimiter2)) {
|
|
342
|
-
if (part.length === 0) continue;
|
|
343
|
-
for (const ext of exts) {
|
|
344
|
-
const candidate = join3(part, `claude${ext}`);
|
|
345
|
-
if (isFile2(candidate)) return { path: candidate, source: "path" };
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
const exec2 = env.CLAUDE_CODE_EXECPATH;
|
|
349
|
-
if (exec2 !== void 0 && isAbsolute(exec2) && isFile2(exec2)) {
|
|
350
|
-
return { path: exec2, source: "execpath" };
|
|
351
|
-
}
|
|
352
|
-
return null;
|
|
353
|
-
}
|
|
354
|
-
function runClaude(bin, args, opts) {
|
|
355
|
-
return new Promise((resolve2) => {
|
|
356
|
-
execFile(
|
|
357
|
-
bin.path,
|
|
358
|
-
args,
|
|
359
|
-
{
|
|
360
|
-
env: opts.env,
|
|
361
|
-
cwd: opts.cwd,
|
|
362
|
-
timeout: opts.timeoutMs ?? 3e4,
|
|
363
|
-
maxBuffer: 4 * 1024 * 1024,
|
|
364
|
-
windowsHide: true
|
|
365
|
-
},
|
|
366
|
-
(err, stdout, stderr) => {
|
|
367
|
-
const code = err === null ? 0 : typeof err.code === "number" ? err.code : null;
|
|
368
|
-
resolve2({ code, stdout: String(stdout), stderr: String(stderr) });
|
|
369
|
-
}
|
|
370
|
-
);
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
function jsonResult(stdout) {
|
|
374
|
-
const lines2 = stdout.split("\n").map((l) => l.trim());
|
|
375
|
-
for (let i = lines2.length - 1; i >= 0; i -= 1) {
|
|
376
|
-
const line = lines2[i];
|
|
377
|
-
if (!line.startsWith("{")) continue;
|
|
378
|
-
try {
|
|
379
|
-
const parsed = JSON.parse(line);
|
|
380
|
-
if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
381
|
-
return parsed;
|
|
382
|
-
}
|
|
383
|
-
} catch {
|
|
384
|
-
continue;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
return null;
|
|
388
|
-
}
|
|
389
|
-
function jsonList(stdout) {
|
|
390
|
-
const start = stdout.indexOf("[");
|
|
391
|
-
if (start === -1) return null;
|
|
392
|
-
try {
|
|
393
|
-
const parsed = JSON.parse(stdout.slice(start));
|
|
394
|
-
return Array.isArray(parsed) ? parsed.filter(
|
|
395
|
-
(row) => row !== null && typeof row === "object" && !Array.isArray(row)
|
|
396
|
-
) : null;
|
|
397
|
-
} catch {
|
|
398
|
-
return null;
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
function parseClaudeVersion(text) {
|
|
402
|
-
return /(\d+)\.(\d+)\.(\d+)/.exec(text)?.[0] ?? null;
|
|
403
|
-
}
|
|
404
|
-
function meetsFloor(version, floor = CLAUDE_CODE_FLOOR) {
|
|
405
|
-
const a = version.split(".").map(Number);
|
|
406
|
-
const b = floor.split(".").map(Number);
|
|
407
|
-
for (let i = 0; i < 3; i += 1) {
|
|
408
|
-
const x = a[i] ?? 0;
|
|
409
|
-
const y = b[i] ?? 0;
|
|
410
|
-
if (x !== y) return x > y;
|
|
411
|
-
}
|
|
412
|
-
return true;
|
|
413
|
-
}
|
|
414
|
-
var CLAUDE_UPDATE_FIX = "Run `claude update` in this session, then start a new Claude Code session so the newer version loads.";
|
|
415
|
-
async function readClaudeCode(env, cwd, find = findClaudeBinary) {
|
|
416
|
-
const binary = find(env);
|
|
417
|
-
if (binary === null) return { binary, version: null, meetsFloor: true };
|
|
418
|
-
const run = await runClaude(binary, ["--version"], { env, cwd, timeoutMs: 15e3 });
|
|
419
|
-
const version = run.code === 0 ? parseClaudeVersion(run.stdout) : null;
|
|
420
|
-
const ok = version === null || meetsFloor(version);
|
|
421
|
-
return {
|
|
422
|
-
binary,
|
|
423
|
-
version,
|
|
424
|
-
meetsFloor: ok,
|
|
425
|
-
...ok ? {} : { fix: CLAUDE_UPDATE_FIX }
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
|
|
429
210
|
// src/router/legacy-install.ts
|
|
430
211
|
import { readFile, stat } from "node:fs/promises";
|
|
431
|
-
import { join as
|
|
212
|
+
import { join as join2 } from "node:path";
|
|
432
213
|
|
|
433
214
|
// src/router/status-line-wiring.ts
|
|
434
215
|
var STATUS_LINE_COMMAND = "tenjin status-line";
|
|
435
216
|
var OUR_MARKER = STATUS_LINE_COMMAND;
|
|
436
217
|
function classifyStatusLine(value) {
|
|
437
218
|
if (value === null || value === void 0) return "absent";
|
|
438
|
-
const
|
|
439
|
-
if (typeof
|
|
440
|
-
if (
|
|
441
|
-
return
|
|
219
|
+
const command = typeof value === "string" ? value : typeof value === "object" && !Array.isArray(value) ? value.command : void 0;
|
|
220
|
+
if (typeof command !== "string" || command.trim().length === 0) return "foreign";
|
|
221
|
+
if (command.trim() === OUR_MARKER) return "ours";
|
|
222
|
+
return command.includes(OUR_MARKER) ? "composed" : "foreign";
|
|
442
223
|
}
|
|
443
224
|
var shUnquote = (value) => value.replaceAll(String.raw`'\''`, "'");
|
|
444
225
|
function composedScript(existing) {
|
|
@@ -449,8 +230,8 @@ function composedScript(existing) {
|
|
|
449
230
|
'printf %s "$yours${tenjin:+ \xB7 $tenjin}"'
|
|
450
231
|
].join("; ");
|
|
451
232
|
}
|
|
452
|
-
function decomposeCommand(
|
|
453
|
-
const trimmed =
|
|
233
|
+
function decomposeCommand(command) {
|
|
234
|
+
const trimmed = command.trim();
|
|
454
235
|
if (!trimmed.startsWith("sh -c '") || !trimmed.endsWith("'")) return null;
|
|
455
236
|
const script = shUnquote(trimmed.slice("sh -c '".length, -1));
|
|
456
237
|
const prefix = 'event=$(cat); yours=$(printf %s "$event" | ';
|
|
@@ -472,19 +253,19 @@ function ownsLegacyHandler(handler) {
|
|
|
472
253
|
if (handler.type === "mcp_tool") {
|
|
473
254
|
return handler.server === LEGACY_MCP_SERVER_NAME && handler.tool === "hook";
|
|
474
255
|
}
|
|
475
|
-
const
|
|
476
|
-
return typeof
|
|
256
|
+
const command = handler.command;
|
|
257
|
+
return typeof command === "string" && LEGACY_COMMAND_RE.test(command.trim());
|
|
477
258
|
}
|
|
478
259
|
function lookalike(handler) {
|
|
479
260
|
if (!isPlainObject(handler) || ownsLegacyHandler(handler)) return null;
|
|
480
|
-
const
|
|
481
|
-
return typeof
|
|
261
|
+
const command = handler.command;
|
|
262
|
+
return typeof command === "string" && command.includes("tenjin hook") ? command : null;
|
|
482
263
|
}
|
|
483
264
|
function classifyMcpEntry(entry) {
|
|
484
265
|
if (entry === null || typeof entry !== "object" || Array.isArray(entry)) return "absent";
|
|
485
|
-
const { command
|
|
486
|
-
if (typeof
|
|
487
|
-
const binary =
|
|
266
|
+
const { command, args } = entry;
|
|
267
|
+
if (typeof command !== "string" || command.length === 0) return "wrong-command";
|
|
268
|
+
const binary = command.split(/[\\/]/).pop();
|
|
488
269
|
const runsRouter = binary === "tenjin" && Array.isArray(args) && args.length === 1 && args[0] === "mcp";
|
|
489
270
|
return runsRouter ? "ok" : "wrong-command";
|
|
490
271
|
}
|
|
@@ -615,8 +396,8 @@ async function removeFromSettings(found, out) {
|
|
|
615
396
|
delete next.statusLine;
|
|
616
397
|
out.statusLine = "removed";
|
|
617
398
|
} else if (found.statusLine === "composed" && isPlainObject(read.settings.statusLine)) {
|
|
618
|
-
const
|
|
619
|
-
const original = typeof
|
|
399
|
+
const command = read.settings.statusLine.command;
|
|
400
|
+
const original = typeof command === "string" ? decomposeCommand(command) : null;
|
|
620
401
|
if (original !== null) {
|
|
621
402
|
next.statusLine = { ...read.settings.statusLine, command: original };
|
|
622
403
|
out.statusLine = "restored";
|
|
@@ -660,200 +441,15 @@ async function removeMcpEntry(opts, out) {
|
|
|
660
441
|
}
|
|
661
442
|
}
|
|
662
443
|
function projectMcpFile(cwd) {
|
|
663
|
-
return
|
|
444
|
+
return join2(cwd, ".mcp.json");
|
|
664
445
|
}
|
|
665
446
|
|
|
666
447
|
// src/router/plugin-registration.ts
|
|
667
|
-
import { readFile as
|
|
668
|
-
import { dirname as
|
|
448
|
+
import { readFile as readFile2, stat as stat2 } from "node:fs/promises";
|
|
449
|
+
import { dirname as dirname2, join as join3 } from "node:path";
|
|
669
450
|
import { fileURLToPath } from "node:url";
|
|
670
|
-
|
|
671
|
-
// src/router/plugin-files.ts
|
|
672
|
-
var ROUTE_HOOK_TIMEOUT_SECONDS = 5;
|
|
673
|
-
var AFTER_CALL_TIMEOUT_SECONDS = 15;
|
|
674
|
-
var LOCAL_HOOK_TIMEOUT_SECONDS = 5;
|
|
675
|
-
var DELEGATION_MATCHER = "Agent|Task";
|
|
676
|
-
var NATIVE_MATCHER = "WebSearch|WebFetch";
|
|
677
|
-
var ASK_MATCHER = "AskUserQuestion";
|
|
678
|
-
var PLUGIN_ROOT_ENTRY = "${CLAUDE_PLUGIN_ROOT}/../../../index.js";
|
|
679
|
-
function cliLaunch(args, entry = PLUGIN_ROOT_ENTRY) {
|
|
680
|
-
return { command: "node", args: [entry, ...args] };
|
|
681
|
-
}
|
|
682
|
-
var ALIVE_ARGS = ["hook", "alive"];
|
|
683
|
-
function permissionAnswer(decision, reason) {
|
|
684
|
-
return JSON.stringify({
|
|
685
|
-
hookSpecificOutput: {
|
|
686
|
-
hookEventName: "PreToolUse",
|
|
687
|
-
permissionDecision: decision,
|
|
688
|
-
permissionDecisionReason: reason
|
|
689
|
-
}
|
|
690
|
-
});
|
|
691
|
-
}
|
|
692
|
-
var PRINT_ARGUMENT = "process.stdout.write(process.argv[1])";
|
|
693
|
-
function printed(answer) {
|
|
694
|
-
return { command: "node", args: ["-e", PRINT_ARGUMENT, answer] };
|
|
695
|
-
}
|
|
696
|
-
var DENY_HOOK = printed(
|
|
697
|
-
permissionAnswer(
|
|
698
|
-
"deny",
|
|
699
|
-
`Only the Tenjin hooks call this tool. To make a lookup, call ${REQUEST_TOOL}.`
|
|
700
|
-
)
|
|
701
|
-
);
|
|
702
|
-
var ALLOW_HOOK = printed(permissionAnswer("allow", "Tenjin lookup"));
|
|
703
|
-
function leg(kind, timeout = ROUTE_HOOK_TIMEOUT_SECONDS) {
|
|
704
|
-
return [
|
|
705
|
-
{
|
|
706
|
-
type: "mcp_tool",
|
|
707
|
-
server: PLUGIN_SERVER,
|
|
708
|
-
tool: HOOK_TOOL,
|
|
709
|
-
input: hookToolInput(kind),
|
|
710
|
-
timeout
|
|
711
|
-
}
|
|
712
|
-
];
|
|
713
|
-
}
|
|
714
|
-
function command(launch) {
|
|
715
|
-
return [{ type: "command", ...launch, timeout: LOCAL_HOOK_TIMEOUT_SECONDS }];
|
|
716
|
-
}
|
|
717
|
-
function routerHookPlan() {
|
|
718
|
-
const afterCall = () => leg("shortfall", AFTER_CALL_TIMEOUT_SECONDS);
|
|
719
|
-
return [
|
|
720
|
-
{ event: "UserPromptSubmit", hooks: leg("prompt") },
|
|
721
|
-
{ event: "PreToolUse", matcher: NATIVE_MATCHER, hooks: leg("native") },
|
|
722
|
-
{ event: "PreToolUse", matcher: DELEGATION_MATCHER, hooks: leg("agent") },
|
|
723
|
-
{ event: "PostToolUse", matcher: NATIVE_MATCHER, hooks: afterCall() },
|
|
724
|
-
{ event: "PostToolUseFailure", matcher: NATIVE_MATCHER, hooks: afterCall() },
|
|
725
|
-
{ event: "PreToolUse", matcher: ASK_MATCHER, hooks: leg("ask") },
|
|
726
|
-
{ event: "PostToolUse", matcher: ASK_MATCHER, hooks: leg("answer") }
|
|
727
|
-
];
|
|
728
|
-
}
|
|
729
|
-
function renderPluginHooks(entry = PLUGIN_ROOT_ENTRY) {
|
|
730
|
-
const plan = [
|
|
731
|
-
{ event: "SessionStart", hooks: command(cliLaunch(ALIVE_ARGS, entry)) },
|
|
732
|
-
...routerHookPlan(),
|
|
733
|
-
{ event: "PreToolUse", matcher: PLUGIN_HOOK_TOOL, hooks: command(DENY_HOOK) },
|
|
734
|
-
{ event: "PreToolUse", matcher: REQUEST_TOOL, hooks: command(ALLOW_HOOK) }
|
|
735
|
-
];
|
|
736
|
-
const hooks = {};
|
|
737
|
-
for (const { event, hooks: handlers, ...rest } of plan) {
|
|
738
|
-
(hooks[event] ??= []).push({ ...rest, hooks: handlers });
|
|
739
|
-
}
|
|
740
|
-
return { hooks };
|
|
741
|
-
}
|
|
742
|
-
var PLUGIN_MCP_ARGS = ["mcp", "--plugin"];
|
|
743
|
-
function renderPluginMcp(entry = PLUGIN_ROOT_ENTRY) {
|
|
744
|
-
return { mcpServers: { [MCP_SERVER_NAME]: cliLaunch(PLUGIN_MCP_ARGS, entry) } };
|
|
745
|
-
}
|
|
746
|
-
var OWNER_MARKER = "tenjin-cli";
|
|
747
|
-
var UNBUILT = "source";
|
|
748
|
-
var DESCRIPTION = "Tenjin picks the right tool when your agent needs one, and one wallet on this machine pays for every call.";
|
|
749
|
-
function renderPluginManifest(version) {
|
|
750
|
-
return {
|
|
751
|
-
name: PLUGIN_NAME,
|
|
752
|
-
...version !== void 0 ? { version } : {},
|
|
753
|
-
description: DESCRIPTION,
|
|
754
|
-
author: { name: "Tenjin", url: PRODUCTION_ORIGIN },
|
|
755
|
-
homepage: `${PRODUCTION_ORIGIN}/agents`,
|
|
756
|
-
repository: "https://github.com/BackTrackCo/tenjin-agent",
|
|
757
|
-
metadata: { [OWNER_MARKER]: version ?? UNBUILT }
|
|
758
|
-
};
|
|
759
|
-
}
|
|
760
|
-
var PLUGIN_DIR = PLUGIN_NAME;
|
|
761
|
-
var PLUGIN_FILES = [
|
|
762
|
-
".mcp.json",
|
|
763
|
-
"hooks/hooks.json",
|
|
764
|
-
".claude-plugin/plugin.json"
|
|
765
|
-
];
|
|
766
|
-
var json = (value) => `${JSON.stringify(value, null, 2)}
|
|
767
|
-
`;
|
|
768
|
-
function renderPluginFiles(version, entry) {
|
|
769
|
-
return {
|
|
770
|
-
".mcp.json": json(renderPluginMcp(entry)),
|
|
771
|
-
"hooks/hooks.json": json(renderPluginHooks(entry)),
|
|
772
|
-
".claude-plugin/plugin.json": json(renderPluginManifest(version))
|
|
773
|
-
};
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
// src/router/plugin-folder.ts
|
|
777
|
-
import { lstat, readdir as readdir2, readFile as readFile2, rm as rm2, rmdir as rmdir2 } from "node:fs/promises";
|
|
778
|
-
import { dirname as dirname3, join as join5, relative, sep as sep2 } from "node:path";
|
|
779
|
-
var FOLDER_NAME = "tenjin-router";
|
|
780
|
-
function pluginFolderPath(base) {
|
|
781
|
-
return join5(base, "skills", FOLDER_NAME);
|
|
782
|
-
}
|
|
783
|
-
async function inspectPluginFolder(dir) {
|
|
784
|
-
const entry = await lstat(dir).catch(() => null);
|
|
785
|
-
if (entry === null) return "absent";
|
|
786
|
-
if (!entry.isDirectory() || entry.isSymbolicLink()) return "foreign";
|
|
787
|
-
try {
|
|
788
|
-
const manifest = JSON.parse(
|
|
789
|
-
await readFile2(join5(dir, ".claude-plugin", "plugin.json"), "utf8")
|
|
790
|
-
);
|
|
791
|
-
const marked = manifest.metadata !== null && typeof manifest.metadata === "object" && OWNER_MARKER in manifest.metadata;
|
|
792
|
-
return manifest.name === PLUGIN_NAME && marked ? "ours" : "foreign";
|
|
793
|
-
} catch {
|
|
794
|
-
return "foreign";
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
async function writePluginFolder(dir, files) {
|
|
798
|
-
const state = await inspectPluginFolder(dir);
|
|
799
|
-
if (state === "foreign") {
|
|
800
|
-
return {
|
|
801
|
-
path: dir,
|
|
802
|
-
state: "refused",
|
|
803
|
-
reason: `${dir} exists and is not a folder this CLI wrote, so it was left as it is`
|
|
804
|
-
};
|
|
805
|
-
}
|
|
806
|
-
try {
|
|
807
|
-
for (const path of PLUGIN_FILES) {
|
|
808
|
-
const body = files[path];
|
|
809
|
-
if (body === void 0) continue;
|
|
810
|
-
await writeFileAtomic(join5(dir, path), body);
|
|
811
|
-
}
|
|
812
|
-
} catch (err) {
|
|
813
|
-
return {
|
|
814
|
-
path: dir,
|
|
815
|
-
state: "refused",
|
|
816
|
-
reason: err instanceof Error ? err.message : String(err)
|
|
817
|
-
};
|
|
818
|
-
}
|
|
819
|
-
return { path: dir, state: "written" };
|
|
820
|
-
}
|
|
821
|
-
async function removePluginFolder(dir) {
|
|
822
|
-
const state = await inspectPluginFolder(dir);
|
|
823
|
-
if (state === "absent") return { path: dir, removed: false, left: [] };
|
|
824
|
-
if (state === "foreign") {
|
|
825
|
-
return {
|
|
826
|
-
path: dir,
|
|
827
|
-
removed: false,
|
|
828
|
-
left: [],
|
|
829
|
-
reason: `${dir} is not a folder this CLI wrote, so nothing in it was removed`
|
|
830
|
-
};
|
|
831
|
-
}
|
|
832
|
-
for (const path of PLUGIN_FILES) await rm2(join5(dir, path), { force: true });
|
|
833
|
-
const subdirs = [...new Set(PLUGIN_FILES.map((p) => dirname3(p)).filter((d) => d !== "."))].sort(
|
|
834
|
-
(a, b) => b.split("/").length - a.split("/").length
|
|
835
|
-
);
|
|
836
|
-
for (const sub of subdirs) await rmdir2(join5(dir, sub)).catch(() => void 0);
|
|
837
|
-
const left = await listFiles(dir);
|
|
838
|
-
if (left.length === 0) await rmdir2(dir).catch(() => void 0);
|
|
839
|
-
return { path: dir, removed: true, left };
|
|
840
|
-
}
|
|
841
|
-
async function listFiles(dir) {
|
|
842
|
-
const out = [];
|
|
843
|
-
const walk = async (current) => {
|
|
844
|
-
for (const entry of await readdir2(current, { withFileTypes: true }).catch(() => [])) {
|
|
845
|
-
const path = join5(current, entry.name);
|
|
846
|
-
if (entry.isDirectory()) await walk(path);
|
|
847
|
-
else out.push(relative(dir, path).split(sep2).join("/"));
|
|
848
|
-
}
|
|
849
|
-
};
|
|
850
|
-
await walk(dir);
|
|
851
|
-
return out.sort();
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
// src/router/plugin-registration.ts
|
|
855
451
|
function folderFor(scope, env, home, cwd) {
|
|
856
|
-
return pluginFolderPath(scope === "local" ?
|
|
452
|
+
return pluginFolderPath(scope === "local" ? join3(cwd, ".claude") : claudeConfigDir(env, home));
|
|
857
453
|
}
|
|
858
454
|
async function registerPlugin(opts) {
|
|
859
455
|
const folder = folderFor(opts.scope, opts.env, opts.home, opts.cwd);
|
|
@@ -908,7 +504,10 @@ async function registerPlugin(opts) {
|
|
|
908
504
|
}
|
|
909
505
|
const written = await writePluginFolder(
|
|
910
506
|
folder,
|
|
911
|
-
renderPluginFiles(opts.version, opts.cliEntry ?? packageCliEntry()
|
|
507
|
+
renderPluginFiles(opts.version, opts.cliEntry ?? packageCliEntry(), {
|
|
508
|
+
node: opts.node,
|
|
509
|
+
mod: await packageMod(opts.hostsDir)
|
|
510
|
+
})
|
|
912
511
|
);
|
|
913
512
|
if (written.state === "written") {
|
|
914
513
|
return {
|
|
@@ -972,10 +571,14 @@ async function viaPluginCommands(binary, hosts, opts, steps) {
|
|
|
972
571
|
return { ok: true, state: "installed" };
|
|
973
572
|
}
|
|
974
573
|
if (installed === available) return { ok: true, state: "current" };
|
|
975
|
-
const
|
|
976
|
-
if (!
|
|
574
|
+
const update2 = await step(steps, ["plugin", "update", PLUGIN_ID, ...scopeArgs, "--json"], run);
|
|
575
|
+
if (!update2.ok) return { ok: false, reason: `claude plugin update failed: ${update2.detail}` };
|
|
977
576
|
return { ok: true, state: "updated" };
|
|
978
577
|
}
|
|
578
|
+
function marketplaceAdded(reg, hosts) {
|
|
579
|
+
const add = `claude plugin marketplace add ${hosts} `;
|
|
580
|
+
return reg.steps.some((s) => s.ok && s.command.startsWith(add));
|
|
581
|
+
}
|
|
979
582
|
async function step(steps, args, run) {
|
|
980
583
|
const out = await run(args);
|
|
981
584
|
const result = jsonResult(out.stdout);
|
|
@@ -994,9 +597,9 @@ async function ownMarketplace(row) {
|
|
|
994
597
|
const path = typeof row.path === "string" ? row.path : void 0;
|
|
995
598
|
if (row.source !== "directory" || path === void 0) return false;
|
|
996
599
|
if (await stat2(path).catch(() => null) === null) {
|
|
997
|
-
return /tenjin-cli[\\/]dist[\\/]hosts[\\/]claude$/.test(path);
|
|
600
|
+
return /tenjin-cli[\\/]dist[\\/]hosts[\\/]claude$/.test(path) || /[\\/]runtime[\\/]claude$/.test(path);
|
|
998
601
|
}
|
|
999
|
-
return await inspectPluginFolder(
|
|
602
|
+
return await inspectPluginFolder(join3(path, PLUGIN_DIR)) === "ours";
|
|
1000
603
|
}
|
|
1001
604
|
async function existingCopy(binary, env, home, cwd) {
|
|
1002
605
|
const out = await runClaude(binary, ["plugin", "list", "--json"], { env, cwd });
|
|
@@ -1007,10 +610,40 @@ async function existingCopy(binary, env, home, cwd) {
|
|
|
1007
610
|
);
|
|
1008
611
|
return typeof row?.id === "string" ? row.id : null;
|
|
1009
612
|
}
|
|
613
|
+
async function recordedInstalls(env, home) {
|
|
614
|
+
let raw;
|
|
615
|
+
try {
|
|
616
|
+
raw = await readFile2(
|
|
617
|
+
join3(claudeConfigDir(env, home), "plugins", "installed_plugins.json"),
|
|
618
|
+
"utf8"
|
|
619
|
+
);
|
|
620
|
+
} catch (err) {
|
|
621
|
+
return hasCode(err, "ENOENT") ? [] : null;
|
|
622
|
+
}
|
|
623
|
+
let plugins;
|
|
624
|
+
try {
|
|
625
|
+
plugins = JSON.parse(raw).plugins;
|
|
626
|
+
} catch {
|
|
627
|
+
return null;
|
|
628
|
+
}
|
|
629
|
+
if (typeof plugins !== "object" || plugins === null || Array.isArray(plugins)) return null;
|
|
630
|
+
const entries = plugins[PLUGIN_ID];
|
|
631
|
+
if (!Array.isArray(entries)) return [];
|
|
632
|
+
const records = [];
|
|
633
|
+
for (const entry of entries) {
|
|
634
|
+
if (typeof entry !== "object" || entry === null) continue;
|
|
635
|
+
const { scope, projectPath } = entry;
|
|
636
|
+
if (scope === "user") records.push({ scope, projectPath: null });
|
|
637
|
+
else if (scope === "local" && typeof projectPath === "string" && projectPath.length > 0) {
|
|
638
|
+
records.push({ scope, projectPath });
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
return records;
|
|
642
|
+
}
|
|
1010
643
|
async function installedThroughCommands(env, home) {
|
|
1011
644
|
try {
|
|
1012
|
-
const raw = await
|
|
1013
|
-
|
|
645
|
+
const raw = await readFile2(
|
|
646
|
+
join3(claudeConfigDir(env, home), "plugins", "installed_plugins.json"),
|
|
1014
647
|
"utf8"
|
|
1015
648
|
);
|
|
1016
649
|
const plugins = JSON.parse(raw).plugins;
|
|
@@ -1019,27 +652,40 @@ async function installedThroughCommands(env, home) {
|
|
|
1019
652
|
return false;
|
|
1020
653
|
}
|
|
1021
654
|
}
|
|
1022
|
-
async function packageHostsDir(moduleDir =
|
|
1023
|
-
const catalog =
|
|
655
|
+
async function packageHostsDir(moduleDir = dirname2(fileURLToPath(import.meta.url))) {
|
|
656
|
+
const catalog = join3(moduleDir, "hosts", "claude", ".claude-plugin", "marketplace.json");
|
|
1024
657
|
const stable = versionFreeEntry(catalog) ?? catalog;
|
|
1025
658
|
if ((await stat2(stable).catch(() => null))?.isFile() !== true) return null;
|
|
1026
|
-
return
|
|
659
|
+
return dirname2(dirname2(stable));
|
|
660
|
+
}
|
|
661
|
+
async function packageMod(hostsDir) {
|
|
662
|
+
const hosts = hostsDir === void 0 ? await packageHostsDir() : hostsDir;
|
|
663
|
+
return hosts === null ? void 0 : readModSources(join3(hosts, PLUGIN_DIR));
|
|
1027
664
|
}
|
|
1028
|
-
function packageCliEntry(moduleDir =
|
|
1029
|
-
const entry =
|
|
665
|
+
function packageCliEntry(moduleDir = dirname2(fileURLToPath(import.meta.url))) {
|
|
666
|
+
const entry = join3(moduleDir, "index.js");
|
|
1030
667
|
return versionFreeEntry(entry) ?? entry;
|
|
1031
668
|
}
|
|
1032
669
|
async function readPluginListing(binary, env, cwd) {
|
|
1033
670
|
const out = await runClaude(binary, ["plugin", "list", "--json"], { env, cwd });
|
|
1034
671
|
const rows = out.code === 0 ? jsonList(out.stdout) : null;
|
|
1035
|
-
if (rows === null)
|
|
672
|
+
if (rows === null) {
|
|
673
|
+
return { id: null, enabled: false, version: null, read: false, scope: null, projects: [] };
|
|
674
|
+
}
|
|
675
|
+
const projects = rows.filter(
|
|
676
|
+
(r) => r.id === PLUGIN_ID && r.enabled !== true && typeof r.projectPath === "string" && r.projectPath.length > 0
|
|
677
|
+
).map((r) => r.projectPath);
|
|
1036
678
|
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);
|
|
1037
|
-
if (row === void 0)
|
|
679
|
+
if (row === void 0) {
|
|
680
|
+
return { id: null, enabled: false, version: null, read: true, scope: null, projects };
|
|
681
|
+
}
|
|
1038
682
|
return {
|
|
1039
683
|
id: String(row.id),
|
|
1040
684
|
enabled: row.enabled === true,
|
|
1041
685
|
version: typeof row.version === "string" ? row.version : null,
|
|
1042
|
-
read: true
|
|
686
|
+
read: true,
|
|
687
|
+
scope: typeof row.scope === "string" ? row.scope : null,
|
|
688
|
+
projects
|
|
1043
689
|
};
|
|
1044
690
|
}
|
|
1045
691
|
async function folderState(scope, env, home, cwd) {
|
|
@@ -1161,111 +807,20 @@ function proxyCredentialsFix(env) {
|
|
|
1161
807
|
return `Put the proxy's credentials in ${proxy} (\`http://user:password@proxy:port\`), then try again.`;
|
|
1162
808
|
}
|
|
1163
809
|
|
|
1164
|
-
// src/router/mcp-processes.ts
|
|
1165
|
-
import { execFile as execFile2 } from "node:child_process";
|
|
1166
|
-
import { stat as stat3 } from "node:fs/promises";
|
|
1167
|
-
import { dirname as dirname5, join as join7 } from "node:path";
|
|
1168
|
-
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
1169
|
-
import { promisify } from "node:util";
|
|
1170
|
-
var exec = promisify(execFile2);
|
|
1171
|
-
var listMcpProcesses = async () => {
|
|
1172
|
-
if (process.platform === "win32" || typeof process.getuid !== "function") return null;
|
|
1173
|
-
try {
|
|
1174
|
-
const { stdout } = await exec(
|
|
1175
|
-
"ps",
|
|
1176
|
-
["-U", String(process.getuid()), "-o", "pid=,lstart=,args="],
|
|
1177
|
-
{ timeout: 5e3, env: { ...process.env, LC_ALL: "C" }, maxBuffer: 4 * 1024 * 1024 }
|
|
1178
|
-
);
|
|
1179
|
-
return parsePs(stdout, process.pid);
|
|
1180
|
-
} catch {
|
|
1181
|
-
return null;
|
|
1182
|
-
}
|
|
1183
|
-
};
|
|
1184
|
-
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+(.*)$/;
|
|
1185
|
-
function parsePs(stdout, selfPid) {
|
|
1186
|
-
const found = [];
|
|
1187
|
-
for (const line of stdout.split("\n")) {
|
|
1188
|
-
const m = PS_LINE.exec(line);
|
|
1189
|
-
if (m === null) continue;
|
|
1190
|
-
const pid = Number(m[1]);
|
|
1191
|
-
if (pid === selfPid || !isTenjinMcp(m[3])) continue;
|
|
1192
|
-
const startedAt = Date.parse(m[2].replace(/\s+/g, " "));
|
|
1193
|
-
found.push({ pid, startedAt: Number.isNaN(startedAt) ? null : startedAt });
|
|
1194
|
-
}
|
|
1195
|
-
return found;
|
|
1196
|
-
}
|
|
1197
|
-
function isTenjinMcp(args) {
|
|
1198
|
-
const tokens = args.trim().split(/\s+/);
|
|
1199
|
-
const bin = tokens.findIndex(
|
|
1200
|
-
(t) => /(^|[/\\])tenjin(\.js|\.cmd)?$/.test(t) || /[/\\]tenjin-cli[/\\]/.test(t) || /[/\\]hosts[/\\]claude[/\\]tenjin[/\\]\.\.[/\\]\.\.[/\\]\.\.[/\\]index\.js$/.test(t)
|
|
1201
|
-
);
|
|
1202
|
-
return bin >= 0 && tokens[bin + 1] === "mcp";
|
|
1203
|
-
}
|
|
1204
|
-
var installedAt = async () => {
|
|
1205
|
-
let dir = dirname5(fileURLToPath2(import.meta.url));
|
|
1206
|
-
for (let i = 0; i < 6; i += 1) {
|
|
1207
|
-
try {
|
|
1208
|
-
const st = await stat3(join7(dir, "package.json"));
|
|
1209
|
-
return Math.max(st.ctimeMs, st.mtimeMs);
|
|
1210
|
-
} catch {
|
|
1211
|
-
dir = dirname5(dir);
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
return null;
|
|
1215
|
-
};
|
|
1216
|
-
var RECONNECT_FIX = "Type /reload-plugins in this Claude Code session, or start a new session.";
|
|
1217
|
-
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.";
|
|
1218
|
-
function mcpServersState(procs, installed, version = package_default.version, fix = RECONNECT_FIX) {
|
|
1219
|
-
const check = (detail) => ({
|
|
1220
|
-
stale: 0,
|
|
1221
|
-
check: { name: "mcp server", status: "ok", required: false, detail }
|
|
1222
|
-
});
|
|
1223
|
-
if (procs === null) {
|
|
1224
|
-
return check("unknown: running `tenjin mcp` processes cannot be listed on this platform");
|
|
1225
|
-
}
|
|
1226
|
-
if (procs.length === 0) return check("none running (starts with the next session)");
|
|
1227
|
-
if (installed === null) {
|
|
1228
|
-
return check(`${procs.length} running; when this build was installed is unknown`);
|
|
1229
|
-
}
|
|
1230
|
-
const stale = procs.filter((p) => p.startedAt !== null && p.startedAt < installed).length;
|
|
1231
|
-
if (stale === 0) {
|
|
1232
|
-
return check(`${procs.length} running, all started after this install`);
|
|
1233
|
-
}
|
|
1234
|
-
const which = stale === 1 ? "process" : "processes";
|
|
1235
|
-
return {
|
|
1236
|
-
stale,
|
|
1237
|
-
check: {
|
|
1238
|
-
name: "mcp server",
|
|
1239
|
-
status: "warn",
|
|
1240
|
-
required: false,
|
|
1241
|
-
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"`,
|
|
1242
|
-
fix
|
|
1243
|
-
}
|
|
1244
|
-
};
|
|
1245
|
-
}
|
|
1246
|
-
async function readMcpServers(deps = {}, opts = {}) {
|
|
1247
|
-
const [procs, installed] = await Promise.all([
|
|
1248
|
-
(deps.listMcpProcesses ?? listMcpProcesses)().catch(() => null),
|
|
1249
|
-
(deps.installedAt ?? installedAt)().catch(() => null)
|
|
1250
|
-
]);
|
|
1251
|
-
const fix = opts.settingsInstallPending === true ? NEW_SESSION_FIX : RECONNECT_FIX;
|
|
1252
|
-
return mcpServersState(procs, installed, package_default.version, fix);
|
|
1253
|
-
}
|
|
1254
|
-
|
|
1255
810
|
// src/router/install.ts
|
|
1256
811
|
var DISCLOSURE = [
|
|
1257
812
|
"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.",
|
|
1258
813
|
"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.",
|
|
1259
814
|
"What never leaves: your private key. It is decrypted in this CLI to sign, and never sent anywhere."
|
|
1260
815
|
];
|
|
1261
|
-
var RELOAD_STEP = "type /reload-plugins in this Claude Code session, or start a new session, so Tenjin loads";
|
|
1262
816
|
var NEW_SESSION_STEP = "start a new Claude Code session so Tenjin loads";
|
|
1263
|
-
|
|
1264
|
-
|
|
817
|
+
var RELOAD_STEP = NEW_SESSION_STEP;
|
|
818
|
+
function loadStep(_settingsInstallPresent) {
|
|
819
|
+
return NEW_SESSION_STEP;
|
|
1265
820
|
}
|
|
1266
821
|
function settingsInstallPaths(project, env, home, cwd) {
|
|
1267
822
|
return project ? {
|
|
1268
|
-
settingsPath:
|
|
823
|
+
settingsPath: join4(cwd, ".claude", "settings.json"),
|
|
1269
824
|
mcpFile: projectMcpFile(cwd),
|
|
1270
825
|
mcpScope: "project"
|
|
1271
826
|
} : {
|
|
@@ -1314,7 +869,7 @@ async function projectInstallHere(cwd, home, env) {
|
|
|
1314
869
|
return projectInstallAt(cwd, home, env);
|
|
1315
870
|
}
|
|
1316
871
|
async function projectInstallAt(dir, home, env) {
|
|
1317
|
-
const local = await
|
|
872
|
+
const local = await readFile3(join4(dir, ".claude", "settings.local.json"), "utf8").then((raw) => JSON.parse(raw)).catch(() => null);
|
|
1318
873
|
if (local?.enabledPlugins?.[PLUGIN_ID] === true) return true;
|
|
1319
874
|
if (await isHome(dir, home)) return false;
|
|
1320
875
|
if ((await folderState("local", env, home, dir)).state === "ours") return true;
|
|
@@ -1328,6 +883,7 @@ async function isHome(dir, home) {
|
|
|
1328
883
|
]);
|
|
1329
884
|
return dirPath === homePath;
|
|
1330
885
|
}
|
|
886
|
+
var NOTHING_TO_REFRESH = "Nothing to refresh";
|
|
1331
887
|
async function somethingToRefresh(claude, scope, legacy, env, home, cwd) {
|
|
1332
888
|
if (legacy.present) return true;
|
|
1333
889
|
if ((await folderState(scope, env, home, cwd)).state === "ours") return true;
|
|
@@ -1339,8 +895,8 @@ async function somethingToRefresh(claude, scope, legacy, env, home, cwd) {
|
|
|
1339
895
|
}
|
|
1340
896
|
async function runRouterInstall(args, ctx, deps = {}) {
|
|
1341
897
|
const env = deps.env ?? process.env;
|
|
1342
|
-
const home = deps.homeDir ??
|
|
1343
|
-
if (!
|
|
898
|
+
const home = deps.homeDir ?? homedir();
|
|
899
|
+
if (!isAbsolute(home)) {
|
|
1344
900
|
throw new CliError("INTERNAL", "The home directory is not an absolute path.", {
|
|
1345
901
|
fix: "Set HOME to your home directory (`export HOME=...`), then re-run `tenjin install`."
|
|
1346
902
|
});
|
|
@@ -1353,10 +909,28 @@ async function runRouterInstall(args, ctx, deps = {}) {
|
|
|
1353
909
|
const claude = await readClaudeCode(env, cwd, deps.findClaude ?? findClaudeBinary);
|
|
1354
910
|
const paths = settingsInstallPaths(project, env, home, cwd);
|
|
1355
911
|
const legacy = await inspectLegacyInstall(paths.settingsPath, paths.mcpFile);
|
|
912
|
+
if (!project) {
|
|
913
|
+
await recordClaudeProjects(ctx.dataDir, config.install?.routerProjects ?? [], env, home);
|
|
914
|
+
}
|
|
915
|
+
const setUpRuntime = () => (deps.runtime ?? defaultRuntime)({
|
|
916
|
+
dataDir: ctx.dataDir,
|
|
917
|
+
home,
|
|
918
|
+
env,
|
|
919
|
+
version: package_default.version,
|
|
920
|
+
moduleDir: dirname3(fileURLToPath2(import.meta.url)),
|
|
921
|
+
refresh: args.refresh === true
|
|
922
|
+
});
|
|
1356
923
|
if (args.refresh === true && !await somethingToRefresh(claude, scope, legacy, env, home, cwd)) {
|
|
924
|
+
if (!project && hasRuntime(ctx.dataDir, home)) {
|
|
925
|
+
const rt2 = await setUpRuntime();
|
|
926
|
+
if (runtimeLaunch(rt2) !== null) {
|
|
927
|
+
await collectRuntime(rt2.root, await fallbackFolders(ctx.dataDir, env, home, cwd, false));
|
|
928
|
+
}
|
|
929
|
+
return runtimeOnlyRefresh(ctx, rt2, home);
|
|
930
|
+
}
|
|
1357
931
|
throw new CliError(
|
|
1358
932
|
"REFUSED",
|
|
1359
|
-
|
|
933
|
+
`${NOTHING_TO_REFRESH}: neither the ${PLUGIN_ID} plugin nor a settings install of Tenjin is registered here.`,
|
|
1360
934
|
{ fix: "Run `tenjin install` to set this machine up." }
|
|
1361
935
|
);
|
|
1362
936
|
}
|
|
@@ -1370,16 +944,28 @@ async function runRouterInstall(args, ctx, deps = {}) {
|
|
|
1370
944
|
`Removed retired settings: ${spend.removed.join(", ")}. Automatic router limits remain in effect; manual pay always requires consent.`
|
|
1371
945
|
] : [];
|
|
1372
946
|
const removedSkills = await removeRetiredSkills(home, project ? cwd : void 0);
|
|
1373
|
-
const
|
|
947
|
+
const deferred = !claude.meetsFloor && legacy.present;
|
|
948
|
+
const rt = deferred ? null : await setUpRuntime();
|
|
949
|
+
const launch = runtimeLaunch(rt);
|
|
950
|
+
const plugin = deferred ? deferredRegistration(scope, claude) : await registerPlugin({
|
|
1374
951
|
binary: claude.binary,
|
|
1375
952
|
scope,
|
|
1376
|
-
version: package_default.version,
|
|
953
|
+
version: launch?.version ?? package_default.version,
|
|
1377
954
|
env,
|
|
1378
955
|
home,
|
|
1379
956
|
cwd,
|
|
1380
|
-
...
|
|
1381
|
-
|
|
957
|
+
...launch !== null ? { hostsDir: launch.hostsDir, cliEntry: launch.cliEntry, node: launch.node } : {
|
|
958
|
+
...deps.hostsDir !== void 0 ? { hostsDir: deps.hostsDir } : {},
|
|
959
|
+
...deps.cliEntry !== void 0 ? { cliEntry: deps.cliEntry } : {}
|
|
960
|
+
}
|
|
1382
961
|
});
|
|
962
|
+
if (rt !== null && launch !== null) {
|
|
963
|
+
if (plugin.state !== "failed") {
|
|
964
|
+
await collectRuntime(rt.root, await fallbackFolders(ctx.dataDir, env, home, cwd, project));
|
|
965
|
+
} else if (!marketplaceAdded(plugin, launch.hostsDir)) {
|
|
966
|
+
await rt.restore?.().catch(() => void 0);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
1383
969
|
if (project && plugin.state !== "failed") {
|
|
1384
970
|
await persistRouterProject(ctx.dataDir, cwd).catch(() => void 0);
|
|
1385
971
|
}
|
|
@@ -1390,10 +976,13 @@ async function runRouterInstall(args, ctx, deps = {}) {
|
|
|
1390
976
|
mcpScope: paths.mcpScope
|
|
1391
977
|
});
|
|
1392
978
|
const pending = settingsInstallStays(migration);
|
|
1393
|
-
const servers = await readMcpServers(deps, {
|
|
979
|
+
const servers = await readMcpServers(deps, {
|
|
980
|
+
settingsInstallPending: pending,
|
|
981
|
+
...launch !== null ? { version: launch.version } : {}
|
|
982
|
+
});
|
|
1394
983
|
const serverLines = servers.stale > 0 ? [paint(ctx.io, "yellow", `! ${servers.check.detail}. ${servers.check.fix ?? ""}`.trim())] : [];
|
|
1395
984
|
const claudeCode = claudeCodeData(claude);
|
|
1396
|
-
const notices = refreshNotices(plugin, claude, migration);
|
|
985
|
+
const notices = refreshNotices(plugin, claude, migration, rt, home);
|
|
1397
986
|
if (args.refresh === true) {
|
|
1398
987
|
if (plugin.state === "failed" && migration.state !== "pending") {
|
|
1399
988
|
throw new CliError(
|
|
@@ -1412,16 +1001,18 @@ async function runRouterInstall(args, ctx, deps = {}) {
|
|
|
1412
1001
|
spend,
|
|
1413
1002
|
removedSkills,
|
|
1414
1003
|
scope,
|
|
1415
|
-
mcpServer: servers.check
|
|
1004
|
+
mcpServer: servers.check,
|
|
1005
|
+
runtime: runtimeData(rt),
|
|
1006
|
+
launcher: rt?.launcher ?? null
|
|
1416
1007
|
},
|
|
1417
1008
|
humanLines: [
|
|
1418
|
-
...refreshLines(ctx, plugin, claude, migration),
|
|
1009
|
+
...refreshLines(ctx, plugin, claude, migration, rt, home),
|
|
1419
1010
|
...removedKeysLines,
|
|
1420
1011
|
...serverLines
|
|
1421
1012
|
]
|
|
1422
1013
|
};
|
|
1423
1014
|
}
|
|
1424
|
-
const { resolveWallet } = await import("./install-wallet-
|
|
1015
|
+
const { resolveWallet } = await import("./install-wallet-SAAPKB73.js");
|
|
1425
1016
|
const wallet = await resolveWallet(ctx, deps, args.noWallet === true ? "flag" : void 0, false);
|
|
1426
1017
|
const effective = await resolveContextSettings(ctx);
|
|
1427
1018
|
const spendAsk = !canPrompt && !answered && unasked ? spendStep(args) : void 0;
|
|
@@ -1444,7 +1035,14 @@ async function runRouterInstall(args, ctx, deps = {}) {
|
|
|
1444
1035
|
plugin,
|
|
1445
1036
|
claudeCode,
|
|
1446
1037
|
migration,
|
|
1447
|
-
next: nextStep(
|
|
1038
|
+
next: nextStep(
|
|
1039
|
+
plugin,
|
|
1040
|
+
claude,
|
|
1041
|
+
wallet,
|
|
1042
|
+
migration,
|
|
1043
|
+
asksAgent && nextSteps.length > 0,
|
|
1044
|
+
ctx.io.isTTY
|
|
1045
|
+
),
|
|
1448
1046
|
nextSteps,
|
|
1449
1047
|
// The check for this scope, said outright; a bare doctor in the project
|
|
1450
1048
|
// also finds it from what the project holds.
|
|
@@ -1458,7 +1056,9 @@ async function runRouterInstall(args, ctx, deps = {}) {
|
|
|
1458
1056
|
},
|
|
1459
1057
|
disclosure: DISCLOSURE,
|
|
1460
1058
|
removedSkills,
|
|
1461
|
-
mcpServer: servers.check
|
|
1059
|
+
mcpServer: servers.check,
|
|
1060
|
+
runtime: runtimeData(rt),
|
|
1061
|
+
launcher: rt?.launcher ?? null
|
|
1462
1062
|
};
|
|
1463
1063
|
return {
|
|
1464
1064
|
data,
|
|
@@ -1472,13 +1072,166 @@ async function runRouterInstall(args, ctx, deps = {}) {
|
|
|
1472
1072
|
asks: asksAgent && nextSteps.length > 0,
|
|
1473
1073
|
policy: effective.policy,
|
|
1474
1074
|
...spendAsk !== void 0 ? { spendAsk } : {},
|
|
1475
|
-
router
|
|
1075
|
+
router,
|
|
1076
|
+
rt,
|
|
1077
|
+
home
|
|
1476
1078
|
}),
|
|
1477
1079
|
...removedKeysLines,
|
|
1478
1080
|
...serverLines
|
|
1479
1081
|
]
|
|
1480
1082
|
};
|
|
1481
1083
|
}
|
|
1084
|
+
async function defaultRuntime(o) {
|
|
1085
|
+
const { setupRuntime } = await import("./runtime-UVNUA3AS.js");
|
|
1086
|
+
return setupRuntime(o);
|
|
1087
|
+
}
|
|
1088
|
+
var sharedResults = /* @__PURE__ */ new WeakSet();
|
|
1089
|
+
function runtimeOncePerRun(setup = defaultRuntime) {
|
|
1090
|
+
let first;
|
|
1091
|
+
return async (o) => {
|
|
1092
|
+
if (first === void 0) {
|
|
1093
|
+
first = setup(o);
|
|
1094
|
+
return first;
|
|
1095
|
+
}
|
|
1096
|
+
const rt = { ...await first };
|
|
1097
|
+
sharedResults.add(rt);
|
|
1098
|
+
return rt;
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
function hasRuntime(dataDir, home) {
|
|
1102
|
+
return resolve(dataDir) === resolve(defaultDataDir(home)) && existsSync(runtimeStatePath(runtimeDir(dataDir)));
|
|
1103
|
+
}
|
|
1104
|
+
function runtimeOnlyRefresh(ctx, rt, home) {
|
|
1105
|
+
return {
|
|
1106
|
+
data: {
|
|
1107
|
+
plugin: null,
|
|
1108
|
+
refresh: true,
|
|
1109
|
+
scope: "user",
|
|
1110
|
+
notices: runtimeNotices(rt, home),
|
|
1111
|
+
runtime: runtimeData(rt),
|
|
1112
|
+
launcher: rt.launcher
|
|
1113
|
+
},
|
|
1114
|
+
humanLines: [
|
|
1115
|
+
`${paint(ctx.io, "green", "\u2713")} Tenjin's runtime is up to date; no Claude Code plugin is registered here, so none was refreshed`,
|
|
1116
|
+
...runtimeLines(ctx, rt, home)
|
|
1117
|
+
]
|
|
1118
|
+
};
|
|
1119
|
+
}
|
|
1120
|
+
async function collectRuntime(root, folders) {
|
|
1121
|
+
try {
|
|
1122
|
+
const { collect } = await import("./runtime-UVNUA3AS.js");
|
|
1123
|
+
await collect(root, { lockWaitMs: 5e3, keep: await folderPointers(root, folders) });
|
|
1124
|
+
} catch {
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
async function fallbackFolders(dataDir, env, home, cwd, project) {
|
|
1128
|
+
const projects = (await loadRawConfig(dataDir).catch(() => null))?.install?.routerProjects ?? [];
|
|
1129
|
+
return [
|
|
1130
|
+
folderFor("user", env, home, cwd),
|
|
1131
|
+
...[...projects, ...project ? [cwd] : []].map((dir) => folderFor("local", env, home, dir))
|
|
1132
|
+
];
|
|
1133
|
+
}
|
|
1134
|
+
var NODE_DIR_RE = /^\d+\.\d+\.\d+$/;
|
|
1135
|
+
async function folderPointers(root, folders) {
|
|
1136
|
+
const pointers = [];
|
|
1137
|
+
for (const dir of folders) {
|
|
1138
|
+
if (await inspectPluginFolder(dir) !== "ours") continue;
|
|
1139
|
+
const server = await readFile3(join4(dir, ".mcp.json"), "utf8").then(
|
|
1140
|
+
(raw) => JSON.parse(raw).mcpServers?.[MCP_SERVER_NAME]
|
|
1141
|
+
).catch(() => void 0);
|
|
1142
|
+
const entry = Array.isArray(server?.args) ? server.args[0] : void 0;
|
|
1143
|
+
const node = server?.command;
|
|
1144
|
+
if (typeof entry !== "string" || typeof node !== "string") continue;
|
|
1145
|
+
const build = runtimeBuild(dirname3(entry));
|
|
1146
|
+
const nodeVersion = relative(join4(root, "node"), node).split(sep)[0] ?? "";
|
|
1147
|
+
if (build !== null && resolve(build.root) === resolve(root) && NODE_DIR_RE.test(nodeVersion)) {
|
|
1148
|
+
pointers.push({ cli: build.cli, node: nodeVersion });
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
return pointers;
|
|
1152
|
+
}
|
|
1153
|
+
function runtimeLaunch(rt) {
|
|
1154
|
+
if (rt === null || rt.state !== "active" && rt.state !== "current" && rt.state !== "kept") {
|
|
1155
|
+
return null;
|
|
1156
|
+
}
|
|
1157
|
+
if (rt.cli === void 0 || rt.hostsDir === void 0 || rt.entry === void 0 || rt.node === void 0) {
|
|
1158
|
+
return null;
|
|
1159
|
+
}
|
|
1160
|
+
return { version: rt.cli, hostsDir: rt.hostsDir, cliEntry: rt.entry, node: rt.node };
|
|
1161
|
+
}
|
|
1162
|
+
function runtimeData(rt) {
|
|
1163
|
+
if (rt === null) return null;
|
|
1164
|
+
return {
|
|
1165
|
+
state: rt.state,
|
|
1166
|
+
root: rt.root,
|
|
1167
|
+
...rt.cli !== void 0 ? { cli: rt.cli } : {},
|
|
1168
|
+
...rt.nodeVersion !== void 0 ? { nodeVersion: rt.nodeVersion } : {},
|
|
1169
|
+
...rt.reason !== void 0 ? { reason: rt.reason } : {},
|
|
1170
|
+
...rt.fix !== void 0 ? { fix: rt.fix } : {}
|
|
1171
|
+
};
|
|
1172
|
+
}
|
|
1173
|
+
async function recordClaudeProjects(dataDir, known, env, home) {
|
|
1174
|
+
const records = await recordedInstalls(env, home).catch(() => null);
|
|
1175
|
+
if (records === null || records.every((r) => r.projectPath === null)) return;
|
|
1176
|
+
const seen = /* @__PURE__ */ new Set([
|
|
1177
|
+
...known,
|
|
1178
|
+
...await Promise.all(known.map((dir) => realpath(dir).catch(() => dir)))
|
|
1179
|
+
]);
|
|
1180
|
+
for (const { projectPath } of records) {
|
|
1181
|
+
if (projectPath === null || seen.has(projectPath)) continue;
|
|
1182
|
+
if ((await stat3(projectPath).catch(() => null))?.isDirectory() !== true) continue;
|
|
1183
|
+
seen.add(projectPath);
|
|
1184
|
+
await persistRouterProject(dataDir, projectPath).catch(() => void 0);
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
function tilde(path, home) {
|
|
1188
|
+
return path === home || path.startsWith(`${home}${sep}`) ? `~${path.slice(home.length)}` : path;
|
|
1189
|
+
}
|
|
1190
|
+
function runtimeSentence(rt, home) {
|
|
1191
|
+
if (rt.state !== "active" || !rt.firstTime) return null;
|
|
1192
|
+
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.`;
|
|
1193
|
+
}
|
|
1194
|
+
function fallbackSentence(rt) {
|
|
1195
|
+
if (rt.state === "fallback" && rt.unpinned !== void 0) {
|
|
1196
|
+
return `Tenjin pins no Node for this platform (${rt.unpinned}), so the plugin runs from npm's copy on the Node on your PATH, as before.`;
|
|
1197
|
+
}
|
|
1198
|
+
const next = rt.fix ?? "run `tenjin install` again to retry";
|
|
1199
|
+
if (rt.state === "fallback") {
|
|
1200
|
+
return `Tenjin's own runtime could not be set up (${rt.reason ?? "unknown reason"}), so the plugin still runs on the Node on your PATH; ${next}.`;
|
|
1201
|
+
}
|
|
1202
|
+
if (rt.state === "kept" && rt.reason !== void 0 && rt.newer !== true) {
|
|
1203
|
+
const retry = rt.unpinned === void 0 ? `; ${next}` : "";
|
|
1204
|
+
return `tenjin-cli ${package_default.version} could not be set up (${rt.reason}), so Tenjin keeps running ${rt.cli ?? "the runtime it has"}${retry}.`;
|
|
1205
|
+
}
|
|
1206
|
+
return null;
|
|
1207
|
+
}
|
|
1208
|
+
function launcherSentence(launcher, home) {
|
|
1209
|
+
if (launcher === null) return null;
|
|
1210
|
+
if (launcher.state === "foreign") {
|
|
1211
|
+
const who = launcher.reason?.replace(/ is not Tenjin's$/, "") ?? launcher.paths[0] ?? "";
|
|
1212
|
+
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.`;
|
|
1213
|
+
}
|
|
1214
|
+
if (launcher.state === "failed") {
|
|
1215
|
+
const dir = launcher.paths[0] !== void 0 ? tilde(dirname3(launcher.paths[0]), home) : "";
|
|
1216
|
+
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.`;
|
|
1217
|
+
}
|
|
1218
|
+
if ((launcher.state === "written" || launcher.state === "current") && !launcher.onPath) {
|
|
1219
|
+
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 ?? ""}`;
|
|
1220
|
+
}
|
|
1221
|
+
return null;
|
|
1222
|
+
}
|
|
1223
|
+
function runtimeLines(ctx, rt, home) {
|
|
1224
|
+
if (rt === null || sharedResults.has(rt)) return [];
|
|
1225
|
+
const warn = (text) => paint(ctx.io, "yellow", `! ${text}`);
|
|
1226
|
+
const runs = runtimeSentence(rt, home);
|
|
1227
|
+
const fallback = fallbackSentence(rt);
|
|
1228
|
+
const launcher = launcherSentence(rt.launcher, home);
|
|
1229
|
+
return [
|
|
1230
|
+
...runs !== null ? [` ${runs}`] : [],
|
|
1231
|
+
...fallback !== null ? [warn(fallback)] : [],
|
|
1232
|
+
...launcher !== null ? [warn(launcher)] : []
|
|
1233
|
+
];
|
|
1234
|
+
}
|
|
1482
1235
|
function claudeCodeData(claude) {
|
|
1483
1236
|
return {
|
|
1484
1237
|
binary: claude.binary?.path ?? null,
|
|
@@ -1498,8 +1251,24 @@ function registrationFix(plugin) {
|
|
|
1498
1251
|
}
|
|
1499
1252
|
return `Run \`tenjin doctor${flag}\` to see the cause, then run \`tenjin install${flag}\` again.`;
|
|
1500
1253
|
}
|
|
1501
|
-
|
|
1254
|
+
var REPAIRABLE = /* @__PURE__ */ new Set([
|
|
1255
|
+
"passphrase_missing",
|
|
1256
|
+
"passphrase_wrong",
|
|
1257
|
+
"env_passphrase_wrong"
|
|
1258
|
+
]);
|
|
1259
|
+
function repairStep(tty) {
|
|
1260
|
+
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)";
|
|
1261
|
+
}
|
|
1262
|
+
function nextStep(plugin, claude, wallet, migration, asksQuestion, tty) {
|
|
1502
1263
|
if (plugin.state === "failed") return registrationFix(plugin);
|
|
1264
|
+
const steps = todaysSteps(plugin, claude, wallet, migration, asksQuestion);
|
|
1265
|
+
const signing = wallet.signing;
|
|
1266
|
+
if (signing?.status === "blocked" && REPAIRABLE.has(signing.reason)) {
|
|
1267
|
+
steps.unshift(repairStep(tty));
|
|
1268
|
+
}
|
|
1269
|
+
return steps.join(", then ");
|
|
1270
|
+
}
|
|
1271
|
+
function todaysSteps(plugin, claude, wallet, migration, asksQuestion) {
|
|
1503
1272
|
const steps = [];
|
|
1504
1273
|
if (asksQuestion) {
|
|
1505
1274
|
steps.push("ask the person the question in nextSteps, then run what the answer names");
|
|
@@ -1511,11 +1280,11 @@ function nextStep(plugin, claude, wallet, migration, asksQuestion) {
|
|
|
1511
1280
|
steps.push(
|
|
1512
1281
|
"run `tenjin install` again; until then the earlier Tenjin setup keeps routing as before"
|
|
1513
1282
|
);
|
|
1514
|
-
return steps
|
|
1283
|
+
return steps;
|
|
1515
1284
|
}
|
|
1516
1285
|
if (!claude.meetsFloor) steps.unshift("run `claude update`");
|
|
1517
1286
|
steps.push(loadStep(settingsInstallStays(migration)));
|
|
1518
|
-
return steps
|
|
1287
|
+
return steps;
|
|
1519
1288
|
}
|
|
1520
1289
|
function settingsInstallStays(migration) {
|
|
1521
1290
|
return migration.state === "pending" || migration.state === "blocked";
|
|
@@ -1541,7 +1310,7 @@ function statusLineNotice(migration) {
|
|
|
1541
1310
|
}
|
|
1542
1311
|
return null;
|
|
1543
1312
|
}
|
|
1544
|
-
function refreshNotices(plugin, claude, migration) {
|
|
1313
|
+
function refreshNotices(plugin, claude, migration, rt, home) {
|
|
1545
1314
|
const out = [];
|
|
1546
1315
|
if (plugin.state === "deferred") {
|
|
1547
1316
|
out.push(
|
|
@@ -1554,11 +1323,24 @@ function refreshNotices(plugin, claude, migration) {
|
|
|
1554
1323
|
}
|
|
1555
1324
|
const status = statusLineNotice(migration);
|
|
1556
1325
|
if (status !== null) out.push(status);
|
|
1326
|
+
if (rt !== null) out.push(...runtimeNotices(rt, home));
|
|
1327
|
+
return out;
|
|
1328
|
+
}
|
|
1329
|
+
function runtimeNotices(rt, home) {
|
|
1330
|
+
const out = [];
|
|
1331
|
+
const runs = runtimeSentence(rt, home);
|
|
1332
|
+
if (runs !== null) out.push(`Tenjin ${runs.charAt(0).toLowerCase()}${runs.slice(1)}`);
|
|
1333
|
+
for (const sentence of [fallbackSentence(rt), launcherSentence(rt.launcher, home)]) {
|
|
1334
|
+
if (sentence !== null) out.push(sentence);
|
|
1335
|
+
}
|
|
1557
1336
|
return out;
|
|
1558
1337
|
}
|
|
1559
1338
|
var SHOW_NOT_RUN = "Show the person addresses as written, and never ask them to run a command.";
|
|
1560
1339
|
function spendStep(args) {
|
|
1561
|
-
|
|
1340
|
+
return spendStepFor(installCommand(args));
|
|
1341
|
+
}
|
|
1342
|
+
function spendStepFor(command) {
|
|
1343
|
+
const options = spendOptions(command);
|
|
1562
1344
|
const [byDefault, custom] = options;
|
|
1563
1345
|
return {
|
|
1564
1346
|
id: "spend",
|
|
@@ -1630,7 +1412,7 @@ async function fundStep(wallet, rpcUrl, deps) {
|
|
|
1630
1412
|
};
|
|
1631
1413
|
}
|
|
1632
1414
|
async function defaultBalance(address, rpcUrl) {
|
|
1633
|
-
const { getUsdcBalance } = await import("./usdc-
|
|
1415
|
+
const { getUsdcBalance } = await import("./usdc-D6X7EIQ2.js");
|
|
1634
1416
|
return getUsdcBalance(address, rpcUrl);
|
|
1635
1417
|
}
|
|
1636
1418
|
function fundLines(fund) {
|
|
@@ -1718,8 +1500,46 @@ function effectiveLimits(policy) {
|
|
|
1718
1500
|
};
|
|
1719
1501
|
}
|
|
1720
1502
|
function walletLines(ctx, ok, w) {
|
|
1721
|
-
|
|
1722
|
-
if (w.status === "
|
|
1503
|
+
const warn = (text) => paint(ctx.io, "yellow", text);
|
|
1504
|
+
if (w.status === "created" || w.status === "existing") {
|
|
1505
|
+
const a = w.address ?? "";
|
|
1506
|
+
const signing = w.signing;
|
|
1507
|
+
const tty = ctx.io.isTTY;
|
|
1508
|
+
if (signing?.status === "blocked") {
|
|
1509
|
+
const wallet = Object.prototype.hasOwnProperty.call(WALLET_REASONS, signing.reason) ? WALLET_REASONS[signing.reason] : void 0;
|
|
1510
|
+
return [
|
|
1511
|
+
warn(`! Wallet ${a} cannot be unlocked by Claude Code: ${signing.detail}.`),
|
|
1512
|
+
` ${tty ? wallet?.fix ?? signing.fix : agentFixFor(signing.reason, signing.fix)}`
|
|
1513
|
+
];
|
|
1514
|
+
}
|
|
1515
|
+
if (signing?.status === "unknown") {
|
|
1516
|
+
return [
|
|
1517
|
+
warn(`! Wallet: ${a}; could not check that it unlocks (${signing.detail}).`),
|
|
1518
|
+
" Run `tenjin doctor` to check it again."
|
|
1519
|
+
];
|
|
1520
|
+
}
|
|
1521
|
+
if (w.shellOnly === "key") {
|
|
1522
|
+
return [
|
|
1523
|
+
warn(
|
|
1524
|
+
`! Wallet: ${a} signs here only through TENJIN_WALLET_KEY in this shell; Claude Code must have the same variable.`
|
|
1525
|
+
)
|
|
1526
|
+
];
|
|
1527
|
+
}
|
|
1528
|
+
if (w.shellOnly === "passphrase") {
|
|
1529
|
+
return [
|
|
1530
|
+
warn(
|
|
1531
|
+
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.`
|
|
1532
|
+
)
|
|
1533
|
+
];
|
|
1534
|
+
}
|
|
1535
|
+
if (w.status === "created") {
|
|
1536
|
+
return [
|
|
1537
|
+
`${ok} Wallet created: ${a}`,
|
|
1538
|
+
...w.passphrase !== void 0 ? [` ${w.passphrase.note}`] : []
|
|
1539
|
+
];
|
|
1540
|
+
}
|
|
1541
|
+
return [`${ok} Wallet: ${a}`];
|
|
1542
|
+
}
|
|
1723
1543
|
if (w.reason === "flag") return [" No wallet yet. Create one with: tenjin wallet create"];
|
|
1724
1544
|
return [
|
|
1725
1545
|
paint(ctx.io, "yellow", `! No wallet was created. ${w.warning ?? ""}`.trimEnd()),
|
|
@@ -1791,6 +1611,7 @@ function lines(ctx, s) {
|
|
|
1791
1611
|
return [
|
|
1792
1612
|
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})`,
|
|
1793
1613
|
...s.plugin.scope === "local" && s.plugin.state !== "failed" ? [" For this project only; check it with: tenjin doctor --project"] : [],
|
|
1614
|
+
...runtimeLines(ctx, s.rt, s.home),
|
|
1794
1615
|
...walletLines(ctx, ok, s.wallet),
|
|
1795
1616
|
...spend,
|
|
1796
1617
|
...s.fund !== void 0 ? fundLines(s.fund) : [],
|
|
@@ -1799,11 +1620,12 @@ function lines(ctx, s) {
|
|
|
1799
1620
|
...migrationLines(ctx, s.migration),
|
|
1800
1621
|
...router,
|
|
1801
1622
|
"",
|
|
1802
|
-
`Next: ${nextStep(s.plugin, s.claude, s.wallet, s.migration, s.asks)}`
|
|
1623
|
+
`Next: ${nextStep(s.plugin, s.claude, s.wallet, s.migration, s.asks, ctx.io.isTTY)}`
|
|
1803
1624
|
];
|
|
1804
1625
|
}
|
|
1805
|
-
function refreshLines(ctx, plugin, claude, migration) {
|
|
1626
|
+
function refreshLines(ctx, plugin, claude, migration, rt, home) {
|
|
1806
1627
|
const issues = [
|
|
1628
|
+
...runtimeLines(ctx, rt, home),
|
|
1807
1629
|
...pluginLines(ctx, plugin),
|
|
1808
1630
|
...claudeLines(ctx, claude),
|
|
1809
1631
|
...migrationLines(ctx, migration)
|
|
@@ -1814,11 +1636,45 @@ function refreshLines(ctx, plugin, claude, migration) {
|
|
|
1814
1636
|
|
|
1815
1637
|
// src/commands/update.ts
|
|
1816
1638
|
var INSTALL_TIMEOUT_MS = 3e5;
|
|
1639
|
+
var STAGE_TIMEOUT_MS = 12e4;
|
|
1640
|
+
var NODE_TIMEOUT_MS = 3e5;
|
|
1817
1641
|
function resolveManager(manager, deps) {
|
|
1818
1642
|
const script = deps.managerScript !== void 0 ? deps.managerScript : resolveManagerScript(manager, process.execPath);
|
|
1819
1643
|
return script === null ? { cmd: MANAGERS[manager].bin, prefix: [] } : { cmd: process.execPath, prefix: [script] };
|
|
1820
1644
|
}
|
|
1821
1645
|
async function runUpdate(opts, ctx, deps = {}) {
|
|
1646
|
+
if (opts.background !== true) return update(opts, ctx, deps);
|
|
1647
|
+
const root = deps.runtimeRoot ?? runtimeDir(ctx.dataDir);
|
|
1648
|
+
const [{ recordAutoUpdate }, { readRuntimeState }] = await Promise.all([
|
|
1649
|
+
import("./auto-update-OPWMRZLS.js"),
|
|
1650
|
+
import("./runtime-layout-BDWZG2TQ.js")
|
|
1651
|
+
]);
|
|
1652
|
+
const from = readRuntimeState(root)?.current.cli;
|
|
1653
|
+
const record = (r) => {
|
|
1654
|
+
if (!existsSync2(root)) return;
|
|
1655
|
+
try {
|
|
1656
|
+
recordAutoUpdate(root, { finishedAt: (/* @__PURE__ */ new Date()).toISOString(), ...r });
|
|
1657
|
+
} catch {
|
|
1658
|
+
}
|
|
1659
|
+
};
|
|
1660
|
+
try {
|
|
1661
|
+
const result = await update(opts, ctx, deps);
|
|
1662
|
+
const d = result.data;
|
|
1663
|
+
record(
|
|
1664
|
+
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 }
|
|
1665
|
+
);
|
|
1666
|
+
return result;
|
|
1667
|
+
} catch (err) {
|
|
1668
|
+
const reason = sanitizeForTerminal(err instanceof Error ? err.message : String(err)).trim();
|
|
1669
|
+
record({
|
|
1670
|
+
outcome: "failed",
|
|
1671
|
+
...from !== void 0 ? { from } : {},
|
|
1672
|
+
reason: reason.slice(0, REASON_LIMIT)
|
|
1673
|
+
});
|
|
1674
|
+
throw err;
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
async function update(opts, ctx, deps) {
|
|
1822
1678
|
const current = deps.currentVersion ?? package_default.version;
|
|
1823
1679
|
const channel = channelTag(current);
|
|
1824
1680
|
const moduleDir = deps.moduleDir ?? fileURLToPath3(new URL(".", import.meta.url));
|
|
@@ -1837,7 +1693,15 @@ async function runUpdate(opts, ctx, deps = {}) {
|
|
|
1837
1693
|
fix: "Check access to registry.npmjs.org and retry"
|
|
1838
1694
|
});
|
|
1839
1695
|
}
|
|
1840
|
-
const
|
|
1696
|
+
const runtime = await runtimeHere(ctx, deps, moduleDir);
|
|
1697
|
+
if (opts.background === true && runtime === null) {
|
|
1698
|
+
return {
|
|
1699
|
+
data: { skipped: "no runtime" },
|
|
1700
|
+
humanLines: ["Nothing to update in the background: Tenjin's runtime is not set up here."]
|
|
1701
|
+
};
|
|
1702
|
+
}
|
|
1703
|
+
const base = runtime?.current ?? current;
|
|
1704
|
+
const latest = resolveTarget(base, tags);
|
|
1841
1705
|
if (latest === null) {
|
|
1842
1706
|
const raw = tags[channel];
|
|
1843
1707
|
throw raw === void 0 ? new CliError("RESOURCE_NOT_FOUND", "npm has no published tenjin-cli on the latest tag", {
|
|
@@ -1851,28 +1715,32 @@ async function runUpdate(opts, ctx, deps = {}) {
|
|
|
1851
1715
|
}
|
|
1852
1716
|
);
|
|
1853
1717
|
}
|
|
1854
|
-
const updateAvailable = isNewer(latest,
|
|
1855
|
-
const data = (
|
|
1856
|
-
current,
|
|
1718
|
+
const updateAvailable = isNewer(latest, base);
|
|
1719
|
+
const data = (updated2) => ({
|
|
1720
|
+
current: base,
|
|
1857
1721
|
latest,
|
|
1858
1722
|
updateAvailable,
|
|
1859
|
-
updated
|
|
1723
|
+
updated: updated2
|
|
1860
1724
|
});
|
|
1861
1725
|
if (!updateAvailable) {
|
|
1862
1726
|
return {
|
|
1863
1727
|
data: data(false),
|
|
1864
|
-
humanLines: [`tenjin-cli ${
|
|
1728
|
+
humanLines: [`tenjin-cli ${base} is up to date`]
|
|
1865
1729
|
};
|
|
1866
1730
|
}
|
|
1867
1731
|
if (opts.check) {
|
|
1868
1732
|
return {
|
|
1869
1733
|
data: data(false),
|
|
1870
1734
|
humanLines: [
|
|
1871
|
-
`tenjin-cli ${latest} is available (you have ${
|
|
1735
|
+
`tenjin-cli ${latest} is available (you have ${base}).`,
|
|
1872
1736
|
"Run tenjin update to install it."
|
|
1873
1737
|
]
|
|
1874
1738
|
};
|
|
1875
1739
|
}
|
|
1740
|
+
if (runtime !== null) {
|
|
1741
|
+
return runtimeUpdate(ctx, deps, { ...runtime, base, latest, current, moduleDir, data });
|
|
1742
|
+
}
|
|
1743
|
+
await refuseRuntimeElsewhere(ctx, moduleDir, deps.homeDir ?? homedir2());
|
|
1876
1744
|
const spec = `tenjin-cli@${latest}`;
|
|
1877
1745
|
refuse(moduleDir, { check: false, spec });
|
|
1878
1746
|
const human = ctx.io.isTTY && !ctx.flags.json;
|
|
@@ -1889,7 +1757,7 @@ async function runUpdate(opts, ctx, deps = {}) {
|
|
|
1889
1757
|
const outcome = await (deps.spawnImpl ?? spawnCapture)(
|
|
1890
1758
|
resolved.cmd,
|
|
1891
1759
|
[...resolved.prefix, ...args],
|
|
1892
|
-
{ cwd:
|
|
1760
|
+
{ cwd: homedir2(), timeoutMs: INSTALL_TIMEOUT_MS },
|
|
1893
1761
|
onOutput
|
|
1894
1762
|
);
|
|
1895
1763
|
if (outcome.kind === "start-failed") {
|
|
@@ -1917,14 +1785,18 @@ async function runUpdate(opts, ctx, deps = {}) {
|
|
|
1917
1785
|
ctx.io,
|
|
1918
1786
|
`tenjin update: replaced the global tenjin-cli with ${latest} via ${manager}`
|
|
1919
1787
|
);
|
|
1920
|
-
const refresh = await refreshProfiles(ctx, deps);
|
|
1788
|
+
const { refresh } = await refreshProfiles(ctx, deps, npmLaunch(deps));
|
|
1789
|
+
return updated(deps, data(true), refresh, [`Updated tenjin-cli ${current} -> ${latest}.`]);
|
|
1790
|
+
}
|
|
1791
|
+
async function updated(deps, data, refresh, head, version) {
|
|
1921
1792
|
const servers = await readMcpServers(deps, {
|
|
1922
|
-
settingsInstallPending: refresh.settingsInstallPending
|
|
1793
|
+
settingsInstallPending: refresh.settingsInstallPending,
|
|
1794
|
+
...version !== void 0 ? { version } : {}
|
|
1923
1795
|
});
|
|
1924
1796
|
return {
|
|
1925
|
-
data: { ...data
|
|
1797
|
+
data: { ...data, refresh, mcpServer: servers.check },
|
|
1926
1798
|
humanLines: [
|
|
1927
|
-
|
|
1799
|
+
...head,
|
|
1928
1800
|
...refreshLines2(refresh),
|
|
1929
1801
|
...projectLines(refresh),
|
|
1930
1802
|
...refresh.notices,
|
|
@@ -1932,9 +1804,119 @@ async function runUpdate(opts, ctx, deps = {}) {
|
|
|
1932
1804
|
]
|
|
1933
1805
|
};
|
|
1934
1806
|
}
|
|
1807
|
+
async function runtimeHere(ctx, deps, moduleDir) {
|
|
1808
|
+
if (resolve2(ctx.dataDir) !== resolve2(defaultDataDir(deps.homeDir ?? homedir2()))) return null;
|
|
1809
|
+
const { readRuntimeState, runtimeBuild: runtimeBuild2 } = await import("./runtime-layout-BDWZG2TQ.js");
|
|
1810
|
+
const root = deps.runtimeRoot ?? runtimeDir(ctx.dataDir);
|
|
1811
|
+
const state = readRuntimeState(root);
|
|
1812
|
+
const inRuntime = runtimeBuild2(moduleDir) !== null;
|
|
1813
|
+
if (state === null && !inRuntime) return null;
|
|
1814
|
+
return { root, current: state?.current.cli ?? null, inRuntime };
|
|
1815
|
+
}
|
|
1816
|
+
async function refuseRuntimeElsewhere(ctx, moduleDir, home) {
|
|
1817
|
+
const { runtimeBuild: runtimeBuild2 } = await import("./runtime-layout-BDWZG2TQ.js");
|
|
1818
|
+
if (runtimeBuild2(moduleDir) === null) return;
|
|
1819
|
+
throw new CliError(
|
|
1820
|
+
"REFUSED",
|
|
1821
|
+
`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`,
|
|
1822
|
+
{
|
|
1823
|
+
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`."
|
|
1824
|
+
}
|
|
1825
|
+
);
|
|
1826
|
+
}
|
|
1827
|
+
async function runtimeUpdate(ctx, deps, o) {
|
|
1828
|
+
const { root, base, latest } = o;
|
|
1829
|
+
const [rt, layout] = await Promise.all([
|
|
1830
|
+
import("./runtime-UVNUA3AS.js"),
|
|
1831
|
+
import("./runtime-layout-BDWZG2TQ.js")
|
|
1832
|
+
]);
|
|
1833
|
+
const stays = `so ${base} stays`;
|
|
1834
|
+
let stage;
|
|
1835
|
+
if (latest === o.current && !o.inRuntime) {
|
|
1836
|
+
const packageRoot = rt.packageRootOf(o.moduleDir);
|
|
1837
|
+
if (packageRoot === null) {
|
|
1838
|
+
throw new CliError(
|
|
1839
|
+
"UPDATE_FAILED",
|
|
1840
|
+
`tenjin-cli ${latest} cannot find its own package, ${stays}`,
|
|
1841
|
+
{
|
|
1842
|
+
fix: "Run `npx -y tenjin-cli@latest install`."
|
|
1843
|
+
}
|
|
1844
|
+
);
|
|
1845
|
+
}
|
|
1846
|
+
stage = await rt.stageSelf(root, packageRoot);
|
|
1847
|
+
} else {
|
|
1848
|
+
stage = await (deps.stage ?? rt.stageTarball)(root, latest, {
|
|
1849
|
+
timeoutMs: STAGE_TIMEOUT_MS,
|
|
1850
|
+
fetchImpl: deps.fetchImpl
|
|
1851
|
+
}).catch((err) => {
|
|
1852
|
+
throw proxyNamed(err, deps);
|
|
1853
|
+
});
|
|
1854
|
+
}
|
|
1855
|
+
let node;
|
|
1856
|
+
try {
|
|
1857
|
+
const pin = rt.readNodePin(stage);
|
|
1858
|
+
if (pin === null) {
|
|
1859
|
+
throw new CliError("UPDATE_FAILED", `tenjin-cli ${latest} carries no Node pin, ${stays}`, {
|
|
1860
|
+
fix: `Nothing to do: ${base} keeps running. Run \`tenjin update\` again after the next release.`
|
|
1861
|
+
});
|
|
1862
|
+
}
|
|
1863
|
+
node = await (deps.ensure ?? rt.ensureNode)(root, pin, {
|
|
1864
|
+
timeoutMs: NODE_TIMEOUT_MS,
|
|
1865
|
+
fetchImpl: deps.fetchImpl
|
|
1866
|
+
});
|
|
1867
|
+
await (deps.place ?? rt.placeVersion)(root, stage, latest);
|
|
1868
|
+
} catch (err) {
|
|
1869
|
+
await rm2(stage, { recursive: true, force: true }).catch(() => void 0);
|
|
1870
|
+
throw proxyNamed(err, deps);
|
|
1871
|
+
}
|
|
1872
|
+
const home = deps.homeDir ?? homedir2();
|
|
1873
|
+
emitWriteNotice(ctx.io, `tenjin update: staged tenjin-cli ${latest} in ${tilde2(root, home)}`);
|
|
1874
|
+
const { refresh, homeTail } = await refreshProfiles(ctx, deps, {
|
|
1875
|
+
node,
|
|
1876
|
+
entry: layout.versionEntry(root, latest)
|
|
1877
|
+
});
|
|
1878
|
+
if (layout.readRuntimeState(root)?.current.cli !== latest) {
|
|
1879
|
+
throw new CliError("UPDATE_FAILED", `tenjin-cli ${latest} did not pass its checks, ${stays}`, {
|
|
1880
|
+
fix: "Run `tenjin update` again; if it fails again, run `tenjin doctor`",
|
|
1881
|
+
details: {
|
|
1882
|
+
reason: refresh.failed[0]?.reason ?? runtimeReason(envelopeData(homeTail)) ?? "The new version did not switch the runtime to itself.",
|
|
1883
|
+
output: homeTail.slice(-2e3)
|
|
1884
|
+
}
|
|
1885
|
+
});
|
|
1886
|
+
}
|
|
1887
|
+
return updated(
|
|
1888
|
+
deps,
|
|
1889
|
+
o.data(true),
|
|
1890
|
+
refresh,
|
|
1891
|
+
[
|
|
1892
|
+
`Updated tenjin-cli ${base} -> ${latest}.`,
|
|
1893
|
+
`The previous version (${base}) stays as the fallback.`
|
|
1894
|
+
],
|
|
1895
|
+
latest
|
|
1896
|
+
);
|
|
1897
|
+
}
|
|
1898
|
+
function proxyNamed(err, deps) {
|
|
1899
|
+
if (!(err instanceof CliError) || err.code !== "NETWORK_ERROR") return err;
|
|
1900
|
+
const skipped = proxySkipped(process.env, deps.proxySupported);
|
|
1901
|
+
if (skipped === null) return err;
|
|
1902
|
+
const step2 = proxyNodeStep("tenjin update");
|
|
1903
|
+
return new CliError("NETWORK_ERROR", `${err.message}: ${skipped}`, {
|
|
1904
|
+
fix: `${step2.charAt(0).toUpperCase()}${step2.slice(1)}.`,
|
|
1905
|
+
cause: err
|
|
1906
|
+
});
|
|
1907
|
+
}
|
|
1908
|
+
function runtimeReason(data) {
|
|
1909
|
+
const reason = data?.runtime?.reason;
|
|
1910
|
+
if (typeof reason !== "string") return void 0;
|
|
1911
|
+
const text = sanitizeForTerminal(reason).trim();
|
|
1912
|
+
return text.length > 0 ? text.slice(0, REASON_LIMIT) : void 0;
|
|
1913
|
+
}
|
|
1914
|
+
function tilde2(path, home) {
|
|
1915
|
+
return path === home || path.startsWith(`${home}${sep2}`) ? `~${path.slice(home.length)}` : path;
|
|
1916
|
+
}
|
|
1935
1917
|
var REFRESH_TIMEOUT_MS = 6e4;
|
|
1936
|
-
async function refreshProfiles(ctx, deps) {
|
|
1937
|
-
const home = deps.homeDir ??
|
|
1918
|
+
async function refreshProfiles(ctx, deps, launch) {
|
|
1919
|
+
const home = deps.homeDir ?? homedir2();
|
|
1938
1920
|
const candidates = [ctx.dataDir];
|
|
1939
1921
|
const fixFor = (dataDir) => manualFix(dataDir, home, ctx.dataDir);
|
|
1940
1922
|
const profiles = [];
|
|
@@ -1943,16 +1925,18 @@ async function refreshProfiles(ctx, deps) {
|
|
|
1943
1925
|
if (isExistingDir(dataDir)) profiles.push(dataDir);
|
|
1944
1926
|
else unrun.push({ dataDir, reason: "It is not a directory.", fix: fixFor(dataDir) });
|
|
1945
1927
|
}
|
|
1946
|
-
|
|
1947
|
-
if (entry === null) {
|
|
1928
|
+
if (launch === null) {
|
|
1948
1929
|
const reason = "This build has no entry the update could safely re-execute.";
|
|
1949
1930
|
return {
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1931
|
+
refresh: {
|
|
1932
|
+
profiles: [],
|
|
1933
|
+
failed: candidates.map((d) => ({ dataDir: d, reason, fix: fixFor(d) })),
|
|
1934
|
+
notices: [],
|
|
1935
|
+
settingsInstallPending: false,
|
|
1936
|
+
projects: [],
|
|
1937
|
+
projectsFailed: []
|
|
1938
|
+
},
|
|
1939
|
+
homeTail: ""
|
|
1956
1940
|
};
|
|
1957
1941
|
}
|
|
1958
1942
|
const failed = [...unrun];
|
|
@@ -1965,8 +1949,10 @@ async function refreshProfiles(ctx, deps) {
|
|
|
1965
1949
|
settingsInstallPending = true;
|
|
1966
1950
|
}
|
|
1967
1951
|
};
|
|
1952
|
+
let homeTail = "";
|
|
1968
1953
|
for (const dataDir of profiles) {
|
|
1969
|
-
const { outcome, tail } = await refreshChild(
|
|
1954
|
+
const { outcome, tail } = await refreshChild(launch, homedir2(), dataDir, deps);
|
|
1955
|
+
homeTail = tail;
|
|
1970
1956
|
if (outcome.kind !== "exit" || outcome.code !== 0) {
|
|
1971
1957
|
failed.push({ dataDir, reason: refreshReason(outcome, tail), fix: fixFor(dataDir) });
|
|
1972
1958
|
continue;
|
|
@@ -1982,7 +1968,7 @@ async function refreshProfiles(ctx, deps) {
|
|
|
1982
1968
|
await forget();
|
|
1983
1969
|
continue;
|
|
1984
1970
|
}
|
|
1985
|
-
const { outcome, tail } = await refreshChild(
|
|
1971
|
+
const { outcome, tail } = await refreshChild(launch, project, ctx.dataDir, deps, ["--project"]);
|
|
1986
1972
|
if (outcome.kind !== "exit" || outcome.code !== 0) {
|
|
1987
1973
|
projectsFailed.push({
|
|
1988
1974
|
project,
|
|
@@ -1994,13 +1980,20 @@ async function refreshProfiles(ctx, deps) {
|
|
|
1994
1980
|
projects.push(project);
|
|
1995
1981
|
heard(envelopeData(tail));
|
|
1996
1982
|
}
|
|
1997
|
-
return {
|
|
1983
|
+
return {
|
|
1984
|
+
refresh: { profiles, failed, notices, settingsInstallPending, projects, projectsFailed },
|
|
1985
|
+
homeTail
|
|
1986
|
+
};
|
|
1987
|
+
}
|
|
1988
|
+
function npmLaunch(deps) {
|
|
1989
|
+
const entry = versionFreeEntry(deps.refreshCommand ?? process.argv[1]);
|
|
1990
|
+
return entry === null ? null : { node: process.execPath, entry };
|
|
1998
1991
|
}
|
|
1999
|
-
async function refreshChild(
|
|
1992
|
+
async function refreshChild(launch, cwd, dataDir, deps, flags = []) {
|
|
2000
1993
|
let tail = "";
|
|
2001
1994
|
const outcome = await (deps.spawnImpl ?? spawnCapture)(
|
|
2002
|
-
|
|
2003
|
-
[entry, "install", "--refresh", ...flags],
|
|
1995
|
+
launch.node,
|
|
1996
|
+
[launch.entry, "install", "--refresh", ...flags],
|
|
2004
1997
|
{
|
|
2005
1998
|
cwd,
|
|
2006
1999
|
timeoutMs: REFRESH_TIMEOUT_MS,
|
|
@@ -2061,21 +2054,21 @@ function envelopeMessage(output) {
|
|
|
2061
2054
|
return void 0;
|
|
2062
2055
|
}
|
|
2063
2056
|
function isExistingDir(path) {
|
|
2064
|
-
return
|
|
2057
|
+
return statSync(path, { throwIfNoEntry: false })?.isDirectory() === true;
|
|
2065
2058
|
}
|
|
2066
2059
|
function manualFix(dataDir, home, invoking) {
|
|
2067
|
-
const bare =
|
|
2068
|
-
const
|
|
2069
|
-
return `Run \`${
|
|
2060
|
+
const bare = resolve2(dataDir) === resolve2(defaultDataDir(home)) && resolve2(dataDir) === resolve2(invoking);
|
|
2061
|
+
const command = bare ? "tenjin install" : `TENJIN_DATA_DIR=${dataDir} tenjin install`;
|
|
2062
|
+
return `Run \`${command}\` to bring the Claude Code plugin up to this version.`;
|
|
2070
2063
|
}
|
|
2071
2064
|
function versionFreeEntry(entry) {
|
|
2072
2065
|
if (entry === void 0 || entry.length === 0) return null;
|
|
2073
|
-
const segs = entry.split(
|
|
2066
|
+
const segs = entry.split(sep2);
|
|
2074
2067
|
const store = segs.indexOf(".pnpm");
|
|
2075
|
-
if (store === -1) return segs.join(
|
|
2068
|
+
if (store === -1) return segs.join(sep2);
|
|
2076
2069
|
const inner = segs.indexOf("node_modules", store);
|
|
2077
2070
|
if (inner === -1) return null;
|
|
2078
|
-
const derived = [...segs.slice(0, store), ...segs.slice(inner + 1)].join(
|
|
2071
|
+
const derived = [...segs.slice(0, store), ...segs.slice(inner + 1)].join(sep2);
|
|
2079
2072
|
return existsSync2(derived) ? derived : null;
|
|
2080
2073
|
}
|
|
2081
2074
|
function refreshLines2(refresh) {
|
|
@@ -2136,39 +2129,45 @@ var spawnCapture = (cmd, args, opts, onOutput) => new Promise((res) => {
|
|
|
2136
2129
|
});
|
|
2137
2130
|
|
|
2138
2131
|
export {
|
|
2139
|
-
CLAUDE_CODE_FLOOR,
|
|
2140
|
-
claudeConfigDir,
|
|
2141
|
-
findClaudeBinary,
|
|
2142
|
-
runClaude,
|
|
2143
|
-
jsonResult,
|
|
2144
|
-
jsonList,
|
|
2145
|
-
readClaudeCode,
|
|
2146
2132
|
inspectLegacyInstall,
|
|
2147
2133
|
removeLegacyInstall,
|
|
2148
|
-
readMcpServers,
|
|
2149
2134
|
runUpdate,
|
|
2150
2135
|
versionFreeEntry,
|
|
2151
2136
|
spawnCapture,
|
|
2152
|
-
ROUTE_HOOK_TIMEOUT_SECONDS,
|
|
2153
|
-
AFTER_CALL_TIMEOUT_SECONDS,
|
|
2154
|
-
removePluginFolder,
|
|
2155
2137
|
folderFor,
|
|
2138
|
+
registerPlugin,
|
|
2139
|
+
marketplaceAdded,
|
|
2156
2140
|
ownMarketplace,
|
|
2141
|
+
recordedInstalls,
|
|
2142
|
+
packageHostsDir,
|
|
2143
|
+
packageMod,
|
|
2144
|
+
packageCliEntry,
|
|
2157
2145
|
readPluginListing,
|
|
2158
2146
|
folderState,
|
|
2159
2147
|
probeRouter,
|
|
2160
2148
|
DISCLOSURE,
|
|
2161
|
-
RELOAD_STEP,
|
|
2162
2149
|
NEW_SESSION_STEP,
|
|
2150
|
+
RELOAD_STEP,
|
|
2163
2151
|
loadStep,
|
|
2164
2152
|
settingsInstallPaths,
|
|
2165
2153
|
pluginProof,
|
|
2166
2154
|
migrateSettingsInstall,
|
|
2167
2155
|
projectInstallHere,
|
|
2168
2156
|
projectInstallAt,
|
|
2157
|
+
NOTHING_TO_REFRESH,
|
|
2169
2158
|
runRouterInstall,
|
|
2159
|
+
defaultRuntime,
|
|
2160
|
+
runtimeOncePerRun,
|
|
2161
|
+
hasRuntime,
|
|
2162
|
+
runtimeData,
|
|
2163
|
+
tilde,
|
|
2164
|
+
runtimeLines,
|
|
2170
2165
|
SHOW_NOT_RUN,
|
|
2166
|
+
spendStepFor,
|
|
2167
|
+
namedLimits,
|
|
2171
2168
|
FUND_QUESTION,
|
|
2172
|
-
FUND_COMMAND
|
|
2169
|
+
FUND_COMMAND,
|
|
2170
|
+
approveLimits,
|
|
2171
|
+
effectiveLimits
|
|
2173
2172
|
};
|
|
2174
|
-
//# sourceMappingURL=chunk-
|
|
2173
|
+
//# sourceMappingURL=chunk-VOZA6O7K.js.map
|