tenjin-cli 0.1.0-alpha.25 → 0.1.0-alpha.26

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.
Files changed (99) hide show
  1. package/README.md +14 -41
  2. package/dist/{chunk-EG7P4SM6.js → chunk-4HAV6IFE.js} +5 -5
  3. package/dist/{chunk-IYLECN4D.js → chunk-5HS54CLI.js} +2 -2
  4. package/dist/{chunk-CEMXMUIU.js → chunk-5INS5ZZF.js} +35 -6
  5. package/dist/chunk-5INS5ZZF.js.map +1 -0
  6. package/dist/{chunk-CKDD554V.js → chunk-5NUF4BHR.js} +5 -3
  7. package/dist/{chunk-CKDD554V.js.map → chunk-5NUF4BHR.js.map} +1 -1
  8. package/dist/{chunk-NTYQHAIM.js → chunk-65EJJVT3.js} +2 -2
  9. package/dist/{chunk-GT6W3VJM.js → chunk-6JIYGYRB.js} +2 -52
  10. package/dist/chunk-6JIYGYRB.js.map +1 -0
  11. package/dist/{chunk-EOGJKIOG.js → chunk-ALJRB7NG.js} +10 -3
  12. package/dist/chunk-ALJRB7NG.js.map +1 -0
  13. package/dist/chunk-BOAI23CX.js +222 -0
  14. package/dist/chunk-BOAI23CX.js.map +1 -0
  15. package/dist/{chunk-KGTQRJGS.js → chunk-DI7WHXOZ.js} +5 -10
  16. package/dist/{chunk-KGTQRJGS.js.map → chunk-DI7WHXOZ.js.map} +1 -1
  17. package/dist/{chunk-DRXDTITB.js → chunk-EJXIK6WY.js} +9 -9
  18. package/dist/{chunk-ODH7UXIS.js → chunk-GHR4BTNJ.js} +3 -2
  19. package/dist/{chunk-ODH7UXIS.js.map → chunk-GHR4BTNJ.js.map} +1 -1
  20. package/dist/chunk-H4BOQLWW.js +99 -0
  21. package/dist/chunk-H4BOQLWW.js.map +1 -0
  22. package/dist/{chunk-VYONGSMQ.js → chunk-OBPZ36HG.js} +29 -3
  23. package/dist/chunk-OBPZ36HG.js.map +1 -0
  24. package/dist/chunk-PM2MOXJ3.js +66 -0
  25. package/dist/chunk-PM2MOXJ3.js.map +1 -0
  26. package/dist/chunk-PZ5N6BAL.js +268 -0
  27. package/dist/chunk-PZ5N6BAL.js.map +1 -0
  28. package/dist/{chunk-YSW57KUT.js → chunk-VNT3CQFV.js} +17 -17
  29. package/dist/chunk-VNT3CQFV.js.map +1 -0
  30. package/dist/{chunk-SCAE6PW6.js → chunk-W36HL4TB.js} +4 -4
  31. package/dist/{chunk-NYPFOHSJ.js → chunk-WT7DHJNJ.js} +2 -2
  32. package/dist/chunk-XMIVHQ35.js +55 -0
  33. package/dist/chunk-XMIVHQ35.js.map +1 -0
  34. package/dist/{chunk-3ZYPVSIU.js → chunk-YHWBDCGS.js} +234 -41
  35. package/dist/chunk-YHWBDCGS.js.map +1 -0
  36. package/dist/{chunk-CP7O6M55.js → chunk-YLCWI6ZR.js} +61 -20
  37. package/dist/chunk-YLCWI6ZR.js.map +1 -0
  38. package/dist/{chunk-EACMJEF3.js → chunk-Z7R2QDX2.js} +35 -171
  39. package/dist/chunk-Z7R2QDX2.js.map +1 -0
  40. package/dist/chunk-ZLD6MJVJ.js +30 -0
  41. package/dist/chunk-ZLD6MJVJ.js.map +1 -0
  42. package/dist/{cli-4WMGZPBP.js → cli-2U5JB7OQ.js} +34 -31
  43. package/dist/{cli-4WMGZPBP.js.map → cli-2U5JB7OQ.js.map} +1 -1
  44. package/dist/{config-VU6U7QOU.js → config-44EGO636.js} +11 -7
  45. package/dist/{doctor-26JS2SG3.js → doctor-BD42BBEG.js} +136 -94
  46. package/dist/doctor-BD42BBEG.js.map +1 -0
  47. package/dist/env-proxy-KEGEMWKX.js +15 -0
  48. package/dist/{fund-JJN3FRRF.js → fund-WQOOUESE.js} +20 -10
  49. package/dist/{fund-JJN3FRRF.js.map → fund-WQOOUESE.js.map} +1 -1
  50. package/dist/{hook-command-S2V4UNB3.js → hook-command-23LC5NRN.js} +12 -8
  51. package/dist/index.js +4 -2
  52. package/dist/index.js.map +1 -1
  53. package/dist/{install-GXQ33J4G.js → install-REPLHNU7.js} +19 -13
  54. package/dist/{install-identity-HFQUXPSI.js → install-identity-4RDWTLJ2.js} +4 -4
  55. package/dist/{install-wallet-27LTEHBI.js → install-wallet-USHWL7AX.js} +8 -6
  56. package/dist/{install-wallet-27LTEHBI.js.map → install-wallet-USHWL7AX.js.map} +1 -1
  57. package/dist/{mcp-AHCZVD2U.js → mcp-T5SYCLP7.js} +238 -64
  58. package/dist/mcp-T5SYCLP7.js.map +1 -0
  59. package/dist/{pay-3TCOPGCX.js → pay-276DSSYG.js} +10 -9
  60. package/dist/{payments-H3LSBGSL.js → payments-TZYLJXK3.js} +5 -4
  61. package/dist/{payments-H3LSBGSL.js.map → payments-TZYLJXK3.js.map} +1 -1
  62. package/dist/{send-LKCLN5GA.js → send-YHDKZPED.js} +6 -5
  63. package/dist/{send-LKCLN5GA.js.map → send-YHDKZPED.js.map} +1 -1
  64. package/dist/{status-2FDGI4LQ.js → status-X2INT6VD.js} +4 -3
  65. package/dist/{status-2FDGI4LQ.js.map → status-X2INT6VD.js.map} +1 -1
  66. package/dist/{status-line-wiring-ZDBYHNYR.js → status-line-wiring-LW4HFRHB.js} +4 -4
  67. package/dist/{uninstall-ZXWABDHS.js → uninstall-NVTGU7JD.js} +21 -15
  68. package/dist/{uninstall-ZXWABDHS.js.map → uninstall-NVTGU7JD.js.map} +1 -1
  69. package/dist/{update-HEIWVOP5.js → update-QXVH2DE7.js} +17 -10
  70. package/dist/update-QXVH2DE7.js.map +1 -0
  71. package/dist/{wallet-T7JYWI6O.js → wallet-CKKB23D5.js} +8 -6
  72. package/dist/wallet-CKKB23D5.js.map +1 -0
  73. package/docs/agent-permissions.md +14 -4
  74. package/docs/troubleshooting.md +13 -0
  75. package/package.json +2 -1
  76. package/dist/chunk-3ZYPVSIU.js.map +0 -1
  77. package/dist/chunk-CEMXMUIU.js.map +0 -1
  78. package/dist/chunk-CP7O6M55.js.map +0 -1
  79. package/dist/chunk-EACMJEF3.js.map +0 -1
  80. package/dist/chunk-EOGJKIOG.js.map +0 -1
  81. package/dist/chunk-GT6W3VJM.js.map +0 -1
  82. package/dist/chunk-VYONGSMQ.js.map +0 -1
  83. package/dist/chunk-YSW57KUT.js.map +0 -1
  84. package/dist/doctor-26JS2SG3.js.map +0 -1
  85. package/dist/mcp-AHCZVD2U.js.map +0 -1
  86. package/dist/update-HEIWVOP5.js.map +0 -1
  87. /package/dist/{chunk-EG7P4SM6.js.map → chunk-4HAV6IFE.js.map} +0 -0
  88. /package/dist/{chunk-IYLECN4D.js.map → chunk-5HS54CLI.js.map} +0 -0
  89. /package/dist/{chunk-NTYQHAIM.js.map → chunk-65EJJVT3.js.map} +0 -0
  90. /package/dist/{chunk-DRXDTITB.js.map → chunk-EJXIK6WY.js.map} +0 -0
  91. /package/dist/{chunk-SCAE6PW6.js.map → chunk-W36HL4TB.js.map} +0 -0
  92. /package/dist/{chunk-NYPFOHSJ.js.map → chunk-WT7DHJNJ.js.map} +0 -0
  93. /package/dist/{config-VU6U7QOU.js.map → config-44EGO636.js.map} +0 -0
  94. /package/dist/{hook-command-S2V4UNB3.js.map → env-proxy-KEGEMWKX.js.map} +0 -0
  95. /package/dist/{install-GXQ33J4G.js.map → hook-command-23LC5NRN.js.map} +0 -0
  96. /package/dist/{install-identity-HFQUXPSI.js.map → install-REPLHNU7.js.map} +0 -0
  97. /package/dist/{pay-3TCOPGCX.js.map → install-identity-4RDWTLJ2.js.map} +0 -0
  98. /package/dist/{status-line-wiring-ZDBYHNYR.js.map → pay-276DSSYG.js.map} +0 -0
  99. /package/dist/{wallet-T7JYWI6O.js.map → status-line-wiring-LW4HFRHB.js.map} +0 -0
@@ -1,4 +1,7 @@
1
1
  import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
+ import {
3
+ promptYesNo
4
+ } from "./chunk-LHHMV4GU.js";
2
5
  import {
3
6
  assertPublicDestination
4
7
  } from "./chunk-LAIZ2AQA.js";
@@ -54,9 +57,6 @@ import {
54
57
  maxUint256,
55
58
  toBytes
56
59
  } from "./chunk-TTNESUPQ.js";
57
- import {
58
- promptYesNo
59
- } from "./chunk-LHHMV4GU.js";
60
60
  import {
61
61
  USDC_ADDRESS
62
62
  } from "./chunk-YTM7OURD.js";
