tenjin-cli 0.1.0-alpha.3 → 0.1.0-alpha.31
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/NOTICE.md +54 -7
- package/README.md +100 -266
- package/dist/{_esm-FEASBWRP.js → _esm-MEXZI5DL.js} +9 -10
- package/dist/alive-J64H46HI.js +31 -0
- package/dist/{ccip-NQXCEK2U.js → ccip-7RMRLAGV.js} +4 -4
- package/dist/{ccip-XR5NE5QK.js → ccip-NLCSCHKI.js} +5 -5
- package/dist/chunk-27EPWVOY.js +108 -0
- package/dist/chunk-27EPWVOY.js.map +1 -0
- package/dist/chunk-2SNUOHAT.js +75 -0
- package/dist/chunk-2SNUOHAT.js.map +1 -0
- package/dist/{chunk-Z6MFJV5Z.js → chunk-2XLC3AEX.js} +857 -504
- package/dist/chunk-2XLC3AEX.js.map +1 -0
- package/dist/chunk-3623BLPV.js +184 -0
- package/dist/chunk-3623BLPV.js.map +1 -0
- package/dist/chunk-3UCIG4TG.js +65 -0
- package/dist/chunk-3UCIG4TG.js.map +1 -0
- package/dist/chunk-4ZZO6ULA.js +151 -0
- package/dist/chunk-4ZZO6ULA.js.map +1 -0
- package/dist/chunk-5C32RLTA.js +115 -0
- package/dist/chunk-5C32RLTA.js.map +1 -0
- package/dist/{chunk-ZMHYXMO6.js → chunk-5IEP5EGE.js} +3 -3
- package/dist/chunk-5K5W4S66.js +105 -0
- package/dist/chunk-5K5W4S66.js.map +1 -0
- package/dist/chunk-5MARFNSB.js +2018 -0
- package/dist/chunk-5MARFNSB.js.map +1 -0
- package/dist/{chunk-CYOF7ROH.js → chunk-6E5R45ZO.js} +3 -3
- package/dist/chunk-77TCKDEC.js +1987 -0
- package/dist/chunk-77TCKDEC.js.map +1 -0
- package/dist/chunk-7EKYXMUO.js +7536 -0
- package/dist/chunk-7EKYXMUO.js.map +1 -0
- package/dist/chunk-7Q5FDF65.js +159 -0
- package/dist/chunk-7Q5FDF65.js.map +1 -0
- package/dist/chunk-7QKHZQKW.js +1680 -0
- package/dist/chunk-7QKHZQKW.js.map +1 -0
- package/dist/{chunk-MUBUQVC3.js → chunk-7WEQQJLG.js} +6 -5
- package/dist/{chunk-MUBUQVC3.js.map → chunk-7WEQQJLG.js.map} +1 -1
- package/dist/chunk-7WU4OPLP.js +244 -0
- package/dist/chunk-7WU4OPLP.js.map +1 -0
- package/dist/chunk-7ZRL2LBQ.js +192 -0
- package/dist/chunk-7ZRL2LBQ.js.map +1 -0
- package/dist/chunk-A36LQPHV.js +29 -0
- package/dist/chunk-A36LQPHV.js.map +1 -0
- package/dist/chunk-AGZ7PJKY.js +326 -0
- package/dist/chunk-AGZ7PJKY.js.map +1 -0
- package/dist/chunk-AKWGE6JQ.js +49 -0
- package/dist/chunk-AKWGE6JQ.js.map +1 -0
- package/dist/chunk-B7HUUJOK.js +29 -0
- package/dist/chunk-B7HUUJOK.js.map +1 -0
- package/dist/{chunk-S3IGX57D.js → chunk-BL3332HQ.js} +290 -7361
- package/dist/chunk-BL3332HQ.js.map +1 -0
- package/dist/{chunk-5CLSD5YN.js → chunk-BPMWXTFX.js} +2 -2
- package/dist/chunk-D65GNPS3.js +12708 -0
- package/dist/chunk-D65GNPS3.js.map +1 -0
- package/dist/chunk-DOQGNFHM.js +121 -0
- package/dist/chunk-DOQGNFHM.js.map +1 -0
- package/dist/{chunk-YALGASEU.js → chunk-EGELTSPU.js} +2 -2
- package/dist/chunk-FW75G2W4.js +406 -0
- package/dist/chunk-FW75G2W4.js.map +1 -0
- package/dist/chunk-GA7JETVM.js +150 -0
- package/dist/chunk-GA7JETVM.js.map +1 -0
- package/dist/chunk-I3EQFHCD.js +175 -0
- package/dist/chunk-I3EQFHCD.js.map +1 -0
- package/dist/chunk-JKKAIPTU.js +108 -0
- package/dist/chunk-JKKAIPTU.js.map +1 -0
- package/dist/{chunk-QVX5MWJZ.js → chunk-JRGFKVAZ.js} +2 -2
- package/dist/{chunk-NCE5NSN6.js → chunk-K3I7C2MO.js} +142 -12
- package/dist/chunk-K3I7C2MO.js.map +1 -0
- package/dist/chunk-K72RURN3.js +239 -0
- package/dist/chunk-K72RURN3.js.map +1 -0
- package/dist/{chunk-HIVZG55D.js → chunk-KG3D7FIF.js} +2 -2
- package/dist/chunk-KOGZDMHO.js +21 -0
- package/dist/chunk-KOGZDMHO.js.map +1 -0
- package/dist/chunk-KXQ4UIP7.js +228 -0
- package/dist/chunk-KXQ4UIP7.js.map +1 -0
- package/dist/chunk-KXVP2VKA.js +194 -0
- package/dist/chunk-KXVP2VKA.js.map +1 -0
- package/dist/chunk-LEFIX6RS.js +100 -0
- package/dist/chunk-LEFIX6RS.js.map +1 -0
- package/dist/chunk-LHHMV4GU.js +27 -0
- package/dist/chunk-LHHMV4GU.js.map +1 -0
- package/dist/{chunk-YBMMV4Y4.js → chunk-MEFB5KHA.js} +13 -5
- package/dist/chunk-MEFB5KHA.js.map +1 -0
- package/dist/chunk-MNXS2U45.js +1768 -0
- package/dist/chunk-MNXS2U45.js.map +1 -0
- package/dist/{chunk-UGX7YPX2.js → chunk-NEFNKLBE.js} +9 -11
- package/dist/{chunk-UGX7YPX2.js.map → chunk-NEFNKLBE.js.map} +1 -1
- package/dist/chunk-OHRR5OYM.js +63 -0
- package/dist/chunk-OHRR5OYM.js.map +1 -0
- package/dist/chunk-ORWL5BSN.js +269 -0
- package/dist/chunk-ORWL5BSN.js.map +1 -0
- package/dist/chunk-P4NH7OUK.js +398 -0
- package/dist/chunk-P4NH7OUK.js.map +1 -0
- package/dist/{chunk-ZABPQJ3M.js → chunk-POUWHWID.js} +2 -2
- package/dist/chunk-QSCPK4F5.js +145 -0
- package/dist/chunk-QSCPK4F5.js.map +1 -0
- package/dist/chunk-QXP3Z3JN.js +131 -0
- package/dist/chunk-QXP3Z3JN.js.map +1 -0
- package/dist/{chunk-XJIW7USF.js → chunk-R5LCN54M.js} +118 -9
- package/dist/chunk-R5LCN54M.js.map +1 -0
- package/dist/chunk-S4SAZ7OD.js +30 -0
- package/dist/chunk-S4SAZ7OD.js.map +1 -0
- package/dist/chunk-SJLTEINJ.js +117 -0
- package/dist/chunk-SJLTEINJ.js.map +1 -0
- package/dist/{chunk-RRN3YTK7.js → chunk-TTNESUPQ.js} +3 -3
- package/dist/chunk-UKY4CHNC.js +498 -0
- package/dist/chunk-UKY4CHNC.js.map +1 -0
- package/dist/chunk-UQUOVWBG.js +114 -0
- package/dist/chunk-UQUOVWBG.js.map +1 -0
- package/dist/chunk-V6BSF6OC.js +260 -0
- package/dist/chunk-V6BSF6OC.js.map +1 -0
- package/dist/chunk-WJXLQXJY.js +43 -0
- package/dist/chunk-WJXLQXJY.js.map +1 -0
- package/dist/chunk-WK7F3B2E.js +114 -0
- package/dist/chunk-WK7F3B2E.js.map +1 -0
- package/dist/chunk-XKESD27X.js +10 -0
- package/dist/chunk-XKESD27X.js.map +1 -0
- package/dist/chunk-XQJXNMSB.js +23 -0
- package/dist/chunk-XQJXNMSB.js.map +1 -0
- package/dist/{chunk-HSDCI7OV.js → chunk-XZKD7DIF.js} +3 -3
- package/dist/chunk-Y527D4TV.js +56 -0
- package/dist/chunk-Y527D4TV.js.map +1 -0
- package/dist/chunk-YFPY4ONH.js +127 -0
- package/dist/chunk-YFPY4ONH.js.map +1 -0
- package/dist/{chunk-OYMYCW7J.js → chunk-YVFXE7RR.js} +606 -97
- package/dist/chunk-YVFXE7RR.js.map +1 -0
- package/dist/clack-EZ7TDWQU.js +19 -0
- package/dist/claude-cli-2YKABJJZ.js +31 -0
- package/dist/{cli-SBXI5AMS.js → cli-D5OE3URZ.js} +458 -218
- package/dist/cli-D5OE3URZ.js.map +1 -0
- package/dist/codex-event-PPNVRRDH.js +16 -0
- package/dist/codex-host-2RJOJW2B.js +28 -0
- package/dist/codex-install-UUZ6QMBQ.js +221 -0
- package/dist/codex-install-UUZ6QMBQ.js.map +1 -0
- package/dist/config-ZD4OB2DO.js +51 -0
- package/dist/dist-3LOO6M4U.js +2842 -0
- package/dist/dist-3LOO6M4U.js.map +1 -0
- package/dist/doctor-KBR34Q4B.js +601 -0
- package/dist/doctor-KBR34Q4B.js.map +1 -0
- package/dist/env-proxy-XL4P73MZ.js +15 -0
- package/dist/{ethersCompat-Df4a6QIZ-3YZIAXDK.js → ethersCompat-Df4a6QIZ-THAVUGIJ.js} +5 -5
- package/dist/ethersCompat-Df4a6QIZ-THAVUGIJ.js.map +1 -0
- package/dist/fund-5ITKQGYF.js +372 -0
- package/dist/fund-5ITKQGYF.js.map +1 -0
- package/dist/hook-command-4TYCHHRL.js +39 -0
- package/dist/hook-command-4TYCHHRL.js.map +1 -0
- package/dist/hosts/claude/.claude-plugin/marketplace.json +19 -0
- package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +15 -0
- package/dist/hosts/claude/tenjin/.mcp.json +12 -0
- package/dist/hosts/claude/tenjin/hooks/hooks.json +224 -0
- package/dist/hosts/claude/tenjin/hooks/register.tsx +589 -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 +12 -0
- package/dist/hosts/codex/tenjin/hooks/hooks.json +52 -0
- package/dist/hosts-FWZOV26H.js +216 -0
- package/dist/hosts-FWZOV26H.js.map +1 -0
- package/dist/index.js +21 -2
- package/dist/index.js.map +1 -1
- package/dist/install-XWGE4Q7L.js +77 -0
- package/dist/install-XWGE4Q7L.js.map +1 -0
- package/dist/install-identity-K7EJIQFP.js +30 -0
- package/dist/install-identity-K7EJIQFP.js.map +1 -0
- package/dist/install-wallet-XQ6XFZV4.js +117 -0
- package/dist/install-wallet-XQ6XFZV4.js.map +1 -0
- package/dist/mcp-3LIJSSJB.js +13553 -0
- package/dist/mcp-3LIJSSJB.js.map +1 -0
- package/dist/package-ZKQFDWLE.js +37 -0
- package/dist/package-ZKQFDWLE.js.map +1 -0
- package/dist/paths-POPTXJO6.js +61 -0
- package/dist/paths-POPTXJO6.js.map +1 -0
- package/dist/pay-WHBERZ3W.js +55 -0
- package/dist/pay-WHBERZ3W.js.map +1 -0
- package/dist/payments-KVICEKD2.js +110 -0
- package/dist/payments-KVICEKD2.js.map +1 -0
- package/dist/plugin-registration-5TIA564H.js +54 -0
- package/dist/plugin-registration-5TIA564H.js.map +1 -0
- package/dist/redact-6W23GGJC.js +15 -0
- package/dist/redact-6W23GGJC.js.map +1 -0
- package/dist/{secp256k1-N3ZHU7LB.js → secp256k1-ZZZT2CAX.js} +3 -3
- package/dist/secp256k1-ZZZT2CAX.js.map +1 -0
- package/dist/send-7G7Y7DLN.js +228 -0
- package/dist/send-7G7Y7DLN.js.map +1 -0
- package/dist/status-OF7RH5HM.js +120 -0
- package/dist/status-OF7RH5HM.js.map +1 -0
- package/dist/status-line-XOUE6MPL.js +90 -0
- package/dist/status-line-XOUE6MPL.js.map +1 -0
- package/dist/uninstall-JXUAFNDB.js +158 -0
- package/dist/uninstall-JXUAFNDB.js.map +1 -0
- package/dist/update-ZKUERSO2.js +44 -0
- package/dist/update-ZKUERSO2.js.map +1 -0
- package/dist/usdc-OGOGEHV2.js +40 -0
- package/dist/usdc-OGOGEHV2.js.map +1 -0
- package/dist/{viemAdapter-By13KInL-ZZE6UV4Y.js → viemAdapter-By13KInL-S3DA7DFW.js} +5 -5
- package/dist/viemAdapter-By13KInL-S3DA7DFW.js.map +1 -0
- package/dist/wallet-2HA6W4R4.js +43 -0
- package/dist/wallet-2HA6W4R4.js.map +1 -0
- package/dist/wallet-kdf-worker.mjs +980 -0
- package/docs/agent-permissions.md +196 -0
- package/docs/safety-model.md +59 -0
- package/docs/troubleshooting.md +13 -0
- package/package.json +28 -19
- package/LICENSE +0 -21
- package/dist/buy-EE6SEXP6.js +0 -1598
- package/dist/buy-EE6SEXP6.js.map +0 -1
- package/dist/candidate-ERMSYYQZ.js +0 -127
- package/dist/candidate-ERMSYYQZ.js.map +0 -1
- package/dist/chunk-3OV7E5G5.js +0 -18
- package/dist/chunk-3OV7E5G5.js.map +0 -1
- package/dist/chunk-4ONXEEQL.js +0 -152
- package/dist/chunk-4ONXEEQL.js.map +0 -1
- package/dist/chunk-662MSGZB.js +0 -286
- package/dist/chunk-662MSGZB.js.map +0 -1
- package/dist/chunk-7KUW4MJD.js +0 -59
- package/dist/chunk-7KUW4MJD.js.map +0 -1
- package/dist/chunk-AWPAWHNX.js +0 -333
- package/dist/chunk-AWPAWHNX.js.map +0 -1
- package/dist/chunk-DXTQ3CSI.js +0 -171
- package/dist/chunk-DXTQ3CSI.js.map +0 -1
- package/dist/chunk-ESPNTPQ2.js +0 -207
- package/dist/chunk-ESPNTPQ2.js.map +0 -1
- package/dist/chunk-FJPLRISB.js +0 -79
- package/dist/chunk-FJPLRISB.js.map +0 -1
- package/dist/chunk-GO75V3NZ.js +0 -160
- package/dist/chunk-GO75V3NZ.js.map +0 -1
- package/dist/chunk-JPHG2JW3.js +0 -96
- package/dist/chunk-JPHG2JW3.js.map +0 -1
- package/dist/chunk-NCE5NSN6.js.map +0 -1
- package/dist/chunk-OYMYCW7J.js.map +0 -1
- package/dist/chunk-RY4XKNV3.js +0 -140
- package/dist/chunk-RY4XKNV3.js.map +0 -1
- package/dist/chunk-S3IGX57D.js.map +0 -1
- package/dist/chunk-TLCMMYLY.js +0 -126
- package/dist/chunk-TLCMMYLY.js.map +0 -1
- package/dist/chunk-UO22YNY4.js +0 -69
- package/dist/chunk-UO22YNY4.js.map +0 -1
- package/dist/chunk-XHC6FCGZ.js +0 -261
- package/dist/chunk-XHC6FCGZ.js.map +0 -1
- package/dist/chunk-XJIW7USF.js.map +0 -1
- package/dist/chunk-YBMMV4Y4.js.map +0 -1
- package/dist/chunk-YN5SHIXQ.js +0 -126
- package/dist/chunk-YN5SHIXQ.js.map +0 -1
- package/dist/chunk-Z52RA3NC.js +0 -137
- package/dist/chunk-Z52RA3NC.js.map +0 -1
- package/dist/chunk-Z6MFJV5Z.js.map +0 -1
- package/dist/cli-SBXI5AMS.js.map +0 -1
- package/dist/config-VELDKLHY.js +0 -21
- package/dist/doctor-T3KWNNP2.js +0 -20
- package/dist/inspect-LMKOXE4Y.js +0 -96
- package/dist/inspect-LMKOXE4Y.js.map +0 -1
- package/dist/install-LEX3ENQ6.js +0 -387
- package/dist/install-LEX3ENQ6.js.map +0 -1
- package/dist/lookup-ZPN2Q67N.js +0 -129
- package/dist/lookup-ZPN2Q67N.js.map +0 -1
- package/dist/outcome-N7TAK6WR.js +0 -66
- package/dist/outcome-N7TAK6WR.js.map +0 -1
- package/dist/publish-BKBQQAW4.js +0 -1478
- package/dist/publish-BKBQQAW4.js.map +0 -1
- package/dist/usdc-JIAJW4SV.js +0 -22
- package/dist/wallet-CWEMYVIH.js +0 -179
- package/dist/wallet-CWEMYVIH.js.map +0 -1
- package/dist/wallet-PA54CRBL.js +0 -30
- package/skills/tenjin/SKILL.md +0 -199
- package/skills/tenjin-publish/SKILL.md +0 -111
- package/skills/tenjin-search/SKILL.md +0 -133
- /package/dist/{_esm-FEASBWRP.js.map → _esm-MEXZI5DL.js.map} +0 -0
- /package/dist/{ccip-NQXCEK2U.js.map → alive-J64H46HI.js.map} +0 -0
- /package/dist/{ccip-XR5NE5QK.js.map → ccip-7RMRLAGV.js.map} +0 -0
- /package/dist/{config-VELDKLHY.js.map → ccip-NLCSCHKI.js.map} +0 -0
- /package/dist/{chunk-ZMHYXMO6.js.map → chunk-5IEP5EGE.js.map} +0 -0
- /package/dist/{chunk-CYOF7ROH.js.map → chunk-6E5R45ZO.js.map} +0 -0
- /package/dist/{chunk-5CLSD5YN.js.map → chunk-BPMWXTFX.js.map} +0 -0
- /package/dist/{chunk-YALGASEU.js.map → chunk-EGELTSPU.js.map} +0 -0
- /package/dist/{chunk-QVX5MWJZ.js.map → chunk-JRGFKVAZ.js.map} +0 -0
- /package/dist/{chunk-HIVZG55D.js.map → chunk-KG3D7FIF.js.map} +0 -0
- /package/dist/{chunk-ZABPQJ3M.js.map → chunk-POUWHWID.js.map} +0 -0
- /package/dist/{chunk-RRN3YTK7.js.map → chunk-TTNESUPQ.js.map} +0 -0
- /package/dist/{chunk-HSDCI7OV.js.map → chunk-XZKD7DIF.js.map} +0 -0
- /package/dist/{doctor-T3KWNNP2.js.map → clack-EZ7TDWQU.js.map} +0 -0
- /package/dist/{ethersCompat-Df4a6QIZ-3YZIAXDK.js.map → claude-cli-2YKABJJZ.js.map} +0 -0
- /package/dist/{secp256k1-N3ZHU7LB.js.map → codex-event-PPNVRRDH.js.map} +0 -0
- /package/dist/{usdc-JIAJW4SV.js.map → codex-host-2RJOJW2B.js.map} +0 -0
- /package/dist/{viemAdapter-By13KInL-ZZE6UV4Y.js.map → config-ZD4OB2DO.js.map} +0 -0
- /package/dist/{wallet-PA54CRBL.js.map → env-proxy-XL4P73MZ.js.map} +0 -0
|
@@ -0,0 +1,1987 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
ROUTER_PATH
|
|
4
|
+
} from "./chunk-UKY4CHNC.js";
|
|
5
|
+
import {
|
|
6
|
+
NUDGE_OPT_OUT,
|
|
7
|
+
channelTag,
|
|
8
|
+
fetchDistTags,
|
|
9
|
+
isNewer,
|
|
10
|
+
resolveTarget
|
|
11
|
+
} from "./chunk-KXVP2VKA.js";
|
|
12
|
+
import {
|
|
13
|
+
MOD_FILES,
|
|
14
|
+
OWNER_MARKER,
|
|
15
|
+
PLUGIN_DIR,
|
|
16
|
+
PLUGIN_FILES,
|
|
17
|
+
renderPluginFiles
|
|
18
|
+
} from "./chunk-GA7JETVM.js";
|
|
19
|
+
import {
|
|
20
|
+
underAgentHarness
|
|
21
|
+
} from "./chunk-KOGZDMHO.js";
|
|
22
|
+
import {
|
|
23
|
+
CLAUDE_CODE_FLOOR,
|
|
24
|
+
claudeConfigDir,
|
|
25
|
+
findClaudeBinary,
|
|
26
|
+
jsonList,
|
|
27
|
+
jsonResult,
|
|
28
|
+
readClaudeCode,
|
|
29
|
+
runClaude,
|
|
30
|
+
userMcpFile,
|
|
31
|
+
userSettingsPath
|
|
32
|
+
} from "./chunk-QXP3Z3JN.js";
|
|
33
|
+
import {
|
|
34
|
+
CLI_SKILL_NAMES,
|
|
35
|
+
FEE_APPROVAL,
|
|
36
|
+
RETIRED_SKILL_NAMES,
|
|
37
|
+
ROUTER_DEFAULTS,
|
|
38
|
+
ROUTING_FEE_TERMS,
|
|
39
|
+
SHIPPED_SKILL_FILES,
|
|
40
|
+
SPEND_QUESTION,
|
|
41
|
+
inspectHooksFile,
|
|
42
|
+
persistRouterDefaults,
|
|
43
|
+
persistRouterProject,
|
|
44
|
+
readSkillFile,
|
|
45
|
+
shownLimits,
|
|
46
|
+
skillFrontmatterName,
|
|
47
|
+
skillsDirsFor,
|
|
48
|
+
spendChoiceQuestion,
|
|
49
|
+
spendOptions
|
|
50
|
+
} from "./chunk-5MARFNSB.js";
|
|
51
|
+
import {
|
|
52
|
+
LEGACY_HOOK_TOOL,
|
|
53
|
+
LEGACY_MCP_SERVER_NAME,
|
|
54
|
+
LEGACY_REQUEST_TOOL,
|
|
55
|
+
MARKETPLACE_NAME,
|
|
56
|
+
PLUGIN_ID,
|
|
57
|
+
PLUGIN_NAME,
|
|
58
|
+
SKILLS_DIR_PLUGIN_ID
|
|
59
|
+
} from "./chunk-WJXLQXJY.js";
|
|
60
|
+
import {
|
|
61
|
+
SUGGESTED_FUND_USD
|
|
62
|
+
} from "./chunk-4ZZO6ULA.js";
|
|
63
|
+
import {
|
|
64
|
+
emitWriteNotice,
|
|
65
|
+
paint,
|
|
66
|
+
sanitizeForTerminal
|
|
67
|
+
} from "./chunk-K72RURN3.js";
|
|
68
|
+
import {
|
|
69
|
+
askText,
|
|
70
|
+
selectOne
|
|
71
|
+
} from "./chunk-DOQGNFHM.js";
|
|
72
|
+
import {
|
|
73
|
+
readAliveStamp
|
|
74
|
+
} from "./chunk-I3EQFHCD.js";
|
|
75
|
+
import {
|
|
76
|
+
envProxySupported,
|
|
77
|
+
proxyVariable
|
|
78
|
+
} from "./chunk-S4SAZ7OD.js";
|
|
79
|
+
import {
|
|
80
|
+
httpRequest
|
|
81
|
+
} from "./chunk-AGZ7PJKY.js";
|
|
82
|
+
import {
|
|
83
|
+
hasCode
|
|
84
|
+
} from "./chunk-2I4QTOLB.js";
|
|
85
|
+
import {
|
|
86
|
+
resolveContextSettings
|
|
87
|
+
} from "./chunk-7WU4OPLP.js";
|
|
88
|
+
import {
|
|
89
|
+
parseUsdToAtomic,
|
|
90
|
+
toMoney
|
|
91
|
+
} from "./chunk-Y527D4TV.js";
|
|
92
|
+
import {
|
|
93
|
+
MAX_AUTO_SPEND_FLOOR_ATOMIC,
|
|
94
|
+
MAX_AUTO_SPEND_FLOOR_WHY,
|
|
95
|
+
loadRawConfig
|
|
96
|
+
} from "./chunk-YVFXE7RR.js";
|
|
97
|
+
import {
|
|
98
|
+
PRODUCTION_ORIGIN,
|
|
99
|
+
isSameDeployment
|
|
100
|
+
} from "./chunk-XQJXNMSB.js";
|
|
101
|
+
import {
|
|
102
|
+
CliError
|
|
103
|
+
} from "./chunk-3UCIG4TG.js";
|
|
104
|
+
import {
|
|
105
|
+
writeFileAtomic
|
|
106
|
+
} from "./chunk-7WEQQJLG.js";
|
|
107
|
+
import {
|
|
108
|
+
defaultDataDir
|
|
109
|
+
} from "./chunk-SJLTEINJ.js";
|
|
110
|
+
import {
|
|
111
|
+
package_default
|
|
112
|
+
} from "./chunk-5C32RLTA.js";
|
|
113
|
+
|
|
114
|
+
// src/commands/update.ts
|
|
115
|
+
import { spawn } from "node:child_process";
|
|
116
|
+
import { existsSync as existsSync2, statSync as statSync2 } from "node:fs";
|
|
117
|
+
import { homedir as homedir2 } from "node:os";
|
|
118
|
+
import { resolve, sep as sep3 } from "node:path";
|
|
119
|
+
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
120
|
+
|
|
121
|
+
// src/lib/install-location.ts
|
|
122
|
+
import { existsSync, realpathSync, statSync } from "node:fs";
|
|
123
|
+
import { delimiter, dirname, join, sep } from "node:path";
|
|
124
|
+
var REFUSALS = [
|
|
125
|
+
{
|
|
126
|
+
test: isSourceCheckout,
|
|
127
|
+
error: () => new CliError("REFUSED", "tenjin-cli is running from a source checkout, not an install", {
|
|
128
|
+
fix: "Update the checkout instead: git pull && pnpm install"
|
|
129
|
+
}),
|
|
130
|
+
needsVersion: false,
|
|
131
|
+
appliesToCheck: false
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
test: (moduleDir) => moduleDir.split(sep).includes("_npx"),
|
|
135
|
+
error: (spec) => new CliError("REFUSED", "tenjin-cli is running from the npx cache, not an install", {
|
|
136
|
+
// Writing a global here would "succeed" and change nothing: the next
|
|
137
|
+
// `npx tenjin` still resolves its own cached copy.
|
|
138
|
+
fix: `npx fetches its own copy every time. To keep one: npm i -g ${spec}`
|
|
139
|
+
}),
|
|
140
|
+
needsVersion: true,
|
|
141
|
+
appliesToCheck: false
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
// The ONLY manager still refused. `yarn global add` is yarn-1 only, and
|
|
145
|
+
// berry dropped global installs altogether, so there is no one command this
|
|
146
|
+
// can drive across the versions a user might have. Every other manager is
|
|
147
|
+
// delegated to rather than refused (see MANAGERS).
|
|
148
|
+
test: (moduleDir) => classifyManager(moduleDir) === "yarn",
|
|
149
|
+
error: (spec) => new CliError(
|
|
150
|
+
"REFUSED",
|
|
151
|
+
"This tenjin-cli was installed with yarn, whose global install exists only in yarn 1",
|
|
152
|
+
{ fix: `yarn global add ${spec}` }
|
|
153
|
+
),
|
|
154
|
+
needsVersion: true,
|
|
155
|
+
appliesToCheck: false
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
// Scoped to npm on purpose: the prefix-vs-project-root test is written for
|
|
159
|
+
// npm's layout. pnpm's global store and bun's global dir both keep a
|
|
160
|
+
// package.json beside `node_modules`, so an unscoped test would read either
|
|
161
|
+
// as a project-local install and refuse the very case we now delegate.
|
|
162
|
+
test: (moduleDir) => classifyManager(moduleDir) === "npm" && !isGlobalTree(moduleDir),
|
|
163
|
+
error: (spec) => new CliError(
|
|
164
|
+
"REFUSED",
|
|
165
|
+
"This tenjin-cli is a project-local dependency, not a global install",
|
|
166
|
+
{
|
|
167
|
+
fix: `Update it where it is declared: npm i ${spec}`
|
|
168
|
+
}
|
|
169
|
+
),
|
|
170
|
+
needsVersion: true,
|
|
171
|
+
appliesToCheck: false
|
|
172
|
+
}
|
|
173
|
+
];
|
|
174
|
+
function refuse(moduleDir, opts) {
|
|
175
|
+
for (const entry of REFUSALS) {
|
|
176
|
+
if (opts.check && !entry.appliesToCheck) continue;
|
|
177
|
+
if (entry.needsVersion !== (opts.spec !== null)) continue;
|
|
178
|
+
if (entry.test(moduleDir)) throw entry.error(opts.spec ?? "", moduleDir);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function isSourceCheckout(moduleDir) {
|
|
182
|
+
let dir = moduleDir;
|
|
183
|
+
for (let i = 0; i < 8; i += 1) {
|
|
184
|
+
if (existsSync(join(dir, "package.json"))) return existsSync(join(dir, "src"));
|
|
185
|
+
const parent = dirname(dir);
|
|
186
|
+
if (parent === dir) break;
|
|
187
|
+
dir = parent;
|
|
188
|
+
}
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
function isGlobalTree(moduleDir) {
|
|
192
|
+
const segs = moduleDir.split(sep);
|
|
193
|
+
const i = segs.lastIndexOf("node_modules");
|
|
194
|
+
if (i <= 0) return false;
|
|
195
|
+
return !existsSync(join(segs.slice(0, i).join(sep), "package.json"));
|
|
196
|
+
}
|
|
197
|
+
function classifyManager(moduleDir) {
|
|
198
|
+
const segs = moduleDir.split(sep);
|
|
199
|
+
const pair = (a, b) => segs.includes(a) && segs.includes(b);
|
|
200
|
+
if (segs.includes(".pnpm") || pair("pnpm", "global")) return "pnpm";
|
|
201
|
+
if (segs.includes(".bun")) return "bun";
|
|
202
|
+
if (segs.includes(".yarn") || pair("yarn", "global")) return "yarn";
|
|
203
|
+
return "npm";
|
|
204
|
+
}
|
|
205
|
+
var MANAGERS = {
|
|
206
|
+
npm: {
|
|
207
|
+
bin: "npm",
|
|
208
|
+
scriptSuffixes: ["npm-cli.js"],
|
|
209
|
+
besideNode: true,
|
|
210
|
+
args: (spec) => ["install", "-g", "--ignore-scripts", spec],
|
|
211
|
+
manual: (spec) => `npm i -g ${spec}`
|
|
212
|
+
},
|
|
213
|
+
pnpm: {
|
|
214
|
+
bin: "pnpm",
|
|
215
|
+
// corepack's shim resolves to `pnpm.js`, a standalone install to `pnpm.cjs`.
|
|
216
|
+
scriptSuffixes: [".cjs", ".js"],
|
|
217
|
+
besideNode: false,
|
|
218
|
+
args: (spec) => ["add", "-g", "--ignore-scripts", spec],
|
|
219
|
+
manual: (spec) => `pnpm add -g ${spec}`
|
|
220
|
+
},
|
|
221
|
+
bun: {
|
|
222
|
+
bin: "bun",
|
|
223
|
+
scriptSuffixes: [],
|
|
224
|
+
besideNode: false,
|
|
225
|
+
// No --ignore-scripts: bun's flag surface for it is not stable across the
|
|
226
|
+
// versions in the wild, and an unknown flag would fail the install outright.
|
|
227
|
+
args: (spec) => ["add", "-g", spec],
|
|
228
|
+
manual: (spec) => `bun add -g ${spec}`
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
function resolveManagerScript(manager, execPath, env = process.env) {
|
|
232
|
+
const plan = MANAGERS[manager];
|
|
233
|
+
if (plan.scriptSuffixes.length === 0) return null;
|
|
234
|
+
const beside = plan.besideNode ? scriptNear(dirname(execPath), plan.bin) : null;
|
|
235
|
+
return beside ?? scriptOnPath(plan.bin, plan.scriptSuffixes, env);
|
|
236
|
+
}
|
|
237
|
+
function scriptNear(dir, bin) {
|
|
238
|
+
const candidates = [
|
|
239
|
+
join(dir, "node_modules", bin, "bin", `${bin}-cli.js`),
|
|
240
|
+
join(dir, "..", "lib", "node_modules", bin, "bin", `${bin}-cli.js`)
|
|
241
|
+
];
|
|
242
|
+
return candidates.find(isFile) ?? null;
|
|
243
|
+
}
|
|
244
|
+
function scriptOnPath(bin, suffixes, env) {
|
|
245
|
+
const exts = process.platform === "win32" ? ["", ...(env.PATHEXT ?? ".EXE;.CMD;.BAT;.COM").split(";").filter((e) => e.length > 0)] : [""];
|
|
246
|
+
for (const part of (env.PATH ?? "").split(delimiter)) {
|
|
247
|
+
if (part.length === 0) continue;
|
|
248
|
+
for (const ext of exts) {
|
|
249
|
+
if (!isFile(join(part, `${bin}${ext}`))) continue;
|
|
250
|
+
const real = realpathOrNull(join(part, `${bin}${ext}`));
|
|
251
|
+
if (real !== null && suffixes.some((suffix) => real.endsWith(suffix))) return real;
|
|
252
|
+
const near = scriptNear(part, bin);
|
|
253
|
+
if (near !== null) return near;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
function isFile(p) {
|
|
259
|
+
try {
|
|
260
|
+
return statSync(p).isFile();
|
|
261
|
+
} catch {
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function realpathOrNull(p) {
|
|
266
|
+
try {
|
|
267
|
+
return realpathSync(p);
|
|
268
|
+
} catch {
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// src/router/install.ts
|
|
274
|
+
import { readFile as readFile4, realpath } from "node:fs/promises";
|
|
275
|
+
import { homedir } from "node:os";
|
|
276
|
+
import { isAbsolute, join as join7 } from "node:path";
|
|
277
|
+
|
|
278
|
+
// src/lib/skill-placement.ts
|
|
279
|
+
import { lstatSync } from "node:fs";
|
|
280
|
+
import { readdir, rm, rmdir } from "node:fs/promises";
|
|
281
|
+
import { dirname as dirname2, join as join2 } from "node:path";
|
|
282
|
+
function isRealDirectory(path) {
|
|
283
|
+
try {
|
|
284
|
+
return lstatSync(path, { throwIfNoEntry: false })?.isDirectory() === true;
|
|
285
|
+
} catch (err) {
|
|
286
|
+
if (hasCode(err, "ENOENT") || hasCode(err, "ENOTDIR")) return false;
|
|
287
|
+
throw err;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
async function removeOwnedSkill(name, skillsDir) {
|
|
291
|
+
if (!isRealDirectory(skillsDir)) {
|
|
292
|
+
return { changed: false };
|
|
293
|
+
}
|
|
294
|
+
const skillDir = join2(skillsDir, name);
|
|
295
|
+
if (!isRealDirectory(skillDir)) {
|
|
296
|
+
return { changed: false };
|
|
297
|
+
}
|
|
298
|
+
const path = join2(skillDir, "SKILL.md");
|
|
299
|
+
const read = await readSkillFile(path);
|
|
300
|
+
if (read.kind === "absent") return { changed: false };
|
|
301
|
+
if (read.kind !== "ok" || skillFrontmatterName(read.bytes.toString("utf8")) !== name) {
|
|
302
|
+
return { changed: false };
|
|
303
|
+
}
|
|
304
|
+
const shipped = SHIPPED_SKILL_FILES[name] ?? [];
|
|
305
|
+
const subdirs = /* @__PURE__ */ new Set();
|
|
306
|
+
for (const rel of shipped) {
|
|
307
|
+
if (rel === "SKILL.md") continue;
|
|
308
|
+
const file = join2(skillDir, rel);
|
|
309
|
+
if (!isRealDirectory(dirname2(file))) continue;
|
|
310
|
+
subdirs.add(dirname2(file));
|
|
311
|
+
if (lstatSync(file, { throwIfNoEntry: false })?.isFile() === true) await rm(file);
|
|
312
|
+
}
|
|
313
|
+
await rm(path, { force: true });
|
|
314
|
+
for (const dir of [...subdirs, skillDir].sort((a, b) => b.length - a.length)) {
|
|
315
|
+
const rest = await readdir(dir).catch(() => null);
|
|
316
|
+
if (rest !== null && rest.length === 0) await rmdir(dir).catch(() => void 0);
|
|
317
|
+
}
|
|
318
|
+
return { changed: true };
|
|
319
|
+
}
|
|
320
|
+
async function removeRetiredSkills(home, project) {
|
|
321
|
+
const removed = [];
|
|
322
|
+
const dirs = [...skillsDirsFor(home), ...project ? skillsDirsFor(project) : []];
|
|
323
|
+
for (const dir of new Set(dirs)) {
|
|
324
|
+
for (const name of [...RETIRED_SKILL_NAMES, ...CLI_SKILL_NAMES]) {
|
|
325
|
+
if ((await removeOwnedSkill(name, dir)).changed) removed.push(join2(dir, name));
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return removed;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// src/router/legacy-install.ts
|
|
332
|
+
import { readFile, stat } from "node:fs/promises";
|
|
333
|
+
import { join as join3 } from "node:path";
|
|
334
|
+
|
|
335
|
+
// src/router/status-line-wiring.ts
|
|
336
|
+
var STATUS_LINE_COMMAND = "tenjin status-line";
|
|
337
|
+
var OUR_MARKER = STATUS_LINE_COMMAND;
|
|
338
|
+
function classifyStatusLine(value) {
|
|
339
|
+
if (value === null || value === void 0) return "absent";
|
|
340
|
+
const command = typeof value === "string" ? value : typeof value === "object" && !Array.isArray(value) ? value.command : void 0;
|
|
341
|
+
if (typeof command !== "string" || command.trim().length === 0) return "foreign";
|
|
342
|
+
if (command.trim() === OUR_MARKER) return "ours";
|
|
343
|
+
return command.includes(OUR_MARKER) ? "composed" : "foreign";
|
|
344
|
+
}
|
|
345
|
+
var shUnquote = (value) => value.replaceAll(String.raw`'\''`, "'");
|
|
346
|
+
function composedScript(existing) {
|
|
347
|
+
return [
|
|
348
|
+
"event=$(cat)",
|
|
349
|
+
`yours=$(printf %s "$event" | ${existing})`,
|
|
350
|
+
`tenjin=$(printf %s "$event" | ${STATUS_LINE_COMMAND})`,
|
|
351
|
+
'printf %s "$yours${tenjin:+ \xB7 $tenjin}"'
|
|
352
|
+
].join("; ");
|
|
353
|
+
}
|
|
354
|
+
function decomposeCommand(command) {
|
|
355
|
+
const trimmed = command.trim();
|
|
356
|
+
if (!trimmed.startsWith("sh -c '") || !trimmed.endsWith("'")) return null;
|
|
357
|
+
const script = shUnquote(trimmed.slice("sh -c '".length, -1));
|
|
358
|
+
const prefix = 'event=$(cat); yours=$(printf %s "$event" | ';
|
|
359
|
+
if (!script.startsWith(prefix)) return null;
|
|
360
|
+
const rest = script.slice(prefix.length);
|
|
361
|
+
const suffix = `); tenjin=$(printf %s "$event" | ${STATUS_LINE_COMMAND}); printf %s "$yours\${tenjin:+ \xB7 $tenjin}"`;
|
|
362
|
+
if (!rest.endsWith(suffix)) return null;
|
|
363
|
+
const existing = rest.slice(0, -suffix.length);
|
|
364
|
+
return existing.length > 0 && composedScript(existing) === script ? existing : null;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// src/router/legacy-install.ts
|
|
368
|
+
var LEGACY_COMMAND_RE = /^(\S*\/)?tenjin hook [a-z]+$/;
|
|
369
|
+
function isPlainObject(value) {
|
|
370
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
371
|
+
}
|
|
372
|
+
function ownsLegacyHandler(handler) {
|
|
373
|
+
if (!isPlainObject(handler)) return false;
|
|
374
|
+
if (handler.type === "mcp_tool") {
|
|
375
|
+
return handler.server === LEGACY_MCP_SERVER_NAME && handler.tool === "hook";
|
|
376
|
+
}
|
|
377
|
+
const command = handler.command;
|
|
378
|
+
return typeof command === "string" && LEGACY_COMMAND_RE.test(command.trim());
|
|
379
|
+
}
|
|
380
|
+
function lookalike(handler) {
|
|
381
|
+
if (!isPlainObject(handler) || ownsLegacyHandler(handler)) return null;
|
|
382
|
+
const command = handler.command;
|
|
383
|
+
return typeof command === "string" && command.includes("tenjin hook") ? command : null;
|
|
384
|
+
}
|
|
385
|
+
function classifyMcpEntry(entry) {
|
|
386
|
+
if (entry === null || typeof entry !== "object" || Array.isArray(entry)) return "absent";
|
|
387
|
+
const { command, args } = entry;
|
|
388
|
+
if (typeof command !== "string" || command.length === 0) return "wrong-command";
|
|
389
|
+
const binary = command.split(/[\\/]/).pop();
|
|
390
|
+
const runsRouter = binary === "tenjin" && Array.isArray(args) && args.length === 1 && args[0] === "mcp";
|
|
391
|
+
return runsRouter ? "ok" : "wrong-command";
|
|
392
|
+
}
|
|
393
|
+
async function readLegacyMcpEntry(path) {
|
|
394
|
+
let raw;
|
|
395
|
+
try {
|
|
396
|
+
raw = await readFile(path, "utf8");
|
|
397
|
+
} catch (err) {
|
|
398
|
+
const code = err.code;
|
|
399
|
+
return code === "ENOENT" || code === "ENOTDIR" ? "absent" : "unreadable";
|
|
400
|
+
}
|
|
401
|
+
let parsed;
|
|
402
|
+
try {
|
|
403
|
+
parsed = JSON.parse(raw);
|
|
404
|
+
} catch {
|
|
405
|
+
return "unreadable";
|
|
406
|
+
}
|
|
407
|
+
const servers = parsed?.mcpServers;
|
|
408
|
+
if (servers === void 0) return "absent";
|
|
409
|
+
if (!isPlainObject(servers)) return "unreadable";
|
|
410
|
+
const entry = servers[LEGACY_MCP_SERVER_NAME];
|
|
411
|
+
return entry === void 0 ? "absent" : classifyMcpEntry(entry);
|
|
412
|
+
}
|
|
413
|
+
async function inspectLegacyInstall(settingsPath, mcpFile) {
|
|
414
|
+
const mcp = await readLegacyMcpEntry(mcpFile);
|
|
415
|
+
const base = {
|
|
416
|
+
settingsPath,
|
|
417
|
+
mcpFile,
|
|
418
|
+
events: [],
|
|
419
|
+
allowRule: false,
|
|
420
|
+
denyRule: false,
|
|
421
|
+
statusLine: "absent",
|
|
422
|
+
mcp,
|
|
423
|
+
lookalikes: []
|
|
424
|
+
};
|
|
425
|
+
const found = await inspectHooksFile(settingsPath);
|
|
426
|
+
if ("refusal" in found) {
|
|
427
|
+
return { ...base, present: mcp === "ok", unreadable: found.refusal.message };
|
|
428
|
+
}
|
|
429
|
+
const events = Object.entries(found.hooks).filter(([, list]) => list.some((entry) => handlersOf(entry).some(ownsLegacyHandler))).map(([event]) => event);
|
|
430
|
+
const lookalikes = Object.values(found.hooks).flatMap(
|
|
431
|
+
(list) => list.flatMap(
|
|
432
|
+
(entry) => handlersOf(entry).map(lookalike).filter((c) => c !== null)
|
|
433
|
+
)
|
|
434
|
+
);
|
|
435
|
+
const rulesOurs = mcp === "ok" || mcp === "absent" && events.length > 0;
|
|
436
|
+
const allowRule = rulesOurs && listOf(found.settings, "allow").includes(LEGACY_REQUEST_TOOL);
|
|
437
|
+
const denyRule = rulesOurs && listOf(found.settings, "deny").includes(LEGACY_HOOK_TOOL);
|
|
438
|
+
const statusLine = events.length > 0 ? classifyStatusLine(found.settings.statusLine) : "absent";
|
|
439
|
+
const statusOurs = statusLine === "ours" || statusLine === "composed";
|
|
440
|
+
return {
|
|
441
|
+
...base,
|
|
442
|
+
present: events.length > 0 || allowRule || denyRule || statusOurs || mcp === "ok",
|
|
443
|
+
events,
|
|
444
|
+
allowRule,
|
|
445
|
+
denyRule,
|
|
446
|
+
statusLine,
|
|
447
|
+
lookalikes
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
function handlersOf(entry) {
|
|
451
|
+
return isPlainObject(entry) && Array.isArray(entry.hooks) ? entry.hooks : [];
|
|
452
|
+
}
|
|
453
|
+
function listOf(settings, key) {
|
|
454
|
+
const permissions = settings.permissions;
|
|
455
|
+
if (!isPlainObject(permissions)) return [];
|
|
456
|
+
const list = permissions[key];
|
|
457
|
+
return Array.isArray(list) ? list : [];
|
|
458
|
+
}
|
|
459
|
+
async function removeLegacyInstall(found, opts) {
|
|
460
|
+
const out = {
|
|
461
|
+
events: [],
|
|
462
|
+
allowRule: false,
|
|
463
|
+
denyRule: false,
|
|
464
|
+
statusLine: "kept",
|
|
465
|
+
mcp: found.mcp === "absent" ? "absent" : "kept",
|
|
466
|
+
wroteSettings: false,
|
|
467
|
+
warnings: []
|
|
468
|
+
};
|
|
469
|
+
if (found.unreadable === void 0) await removeFromSettings(found, out);
|
|
470
|
+
else out.warnings.push(found.unreadable);
|
|
471
|
+
if (found.mcp === "ok") await removeMcpEntry(opts, out);
|
|
472
|
+
else if (found.mcp === "wrong-command") {
|
|
473
|
+
out.warnings.push(
|
|
474
|
+
`an MCP server named ${LEGACY_MCP_SERVER_NAME} launches something else, so it is not Tenjin's and was left in place`
|
|
475
|
+
);
|
|
476
|
+
} else if (found.mcp === "unreadable") {
|
|
477
|
+
out.warnings.push(`${found.mcpFile} could not be read, so nothing was removed from it`);
|
|
478
|
+
}
|
|
479
|
+
return out;
|
|
480
|
+
}
|
|
481
|
+
async function removeFromSettings(found, out) {
|
|
482
|
+
const read = await inspectHooksFile(found.settingsPath);
|
|
483
|
+
if ("refusal" in read) {
|
|
484
|
+
out.warnings.push(read.refusal.message);
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
if (read.raw === null) return;
|
|
488
|
+
const next = { ...read.settings };
|
|
489
|
+
if (isPlainObject(read.settings.hooks)) {
|
|
490
|
+
const hooks = {};
|
|
491
|
+
for (const [event, list] of Object.entries(read.hooks)) {
|
|
492
|
+
const kept = [];
|
|
493
|
+
for (const entry of list) {
|
|
494
|
+
const handlers = handlersOf(entry);
|
|
495
|
+
const left = handlers.filter((h) => !ownsLegacyHandler(h));
|
|
496
|
+
if (left.length === handlers.length) kept.push(entry);
|
|
497
|
+
else if (left.length > 0) kept.push({ ...entry, hooks: left });
|
|
498
|
+
}
|
|
499
|
+
if (kept.length !== list.length || kept.some((e, i) => e !== list[i])) out.events.push(event);
|
|
500
|
+
if (kept.length > 0 || list.length === 0) hooks[event] = kept;
|
|
501
|
+
}
|
|
502
|
+
next.hooks = hooks;
|
|
503
|
+
}
|
|
504
|
+
if ((found.allowRule || found.denyRule) && isPlainObject(read.settings.permissions)) {
|
|
505
|
+
const permissions = { ...read.settings.permissions };
|
|
506
|
+
if (found.allowRule && Array.isArray(permissions.allow)) {
|
|
507
|
+
permissions.allow = permissions.allow.filter((r) => r !== LEGACY_REQUEST_TOOL);
|
|
508
|
+
out.allowRule = true;
|
|
509
|
+
}
|
|
510
|
+
if (found.denyRule && Array.isArray(permissions.deny)) {
|
|
511
|
+
permissions.deny = permissions.deny.filter((r) => r !== LEGACY_HOOK_TOOL);
|
|
512
|
+
out.denyRule = true;
|
|
513
|
+
}
|
|
514
|
+
next.permissions = permissions;
|
|
515
|
+
}
|
|
516
|
+
if (found.statusLine === "ours") {
|
|
517
|
+
delete next.statusLine;
|
|
518
|
+
out.statusLine = "removed";
|
|
519
|
+
} else if (found.statusLine === "composed" && isPlainObject(read.settings.statusLine)) {
|
|
520
|
+
const command = read.settings.statusLine.command;
|
|
521
|
+
const original = typeof command === "string" ? decomposeCommand(command) : null;
|
|
522
|
+
if (original !== null) {
|
|
523
|
+
next.statusLine = { ...read.settings.statusLine, command: original };
|
|
524
|
+
out.statusLine = "restored";
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
const removed = out.events.length > 0 || out.allowRule || out.denyRule || out.statusLine !== "kept";
|
|
528
|
+
if (!removed) return;
|
|
529
|
+
const body = `${JSON.stringify(next, null, 2)}
|
|
530
|
+
`;
|
|
531
|
+
const mode = await stat(read.path).then((s) => ({ mode: s.mode & 511 })).catch(() => ({}));
|
|
532
|
+
if (await readFile(read.path, "utf8").catch(() => null) !== read.raw) {
|
|
533
|
+
out.warnings.push(`${read.path} changed while it was read, so it was left as it is`);
|
|
534
|
+
Object.assign(out, { events: [], allowRule: false, denyRule: false, statusLine: "kept" });
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
try {
|
|
538
|
+
await writeFileAtomic(read.path, body, mode);
|
|
539
|
+
out.wroteSettings = true;
|
|
540
|
+
} catch (err) {
|
|
541
|
+
out.warnings.push(err instanceof Error ? err.message : String(err));
|
|
542
|
+
Object.assign(out, { events: [], allowRule: false, denyRule: false, statusLine: "kept" });
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
async function removeMcpEntry(opts, out) {
|
|
546
|
+
if (opts.binary === null) {
|
|
547
|
+
out.warnings.push(
|
|
548
|
+
`the ${LEGACY_MCP_SERVER_NAME} MCP registration stays until a run with the claude binary removes it`
|
|
549
|
+
);
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
const run = await runClaude(
|
|
553
|
+
opts.binary,
|
|
554
|
+
["mcp", "remove", LEGACY_MCP_SERVER_NAME, "-s", opts.mcpScope],
|
|
555
|
+
{ env: opts.env, cwd: opts.cwd }
|
|
556
|
+
);
|
|
557
|
+
if (run.code === 0) out.mcp = "removed";
|
|
558
|
+
else {
|
|
559
|
+
out.warnings.push(
|
|
560
|
+
`claude mcp remove ${LEGACY_MCP_SERVER_NAME} did not succeed: ${(run.stderr || run.stdout).trim().slice(0, 200) || "no output"}`
|
|
561
|
+
);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
function projectMcpFile(cwd) {
|
|
565
|
+
return join3(cwd, ".mcp.json");
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// src/router/plugin-registration.ts
|
|
569
|
+
import { readFile as readFile3, stat as stat2 } from "node:fs/promises";
|
|
570
|
+
import { dirname as dirname4, join as join5 } from "node:path";
|
|
571
|
+
import { fileURLToPath } from "node:url";
|
|
572
|
+
|
|
573
|
+
// src/router/plugin-folder.ts
|
|
574
|
+
import { lstat, readdir as readdir2, readFile as readFile2, rm as rm2, rmdir as rmdir2 } from "node:fs/promises";
|
|
575
|
+
import { dirname as dirname3, join as join4, relative, sep as sep2 } from "node:path";
|
|
576
|
+
var FOLDER_NAME = "tenjin-router";
|
|
577
|
+
async function readModSources(pluginDir) {
|
|
578
|
+
const entries = await Promise.all(
|
|
579
|
+
MOD_FILES.map(async (path) => [path, await readFile2(join4(pluginDir, path), "utf8")])
|
|
580
|
+
).catch(() => null);
|
|
581
|
+
return entries === null ? void 0 : Object.fromEntries(entries);
|
|
582
|
+
}
|
|
583
|
+
function pluginFolderPath(base) {
|
|
584
|
+
return join4(base, "skills", FOLDER_NAME);
|
|
585
|
+
}
|
|
586
|
+
async function inspectPluginFolder(dir) {
|
|
587
|
+
const entry = await lstat(dir).catch(() => null);
|
|
588
|
+
if (entry === null) return "absent";
|
|
589
|
+
if (!entry.isDirectory() || entry.isSymbolicLink()) return "foreign";
|
|
590
|
+
try {
|
|
591
|
+
const manifest = JSON.parse(
|
|
592
|
+
await readFile2(join4(dir, ".claude-plugin", "plugin.json"), "utf8")
|
|
593
|
+
);
|
|
594
|
+
const marked = manifest.metadata !== null && typeof manifest.metadata === "object" && OWNER_MARKER in manifest.metadata;
|
|
595
|
+
return manifest.name === PLUGIN_NAME && marked ? "ours" : "foreign";
|
|
596
|
+
} catch {
|
|
597
|
+
return "foreign";
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
async function writePluginFolder(dir, files) {
|
|
601
|
+
const state = await inspectPluginFolder(dir);
|
|
602
|
+
if (state === "foreign") {
|
|
603
|
+
return {
|
|
604
|
+
path: dir,
|
|
605
|
+
state: "refused",
|
|
606
|
+
reason: `${dir} exists and is not a folder this CLI wrote, so it was left as it is`
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
try {
|
|
610
|
+
for (const path of PLUGIN_FILES) {
|
|
611
|
+
const body = files[path];
|
|
612
|
+
if (body === void 0) continue;
|
|
613
|
+
await writeFileAtomic(join4(dir, path), body);
|
|
614
|
+
}
|
|
615
|
+
} catch (err) {
|
|
616
|
+
return {
|
|
617
|
+
path: dir,
|
|
618
|
+
state: "refused",
|
|
619
|
+
reason: err instanceof Error ? err.message : String(err)
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
return { path: dir, state: "written" };
|
|
623
|
+
}
|
|
624
|
+
async function removePluginFolder(dir) {
|
|
625
|
+
const state = await inspectPluginFolder(dir);
|
|
626
|
+
if (state === "absent") return { path: dir, removed: false, left: [] };
|
|
627
|
+
if (state === "foreign") {
|
|
628
|
+
return {
|
|
629
|
+
path: dir,
|
|
630
|
+
removed: false,
|
|
631
|
+
left: [],
|
|
632
|
+
reason: `${dir} is not a folder this CLI wrote, so nothing in it was removed`
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
for (const path of PLUGIN_FILES) await rm2(join4(dir, path), { force: true });
|
|
636
|
+
const subdirs = [...new Set(PLUGIN_FILES.map((p) => dirname3(p)).filter((d) => d !== "."))].sort(
|
|
637
|
+
(a, b) => b.split("/").length - a.split("/").length
|
|
638
|
+
);
|
|
639
|
+
for (const sub of subdirs) await rmdir2(join4(dir, sub)).catch(() => void 0);
|
|
640
|
+
const left = await listFiles(dir);
|
|
641
|
+
if (left.length === 0) await rmdir2(dir).catch(() => void 0);
|
|
642
|
+
return { path: dir, removed: true, left };
|
|
643
|
+
}
|
|
644
|
+
async function listFiles(dir) {
|
|
645
|
+
const out = [];
|
|
646
|
+
const walk = async (current) => {
|
|
647
|
+
for (const entry of await readdir2(current, { withFileTypes: true }).catch(() => [])) {
|
|
648
|
+
const path = join4(current, entry.name);
|
|
649
|
+
if (entry.isDirectory()) await walk(path);
|
|
650
|
+
else out.push(relative(dir, path).split(sep2).join("/"));
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
await walk(dir);
|
|
654
|
+
return out.sort();
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// src/router/plugin-registration.ts
|
|
658
|
+
function folderFor(scope, env, home, cwd) {
|
|
659
|
+
return pluginFolderPath(scope === "local" ? join5(cwd, ".claude") : claudeConfigDir(env, home));
|
|
660
|
+
}
|
|
661
|
+
async function registerPlugin(opts) {
|
|
662
|
+
const folder = folderFor(opts.scope, opts.env, opts.home, opts.cwd);
|
|
663
|
+
const steps = [];
|
|
664
|
+
let fallbackReason;
|
|
665
|
+
if (opts.binary !== null) {
|
|
666
|
+
const hosts = opts.hostsDir === void 0 ? await packageHostsDir() : opts.hostsDir;
|
|
667
|
+
if (hosts === null) {
|
|
668
|
+
fallbackReason = "this build carries no plugin marketplace folder (dist/hosts/claude)";
|
|
669
|
+
} else {
|
|
670
|
+
const done = await viaPluginCommands(opts.binary, hosts, opts, steps);
|
|
671
|
+
if (done.ok) {
|
|
672
|
+
const superseded = await removePluginFolder(folder);
|
|
673
|
+
return {
|
|
674
|
+
method: "plugin",
|
|
675
|
+
id: PLUGIN_ID,
|
|
676
|
+
scope: opts.scope,
|
|
677
|
+
state: done.state,
|
|
678
|
+
path: hosts,
|
|
679
|
+
version: opts.version,
|
|
680
|
+
steps,
|
|
681
|
+
...superseded.removed ? { supersededFolder: superseded } : {}
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
fallbackReason = done.reason;
|
|
685
|
+
}
|
|
686
|
+
const existing = await existingCopy(opts.binary, opts.env, opts.home, opts.cwd);
|
|
687
|
+
if (existing !== null) {
|
|
688
|
+
return {
|
|
689
|
+
method: "none",
|
|
690
|
+
id: existing,
|
|
691
|
+
scope: opts.scope,
|
|
692
|
+
state: "failed",
|
|
693
|
+
version: opts.version,
|
|
694
|
+
steps,
|
|
695
|
+
reason: `${fallbackReason}; ${existing} is already in Claude Code and was left as it is, so no second copy was written`
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
} else {
|
|
699
|
+
fallbackReason = "no claude binary on PATH or in CLAUDE_CODE_EXECPATH";
|
|
700
|
+
if (await installedThroughCommands(opts.env, opts.home)) {
|
|
701
|
+
return {
|
|
702
|
+
method: "plugin",
|
|
703
|
+
id: PLUGIN_ID,
|
|
704
|
+
scope: opts.scope,
|
|
705
|
+
state: "current",
|
|
706
|
+
version: opts.version,
|
|
707
|
+
steps,
|
|
708
|
+
fallbackReason: `${fallbackReason}; ${PLUGIN_ID} is already registered, so it was left as it is`
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
const written = await writePluginFolder(
|
|
713
|
+
folder,
|
|
714
|
+
renderPluginFiles(
|
|
715
|
+
opts.version,
|
|
716
|
+
opts.cliEntry ?? packageCliEntry(),
|
|
717
|
+
await packageMod(opts.hostsDir)
|
|
718
|
+
)
|
|
719
|
+
);
|
|
720
|
+
if (written.state === "written") {
|
|
721
|
+
return {
|
|
722
|
+
method: "skills-dir",
|
|
723
|
+
id: SKILLS_DIR_PLUGIN_ID,
|
|
724
|
+
scope: opts.scope,
|
|
725
|
+
state: "written",
|
|
726
|
+
path: folder,
|
|
727
|
+
version: opts.version,
|
|
728
|
+
steps,
|
|
729
|
+
fallbackReason
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
return {
|
|
733
|
+
method: "none",
|
|
734
|
+
id: null,
|
|
735
|
+
scope: opts.scope,
|
|
736
|
+
state: "failed",
|
|
737
|
+
path: folder,
|
|
738
|
+
version: opts.version,
|
|
739
|
+
steps,
|
|
740
|
+
fallbackReason,
|
|
741
|
+
reason: written.reason ?? "the plugin folder could not be written"
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
async function viaPluginCommands(binary, hosts, opts, steps) {
|
|
745
|
+
const run = (args) => runClaude(binary, args, { env: opts.env, cwd: opts.cwd });
|
|
746
|
+
const scopeArgs = ["--scope", opts.scope];
|
|
747
|
+
const marketplaceScope = opts.scope === "user" ? [] : scopeArgs;
|
|
748
|
+
const known = await run(["plugin", "marketplace", "list", "--json"]);
|
|
749
|
+
const listed = known.code === 0 ? jsonList(known.stdout) : null;
|
|
750
|
+
steps.push({
|
|
751
|
+
command: "claude plugin marketplace list --json",
|
|
752
|
+
ok: listed !== null,
|
|
753
|
+
...listed === null ? { detail: commandDetail(known) } : {}
|
|
754
|
+
});
|
|
755
|
+
if (listed === null) {
|
|
756
|
+
return {
|
|
757
|
+
ok: false,
|
|
758
|
+
reason: `claude plugin marketplace list could not be read (${commandDetail(known)}), so no marketplace was added or repointed`
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
const existing = listed.find((m) => m.name === MARKETPLACE_NAME);
|
|
762
|
+
if (existing !== void 0 && !await ownMarketplace(existing)) {
|
|
763
|
+
return {
|
|
764
|
+
ok: false,
|
|
765
|
+
reason: `a marketplace named ${MARKETPLACE_NAME} that this CLI did not add is already configured, so it was left as it is`
|
|
766
|
+
};
|
|
767
|
+
}
|
|
768
|
+
const add = await step(
|
|
769
|
+
steps,
|
|
770
|
+
["plugin", "marketplace", "add", hosts, "--json", ...marketplaceScope],
|
|
771
|
+
run
|
|
772
|
+
);
|
|
773
|
+
if (!add.ok) return { ok: false, reason: `claude plugin marketplace add failed: ${add.detail}` };
|
|
774
|
+
const install = await step(steps, ["plugin", "install", PLUGIN_ID, ...scopeArgs, "--json"], run);
|
|
775
|
+
if (!install.ok) return { ok: false, reason: `claude plugin install failed: ${install.detail}` };
|
|
776
|
+
const installed = install.result?.installedVersion;
|
|
777
|
+
const available = install.result?.availableVersion;
|
|
778
|
+
if (typeof installed !== "string" || typeof available !== "string") {
|
|
779
|
+
return { ok: true, state: "installed" };
|
|
780
|
+
}
|
|
781
|
+
if (installed === available) return { ok: true, state: "current" };
|
|
782
|
+
const update = await step(steps, ["plugin", "update", PLUGIN_ID, ...scopeArgs, "--json"], run);
|
|
783
|
+
if (!update.ok) return { ok: false, reason: `claude plugin update failed: ${update.detail}` };
|
|
784
|
+
return { ok: true, state: "updated" };
|
|
785
|
+
}
|
|
786
|
+
async function step(steps, args, run) {
|
|
787
|
+
const out = await run(args);
|
|
788
|
+
const result = jsonResult(out.stdout);
|
|
789
|
+
const ok = out.code === 0 && (result === null || result.outcome === void 0 || result.outcome === "ok");
|
|
790
|
+
const detail = commandDetail(out, result);
|
|
791
|
+
steps.push({ command: `claude ${args.join(" ")}`, ok, ...ok ? {} : { detail } });
|
|
792
|
+
return { ok, detail, result };
|
|
793
|
+
}
|
|
794
|
+
function commandDetail(out, result = null) {
|
|
795
|
+
if (typeof result?.message === "string") return result.message;
|
|
796
|
+
const text = (out.stderr || out.stdout).trim().slice(0, 300);
|
|
797
|
+
if (text.length > 0) return text;
|
|
798
|
+
return out.code === null ? "the command could not be run" : `exit ${out.code}`;
|
|
799
|
+
}
|
|
800
|
+
async function ownMarketplace(row) {
|
|
801
|
+
const path = typeof row.path === "string" ? row.path : void 0;
|
|
802
|
+
if (row.source !== "directory" || path === void 0) return false;
|
|
803
|
+
if (await stat2(path).catch(() => null) === null) {
|
|
804
|
+
return /tenjin-cli[\\/]dist[\\/]hosts[\\/]claude$/.test(path);
|
|
805
|
+
}
|
|
806
|
+
return await inspectPluginFolder(join5(path, PLUGIN_DIR)) === "ours";
|
|
807
|
+
}
|
|
808
|
+
async function existingCopy(binary, env, home, cwd) {
|
|
809
|
+
const out = await runClaude(binary, ["plugin", "list", "--json"], { env, cwd });
|
|
810
|
+
const listed = out.code === 0 ? jsonList(out.stdout) : null;
|
|
811
|
+
if (listed === null) return await installedThroughCommands(env, home) ? PLUGIN_ID : null;
|
|
812
|
+
const row = listed.find(
|
|
813
|
+
(p) => typeof p.id === "string" && p.id.startsWith(`${PLUGIN_NAME}@`) && p.id !== SKILLS_DIR_PLUGIN_ID && p.enabled === true
|
|
814
|
+
);
|
|
815
|
+
return typeof row?.id === "string" ? row.id : null;
|
|
816
|
+
}
|
|
817
|
+
async function installedThroughCommands(env, home) {
|
|
818
|
+
try {
|
|
819
|
+
const raw = await readFile3(
|
|
820
|
+
join5(claudeConfigDir(env, home), "plugins", "installed_plugins.json"),
|
|
821
|
+
"utf8"
|
|
822
|
+
);
|
|
823
|
+
const plugins = JSON.parse(raw).plugins;
|
|
824
|
+
return plugins !== null && typeof plugins === "object" && PLUGIN_ID in plugins;
|
|
825
|
+
} catch {
|
|
826
|
+
return false;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
async function packageHostsDir(moduleDir = dirname4(fileURLToPath(import.meta.url))) {
|
|
830
|
+
const catalog = join5(moduleDir, "hosts", "claude", ".claude-plugin", "marketplace.json");
|
|
831
|
+
const stable = versionFreeEntry(catalog) ?? catalog;
|
|
832
|
+
if ((await stat2(stable).catch(() => null))?.isFile() !== true) return null;
|
|
833
|
+
return dirname4(dirname4(stable));
|
|
834
|
+
}
|
|
835
|
+
async function packageMod(hostsDir) {
|
|
836
|
+
const hosts = hostsDir === void 0 ? await packageHostsDir() : hostsDir;
|
|
837
|
+
return hosts === null ? void 0 : readModSources(join5(hosts, PLUGIN_DIR));
|
|
838
|
+
}
|
|
839
|
+
function packageCliEntry(moduleDir = dirname4(fileURLToPath(import.meta.url))) {
|
|
840
|
+
const entry = join5(moduleDir, "index.js");
|
|
841
|
+
return versionFreeEntry(entry) ?? entry;
|
|
842
|
+
}
|
|
843
|
+
async function readPluginListing(binary, env, cwd) {
|
|
844
|
+
const out = await runClaude(binary, ["plugin", "list", "--json"], { env, cwd });
|
|
845
|
+
const rows = out.code === 0 ? jsonList(out.stdout) : null;
|
|
846
|
+
if (rows === null) return { id: null, enabled: false, version: null, read: false };
|
|
847
|
+
const row = rows.find((r) => r.id === PLUGIN_ID && r.enabled === true) ?? rows.find((r) => r.id === SKILLS_DIR_PLUGIN_ID && r.enabled === true) ?? rows.find((r) => r.id === PLUGIN_ID || r.id === SKILLS_DIR_PLUGIN_ID);
|
|
848
|
+
if (row === void 0) return { id: null, enabled: false, version: null, read: true };
|
|
849
|
+
return {
|
|
850
|
+
id: String(row.id),
|
|
851
|
+
enabled: row.enabled === true,
|
|
852
|
+
version: typeof row.version === "string" ? row.version : null,
|
|
853
|
+
read: true
|
|
854
|
+
};
|
|
855
|
+
}
|
|
856
|
+
async function folderState(scope, env, home, cwd) {
|
|
857
|
+
const path = folderFor(scope, env, home, cwd);
|
|
858
|
+
return { path, state: await inspectPluginFolder(path) };
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
// src/router/reachability.ts
|
|
862
|
+
async function probeRouter(baseUrl, opts) {
|
|
863
|
+
const fail = (detail, fix) => ({
|
|
864
|
+
name: "router",
|
|
865
|
+
status: "fail",
|
|
866
|
+
required: true,
|
|
867
|
+
detail,
|
|
868
|
+
fix
|
|
869
|
+
});
|
|
870
|
+
let url;
|
|
871
|
+
try {
|
|
872
|
+
url = new URL(ROUTER_PATH, baseUrl).toString();
|
|
873
|
+
} catch {
|
|
874
|
+
return fail(
|
|
875
|
+
`the base URL ${JSON.stringify(baseUrl)} is not a URL`,
|
|
876
|
+
`Check TENJIN_BASE_URL, or set it with \`tenjin config set baseUrl ${PRODUCTION_ORIGIN}\`.`
|
|
877
|
+
);
|
|
878
|
+
}
|
|
879
|
+
const host = new URL(url).host;
|
|
880
|
+
const probe = await httpRequest(url, {
|
|
881
|
+
method: "POST",
|
|
882
|
+
timeoutMs: opts.timeoutMs,
|
|
883
|
+
blockRedirects: true,
|
|
884
|
+
// A reachability check, not use: it must not count this machine as an install.
|
|
885
|
+
anonymous: true,
|
|
886
|
+
jsonBody: {},
|
|
887
|
+
...opts.fetchImpl !== void 0 ? { fetchImpl: opts.fetchImpl } : {}
|
|
888
|
+
});
|
|
889
|
+
const production = isSameDeployment(new URL(url).origin, PRODUCTION_ORIGIN);
|
|
890
|
+
const checkBase = production ? "Try again later." : "Check that the configured base URL names the Tenjin router (`tenjin config get baseUrl`), then try again later.";
|
|
891
|
+
const env = opts.env ?? process.env;
|
|
892
|
+
const network = networkFix(host, env, production, opts.proxySupported ?? envProxySupported());
|
|
893
|
+
const credentials = proxyCredentialsFix(env);
|
|
894
|
+
const unreached = production ? network : checkBase;
|
|
895
|
+
if (!probe.ok) {
|
|
896
|
+
const t = probe.transport;
|
|
897
|
+
if (t?.layer === "proxy" && t.proxyStatus === 407) {
|
|
898
|
+
return fail(
|
|
899
|
+
`a proxy between this machine and ${host} asked for its own credentials (407)`,
|
|
900
|
+
credentials
|
|
901
|
+
);
|
|
902
|
+
}
|
|
903
|
+
if (t?.layer === "proxy") {
|
|
904
|
+
return fail(
|
|
905
|
+
`a proxy refused the connection to ${host} (${t.proxyStatus}), so the router never answered`,
|
|
906
|
+
unreached
|
|
907
|
+
);
|
|
908
|
+
}
|
|
909
|
+
if (t?.layer === "dns") {
|
|
910
|
+
return fail(`${host} did not resolve (${t.code}), so the router was not reached`, unreached);
|
|
911
|
+
}
|
|
912
|
+
if (t?.layer === "tls") {
|
|
913
|
+
return fail(
|
|
914
|
+
`the TLS connection to ${host} failed (${t.code}). A proxy that inspects TLS causes this`,
|
|
915
|
+
`If this network inspects TLS, set NODE_EXTRA_CA_CERTS to its CA certificate. ${unreached}`
|
|
916
|
+
);
|
|
917
|
+
}
|
|
918
|
+
if (t?.layer === "connect") {
|
|
919
|
+
return fail(`could not connect to ${host} (${t.code})`, unreached);
|
|
920
|
+
}
|
|
921
|
+
return fail(`the router at ${url} is unreachable or erroring (${probe.message})`, unreached);
|
|
922
|
+
}
|
|
923
|
+
if (probe.status === 200 || probe.status === 400 || probe.status === 429) {
|
|
924
|
+
return { name: "router", status: "ok", required: true, detail: `${url} is live` };
|
|
925
|
+
}
|
|
926
|
+
if (probe.status === 404) {
|
|
927
|
+
return fail(`the router is not enabled at ${url}`, checkBase);
|
|
928
|
+
}
|
|
929
|
+
if (probe.status === 407) {
|
|
930
|
+
return fail(
|
|
931
|
+
`a proxy between this machine and ${host} asked for its own credentials (407)`,
|
|
932
|
+
credentials
|
|
933
|
+
);
|
|
934
|
+
}
|
|
935
|
+
if (probe.status === 401 || probe.status === 403) {
|
|
936
|
+
if (!fromDeployment(probe)) {
|
|
937
|
+
return fail(
|
|
938
|
+
`${host} answered ${probe.status} without the headers a Tenjin deployment sends, so a proxy, firewall or VPN on the way most likely refused the request`,
|
|
939
|
+
network
|
|
940
|
+
);
|
|
941
|
+
}
|
|
942
|
+
if (production) {
|
|
943
|
+
return fail(`${url} refused this machine (${probe.status})`, checkBase);
|
|
944
|
+
}
|
|
945
|
+
return fail(
|
|
946
|
+
`${url} is not a Tenjin router (it asked for credentials)`,
|
|
947
|
+
`Set the router URL with \`tenjin config set baseUrl ${PRODUCTION_ORIGIN}\`.`
|
|
948
|
+
);
|
|
949
|
+
}
|
|
950
|
+
if (probe.status >= 500) {
|
|
951
|
+
return fail(`the router at ${url} is unreachable or erroring (${probe.status})`, checkBase);
|
|
952
|
+
}
|
|
953
|
+
return fail(
|
|
954
|
+
`${url} answered ${probe.status}, which a Tenjin router does not`,
|
|
955
|
+
"Check that the configured base URL names a Tenjin deployment (`tenjin config get baseUrl`)."
|
|
956
|
+
);
|
|
957
|
+
}
|
|
958
|
+
function fromDeployment(probe) {
|
|
959
|
+
return probe.header("x-vercel-id") !== void 0 || probe.header("x-request-id") !== void 0;
|
|
960
|
+
}
|
|
961
|
+
function networkFix(host, env, production, proxySupported) {
|
|
962
|
+
const proxy = proxyVariable(env);
|
|
963
|
+
const config = production ? " Tenjin's own config is correct and needs no change." : "";
|
|
964
|
+
if (proxy !== void 0 && !proxySupported) {
|
|
965
|
+
return `This shell sets ${proxy}, but Node ${process.versions.node} cannot send Tenjin's requests through it. Upgrade to Node 24.14 or newer, or run from a network that reaches ${host} directly.${config}`;
|
|
966
|
+
}
|
|
967
|
+
const via = proxy !== void 0 ? ` (this shell sets ${proxy})` : "";
|
|
968
|
+
return `Allow ${host} through your proxy, firewall or VPN${via}, or run from a network that reaches it.${config}`;
|
|
969
|
+
}
|
|
970
|
+
function proxyCredentialsFix(env) {
|
|
971
|
+
const proxy = proxyVariable(env) ?? "HTTPS_PROXY";
|
|
972
|
+
return `Put the proxy's credentials in ${proxy} (\`http://user:password@proxy:port\`), then try again.`;
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
// src/router/mcp-processes.ts
|
|
976
|
+
import { execFile } from "node:child_process";
|
|
977
|
+
import { stat as stat3 } from "node:fs/promises";
|
|
978
|
+
import { dirname as dirname5, join as join6 } from "node:path";
|
|
979
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
980
|
+
import { promisify } from "node:util";
|
|
981
|
+
var exec = promisify(execFile);
|
|
982
|
+
var listMcpProcesses = async () => {
|
|
983
|
+
if (process.platform === "win32" || typeof process.getuid !== "function") return null;
|
|
984
|
+
try {
|
|
985
|
+
const { stdout } = await exec(
|
|
986
|
+
"ps",
|
|
987
|
+
["-U", String(process.getuid()), "-o", "pid=,lstart=,args="],
|
|
988
|
+
{ timeout: 5e3, env: { ...process.env, LC_ALL: "C" }, maxBuffer: 4 * 1024 * 1024 }
|
|
989
|
+
);
|
|
990
|
+
return parsePs(stdout, process.pid);
|
|
991
|
+
} catch {
|
|
992
|
+
return null;
|
|
993
|
+
}
|
|
994
|
+
};
|
|
995
|
+
var PS_LINE = /^\s*(\d+)\s+(\w{3}\s+\w{3}\s+\d{1,2}\s+\d{2}:\d{2}:\d{2}\s+\d{4})\s+(.*)$/;
|
|
996
|
+
function parsePs(stdout, selfPid) {
|
|
997
|
+
const found = [];
|
|
998
|
+
for (const line of stdout.split("\n")) {
|
|
999
|
+
const m = PS_LINE.exec(line);
|
|
1000
|
+
if (m === null) continue;
|
|
1001
|
+
const pid = Number(m[1]);
|
|
1002
|
+
if (pid === selfPid || !isTenjinMcp(m[3])) continue;
|
|
1003
|
+
const startedAt = Date.parse(m[2].replace(/\s+/g, " "));
|
|
1004
|
+
found.push({ pid, startedAt: Number.isNaN(startedAt) ? null : startedAt });
|
|
1005
|
+
}
|
|
1006
|
+
return found;
|
|
1007
|
+
}
|
|
1008
|
+
function isTenjinMcp(args) {
|
|
1009
|
+
const tokens = args.trim().split(/\s+/);
|
|
1010
|
+
const bin = tokens.findIndex(
|
|
1011
|
+
(t) => /(^|[/\\])tenjin(\.js|\.cmd)?$/.test(t) || /[/\\]tenjin-cli[/\\]/.test(t) || /[/\\]hosts[/\\]claude[/\\]tenjin[/\\]\.\.[/\\]\.\.[/\\]\.\.[/\\]index\.js$/.test(t)
|
|
1012
|
+
);
|
|
1013
|
+
return bin >= 0 && tokens[bin + 1] === "mcp";
|
|
1014
|
+
}
|
|
1015
|
+
var installedAt = async () => {
|
|
1016
|
+
let dir = dirname5(fileURLToPath2(import.meta.url));
|
|
1017
|
+
for (let i = 0; i < 6; i += 1) {
|
|
1018
|
+
try {
|
|
1019
|
+
const st = await stat3(join6(dir, "package.json"));
|
|
1020
|
+
return Math.max(st.ctimeMs, st.mtimeMs);
|
|
1021
|
+
} catch {
|
|
1022
|
+
dir = dirname5(dir);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
return null;
|
|
1026
|
+
};
|
|
1027
|
+
var RECONNECT_FIX = "Type /reload-plugins in this Claude Code session, or start a new session.";
|
|
1028
|
+
var NEW_SESSION_FIX = "Start a new Claude Code session: the earlier Tenjin setup is still in this one, and /reload-plugins would run both.";
|
|
1029
|
+
function mcpServersState(procs, installed, version = package_default.version, fix = RECONNECT_FIX) {
|
|
1030
|
+
const check = (detail) => ({
|
|
1031
|
+
stale: 0,
|
|
1032
|
+
check: { name: "mcp server", status: "ok", required: false, detail }
|
|
1033
|
+
});
|
|
1034
|
+
if (procs === null) {
|
|
1035
|
+
return check("unknown: running `tenjin mcp` processes cannot be listed on this platform");
|
|
1036
|
+
}
|
|
1037
|
+
if (procs.length === 0) return check("none running (starts with the next session)");
|
|
1038
|
+
if (installed === null) {
|
|
1039
|
+
return check(`${procs.length} running; when this build was installed is unknown`);
|
|
1040
|
+
}
|
|
1041
|
+
const stale = procs.filter((p) => p.startedAt !== null && p.startedAt < installed).length;
|
|
1042
|
+
if (stale === 0) {
|
|
1043
|
+
return check(`${procs.length} running, all started after this install`);
|
|
1044
|
+
}
|
|
1045
|
+
const which = stale === 1 ? "process" : "processes";
|
|
1046
|
+
return {
|
|
1047
|
+
stale,
|
|
1048
|
+
check: {
|
|
1049
|
+
name: "mcp server",
|
|
1050
|
+
status: "warn",
|
|
1051
|
+
required: false,
|
|
1052
|
+
detail: `${stale} running \`tenjin mcp\` ${which} started before this install (${version}), so ${stale === 1 ? "it runs" : "they run"} the older build, where the hooks can fail with "Tool hook not found"`,
|
|
1053
|
+
fix
|
|
1054
|
+
}
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
async function readMcpServers(deps = {}, opts = {}) {
|
|
1058
|
+
const [procs, installed] = await Promise.all([
|
|
1059
|
+
(deps.listMcpProcesses ?? listMcpProcesses)().catch(() => null),
|
|
1060
|
+
(deps.installedAt ?? installedAt)().catch(() => null)
|
|
1061
|
+
]);
|
|
1062
|
+
const fix = opts.settingsInstallPending === true ? NEW_SESSION_FIX : RECONNECT_FIX;
|
|
1063
|
+
return mcpServersState(procs, installed, package_default.version, fix);
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
// src/router/install.ts
|
|
1067
|
+
var DISCLOSURE = [
|
|
1068
|
+
"What leaves this machine: the bounded text of each prompt, each native search query or URL (and, when one came back short, its status, size or error), each task handed to a subagent, and each question your assistant asks you with your answers, sent to Tenjin for the free routing gate, beside this session's id. When the gate offers free library docs for a search, that search query also goes to Tenjin's docs lookup, which asks Context7.",
|
|
1069
|
+
"What is kept when a lookup is paid: the capability chosen, a hash of the contract, a hash of the arguments, and your wallet address. No prompt text, no arguments, no hint text.",
|
|
1070
|
+
"What never leaves: your private key. It is decrypted in this CLI to sign, and never sent anywhere."
|
|
1071
|
+
];
|
|
1072
|
+
var RELOAD_STEP = "type /reload-plugins in this Claude Code session, or start a new session, so Tenjin loads";
|
|
1073
|
+
var NEW_SESSION_STEP = "start a new Claude Code session so Tenjin loads";
|
|
1074
|
+
function loadStep(settingsInstallPresent) {
|
|
1075
|
+
return settingsInstallPresent ? NEW_SESSION_STEP : RELOAD_STEP;
|
|
1076
|
+
}
|
|
1077
|
+
function settingsInstallPaths(project, env, home, cwd) {
|
|
1078
|
+
return project ? {
|
|
1079
|
+
settingsPath: join7(cwd, ".claude", "settings.json"),
|
|
1080
|
+
mcpFile: projectMcpFile(cwd),
|
|
1081
|
+
mcpScope: "project"
|
|
1082
|
+
} : {
|
|
1083
|
+
settingsPath: userSettingsPath(env, home),
|
|
1084
|
+
mcpFile: userMcpFile(env, home),
|
|
1085
|
+
mcpScope: "user"
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1088
|
+
async function pluginProof(claude, dataDir, env, cwd) {
|
|
1089
|
+
if (claude.binary !== null && !claude.meetsFloor) {
|
|
1090
|
+
return {
|
|
1091
|
+
proven: false,
|
|
1092
|
+
reason: `Claude Code ${claude.version ?? "(unknown)"} is older than the plugin needs`
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
if (claude.binary !== null) {
|
|
1096
|
+
const listing = await readPluginListing(claude.binary, env, cwd);
|
|
1097
|
+
if (!listing.enabled) {
|
|
1098
|
+
return { proven: false, reason: "Claude Code does not list the plugin as enabled yet" };
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
if (await readAliveStamp(dataDir) === null) {
|
|
1102
|
+
return {
|
|
1103
|
+
proven: false,
|
|
1104
|
+
reason: "the plugin has not loaded in a Claude Code session on this machine yet"
|
|
1105
|
+
};
|
|
1106
|
+
}
|
|
1107
|
+
return { proven: true };
|
|
1108
|
+
}
|
|
1109
|
+
async function migrateSettingsInstall(legacy, claude, opts) {
|
|
1110
|
+
if (!legacy.present) return { state: "none", settingsPath: legacy.settingsPath };
|
|
1111
|
+
const proof = await pluginProof(claude, opts.dataDir, opts.env, opts.cwd);
|
|
1112
|
+
if (!proof.proven) {
|
|
1113
|
+
return { state: "pending", settingsPath: legacy.settingsPath, reason: proof.reason };
|
|
1114
|
+
}
|
|
1115
|
+
const removed = await removeLegacyInstall(legacy, {
|
|
1116
|
+
binary: claude.binary,
|
|
1117
|
+
env: opts.env,
|
|
1118
|
+
cwd: opts.cwd,
|
|
1119
|
+
mcpScope: opts.mcpScope
|
|
1120
|
+
});
|
|
1121
|
+
return { state: "done", settingsPath: legacy.settingsPath, removed };
|
|
1122
|
+
}
|
|
1123
|
+
async function projectInstallHere(cwd, home, env) {
|
|
1124
|
+
if (await isHome(cwd, home)) return false;
|
|
1125
|
+
return projectInstallAt(cwd, home, env);
|
|
1126
|
+
}
|
|
1127
|
+
async function projectInstallAt(dir, home, env) {
|
|
1128
|
+
const local = await readFile4(join7(dir, ".claude", "settings.local.json"), "utf8").then((raw) => JSON.parse(raw)).catch(() => null);
|
|
1129
|
+
if (local?.enabledPlugins?.[PLUGIN_ID] === true) return true;
|
|
1130
|
+
if (await isHome(dir, home)) return false;
|
|
1131
|
+
if ((await folderState("local", env, home, dir)).state === "ours") return true;
|
|
1132
|
+
const paths = settingsInstallPaths(true, env, home, dir);
|
|
1133
|
+
return (await inspectLegacyInstall(paths.settingsPath, paths.mcpFile)).events.length > 0;
|
|
1134
|
+
}
|
|
1135
|
+
async function isHome(dir, home) {
|
|
1136
|
+
const [dirPath, homePath] = await Promise.all([
|
|
1137
|
+
realpath(dir).catch(() => dir),
|
|
1138
|
+
realpath(home).catch(() => home)
|
|
1139
|
+
]);
|
|
1140
|
+
return dirPath === homePath;
|
|
1141
|
+
}
|
|
1142
|
+
async function somethingToRefresh(claude, scope, legacy, env, home, cwd) {
|
|
1143
|
+
if (legacy.present) return true;
|
|
1144
|
+
if ((await folderState(scope, env, home, cwd)).state === "ours") return true;
|
|
1145
|
+
if (claude.binary !== null) {
|
|
1146
|
+
const listing = await readPluginListing(claude.binary, env, cwd);
|
|
1147
|
+
if (listing.id === PLUGIN_ID) return true;
|
|
1148
|
+
}
|
|
1149
|
+
return false;
|
|
1150
|
+
}
|
|
1151
|
+
async function runRouterInstall(args, ctx, deps = {}) {
|
|
1152
|
+
const env = deps.env ?? process.env;
|
|
1153
|
+
const home = deps.homeDir ?? homedir();
|
|
1154
|
+
if (!isAbsolute(home)) {
|
|
1155
|
+
throw new CliError("INTERNAL", "The home directory is not an absolute path.", {
|
|
1156
|
+
fix: "Set HOME to your home directory (`export HOME=...`), then re-run `tenjin install`."
|
|
1157
|
+
});
|
|
1158
|
+
}
|
|
1159
|
+
const config = await loadRawConfig(ctx.dataDir);
|
|
1160
|
+
const named = namedLimits(args);
|
|
1161
|
+
const cwd = deps.cwd ?? process.cwd();
|
|
1162
|
+
const project = args.project ?? (args.refresh === true && await projectInstallHere(cwd, home, env));
|
|
1163
|
+
const scope = project ? "local" : "user";
|
|
1164
|
+
const claude = await readClaudeCode(env, cwd, deps.findClaude ?? findClaudeBinary);
|
|
1165
|
+
const paths = settingsInstallPaths(project, env, home, cwd);
|
|
1166
|
+
const legacy = await inspectLegacyInstall(paths.settingsPath, paths.mcpFile);
|
|
1167
|
+
if (args.refresh === true && !await somethingToRefresh(claude, scope, legacy, env, home, cwd)) {
|
|
1168
|
+
throw new CliError(
|
|
1169
|
+
"REFUSED",
|
|
1170
|
+
`Nothing to refresh: neither the ${PLUGIN_ID} plugin nor a settings install of Tenjin is registered here.`,
|
|
1171
|
+
{ fix: "Run `tenjin install` to set this machine up." }
|
|
1172
|
+
);
|
|
1173
|
+
}
|
|
1174
|
+
const humanOutput = ctx.flags.json === true ? false : deps.isInteractive ?? ctx.io.isTTY;
|
|
1175
|
+
const canPrompt = humanOutput && (deps.isInteractive ?? Boolean(process.stdin.isTTY));
|
|
1176
|
+
const answered = args.yes === true || named.keys.length > 0;
|
|
1177
|
+
const unasked = config.maxAutoSpend === void 0 && config.sessionBudget === void 0;
|
|
1178
|
+
const limits = args.refresh === true ? void 0 : named.keys.length > 0 ? { ...shownLimits(config), ...named.limits } : args.yes === true ? shownLimits(config) : canPrompt && unasked ? await approveLimits(deps) : {};
|
|
1179
|
+
const spend = await persistRouterDefaults(ctx.dataDir, args.refresh === true, limits, named.keys);
|
|
1180
|
+
const removedKeysLines = spend.removed.length > 0 ? [
|
|
1181
|
+
`Removed retired settings: ${spend.removed.join(", ")}. Automatic router limits remain in effect; manual pay always requires consent.`
|
|
1182
|
+
] : [];
|
|
1183
|
+
const removedSkills = await removeRetiredSkills(home, project ? cwd : void 0);
|
|
1184
|
+
const plugin = !claude.meetsFloor && legacy.present ? deferredRegistration(scope, claude) : await registerPlugin({
|
|
1185
|
+
binary: claude.binary,
|
|
1186
|
+
scope,
|
|
1187
|
+
version: package_default.version,
|
|
1188
|
+
env,
|
|
1189
|
+
home,
|
|
1190
|
+
cwd,
|
|
1191
|
+
...deps.hostsDir !== void 0 ? { hostsDir: deps.hostsDir } : {},
|
|
1192
|
+
...deps.cliEntry !== void 0 ? { cliEntry: deps.cliEntry } : {}
|
|
1193
|
+
});
|
|
1194
|
+
if (project && plugin.state !== "failed") {
|
|
1195
|
+
await persistRouterProject(ctx.dataDir, cwd).catch(() => void 0);
|
|
1196
|
+
}
|
|
1197
|
+
const migration = legacy.unreadable !== void 0 && !legacy.present ? { state: "blocked", settingsPath: paths.settingsPath, reason: legacy.unreadable } : await migrateSettingsInstall(legacy, claude, {
|
|
1198
|
+
dataDir: ctx.dataDir,
|
|
1199
|
+
env,
|
|
1200
|
+
cwd,
|
|
1201
|
+
mcpScope: paths.mcpScope
|
|
1202
|
+
});
|
|
1203
|
+
const pending = settingsInstallStays(migration);
|
|
1204
|
+
const servers = await readMcpServers(deps, { settingsInstallPending: pending });
|
|
1205
|
+
const serverLines = servers.stale > 0 ? [paint(ctx.io, "yellow", `! ${servers.check.detail}. ${servers.check.fix ?? ""}`.trim())] : [];
|
|
1206
|
+
const claudeCode = claudeCodeData(claude);
|
|
1207
|
+
const notices = refreshNotices(plugin, claude, migration);
|
|
1208
|
+
if (args.refresh === true) {
|
|
1209
|
+
if (plugin.state === "failed" && migration.state !== "pending") {
|
|
1210
|
+
throw new CliError(
|
|
1211
|
+
"REFUSED",
|
|
1212
|
+
`The ${PLUGIN_ID} plugin could not be registered: ${plugin.reason ?? "unknown reason"}.`,
|
|
1213
|
+
{ fix: registrationFix(plugin), details: { plugin, claudeCode, migration } }
|
|
1214
|
+
);
|
|
1215
|
+
}
|
|
1216
|
+
return {
|
|
1217
|
+
data: {
|
|
1218
|
+
plugin,
|
|
1219
|
+
claudeCode,
|
|
1220
|
+
migration,
|
|
1221
|
+
notices,
|
|
1222
|
+
refresh: true,
|
|
1223
|
+
spend,
|
|
1224
|
+
removedSkills,
|
|
1225
|
+
scope,
|
|
1226
|
+
mcpServer: servers.check
|
|
1227
|
+
},
|
|
1228
|
+
humanLines: [
|
|
1229
|
+
...refreshLines(ctx, plugin, claude, migration),
|
|
1230
|
+
...removedKeysLines,
|
|
1231
|
+
...serverLines
|
|
1232
|
+
]
|
|
1233
|
+
};
|
|
1234
|
+
}
|
|
1235
|
+
const { resolveWallet } = await import("./install-wallet-XQ6XFZV4.js");
|
|
1236
|
+
const wallet = await resolveWallet(ctx, deps, args.noWallet === true ? "flag" : void 0, false);
|
|
1237
|
+
const effective = await resolveContextSettings(ctx);
|
|
1238
|
+
const spendAsk = !canPrompt && !answered && unasked ? spendStep(args) : void 0;
|
|
1239
|
+
const asksAgent = !canPrompt && underAgentHarness(env);
|
|
1240
|
+
const [router, fund] = await Promise.all([
|
|
1241
|
+
probeRouter(effective.baseUrl, {
|
|
1242
|
+
timeoutMs: ctx.flags.timeout,
|
|
1243
|
+
env,
|
|
1244
|
+
...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {}
|
|
1245
|
+
}),
|
|
1246
|
+
// The spend question comes first, because its answer picks the install
|
|
1247
|
+
// command. The funding question rides on the install that follows it.
|
|
1248
|
+
asksAgent && spendAsk === void 0 ? fundStep(wallet, effective.rpcUrl, deps) : Promise.resolve(void 0)
|
|
1249
|
+
]);
|
|
1250
|
+
const nextSteps = [
|
|
1251
|
+
...spendAsk !== void 0 ? [spendAsk] : [],
|
|
1252
|
+
...fund !== void 0 ? [fund] : []
|
|
1253
|
+
];
|
|
1254
|
+
const data = {
|
|
1255
|
+
plugin,
|
|
1256
|
+
claudeCode,
|
|
1257
|
+
migration,
|
|
1258
|
+
next: nextStep(plugin, claude, wallet, migration, asksAgent && nextSteps.length > 0),
|
|
1259
|
+
nextSteps,
|
|
1260
|
+
// The check for this scope, said outright; a bare doctor in the project
|
|
1261
|
+
// also finds it from what the project holds.
|
|
1262
|
+
...project ? { doctor: "tenjin doctor --project" } : {},
|
|
1263
|
+
spend: { ...spend, effective: effectiveLimits(effective.policy) },
|
|
1264
|
+
wallet,
|
|
1265
|
+
router: {
|
|
1266
|
+
status: router.status === "ok" ? "ok" : "warn",
|
|
1267
|
+
detail: router.detail,
|
|
1268
|
+
...router.fix !== void 0 ? { fix: router.fix } : {}
|
|
1269
|
+
},
|
|
1270
|
+
disclosure: DISCLOSURE,
|
|
1271
|
+
removedSkills,
|
|
1272
|
+
mcpServer: servers.check
|
|
1273
|
+
};
|
|
1274
|
+
return {
|
|
1275
|
+
data,
|
|
1276
|
+
humanLines: [
|
|
1277
|
+
...lines(ctx, {
|
|
1278
|
+
plugin,
|
|
1279
|
+
claude,
|
|
1280
|
+
migration,
|
|
1281
|
+
wallet,
|
|
1282
|
+
...fund !== void 0 ? { fund } : {},
|
|
1283
|
+
asks: asksAgent && nextSteps.length > 0,
|
|
1284
|
+
policy: effective.policy,
|
|
1285
|
+
...spendAsk !== void 0 ? { spendAsk } : {},
|
|
1286
|
+
router
|
|
1287
|
+
}),
|
|
1288
|
+
...removedKeysLines,
|
|
1289
|
+
...serverLines
|
|
1290
|
+
]
|
|
1291
|
+
};
|
|
1292
|
+
}
|
|
1293
|
+
function claudeCodeData(claude) {
|
|
1294
|
+
return {
|
|
1295
|
+
binary: claude.binary?.path ?? null,
|
|
1296
|
+
source: claude.binary?.source ?? null,
|
|
1297
|
+
version: claude.version,
|
|
1298
|
+
meetsFloor: claude.meetsFloor,
|
|
1299
|
+
...claude.fix !== void 0 ? { fix: claude.fix } : {}
|
|
1300
|
+
};
|
|
1301
|
+
}
|
|
1302
|
+
function registrationFix(plugin) {
|
|
1303
|
+
const flag = plugin.scope === "local" ? " --project" : "";
|
|
1304
|
+
if (plugin.id !== null && plugin.method === "none") {
|
|
1305
|
+
return `${plugin.id} keeps serving this machine at the version Claude Code has; run \`tenjin install${flag}\` again to retry.`;
|
|
1306
|
+
}
|
|
1307
|
+
if (plugin.path !== void 0 && plugin.reason?.includes("not a folder this CLI wrote") === true) {
|
|
1308
|
+
return `Move ${plugin.path} aside, then run \`tenjin install${flag}\` again.`;
|
|
1309
|
+
}
|
|
1310
|
+
return `Run \`tenjin doctor${flag}\` to see the cause, then run \`tenjin install${flag}\` again.`;
|
|
1311
|
+
}
|
|
1312
|
+
function nextStep(plugin, claude, wallet, migration, asksQuestion) {
|
|
1313
|
+
if (plugin.state === "failed") return registrationFix(plugin);
|
|
1314
|
+
const steps = [];
|
|
1315
|
+
if (asksQuestion) {
|
|
1316
|
+
steps.push("ask the person the question in nextSteps, then run what the answer names");
|
|
1317
|
+
} else if (wallet.status === "created") {
|
|
1318
|
+
steps.push("fund the wallet with `tenjin wallet fund`");
|
|
1319
|
+
}
|
|
1320
|
+
if (plugin.state === "deferred") {
|
|
1321
|
+
steps.unshift("run `claude update`");
|
|
1322
|
+
steps.push(
|
|
1323
|
+
"run `tenjin install` again; until then the earlier Tenjin setup keeps routing as before"
|
|
1324
|
+
);
|
|
1325
|
+
return steps.join(", then ");
|
|
1326
|
+
}
|
|
1327
|
+
if (!claude.meetsFloor) steps.unshift("run `claude update`");
|
|
1328
|
+
steps.push(loadStep(settingsInstallStays(migration)));
|
|
1329
|
+
return steps.join(", then ");
|
|
1330
|
+
}
|
|
1331
|
+
function settingsInstallStays(migration) {
|
|
1332
|
+
return migration.state === "pending" || migration.state === "blocked";
|
|
1333
|
+
}
|
|
1334
|
+
function deferredRegistration(scope, claude) {
|
|
1335
|
+
return {
|
|
1336
|
+
method: "none",
|
|
1337
|
+
id: null,
|
|
1338
|
+
scope,
|
|
1339
|
+
state: "deferred",
|
|
1340
|
+
version: package_default.version,
|
|
1341
|
+
steps: [],
|
|
1342
|
+
reason: `Claude Code ${claude.version ?? ""} is older than ${CLAUDE_CODE_FLOOR}, which the plugin needs, so it was not registered and the earlier settings setup keeps routing`
|
|
1343
|
+
};
|
|
1344
|
+
}
|
|
1345
|
+
function statusLineNotice(migration) {
|
|
1346
|
+
const status = migration.removed?.statusLine;
|
|
1347
|
+
if (status === "removed") {
|
|
1348
|
+
return "Removed the Tenjin status line (`tenjin status-line`) with the earlier settings setup; the plugin sets none. To keep it, set `tenjin status-line` as your Claude Code status line command.";
|
|
1349
|
+
}
|
|
1350
|
+
if (status === "restored") {
|
|
1351
|
+
return "Took the Tenjin footer out of your status line and put your own command back; the plugin sets none.";
|
|
1352
|
+
}
|
|
1353
|
+
return null;
|
|
1354
|
+
}
|
|
1355
|
+
function refreshNotices(plugin, claude, migration) {
|
|
1356
|
+
const out = [];
|
|
1357
|
+
if (plugin.state === "deferred") {
|
|
1358
|
+
out.push(
|
|
1359
|
+
`Claude Code ${claude.version ?? ""} is older than ${CLAUDE_CODE_FLOOR}, so the Tenjin plugin was not registered and the earlier settings setup keeps routing. Run \`claude update\`, then \`tenjin install\`.`
|
|
1360
|
+
);
|
|
1361
|
+
} else if (plugin.state !== "failed" && settingsInstallStays(migration)) {
|
|
1362
|
+
out.push(
|
|
1363
|
+
"Start a new Claude Code session so the Tenjin plugin loads; the earlier settings setup is removed by the next `tenjin update` or `tenjin install` after that."
|
|
1364
|
+
);
|
|
1365
|
+
}
|
|
1366
|
+
const status = statusLineNotice(migration);
|
|
1367
|
+
if (status !== null) out.push(status);
|
|
1368
|
+
return out;
|
|
1369
|
+
}
|
|
1370
|
+
var SHOW_NOT_RUN = "Show the person addresses as written, and never ask them to run a command.";
|
|
1371
|
+
function spendStep(args) {
|
|
1372
|
+
return spendStepFor(installCommand(args));
|
|
1373
|
+
}
|
|
1374
|
+
function spendStepFor(command) {
|
|
1375
|
+
const options = spendOptions(command);
|
|
1376
|
+
const [byDefault, custom] = options;
|
|
1377
|
+
return {
|
|
1378
|
+
id: "spend",
|
|
1379
|
+
question: spendChoiceQuestion(),
|
|
1380
|
+
options,
|
|
1381
|
+
next: `In this session, ask the person this question with your question tool, offering these two options in order with the defaults marked recommended. The defaults are already in effect. Use the defaults: run \`${byDefault.command}\`. Set my own limits: ask for the most per day in USD (or none for no daily limit) and the most per call in USD (at least 0.25), then run \`${custom.command}\` with their amounts. Run the command alone, never joined with another command, and do not ask again a question its output repeats. ${SHOW_NOT_RUN}`
|
|
1382
|
+
};
|
|
1383
|
+
}
|
|
1384
|
+
function installCommand(args) {
|
|
1385
|
+
return [
|
|
1386
|
+
"tenjin install",
|
|
1387
|
+
...args.project === true ? ["--project"] : [],
|
|
1388
|
+
...args.noWallet === true ? ["--no-wallet"] : []
|
|
1389
|
+
].join(" ");
|
|
1390
|
+
}
|
|
1391
|
+
function namedLimits(args) {
|
|
1392
|
+
const flags = [
|
|
1393
|
+
["maxAutoSpend", "--max-auto-spend", args.maxAutoSpend, "call"],
|
|
1394
|
+
["sessionBudget", "--session-budget", args.sessionBudget, "day"]
|
|
1395
|
+
];
|
|
1396
|
+
const limits = {};
|
|
1397
|
+
const keys = [];
|
|
1398
|
+
for (const [key, flag, raw, per] of flags) {
|
|
1399
|
+
if (raw === void 0) continue;
|
|
1400
|
+
if (args.refresh === true) {
|
|
1401
|
+
throw new CliError("USAGE", `${flag} sets a spend limit, and --refresh writes none.`, {
|
|
1402
|
+
fix: `Run \`tenjin install ${flag} ${raw}\` without --refresh.`
|
|
1403
|
+
});
|
|
1404
|
+
}
|
|
1405
|
+
const parsed = parseLimit(raw, per);
|
|
1406
|
+
if ("refusal" in parsed) {
|
|
1407
|
+
throw new CliError("USAGE", `${flag} ${raw}: ${parsed.refusal}`, {
|
|
1408
|
+
fix: per === "day" ? `Give a positive USD amount or none, for example \`${flag} 5\`.` : `Give 0.25 USD or more, for example \`${flag} 0.5\`. ${MAX_AUTO_SPEND_FLOOR_WHY}`
|
|
1409
|
+
});
|
|
1410
|
+
}
|
|
1411
|
+
limits[key] = parsed.value;
|
|
1412
|
+
keys.push(key);
|
|
1413
|
+
}
|
|
1414
|
+
return { limits, keys };
|
|
1415
|
+
}
|
|
1416
|
+
var FUND_QUESTION = `Do you want to add $${SUGGESTED_FUND_USD} to your Tenjin wallet now?`;
|
|
1417
|
+
var FUND_COMMAND = `tenjin wallet fund ${SUGGESTED_FUND_USD}`;
|
|
1418
|
+
async function fundStep(wallet, rpcUrl, deps) {
|
|
1419
|
+
const address = wallet.address;
|
|
1420
|
+
if (address === void 0 || wallet.status !== "created" && wallet.status !== "existing") {
|
|
1421
|
+
return void 0;
|
|
1422
|
+
}
|
|
1423
|
+
const funded = wallet.status === "created" ? false : await (deps.walletBalance ?? defaultBalance)(address, rpcUrl).then(
|
|
1424
|
+
(atomic) => atomic > 0n,
|
|
1425
|
+
() => null
|
|
1426
|
+
);
|
|
1427
|
+
if (funded === true) return void 0;
|
|
1428
|
+
const show = `To add funds, send USDC on Base to ${address}.`;
|
|
1429
|
+
return {
|
|
1430
|
+
id: "fund",
|
|
1431
|
+
question: FUND_QUESTION,
|
|
1432
|
+
options: [
|
|
1433
|
+
{
|
|
1434
|
+
id: "fund",
|
|
1435
|
+
label: "Yes, open the funding page",
|
|
1436
|
+
recommended: false,
|
|
1437
|
+
command: FUND_COMMAND
|
|
1438
|
+
},
|
|
1439
|
+
{ id: "later", label: "Not now", recommended: false, command: null }
|
|
1440
|
+
],
|
|
1441
|
+
next: `The install is done. Ask the person this question with your question tool. On "Yes, open the funding page", run \`${FUND_COMMAND}\` alone, in the same turn. On "Not now", run nothing and show the person this for later: ${show} Never run \`${FUND_COMMAND}\` without this yes. ${SHOW_NOT_RUN}`,
|
|
1442
|
+
address,
|
|
1443
|
+
show
|
|
1444
|
+
};
|
|
1445
|
+
}
|
|
1446
|
+
async function defaultBalance(address, rpcUrl) {
|
|
1447
|
+
const { getUsdcBalance } = await import("./usdc-OGOGEHV2.js");
|
|
1448
|
+
return getUsdcBalance(address, rpcUrl);
|
|
1449
|
+
}
|
|
1450
|
+
function fundLines(fund) {
|
|
1451
|
+
return [
|
|
1452
|
+
` Ask the person: ${fund.question}`,
|
|
1453
|
+
` Yes, open the funding page: ${FUND_COMMAND}`,
|
|
1454
|
+
` Not now: run nothing, show them: ${fund.show}`
|
|
1455
|
+
];
|
|
1456
|
+
}
|
|
1457
|
+
async function approveLimits(deps) {
|
|
1458
|
+
const choice = await (deps.promptLimits ?? promptLimits)(
|
|
1459
|
+
`${SPEND_QUESTION}
|
|
1460
|
+
${ROUTING_FEE_TERMS}
|
|
1461
|
+
${FEE_APPROVAL}`
|
|
1462
|
+
);
|
|
1463
|
+
if (choice === null) throw installCancelled();
|
|
1464
|
+
if (choice === "approve") return { ...ROUTER_DEFAULTS };
|
|
1465
|
+
const ask = deps.promptAmount ?? promptAmount;
|
|
1466
|
+
const sessionBudget = await askLimit(
|
|
1467
|
+
ask,
|
|
1468
|
+
"Most it may pay in a day, in USD, or none",
|
|
1469
|
+
"5",
|
|
1470
|
+
"day"
|
|
1471
|
+
);
|
|
1472
|
+
const maxAutoSpend = await askLimit(
|
|
1473
|
+
ask,
|
|
1474
|
+
"Most it may pay for one call, in USD, at least 0.25",
|
|
1475
|
+
"0.25",
|
|
1476
|
+
"call"
|
|
1477
|
+
);
|
|
1478
|
+
return { maxAutoSpend, sessionBudget };
|
|
1479
|
+
}
|
|
1480
|
+
async function askLimit(ask, question, placeholder, per) {
|
|
1481
|
+
let message = question;
|
|
1482
|
+
for (; ; ) {
|
|
1483
|
+
const answer = await ask(message, placeholder);
|
|
1484
|
+
if (answer === null) throw installCancelled();
|
|
1485
|
+
const parsed = parseLimit(answer, per);
|
|
1486
|
+
if (!("refusal" in parsed)) return parsed.value;
|
|
1487
|
+
message = `${parsed.refusal} ${question}`;
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
function parseLimit(answer, per) {
|
|
1491
|
+
const trimmed = answer.trim();
|
|
1492
|
+
if (per === "day" && trimmed === "none") return { value: "none" };
|
|
1493
|
+
let atomic;
|
|
1494
|
+
try {
|
|
1495
|
+
atomic = parseUsdToAtomic(trimmed);
|
|
1496
|
+
} catch (err) {
|
|
1497
|
+
if (err instanceof CliError) return { refusal: `${err.message}.` };
|
|
1498
|
+
throw err;
|
|
1499
|
+
}
|
|
1500
|
+
if (per === "call" && BigInt(atomic) < MAX_AUTO_SPEND_FLOOR_ATOMIC) {
|
|
1501
|
+
return { refusal: "The per-call limit is at least $0.25." };
|
|
1502
|
+
}
|
|
1503
|
+
if (atomic === "0") {
|
|
1504
|
+
return {
|
|
1505
|
+
refusal: "The limit must be more than zero; `tenjin config set router.enabled false` turns the router off."
|
|
1506
|
+
};
|
|
1507
|
+
}
|
|
1508
|
+
return { value: atomic };
|
|
1509
|
+
}
|
|
1510
|
+
function installCancelled() {
|
|
1511
|
+
return new CliError("REFUSED", "Install cancelled before anything was written.", {
|
|
1512
|
+
fix: "Re-run `tenjin install` and choose the defaults or your own limits."
|
|
1513
|
+
});
|
|
1514
|
+
}
|
|
1515
|
+
function promptLimits(message) {
|
|
1516
|
+
return selectOne({
|
|
1517
|
+
message,
|
|
1518
|
+
choices: [
|
|
1519
|
+
{ value: "approve", label: "Use the defaults" },
|
|
1520
|
+
{ value: "own", label: "Set my own limits" }
|
|
1521
|
+
],
|
|
1522
|
+
initialValue: "approve"
|
|
1523
|
+
});
|
|
1524
|
+
}
|
|
1525
|
+
function promptAmount(message, placeholder) {
|
|
1526
|
+
return askText({ message, placeholder });
|
|
1527
|
+
}
|
|
1528
|
+
function effectiveLimits(policy) {
|
|
1529
|
+
return {
|
|
1530
|
+
maxAutoSpend: toMoney(policy.maxAutoSpendAtomic.toString()).usd,
|
|
1531
|
+
sessionBudget: policy.sessionBudgetAtomic === null ? "no daily ceiling" : toMoney(policy.sessionBudgetAtomic.toString()).usd
|
|
1532
|
+
};
|
|
1533
|
+
}
|
|
1534
|
+
function walletLines(ctx, ok, w) {
|
|
1535
|
+
if (w.status === "created") return [`${ok} Wallet created: ${w.address}`];
|
|
1536
|
+
if (w.status === "existing") return [`${ok} Wallet: ${w.address}`];
|
|
1537
|
+
if (w.reason === "flag") return [" No wallet yet. Create one with: tenjin wallet create"];
|
|
1538
|
+
return [
|
|
1539
|
+
paint(ctx.io, "yellow", `! No wallet was created. ${w.warning ?? ""}`.trimEnd()),
|
|
1540
|
+
` ${w.fix ?? "Create one with: tenjin wallet create"}`
|
|
1541
|
+
];
|
|
1542
|
+
}
|
|
1543
|
+
function pluginLines(ctx, plugin) {
|
|
1544
|
+
const warn = (text) => paint(ctx.io, "yellow", `! ${text}`);
|
|
1545
|
+
if (plugin.state === "deferred") return [warn(`${plugin.reason ?? ""}`)];
|
|
1546
|
+
if (plugin.state === "failed") {
|
|
1547
|
+
return [warn(`The Tenjin plugin was not registered: ${plugin.reason ?? "unknown reason"}`)];
|
|
1548
|
+
}
|
|
1549
|
+
if (plugin.method === "skills-dir") {
|
|
1550
|
+
return [
|
|
1551
|
+
` Plugin ${plugin.id ?? ""} written to ${plugin.path ?? ""} (${plugin.fallbackReason ?? ""})`
|
|
1552
|
+
];
|
|
1553
|
+
}
|
|
1554
|
+
return [];
|
|
1555
|
+
}
|
|
1556
|
+
function migrationLines(ctx, migration) {
|
|
1557
|
+
const warn = (text) => paint(ctx.io, "yellow", `! ${text}`);
|
|
1558
|
+
if (migration.state === "pending") {
|
|
1559
|
+
return [
|
|
1560
|
+
` The settings install in ${migration.settingsPath} stays until the plugin has loaded (${migration.reason ?? ""}); \`tenjin update\` or \`tenjin install\` removes it then.`
|
|
1561
|
+
];
|
|
1562
|
+
}
|
|
1563
|
+
if (migration.state === "blocked") {
|
|
1564
|
+
return [warn(`${migration.settingsPath} could not be read: ${migration.reason ?? ""}`)];
|
|
1565
|
+
}
|
|
1566
|
+
if (migration.state === "done") {
|
|
1567
|
+
const removed = migration.removed;
|
|
1568
|
+
const status = statusLineNotice(migration);
|
|
1569
|
+
return [
|
|
1570
|
+
` Removed the earlier settings setup from ${migration.settingsPath}: the plugin carries its hooks, permissions and server`,
|
|
1571
|
+
...status !== null ? [` ${status}`] : [],
|
|
1572
|
+
...(removed?.warnings ?? []).map((w) => warn(w))
|
|
1573
|
+
];
|
|
1574
|
+
}
|
|
1575
|
+
return [];
|
|
1576
|
+
}
|
|
1577
|
+
function claudeLines(ctx, claude) {
|
|
1578
|
+
if (claude.meetsFloor) return [];
|
|
1579
|
+
return [
|
|
1580
|
+
paint(
|
|
1581
|
+
ctx.io,
|
|
1582
|
+
"yellow",
|
|
1583
|
+
`! Claude Code ${claude.version ?? ""} is older than the plugin needs. ${claude.fix ?? ""}`.trim()
|
|
1584
|
+
)
|
|
1585
|
+
];
|
|
1586
|
+
}
|
|
1587
|
+
function lines(ctx, s) {
|
|
1588
|
+
const ok = paint(ctx.io, "green", "\u2713");
|
|
1589
|
+
const warn = (text) => paint(ctx.io, "yellow", `! ${text}`);
|
|
1590
|
+
const limits = effectiveLimits(s.policy);
|
|
1591
|
+
const daily = s.policy.sessionBudgetAtomic === null ? "no daily limit" : `$${limits.sessionBudget} a day`;
|
|
1592
|
+
const spend = [
|
|
1593
|
+
` Automatic router: up to $${limits.maxAutoSpend} per call; daily limit ${daily}`,
|
|
1594
|
+
...s.spendAsk !== void 0 ? [
|
|
1595
|
+
` Ask the person in this session: ${s.spendAsk.question}`,
|
|
1596
|
+
...s.spendAsk.options.map(
|
|
1597
|
+
(o) => ` ${o.label}${o.recommended ? " (recommended)" : ""}: ${o.command}`
|
|
1598
|
+
)
|
|
1599
|
+
] : []
|
|
1600
|
+
];
|
|
1601
|
+
const router = s.router.status === "ok" ? [] : [
|
|
1602
|
+
warn(`The router did not answer: ${s.router.detail}`),
|
|
1603
|
+
...s.router.fix !== void 0 ? [` ${s.router.fix}`] : []
|
|
1604
|
+
];
|
|
1605
|
+
return [
|
|
1606
|
+
s.plugin.state === "failed" ? warn("Tenjin could not finish setting up Claude Code") : s.plugin.state === "deferred" ? warn("Tenjin keeps its earlier Claude Code setup until Claude Code is updated") : `${ok} Tenjin is set up for Claude Code (plugin ${s.plugin.id ?? PLUGIN_ID})`,
|
|
1607
|
+
...s.plugin.scope === "local" && s.plugin.state !== "failed" ? [" For this project only; check it with: tenjin doctor --project"] : [],
|
|
1608
|
+
...walletLines(ctx, ok, s.wallet),
|
|
1609
|
+
...spend,
|
|
1610
|
+
...s.fund !== void 0 ? fundLines(s.fund) : [],
|
|
1611
|
+
...pluginLines(ctx, s.plugin),
|
|
1612
|
+
...claudeLines(ctx, s.claude),
|
|
1613
|
+
...migrationLines(ctx, s.migration),
|
|
1614
|
+
...router,
|
|
1615
|
+
"",
|
|
1616
|
+
`Next: ${nextStep(s.plugin, s.claude, s.wallet, s.migration, s.asks)}`
|
|
1617
|
+
];
|
|
1618
|
+
}
|
|
1619
|
+
function refreshLines(ctx, plugin, claude, migration) {
|
|
1620
|
+
const issues = [
|
|
1621
|
+
...pluginLines(ctx, plugin),
|
|
1622
|
+
...claudeLines(ctx, claude),
|
|
1623
|
+
...migrationLines(ctx, migration)
|
|
1624
|
+
];
|
|
1625
|
+
const head = plugin.state === "failed" ? paint(ctx.io, "yellow", "! Tenjin is updated, but its plugin was not registered") : plugin.state === "deferred" ? paint(ctx.io, "yellow", "! Tenjin is updated; its plugin waits for a newer Claude Code") : `${paint(ctx.io, "green", "\u2713")} Tenjin is up to date (plugin ${plugin.id ?? PLUGIN_ID})`;
|
|
1626
|
+
return [head, ...issues];
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
// src/commands/update.ts
|
|
1630
|
+
var INSTALL_TIMEOUT_MS = 3e5;
|
|
1631
|
+
function resolveManager(manager, deps) {
|
|
1632
|
+
const script = deps.managerScript !== void 0 ? deps.managerScript : resolveManagerScript(manager, process.execPath);
|
|
1633
|
+
return script === null ? { cmd: MANAGERS[manager].bin, prefix: [] } : { cmd: process.execPath, prefix: [script] };
|
|
1634
|
+
}
|
|
1635
|
+
async function runUpdate(opts, ctx, deps = {}) {
|
|
1636
|
+
const current = deps.currentVersion ?? package_default.version;
|
|
1637
|
+
const channel = channelTag(current);
|
|
1638
|
+
const moduleDir = deps.moduleDir ?? fileURLToPath3(new URL(".", import.meta.url));
|
|
1639
|
+
if (channel === null) {
|
|
1640
|
+
throw new CliError("REFUSED", `tenjin-cli reports an unrecognizable version (${current})`, {
|
|
1641
|
+
fix: "Reinstall a published build: npm i -g tenjin-cli"
|
|
1642
|
+
});
|
|
1643
|
+
}
|
|
1644
|
+
refuse(moduleDir, { check: opts.check, spec: null });
|
|
1645
|
+
const tags = await fetchDistTags({
|
|
1646
|
+
fetchImpl: deps.fetchImpl,
|
|
1647
|
+
timeoutMs: ctx.flags.timeout
|
|
1648
|
+
});
|
|
1649
|
+
if (tags === null) {
|
|
1650
|
+
throw new CliError("NETWORK_ERROR", "Could not read tenjin-cli dist-tags from npm", {
|
|
1651
|
+
fix: "Check access to registry.npmjs.org and retry"
|
|
1652
|
+
});
|
|
1653
|
+
}
|
|
1654
|
+
const latest = resolveTarget(current, tags);
|
|
1655
|
+
if (latest === null) {
|
|
1656
|
+
const raw = tags[channel];
|
|
1657
|
+
throw raw === void 0 ? new CliError("RESOURCE_NOT_FOUND", "npm has no published tenjin-cli on the latest tag", {
|
|
1658
|
+
fix: "Pick a version yourself: npm view tenjin-cli versions"
|
|
1659
|
+
}) : new CliError(
|
|
1660
|
+
"RESOURCE_NOT_FOUND",
|
|
1661
|
+
// Registry-controlled: bounded here, escaped by the error emitter.
|
|
1662
|
+
`npm's latest tenjin-cli (${raw.slice(0, 40)}) is not a version this build can read`,
|
|
1663
|
+
{
|
|
1664
|
+
fix: "Install it by name: npm i -g tenjin-cli@<version> (npm view tenjin-cli versions)"
|
|
1665
|
+
}
|
|
1666
|
+
);
|
|
1667
|
+
}
|
|
1668
|
+
const updateAvailable = isNewer(latest, current);
|
|
1669
|
+
const data = (updated) => ({
|
|
1670
|
+
current,
|
|
1671
|
+
latest,
|
|
1672
|
+
updateAvailable,
|
|
1673
|
+
updated
|
|
1674
|
+
});
|
|
1675
|
+
if (!updateAvailable) {
|
|
1676
|
+
return {
|
|
1677
|
+
data: data(false),
|
|
1678
|
+
humanLines: [`tenjin-cli ${current} is up to date`]
|
|
1679
|
+
};
|
|
1680
|
+
}
|
|
1681
|
+
if (opts.check) {
|
|
1682
|
+
return {
|
|
1683
|
+
data: data(false),
|
|
1684
|
+
humanLines: [
|
|
1685
|
+
`tenjin-cli ${latest} is available (you have ${current}).`,
|
|
1686
|
+
"Run tenjin update to install it."
|
|
1687
|
+
]
|
|
1688
|
+
};
|
|
1689
|
+
}
|
|
1690
|
+
const spec = `tenjin-cli@${latest}`;
|
|
1691
|
+
refuse(moduleDir, { check: false, spec });
|
|
1692
|
+
const human = ctx.io.isTTY && !ctx.flags.json;
|
|
1693
|
+
let tail = "";
|
|
1694
|
+
const onOutput = (chunk) => {
|
|
1695
|
+
tail = (tail + chunk).slice(-2e3);
|
|
1696
|
+
if (human) ctx.io.stderr.write(chunk.split("\n").map(sanitizeForTerminal).join("\n"));
|
|
1697
|
+
};
|
|
1698
|
+
const manager = classifyManager(moduleDir);
|
|
1699
|
+
const plan = MANAGERS[manager];
|
|
1700
|
+
const args = plan.args(spec);
|
|
1701
|
+
const resolved = resolveManager(manager, deps);
|
|
1702
|
+
const manual = `Run it yourself: ${plan.manual(spec)}`;
|
|
1703
|
+
const outcome = await (deps.spawnImpl ?? spawnCapture)(
|
|
1704
|
+
resolved.cmd,
|
|
1705
|
+
[...resolved.prefix, ...args],
|
|
1706
|
+
{ cwd: homedir2(), timeoutMs: INSTALL_TIMEOUT_MS },
|
|
1707
|
+
onOutput
|
|
1708
|
+
);
|
|
1709
|
+
if (outcome.kind === "start-failed") {
|
|
1710
|
+
throw new CliError("UPDATE_FAILED", `Could not start ${manager}`, {
|
|
1711
|
+
fix: manual,
|
|
1712
|
+
cause: outcome.cause
|
|
1713
|
+
});
|
|
1714
|
+
}
|
|
1715
|
+
if (outcome.kind === "timeout") {
|
|
1716
|
+
throw new CliError(
|
|
1717
|
+
"UPDATE_FAILED",
|
|
1718
|
+
`${manager} did not finish in ${INSTALL_TIMEOUT_MS / 1e3}s`,
|
|
1719
|
+
{ fix: manual, details: { output: tail } }
|
|
1720
|
+
);
|
|
1721
|
+
}
|
|
1722
|
+
if (outcome.code !== 0) {
|
|
1723
|
+
throw new CliError("UPDATE_FAILED", `${manager} ${args.join(" ")} exited ${outcome.code}`, {
|
|
1724
|
+
// EACCES on a root-owned global prefix is the common cause; the operator
|
|
1725
|
+
// fixing that themselves beats this CLI ever escalating.
|
|
1726
|
+
fix: manual,
|
|
1727
|
+
details: { output: tail }
|
|
1728
|
+
});
|
|
1729
|
+
}
|
|
1730
|
+
emitWriteNotice(
|
|
1731
|
+
ctx.io,
|
|
1732
|
+
`tenjin update: replaced the global tenjin-cli with ${latest} via ${manager}`
|
|
1733
|
+
);
|
|
1734
|
+
const refresh = await refreshProfiles(ctx, deps);
|
|
1735
|
+
const servers = await readMcpServers(deps, {
|
|
1736
|
+
settingsInstallPending: refresh.settingsInstallPending
|
|
1737
|
+
});
|
|
1738
|
+
return {
|
|
1739
|
+
data: { ...data(true), refresh, mcpServer: servers.check },
|
|
1740
|
+
humanLines: [
|
|
1741
|
+
`Updated tenjin-cli ${current} -> ${latest}.`,
|
|
1742
|
+
...refreshLines2(refresh),
|
|
1743
|
+
...projectLines(refresh),
|
|
1744
|
+
...refresh.notices,
|
|
1745
|
+
...servers.stale > 0 ? [`! ${servers.check.detail}. ${servers.check.fix ?? ""}`.trim()] : []
|
|
1746
|
+
]
|
|
1747
|
+
};
|
|
1748
|
+
}
|
|
1749
|
+
var REFRESH_TIMEOUT_MS = 6e4;
|
|
1750
|
+
async function refreshProfiles(ctx, deps) {
|
|
1751
|
+
const home = deps.homeDir ?? homedir2();
|
|
1752
|
+
const candidates = [ctx.dataDir];
|
|
1753
|
+
const fixFor = (dataDir) => manualFix(dataDir, home, ctx.dataDir);
|
|
1754
|
+
const profiles = [];
|
|
1755
|
+
const unrun = [];
|
|
1756
|
+
for (const dataDir of candidates) {
|
|
1757
|
+
if (isExistingDir(dataDir)) profiles.push(dataDir);
|
|
1758
|
+
else unrun.push({ dataDir, reason: "It is not a directory.", fix: fixFor(dataDir) });
|
|
1759
|
+
}
|
|
1760
|
+
const entry = versionFreeEntry(deps.refreshCommand ?? process.argv[1]);
|
|
1761
|
+
if (entry === null) {
|
|
1762
|
+
const reason = "This build has no entry the update could safely re-execute.";
|
|
1763
|
+
return {
|
|
1764
|
+
profiles: [],
|
|
1765
|
+
failed: candidates.map((d) => ({ dataDir: d, reason, fix: fixFor(d) })),
|
|
1766
|
+
notices: [],
|
|
1767
|
+
settingsInstallPending: false,
|
|
1768
|
+
projects: [],
|
|
1769
|
+
projectsFailed: []
|
|
1770
|
+
};
|
|
1771
|
+
}
|
|
1772
|
+
const failed = [...unrun];
|
|
1773
|
+
const notices = [];
|
|
1774
|
+
let settingsInstallPending = false;
|
|
1775
|
+
const heard = (reported) => {
|
|
1776
|
+
for (const notice of noticesOf(reported)) if (!notices.includes(notice)) notices.push(notice);
|
|
1777
|
+
const migration = reported?.migration;
|
|
1778
|
+
if (migration?.state === "pending" || migration?.state === "blocked") {
|
|
1779
|
+
settingsInstallPending = true;
|
|
1780
|
+
}
|
|
1781
|
+
};
|
|
1782
|
+
for (const dataDir of profiles) {
|
|
1783
|
+
const { outcome, tail } = await refreshChild(entry, homedir2(), dataDir, deps);
|
|
1784
|
+
if (outcome.kind !== "exit" || outcome.code !== 0) {
|
|
1785
|
+
failed.push({ dataDir, reason: refreshReason(outcome, tail), fix: fixFor(dataDir) });
|
|
1786
|
+
continue;
|
|
1787
|
+
}
|
|
1788
|
+
heard(envelopeData(tail));
|
|
1789
|
+
}
|
|
1790
|
+
const projects = [];
|
|
1791
|
+
const projectsFailed = [];
|
|
1792
|
+
const recorded = profiles.includes(ctx.dataDir) ? (await loadRawConfig(ctx.dataDir).catch(() => null))?.install?.routerProjects ?? [] : [];
|
|
1793
|
+
for (const project of recorded) {
|
|
1794
|
+
const forget = () => persistRouterProject(ctx.dataDir, project, false).catch(() => void 0);
|
|
1795
|
+
if (!isExistingDir(project) || !await projectInstallAt(project, home, process.env)) {
|
|
1796
|
+
await forget();
|
|
1797
|
+
continue;
|
|
1798
|
+
}
|
|
1799
|
+
const { outcome, tail } = await refreshChild(entry, project, ctx.dataDir, deps, ["--project"]);
|
|
1800
|
+
if (outcome.kind !== "exit" || outcome.code !== 0) {
|
|
1801
|
+
projectsFailed.push({
|
|
1802
|
+
project,
|
|
1803
|
+
reason: refreshReason(outcome, tail),
|
|
1804
|
+
fix: `Run \`tenjin install --project\` in ${project}.`
|
|
1805
|
+
});
|
|
1806
|
+
continue;
|
|
1807
|
+
}
|
|
1808
|
+
projects.push(project);
|
|
1809
|
+
heard(envelopeData(tail));
|
|
1810
|
+
}
|
|
1811
|
+
return { profiles, failed, notices, settingsInstallPending, projects, projectsFailed };
|
|
1812
|
+
}
|
|
1813
|
+
async function refreshChild(entry, cwd, dataDir, deps, flags = []) {
|
|
1814
|
+
let tail = "";
|
|
1815
|
+
const outcome = await (deps.spawnImpl ?? spawnCapture)(
|
|
1816
|
+
process.execPath,
|
|
1817
|
+
[entry, "install", "--refresh", ...flags],
|
|
1818
|
+
{
|
|
1819
|
+
cwd,
|
|
1820
|
+
timeoutMs: REFRESH_TIMEOUT_MS,
|
|
1821
|
+
// TENJIN_DATA_DIR aims the child at this profile; the nudge opt-out is
|
|
1822
|
+
// what keeps it from touching any other file in there (lib/update-check).
|
|
1823
|
+
env: { TENJIN_DATA_DIR: dataDir, [NUDGE_OPT_OUT]: "1" }
|
|
1824
|
+
},
|
|
1825
|
+
(chunk) => {
|
|
1826
|
+
tail = (tail + chunk).slice(-REFRESH_TAIL_LIMIT);
|
|
1827
|
+
}
|
|
1828
|
+
);
|
|
1829
|
+
return { outcome, tail };
|
|
1830
|
+
}
|
|
1831
|
+
function envelopeData(output) {
|
|
1832
|
+
const lines2 = output.split("\n");
|
|
1833
|
+
for (let i = lines2.length - 1; i >= 0; i -= 1) {
|
|
1834
|
+
if (lines2[i]?.trim() !== "{" && !lines2[i]?.trim().startsWith('{"')) continue;
|
|
1835
|
+
try {
|
|
1836
|
+
const parsed = JSON.parse(lines2.slice(i).join("\n"));
|
|
1837
|
+
if (parsed?.ok === true && parsed.data !== null && typeof parsed.data === "object") {
|
|
1838
|
+
return parsed.data;
|
|
1839
|
+
}
|
|
1840
|
+
} catch {
|
|
1841
|
+
continue;
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
return null;
|
|
1845
|
+
}
|
|
1846
|
+
function noticesOf(data) {
|
|
1847
|
+
const raw = data?.notices;
|
|
1848
|
+
if (!Array.isArray(raw)) return [];
|
|
1849
|
+
return raw.filter((n) => typeof n === "string").map((n) => sanitizeForTerminal(n).trim().slice(0, REASON_LIMIT)).filter((n) => n.length > 0).slice(0, 5);
|
|
1850
|
+
}
|
|
1851
|
+
var REFRESH_TAIL_LIMIT = 64e3;
|
|
1852
|
+
var REASON_LIMIT = 300;
|
|
1853
|
+
function refreshReason(outcome, output) {
|
|
1854
|
+
const reported = envelopeMessage(output);
|
|
1855
|
+
if (reported !== void 0) return reported;
|
|
1856
|
+
if (outcome.kind === "timeout") return `It did not finish in ${REFRESH_TIMEOUT_MS / 1e3}s.`;
|
|
1857
|
+
if (outcome.kind === "start-failed") return "The refresh could not be started.";
|
|
1858
|
+
return `The refresh exited ${outcome.code} without reporting a reason.`;
|
|
1859
|
+
}
|
|
1860
|
+
function envelopeMessage(output) {
|
|
1861
|
+
const lines2 = output.split("\n");
|
|
1862
|
+
for (let i = lines2.length - 1; i >= 0; i -= 1) {
|
|
1863
|
+
const line = lines2[i]?.trim();
|
|
1864
|
+
if (line === void 0 || !line.startsWith("{")) continue;
|
|
1865
|
+
let parsed;
|
|
1866
|
+
try {
|
|
1867
|
+
parsed = JSON.parse(lines2.slice(i).join("\n"));
|
|
1868
|
+
} catch {
|
|
1869
|
+
continue;
|
|
1870
|
+
}
|
|
1871
|
+
if (parsed?.ok !== false || typeof parsed.error?.message !== "string") continue;
|
|
1872
|
+
const message = sanitizeForTerminal(parsed.error.message).trim();
|
|
1873
|
+
if (message.length > 0) return message.slice(0, REASON_LIMIT);
|
|
1874
|
+
}
|
|
1875
|
+
return void 0;
|
|
1876
|
+
}
|
|
1877
|
+
function isExistingDir(path) {
|
|
1878
|
+
return statSync2(path, { throwIfNoEntry: false })?.isDirectory() === true;
|
|
1879
|
+
}
|
|
1880
|
+
function manualFix(dataDir, home, invoking) {
|
|
1881
|
+
const bare = resolve(dataDir) === resolve(defaultDataDir(home)) && resolve(dataDir) === resolve(invoking);
|
|
1882
|
+
const command = bare ? "tenjin install" : `TENJIN_DATA_DIR=${dataDir} tenjin install`;
|
|
1883
|
+
return `Run \`${command}\` to bring the Claude Code plugin up to this version.`;
|
|
1884
|
+
}
|
|
1885
|
+
function versionFreeEntry(entry) {
|
|
1886
|
+
if (entry === void 0 || entry.length === 0) return null;
|
|
1887
|
+
const segs = entry.split(sep3);
|
|
1888
|
+
const store = segs.indexOf(".pnpm");
|
|
1889
|
+
if (store === -1) return segs.join(sep3);
|
|
1890
|
+
const inner = segs.indexOf("node_modules", store);
|
|
1891
|
+
if (inner === -1) return null;
|
|
1892
|
+
const derived = [...segs.slice(0, store), ...segs.slice(inner + 1)].join(sep3);
|
|
1893
|
+
return existsSync2(derived) ? derived : null;
|
|
1894
|
+
}
|
|
1895
|
+
function refreshLines2(refresh) {
|
|
1896
|
+
const failedDirs = new Set(refresh.failed.map((f) => f.dataDir));
|
|
1897
|
+
const done = refresh.profiles.filter((p) => !failedDirs.has(p));
|
|
1898
|
+
if (refresh.failed.length === 0) {
|
|
1899
|
+
return [
|
|
1900
|
+
done.length > 1 ? `Refreshed the Claude Code plugin for ${done.length} profiles: ${done.join(", ")}.` : `Refreshed the Claude Code plugin for ${done[0]}.`
|
|
1901
|
+
];
|
|
1902
|
+
}
|
|
1903
|
+
const total = done.length + refresh.failed.length;
|
|
1904
|
+
const lines2 = done.length > 0 ? [
|
|
1905
|
+
`Refreshed the Claude Code plugin for ${done.length} of ${total} profiles: ${done.join(", ")}.`
|
|
1906
|
+
] : [];
|
|
1907
|
+
lines2.push(`Could not refresh the Claude Code plugin for ${refresh.failed.length}:`);
|
|
1908
|
+
lines2.push(...refresh.failed.map((f) => `- ${f.dataDir}: ${f.reason} ${f.fix}`));
|
|
1909
|
+
return lines2;
|
|
1910
|
+
}
|
|
1911
|
+
function projectLines(refresh) {
|
|
1912
|
+
return [
|
|
1913
|
+
...refresh.projects.length > 0 ? [`Refreshed the project install in ${refresh.projects.join(", ")}.`] : [],
|
|
1914
|
+
...refresh.projectsFailed.length > 0 ? [
|
|
1915
|
+
`Could not refresh the project install in ${refresh.projectsFailed.length}:`,
|
|
1916
|
+
...refresh.projectsFailed.map((p) => `- ${p.project}: ${p.reason} ${p.fix}`)
|
|
1917
|
+
] : []
|
|
1918
|
+
];
|
|
1919
|
+
}
|
|
1920
|
+
var spawnCapture = (cmd, args, opts, onOutput) => new Promise((res) => {
|
|
1921
|
+
let child;
|
|
1922
|
+
try {
|
|
1923
|
+
child = spawn(cmd, args, {
|
|
1924
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
1925
|
+
cwd: opts.cwd,
|
|
1926
|
+
// Layered onto this process's environment rather than replacing it: the
|
|
1927
|
+
// child is a Node CLI that needs PATH and HOME, and only the keys named
|
|
1928
|
+
// here are being decided.
|
|
1929
|
+
...opts.env !== void 0 ? { env: { ...process.env, ...opts.env } } : {}
|
|
1930
|
+
});
|
|
1931
|
+
} catch (cause) {
|
|
1932
|
+
res({ kind: "start-failed", cause });
|
|
1933
|
+
return;
|
|
1934
|
+
}
|
|
1935
|
+
let timedOut = false;
|
|
1936
|
+
const timer = setTimeout(() => {
|
|
1937
|
+
timedOut = true;
|
|
1938
|
+
child.kill("SIGKILL");
|
|
1939
|
+
}, opts.timeoutMs);
|
|
1940
|
+
child.stdout?.on("data", (chunk) => onOutput(chunk.toString()));
|
|
1941
|
+
child.stderr?.on("data", (chunk) => onOutput(chunk.toString()));
|
|
1942
|
+
child.on("error", (cause) => {
|
|
1943
|
+
clearTimeout(timer);
|
|
1944
|
+
res({ kind: "start-failed", cause });
|
|
1945
|
+
});
|
|
1946
|
+
child.on("close", (code) => {
|
|
1947
|
+
clearTimeout(timer);
|
|
1948
|
+
res(timedOut ? { kind: "timeout" } : { kind: "exit", code: code ?? 1 });
|
|
1949
|
+
});
|
|
1950
|
+
});
|
|
1951
|
+
|
|
1952
|
+
export {
|
|
1953
|
+
inspectLegacyInstall,
|
|
1954
|
+
removeLegacyInstall,
|
|
1955
|
+
readMcpServers,
|
|
1956
|
+
runUpdate,
|
|
1957
|
+
versionFreeEntry,
|
|
1958
|
+
spawnCapture,
|
|
1959
|
+
removePluginFolder,
|
|
1960
|
+
folderFor,
|
|
1961
|
+
registerPlugin,
|
|
1962
|
+
ownMarketplace,
|
|
1963
|
+
packageHostsDir,
|
|
1964
|
+
packageMod,
|
|
1965
|
+
packageCliEntry,
|
|
1966
|
+
readPluginListing,
|
|
1967
|
+
folderState,
|
|
1968
|
+
probeRouter,
|
|
1969
|
+
DISCLOSURE,
|
|
1970
|
+
RELOAD_STEP,
|
|
1971
|
+
NEW_SESSION_STEP,
|
|
1972
|
+
loadStep,
|
|
1973
|
+
settingsInstallPaths,
|
|
1974
|
+
pluginProof,
|
|
1975
|
+
migrateSettingsInstall,
|
|
1976
|
+
projectInstallHere,
|
|
1977
|
+
projectInstallAt,
|
|
1978
|
+
runRouterInstall,
|
|
1979
|
+
SHOW_NOT_RUN,
|
|
1980
|
+
spendStepFor,
|
|
1981
|
+
namedLimits,
|
|
1982
|
+
FUND_QUESTION,
|
|
1983
|
+
FUND_COMMAND,
|
|
1984
|
+
approveLimits,
|
|
1985
|
+
effectiveLimits
|
|
1986
|
+
};
|
|
1987
|
+
//# sourceMappingURL=chunk-77TCKDEC.js.map
|