tenjin-cli 0.1.0-alpha.34 → 0.1.0-alpha.35
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 +30 -0
- package/README.md +20 -18
- package/dist/{_esm-MMYV66AX.js → _esm-2KST7HQ7.js} +4 -4
- package/dist/{alive-VOIL5W3I.js → alive-5TV22PNF.js} +13 -13
- package/dist/{auth-UHD3QFX4.js → auth-XI7BJFLW.js} +4 -4
- package/dist/balance-DFHC6XEU.js +71 -0
- package/dist/{ccip-CS7K5QRQ.js → ccip-HOW3DZYF.js} +3 -3
- package/dist/{chunk-RJ5HRPAZ.js → chunk-24XKUN2S.js} +68 -10
- package/dist/chunk-24XKUN2S.js.map +1 -0
- package/dist/chunk-2L7TDGLV.js +56 -0
- package/dist/chunk-2L7TDGLV.js.map +1 -0
- package/dist/{chunk-PZHBPGDE.js → chunk-34SAECKZ.js} +34 -10
- package/dist/chunk-34SAECKZ.js.map +1 -0
- package/dist/{chunk-EQZ2CCWC.js → chunk-3Y2EHT4F.js} +5 -2
- package/dist/chunk-3Y2EHT4F.js.map +1 -0
- package/dist/{chunk-FSYH7J75.js → chunk-3Y6BHIN6.js} +3 -3
- package/dist/{chunk-FZZWTDWP.js → chunk-3YPL6T3P.js} +6 -6
- package/dist/{chunk-JEZMWJEF.js → chunk-44MVIRZH.js} +4 -4
- package/dist/{chunk-27FIHFXF.js → chunk-45MMSBHA.js} +5 -5
- package/dist/{chunk-QXP3Z3JN.js → chunk-4MBCJFY4.js} +35 -3
- package/dist/chunk-4MBCJFY4.js.map +1 -0
- package/dist/chunk-4TPL54KW.js +227 -0
- package/dist/chunk-4TPL54KW.js.map +1 -0
- package/dist/{chunk-7JB6SYJX.js → chunk-54ELBTKE.js} +2 -2
- package/dist/{chunk-6J64MQFD.js → chunk-5F4OB5B3.js} +21 -15
- package/dist/chunk-5F4OB5B3.js.map +1 -0
- package/dist/{chunk-PYVQ74D5.js → chunk-5HN4KVQU.js} +189 -117
- package/dist/chunk-5HN4KVQU.js.map +1 -0
- package/dist/{chunk-VFKPIIV2.js → chunk-5J4E5GYI.js} +35 -32
- package/dist/chunk-5J4E5GYI.js.map +1 -0
- package/dist/chunk-5USBZ2MU.js +58 -0
- package/dist/chunk-5USBZ2MU.js.map +1 -0
- package/dist/chunk-64WOMNYR.js +183 -0
- package/dist/chunk-64WOMNYR.js.map +1 -0
- package/dist/{chunk-APWELUI7.js → chunk-65RS4LQS.js} +57 -43
- package/dist/chunk-65RS4LQS.js.map +1 -0
- package/dist/{chunk-HWZO6HYZ.js → chunk-6QMDUDF2.js} +3 -3
- package/dist/{chunk-FNBGRKS6.js → chunk-7V25UAQO.js} +2 -2
- package/dist/chunk-BGA4DO5M.js +719 -0
- package/dist/chunk-BGA4DO5M.js.map +1 -0
- package/dist/chunk-BVP7YK2J.js +706 -0
- package/dist/chunk-BVP7YK2J.js.map +1 -0
- package/dist/chunk-C265QIMJ.js +83 -0
- package/dist/chunk-C265QIMJ.js.map +1 -0
- package/dist/{chunk-MXN2ZEUB.js → chunk-D6M3ZK66.js} +2 -2
- package/dist/chunk-D6M3ZK66.js.map +1 -0
- package/dist/chunk-DJ36BM62.js +78 -0
- package/dist/chunk-DJ36BM62.js.map +1 -0
- package/dist/{chunk-JOKPBYXP.js → chunk-DTEWAVNE.js} +2 -2
- package/dist/chunk-F2KJAJ7T.js +13 -0
- package/dist/chunk-F2KJAJ7T.js.map +1 -0
- package/dist/{chunk-KAILF7QA.js → chunk-F43CV6UC.js} +2 -2
- package/dist/{chunk-ACO7ZCR2.js → chunk-FKVJKLPI.js} +2 -2
- package/dist/{chunk-43HLS2HM.js → chunk-FYFHH7V5.js} +54 -3
- package/dist/{chunk-43HLS2HM.js.map → chunk-FYFHH7V5.js.map} +1 -1
- package/dist/{chunk-2F5JUAHZ.js → chunk-GAJC4BQZ.js} +3 -3
- package/dist/{chunk-L7N73ZAW.js → chunk-HAZAN4UM.js} +2 -2
- package/dist/{chunk-6QJZA6EX.js → chunk-HI5XQOX2.js} +2 -2
- package/dist/{chunk-BOENA6XR.js → chunk-HKGUKAQW.js} +6 -6
- package/dist/{chunk-LJSCGIYH.js → chunk-HPRVFJPM.js} +2 -2
- package/dist/{chunk-OO6FIBL7.js → chunk-HZKANST2.js} +3 -6
- package/dist/chunk-HZKANST2.js.map +1 -0
- package/dist/{chunk-UVDJ5SSQ.js → chunk-I557SAOM.js} +8 -2
- package/dist/chunk-I557SAOM.js.map +1 -0
- package/dist/{chunk-SDUOJRSV.js → chunk-IGLWLH73.js} +3 -3
- package/dist/{chunk-3AKH7ODX.js → chunk-INSIW65E.js} +5 -5
- package/dist/{chunk-PNHNXUSL.js → chunk-IULCDMVG.js} +12 -1
- package/dist/chunk-IULCDMVG.js.map +1 -0
- package/dist/{chunk-JF4T4HCQ.js → chunk-IVNSUAVC.js} +10 -5
- package/dist/chunk-IVNSUAVC.js.map +1 -0
- package/dist/chunk-JDQZCREI.js +87 -0
- package/dist/chunk-JDQZCREI.js.map +1 -0
- package/dist/{chunk-2P3NJTHE.js → chunk-JHFFUVON.js} +23 -23
- package/dist/{chunk-7JVARP5R.js → chunk-JTILUN4W.js} +55 -29
- package/dist/{chunk-7JVARP5R.js.map → chunk-JTILUN4W.js.map} +1 -1
- package/dist/{chunk-2TO5F6CT.js → chunk-K5KNGC4I.js} +8 -8
- package/dist/{chunk-HUWTFKEM.js → chunk-KAQ4Q3TO.js} +3 -3
- package/dist/{chunk-E6VP6MQM.js → chunk-KGUE5AVX.js} +4 -4
- package/dist/chunk-KGUE5AVX.js.map +1 -0
- package/dist/{chunk-GS5RZF7U.js → chunk-KLDMLWXT.js} +2 -2
- package/dist/{chunk-HN2EN6P4.js → chunk-KNKDMTHU.js} +5 -5
- package/dist/chunk-LDA6TAYQ.js +95 -0
- package/dist/chunk-LDA6TAYQ.js.map +1 -0
- package/dist/chunk-LWSSIZOY.js +347 -0
- package/dist/chunk-LWSSIZOY.js.map +1 -0
- package/dist/{chunk-5VWQSCDO.js → chunk-MAHNZA6C.js} +89 -9
- package/dist/chunk-MAHNZA6C.js.map +1 -0
- package/dist/{chunk-46HAB26L.js → chunk-MEWZCIA6.js} +56 -9
- package/dist/chunk-MEWZCIA6.js.map +1 -0
- package/dist/{chunk-R2KMLONN.js → chunk-MJDO4EXD.js} +4 -4
- package/dist/{chunk-IHVUE3XF.js → chunk-NJA6NT3A.js} +3 -3
- package/dist/{chunk-TSIID2LV.js → chunk-ODRPASFP.js} +375 -1166
- package/dist/chunk-ODRPASFP.js.map +1 -0
- package/dist/{chunk-S3JKF3IK.js → chunk-OJJFANO6.js} +3 -3
- package/dist/{chunk-56SOPRM2.js → chunk-OQWPRFAC.js} +344 -4
- package/dist/chunk-OQWPRFAC.js.map +1 -0
- package/dist/{chunk-QEZZDIQT.js → chunk-P6YQWIT2.js} +4053 -4039
- package/dist/chunk-P6YQWIT2.js.map +1 -0
- package/dist/{chunk-GGGEGMWC.js → chunk-Q6RSJCXB.js} +9 -9
- package/dist/{chunk-OTIUEUIS.js → chunk-QKEUKBRK.js} +7 -7
- package/dist/{chunk-X52BVGCJ.js → chunk-QQDPRTLP.js} +5 -5
- package/dist/chunk-QQYCYAKI.js +79 -0
- package/dist/chunk-QQYCYAKI.js.map +1 -0
- package/dist/chunk-R4KDH477.js +1064 -0
- package/dist/chunk-R4KDH477.js.map +1 -0
- package/dist/{chunk-6AQSUBNR.js → chunk-RGCPELQN.js} +2 -2
- package/dist/{chunk-AXODGQ23.js → chunk-RGVCOG2S.js} +9 -2
- package/dist/{chunk-AXODGQ23.js.map → chunk-RGVCOG2S.js.map} +1 -1
- package/dist/chunk-SOLNJ3AZ.js +209 -0
- package/dist/chunk-SOLNJ3AZ.js.map +1 -0
- package/dist/{chunk-LQ33RLHL.js → chunk-TFT2X7SH.js} +3 -3
- package/dist/chunk-TVWCLUBI.js +293 -0
- package/dist/chunk-TVWCLUBI.js.map +1 -0
- package/dist/{chunk-VH7JMLTG.js → chunk-UIB33QQP.js} +25 -16
- package/dist/chunk-UIB33QQP.js.map +1 -0
- package/dist/chunk-V6GIVALQ.js +1889 -0
- package/dist/chunk-V6GIVALQ.js.map +1 -0
- package/dist/{chunk-IVHGQNIN.js → chunk-VHXCPXUS.js} +8 -8
- package/dist/{chunk-7DW7GAM6.js → chunk-VU6GMWF6.js} +2 -2
- package/dist/chunk-VWZYE3NC.js +8415 -0
- package/dist/chunk-VWZYE3NC.js.map +1 -0
- package/dist/{chunk-3X4GOMXT.js → chunk-W2GXIARJ.js} +12 -7
- package/dist/chunk-W2GXIARJ.js.map +1 -0
- package/dist/chunk-W4G3K3V7.js +288 -0
- package/dist/chunk-W4G3K3V7.js.map +1 -0
- package/dist/{chunk-FHXTEVO7.js → chunk-W74LJ5OT.js} +21 -28
- package/dist/chunk-W74LJ5OT.js.map +1 -0
- package/dist/{chunk-FOEPH67T.js → chunk-W7ELYLYK.js} +1 -74
- package/dist/chunk-W7ELYLYK.js.map +1 -0
- package/dist/{chunk-YU3DLVSQ.js → chunk-XSCGUO2U.js} +5 -5
- package/dist/{chunk-EPCIJLLU.js → chunk-XWROSMI5.js} +9 -9
- package/dist/{chunk-HMT6L65V.js → chunk-YJGEVBKZ.js} +4 -4
- package/dist/{chunk-7U3P4PB7.js → chunk-ZEYA2WWX.js} +4 -4
- package/dist/chunk-ZEYA2WWX.js.map +1 -0
- package/dist/chunk-ZRC7Z5X3.js +82 -0
- package/dist/chunk-ZRC7Z5X3.js.map +1 -0
- package/dist/{chunk-I47ARU5G.js → chunk-ZS7JIUJ3.js} +2 -2
- package/dist/{claude-cli-2YKABJJZ.js → claude-cli-GIIHOBGT.js} +4 -2
- package/dist/claude-install-BAUSJMW3.js +64 -0
- package/dist/{cli-BFDKEX53.js → cli-QY4KKA3D.js} +116 -49
- package/dist/cli-QY4KKA3D.js.map +1 -0
- package/dist/{client-XMWEKXX7.js → client-3YQKORVK.js} +4 -4
- package/dist/{codex-host-B6NAUWL6.js → codex-host-ZON3S6HU.js} +5 -5
- package/dist/{codex-install-GTGO5FYN.js → codex-install-HZV2DOAB.js} +62 -47
- package/dist/codex-install-HZV2DOAB.js.map +1 -0
- package/dist/{config-THJANIU5.js → config-QZOBMTEL.js} +18 -18
- package/dist/{config-names-JU54HYWY.js → config-names-Z5NZD5R2.js} +18 -18
- package/dist/{config-rules-VNU23RL4.js → config-rules-YOYHS6YL.js} +19 -19
- package/dist/config-subagents-WQV2ZAD5.js +362 -0
- package/dist/config-subagents-WQV2ZAD5.js.map +1 -0
- package/dist/{connect-HPWS7U63.js → connect-YDWTYU4B.js} +28 -27
- package/dist/{connect-HPWS7U63.js.map → connect-YDWTYU4B.js.map} +1 -1
- package/dist/core-0a66n3e7-TTP554XV.js +127 -0
- package/dist/core-0a66n3e7-TTP554XV.js.map +1 -0
- package/dist/core-0bmnpbz2-C2JIRVZO.js +10790 -0
- package/dist/core-0bmnpbz2-C2JIRVZO.js.map +1 -0
- package/dist/core-9je8ee1j-74DGHWPV.js +30 -0
- package/dist/core-9je8ee1j-74DGHWPV.js.map +1 -0
- package/dist/core-wadgcjfh-TSZFQZGH.js +666 -0
- package/dist/core-wadgcjfh-TSZFQZGH.js.map +1 -0
- package/dist/core-zg882d22-LKV5DZYW.js +37 -0
- package/dist/core-zg882d22-LKV5DZYW.js.map +1 -0
- package/dist/{decision-JIIHDTOF.js → decision-QSKHOGCO.js} +6 -6
- package/dist/{doctor-4MMHBRDU.js → doctor-ZWJXRD75.js} +67 -66
- package/dist/doctor-ZWJXRD75.js.map +1 -0
- package/dist/{explicit-AGENAX6E.js → explicit-ME2NRADQ.js} +45 -42
- package/dist/{explicit-AGENAX6E.js.map → explicit-ME2NRADQ.js.map} +1 -1
- package/dist/flush-stdio-NYIJ3QXT.js +18 -0
- package/dist/{fund-MLXUH24Q.js → fund-VF7TLDJH.js} +110 -34
- package/dist/fund-VF7TLDJH.js.map +1 -0
- package/dist/{hook-command-UB7FOEUL.js → hook-command-VZ27MGWO.js} +21 -20
- package/dist/hosts/claude/.claude-plugin/marketplace.json +2 -2
- package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +2 -2
- package/dist/hosts/claude/tenjin/hooks/hook-data.ts +152 -0
- package/dist/hosts/claude/tenjin/hooks/hooks.json +7 -0
- package/dist/hosts/claude/tenjin/hooks/model-viewer.tsx +2987 -0
- package/dist/hosts/claude/tenjin/hooks/register.tsx +265 -30
- package/dist/hosts/claude/tenjin/skills/tenjin-pay/SKILL.md +14 -4
- package/dist/hosts/claude/tenjin/types/index.d.ts +133 -0
- package/dist/{hosts-WNQKYKP2.js → hosts-3EMTVM4H.js} +5 -3
- package/dist/index.js +16 -13
- package/dist/index.js.map +1 -1
- package/dist/{install-Q5SHHEDH.js → install-ZA7L2UF3.js} +34 -30
- package/dist/{install-funding-EGSW2KEP.js → install-funding-JDGYTF72.js} +9 -13
- package/dist/{install-identity-OID43B4D.js → install-identity-FFAYEFLX.js} +8 -8
- package/dist/{install-wallet-TZFWY5GK.js → install-wallet-2SFOVE3Q.js} +48 -33
- package/dist/{install-wallet-TZFWY5GK.js.map → install-wallet-2SFOVE3Q.js.map} +1 -1
- package/dist/mcp-36S6MK3C.js +67642 -0
- package/dist/mcp-36S6MK3C.js.map +1 -0
- package/dist/new-install-5L4GY3LN.js +51 -0
- package/dist/{package-NRHU7HBR.js → package-BONDXSV3.js} +2 -2
- package/dist/{passphrase-3JEVW5XG.js → passphrase-T4ULBN4M.js} +4 -4
- package/dist/{pay-I47AIUQR.js → pay-CMV5KL74.js} +37 -30
- package/dist/{payments-A5FNI5GN.js → payments-Z6UBZL4Z.js} +10 -10
- package/dist/reclaim-subagent-credit-ABSF67SJ.js +105 -0
- package/dist/reclaim-subagent-credit-ABSF67SJ.js.map +1 -0
- package/dist/{routing-quote-QQW2I5MH.js → routing-quote-AHLAREXR.js} +16 -18
- package/dist/{run-4SHEOBIU.js → run-JH7ELYAM.js} +41 -38
- package/dist/{runtime-BABJMHY7.js → runtime-2GX4ALJP.js} +12 -12
- package/dist/{runtime-activate-N6VLQI2C.js → runtime-activate-IDQ2NCSP.js} +9 -9
- package/dist/{runtime-launchers-GMAUICRW.js → runtime-launchers-YAPKCBHV.js} +7 -7
- package/dist/{runtime-place-DOEWFTF3.js → runtime-place-4POL4KK4.js} +3 -3
- package/dist/{send-ECXS6JEO.js → send-ELXFKEKY.js} +17 -17
- package/dist/{status-AHE5HSR7.js → status-FXUFWJDM.js} +89 -36
- package/dist/status-FXUFWJDM.js.map +1 -0
- package/dist/{status-line-63XFJAXR.js → status-line-IH5JBWBC.js} +11 -11
- package/dist/{streamableHttp-Z3YF6LTQ.js → streamableHttp-CP2ZQBIK.js} +4 -4
- package/dist/{uninstall-YGQPRCVY.js → uninstall-LJZUKM4D.js} +42 -38
- package/dist/{uninstall-YGQPRCVY.js.map → uninstall-LJZUKM4D.js.map} +1 -1
- package/dist/{update-GTLMLFA3.js → update-EUIX72IX.js} +34 -30
- package/dist/{usage-FCWP2CHO.js → usage-EKDC7LUC.js} +13 -13
- package/dist/{usdc-25RNBYYR.js → usdc-YIHK2OMC.js} +5 -5
- package/dist/{viemAdapter-By13KInL-3CG63XDX.js → viemAdapter-By13KInL-PRLSIESK.js} +2 -2
- package/dist/viemAdapter-By13KInL-PRLSIESK.js.map +1 -0
- package/dist/wallet-HSW757W6.js +80 -0
- package/dist/wallet-HSW757W6.js.map +1 -0
- package/docs/agent-permissions.md +19 -11
- package/docs/router-reference.md +21 -12
- package/docs/safety-model.md +4 -2
- package/docs/subagents-internals.md +97 -0
- package/docs/subagents.md +348 -0
- package/package.json +4 -1
- package/dist/balance-RQW5T5FB.js +0 -55
- package/dist/chunk-3X4GOMXT.js.map +0 -1
- package/dist/chunk-46HAB26L.js.map +0 -1
- package/dist/chunk-56SOPRM2.js.map +0 -1
- package/dist/chunk-5VWQSCDO.js.map +0 -1
- package/dist/chunk-6J64MQFD.js.map +0 -1
- package/dist/chunk-7U3P4PB7.js.map +0 -1
- package/dist/chunk-APWELUI7.js.map +0 -1
- package/dist/chunk-E6VP6MQM.js.map +0 -1
- package/dist/chunk-EQZ2CCWC.js.map +0 -1
- package/dist/chunk-FHXTEVO7.js.map +0 -1
- package/dist/chunk-FOEPH67T.js.map +0 -1
- package/dist/chunk-IVXPIIZJ.js +0 -91
- package/dist/chunk-IVXPIIZJ.js.map +0 -1
- package/dist/chunk-JF4T4HCQ.js.map +0 -1
- package/dist/chunk-LPQNZKSG.js +0 -269
- package/dist/chunk-LPQNZKSG.js.map +0 -1
- package/dist/chunk-MXN2ZEUB.js.map +0 -1
- package/dist/chunk-OO6FIBL7.js.map +0 -1
- package/dist/chunk-PNHNXUSL.js.map +0 -1
- package/dist/chunk-PYVQ74D5.js.map +0 -1
- package/dist/chunk-PZHBPGDE.js.map +0 -1
- package/dist/chunk-QEZZDIQT.js.map +0 -1
- package/dist/chunk-QXP3Z3JN.js.map +0 -1
- package/dist/chunk-RJ5HRPAZ.js.map +0 -1
- package/dist/chunk-TSIID2LV.js.map +0 -1
- package/dist/chunk-UVDJ5SSQ.js.map +0 -1
- package/dist/chunk-VFKPIIV2.js.map +0 -1
- package/dist/chunk-VH7JMLTG.js.map +0 -1
- package/dist/claude-install-7CVYQ73E.js +0 -60
- package/dist/cli-BFDKEX53.js.map +0 -1
- package/dist/codex-install-GTGO5FYN.js.map +0 -1
- package/dist/doctor-4MMHBRDU.js.map +0 -1
- package/dist/fund-MLXUH24Q.js.map +0 -1
- package/dist/mcp-CC3H7LFO.js +0 -3655
- package/dist/mcp-CC3H7LFO.js.map +0 -1
- package/dist/status-AHE5HSR7.js.map +0 -1
- package/dist/wallet-CJGEHP2Q.js +0 -64
- /package/dist/{_esm-MMYV66AX.js.map → _esm-2KST7HQ7.js.map} +0 -0
- /package/dist/{alive-VOIL5W3I.js.map → alive-5TV22PNF.js.map} +0 -0
- /package/dist/{auth-UHD3QFX4.js.map → auth-XI7BJFLW.js.map} +0 -0
- /package/dist/{balance-RQW5T5FB.js.map → balance-DFHC6XEU.js.map} +0 -0
- /package/dist/{ccip-CS7K5QRQ.js.map → ccip-HOW3DZYF.js.map} +0 -0
- /package/dist/{chunk-FSYH7J75.js.map → chunk-3Y6BHIN6.js.map} +0 -0
- /package/dist/{chunk-FZZWTDWP.js.map → chunk-3YPL6T3P.js.map} +0 -0
- /package/dist/{chunk-JEZMWJEF.js.map → chunk-44MVIRZH.js.map} +0 -0
- /package/dist/{chunk-27FIHFXF.js.map → chunk-45MMSBHA.js.map} +0 -0
- /package/dist/{chunk-7JB6SYJX.js.map → chunk-54ELBTKE.js.map} +0 -0
- /package/dist/{chunk-HWZO6HYZ.js.map → chunk-6QMDUDF2.js.map} +0 -0
- /package/dist/{chunk-FNBGRKS6.js.map → chunk-7V25UAQO.js.map} +0 -0
- /package/dist/{chunk-JOKPBYXP.js.map → chunk-DTEWAVNE.js.map} +0 -0
- /package/dist/{chunk-KAILF7QA.js.map → chunk-F43CV6UC.js.map} +0 -0
- /package/dist/{chunk-ACO7ZCR2.js.map → chunk-FKVJKLPI.js.map} +0 -0
- /package/dist/{chunk-2F5JUAHZ.js.map → chunk-GAJC4BQZ.js.map} +0 -0
- /package/dist/{chunk-L7N73ZAW.js.map → chunk-HAZAN4UM.js.map} +0 -0
- /package/dist/{chunk-6QJZA6EX.js.map → chunk-HI5XQOX2.js.map} +0 -0
- /package/dist/{chunk-BOENA6XR.js.map → chunk-HKGUKAQW.js.map} +0 -0
- /package/dist/{chunk-LJSCGIYH.js.map → chunk-HPRVFJPM.js.map} +0 -0
- /package/dist/{chunk-SDUOJRSV.js.map → chunk-IGLWLH73.js.map} +0 -0
- /package/dist/{chunk-3AKH7ODX.js.map → chunk-INSIW65E.js.map} +0 -0
- /package/dist/{chunk-2P3NJTHE.js.map → chunk-JHFFUVON.js.map} +0 -0
- /package/dist/{chunk-2TO5F6CT.js.map → chunk-K5KNGC4I.js.map} +0 -0
- /package/dist/{chunk-HUWTFKEM.js.map → chunk-KAQ4Q3TO.js.map} +0 -0
- /package/dist/{chunk-GS5RZF7U.js.map → chunk-KLDMLWXT.js.map} +0 -0
- /package/dist/{chunk-HN2EN6P4.js.map → chunk-KNKDMTHU.js.map} +0 -0
- /package/dist/{chunk-R2KMLONN.js.map → chunk-MJDO4EXD.js.map} +0 -0
- /package/dist/{chunk-IHVUE3XF.js.map → chunk-NJA6NT3A.js.map} +0 -0
- /package/dist/{chunk-S3JKF3IK.js.map → chunk-OJJFANO6.js.map} +0 -0
- /package/dist/{chunk-GGGEGMWC.js.map → chunk-Q6RSJCXB.js.map} +0 -0
- /package/dist/{chunk-OTIUEUIS.js.map → chunk-QKEUKBRK.js.map} +0 -0
- /package/dist/{chunk-X52BVGCJ.js.map → chunk-QQDPRTLP.js.map} +0 -0
- /package/dist/{chunk-6AQSUBNR.js.map → chunk-RGCPELQN.js.map} +0 -0
- /package/dist/{chunk-LQ33RLHL.js.map → chunk-TFT2X7SH.js.map} +0 -0
- /package/dist/{chunk-IVHGQNIN.js.map → chunk-VHXCPXUS.js.map} +0 -0
- /package/dist/{chunk-7DW7GAM6.js.map → chunk-VU6GMWF6.js.map} +0 -0
- /package/dist/{chunk-YU3DLVSQ.js.map → chunk-XSCGUO2U.js.map} +0 -0
- /package/dist/{chunk-EPCIJLLU.js.map → chunk-XWROSMI5.js.map} +0 -0
- /package/dist/{chunk-HMT6L65V.js.map → chunk-YJGEVBKZ.js.map} +0 -0
- /package/dist/{chunk-I47ARU5G.js.map → chunk-ZS7JIUJ3.js.map} +0 -0
- /package/dist/{claude-cli-2YKABJJZ.js.map → claude-cli-GIIHOBGT.js.map} +0 -0
- /package/dist/{claude-install-7CVYQ73E.js.map → claude-install-BAUSJMW3.js.map} +0 -0
- /package/dist/{client-XMWEKXX7.js.map → client-3YQKORVK.js.map} +0 -0
- /package/dist/{codex-host-B6NAUWL6.js.map → codex-host-ZON3S6HU.js.map} +0 -0
- /package/dist/{config-THJANIU5.js.map → config-QZOBMTEL.js.map} +0 -0
- /package/dist/{config-names-JU54HYWY.js.map → config-names-Z5NZD5R2.js.map} +0 -0
- /package/dist/{config-rules-VNU23RL4.js.map → config-rules-YOYHS6YL.js.map} +0 -0
- /package/dist/{decision-JIIHDTOF.js.map → decision-QSKHOGCO.js.map} +0 -0
- /package/dist/{hook-command-UB7FOEUL.js.map → flush-stdio-NYIJ3QXT.js.map} +0 -0
- /package/dist/{hosts-WNQKYKP2.js.map → hook-command-VZ27MGWO.js.map} +0 -0
- /package/dist/{install-Q5SHHEDH.js.map → hosts-3EMTVM4H.js.map} +0 -0
- /package/dist/{install-funding-EGSW2KEP.js.map → install-ZA7L2UF3.js.map} +0 -0
- /package/dist/{install-identity-OID43B4D.js.map → install-funding-JDGYTF72.js.map} +0 -0
- /package/dist/{package-NRHU7HBR.js.map → install-identity-FFAYEFLX.js.map} +0 -0
- /package/dist/{passphrase-3JEVW5XG.js.map → new-install-5L4GY3LN.js.map} +0 -0
- /package/dist/{pay-I47AIUQR.js.map → package-BONDXSV3.js.map} +0 -0
- /package/dist/{routing-quote-QQW2I5MH.js.map → passphrase-T4ULBN4M.js.map} +0 -0
- /package/dist/{run-4SHEOBIU.js.map → pay-CMV5KL74.js.map} +0 -0
- /package/dist/{payments-A5FNI5GN.js.map → payments-Z6UBZL4Z.js.map} +0 -0
- /package/dist/{runtime-activate-N6VLQI2C.js.map → routing-quote-AHLAREXR.js.map} +0 -0
- /package/dist/{runtime-launchers-GMAUICRW.js.map → run-JH7ELYAM.js.map} +0 -0
- /package/dist/{runtime-BABJMHY7.js.map → runtime-2GX4ALJP.js.map} +0 -0
- /package/dist/{runtime-place-DOEWFTF3.js.map → runtime-activate-IDQ2NCSP.js.map} +0 -0
- /package/dist/{update-GTLMLFA3.js.map → runtime-launchers-YAPKCBHV.js.map} +0 -0
- /package/dist/{usdc-25RNBYYR.js.map → runtime-place-4POL4KK4.js.map} +0 -0
- /package/dist/{send-ECXS6JEO.js.map → send-ELXFKEKY.js.map} +0 -0
- /package/dist/{status-line-63XFJAXR.js.map → status-line-IH5JBWBC.js.map} +0 -0
- /package/dist/{streamableHttp-Z3YF6LTQ.js.map → streamableHttp-CP2ZQBIK.js.map} +0 -0
- /package/dist/{viemAdapter-By13KInL-3CG63XDX.js.map → update-EUIX72IX.js.map} +0 -0
- /package/dist/{usage-FCWP2CHO.js.map → usage-EKDC7LUC.js.map} +0 -0
- /package/dist/{wallet-CJGEHP2Q.js.map → usdc-YIHK2OMC.js.map} +0 -0
|
@@ -2,96 +2,98 @@ import { createRequire as __tenjinCreateRequire } from 'node:module'; const requ
|
|
|
2
2
|
import {
|
|
3
3
|
openInBrowser
|
|
4
4
|
} from "./chunk-U4TRWSVE.js";
|
|
5
|
-
import {
|
|
6
|
-
SIWX_CHAIN_ID,
|
|
7
|
-
SIWX_HEADER,
|
|
8
|
-
buildSiwxHeader
|
|
9
|
-
} from "./chunk-56SOPRM2.js";
|
|
10
5
|
import {
|
|
11
6
|
underAgentHarness
|
|
12
7
|
} from "./chunk-WXA3WTPF.js";
|
|
13
|
-
import "./chunk-YWWMISDY.js";
|
|
14
8
|
import {
|
|
15
9
|
addressQrLines,
|
|
16
10
|
textQrLines
|
|
17
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-VU6GMWF6.js";
|
|
12
|
+
import {
|
|
13
|
+
liveLine
|
|
14
|
+
} from "./chunk-DJ36BM62.js";
|
|
18
15
|
import {
|
|
19
16
|
LINK_LIFETIME_MS,
|
|
20
17
|
STATUS_GRACE_MS,
|
|
21
18
|
dollars,
|
|
22
19
|
forgetLink,
|
|
23
20
|
inFlight,
|
|
24
|
-
liveLine,
|
|
25
21
|
readLinkStatus,
|
|
26
22
|
recallLink,
|
|
27
23
|
rememberLink,
|
|
28
24
|
tokenExpiry,
|
|
29
25
|
tokenOf,
|
|
30
26
|
watchFunding
|
|
31
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-W7ELYLYK.js";
|
|
28
|
+
import {
|
|
29
|
+
SIWX_CHAIN_ID,
|
|
30
|
+
SIWX_HEADER,
|
|
31
|
+
buildSiwxHeader
|
|
32
|
+
} from "./chunk-OQWPRFAC.js";
|
|
32
33
|
import {
|
|
33
34
|
describeWallet,
|
|
34
35
|
resolveWalletProvider
|
|
35
|
-
} from "./chunk-
|
|
36
|
-
import "./chunk-
|
|
37
|
-
import "./chunk-
|
|
38
|
-
import "./chunk-
|
|
36
|
+
} from "./chunk-K5KNGC4I.js";
|
|
37
|
+
import "./chunk-FYFHH7V5.js";
|
|
38
|
+
import "./chunk-HPRVFJPM.js";
|
|
39
|
+
import "./chunk-RGVCOG2S.js";
|
|
40
|
+
import "./chunk-FKVJKLPI.js";
|
|
41
|
+
import "./chunk-YWWMISDY.js";
|
|
42
|
+
import "./chunk-JNUKLSMZ.js";
|
|
43
|
+
import "./chunk-HI5XQOX2.js";
|
|
39
44
|
import "./chunk-XRGFH7FI.js";
|
|
40
|
-
import "./chunk-AXODGQ23.js";
|
|
41
45
|
import {
|
|
42
46
|
getUsdcBalance
|
|
43
|
-
} from "./chunk-
|
|
44
|
-
import "./chunk-
|
|
47
|
+
} from "./chunk-IGLWLH73.js";
|
|
48
|
+
import "./chunk-7V25UAQO.js";
|
|
45
49
|
import "./chunk-PETQ5WEA.js";
|
|
46
50
|
import {
|
|
47
51
|
getAddress,
|
|
48
52
|
isAddress
|
|
49
|
-
} from "./chunk-
|
|
50
|
-
import "./chunk-RBJPAZFI.js";
|
|
51
|
-
import "./chunk-ACO7ZCR2.js";
|
|
52
|
-
import "./chunk-JNUKLSMZ.js";
|
|
53
|
+
} from "./chunk-INSIW65E.js";
|
|
53
54
|
import "./chunk-CZJOMUBP.js";
|
|
55
|
+
import "./chunk-RBJPAZFI.js";
|
|
54
56
|
import "./chunk-WFZX352D.js";
|
|
55
|
-
import "./chunk-
|
|
57
|
+
import "./chunk-ZS7JIUJ3.js";
|
|
56
58
|
import "./chunk-JWAK7JQB.js";
|
|
57
59
|
import "./chunk-2W4DQQUU.js";
|
|
58
60
|
import {
|
|
59
61
|
emitWriteNotice,
|
|
60
62
|
paint,
|
|
61
63
|
style
|
|
62
|
-
} from "./chunk-
|
|
64
|
+
} from "./chunk-KLDMLWXT.js";
|
|
63
65
|
import {
|
|
64
66
|
SUGGESTED_FUND_USD
|
|
65
|
-
} from "./chunk-
|
|
67
|
+
} from "./chunk-HZKANST2.js";
|
|
66
68
|
import {
|
|
67
69
|
toMoney
|
|
68
70
|
} from "./chunk-MEZJ3I63.js";
|
|
69
71
|
import "./chunk-RFZA7PSM.js";
|
|
70
72
|
import "./chunk-JUUBBBY5.js";
|
|
71
|
-
import "./chunk-7WEQQJLG.js";
|
|
72
73
|
import {
|
|
73
74
|
loadRawConfig,
|
|
74
75
|
resolveSettings
|
|
75
|
-
} from "./chunk-
|
|
76
|
-
import "./chunk-
|
|
76
|
+
} from "./chunk-UIB33QQP.js";
|
|
77
|
+
import "./chunk-7WEQQJLG.js";
|
|
77
78
|
import "./chunk-ZCT5DJ3G.js";
|
|
79
|
+
import "./chunk-3MZ7DYRO.js";
|
|
78
80
|
import "./chunk-JTX3BUDK.js";
|
|
79
|
-
import "./chunk-
|
|
81
|
+
import "./chunk-ZEYA2WWX.js";
|
|
80
82
|
import "./chunk-DIH2G3YG.js";
|
|
81
83
|
import {
|
|
82
84
|
fetchFailureToCliError,
|
|
83
85
|
httpRequest
|
|
84
|
-
} from "./chunk-
|
|
85
|
-
import "./chunk-
|
|
86
|
+
} from "./chunk-D6M3ZK66.js";
|
|
87
|
+
import "./chunk-RGCPELQN.js";
|
|
86
88
|
import {
|
|
87
89
|
PRODUCTION_ORIGIN
|
|
88
90
|
} from "./chunk-CRG54LEB.js";
|
|
89
91
|
import "./chunk-TUCKEEXE.js";
|
|
90
|
-
import "./chunk-
|
|
92
|
+
import "./chunk-P6YQWIT2.js";
|
|
91
93
|
import {
|
|
92
94
|
CliError
|
|
93
95
|
} from "./chunk-DI4QAGRZ.js";
|
|
94
|
-
import "./chunk-
|
|
96
|
+
import "./chunk-3Y2EHT4F.js";
|
|
95
97
|
import "./chunk-ZXTAQYNA.js";
|
|
96
98
|
|
|
97
99
|
// src/lib/device-name.ts
|
|
@@ -139,6 +141,73 @@ function macComputerName() {
|
|
|
139
141
|
});
|
|
140
142
|
}
|
|
141
143
|
|
|
144
|
+
// src/lib/machine-id.ts
|
|
145
|
+
import { execFile as execFile2 } from "node:child_process";
|
|
146
|
+
import { createHash } from "node:crypto";
|
|
147
|
+
import { readFile } from "node:fs/promises";
|
|
148
|
+
import { win32 } from "node:path";
|
|
149
|
+
var HASH_PREFIX = "tenjin-promo-machine-v1:";
|
|
150
|
+
var READ_TIMEOUT_MS = 1500;
|
|
151
|
+
var IOREG = "/usr/sbin/ioreg";
|
|
152
|
+
var LINUX_ID_FILES = ["/etc/machine-id", "/var/lib/dbus/machine-id"];
|
|
153
|
+
var PLAUSIBLE_ID = /^[0-9a-f-]{16,64}$/;
|
|
154
|
+
async function machineHash(deps = {}) {
|
|
155
|
+
try {
|
|
156
|
+
const raw = await rawMachineId(deps);
|
|
157
|
+
if (raw === void 0) return void 0;
|
|
158
|
+
return createHash("sha256").update(`${HASH_PREFIX}${raw}`).digest("hex");
|
|
159
|
+
} catch {
|
|
160
|
+
return void 0;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
async function rawMachineId(deps) {
|
|
164
|
+
const platform = deps.platform ?? process.platform;
|
|
165
|
+
if (platform === "darwin") {
|
|
166
|
+
const out = await run(deps, IOREG, ["-rd1", "-c", "IOPlatformExpertDevice"]);
|
|
167
|
+
return plausible(/"IOPlatformUUID"\s*=\s*"([^"]+)"/.exec(out ?? "")?.[1]);
|
|
168
|
+
}
|
|
169
|
+
if (platform === "linux") {
|
|
170
|
+
const read = deps.readFileImpl ?? ((path) => readFile(path, "utf8"));
|
|
171
|
+
for (const path of LINUX_ID_FILES) {
|
|
172
|
+
const id = plausible(await read(path).catch(() => void 0));
|
|
173
|
+
if (id !== void 0) return id;
|
|
174
|
+
}
|
|
175
|
+
return void 0;
|
|
176
|
+
}
|
|
177
|
+
if (platform === "win32") {
|
|
178
|
+
const root = (deps.env ?? process.env).SystemRoot ?? "C:\\Windows";
|
|
179
|
+
const out = await run(deps, win32.join(root, "System32", "reg.exe"), [
|
|
180
|
+
"query",
|
|
181
|
+
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography",
|
|
182
|
+
"/v",
|
|
183
|
+
"MachineGuid",
|
|
184
|
+
"/reg:64"
|
|
185
|
+
]);
|
|
186
|
+
return plausible(/^\s*MachineGuid\s+REG_SZ\s+(\S+)\s*$/im.exec(out ?? "")?.[1]);
|
|
187
|
+
}
|
|
188
|
+
return void 0;
|
|
189
|
+
}
|
|
190
|
+
function plausible(raw) {
|
|
191
|
+
const id = raw?.trim().toLowerCase();
|
|
192
|
+
if (id === void 0 || !PLAUSIBLE_ID.test(id)) return void 0;
|
|
193
|
+
return /[1-9a-f]/.test(id) ? id : void 0;
|
|
194
|
+
}
|
|
195
|
+
function run(deps, cmd, args) {
|
|
196
|
+
const exec = deps.execFileImpl ?? execFile2;
|
|
197
|
+
return new Promise((resolve) => {
|
|
198
|
+
try {
|
|
199
|
+
exec(
|
|
200
|
+
cmd,
|
|
201
|
+
args,
|
|
202
|
+
{ timeout: READ_TIMEOUT_MS, windowsHide: true, encoding: "utf8" },
|
|
203
|
+
(err, stdout) => resolve(err === null ? String(stdout) : void 0)
|
|
204
|
+
);
|
|
205
|
+
} catch {
|
|
206
|
+
resolve(void 0);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
|
|
142
211
|
// src/commands/fund.ts
|
|
143
212
|
var COINBASE_CHECKOUT_HOST = "pay.coinbase.com";
|
|
144
213
|
var HOSTED_LIFETIME_MS = 5 * 6e4;
|
|
@@ -188,11 +257,16 @@ async function runFund(ctx, opts = {}) {
|
|
|
188
257
|
let signer;
|
|
189
258
|
const mint = async () => {
|
|
190
259
|
signer ??= await provider.getSigner();
|
|
260
|
+
const [deviceName2, machineHash2] = await Promise.all([
|
|
261
|
+
(opts.deviceName ?? deviceName)().catch(() => void 0),
|
|
262
|
+
(opts.machineHash ?? machineHash)().catch(() => void 0)
|
|
263
|
+
]);
|
|
191
264
|
const url = await mintLink(ctx, signer, address, {
|
|
192
265
|
...preset !== void 0 ? { presetAmount: preset } : {},
|
|
193
266
|
...need !== void 0 ? { need } : {},
|
|
194
267
|
source,
|
|
195
|
-
deviceName:
|
|
268
|
+
deviceName: deviceName2,
|
|
269
|
+
machineHash: machineHash2,
|
|
196
270
|
...opts.fetchImpl !== void 0 ? { fetchImpl: opts.fetchImpl } : {}
|
|
197
271
|
});
|
|
198
272
|
const token = tokenOf(url);
|
|
@@ -465,12 +539,14 @@ async function mintLink(ctx, signer, address, extra) {
|
|
|
465
539
|
method: "POST",
|
|
466
540
|
timeoutMs: ctx.flags.timeout,
|
|
467
541
|
headers: { [SIWX_HEADER]: siwxHeader },
|
|
468
|
-
// `deviceName`, `source` and `need` are display context for the page
|
|
542
|
+
// `deviceName`, `source` and `need` are display context for the page, and
|
|
543
|
+
// `machineHash` is for its "Have a code?" box's one-per-computer check. A
|
|
469
544
|
// server without them ignores them (its body schema is not strict).
|
|
470
545
|
jsonBody: {
|
|
471
546
|
address,
|
|
472
547
|
...extra.presetAmount !== void 0 ? { presetAmount: extra.presetAmount } : {},
|
|
473
548
|
...extra.deviceName !== void 0 ? { deviceName: extra.deviceName } : {},
|
|
549
|
+
...extra.machineHash !== void 0 ? { machineHash: extra.machineHash } : {},
|
|
474
550
|
source: extra.source,
|
|
475
551
|
...extra.need !== void 0 ? { need: extra.need } : {}
|
|
476
552
|
}
|
|
@@ -643,4 +719,4 @@ export {
|
|
|
643
719
|
parseNeed,
|
|
644
720
|
runFund
|
|
645
721
|
};
|
|
646
|
-
//# sourceMappingURL=fund-
|
|
722
|
+
//# sourceMappingURL=fund-VF7TLDJH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/device-name.ts","../src/lib/machine-id.ts","../src/commands/fund.ts"],"sourcesContent":["import { execFile } from 'node:child_process';\nimport { hostname } from 'node:os';\n\n/**\n * THIS COMPUTER'S NAME, for the fund page to show (\"Tenjin on Ada's MacBook\n * Pro\"), so a person paying can see which machine the link is for. Display\n * only: the server signs it into the link and stores nothing.\n *\n * macOS asks `scutil --get ComputerName`, the name System Settings shows,\n * because `os.hostname()` there is the network name (`adas-mbp.local`).\n * Windows and Linux report the hostname, which is often one the machine made\n * up (`DESKTOP-7F3K2LQ`, `ip-172-31-5-10`, a container id): those read as noise\n * on a payment page, so they are left out and the page says just \"tenjin\". A\n * trailing `.local` is dropped, controls and anything past 64 characters are\n * cut, and nothing here ever throws: a fund link never fails over its label.\n */\n\n/** Hostnames a machine or a cloud gives itself, never a name a person chose. */\nconst GENERATED_HOSTNAME = [\n /^(desktop|laptop|win)-[a-z0-9]{5,}$/i, // Windows' default names\n /^ip-\\d{1,3}-\\d{1,3}-\\d{1,3}-\\d{1,3}\\b/i, // AWS\n /^[0-9a-f]{12}([0-9a-f]{52})?$/i, // a Docker container id\n /^codespaces-[0-9a-z]+$/i, // GitHub Codespaces\n /^(localhost|\\d{1,3}(\\.\\d{1,3}){3})(\\.localdomain)?$/i,\n];\n\nconst MAX_DEVICE_NAME = 64;\nconst SCUTIL = '/usr/sbin/scutil';\nconst SCUTIL_TIMEOUT_MS = 1_000;\n\nexport interface DeviceNameDeps {\n platform?: NodeJS.Platform;\n /** `scutil --get ComputerName`'s output, or null when it failed. */\n computerName?: () => Promise<string | null>;\n hostname?: () => string;\n}\n\nexport async function deviceName(deps: DeviceNameDeps = {}): Promise<string | undefined> {\n try {\n const platform = deps.platform ?? process.platform;\n const fromMac = platform === 'darwin' ? await (deps.computerName ?? macComputerName)() : null;\n const named = clean(fromMac ?? '');\n if (named !== undefined) return named;\n const host = clean((deps.hostname ?? hostname)());\n return host !== undefined && GENERATED_HOSTNAME.some((re) => re.test(host)) ? undefined : host;\n } catch {\n return undefined;\n }\n}\n\n/** Printable, trimmed, without `.local`, at most 64 characters; undefined when nothing is left. */\nexport function clean(raw: string): string | undefined {\n const printable = raw\n // eslint-disable-next-line no-control-regex\n .replace(/[\\x00-\\x1f\\x7f-\\x9f\\u061c\\u200e\\u200f\\u202a-\\u202e\\u2066-\\u2069\\ufeff]/g, '')\n .trim()\n .replace(/\\.local$/i, '')\n .trim();\n const capped = [...printable].slice(0, MAX_DEVICE_NAME).join('').trim();\n return capped.length > 0 ? capped : undefined;\n}\n\nfunction macComputerName(): Promise<string | null> {\n return new Promise((resolve) => {\n execFile(\n SCUTIL,\n ['--get', 'ComputerName'],\n { timeout: SCUTIL_TIMEOUT_MS, windowsHide: true },\n (err, stdout) => resolve(err === null ? String(stdout) : null),\n );\n });\n}\n","import { execFile } from 'node:child_process';\nimport { createHash } from 'node:crypto';\nimport { readFile } from 'node:fs/promises';\nimport { win32 } from 'node:path';\n\n/**\n * A HASH THAT NAMES THIS COMPUTER, for the one-per-computer check on event\n * codes in the fund page's \"Have a code?\" box. `tenjin fund` signs it into the\n * link. The server\n * sees only the hash: the operating system's own machine ID never leaves this\n * module, and the prefix keeps the hash from matching any other product's\n * hash of the same ID.\n *\n * Hand-rolled rather than `node-machine-id`, which is unmaintained and runs\n * its commands through `execSync` strings. Here, as in `open-url.ts` and\n * `device-name.ts`, each read is an absolute binary with an argv array, never\n * a shell, under a hard timeout, and any failure is `undefined`, never a throw:\n * a code that needs no per-computer check still redeems without it.\n *\n * - macOS: `IOPlatformUUID` from `ioreg`, the hardware UUID.\n * - Linux: `/etc/machine-id`, else `/var/lib/dbus/machine-id`.\n * - Windows: `MachineGuid` under `HKLM\\SOFTWARE\\Microsoft\\Cryptography`, read\n * from the 64-bit registry view so a 32-bit Node reads the same key.\n */\n\n/** Changing it lets every computer that already redeemed a code redeem it again. */\nconst HASH_PREFIX = 'tenjin-promo-machine-v1:';\nconst READ_TIMEOUT_MS = 1_500;\nconst IOREG = '/usr/sbin/ioreg';\nconst LINUX_ID_FILES = ['/etc/machine-id', '/var/lib/dbus/machine-id'] as const;\n/**\n * What a machine ID looks like on all three: hex, as a UUID or bare. Anything\n * else (systemd's `uninitialized` placeholder, an empty file) is no ID.\n */\nconst PLAUSIBLE_ID = /^[0-9a-f-]{16,64}$/;\n\nexport interface MachineIdDeps {\n platform?: NodeJS.Platform;\n execFileImpl?: typeof execFile;\n readFileImpl?: (path: string) => Promise<string>;\n /** For `%SystemRoot%` on Windows. */\n env?: NodeJS.ProcessEnv;\n}\n\n/** sha256 hex of the prefix and this computer's ID, or undefined when it cannot be read. */\nexport async function machineHash(deps: MachineIdDeps = {}): Promise<string | undefined> {\n try {\n const raw = await rawMachineId(deps);\n if (raw === undefined) return undefined;\n return createHash('sha256').update(`${HASH_PREFIX}${raw}`).digest('hex');\n } catch {\n return undefined;\n }\n}\n\n/** The ID itself, lowercased and trimmed; module-private so it cannot be sent anywhere. */\nasync function rawMachineId(deps: MachineIdDeps): Promise<string | undefined> {\n const platform = deps.platform ?? process.platform;\n if (platform === 'darwin') {\n const out = await run(deps, IOREG, ['-rd1', '-c', 'IOPlatformExpertDevice']);\n return plausible(/\"IOPlatformUUID\"\\s*=\\s*\"([^\"]+)\"/.exec(out ?? '')?.[1]);\n }\n if (platform === 'linux') {\n const read = deps.readFileImpl ?? ((path: string) => readFile(path, 'utf8'));\n for (const path of LINUX_ID_FILES) {\n const id = plausible(await read(path).catch(() => undefined));\n if (id !== undefined) return id;\n }\n return undefined;\n }\n if (platform === 'win32') {\n const root = (deps.env ?? process.env).SystemRoot ?? 'C:\\\\Windows';\n const out = await run(deps, win32.join(root, 'System32', 'reg.exe'), [\n 'query',\n 'HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\Microsoft\\\\Cryptography',\n '/v',\n 'MachineGuid',\n '/reg:64',\n ]);\n return plausible(/^\\s*MachineGuid\\s+REG_SZ\\s+(\\S+)\\s*$/im.exec(out ?? '')?.[1]);\n }\n return undefined;\n}\n\n/** An all-zero ID is a VM's placeholder that many computers share, so it names none. */\nfunction plausible(raw: string | undefined): string | undefined {\n const id = raw?.trim().toLowerCase();\n if (id === undefined || !PLAUSIBLE_ID.test(id)) return undefined;\n return /[1-9a-f]/.test(id) ? id : undefined;\n}\n\nfunction run(deps: MachineIdDeps, cmd: string, args: string[]): Promise<string | undefined> {\n const exec = deps.execFileImpl ?? execFile;\n return new Promise((resolve) => {\n try {\n exec(\n cmd,\n args,\n { timeout: READ_TIMEOUT_MS, windowsHide: true, encoding: 'utf8' },\n (err, stdout) => resolve(err === null ? String(stdout) : undefined),\n );\n } catch {\n resolve(undefined);\n }\n });\n}\n","import { getAddress, isAddress } from 'viem';\nimport { CliError } from '../lib/errors';\nimport { loadRawConfig, resolveSettings } from '../lib/config';\nimport { deviceName as readDeviceName } from '../lib/device-name';\nimport { machineHash as readMachineHash } from '../lib/machine-id';\nimport { httpRequest, fetchFailureToCliError, type HttpRequestOptions } from '../lib/http';\nimport { liveLine, type LiveLine } from '../lib/live-line';\nimport { buildSiwxHeader, SIWX_CHAIN_ID, SIWX_HEADER } from '../lib/siwx';\nimport {\n describeWallet,\n resolveWalletProvider,\n type ResolveWalletProviderOptions,\n type TenjinSigner,\n} from '../lib/wallet';\nimport { getUsdcBalance } from '../lib/usdc';\nimport { toMoney } from '../lib/money';\nimport { emitWriteNotice, paint, style } from '../lib/output';\nimport { addressQrLines, textQrLines } from '../lib/qr';\nimport { openInBrowser } from '../lib/open-url';\nimport { PRODUCTION_ORIGIN } from '../lib/production-origin';\nimport { underAgentHarness } from '../lib/session';\nimport { SUGGESTED_FUND_USD } from '../router/fee';\nimport {\n dollars,\n forgetLink,\n inFlight,\n LINK_LIFETIME_MS,\n readLinkStatus,\n recallLink,\n rememberLink,\n STATUS_GRACE_MS,\n tokenExpiry,\n tokenOf,\n watchFunding,\n type LinkStatus,\n type RememberedLink,\n type WatchEnd,\n} from './fund-watch';\nimport type { CommandContext, CommandResult } from '../context';\n\n/*\n * `tenjin fund` (and `tenjin wallet fund`): add funds to THIS wallet in the\n * browser. The CLI signs a SIWX proof with the wallet's own key and asks the\n * Tenjin backend for a checkout link for that same address (the server refuses\n * any other address). The link is the Tenjin /fund page, with a short-lived\n * token in the URL fragment, or a Coinbase-hosted checkout. The money moves\n * entirely on the provider's side and the link grants no spending power over\n * the wallet. A hosted link is single-use, expires in ~5 minutes and is bound\n * to this machine's public IP at mint time.\n *\n * At a terminal it then watches: the link's payment status from the server\n * and the balance, on one status line, until the money lands\n * (`fund-watch.ts`). `--usdc` shows the address to send USDC to instead,\n * and watches the same way.\n */\n\n/** The hosted Coinbase checkout host, one of the two hosts a returned link may use. */\nconst COINBASE_CHECKOUT_HOST = 'pay.coinbase.com';\n/** A hosted Coinbase link's own lifetime. */\nconst HOSTED_LIFETIME_MS = 5 * 60_000;\n/**\n * fund talks to production, full stop (owner decision, 2026-08-12): the mint\n * signs with the wallet key, so this path takes no override -- not `--base-url`,\n * not the env, not config. Cutting the surface entirely is what lets the verb\n * sit in the free allowlist tier with nothing to caveat.\n */\nconst FUND_ORIGIN = PRODUCTION_ORIGIN;\n/**\n * The only hosts a returned link may point at; anything else is refused unopened.\n * The first is the host of the pinned origin (the Tenjin /fund page), so it\n * follows the origin if that is ever re-pointed.\n */\nconst ALLOWED_CHECKOUT_HOSTS: readonly string[] = [\n new URL(FUND_ORIGIN).host,\n COINBASE_CHECKOUT_HOST,\n];\n/** Matches the server's presetAmount bound (the fund link route's body schema). */\nconst MAX_PRESET_USD = 100_000;\n/** The link route's bounds on `need`. */\nconst NEED_LABEL_MAX = 60;\nconst NEED_PRICE_MAX_USD = 100;\n/** How long the balance read before a mint may take: it never holds the link up for long. */\nconst BASELINE_TIMEOUT_MS = 4_000;\n/**\n * A payment started on a link this recent, with the balance not yet up, is\n * one on its way: a rerun waits on it rather than opening a second checkout.\n */\nconst DUPLICATE_WINDOW_MS = 15 * 60_000;\n/** How long `--usdc` watches for a transfer. */\nconst USDC_WAIT_MS = 15 * 60_000;\n\n/**\n * Why the run is not reporting an arrival, kept distinct in the envelope because\n * three different outcomes otherwise collapse into `funded: false`: the run never\n * waited, it wanted to but could not read a baseline balance, or it waited and\n * the deadline (or the link's expiry) won. None establishes the payment status;\n * `status` carries what the page reported, when it did.\n */\nexport type FundPollStatus = 'skipped' | 'unavailable' | 'timed-out' | 'arrived';\n\n/** Where a fund link was asked for, as the fund page is told. */\nexport type FundSource = 'install' | 'agent' | 'terminal';\n\nexport interface FundNeed {\n label: string;\n priceUsd: number;\n}\n\nexport interface FundOptions extends ResolveWalletProviderOptions {\n /** Optional USD preset forwarded to the checkout. */\n amountUsd?: string;\n /** Skip the browser open (still prints the URL). */\n open?: boolean;\n /** The environment the agent-harness and browser checks read; defaults to the process's. */\n env?: NodeJS.ProcessEnv;\n /** `--no-qr`: no QR code, even where no browser can open. */\n qr?: boolean;\n /** Watch for the payment after issuing the link. Defaults to ON at a TTY, OFF otherwise. */\n wait?: boolean;\n /** `--usdc`: the address and a QR to send USDC to, no checkout. */\n usdc?: boolean;\n /** `--for` and `--price`: the paid call the money is for, shown on the page. */\n forLabel?: string;\n priceUsd?: string;\n /** Overrides the derived source; install passes `install`. */\n source?: FundSource;\n /** The \"Add funds to Tenjin\" title and balance; install has its own heading. */\n header?: boolean;\n /** Printed after \"Stopped watching\" on Ctrl-C: install's limits, next step and disclosure. */\n onStopLines?: readonly string[];\n fetchImpl?: typeof fetch;\n openUrl?: typeof openInBrowser;\n deviceName?: () => Promise<string | undefined>;\n /** This computer's hash for the fund page's one-per-computer code check (`lib/machine-id.ts`). */\n machineHash?: () => Promise<string | undefined>;\n /** One key from the person, for the expired link's `r` / `q`; null when nobody can answer. */\n readKey?: (keys: readonly string[]) => Promise<string | null>;\n /** Poll seams so tests never sleep for real. */\n sleep?: (ms: number) => Promise<void>;\n now?: () => number;\n pollIntervalMs?: number;\n /** Bounds the whole wait, in place of the link's expiry plus its grace. */\n pollTimeoutMs?: number;\n /** The status line's stream behavior, for tests. */\n live?: LiveLine;\n platform?: NodeJS.Platform;\n}\n\ninterface Issued {\n url: string;\n token?: string;\n expiresAt: number;\n hosted: boolean;\n}\n\nexport async function runFund(ctx: CommandContext, opts: FundOptions = {}): Promise<CommandResult> {\n const preset = parsePreset(opts.amountUsd);\n const need = parseNeed(opts.forLabel, opts.priceUsd);\n const env = opts.env ?? process.env;\n const now = opts.now ?? Date.now;\n const human = ctx.io.isTTY && !ctx.flags.json;\n\n const provider = resolveWalletProvider(ctx, opts);\n const desc = await describeWallet(provider);\n const address = checksummed(desc.address);\n\n const config = await loadRawConfig(ctx.dataDir);\n const settings = resolveSettings({ config, flags: {}, env: process.env });\n const rpcUrl = settings.rpcUrl.value;\n const readBalance = () => balanceOrUndefined(address, rpcUrl);\n\n // Waiting is an INTERACTIVE posture: a human is standing at the terminal with\n // a browser open. Piped, --json, and MCP runs default to not waiting: the\n // envelope carrying the link is written only after runFund returns, and an\n // agent waits with `tenjin balance --wait` in the background instead.\n const shouldWait = opts.wait ?? ctx.io.isTTY;\n const live = opts.live ?? liveLine(ctx.io.stderr);\n const err = ctx.io.stderr;\n const say = (line = '') => err.write(`${line}\\n`);\n const dim = (text: string) => style('dim', text, err);\n\n if (opts.usdc === true) {\n return fundByUsdc(ctx, { address, readBalance, human, shouldWait, live, say, dim, opts });\n }\n\n // Read the balance BEFORE minting, every time: it is the baseline the wait\n // and a later `tenjin balance --wait` measure an arrival from, and what the\n // header shows. A slow or failed read only costs those, never the link.\n const startBalance = await withTimeout(readBalance(), BASELINE_TIMEOUT_MS);\n\n if (human && opts.header !== false) {\n say();\n say(` ${style('bold', 'Add funds to Tenjin', err)}`);\n say();\n if (startBalance !== undefined) say(` Balance ${dollars(startBalance)}`);\n }\n\n // A PAYMENT ALREADY ON ITS WAY is waited on, never doubled: a rerun while\n // money is landing is exactly how a second top-up happens.\n const prior = await recallLink(ctx.dataDir, address, now());\n const onItsWay =\n prior !== null && now() - prior.issuedAt < DUPLICATE_WINDOW_MS\n ? await paymentOnItsWay(prior, startBalance, opts.fetchImpl)\n : undefined;\n\n const source: FundSource = opts.source ?? (underAgentHarness(env) ? 'agent' : 'terminal');\n // Unlocked only to mint: waiting on a payment already on its way needs no\n // key, and a fresh link after it expires unlocks then.\n let signer: TenjinSigner | undefined;\n const mint = async (): Promise<Issued> => {\n signer ??= await provider.getSigner();\n const [deviceName, machineHash] = await Promise.all([\n (opts.deviceName ?? readDeviceName)().catch(() => undefined),\n (opts.machineHash ?? readMachineHash)().catch(() => undefined),\n ]);\n const url = await mintLink(ctx, signer, address, {\n ...(preset !== undefined ? { presetAmount: preset } : {}),\n ...(need !== undefined ? { need } : {}),\n source,\n deviceName,\n machineHash,\n ...(opts.fetchImpl !== undefined ? { fetchImpl: opts.fetchImpl } : {}),\n });\n const token = tokenOf(url);\n const hosted = new URL(url).host === COINBASE_CHECKOUT_HOST;\n const issuedAt = now();\n const expiresAt =\n (token !== undefined ? tokenExpiry(token) : undefined) ??\n issuedAt + (hosted ? HOSTED_LIFETIME_MS : LINK_LIFETIME_MS);\n // Every link is remembered, a hosted one too: its starting balance is what\n // a later `tenjin balance --wait` measures an arrival from. Only a Tenjin\n // link has a token, so only it has a status to follow.\n await rememberLink(ctx.dataDir, {\n version: 1,\n address: address.toLowerCase(),\n url,\n ...(token !== undefined ? { token } : {}),\n issuedAt,\n expiresAt,\n ...(startBalance !== undefined ? { startBalanceAtomic: startBalance.toString() } : {}),\n });\n return { url, ...(token !== undefined ? { token } : {}), expiresAt, hosted };\n };\n\n let link: Issued =\n onItsWay !== undefined\n ? {\n // On its way means it had a token, so it is a Tenjin link with a url.\n url: prior!.url!,\n ...(prior!.token !== undefined ? { token: prior!.token } : {}),\n expiresAt: prior!.expiresAt,\n hosted: false,\n }\n : await mint();\n\n // The link goes out on EVERY surface and before any waiting: the stdout\n // envelope that also carries it is written only after this function\n // returns. Off a terminal these are write-notices (stderr, no TTY or --json\n // gate); stdout stays exactly one JSON object. The link prints whole on\n // every path: a person who copies it into another browser needs the token\n // in its fragment, which can only fund this wallet and expires with the link.\n if (!human) {\n emitWriteNotice(\n ctx.io,\n `${onItsWay !== undefined ? 'Payment on its way, from' : 'Checkout'}: ${link.url}`,\n );\n emitWriteNotice(\n ctx.io,\n link.hosted\n ? 'The link is single-use, expires in ~5 minutes, and only works in a browser on this machine (it is bound to this network).'\n : 'The link expires in about 10 minutes.',\n );\n }\n\n // An explicitly requested funding command can open under an agent harness\n // even without a terminal. The opener is resolved by absolute path and\n // ignores BROWSER (lib/open-url.ts), so an agent host cannot route the link\n // into its embedded view.\n const willOpen =\n onItsWay === undefined && opts.open !== false && (ctx.io.isTTY || underAgentHarness(env));\n const show = async (issued: Issued): Promise<boolean> => {\n const browser = browserAvailable(env, opts.platform ?? process.platform);\n const opened = willOpen && browser ? await (opts.openUrl ?? openInBrowser)(issued.url) : false;\n if (!human) return opened;\n if (onItsWay !== undefined) {\n say();\n say(' A payment is already on its way.');\n say(` ${dim(issued.url)}`);\n } else if (opened) {\n say(' Checkout opened in your browser');\n say(` ${dim(issued.url)}`);\n } else if (!willOpen) {\n say(' Checkout open this link to pay:');\n say(` ${issued.url}`);\n } else {\n // No browser here (SSH, no display) or it would not open: a phone\n // camera opens the same page, the same flow.\n const qr = opts.qr !== false ? textQrLines(issued.url, err) : [];\n say();\n if (qr.length > 0) {\n say(\n browser\n ? \" Couldn't open a browser. Scan to pay on your phone:\"\n : ' No browser on this machine. Scan to pay on your phone:',\n );\n for (const line of qr) say(` ${line}`);\n say(` or open ${issued.url}`);\n } else {\n say(\n browser\n ? \" Couldn't open a browser. Open this link to pay:\"\n : ' No browser on this machine. Open this link to pay:',\n );\n say(` ${issued.url}`);\n }\n }\n say();\n return opened;\n };\n let opened = await show(link);\n\n let pollStatus: FundPollStatus = 'skipped';\n let end: WatchEnd | undefined;\n if (shouldWait && startBalance === undefined) pollStatus = 'unavailable';\n if (shouldWait && startBalance !== undefined) {\n const stopInterrupt = human ? onInterrupt(live, say, opts.onStopLines) : () => undefined;\n try {\n for (;;) {\n end = await watchFunding({\n startBalance,\n readBalance,\n ...(link.token !== undefined ? { token: link.token } : {}),\n expiresAt: link.expiresAt,\n deadline:\n opts.pollTimeoutMs !== undefined\n ? now() + opts.pollTimeoutMs\n : link.expiresAt + STATUS_GRACE_MS,\n view: 'checkout',\n ...(human ? { live } : {}),\n ...(opts.fetchImpl !== undefined ? { fetchImpl: opts.fetchImpl } : {}),\n ...(opts.sleep !== undefined ? { sleep: opts.sleep } : {}),\n ...(opts.pollIntervalMs !== undefined ? { intervalMs: opts.pollIntervalMs } : {}),\n now,\n });\n if (end.kind !== 'expired' || !human) break;\n // AN EXPIRED LINK, at a terminal: say whether money moved, then offer\n // a fresh link. Nothing was charged on it, unless the page could not\n // report (no status), where the payment may still be landing.\n live.warn(\n end.statusKnown\n ? 'The checkout link expired. Nothing was charged.'\n : 'The checkout link expired.',\n );\n if (!end.statusKnown) say(' If you paid, it still lands; `tenjin balance` shows it.');\n const ask = opts.readKey ?? (process.stdin.isTTY ? readKey : undefined);\n if (ask === undefined) break;\n say(` ${style('bold', 'r', err)} new link ${style('bold', 'q', err)} stop`);\n const key = await ask(['r', 'q']);\n if (key !== 'r') break;\n say();\n link = await mint();\n opened = await show(link);\n }\n } finally {\n stopInterrupt();\n live.stop();\n }\n pollStatus = end.kind === 'arrived' ? 'arrived' : 'timed-out';\n }\n\n const arrived = end?.kind === 'arrived' ? end : undefined;\n if (arrived !== undefined) await forgetLink(ctx.dataDir);\n const status: LinkStatus | undefined = end?.status ?? onItsWay;\n const balanceAtomic = arrived?.balance ?? startBalance;\n const amount = preset !== undefined ? String(preset) : SUGGESTED_FUND_USD;\n return {\n data: {\n address,\n checkoutUrl: link.url,\n opened,\n ...(preset !== undefined ? { presetAmount: preset } : {}),\n funded: arrived !== undefined,\n pollStatus,\n ...(status !== undefined ? { status: status.state } : {}),\n ...(onItsWay !== undefined ? { paymentInFlight: true } : {}),\n // The link expired and this round's status read said no payment is on it.\n ...(end?.kind === 'expired' && end.statusKnown ? { nothingCharged: true } : {}),\n source,\n ...(need !== undefined ? { need } : {}),\n nextStep:\n arrived !== undefined\n ? 'Funds confirmed. Continue the original task; funding does not require another restart.'\n : agentNextStep({\n opened,\n amount,\n inFlight: onItsWay !== undefined,\n ...(need ? { need } : {}),\n }),\n ...(balanceAtomic !== undefined ? { balance: toMoney(balanceAtomic.toString()) } : {}),\n ...(arrived !== undefined ? { added: toMoney(arrived.added.toString()) } : {}),\n },\n humanLines: humanEnding(ctx.io, pollStatus, end, arrived?.balance),\n };\n}\n\n/** What a person reads last: the balance and what follows. */\nfunction humanEnding(\n io: CommandContext['io'],\n pollStatus: FundPollStatus,\n end: WatchEnd | undefined,\n balance: bigint | undefined,\n): string[] {\n if (pollStatus === 'arrived' && balance !== undefined) {\n return [\n '',\n ` Balance ${paint(io, 'bold', dollars(balance))}`,\n ' You can close the browser tab.',\n ];\n }\n if (pollStatus === 'unavailable') {\n return [\n \" Couldn't read your balance to watch for the payment. The link still works,\",\n ' and `tenjin balance` shows the payment once it lands.',\n ];\n }\n if (pollStatus === 'skipped') {\n return [' `tenjin balance --wait` tells you when the payment lands.'];\n }\n if (end?.kind === 'expired') {\n return ['', ' Run `tenjin fund` for a fresh link when you are ready.'];\n }\n return [\n '',\n \" The payment hasn't reached your balance yet. It still can:\",\n ' `tenjin balance --wait` watches for it.',\n ];\n}\n\n/**\n * THE AGENT'S NEXT STEP after a link it did not wait on: say what the money is\n * for, wait in the background, carry on when it lands. It never asks the\n * person to come back and type that they are done.\n */\nfunction agentNextStep(o: {\n opened: boolean;\n amount: string;\n inFlight: boolean;\n need?: FundNeed;\n}): string {\n const wait =\n 'run `tenjin balance --wait` in the background, with the same Tenjin executable and shell as this command (in Claude Code, as a background Bash command, so you are woken when it exits), and continue the task when it exits: exit 0 means the funds arrived, and its output says how much. If it exits without funds, say once that nothing arrived and nothing went wrong, and continue without paid tools.';\n if (o.inFlight) {\n return `A payment for this machine is already on its way, so no second checkout was opened; do not open another. Tell the person in one sentence, then ${wait} Never ask the person to type \"done\" or to tell you when the money arrives.`;\n }\n const what =\n o.need !== undefined\n ? `what the money is for (${o.need.label}, $${o.need.priceUsd} a call)`\n : 'what the money is for (the paid tool you wanted and its price, if there is one)';\n const where = o.opened\n ? `that checkout is open in their browser with $${o.amount} filled in`\n : `that checkout is ready with $${o.amount} filled in, and show checkoutUrl as a clickable link`;\n return `Tell the person in one or two sentences ${what} and ${where}. Then ${wait} Never ask the person to type \"done\" or to tell you when they have paid. Ask about adding funds at most once per session: if they decline, carry on without paid tools and do not offer again. Do not open another checkout unless they ask for a new link.`;\n}\n\n/**\n * `--usdc`: the address to send USDC to, its safety rule first, and a QR of\n * the plain address. Nothing is minted and no key is unlocked; the wait is\n * the balance alone.\n */\nasync function fundByUsdc(\n ctx: CommandContext,\n c: {\n address: string;\n readBalance: () => Promise<bigint | undefined>;\n human: boolean;\n shouldWait: boolean;\n live: LiveLine;\n say: (line?: string) => void;\n dim: (text: string) => string;\n opts: FundOptions;\n },\n): Promise<CommandResult> {\n const { address, human, say, dim, opts } = c;\n const now = opts.now ?? Date.now;\n const warning = \"Only USDC, only on the Base network. Anything else can't be recovered.\";\n const check = `starts ${address.slice(0, 6)} · ends ${address.slice(-4)}`;\n // Read the balance BEFORE the handoff, waiting or not: it is what this wait\n // and a later `tenjin balance --wait` measure an arrival from, so a transfer\n // that lands before that wait starts still counts. Bounded off the wait, as\n // for a checkout, so it never holds up the agent's envelope.\n const startBalance = c.shouldWait\n ? await c.readBalance()\n : await withTimeout(c.readBalance(), BASELINE_TIMEOUT_MS);\n // Remembered with no url and no token: `tenjin fund` finds no status to\n // follow, so it never reads this as a checkout on its way. A live checkout\n // link with a token is kept instead: replacing it would hide a card payment\n // still landing from the next `tenjin fund`, which would open a second\n // checkout. Its starting balance drops to this reading when that is lower\n // or it has none (its own read failed, or money was spent since), so\n // `tenjin balance --wait` counts a transfer that lands before it starts,\n // and a card payment still rises above it.\n if (startBalance !== undefined) {\n const prior = await recallLink(ctx.dataDir, address, now());\n if (prior?.token === undefined) {\n const issuedAt = now();\n await rememberLink(ctx.dataDir, {\n version: 1,\n address: address.toLowerCase(),\n issuedAt,\n expiresAt: issuedAt + USDC_WAIT_MS,\n startBalanceAtomic: startBalance.toString(),\n });\n } else if (\n prior.startBalanceAtomic === undefined ||\n startBalance < BigInt(prior.startBalanceAtomic)\n ) {\n await rememberLink(ctx.dataDir, { ...prior, startBalanceAtomic: startBalance.toString() });\n }\n }\n if (human) {\n const err = ctx.io.stderr;\n say();\n say(` ${style('bold', 'Send USDC to add funds', ctx.io.stderr)}`);\n say();\n say(` ${style('yellow', warning, err)}`);\n say();\n say(` ${style('bold', address, err)}`);\n say(` ${dim(check)}`);\n const qr = opts.qr !== false ? addressQrLines(address, err) : [];\n if (qr.length > 0) {\n say();\n for (const line of qr) say(` ${line}`);\n }\n say();\n } else {\n emitWriteNotice(ctx.io, `Send USDC to ${address} (${check}).`);\n emitWriteNotice(ctx.io, warning);\n }\n\n let end: WatchEnd | undefined;\n let pollStatus: FundPollStatus = c.shouldWait ? 'unavailable' : 'skipped';\n if (c.shouldWait && startBalance !== undefined) {\n const stopInterrupt = human ? onInterrupt(c.live, say, opts.onStopLines) : () => undefined;\n try {\n end = await watchFunding({\n startBalance,\n readBalance: c.readBalance,\n deadline: now() + (opts.pollTimeoutMs ?? USDC_WAIT_MS),\n view: 'usdc',\n ...(human ? { live: c.live } : {}),\n ...(opts.sleep !== undefined ? { sleep: opts.sleep } : {}),\n ...(opts.pollIntervalMs !== undefined ? { intervalMs: opts.pollIntervalMs } : {}),\n now,\n });\n } finally {\n stopInterrupt();\n c.live.stop();\n }\n pollStatus = end.kind === 'arrived' ? 'arrived' : 'timed-out';\n }\n const arrived = end?.kind === 'arrived' ? end : undefined;\n if (arrived !== undefined) await forgetLink(ctx.dataDir);\n const balanceAtomic = arrived?.balance ?? startBalance;\n return {\n data: {\n address,\n usdc: true,\n funded: arrived !== undefined,\n pollStatus,\n nextStep:\n arrived !== undefined\n ? 'Funds confirmed. Continue the original task; funding does not require another restart.'\n : `Give the person the address exactly as printed, with the rule \"${warning}\" Then run \\`tenjin balance --wait\\` in the background (in Claude Code, as a background Bash command) and continue the task when it exits. Never ask the person to type \"done\".`,\n ...(balanceAtomic !== undefined ? { balance: toMoney(balanceAtomic.toString()) } : {}),\n ...(arrived !== undefined ? { added: toMoney(arrived.added.toString()) } : {}),\n },\n humanLines:\n arrived !== undefined\n ? ['', ` Balance ${paint(ctx.io, 'bold', dollars(arrived.balance))}`]\n : pollStatus === 'skipped'\n ? [' `tenjin balance --wait` says when it arrives.']\n : ['', ' Nothing has arrived yet. `tenjin balance --wait` keeps watching.'],\n };\n}\n\n/**\n * The prior link's payment status when it shows money on its way: `paying`,\n * or `paid` with the balance not yet above where it was when that link was\n * issued. Undefined otherwise, when the status cannot be read, or for a hosted\n * link or a `--usdc` handoff, which have no status to read.\n */\nasync function paymentOnItsWay(\n prior: RememberedLink,\n balance: bigint | undefined,\n fetchImpl: typeof fetch | undefined,\n): Promise<LinkStatus | undefined> {\n if (prior.token === undefined) return undefined;\n const read = await readLinkStatus(prior.token, {\n ...(fetchImpl !== undefined ? { fetchImpl } : {}),\n });\n if (!('status' in read) || !inFlight(read.status)) return undefined;\n if (balance !== undefined && prior.startBalanceAtomic !== undefined) {\n return balance > BigInt(prior.startBalanceAtomic) ? undefined : read.status;\n }\n // No balance to compare: only a payment still in progress is certain to be pending.\n return read.status.state === 'paying' ? read.status : undefined;\n}\n\n/** POST /api/fund/link with the wallet's SIWX proof: the checkout URL, validated. */\nasync function mintLink(\n ctx: CommandContext,\n signer: TenjinSigner,\n address: string,\n extra: {\n presetAmount?: number;\n need?: FundNeed;\n source: FundSource;\n deviceName: string | undefined;\n machineHash: string | undefined;\n fetchImpl?: typeof fetch;\n },\n): Promise<string> {\n const siwxHeader = await buildSiwxHeader(signer, {\n baseUrl: FUND_ORIGIN,\n chainId: SIWX_CHAIN_ID,\n });\n const request: HttpRequestOptions = {\n method: 'POST',\n timeoutMs: ctx.flags.timeout,\n headers: { [SIWX_HEADER]: siwxHeader },\n // `deviceName`, `source` and `need` are display context for the page, and\n // `machineHash` is for its \"Have a code?\" box's one-per-computer check. A\n // server without them ignores them (its body schema is not strict).\n jsonBody: {\n address,\n ...(extra.presetAmount !== undefined ? { presetAmount: extra.presetAmount } : {}),\n ...(extra.deviceName !== undefined ? { deviceName: extra.deviceName } : {}),\n ...(extra.machineHash !== undefined ? { machineHash: extra.machineHash } : {}),\n source: extra.source,\n ...(extra.need !== undefined ? { need: extra.need } : {}),\n },\n };\n const res = await httpRequest(`${FUND_ORIGIN}/api/fund/link`, {\n ...request,\n ...(extra.fetchImpl !== undefined ? { fetchImpl: extra.fetchImpl } : {}),\n });\n if (!res.ok) {\n throw fetchFailureToCliError(res, {\n fix: 'Check your network, then retry.',\n });\n }\n return checkoutUrlFrom(res.status, res.json);\n}\n\n/**\n * Is there a browser on this machine a person is sitting at? Not over SSH,\n * and not on a Linux or BSD desktop with no display server.\n */\nexport function browserAvailable(env: NodeJS.ProcessEnv, platform: NodeJS.Platform): boolean {\n const set = (v: string | undefined) => typeof v === 'string' && v.length > 0;\n if (set(env.SSH_CONNECTION) || set(env.SSH_CLIENT) || set(env.SSH_TTY)) return false;\n if (platform === 'darwin' || platform === 'win32') return true;\n return set(env.DISPLAY) || set(env.WAYLAND_DISPLAY);\n}\n\n/**\n * Ctrl-C while watching: clear the status line, say that checkout carries on,\n * print what the caller still owes the person (install's next step), then let\n * the signal end the process as it always did. Returns the remover.\n */\nfunction onInterrupt(\n live: LiveLine,\n say: (line?: string) => void,\n after: readonly string[] = [],\n): () => void {\n const handler = () => {\n live.stop();\n say();\n say(\" Stopped watching. This doesn't cancel checkout: `tenjin balance` shows the\");\n say(' payment once it lands.');\n for (const line of after) say(line);\n process.removeListener('SIGINT', handler);\n process.kill(process.pid, 'SIGINT');\n };\n process.on('SIGINT', handler);\n return () => process.removeListener('SIGINT', handler);\n}\n\n/** One key from the terminal, in raw mode; Ctrl-C and Escape read as `q`. */\nasync function readKey(keys: readonly string[]): Promise<string | null> {\n const stdin = process.stdin;\n if (!stdin.isTTY) return null;\n return new Promise((resolve) => {\n const wasRaw = stdin.isRaw;\n stdin.setRawMode(true);\n stdin.resume();\n const onData = (chunk: Buffer) => {\n const key = chunk.toString('utf8').toLowerCase();\n const answer = key === '\\x03' || key === '\\x1b' ? 'q' : keys.includes(key) ? key : null;\n if (answer === null) return;\n stdin.removeListener('data', onData);\n stdin.setRawMode(wasRaw);\n stdin.pause();\n resolve(answer);\n };\n stdin.on('data', onData);\n });\n}\n\n/**\n * The route parses the destination with strict EIP-55 (`checksummedAddress`) but\n * the local wallet store accepts any casing, so an imported or hand-edited wallet\n * file would earn an unactionable 400 on a purely local condition. Normalize here\n * instead, as `send` does for its recipient.\n */\nfunction checksummed(address: string): string {\n if (!isAddress(address, { strict: false })) {\n throw new CliError(\n 'USAGE',\n `The active wallet address is not a valid EVM address: ${address}`,\n {\n fix: 'Check the wallet file, or create a fresh wallet with `tenjin wallet create`.',\n },\n );\n }\n return getAddress(address);\n}\n\nfunction parsePreset(raw: string | undefined): number | undefined {\n if (raw === undefined) return undefined;\n const n = Number(raw);\n if (!Number.isFinite(n) || n <= 0 || n > MAX_PRESET_USD) {\n throw new CliError('USAGE', `Amount must be a positive USD number up to ${MAX_PRESET_USD}.`, {\n fix: 'Example: tenjin fund 5',\n });\n }\n return n;\n}\n\n/** `--for` and `--price`, together or not at all, within the link route's bounds. */\nexport function parseNeed(\n label: string | undefined,\n price: string | undefined,\n): FundNeed | undefined {\n if (label === undefined && price === undefined) return undefined;\n const example = 'Example: tenjin fund 5 --for \"X post read\" --price 0.006';\n if (label === undefined || price === undefined) {\n throw new CliError('USAGE', '--for and --price go together.', { fix: example });\n }\n const trimmed = label\n // eslint-disable-next-line no-control-regex\n .replace(/[\\x00-\\x1f\\x7f-\\x9f\\u061c\\u200e\\u200f\\u202a-\\u202e\\u2066-\\u2069]/g, '')\n .trim();\n if (trimmed.length === 0 || [...trimmed].length > NEED_LABEL_MAX) {\n throw new CliError('USAGE', `--for takes a label of 1 to ${NEED_LABEL_MAX} characters.`, {\n fix: example,\n });\n }\n const n = Number(price);\n if (\n !/^\\d+(\\.\\d+)?$/.test(price.trim()) ||\n !Number.isFinite(n) ||\n n <= 0 ||\n n > NEED_PRICE_MAX_USD\n ) {\n throw new CliError(\n 'USAGE',\n `--price takes the call's price in USD, above 0 and at most ${NEED_PRICE_MAX_USD}.`,\n { fix: example },\n );\n }\n return { label: trimmed, priceUsd: n };\n}\n\n/**\n * Map the mint response to either the checkout URL or the coded refusal. The\n * URL is opened by this process, so it is validated as https on one of the two\n * allowed hosts (the Tenjin origin or Coinbase's checkout) before anything else\n * sees it: a compromised or misconfigured server must not be able to steer the\n * user's browser anywhere else.\n */\nfunction checkoutUrlFrom(status: number, json: unknown): string {\n if (status === 200) {\n const url =\n typeof json === 'object' && json !== null ? (json as { url?: unknown }).url : undefined;\n if (typeof url === 'string') {\n let parsed: URL | undefined;\n try {\n parsed = new URL(url);\n } catch {\n parsed = undefined;\n }\n if (\n parsed !== undefined &&\n parsed.protocol === 'https:' &&\n ALLOWED_CHECKOUT_HOSTS.includes(parsed.host)\n ) {\n return url;\n }\n }\n throw new CliError(\n 'CONTRACT_MISMATCH',\n `The server's checkout URL was missing or not https on ${ALLOWED_CHECKOUT_HOSTS.join(' or ')}; refusing to open it.`,\n );\n }\n const code = errorCode(json);\n if (status === 403 && code === 'region_not_supported') {\n throw new CliError('REFUSED', 'Adding funds is not available in your region yet.');\n }\n // A rejected proof is a local condition (\"retry\" never fixes it): the signed\n // window is clock-relative, and the domain is always the pinned production origin.\n if (status === 401) {\n throw new CliError('REFUSED', \"Your computer's clock is off, so Tenjin could not sign in.\", {\n fix: \"Set your computer's clock right in its system settings, then run `tenjin fund` again.\",\n });\n }\n if (status === 429) {\n throw new CliError('RATE_LIMITED', 'Too many tries. Nothing was charged.', {\n fix: 'Wait a minute and retry.',\n });\n }\n if (status === 503) {\n throw new CliError('API_UNREACHABLE', 'Adding funds is down right now. Nothing was charged.', {\n fix: 'Retry later.',\n });\n }\n throw new CliError(\n 'API_UNREACHABLE',\n `The funding endpoint returned ${status}${code !== undefined ? ` (${code})` : ''}.`,\n { fix: 'Retry; if it persists, check the service status.' },\n );\n}\n\n/** The `error.code` of the withApi failure envelope, when the server sent one. */\nfunction errorCode(json: unknown): string | undefined {\n if (typeof json !== 'object' || json === null) return undefined;\n const err = (json as { error?: unknown }).error;\n if (typeof err !== 'object' || err === null) return undefined;\n const code = (err as { code?: unknown }).code;\n return typeof code === 'string' ? code : undefined;\n}\n\nasync function balanceOrUndefined(address: string, rpcUrl: string): Promise<bigint | undefined> {\n try {\n return await getUsdcBalance(address as `0x${string}`, rpcUrl);\n } catch {\n return undefined;\n }\n}\n\n/** `p`, or undefined once `ms` has passed. */\nasync function withTimeout<T>(p: Promise<T | undefined>, ms: number): Promise<T | undefined> {\n let timer: NodeJS.Timeout | undefined;\n const late = new Promise<undefined>((resolve) => {\n timer = setTimeout(() => resolve(undefined), ms);\n timer.unref();\n });\n try {\n return await Promise.race([p, late]);\n } finally {\n clearTimeout(timer);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AAiBzB,IAAM,qBAAqB;AAAA,EACzB;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AACF;AAEA,IAAM,kBAAkB;AACxB,IAAM,SAAS;AACf,IAAM,oBAAoB;AAS1B,eAAsB,WAAW,OAAuB,CAAC,GAAgC;AACvF,MAAI;AACF,UAAM,WAAW,KAAK,YAAY,QAAQ;AAC1C,UAAM,UAAU,aAAa,WAAW,OAAO,KAAK,gBAAgB,iBAAiB,IAAI;AACzF,UAAM,QAAQ,MAAM,WAAW,EAAE;AACjC,QAAI,UAAU,OAAW,QAAO;AAChC,UAAM,OAAO,OAAO,KAAK,YAAY,UAAU,CAAC;AAChD,WAAO,SAAS,UA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,GAAG,SAAS,SAAY,KAAK,IAAI,MAAM,EAAE;AAAA,IAChF,EAAE,KAAK,mDAAmD;AAAA,EAC5D;AACF;AAGA,SAAS,UAAU,MAAmC;AACpD,MAAI,OAAO,SAAS,YAAY,SAAS,KAAM,QAAO;AACtD,QAAM,MAAO,KAA6B;AAC1C,MAAI,OAAO,QAAQ,YAAY,QAAQ,KAAM,QAAO;AACpD,QAAM,OAAQ,IAA2B;AACzC,SAAO,OAAO,SAAS,WAAW,OAAO;AAC3C;AAEA,eAAe,mBAAmB,SAAiB,QAA6C;AAC9F,MAAI;AACF,WAAO,MAAM,eAAe,SAA0B,MAAM;AAAA,EAC9D,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAGA,eAAe,YAAe,GAA2B,IAAoC;AAC3F,MAAI;AACJ,QAAM,OAAO,IAAI,QAAmB,CAAC,YAAY;AAC/C,YAAQ,WAAW,MAAM,QAAQ,MAAS,GAAG,EAAE;AAC/C,UAAM,MAAM;AAAA,EACd,CAAC;AACD,MAAI;AACF,WAAO,MAAM,QAAQ,KAAK,CAAC,GAAG,IAAI,CAAC;AAAA,EACrC,UAAE;AACA,iBAAa,KAAK;AAAA,EACpB;AACF;","names":["execFile","deviceName","machineHash","opened"]}
|
|
@@ -3,46 +3,47 @@ import {
|
|
|
3
3
|
STALE_HOOK_LINE,
|
|
4
4
|
runHookCommand,
|
|
5
5
|
runHookKind
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-5J4E5GYI.js";
|
|
7
|
+
import "./chunk-HKGUKAQW.js";
|
|
7
8
|
import "./chunk-KFVJYLVL.js";
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-LPQNZKSG.js";
|
|
9
|
+
import "./chunk-LWSSIZOY.js";
|
|
10
10
|
import "./chunk-Y2EXZ47H.js";
|
|
11
|
-
import "./chunk-
|
|
12
|
-
import "./chunk-
|
|
13
|
-
import "./chunk-
|
|
11
|
+
import "./chunk-IULCDMVG.js";
|
|
12
|
+
import "./chunk-F2KJAJ7T.js";
|
|
13
|
+
import "./chunk-64WOMNYR.js";
|
|
14
14
|
import "./chunk-P4I7BFNJ.js";
|
|
15
|
-
import "./chunk-
|
|
16
|
-
import "./chunk-
|
|
15
|
+
import "./chunk-HPRVFJPM.js";
|
|
16
|
+
import "./chunk-5F4OB5B3.js";
|
|
17
|
+
import "./chunk-ZS7JIUJ3.js";
|
|
17
18
|
import "./chunk-JWAK7JQB.js";
|
|
18
|
-
import "./chunk-
|
|
19
|
+
import "./chunk-HZKANST2.js";
|
|
19
20
|
import "./chunk-MEZJ3I63.js";
|
|
20
21
|
import "./chunk-ILWCKCOI.js";
|
|
21
22
|
import "./chunk-RFZA7PSM.js";
|
|
22
23
|
import "./chunk-JUUBBBY5.js";
|
|
23
24
|
import "./chunk-7SLOTLO7.js";
|
|
24
25
|
import "./chunk-2U7H35IP.js";
|
|
25
|
-
import "./chunk-
|
|
26
|
-
import "./chunk-
|
|
27
|
-
import "./chunk-
|
|
26
|
+
import "./chunk-W2GXIARJ.js";
|
|
27
|
+
import "./chunk-TFT2X7SH.js";
|
|
28
|
+
import "./chunk-DTEWAVNE.js";
|
|
29
|
+
import "./chunk-UIB33QQP.js";
|
|
28
30
|
import "./chunk-7WEQQJLG.js";
|
|
29
|
-
import "./chunk-VH7JMLTG.js";
|
|
30
|
-
import "./chunk-3MZ7DYRO.js";
|
|
31
31
|
import "./chunk-ZCT5DJ3G.js";
|
|
32
|
+
import "./chunk-3MZ7DYRO.js";
|
|
32
33
|
import "./chunk-JTX3BUDK.js";
|
|
33
|
-
import "./chunk-
|
|
34
|
+
import "./chunk-ZEYA2WWX.js";
|
|
34
35
|
import "./chunk-DIH2G3YG.js";
|
|
35
|
-
import "./chunk-
|
|
36
|
-
import "./chunk-
|
|
36
|
+
import "./chunk-D6M3ZK66.js";
|
|
37
|
+
import "./chunk-RGCPELQN.js";
|
|
37
38
|
import "./chunk-CRG54LEB.js";
|
|
38
39
|
import "./chunk-TUCKEEXE.js";
|
|
39
|
-
import "./chunk-
|
|
40
|
+
import "./chunk-P6YQWIT2.js";
|
|
40
41
|
import "./chunk-DI4QAGRZ.js";
|
|
41
|
-
import "./chunk-
|
|
42
|
+
import "./chunk-3Y2EHT4F.js";
|
|
42
43
|
import "./chunk-ZXTAQYNA.js";
|
|
43
44
|
export {
|
|
44
45
|
STALE_HOOK_LINE,
|
|
45
46
|
runHookCommand,
|
|
46
47
|
runHookKind
|
|
47
48
|
};
|
|
48
|
-
//# sourceMappingURL=hook-command-
|
|
49
|
+
//# sourceMappingURL=hook-command-VZ27MGWO.js.map
|
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
},
|
|
7
7
|
"description": "Tenjin's tool router for Claude Code, installed by `tenjin install`.",
|
|
8
8
|
"metadata": {
|
|
9
|
-
"version": "0.1.0-alpha.
|
|
9
|
+
"version": "0.1.0-alpha.35"
|
|
10
10
|
},
|
|
11
11
|
"plugins": [
|
|
12
12
|
{
|
|
13
13
|
"name": "tenjin",
|
|
14
14
|
"source": "./tenjin",
|
|
15
15
|
"description": "Tenjin picks the right tool when your agent needs one, and one wallet on this machine pays for every call.",
|
|
16
|
-
"version": "0.1.0-alpha.
|
|
16
|
+
"version": "0.1.0-alpha.35"
|
|
17
17
|
}
|
|
18
18
|
]
|
|
19
19
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tenjin",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.35",
|
|
4
4
|
"description": "Tenjin picks the right tool when your agent needs one, and one wallet on this machine pays for every call.",
|
|
5
5
|
"types": "./types/index.d.ts",
|
|
6
6
|
"author": {
|
|
@@ -10,6 +10,6 @@
|
|
|
10
10
|
"homepage": "https://tenjin.sh/agents",
|
|
11
11
|
"repository": "https://github.com/BackTrackCo/tenjin-agent",
|
|
12
12
|
"metadata": {
|
|
13
|
-
"tenjin-cli": "0.1.0-alpha.
|
|
13
|
+
"tenjin-cli": "0.1.0-alpha.35"
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import type { EngineInterface } from 'claude-code';
|
|
2
|
+
type Dollar = EngineInterface;
|
|
3
|
+
type Json = Record<string, unknown>;
|
|
4
|
+
|
|
5
|
+
export function textOf(output: unknown): string | undefined {
|
|
6
|
+
if (typeof output === 'string') return output;
|
|
7
|
+
const blocks = Array.isArray(output) ? output : asRecord(output)?.content;
|
|
8
|
+
if (!Array.isArray(blocks)) return undefined;
|
|
9
|
+
const text = blocks
|
|
10
|
+
.map((block) => asRecord(block))
|
|
11
|
+
.filter((block) => block?.type === 'text' && typeof block.text === 'string')
|
|
12
|
+
.map((block) => block!.text as string)
|
|
13
|
+
.join('');
|
|
14
|
+
return text || undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function tenjinDataDir($: Dollar): Promise<string | null> {
|
|
18
|
+
const override = await $.env.get('TENJIN_DATA_DIR');
|
|
19
|
+
if (override !== undefined && override.length > 0) return override;
|
|
20
|
+
const home = (await $.env.get('HOME')) ?? (await $.env.get('USERPROFILE'));
|
|
21
|
+
return home !== undefined && home.length > 0 ? `${home}/.tenjin` : null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function readJson($: Dollar, path: string): Promise<Json | null> {
|
|
25
|
+
try {
|
|
26
|
+
return asRecord(parseJson(await $.fs.read(path))) ?? null;
|
|
27
|
+
} catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function parseJson(text: unknown): unknown {
|
|
33
|
+
if (typeof text !== 'string') return undefined;
|
|
34
|
+
try {
|
|
35
|
+
return JSON.parse(text) as unknown;
|
|
36
|
+
} catch {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function asRecord(value: unknown): Json | undefined {
|
|
42
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
43
|
+
? (value as Json)
|
|
44
|
+
: undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function subagentsEnabled($: Dollar): Promise<boolean> {
|
|
48
|
+
if ((await $.env.get('TENJIN_MODEL_WORKER')) === '1') return false;
|
|
49
|
+
const dir = await tenjinDataDir($);
|
|
50
|
+
return (
|
|
51
|
+
dir !== null && asRecord((await readJson($, dir + '/config.json'))?.router)?.subagents === true
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* HOW A HELD AGENT CALL IS ANSWERED: as a refusal whose text carries the offer. Claude
|
|
57
|
+
* Code's own summary of two or more Agent calls reads each call's state, which no hook
|
|
58
|
+
* redraws; answered as completed, a call that was only held read `finished` and `Done`.
|
|
59
|
+
* Refused, it reads as not run. The first line is for a person, and it is how this plugin
|
|
60
|
+
* knows its own held calls again (`model-viewer.tsx`).
|
|
61
|
+
*/
|
|
62
|
+
export const HELD_WITH_OFFER = 'Tenjin offered DeepSeek for this call and held it';
|
|
63
|
+
export const HELD_NOT_STARTED = 'Tenjin held this call and started nothing';
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* THE ROUTER'S HINT FOR A DELEGATED TASK REACHES THE SUBAGENT AS CONTEXT, NOT IN ITS PROMPT.
|
|
67
|
+
* The CLI's hook leg for an Agent call appends its hint to the call's prompt
|
|
68
|
+
* (`updatedInput`, `src/router/hooks.ts`). In auto mode Claude Code then refuses the call
|
|
69
|
+
* once ("a hook changed this call's input after auto mode reviewed it"), and a second
|
|
70
|
+
* call of the same response with it: one more response, and a `Not run` row. So the hint
|
|
71
|
+
* is taken off the call by this plugin's own `classic.PreToolUse` hook, which sits above
|
|
72
|
+
* that leg, and handed to the subagent the call starts as `SubagentStart` context, which changes no input.
|
|
73
|
+
*
|
|
74
|
+
* Only the router's own line is taken: an input that differs from the call's in anything
|
|
75
|
+
* but that line appended to the prompt is another hook's rewrite and passes on whole. A
|
|
76
|
+
* call that starts a teammate or a remote agent raises no `SubagentStart` here, so it
|
|
77
|
+
* keeps the hint in its prompt. A hint is matched to the started agent by the call's
|
|
78
|
+
* agent type and description, which is all the start event and the agent list carry.
|
|
79
|
+
*/
|
|
80
|
+
const HINT_SOURCE = 'Tenjin router (installed by the user)';
|
|
81
|
+
/** How long a hint waits for its subagent to start: a refused or failed call starts none. */
|
|
82
|
+
const HINT_MS = 120_000;
|
|
83
|
+
const pendingHints: { type: string; description: string; text: string; at: number }[] = [];
|
|
84
|
+
function delegatedHint(given: unknown, updated: unknown): string | undefined {
|
|
85
|
+
const [before, after] = [asRecord(given), asRecord(updated)];
|
|
86
|
+
if (!before || !after || typeof before.prompt !== 'string' || typeof after.prompt !== 'string')
|
|
87
|
+
return undefined;
|
|
88
|
+
if (before.name || before.team_name || before.isolation === 'remote') return undefined;
|
|
89
|
+
const keys = new Set([...Object.keys(before), ...Object.keys(after)]);
|
|
90
|
+
for (const key of keys)
|
|
91
|
+
if (key !== 'prompt' && JSON.stringify(before[key]) !== JSON.stringify(after[key]))
|
|
92
|
+
return undefined;
|
|
93
|
+
if (!after.prompt.startsWith(before.prompt + '\n\n')) return undefined;
|
|
94
|
+
const hint = after.prompt.slice(before.prompt.length + 2);
|
|
95
|
+
return hint.startsWith(HINT_SOURCE) ? hint : undefined;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** A `classic.PreToolUse` result with the router's hint taken off an Agent call and kept for its subagent. */
|
|
99
|
+
export async function keepDelegatedHint<R extends { updatedInput?: Json }>(
|
|
100
|
+
$: Dollar,
|
|
101
|
+
tool: string,
|
|
102
|
+
call: Json,
|
|
103
|
+
result: R,
|
|
104
|
+
): Promise<R> {
|
|
105
|
+
if ((tool !== 'Agent' && tool !== 'Task') || !result.updatedInput) return result;
|
|
106
|
+
const text = delegatedHint(call, result.updatedInput);
|
|
107
|
+
if (text === undefined) return result;
|
|
108
|
+
const now = await $.clock.now().catch(() => 0);
|
|
109
|
+
while (pendingHints.length >= 32 || (pendingHints[0] && now - pendingHints[0].at > HINT_MS))
|
|
110
|
+
pendingHints.shift();
|
|
111
|
+
pendingHints.push({
|
|
112
|
+
type: typeof call.subagent_type === 'string' ? call.subagent_type : 'general-purpose',
|
|
113
|
+
description: typeof call.description === 'string' ? call.description : '',
|
|
114
|
+
text,
|
|
115
|
+
at: now,
|
|
116
|
+
});
|
|
117
|
+
const rest = { ...result };
|
|
118
|
+
delete rest.updatedInput;
|
|
119
|
+
return rest;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** A `classic.SubagentStart` result with the hint kept for the agent that starts, if one was. */
|
|
123
|
+
export async function withDelegatedHint<R extends { additionalContext?: string[] }>(
|
|
124
|
+
$: Dollar,
|
|
125
|
+
e: { agent_id: string; agent_type: string },
|
|
126
|
+
result: R,
|
|
127
|
+
): Promise<R> {
|
|
128
|
+
if (pendingHints.length === 0) return result;
|
|
129
|
+
const now = await $.clock.now().catch(() => 0);
|
|
130
|
+
const live = (hint: (typeof pendingHints)[number]) => now - hint.at <= HINT_MS;
|
|
131
|
+
let at = -1;
|
|
132
|
+
let listed = false;
|
|
133
|
+
try {
|
|
134
|
+
const started = (await $.agent.list()).find((agent) => agent.id === e.agent_id);
|
|
135
|
+
listed = started !== undefined;
|
|
136
|
+
if (started)
|
|
137
|
+
at = pendingHints.findIndex(
|
|
138
|
+
(hint) =>
|
|
139
|
+
live(hint) && hint.type === started.type && hint.description === started.description,
|
|
140
|
+
);
|
|
141
|
+
} catch {
|
|
142
|
+
/* Matched by its type below, where that names one call. */
|
|
143
|
+
}
|
|
144
|
+
// An agent the list does not show yet is matched by its type, where one call waits for it.
|
|
145
|
+
if (at < 0 && !listed) {
|
|
146
|
+
const same = pendingHints.filter((hint) => live(hint) && hint.type === e.agent_type);
|
|
147
|
+
if (same.length === 1) at = pendingHints.indexOf(same[0]!);
|
|
148
|
+
}
|
|
149
|
+
if (at < 0) return result;
|
|
150
|
+
const [hint] = pendingHints.splice(at, 1);
|
|
151
|
+
return { ...result, additionalContext: [...(result.additionalContext ?? []), hint!.text] };
|
|
152
|
+
}
|