tenjin-cli 0.1.0-alpha.3 → 0.1.0-alpha.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE.md +54 -7
- package/README.md +100 -266
- package/dist/{_esm-FEASBWRP.js → _esm-MEXZI5DL.js} +9 -10
- package/dist/alive-J64H46HI.js +31 -0
- package/dist/{ccip-NQXCEK2U.js → ccip-7RMRLAGV.js} +4 -4
- package/dist/{ccip-XR5NE5QK.js → ccip-NLCSCHKI.js} +5 -5
- package/dist/chunk-27EPWVOY.js +108 -0
- package/dist/chunk-27EPWVOY.js.map +1 -0
- package/dist/chunk-2SNUOHAT.js +75 -0
- package/dist/chunk-2SNUOHAT.js.map +1 -0
- package/dist/{chunk-Z6MFJV5Z.js → chunk-2XLC3AEX.js} +857 -504
- package/dist/chunk-2XLC3AEX.js.map +1 -0
- package/dist/chunk-3623BLPV.js +184 -0
- package/dist/chunk-3623BLPV.js.map +1 -0
- package/dist/chunk-3UCIG4TG.js +65 -0
- package/dist/chunk-3UCIG4TG.js.map +1 -0
- package/dist/chunk-4ZZO6ULA.js +151 -0
- package/dist/chunk-4ZZO6ULA.js.map +1 -0
- package/dist/chunk-5C32RLTA.js +115 -0
- package/dist/chunk-5C32RLTA.js.map +1 -0
- package/dist/{chunk-ZMHYXMO6.js → chunk-5IEP5EGE.js} +3 -3
- package/dist/chunk-5K5W4S66.js +105 -0
- package/dist/chunk-5K5W4S66.js.map +1 -0
- package/dist/chunk-5MARFNSB.js +2018 -0
- package/dist/chunk-5MARFNSB.js.map +1 -0
- package/dist/{chunk-CYOF7ROH.js → chunk-6E5R45ZO.js} +3 -3
- package/dist/chunk-77TCKDEC.js +1987 -0
- package/dist/chunk-77TCKDEC.js.map +1 -0
- package/dist/chunk-7EKYXMUO.js +7536 -0
- package/dist/chunk-7EKYXMUO.js.map +1 -0
- package/dist/chunk-7Q5FDF65.js +159 -0
- package/dist/chunk-7Q5FDF65.js.map +1 -0
- package/dist/chunk-7QKHZQKW.js +1680 -0
- package/dist/chunk-7QKHZQKW.js.map +1 -0
- package/dist/{chunk-MUBUQVC3.js → chunk-7WEQQJLG.js} +6 -5
- package/dist/{chunk-MUBUQVC3.js.map → chunk-7WEQQJLG.js.map} +1 -1
- package/dist/chunk-7WU4OPLP.js +244 -0
- package/dist/chunk-7WU4OPLP.js.map +1 -0
- package/dist/chunk-7ZRL2LBQ.js +192 -0
- package/dist/chunk-7ZRL2LBQ.js.map +1 -0
- package/dist/chunk-A36LQPHV.js +29 -0
- package/dist/chunk-A36LQPHV.js.map +1 -0
- package/dist/chunk-AGZ7PJKY.js +326 -0
- package/dist/chunk-AGZ7PJKY.js.map +1 -0
- package/dist/chunk-AKWGE6JQ.js +49 -0
- package/dist/chunk-AKWGE6JQ.js.map +1 -0
- package/dist/chunk-B7HUUJOK.js +29 -0
- package/dist/chunk-B7HUUJOK.js.map +1 -0
- package/dist/{chunk-S3IGX57D.js → chunk-BL3332HQ.js} +290 -7361
- package/dist/chunk-BL3332HQ.js.map +1 -0
- package/dist/{chunk-5CLSD5YN.js → chunk-BPMWXTFX.js} +2 -2
- package/dist/chunk-D65GNPS3.js +12708 -0
- package/dist/chunk-D65GNPS3.js.map +1 -0
- package/dist/chunk-DOQGNFHM.js +121 -0
- package/dist/chunk-DOQGNFHM.js.map +1 -0
- package/dist/{chunk-YALGASEU.js → chunk-EGELTSPU.js} +2 -2
- package/dist/chunk-FW75G2W4.js +406 -0
- package/dist/chunk-FW75G2W4.js.map +1 -0
- package/dist/chunk-GA7JETVM.js +150 -0
- package/dist/chunk-GA7JETVM.js.map +1 -0
- package/dist/chunk-I3EQFHCD.js +175 -0
- package/dist/chunk-I3EQFHCD.js.map +1 -0
- package/dist/chunk-JKKAIPTU.js +108 -0
- package/dist/chunk-JKKAIPTU.js.map +1 -0
- package/dist/{chunk-QVX5MWJZ.js → chunk-JRGFKVAZ.js} +2 -2
- package/dist/{chunk-NCE5NSN6.js → chunk-K3I7C2MO.js} +142 -12
- package/dist/chunk-K3I7C2MO.js.map +1 -0
- package/dist/chunk-K72RURN3.js +239 -0
- package/dist/chunk-K72RURN3.js.map +1 -0
- package/dist/{chunk-HIVZG55D.js → chunk-KG3D7FIF.js} +2 -2
- package/dist/chunk-KOGZDMHO.js +21 -0
- package/dist/chunk-KOGZDMHO.js.map +1 -0
- package/dist/chunk-KXQ4UIP7.js +228 -0
- package/dist/chunk-KXQ4UIP7.js.map +1 -0
- package/dist/chunk-KXVP2VKA.js +194 -0
- package/dist/chunk-KXVP2VKA.js.map +1 -0
- package/dist/chunk-LEFIX6RS.js +100 -0
- package/dist/chunk-LEFIX6RS.js.map +1 -0
- package/dist/chunk-LHHMV4GU.js +27 -0
- package/dist/chunk-LHHMV4GU.js.map +1 -0
- package/dist/{chunk-YBMMV4Y4.js → chunk-MEFB5KHA.js} +13 -5
- package/dist/chunk-MEFB5KHA.js.map +1 -0
- package/dist/chunk-MNXS2U45.js +1768 -0
- package/dist/chunk-MNXS2U45.js.map +1 -0
- package/dist/{chunk-UGX7YPX2.js → chunk-NEFNKLBE.js} +9 -11
- package/dist/{chunk-UGX7YPX2.js.map → chunk-NEFNKLBE.js.map} +1 -1
- package/dist/chunk-OHRR5OYM.js +63 -0
- package/dist/chunk-OHRR5OYM.js.map +1 -0
- package/dist/chunk-ORWL5BSN.js +269 -0
- package/dist/chunk-ORWL5BSN.js.map +1 -0
- package/dist/chunk-P4NH7OUK.js +398 -0
- package/dist/chunk-P4NH7OUK.js.map +1 -0
- package/dist/{chunk-ZABPQJ3M.js → chunk-POUWHWID.js} +2 -2
- package/dist/chunk-QSCPK4F5.js +145 -0
- package/dist/chunk-QSCPK4F5.js.map +1 -0
- package/dist/chunk-QXP3Z3JN.js +131 -0
- package/dist/chunk-QXP3Z3JN.js.map +1 -0
- package/dist/{chunk-XJIW7USF.js → chunk-R5LCN54M.js} +118 -9
- package/dist/chunk-R5LCN54M.js.map +1 -0
- package/dist/chunk-S4SAZ7OD.js +30 -0
- package/dist/chunk-S4SAZ7OD.js.map +1 -0
- package/dist/chunk-SJLTEINJ.js +117 -0
- package/dist/chunk-SJLTEINJ.js.map +1 -0
- package/dist/{chunk-RRN3YTK7.js → chunk-TTNESUPQ.js} +3 -3
- package/dist/chunk-UKY4CHNC.js +498 -0
- package/dist/chunk-UKY4CHNC.js.map +1 -0
- package/dist/chunk-UQUOVWBG.js +114 -0
- package/dist/chunk-UQUOVWBG.js.map +1 -0
- package/dist/chunk-V6BSF6OC.js +260 -0
- package/dist/chunk-V6BSF6OC.js.map +1 -0
- package/dist/chunk-WJXLQXJY.js +43 -0
- package/dist/chunk-WJXLQXJY.js.map +1 -0
- package/dist/chunk-WK7F3B2E.js +114 -0
- package/dist/chunk-WK7F3B2E.js.map +1 -0
- package/dist/chunk-XKESD27X.js +10 -0
- package/dist/chunk-XKESD27X.js.map +1 -0
- package/dist/chunk-XQJXNMSB.js +23 -0
- package/dist/chunk-XQJXNMSB.js.map +1 -0
- package/dist/{chunk-HSDCI7OV.js → chunk-XZKD7DIF.js} +3 -3
- package/dist/chunk-Y527D4TV.js +56 -0
- package/dist/chunk-Y527D4TV.js.map +1 -0
- package/dist/chunk-YFPY4ONH.js +127 -0
- package/dist/chunk-YFPY4ONH.js.map +1 -0
- package/dist/{chunk-OYMYCW7J.js → chunk-YVFXE7RR.js} +606 -97
- package/dist/chunk-YVFXE7RR.js.map +1 -0
- package/dist/clack-EZ7TDWQU.js +19 -0
- package/dist/claude-cli-2YKABJJZ.js +31 -0
- package/dist/{cli-SBXI5AMS.js → cli-D5OE3URZ.js} +458 -218
- package/dist/cli-D5OE3URZ.js.map +1 -0
- package/dist/codex-event-PPNVRRDH.js +16 -0
- package/dist/codex-host-2RJOJW2B.js +28 -0
- package/dist/codex-install-UUZ6QMBQ.js +221 -0
- package/dist/codex-install-UUZ6QMBQ.js.map +1 -0
- package/dist/config-ZD4OB2DO.js +51 -0
- package/dist/dist-3LOO6M4U.js +2842 -0
- package/dist/dist-3LOO6M4U.js.map +1 -0
- package/dist/doctor-KBR34Q4B.js +601 -0
- package/dist/doctor-KBR34Q4B.js.map +1 -0
- package/dist/env-proxy-XL4P73MZ.js +15 -0
- package/dist/{ethersCompat-Df4a6QIZ-3YZIAXDK.js → ethersCompat-Df4a6QIZ-THAVUGIJ.js} +5 -5
- package/dist/ethersCompat-Df4a6QIZ-THAVUGIJ.js.map +1 -0
- package/dist/fund-5ITKQGYF.js +372 -0
- package/dist/fund-5ITKQGYF.js.map +1 -0
- package/dist/hook-command-4TYCHHRL.js +39 -0
- package/dist/hook-command-4TYCHHRL.js.map +1 -0
- package/dist/hosts/claude/.claude-plugin/marketplace.json +19 -0
- package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +15 -0
- package/dist/hosts/claude/tenjin/.mcp.json +12 -0
- package/dist/hosts/claude/tenjin/hooks/hooks.json +224 -0
- package/dist/hosts/claude/tenjin/hooks/register.tsx +589 -0
- package/dist/hosts/claude/tenjin/types/index.d.ts +41 -0
- package/dist/hosts/codex/.agents/plugins/marketplace.json +20 -0
- package/dist/hosts/codex/tenjin/.codex-plugin/plugin.json +16 -0
- package/dist/hosts/codex/tenjin/.mcp.json +12 -0
- package/dist/hosts/codex/tenjin/hooks/hooks.json +52 -0
- package/dist/hosts-FWZOV26H.js +216 -0
- package/dist/hosts-FWZOV26H.js.map +1 -0
- package/dist/index.js +21 -2
- package/dist/index.js.map +1 -1
- package/dist/install-XWGE4Q7L.js +77 -0
- package/dist/install-XWGE4Q7L.js.map +1 -0
- package/dist/install-identity-K7EJIQFP.js +30 -0
- package/dist/install-identity-K7EJIQFP.js.map +1 -0
- package/dist/install-wallet-XQ6XFZV4.js +117 -0
- package/dist/install-wallet-XQ6XFZV4.js.map +1 -0
- package/dist/mcp-3LIJSSJB.js +13553 -0
- package/dist/mcp-3LIJSSJB.js.map +1 -0
- package/dist/package-ZKQFDWLE.js +37 -0
- package/dist/package-ZKQFDWLE.js.map +1 -0
- package/dist/paths-POPTXJO6.js +61 -0
- package/dist/paths-POPTXJO6.js.map +1 -0
- package/dist/pay-WHBERZ3W.js +55 -0
- package/dist/pay-WHBERZ3W.js.map +1 -0
- package/dist/payments-KVICEKD2.js +110 -0
- package/dist/payments-KVICEKD2.js.map +1 -0
- package/dist/plugin-registration-5TIA564H.js +54 -0
- package/dist/plugin-registration-5TIA564H.js.map +1 -0
- package/dist/redact-6W23GGJC.js +15 -0
- package/dist/redact-6W23GGJC.js.map +1 -0
- package/dist/{secp256k1-N3ZHU7LB.js → secp256k1-ZZZT2CAX.js} +3 -3
- package/dist/secp256k1-ZZZT2CAX.js.map +1 -0
- package/dist/send-7G7Y7DLN.js +228 -0
- package/dist/send-7G7Y7DLN.js.map +1 -0
- package/dist/status-OF7RH5HM.js +120 -0
- package/dist/status-OF7RH5HM.js.map +1 -0
- package/dist/status-line-XOUE6MPL.js +90 -0
- package/dist/status-line-XOUE6MPL.js.map +1 -0
- package/dist/uninstall-JXUAFNDB.js +158 -0
- package/dist/uninstall-JXUAFNDB.js.map +1 -0
- package/dist/update-ZKUERSO2.js +44 -0
- package/dist/update-ZKUERSO2.js.map +1 -0
- package/dist/usdc-OGOGEHV2.js +40 -0
- package/dist/usdc-OGOGEHV2.js.map +1 -0
- package/dist/{viemAdapter-By13KInL-ZZE6UV4Y.js → viemAdapter-By13KInL-S3DA7DFW.js} +5 -5
- package/dist/viemAdapter-By13KInL-S3DA7DFW.js.map +1 -0
- package/dist/wallet-2HA6W4R4.js +43 -0
- package/dist/wallet-2HA6W4R4.js.map +1 -0
- package/dist/wallet-kdf-worker.mjs +980 -0
- package/docs/agent-permissions.md +196 -0
- package/docs/safety-model.md +59 -0
- package/docs/troubleshooting.md +13 -0
- package/package.json +28 -19
- package/LICENSE +0 -21
- package/dist/buy-EE6SEXP6.js +0 -1598
- package/dist/buy-EE6SEXP6.js.map +0 -1
- package/dist/candidate-ERMSYYQZ.js +0 -127
- package/dist/candidate-ERMSYYQZ.js.map +0 -1
- package/dist/chunk-3OV7E5G5.js +0 -18
- package/dist/chunk-3OV7E5G5.js.map +0 -1
- package/dist/chunk-4ONXEEQL.js +0 -152
- package/dist/chunk-4ONXEEQL.js.map +0 -1
- package/dist/chunk-662MSGZB.js +0 -286
- package/dist/chunk-662MSGZB.js.map +0 -1
- package/dist/chunk-7KUW4MJD.js +0 -59
- package/dist/chunk-7KUW4MJD.js.map +0 -1
- package/dist/chunk-AWPAWHNX.js +0 -333
- package/dist/chunk-AWPAWHNX.js.map +0 -1
- package/dist/chunk-DXTQ3CSI.js +0 -171
- package/dist/chunk-DXTQ3CSI.js.map +0 -1
- package/dist/chunk-ESPNTPQ2.js +0 -207
- package/dist/chunk-ESPNTPQ2.js.map +0 -1
- package/dist/chunk-FJPLRISB.js +0 -79
- package/dist/chunk-FJPLRISB.js.map +0 -1
- package/dist/chunk-GO75V3NZ.js +0 -160
- package/dist/chunk-GO75V3NZ.js.map +0 -1
- package/dist/chunk-JPHG2JW3.js +0 -96
- package/dist/chunk-JPHG2JW3.js.map +0 -1
- package/dist/chunk-NCE5NSN6.js.map +0 -1
- package/dist/chunk-OYMYCW7J.js.map +0 -1
- package/dist/chunk-RY4XKNV3.js +0 -140
- package/dist/chunk-RY4XKNV3.js.map +0 -1
- package/dist/chunk-S3IGX57D.js.map +0 -1
- package/dist/chunk-TLCMMYLY.js +0 -126
- package/dist/chunk-TLCMMYLY.js.map +0 -1
- package/dist/chunk-UO22YNY4.js +0 -69
- package/dist/chunk-UO22YNY4.js.map +0 -1
- package/dist/chunk-XHC6FCGZ.js +0 -261
- package/dist/chunk-XHC6FCGZ.js.map +0 -1
- package/dist/chunk-XJIW7USF.js.map +0 -1
- package/dist/chunk-YBMMV4Y4.js.map +0 -1
- package/dist/chunk-YN5SHIXQ.js +0 -126
- package/dist/chunk-YN5SHIXQ.js.map +0 -1
- package/dist/chunk-Z52RA3NC.js +0 -137
- package/dist/chunk-Z52RA3NC.js.map +0 -1
- package/dist/chunk-Z6MFJV5Z.js.map +0 -1
- package/dist/cli-SBXI5AMS.js.map +0 -1
- package/dist/config-VELDKLHY.js +0 -21
- package/dist/doctor-T3KWNNP2.js +0 -20
- package/dist/inspect-LMKOXE4Y.js +0 -96
- package/dist/inspect-LMKOXE4Y.js.map +0 -1
- package/dist/install-LEX3ENQ6.js +0 -387
- package/dist/install-LEX3ENQ6.js.map +0 -1
- package/dist/lookup-ZPN2Q67N.js +0 -129
- package/dist/lookup-ZPN2Q67N.js.map +0 -1
- package/dist/outcome-N7TAK6WR.js +0 -66
- package/dist/outcome-N7TAK6WR.js.map +0 -1
- package/dist/publish-BKBQQAW4.js +0 -1478
- package/dist/publish-BKBQQAW4.js.map +0 -1
- package/dist/usdc-JIAJW4SV.js +0 -22
- package/dist/wallet-CWEMYVIH.js +0 -179
- package/dist/wallet-CWEMYVIH.js.map +0 -1
- package/dist/wallet-PA54CRBL.js +0 -30
- package/skills/tenjin/SKILL.md +0 -199
- package/skills/tenjin-publish/SKILL.md +0 -111
- package/skills/tenjin-search/SKILL.md +0 -133
- /package/dist/{_esm-FEASBWRP.js.map → _esm-MEXZI5DL.js.map} +0 -0
- /package/dist/{ccip-NQXCEK2U.js.map → alive-J64H46HI.js.map} +0 -0
- /package/dist/{ccip-XR5NE5QK.js.map → ccip-7RMRLAGV.js.map} +0 -0
- /package/dist/{config-VELDKLHY.js.map → ccip-NLCSCHKI.js.map} +0 -0
- /package/dist/{chunk-ZMHYXMO6.js.map → chunk-5IEP5EGE.js.map} +0 -0
- /package/dist/{chunk-CYOF7ROH.js.map → chunk-6E5R45ZO.js.map} +0 -0
- /package/dist/{chunk-5CLSD5YN.js.map → chunk-BPMWXTFX.js.map} +0 -0
- /package/dist/{chunk-YALGASEU.js.map → chunk-EGELTSPU.js.map} +0 -0
- /package/dist/{chunk-QVX5MWJZ.js.map → chunk-JRGFKVAZ.js.map} +0 -0
- /package/dist/{chunk-HIVZG55D.js.map → chunk-KG3D7FIF.js.map} +0 -0
- /package/dist/{chunk-ZABPQJ3M.js.map → chunk-POUWHWID.js.map} +0 -0
- /package/dist/{chunk-RRN3YTK7.js.map → chunk-TTNESUPQ.js.map} +0 -0
- /package/dist/{chunk-HSDCI7OV.js.map → chunk-XZKD7DIF.js.map} +0 -0
- /package/dist/{doctor-T3KWNNP2.js.map → clack-EZ7TDWQU.js.map} +0 -0
- /package/dist/{ethersCompat-Df4a6QIZ-3YZIAXDK.js.map → claude-cli-2YKABJJZ.js.map} +0 -0
- /package/dist/{secp256k1-N3ZHU7LB.js.map → codex-event-PPNVRRDH.js.map} +0 -0
- /package/dist/{usdc-JIAJW4SV.js.map → codex-host-2RJOJW2B.js.map} +0 -0
- /package/dist/{viemAdapter-By13KInL-ZZE6UV4Y.js.map → config-ZD4OB2DO.js.map} +0 -0
- /package/dist/{wallet-PA54CRBL.js.map → env-proxy-XL4P73MZ.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/codex-bin.ts","../src/lib/codex-app-server.ts","../src/lib/codex-home.ts"],"sourcesContent":["import { statSync } from 'node:fs';\nimport { join } from 'node:path';\n\n/**\n * WHAT TO START TO RUN `codex`, WITH NO SHELL. The PATH walk tries the PATHEXT\n * extensions on win32, as `findClaudeBinary` does for `claude`. A native\n * `codex.exe` runs as found. npm's `codex.cmd` shim cannot be started without\n * a shell, so the script it points at, `@openai/codex/bin/codex.js` beside it,\n * runs under this Node instead.\n */\nexport interface CodexCommand {\n cmd: string;\n /** Arguments that go before Codex's own: the script, for an npm shim. */\n prefix: string[];\n}\n\nconst NPM_SCRIPT = ['node_modules', '@openai', 'codex', 'bin', 'codex.js'];\n\nfunction isFile(path: string): boolean {\n try {\n return statSync(path).isFile();\n } catch {\n return false;\n }\n}\n\n/** The `codex` this machine runs, or null when PATH holds none that can start. */\nexport function resolveCodex(\n env: NodeJS.ProcessEnv = process.env,\n platform: NodeJS.Platform = process.platform,\n execPath: string = process.execPath,\n): CodexCommand | null {\n const win = platform === 'win32';\n const exts = win\n ? (env.PATHEXT ?? '.EXE;.CMD;.BAT;.COM').split(';').filter((e) => e.length > 0)\n : [''];\n for (const part of (env.PATH ?? '').split(win ? ';' : ':')) {\n if (part.length === 0) continue;\n for (const ext of exts) {\n // PATHEXT is upper case; Windows matches names in any case, so try both.\n const candidate = [ext, ext.toLowerCase()].map((e) => join(part, `codex${e}`)).find(isFile);\n if (candidate === undefined) continue;\n if (/^\\.(cmd|bat)$/i.test(ext)) {\n const script = join(part, ...NPM_SCRIPT);\n if (isFile(script)) return { cmd: execPath, prefix: [script] };\n continue;\n }\n return { cmd: candidate, prefix: [] };\n }\n }\n return null;\n}\n","import { spawn } from 'node:child_process';\nimport { resolveCodex } from './codex-bin';\nimport { codexHome } from './codex-home';\nfunction isRecord(v: unknown): v is Record<string, unknown> {\n return v !== null && typeof v === 'object' && !Array.isArray(v);\n}\n\nexport async function withAppServer<T>(\n home: string,\n env: NodeJS.ProcessEnv,\n timeoutMs: number,\n fn: (request: (method: string, params: unknown) => Promise<unknown>) => Promise<T>,\n): Promise<T | null> {\n const codex = resolveCodex(env);\n if (codex === null) return null;\n let child: ReturnType<typeof spawn>;\n try {\n child = spawn(codex.cmd, [...codex.prefix, 'app-server'], {\n env: { ...env, CODEX_HOME: codexHome(home, env) },\n stdio: ['pipe', 'pipe', 'ignore'],\n windowsHide: true,\n });\n } catch {\n return null;\n }\n\n let dead = false;\n const pending = new Map<number, (value: unknown) => void>();\n const fail = (): void => {\n dead = true;\n for (const resolve of pending.values()) resolve(undefined);\n pending.clear();\n };\n child.on('error', fail);\n child.on('exit', fail);\n\n let buffered = '';\n child.stdout?.setEncoding('utf8');\n child.stdout?.on('data', (chunk: string) => {\n buffered += chunk;\n let cut = buffered.indexOf('\\n');\n while (cut !== -1) {\n const line = buffered.slice(0, cut);\n buffered = buffered.slice(cut + 1);\n cut = buffered.indexOf('\\n');\n let msg: unknown;\n try {\n msg = JSON.parse(line);\n } catch {\n continue;\n }\n if (!isRecord(msg) || typeof msg.id !== 'number') continue;\n const waiting = pending.get(msg.id);\n if (waiting === undefined) continue;\n pending.delete(msg.id);\n waiting(msg.error !== undefined ? undefined : msg.result);\n }\n });\n\n let nextId = 1;\n const send = (payload: unknown): boolean => {\n try {\n child.stdin?.write(`${JSON.stringify(payload)}\\n`);\n return true;\n } catch {\n return false;\n }\n };\n const request = async (method: string, params: unknown): Promise<unknown> => {\n if (dead) return undefined;\n const id = ++nextId;\n return await new Promise<unknown>((resolve) => {\n const timer = setTimeout(() => {\n pending.delete(id);\n resolve(undefined);\n }, timeoutMs);\n pending.set(id, (value) => {\n clearTimeout(timer);\n resolve(value);\n });\n if (!send({ jsonrpc: '2.0', id, method, params })) {\n pending.delete(id);\n clearTimeout(timer);\n resolve(undefined);\n }\n });\n };\n\n try {\n // Load-bearing in this order: a request sent before the `initialized`\n // notification is dropped with no reply and no error.\n send({\n jsonrpc: '2.0',\n id: 1,\n method: 'initialize',\n params: { clientInfo: { name: 'tenjin', title: 'tenjin', version: '1' } },\n });\n send({ jsonrpc: '2.0', method: 'initialized', params: {} });\n return await fn(request);\n } catch {\n return null;\n } finally {\n try {\n child.stdin?.end();\n } catch {\n // Already closed.\n }\n child.kill('SIGTERM');\n }\n}\n","import { join } from 'node:path';\n\n/** `$CODEX_HOME`, else `~/.codex`: the same root the CLI reads its config from. */\nexport function codexHome(home: string, env: NodeJS.ProcessEnv = process.env): string {\n const override = env.CODEX_HOME;\n return override !== undefined && override.length > 0 ? override : join(home, '.codex');\n}\n"],"mappings":";;;AAAA,SAAS,gBAAgB;AACzB,SAAS,YAAY;AAerB,IAAM,aAAa,CAAC,gBAAgB,WAAW,SAAS,OAAO,UAAU;AAEzE,SAAS,OAAO,MAAuB;AACrC,MAAI;AACF,WAAO,SAAS,IAAI,EAAE,OAAO;AAAA,EAC/B,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAGO,SAAS,aACd,MAAyB,QAAQ,KACjC,WAA4B,QAAQ,UACpC,WAAmB,QAAQ,UACN;AACrB,QAAM,MAAM,aAAa;AACzB,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I,QAAiB,CAAC,YAAY;AAC7C,YAAM,QAAQ,WAAW,MAAM;AAC7B,gBAAQ,OAAO,EAAE;AACjB,gBAAQ,MAAS;AAAA,MACnB,GAAG,SAAS;AACZ,cAAQ,IAAI,IAAI,CAAC,UAAU;AACzB,qBAAa,KAAK;AAClB,gBAAQ,KAAK;AAAA,MACf,CAAC;AACD,UAAI,CAAC,KAAK,EAAE,SAAS,OAAO,IAAI,QAAQ,OAAO,CAAC,GAAG;AACjD,gBAAQ,OAAO,EAAE;AACjB,qBAAa,KAAK;AAClB,gBAAQ,MAAS;AAAA,MACnB;AAAA,IACF,CAAC;AAAA,EACH;AAEA,MAAI;AAGF,SAAK;AAAA,MACH,SAAS;AAAA,MACT,IAAI;AAAA,MACJ,QAAQ;AAAA,MACR,QAAQ,EAAE,YAAY,EAAE,MAAM,UAAU,OAAO,UAAU,SAAS,IAAI,EAAE;AAAA,IAC1E,CAAC;AACD,SAAK,EAAE,SAAS,OAAO,QAAQ,eAAe,QAAQ,CAAC,EAAE,CAAC;AAC1D,WAAO,MAAM,GAAG,OAAO;AAAA,EACzB,QAAQ;AACN,WAAO;AAAA,EACT,UAAE;AACA,QAAI;AACF,YAAM,OAAO,IAAI;AAAA,IACnB,QAAQ;AAAA,IAER;AACA,UAAM,KAAK,SAAS;AAAA,EACtB;AACF;","names":["join"]}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// src/router/claude-cli.ts
|
|
4
|
+
import { execFile } from "node:child_process";
|
|
5
|
+
import { statSync } from "node:fs";
|
|
6
|
+
import { homedir } from "node:os";
|
|
7
|
+
import { delimiter, isAbsolute, join } from "node:path";
|
|
8
|
+
var CLAUDE_CODE_FLOOR = "2.1.287";
|
|
9
|
+
function claudeConfigDir(env, home = homedir()) {
|
|
10
|
+
const dir = env.CLAUDE_CONFIG_DIR;
|
|
11
|
+
return dir !== void 0 && dir.length > 0 ? dir : join(home, ".claude");
|
|
12
|
+
}
|
|
13
|
+
function userSettingsPath(env, home = homedir()) {
|
|
14
|
+
return join(claudeConfigDir(env, home), "settings.json");
|
|
15
|
+
}
|
|
16
|
+
function userMcpFile(env, home = homedir()) {
|
|
17
|
+
const dir = env.CLAUDE_CONFIG_DIR;
|
|
18
|
+
return dir !== void 0 && dir.length > 0 ? join(dir, ".claude.json") : join(home, ".claude.json");
|
|
19
|
+
}
|
|
20
|
+
function isFile(path) {
|
|
21
|
+
try {
|
|
22
|
+
return statSync(path).isFile();
|
|
23
|
+
} catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function findClaudeBinary(env) {
|
|
28
|
+
const exts = process.platform === "win32" ? ["", ...(env.PATHEXT ?? ".EXE;.CMD;.BAT;.COM").split(";").filter((e) => e.length > 0)] : [""];
|
|
29
|
+
for (const part of (env.PATH ?? "").split(delimiter)) {
|
|
30
|
+
if (part.length === 0) continue;
|
|
31
|
+
for (const ext of exts) {
|
|
32
|
+
const candidate = join(part, `claude${ext}`);
|
|
33
|
+
if (isFile(candidate)) return { path: candidate, source: "path" };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const exec = env.CLAUDE_CODE_EXECPATH;
|
|
37
|
+
if (exec !== void 0 && isAbsolute(exec) && isFile(exec)) {
|
|
38
|
+
return { path: exec, source: "execpath" };
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
function runClaude(bin, args, opts) {
|
|
43
|
+
return new Promise((resolve) => {
|
|
44
|
+
execFile(
|
|
45
|
+
bin.path,
|
|
46
|
+
args,
|
|
47
|
+
{
|
|
48
|
+
env: opts.env,
|
|
49
|
+
cwd: opts.cwd,
|
|
50
|
+
timeout: opts.timeoutMs ?? 3e4,
|
|
51
|
+
maxBuffer: 4 * 1024 * 1024,
|
|
52
|
+
windowsHide: true
|
|
53
|
+
},
|
|
54
|
+
(err, stdout, stderr) => {
|
|
55
|
+
const code = err === null ? 0 : typeof err.code === "number" ? err.code : null;
|
|
56
|
+
resolve({ code, stdout: String(stdout), stderr: String(stderr) });
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function jsonResult(stdout) {
|
|
62
|
+
const lines = stdout.split("\n").map((l) => l.trim());
|
|
63
|
+
for (let i = lines.length - 1; i >= 0; i -= 1) {
|
|
64
|
+
const line = lines[i];
|
|
65
|
+
if (!line.startsWith("{")) continue;
|
|
66
|
+
try {
|
|
67
|
+
const parsed = JSON.parse(line);
|
|
68
|
+
if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
69
|
+
return parsed;
|
|
70
|
+
}
|
|
71
|
+
} catch {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
function jsonList(stdout) {
|
|
78
|
+
const start = stdout.indexOf("[");
|
|
79
|
+
if (start === -1) return null;
|
|
80
|
+
try {
|
|
81
|
+
const parsed = JSON.parse(stdout.slice(start));
|
|
82
|
+
return Array.isArray(parsed) ? parsed.filter(
|
|
83
|
+
(row) => row !== null && typeof row === "object" && !Array.isArray(row)
|
|
84
|
+
) : null;
|
|
85
|
+
} catch {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function parseClaudeVersion(text) {
|
|
90
|
+
return /(\d+)\.(\d+)\.(\d+)/.exec(text)?.[0] ?? null;
|
|
91
|
+
}
|
|
92
|
+
function meetsFloor(version, floor = CLAUDE_CODE_FLOOR) {
|
|
93
|
+
const a = version.split(".").map(Number);
|
|
94
|
+
const b = floor.split(".").map(Number);
|
|
95
|
+
for (let i = 0; i < 3; i += 1) {
|
|
96
|
+
const x = a[i] ?? 0;
|
|
97
|
+
const y = b[i] ?? 0;
|
|
98
|
+
if (x !== y) return x > y;
|
|
99
|
+
}
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
var CLAUDE_UPDATE_FIX = "Run `claude update` in this session, then start a new Claude Code session so the newer version loads.";
|
|
103
|
+
async function readClaudeCode(env, cwd, find = findClaudeBinary) {
|
|
104
|
+
const binary = find(env);
|
|
105
|
+
if (binary === null) return { binary, version: null, meetsFloor: true };
|
|
106
|
+
const run = await runClaude(binary, ["--version"], { env, cwd, timeoutMs: 15e3 });
|
|
107
|
+
const version = run.code === 0 ? parseClaudeVersion(run.stdout) : null;
|
|
108
|
+
const ok = version === null || meetsFloor(version);
|
|
109
|
+
return {
|
|
110
|
+
binary,
|
|
111
|
+
version,
|
|
112
|
+
meetsFloor: ok,
|
|
113
|
+
...ok ? {} : { fix: CLAUDE_UPDATE_FIX }
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export {
|
|
118
|
+
CLAUDE_CODE_FLOOR,
|
|
119
|
+
claudeConfigDir,
|
|
120
|
+
userSettingsPath,
|
|
121
|
+
userMcpFile,
|
|
122
|
+
findClaudeBinary,
|
|
123
|
+
runClaude,
|
|
124
|
+
jsonResult,
|
|
125
|
+
jsonList,
|
|
126
|
+
parseClaudeVersion,
|
|
127
|
+
meetsFloor,
|
|
128
|
+
CLAUDE_UPDATE_FIX,
|
|
129
|
+
readClaudeCode
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=chunk-QXP3Z3JN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/router/claude-cli.ts"],"sourcesContent":["import { execFile } from 'node:child_process';\nimport { statSync } from 'node:fs';\nimport { homedir } from 'node:os';\nimport { delimiter, isAbsolute, join } from 'node:path';\n\n/**\n * CLAUDE CODE'S OWN COMMANDS, AND WHERE ITS CONFIG LIVES. Install, update,\n * uninstall and doctor register and read the plugin through `claude plugin`\n * and `claude mcp` rather than editing Claude Code's files, so every write is\n * Claude Code's and lands where it would put it. This module finds the binary,\n * runs it without a shell, and reads its `--json` answers. It never throws on a\n * failed command: each caller decides what a failure means.\n */\n\n/** The oldest Claude Code the plugin is built for: `mcp_tool` legs on a plugin server. */\nexport const CLAUDE_CODE_FLOOR = '2.1.287';\n\n/**\n * Claude Code's config directory: `CLAUDE_CONFIG_DIR` when set, else\n * `~/.claude`. Every path this CLI reads or writes for Claude Code goes through\n * here, so the plugin, the migration and doctor see the config the `claude`\n * commands they run see.\n */\nexport function claudeConfigDir(env: NodeJS.ProcessEnv, home: string = homedir()): string {\n const dir = env.CLAUDE_CONFIG_DIR;\n return dir !== undefined && dir.length > 0 ? dir : join(home, '.claude');\n}\n\n/** The user settings file, under {@link claudeConfigDir}. */\nexport function userSettingsPath(env: NodeJS.ProcessEnv, home: string = homedir()): string {\n return join(claudeConfigDir(env, home), 'settings.json');\n}\n\n/**\n * Where `claude mcp add -s user` writes: `.claude.json` inside\n * `CLAUDE_CONFIG_DIR` when it is set, else `~/.claude.json` beside `~/.claude`.\n */\nexport function userMcpFile(env: NodeJS.ProcessEnv, home: string = homedir()): string {\n const dir = env.CLAUDE_CONFIG_DIR;\n return dir !== undefined && dir.length > 0\n ? join(dir, '.claude.json')\n : join(home, '.claude.json');\n}\n\nexport interface ClaudeBinary {\n /** The absolute path this run executes. */\n path: string;\n /** `path` when found on PATH, `execpath` when it came from `CLAUDE_CODE_EXECPATH`. */\n source: 'path' | 'execpath';\n}\n\nfunction isFile(path: string): boolean {\n try {\n return statSync(path).isFile();\n } catch {\n return false;\n }\n}\n\n/**\n * THE BINARY, WITHOUT ASKING ANYONE TO INSTALL IT: `claude` on PATH first,\n * then `CLAUDE_CODE_EXECPATH`, which Claude Code exports to the commands its\n * Bash tool runs (so an agent's install finds it even where PATH does not, as\n * in Claude Desktop). Null when neither exists; the caller then writes the\n * plugin folder, which needs no binary.\n */\nexport function findClaudeBinary(env: NodeJS.ProcessEnv): ClaudeBinary | null {\n const exts =\n process.platform === 'win32'\n ? ['', ...(env.PATHEXT ?? '.EXE;.CMD;.BAT;.COM').split(';').filter((e) => e.length > 0)]\n : [''];\n for (const part of (env.PATH ?? '').split(delimiter)) {\n if (part.length === 0) continue;\n for (const ext of exts) {\n const candidate = join(part, `claude${ext}`);\n if (isFile(candidate)) return { path: candidate, source: 'path' };\n }\n }\n const exec = env.CLAUDE_CODE_EXECPATH;\n if (exec !== undefined && isAbsolute(exec) && isFile(exec)) {\n return { path: exec, source: 'execpath' };\n }\n return null;\n}\n\nexport interface ClaudeRun {\n /** The exit code, or null when the binary could not be started or was killed. */\n code: number | null;\n stdout: string;\n stderr: string;\n}\n\nexport interface ClaudeRunOptions {\n env: NodeJS.ProcessEnv;\n cwd: string;\n timeoutMs?: number;\n}\n\n/** One `claude` command, no shell. Never rejects. */\nexport function runClaude(\n bin: ClaudeBinary,\n args: string[],\n opts: ClaudeRunOptions,\n): Promise<ClaudeRun> {\n return new Promise((resolve) => {\n execFile(\n bin.path,\n args,\n {\n env: opts.env,\n cwd: opts.cwd,\n timeout: opts.timeoutMs ?? 30_000,\n maxBuffer: 4 * 1024 * 1024,\n windowsHide: true,\n },\n (err, stdout, stderr) => {\n const code =\n err === null\n ? 0\n : typeof (err as { code?: unknown }).code === 'number'\n ? (err as { code: number }).code\n : null;\n resolve({ code, stdout: String(stdout), stderr: String(stderr) });\n },\n );\n });\n}\n\n/**\n * The one result line a `--json` plugin command prints: the last stdout line\n * that parses as an object. Failures also print a human line on stderr, which\n * is ignored here.\n */\nexport function jsonResult(stdout: string): Record<string, unknown> | null {\n const lines = stdout.split('\\n').map((l) => l.trim());\n for (let i = lines.length - 1; i >= 0; i -= 1) {\n const line = lines[i]!;\n if (!line.startsWith('{')) continue;\n try {\n const parsed = JSON.parse(line) as unknown;\n if (parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)) {\n return parsed as Record<string, unknown>;\n }\n } catch {\n continue;\n }\n }\n return null;\n}\n\n/** A `--json` list (`plugin list`, `marketplace list`), or null when it is not one. */\nexport function jsonList(stdout: string): Record<string, unknown>[] | null {\n const start = stdout.indexOf('[');\n if (start === -1) return null;\n try {\n const parsed = JSON.parse(stdout.slice(start)) as unknown;\n return Array.isArray(parsed)\n ? parsed.filter(\n (row): row is Record<string, unknown> =>\n row !== null && typeof row === 'object' && !Array.isArray(row),\n )\n : null;\n } catch {\n return null;\n }\n}\n\n/** `2.1.296 (Claude Code)` to `2.1.296`. */\nexport function parseClaudeVersion(text: string): string | null {\n return /(\\d+)\\.(\\d+)\\.(\\d+)/.exec(text)?.[0] ?? null;\n}\n\n/** Is `version` at or above {@link CLAUDE_CODE_FLOOR}? */\nexport function meetsFloor(version: string, floor: string = CLAUDE_CODE_FLOOR): boolean {\n const a = version.split('.').map(Number);\n const b = floor.split('.').map(Number);\n for (let i = 0; i < 3; i += 1) {\n const x = a[i] ?? 0;\n const y = b[i] ?? 0;\n if (x !== y) return x > y;\n }\n return true;\n}\n\nexport interface ClaudeCodeState {\n binary: ClaudeBinary | null;\n /** The version `claude --version` printed, or null when it could not be read. */\n version: string | null;\n /** False only for a version read and found below the floor. */\n meetsFloor: boolean;\n /** What to do about it, worded for the session the agent runs in. */\n fix?: string;\n}\n\n/**\n * THE FLOOR'S FIX IS ONE THE AGENT RUNS: `claude update` updates the binary in\n * place, and a new session picks it up. Nobody is sent out of the session to\n * do it.\n */\nexport const CLAUDE_UPDATE_FIX =\n 'Run `claude update` in this session, then start a new Claude Code session so the newer version loads.';\n\n/** The binary and its version, read once per command. */\nexport async function readClaudeCode(\n env: NodeJS.ProcessEnv,\n cwd: string,\n find: (env: NodeJS.ProcessEnv) => ClaudeBinary | null = findClaudeBinary,\n): Promise<ClaudeCodeState> {\n const binary = find(env);\n if (binary === null) return { binary, version: null, meetsFloor: true };\n const run = await runClaude(binary, ['--version'], { env, cwd, timeoutMs: 15_000 });\n const version = run.code === 0 ? parseClaudeVersion(run.stdout) : null;\n const ok = version === null || meetsFloor(version);\n return {\n binary,\n version,\n meetsFloor: ok,\n ...(ok ? {} : { fix: CLAUDE_UPDATE_FIX }),\n };\n}\n"],"mapp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E,IACA;AAAA,EACN,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAGO,SAAS,mBAAmB,MAA6B;AAC9D,SAAO,sBAAsB,KAAK,IAAI,IAAI,CAAC,KAAK;AAClD;AAGO,SAAS,WAAW,SAAiB,QAAgB,mBAA4B;AACtF,QAAM,IAAI,QAAQ,MAAM,GAAG,EAAE,IAAI,MAAM;AACvC,QAAM,IAAI,MAAM,MAAM,GAAG,EAAE,IAAI,MAAM;AACrC,WAAS,IAAI,GAAG,IAAI,GAAG,KAAK,GAAG;AAC7B,UAAM,IAAI,EAAE,CAAC,KAAK;AAClB,UAAM,IAAI,EAAE,CAAC,KAAK;AAClB,QAAI,MAAM,EAAG,QAAO,IAAI;AAAA,EAC1B;AACA,SAAO;AACT;AAiBO,IAAM,oBACX;AAGF,eAAsB,eACpB,KACA,KACA,OAAwD,kBAC9B;AAC1B,QAAM,SAAS,KAAK,GAAG;AACvB,MAAI,WAAW,KAAM,QAAO,EAAE,QAAQ,SAAS,MAAM,YAAY,KAAK;AACtE,QAAM,MAAM,MAAM,UAAU,QAAQ,CAAC,WAAW,GAAG,EAAE,KAAK,KAAK,WAAW,KAAO,CAAC;AAClF,QAAM,UAAU,IAAI,SAAS,IAAI,mBAAmB,IAAI,MAAM,IAAI;AAClE,QAAM,KAAK,YAAY,QAAQ,WAAW,OAAO;AACjD,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,YAAY;AAAA,IACZ,GAAI,KAAK,CAAC,IAAI,EAAE,KAAK,kBAAkB;AAAA,EACzC;AACF;","names":[]}
|
|
@@ -7,14 +7,16 @@ import {
|
|
|
7
7
|
defineTransactionReceipt,
|
|
8
8
|
formatTransaction,
|
|
9
9
|
http
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-NEFNKLBE.js";
|
|
11
11
|
import {
|
|
12
12
|
serializeTransaction,
|
|
13
13
|
toRlp
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-K3I7C2MO.js";
|
|
15
15
|
import {
|
|
16
|
+
decodeFunctionData,
|
|
17
|
+
encodeFunctionData,
|
|
16
18
|
erc20Abi
|
|
17
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-5IEP5EGE.js";
|
|
18
20
|
import {
|
|
19
21
|
InvalidAddressError,
|
|
20
22
|
concatHex,
|
|
@@ -22,7 +24,10 @@ import {
|
|
|
22
24
|
hexToNumber,
|
|
23
25
|
isAddress,
|
|
24
26
|
toHex
|
|
25
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-EGELTSPU.js";
|
|
28
|
+
import {
|
|
29
|
+
USDC_ADDRESS
|
|
30
|
+
} from "./chunk-27EPWVOY.js";
|
|
26
31
|
|
|
27
32
|
// node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/_esm/op-stack/contracts.js
|
|
28
33
|
var contracts = {
|
|
@@ -197,21 +202,125 @@ var basePreconf = /* @__PURE__ */ defineChain({
|
|
|
197
202
|
});
|
|
198
203
|
|
|
199
204
|
// src/lib/usdc.ts
|
|
200
|
-
var
|
|
205
|
+
var USDC_ADDRESS2 = USDC_ADDRESS;
|
|
201
206
|
var USDC_DECIMALS = 6;
|
|
202
207
|
async function getUsdcBalance(address, rpcUrl) {
|
|
203
208
|
const client = createPublicClient({ chain: base, transport: http(rpcUrl) });
|
|
204
209
|
return client.readContract({
|
|
205
|
-
address:
|
|
210
|
+
address: USDC_ADDRESS2,
|
|
206
211
|
abi: erc20Abi,
|
|
207
212
|
functionName: "balanceOf",
|
|
208
213
|
args: [address]
|
|
209
214
|
});
|
|
210
215
|
}
|
|
216
|
+
var SEND_GAS_CAP = 150000n;
|
|
217
|
+
var SEND_MAX_FEE_PER_GAS_CAP = 10000000000n;
|
|
218
|
+
var SEND_MAX_PRIORITY_FEE_CAP = 2000000000n;
|
|
219
|
+
var FeeCapExceededError = class extends Error {
|
|
220
|
+
constructor(field, value, cap) {
|
|
221
|
+
super(`${field} estimate ${value} exceeds the send ceiling ${cap}`);
|
|
222
|
+
this.name = "FeeCapExceededError";
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
var SendRevertedError = class extends Error {
|
|
226
|
+
constructor(txHash) {
|
|
227
|
+
super(`Transaction ${txHash} reverted`);
|
|
228
|
+
this.txHash = txHash;
|
|
229
|
+
this.name = "SendRevertedError";
|
|
230
|
+
}
|
|
231
|
+
txHash;
|
|
232
|
+
};
|
|
233
|
+
var SendPendingError = class extends Error {
|
|
234
|
+
constructor(txHash) {
|
|
235
|
+
super(`Transaction ${txHash} was broadcast but not confirmed in time`);
|
|
236
|
+
this.txHash = txHash;
|
|
237
|
+
this.name = "SendPendingError";
|
|
238
|
+
}
|
|
239
|
+
txHash;
|
|
240
|
+
};
|
|
241
|
+
async function prepareUsdcSend({
|
|
242
|
+
from,
|
|
243
|
+
to,
|
|
244
|
+
amountAtomic,
|
|
245
|
+
rpcUrl
|
|
246
|
+
}) {
|
|
247
|
+
const client = createPublicClient({ chain: base, transport: http(rpcUrl) });
|
|
248
|
+
const data = encodeFunctionData({
|
|
249
|
+
abi: erc20Abi,
|
|
250
|
+
functionName: "transfer",
|
|
251
|
+
args: [to, amountAtomic]
|
|
252
|
+
});
|
|
253
|
+
const [nonce, gas, fees, ethBalanceWei] = await Promise.all([
|
|
254
|
+
client.getTransactionCount({ address: from, blockTag: "pending" }),
|
|
255
|
+
client.estimateGas({ account: from, to: USDC_ADDRESS2, data }),
|
|
256
|
+
client.estimateFeesPerGas(),
|
|
257
|
+
client.getBalance({ address: from })
|
|
258
|
+
]);
|
|
259
|
+
assertUnderCap("gas", gas, SEND_GAS_CAP);
|
|
260
|
+
assertUnderCap("maxFeePerGas", fees.maxFeePerGas, SEND_MAX_FEE_PER_GAS_CAP);
|
|
261
|
+
assertUnderCap("maxPriorityFeePerGas", fees.maxPriorityFeePerGas, SEND_MAX_PRIORITY_FEE_CAP);
|
|
262
|
+
return {
|
|
263
|
+
to,
|
|
264
|
+
amountAtomic,
|
|
265
|
+
data,
|
|
266
|
+
nonce,
|
|
267
|
+
gas,
|
|
268
|
+
maxFeePerGas: fees.maxFeePerGas,
|
|
269
|
+
maxPriorityFeePerGas: fees.maxPriorityFeePerGas,
|
|
270
|
+
feeWei: gas * fees.maxFeePerGas,
|
|
271
|
+
ethBalanceWei
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
async function broadcastUsdcSend({
|
|
275
|
+
signer,
|
|
276
|
+
prepared,
|
|
277
|
+
rpcUrl,
|
|
278
|
+
receiptTimeoutMs = 12e4
|
|
279
|
+
}) {
|
|
280
|
+
const client = createPublicClient({ chain: base, transport: http(rpcUrl) });
|
|
281
|
+
const decoded = decodeFunctionData({ abi: erc20Abi, data: prepared.data });
|
|
282
|
+
if (decoded.functionName !== "transfer" || decoded.args[0].toLowerCase() !== prepared.to.toLowerCase() || decoded.args[1] !== prepared.amountAtomic) {
|
|
283
|
+
throw new Error(
|
|
284
|
+
"Prepared calldata does not decode to the previewed recipient and amount; nothing was signed."
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
const serializedTransaction = await signer.signTransaction({
|
|
288
|
+
type: "eip1559",
|
|
289
|
+
chainId: base.id,
|
|
290
|
+
to: USDC_ADDRESS2,
|
|
291
|
+
// Explicitly zero: an ERC-20 transfer carries no native value (test-pinned).
|
|
292
|
+
value: 0n,
|
|
293
|
+
data: prepared.data,
|
|
294
|
+
nonce: prepared.nonce,
|
|
295
|
+
gas: prepared.gas,
|
|
296
|
+
maxFeePerGas: prepared.maxFeePerGas,
|
|
297
|
+
maxPriorityFeePerGas: prepared.maxPriorityFeePerGas
|
|
298
|
+
});
|
|
299
|
+
const txHash = await client.sendRawTransaction({ serializedTransaction });
|
|
300
|
+
let receipt;
|
|
301
|
+
try {
|
|
302
|
+
receipt = await client.waitForTransactionReceipt({ hash: txHash, timeout: receiptTimeoutMs });
|
|
303
|
+
} catch {
|
|
304
|
+
throw new SendPendingError(txHash);
|
|
305
|
+
}
|
|
306
|
+
if (receipt.status !== "success") throw new SendRevertedError(txHash);
|
|
307
|
+
return txHash;
|
|
308
|
+
}
|
|
309
|
+
function assertUnderCap(field, value, cap) {
|
|
310
|
+
if (value > cap) throw new FeeCapExceededError(field, value, cap);
|
|
311
|
+
}
|
|
211
312
|
|
|
212
313
|
export {
|
|
213
|
-
USDC_ADDRESS,
|
|
314
|
+
USDC_ADDRESS2 as USDC_ADDRESS,
|
|
214
315
|
USDC_DECIMALS,
|
|
215
|
-
getUsdcBalance
|
|
316
|
+
getUsdcBalance,
|
|
317
|
+
SEND_GAS_CAP,
|
|
318
|
+
SEND_MAX_FEE_PER_GAS_CAP,
|
|
319
|
+
SEND_MAX_PRIORITY_FEE_CAP,
|
|
320
|
+
FeeCapExceededError,
|
|
321
|
+
SendRevertedError,
|
|
322
|
+
SendPendingError,
|
|
323
|
+
prepareUsdcSend,
|
|
324
|
+
broadcastUsdcSend
|
|
216
325
|
};
|
|
217
|
-
//# sourceMappingURL=chunk-
|
|
326
|
+
//# sourceMappingURL=chunk-R5LCN54M.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/op-stack/contracts.ts","../node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/op-stack/formatters.ts","../node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/op-stack/serializers.ts","../node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/op-stack/chainConfig.ts","../node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/chains/definitions/base.ts","../src/lib/usdc.ts"],"sourcesContent":["import type { Chain } from '../types/chain.js'\n\n/**\n * Predeploy contracts for OP Stack.\n * @see https://github.com/ethereum-optimism/optimism/blob/develop/specs/predeploys.md\n */\nexport const contracts = {\n gasPriceOracle: { address: '0x420000000000000000000000000000000000000F' },\n l1Block: { address: '0x4200000000000000000000000000000000000015' },\n l2CrossDomainMessenger: {\n address: '0x4200000000000000000000000000000000000007',\n },\n l2Erc721Bridge: { address: '0x4200000000000000000000000000000000000014' },\n l2StandardBridge: { address: '0x4200000000000000000000000000000000000010' },\n l2ToL1MessagePasser: {\n address: '0x4200000000000000000000000000000000000016',\n },\n} as const satisfies Chain['contracts']\n","import type { ChainFormatters } from '../types/chain.js'\nimport type { RpcTransaction } from '../types/rpc.js'\nimport { hexToBigInt, hexToNumber } from '../utils/encoding/fromHex.js'\nimport { defineBlock } from '../utils/formatters/block.js'\nimport {\n defineTransaction,\n formatTransaction,\n} from '../utils/formatters/transaction.js'\nimport { defineTransactionReceipt } from '../utils/formatters/transactionReceipt.js'\nimport type { OpStackBlock, OpStackRpcBlock } from './types/block.js'\nimport type {\n OpStackRpcTransaction,\n OpStackRpcTransactionReceipt,\n OpStackTransaction,\n OpStackTransactionReceipt,\n} from './types/transaction.js'\n\nexport const formatters = {\n block: /*#__PURE__*/ defineBlock({\n format(args: OpStackRpcBlock): OpStackBlock {\n const transactions = args.transactions?.map((transaction) => {\n if (typeof transaction === 'string') return transaction\n const formatted = formatTransaction(\n transaction as RpcTransaction,\n ) as OpStackTransaction\n if (formatted.typeHex === '0x7e') {\n formatted.isSystemTx = transaction.isSystemTx\n formatted.mint = transaction.mint\n ? hexToBigInt(transaction.mint)\n : undefined\n formatted.sourceHash = transaction.sourceHash\n formatted.type = 'deposit'\n }\n return formatted\n })\n return {\n transactions,\n stateRoot: args.stateRoot,\n } as OpStackBlock\n },\n }),\n transaction: /*#__PURE__*/ defineTransaction({\n format(args: OpStackRpcTransaction): OpStackTransaction {\n const transaction = {} as OpStackTransaction\n if (args.type === '0x7e') {\n transaction.isSystemTx = args.isSystemTx\n transaction.mint = args.mint ? hexToBigInt(args.mint) : undefined\n transaction.sourceHash = args.sourceHash\n transaction.type = 'deposit'\n }\n return transaction\n },\n }),\n transactionReceipt: /*#__PURE__*/ defineTransactionReceipt({\n format(args: OpStackRpcTransactionReceipt): OpStackTransactionReceipt {\n return {\n ...(args.depositNonce\n ? { depositNonce: hexToBigInt(args.depositNonce) }\n : {}),\n ...(args.depositReceiptVersion\n ? { depositReceiptVersion: hexToNumber(args.depositReceiptVersion) }\n : {}),\n l1GasPrice: args.l1GasPrice ? hexToBigInt(args.l1GasPrice) : null,\n l1GasUsed: args.l1GasUsed ? hexToBigInt(args.l1GasUsed) : null,\n l1Fee: args.l1Fee ? hexToBigInt(args.l1Fee) : null,\n l1FeeScalar: args.l1FeeScalar ? Number(args.l1FeeScalar) : null,\n } as OpStackTransactionReceipt\n },\n }),\n} as const satisfies ChainFormatters\n","import { InvalidAddressError } from '../errors/address.js'\nimport type { ErrorType } from '../errors/utils.js'\nimport type { ChainSerializers } from '../types/chain.js'\nimport type { Hex, Signature } from '../types/misc.js'\nimport type { TransactionSerializable } from '../types/transaction.js'\nimport type { RequiredBy } from '../types/utils.js'\nimport { isAddress } from '../utils/address/isAddress.js'\nimport { concatHex } from '../utils/data/concat.js'\nimport { toHex } from '../utils/encoding/toHex.js'\nimport { toRlp } from '../utils/encoding/toRlp.js'\nimport {\n type SerializeTransactionErrorType as SerializeTransactionErrorType_,\n serializeTransaction as serializeTransaction_,\n} from '../utils/transaction/serializeTransaction.js'\nimport type {\n OpStackTransactionSerializable,\n TransactionSerializableDeposit,\n TransactionSerializedDeposit,\n} from './types/transaction.js'\n\nexport type SerializeTransactionReturnType = ReturnType<\n typeof serializeTransaction\n>\n\nexport type SerializeTransactionErrorType =\n | SerializeTransactionErrorType_\n | ErrorType\n\nexport function serializeTransaction(\n transaction: OpStackTransactionSerializable,\n signature?: Signature,\n) {\n if (isDeposit(transaction)) return serializeTransactionDeposit(transaction)\n return serializeTransaction_(\n transaction as TransactionSerializable,\n signature,\n )\n}\n\nexport const serializers = {\n transaction: serializeTransaction,\n} as const satisfies ChainSerializers\n\n//////////////////////////////////////////////////////////////////////////////\n// Serializers\n\nexport type SerializeTransactionDepositReturnType = TransactionSerializedDeposit\n\nfunction serializeTransactionDeposit(\n transaction: TransactionSerializableDeposit,\n): SerializeTransactionDepositReturnType {\n assertTransactionDeposit(transaction)\n\n const { sourceHash, data, from, gas, isSystemTx, mint, to, value } =\n transaction\n\n const serializedTransaction: Hex[] = [\n sourceHash,\n from,\n to ?? '0x',\n mint ? toHex(mint) : '0x',\n value ? toHex(value) : '0x',\n gas ? toHex(gas) : '0x',\n isSystemTx ? '0x1' : '0x',\n data ?? '0x',\n ]\n\n return concatHex([\n '0x7e',\n toRlp(serializedTransaction),\n ]) as SerializeTransactionDepositReturnType\n}\n\nfunction isDeposit(\n transaction: OpStackTransactionSerializable,\n): transaction is RequiredBy<TransactionSerializableDeposit, 'type'> {\n if (transaction.type === 'deposit') return true\n if (typeof transaction.sourceHash !== 'undefined') return true\n return false\n}\n\nexport function assertTransactionDeposit(\n transaction: TransactionSerializableDeposit,\n) {\n const { from, to } = transaction\n if (from && !isAddress(from)) throw new InvalidAddressError({ address: from })\n if (to && !isAddress(to)) throw new InvalidAddressError({ address: to })\n}\n","import { contracts } from './contracts.js'\nimport { formatters } from './formatters.js'\nimport { serializers } from './serializers.js'\n\nexport const chainConfig = {\n blockTime: 2_000,\n contracts,\n formatters,\n serializers,\n} as const\n","import { chainConfig } from '../../op-stack/chainConfig.js'\nimport { defineChain } from '../../utils/chain/defineChain.js'\n\nconst sourceId = 1 // mainnet\n\nexport const base = /*#__PURE__*/ defineChain({\n ...chainConfig,\n id: 8453,\n name: 'Base',\n nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },\n rpcUrls: {\n default: {\n http: ['https://mainnet.base.org'],\n },\n },\n blockExplorers: {\n default: {\n name: 'Basescan',\n url: 'https://basescan.org',\n apiUrl: 'https://api.basescan.org/api',\n },\n },\n contracts: {\n ...chainConfig.contracts,\n disputeGameFactory: {\n [sourceId]: {\n address: '0x43edB88C4B80fDD2AdFF2412A7BebF9dF42cB40e',\n },\n },\n l2OutputOracle: {\n [sourceId]: {\n address: '0x56315b90c40730925ec5485cf004d835058518A0',\n },\n },\n multicall3: {\n address: '0xca11bde05977b3631167028862be2a173976ca11',\n blockCreated: 5022,\n },\n portal: {\n [sourceId]: {\n address: '0x49048044D57e1C92A77f79988d21Fa8fAF74E97e',\n blockCreated: 17482143,\n },\n },\n l1StandardBridge: {\n [sourceId]: {\n address: '0x3154Cf16ccdb4C6d922629664174b904d80F2C35',\n blockCreated: 17482143,\n },\n },\n },\n sourceId,\n})\n\nexport const basePreconf = /*#__PURE__*/ defineChain({\n ...base,\n experimental_preconfirmationTime: 200,\n rpcUrls: {\n default: {\n http: ['https://mainnet-preconf.base.org'],\n },\n },\n})\n","import {\n createPublicClient,\n decodeFunctionData,\n encodeFunctionData,\n erc20Abi,\n http,\n type Address,\n type Hex,\n} from 'viem';\nimport { base } from 'viem/chains';\nimport { USDC_ADDRESS as USDC } from './usdc-balance';\nimport type { TenjinSigner } from './wallet/provider';\n\n/** Lives in `usdc-balance.ts`, which the viem-free hooks can load. */\nexport const USDC_ADDRESS: Address = USDC;\nexport const USDC_DECIMALS = 6;\n\nexport async function getUsdcBalance(address: Address, rpcUrl: string): Promise<bigint> {\n const client = createPublicClient({ chain: base, transport: http(rpcUrl) });\n return client.readContract({\n address: USDC_ADDRESS,\n abi: erc20Abi,\n functionName: 'balanceOf',\n args: [address],\n });\n}\n\n// The chain boundary for `tenjin wallet send`, two-phase around the human confirm:\n// prepareUsdcSend (read-only: encode, nonce, gas, fees, ETH-for-gas balance)\n// runs BEFORE the confirm so the prompt can show the fee, broadcastUsdcSend\n// (sign via the TenjinSigner seam, broadcast, wait for the receipt) runs after.\n// Command tests mock this whole module, so no test can ever reach a real chain.\n\n/**\n * Ceilings on the RPC-supplied gas and fee fields. The RPC endpoint is\n * config-controlled and its estimates go straight into the signed transaction; a\n * hostile or broken endpoint returning huge values would burn the wallet's ETH\n * as fees. An ERC-20 transfer is ~65k gas and Base fees run well under a gwei,\n * so estimates past these bounds mean something is wrong: refuse, never clamp\n * (a clamped maxFeePerGas below the real base fee would just strand the tx).\n * A genuine extreme fee spike on Base trips the same refusal; that is intended\n * — waiting it out beats signing an irreversible transfer at panic prices.\n */\nexport const SEND_GAS_CAP = 150_000n;\nexport const SEND_MAX_FEE_PER_GAS_CAP = 10_000_000_000n; // 10 gwei\nexport const SEND_MAX_PRIORITY_FEE_CAP = 2_000_000_000n; // 2 gwei\n\n/** An RPC gas/fee estimate exceeded the send ceilings; nothing was signed. */\nexport class FeeCapExceededError extends Error {\n constructor(field: string, value: bigint, cap: bigint) {\n super(`${field} estimate ${value} exceeds the send ceiling ${cap}`);\n this.name = 'FeeCapExceededError';\n }\n}\n\n/** The transfer was mined but reverted; the fee was spent, the USDC did not move. */\nexport class SendRevertedError extends Error {\n constructor(readonly txHash: Hex) {\n super(`Transaction ${txHash} reverted`);\n this.name = 'SendRevertedError';\n }\n}\n\n/** Broadcast succeeded but no receipt arrived in time; the tx may still mine. */\nexport class SendPendingError extends Error {\n constructor(readonly txHash: Hex) {\n super(`Transaction ${txHash} was broadcast but not confirmed in time`);\n this.name = 'SendPendingError';\n }\n}\n\nexport interface PrepareUsdcSendArgs {\n from: Address;\n to: Address;\n amountAtomic: bigint;\n rpcUrl: string;\n}\n\n/**\n * Everything signed later, fixed at prepare time, plus the gas-cost preview.\n * The nonce is pinned here, BEFORE the human confirm, so anything else spending\n * from this key during that window makes the later broadcast fail nonce-stale\n * (an RPC_ERROR from the node; nothing double-spends — re-run to re-prepare).\n * `to` and `amountAtomic` are the previewed intent; broadcastUsdcSend re-decodes\n * `data` against them before signing.\n */\nexport interface PreparedUsdcSend {\n to: Address;\n amountAtomic: bigint;\n data: Hex;\n nonce: number;\n gas: bigint;\n maxFeePerGas: bigint;\n maxPriorityFeePerGas: bigint;\n /** Worst-case fee (gas * maxFeePerGas), for the confirm prompt and gas check. */\n feeWei: bigint;\n /** The sender's native ETH balance, for the has-gas pre-check. */\n ethBalanceWei: bigint;\n}\n\nexport async function prepareUsdcSend({\n from,\n to,\n amountAtomic,\n rpcUrl,\n}: PrepareUsdcSendArgs): Promise<PreparedUsdcSend> {\n const client = createPublicClient({ chain: base, transport: http(rpcUrl) });\n const data = encodeFunctionData({\n abi: erc20Abi,\n functionName: 'transfer',\n args: [to, amountAtomic],\n });\n const [nonce, gas, fees, ethBalanceWei] = await Promise.all([\n client.getTransactionCount({ address: from, blockTag: 'pending' }),\n client.estimateGas({ account: from, to: USDC_ADDRESS, data }),\n client.estimateFeesPerGas(),\n client.getBalance({ address: from }),\n ]);\n assertUnderCap('gas', gas, SEND_GAS_CAP);\n assertUnderCap('maxFeePerGas', fees.maxFeePerGas, SEND_MAX_FEE_PER_GAS_CAP);\n assertUnderCap('maxPriorityFeePerGas', fees.maxPriorityFeePerGas, SEND_MAX_PRIORITY_FEE_CAP);\n return {\n to,\n amountAtomic,\n data,\n nonce,\n gas,\n maxFeePerGas: fees.maxFeePerGas,\n maxPriorityFeePerGas: fees.maxPriorityFeePerGas,\n feeWei: gas * fees.maxFeePerGas,\n ethBalanceWei,\n };\n}\n\nexport interface BroadcastUsdcSendArgs {\n signer: TenjinSigner;\n prepared: PreparedUsdcSend;\n rpcUrl: string;\n /** Receipt wait bound in ms; Base blocks are ~2s, so the default is generous. */\n receiptTimeoutMs?: number;\n}\n\n/**\n * Sign the prepared transfer through the TenjinSigner seam (never a raw key),\n * broadcast it, and wait for the receipt so \"sent\" means mined. Throws\n * SendRevertedError (mined but failed) or SendPendingError (no receipt in time);\n * both carry the hash so the caller can report it either way.\n */\nexport async function broadcastUsdcSend({\n signer,\n prepared,\n rpcUrl,\n receiptTimeoutMs = 120_000,\n}: BroadcastUsdcSendArgs): Promise<Hex> {\n const client = createPublicClient({ chain: base, transport: http(rpcUrl) });\n // Pre-sign cross-check, the calldata twin of send.ts's signer/preview match:\n // the bytes about to be signed must still decode to the previewed recipient\n // and amount. Unreachable unless prepare-time state was corrupted; refusing\n // here means nothing is signed against a preview it does not match.\n const decoded = decodeFunctionData({ abi: erc20Abi, data: prepared.data });\n if (\n decoded.functionName !== 'transfer' ||\n decoded.args[0].toLowerCase() !== prepared.to.toLowerCase() ||\n decoded.args[1] !== prepared.amountAtomic\n ) {\n throw new Error(\n 'Prepared calldata does not decode to the previewed recipient and amount; nothing was signed.',\n );\n }\n const serializedTransaction = await signer.signTransaction({\n type: 'eip1559',\n chainId: base.id,\n to: USDC_ADDRESS,\n // Explicitly zero: an ERC-20 transfer carries no native value (test-pinned).\n value: 0n,\n data: prepared.data,\n nonce: prepared.nonce,\n gas: prepared.gas,\n maxFeePerGas: prepared.maxFeePerGas,\n maxPriorityFeePerGas: prepared.maxPriorityFeePerGas,\n });\n const txHash = await client.sendRawTransaction({ serializedTransaction });\n let receipt;\n try {\n receipt = await client.waitForTransactionReceipt({ hash: txHash, timeout: receiptTimeoutMs });\n } catch {\n throw new SendPendingError(txHash);\n }\n if (receipt.status !== 'success') throw new SendRevertedError(txHash);\n return txHash;\n}\n\nfunction assertUnderCap(field: string, value: bigint, cap: bigint): void {\n if (value > cap) throw new FeeCapExceededError(field, value, cap);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMO,IAAM,YAAY;EACvB,gBAAgB,EAAE,SAAS,6CAA4C;EACvE,SAAS,EAAE,SAAS,6CAA4C;EAChE,wBAAwB;IACtB,SAAS;;EAEX,gBAAgB,EAAE,SAAS,6CAA4C;EACvE,kBAAkB,EAAE,SAAS,6CAA4C;EACzE,qBAAqB;IACnB,SAAS;;;;;ACEN,IAAM,aAAa;EACxB,OAAqB,4BAAY;IAC/B,OAAO,MAAqB;AAC1B,YAAM,eAAe,KAAK,cAAc,IAAI,CAAC,gBAAe;AAC1D,YAAI,OAAO,gBAAgB;AAAU,iBAAO;AAC5C,cAAM,YAAY,kBAChB,WAA6B;AAE/B,YAAI,UAAU,YAAY,QAAQ;AAChC,oBAAU,aAAa,YAAY;AACnC,oBAAU,OAAO,YAAY,OACzB,YAAY,YAAY,IAAI,IAC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I,QAAQ,WAAW,UAAW,OAAM,IAAI,kBAAkB,MAAM;AACpE,SAAO;AACT;AAEA,SAAS,eAAe,OAAe,OAAe,KAAmB;AACvE,MAAI,QAAQ,IAAK,OAAM,IAAI,oBAAoB,OAAO,OAAO,GAAG;AAClE;","names":["serializeTransaction","USDC_ADDRESS"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// src/lib/env-proxy.ts
|
|
4
|
+
import * as http from "node:http";
|
|
5
|
+
var PROXY_VARIABLES = ["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy"];
|
|
6
|
+
var nodeSetGlobalProxy = http.setGlobalProxyFromEnv;
|
|
7
|
+
function proxyVariable(env) {
|
|
8
|
+
return PROXY_VARIABLES.find((name) => (env[name] ?? "") !== "");
|
|
9
|
+
}
|
|
10
|
+
function envProxySupported(setGlobal = nodeSetGlobalProxy) {
|
|
11
|
+
return typeof setGlobal === "function";
|
|
12
|
+
}
|
|
13
|
+
function useEnvProxy(env, setGlobal = nodeSetGlobalProxy ?? null) {
|
|
14
|
+
if (proxyVariable(env) === void 0) return "none";
|
|
15
|
+
if (typeof setGlobal !== "function") return "unsupported";
|
|
16
|
+
try {
|
|
17
|
+
setGlobal(env);
|
|
18
|
+
return "set";
|
|
19
|
+
} catch {
|
|
20
|
+
return "invalid";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
PROXY_VARIABLES,
|
|
26
|
+
proxyVariable,
|
|
27
|
+
envProxySupported,
|
|
28
|
+
useEnvProxy
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=chunk-S4SAZ7OD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/env-proxy.ts"],"sourcesContent":["import * as http from 'node:http';\n\n/** Named, never quoted: a proxy URL can carry its own credentials. */\nexport const PROXY_VARIABLES = ['HTTPS_PROXY', 'https_proxy', 'HTTP_PROXY', 'http_proxy'] as const;\n\ntype SetGlobalProxy = (env: NodeJS.ProcessEnv) => () => void;\n\n/** Node 24.14 added it. `engines` admits 22.0, where it is absent. */\nconst nodeSetGlobalProxy = (http as { setGlobalProxyFromEnv?: SetGlobalProxy })\n .setGlobalProxyFromEnv;\n\n/** The first proxy variable this environment sets, or undefined. */\nexport function proxyVariable(env: NodeJS.ProcessEnv): string | undefined {\n return PROXY_VARIABLES.find((name) => (env[name] ?? '') !== '');\n}\n\n/** Can this Node route `fetch` through the proxy the environment names? */\nexport function envProxySupported(setGlobal: unknown = nodeSetGlobalProxy): boolean {\n return typeof setGlobal === 'function';\n}\n\nexport type EnvProxyResult = 'none' | 'set' | 'unsupported' | 'invalid';\n\n/**\n * Send `fetch` and `https.request` through the proxy the environment names.\n * Node's `fetch` ignores HTTPS_PROXY, HTTP_PROXY and NO_PROXY unless\n * NODE_USE_ENV_PROXY=1, so on a network where the proxy is the only way out the\n * harness reaches the internet and Tenjin does not. Called once by the bin\n * entry, so the CLI, the hooks and `tenjin mcp` all get it. Never throws: a\n * proxy URL Node cannot parse leaves the transport as it was.\n */\nexport function useEnvProxy(\n env: NodeJS.ProcessEnv,\n setGlobal: SetGlobalProxy | null = nodeSetGlobalProxy ?? null,\n): EnvProxyResult {\n if (proxyVariable(env) === undefined) return 'none';\n if (typeof setGlobal !== 'function') return 'unsupported';\n try {\n setGlobal(env);\n return 'set';\n } catch {\n return 'invalid';\n }\n}\n"],"mappings":";;;AAAA,YAAY,UAAU;AAGf,IAAM,kBAAkB,CAAC,eAAe,eAAe,cAAc,YAAY;AAKxF,IAAM,qBACH;AAGI,SAAS,cAAc,KAA4C;AACxE,SAAO,gBAAgB,KAAK,CAAC,UAAU,IAAI,IAAI,KAAK,QAAQ,EAAE;AAChE;AAGO,SAAS,kBAAkB,YAAqB,oBAA6B;AAClF,SAAO,OAAO,cAAc;AAC9B;AAYO,SAAS,YACd,KACA,YAAmC,sBAAsB,MACzC;AAChB,MAAI,cAAc,GAAG,MAAM,OAAW,QAAO;AAC7C,MAAI,OAAO,cAAc,WAAY,QAAO;AAC5C,MAAI;AACF,cAAU,GAAG;AACb,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// src/lib/paths.ts
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { join, resolve } from "node:path";
|
|
6
|
+
function dataDir(env = process.env) {
|
|
7
|
+
const override = env.TENJIN_DATA_DIR;
|
|
8
|
+
if (override !== void 0 && override.length > 0) return resolve(override);
|
|
9
|
+
return defaultDataDir();
|
|
10
|
+
}
|
|
11
|
+
function defaultDataDir(home = homedir()) {
|
|
12
|
+
return join(home, ".tenjin");
|
|
13
|
+
}
|
|
14
|
+
function configPath(dir = dataDir()) {
|
|
15
|
+
return join(dir, "config.json");
|
|
16
|
+
}
|
|
17
|
+
function walletPath(dir = dataDir()) {
|
|
18
|
+
return join(dir, "wallet.json");
|
|
19
|
+
}
|
|
20
|
+
function installIdPath(dir = dataDir()) {
|
|
21
|
+
return join(dir, "install-id");
|
|
22
|
+
}
|
|
23
|
+
function sessionPath(dir = dataDir()) {
|
|
24
|
+
return join(dir, "session.json");
|
|
25
|
+
}
|
|
26
|
+
function spendLedgerPath(dir = dataDir()) {
|
|
27
|
+
return join(dir, "spend.json");
|
|
28
|
+
}
|
|
29
|
+
function balanceCachePath(dir = dataDir()) {
|
|
30
|
+
return join(dir, "balance.json");
|
|
31
|
+
}
|
|
32
|
+
function updateCheckPath(dir = dataDir()) {
|
|
33
|
+
return join(dir, "update-check.json");
|
|
34
|
+
}
|
|
35
|
+
function hooksDir(dir = dataDir()) {
|
|
36
|
+
return join(dir, "hooks");
|
|
37
|
+
}
|
|
38
|
+
function hookHealthPath(dir = dataDir()) {
|
|
39
|
+
return join(dir, "hook-health.json");
|
|
40
|
+
}
|
|
41
|
+
function passphraseBlobPath(dir = dataDir()) {
|
|
42
|
+
return join(dir, "passphrase.dpapi");
|
|
43
|
+
}
|
|
44
|
+
function passphraseBlobPathFor(account, dir = dataDir()) {
|
|
45
|
+
return join(dir, `passphrase.${account}.dpapi`);
|
|
46
|
+
}
|
|
47
|
+
function archivedWalletPath(account, dir = dataDir()) {
|
|
48
|
+
return join(dir, `wallet.${account}.json.bak`);
|
|
49
|
+
}
|
|
50
|
+
function loopDbPath(dir = dataDir()) {
|
|
51
|
+
return join(dir, "loop.db");
|
|
52
|
+
}
|
|
53
|
+
function daemonTokenPath(dir = dataDir()) {
|
|
54
|
+
return join(dir, "daemon.token");
|
|
55
|
+
}
|
|
56
|
+
function daemonPidPath(dir = dataDir()) {
|
|
57
|
+
return join(dir, "daemon.pid");
|
|
58
|
+
}
|
|
59
|
+
function daemonLogPath(dir = dataDir()) {
|
|
60
|
+
return join(dir, "daemon.log");
|
|
61
|
+
}
|
|
62
|
+
function daemonSpawnPath(dir = dataDir()) {
|
|
63
|
+
return join(dir, "daemon.spawn");
|
|
64
|
+
}
|
|
65
|
+
function daemonBundlePath(dir = dataDir()) {
|
|
66
|
+
return join(hooksDir(dir), "tenjin-daemon.mjs");
|
|
67
|
+
}
|
|
68
|
+
function shimBundlePath(dir = dataDir()) {
|
|
69
|
+
return join(hooksDir(dir), "tenjin-shim.mjs");
|
|
70
|
+
}
|
|
71
|
+
var VITEST_REPORTER_FILE = "tenjin-vitest-reporter.mjs";
|
|
72
|
+
function vitestReporterPath(dir = dataDir()) {
|
|
73
|
+
return join(hooksDir(dir), VITEST_REPORTER_FILE);
|
|
74
|
+
}
|
|
75
|
+
function downloadsDir(dir = dataDir()) {
|
|
76
|
+
return join(dir, "downloads");
|
|
77
|
+
}
|
|
78
|
+
function paidLedgerPath(dir = dataDir()) {
|
|
79
|
+
return join(dir, "paid", "ledger.jsonl");
|
|
80
|
+
}
|
|
81
|
+
function jobsDir(dir = dataDir()) {
|
|
82
|
+
return join(dir, "jobs");
|
|
83
|
+
}
|
|
84
|
+
function quotesDir(dir = dataDir()) {
|
|
85
|
+
return join(dir, "quotes");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export {
|
|
89
|
+
dataDir,
|
|
90
|
+
defaultDataDir,
|
|
91
|
+
configPath,
|
|
92
|
+
walletPath,
|
|
93
|
+
installIdPath,
|
|
94
|
+
sessionPath,
|
|
95
|
+
spendLedgerPath,
|
|
96
|
+
balanceCachePath,
|
|
97
|
+
updateCheckPath,
|
|
98
|
+
hooksDir,
|
|
99
|
+
hookHealthPath,
|
|
100
|
+
passphraseBlobPath,
|
|
101
|
+
passphraseBlobPathFor,
|
|
102
|
+
archivedWalletPath,
|
|
103
|
+
loopDbPath,
|
|
104
|
+
daemonTokenPath,
|
|
105
|
+
daemonPidPath,
|
|
106
|
+
daemonLogPath,
|
|
107
|
+
daemonSpawnPath,
|
|
108
|
+
daemonBundlePath,
|
|
109
|
+
shimBundlePath,
|
|
110
|
+
VITEST_REPORTER_FILE,
|
|
111
|
+
vitestReporterPath,
|
|
112
|
+
downloadsDir,
|
|
113
|
+
paidLedgerPath,
|
|
114
|
+
jobsDir,
|
|
115
|
+
quotesDir
|
|
116
|
+
};
|
|
117
|
+
//# sourceMappingURL=chunk-SJLTEINJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/paths.ts"],"sourcesContent":["import { homedir } from 'node:os';\nimport { join, resolve } from 'node:path';\n\n/**\n * Where the CLI keeps its config and wallet. Defaults to ~/.tenjin, overridable\n * via TENJIN_DATA_DIR (CI, ephemeral agents, and every test — which point it at\n * a temp dir so the real home is never touched).\n */\nexport function dataDir(env: NodeJS.ProcessEnv = process.env): string {\n const override = env.TENJIN_DATA_DIR;\n // Absolute, always: the daemon compares this string against its own\n // `data_dir` and is spawned with it as `cwd`, so a relative override must\n // mean the same directory from every process.\n if (override !== undefined && override.length > 0) return resolve(override);\n return defaultDataDir();\n}\n\n/**\n * The data dir a run with no override resolves. Split out of {@link dataDir} so\n * a caller holding a home directory can ask whether some other profile IS the\n * default one, without a second copy of the `.tenjin` literal.\n */\nexport function defaultDataDir(home: string = homedir()): string {\n return join(home, '.tenjin');\n}\n\nexport function configPath(dir: string = dataDir()): string {\n return join(dir, 'config.json');\n}\n\nexport function walletPath(dir: string = dataDir()): string {\n return join(dir, 'wallet.json');\n}\n\n/**\n * The anonymous install id sent to Tenjin as `X-Tenjin-Install` (lib/install-identity).\n * Under the data dir so it survives upgrades and reinstalls of the CLI itself.\n */\nexport function installIdPath(dir: string = dataDir()): string {\n return join(dir, 'install-id');\n}\n\n/**\n * Where the delegated P-256 session key + its wallet-signed SIWX delegation are\n * cached (B3, D35). A short-lived (≤24h) hot key: lower stakes than wallet.json,\n * but still written 0600 and address-bound so a wallet change invalidates it.\n */\nexport function sessionPath(dir: string = dataDir()): string {\n return join(dir, 'session.json');\n}\n\n/**\n * Where the client-side rolling spend ledger lives (lib/wallet/spend.ts).\n *\n * Its own file, NOT session.json: the two schemas are incompatible and both\n * readers treat a parse failure as \"absent\", so a shared path meant each writer\n * silently destroyed the other's file — a session key wiped the spend window, and\n * the next spend wiped the session key.\n */\nexport function spendLedgerPath(dir: string = dataDir()): string {\n return join(dir, 'spend.json');\n}\n\n/**\n * The wallet's last USDC balance read (lib/usdc-balance). A pure cache, a\n * minute long: an unreadable file is simply read again from the chain.\n */\nexport function balanceCachePath(dir: string = dataDir()): string {\n return join(dir, 'balance.json');\n}\n\n/**\n * Where the once-a-day \"a newer tenjin-cli exists\" check caches the registry\n * answer. A pure cache: nothing here is authoritative, so an unreadable file is\n * simply re-fetched.\n */\nexport function updateCheckPath(dir: string = dataDir()): string {\n return join(dir, 'update-check.json');\n}\n\n/**\n * Where `install` writes the standalone harness hook scripts. Under the data dir\n * rather than the harness's own config directory: the scripts are ours, a harness\n * only ever holds the path to them, and one location serves every harness.\n */\nexport function hooksDir(dir: string = dataDir()): string {\n return join(dir, 'hooks');\n}\n\n/**\n * How the marketplace has been answering the dispatch hook lately, so a run of\n * failures stops the arm instead of paying the fetch budget per subagent through\n * an outage. Hook-written, unlocked, and cheap to lose, since a missing file\n * reads as \"healthy\". Its own file because two hooks writing one unlocked file\n * would erase each other.\n */\nexport function hookHealthPath(dir: string = dataDir()): string {\n return join(dir, 'hook-health.json');\n}\n\n/**\n * Where the LEGACY (pre-per-wallet) Windows DPAPI passphrase blob lives. The\n * file holds a DPAPI CurrentUser ciphertext, not the passphrase in plaintext.\n * New writes go to the per-wallet path below; this one is only read as a\n * migration fallback and removed after a verified per-wallet copy exists.\n */\nexport function passphraseBlobPath(dir: string = dataDir()): string {\n return join(dir, 'passphrase.dpapi');\n}\n\n/**\n * The per-wallet Windows DPAPI passphrase blob: one file per wallet address\n * (lowercase), so creating a new wallet never clobbers an old wallet's blob.\n * Only ever written on win32; other platforms use their own OS store.\n */\nexport function passphraseBlobPathFor(account: string, dir: string = dataDir()): string {\n return join(dir, `passphrase.${account}.dpapi`);\n}\n\n/**\n * Where `wallet create --replace` parks the outgoing wallet's keystore, keyed by\n * its lowercase address so successive replaces can never collide. Together with\n * the wallet's per-address passphrase entry in the OS store, this file keeps the\n * replaced wallet's funds recoverable; it is never read by the active-wallet\n * path.\n */\nexport function archivedWalletPath(account: string, dir: string = dataDir()): string {\n return join(dir, `wallet.${account}.json.bak`);\n}\n\n/**\n * The loop daemon's own state, all under the data dir (tenjin-notes\n * loop-redesign/02-redesign.md §4, §10).\n */\nexport function loopDbPath(dir: string = dataDir()): string {\n return join(dir, 'loop.db');\n}\n\n/** 32 random bytes, hex, 0600. Minted by `tenjin daemon start`, rotated only by\n * reinstall, NEVER deleted by the daemon: every transport reads it, and an idle\n * exit that removed it would strand them all. */\nexport function daemonTokenPath(dir: string = dataDir()): string {\n return join(dir, 'daemon.token');\n}\n\n/** `{ pid, port, started_at, data_dir }`, advisory: written after the bind,\n * removed at exit only by the process whose pid it names. Liveness is\n * `GET /health`, never this file alone. */\nexport function daemonPidPath(dir: string = dataDir()): string {\n return join(dir, 'daemon.pid');\n}\n\n/** Where a detached daemon's stdout and stderr go, and where the shim writes its\n * one `daemon-down` line when it cannot reach one. */\nexport function daemonLogPath(dir: string = dataDir()): string {\n return join(dir, 'daemon.log');\n}\n\n/** An empty file whose mtime is the last spawn attempt; the shim's backoff. */\nexport function daemonSpawnPath(dir: string = dataDir()): string {\n return join(dir, 'daemon.spawn');\n}\n\n/** The single-file daemon bundle `tenjin daemon start` copies from `dist`. */\nexport function daemonBundlePath(dir: string = dataDir()): string {\n return join(hooksDir(dir), 'tenjin-daemon.mjs');\n}\n\n/** The ensure-and-forward shim the two `command` hook entries run. */\nexport function shimBundlePath(dir: string = dataDir()): string {\n return join(hooksDir(dir), 'tenjin-shim.mjs');\n}\n\n/** Tenjin's own vitest reporter, copied beside the bundles. NOT A HOOK ENTRY\n * and never spawned: a repo's own `vitest.config.ts` imports it by this\n * absolute path, which is why `doctor` can hint at it verbatim. */\nexport const VITEST_REPORTER_FILE = 'tenjin-vitest-reporter.mjs';\n\nexport function vitestReporterPath(dir: string = dataDir()): string {\n return join(hooksDir(dir), VITEST_REPORTER_FILE);\n}\n\n/**\n * Where a router lookup that bought a file (a sound, an image) saves it. The\n * bytes cannot ride in the tool result, so the result names this file instead.\n */\nexport function downloadsDir(dir: string = dataDir()): string {\n return join(dir, 'downloads');\n}\n\n/**\n * One JSON line per paid router call: what was bought, from whom, for how much,\n * the settlement it carried and the files it saved. The user's own record; only\n * reconcile reads it back (`tenjin payments reconcile`, and the `request` tool's\n * pass beside each lookup), to settle what was left unknown.\n */\nexport function paidLedgerPath(dir: string = dataDir()): string {\n return join(dir, 'paid', 'ledger.jsonl');\n}\n\n/**\n * One file per take of a paid router call whose seller was still working when\n * the call ended: where to poll, until when, and what it saved. `request({job})`\n * resumes from it in any later process.\n */\nexport function jobsDir(dir: string = dataDir()): string {\n return join(dir, 'jobs');\n}\n\n/**\n * One file per quote: a router call over the automatic limits, kept with its\n * exact plan until the user approves it, it runs once, or it expires.\n */\nexport function quotesDir(dir: string = dataDir()): string {\n return join(dir, 'quotes');\n}\n"],"mappings":";;;AAAA,SAAS,eAAe;AACxB,SAAS,MAAM,eAAe;AAOvB,SAAS,QAAQ,MAAyB,QAAQ,KAAa;AACpE,QAAM,WAAW,IAAI;AAIrB,MAAI,aAAa,UAAa,SAAS,SAAS,EAAG,QAAO,QAAQ,QAAQ;AAC1E,SAAO,eAAe;AACxB;AAOO,SAAS,eAAe,OAAe,QAAQ,GAAW;AAC/D,SAAO,KAAK,MAAM,SAAS;AAC7B;AAEO,SAAS,WAAW,MAAc,QAAQ,GAAW;AAC1D,SAAO,KAAK,KAAK,aAAa;AAChC;AAEO,SAAS,WAAW,MAAc,QAAQ,GAAW;AAC1D,SAAO,KAAK,KAAK,aAAa;AAChC;AAMO,SAAS,cAAc,MAAc,QAAQ,GAAW;AAC7D,SAAO,KAAK,KAAK,YAAY;AAC/B;AAOO,SAAS,YAAY,MAAc,QAAQ,GAAW;AAC3D,SAAO,KAAK,KAAK,cAAc;AACjC;AAUO,SAAS,gBAAgB,MAAc,QAAQ,GAAW;AAC/D,SAAO,KAAK,KAAK,YAAY;AAC/B;AAMO,SAAS,iBAAiB,MAAc,QAAQ,GAAW;AAChE,SAAO,KAAK,KAAK,cAAc;AACjC;AAOO,SAAS,gBAAgB,MAAc,QAAQ,GAAW;AAC/D,SAAO,KAAK,KAAK,mBAAmB;AACtC;AAOO,SAAS,SAAS,MAAc,QAAQ,GAAW;AACxD,SAAO,KAAK,KAAK,OAAO;AAC1B;AASO,SAAS,eAAe,MAAc,QAAQ,GAAW;AAC9D,SAAO,KAAK,KAAK,kBAAkB;AACrC;AAQO,SAAS,mBAAmB,MAAc,QAAQ,GAAW;AAClE,SAAO,KAAK,KAAK,kBAAkB;AACrC;AAOO,SAAS,sBAAsB,SAAi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tenjinCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
keccak_256
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-KG3D7FIF.js";
|
|
5
5
|
|
|
6
6
|
// node_modules/.pnpm/abitype@1.2.3_typescript@6.0.3_zod@3.25.76/node_modules/abitype/dist/esm/version.js
|
|
7
7
|
var version = "1.2.3";
|
|
@@ -5630,7 +5630,7 @@ async function call(client, args) {
|
|
|
5630
5630
|
if (isAbortError(err))
|
|
5631
5631
|
throw err;
|
|
5632
5632
|
const data2 = getRevertErrorData(err);
|
|
5633
|
-
const { offchainLookup: offchainLookup2, offchainLookupSignature: offchainLookupSignature2 } = await import("./ccip-
|
|
5633
|
+
const { offchainLookup: offchainLookup2, offchainLookupSignature: offchainLookupSignature2 } = await import("./ccip-7RMRLAGV.js");
|
|
5634
5634
|
if (client.ccipRead !== false && data2?.slice(0, 10) === offchainLookupSignature2 && to)
|
|
5635
5635
|
return {
|
|
5636
5636
|
data: await offchainLookup2(client, { data: data2, requestOptions, to })
|
|
@@ -6196,4 +6196,4 @@ export {
|
|
|
6196
6196
|
ccipRequest,
|
|
6197
6197
|
call
|
|
6198
6198
|
};
|
|
6199
|
-
//# sourceMappingURL=chunk-
|
|
6199
|
+
//# sourceMappingURL=chunk-TTNESUPQ.js.map
|