tenjin-cli 0.1.0-alpha.30 → 0.1.0-alpha.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -116
- package/dist/{_esm-CE7KNONL.js → _esm-RLLC72MS.js} +127 -131
- package/dist/alive-MROUMFH3.js +38 -0
- package/dist/auto-update-OPWMRZLS.js +22 -0
- package/dist/{ccip-7RMRLAGV.js → ccip-DHDFKTQV.js} +2 -2
- package/dist/chunk-2GNOFONN.js +560 -0
- package/dist/chunk-2GNOFONN.js.map +1 -0
- package/dist/{chunk-TTNESUPQ.js → chunk-2GP3HRYK.js} +2120 -193
- package/dist/chunk-2GP3HRYK.js.map +1 -0
- package/dist/chunk-3623BLPV.js +184 -0
- package/dist/chunk-3623BLPV.js.map +1 -0
- package/dist/chunk-3AIHRXKO.js +72 -0
- package/dist/chunk-3AIHRXKO.js.map +1 -0
- package/dist/chunk-3DIL66VX.js +120 -0
- package/dist/chunk-3DIL66VX.js.map +1 -0
- package/dist/{chunk-S4SAZ7OD.js → chunk-3FMZGI7I.js} +12 -2
- package/dist/{chunk-S4SAZ7OD.js.map → chunk-3FMZGI7I.js.map} +1 -1
- package/dist/chunk-3UCIG4TG.js +65 -0
- package/dist/chunk-3UCIG4TG.js.map +1 -0
- package/dist/{chunk-LFZJM56J.js → chunk-445VQTVM.js} +3 -3
- package/dist/{chunk-A36LQPHV.js → chunk-4LMUQMBH.js} +1 -1
- package/dist/{chunk-A36LQPHV.js.map → chunk-4LMUQMBH.js.map} +1 -1
- package/dist/{chunk-RAULEAZ6.js → chunk-4USCZ2NI.js} +3 -3
- package/dist/chunk-62KNUYWD.js +111 -0
- package/dist/chunk-62KNUYWD.js.map +1 -0
- package/dist/{chunk-POUWHWID.js → chunk-6CMM6YCB.js} +3 -3
- package/dist/{chunk-POUWHWID.js.map → chunk-6CMM6YCB.js.map} +1 -1
- package/dist/chunk-7WEQQJLG.js +68 -0
- package/dist/chunk-7WEQQJLG.js.map +1 -0
- package/dist/{chunk-3O2BQIF6.js → chunk-AD226HDR.js} +344 -534
- package/dist/chunk-AD226HDR.js.map +1 -0
- package/dist/chunk-ADV4LDTB.js +106 -0
- package/dist/chunk-ADV4LDTB.js.map +1 -0
- package/dist/{chunk-AWFUPKTM.js → chunk-AV5NZMYO.js} +15 -7
- package/dist/{chunk-AWFUPKTM.js.map → chunk-AV5NZMYO.js.map} +1 -1
- package/dist/chunk-B7EM4GGF.js +198 -0
- package/dist/chunk-B7EM4GGF.js.map +1 -0
- package/dist/chunk-BFDQ4WNW.js +119 -0
- package/dist/chunk-BFDQ4WNW.js.map +1 -0
- package/dist/{chunk-OSYTBCUC.js → chunk-BI673VEJ.js} +531 -503
- package/dist/chunk-BI673VEJ.js.map +1 -0
- package/dist/chunk-CEXSOI5R.js +808 -0
- package/dist/chunk-CEXSOI5R.js.map +1 -0
- package/dist/{chunk-OK2TDZQU.js → chunk-CISYM4EO.js} +9 -7
- package/dist/chunk-CISYM4EO.js.map +1 -0
- package/dist/{chunk-VFMQTSXG.js → chunk-D3ZURCG7.js} +3 -3
- package/dist/chunk-D5TOQSO4.js +474 -0
- package/dist/chunk-D5TOQSO4.js.map +1 -0
- package/dist/{chunk-P7LABKCW.js → chunk-DOQGNFHM.js} +33 -2
- package/dist/{chunk-P7LABKCW.js.map → chunk-DOQGNFHM.js.map} +1 -1
- package/dist/{chunk-QUVVWYJW.js → chunk-DRDUIZIA.js} +11 -9
- package/dist/{chunk-QUVVWYJW.js.map → chunk-DRDUIZIA.js.map} +1 -1
- package/dist/{chunk-O2FRQ2L2.js → chunk-DW4YTVR3.js} +5 -65
- package/dist/chunk-DW4YTVR3.js.map +1 -0
- package/dist/chunk-E7LGOMH6.js +449 -0
- package/dist/chunk-E7LGOMH6.js.map +1 -0
- package/dist/chunk-E7SW44LM.js +138 -0
- package/dist/chunk-E7SW44LM.js.map +1 -0
- package/dist/chunk-EDJWHDDL.js +33 -0
- package/dist/chunk-EDJWHDDL.js.map +1 -0
- package/dist/chunk-F3ED5WTR.js +13 -0
- package/dist/chunk-F3ED5WTR.js.map +1 -0
- package/dist/chunk-G75OPGAK.js +111 -0
- package/dist/chunk-G75OPGAK.js.map +1 -0
- package/dist/{chunk-YFQOA5AU.js → chunk-GAKUQHKA.js} +13 -17
- package/dist/{chunk-YFQOA5AU.js.map → chunk-GAKUQHKA.js.map} +1 -1
- package/dist/{chunk-PAYV4XUA.js → chunk-HDPUXS3Z.js} +20 -49
- package/dist/chunk-HDPUXS3Z.js.map +1 -0
- package/dist/{chunk-ORWL5BSN.js → chunk-HGZEPQUT.js} +2 -2
- package/dist/{chunk-HPWO4O6S.js → chunk-HREHWL32.js} +4 -4
- package/dist/{chunk-HPWO4O6S.js.map → chunk-HREHWL32.js.map} +1 -1
- package/dist/{chunk-VZGAONSJ.js → chunk-I5TDIUKM.js} +16 -35
- package/dist/chunk-I5TDIUKM.js.map +1 -0
- package/dist/{chunk-7QKHZQKW.js → chunk-IADZOXKN.js} +39 -6
- package/dist/chunk-IADZOXKN.js.map +1 -0
- package/dist/{chunk-U6YQ6FRI.js → chunk-IDTRSAHE.js} +32 -12
- package/dist/chunk-IDTRSAHE.js.map +1 -0
- package/dist/{chunk-SPAVAYSW.js → chunk-JEVQ5LKO.js} +7 -5
- package/dist/{chunk-SPAVAYSW.js.map → chunk-JEVQ5LKO.js.map} +1 -1
- package/dist/{chunk-EBVIKMCH.js → chunk-JKKAIPTU.js} +2 -2
- package/dist/chunk-JNJWBTU2.js +3497 -0
- package/dist/chunk-JNJWBTU2.js.map +1 -0
- package/dist/{chunk-TTBKWWTV.js → chunk-JRZBBPO6.js} +390 -146
- package/dist/chunk-JRZBBPO6.js.map +1 -0
- package/dist/{chunk-WVUSXNIE.js → chunk-MPZUYCAP.js} +9 -2
- package/dist/{chunk-WVUSXNIE.js.map → chunk-MPZUYCAP.js.map} +1 -1
- package/dist/{chunk-SJLTEINJ.js → chunk-OJNTCYQQ.js} +17 -1
- package/dist/chunk-OJNTCYQQ.js.map +1 -0
- package/dist/{chunk-IOODYAXL.js → chunk-OTWLERSW.js} +25 -6
- package/dist/chunk-OTWLERSW.js.map +1 -0
- package/dist/{chunk-AWQPGIR6.js → chunk-PJNENX2A.js} +1535 -422
- package/dist/chunk-PJNENX2A.js.map +1 -0
- package/dist/{chunk-KHE6L6TD.js → chunk-PKHI276N.js} +97 -11
- package/dist/chunk-PKHI276N.js.map +1 -0
- package/dist/{chunk-YHKXNYTB.js → chunk-QF3LSMGS.js} +2 -2
- package/dist/chunk-QXP3Z3JN.js +131 -0
- package/dist/chunk-QXP3Z3JN.js.map +1 -0
- package/dist/{chunk-XZKD7DIF.js → chunk-RL5UUDT4.js} +3 -3
- package/dist/{chunk-XZKD7DIF.js.map → chunk-RL5UUDT4.js.map} +1 -1
- package/dist/chunk-SFASB5FL.js +69 -0
- package/dist/chunk-SFASB5FL.js.map +1 -0
- package/dist/{chunk-WO5BJNIB.js → chunk-SNNSAGMT.js} +7273 -2741
- package/dist/chunk-SNNSAGMT.js.map +1 -0
- package/dist/{chunk-NZIP4PA2.js → chunk-SO3XRZPX.js} +3 -3
- package/dist/chunk-SYOS5CAC.js +176 -0
- package/dist/chunk-SYOS5CAC.js.map +1 -0
- package/dist/chunk-TAW4UFFF.js +293 -0
- package/dist/chunk-TAW4UFFF.js.map +1 -0
- package/dist/chunk-TF5HCP33.js +271 -0
- package/dist/chunk-TF5HCP33.js.map +1 -0
- package/dist/{chunk-AKWGE6JQ.js → chunk-UUGOUOVT.js} +37 -2
- package/dist/chunk-UUGOUOVT.js.map +1 -0
- package/dist/{chunk-AEG2PXBP.js → chunk-V2LQLN5H.js} +7 -7
- package/dist/{chunk-KYFZTGMC.js → chunk-VJUVFZ2D.js} +5 -3
- package/dist/{chunk-KYFZTGMC.js.map → chunk-VJUVFZ2D.js.map} +1 -1
- package/dist/{chunk-JMM6YE7J.js → chunk-VOZA6O7K.js} +708 -709
- package/dist/chunk-VOZA6O7K.js.map +1 -0
- package/dist/{chunk-5LJCEMFD.js → chunk-VUGQTZ2L.js} +209 -77
- package/dist/chunk-VUGQTZ2L.js.map +1 -0
- package/dist/chunk-WOM257PW.js +393 -0
- package/dist/chunk-WOM257PW.js.map +1 -0
- package/dist/chunk-WYXUQGOL.js +191 -0
- package/dist/chunk-WYXUQGOL.js.map +1 -0
- package/dist/chunk-X5ZBP3IY.js +97 -0
- package/dist/chunk-X5ZBP3IY.js.map +1 -0
- package/dist/chunk-XQJXNMSB.js +23 -0
- package/dist/chunk-XQJXNMSB.js.map +1 -0
- package/dist/chunk-Y527D4TV.js +56 -0
- package/dist/chunk-Y527D4TV.js.map +1 -0
- package/dist/{chunk-VUFAK2LW.js → chunk-YUY4SAGM.js} +17 -2
- package/dist/chunk-YUY4SAGM.js.map +1 -0
- package/dist/clack-EZ7TDWQU.js +19 -0
- package/dist/claude-cli-2YKABJJZ.js +31 -0
- package/dist/{cli-O5SN7ZJ4.js → cli-FB4LOA5A.js} +221 -68
- package/dist/{cli-O5SN7ZJ4.js.map → cli-FB4LOA5A.js.map} +1 -1
- package/dist/codex-event-TYVES3UX.js +16 -0
- package/dist/codex-host-WW4H2SKT.js +29 -0
- package/dist/codex-install-2C623HPW.js +393 -0
- package/dist/codex-install-2C623HPW.js.map +1 -0
- package/dist/{config-OJQI27LT.js → config-HOVJFEKD.js} +25 -15
- package/dist/doctor-NKU4V5OV.js +1312 -0
- package/dist/doctor-NKU4V5OV.js.map +1 -0
- package/dist/{env-proxy-XL4P73MZ.js → env-proxy-R6ZMLQTT.js} +6 -2
- package/dist/{ethersCompat-Df4a6QIZ-THAVUGIJ.js → ethersCompat-Df4a6QIZ-X6YZWAML.js} +3 -3
- package/dist/{fund-WEV6DMTD.js → fund-WEBHTZGN.js} +38 -30
- package/dist/{fund-WEV6DMTD.js.map → fund-WEBHTZGN.js.map} +1 -1
- package/dist/hook-command-ZA2PNKS6.js +44 -0
- package/dist/hosts/claude/.claude-plugin/marketplace.json +2 -2
- package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +3 -2
- package/dist/hosts/claude/tenjin/hooks/hooks.json +4 -1
- package/dist/hosts/claude/tenjin/hooks/register.tsx +589 -0
- package/dist/hosts/claude/tenjin/skills/tenjin-pay/SKILL.md +82 -0
- package/dist/hosts/claude/tenjin/types/index.d.ts +41 -0
- package/dist/hosts/codex/.agents/plugins/marketplace.json +20 -0
- package/dist/hosts/codex/tenjin/.codex-plugin/plugin.json +16 -0
- package/dist/hosts/codex/tenjin/.mcp.json +15 -0
- package/dist/hosts/codex/tenjin/hooks/hooks.json +98 -0
- package/dist/hosts-AV5MHBAU.js +38 -0
- package/dist/index.js +28 -8
- package/dist/index.js.map +1 -1
- package/dist/install-PT4EZS4R.js +100 -0
- package/dist/{install-identity-WHPNMNMQ.js → install-identity-5A4OE6YC.js} +13 -8
- package/dist/install-wallet-SAAPKB73.js +281 -0
- package/dist/install-wallet-SAAPKB73.js.map +1 -0
- package/dist/{mcp-QML7ZMPH.js → mcp-HAWKCTPQ.js} +909 -208
- package/dist/mcp-HAWKCTPQ.js.map +1 -0
- package/dist/{mine.wasm-6PIT3DK6.js → mine.wasm-QFAHIFPY.js} +2 -2
- package/dist/{mine.wasm-6PIT3DK6.js.map → mine.wasm-QFAHIFPY.js.map} +1 -1
- package/dist/{package-LGKYOEPV.js → package-SR2WB6MK.js} +4 -2
- package/dist/passphrase-IFTDS3CU.js +44 -0
- package/dist/{paths-POPTXJO6.js → paths-XCSAKISU.js} +10 -2
- package/dist/pay-OXC3WKYV.js +55 -0
- package/dist/pay-OXC3WKYV.js.map +1 -0
- package/dist/{payments-C44QUFXU.js → payments-3KHMP2MG.js} +18 -13
- package/dist/{payments-C44QUFXU.js.map → payments-3KHMP2MG.js.map} +1 -1
- package/dist/plugin-registration-N3GRIZVM.js +67 -0
- package/dist/plugin-registration-N3GRIZVM.js.map +1 -0
- package/dist/{redact-6W23GGJC.js → redact-D7ASVWKL.js} +2 -2
- package/dist/redact-D7ASVWKL.js.map +1 -0
- package/dist/runtime-UVNUA3AS.js +1203 -0
- package/dist/runtime-UVNUA3AS.js.map +1 -0
- package/dist/runtime-fetch-EKFRNR6Z.js +20 -0
- package/dist/runtime-fetch-EKFRNR6Z.js.map +1 -0
- package/dist/runtime-layout-BDWZG2TQ.js +25 -0
- package/dist/runtime-layout-BDWZG2TQ.js.map +1 -0
- package/dist/{send-KVJX4XIR.js → send-HMKJLT34.js} +26 -18
- package/dist/{send-KVJX4XIR.js.map → send-HMKJLT34.js.map} +1 -1
- package/dist/{status-S7C3WMSH.js → status-RWXIIWYS.js} +57 -22
- package/dist/status-RWXIIWYS.js.map +1 -0
- package/dist/{status-line-YR2T5HC4.js → status-line-77XYZP7E.js} +13 -8
- package/dist/{status-line-YR2T5HC4.js.map → status-line-77XYZP7E.js.map} +1 -1
- package/dist/uninstall-D5G67UJH.js +480 -0
- package/dist/uninstall-D5G67UJH.js.map +1 -0
- package/dist/update-LRNOEGSB.js +53 -0
- package/dist/update-LRNOEGSB.js.map +1 -0
- package/dist/{usdc-JK4RRFFQ.js → usdc-D6X7EIQ2.js} +7 -8
- package/dist/usdc-D6X7EIQ2.js.map +1 -0
- package/dist/{viemAdapter-By13KInL-X2VY6CY3.js → viemAdapter-By13KInL-RL742ETX.js} +3 -3
- package/dist/viemAdapter-By13KInL-RL742ETX.js.map +1 -0
- package/dist/wallet-XFYC27BR.js +55 -0
- package/dist/wallet-XFYC27BR.js.map +1 -0
- package/dist/wallet-kdf-worker.mjs +8 -8
- package/docs/agent-permissions.md +56 -22
- package/docs/safety-model.md +1 -1
- package/docs/troubleshooting.md +72 -1
- package/package.json +14 -1
- package/dist/alive-3J3CHOQP.js +0 -21
- package/dist/ccip-NLCSCHKI.js +0 -19
- package/dist/chunk-3O2BQIF6.js.map +0 -1
- package/dist/chunk-5IEP5EGE.js +0 -5332
- package/dist/chunk-5IEP5EGE.js.map +0 -1
- package/dist/chunk-5LJCEMFD.js.map +0 -1
- package/dist/chunk-6W5GYG3W.js +0 -128
- package/dist/chunk-6W5GYG3W.js.map +0 -1
- package/dist/chunk-7EKYXMUO.js +0 -7536
- package/dist/chunk-7EKYXMUO.js.map +0 -1
- package/dist/chunk-7QKHZQKW.js.map +0 -1
- package/dist/chunk-AKWGE6JQ.js.map +0 -1
- package/dist/chunk-AWQPGIR6.js.map +0 -1
- package/dist/chunk-EGELTSPU.js +0 -2865
- package/dist/chunk-EGELTSPU.js.map +0 -1
- package/dist/chunk-EL56RW2J.js +0 -7611
- package/dist/chunk-EL56RW2J.js.map +0 -1
- package/dist/chunk-HE2MS4QO.js +0 -256
- package/dist/chunk-HE2MS4QO.js.map +0 -1
- package/dist/chunk-IOODYAXL.js.map +0 -1
- package/dist/chunk-JMM6YE7J.js.map +0 -1
- package/dist/chunk-KHE6L6TD.js.map +0 -1
- package/dist/chunk-N35E6CM2.js +0 -1185
- package/dist/chunk-N35E6CM2.js.map +0 -1
- package/dist/chunk-O2FRQ2L2.js.map +0 -1
- package/dist/chunk-OK2TDZQU.js.map +0 -1
- package/dist/chunk-OSYTBCUC.js.map +0 -1
- package/dist/chunk-PAYV4XUA.js.map +0 -1
- package/dist/chunk-SJLTEINJ.js.map +0 -1
- package/dist/chunk-TTBKWWTV.js.map +0 -1
- package/dist/chunk-TTNESUPQ.js.map +0 -1
- package/dist/chunk-U6YQ6FRI.js.map +0 -1
- package/dist/chunk-VUFAK2LW.js.map +0 -1
- package/dist/chunk-VZGAONSJ.js.map +0 -1
- package/dist/chunk-WO5BJNIB.js.map +0 -1
- package/dist/doctor-IQQJHGGM.js +0 -590
- package/dist/doctor-IQQJHGGM.js.map +0 -1
- package/dist/hook-command-D2P3ILRV.js +0 -32
- package/dist/install-TUCRF32I.js +0 -60
- package/dist/install-wallet-MA27FTQ5.js +0 -113
- package/dist/install-wallet-MA27FTQ5.js.map +0 -1
- package/dist/mcp-QML7ZMPH.js.map +0 -1
- package/dist/pay-2C2UBBXJ.js +0 -51
- package/dist/status-S7C3WMSH.js.map +0 -1
- package/dist/uninstall-HY6LKIIT.js +0 -149
- package/dist/uninstall-HY6LKIIT.js.map +0 -1
- package/dist/update-OJV22LR3.js +0 -36
- package/dist/wallet-PD2IMZDU.js +0 -39
- /package/dist/{_esm-CE7KNONL.js.map → _esm-RLLC72MS.js.map} +0 -0
- /package/dist/{alive-3J3CHOQP.js.map → alive-MROUMFH3.js.map} +0 -0
- /package/dist/{ccip-7RMRLAGV.js.map → auto-update-OPWMRZLS.js.map} +0 -0
- /package/dist/{ccip-NLCSCHKI.js.map → ccip-DHDFKTQV.js.map} +0 -0
- /package/dist/{chunk-LFZJM56J.js.map → chunk-445VQTVM.js.map} +0 -0
- /package/dist/{chunk-RAULEAZ6.js.map → chunk-4USCZ2NI.js.map} +0 -0
- /package/dist/{chunk-VFMQTSXG.js.map → chunk-D3ZURCG7.js.map} +0 -0
- /package/dist/{chunk-ORWL5BSN.js.map → chunk-HGZEPQUT.js.map} +0 -0
- /package/dist/{chunk-EBVIKMCH.js.map → chunk-JKKAIPTU.js.map} +0 -0
- /package/dist/{chunk-YHKXNYTB.js.map → chunk-QF3LSMGS.js.map} +0 -0
- /package/dist/{chunk-NZIP4PA2.js.map → chunk-SO3XRZPX.js.map} +0 -0
- /package/dist/{chunk-AEG2PXBP.js.map → chunk-V2LQLN5H.js.map} +0 -0
- /package/dist/{config-OJQI27LT.js.map → clack-EZ7TDWQU.js.map} +0 -0
- /package/dist/{env-proxy-XL4P73MZ.js.map → claude-cli-2YKABJJZ.js.map} +0 -0
- /package/dist/{ethersCompat-Df4a6QIZ-THAVUGIJ.js.map → codex-event-TYVES3UX.js.map} +0 -0
- /package/dist/{hook-command-D2P3ILRV.js.map → codex-host-WW4H2SKT.js.map} +0 -0
- /package/dist/{install-TUCRF32I.js.map → config-HOVJFEKD.js.map} +0 -0
- /package/dist/{install-identity-WHPNMNMQ.js.map → env-proxy-R6ZMLQTT.js.map} +0 -0
- /package/dist/{package-LGKYOEPV.js.map → ethersCompat-Df4a6QIZ-X6YZWAML.js.map} +0 -0
- /package/dist/{paths-POPTXJO6.js.map → hook-command-ZA2PNKS6.js.map} +0 -0
- /package/dist/{pay-2C2UBBXJ.js.map → hosts-AV5MHBAU.js.map} +0 -0
- /package/dist/{redact-6W23GGJC.js.map → install-PT4EZS4R.js.map} +0 -0
- /package/dist/{update-OJV22LR3.js.map → install-identity-5A4OE6YC.js.map} +0 -0
- /package/dist/{usdc-JK4RRFFQ.js.map → package-SR2WB6MK.js.map} +0 -0
- /package/dist/{viemAdapter-By13KInL-X2VY6CY3.js.map → passphrase-IFTDS3CU.js.map} +0 -0
- /package/dist/{wallet-PD2IMZDU.js.map → paths-XCSAKISU.js.map} +0 -0
|
@@ -1,41 +1,54 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
isPublicAddress
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-JKKAIPTU.js";
|
|
5
|
+
import {
|
|
6
|
+
codexRouterEvent,
|
|
7
|
+
codexSession
|
|
8
|
+
} from "./chunk-SFASB5FL.js";
|
|
5
9
|
import {
|
|
6
10
|
UNREACHABLE_BACKOFF_MS,
|
|
7
11
|
clearRouterMemo,
|
|
8
12
|
readRouterMemo,
|
|
9
13
|
requestToolAccess,
|
|
10
14
|
writeRouterMemo
|
|
11
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-4USCZ2NI.js";
|
|
16
|
+
import {
|
|
17
|
+
canPayProvider,
|
|
18
|
+
canSign
|
|
19
|
+
} from "./chunk-62KNUYWD.js";
|
|
12
20
|
import {
|
|
13
21
|
readSpendSummary,
|
|
14
22
|
spentOf
|
|
15
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-SO3XRZPX.js";
|
|
16
24
|
import {
|
|
17
25
|
ChoicesSchema,
|
|
18
26
|
OfferSpecSchema,
|
|
19
27
|
ROUTER_PATH,
|
|
20
28
|
requestDecision
|
|
21
|
-
} from "./chunk-
|
|
22
|
-
import {
|
|
23
|
-
launchedByPlugin,
|
|
24
|
-
requestToolName
|
|
25
|
-
} from "./chunk-WVUSXNIE.js";
|
|
29
|
+
} from "./chunk-PKHI276N.js";
|
|
26
30
|
import {
|
|
27
31
|
FEE_REQUIRED,
|
|
28
32
|
depositSentence,
|
|
29
|
-
firstNoticeFor,
|
|
30
33
|
isFeeRequired,
|
|
31
34
|
unpaidSentence
|
|
32
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-HDPUXS3Z.js";
|
|
33
36
|
import {
|
|
34
37
|
evaluateSpendPolicy
|
|
35
38
|
} from "./chunk-2SNUOHAT.js";
|
|
39
|
+
import {
|
|
40
|
+
launchedByPlugin,
|
|
41
|
+
requestToolName
|
|
42
|
+
} from "./chunk-MPZUYCAP.js";
|
|
43
|
+
import {
|
|
44
|
+
proxyVariable
|
|
45
|
+
} from "./chunk-3FMZGI7I.js";
|
|
46
|
+
import {
|
|
47
|
+
composeUserAgent
|
|
48
|
+
} from "./chunk-OTWLERSW.js";
|
|
36
49
|
import {
|
|
37
50
|
mask
|
|
38
|
-
} from "./chunk-
|
|
51
|
+
} from "./chunk-IADZOXKN.js";
|
|
39
52
|
import {
|
|
40
53
|
augmentOf,
|
|
41
54
|
bindDecision,
|
|
@@ -51,48 +64,98 @@ import {
|
|
|
51
64
|
sessionDir,
|
|
52
65
|
wasOffered,
|
|
53
66
|
writeProgress
|
|
54
|
-
} from "./chunk-
|
|
67
|
+
} from "./chunk-IDTRSAHE.js";
|
|
55
68
|
import {
|
|
56
69
|
routerSettings
|
|
57
|
-
} from "./chunk-
|
|
70
|
+
} from "./chunk-JEVQ5LKO.js";
|
|
58
71
|
import {
|
|
59
|
-
|
|
60
|
-
} from "./chunk-
|
|
72
|
+
resolveContextSettings
|
|
73
|
+
} from "./chunk-AV5NZMYO.js";
|
|
61
74
|
import {
|
|
62
|
-
|
|
63
|
-
|
|
75
|
+
parseUsdToAtomic,
|
|
76
|
+
toMoney
|
|
77
|
+
} from "./chunk-Y527D4TV.js";
|
|
64
78
|
import {
|
|
65
|
-
|
|
66
|
-
|
|
79
|
+
noticeCleared,
|
|
80
|
+
noticeFor,
|
|
81
|
+
readWalletFacts,
|
|
82
|
+
sessionServedByPlugin,
|
|
83
|
+
settleCurrent
|
|
84
|
+
} from "./chunk-WOM257PW.js";
|
|
67
85
|
import {
|
|
68
|
-
|
|
69
|
-
|
|
86
|
+
WALLET_UNLOCKED,
|
|
87
|
+
agentFixFor
|
|
88
|
+
} from "./chunk-BFDQ4WNW.js";
|
|
70
89
|
import {
|
|
71
|
-
external_exports,
|
|
72
|
-
isSameDeployment,
|
|
73
90
|
loadRawConfig,
|
|
74
|
-
parseUsdToAtomic,
|
|
75
91
|
resolveExperimentalBazaar,
|
|
76
|
-
resolveSettings
|
|
77
|
-
|
|
78
|
-
|
|
92
|
+
resolveSettings
|
|
93
|
+
} from "./chunk-2GNOFONN.js";
|
|
94
|
+
import {
|
|
95
|
+
rememberingBalanceReader
|
|
96
|
+
} from "./chunk-DW4YTVR3.js";
|
|
97
|
+
import {
|
|
98
|
+
isSameDeployment
|
|
99
|
+
} from "./chunk-XQJXNMSB.js";
|
|
100
|
+
import {
|
|
101
|
+
external_exports
|
|
102
|
+
} from "./chunk-SNNSAGMT.js";
|
|
79
103
|
import {
|
|
80
|
-
rememberingBalanceReader,
|
|
81
104
|
writeFileAtomic,
|
|
82
105
|
writeFileAtomicExclusive
|
|
83
|
-
} from "./chunk-
|
|
84
|
-
import {
|
|
85
|
-
walletPath
|
|
86
|
-
} from "./chunk-SJLTEINJ.js";
|
|
106
|
+
} from "./chunk-7WEQQJLG.js";
|
|
87
107
|
|
|
88
108
|
// src/router/hooks.ts
|
|
89
|
-
import { readFile } from "node:fs/promises";
|
|
90
109
|
import { homedir } from "node:os";
|
|
91
110
|
|
|
92
111
|
// src/router/context.ts
|
|
93
112
|
import { open } from "node:fs/promises";
|
|
94
113
|
import { isIP } from "node:net";
|
|
95
114
|
import { dirname, join } from "node:path";
|
|
115
|
+
|
|
116
|
+
// src/router/codex-history.ts
|
|
117
|
+
function record(value) {
|
|
118
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
119
|
+
}
|
|
120
|
+
function parseCodexHistory(raw, session) {
|
|
121
|
+
const messages = [];
|
|
122
|
+
const seen = /* @__PURE__ */ new Set();
|
|
123
|
+
let owned = false;
|
|
124
|
+
for (const line of raw.split("\n")) {
|
|
125
|
+
if (!line.trim()) continue;
|
|
126
|
+
let row;
|
|
127
|
+
try {
|
|
128
|
+
row = JSON.parse(line);
|
|
129
|
+
} catch {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
if (!record(row) || !record(row.payload)) continue;
|
|
133
|
+
const p = row.payload;
|
|
134
|
+
if (row.type === "session_meta") {
|
|
135
|
+
if (owned || p.id !== session || p.session_id !== session || p.thread_source !== "user" || p.parent_thread_id != null)
|
|
136
|
+
return null;
|
|
137
|
+
owned = true;
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (!owned) return null;
|
|
141
|
+
if (row.type === "compacted" || p.type === "context_compacted" || p.type === "compaction" || p.type === "compaction_completed")
|
|
142
|
+
return null;
|
|
143
|
+
if (row.type !== "event_msg" || p.type !== "item_completed") continue;
|
|
144
|
+
if (p.thread_id !== session || !record(p.item)) return null;
|
|
145
|
+
const item = p.item;
|
|
146
|
+
if (item.type === "ContextCompaction" || item.type === "Compaction") return null;
|
|
147
|
+
const user = item.type === "UserMessage";
|
|
148
|
+
if (!user && !(item.type === "AgentMessage" && item.phase === "final_answer")) continue;
|
|
149
|
+
if (typeof item.id !== "string" || !Array.isArray(item.content)) return null;
|
|
150
|
+
if (seen.has(item.id)) continue;
|
|
151
|
+
seen.add(item.id);
|
|
152
|
+
const text = item.content.filter(record).filter((b) => b.type === (user ? "text" : "Text") && typeof b.text === "string").map((b) => b.text).join("\n");
|
|
153
|
+
if (text.trim()) messages.push({ role: user ? "user" : "assistant", text });
|
|
154
|
+
}
|
|
155
|
+
return owned && messages.some((m) => m.role === "user") ? messages : null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/router/context.ts
|
|
96
159
|
var MAX_HISTORY = 6;
|
|
97
160
|
var MAX_PACKET_BYTES = 16 * 1024;
|
|
98
161
|
var MAX_MESSAGE_CHARS = 16e3;
|
|
@@ -189,10 +252,10 @@ function isLocalTarget(raw) {
|
|
|
189
252
|
if (LOCAL_NAME.test(host)) return true;
|
|
190
253
|
return isIP(host) !== 0 && !isPublicAddress(host);
|
|
191
254
|
}
|
|
192
|
-
async function buildPromptPacket(transcriptPath, sessionId, prompt) {
|
|
255
|
+
async function buildPromptPacket(transcriptPath, sessionId, prompt, harness = "claude") {
|
|
193
256
|
const trimmed = prompt.trim();
|
|
194
257
|
const text = trimmed.length > 0 ? trimmed : "(empty prompt)";
|
|
195
|
-
const read = await readHistory(transcriptPath, { sessionId });
|
|
258
|
+
const read = await readHistory(transcriptPath, { sessionId, harness });
|
|
196
259
|
return {
|
|
197
260
|
current: { role: "user", text },
|
|
198
261
|
history: read ?? [],
|
|
@@ -201,10 +264,10 @@ async function buildPromptPacket(transcriptPath, sessionId, prompt) {
|
|
|
201
264
|
};
|
|
202
265
|
}
|
|
203
266
|
async function buildNativePacket(transcriptPath, sessionId, pending, opts = {}) {
|
|
204
|
-
const { agentId, nativeOutcome } = opts;
|
|
267
|
+
const { agentId, nativeOutcome, harness = "claude" } = opts;
|
|
205
268
|
const subject = subjectOf(pending);
|
|
206
|
-
const read = await readHistory(transcriptPath, { sessionId });
|
|
207
|
-
const own = agentId === void 0 ? null : await readHistory(subagentTranscriptPath(transcriptPath, sessionId, agentId), {
|
|
269
|
+
const read = await readHistory(transcriptPath, { sessionId, harness });
|
|
270
|
+
const own = agentId === void 0 || harness === "codex" ? null : await readHistory(subagentTranscriptPath(transcriptPath, sessionId, agentId), {
|
|
208
271
|
sessionId,
|
|
209
272
|
agentId
|
|
210
273
|
});
|
|
@@ -250,6 +313,7 @@ async function readHistory(path, scope) {
|
|
|
250
313
|
await file.close();
|
|
251
314
|
}
|
|
252
315
|
try {
|
|
316
|
+
if (scope.harness === "codex") return tail ? null : parseCodexHistory(raw, scope.sessionId);
|
|
253
317
|
const messages = parseRows(raw, scope);
|
|
254
318
|
if (tail && !messages.some((message) => message.role === "user")) {
|
|
255
319
|
if (scope.agentId === void 0) return null;
|
|
@@ -379,11 +443,23 @@ var digest = (value) => createHash("sha256").update(value).digest("hex");
|
|
|
379
443
|
function specPath(dataDir, id) {
|
|
380
444
|
return join2(dataDir, SPECS_DIR, `${digest(id)}.json`);
|
|
381
445
|
}
|
|
446
|
+
var SHOWN_KEY = "shown";
|
|
447
|
+
function shownInputField(spec) {
|
|
448
|
+
if (spec.output === "media") return null;
|
|
449
|
+
const held = spec.holds?.WebSearch ?? spec.holds?.WebFetch;
|
|
450
|
+
if (held !== void 0) return held;
|
|
451
|
+
const properties = spec.input.properties;
|
|
452
|
+
if (properties === null || typeof properties !== "object") return null;
|
|
453
|
+
const isString = (name) => properties[name]?.type === "string";
|
|
454
|
+
const required = Array.isArray(spec.input.required) ? spec.input.required.filter((name) => typeof name === "string") : [];
|
|
455
|
+
return required.find(isString) ?? Object.keys(properties).find(isString) ?? null;
|
|
456
|
+
}
|
|
382
457
|
async function storeSpecs(dataDir, specs) {
|
|
383
458
|
if (specs === void 0 || specs.length === 0) return;
|
|
384
459
|
for (const spec of specs) {
|
|
385
460
|
try {
|
|
386
|
-
|
|
461
|
+
const kept = { ...spec, [SHOWN_KEY]: shownInputField(spec) };
|
|
462
|
+
await writeFileAtomic(specPath(dataDir, spec.id), JSON.stringify(kept), {
|
|
387
463
|
mode: 384,
|
|
388
464
|
dirMode: 448
|
|
389
465
|
});
|
|
@@ -399,7 +475,9 @@ async function readSpec(dataDir, id) {
|
|
|
399
475
|
try {
|
|
400
476
|
const stat = await file.stat();
|
|
401
477
|
if (Date.now() - stat.mtimeMs > SPEC_TTL_MS || stat.size > MAX_SPEC_BYTES) return null;
|
|
402
|
-
const
|
|
478
|
+
const kept = JSON.parse(await file.readFile("utf8"));
|
|
479
|
+
delete kept[SHOWN_KEY];
|
|
480
|
+
const parsed = OfferSpecSchema.safeParse(kept);
|
|
403
481
|
return parsed.success && parsed.data.id === id ? parsed.data : null;
|
|
404
482
|
} catch {
|
|
405
483
|
return null;
|
|
@@ -485,13 +563,13 @@ async function settleSpecPayment(dataDir, id, left, now = Date.now()) {
|
|
|
485
563
|
return;
|
|
486
564
|
}
|
|
487
565
|
const at = new Date(now).toISOString();
|
|
488
|
-
const
|
|
566
|
+
const record2 = left.amountAtomic > 0n ? {
|
|
489
567
|
state: "paid",
|
|
490
568
|
at,
|
|
491
569
|
amountAtomic: left.amountAtomic.toString(),
|
|
492
570
|
...left.txHash !== void 0 ? { txHash: left.txHash } : {}
|
|
493
571
|
} : { state: "possibly_paid", at };
|
|
494
|
-
await writeFileAtomic(path, JSON.stringify(
|
|
572
|
+
await writeFileAtomic(path, JSON.stringify(record2), { mode: 384, dirMode: 448 }).catch(
|
|
495
573
|
() => void 0
|
|
496
574
|
);
|
|
497
575
|
}
|
|
@@ -636,29 +714,47 @@ function spawnPrefetch(job) {
|
|
|
636
714
|
child.on("error", () => void 0);
|
|
637
715
|
child.unref();
|
|
638
716
|
}
|
|
639
|
-
function
|
|
717
|
+
function onDeployment(value, baseUrl) {
|
|
640
718
|
let url;
|
|
641
719
|
let base;
|
|
642
720
|
try {
|
|
643
|
-
url = new URL(
|
|
721
|
+
url = new URL(value);
|
|
644
722
|
base = new URL(baseUrl);
|
|
645
723
|
} catch {
|
|
646
724
|
return null;
|
|
647
725
|
}
|
|
648
726
|
if (url.username !== "" || url.password !== "") return null;
|
|
649
|
-
|
|
727
|
+
return isSameDeployment(url.origin, base.origin) ? url : null;
|
|
728
|
+
}
|
|
729
|
+
function docsUrl(endpoint, query, baseUrl) {
|
|
730
|
+
const url = onDeployment(endpoint, baseUrl);
|
|
731
|
+
if (url === null) return null;
|
|
650
732
|
url.searchParams.set("query", query.slice(0, DOCS_QUERY_MAX));
|
|
651
733
|
return url.toString();
|
|
652
734
|
}
|
|
735
|
+
function augmentTarget(offer, query, baseUrl) {
|
|
736
|
+
if (offer.delivery === "offer") return null;
|
|
737
|
+
if (offer.delivery === "augment") {
|
|
738
|
+
if (offer.augmentUrl === void 0) return null;
|
|
739
|
+
return onDeployment(offer.augmentUrl, baseUrl)?.toString() ?? null;
|
|
740
|
+
}
|
|
741
|
+
return docsUrl(offer.endpoint, query, baseUrl);
|
|
742
|
+
}
|
|
653
743
|
async function startAugment(call, offer, baseUrl, deps) {
|
|
654
744
|
if (call.toolUseId === void 0) return false;
|
|
655
|
-
const url =
|
|
745
|
+
const url = augmentTarget(offer, call.query, baseUrl);
|
|
656
746
|
if (url === null) return false;
|
|
657
747
|
const now = deps.now?.() ?? Date.now();
|
|
658
748
|
if (!await claimQuery(deps.dataDir, call.sessionId, call.agentId, call.query, now)) {
|
|
659
749
|
return false;
|
|
660
750
|
}
|
|
661
|
-
const out = await markAugment(
|
|
751
|
+
const out = await markAugment(
|
|
752
|
+
deps.dataDir,
|
|
753
|
+
call.sessionId,
|
|
754
|
+
call.toolUseId,
|
|
755
|
+
{ provider: offer.provider, ...offer.label !== void 0 ? { label: offer.label } : {} },
|
|
756
|
+
now
|
|
757
|
+
);
|
|
662
758
|
if (out === null) return false;
|
|
663
759
|
try {
|
|
664
760
|
(deps.prefetch ?? spawnPrefetch)({ url, out, userAgent: composeUserAgent() });
|
|
@@ -684,12 +780,15 @@ async function finishAugment(call, deps) {
|
|
|
684
780
|
return {
|
|
685
781
|
updatedToolOutput: {
|
|
686
782
|
...call.search.raw,
|
|
687
|
-
results: [
|
|
783
|
+
results: [
|
|
784
|
+
docsLine(marker.label ?? `${marker.provider || "library"} docs`, text),
|
|
785
|
+
...call.search.results
|
|
786
|
+
]
|
|
688
787
|
}
|
|
689
788
|
};
|
|
690
789
|
}
|
|
691
|
-
function docsLine(
|
|
692
|
-
return `Tenjin router added ${
|
|
790
|
+
function docsLine(name, text) {
|
|
791
|
+
return `Tenjin router added ${name} for this search (free). If they don't cover it, use the web results below.
|
|
693
792
|
|
|
694
793
|
${text}`;
|
|
695
794
|
}
|
|
@@ -910,19 +1009,19 @@ function promptSkipReason(prompt) {
|
|
|
910
1009
|
}
|
|
911
1010
|
var HINT_SOURCE = "Tenjin router (installed by the user)";
|
|
912
1011
|
var BARE_CALL_RE = /(?<![\w$])request\(\{/g;
|
|
913
|
-
function toolNamed(hint, env = process.env) {
|
|
914
|
-
return hint.replace(BARE_CALL_RE, `${requestToolName(env)}({`);
|
|
1012
|
+
function toolNamed(hint, host = "claude", env = process.env) {
|
|
1013
|
+
return hint.replace(BARE_CALL_RE, `${requestToolName(host, env)}({`);
|
|
915
1014
|
}
|
|
916
|
-
function attributed(hint) {
|
|
917
|
-
return `${HINT_SOURCE}: ${toolNamed(hint)}`;
|
|
1015
|
+
function attributed(hint, host) {
|
|
1016
|
+
return `${HINT_SOURCE}: ${toolNamed(hint, host)}`;
|
|
918
1017
|
}
|
|
919
1018
|
var ONE_BLOCK = "If this does not cover it, make your own call again: you will not be redirected twice in a row for the same search or URL.";
|
|
920
1019
|
var ONE_BLOCK_QUESTION = "If this does not cover it, ask your question again: you will not be redirected twice in a row for the same question.";
|
|
921
1020
|
function savedPdfHint(path) {
|
|
922
1021
|
return `${HINT_SOURCE}: WebFetch's summary cannot read a PDF, but it saved this one whole to ${path}. Read that file for its text, free (pass pages, such as "1-10", for a long one).`;
|
|
923
1022
|
}
|
|
924
|
-
function shortfallOffer(tool, hint) {
|
|
925
|
-
return `${HINT_SOURCE}: your ${tool} call came back short. Optional: ${toolNamed(hint)}`;
|
|
1023
|
+
function shortfallOffer(tool, hint, host) {
|
|
1024
|
+
return `${HINT_SOURCE}: your ${tool} call came back short. Optional: ${toolNamed(hint, host)}`;
|
|
926
1025
|
}
|
|
927
1026
|
var NEAR_EMPTY_BYTES = 64;
|
|
928
1027
|
function shortfallOf(event) {
|
|
@@ -980,7 +1079,7 @@ async function spendShortfall(decision, deps, deadline) {
|
|
|
980
1079
|
withheld: "offer needs approval",
|
|
981
1080
|
note: `Note: ${price} ${detail}; request will pay nothing and return needs_approval with what it costs.`
|
|
982
1081
|
});
|
|
983
|
-
let
|
|
1082
|
+
let policy;
|
|
984
1083
|
try {
|
|
985
1084
|
const settings = await resolveContextSettings(hookContext(deps));
|
|
986
1085
|
const ledger = await readSpendSummary(deps.dataDir, {
|
|
@@ -991,55 +1090,87 @@ async function spendShortfall(decision, deps, deadline) {
|
|
|
991
1090
|
creator: new URL(decision.endpoint).host,
|
|
992
1091
|
sessionSpentAtomic: ledger === null ? 0n : spentOf(ledger)
|
|
993
1092
|
});
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
1093
|
+
policy = evaluation.decision !== "allow" ? approval(
|
|
1094
|
+
evaluation.reason === "above_auto_spend" ? `is above this machine's automatic per-call limit ($${toMoney(settings.policy.maxAutoSpendAtomic.toString()).usd})` : "needs approval under this machine's spend limits"
|
|
1095
|
+
) : { rpcUrl: settings.rpcUrl };
|
|
1096
|
+
} catch {
|
|
1097
|
+
policy = approval("needs approval under this machine's spend limits");
|
|
1098
|
+
}
|
|
1099
|
+
if (BigInt(decision.providerPriceAtomic) === 0n) return "rpcUrl" in policy ? null : policy;
|
|
1100
|
+
const facts = await readWalletFacts(deps.dataDir, deps.env ?? process.env);
|
|
1101
|
+
const sign = deps.signer?.() ?? canSign(facts);
|
|
1102
|
+
if (sign.status === "blocked") return cannotSign(sign);
|
|
1103
|
+
if (!("rpcUrl" in policy)) return policy;
|
|
1104
|
+
const { rpcUrl } = policy;
|
|
1105
|
+
let balance = null;
|
|
1106
|
+
if (facts.address !== null && facts.envKey !== "valid") {
|
|
1107
|
+
const readBalance = rememberingBalanceReader(deps.dataDir, {
|
|
1108
|
+
...deps.now !== void 0 ? { now: deps.now } : {}
|
|
1109
|
+
});
|
|
1110
|
+
balance = await readBalance(facts.address, rpcUrl, {
|
|
1111
|
+
timeoutMs: Math.min(BALANCE_TIMEOUT_MS, deadline - (deps.now?.() ?? Date.now())),
|
|
1112
|
+
...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {}
|
|
1113
|
+
});
|
|
1114
|
+
if (balance === null) {
|
|
1115
|
+
(deps.warn ?? ((line) => process.stderr.write(`${line}
|
|
1116
|
+
`)))(
|
|
1117
|
+
`tenjin hook: the wallet's USDC balance could not be read from ${new URL(rpcUrl).host}, so the spend policy alone decides`
|
|
997
1118
|
);
|
|
998
1119
|
}
|
|
999
|
-
rpcUrl = settings.rpcUrl;
|
|
1000
|
-
} catch {
|
|
1001
|
-
return approval("needs approval under this machine's spend limits");
|
|
1002
1120
|
}
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
`)))(
|
|
1016
|
-
`tenjin hook: the wallet's USDC balance could not be read from ${new URL(rpcUrl).host}, so the spend policy alone decides`
|
|
1017
|
-
);
|
|
1018
|
-
return null;
|
|
1121
|
+
const v = canPayProvider(
|
|
1122
|
+
{ policy: { decision: "allow" }, sign, balanceAtomic: balance },
|
|
1123
|
+
BigInt(decision.providerPriceAtomic)
|
|
1124
|
+
);
|
|
1125
|
+
if (v.status !== "blocked" || v.reason === "needs_approval") return null;
|
|
1126
|
+
if (v.reason === "wallet_short") {
|
|
1127
|
+
if (balance === null) return null;
|
|
1128
|
+
const short = BigInt(decision.providerPriceAtomic) - balance;
|
|
1129
|
+
return {
|
|
1130
|
+
withheld: "wallet needs USDC",
|
|
1131
|
+
note: `Note: the wallet holds $${toMoney(balance.toString()).usd}, $${toMoney(short.toString()).usd} short of its ${price}; fund it with \`tenjin wallet fund\`.`
|
|
1132
|
+
};
|
|
1019
1133
|
}
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1134
|
+
return cannotSign(v);
|
|
1135
|
+
}
|
|
1136
|
+
function cannotSign(v) {
|
|
1137
|
+
return {
|
|
1138
|
+
withheld: "wallet cannot sign",
|
|
1139
|
+
note: `Note: Tenjin's wallet cannot pay for this (${v.detail}); ${agentFixFor(v.reason, v.fix)}`,
|
|
1140
|
+
signBlocked: true
|
|
1141
|
+
};
|
|
1025
1142
|
}
|
|
1026
1143
|
async function vetOffer(offer, deps, deadline, canAskUser) {
|
|
1027
1144
|
const shortfall = await spendShortfall(termsOf(offer), deps, deadline);
|
|
1028
1145
|
if (shortfall === null) {
|
|
1029
|
-
const note = await overCapNote(offer
|
|
1146
|
+
const note = await overCapNote(offer, deps, canAskUser);
|
|
1030
1147
|
return { offer: note === null ? offer : { ...offer, hint: `${offer.hint} ${note}` } };
|
|
1031
1148
|
}
|
|
1032
|
-
if (offer.action === "discovered" && canAskUser) {
|
|
1149
|
+
if (offer.action === "discovered" && canAskUser && shortfall.signBlocked !== true) {
|
|
1033
1150
|
return { offer: { ...offer, hint: `${offer.hint} ${shortfall.note}` } };
|
|
1034
1151
|
}
|
|
1035
1152
|
return { withheld: shortfall.withheld };
|
|
1036
1153
|
}
|
|
1037
1154
|
var LISTED_PRICE_RE = /about \$(\d+(?:\.\d+)?)(?= per call|: request\(| \(price can vary)|\$(\d+(?:\.\d+)?)(?=\): request\(| via https?:\/\/)/g;
|
|
1038
1155
|
var QUOTED_RE = /"(?:[^"\\]|\\.)*"/g;
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
(
|
|
1042
|
-
|
|
1156
|
+
function listedPrices(offer) {
|
|
1157
|
+
if (offer.specs !== void 0) {
|
|
1158
|
+
return offer.specs.filter((spec) => spec.id !== offer.id).map((spec) => BigInt(spec.priceAtomic));
|
|
1159
|
+
}
|
|
1160
|
+
return [...offer.hint.replace(QUOTED_RE, '""').matchAll(LISTED_PRICE_RE)].flatMap((match) => {
|
|
1161
|
+
try {
|
|
1162
|
+
return [BigInt(parseUsdToAtomic(match[1] ?? match[2]))];
|
|
1163
|
+
} catch {
|
|
1164
|
+
return [];
|
|
1165
|
+
}
|
|
1166
|
+
});
|
|
1167
|
+
}
|
|
1168
|
+
function listedUsd(atomic) {
|
|
1169
|
+
const [whole, fraction = ""] = toMoney(atomic.toString()).usd.split(".");
|
|
1170
|
+
return `${whole}.${fraction.padEnd(2, "0")}`;
|
|
1171
|
+
}
|
|
1172
|
+
async function overCapNote(offer, deps, canAskUser) {
|
|
1173
|
+
const listed = listedPrices(offer);
|
|
1043
1174
|
if (listed.length === 0) return null;
|
|
1044
1175
|
let cap;
|
|
1045
1176
|
try {
|
|
@@ -1047,30 +1178,11 @@ async function overCapNote(hint, deps, canAskUser) {
|
|
|
1047
1178
|
} catch {
|
|
1048
1179
|
return null;
|
|
1049
1180
|
}
|
|
1050
|
-
const over = [
|
|
1051
|
-
...new Set(
|
|
1052
|
-
listed.filter((usd) => {
|
|
1053
|
-
try {
|
|
1054
|
-
return BigInt(parseUsdToAtomic(usd)) > cap;
|
|
1055
|
-
} catch {
|
|
1056
|
-
return false;
|
|
1057
|
-
}
|
|
1058
|
-
})
|
|
1059
|
-
)
|
|
1060
|
-
];
|
|
1181
|
+
const over = [...new Set(listed.filter((atomic) => atomic > cap).map(listedUsd))];
|
|
1061
1182
|
if (over.length === 0) return null;
|
|
1062
1183
|
const prices = over.map((usd) => `$${usd}`).join(" and ");
|
|
1063
1184
|
const which = over.length > 1 ? "those services" : "that service";
|
|
1064
|
-
return `Note: ${prices} ${over.length > 1 ? "are" : "is"} above this machine's automatic per-call limit ($${toMoney(cap.toString()).usd}), so request returns needs_approval for ${which}; ` + (canAskUser ? "prefer one within the limit
|
|
1065
|
-
}
|
|
1066
|
-
async function walletAddress(dataDir) {
|
|
1067
|
-
try {
|
|
1068
|
-
const record = JSON.parse(await readFile(walletPath(dataDir), "utf8"));
|
|
1069
|
-
const address = record?.address;
|
|
1070
|
-
return typeof address === "string" && /^0x[0-9a-fA-F]{40}$/.test(address) ? address : null;
|
|
1071
|
-
} catch {
|
|
1072
|
-
return null;
|
|
1073
|
-
}
|
|
1185
|
+
return `Note: ${prices} ${over.length > 1 ? "are" : "is"} above this machine's automatic per-call limit ($${toMoney(cap.toString()).usd}), so request returns needs_approval for ${which}; ` + (canAskUser ? "prefer one within the limit." : "use one within the limit.");
|
|
1074
1186
|
}
|
|
1075
1187
|
function agentLookup(cwd, deps) {
|
|
1076
1188
|
return { ...cwd !== void 0 ? { cwd } : {}, homeDir: deps.homeDir ?? homedir() };
|
|
@@ -1083,12 +1195,12 @@ function hookContext(deps) {
|
|
|
1083
1195
|
};
|
|
1084
1196
|
}
|
|
1085
1197
|
async function runPromptHook(raw, deps) {
|
|
1086
|
-
const event =
|
|
1198
|
+
const event = eventOf(raw, deps);
|
|
1087
1199
|
if (event?.kind !== "prompt") return { response: null };
|
|
1088
1200
|
return offerOnUserText(event, event.prompt, "UserPromptSubmit", deps);
|
|
1089
1201
|
}
|
|
1090
1202
|
async function runAnswerHook(raw, deps) {
|
|
1091
|
-
const event =
|
|
1203
|
+
const event = eventOf(raw, deps);
|
|
1092
1204
|
if (event?.kind !== "answer" || event.answers === null) return { response: null };
|
|
1093
1205
|
return offerOnUserText(event, event.answers, "PostToolUse", deps);
|
|
1094
1206
|
}
|
|
@@ -1098,11 +1210,21 @@ async function offerOnUserText(event, text, hookEventName, deps) {
|
|
|
1098
1210
|
const router = await routerFor(event.cwd, deps);
|
|
1099
1211
|
if (router === null) return { response: null };
|
|
1100
1212
|
const sealed = seal(
|
|
1101
|
-
scoped(
|
|
1213
|
+
scoped(
|
|
1214
|
+
await buildPromptPacket(event.transcriptPath, event.sessionId, text, hostOf(deps)),
|
|
1215
|
+
router.settings
|
|
1216
|
+
)
|
|
1102
1217
|
);
|
|
1103
1218
|
const footer = await openFooter(deps, event.sessionId, "prompt");
|
|
1104
1219
|
const deadline = gateDeadline(deps);
|
|
1105
|
-
const outcome = await decide(
|
|
1220
|
+
const outcome = await decide(
|
|
1221
|
+
sealed,
|
|
1222
|
+
deps,
|
|
1223
|
+
router.config,
|
|
1224
|
+
event.sessionId,
|
|
1225
|
+
deadline,
|
|
1226
|
+
footer.unpaid
|
|
1227
|
+
);
|
|
1106
1228
|
if (!isOffer(outcome)) {
|
|
1107
1229
|
await footer.close(outcome);
|
|
1108
1230
|
return { response: null, ...outcome !== null ? { action: outcome.action } : {} };
|
|
@@ -1116,7 +1238,7 @@ async function offerOnUserText(event, text, hookEventName, deps) {
|
|
|
1116
1238
|
return {
|
|
1117
1239
|
action: outcome.action,
|
|
1118
1240
|
id: outcome.id,
|
|
1119
|
-
...injection(hookEventName, attributed(vetted.offer.hint))
|
|
1241
|
+
...injection(hookEventName, attributed(vetted.offer.hint, hostOf(deps)))
|
|
1120
1242
|
};
|
|
1121
1243
|
}
|
|
1122
1244
|
function injection(hookEventName, line) {
|
|
@@ -1153,7 +1275,8 @@ async function routeNativeCall(event, pending, deps, opts = {}) {
|
|
|
1153
1275
|
scoped(
|
|
1154
1276
|
await buildNativePacket(event.transcriptPath, event.sessionId, pending, {
|
|
1155
1277
|
...event.agentId !== void 0 ? { agentId: event.agentId } : {},
|
|
1156
|
-
...nativeOutcome !== void 0 ? { nativeOutcome } : {}
|
|
1278
|
+
...nativeOutcome !== void 0 ? { nativeOutcome } : {},
|
|
1279
|
+
harness: hostOf(deps)
|
|
1157
1280
|
}),
|
|
1158
1281
|
router.settings
|
|
1159
1282
|
)
|
|
@@ -1176,7 +1299,14 @@ async function routeNativeCall(event, pending, deps, opts = {}) {
|
|
|
1176
1299
|
}
|
|
1177
1300
|
const footer = await openFooter(deps, event.sessionId, opts.operation ?? "search");
|
|
1178
1301
|
const deadline = gateDeadline(deps);
|
|
1179
|
-
const outcome = await decide(
|
|
1302
|
+
const outcome = await decide(
|
|
1303
|
+
sealed,
|
|
1304
|
+
deps,
|
|
1305
|
+
router.config,
|
|
1306
|
+
event.sessionId,
|
|
1307
|
+
deadline,
|
|
1308
|
+
footer.unpaid
|
|
1309
|
+
);
|
|
1180
1310
|
if (!isOffer(outcome)) {
|
|
1181
1311
|
await footer.close(outcome);
|
|
1182
1312
|
return {
|
|
@@ -1209,20 +1339,34 @@ async function routeNativeCall(event, pending, deps, opts = {}) {
|
|
|
1209
1339
|
return { offer: vetted.offer };
|
|
1210
1340
|
}
|
|
1211
1341
|
async function runNativeHook(raw, deps) {
|
|
1212
|
-
const event =
|
|
1342
|
+
const event = eventOf(raw, deps);
|
|
1213
1343
|
if (event?.kind !== "native" || event.pending === null) return { response: null };
|
|
1214
1344
|
const target = redirectTarget(event.pending);
|
|
1345
|
+
const targets = [...new Set((event.targets ?? [event.pending]).map(redirectTarget))];
|
|
1346
|
+
const session = localSession(event.sessionId, deps);
|
|
1347
|
+
const claim = (t) => claimRedirect(deps.dataDir, session, event.agentId, t, deps.now?.());
|
|
1215
1348
|
const routed = await routeNativeCall(event, event.pending, deps, {
|
|
1216
1349
|
passFree: true,
|
|
1217
|
-
repeated: async () =>
|
|
1218
|
-
|
|
1350
|
+
repeated: async () => {
|
|
1351
|
+
if (!await claim(target)) return true;
|
|
1352
|
+
await Promise.all(targets.filter((t) => t !== target).map(claim));
|
|
1353
|
+
return false;
|
|
1354
|
+
},
|
|
1355
|
+
redirected: async () => {
|
|
1356
|
+
for (const t of targets) {
|
|
1357
|
+
if (await redirectClaimed(deps.dataDir, session, event.agentId, t, deps.now?.())) {
|
|
1358
|
+
return true;
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
return false;
|
|
1362
|
+
}
|
|
1219
1363
|
});
|
|
1220
1364
|
if (routed.offer === null) return routed.outcome;
|
|
1221
1365
|
if (routed.free === true) {
|
|
1222
1366
|
const { pending } = event;
|
|
1223
1367
|
const augmenting = pending.tool === "WebSearch" && await startAugment(
|
|
1224
1368
|
{
|
|
1225
|
-
sessionId:
|
|
1369
|
+
sessionId: session,
|
|
1226
1370
|
query: pending.query,
|
|
1227
1371
|
...event.agentId !== void 0 ? { agentId: event.agentId } : {},
|
|
1228
1372
|
...event.toolUseId !== void 0 ? { toolUseId: event.toolUseId } : {}
|
|
@@ -1240,11 +1384,32 @@ async function runNativeHook(raw, deps) {
|
|
|
1240
1384
|
};
|
|
1241
1385
|
}
|
|
1242
1386
|
if (event.toolUseId !== void 0) {
|
|
1243
|
-
await markOffered(
|
|
1387
|
+
await markOffered(
|
|
1388
|
+
deps.dataDir,
|
|
1389
|
+
session,
|
|
1390
|
+
event.toolUseId,
|
|
1391
|
+
offeredTerms(routed.offer),
|
|
1392
|
+
deps.now?.()
|
|
1393
|
+
);
|
|
1244
1394
|
}
|
|
1245
|
-
return redirect(
|
|
1395
|
+
return redirect(
|
|
1396
|
+
routed.offer,
|
|
1397
|
+
hostOf(deps),
|
|
1398
|
+
event.rest === void 0 ? ONE_BLOCK : `${ONE_BLOCK} ${restSentence(event.rest)}`
|
|
1399
|
+
);
|
|
1400
|
+
}
|
|
1401
|
+
function restSentence(rest) {
|
|
1402
|
+
return `Nothing else in this web.run call ran either; to run the rest as written, call web.run again with exactly ${JSON.stringify(rest)}`;
|
|
1403
|
+
}
|
|
1404
|
+
function offeredTerms(offer) {
|
|
1405
|
+
const label = (offer.action === "execute" ? offer.label : void 0) ?? offer.specs?.find((spec) => spec.id === offer.id)?.label;
|
|
1406
|
+
return {
|
|
1407
|
+
offerId: offer.id,
|
|
1408
|
+
...label !== void 0 ? { label } : {},
|
|
1409
|
+
priceAtomic: termsOf(offer).providerPriceAtomic
|
|
1410
|
+
};
|
|
1246
1411
|
}
|
|
1247
|
-
function redirect(offer, oneBlock = ONE_BLOCK) {
|
|
1412
|
+
function redirect(offer, host, oneBlock = ONE_BLOCK) {
|
|
1248
1413
|
return {
|
|
1249
1414
|
response: {
|
|
1250
1415
|
hookSpecificOutput: {
|
|
@@ -1253,7 +1418,7 @@ function redirect(offer, oneBlock = ONE_BLOCK) {
|
|
|
1253
1418
|
// THE SERVER'S LINE, attributed and tool-named, then this client's one
|
|
1254
1419
|
// sentence. The line already carries the id and the exact search, URL
|
|
1255
1420
|
// or question that was denied.
|
|
1256
|
-
permissionDecisionReason: `${attributed(offer.hint)} ${oneBlock}`
|
|
1421
|
+
permissionDecisionReason: `${attributed(offer.hint, host)} ${oneBlock}`
|
|
1257
1422
|
}
|
|
1258
1423
|
},
|
|
1259
1424
|
action: offer.action,
|
|
@@ -1261,7 +1426,7 @@ function redirect(offer, oneBlock = ONE_BLOCK) {
|
|
|
1261
1426
|
};
|
|
1262
1427
|
}
|
|
1263
1428
|
async function runAskHook(raw, deps) {
|
|
1264
|
-
const event =
|
|
1429
|
+
const event = eventOf(raw, deps);
|
|
1265
1430
|
if (event?.kind !== "ask" || event.pending === null) return { response: null };
|
|
1266
1431
|
const target = redirectTarget(event.pending);
|
|
1267
1432
|
const routed = await routeNativeCall(event, event.pending, deps, {
|
|
@@ -1275,14 +1440,23 @@ async function runAskHook(raw, deps) {
|
|
|
1275
1440
|
if (routed.free === true) {
|
|
1276
1441
|
return { response: null, action: routed.offer.action, id: routed.offer.id, free: true };
|
|
1277
1442
|
}
|
|
1278
|
-
|
|
1443
|
+
if (event.toolUseId !== void 0) {
|
|
1444
|
+
await markOffered(
|
|
1445
|
+
deps.dataDir,
|
|
1446
|
+
localSession(event.sessionId, deps),
|
|
1447
|
+
event.toolUseId,
|
|
1448
|
+
offeredTerms(routed.offer),
|
|
1449
|
+
deps.now?.()
|
|
1450
|
+
);
|
|
1451
|
+
}
|
|
1452
|
+
return redirect(routed.offer, hostOf(deps), ONE_BLOCK_QUESTION);
|
|
1279
1453
|
}
|
|
1280
1454
|
async function runShortfallHook(raw, deps) {
|
|
1281
|
-
const event =
|
|
1455
|
+
const event = eventOf(raw, deps);
|
|
1282
1456
|
if (event?.kind !== "shortfall") return { response: null };
|
|
1283
1457
|
const augment = await finishAugment(
|
|
1284
1458
|
{
|
|
1285
|
-
sessionId: event.sessionId,
|
|
1459
|
+
sessionId: localSession(event.sessionId, deps),
|
|
1286
1460
|
search: event.search,
|
|
1287
1461
|
...event.toolUseId !== void 0 ? { toolUseId: event.toolUseId } : {}
|
|
1288
1462
|
},
|
|
@@ -1319,7 +1493,12 @@ async function offerOnShortfall(event, deps, docsJustMissed = false) {
|
|
|
1319
1493
|
const { nativeOutcome, pending, eventName } = event;
|
|
1320
1494
|
if (nativeOutcome === null) return { response: null };
|
|
1321
1495
|
if (pending === null) return { response: null };
|
|
1322
|
-
if (event.toolUseId !== void 0 && await wasOffered(
|
|
1496
|
+
if (event.toolUseId !== void 0 && await wasOffered(
|
|
1497
|
+
deps.dataDir,
|
|
1498
|
+
localSession(event.sessionId, deps),
|
|
1499
|
+
event.toolUseId,
|
|
1500
|
+
deps.now?.()
|
|
1501
|
+
)) {
|
|
1323
1502
|
return { response: null, nativeOutcome, alreadyOffered: true };
|
|
1324
1503
|
}
|
|
1325
1504
|
const routed = await routeNativeCall(event, pending, deps, { nativeOutcome });
|
|
@@ -1332,7 +1511,7 @@ async function offerOnShortfall(event, deps, docsJustMissed = false) {
|
|
|
1332
1511
|
hookEventName: eventName,
|
|
1333
1512
|
// THE SERVER'S LINE, attributed and framed as the option it is. It
|
|
1334
1513
|
// already carries the id and the exact search or URL that came back short.
|
|
1335
|
-
additionalContext: shortfallOffer(event.tool, routed.offer.hint)
|
|
1514
|
+
additionalContext: shortfallOffer(event.tool, routed.offer.hint, hostOf(deps))
|
|
1336
1515
|
}
|
|
1337
1516
|
},
|
|
1338
1517
|
nativeOutcome,
|
|
@@ -1341,7 +1520,7 @@ async function offerOnShortfall(event, deps, docsJustMissed = false) {
|
|
|
1341
1520
|
};
|
|
1342
1521
|
}
|
|
1343
1522
|
async function runDelegationHook(raw, deps) {
|
|
1344
|
-
const event =
|
|
1523
|
+
const event = eventOf(raw, deps);
|
|
1345
1524
|
if (event?.kind !== "delegation") return { response: null };
|
|
1346
1525
|
const { task } = event;
|
|
1347
1526
|
if (task === null || task.trim().length === 0) return { response: null };
|
|
@@ -1364,7 +1543,14 @@ async function runDelegationHook(raw, deps) {
|
|
|
1364
1543
|
if (sealed.packet.historyStatus !== "ok") return { response: null };
|
|
1365
1544
|
const footer = await openFooter(deps, event.sessionId, "delegate");
|
|
1366
1545
|
const deadline = gateDeadline(deps);
|
|
1367
|
-
const outcome = await decide(
|
|
1546
|
+
const outcome = await decide(
|
|
1547
|
+
sealed,
|
|
1548
|
+
deps,
|
|
1549
|
+
router.config,
|
|
1550
|
+
event.sessionId,
|
|
1551
|
+
deadline,
|
|
1552
|
+
footer.unpaid
|
|
1553
|
+
);
|
|
1368
1554
|
if (!isOffer(outcome)) {
|
|
1369
1555
|
await footer.close(outcome);
|
|
1370
1556
|
return { response: null, ...outcome !== null ? { action: outcome.action } : {} };
|
|
@@ -1393,6 +1579,7 @@ ${delegationOffer(outcome.hint)}`
|
|
|
1393
1579
|
};
|
|
1394
1580
|
}
|
|
1395
1581
|
async function openFooter(deps, sessionId, operation) {
|
|
1582
|
+
sessionId = localSession(sessionId, deps);
|
|
1396
1583
|
const now = () => deps.now?.() ?? Date.now();
|
|
1397
1584
|
const directory = sessionDir(deps.dataDir, sessionId);
|
|
1398
1585
|
const callId = newCallId();
|
|
@@ -1405,7 +1592,11 @@ async function openFooter(deps, sessionId, operation) {
|
|
|
1405
1592
|
);
|
|
1406
1593
|
await pruneProgress(directory, now());
|
|
1407
1594
|
await pruneSessions(deps.dataDir, now());
|
|
1595
|
+
let unpaid;
|
|
1408
1596
|
return {
|
|
1597
|
+
unpaid: (why) => {
|
|
1598
|
+
unpaid = why;
|
|
1599
|
+
},
|
|
1409
1600
|
close: async (decision, opts) => {
|
|
1410
1601
|
const withheld = opts?.withheld;
|
|
1411
1602
|
await writeProgress(
|
|
@@ -1414,7 +1605,7 @@ async function openFooter(deps, sessionId, operation) {
|
|
|
1414
1605
|
{
|
|
1415
1606
|
phase: "done",
|
|
1416
1607
|
operation,
|
|
1417
|
-
outcome: withheld !== void 0 ? `native tools (${withheld})` : hookOutcome(decision)
|
|
1608
|
+
outcome: withheld !== void 0 ? `native tools (${withheld})` : hookOutcome(decision, unpaid)
|
|
1418
1609
|
},
|
|
1419
1610
|
now()
|
|
1420
1611
|
);
|
|
@@ -1431,13 +1622,16 @@ async function openFooter(deps, sessionId, operation) {
|
|
|
1431
1622
|
}
|
|
1432
1623
|
};
|
|
1433
1624
|
}
|
|
1434
|
-
function hookOutcome(decision) {
|
|
1435
|
-
if (decision === null) return "native tools (router unavailable)";
|
|
1625
|
+
function hookOutcome(decision, unpaid) {
|
|
1436
1626
|
if (isOffer(decision)) return `paid lookup offered (${termsOf(decision).provider})`;
|
|
1437
|
-
if (decision.action === "native")
|
|
1627
|
+
if (unpaid !== void 0 && (decision === null || decision.action === "native")) {
|
|
1628
|
+
return `fee unpaid: ${unpaid}`;
|
|
1629
|
+
}
|
|
1630
|
+
if (decision === null) return "native tools (router unavailable)";
|
|
1631
|
+
if (decision.action === "native") return "native tools (router chose native)";
|
|
1438
1632
|
return "needs input";
|
|
1439
1633
|
}
|
|
1440
|
-
async function decide({ packet }, deps, config, sessionId, deadline) {
|
|
1634
|
+
async function decide({ packet }, deps, config, sessionId, deadline, unpaid) {
|
|
1441
1635
|
const baseUrl = resolveBaseUrl(deps, config);
|
|
1442
1636
|
const warn = deps.warn ?? ((line) => process.stderr.write(`${line}
|
|
1443
1637
|
`));
|
|
@@ -1456,6 +1650,7 @@ async function decide({ packet }, deps, config, sessionId, deadline) {
|
|
|
1456
1650
|
ctx: hookContext(deps),
|
|
1457
1651
|
baseUrl,
|
|
1458
1652
|
acceptsBazaar: resolveExperimentalBazaar(config).value === "on",
|
|
1653
|
+
harness: hostOf(deps),
|
|
1459
1654
|
timeoutMs: Math.max(0, deadline - now),
|
|
1460
1655
|
...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {},
|
|
1461
1656
|
...route !== null ? { route } : {}
|
|
@@ -1464,10 +1659,15 @@ async function decide({ packet }, deps, config, sessionId, deadline) {
|
|
|
1464
1659
|
const deposited = route?.deposited?.() ?? 0n;
|
|
1465
1660
|
if (deposited > 0n) deps.notice?.(depositSentence(deposited));
|
|
1466
1661
|
const why = outcome.status === "skipped" ? outcome.why : outcome.freePath ?? (outcome.status === "decided" && isFeeRequired(outcome.decision) ? FEE_REQUIRED : void 0);
|
|
1662
|
+
if (why !== void 0) unpaid?.(why);
|
|
1467
1663
|
const memoed = deps.route !== void 0 && route === null;
|
|
1468
1664
|
if (why !== void 0 && !(memoed && why === FEE_REQUIRED)) {
|
|
1469
1665
|
await tellOnce(deps, sessionId, why, now);
|
|
1470
1666
|
}
|
|
1667
|
+
if (route !== null && outcome.status === "decided" && outcome.freePath === void 0) {
|
|
1668
|
+
const cleared = await noticeCleared(deps.dataDir, sessionId, now).catch(() => null);
|
|
1669
|
+
if (cleared !== null) deps.notice?.(cleared);
|
|
1670
|
+
}
|
|
1471
1671
|
if (outcome.status === "decided" && isFeeRequired(outcome.decision)) {
|
|
1472
1672
|
await clearRouterMemo(deps.dataDir, "paid-path-absent", baseUrl);
|
|
1473
1673
|
}
|
|
@@ -1496,7 +1696,8 @@ async function decide({ packet }, deps, config, sessionId, deadline) {
|
|
|
1496
1696
|
async function tellOnce(deps, sessionId, why, now) {
|
|
1497
1697
|
const sentence = unpaidSentence(why);
|
|
1498
1698
|
if (sentence === null || deps.notice === void 0) return;
|
|
1499
|
-
|
|
1699
|
+
const told = await noticeFor(deps.dataDir, sessionId, why, now).catch(() => "quiet");
|
|
1700
|
+
if (told === "tell") deps.notice(sentence);
|
|
1500
1701
|
}
|
|
1501
1702
|
function nullStream() {
|
|
1502
1703
|
return { write: () => true };
|
|
@@ -1536,6 +1737,15 @@ async function routerFor(cwd, deps) {
|
|
|
1536
1737
|
function scoped(packet, router) {
|
|
1537
1738
|
return router.context.value === "turn" ? { ...packet, history: [] } : packet;
|
|
1538
1739
|
}
|
|
1740
|
+
function hostOf(deps) {
|
|
1741
|
+
return deps.harness ?? "claude";
|
|
1742
|
+
}
|
|
1743
|
+
function eventOf(raw, deps) {
|
|
1744
|
+
return hostOf(deps) === "codex" ? codexRouterEvent(raw) : decodeEvent(raw);
|
|
1745
|
+
}
|
|
1746
|
+
function localSession(sessionId, deps) {
|
|
1747
|
+
return hostOf(deps) === "codex" ? codexSession(sessionId) : sessionId;
|
|
1748
|
+
}
|
|
1539
1749
|
|
|
1540
1750
|
// src/router/hook-command.ts
|
|
1541
1751
|
var MAX_EVENT_BYTES = 1e6;
|
|
@@ -1545,21 +1755,55 @@ async function runHookCommand(kind, io, deps) {
|
|
|
1545
1755
|
try {
|
|
1546
1756
|
const raw = await (deps.readEvent ?? readStdin)();
|
|
1547
1757
|
const event = JSON.parse(raw);
|
|
1548
|
-
if (
|
|
1549
|
-
|
|
1758
|
+
if (deps.harness === "codex") {
|
|
1759
|
+
const { codexResponse } = await import("./codex-event-TYVES3UX.js");
|
|
1760
|
+
response = codexResponse(await runHookKind(kind, event, deps));
|
|
1761
|
+
} else {
|
|
1762
|
+
if (!launchedByPlugin(deps.env) && await sessionServedByPlugin(deps.dataDir, event)) return;
|
|
1763
|
+
response = await runHookKind(kind, event, deps);
|
|
1764
|
+
}
|
|
1550
1765
|
} catch {
|
|
1551
1766
|
response = null;
|
|
1552
1767
|
}
|
|
1553
1768
|
if (response !== null) io.stdout.write(`${JSON.stringify(response)}
|
|
1554
1769
|
`);
|
|
1555
1770
|
}
|
|
1771
|
+
function sessionIdOf(event) {
|
|
1772
|
+
if (event === null || typeof event !== "object") return null;
|
|
1773
|
+
const id = event.session_id;
|
|
1774
|
+
return typeof id === "string" && id.length > 0 && id.length <= 200 ? id : null;
|
|
1775
|
+
}
|
|
1556
1776
|
async function runHookKind(kind, event, hookDeps) {
|
|
1557
1777
|
const notices = /* @__PURE__ */ new Set();
|
|
1558
1778
|
const deps = { ...hookDeps, notice: (line) => notices.add(line) };
|
|
1559
|
-
const
|
|
1560
|
-
|
|
1779
|
+
const sessionId = sessionIdOf(event);
|
|
1780
|
+
const news = sessionId !== null && hookDeps.walletNews !== void 0 ? await hookDeps.walletNews(sessionId).catch(() => null) : null;
|
|
1781
|
+
for (const line of news?.lines ?? []) notices.add(line);
|
|
1782
|
+
let response;
|
|
1783
|
+
try {
|
|
1784
|
+
if (sessionId !== null && news?.lines.includes(WALLET_UNLOCKED) === true) {
|
|
1785
|
+
await settleCurrent(hookDeps.dataDir, sessionId, hookDeps.now?.() ?? Date.now()).catch(
|
|
1786
|
+
() => void 0
|
|
1787
|
+
);
|
|
1788
|
+
}
|
|
1789
|
+
if (sessionId !== null && news?.told !== void 0) {
|
|
1790
|
+
await noticeFor(hookDeps.dataDir, sessionId, news.told, hookDeps.now?.() ?? Date.now()).catch(
|
|
1791
|
+
() => void 0
|
|
1792
|
+
);
|
|
1793
|
+
}
|
|
1794
|
+
const outcome = kind === "prompt" ? await runPromptHook(event, deps) : kind === "native" ? await runNativeHook(event, deps) : kind === "shortfall" ? await runShortfallHook(event, deps) : kind === "ask" ? await runAskHook(event, deps) : kind === "answer" ? await runAnswerHook(event, deps) : await runDelegationHook(event, deps);
|
|
1795
|
+
response = withNotices(outcome.response, notices);
|
|
1796
|
+
} catch (err) {
|
|
1797
|
+
news?.release();
|
|
1798
|
+
throw err;
|
|
1799
|
+
}
|
|
1800
|
+
if (news !== null) await news.ack().catch(() => void 0);
|
|
1801
|
+
return response;
|
|
1802
|
+
}
|
|
1803
|
+
function withNotices(response, notices) {
|
|
1804
|
+
if (notices.size === 0) return response;
|
|
1561
1805
|
const systemMessage = [...notices].join("\n");
|
|
1562
|
-
return
|
|
1806
|
+
return response === null || typeof response !== "object" ? { systemMessage } : { ...response, systemMessage };
|
|
1563
1807
|
}
|
|
1564
1808
|
async function readStdin() {
|
|
1565
1809
|
return new Promise((resolve, reject) => {
|
|
@@ -1602,4 +1846,4 @@ export {
|
|
|
1602
1846
|
runHookCommand,
|
|
1603
1847
|
runHookKind
|
|
1604
1848
|
};
|
|
1605
|
-
//# sourceMappingURL=chunk-
|
|
1849
|
+
//# sourceMappingURL=chunk-JRZBBPO6.js.map
|