@@ -64,20 +64,20 @@ import {
64
64
  describeWallet,
65
65
  resolveSpendAuthorizer,
66
66
  resolveWalletProvider
67
- } from "./chunk-EG7P4SM6.js";
68
- import {
69
- getAddress
70
- } from "./chunk-EGELTSPU.js";
67
+ } from "./chunk-4HAV6IFE.js";
71
68
  import {
72
69
  sanitizeForTerminal
73
70
  } from "./chunk-UDWGT4FX.js";
71
+ import {
72
+ getAddress
73
+ } from "./chunk-EGELTSPU.js";
74
74
  import {
75
75
  mask
76
76
  } from "./chunk-7QKHZQKW.js";
77
77
  import {
78
78
  fetchFailureToCliError,
79
79
  httpRequest
80
- } from "./chunk-CEMXMUIU.js";
80
+ } from "./chunk-5INS5ZZF.js";
81
81
  import {
82
82
  resolveContextSettings
83
83
  } from "./chunk-HII5HOQV.js";
@@ -12304,4 +12304,4 @@ export {
12304
12304
  paidLegTimeoutMs,
12305
12305
  settlementTx
12306
12306
  };
12307
- //# sourceMappingURL=chunk-DRXDTITB.js.map
12307
+ //# sourceMappingURL=chunk-EJXIK6WY.js.map
@@ -3,7 +3,7 @@ import { createRequire as __tenjinCreateRequire } from 'node:module'; const requ
3
3
  // package.json
4
4
  var package_default = {
5
5
  name: "tenjin-cli",
6
- version: "0.1.0-alpha.25",
6
+ version: "0.1.0-alpha.26",
7
7
  type: "module",
8
8
  description: "The tool router for coding agents. Tenjin picks the right tool when your agent needs one, and one wallet pays for every call.",
9
9
  repository: {
@@ -69,6 +69,7 @@ var package_default = {
69
69
  commander: "^14.0.1",
70
70
  eslint: "^10",
71
71
  "eslint-config-prettier": "^10",
72
+ "lean-qr": "^2.7.4",
72
73
  ox: "0.14.30",
73
74
  prettier: "^3",
74
75
  tsup: "^8.5.0",
@@ -83,4 +84,4 @@ var package_default = {
83
84
  export {
84
85
  package_default
85
86
  };
86
- //# sourceMappingURL=chunk-ODH7UXIS.js.map
87
+ //# sourceMappingURL=chunk-GHR4BTNJ.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../package.json"],"sourcesContent":["{\n \"name\": \"tenjin-cli\",\n \"version\": \"0.1.0-alpha.25\",\n \"type\": \"module\",\n \"description\": \"The tool router for coding agents. Tenjin picks the right tool when your agent needs one, and one wallet pays for every call.\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/BackTrackCo/tenjin-agent.git\"\n },\n \"homepage\": \"https://tenjin.sh/agents\",\n \"bugs\": \"https://github.com/BackTrackCo/tenjin-agent/issues\",\n \"keywords\": [\n \"claude-code\",\n \"coding-agents\",\n \"tool-router\",\n \"ai-agents\",\n \"agent-tools\",\n \"mcp\",\n \"x402\",\n \"usdc\",\n \"base\",\n \"micropayments\",\n \"agent-payments\",\n \"claude\",\n \"codex\",\n \"cli\"\n ],\n \"bin\": {\n \"tenjin\": \"dist/index.js\"\n },\n \"engines\": {\n \"node\": \">=24\"\n },\n \"files\": [\n \"dist\",\n \"docs\",\n \"NOTICE.md\"\n ],\n \"packageManager\": \"pnpm@11.11.0\",\n \"scripts\": {\n \"build\": \"rm -rf dist && tsup\",\n \"test\": \"vitest run\",\n \"typecheck\": \"tsc --noEmit\",\n \"lint\": \"eslint .\",\n \"format\": \"prettier --write .\",\n \"format:check\": \"prettier --check .\",\n \"check\": \"pnpm run build && pnpm run test\",\n \"sync:skill\": \"node scripts/sync-skill.mjs\",\n \"pack-smoke\": \"bash scripts/pack-smoke.sh\",\n \"changeset\": \"changeset\",\n \"prepublishOnly\": \"pnpm run build\",\n \"githooks\": \"git config core.hooksPath .githooks\"\n },\n \"devDependencies\": {\n \"@changesets/cli\": \"^3.0.3\",\n \"@clack/prompts\": \"^1.7.0\",\n \"@eslint/js\": \"^10\",\n \"@modelcontextprotocol/sdk\": \"1.31.0\",\n \"@types/node\": \"^25\",\n \"@x402/core\": \"2.28.0\",\n \"@x402/evm\": \"2.28.0\",\n \"@x402/extensions\": \"2.28.0\",\n \"@x402/fetch\": \"2.28.0\",\n \"ajv\": \"^8.20.0\",\n \"ajv-formats\": \"^3.0.1\",\n \"commander\": \"^14.0.1\",\n \"eslint\": \"^10\",\n \"eslint-config-prettier\": \"^10\",\n \"ox\": \"0.14.30\",\n \"prettier\": \"^3\",\n \"tsup\": \"^8.5.0\",\n \"typescript\": \"^6\",\n \"typescript-eslint\": \"^8\",\n \"viem\": \"^2.53.1\",\n \"vitest\": \"^4.1.9\",\n \"zod\": \"^4.4.3\"\n }\n}\n"],"mappings":";;;AAAA;AAAA,EACE,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,MAAQ;AAAA,EACR,aAAe;AAAA,EACf,YAAc;AAAA,IACZ,MAAQ;AAAA,IACR,KAAO;AAAA,EACT;AAAA,EACA,UAAY;AAAA,EACZ,MAAQ;AAAA,EACR,UAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,KAAO;AAAA,IACL,QAAU;AAAA,EACZ;AAAA,EACA,SAAW;AAAA,IACT,MAAQ;AAAA,EACV;AAAA,EACA,OAAS;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,gBAAkB;AAAA,EAClB,SAAW;AAAA,IACT,OAAS;AAAA,IACT,MAAQ;AAAA,IACR,WAAa;AAAA,IACb,MAAQ;AAAA,IACR,QAAU;AAAA,IACV,gBAAgB;AAAA,IAChB,OAAS;AAAA,IACT,cAAc;AAAA,IACd,cAAc;AAAA,IACd,WAAa;AAAA,IACb,gBAAkB;AAAA,IAClB,UAAY;AAAA,EACd;AAAA,EACA,iBAAmB;AAAA,IACjB,mBAAmB;AAAA,IACnB,kBAAkB;AAAA,IAClB,cAAc;AAAA,IACd,6BAA6B;AAAA,IAC7B,eAAe;AAAA,IACf,cAAc;AAAA,IACd,aAAa;AAAA,IACb,oBAAoB;AAAA,IACpB,eAAe;AAAA,IACf,KAAO;AAAA,IACP,eAAe;AAAA,IACf,WAAa;AAAA,IACb,QAAU;AAAA,IACV,0BAA0B;AAAA,IAC1B,IAAM;AAAA,IACN,UAAY;AAAA,IACZ,MAAQ;AAAA,IACR,YAAc;AAAA,IACd,qBAAqB;AAAA,IACrB,MAAQ;AAAA,IACR,QAAU;AAAA,IACV,KAAO;AAAA,EACT;AACF;","names":[]}
1
+ {"version":3,"sources":["../package.json"],"sourcesContent":["{\n \"name\": \"tenjin-cli\",\n \"version\": \"0.1.0-alpha.26\",\n \"type\": \"module\",\n \"description\": \"The tool router for coding agents. Tenjin picks the right tool when your agent needs one, and one wallet pays for every call.\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/BackTrackCo/tenjin-agent.git\"\n },\n \"homepage\": \"https://tenjin.sh/agents\",\n \"bugs\": \"https://github.com/BackTrackCo/tenjin-agent/issues\",\n \"keywords\": [\n \"claude-code\",\n \"coding-agents\",\n \"tool-router\",\n \"ai-agents\",\n \"agent-tools\",\n \"mcp\",\n \"x402\",\n \"usdc\",\n \"base\",\n \"micropayments\",\n \"agent-payments\",\n \"claude\",\n \"codex\",\n \"cli\"\n ],\n \"bin\": {\n \"tenjin\": \"dist/index.js\"\n },\n \"engines\": {\n \"node\": \">=24\"\n },\n \"files\": [\n \"dist\",\n \"docs\",\n \"NOTICE.md\"\n ],\n \"packageManager\": \"pnpm@11.11.0\",\n \"scripts\": {\n \"build\": \"rm -rf dist && tsup\",\n \"test\": \"vitest run\",\n \"typecheck\": \"tsc --noEmit\",\n \"lint\": \"eslint .\",\n \"format\": \"prettier --write .\",\n \"format:check\": \"prettier --check .\",\n \"check\": \"pnpm run build && pnpm run test\",\n \"sync:skill\": \"node scripts/sync-skill.mjs\",\n \"pack-smoke\": \"bash scripts/pack-smoke.sh\",\n \"changeset\": \"changeset\",\n \"prepublishOnly\": \"pnpm run build\",\n \"githooks\": \"git config core.hooksPath .githooks\"\n },\n \"devDependencies\": {\n \"@changesets/cli\": \"^3.0.3\",\n \"@clack/prompts\": \"^1.7.0\",\n \"@eslint/js\": \"^10\",\n \"@modelcontextprotocol/sdk\": \"1.31.0\",\n \"@types/node\": \"^25\",\n \"@x402/core\": \"2.28.0\",\n \"@x402/evm\": \"2.28.0\",\n \"@x402/extensions\": \"2.28.0\",\n \"@x402/fetch\": \"2.28.0\",\n \"ajv\": \"^8.20.0\",\n \"ajv-formats\": \"^3.0.1\",\n \"commander\": \"^14.0.1\",\n \"eslint\": \"^10\",\n \"eslint-config-prettier\": \"^10\",\n \"lean-qr\": \"^2.7.4\",\n \"ox\": \"0.14.30\",\n \"prettier\": \"^3\",\n \"tsup\": \"^8.5.0\",\n \"typescript\": \"^6\",\n \"typescript-eslint\": \"^8\",\n \"viem\": \"^2.53.1\",\n \"vitest\": \"^4.1.9\",\n \"zod\": \"^4.4.3\"\n }\n}\n"],"mappings":";;;AAAA;AAAA,EACE,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,MAAQ;AAAA,EACR,aAAe;AAAA,EACf,YAAc;AAAA,IACZ,MAAQ;AAAA,IACR,KAAO;AAAA,EACT;AAAA,EACA,UAAY;AAAA,EACZ,MAAQ;AAAA,EACR,UAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,KAAO;AAAA,IACL,QAAU;AAAA,EACZ;AAAA,EACA,SAAW;AAAA,IACT,MAAQ;AAAA,EACV;AAAA,EACA,OAAS;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,gBAAkB;AAAA,EAClB,SAAW;AAAA,IACT,OAAS;AAAA,IACT,MAAQ;AAAA,IACR,WAAa;AAAA,IACb,MAAQ;AAAA,IACR,QAAU;AAAA,IACV,gBAAgB;AAAA,IAChB,OAAS;AAAA,IACT,cAAc;AAAA,IACd,cAAc;AAAA,IACd,WAAa;AAAA,IACb,gBAAkB;AAAA,IAClB,UAAY;AAAA,EACd;AAAA,EACA,iBAAmB;AAAA,IACjB,mBAAmB;AAAA,IACnB,kBAAkB;AAAA,IAClB,cAAc;AAAA,IACd,6BAA6B;AAAA,IAC7B,eAAe;AAAA,IACf,cAAc;AAAA,IACd,aAAa;AAAA,IACb,oBAAoB;AAAA,IACpB,eAAe;AAAA,IACf,KAAO;AAAA,IACP,eAAe;AAAA,IACf,WAAa;AAAA,IACb,QAAU;AAAA,IACV,0BAA0B;AAAA,IAC1B,WAAW;AAAA,IACX,IAAM;AAAA,IACN,UAAY;AAAA,IACZ,MAAQ;AAAA,IACR,YAAc;AAAA,IACd,qBAAqB;AAAA,IACrB,MAAQ;AAAA,IACR,QAAU;AAAA,IACV,KAAO;AAAA,EACT;AACF;","names":[]}
@@ -0,0 +1,99 @@
1
+ import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
+ import {
3
+ package_default
4
+ } from "./chunk-GHR4BTNJ.js";
5
+
6
+ // src/router/mcp-processes.ts
7
+ import { execFile } from "node:child_process";
8
+ import { stat } from "node:fs/promises";
9
+ import { dirname, join } from "node:path";
10
+ import { fileURLToPath } from "node:url";
11
+ import { promisify } from "node:util";
12
+ var exec = promisify(execFile);
13
+ var listMcpProcesses = async () => {
14
+ if (process.platform === "win32" || typeof process.getuid !== "function") return null;
15
+ try {
16
+ const { stdout } = await exec(
17
+ "ps",
18
+ ["-U", String(process.getuid()), "-o", "pid=,lstart=,args="],
19
+ { timeout: 5e3, env: { ...process.env, LC_ALL: "C" }, maxBuffer: 4 * 1024 * 1024 }
20
+ );
21
+ return parsePs(stdout, process.pid);
22
+ } catch {
23
+ return null;
24
+ }
25
+ };
26
+ var PS_LINE = /^\s*(\d+)\s+(\w{3}\s+\w{3}\s+\d{1,2}\s+\d{2}:\d{2}:\d{2}\s+\d{4})\s+(.*)$/;
27
+ function parsePs(stdout, selfPid) {
28
+ const found = [];
29
+ for (const line of stdout.split("\n")) {
30
+ const m = PS_LINE.exec(line);
31
+ if (m === null) continue;
32
+ const pid = Number(m[1]);
33
+ if (pid === selfPid || !isTenjinMcp(m[3])) continue;
34
+ const startedAt = Date.parse(m[2].replace(/\s+/g, " "));
35
+ found.push({ pid, startedAt: Number.isNaN(startedAt) ? null : startedAt });
36
+ }
37
+ return found;
38
+ }
39
+ function isTenjinMcp(args) {
40
+ const tokens = args.trim().split(/\s+/);
41
+ const bin = tokens.findIndex(
42
+ (t) => /(^|[/\\])tenjin(\.js|\.cmd)?$/.test(t) || /[/\\]tenjin-cli[/\\]/.test(t)
43
+ );
44
+ return bin >= 0 && tokens[bin + 1] === "mcp";
45
+ }
46
+ var installedAt = async () => {
47
+ let dir = dirname(fileURLToPath(import.meta.url));
48
+ for (let i = 0; i < 6; i += 1) {
49
+ try {
50
+ const st = await stat(join(dir, "package.json"));
51
+ return Math.max(st.ctimeMs, st.mtimeMs);
52
+ } catch {
53
+ dir = dirname(dir);
54
+ }
55
+ }
56
+ return null;
57
+ };
58
+ var RECONNECT_FIX = "Reconnect x402 with /mcp, or start a new Claude Code session.";
59
+ function mcpServersState(procs, installed, version = package_default.version) {
60
+ const check = (detail) => ({
61
+ stale: 0,
62
+ check: { name: "mcp server", status: "ok", required: false, detail }
63
+ });
64
+ if (procs === null) {
65
+ return check("unknown: running `tenjin mcp` processes cannot be listed on this platform");
66
+ }
67
+ if (procs.length === 0) return check("none running (starts with the next session)");
68
+ if (installed === null) {
69
+ return check(`${procs.length} running; when this build was installed is unknown`);
70
+ }
71
+ const stale = procs.filter((p) => p.startedAt !== null && p.startedAt < installed).length;
72
+ if (stale === 0) {
73
+ return check(`${procs.length} running, all started after this install`);
74
+ }
75
+ const which = stale === 1 ? "process" : "processes";
76
+ return {
77
+ stale,
78
+ check: {
79
+ name: "mcp server",
80
+ status: "warn",
81
+ required: false,
82
+ detail: `${stale} running \`tenjin mcp\` ${which} started before this install (${version}), so ${stale === 1 ? "it runs" : "they run"} the older build, where the hooks can fail with "Tool hook not found"`,
83
+ fix: RECONNECT_FIX
84
+ }
85
+ };
86
+ }
87
+ async function readMcpServers(deps = {}) {
88
+ const [procs, installed] = await Promise.all([
89
+ (deps.listMcpProcesses ?? listMcpProcesses)().catch(() => null),
90
+ (deps.installedAt ?? installedAt)().catch(() => null)
91
+ ]);
92
+ return mcpServersState(procs, installed);
93
+ }
94
+
95
+ export {
96
+ RECONNECT_FIX,
97
+ readMcpServers
98
+ };
99
+ //# sourceMappingURL=chunk-H4BOQLWW.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/router/mcp-processes.ts"],"sourcesContent":["import { execFile } from 'node:child_process';\nimport { stat } from 'node:fs/promises';\nimport { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { promisify } from 'node:util';\nimport pkg from '../../package.json';\nimport type { RouterCheck } from './reachability';\n\n/**\n * A `tenjin mcp` STARTED BEFORE THIS INSTALL still runs the code it started\n * with. Claude Code keeps its MCP servers for the life of a session, so after\n * an update the hooks the new install wrote can call a tool the old process\n * does not have (\"Tool hook not found\"), while every file on disk reads as\n * correct. This finds this user's running `tenjin mcp` processes and compares\n * each start time with the installed package's own `package.json`.\n */\n\nexport interface McpProcess {\n pid: number;\n /** Start time in epoch ms, or null when `ps` gave none this could read. */\n startedAt: number | null;\n}\n\n/** This user's running `tenjin mcp` processes, or null where they cannot be listed. */\nexport type ListMcpProcesses = () => Promise<McpProcess[] | null>;\n\n/** When the installed package was written, in epoch ms, or null. */\nexport type InstalledAt = () => Promise<number | null>;\n\nconst exec = promisify(execFile);\n\n/** `ps` on macOS and Linux; null on Windows or when `ps` fails, which is \"unknown\". */\nexport const listMcpProcesses: ListMcpProcesses = async () => {\n if (process.platform === 'win32' || typeof process.getuid !== 'function') return null;\n try {\n const { stdout } = await exec(\n 'ps',\n ['-U', String(process.getuid()), '-o', 'pid=,lstart=,args='],\n { timeout: 5_000, env: { ...process.env, LC_ALL: 'C' }, maxBuffer: 4 * 1024 * 1024 },\n );\n return parsePs(stdout, process.pid);\n } catch {\n return null;\n }\n};\n\nconst PS_LINE = /^\\s*(\\d+)\\s+(\\w{3}\\s+\\w{3}\\s+\\d{1,2}\\s+\\d{2}:\\d{2}:\\d{2}\\s+\\d{4})\\s+(.*)$/;\n\n/** The `tenjin mcp` lines of `ps -o pid=,lstart=,args=`, this process left out. */\nexport function parsePs(stdout: string, selfPid: number): McpProcess[] {\n const found: McpProcess[] = [];\n for (const line of stdout.split('\\n')) {\n const m = PS_LINE.exec(line);\n if (m === null) continue;\n const pid = Number(m[1]);\n if (pid === selfPid || !isTenjinMcp(m[3]!)) continue;\n const startedAt = Date.parse(m[2]!.replace(/\\s+/g, ' '));\n found.push({ pid, startedAt: Number.isNaN(startedAt) ? null : startedAt });\n }\n return found;\n}\n\n/** `tenjin mcp`, however the bin was invoked: `node /path/bin/tenjin mcp`, `tenjin mcp`. */\nfunction isTenjinMcp(args: string): boolean {\n const tokens = args.trim().split(/\\s+/);\n const bin = tokens.findIndex(\n (t) => /(^|[/\\\\])tenjin(\\.js|\\.cmd)?$/.test(t) || /[/\\\\]tenjin-cli[/\\\\]/.test(t),\n );\n return bin >= 0 && tokens[bin + 1] === 'mcp';\n}\n\n/**\n * When this build's `package.json`, the nearest one above this module, was\n * written. Its ctime, not its mtime: npm extracts a package with the\n * tarball's fixed 1985 mtimes, and setting them is what moves the ctime to\n * the moment of the install.\n */\nexport const installedAt: InstalledAt = async () => {\n let dir = dirname(fileURLToPath(import.meta.url));\n for (let i = 0; i < 6; i += 1) {\n try {\n const st = await stat(join(dir, 'package.json'));\n return Math.max(st.ctimeMs, st.mtimeMs);\n } catch {\n dir = dirname(dir);\n }\n }\n return null;\n};\n\n/** How many running servers predate the install, and what doctor says about it. */\nexport interface McpServersState {\n stale: number;\n check: RouterCheck;\n}\n\nexport const RECONNECT_FIX = 'Reconnect x402 with /mcp, or start a new Claude Code session.';\n\n/** The `mcp server` check from a process list and the install time. Never a failure. */\nexport function mcpServersState(\n procs: McpProcess[] | null,\n installed: number | null,\n version: string = pkg.version,\n): McpServersState {\n const check = (detail: string): McpServersState => ({\n stale: 0,\n check: { name: 'mcp server', status: 'ok', required: false, detail },\n });\n if (procs === null) {\n return check('unknown: running `tenjin mcp` processes cannot be listed on this platform');\n }\n if (procs.length === 0) return check('none running (starts with the next session)');\n if (installed === null) {\n return check(`${procs.length} running; when this build was installed is unknown`);\n }\n const stale = procs.filter((p) => p.startedAt !== null && p.startedAt < installed).length;\n if (stale === 0) {\n return check(`${procs.length} running, all started after this install`);\n }\n const which = stale === 1 ? 'process' : 'processes';\n return {\n stale,\n check: {\n name: 'mcp server',\n status: 'warn',\n required: false,\n detail: `${stale} running \\`tenjin mcp\\` ${which} started before this install (${version}), so ${stale === 1 ? 'it runs' : 'they run'} the older build, where the hooks can fail with \"Tool hook not found\"`,\n fix: RECONNECT_FIX,\n },\n };\n}\n\n/** The check, read from this machine (or the injected sources). */\nexport async function readMcpServers(\n deps: { listMcpProcesses?: ListMcpProcesses; installedAt?: InstalledAt } = {},\n): Promise<McpServersState> {\n const [procs, installed] = await Promise.all([\n (deps.listMcpProcesses ?? listMcpProcesses)().catch(() => null),\n (deps.installedAt ?? installedAt)().catch(() => null),\n ]);\n return mcpServersState(procs, installed);\n}\n"],"mappings":";;;;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,YAAY;AACrB,SAAS,SAAS,YAAY;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,iBAAiB;AAyB1B,IAAM,OAAO,UAAU,QAAQ;AAGxB,IAAM,mBAAqC,YAAY;AAC5D,MAAI,QAAQ,aAAa,WAAW,OAAO,QAAQ,WAAW,WAAY,QAAO;AACjF,MAAI;AAC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__tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
+ import {
3
+ evaluateSpendPolicy
4
+ } from "./chunk-XMIVHQ35.js";
2
5
  import {
3
6
  hasCode
4
7
  } from "./chunk-2I4QTOLB.js";
@@ -14,6 +17,21 @@ var ROUTE_PAID_PATH = "/api/x402-router/route";
14
17
  var ROUTING_FEE_ATOMIC = 3000n;
15
18
  var CHANNEL_DEPOSIT_ATOMIC = 250000n;
16
19
  var MIN_DEPOSIT_ATOMIC = 10n * ROUTING_FEE_ATOMIC;
20
+ var REFUSED = {
21
+ not_allowlisted: "not_allowlisted",
22
+ session_budget_exceeded: "budget_reached",
23
+ above_auto_spend: "limit_below_deposit"
24
+ };
25
+ function refusedWhy(reason) {
26
+ return REFUSED[reason] ?? reason;
27
+ }
28
+ function feeRefusal(policy, host) {
29
+ const evaluation = evaluateSpendPolicy(
30
+ { ...policy, sessionBudgetAtomic: policy.sessionBudgetAtomic === 0n ? 0n : null },
31
+ { mode: "automatic", amountAtomic: ROUTING_FEE_ATOMIC, creator: host, sessionSpentAtomic: 0n }
32
+ );
33
+ return evaluation.decision === "allow" ? null : refusedWhy(evaluation.reason);
34
+ }
17
35
  var FEE_REQUIRED = "fee_required";
18
36
  function isFeeRequired(response) {
19
37
  const decision = response?.decision;
@@ -38,7 +56,7 @@ var UNPAID = {
38
56
  fix: "Run `tenjin doctor`."
39
57
  },
40
58
  budget_reached: {
41
- reason: "the daily spend limit has no room left for a routing deposit",
59
+ reason: "the daily spend limit has no room left for the routing fee or its deposit",
42
60
  fix: "Run `tenjin doctor`."
43
61
  },
44
62
  not_allowlisted: {
@@ -54,7 +72,13 @@ var UNPAID = {
54
72
  fix: "Run `tenjin doctor`."
55
73
  }
56
74
  };
57
- var NO_FAULT = /* @__PURE__ */ new Set(["channel_busy", "paid_path_absent", "busy", "no_call"]);
75
+ var NO_FAULT = /* @__PURE__ */ new Set([
76
+ "channel_busy",
77
+ "paid_path_absent",
78
+ "busy",
79
+ "no_call",
80
+ "deadline_after_payment_sent"
81
+ ]);
58
82
  function unpaid(why) {
59
83
  if (NO_FAULT.has(why)) return null;
60
84
  return UNPAID[why] ?? UNPAID["payment_failed"];
@@ -108,6 +132,8 @@ export {
108
132
  ROUTING_FEE_ATOMIC,
109
133
  CHANNEL_DEPOSIT_ATOMIC,
110
134
  MIN_DEPOSIT_ATOMIC,
135
+ refusedWhy,
136
+ feeRefusal,
111
137
  FEE_REQUIRED,
112
138
  isFeeRequired,
113
139
  unpaid,
@@ -116,4 +142,4 @@ export {
116
142
  usd,
117
143
  firstNoticeFor
118
144
  };
119
- //# sourceMappingURL=chunk-VYONGSMQ.js.map
145
+ //# sourceMappingURL=chunk-OBPZ36HG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/router/fee.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport { mkdir, open, readFile, readdir, rm } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { hasCode } from '../lib/errno';\nimport { formatUsdDisplay } from '../lib/money';\nimport { evaluateSpendPolicy, type PolicyReason, type SpendPolicy } from '../lib/policy';\nimport type { DecisionRoute } from './decision';\n\n/**\n * THE ROUTING FEE, WITHOUT ANYTHING THAT PAYS. Every routing call on the paid\n * path pays $0.003 over x402 `batch-settlement`, and the stock SDK client in\n * `tenjin mcp` does all of it (`routing-payer.ts`). Everything else, `tenjin\n * hook` included, is the free path exactly as before this fee existed.\n *\n * Hook-safe: `tenjin hook` loads this module, and its chunk graph stays free\n * of the wallet and the x402 SDK (`dist-chunks.test.ts`).\n */\n\nexport const ROUTE_PAID_PATH = '/api/x402-router/route';\n\n/** The flat fee per routing call, atomic USDC ($0.003). */\nexport const ROUTING_FEE_ATOMIC = 3_000n;\n/** The largest channel deposit, atomic USDC ($0.25), made inline by the SDK\n * on the first paid call of a channel that cannot cover the next fee. */\nexport const CHANNEL_DEPOSIT_ATOMIC = 250_000n;\n/**\n * The smallest deposit worth signing: ten fees ($0.03). A per-call limit under\n * $0.25 sizes the deposit down to the limit while it still covers this many.\n */\nexport const MIN_DEPOSIT_ATOMIC = 10n * ROUTING_FEE_ATOMIC;\n\n/** A spend refusal, as the reason the call was not paid. */\nconst REFUSED: Partial<Record<PolicyReason, string>> = {\n not_allowlisted: 'not_allowlisted',\n session_budget_exceeded: 'budget_reached',\n above_auto_spend: 'limit_below_deposit',\n};\n\n/** The reason a spend refusal leaves a routing call unpaid. */\nexport function refusedWhy(reason: PolicyReason): string {\n return REFUSED[reason] ?? reason;\n}\n\n/**\n * THE DEPOSIT IS THE SPEND. It meets the whole policy once, the day's budget\n * included, when the SDK's `depositStrategy` reserves it. Each fee paid from\n * it then gets only the per-payment checks: the per-call limit, the creator\n * allowlist (the router's host) and an explicit zero daily limit. It is never\n * refused for the day's running total, which the deposit already consumed.\n * Null when those checks allow the fee.\n */\nexport function feeRefusal(policy: SpendPolicy, host: string): string | null {\n const evaluation = evaluateSpendPolicy(\n { ...policy, sessionBudgetAtomic: policy.sessionBudgetAtomic === 0n ? 0n : null },\n { mode: 'automatic', amountAtomic: ROUTING_FEE_ATOMIC, creator: host, sessionSpentAtomic: 0n },\n );\n return evaluation.decision === 'allow' ? null : refusedWhy(evaluation.reason);\n}\n\n/** The paid path for this call, or null for the free path. `tenjin mcp` passes\n * its payer's; absent, every call is free. */\nexport type RouteFor = (baseUrl: string) => Promise<DecisionRoute | null>;\n\n/** The free path's reason code once the server routes only paid calls. */\nexport const FEE_REQUIRED = 'fee_required';\n\n/** Whether a decision is the free path's `fee_required` answer. */\nexport function isFeeRequired(response: unknown): boolean {\n const decision = (response as { decision?: { action?: unknown; diagnostics?: unknown } })\n ?.decision;\n const diagnostics = decision?.diagnostics as { reasonCode?: unknown } | undefined;\n return decision?.action === 'native' && diagnostics?.reasonCode === FEE_REQUIRED;\n}\n\n/**\n * WHY A CALL WAS NOT PAID, for the user: the reason and the fix, keyed by the\n * payer's skip reason (or `fee_required`, when the free path answered it and\n * nothing else explains why). Null for a reason that is no fault and needs no\n * fix: another session's call on the channel, a server with no paid path, or\n * a call queued past its own budget, or a payment still out when the call's\n * budget ran out (it finishes in the background).\n */\nconst UNPAID: Record<string, { reason: string; fix: string }> = {\n wallet_low: {\n reason: `the wallet holds less than the $${usd(CHANNEL_DEPOSIT_ATOMIC)} routing deposit`,\n fix: `Fund it with \\`tenjin wallet fund ${usd(CHANNEL_DEPOSIT_ATOMIC)}\\`.`,\n },\n wallet_locked: {\n reason: '`tenjin mcp` cannot unlock the wallet without a prompt',\n fix: 'Set TENJIN_WALLET_PASSPHRASE in the environment Claude Code starts from, then restart Claude Code.',\n },\n no_wallet: {\n reason: 'this machine has no wallet',\n fix: 'Run `tenjin doctor`.',\n },\n limit_below_deposit: {\n reason: `the per-call spend limit is below the smallest routing deposit ($${usd(MIN_DEPOSIT_ATOMIC)})`,\n fix: 'Run `tenjin doctor`.',\n },\n budget_reached: {\n reason: 'the daily spend limit has no room left for the routing fee or its deposit',\n fix: 'Run `tenjin doctor`.',\n },\n not_allowlisted: {\n reason: 'allowlistCreators does not include the router',\n fix: 'Run `tenjin doctor`.',\n },\n payment_failed: {\n reason: 'the routing payment failed',\n fix: 'Run `tenjin doctor`.',\n },\n [FEE_REQUIRED]: {\n reason: 'the router now charges it, and this session cannot pay it',\n fix: 'Run `tenjin doctor`.',\n },\n};\nconst NO_FAULT = new Set([\n 'channel_busy',\n 'paid_path_absent',\n 'busy',\n 'no_call',\n 'deadline_after_payment_sent',\n]);\n\n/** The reason and fix for an unpaid call, or null when it needs no word. */\nexport function unpaid(why: string): { reason: string; fix: string } | null {\n if (NO_FAULT.has(why)) return null;\n return UNPAID[why] ?? UNPAID['payment_failed']!;\n}\n\n/** The one line the user sees, once per session, when a call was not paid. */\nexport function unpaidSentence(why: string): string | null {\n const u = unpaid(why);\n if (u === null) return null;\n return `Tenjin routing could not pay its $${usd(ROUTING_FEE_ATOMIC)} fee (${u.reason}), so calls take the free path until that is fixed. ${u.fix}`;\n}\n\nconst ADDRESS_RE = /^0x[0-9a-f]{40}$/;\n\n/** One wallet's folder: the SDK's file storage for its routing channel\n * (`client/<channelId>.json`). */\nexport function payerDir(dataDir: string, payer: string): string {\n const name = payer.toLowerCase();\n if (!ADDRESS_RE.test(name)) throw new Error(`not a wallet address: ${payer}`);\n return join(dataDir, 'router', 'fee', name);\n}\n\n/** Atomic USDC as dollars with at least two decimals, never a float. */\nexport function usd(atomic: bigint): string {\n return formatUsdDisplay(atomic.toString());\n}\n\n/** How long a session's notice marker is kept. */\nconst NOTICE_KEEP_MS = 7 * 86_400_000;\n\n/**\n * TRUE ONCE PER SESSION: the first caller for a session id creates its marker\n * and gets true; every later one gets false. Each marker holds the time it was\n * made, and those older than a week go on the way past, so the directory does\n * not grow with every session ever run.\n */\nexport async function firstNoticeFor(\n dataDir: string,\n sessionId: string,\n now: number,\n): Promise<boolean> {\n const dir = join(dataDir, 'router', 'notices');\n const name = createHash('sha256').update(sessionId).digest('hex').slice(0, 32);\n const created = await createExclusive(join(dir, name), String(now));\n if (created) {\n for (const entry of await readdir(dir).catch(() => [] as string[])) {\n const path = join(dir, entry);\n const at = Number(await readFile(path, 'utf8').catch(() => 'NaN'));\n if (!Number.isFinite(at) || now - at > NOTICE_KEEP_MS) await rm(path, { force: true });\n }\n }\n return created;\n}\n\nasync function createExclusive(path: string, body: string): Promise<boolean> {\n try {\n await mkdir(join(path, '..'), { recursive: true, mode: 0o700 });\n const handle = await open(path, 'wx', 0o600);\n try {\n await handle.writeFile(body);\n } finally {\n await handle.close();\n }\n return true;\n } catch (err) {\n if (hasCode(err, 'EEXIST')) return false;\n throw err;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,kBAAkB;AAC3B,SAAS,OAAO,MAAM,UAAU,SAAS,UAAU;AACnD,SAAS,YAAY;AAgBd,IAAM,kBAAkB;AAGxB,IAAM,qBAAqB;AAG3B,IAAM,yBAAyB;AAK/B,IAAM,qBAAqB,MAAM;AAGxC,IAAM,UAAiD;AAAA,EACrD,iBAAiB;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,eAAe,gBAAgB,MAAc,MAAgC;AAC3E,MAAI;AACF,UAAM,MAAM,KAAK,MAAM,IAAI,GAAG,EAAE,WAAW,MAAM,MAAM,IAAM,CAAC;AAC9D,UAAM,SAAS,MAAM,KAAK,MAAM,MAAM,GAAK;AAC3C,QAAI;AACF,YAAM,OAAO,UAAU,IAAI;AAAA,IAC7B,UAAE;AACA,YAAM,OAAO,MAAM;AAAA,IACrB;AACA,WAAO;AAAA,EACT,SAAS,KAAK;AACZ,QAAI,QAAQ,KAAK,QAAQ,EAAG,QAAO;AACnC,UAAM;AAAA,EACR;AACF;","names":[]}
@@ -0,0 +1,66 @@
1
+ import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
+ import {
3
+ CHANNEL_DEPOSIT_ATOMIC,
4
+ ROUTING_FEE_ATOMIC,
5
+ unpaidSentence,
6
+ usd
7
+ } from "./chunk-OBPZ36HG.js";
8
+ import {
9
+ toMoney
10
+ } from "./chunk-XICKN3CH.js";
11
+
12
+ // src/router/spend-question.ts
13
+ var ROUTER_DEFAULTS = {
14
+ maxAutoSpend: "250000",
15
+ sessionBudget: "5000000"
16
+ };
17
+ function shownLimits(config) {
18
+ return {
19
+ maxAutoSpend: config.maxAutoSpend ?? ROUTER_DEFAULTS.maxAutoSpend,
20
+ sessionBudget: config.sessionBudget ?? ROUTER_DEFAULTS.sessionBudget
21
+ };
22
+ }
23
+ function limitsUsd(limits) {
24
+ return {
25
+ maxAutoSpend: toMoney(limits.maxAutoSpend).usd,
26
+ sessionBudget: limits.sessionBudget === "none" ? "none" : toMoney(limits.sessionBudget).usd
27
+ };
28
+ }
29
+ function limitsPhrase(limits) {
30
+ const usdOf = limitsUsd(limits);
31
+ const daily = usdOf.sessionBudget === "none" ? "with no daily limit" : `and $${usdOf.sessionBudget} a day`;
32
+ return `up to $${usdOf.maxAutoSpend} a call ${daily}`;
33
+ }
34
+ var ROUTING_FEE_TERMS = `Routing costs $${usd(ROUTING_FEE_ATOMIC)} a call, paid from channel deposits of up to $${usd(CHANNEL_DEPOSIT_ATOMIC)} that stay yours until spent; each deposit counts against these limits.`;
35
+ var ACCEPT_COMMAND = `tenjin config set maxAutoSpend ${toMoney(ROUTER_DEFAULTS.maxAutoSpend).usd}`;
36
+ var OWN_LIMITS_COMMANDS = "`tenjin config set maxAutoSpend <usd>` and `tenjin config set sessionBudget <usd|none>`";
37
+ var FEE_APPROVAL = "Using these limits or choosing your own also approves the routing fee.";
38
+ function spendQuestion(limits) {
39
+ return `May Tenjin pay for tool calls without asking you each time, ${limitsPhrase(limits)}? ${ROUTING_FEE_TERMS} ${FEE_APPROVAL}`;
40
+ }
41
+ function unansweredNotice(limits, reader) {
42
+ const open = "Tenjin pays for nothing on its own yet: the spend limits are not answered.";
43
+ if (reader === "agent") {
44
+ return `${open} Ask the user: ${spendQuestion(limits)} For a yes, run \`${ACCEPT_COMMAND}\`; for other amounts, run ${OWN_LIMITS_COMMANDS}.`;
45
+ }
46
+ return `${open} It can pay for tool calls without asking you each time, ${limitsPhrase(limits)}. ${ROUTING_FEE_TERMS} ${FEE_APPROVAL} To use these limits, run \`${ACCEPT_COMMAND}\`; to choose your own, run ${OWN_LIMITS_COMMANDS}.`;
47
+ }
48
+ function unpaidNotice(why, config, reader) {
49
+ if (why === "limit_below_deposit" && config.maxAutoSpend === void 0) {
50
+ return unansweredNotice(shownLimits(config), reader);
51
+ }
52
+ return unpaidSentence(why);
53
+ }
54
+
55
+ export {
56
+ ROUTER_DEFAULTS,
57
+ shownLimits,
58
+ limitsUsd,
59
+ ROUTING_FEE_TERMS,
60
+ ACCEPT_COMMAND,
61
+ OWN_LIMITS_COMMANDS,
62
+ FEE_APPROVAL,
63
+ spendQuestion,
64
+ unpaidNotice
65
+ };
66
+ //# sourceMappingURL=chunk-PM2MOXJ3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/router/spend-question.ts"],"sourcesContent":["import { toMoney } from '../lib/money';\nimport { CHANNEL_DEPOSIT_ATOMIC, ROUTING_FEE_ATOMIC, unpaidSentence, usd } from './fee';\n\n/**\n * THE SPEND QUESTION, ONE TEXT FOR EVERY PLACE THAT ASKS IT. The selector in a\n * terminal, the question an install that could not ask hands to its agent,\n * doctor's warning and the routing notice all show the same limits, the same\n * routing-fee terms and the same one-step yes, so the agent can put to the\n * user exactly what the selector would have.\n */\n\n/** Absent-only automatic router defaults, in atomic USDC. */\nexport const ROUTER_DEFAULTS = {\n maxAutoSpend: '250000',\n sessionBudget: '5000000',\n} as const;\n\n/** The automatic limits a fresh install fills in, in atomic USDC; `sessionBudget` may be `none`. */\nexport interface RouterLimits {\n maxAutoSpend: string;\n sessionBudget: string;\n}\n\n/** What the question shows: the file's own value where it names one, else the default. */\nexport function shownLimits(config: {\n maxAutoSpend?: string | undefined;\n sessionBudget?: string | undefined;\n}): RouterLimits {\n return {\n maxAutoSpend: config.maxAutoSpend ?? ROUTER_DEFAULTS.maxAutoSpend,\n sessionBudget: config.sessionBudget ?? ROUTER_DEFAULTS.sessionBudget,\n };\n}\n\n/** The limits in USD, as the question shows them. */\nexport function limitsUsd(limits: RouterLimits): { maxAutoSpend: string; sessionBudget: string } {\n return {\n maxAutoSpend: toMoney(limits.maxAutoSpend).usd,\n sessionBudget: limits.sessionBudget === 'none' ? 'none' : toMoney(limits.sessionBudget).usd,\n };\n}\n\n/** \"up to $0.25 a call and $5 a day\" */\nexport function limitsPhrase(limits: RouterLimits): string {\n const usdOf = limitsUsd(limits);\n const daily =\n usdOf.sessionBudget === 'none' ? 'with no daily limit' : `and $${usdOf.sessionBudget} a day`;\n return `up to $${usdOf.maxAutoSpend} a call ${daily}`;\n}\n\n/** The routing fee's terms, as the selector names them. */\nexport const ROUTING_FEE_TERMS = `Routing costs $${usd(ROUTING_FEE_ATOMIC)} a call, paid from channel deposits of up to $${usd(CHANNEL_DEPOSIT_ATOMIC)} that stay yours until spent; each deposit counts against these limits.`;\n\n/**\n * The yes to the limits shown, where the command install ran is not known\n * (doctor, the routing notice, the request tool): the per-call limit only.\n * The daily limit already defaults to the one shown. A bare `install --yes`\n * here would undo a `--project`, `--no-wallet` or `--status-line skip`\n * install; install's own output names that command with its flags instead.\n */\nexport const ACCEPT_COMMAND = `tenjin config set maxAutoSpend ${toMoney(ROUTER_DEFAULTS.maxAutoSpend).usd}`;\n\n/** The commands for limits of the user's own, each in backticks. */\nexport const OWN_LIMITS_COMMANDS =\n '`tenjin config set maxAutoSpend <usd>` and `tenjin config set sessionBudget <usd|none>`';\n\n/** The selector's own line: either answer approves the fee. */\nexport const FEE_APPROVAL =\n 'Using these limits or choosing your own also approves the routing fee.';\n\n/** The question, for the agent to put to the user as written. */\nexport function spendQuestion(limits: RouterLimits): string {\n return `May Tenjin pay for tool calls without asking you each time, ${limitsPhrase(limits)}? ${ROUTING_FEE_TERMS} ${FEE_APPROVAL}`;\n}\n\n/** Who reads a notice: the user, in the hook's `systemMessage`, or the agent,\n * in the request tool's answer. */\nexport type NoticeReader = 'user' | 'agent';\n\n/**\n * The routing notice for a machine whose limits nobody has answered: the\n * question and the one-step yes, put to the user directly, or handed to the\n * agent to ask.\n */\nexport function unansweredNotice(limits: RouterLimits, reader: NoticeReader): string {\n const open = 'Tenjin pays for nothing on its own yet: the spend limits are not answered.';\n if (reader === 'agent') {\n return `${open} Ask the user: ${spendQuestion(limits)} For a yes, run \\`${ACCEPT_COMMAND}\\`; for other amounts, run ${OWN_LIMITS_COMMANDS}.`;\n }\n return `${open} It can pay for tool calls without asking you each time, ${limitsPhrase(limits)}. ${ROUTING_FEE_TERMS} ${FEE_APPROVAL} To use these limits, run \\`${ACCEPT_COMMAND}\\`; to choose your own, run ${OWN_LIMITS_COMMANDS}.`;\n}\n\n/**\n * The routing notice for a call that was not paid: the limits question when\n * the per-call limit is the code default's zero because nobody has answered\n * it, else the reason and fix for `why`.\n */\nexport function unpaidNotice(\n why: string,\n config: { maxAutoSpend?: string | undefined; sessionBudget?: string | undefined },\n reader: NoticeReader,\n): string | null {\n if (why === 'limit_below_deposit' && config.maxAutoSpend === undefined) {\n return unansweredNotice(shownLimits(config), reader);\n }\n return unpaidSentence(why);\n}\n"],"mappings":";;;;;;;;;;;;AAYO,IAAM,kBAAkB;AAAA,EAC7B,cAAc;AAAA,EACd,eAAe;AACjB;AASO,SAAS,YAAY,QAGX;AACf,SAAO;AAAA,IACL,cAAc,OAAO,gBAAgB,gBAAgB;AAAA,IACrD,eAAe,OAAO,iBAAiB,gBAAgB;AAAA,EACzD;AACF;AAGO,SAAS,UAAU,QAAuE;AAC/F,SAAO;AAAA,IACL,cAAc,QAAQ,OAAO,YAAY,EAAE;AAAA,IAC3C,eAAe,OAAO,kBAAkB,SAAS,SAAS,QAAQ,OAAO,aAAa,EAAE;AAAA,EAC1F;AACF;AAGO,SAAS,aAAa,QAA8B;AACzD,QAAM,QAAQ,UAAU,MAAM;AAC9B,QAAM,QACJ,MAAM,kBAAkB,SAAS,wBAAwB,QAAQ,MAAM,aAAa;AACtF,SAAO,UAAU,MAAM,YAAY,WAAW,KAAK;AACrD;AAGO,IAAM,oBAAoB,kBAAkB,IAAI,kBAAkB,CAAC,iDAAiD,IAAI,sBAAsB,CAAC;AAS/I,IAAM,iBAAiB,kCAAkC,QAAQ,gBAAgB,YAAY,EAAE,GAAG;AAGlG,IAAM,sBACX;AAGK,IAAM,eACX;AAGK,SAAS,cAAc,QAA8B;AAC1D,SAAO,+DAA+D,aAAa,MAAM,CAAC,KAAK,iBAAiB,IAAI,YAAY;AAClI;AAWO,SAAS,iBAAiB,QAAsB,QAA8B;AACnF,QAAM,OAAO;AACb,MAAI,WAAW,SAAS;AACtB,WAAO,GAAG,IAAI,kBAAkB,cAAc,MAAM,CAAC,qBAAqB,cAAc,8BAA8B,mBAAmB;AAAA,EAC3I;AACA,SAAO,GAAG,IAAI,4DAA4D,aAAa,MAAM,CAAC,KAAK,iBAAiB,IAAI,YAAY,+BAA+B,cAAc,+BAA+B,mBAAmB;AACrO;AAOO,SAAS,aACd,KACA,QACA,QACe;AACf,MAAI,QAAQ,yBAAyB,OAAO,iBAAiB,QAAW;AACtE,WAAO,iBAAiB,YAAY,MAAM,GAAG,MAAM;AAAA,EACrD;AACA,SAAO,eAAe,GAAG;AAC3B;","names":[]}
@@ -0,0 +1,268 @@
1
+ import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
+ import {
3
+ getAddress,
4
+ isAddress
5
+ } from "./chunk-EGELTSPU.js";
6
+
7
+ // node_modules/.pnpm/lean-qr@2.7.4/node_modules/lean-qr/index.mjs
8
+ var t = [0.2, 3 / 8, 5 / 9, 2 / 3];
9
+ var o = (o2, e2) => (r2) => {
10
+ const n2 = 4 * o2 + r2 - 4, s2 = "*-04-39?2$%%$%%'$%''%'''%')(%'))%(++'(++'(+.'+-.',/3',33)-/5)-43).36)058*18<+37<+4:<,4:E,5<A-7>C/8@F/:EH/<EK0=FM1?IP2@KS3BNV4DPY5FS\\6HV_6IXb7K[e8N^i9Pam;Rdp<Tgt".charCodeAt(n2) - 35, f2 = n2 > 8 ? s2 : 1, c2 = e2 / f2 | 0, i2 = e2 % f2, l2 = f2 - i2, a2 = n2 > 8 ? c2 * t[r2] + (o2 > 5) & -2 : s2, _2 = c2 - a2;
11
+ return { t: l2 * _2 + i2 * _2 + i2, o: [[l2, _2], [i2, _2 + 1]], i: a2 };
12
+ };
13
+ var e = { min: 0, L: 0, M: 1, Q: 2, H: 3, max: 3 };
14
+ var r = (t2) => new Uint8Array(t2);
15
+ var n = (t2) => {
16
+ const o2 = new Error(`lean-qr error ${t2}`);
17
+ throw o2.code = t2, o2;
18
+ };
19
+ var s = (t2) => "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:".indexOf(t2);
20
+ var f = (t2) => t2.charCodeAt(0);
21
+ var c = (...t2) => (o2, e2) => t2.forEach((t3) => t3(o2, e2));
22
+ var i = (t2) => (o2) => {
23
+ o2.eci !== t2 && (o2.push(7, 4), t2 < 128 ? o2.push(t2, 8) : t2 < 16384 ? o2.push(32768 | t2, 16) : o2.push(12582912 | t2, 24), o2.eci = t2);
24
+ };
25
+ var l = (t2) => (o2, e2) => {
26
+ o2.push(4, 4), o2.push(t2.length, 8 + 8 * (e2 > 9)), t2.forEach((t3) => o2.push(t3, 8));
27
+ };
28
+ var a = (t2, o2, e2, r2, n2 = (t3, o3) => e2(t3.length, o3), s2 = r2 ? (o3) => c(i(r2), t2(o3)) : t2) => (s2.test = o2, s2.l = e2, s2.est = n2, s2.eci = r2 && [r2], s2);
29
+ var _ = a((t2) => (o2, e2) => {
30
+ o2.push(1, 4), o2.push(t2.length, 10 + 2 * (e2 > 26) + 2 * (e2 > 9));
31
+ let r2 = 0;
32
+ for (; r2 < t2.length - 2; r2 += 3) o2.push(+t2.slice(r2, r2 + 3), 10);
33
+ r2 < t2.length - 1 ? o2.push(+t2.slice(r2), 7) : r2 < t2.length && o2.push(+t2[r2], 4);
34
+ }, (t2) => /[0-9]/.test(t2), (t2, o2) => 14 + 2 * (o2 > 26) + 2 * (o2 > 9) + 10 * t2 / 3);
35
+ var u = a((t2) => (o2, e2) => {
36
+ o2.push(2, 4), o2.push(t2.length, 9 + 2 * (e2 > 26) + 2 * (e2 > 9));
37
+ let r2 = 0;
38
+ for (; r2 < t2.length - 1; r2 += 2) o2.push(45 * s(t2[r2]) + s(t2[r2 + 1]), 11);
39
+ r2 < t2.length && o2.push(s(t2[r2]), 6);
40
+ }, (t2) => s(t2) >= 0, (t2, o2) => 13 + 2 * (o2 > 26) + 2 * (o2 > 9) + 5.5 * t2);
41
+ var d = a((t2) => l([...t2].map(f)), (t2) => f(t2) < 128, (t2, o2) => 12 + 8 * (o2 > 9) + 8 * t2);
42
+ d._ = true, d.u = true;
43
+ var p = a(d, (t2) => f(t2) < 256, d.l, 3);
44
+ p._ = true;
45
+ var m = new TextEncoder();
46
+ var h = a((t2) => l(m.encode(t2)), () => 1, 0, 26, (t2, o2) => 12 + 8 * (o2 > 9) + 8 * m.encode(t2).length);
47
+ h._ = true;
48
+ var w = () => {
49
+ const t2 = /* @__PURE__ */ new Map(), o2 = new TextDecoder("sjis"), e2 = r(2);
50
+ for (let r2 = 0; r2 < 7973; ++r2) e2[0] = r2 / 192 + 129 + 64 * (r2 > 5951), e2[1] = r2 % 192 + 64, t2.set(o2.decode(e2), r2);
51
+ return t2.delete("\uFFFD"), w = () => t2, t2;
52
+ };
53
+ var y = a((t2) => (o2, e2) => {
54
+ o2.push(8, 4), o2.push(t2.length, 8 + 2 * (e2 > 26) + 2 * (e2 > 9));
55
+ for (const e3 of t2) o2.push(w().get(e3), 13);
56
+ }, (t2) => w().has(t2), (t2, o2) => 12 + 2 * (o2 > 26) + 2 * (o2 > 9) + 13 * t2);
57
+ y._ = true;
58
+ var g = [_, u, d, p, y, h];
59
+ var b = { auto: (t2, { modes: o2 = g } = {}) => (e2, r2) => {
60
+ const s2 = o2.map((o3, e3) => {
61
+ const n2 = /* @__PURE__ */ new Map(), s3 = (t3, o4) => (n2.has(t3) || n2.set(t3, o4(t3, r2)), n2.get(t3));
62
+ return { m: o3, h: 1 << e3, C: o3.est("", r2), S: o3.l ? (t3, e4) => s3(e4 - t3, o3.l) : (e4, r3) => s3(t2.slice(e4, r3), o3.est) };
63
+ });
64
+ let f2 = [{ v: 0 }], c2 = 0, i2 = 0, l2 = -1;
65
+ for (const o3 of [...t2, ""]) {
66
+ let t3 = 0;
67
+ if (o3) for (const e3 of s2) e3.m.test(o3) && (t3 |= e3.h);
68
+ if (!o3 || t3 !== l2) {
69
+ if (-1 !== l2) {
70
+ const t4 = new Set(f2.map((t5) => t5.D)), o4 = [];
71
+ for (const { m: e3, C: r3, S: n2, h: a3 } of s2) if (l2 & a3) {
72
+ const s3 = n2(c2, i2);
73
+ for (const l3 of e3.eci ?? t4) if (!e3.u || !l3) {
74
+ let t5;
75
+ for (const o5 of f2) if (o5.D === l3 || e3.eci) {
76
+ const f3 = o5.m === e3 && o5.D === l3, a4 = f3 ? o5.V : o5, _2 = e3._ && f3 ? o5.v + s3 - r3 : a4.v + 12 * (a4.D !== l3) + (f3 ? n2(f3 ? o5.$ : c2, i2) : s3);
77
+ (!t5 || _2 < t5.v) && (t5 = { $: f3 ? o5.$ : c2, V: a4, m: e3, D: l3, A: i2, v: _2 });
78
+ }
79
+ t5 && o4.push(t5);
80
+ }
81
+ }
82
+ f2 = o4;
83
+ }
84
+ l2 = t3, c2 = i2;
85
+ }
86
+ i2 += o3.length;
87
+ }
88
+ f2.length || n(5);
89
+ const a2 = [];
90
+ for (let o3 = f2.reduce((t3, o4) => o4.v < t3.v ? o4 : t3); o3.m; o3 = o3.V) a2.push(o3.m(t2.slice(o3.$, o3.A)));
91
+ a2.reverse().forEach((t3) => t3(e2, r2));
92
+ }, multi: c, eci: i, bytes: l, numeric: _, alphaNumeric: u, ascii: d, iso8859_1: p, shift_jis: y, utf8: h };
93
+ var C = () => ({ F: r(2956), I: 0, push(t2, o2) {
94
+ for (let e2 = o2, r2 = 8 - (7 & this.I); e2 > 0; e2 -= r2, r2 = 8) this.F[this.I >> 3] |= t2 << r2 >> e2, this.I += e2 < r2 ? e2 : r2;
95
+ } });
96
+ var x = (t2, o2 = t2 * t2, e2 = r(o2)) => ({ size: t2, K: e2, get: (o3, r2) => o3 >= 0 && o3 < t2 && !!(1 & e2[r2 * t2 + o3]), toString({ on: o3 = "##", off: e3 = " ", lf: r2 = "\n", pad: n2 = 4, padX: s2 = n2, padY: f2 = n2 } = {}) {
97
+ let c2 = "";
98
+ for (let n3 = -f2; n3 < t2 + f2; ++n3) {
99
+ for (let r3 = -s2; r3 < t2 + s2; ++r3) c2 += this.get(r3, n3) ? o3 : e3;
100
+ c2 += r2;
101
+ }
102
+ return c2;
103
+ }, toImageData(o3, { on: e3 = [0, 0, 0], off: r2 = [0, 0, 0, 0], pad: n2 = 4, padX: s2 = n2, padY: f2 = n2 } = {}) {
104
+ const c2 = t2 + 2 * s2, i2 = t2 + 2 * f2, l2 = o3.createImageData(c2, i2), a2 = new Uint32Array(l2.data.buffer);
105
+ l2.data.set([...e3, 255]);
106
+ const _2 = a2[0];
107
+ l2.data.set([...r2, 255]);
108
+ const u2 = a2[0];
109
+ for (let t3 = 0; t3 < i2; ++t3) for (let o4 = 0; o4 < c2; ++o4) a2[t3 * c2 + o4] = this.get(o4 - s2, t3 - f2) ? _2 : u2;
110
+ return l2;
111
+ }, toCanvas(t3, o3) {
112
+ const e3 = t3.getContext("2d"), r2 = this.toImageData(e3, o3);
113
+ t3.width = r2.width, t3.height = r2.height, e3.putImageData(r2, 0, 0);
114
+ }, toDataURL({ type: t3 = "image/png", scale: o3 = 1, ...e3 } = {}) {
115
+ const r2 = document.createElement("canvas"), n2 = r2.getContext("2d"), s2 = this.toImageData(n2, e3);
116
+ return r2.width = s2.width * o3, r2.height = s2.height * o3, n2.putImageData(s2, 0, 0), n2.imageSmoothingEnabled = false, n2.globalCompositeOperation = "copy", n2.drawImage(r2, 0, 0, s2.width, s2.height, 0, 0, r2.width, r2.height), r2.toDataURL(t3, 1);
117
+ } });
118
+ var z = [(t2, o2) => 1 & (t2 ^ o2), (t2, o2) => 1 & o2, (t2) => t2 % 3, (t2, o2) => (t2 + o2) % 3, (t2, o2) => 1 & (t2 / 3 ^ o2 >> 1), (t2, o2) => (t2 & o2 & 1) + t2 * o2 % 3, (t2, o2) => (t2 & o2) + t2 * o2 % 3 & 1, (t2, o2) => (t2 ^ o2) + t2 * o2 % 3 & 1];
119
+ var E = r(511);
120
+ for (let t2 = 0, o2 = 1; t2 < 255; o2 = 2 * o2 ^ 285 * (o2 > 127)) E[E[o2 + 255] = t2++] = o2;
121
+ var M = (t2) => E[t2 % 255];
122
+ var S = (t2) => E[t2 + 255];
123
+ var v = (t2, o2) => {
124
+ const e2 = r(t2.length + o2.length - 1);
125
+ for (let r2 = 0; r2 < t2.length; ++r2) for (let n2 = 0; n2 < o2.length; ++n2) e2[r2 + n2] ^= M(t2[r2] + o2[n2]);
126
+ return e2.map(S);
127
+ };
128
+ var D = (t2, o2) => {
129
+ const e2 = r(t2.length + o2.length - 1);
130
+ e2.set(t2, 0);
131
+ for (let r2 = 0; r2 < t2.length; ++r2) if (e2[r2]) {
132
+ const t3 = S(e2[r2]);
133
+ for (let n2 = 0; n2 < o2.length; ++n2) e2[r2 + n2] ^= M(o2[n2] + t3);
134
+ }
135
+ return e2.slice(t2.length);
136
+ };
137
+ var L = [[0], [0, 0]];
138
+ for (let t2 = 1; t2 < 30; ++t2) L.push(v(L[t2], [0, t2]));
139
+ var V = (t2, o2) => {
140
+ const e2 = [[], []];
141
+ let n2 = 0, s2 = 0;
142
+ for (const [r2, f3] of o2.o) for (let c2 = 0; c2 < r2; ++c2, n2 += f3) {
143
+ const r3 = t2.slice(n2, n2 + f3);
144
+ e2[0].push(r3), e2[1].push(D(r3, L[o2.i])), s2 += f3 + o2.i;
145
+ }
146
+ const f2 = r(s2);
147
+ s2 = 0;
148
+ for (const t3 of e2) for (let o3 = 0, e3 = -1; e3 < s2; ++o3) {
149
+ e3 = s2;
150
+ for (const e4 of t3) o3 < e4.length && (f2[s2++] = e4[o3]);
151
+ }
152
+ return f2;
153
+ };
154
+ var $ = (t2, o2, e2) => {
155
+ let r2 = t2 <<= e2;
156
+ for (let t3 = 134217728; t3 >>= 1; ) r2 & t3 && (r2 ^= o2 * (t3 >> e2));
157
+ return r2 | t2;
158
+ };
159
+ var A = ({ size: t2, K: o2 }, e2) => {
160
+ const r2 = (e3, r3, n3, s3) => {
161
+ for (; n3-- > 0; e3 += t2) o2.fill(s3, e3, e3 + r3);
162
+ }, n2 = (o3, e3, n3) => {
163
+ for (let s3 = 0; s3++ < 3; n3 -= 2) r2(e3 * t2 + o3 - (n3 >> 1) * (t2 + 1), n3, n3, 2 | s3);
164
+ }, s2 = 2 * ((t2 - 13) / (1 + (e2 / 7 | 0)) / 2 + 0.75 | 0);
165
+ if (e2 > 1) for (let o3 = t2 - 7; o3 > 8; o3 -= s2) {
166
+ for (let t3 = o3; t3 > 8; t3 -= s2) n2(o3, t3, 5);
167
+ o3 < t2 - 7 && n2(o3, 6, 5);
168
+ }
169
+ if (e2 > 6) for (let r3 = $(e2, 7973, 12), n3 = 1; n3 < 7; ++n3) for (let e3 = 12; e3-- > 9; r3 >>= 1) o2[n3 * t2 - e3] = 2 | 1 & r3;
170
+ r2(7, 2, 9, 2), r2(t2 - 8, 8, 9, 2);
171
+ for (let e3 = 0; e3 < t2; ++e3) o2[6 * t2 + e3] = 3 ^ 1 & e3;
172
+ n2(3, 3, 7), n2(t2 - 4, 3, 7);
173
+ for (let e3 = 0; e3 < t2; ++e3) for (let r3 = e3; r3 < t2; ++r3) o2[r3 * t2 + e3] = o2[e3 * t2 + r3];
174
+ o2[(t2 - 8) * t2 + 8] = 3;
175
+ };
176
+ var F = ({ size: t2, K: o2 }) => {
177
+ const e2 = [];
178
+ for (let r2 = t2 - 2, n2 = t2, s2 = -1; r2 >= 0; r2 -= 2) {
179
+ for (5 === r2 && (r2 = 4); n2 += s2, -1 !== n2 && n2 !== t2; ) {
180
+ const s3 = n2 * t2 + r2;
181
+ o2[s3 + 1] || e2.push(s3 + 1), o2[s3] || e2.push(s3);
182
+ }
183
+ s2 *= -1;
184
+ }
185
+ return e2;
186
+ };
187
+ var H = ({ K: t2 }, o2, e2) => o2.forEach((o3, r2) => t2[o3] = e2[r2 >> 3] >> (7 & ~r2) & 1);
188
+ var I = ({ size: t2, K: o2 }, e2, r2, n2) => {
189
+ for (let r3 = 0; r3 < t2; ++r3) for (let n3 = 0; n3 < t2; ++n3) {
190
+ const s3 = r3 * t2 + n3;
191
+ o2[s3] ^= !(e2(n3, r3) || 2 & o2[s3]);
192
+ }
193
+ let s2 = 21522 ^ $((1 ^ n2) << 3 | r2, 1335, 10);
194
+ for (let e3 = 0; e3++ < 8; s2 >>= 1) o2[(e3 - (e3 < 7)) * t2 + 8] = 1 & s2, o2[9 * t2 - e3] = 1 & s2;
195
+ for (let e3 = 8; --e3, s2; s2 >>= 1) o2[8 * t2 + e3 - (e3 < 7)] = 1 & s2, o2[(t2 - e3) * t2 + 8] = 1 & s2;
196
+ };
197
+ var K = ({ size: t2, K: o2 }, e2 = 0, r2 = 0) => {
198
+ for (let n2 = 0; n2 < t2; ++n2) {
199
+ for (let s2 = 0; s2 < 2; ++s2) for (let f2, c2 = 0, i2 = 0, l2 = 2; c2 < t2; ++c2) {
200
+ const a2 = 1 & o2[s2 ? n2 * t2 + c2 : c2 * t2 + n2];
201
+ r2 += a2, i2 = (i2 >> 1 | 2098176) & (3047517 ^ a2 - 1), 2049 & i2 && (e2 += 40), a2 ^ l2 && (f2 = 0), l2 = a2, e2 += 5 === ++f2 ? 3 : f2 > 5;
202
+ }
203
+ if (n2) for (let r3 = t2 + n2, s2 = 5 * o2[n2 - 1] ^ o2[n2]; r3 < t2 * t2; r3 += t2) {
204
+ const t3 = 5 * o2[r3 - 1] ^ o2[r3];
205
+ e2 += 3 * !(1 & (s2 | t3) | 4 & (s2 ^ t3)), s2 = t3;
206
+ }
207
+ }
208
+ return e2 + 10 * (10 * Math.abs(r2 / (t2 * t2) - 1) | 0);
209
+ };
210
+ var N = [];
211
+ var P = (t2 = n(1), { minCorrectionLevel: e2 = 0, maxCorrectionLevel: r2 = 3, minVersion: s2 = 1, maxVersion: f2 = 40, mask: c2, trailer: i2 = 60433, ...l2 } = {}) => {
212
+ r2 < e2 && n(3), f2 < s2 && n(2), "string" == typeof t2 && (t2 = b.auto(t2, l2));
213
+ for (let n2 = s2, l3 = 0; n2 <= f2; ++n2) {
214
+ let s3 = N[n2];
215
+ s3 || (N[n2] = s3 = x(4 * n2 + 17), A(s3, n2), s3.p = F(s3));
216
+ const f3 = o(n2, s3.p.length >> 3);
217
+ if (8 * f3(e2).t < l3) continue;
218
+ const a2 = C();
219
+ t2(a2, n2), l3 = a2.I;
220
+ for (let t3 = r2; t3 >= e2; --t3) {
221
+ const o2 = f3(t3);
222
+ if (8 * o2.t < l3) continue;
223
+ for (a2.I = l3 + 11 & -8; a2.I < 8 * o2.t; ) a2.push(i2, 16);
224
+ const e3 = x(s3.size, s3.K);
225
+ return H(e3, s3.p, V(a2.F, o2)), (z[c2] ? [z[c2]] : z).map((o3, r3) => {
226
+ const n3 = x(e3.size, e3.K);
227
+ return I(n3, o3, c2 ?? r3, t3), n3.s = z[c2] ? 0 : K(n3), n3;
228
+ }).reduce((t4, o3) => o3.s < t4.s ? o3 : t4);
229
+ }
230
+ }
231
+ n(4);
232
+ };
233
+ P.with = (...t2) => (o2, e2) => P(o2, { modes: [...g, ...t2], ...e2 });
234
+
235
+ // src/lib/qr.ts
236
+ var QR_NETWORK_LINE = "USDC on Base (eip155:8453)";
237
+ var QUIET_ZONE = 2;
238
+ var DARK_ON_LIGHT = "\x1B[30;47m";
239
+ var RESET = "\x1B[0m";
240
+ function addressQrLines(address, stream) {
241
+ if (!isAddress(address, { strict: false })) return [];
242
+ const facts = stream;
243
+ if (typeof facts.hasColors !== "function" || facts.hasColors.call(stream) !== true) return [];
244
+ const code = P(getAddress(address), {
245
+ minCorrectionLevel: e.M,
246
+ maxCorrectionLevel: e.M
247
+ });
248
+ const span = code.size + 2 * QUIET_ZONE;
249
+ if (typeof facts.columns !== "number" || facts.columns < span) return [];
250
+ const dark = (x2, y2) => x2 >= 0 && y2 >= 0 && x2 < code.size && y2 < code.size && code.get(x2, y2);
251
+ const lines = [];
252
+ for (let y2 = -QUIET_ZONE; y2 < code.size + QUIET_ZONE; y2 += 2) {
253
+ let line = "";
254
+ for (let x2 = -QUIET_ZONE; x2 < code.size + QUIET_ZONE; x2++) {
255
+ const top = dark(x2, y2);
256
+ const bottom = dark(x2, y2 + 1);
257
+ line += top && bottom ? "\u2588" : top ? "\u2580" : bottom ? "\u2584" : " ";
258
+ }
259
+ lines.push(`${DARK_ON_LIGHT}${line}${RESET}`);
260
+ }
261
+ lines.push(QR_NETWORK_LINE);
262
+ return lines;
263
+ }
264
+
265
+ export {
266
+ addressQrLines
267
+ };
268
+ //# sourceMappingURL=chunk-PZ5N6BAL.js.map